xref: /onnv-gate/usr/src/cmd/lp/lib/users/usermgmt.c (revision 320:7e1ecf3ab9be)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*320Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
30*320Sceastha #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate /* LINTLIBRARY */
330Sstevel@tonic-gate 
340Sstevel@tonic-gate # include	<stdio.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate # include	"lp.h"
370Sstevel@tonic-gate # include	"users.h"
380Sstevel@tonic-gate 
39*320Sceastha static int loaded = 0;
400Sstevel@tonic-gate static struct user_priority *ppri_tbl;
410Sstevel@tonic-gate struct user_priority *ld_priority_file();
420Sstevel@tonic-gate static USER usr;
430Sstevel@tonic-gate 
putuser(char * user,USER * pri_s)440Sstevel@tonic-gate int putuser ( char * user, USER * pri_s )
450Sstevel@tonic-gate {
460Sstevel@tonic-gate     int fd;
470Sstevel@tonic-gate 
480Sstevel@tonic-gate     if (!loaded)
490Sstevel@tonic-gate     {
500Sstevel@tonic-gate 	if (!(ppri_tbl = ld_priority_file(Lp_Users)))
510Sstevel@tonic-gate 	    return(-1);
520Sstevel@tonic-gate 	loaded = 1;
530Sstevel@tonic-gate     }
540Sstevel@tonic-gate 
550Sstevel@tonic-gate     if (!add_user(ppri_tbl, user, pri_s->priority_limit))
560Sstevel@tonic-gate     {
570Sstevel@tonic-gate 	return(-1);
580Sstevel@tonic-gate     }
590Sstevel@tonic-gate 
600Sstevel@tonic-gate     if ((fd = open_locked(Lp_Users, "w", LPU_MODE)) < 0)
610Sstevel@tonic-gate 	return(-1);
620Sstevel@tonic-gate     output_tbl(fd, ppri_tbl);
630Sstevel@tonic-gate     close(fd);
640Sstevel@tonic-gate     return(0);
650Sstevel@tonic-gate }
660Sstevel@tonic-gate 
getuser(char * user)670Sstevel@tonic-gate USER * getuser ( char * user )
680Sstevel@tonic-gate {
690Sstevel@tonic-gate     int limit;
700Sstevel@tonic-gate 
710Sstevel@tonic-gate     /* root and lp do not get a limit */
720Sstevel@tonic-gate     if (STREQU(user, "root") || STREQU(user, LPUSER))
730Sstevel@tonic-gate     {
740Sstevel@tonic-gate 	usr.priority_limit = 0;
750Sstevel@tonic-gate 	return(&usr);
760Sstevel@tonic-gate     }
770Sstevel@tonic-gate 
780Sstevel@tonic-gate     if (!loaded)
790Sstevel@tonic-gate     {
800Sstevel@tonic-gate 	if (!(ppri_tbl = ld_priority_file(Lp_Users)))
810Sstevel@tonic-gate 	    return((USER *)0);
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 	loaded = 1;
840Sstevel@tonic-gate     }
850Sstevel@tonic-gate 
860Sstevel@tonic-gate     for (limit = PRI_MIN; limit <= PRI_MAX; limit++)
870Sstevel@tonic-gate 	if (bang_searchlist(user, ppri_tbl->users[limit - PRI_MIN]))
880Sstevel@tonic-gate 	{
890Sstevel@tonic-gate 	    usr.priority_limit = limit;
900Sstevel@tonic-gate 	    return(&usr);
910Sstevel@tonic-gate 	}
920Sstevel@tonic-gate 
930Sstevel@tonic-gate     usr.priority_limit = ppri_tbl->deflt_limit;
940Sstevel@tonic-gate     return(&usr);
950Sstevel@tonic-gate }
960Sstevel@tonic-gate 
deluser(char * user)970Sstevel@tonic-gate int deluser ( char * user )
980Sstevel@tonic-gate {
990Sstevel@tonic-gate     int fd;
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate     if (!loaded)
1020Sstevel@tonic-gate     {
1030Sstevel@tonic-gate 	if (!(ppri_tbl = ld_priority_file(Lp_Users)))
1040Sstevel@tonic-gate 	    return(-1);
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	loaded = 1;
1070Sstevel@tonic-gate     }
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate     del_user(ppri_tbl, user);
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate     if ((fd = open_locked(Lp_Users, "w", LPU_MODE)) < 0)
1120Sstevel@tonic-gate 	return(-1);
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate     output_tbl(fd, ppri_tbl);
1150Sstevel@tonic-gate     close(fd);
1160Sstevel@tonic-gate     return(0);
1170Sstevel@tonic-gate }
1180Sstevel@tonic-gate 
getdfltpri(void)1190Sstevel@tonic-gate int getdfltpri ( void )
1200Sstevel@tonic-gate {
1210Sstevel@tonic-gate     if (!loaded)
1220Sstevel@tonic-gate     {
1230Sstevel@tonic-gate 	if (!(ppri_tbl = ld_priority_file(Lp_Users)))
1240Sstevel@tonic-gate 	    return(-1);
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate 	loaded = 1;
1270Sstevel@tonic-gate     }
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate     return (ppri_tbl->deflt);
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate void
trashusers(void)1330Sstevel@tonic-gate trashusers(void)
1340Sstevel@tonic-gate {
1350Sstevel@tonic-gate     int limit;
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate     if (loaded)
1380Sstevel@tonic-gate     {
1390Sstevel@tonic-gate 	if (ppri_tbl)
1400Sstevel@tonic-gate 	{
1410Sstevel@tonic-gate 	    for (limit = PRI_MIN; limit <= PRI_MAX; limit++)
1420Sstevel@tonic-gate 		freelist (ppri_tbl->users[limit - PRI_MIN]);
1430Sstevel@tonic-gate 	    ppri_tbl = 0;
1440Sstevel@tonic-gate 	}
1450Sstevel@tonic-gate 	loaded = 0;
1460Sstevel@tonic-gate     }
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate 
149