chiark / gitweb /
Initial revision
[become] / src / class.h
1 /* -*-c-*-
2  *
3  * $Id: class.h,v 1.1 1997/07/21 13:47:52 mdw Exp $
4  *
5  * Handling classes of things nicely
6  *
7  * (c) 1997 EBI
8  */
9
10 /*----- Licencing notice --------------------------------------------------*
11  *
12  * This file is part of `become'
13  *
14  * `Become' is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * `Become' is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with `become'; if not, write to the Free Software
26  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27  */
28
29 /*----- Revision history --------------------------------------------------*
30  *
31  * $Log: class.h,v $
32  * Revision 1.1  1997/07/21 13:47:52  mdw
33  * Initial revision
34  *
35  */
36
37 #ifndef CLASS_H
38 #define CLASS_H
39
40 #ifdef __cplusplus
41   extern "C" {
42 #endif
43
44 /*----- Required headers --------------------------------------------------*/
45
46 #include <sys/types.h>
47 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
50
51 #ifndef SYM_H
52 #  include "sym.h"
53 #endif
54
55 /*----- Data structures ---------------------------------------------------*/
56
57 /* --- Class types --- */
58
59 enum {
60   clType_user = 1,                      /* Class of users */
61   clType_command = 2,                   /* Class of command strings */
62   clType_host = 4,                      /* Class of host names */
63   clType_all = 7,                       /* All of the above (maintain me) */
64   clType__limit                         /* First undefined class type */
65 };
66
67 /* --- Class block --- */
68
69 typedef struct classdef {
70   unsigned type;                        /* Type of this class */
71   unsigned ref;                         /* Reference count */
72   sym_table *t;                         /* Symbol table for this class */
73 } classdef;
74
75 /*----- Global variables --------------------------------------------------*/
76
77 extern classdef *class_all;             /* The match-everything class */
78
79 /*----- Functions provided ------------------------------------------------*/
80
81 /* --- @class_create@ --- *
82  *
83  * Arguments:   @unsigned type@ = type of the class to create
84  *              @sym_table *t@ = pointer to symbol table which stores info
85  *
86  * Returns:     Pointer to a @classdef@ which maintains the class's info.
87  *
88  * Use:         Creates a new class definition.  The new definition has one
89  *              reference attached to it (which is the one you get returned).
90  */
91
92 extern classdef *class_create(unsigned /*type*/, sym_table */*t*/);
93
94 /* --- @class_inc@ --- *
95  *
96  * Arguments:   @classdef *c@ = pointer to a class block
97  *
98  * Returns:     ---
99  *
100  * Use:         Adds a reference to the class definition.
101  */
102
103 extern void class_inc(classdef */*c*/);
104
105 /* --- @class_dec@ --- *
106  *
107  * Arguments:   @classdef *c@ = pointer to a class block
108  *
109  * Returns:     ---
110  *
111  * Use:         Removes a reference to a class block.
112  */
113
114 extern void class_dec(classdef */*c*/);
115
116 /* --- @class_userMatch@ --- *
117  *
118  * Arguments:   @classdef *c@ = pointer to a class block
119  *              @int u@ = uid number to check against
120  *
121  * Returns:     Zero if no match, nonzero if it matched.
122  *
123  * Use:         Looks to see if a user is in a group.
124  */
125
126 extern int class_userMatch(classdef */*c*/, int /*u*/);
127
128 /* --- @class_commandMatch@ --- *
129  *
130  * Arguments:   @classdef *c@ = pointer to a class block
131  *              @const char *p@ = pointer to command string to match
132  *
133  * Returns:     Zero for no match, nonzero if it matched.
134  *
135  * Use:         Tries to match a string against the wildcard patterns in the
136  *              given class.  Note that this involves examining all the
137  *              items, so it's not too quick.  Then again, you don't have
138  *              big command classes, do you...?
139  */
140
141 extern int class_commandMatch(classdef */*c*/, const char */*p*/);
142
143 /* --- @class_hostMatch@ --- *
144  *
145  * Arguments:   @classdef *c@ = pointer to class block
146  *              @struct in_addr addr@ = IP address to match
147  *
148  * Returns:     Zero for no match, nonzero if it matched.
149  *
150  * Use:         Tries to match an IP address against the patterns and masks
151  *              in the given class.
152  */
153
154 extern int class_hostMatch(classdef */*c*/, struct in_addr /*addr*/);
155
156 /* --- @class_dump@ --- *
157  *
158  * Arguments:   @classdef *c@ = pointer to a class block
159  *              @FILE *fp@ = pointer to a stream object
160  *
161  * Returns:     ---
162  *
163  * Use:         Dumps the contents of a class to a stream.
164  */
165
166 extern void class_dump(classdef */*c*/, FILE */*fp*/);
167
168 /*----- That's all, folks -------------------------------------------------*/
169
170 #ifdef __cplusplus
171   }
172 #endif
173
174 #endif
175