c4f2d992 |
1 | /* -*-c-*- |
2 | * |
03f996bd |
3 | * $Id: class.h,v 1.2 1997/08/04 10:24:21 mdw Exp $ |
c4f2d992 |
4 | * |
5 | * Handling classes of things nicely |
6 | * |
7 | * (c) 1997 EBI |
8 | */ |
9 | |
03f996bd |
10 | /*----- Licensing notice --------------------------------------------------* |
c4f2d992 |
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 |
03f996bd |
25 | * along with `become'; if not, write to the Free Software Foundation, |
26 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
c4f2d992 |
27 | */ |
28 | |
29 | /*----- Revision history --------------------------------------------------* |
30 | * |
31 | * $Log: class.h,v $ |
03f996bd |
32 | * Revision 1.2 1997/08/04 10:24:21 mdw |
33 | * Sources placed under CVS control. |
34 | * |
35 | * Revision 1.1 1997/07/21 13:47:52 mdw |
c4f2d992 |
36 | * Initial revision |
37 | * |
38 | */ |
39 | |
40 | #ifndef CLASS_H |
41 | #define CLASS_H |
42 | |
43 | #ifdef __cplusplus |
44 | extern "C" { |
45 | #endif |
46 | |
47 | /*----- Required headers --------------------------------------------------*/ |
48 | |
49 | #include <sys/types.h> |
50 | #include <sys/socket.h> |
51 | #include <netinet/in.h> |
52 | #include <arpa/inet.h> |
53 | |
54 | #ifndef SYM_H |
55 | # include "sym.h" |
56 | #endif |
57 | |
58 | /*----- Data structures ---------------------------------------------------*/ |
59 | |
60 | /* --- Class types --- */ |
61 | |
62 | enum { |
63 | clType_user = 1, /* Class of users */ |
64 | clType_command = 2, /* Class of command strings */ |
65 | clType_host = 4, /* Class of host names */ |
66 | clType_all = 7, /* All of the above (maintain me) */ |
67 | clType__limit /* First undefined class type */ |
68 | }; |
69 | |
70 | /* --- Class block --- */ |
71 | |
72 | typedef struct classdef { |
73 | unsigned type; /* Type of this class */ |
74 | unsigned ref; /* Reference count */ |
75 | sym_table *t; /* Symbol table for this class */ |
76 | } classdef; |
77 | |
78 | /*----- Global variables --------------------------------------------------*/ |
79 | |
80 | extern classdef *class_all; /* The match-everything class */ |
81 | |
82 | /*----- Functions provided ------------------------------------------------*/ |
83 | |
84 | /* --- @class_create@ --- * |
85 | * |
86 | * Arguments: @unsigned type@ = type of the class to create |
87 | * @sym_table *t@ = pointer to symbol table which stores info |
88 | * |
89 | * Returns: Pointer to a @classdef@ which maintains the class's info. |
90 | * |
91 | * Use: Creates a new class definition. The new definition has one |
92 | * reference attached to it (which is the one you get returned). |
93 | */ |
94 | |
95 | extern classdef *class_create(unsigned /*type*/, sym_table */*t*/); |
96 | |
97 | /* --- @class_inc@ --- * |
98 | * |
99 | * Arguments: @classdef *c@ = pointer to a class block |
100 | * |
101 | * Returns: --- |
102 | * |
103 | * Use: Adds a reference to the class definition. |
104 | */ |
105 | |
106 | extern void class_inc(classdef */*c*/); |
107 | |
108 | /* --- @class_dec@ --- * |
109 | * |
110 | * Arguments: @classdef *c@ = pointer to a class block |
111 | * |
112 | * Returns: --- |
113 | * |
114 | * Use: Removes a reference to a class block. |
115 | */ |
116 | |
117 | extern void class_dec(classdef */*c*/); |
118 | |
119 | /* --- @class_userMatch@ --- * |
120 | * |
121 | * Arguments: @classdef *c@ = pointer to a class block |
122 | * @int u@ = uid number to check against |
123 | * |
124 | * Returns: Zero if no match, nonzero if it matched. |
125 | * |
126 | * Use: Looks to see if a user is in a group. |
127 | */ |
128 | |
129 | extern int class_userMatch(classdef */*c*/, int /*u*/); |
130 | |
131 | /* --- @class_commandMatch@ --- * |
132 | * |
133 | * Arguments: @classdef *c@ = pointer to a class block |
134 | * @const char *p@ = pointer to command string to match |
135 | * |
136 | * Returns: Zero for no match, nonzero if it matched. |
137 | * |
138 | * Use: Tries to match a string against the wildcard patterns in the |
139 | * given class. Note that this involves examining all the |
140 | * items, so it's not too quick. Then again, you don't have |
141 | * big command classes, do you...? |
142 | */ |
143 | |
144 | extern int class_commandMatch(classdef */*c*/, const char */*p*/); |
145 | |
146 | /* --- @class_hostMatch@ --- * |
147 | * |
148 | * Arguments: @classdef *c@ = pointer to class block |
149 | * @struct in_addr addr@ = IP address to match |
150 | * |
151 | * Returns: Zero for no match, nonzero if it matched. |
152 | * |
153 | * Use: Tries to match an IP address against the patterns and masks |
154 | * in the given class. |
155 | */ |
156 | |
157 | extern int class_hostMatch(classdef */*c*/, struct in_addr /*addr*/); |
158 | |
159 | /* --- @class_dump@ --- * |
160 | * |
161 | * Arguments: @classdef *c@ = pointer to a class block |
c4f2d992 |
162 | * |
163 | * Returns: --- |
164 | * |
165 | * Use: Dumps the contents of a class to a stream. |
166 | */ |
167 | |
03f996bd |
168 | extern void class_dump(classdef */*c*/); |
c4f2d992 |
169 | |
170 | /*----- That's all, folks -------------------------------------------------*/ |
171 | |
172 | #ifdef __cplusplus |
173 | } |
174 | #endif |
175 | |
176 | #endif |
177 | |