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 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.8 */ 32*7c478bd9Sstevel@tonic-gate /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */ 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #include "errno.h" 35*7c478bd9Sstevel@tonic-gate #include "string.h" 36*7c478bd9Sstevel@tonic-gate #include "stdlib.h" 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #include "lp.h" 39*7c478bd9Sstevel@tonic-gate #include "access.h" 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate static int chgaccess ( int , char ** , char * , char * , char * ); 42*7c478bd9Sstevel@tonic-gate static char ** empty_list ( void ); 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate /** 45*7c478bd9Sstevel@tonic-gate ** deny_user_form() - DENY USER ACCESS TO FORM 46*7c478bd9Sstevel@tonic-gate **/ 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate int 49*7c478bd9Sstevel@tonic-gate deny_user_form(char **user_list, char *form) 50*7c478bd9Sstevel@tonic-gate { 51*7c478bd9Sstevel@tonic-gate return (chgaccess(0, user_list, form, Lp_A_Forms, "")); 52*7c478bd9Sstevel@tonic-gate } 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate /** 55*7c478bd9Sstevel@tonic-gate ** allow_user_form() - ALLOW USER ACCESS TO FORM 56*7c478bd9Sstevel@tonic-gate **/ 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate int 59*7c478bd9Sstevel@tonic-gate allow_user_form(char **user_list, char *form) 60*7c478bd9Sstevel@tonic-gate { 61*7c478bd9Sstevel@tonic-gate return (chgaccess(1, user_list, form, Lp_A_Forms, "")); 62*7c478bd9Sstevel@tonic-gate } 63*7c478bd9Sstevel@tonic-gate 64*7c478bd9Sstevel@tonic-gate /** 65*7c478bd9Sstevel@tonic-gate ** deny_user_printer() - DENY USER ACCESS TO PRINTER 66*7c478bd9Sstevel@tonic-gate **/ 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate int 69*7c478bd9Sstevel@tonic-gate deny_user_printer(char **user_list, char *printer) 70*7c478bd9Sstevel@tonic-gate { 71*7c478bd9Sstevel@tonic-gate return (chgaccess(0, user_list, printer, Lp_A_Printers, UACCESSPREFIX)); 72*7c478bd9Sstevel@tonic-gate } 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate /** 75*7c478bd9Sstevel@tonic-gate ** allow_user_printer() - ALLOW USER ACCESS TO PRINTER 76*7c478bd9Sstevel@tonic-gate **/ 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate int 79*7c478bd9Sstevel@tonic-gate allow_user_printer(char **user_list, char *printer) 80*7c478bd9Sstevel@tonic-gate { 81*7c478bd9Sstevel@tonic-gate return (chgaccess(1, user_list, printer, Lp_A_Printers, UACCESSPREFIX)); 82*7c478bd9Sstevel@tonic-gate } 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate /** 85*7c478bd9Sstevel@tonic-gate ** deny_form_printer() - DENY FORM USE ON PRINTER 86*7c478bd9Sstevel@tonic-gate **/ 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate int 89*7c478bd9Sstevel@tonic-gate deny_form_printer(char **form_list, char *printer) 90*7c478bd9Sstevel@tonic-gate { 91*7c478bd9Sstevel@tonic-gate return (chgaccess(0, form_list, printer, Lp_A_Printers, FACCESSPREFIX)); 92*7c478bd9Sstevel@tonic-gate } 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate /** 95*7c478bd9Sstevel@tonic-gate ** allow_form_printer() - ALLOW FORM USE ON PRINTER 96*7c478bd9Sstevel@tonic-gate **/ 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate int 99*7c478bd9Sstevel@tonic-gate allow_form_printer(char **form_list, char *printer) 100*7c478bd9Sstevel@tonic-gate { 101*7c478bd9Sstevel@tonic-gate return (chgaccess(1, form_list, printer, Lp_A_Printers, FACCESSPREFIX)); 102*7c478bd9Sstevel@tonic-gate } 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate /** 105*7c478bd9Sstevel@tonic-gate ** remove_paper_from_printer() - DENY FORM USE ON PRINTER 106*7c478bd9Sstevel@tonic-gate **/ 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate int 109*7c478bd9Sstevel@tonic-gate remove_paper_from_printer(char **form_list, char *printer) 110*7c478bd9Sstevel@tonic-gate { 111*7c478bd9Sstevel@tonic-gate return (chgaccess(0, form_list, printer, Lp_A_Printers, PACCESSPREFIX)); 112*7c478bd9Sstevel@tonic-gate } 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate /** 115*7c478bd9Sstevel@tonic-gate ** add_paper_to_printer() - ALLOW FORM USE ON PRINTER 116*7c478bd9Sstevel@tonic-gate **/ 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate int 119*7c478bd9Sstevel@tonic-gate add_paper_to_printer(char **form_list, char *printer) 120*7c478bd9Sstevel@tonic-gate { 121*7c478bd9Sstevel@tonic-gate return (chgaccess(1, form_list, printer, Lp_A_Printers, PACCESSPREFIX)); 122*7c478bd9Sstevel@tonic-gate } 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate /** 125*7c478bd9Sstevel@tonic-gate ** chgaccess() - UPDATE ALLOW/DENY ACCESS OF ITEM TO RESOURCE 126*7c478bd9Sstevel@tonic-gate **/ 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate static int 129*7c478bd9Sstevel@tonic-gate chgaccess(int isallow, char **list, char *name, char *dir, char *prefix) 130*7c478bd9Sstevel@tonic-gate { 131*7c478bd9Sstevel@tonic-gate register char ***padd_list, 132*7c478bd9Sstevel@tonic-gate ***prem_list, 133*7c478bd9Sstevel@tonic-gate **pl; 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate char **allow_list, 136*7c478bd9Sstevel@tonic-gate **deny_list; 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate if (loadaccess(dir, name, prefix, &allow_list, &deny_list) == -1) 139*7c478bd9Sstevel@tonic-gate return (-1); 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate if (isallow) { 142*7c478bd9Sstevel@tonic-gate padd_list = &allow_list; 143*7c478bd9Sstevel@tonic-gate prem_list = &deny_list; 144*7c478bd9Sstevel@tonic-gate } else { 145*7c478bd9Sstevel@tonic-gate padd_list = &deny_list; 146*7c478bd9Sstevel@tonic-gate prem_list = &allow_list; 147*7c478bd9Sstevel@tonic-gate } 148*7c478bd9Sstevel@tonic-gate 149*7c478bd9Sstevel@tonic-gate for (pl = list; *pl; pl++) { 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate /* 152*7c478bd9Sstevel@tonic-gate * Do the ``all'' and ``none'' cases explicitly, 153*7c478bd9Sstevel@tonic-gate * so that we can clean up the lists nicely. 154*7c478bd9Sstevel@tonic-gate */ 155*7c478bd9Sstevel@tonic-gate if (STREQU(*pl, NAME_NONE)) { 156*7c478bd9Sstevel@tonic-gate isallow = !isallow; 157*7c478bd9Sstevel@tonic-gate goto AllCase; 158*7c478bd9Sstevel@tonic-gate } 159*7c478bd9Sstevel@tonic-gate if ( 160*7c478bd9Sstevel@tonic-gate STREQU(*pl, NAME_ALL) 161*7c478bd9Sstevel@tonic-gate || STREQU(*pl, NAME_ANY) 162*7c478bd9Sstevel@tonic-gate || STREQU(*pl, ALL_BANG_ALL) 163*7c478bd9Sstevel@tonic-gate ) { 164*7c478bd9Sstevel@tonic-gate AllCase: 165*7c478bd9Sstevel@tonic-gate freelist (allow_list); 166*7c478bd9Sstevel@tonic-gate freelist (deny_list); 167*7c478bd9Sstevel@tonic-gate if (isallow) { 168*7c478bd9Sstevel@tonic-gate allow_list = 0; 169*7c478bd9Sstevel@tonic-gate deny_list = empty_list(); 170*7c478bd9Sstevel@tonic-gate } else { 171*7c478bd9Sstevel@tonic-gate allow_list = 0; 172*7c478bd9Sstevel@tonic-gate deny_list = 0; 173*7c478bd9Sstevel@tonic-gate } 174*7c478bd9Sstevel@tonic-gate break; 175*7c478bd9Sstevel@tonic-gate 176*7c478bd9Sstevel@tonic-gate } else { 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate /* 179*7c478bd9Sstevel@tonic-gate * For each regular item in the list, 180*7c478bd9Sstevel@tonic-gate * we add it to the ``add list'' and remove it 181*7c478bd9Sstevel@tonic-gate * from the ``remove list''. This is not 182*7c478bd9Sstevel@tonic-gate * efficient, especially if there are a lot of 183*7c478bd9Sstevel@tonic-gate * items in the caller's list; doing it the 184*7c478bd9Sstevel@tonic-gate * way we do, however, has the side effect 185*7c478bd9Sstevel@tonic-gate * of skipping duplicate names in the caller's 186*7c478bd9Sstevel@tonic-gate * list. 187*7c478bd9Sstevel@tonic-gate * 188*7c478bd9Sstevel@tonic-gate * Do a regular "addlist()"--the resulting 189*7c478bd9Sstevel@tonic-gate * list may have redundancies, but it will 190*7c478bd9Sstevel@tonic-gate * still be correct. 191*7c478bd9Sstevel@tonic-gate */ 192*7c478bd9Sstevel@tonic-gate if (addlist(padd_list, *pl) == -1) 193*7c478bd9Sstevel@tonic-gate return (-1); 194*7c478bd9Sstevel@tonic-gate if (bang_dellist(prem_list, *pl) == -1) 195*7c478bd9Sstevel@tonic-gate return (-1); 196*7c478bd9Sstevel@tonic-gate 197*7c478bd9Sstevel@tonic-gate } 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate } 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate return (dumpaccess(dir, name, prefix, &allow_list, &deny_list)); 202*7c478bd9Sstevel@tonic-gate } 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate /** 205*7c478bd9Sstevel@tonic-gate ** empty_list() - CREATE AN EMPTY LIST 206*7c478bd9Sstevel@tonic-gate **/ 207*7c478bd9Sstevel@tonic-gate 208*7c478bd9Sstevel@tonic-gate static char ** 209*7c478bd9Sstevel@tonic-gate empty_list(void) 210*7c478bd9Sstevel@tonic-gate { 211*7c478bd9Sstevel@tonic-gate register char **empty; 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gate 214*7c478bd9Sstevel@tonic-gate if (!(empty = (char **)Malloc(sizeof(char *)))) { 215*7c478bd9Sstevel@tonic-gate errno = ENOMEM; 216*7c478bd9Sstevel@tonic-gate return (0); 217*7c478bd9Sstevel@tonic-gate } 218*7c478bd9Sstevel@tonic-gate *empty = 0; 219*7c478bd9Sstevel@tonic-gate return (empty); 220*7c478bd9Sstevel@tonic-gate } 221