8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / lp / lib / access / change.c
blob892586e5c34c5b87765ef9e20b9390860bd462ae
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.8 */
32 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
34 #include "errno.h"
35 #include "string.h"
36 #include "stdlib.h"
38 #include "lp.h"
39 #include "access.h"
41 static int chgaccess ( int , char ** , char * , char * , char * );
42 static char ** empty_list ( void );
44 /**
45 ** deny_user_form() - DENY USER ACCESS TO FORM
46 **/
48 int
49 deny_user_form(char **user_list, char *form)
51 return (chgaccess(0, user_list, form, Lp_A_Forms, ""));
54 /**
55 ** allow_user_form() - ALLOW USER ACCESS TO FORM
56 **/
58 int
59 allow_user_form(char **user_list, char *form)
61 return (chgaccess(1, user_list, form, Lp_A_Forms, ""));
64 /**
65 ** deny_user_printer() - DENY USER ACCESS TO PRINTER
66 **/
68 int
69 deny_user_printer(char **user_list, char *printer)
71 return (chgaccess(0, user_list, printer, Lp_A_Printers, UACCESSPREFIX));
74 /**
75 ** allow_user_printer() - ALLOW USER ACCESS TO PRINTER
76 **/
78 int
79 allow_user_printer(char **user_list, char *printer)
81 return (chgaccess(1, user_list, printer, Lp_A_Printers, UACCESSPREFIX));
84 /**
85 ** deny_form_printer() - DENY FORM USE ON PRINTER
86 **/
88 int
89 deny_form_printer(char **form_list, char *printer)
91 return (chgaccess(0, form_list, printer, Lp_A_Printers, FACCESSPREFIX));
94 /**
95 ** allow_form_printer() - ALLOW FORM USE ON PRINTER
96 **/
98 int
99 allow_form_printer(char **form_list, char *printer)
101 return (chgaccess(1, form_list, printer, Lp_A_Printers, FACCESSPREFIX));
105 ** remove_paper_from_printer() - DENY FORM USE ON PRINTER
109 remove_paper_from_printer(char **form_list, char *printer)
111 return (chgaccess(0, form_list, printer, Lp_A_Printers, PACCESSPREFIX));
115 ** add_paper_to_printer() - ALLOW FORM USE ON PRINTER
119 add_paper_to_printer(char **form_list, char *printer)
121 return (chgaccess(1, form_list, printer, Lp_A_Printers, PACCESSPREFIX));
125 ** chgaccess() - UPDATE ALLOW/DENY ACCESS OF ITEM TO RESOURCE
128 static int
129 chgaccess(int isallow, char **list, char *name, char *dir, char *prefix)
131 register char ***padd_list,
132 ***prem_list,
133 **pl;
135 char **allow_list,
136 **deny_list;
138 if (loadaccess(dir, name, prefix, &allow_list, &deny_list) == -1)
139 return (-1);
141 if (isallow) {
142 padd_list = &allow_list;
143 prem_list = &deny_list;
144 } else {
145 padd_list = &deny_list;
146 prem_list = &allow_list;
149 for (pl = list; *pl; pl++) {
152 * Do the ``all'' and ``none'' cases explicitly,
153 * so that we can clean up the lists nicely.
155 if (STREQU(*pl, NAME_NONE)) {
156 isallow = !isallow;
157 goto AllCase;
159 if (
160 STREQU(*pl, NAME_ALL)
161 || STREQU(*pl, NAME_ANY)
162 || STREQU(*pl, ALL_BANG_ALL)
164 AllCase:
165 freelist (allow_list);
166 freelist (deny_list);
167 if (isallow) {
168 allow_list = 0;
169 deny_list = empty_list();
170 } else {
171 allow_list = 0;
172 deny_list = 0;
174 break;
176 } else {
179 * For each regular item in the list,
180 * we add it to the ``add list'' and remove it
181 * from the ``remove list''. This is not
182 * efficient, especially if there are a lot of
183 * items in the caller's list; doing it the
184 * way we do, however, has the side effect
185 * of skipping duplicate names in the caller's
186 * list.
188 * Do a regular "addlist()"--the resulting
189 * list may have redundancies, but it will
190 * still be correct.
192 if (addlist(padd_list, *pl) == -1)
193 return (-1);
194 if (bang_dellist(prem_list, *pl) == -1)
195 return (-1);
201 return (dumpaccess(dir, name, prefix, &allow_list, &deny_list));
205 ** empty_list() - CREATE AN EMPTY LIST
208 static char **
209 empty_list(void)
211 register char **empty;
214 if (!(empty = (char **)Malloc(sizeof(char *)))) {
215 errno = ENOMEM;
216 return (0);
218 *empty = 0;
219 return (empty);