17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*f928ce67Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 30*f928ce67Sceastha #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate /* lpusers [-q priority-level] -u (user-list | "") 337c478bd9Sstevel@tonic-gate lpusers -d priority-level 347c478bd9Sstevel@tonic-gate lpusers -l 357c478bd9Sstevel@tonic-gate */ 367c478bd9Sstevel@tonic-gate #include <errno.h> 377c478bd9Sstevel@tonic-gate #include <fcntl.h> 387c478bd9Sstevel@tonic-gate #include <stdio.h> 397c478bd9Sstevel@tonic-gate #include <sys/types.h> 407c478bd9Sstevel@tonic-gate #include <locale.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #include "lp.h" 437c478bd9Sstevel@tonic-gate #include "users.h" 447c478bd9Sstevel@tonic-gate #include "msgs.h" 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #define WHO_AM_I I_AM_LPUSERS 477c478bd9Sstevel@tonic-gate #include "oam.h" 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate char message[100], 507c478bd9Sstevel@tonic-gate reply[100]; 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate char *PRIORITY; 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate int add_user(), del_user(); 557c478bd9Sstevel@tonic-gate 56*f928ce67Sceastha int 57*f928ce67Sceastha main(int argc, char *argv[]) 587c478bd9Sstevel@tonic-gate { 597c478bd9Sstevel@tonic-gate int mtype, size, c, 607c478bd9Sstevel@tonic-gate list = FALSE, limit = -1, deflt = -1; 617c478bd9Sstevel@tonic-gate int fd; 627c478bd9Sstevel@tonic-gate char *userlist = 0, *user, **users, *p; 637c478bd9Sstevel@tonic-gate short status; 647c478bd9Sstevel@tonic-gate struct user_priority *ppri_tbl, *ld_priority_file(); 657c478bd9Sstevel@tonic-gate extern char *optarg; 667c478bd9Sstevel@tonic-gate extern int optind, opterr, optopt, errno; 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate setlocale(LC_ALL, ""); 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 717c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 727c478bd9Sstevel@tonic-gate #endif 737c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate if(argc == 1) { 777c478bd9Sstevel@tonic-gate usage: 787c478bd9Sstevel@tonic-gate (void) printf(gettext("usage: \n")); 797c478bd9Sstevel@tonic-gate (void) printf(gettext("(assign priority limit to users)\n")); 807c478bd9Sstevel@tonic-gate (void) printf(gettext("\tlpusers -q priority -u user-list\n")); 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate (void) printf(gettext( 837c478bd9Sstevel@tonic-gate "(assign default priority limit for balance of users)\n")); 847c478bd9Sstevel@tonic-gate (void) printf(gettext("\tlpusers -q priority\n")); 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate (void) printf(gettext("(put users back to default priority limit)\n")); 877c478bd9Sstevel@tonic-gate (void) printf(gettext("\tlpusers -u user-list\n")); 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate (void) printf(gettext("(assign default priority)\n")); 907c478bd9Sstevel@tonic-gate (void) printf(gettext("\tlpusers -d priority\n")); 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate (void) printf(gettext("(examine priority limits, defaults)\n")); 937c478bd9Sstevel@tonic-gate (void) printf(gettext("\tlpusers -l\n")); 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate exit(argc == 1); 967c478bd9Sstevel@tonic-gate } 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate opterr = 0; /* disable printing of errors by getopt */ 997c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "ld:q:u:")) != -1) 1007c478bd9Sstevel@tonic-gate switch(c) { 1017c478bd9Sstevel@tonic-gate case 'l': 1027c478bd9Sstevel@tonic-gate if (list) 1037c478bd9Sstevel@tonic-gate LP_ERRMSG1(WARNING, E_LP_2MANY, 'l'); 1047c478bd9Sstevel@tonic-gate list = TRUE; 1057c478bd9Sstevel@tonic-gate break; 1067c478bd9Sstevel@tonic-gate case 'd': 1077c478bd9Sstevel@tonic-gate if (deflt != -1) 1087c478bd9Sstevel@tonic-gate LP_ERRMSG1(WARNING, E_LP_2MANY, 'd'); 1097c478bd9Sstevel@tonic-gate deflt = (int)strtol(optarg,&p,10); 1107c478bd9Sstevel@tonic-gate if (*p || deflt<PRI_MIN || deflt>PRI_MAX) { 1117c478bd9Sstevel@tonic-gate LP_ERRMSG1(ERROR, E_LP_BADPRI, optarg); 1127c478bd9Sstevel@tonic-gate exit(1); 1137c478bd9Sstevel@tonic-gate } 1147c478bd9Sstevel@tonic-gate break; 1157c478bd9Sstevel@tonic-gate case 'q': 1167c478bd9Sstevel@tonic-gate if (limit != -1) 1177c478bd9Sstevel@tonic-gate LP_ERRMSG1(WARNING, E_LP_2MANY, 'q'); 1187c478bd9Sstevel@tonic-gate limit = (int)strtol(optarg,&p,10); 1197c478bd9Sstevel@tonic-gate if (*p || limit<PRI_MIN || limit>PRI_MAX) { 1207c478bd9Sstevel@tonic-gate LP_ERRMSG1(ERROR, E_LP_BADPRI, optarg); 1217c478bd9Sstevel@tonic-gate exit(1); 1227c478bd9Sstevel@tonic-gate } 1237c478bd9Sstevel@tonic-gate break; 1247c478bd9Sstevel@tonic-gate case 'u': 1257c478bd9Sstevel@tonic-gate if (userlist) 1267c478bd9Sstevel@tonic-gate LP_ERRMSG1(WARNING, E_LP_2MANY, 'u'); 1277c478bd9Sstevel@tonic-gate userlist = optarg; 1287c478bd9Sstevel@tonic-gate break; 1297c478bd9Sstevel@tonic-gate case '?': 1307c478bd9Sstevel@tonic-gate if (optopt == '?') goto usage; 1317c478bd9Sstevel@tonic-gate (p = "-X")[1] = optopt; 1327c478bd9Sstevel@tonic-gate if (strchr("ldqu", optopt)) 1337c478bd9Sstevel@tonic-gate LP_ERRMSG1(ERROR, E_LP_OPTARG, p); 1347c478bd9Sstevel@tonic-gate else 1357c478bd9Sstevel@tonic-gate LP_ERRMSG1(ERROR, E_LP_OPTION, p); 1367c478bd9Sstevel@tonic-gate exit(1); 1377c478bd9Sstevel@tonic-gate } 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate if (optind < argc) { 1407c478bd9Sstevel@tonic-gate LP_ERRMSG1(ERROR, E_LP_EXTRA, argv[optind]); 1417c478bd9Sstevel@tonic-gate exit(1); 1427c478bd9Sstevel@tonic-gate } 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate if (((list || deflt != -1) && (limit != -1 || userlist)) 1457c478bd9Sstevel@tonic-gate || (list && deflt != -1)) { 1467c478bd9Sstevel@tonic-gate LP_ERRMSG(ERROR, E_LP_OPTCOMB); 1477c478bd9Sstevel@tonic-gate /* invalid combination of options */ 1487c478bd9Sstevel@tonic-gate exit(1); 1497c478bd9Sstevel@tonic-gate } 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate PRIORITY = Lp_Users; 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate /* load existing priorities from file */ 1547c478bd9Sstevel@tonic-gate if (!(ppri_tbl = ld_priority_file(PRIORITY))) { 1557c478bd9Sstevel@tonic-gate switch (errno) { 1567c478bd9Sstevel@tonic-gate case EBADF: 1577c478bd9Sstevel@tonic-gate LP_ERRMSG1(ERROR, E_LPU_BADFORM, PRIORITY); 1587c478bd9Sstevel@tonic-gate break; 1597c478bd9Sstevel@tonic-gate default: 1607c478bd9Sstevel@tonic-gate LP_ERRMSG2(ERROR, E_LPU_BADFILE, PRIORITY, errno); 1617c478bd9Sstevel@tonic-gate } 1627c478bd9Sstevel@tonic-gate exit(1); 1637c478bd9Sstevel@tonic-gate } 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate if (list) { 1667c478bd9Sstevel@tonic-gate print_tbl(ppri_tbl); 1677c478bd9Sstevel@tonic-gate exit (0); 1687c478bd9Sstevel@tonic-gate } else { 1697c478bd9Sstevel@tonic-gate if (userlist) { 1707c478bd9Sstevel@tonic-gate users = getlist(userlist, " \t", ","); 1717c478bd9Sstevel@tonic-gate if (users) 1727c478bd9Sstevel@tonic-gate while (user = *users++) { 1737c478bd9Sstevel@tonic-gate if (del_user(ppri_tbl, user) && (limit == -1)) 1747c478bd9Sstevel@tonic-gate LP_ERRMSG1(WARNING, E_LPU_NOUSER, user); 1757c478bd9Sstevel@tonic-gate if (limit != -1) { 1767c478bd9Sstevel@tonic-gate if (add_user(ppri_tbl, user, limit)) 1777c478bd9Sstevel@tonic-gate LP_ERRMSG1(WARNING, E_LPU_BADU, user); 1787c478bd9Sstevel@tonic-gate } 1797c478bd9Sstevel@tonic-gate } 1807c478bd9Sstevel@tonic-gate } else if (deflt != -1) 1817c478bd9Sstevel@tonic-gate ppri_tbl->deflt = deflt; 1827c478bd9Sstevel@tonic-gate else 1837c478bd9Sstevel@tonic-gate ppri_tbl->deflt_limit = limit; 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate if ((fd = open_locked(PRIORITY, "w", LPU_MODE)) < 0) { 1867c478bd9Sstevel@tonic-gate LP_ERRMSG1(ERROR, E_LP_ACCESS, PRIORITY); 1877c478bd9Sstevel@tonic-gate exit(1); 1887c478bd9Sstevel@tonic-gate } 1897c478bd9Sstevel@tonic-gate output_tbl(fd, ppri_tbl); 1907c478bd9Sstevel@tonic-gate close(fd); 1917c478bd9Sstevel@tonic-gate } 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate if (mopen()) /* error on mopen == no spooler, exit quietly */ 1947c478bd9Sstevel@tonic-gate exit(0); 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate (void)putmessage (message, S_LOAD_USER_FILE); 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate if (msend(message)) 1997c478bd9Sstevel@tonic-gate goto Error; 2007c478bd9Sstevel@tonic-gate if (mrecv(reply, sizeof(reply)) == -1) 2017c478bd9Sstevel@tonic-gate goto Error; 2027c478bd9Sstevel@tonic-gate mtype = getmessage(reply, R_LOAD_USER_FILE, &status); 2037c478bd9Sstevel@tonic-gate if (mtype != R_LOAD_USER_FILE) { 2047c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_BADREPLY, mtype); 2057c478bd9Sstevel@tonic-gate goto NoError; 2067c478bd9Sstevel@tonic-gate } 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate if (status == 0) 2097c478bd9Sstevel@tonic-gate goto NoError; 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate Error: LP_ERRMSG (ERROR, E_LPU_NOLOAD); 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate NoError:(void)mclose (); 214*f928ce67Sceastha return (0); 2157c478bd9Sstevel@tonic-gate } 216