3 * $Id: rule.c,v 1.1 1997/07/21 13:47:45 mdw Exp $
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:45 mdw
37 /*----- Header files ------------------------------------------------------*/
39 /* --- ANSI headers --- */
45 /* --- Local headers --- */
52 /*----- Type definitions --------------------------------------------------*/
54 /* --- Rule block --- */
57 struct rule
*next
; /* Next rule in the list */
58 classdef
*host
; /* Hosts this rule applies to */
59 classdef
*from
; /* From users in this class */
60 classdef
*to
; /* To users in this class */
61 classdef
*cmd
; /* To run commands in this class */
64 /*----- Static variables --------------------------------------------------*/
66 static rule
*rule__list
; /* List of rules */
67 static rule
*rule__tail
; /* Pointer to last rule item */
69 /*----- Main code ---------------------------------------------------------*/
71 /* --- @rule_init@ --- *
77 * Use: Intialises the rule database.
83 rule__tail
= (rule
*)&rule__list
;
86 /* --- @rule_reinit@ --- *
92 * Use: Reinitialises the rule database.
95 void rule_reinit(void)
109 /* --- @rule_add@ --- *
111 * Arguments: @classdef *host@ = class of hosts this rule applies to
112 * @classdef *from@ = class of users allowed to change
113 * @classdef *to@ = class of users allowed to be changed to
114 * @classdef *cmd@ = class of commands allowed
118 * Use: Registers another rule.
121 void rule_add(classdef
*host
, classdef
*from
, classdef
*to
, classdef
*cmd
)
123 rule
*r
= xmalloc(sizeof(*r
));
130 rule__tail
->next
= r
;
134 /* --- @rule_check@ --- *
136 * Arguments: @request *r@ = pointer to a request block
138 * Returns: Zero if disallowed, nonzero if allowed.
140 * Use: Checks a request to see if it's allowed.
143 int rule_check(request
*r
)
145 rule
*rr
= rule__list
;
148 if (class_userMatch(rr
->from
, r
->from
) &&
149 class_userMatch(rr
->to
, r
->to
) &&
150 class_commandMatch(rr
->cmd
, r
->cmd
) &&
151 class_hostMatch(rr
->host
, r
->host
))
158 /*----- That's all, folks -------------------------------------------------*/