xref: /onnv-gate/usr/src/cmd/print/lpset/lpset.c (revision 11262:b7ebfbf2359e)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52264Sjacobs  * Common Development and Distribution License (the "License").
62264Sjacobs  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
2211134SCasper.Dik@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <stdio.h>
270Sstevel@tonic-gate #include <stdlib.h>
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <stdarg.h>
300Sstevel@tonic-gate #include <unistd.h>
310Sstevel@tonic-gate #include <limits.h>
320Sstevel@tonic-gate #include <string.h>
330Sstevel@tonic-gate #include <syslog.h>
340Sstevel@tonic-gate #include <errno.h>
350Sstevel@tonic-gate #include <locale.h>
360Sstevel@tonic-gate #ifndef SUNOS_4
370Sstevel@tonic-gate #include <libintl.h>
380Sstevel@tonic-gate #endif
390Sstevel@tonic-gate #include <pwd.h>
4011134SCasper.Dik@Sun.COM #include <alloca.h>
410Sstevel@tonic-gate 
422264Sjacobs #include <ns.h>
432264Sjacobs #include <list.h>
440Sstevel@tonic-gate 
450Sstevel@tonic-gate extern char *optarg;
460Sstevel@tonic-gate extern int optind, opterr, optopt;
470Sstevel@tonic-gate extern char *getenv(const char *);
480Sstevel@tonic-gate 
490Sstevel@tonic-gate static void _decode_ldapResult(int result, char *printerName);
500Sstevel@tonic-gate 
513999Sjacobs static int
authorized()523999Sjacobs authorized()
533999Sjacobs {
543999Sjacobs 	struct passwd *pw;
553999Sjacobs 	uid_t uid;
5611134SCasper.Dik@Sun.COM 	gid_t *list;
573999Sjacobs 	int len;
5811134SCasper.Dik@Sun.COM 	int maxgrp;
593999Sjacobs 
603999Sjacobs 	if ((uid = getuid()) == 0)
613999Sjacobs 		return (1);	/* "root" is authorized */
623999Sjacobs 
633999Sjacobs 	if (((pw = getpwnam("lp")) != NULL) && (uid == pw->pw_uid))
643999Sjacobs 		return (1);	/* "lp" is authorized */
653999Sjacobs 
663999Sjacobs 	if ((pw = getpwuid(uid)) == NULL)
673999Sjacobs 		return (0);	/* intruders are not authorized */
683999Sjacobs 
693999Sjacobs 	if (chkauthattr("solaris.print.admin", pw->pw_name) == 1)
703999Sjacobs 		return (1);	/* "solaris.print.admin" is authorized */
713999Sjacobs 
7211134SCasper.Dik@Sun.COM 	/* How many supplemental groups do we have? */
7311134SCasper.Dik@Sun.COM 	maxgrp = getgroups(0, NULL);
7411134SCasper.Dik@Sun.COM 	list = alloca(maxgrp * sizeof (gid_t));
7511134SCasper.Dik@Sun.COM 
7611134SCasper.Dik@Sun.COM 	if ((len = getgroups(maxgrp, list)) != -1)
7711134SCasper.Dik@Sun.COM 		while (len-- > 0)
783999Sjacobs 			if (list[len] == 14)
793999Sjacobs 				return (1);	/* group 14 is authorized */
803999Sjacobs 
813999Sjacobs 	return (0);	/* nobody else is authorized */
823999Sjacobs }
833999Sjacobs 
840Sstevel@tonic-gate static void
Usage(char * name)850Sstevel@tonic-gate Usage(char *name)
860Sstevel@tonic-gate {
870Sstevel@tonic-gate 	(void) fprintf(stderr,
88*11262SRajagopal.Andra@Sun.COM 	    gettext("Usage: %s [-n files | ldap] [-x] "
89*11262SRajagopal.Andra@Sun.COM 	    "[-h ldaphost] [-D binddn] [-w passwd] "
90*11262SRajagopal.Andra@Sun.COM 	    "[-a key=value] [-d key] (printer)\n"),
91*11262SRajagopal.Andra@Sun.COM 	    name);
920Sstevel@tonic-gate 	exit(1);
930Sstevel@tonic-gate }
940Sstevel@tonic-gate 
950Sstevel@tonic-gate 
960Sstevel@tonic-gate /*
970Sstevel@tonic-gate  *  main() calls the appropriate routine to parse the command line arguments
980Sstevel@tonic-gate  *	and then calls the local remove routine, followed by the remote remove
990Sstevel@tonic-gate  *	routine to remove jobs.
1000Sstevel@tonic-gate  */
1010Sstevel@tonic-gate int
main(int ac,char * av[])1020Sstevel@tonic-gate main(int ac, char *av[])
1030Sstevel@tonic-gate {
1040Sstevel@tonic-gate 	int result = 0;
1050Sstevel@tonic-gate 	int delete_printer = 0;
1060Sstevel@tonic-gate 	int c;
1070Sstevel@tonic-gate 	char	*program = NULL,
108*11262SRajagopal.Andra@Sun.COM 	    *printer = NULL,
109*11262SRajagopal.Andra@Sun.COM 	    *host = NULL,
110*11262SRajagopal.Andra@Sun.COM 	    *binddn = NULL,
111*11262SRajagopal.Andra@Sun.COM 	    *passwd = NULL,
112*11262SRajagopal.Andra@Sun.COM 	    *ins = NULL,
113*11262SRajagopal.Andra@Sun.COM 	    *ons = "files";
1140Sstevel@tonic-gate 	char	**changes = NULL;
1150Sstevel@tonic-gate 	ns_cred_t	*cred = NULL;
1160Sstevel@tonic-gate 	ns_printer_t 	*printer_obj = NULL;
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate #if	!defined(TEXT_DOMAIN)
1210Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"
1220Sstevel@tonic-gate #endif
1230Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate 	if ((program = strrchr(av[0], '/')) == NULL)
1260Sstevel@tonic-gate 		program = av[0];
1270Sstevel@tonic-gate 	else
1280Sstevel@tonic-gate 		program++;
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 	openlog(program, LOG_PID, LOG_LPR);
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate 	if (ac < 2)
1330Sstevel@tonic-gate 		Usage(program);
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 	while ((c = getopt(ac, av, "a:d:D:h:n:r:w:x")) != EOF)
1360Sstevel@tonic-gate 		switch (c) {
1370Sstevel@tonic-gate 		case 'd':
1380Sstevel@tonic-gate 			if (strchr(optarg, '=') != NULL)
1390Sstevel@tonic-gate 				Usage(program);
1400Sstevel@tonic-gate 			/* FALLTHRU */
1410Sstevel@tonic-gate 		case 'a':
1420Sstevel@tonic-gate 			changes = (char **)list_append((void**)changes,
143*11262SRajagopal.Andra@Sun.COM 			    (void *)strdup(optarg));
1440Sstevel@tonic-gate 			break;
1450Sstevel@tonic-gate 		case 'D':
1460Sstevel@tonic-gate 			binddn = optarg;
1470Sstevel@tonic-gate 			break;
1480Sstevel@tonic-gate 		case 'h':
1490Sstevel@tonic-gate 			host = optarg;
1500Sstevel@tonic-gate 			break;
1510Sstevel@tonic-gate 		case 'n':
1520Sstevel@tonic-gate 			ons = optarg;
1530Sstevel@tonic-gate 			break;
1540Sstevel@tonic-gate 		case 'r':
1550Sstevel@tonic-gate 			ins = optarg;
1560Sstevel@tonic-gate 			break;
1570Sstevel@tonic-gate 		case 'w':
1580Sstevel@tonic-gate 			passwd = optarg;
1590Sstevel@tonic-gate 			break;
1600Sstevel@tonic-gate 		case 'x':
1610Sstevel@tonic-gate 			delete_printer++;
1620Sstevel@tonic-gate 			break;
1630Sstevel@tonic-gate 		default:
1640Sstevel@tonic-gate 			Usage(program);
1650Sstevel@tonic-gate 		}
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate 	if (optind != ac-1)
1680Sstevel@tonic-gate 		Usage(program);
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 	/*
1710Sstevel@tonic-gate 	 * Check required options have been given: [ -x | [ -a | -d ]]
1720Sstevel@tonic-gate 	 */
1730Sstevel@tonic-gate 	if ((changes == NULL) && (delete_printer == 0)) {
1740Sstevel@tonic-gate 		Usage(program);
1750Sstevel@tonic-gate 	}
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate 	printer = av[optind];
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate 	if (strchr(printer, ':') != NULL) {
1800Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(
181*11262SRajagopal.Andra@Sun.COM 		    "POSIX-Style names are not valid destinations (%s)\n"),
182*11262SRajagopal.Andra@Sun.COM 		    printer);
1830Sstevel@tonic-gate 		return (1);
1840Sstevel@tonic-gate 	}
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate 	ins = normalize_ns_name(ins);
1870Sstevel@tonic-gate 	ons = normalize_ns_name(ons);
1880Sstevel@tonic-gate 	if (ins == NULL)
1890Sstevel@tonic-gate 		ins = ons;
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate 	/* check / set the name service for writing */
1920Sstevel@tonic-gate 	if (strcasecmp("user", ons) == 0) {
1930Sstevel@tonic-gate 		(void) setuid(getuid());
1940Sstevel@tonic-gate 		ons = "user";
1950Sstevel@tonic-gate 	} else if (strcasecmp("files", ons) == 0) {
1963999Sjacobs 		if (authorized() == 0) {
1973999Sjacobs 			(void) fprintf(stderr, gettext(
198*11262SRajagopal.Andra@Sun.COM 			    "Permission denied: not authorized\n"));
1993999Sjacobs 			return (1);
2000Sstevel@tonic-gate 		}
2010Sstevel@tonic-gate 		ons = "files";
2020Sstevel@tonic-gate 	} else if (strcasecmp("ldap", ons) == 0) {
2030Sstevel@tonic-gate 		if ((cred = calloc(1, sizeof (*cred))) == NULL) {
2040Sstevel@tonic-gate 			(void) fprintf(stderr,
205*11262SRajagopal.Andra@Sun.COM 			    gettext("could not initialize credential\n"));
2060Sstevel@tonic-gate 			return (1);
2070Sstevel@tonic-gate 		}
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate 		if (binddn == NULL) {
2100Sstevel@tonic-gate 			(void) fprintf(stderr,
2110Sstevel@tonic-gate 			    gettext("Distinguished Name is required.\n"));
2120Sstevel@tonic-gate 			return (1);
2130Sstevel@tonic-gate 		}
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate 		if (passwd == NULL) {
2160Sstevel@tonic-gate 			passwd = getpassphrase(gettext("Bind Password:"));
2170Sstevel@tonic-gate 		}
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate 		/*
2200Sstevel@tonic-gate 		 * Setup LDAP bind credentials, so that it uses
2210Sstevel@tonic-gate 		 * the default ldap port, and the NS domain for this
2220Sstevel@tonic-gate 		 * ldapclient box. Note: passwdType is currently not
2230Sstevel@tonic-gate 		 * used but once the ldap native function can select
2240Sstevel@tonic-gate 		 * secure or insure password it will pass the user selected
2250Sstevel@tonic-gate 		 * security type.
2260Sstevel@tonic-gate 		 */
2270Sstevel@tonic-gate 		cred->passwd = passwd;
2280Sstevel@tonic-gate 		cred->passwdType = NS_PW_INSECURE; /* use default */
2290Sstevel@tonic-gate 		cred->binddn = binddn;
2300Sstevel@tonic-gate 		cred->host = host;
2310Sstevel@tonic-gate 		cred->port = 0;		/* use default */
2320Sstevel@tonic-gate 		cred->domainDN = NULL;	/* use default */
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate 		ons = "ldap";
2350Sstevel@tonic-gate 		(void) setuid(getuid());
2360Sstevel@tonic-gate 	} else {
2370Sstevel@tonic-gate 		(void) fprintf(stderr,
238*11262SRajagopal.Andra@Sun.COM 		    gettext("%s is not a supported name service.\n"),
239*11262SRajagopal.Andra@Sun.COM 		    ons);
2400Sstevel@tonic-gate 		return (1);
2410Sstevel@tonic-gate 	}
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 	if (strcasecmp(NS_SVC_LDAP, ons) != 0) {
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate 	    /* Naming Service is not LDAP */
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate 	    /* get the printer object */
248*11262SRajagopal.Andra@Sun.COM 		if ((printer_obj = ns_printer_get_name(printer, ins)) == NULL) {
249*11262SRajagopal.Andra@Sun.COM 			if (delete_printer != 0) {
250*11262SRajagopal.Andra@Sun.COM 				(void) fprintf(stderr, gettext
251*11262SRajagopal.Andra@Sun.COM 				    ("%s: unknown printer\n"), printer);
2520Sstevel@tonic-gate 			return (1);
253*11262SRajagopal.Andra@Sun.COM 			}
254*11262SRajagopal.Andra@Sun.COM 			if ((printer_obj = calloc(1, sizeof (*printer_obj)))
255*11262SRajagopal.Andra@Sun.COM 			    == NULL) {
256*11262SRajagopal.Andra@Sun.COM 				(void) fprintf(stderr, gettext(
257*11262SRajagopal.Andra@Sun.COM 				    "could not initialize printer object\n"));
258*11262SRajagopal.Andra@Sun.COM 				return (1);
259*11262SRajagopal.Andra@Sun.COM 			}
260*11262SRajagopal.Andra@Sun.COM 			printer_obj->name = strdup(printer);
2610Sstevel@tonic-gate 		}
2620Sstevel@tonic-gate 
263*11262SRajagopal.Andra@Sun.COM 		printer_obj->source = ons;
2640Sstevel@tonic-gate 
265*11262SRajagopal.Andra@Sun.COM 		if (cred != NULL) {
266*11262SRajagopal.Andra@Sun.COM 			printer_obj->cred = cred;
267*11262SRajagopal.Andra@Sun.COM 		}
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate 	    /* make the changes to it */
270*11262SRajagopal.Andra@Sun.COM 		while (changes != NULL && *changes != NULL) {
271*11262SRajagopal.Andra@Sun.COM 			int has_equals = (strchr(*changes, '=') != NULL);
272*11262SRajagopal.Andra@Sun.COM 			char *p, *key = NULL, *value = NULL;
2730Sstevel@tonic-gate 
274*11262SRajagopal.Andra@Sun.COM 			key = *(changes++);
2750Sstevel@tonic-gate 
276*11262SRajagopal.Andra@Sun.COM 			for (p = key; ((p != NULL) && (*p != NULL)); p++)
277*11262SRajagopal.Andra@Sun.COM 				if (*p == '=') {
278*11262SRajagopal.Andra@Sun.COM 					*p = NULL;
279*11262SRajagopal.Andra@Sun.COM 					value = ++p;
280*11262SRajagopal.Andra@Sun.COM 					break;
281*11262SRajagopal.Andra@Sun.COM 				} else if (*p == '\\')
282*11262SRajagopal.Andra@Sun.COM 					p++;
2830Sstevel@tonic-gate 
284*11262SRajagopal.Andra@Sun.COM 			if ((value != NULL) && (*value == NULL))
285*11262SRajagopal.Andra@Sun.COM 				value = NULL;
2860Sstevel@tonic-gate 
287*11262SRajagopal.Andra@Sun.COM 			if ((key != NULL) && (key[0] != NULL)) {
288*11262SRajagopal.Andra@Sun.COM 				if ((value == NULL) &&
289*11262SRajagopal.Andra@Sun.COM 				    (ns_get_value(key, printer_obj) == NULL) &&
290*11262SRajagopal.Andra@Sun.COM 				    (has_equals == 0)) {
291*11262SRajagopal.Andra@Sun.COM 					fprintf(stderr,
292*11262SRajagopal.Andra@Sun.COM 					    gettext("%s: unknown attribute\n"),
293*11262SRajagopal.Andra@Sun.COM 					    key);
294*11262SRajagopal.Andra@Sun.COM 					result = 1;
295*11262SRajagopal.Andra@Sun.COM 				} else
296*11262SRajagopal.Andra@Sun.COM 				(void) ns_set_value_from_string(key, value,
297*11262SRajagopal.Andra@Sun.COM 				    printer_obj);
298*11262SRajagopal.Andra@Sun.COM 			}
2990Sstevel@tonic-gate 		}
300*11262SRajagopal.Andra@Sun.COM 		if (delete_printer != 0)
301*11262SRajagopal.Andra@Sun.COM 			printer_obj->attributes = NULL;
3020Sstevel@tonic-gate 
303*11262SRajagopal.Andra@Sun.COM 		/* write it back */
304*11262SRajagopal.Andra@Sun.COM 		if (ns_printer_put(printer_obj) != 0) {
305*11262SRajagopal.Andra@Sun.COM 			(void) fprintf(stderr,
306*11262SRajagopal.Andra@Sun.COM 			    gettext("Failed to write into %s database\n"),
307*11262SRajagopal.Andra@Sun.COM 			    ons);
308*11262SRajagopal.Andra@Sun.COM 			result = 1;
309*11262SRajagopal.Andra@Sun.COM 		}
3100Sstevel@tonic-gate 	}
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate 	else {
3130Sstevel@tonic-gate 		/*
3140Sstevel@tonic-gate 		 * Naming Service is LDAP
3150Sstevel@tonic-gate 		 *
3160Sstevel@tonic-gate 		 * Action the request by calling ns ldap functions to
3170Sstevel@tonic-gate 		 * add, modify or delete the printer object.
3180Sstevel@tonic-gate 		 */
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate 		if ((printer_obj = calloc(1, sizeof (*printer_obj))) == NULL) {
3210Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
322*11262SRajagopal.Andra@Sun.COM 			    "could not initialize printer object\n"));
3230Sstevel@tonic-gate 			return (1);
3240Sstevel@tonic-gate 		}
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate 		if ((cred != NULL) && (printer_obj != NULL)) {
3270Sstevel@tonic-gate 			printer_obj->name = strdup(printer);
3280Sstevel@tonic-gate 			printer_obj->cred = cred;
3290Sstevel@tonic-gate 			printer_obj->cred->domainDN = NULL; /* use default */
3300Sstevel@tonic-gate 			printer_obj->source = ons;
3310Sstevel@tonic-gate 			printer_obj->nsdata = malloc(sizeof (NS_LDAPDATA));
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate 			if (printer_obj->nsdata != NULL) {
3340Sstevel@tonic-gate 				/*
3350Sstevel@tonic-gate 				 * Update the LDAP directory for this printer
3360Sstevel@tonic-gate 				 */
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate 				if (delete_printer != 0) {
3390Sstevel@tonic-gate 					/* Delete the printer object */
3400Sstevel@tonic-gate 					((NS_LDAPDATA *)
341*11262SRajagopal.Andra@Sun.COM 					    (printer_obj->nsdata))->attrList
342*11262SRajagopal.Andra@Sun.COM 					    = NULL;
3430Sstevel@tonic-gate 				} else {
3440Sstevel@tonic-gate 					/* Add or modify the printer object */
3450Sstevel@tonic-gate 					((NS_LDAPDATA *)
346*11262SRajagopal.Andra@Sun.COM 					    (printer_obj->nsdata))->attrList =
347*11262SRajagopal.Andra@Sun.COM 					    changes;
3480Sstevel@tonic-gate 				}
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate 				result = ns_printer_put(printer_obj);
3510Sstevel@tonic-gate 				if (result != 0) {
3520Sstevel@tonic-gate 					/* display LDAP specific message */
3530Sstevel@tonic-gate 					_decode_ldapResult(result, printer);
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate 					(void) fprintf(stderr, gettext(
3560Sstevel@tonic-gate 					"Failed to update %s database\n"), ons);
3570Sstevel@tonic-gate 					result = 1;
3580Sstevel@tonic-gate 				}
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 				free(printer_obj->nsdata);
3610Sstevel@tonic-gate 			}
3620Sstevel@tonic-gate 
3630Sstevel@tonic-gate 			else {
3640Sstevel@tonic-gate 				_decode_ldapResult(NSL_ERR_MEMORY, NULL);
3650Sstevel@tonic-gate 				result = 1;
3660Sstevel@tonic-gate 			}
3670Sstevel@tonic-gate 		}
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate 		else {
3700Sstevel@tonic-gate 			result = 1;
3710Sstevel@tonic-gate 			(void) fprintf(stderr,
372*11262SRajagopal.Andra@Sun.COM 			    gettext("Error - no LDAP credentials\n"));
3730Sstevel@tonic-gate 		}
3740Sstevel@tonic-gate 
3750Sstevel@tonic-gate 		if (printer_obj != NULL) {
3760Sstevel@tonic-gate 			if (printer_obj->name != NULL) {
3770Sstevel@tonic-gate 				free(printer_obj->name);
3780Sstevel@tonic-gate 			}
3790Sstevel@tonic-gate 			free(printer_obj);
3800Sstevel@tonic-gate 		}
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate 	}
3830Sstevel@tonic-gate 
3840Sstevel@tonic-gate 	return (result);
3850Sstevel@tonic-gate } /* main */
3860Sstevel@tonic-gate 
3870Sstevel@tonic-gate 
3880Sstevel@tonic-gate 
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate /*
3910Sstevel@tonic-gate  * *****************************************************************************
3920Sstevel@tonic-gate  *
3930Sstevel@tonic-gate  * Function:    _decode_ldapResult()
3940Sstevel@tonic-gate  *
3950Sstevel@tonic-gate  * Description: Decode the ldap_put_printer specific error codes and display
3960Sstevel@tonic-gate  *              the appropriate error message.
3970Sstevel@tonic-gate  *
3980Sstevel@tonic-gate  * Parameters:
3990Sstevel@tonic-gate  * Input:       int result - contains the NSL_RESULT codes
4000Sstevel@tonic-gate  *              char *printerName - name of printer
4010Sstevel@tonic-gate  * Output:      None
4020Sstevel@tonic-gate  *
4030Sstevel@tonic-gate  * Returns:     void
4040Sstevel@tonic-gate  *
4050Sstevel@tonic-gate  * *****************************************************************************
4060Sstevel@tonic-gate  */
4070Sstevel@tonic-gate 
4080Sstevel@tonic-gate static void
_decode_ldapResult(int result,char * printerName)4090Sstevel@tonic-gate _decode_ldapResult(int result, char *printerName)
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate {
4120Sstevel@tonic-gate 	NSL_RESULT lresult = (NSL_RESULT)result;
4130Sstevel@tonic-gate 
4140Sstevel@tonic-gate 	/* ------------- */
4150Sstevel@tonic-gate 
4160Sstevel@tonic-gate 	switch (lresult)
4170Sstevel@tonic-gate 	{
4180Sstevel@tonic-gate 		case NSL_OK:
4190Sstevel@tonic-gate 		{
4200Sstevel@tonic-gate 			break;
4210Sstevel@tonic-gate 		}
4220Sstevel@tonic-gate 
4230Sstevel@tonic-gate 		case NSL_ERR_INTERNAL:
4240Sstevel@tonic-gate 		{
4250Sstevel@tonic-gate 			(void) fprintf(stderr,
4260Sstevel@tonic-gate 				gettext("Unexpected software error\n"));
4270Sstevel@tonic-gate 			break;
4280Sstevel@tonic-gate 		}
4290Sstevel@tonic-gate 
4300Sstevel@tonic-gate 		case NSL_ERR_ADD_FAILED:
4310Sstevel@tonic-gate 		{
4320Sstevel@tonic-gate 			(void) fprintf(stderr, "%s %s\n",
4330Sstevel@tonic-gate 				gettext("Failed to add printer:"), printerName);
4340Sstevel@tonic-gate 			break;
4350Sstevel@tonic-gate 		}
4360Sstevel@tonic-gate 
4370Sstevel@tonic-gate 		case NSL_ERR_MOD_FAILED:
4380Sstevel@tonic-gate 		{
4390Sstevel@tonic-gate 			(void) fprintf(stderr, "%s %s\n",
4400Sstevel@tonic-gate 				gettext("Failed to modify printer:"),
4410Sstevel@tonic-gate 					printerName);
4420Sstevel@tonic-gate 			break;
4430Sstevel@tonic-gate 		}
4440Sstevel@tonic-gate 
4450Sstevel@tonic-gate 		case NSL_ERR_DEL_FAILED:
4460Sstevel@tonic-gate 		{
4470Sstevel@tonic-gate 			(void) fprintf(stderr, "%s %s\n",
4480Sstevel@tonic-gate 				gettext("Failed to delete printer:"),
4490Sstevel@tonic-gate 					printerName);
4500Sstevel@tonic-gate 			break;
4510Sstevel@tonic-gate 		}
4520Sstevel@tonic-gate 
4530Sstevel@tonic-gate 
4540Sstevel@tonic-gate 		case NSL_ERR_UNKNOWN_PRINTER:
4550Sstevel@tonic-gate 		{
4560Sstevel@tonic-gate 			(void) fprintf(stderr, "%s %s\n",
4570Sstevel@tonic-gate 				gettext("Unknown printer:"), printerName);
4580Sstevel@tonic-gate 			break;
4590Sstevel@tonic-gate 		}
4600Sstevel@tonic-gate 
4610Sstevel@tonic-gate 		case NSL_ERR_CREDENTIALS:
4620Sstevel@tonic-gate 		{
4630Sstevel@tonic-gate 			(void) fprintf(stderr, "%s\n",
4640Sstevel@tonic-gate 		gettext("Missing LDAP credential information for printer:"));
4650Sstevel@tonic-gate 			break;
4660Sstevel@tonic-gate 		}
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate 		case NSL_ERR_CONNECT:
4690Sstevel@tonic-gate 		{
4700Sstevel@tonic-gate 			(void) fprintf(stderr, "%s\n",
4710Sstevel@tonic-gate 				gettext("Failed to connect to LDAP server"));
4720Sstevel@tonic-gate 			break;
4730Sstevel@tonic-gate 		}
4740Sstevel@tonic-gate 
4750Sstevel@tonic-gate 		case NSL_ERR_BIND:
4760Sstevel@tonic-gate 		{
4770Sstevel@tonic-gate 			(void) fprintf(stderr, gettext("LDAP bind failed\n"));
4780Sstevel@tonic-gate 			break;
4790Sstevel@tonic-gate 		}
4800Sstevel@tonic-gate 
4810Sstevel@tonic-gate 		case NSL_ERR_RENAME:
4820Sstevel@tonic-gate 		{
4830Sstevel@tonic-gate 			(void) fprintf(stderr, "%s %s\n",
4840Sstevel@tonic-gate 			    gettext("Object rename not allowed for printer:"),
4850Sstevel@tonic-gate 			    printerName);
4860Sstevel@tonic-gate 			break;
4870Sstevel@tonic-gate 		}
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate 		case NSL_ERR_KVP:
4900Sstevel@tonic-gate 		{
4910Sstevel@tonic-gate 			(void) fprintf(stderr, "%s",
4920Sstevel@tonic-gate 			    gettext("Setting sun-printer-kvp attribute is "
4930Sstevel@tonic-gate 				"not supported through this command.\n"));
4940Sstevel@tonic-gate 			break;
4950Sstevel@tonic-gate 		}
4960Sstevel@tonic-gate 
4970Sstevel@tonic-gate 		case NSL_ERR_BSDADDR:
4980Sstevel@tonic-gate 		{
4990Sstevel@tonic-gate 			(void) fprintf(stderr, "%s",
5000Sstevel@tonic-gate 			    gettext("Setting sun-printer-bsdaddr attribute is "
5010Sstevel@tonic-gate 				"not supported through this command.\n"
5020Sstevel@tonic-gate 				"Use the bsaddr attribute instead.\n"));
5030Sstevel@tonic-gate 			break;
5040Sstevel@tonic-gate 		}
5050Sstevel@tonic-gate 
5060Sstevel@tonic-gate 		case NSL_ERR_PNAME:
5070Sstevel@tonic-gate 		{
5080Sstevel@tonic-gate 			(void) fprintf(stderr, "%s",
5090Sstevel@tonic-gate 			    gettext("Setting printer-name attribute is "
5100Sstevel@tonic-gate 				"not supported through this command.\n"));
5110Sstevel@tonic-gate 			break;
5120Sstevel@tonic-gate 		}
5130Sstevel@tonic-gate 
5140Sstevel@tonic-gate 		case NSL_ERR_MEMORY:
5150Sstevel@tonic-gate 		{
5160Sstevel@tonic-gate 			(void) fprintf(stderr,
5170Sstevel@tonic-gate 					gettext("Memory allocation error\n"));
5180Sstevel@tonic-gate 			break;
5190Sstevel@tonic-gate 		}
5200Sstevel@tonic-gate 
5210Sstevel@tonic-gate 		case NSL_ERR_MULTIOP:
5220Sstevel@tonic-gate 		{
5230Sstevel@tonic-gate 			(void) fprintf(stderr,
5240Sstevel@tonic-gate 				gettext("Delete and add operation on the "
5250Sstevel@tonic-gate 					"same key attribute is not allowed\n"));
5260Sstevel@tonic-gate 			break;
5270Sstevel@tonic-gate 		}
5280Sstevel@tonic-gate 
5290Sstevel@tonic-gate 		case NSL_ERR_NOTALLOWED:
5300Sstevel@tonic-gate 		{
5310Sstevel@tonic-gate 			(void) fprintf(stderr,
5320Sstevel@tonic-gate 				gettext("KVP attribute is not allowed\n"));
5330Sstevel@tonic-gate 			break;
5340Sstevel@tonic-gate 		}
5350Sstevel@tonic-gate 
5360Sstevel@tonic-gate 		default:
5370Sstevel@tonic-gate 		{
5380Sstevel@tonic-gate 			(void) fprintf(stderr,
5390Sstevel@tonic-gate 					gettext("Error code = %d\n"), result);
5400Sstevel@tonic-gate 			break;
5410Sstevel@tonic-gate 		}
5420Sstevel@tonic-gate 	}
5430Sstevel@tonic-gate 
5440Sstevel@tonic-gate } /* _decode_ldapResult */
545