xref: /titanic_52/usr/src/cmd/lp/lib/access/allowed.c (revision 1cb6af97c6f66f456d4f726ef056e1ebc0f73305)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.7	*/
27 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
28 
29 #include "string.h"
30 #include "unistd.h"
31 
32 #include "lp.h"
33 #include "access.h"
34 
35 /**
36  ** is_user_admin() - CHECK IF CURRENT USER IS AN ADMINISTRATOR
37  **/
38 
39 int
40 #if	defined(__STDC__)
41 is_user_admin (
42 	void
43 )
44 #else
45 is_user_admin ()
46 #endif
47 {
48 	return (Access(Lp_A, W_OK) == -1? 0 : 1);
49 }
50 
51 /**
52  ** is_user_allowed() - CHECK USER ACCESS ACCORDING TO ALLOW/DENY LISTS
53  **/
54 
55 int
56 #if	defined(__STDC__)
57 is_user_allowed (
58 	char *			user,
59 	char **			allow,
60 	char **			deny
61 )
62 #else
63 is_user_allowed (user, allow, deny)
64 	char			*user,
65 				**allow,
66 				**deny;
67 #endif
68 {
69 	if (bangequ(user, LOCAL_LPUSER) || bangequ(user, LOCAL_ROOTUSER))
70 		return (1);
71 
72 	return (allowed(user, allow, deny));
73 }
74 
75 /**
76  ** is_user_allowed_form() - CHECK USER ACCESS TO FORM
77  **/
78 
79 int
80 #if	defined(__STDC__)
81 is_user_allowed_form (
82 	char *			user,
83 	char *			form
84 )
85 #else
86 is_user_allowed_form (user, form)
87 	char			*user,
88 				*form;
89 #endif
90 {
91 	char			**allow,
92 				**deny;
93 
94 	if (loadaccess(Lp_A_Forms, form, "", &allow, &deny) == -1)
95 		return (-1);
96 
97 	return (is_user_allowed(user, allow, deny));
98 }
99 
100 /**
101  ** is_user_allowed_printer() - CHECK USER ACCESS TO PRINTER
102  **/
103 
104 int
105 #if	defined(__STDC__)
106 is_user_allowed_printer (
107 	char *			user,
108 	char *			printer
109 )
110 #else
111 is_user_allowed_printer (user, printer)
112 	char			*user,
113 				*printer;
114 #endif
115 {
116 	char			**allow,
117 				**deny;
118 
119 	if (loadaccess(Lp_A_Printers, printer, UACCESSPREFIX, &allow, &deny) == -1)
120 		return (-1);
121 
122 	return (is_user_allowed(user, allow, deny));
123 }
124 
125 /**
126  ** is_form_allowed_printer() - CHECK FORM USE ON PRINTER
127  **/
128 
129 int
130 #if	defined(__STDC__)
131 is_form_allowed_printer (
132 	char *			form,
133 	char *			printer
134 )
135 #else
136 is_form_allowed_printer (form, printer)
137 	char			*form,
138 				*printer;
139 #endif
140 {
141 	char			**allow,
142 				**deny;
143 
144 	if (loadaccess(Lp_A_Printers, printer, FACCESSPREFIX, &allow, &deny) == -1)
145 		return (-1);
146 
147 	return (allowed(form, allow, deny));
148 }
149 
150 /**
151  ** allowed() - GENERAL ROUTINE TO CHECK ALLOW/DENY LISTS
152  **/
153 
154 int
155 #if	defined(__STDC__)
156 allowed (
157 	char *			item,
158 	char **			allow,
159 	char **			deny
160 )
161 #else
162 allowed (item, allow, deny)
163 	char			*item,
164 				**allow,
165 				**deny;
166 #endif
167 {
168 	if (allow) {
169 		if (bang_searchlist(item, allow))
170 			return (1);
171 		else
172 			return (0);
173 	}
174 
175 	if (deny) {
176 		if (bang_searchlist(item, deny))
177 			return (0);
178 		else
179 			return (1);
180 	}
181 
182 	return (0);
183 }
184