1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gate /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate #include "errno.h"
33*7c478bd9Sstevel@tonic-gate #include "string.h"
34*7c478bd9Sstevel@tonic-gate #include "stdlib.h"
35*7c478bd9Sstevel@tonic-gate
36*7c478bd9Sstevel@tonic-gate #include "lp.h"
37*7c478bd9Sstevel@tonic-gate #include "access.h"
38*7c478bd9Sstevel@tonic-gate
39*7c478bd9Sstevel@tonic-gate static int chgaccess ( int , char ** , char * , char * , char * );
40*7c478bd9Sstevel@tonic-gate static char ** empty_list ( void );
41*7c478bd9Sstevel@tonic-gate
42*7c478bd9Sstevel@tonic-gate /**
43*7c478bd9Sstevel@tonic-gate ** deny_user_form() - DENY USER ACCESS TO FORM
44*7c478bd9Sstevel@tonic-gate **/
45*7c478bd9Sstevel@tonic-gate
46*7c478bd9Sstevel@tonic-gate int
deny_user_form(char ** user_list,char * form)47*7c478bd9Sstevel@tonic-gate deny_user_form(char **user_list, char *form)
48*7c478bd9Sstevel@tonic-gate {
49*7c478bd9Sstevel@tonic-gate return (chgaccess(0, user_list, form, Lp_A_Forms, ""));
50*7c478bd9Sstevel@tonic-gate }
51*7c478bd9Sstevel@tonic-gate
52*7c478bd9Sstevel@tonic-gate /**
53*7c478bd9Sstevel@tonic-gate ** allow_user_form() - ALLOW USER ACCESS TO FORM
54*7c478bd9Sstevel@tonic-gate **/
55*7c478bd9Sstevel@tonic-gate
56*7c478bd9Sstevel@tonic-gate int
allow_user_form(char ** user_list,char * form)57*7c478bd9Sstevel@tonic-gate allow_user_form(char **user_list, char *form)
58*7c478bd9Sstevel@tonic-gate {
59*7c478bd9Sstevel@tonic-gate return (chgaccess(1, user_list, form, Lp_A_Forms, ""));
60*7c478bd9Sstevel@tonic-gate }
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gate /**
63*7c478bd9Sstevel@tonic-gate ** deny_user_printer() - DENY USER ACCESS TO PRINTER
64*7c478bd9Sstevel@tonic-gate **/
65*7c478bd9Sstevel@tonic-gate
66*7c478bd9Sstevel@tonic-gate int
deny_user_printer(char ** user_list,char * printer)67*7c478bd9Sstevel@tonic-gate deny_user_printer(char **user_list, char *printer)
68*7c478bd9Sstevel@tonic-gate {
69*7c478bd9Sstevel@tonic-gate return (chgaccess(0, user_list, printer, Lp_A_Printers, UACCESSPREFIX));
70*7c478bd9Sstevel@tonic-gate }
71*7c478bd9Sstevel@tonic-gate
72*7c478bd9Sstevel@tonic-gate /**
73*7c478bd9Sstevel@tonic-gate ** allow_user_printer() - ALLOW USER ACCESS TO PRINTER
74*7c478bd9Sstevel@tonic-gate **/
75*7c478bd9Sstevel@tonic-gate
76*7c478bd9Sstevel@tonic-gate int
allow_user_printer(char ** user_list,char * printer)77*7c478bd9Sstevel@tonic-gate allow_user_printer(char **user_list, char *printer)
78*7c478bd9Sstevel@tonic-gate {
79*7c478bd9Sstevel@tonic-gate return (chgaccess(1, user_list, printer, Lp_A_Printers, UACCESSPREFIX));
80*7c478bd9Sstevel@tonic-gate }
81*7c478bd9Sstevel@tonic-gate
82*7c478bd9Sstevel@tonic-gate /**
83*7c478bd9Sstevel@tonic-gate ** deny_form_printer() - DENY FORM USE ON PRINTER
84*7c478bd9Sstevel@tonic-gate **/
85*7c478bd9Sstevel@tonic-gate
86*7c478bd9Sstevel@tonic-gate int
deny_form_printer(char ** form_list,char * printer)87*7c478bd9Sstevel@tonic-gate deny_form_printer(char **form_list, char *printer)
88*7c478bd9Sstevel@tonic-gate {
89*7c478bd9Sstevel@tonic-gate return (chgaccess(0, form_list, printer, Lp_A_Printers, FACCESSPREFIX));
90*7c478bd9Sstevel@tonic-gate }
91*7c478bd9Sstevel@tonic-gate
92*7c478bd9Sstevel@tonic-gate /**
93*7c478bd9Sstevel@tonic-gate ** allow_form_printer() - ALLOW FORM USE ON PRINTER
94*7c478bd9Sstevel@tonic-gate **/
95*7c478bd9Sstevel@tonic-gate
96*7c478bd9Sstevel@tonic-gate int
allow_form_printer(char ** form_list,char * printer)97*7c478bd9Sstevel@tonic-gate allow_form_printer(char **form_list, char *printer)
98*7c478bd9Sstevel@tonic-gate {
99*7c478bd9Sstevel@tonic-gate return (chgaccess(1, form_list, printer, Lp_A_Printers, FACCESSPREFIX));
100*7c478bd9Sstevel@tonic-gate }
101*7c478bd9Sstevel@tonic-gate
102*7c478bd9Sstevel@tonic-gate /**
103*7c478bd9Sstevel@tonic-gate ** remove_paper_from_printer() - DENY FORM USE ON PRINTER
104*7c478bd9Sstevel@tonic-gate **/
105*7c478bd9Sstevel@tonic-gate
106*7c478bd9Sstevel@tonic-gate int
remove_paper_from_printer(char ** form_list,char * printer)107*7c478bd9Sstevel@tonic-gate remove_paper_from_printer(char **form_list, char *printer)
108*7c478bd9Sstevel@tonic-gate {
109*7c478bd9Sstevel@tonic-gate return (chgaccess(0, form_list, printer, Lp_A_Printers, PACCESSPREFIX));
110*7c478bd9Sstevel@tonic-gate }
111*7c478bd9Sstevel@tonic-gate
112*7c478bd9Sstevel@tonic-gate /**
113*7c478bd9Sstevel@tonic-gate ** add_paper_to_printer() - ALLOW FORM USE ON PRINTER
114*7c478bd9Sstevel@tonic-gate **/
115*7c478bd9Sstevel@tonic-gate
116*7c478bd9Sstevel@tonic-gate int
add_paper_to_printer(char ** form_list,char * printer)117*7c478bd9Sstevel@tonic-gate add_paper_to_printer(char **form_list, char *printer)
118*7c478bd9Sstevel@tonic-gate {
119*7c478bd9Sstevel@tonic-gate return (chgaccess(1, form_list, printer, Lp_A_Printers, PACCESSPREFIX));
120*7c478bd9Sstevel@tonic-gate }
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate /**
123*7c478bd9Sstevel@tonic-gate ** chgaccess() - UPDATE ALLOW/DENY ACCESS OF ITEM TO RESOURCE
124*7c478bd9Sstevel@tonic-gate **/
125*7c478bd9Sstevel@tonic-gate
126*7c478bd9Sstevel@tonic-gate static int
chgaccess(int isallow,char ** list,char * name,char * dir,char * prefix)127*7c478bd9Sstevel@tonic-gate chgaccess(int isallow, char **list, char *name, char *dir, char *prefix)
128*7c478bd9Sstevel@tonic-gate {
129*7c478bd9Sstevel@tonic-gate register char ***padd_list,
130*7c478bd9Sstevel@tonic-gate ***prem_list,
131*7c478bd9Sstevel@tonic-gate **pl;
132*7c478bd9Sstevel@tonic-gate
133*7c478bd9Sstevel@tonic-gate char **allow_list,
134*7c478bd9Sstevel@tonic-gate **deny_list;
135*7c478bd9Sstevel@tonic-gate
136*7c478bd9Sstevel@tonic-gate if (loadaccess(dir, name, prefix, &allow_list, &deny_list) == -1)
137*7c478bd9Sstevel@tonic-gate return (-1);
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gate if (isallow) {
140*7c478bd9Sstevel@tonic-gate padd_list = &allow_list;
141*7c478bd9Sstevel@tonic-gate prem_list = &deny_list;
142*7c478bd9Sstevel@tonic-gate } else {
143*7c478bd9Sstevel@tonic-gate padd_list = &deny_list;
144*7c478bd9Sstevel@tonic-gate prem_list = &allow_list;
145*7c478bd9Sstevel@tonic-gate }
146*7c478bd9Sstevel@tonic-gate
147*7c478bd9Sstevel@tonic-gate for (pl = list; *pl; pl++) {
148*7c478bd9Sstevel@tonic-gate
149*7c478bd9Sstevel@tonic-gate /*
150*7c478bd9Sstevel@tonic-gate * Do the ``all'' and ``none'' cases explicitly,
151*7c478bd9Sstevel@tonic-gate * so that we can clean up the lists nicely.
152*7c478bd9Sstevel@tonic-gate */
153*7c478bd9Sstevel@tonic-gate if (STREQU(*pl, NAME_NONE)) {
154*7c478bd9Sstevel@tonic-gate isallow = !isallow;
155*7c478bd9Sstevel@tonic-gate goto AllCase;
156*7c478bd9Sstevel@tonic-gate }
157*7c478bd9Sstevel@tonic-gate if (
158*7c478bd9Sstevel@tonic-gate STREQU(*pl, NAME_ALL)
159*7c478bd9Sstevel@tonic-gate || STREQU(*pl, NAME_ANY)
160*7c478bd9Sstevel@tonic-gate || STREQU(*pl, ALL_BANG_ALL)
161*7c478bd9Sstevel@tonic-gate ) {
162*7c478bd9Sstevel@tonic-gate AllCase:
163*7c478bd9Sstevel@tonic-gate freelist (allow_list);
164*7c478bd9Sstevel@tonic-gate freelist (deny_list);
165*7c478bd9Sstevel@tonic-gate if (isallow) {
166*7c478bd9Sstevel@tonic-gate allow_list = 0;
167*7c478bd9Sstevel@tonic-gate deny_list = empty_list();
168*7c478bd9Sstevel@tonic-gate } else {
169*7c478bd9Sstevel@tonic-gate allow_list = 0;
170*7c478bd9Sstevel@tonic-gate deny_list = 0;
171*7c478bd9Sstevel@tonic-gate }
172*7c478bd9Sstevel@tonic-gate break;
173*7c478bd9Sstevel@tonic-gate
174*7c478bd9Sstevel@tonic-gate } else {
175*7c478bd9Sstevel@tonic-gate
176*7c478bd9Sstevel@tonic-gate /*
177*7c478bd9Sstevel@tonic-gate * For each regular item in the list,
178*7c478bd9Sstevel@tonic-gate * we add it to the ``add list'' and remove it
179*7c478bd9Sstevel@tonic-gate * from the ``remove list''. This is not
180*7c478bd9Sstevel@tonic-gate * efficient, especially if there are a lot of
181*7c478bd9Sstevel@tonic-gate * items in the caller's list; doing it the
182*7c478bd9Sstevel@tonic-gate * way we do, however, has the side effect
183*7c478bd9Sstevel@tonic-gate * of skipping duplicate names in the caller's
184*7c478bd9Sstevel@tonic-gate * list.
185*7c478bd9Sstevel@tonic-gate *
186*7c478bd9Sstevel@tonic-gate * Do a regular "addlist()"--the resulting
187*7c478bd9Sstevel@tonic-gate * list may have redundancies, but it will
188*7c478bd9Sstevel@tonic-gate * still be correct.
189*7c478bd9Sstevel@tonic-gate */
190*7c478bd9Sstevel@tonic-gate if (addlist(padd_list, *pl) == -1)
191*7c478bd9Sstevel@tonic-gate return (-1);
192*7c478bd9Sstevel@tonic-gate if (bang_dellist(prem_list, *pl) == -1)
193*7c478bd9Sstevel@tonic-gate return (-1);
194*7c478bd9Sstevel@tonic-gate
195*7c478bd9Sstevel@tonic-gate }
196*7c478bd9Sstevel@tonic-gate
197*7c478bd9Sstevel@tonic-gate }
198*7c478bd9Sstevel@tonic-gate
199*7c478bd9Sstevel@tonic-gate return (dumpaccess(dir, name, prefix, &allow_list, &deny_list));
200*7c478bd9Sstevel@tonic-gate }
201*7c478bd9Sstevel@tonic-gate
202*7c478bd9Sstevel@tonic-gate /**
203*7c478bd9Sstevel@tonic-gate ** empty_list() - CREATE AN EMPTY LIST
204*7c478bd9Sstevel@tonic-gate **/
205*7c478bd9Sstevel@tonic-gate
206*7c478bd9Sstevel@tonic-gate static char **
empty_list(void)207*7c478bd9Sstevel@tonic-gate empty_list(void)
208*7c478bd9Sstevel@tonic-gate {
209*7c478bd9Sstevel@tonic-gate register char **empty;
210*7c478bd9Sstevel@tonic-gate
211*7c478bd9Sstevel@tonic-gate
212*7c478bd9Sstevel@tonic-gate if (!(empty = (char **)Malloc(sizeof(char *)))) {
213*7c478bd9Sstevel@tonic-gate errno = ENOMEM;
214*7c478bd9Sstevel@tonic-gate return (0);
215*7c478bd9Sstevel@tonic-gate }
216*7c478bd9Sstevel@tonic-gate *empty = 0;
217*7c478bd9Sstevel@tonic-gate return (empty);
218*7c478bd9Sstevel@tonic-gate }
219