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 #include "stdio.h"
36 #include "ctype.h"
37 #include "errno.h"
38 #include "sys/types.h"
39 #include "sys/utsname.h"
40 #include "string.h"
41
42 #include "lp.h"
43 #include "msgs.h"
44 #include "access.h"
45 #include "class.h"
46 #include "printers.h"
47
48 #define WHO_AM_I I_AM_LPADMIN
49 #include "oam.h"
50
51 #include "lpadmin.h"
52
53 #include <locale.h>
54
55 extern void chkopts(),
56 chkopts2(),
57 chkopts3(),
58 exit();
59
60 int system_labeled = 0;
61
62 int scheduler_active = 0;
63
64 char *label = 0;
65
66 PRINTER *printer_pointer = 0;
67
68 static CLASS *class_pointer = 0;
69
70 PWHEEL *pwheel_pointer = 0;
71 char *Local_System = 0;
72
73 /**
74 ** main()
75 **/
76
77 int
main(int argc,char * argv[])78 main(int argc, char *argv[])
79 {
80 struct utsname un;
81
82 (void) setlocale (LC_ALL, "");
83
84 #if !defined(TEXT_DOMAIN)
85 #define TEXT_DOMAIN "SYS_TEST"
86 #endif
87 (void) textdomain(TEXT_DOMAIN);
88
89 if (!is_user_admin()) {
90 LP_ERRMSG (ERROR, E_LP_NOTADM);
91 done (1);
92 /*NOTREACHED*/
93 }
94
95 system_labeled = is_system_labeled();
96
97 uname(&un);
98 Local_System = strdup(un.nodename);
99
100 options (argc, argv); /* process command line options */
101
102 chkopts (); /* check for legality of options */
103
104 startup (); /* open path to Spooler */
105
106 if (d)
107 newdflt (d); /* -d */
108
109 else if (x) {
110
111 /* allow "any" or "all" to do all destinations */
112 if (STREQU(NAME_ALL, x) || STREQU(NAME_ANY, x)) {
113
114 /*
115 * Just deleting all the printers should get
116 * rid of all the classes, too, but removing
117 * the classes first should make things go a bit
118 * faster.
119 */
120
121 while ((class_pointer = getclass(NAME_ALL)))
122 rmdest (1, class_pointer->name);
123
124 if (errno != ENOENT) {
125 LP_ERRMSG1 (
126 ERROR,
127 E_ADM_GETCLASSES,
128 PERROR
129 );
130 done (1);
131 /*NOTREACHED*/
132 }
133
134 while ((printer_pointer = getprinter(NAME_ALL)))
135 rmdest (0, printer_pointer->name);
136
137 if (errno != ENOENT) {
138 LP_ERRMSG1 (
139 ERROR,
140 E_ADM_GETPRINTERS,
141 PERROR
142 );
143 done (1);
144 /*NOTREACHED*/
145 }
146
147 } else
148 rmdest (isclass(x), x);
149
150 } else if (!p && S) {
151 if (STREQU(*S, NAME_ALL) || STREQU(*S, NAME_ANY)) {
152 while ((pwheel_pointer = getpwheel(NAME_ALL))) {
153 *S = pwheel_pointer->name;
154 chkopts3 (0);
155 label = *S;
156 do_pwheel ();
157 }
158 } else {
159 label = 0;
160 do_pwheel ();
161 }
162
163 #if defined(J_OPTION)
164 } else if (j) {
165 do_fault (); /* -j */
166 #endif
167
168 } else {
169 /* allow "any" or "all" to do all printers */
170 if (STREQU(NAME_ALL, p) || STREQU(NAME_ANY, p)) {
171 int called=0;
172 while ((printer_pointer = getprinter(NAME_ALL)) != NULL) {
173 /*
174 * "chkopts2()" will clobber "s".
175 */
176 char * save_s = s;
177
178 called++;
179 p = printer_pointer->name;
180 chkopts2 (0);
181
182 if (s)
183 if (
184 A || a || e || F || H
185 || h || i || l || m || M
186 || o || U || v
187 || Q != -1 || W != -1
188 )
189 LP_ERRMSG1 (
190 WARNING,
191 E_ADM_SIGNORE,
192 p
193 );
194 label = p;
195 do_printer ();
196
197 s = save_s;
198 }
199 if (called == 0 )
200 LP_ERRMSG (ERROR, E_ADM_PLONELY);
201
202 if (errno != ENOENT) {
203 LP_ERRMSG2 (
204 ERROR,
205 E_LP_GETPRINTER,
206 NAME_ALL,
207 PERROR
208 );
209 done (1);
210 /*NOTREACHED*/
211 }
212 } else {
213 label = 0;
214 do_printer (); /* -p etc. */
215 }
216 }
217 done (0);
218 /*NOTREACHED*/
219 return (0);
220 }
221
222 /**
223 ** putp() - FAKE ROUTINES TO AVOID REAL ONES
224 **/
225
putp()226 int putp ()
227 {
228 return (0);
229 }
230