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