3 * $Id: class.h,v 1.1 1997/07/21 13:47:52 mdw Exp $
5 * Handling classes of things nicely
10 /*----- Licencing notice --------------------------------------------------*
12 * This file is part of `become'
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.
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.
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.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.1 1997/07/21 13:47:52 mdw
44 /*----- Required headers --------------------------------------------------*/
46 #include <sys/types.h>
47 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
55 /*----- Data structures ---------------------------------------------------*/
57 /* --- Class types --- */
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 */
67 /* --- Class block --- */
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 */
75 /*----- Global variables --------------------------------------------------*/
77 extern classdef *class_all; /* The match-everything class */
79 /*----- Functions provided ------------------------------------------------*/
81 /* --- @class_create@ --- *
83 * Arguments: @unsigned type@ = type of the class to create
84 * @sym_table *t@ = pointer to symbol table which stores info
86 * Returns: Pointer to a @classdef@ which maintains the class's info.
88 * Use: Creates a new class definition. The new definition has one
89 * reference attached to it (which is the one you get returned).
92 extern classdef *class_create(unsigned /*type*/, sym_table */*t*/);
94 /* --- @class_inc@ --- *
96 * Arguments: @classdef *c@ = pointer to a class block
100 * Use: Adds a reference to the class definition.
103 extern void class_inc(classdef */*c*/);
105 /* --- @class_dec@ --- *
107 * Arguments: @classdef *c@ = pointer to a class block
111 * Use: Removes a reference to a class block.
114 extern void class_dec(classdef */*c*/);
116 /* --- @class_userMatch@ --- *
118 * Arguments: @classdef *c@ = pointer to a class block
119 * @int u@ = uid number to check against
121 * Returns: Zero if no match, nonzero if it matched.
123 * Use: Looks to see if a user is in a group.
126 extern int class_userMatch(classdef */*c*/, int /*u*/);
128 /* --- @class_commandMatch@ --- *
130 * Arguments: @classdef *c@ = pointer to a class block
131 * @const char *p@ = pointer to command string to match
133 * Returns: Zero for no match, nonzero if it matched.
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...?
141 extern int class_commandMatch(classdef */*c*/, const char */*p*/);
143 /* --- @class_hostMatch@ --- *
145 * Arguments: @classdef *c@ = pointer to class block
146 * @struct in_addr addr@ = IP address to match
148 * Returns: Zero for no match, nonzero if it matched.
150 * Use: Tries to match an IP address against the patterns and masks
151 * in the given class.
154 extern int class_hostMatch(classdef */*c*/, struct in_addr /*addr*/);
156 /* --- @class_dump@ --- *
158 * Arguments: @classdef *c@ = pointer to a class block
159 * @FILE *fp@ = pointer to a stream object
163 * Use: Dumps the contents of a class to a stream.
166 extern void class_dump(classdef */*c*/, FILE */*fp*/);
168 /*----- That's all, folks -------------------------------------------------*/