xref: /illumos-gate/usr/src/cmd/lp/cmd/lpadmin/lpadmin.c (revision 55381082)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include "stdio.h"
34 #include "ctype.h"
35 #include "errno.h"
36 #include "sys/types.h"
37 #include "sys/utsname.h"
38 #include "string.h"
39 
40 #include "lp.h"
41 #include "msgs.h"
42 #include "access.h"
43 #include "class.h"
44 #include "printers.h"
45 
46 #define	WHO_AM_I	I_AM_LPADMIN
47 #include "oam.h"
48 
49 #include "lpadmin.h"
50 
51 #include <locale.h>
52 
53 extern void		chkopts(),
54 			chkopts2(),
55 			chkopts3(),
56 			exit();
57 
58 int			scheduler_active = 0;
59 
60 char			*label = 0;
61 
62 PRINTER			*printer_pointer = 0;
63 
64 static CLASS		*class_pointer = 0;
65 
66 PWHEEL			*pwheel_pointer	= 0;
67 char			*Local_System = 0;
68 
69 /**
70  ** main()
71  **/
72 
73 int
74 main(int argc, char *argv[])
75 {
76 	struct utsname	un;
77 
78 	(void) setlocale (LC_ALL, "");
79 
80 #if !defined(TEXT_DOMAIN)
81 #define TEXT_DOMAIN "SYS_TEST"
82 #endif
83 	(void) textdomain(TEXT_DOMAIN);
84 
85 	if (!is_user_admin()) {
86 		LP_ERRMSG (ERROR, E_LP_NOTADM);
87 		done (1);
88 		/*NOTREACHED*/
89 	}
90 
91 	uname(&un);
92 	Local_System = strdup(un.nodename);
93 
94 	options (argc, argv);	/* process command line options */
95 
96 	chkopts ();		/* check for legality of options */
97 
98 	startup ();		/* open path to Spooler */
99 
100 	if (d)
101 		newdflt (d);	/* -d */
102 
103 	else if (x) {
104 
105 		/* allow "any" or "all" to do all destinations */
106 		if (STREQU(NAME_ALL, x) || STREQU(NAME_ANY, x)) {
107 
108 			/*
109 			 * Just deleting all the printers should get
110 			 * rid of all the classes, too, but removing
111 			 * the classes first should make things go a bit
112 			 * faster.
113 			 */
114 
115 			while ((class_pointer = getclass(NAME_ALL)))
116 				rmdest (1, class_pointer->name);
117 
118 			if (errno != ENOENT) {
119 				LP_ERRMSG1 (
120 					ERROR,
121 					E_ADM_GETCLASSES,
122 					PERROR
123 				);
124 				done (1);
125 				/*NOTREACHED*/
126 			}
127 
128 			while ((printer_pointer = getprinter(NAME_ALL)))
129 				rmdest (0, printer_pointer->name);
130 
131 			if (errno != ENOENT) {
132 				LP_ERRMSG1 (
133 					ERROR,
134 					E_ADM_GETPRINTERS,
135 					PERROR
136 				);
137 				done (1);
138 				/*NOTREACHED*/
139 			}
140 
141 		} else
142 			rmdest (isclass(x), x);
143 
144 	} else if (!p && S) {
145 		if (STREQU(*S, NAME_ALL) || STREQU(*S, NAME_ANY)) {
146 			while ((pwheel_pointer = getpwheel(NAME_ALL))) {
147 				*S = pwheel_pointer->name;
148 				chkopts3 (0);
149 				label = *S;
150 				do_pwheel ();
151 			}
152 		} else {
153 			label = 0;
154 			do_pwheel ();
155 		}
156 
157 #if	defined(J_OPTION)
158 	} else if (j) {
159 		do_fault ();	/* -j */
160 #endif
161 
162 	} else {
163 		/* allow "any" or "all" to do all printers */
164 		if (STREQU(NAME_ALL, p) || STREQU(NAME_ANY, p)) {
165 			int called=0;
166 			while ((printer_pointer = getprinter(NAME_ALL)) != NULL) {
167 				/*
168 				 * "chkopts2()" will clobber "s".
169 				 */
170 				char *		save_s = s;
171 
172 				called++;
173 				p = printer_pointer->name;
174 				chkopts2 (0);
175 
176 				if (s)
177 					if (
178 						A || a || e || F || H
179 					     || h || i || l || m || M
180 					     || o || U || v
181 					     || Q != -1 || W != -1
182 					)
183 						LP_ERRMSG1 (
184 							WARNING,
185 							E_ADM_SIGNORE,
186 							p
187 						);
188 				label = p;
189 				do_printer ();
190 
191 				s = save_s;
192 			}
193 			if (called == 0 )
194 				LP_ERRMSG (ERROR, E_ADM_PLONELY);
195 
196 			if (errno != ENOENT) {
197 				LP_ERRMSG2 (
198 					ERROR,
199 					E_LP_GETPRINTER,
200 					NAME_ALL,
201 					PERROR
202 				);
203 				done (1);
204 				/*NOTREACHED*/
205 			}
206 		} else {
207 			label = 0;
208 			do_printer ();	/* -p etc. */
209 		}
210 	}
211 	done (0);
212 	/*NOTREACHED*/
213 	return (0);
214 }
215 
216 /**
217  ** putp() - FAKE ROUTINES TO AVOID REAL ONES
218  **/
219 
220 int			putp ()
221 {
222 	return (0);
223 }
224