10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*1676Sjpk * Common Development and Distribution License (the "License").
6*1676Sjpk * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
220Sstevel@tonic-gate /* All Rights Reserved */
230Sstevel@tonic-gate
240Sstevel@tonic-gate
25*1676Sjpk #pragma ident "%Z%%M% %I% %E% SMI"
26*1676Sjpk
27*1676Sjpk /*
28*1676Sjpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
29*1676Sjpk * Use is subject to license terms.
30*1676Sjpk */
31*1676Sjpk
320Sstevel@tonic-gate /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
330Sstevel@tonic-gate
340Sstevel@tonic-gate #include "string.h"
350Sstevel@tonic-gate #include "unistd.h"
360Sstevel@tonic-gate
370Sstevel@tonic-gate #include "lp.h"
380Sstevel@tonic-gate #include "access.h"
39*1676Sjpk #include <pwd.h>
40*1676Sjpk #include <auth_attr.h>
41*1676Sjpk #include <auth_list.h>
42*1676Sjpk #include <tsol/label.h>
430Sstevel@tonic-gate
440Sstevel@tonic-gate /**
450Sstevel@tonic-gate ** is_user_admin() - CHECK IF CURRENT USER IS AN ADMINISTRATOR
460Sstevel@tonic-gate **/
470Sstevel@tonic-gate
480Sstevel@tonic-gate int
490Sstevel@tonic-gate #if defined(__STDC__)
is_user_admin(void)500Sstevel@tonic-gate is_user_admin (
510Sstevel@tonic-gate void
520Sstevel@tonic-gate )
530Sstevel@tonic-gate #else
540Sstevel@tonic-gate is_user_admin ()
550Sstevel@tonic-gate #endif
560Sstevel@tonic-gate {
57*1676Sjpk /* For a labeled system, tsol_check_admin_auth is called
58*1676Sjpk * instead of using Access.
59*1676Sjpk */
60*1676Sjpk if (is_system_labeled()) {
61*1676Sjpk /* Check that user has print admin authorization */
62*1676Sjpk return (tsol_check_admin_auth(getuid()));
63*1676Sjpk } else {
64*1676Sjpk return (Access(Lp_A, W_OK) == -1? 0 : 1);
65*1676Sjpk }
660Sstevel@tonic-gate }
670Sstevel@tonic-gate
680Sstevel@tonic-gate /**
690Sstevel@tonic-gate ** is_user_allowed() - CHECK USER ACCESS ACCORDING TO ALLOW/DENY LISTS
700Sstevel@tonic-gate **/
710Sstevel@tonic-gate
720Sstevel@tonic-gate int
730Sstevel@tonic-gate #if defined(__STDC__)
is_user_allowed(char * user,char ** allow,char ** deny)740Sstevel@tonic-gate is_user_allowed (
750Sstevel@tonic-gate char * user,
760Sstevel@tonic-gate char ** allow,
770Sstevel@tonic-gate char ** deny
780Sstevel@tonic-gate )
790Sstevel@tonic-gate #else
800Sstevel@tonic-gate is_user_allowed (user, allow, deny)
810Sstevel@tonic-gate char *user,
820Sstevel@tonic-gate **allow,
830Sstevel@tonic-gate **deny;
840Sstevel@tonic-gate #endif
850Sstevel@tonic-gate {
860Sstevel@tonic-gate if (bangequ(user, LOCAL_LPUSER) || bangequ(user, LOCAL_ROOTUSER))
870Sstevel@tonic-gate return (1);
880Sstevel@tonic-gate
890Sstevel@tonic-gate return (allowed(user, allow, deny));
900Sstevel@tonic-gate }
910Sstevel@tonic-gate
920Sstevel@tonic-gate /**
930Sstevel@tonic-gate ** is_user_allowed_form() - CHECK USER ACCESS TO FORM
940Sstevel@tonic-gate **/
950Sstevel@tonic-gate
960Sstevel@tonic-gate int
970Sstevel@tonic-gate #if defined(__STDC__)
is_user_allowed_form(char * user,char * form)980Sstevel@tonic-gate is_user_allowed_form (
990Sstevel@tonic-gate char * user,
1000Sstevel@tonic-gate char * form
1010Sstevel@tonic-gate )
1020Sstevel@tonic-gate #else
1030Sstevel@tonic-gate is_user_allowed_form (user, form)
1040Sstevel@tonic-gate char *user,
1050Sstevel@tonic-gate *form;
1060Sstevel@tonic-gate #endif
1070Sstevel@tonic-gate {
1080Sstevel@tonic-gate char **allow,
1090Sstevel@tonic-gate **deny;
1100Sstevel@tonic-gate
1110Sstevel@tonic-gate if (loadaccess(Lp_A_Forms, form, "", &allow, &deny) == -1)
1120Sstevel@tonic-gate return (-1);
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate return (is_user_allowed(user, allow, deny));
1150Sstevel@tonic-gate }
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate /**
1180Sstevel@tonic-gate ** is_user_allowed_printer() - CHECK USER ACCESS TO PRINTER
1190Sstevel@tonic-gate **/
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate int
1220Sstevel@tonic-gate #if defined(__STDC__)
is_user_allowed_printer(char * user,char * printer)1230Sstevel@tonic-gate is_user_allowed_printer (
1240Sstevel@tonic-gate char * user,
1250Sstevel@tonic-gate char * printer
1260Sstevel@tonic-gate )
1270Sstevel@tonic-gate #else
1280Sstevel@tonic-gate is_user_allowed_printer (user, printer)
1290Sstevel@tonic-gate char *user,
1300Sstevel@tonic-gate *printer;
1310Sstevel@tonic-gate #endif
1320Sstevel@tonic-gate {
1330Sstevel@tonic-gate char **allow,
1340Sstevel@tonic-gate **deny;
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate if (loadaccess(Lp_A_Printers, printer, UACCESSPREFIX, &allow, &deny) == -1)
1370Sstevel@tonic-gate return (-1);
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate return (is_user_allowed(user, allow, deny));
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate /**
1430Sstevel@tonic-gate ** is_form_allowed_printer() - CHECK FORM USE ON PRINTER
1440Sstevel@tonic-gate **/
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate int
1470Sstevel@tonic-gate #if defined(__STDC__)
is_form_allowed_printer(char * form,char * printer)1480Sstevel@tonic-gate is_form_allowed_printer (
1490Sstevel@tonic-gate char * form,
1500Sstevel@tonic-gate char * printer
1510Sstevel@tonic-gate )
1520Sstevel@tonic-gate #else
1530Sstevel@tonic-gate is_form_allowed_printer (form, printer)
1540Sstevel@tonic-gate char *form,
1550Sstevel@tonic-gate *printer;
1560Sstevel@tonic-gate #endif
1570Sstevel@tonic-gate {
1580Sstevel@tonic-gate char **allow,
1590Sstevel@tonic-gate **deny;
1600Sstevel@tonic-gate
1610Sstevel@tonic-gate if (loadaccess(Lp_A_Printers, printer, FACCESSPREFIX, &allow, &deny) == -1)
1620Sstevel@tonic-gate return (-1);
1630Sstevel@tonic-gate
1640Sstevel@tonic-gate return (allowed(form, allow, deny));
1650Sstevel@tonic-gate }
1660Sstevel@tonic-gate
1670Sstevel@tonic-gate /**
1680Sstevel@tonic-gate ** allowed() - GENERAL ROUTINE TO CHECK ALLOW/DENY LISTS
1690Sstevel@tonic-gate **/
1700Sstevel@tonic-gate
1710Sstevel@tonic-gate int
1720Sstevel@tonic-gate #if defined(__STDC__)
allowed(char * item,char ** allow,char ** deny)1730Sstevel@tonic-gate allowed (
1740Sstevel@tonic-gate char * item,
1750Sstevel@tonic-gate char ** allow,
1760Sstevel@tonic-gate char ** deny
1770Sstevel@tonic-gate )
1780Sstevel@tonic-gate #else
1790Sstevel@tonic-gate allowed (item, allow, deny)
1800Sstevel@tonic-gate char *item,
1810Sstevel@tonic-gate **allow,
1820Sstevel@tonic-gate **deny;
1830Sstevel@tonic-gate #endif
1840Sstevel@tonic-gate {
1850Sstevel@tonic-gate if (allow) {
1860Sstevel@tonic-gate if (bang_searchlist(item, allow))
1870Sstevel@tonic-gate return (1);
1880Sstevel@tonic-gate else
1890Sstevel@tonic-gate return (0);
1900Sstevel@tonic-gate }
1910Sstevel@tonic-gate
1920Sstevel@tonic-gate if (deny) {
1930Sstevel@tonic-gate if (bang_searchlist(item, deny))
1940Sstevel@tonic-gate return (0);
1950Sstevel@tonic-gate else
1960Sstevel@tonic-gate return (1);
1970Sstevel@tonic-gate }
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate return (0);
2000Sstevel@tonic-gate }
201*1676Sjpk
202*1676Sjpk /*
203*1676Sjpk * Check to see if the specified user has the administer the printing
204*1676Sjpk * system authorization.
205*1676Sjpk */
206*1676Sjpk int
tsol_check_admin_auth(uid_t uid)207*1676Sjpk tsol_check_admin_auth(uid_t uid)
208*1676Sjpk {
209*1676Sjpk struct passwd *p;
210*1676Sjpk char *name;
211*1676Sjpk
212*1676Sjpk p = getpwuid(uid);
213*1676Sjpk if (p != NULL && p->pw_name != NULL)
214*1676Sjpk name = p->pw_name;
215*1676Sjpk else
216*1676Sjpk name = "";
217*1676Sjpk
218*1676Sjpk return (chkauthattr(PRINT_ADMIN_AUTH, name));
219*1676Sjpk }
220