xref: /onnv-gate/usr/src/cmd/print/lpset/lpset.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 1998-2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <stdio.h>
30*0Sstevel@tonic-gate #include <stdlib.h>
31*0Sstevel@tonic-gate #include <sys/types.h>
32*0Sstevel@tonic-gate #include <stdarg.h>
33*0Sstevel@tonic-gate #include <unistd.h>
34*0Sstevel@tonic-gate #include <limits.h>
35*0Sstevel@tonic-gate #include <string.h>
36*0Sstevel@tonic-gate #include <syslog.h>
37*0Sstevel@tonic-gate #include <errno.h>
38*0Sstevel@tonic-gate #include <locale.h>
39*0Sstevel@tonic-gate #ifndef SUNOS_4
40*0Sstevel@tonic-gate #include <libintl.h>
41*0Sstevel@tonic-gate #endif
42*0Sstevel@tonic-gate #include <pwd.h>
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate #include <print/ns.h>
45*0Sstevel@tonic-gate #include <print/misc.h>
46*0Sstevel@tonic-gate #include <print/list.h>
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate extern char *optarg;
49*0Sstevel@tonic-gate extern int optind, opterr, optopt;
50*0Sstevel@tonic-gate extern char *getenv(const char *);
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate static void _decode_ldapResult(int result, char *printerName);
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate static void
55*0Sstevel@tonic-gate Usage(char *name)
56*0Sstevel@tonic-gate {
57*0Sstevel@tonic-gate 	(void) fprintf(stderr,
58*0Sstevel@tonic-gate 		gettext("Usage: %s [-n files | nisplus | ldap] [-x] "
59*0Sstevel@tonic-gate 			"[-h ldaphost] [-D binddn] [-w passwd] "
60*0Sstevel@tonic-gate 			"[-a key=value] [-d key] (printer)\n"),
61*0Sstevel@tonic-gate 		name);
62*0Sstevel@tonic-gate 	exit(1);
63*0Sstevel@tonic-gate }
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate /*
67*0Sstevel@tonic-gate  *  main() calls the appropriate routine to parse the command line arguments
68*0Sstevel@tonic-gate  *	and then calls the local remove routine, followed by the remote remove
69*0Sstevel@tonic-gate  *	routine to remove jobs.
70*0Sstevel@tonic-gate  */
71*0Sstevel@tonic-gate int
72*0Sstevel@tonic-gate main(int ac, char *av[])
73*0Sstevel@tonic-gate {
74*0Sstevel@tonic-gate 	int result = 0;
75*0Sstevel@tonic-gate 	int delete_printer = 0;
76*0Sstevel@tonic-gate 	int c;
77*0Sstevel@tonic-gate 	char	*program = NULL,
78*0Sstevel@tonic-gate 		*printer = NULL,
79*0Sstevel@tonic-gate 		*host = NULL,
80*0Sstevel@tonic-gate 		*binddn = NULL,
81*0Sstevel@tonic-gate 		*passwd = NULL,
82*0Sstevel@tonic-gate 		*ins = NULL,
83*0Sstevel@tonic-gate 		*ons = "files";
84*0Sstevel@tonic-gate 	char	**changes = NULL;
85*0Sstevel@tonic-gate 	ns_cred_t	*cred = NULL;
86*0Sstevel@tonic-gate 	ns_printer_t 	*printer_obj = NULL;
87*0Sstevel@tonic-gate 
88*0Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate #if	!defined(TEXT_DOMAIN)
91*0Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"
92*0Sstevel@tonic-gate #endif
93*0Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
94*0Sstevel@tonic-gate 
95*0Sstevel@tonic-gate 	if ((program = strrchr(av[0], '/')) == NULL)
96*0Sstevel@tonic-gate 		program = av[0];
97*0Sstevel@tonic-gate 	else
98*0Sstevel@tonic-gate 		program++;
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate 	openlog(program, LOG_PID, LOG_LPR);
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate 	if (ac < 2)
103*0Sstevel@tonic-gate 		Usage(program);
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate 	while ((c = getopt(ac, av, "a:d:D:h:n:r:w:x")) != EOF)
106*0Sstevel@tonic-gate 		switch (c) {
107*0Sstevel@tonic-gate 		case 'd':
108*0Sstevel@tonic-gate 			if (strchr(optarg, '=') != NULL)
109*0Sstevel@tonic-gate 				Usage(program);
110*0Sstevel@tonic-gate 			/* FALLTHRU */
111*0Sstevel@tonic-gate 		case 'a':
112*0Sstevel@tonic-gate 			changes = (char **)list_append((void**)changes,
113*0Sstevel@tonic-gate 						(void *)strdup(optarg));
114*0Sstevel@tonic-gate 			break;
115*0Sstevel@tonic-gate 		case 'D':
116*0Sstevel@tonic-gate 			binddn = optarg;
117*0Sstevel@tonic-gate 			break;
118*0Sstevel@tonic-gate 		case 'h':
119*0Sstevel@tonic-gate 			host = optarg;
120*0Sstevel@tonic-gate 			break;
121*0Sstevel@tonic-gate 		case 'n':
122*0Sstevel@tonic-gate 			ons = optarg;
123*0Sstevel@tonic-gate 			break;
124*0Sstevel@tonic-gate 		case 'r':
125*0Sstevel@tonic-gate 			ins = optarg;
126*0Sstevel@tonic-gate 			break;
127*0Sstevel@tonic-gate 		case 'w':
128*0Sstevel@tonic-gate 			passwd = optarg;
129*0Sstevel@tonic-gate 			break;
130*0Sstevel@tonic-gate 		case 'x':
131*0Sstevel@tonic-gate 			delete_printer++;
132*0Sstevel@tonic-gate 			break;
133*0Sstevel@tonic-gate 		default:
134*0Sstevel@tonic-gate 			Usage(program);
135*0Sstevel@tonic-gate 		}
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate 	if (optind != ac-1)
138*0Sstevel@tonic-gate 		Usage(program);
139*0Sstevel@tonic-gate 
140*0Sstevel@tonic-gate 	/*
141*0Sstevel@tonic-gate 	 * Check required options have been given: [ -x | [ -a | -d ]]
142*0Sstevel@tonic-gate 	 */
143*0Sstevel@tonic-gate 	if ((changes == NULL) && (delete_printer == 0)) {
144*0Sstevel@tonic-gate 		Usage(program);
145*0Sstevel@tonic-gate 	}
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate 	printer = av[optind];
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate 	if (strchr(printer, ':') != NULL) {
150*0Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(
151*0Sstevel@tonic-gate 			"POSIX-Style names are not valid destinations (%s)\n"),
152*0Sstevel@tonic-gate 			printer);
153*0Sstevel@tonic-gate 		return (1);
154*0Sstevel@tonic-gate 	}
155*0Sstevel@tonic-gate 
156*0Sstevel@tonic-gate 	ins = normalize_ns_name(ins);
157*0Sstevel@tonic-gate 	ons = normalize_ns_name(ons);
158*0Sstevel@tonic-gate 	if (ins == NULL)
159*0Sstevel@tonic-gate 		ins = ons;
160*0Sstevel@tonic-gate 
161*0Sstevel@tonic-gate 	/* check / set the name service for writing */
162*0Sstevel@tonic-gate 	if (strcasecmp("user", ons) == 0) {
163*0Sstevel@tonic-gate 		(void) setuid(getuid());
164*0Sstevel@tonic-gate 		ons = "user";
165*0Sstevel@tonic-gate 	} else if (strcasecmp("files", ons) == 0) {
166*0Sstevel@tonic-gate 		struct passwd *pw = getpwnam("lp");
167*0Sstevel@tonic-gate 		uid_t uid, lpuid = 0;
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate 		if (pw != NULL)
170*0Sstevel@tonic-gate 			lpuid = pw->pw_uid;
171*0Sstevel@tonic-gate 		uid = getuid();
172*0Sstevel@tonic-gate 		if ((uid != 0) && (uid != lpuid)) {
173*0Sstevel@tonic-gate 			int len;
174*0Sstevel@tonic-gate 			gid_t list[NGROUPS_MAX];
175*0Sstevel@tonic-gate 
176*0Sstevel@tonic-gate 			len = getgroups(sizeof (list), list);
177*0Sstevel@tonic-gate 			if (len == -1) {
178*0Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
179*0Sstevel@tonic-gate 					"Call to getgroups failed with "
180*0Sstevel@tonic-gate 					"errno %d\n"), errno);
181*0Sstevel@tonic-gate 				return (1);
182*0Sstevel@tonic-gate 			}
183*0Sstevel@tonic-gate 
184*0Sstevel@tonic-gate 			for (; len >= 0; len--)
185*0Sstevel@tonic-gate 				if (list[len] == 14)
186*0Sstevel@tonic-gate 					break;
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate 			if (len == -1) {
189*0Sstevel@tonic-gate 				(void) fprintf(stderr, gettext(
190*0Sstevel@tonic-gate 				    "Permission denied: not in group 14\n"));
191*0Sstevel@tonic-gate 				return (1);
192*0Sstevel@tonic-gate 			}
193*0Sstevel@tonic-gate 		}
194*0Sstevel@tonic-gate 		ons = "files";
195*0Sstevel@tonic-gate 	} else if (strcasecmp("nisplus", ons) == 0) {
196*0Sstevel@tonic-gate 		ons = "nisplus";
197*0Sstevel@tonic-gate 	} else if (strcasecmp("ldap", ons) == 0) {
198*0Sstevel@tonic-gate 		if ((cred = calloc(1, sizeof (*cred))) == NULL) {
199*0Sstevel@tonic-gate 			(void) fprintf(stderr,
200*0Sstevel@tonic-gate 				gettext("could not initialize credential\n"));
201*0Sstevel@tonic-gate 			return (1);
202*0Sstevel@tonic-gate 		}
203*0Sstevel@tonic-gate 
204*0Sstevel@tonic-gate 		if (binddn == NULL) {
205*0Sstevel@tonic-gate 			(void) fprintf(stderr,
206*0Sstevel@tonic-gate 			    gettext("Distinguished Name is required.\n"));
207*0Sstevel@tonic-gate 			return (1);
208*0Sstevel@tonic-gate 		}
209*0Sstevel@tonic-gate 
210*0Sstevel@tonic-gate 		if (passwd == NULL) {
211*0Sstevel@tonic-gate 			passwd = getpassphrase(gettext("Bind Password:"));
212*0Sstevel@tonic-gate 		}
213*0Sstevel@tonic-gate 
214*0Sstevel@tonic-gate 		/*
215*0Sstevel@tonic-gate 		 * Setup LDAP bind credentials, so that it uses
216*0Sstevel@tonic-gate 		 * the default ldap port, and the NS domain for this
217*0Sstevel@tonic-gate 		 * ldapclient box. Note: passwdType is currently not
218*0Sstevel@tonic-gate 		 * used but once the ldap native function can select
219*0Sstevel@tonic-gate 		 * secure or insure password it will pass the user selected
220*0Sstevel@tonic-gate 		 * security type.
221*0Sstevel@tonic-gate 		 */
222*0Sstevel@tonic-gate 		cred->passwd = passwd;
223*0Sstevel@tonic-gate 		cred->passwdType = NS_PW_INSECURE; /* use default */
224*0Sstevel@tonic-gate 		cred->binddn = binddn;
225*0Sstevel@tonic-gate 		cred->host = host;
226*0Sstevel@tonic-gate 		cred->port = 0;		/* use default */
227*0Sstevel@tonic-gate 		cred->domainDN = NULL;	/* use default */
228*0Sstevel@tonic-gate 
229*0Sstevel@tonic-gate 		ons = "ldap";
230*0Sstevel@tonic-gate 		(void) setuid(getuid());
231*0Sstevel@tonic-gate 	} else {
232*0Sstevel@tonic-gate 		(void) fprintf(stderr,
233*0Sstevel@tonic-gate 			gettext("%s is not a supported name service.\n"),
234*0Sstevel@tonic-gate 			ons);
235*0Sstevel@tonic-gate 		return (1);
236*0Sstevel@tonic-gate 	}
237*0Sstevel@tonic-gate 
238*0Sstevel@tonic-gate 	if (strcasecmp(NS_SVC_LDAP, ons) != 0) {
239*0Sstevel@tonic-gate 
240*0Sstevel@tonic-gate 	    /* Naming Service is not LDAP */
241*0Sstevel@tonic-gate 
242*0Sstevel@tonic-gate 	    /* get the printer object */
243*0Sstevel@tonic-gate 	    if ((printer_obj = ns_printer_get_name(printer, ins)) == NULL) {
244*0Sstevel@tonic-gate 		if (delete_printer != 0) {
245*0Sstevel@tonic-gate 			(void) fprintf(stderr, gettext("%s: unknown printer\n"),
246*0Sstevel@tonic-gate 				printer);
247*0Sstevel@tonic-gate 			return (1);
248*0Sstevel@tonic-gate 		}
249*0Sstevel@tonic-gate 		if ((printer_obj = calloc(1, sizeof (*printer_obj))) == NULL) {
250*0Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
251*0Sstevel@tonic-gate 				"could not initialize printer object\n"));
252*0Sstevel@tonic-gate 			return (1);
253*0Sstevel@tonic-gate 		}
254*0Sstevel@tonic-gate 		printer_obj->name = strdup(printer);
255*0Sstevel@tonic-gate 	    }
256*0Sstevel@tonic-gate 
257*0Sstevel@tonic-gate 	    printer_obj->source = ons;
258*0Sstevel@tonic-gate 
259*0Sstevel@tonic-gate 	    if (cred != NULL) {
260*0Sstevel@tonic-gate 		printer_obj->cred = cred;
261*0Sstevel@tonic-gate 	    }
262*0Sstevel@tonic-gate 
263*0Sstevel@tonic-gate 	    /* make the changes to it */
264*0Sstevel@tonic-gate 	    while (changes != NULL && *changes != NULL) {
265*0Sstevel@tonic-gate 		int has_equals = (strchr(*changes, '=') != NULL);
266*0Sstevel@tonic-gate 		char *p, *key = NULL, *value = NULL;
267*0Sstevel@tonic-gate 
268*0Sstevel@tonic-gate 		key = *(changes++);
269*0Sstevel@tonic-gate 
270*0Sstevel@tonic-gate 		for (p = key; ((p != NULL) && (*p != NULL)); p++)
271*0Sstevel@tonic-gate 			if (*p == '=') {
272*0Sstevel@tonic-gate 				*p = NULL;
273*0Sstevel@tonic-gate 				value = ++p;
274*0Sstevel@tonic-gate 				break;
275*0Sstevel@tonic-gate 			} else if (*p == '\\')
276*0Sstevel@tonic-gate 				p++;
277*0Sstevel@tonic-gate 
278*0Sstevel@tonic-gate 		if ((value != NULL) && (*value == NULL))
279*0Sstevel@tonic-gate 			value = NULL;
280*0Sstevel@tonic-gate 
281*0Sstevel@tonic-gate 		if ((key != NULL) && (key[0] != NULL)) {
282*0Sstevel@tonic-gate 			if ((value == NULL) &&
283*0Sstevel@tonic-gate 			    (ns_get_value(key, printer_obj) == NULL) &&
284*0Sstevel@tonic-gate 			    (has_equals == 0)) {
285*0Sstevel@tonic-gate 				fprintf(stderr,
286*0Sstevel@tonic-gate 					gettext("%s: unknown attribute\n"),
287*0Sstevel@tonic-gate 					key);
288*0Sstevel@tonic-gate 				result = 1;
289*0Sstevel@tonic-gate 			} else
290*0Sstevel@tonic-gate 			(void) ns_set_value_from_string(key, value,
291*0Sstevel@tonic-gate 				printer_obj);
292*0Sstevel@tonic-gate 		}
293*0Sstevel@tonic-gate 	    }
294*0Sstevel@tonic-gate 	    if (delete_printer != 0)
295*0Sstevel@tonic-gate 		printer_obj->attributes = NULL;
296*0Sstevel@tonic-gate 
297*0Sstevel@tonic-gate 	    /* write it back */
298*0Sstevel@tonic-gate 	    if (ns_printer_put(printer_obj) != 0) {
299*0Sstevel@tonic-gate 		(void) fprintf(stderr,
300*0Sstevel@tonic-gate 				gettext("Failed to write into %s database\n"),
301*0Sstevel@tonic-gate 				ons);
302*0Sstevel@tonic-gate 		result = 1;
303*0Sstevel@tonic-gate 	    }
304*0Sstevel@tonic-gate 	}
305*0Sstevel@tonic-gate 
306*0Sstevel@tonic-gate 	else {
307*0Sstevel@tonic-gate 		/*
308*0Sstevel@tonic-gate 		 * Naming Service is LDAP
309*0Sstevel@tonic-gate 		 *
310*0Sstevel@tonic-gate 		 * Action the request by calling ns ldap functions to
311*0Sstevel@tonic-gate 		 * add, modify or delete the printer object.
312*0Sstevel@tonic-gate 		 */
313*0Sstevel@tonic-gate 
314*0Sstevel@tonic-gate 		if ((printer_obj = calloc(1, sizeof (*printer_obj))) == NULL) {
315*0Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
316*0Sstevel@tonic-gate 				"could not initialize printer object\n"));
317*0Sstevel@tonic-gate 			return (1);
318*0Sstevel@tonic-gate 		}
319*0Sstevel@tonic-gate 
320*0Sstevel@tonic-gate 		if ((cred != NULL) && (printer_obj != NULL)) {
321*0Sstevel@tonic-gate 			printer_obj->name = strdup(printer);
322*0Sstevel@tonic-gate 			printer_obj->cred = cred;
323*0Sstevel@tonic-gate 			printer_obj->cred->domainDN = NULL; /* use default */
324*0Sstevel@tonic-gate 			printer_obj->source = ons;
325*0Sstevel@tonic-gate 			printer_obj->nsdata = malloc(sizeof (NS_LDAPDATA));
326*0Sstevel@tonic-gate 
327*0Sstevel@tonic-gate 			if (printer_obj->nsdata != NULL) {
328*0Sstevel@tonic-gate 				/*
329*0Sstevel@tonic-gate 				 * Update the LDAP directory for this printer
330*0Sstevel@tonic-gate 				 */
331*0Sstevel@tonic-gate 
332*0Sstevel@tonic-gate 				if (delete_printer != 0) {
333*0Sstevel@tonic-gate 					/* Delete the printer object */
334*0Sstevel@tonic-gate 					((NS_LDAPDATA *)
335*0Sstevel@tonic-gate 					(printer_obj->nsdata))->attrList = NULL;
336*0Sstevel@tonic-gate 				} else {
337*0Sstevel@tonic-gate 					/* Add or modify the printer object */
338*0Sstevel@tonic-gate 					((NS_LDAPDATA *)
339*0Sstevel@tonic-gate 					(printer_obj->nsdata))->attrList =
340*0Sstevel@tonic-gate 									changes;
341*0Sstevel@tonic-gate 				}
342*0Sstevel@tonic-gate 
343*0Sstevel@tonic-gate 				result = ns_printer_put(printer_obj);
344*0Sstevel@tonic-gate 				if (result != 0) {
345*0Sstevel@tonic-gate 					/* display LDAP specific message */
346*0Sstevel@tonic-gate 					_decode_ldapResult(result, printer);
347*0Sstevel@tonic-gate 
348*0Sstevel@tonic-gate 					(void) fprintf(stderr, gettext(
349*0Sstevel@tonic-gate 					"Failed to update %s database\n"), ons);
350*0Sstevel@tonic-gate 					result = 1;
351*0Sstevel@tonic-gate 				}
352*0Sstevel@tonic-gate 
353*0Sstevel@tonic-gate 				free(printer_obj->nsdata);
354*0Sstevel@tonic-gate 			}
355*0Sstevel@tonic-gate 
356*0Sstevel@tonic-gate 			else {
357*0Sstevel@tonic-gate 				_decode_ldapResult(NSL_ERR_MEMORY, NULL);
358*0Sstevel@tonic-gate 				result = 1;
359*0Sstevel@tonic-gate 			}
360*0Sstevel@tonic-gate 		}
361*0Sstevel@tonic-gate 
362*0Sstevel@tonic-gate 		else {
363*0Sstevel@tonic-gate 			result = 1;
364*0Sstevel@tonic-gate 			(void) fprintf(stderr,
365*0Sstevel@tonic-gate 				gettext("Error - no LDAP credentials\n"));
366*0Sstevel@tonic-gate 		}
367*0Sstevel@tonic-gate 
368*0Sstevel@tonic-gate 		if (printer_obj != NULL) {
369*0Sstevel@tonic-gate 			if (printer_obj->name != NULL) {
370*0Sstevel@tonic-gate 				free(printer_obj->name);
371*0Sstevel@tonic-gate 			}
372*0Sstevel@tonic-gate 			free(printer_obj);
373*0Sstevel@tonic-gate 		}
374*0Sstevel@tonic-gate 
375*0Sstevel@tonic-gate 	}
376*0Sstevel@tonic-gate 
377*0Sstevel@tonic-gate 	return (result);
378*0Sstevel@tonic-gate } /* main */
379*0Sstevel@tonic-gate 
380*0Sstevel@tonic-gate 
381*0Sstevel@tonic-gate 
382*0Sstevel@tonic-gate 
383*0Sstevel@tonic-gate /*
384*0Sstevel@tonic-gate  * *****************************************************************************
385*0Sstevel@tonic-gate  *
386*0Sstevel@tonic-gate  * Function:    _decode_ldapResult()
387*0Sstevel@tonic-gate  *
388*0Sstevel@tonic-gate  * Description: Decode the ldap_put_printer specific error codes and display
389*0Sstevel@tonic-gate  *              the appropriate error message.
390*0Sstevel@tonic-gate  *
391*0Sstevel@tonic-gate  * Parameters:
392*0Sstevel@tonic-gate  * Input:       int result - contains the NSL_RESULT codes
393*0Sstevel@tonic-gate  *              char *printerName - name of printer
394*0Sstevel@tonic-gate  * Output:      None
395*0Sstevel@tonic-gate  *
396*0Sstevel@tonic-gate  * Returns:     void
397*0Sstevel@tonic-gate  *
398*0Sstevel@tonic-gate  * *****************************************************************************
399*0Sstevel@tonic-gate  */
400*0Sstevel@tonic-gate 
401*0Sstevel@tonic-gate static void
402*0Sstevel@tonic-gate _decode_ldapResult(int result, char *printerName)
403*0Sstevel@tonic-gate 
404*0Sstevel@tonic-gate {
405*0Sstevel@tonic-gate 	NSL_RESULT lresult = (NSL_RESULT)result;
406*0Sstevel@tonic-gate 
407*0Sstevel@tonic-gate 	/* ------------- */
408*0Sstevel@tonic-gate 
409*0Sstevel@tonic-gate 	switch (lresult)
410*0Sstevel@tonic-gate 	{
411*0Sstevel@tonic-gate 		case NSL_OK:
412*0Sstevel@tonic-gate 		{
413*0Sstevel@tonic-gate 			break;
414*0Sstevel@tonic-gate 		}
415*0Sstevel@tonic-gate 
416*0Sstevel@tonic-gate 		case NSL_ERR_INTERNAL:
417*0Sstevel@tonic-gate 		{
418*0Sstevel@tonic-gate 			(void) fprintf(stderr,
419*0Sstevel@tonic-gate 				gettext("Unexpected software error\n"));
420*0Sstevel@tonic-gate 			break;
421*0Sstevel@tonic-gate 		}
422*0Sstevel@tonic-gate 
423*0Sstevel@tonic-gate 		case NSL_ERR_ADD_FAILED:
424*0Sstevel@tonic-gate 		{
425*0Sstevel@tonic-gate 			(void) fprintf(stderr, "%s %s\n",
426*0Sstevel@tonic-gate 				gettext("Failed to add printer:"), printerName);
427*0Sstevel@tonic-gate 			break;
428*0Sstevel@tonic-gate 		}
429*0Sstevel@tonic-gate 
430*0Sstevel@tonic-gate 		case NSL_ERR_MOD_FAILED:
431*0Sstevel@tonic-gate 		{
432*0Sstevel@tonic-gate 			(void) fprintf(stderr, "%s %s\n",
433*0Sstevel@tonic-gate 				gettext("Failed to modify printer:"),
434*0Sstevel@tonic-gate 					printerName);
435*0Sstevel@tonic-gate 			break;
436*0Sstevel@tonic-gate 		}
437*0Sstevel@tonic-gate 
438*0Sstevel@tonic-gate 		case NSL_ERR_DEL_FAILED:
439*0Sstevel@tonic-gate 		{
440*0Sstevel@tonic-gate 			(void) fprintf(stderr, "%s %s\n",
441*0Sstevel@tonic-gate 				gettext("Failed to delete printer:"),
442*0Sstevel@tonic-gate 					printerName);
443*0Sstevel@tonic-gate 			break;
444*0Sstevel@tonic-gate 		}
445*0Sstevel@tonic-gate 
446*0Sstevel@tonic-gate 
447*0Sstevel@tonic-gate 		case NSL_ERR_UNKNOWN_PRINTER:
448*0Sstevel@tonic-gate 		{
449*0Sstevel@tonic-gate 			(void) fprintf(stderr, "%s %s\n",
450*0Sstevel@tonic-gate 				gettext("Unknown printer:"), printerName);
451*0Sstevel@tonic-gate 			break;
452*0Sstevel@tonic-gate 		}
453*0Sstevel@tonic-gate 
454*0Sstevel@tonic-gate 		case NSL_ERR_CREDENTIALS:
455*0Sstevel@tonic-gate 		{
456*0Sstevel@tonic-gate 			(void) fprintf(stderr, "%s\n",
457*0Sstevel@tonic-gate 		gettext("Missing LDAP credential information for printer:"));
458*0Sstevel@tonic-gate 			break;
459*0Sstevel@tonic-gate 		}
460*0Sstevel@tonic-gate 
461*0Sstevel@tonic-gate 		case NSL_ERR_CONNECT:
462*0Sstevel@tonic-gate 		{
463*0Sstevel@tonic-gate 			(void) fprintf(stderr, "%s\n",
464*0Sstevel@tonic-gate 				gettext("Failed to connect to LDAP server"));
465*0Sstevel@tonic-gate 			break;
466*0Sstevel@tonic-gate 		}
467*0Sstevel@tonic-gate 
468*0Sstevel@tonic-gate 		case NSL_ERR_BIND:
469*0Sstevel@tonic-gate 		{
470*0Sstevel@tonic-gate 			(void) fprintf(stderr, gettext("LDAP bind failed\n"));
471*0Sstevel@tonic-gate 			break;
472*0Sstevel@tonic-gate 		}
473*0Sstevel@tonic-gate 
474*0Sstevel@tonic-gate 		case NSL_ERR_RENAME:
475*0Sstevel@tonic-gate 		{
476*0Sstevel@tonic-gate 			(void) fprintf(stderr, "%s %s\n",
477*0Sstevel@tonic-gate 			    gettext("Object rename not allowed for printer:"),
478*0Sstevel@tonic-gate 			    printerName);
479*0Sstevel@tonic-gate 			break;
480*0Sstevel@tonic-gate 		}
481*0Sstevel@tonic-gate 
482*0Sstevel@tonic-gate 		case NSL_ERR_KVP:
483*0Sstevel@tonic-gate 		{
484*0Sstevel@tonic-gate 			(void) fprintf(stderr, "%s",
485*0Sstevel@tonic-gate 			    gettext("Setting sun-printer-kvp attribute is "
486*0Sstevel@tonic-gate 				"not supported through this command.\n"));
487*0Sstevel@tonic-gate 			break;
488*0Sstevel@tonic-gate 		}
489*0Sstevel@tonic-gate 
490*0Sstevel@tonic-gate 		case NSL_ERR_BSDADDR:
491*0Sstevel@tonic-gate 		{
492*0Sstevel@tonic-gate 			(void) fprintf(stderr, "%s",
493*0Sstevel@tonic-gate 			    gettext("Setting sun-printer-bsdaddr attribute is "
494*0Sstevel@tonic-gate 				"not supported through this command.\n"
495*0Sstevel@tonic-gate 				"Use the bsaddr attribute instead.\n"));
496*0Sstevel@tonic-gate 			break;
497*0Sstevel@tonic-gate 		}
498*0Sstevel@tonic-gate 
499*0Sstevel@tonic-gate 		case NSL_ERR_PNAME:
500*0Sstevel@tonic-gate 		{
501*0Sstevel@tonic-gate 			(void) fprintf(stderr, "%s",
502*0Sstevel@tonic-gate 			    gettext("Setting printer-name attribute is "
503*0Sstevel@tonic-gate 				"not supported through this command.\n"));
504*0Sstevel@tonic-gate 			break;
505*0Sstevel@tonic-gate 		}
506*0Sstevel@tonic-gate 
507*0Sstevel@tonic-gate 		case NSL_ERR_MEMORY:
508*0Sstevel@tonic-gate 		{
509*0Sstevel@tonic-gate 			(void) fprintf(stderr,
510*0Sstevel@tonic-gate 					gettext("Memory allocation error\n"));
511*0Sstevel@tonic-gate 			break;
512*0Sstevel@tonic-gate 		}
513*0Sstevel@tonic-gate 
514*0Sstevel@tonic-gate 		case NSL_ERR_MULTIOP:
515*0Sstevel@tonic-gate 		{
516*0Sstevel@tonic-gate 			(void) fprintf(stderr,
517*0Sstevel@tonic-gate 				gettext("Delete and add operation on the "
518*0Sstevel@tonic-gate 					"same key attribute is not allowed\n"));
519*0Sstevel@tonic-gate 			break;
520*0Sstevel@tonic-gate 		}
521*0Sstevel@tonic-gate 
522*0Sstevel@tonic-gate 		case NSL_ERR_NOTALLOWED:
523*0Sstevel@tonic-gate 		{
524*0Sstevel@tonic-gate 			(void) fprintf(stderr,
525*0Sstevel@tonic-gate 				gettext("KVP attribute is not allowed\n"));
526*0Sstevel@tonic-gate 			break;
527*0Sstevel@tonic-gate 		}
528*0Sstevel@tonic-gate 
529*0Sstevel@tonic-gate 		default:
530*0Sstevel@tonic-gate 		{
531*0Sstevel@tonic-gate 			(void) fprintf(stderr,
532*0Sstevel@tonic-gate 					gettext("Error code = %d\n"), result);
533*0Sstevel@tonic-gate 			break;
534*0Sstevel@tonic-gate 		}
535*0Sstevel@tonic-gate 	}
536*0Sstevel@tonic-gate 
537*0Sstevel@tonic-gate } /* _decode_ldapResult */
538