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