xref: /illumos-gate/usr/src/cmd/print/lpset/lpset.c (revision 5243e334)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5355b4669Sjacobs  * Common Development and Distribution License (the "License").
6355b4669Sjacobs  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2267dbe2beSCasper H.S. Dik  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <stdio.h>
277c478bd9Sstevel@tonic-gate #include <stdlib.h>
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <stdarg.h>
307c478bd9Sstevel@tonic-gate #include <unistd.h>
317c478bd9Sstevel@tonic-gate #include <limits.h>
327c478bd9Sstevel@tonic-gate #include <string.h>
337c478bd9Sstevel@tonic-gate #include <syslog.h>
347c478bd9Sstevel@tonic-gate #include <errno.h>
357c478bd9Sstevel@tonic-gate #include <locale.h>
367c478bd9Sstevel@tonic-gate #ifndef SUNOS_4
377c478bd9Sstevel@tonic-gate #include <libintl.h>
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate #include <pwd.h>
4067dbe2beSCasper H.S. Dik #include <alloca.h>
417c478bd9Sstevel@tonic-gate 
42355b4669Sjacobs #include <ns.h>
43355b4669Sjacobs #include <list.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate extern char *optarg;
467c478bd9Sstevel@tonic-gate extern int optind, opterr, optopt;
477c478bd9Sstevel@tonic-gate extern char *getenv(const char *);
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate static void _decode_ldapResult(int result, char *printerName);
507c478bd9Sstevel@tonic-gate 
5153ac4dcaSjacobs static int
authorized()5253ac4dcaSjacobs authorized()
5353ac4dcaSjacobs {
5453ac4dcaSjacobs 	struct passwd *pw;
5553ac4dcaSjacobs 	uid_t uid;
5667dbe2beSCasper H.S. Dik 	gid_t *list;
5753ac4dcaSjacobs 	int len;
5867dbe2beSCasper H.S. Dik 	int maxgrp;
5953ac4dcaSjacobs 
6053ac4dcaSjacobs 	if ((uid = getuid()) == 0)
6153ac4dcaSjacobs 		return (1);	/* "root" is authorized */
6253ac4dcaSjacobs 
6353ac4dcaSjacobs 	if (((pw = getpwnam("lp")) != NULL) && (uid == pw->pw_uid))
6453ac4dcaSjacobs 		return (1);	/* "lp" is authorized */
6553ac4dcaSjacobs 
6653ac4dcaSjacobs 	if ((pw = getpwuid(uid)) == NULL)
6753ac4dcaSjacobs 		return (0);	/* intruders are not authorized */
6853ac4dcaSjacobs 
6953ac4dcaSjacobs 	if (chkauthattr("solaris.print.admin", pw->pw_name) == 1)
7053ac4dcaSjacobs 		return (1);	/* "solaris.print.admin" is authorized */
7153ac4dcaSjacobs 
7267dbe2beSCasper H.S. Dik 	/* How many supplemental groups do we have? */
7367dbe2beSCasper H.S. Dik 	maxgrp = getgroups(0, NULL);
7467dbe2beSCasper H.S. Dik 	list = alloca(maxgrp * sizeof (gid_t));
7567dbe2beSCasper H.S. Dik 
7667dbe2beSCasper H.S. Dik 	if ((len = getgroups(maxgrp, list)) != -1)
7767dbe2beSCasper H.S. Dik 		while (len-- > 0)
7853ac4dcaSjacobs 			if (list[len] == 14)
7953ac4dcaSjacobs 				return (1);	/* group 14 is authorized */
8053ac4dcaSjacobs 
8153ac4dcaSjacobs 	return (0);	/* nobody else is authorized */
8253ac4dcaSjacobs }
8353ac4dcaSjacobs 
847c478bd9Sstevel@tonic-gate static void
Usage(char * name)857c478bd9Sstevel@tonic-gate Usage(char *name)
867c478bd9Sstevel@tonic-gate {
877c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
8836e852a1SRaja Andra 	    gettext("Usage: %s [-n files | ldap] [-x] "
8936e852a1SRaja Andra 	    "[-h ldaphost] [-D binddn] [-w passwd] "
9036e852a1SRaja Andra 	    "[-a key=value] [-d key] (printer)\n"),
9136e852a1SRaja Andra 	    name);
927c478bd9Sstevel@tonic-gate 	exit(1);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  *  main() calls the appropriate routine to parse the command line arguments
987c478bd9Sstevel@tonic-gate  *	and then calls the local remove routine, followed by the remote remove
997c478bd9Sstevel@tonic-gate  *	routine to remove jobs.
1007c478bd9Sstevel@tonic-gate  */
1017c478bd9Sstevel@tonic-gate int
main(int ac,char * av[])1027c478bd9Sstevel@tonic-gate main(int ac, char *av[])
1037c478bd9Sstevel@tonic-gate {
1047c478bd9Sstevel@tonic-gate 	int result = 0;
1057c478bd9Sstevel@tonic-gate 	int delete_printer = 0;
1067c478bd9Sstevel@tonic-gate 	int c;
1077c478bd9Sstevel@tonic-gate 	char	*program = NULL,
10836e852a1SRaja Andra 	    *printer = NULL,
10936e852a1SRaja Andra 	    *host = NULL,
11036e852a1SRaja Andra 	    *binddn = NULL,
11136e852a1SRaja Andra 	    *passwd = NULL,
11236e852a1SRaja Andra 	    *ins = NULL,
11336e852a1SRaja Andra 	    *ons = "files";
1147c478bd9Sstevel@tonic-gate 	char	**changes = NULL;
1157c478bd9Sstevel@tonic-gate 	ns_cred_t	*cred = NULL;
1167c478bd9Sstevel@tonic-gate 	ns_printer_t 	*printer_obj = NULL;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #if	!defined(TEXT_DOMAIN)
1217c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"
1227c478bd9Sstevel@tonic-gate #endif
1237c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	if ((program = strrchr(av[0], '/')) == NULL)
1267c478bd9Sstevel@tonic-gate 		program = av[0];
1277c478bd9Sstevel@tonic-gate 	else
1287c478bd9Sstevel@tonic-gate 		program++;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	openlog(program, LOG_PID, LOG_LPR);
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	if (ac < 2)
1337c478bd9Sstevel@tonic-gate 		Usage(program);
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	while ((c = getopt(ac, av, "a:d:D:h:n:r:w:x")) != EOF)
1367c478bd9Sstevel@tonic-gate 		switch (c) {
1377c478bd9Sstevel@tonic-gate 		case 'd':
1387c478bd9Sstevel@tonic-gate 			if (strchr(optarg, '=') != NULL)
1397c478bd9Sstevel@tonic-gate 				Usage(program);
1407c478bd9Sstevel@tonic-gate 			/* FALLTHRU */
1417c478bd9Sstevel@tonic-gate 		case 'a':
1427c478bd9Sstevel@tonic-gate 			changes = (char **)list_append((void**)changes,
14336e852a1SRaja Andra 			    (void *)strdup(optarg));
1447c478bd9Sstevel@tonic-gate 			break;
1457c478bd9Sstevel@tonic-gate 		case 'D':
1467c478bd9Sstevel@tonic-gate 			binddn = optarg;
1477c478bd9Sstevel@tonic-gate 			break;
1487c478bd9Sstevel@tonic-gate 		case 'h':
1497c478bd9Sstevel@tonic-gate 			host = optarg;
1507c478bd9Sstevel@tonic-gate 			break;
1517c478bd9Sstevel@tonic-gate 		case 'n':
1527c478bd9Sstevel@tonic-gate 			ons = optarg;
1537c478bd9Sstevel@tonic-gate 			break;
1547c478bd9Sstevel@tonic-gate 		case 'r':
1557c478bd9Sstevel@tonic-gate 			ins = optarg;
1567c478bd9Sstevel@tonic-gate 			break;
1577c478bd9Sstevel@tonic-gate 		case 'w':
1587c478bd9Sstevel@tonic-gate 			passwd = optarg;
1597c478bd9Sstevel@tonic-gate 			break;
1607c478bd9Sstevel@tonic-gate 		case 'x':
1617c478bd9Sstevel@tonic-gate 			delete_printer++;
1627c478bd9Sstevel@tonic-gate 			break;
1637c478bd9Sstevel@tonic-gate 		default:
1647c478bd9Sstevel@tonic-gate 			Usage(program);
1657c478bd9Sstevel@tonic-gate 		}
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	if (optind != ac-1)
1687c478bd9Sstevel@tonic-gate 		Usage(program);
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	/*
1717c478bd9Sstevel@tonic-gate 	 * Check required options have been given: [ -x | [ -a | -d ]]
1727c478bd9Sstevel@tonic-gate 	 */
1737c478bd9Sstevel@tonic-gate 	if ((changes == NULL) && (delete_printer == 0)) {
1747c478bd9Sstevel@tonic-gate 		Usage(program);
1757c478bd9Sstevel@tonic-gate 	}
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	printer = av[optind];
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	if (strchr(printer, ':') != NULL) {
1807c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, gettext(
18136e852a1SRaja Andra 		    "POSIX-Style names are not valid destinations (%s)\n"),
18236e852a1SRaja Andra 		    printer);
1837c478bd9Sstevel@tonic-gate 		return (1);
1847c478bd9Sstevel@tonic-gate 	}
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 	ins = normalize_ns_name(ins);
1877c478bd9Sstevel@tonic-gate 	ons = normalize_ns_name(ons);
1887c478bd9Sstevel@tonic-gate 	if (ins == NULL)
1897c478bd9Sstevel@tonic-gate 		ins = ons;
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	/* check / set the name service for writing */
1927c478bd9Sstevel@tonic-gate 	if (strcasecmp("user", ons) == 0) {
1937c478bd9Sstevel@tonic-gate 		(void) setuid(getuid());
1947c478bd9Sstevel@tonic-gate 		ons = "user";
1957c478bd9Sstevel@tonic-gate 	} else if (strcasecmp("files", ons) == 0) {
19653ac4dcaSjacobs 		if (authorized() == 0) {
19753ac4dcaSjacobs 			(void) fprintf(stderr, gettext(
19836e852a1SRaja Andra 			    "Permission denied: not authorized\n"));
19953ac4dcaSjacobs 			return (1);
2007c478bd9Sstevel@tonic-gate 		}
2017c478bd9Sstevel@tonic-gate 		ons = "files";
2027c478bd9Sstevel@tonic-gate 	} else if (strcasecmp("ldap", ons) == 0) {
2037c478bd9Sstevel@tonic-gate 		if ((cred = calloc(1, sizeof (*cred))) == NULL) {
2047c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
20536e852a1SRaja Andra 			    gettext("could not initialize credential\n"));
2067c478bd9Sstevel@tonic-gate 			return (1);
2077c478bd9Sstevel@tonic-gate 		}
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate 		if (binddn == NULL) {
2107c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
2117c478bd9Sstevel@tonic-gate 			    gettext("Distinguished Name is required.\n"));
2127c478bd9Sstevel@tonic-gate 			return (1);
2137c478bd9Sstevel@tonic-gate 		}
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 		if (passwd == NULL) {
2167c478bd9Sstevel@tonic-gate 			passwd = getpassphrase(gettext("Bind Password:"));
2177c478bd9Sstevel@tonic-gate 		}
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 		/*
2207c478bd9Sstevel@tonic-gate 		 * Setup LDAP bind credentials, so that it uses
2217c478bd9Sstevel@tonic-gate 		 * the default ldap port, and the NS domain for this
2227c478bd9Sstevel@tonic-gate 		 * ldapclient box. Note: passwdType is currently not
2237c478bd9Sstevel@tonic-gate 		 * used but once the ldap native function can select
2247c478bd9Sstevel@tonic-gate 		 * secure or insure password it will pass the user selected
2257c478bd9Sstevel@tonic-gate 		 * security type.
2267c478bd9Sstevel@tonic-gate 		 */
2277c478bd9Sstevel@tonic-gate 		cred->passwd = passwd;
2287c478bd9Sstevel@tonic-gate 		cred->passwdType = NS_PW_INSECURE; /* use default */
2297c478bd9Sstevel@tonic-gate 		cred->binddn = binddn;
2307c478bd9Sstevel@tonic-gate 		cred->host = host;
2317c478bd9Sstevel@tonic-gate 		cred->port = 0;		/* use default */
2327c478bd9Sstevel@tonic-gate 		cred->domainDN = NULL;	/* use default */
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 		ons = "ldap";
2357c478bd9Sstevel@tonic-gate 		(void) setuid(getuid());
2367c478bd9Sstevel@tonic-gate 	} else {
2377c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
23836e852a1SRaja Andra 		    gettext("%s is not a supported name service.\n"),
23936e852a1SRaja Andra 		    ons);
2407c478bd9Sstevel@tonic-gate 		return (1);
2417c478bd9Sstevel@tonic-gate 	}
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 	if (strcasecmp(NS_SVC_LDAP, ons) != 0) {
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 	    /* Naming Service is not LDAP */
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	    /* get the printer object */
24836e852a1SRaja Andra 		if ((printer_obj = ns_printer_get_name(printer, ins)) == NULL) {
24936e852a1SRaja Andra 			if (delete_printer != 0) {
25036e852a1SRaja Andra 				(void) fprintf(stderr, gettext
25136e852a1SRaja Andra 				    ("%s: unknown printer\n"), printer);
2527c478bd9Sstevel@tonic-gate 			return (1);
25336e852a1SRaja Andra 			}
25436e852a1SRaja Andra 			if ((printer_obj = calloc(1, sizeof (*printer_obj)))
25536e852a1SRaja Andra 			    == NULL) {
25636e852a1SRaja Andra 				(void) fprintf(stderr, gettext(
25736e852a1SRaja Andra 				    "could not initialize printer object\n"));
25836e852a1SRaja Andra 				return (1);
25936e852a1SRaja Andra 			}
26036e852a1SRaja Andra 			printer_obj->name = strdup(printer);
2617c478bd9Sstevel@tonic-gate 		}
2627c478bd9Sstevel@tonic-gate 
26336e852a1SRaja Andra 		printer_obj->source = ons;
2647c478bd9Sstevel@tonic-gate 
26536e852a1SRaja Andra 		if (cred != NULL) {
26636e852a1SRaja Andra 			printer_obj->cred = cred;
26736e852a1SRaja Andra 		}
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	    /* make the changes to it */
27036e852a1SRaja Andra 		while (changes != NULL && *changes != NULL) {
27136e852a1SRaja Andra 			int has_equals = (strchr(*changes, '=') != NULL);
27236e852a1SRaja Andra 			char *p, *key = NULL, *value = NULL;
27336e852a1SRaja Andra 
27436e852a1SRaja Andra 			key = *(changes++);
27536e852a1SRaja Andra 
276*5243e334SToomas Soome 			for (p = key; ((p != NULL) && (*p != '\0')); p++)
27736e852a1SRaja Andra 				if (*p == '=') {
278*5243e334SToomas Soome 					*p = '\0';
27936e852a1SRaja Andra 					value = ++p;
28036e852a1SRaja Andra 					break;
28136e852a1SRaja Andra 				} else if (*p == '\\')
28236e852a1SRaja Andra 					p++;
28336e852a1SRaja Andra 
284*5243e334SToomas Soome 			if ((value != NULL) && (*value == '\0'))
28536e852a1SRaja Andra 				value = NULL;
28636e852a1SRaja Andra 
287*5243e334SToomas Soome 			if ((key != NULL) && (key[0] != '\0')) {
28836e852a1SRaja Andra 				if ((value == NULL) &&
28936e852a1SRaja Andra 				    (ns_get_value(key, printer_obj) == NULL) &&
29036e852a1SRaja Andra 				    (has_equals == 0)) {
29136e852a1SRaja Andra 					fprintf(stderr,
29236e852a1SRaja Andra 					    gettext("%s: unknown attribute\n"),
29336e852a1SRaja Andra 					    key);
29436e852a1SRaja Andra 					result = 1;
29536e852a1SRaja Andra 				} else
29636e852a1SRaja Andra 				(void) ns_set_value_from_string(key, value,
29736e852a1SRaja Andra 				    printer_obj);
29836e852a1SRaja Andra 			}
2997c478bd9Sstevel@tonic-gate 		}
30036e852a1SRaja Andra 		if (delete_printer != 0)
30136e852a1SRaja Andra 			printer_obj->attributes = NULL;
3027c478bd9Sstevel@tonic-gate 
30336e852a1SRaja Andra 		/* write it back */
30436e852a1SRaja Andra 		if (ns_printer_put(printer_obj) != 0) {
30536e852a1SRaja Andra 			(void) fprintf(stderr,
30636e852a1SRaja Andra 			    gettext("Failed to write into %s database\n"),
30736e852a1SRaja Andra 			    ons);
30836e852a1SRaja Andra 			result = 1;
30936e852a1SRaja Andra 		}
3107c478bd9Sstevel@tonic-gate 	}
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	else {
3137c478bd9Sstevel@tonic-gate 		/*
3147c478bd9Sstevel@tonic-gate 		 * Naming Service is LDAP
3157c478bd9Sstevel@tonic-gate 		 *
3167c478bd9Sstevel@tonic-gate 		 * Action the request by calling ns ldap functions to
3177c478bd9Sstevel@tonic-gate 		 * add, modify or delete the printer object.
3187c478bd9Sstevel@tonic-gate 		 */
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 		if ((printer_obj = calloc(1, sizeof (*printer_obj))) == NULL) {
3217c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext(
32236e852a1SRaja Andra 			    "could not initialize printer object\n"));
3237c478bd9Sstevel@tonic-gate 			return (1);
3247c478bd9Sstevel@tonic-gate 		}
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 		if ((cred != NULL) && (printer_obj != NULL)) {
3277c478bd9Sstevel@tonic-gate 			printer_obj->name = strdup(printer);
3287c478bd9Sstevel@tonic-gate 			printer_obj->cred = cred;
3297c478bd9Sstevel@tonic-gate 			printer_obj->cred->domainDN = NULL; /* use default */
3307c478bd9Sstevel@tonic-gate 			printer_obj->source = ons;
3317c478bd9Sstevel@tonic-gate 			printer_obj->nsdata = malloc(sizeof (NS_LDAPDATA));
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 			if (printer_obj->nsdata != NULL) {
3347c478bd9Sstevel@tonic-gate 				/*
3357c478bd9Sstevel@tonic-gate 				 * Update the LDAP directory for this printer
3367c478bd9Sstevel@tonic-gate 				 */
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 				if (delete_printer != 0) {
3397c478bd9Sstevel@tonic-gate 					/* Delete the printer object */
3407c478bd9Sstevel@tonic-gate 					((NS_LDAPDATA *)
34136e852a1SRaja Andra 					    (printer_obj->nsdata))->attrList
34236e852a1SRaja Andra 					    = NULL;
3437c478bd9Sstevel@tonic-gate 				} else {
3447c478bd9Sstevel@tonic-gate 					/* Add or modify the printer object */
3457c478bd9Sstevel@tonic-gate 					((NS_LDAPDATA *)
34636e852a1SRaja Andra 					    (printer_obj->nsdata))->attrList =
34736e852a1SRaja Andra 					    changes;
3487c478bd9Sstevel@tonic-gate 				}
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate 				result = ns_printer_put(printer_obj);
3517c478bd9Sstevel@tonic-gate 				if (result != 0) {
3527c478bd9Sstevel@tonic-gate 					/* display LDAP specific message */
3537c478bd9Sstevel@tonic-gate 					_decode_ldapResult(result, printer);
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate 					(void) fprintf(stderr, gettext(
3567c478bd9Sstevel@tonic-gate 					"Failed to update %s database\n"), ons);
3577c478bd9Sstevel@tonic-gate 					result = 1;
3587c478bd9Sstevel@tonic-gate 				}
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate 				free(printer_obj->nsdata);
3617c478bd9Sstevel@tonic-gate 			}
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 			else {
3647c478bd9Sstevel@tonic-gate 				_decode_ldapResult(NSL_ERR_MEMORY, NULL);
3657c478bd9Sstevel@tonic-gate 				result = 1;
3667c478bd9Sstevel@tonic-gate 			}
3677c478bd9Sstevel@tonic-gate 		}
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 		else {
3707c478bd9Sstevel@tonic-gate 			result = 1;
3717c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
37236e852a1SRaja Andra 			    gettext("Error - no LDAP credentials\n"));
3737c478bd9Sstevel@tonic-gate 		}
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate 		if (printer_obj != NULL) {
3767c478bd9Sstevel@tonic-gate 			if (printer_obj->name != NULL) {
3777c478bd9Sstevel@tonic-gate 				free(printer_obj->name);
3787c478bd9Sstevel@tonic-gate 			}
3797c478bd9Sstevel@tonic-gate 			free(printer_obj);
3807c478bd9Sstevel@tonic-gate 		}
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate 	}
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 	return (result);
3857c478bd9Sstevel@tonic-gate } /* main */
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate /*
3917c478bd9Sstevel@tonic-gate  * *****************************************************************************
3927c478bd9Sstevel@tonic-gate  *
3937c478bd9Sstevel@tonic-gate  * Function:    _decode_ldapResult()
3947c478bd9Sstevel@tonic-gate  *
3957c478bd9Sstevel@tonic-gate  * Description: Decode the ldap_put_printer specific error codes and display
3967c478bd9Sstevel@tonic-gate  *              the appropriate error message.
3977c478bd9Sstevel@tonic-gate  *
3987c478bd9Sstevel@tonic-gate  * Parameters:
3997c478bd9Sstevel@tonic-gate  * Input:       int result - contains the NSL_RESULT codes
4007c478bd9Sstevel@tonic-gate  *              char *printerName - name of printer
4017c478bd9Sstevel@tonic-gate  * Output:      None
4027c478bd9Sstevel@tonic-gate  *
4037c478bd9Sstevel@tonic-gate  * Returns:     void
4047c478bd9Sstevel@tonic-gate  *
4057c478bd9Sstevel@tonic-gate  * *****************************************************************************
4067c478bd9Sstevel@tonic-gate  */
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate static void
_decode_ldapResult(int result,char * printerName)4097c478bd9Sstevel@tonic-gate _decode_ldapResult(int result, char *printerName)
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate {
4127c478bd9Sstevel@tonic-gate 	NSL_RESULT lresult = (NSL_RESULT)result;
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate 	/* ------------- */
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate 	switch (lresult)
4177c478bd9Sstevel@tonic-gate 	{
4187c478bd9Sstevel@tonic-gate 		case NSL_OK:
4197c478bd9Sstevel@tonic-gate 		{
4207c478bd9Sstevel@tonic-gate 			break;
4217c478bd9Sstevel@tonic-gate 		}
4227c478bd9Sstevel@tonic-gate 
4237c478bd9Sstevel@tonic-gate 		case NSL_ERR_INTERNAL:
4247c478bd9Sstevel@tonic-gate 		{
4257c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
4267c478bd9Sstevel@tonic-gate 				gettext("Unexpected software error\n"));
4277c478bd9Sstevel@tonic-gate 			break;
4287c478bd9Sstevel@tonic-gate 		}
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 		case NSL_ERR_ADD_FAILED:
4317c478bd9Sstevel@tonic-gate 		{
4327c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s %s\n",
4337c478bd9Sstevel@tonic-gate 				gettext("Failed to add printer:"), printerName);
4347c478bd9Sstevel@tonic-gate 			break;
4357c478bd9Sstevel@tonic-gate 		}
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate 		case NSL_ERR_MOD_FAILED:
4387c478bd9Sstevel@tonic-gate 		{
4397c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s %s\n",
4407c478bd9Sstevel@tonic-gate 				gettext("Failed to modify printer:"),
4417c478bd9Sstevel@tonic-gate 					printerName);
4427c478bd9Sstevel@tonic-gate 			break;
4437c478bd9Sstevel@tonic-gate 		}
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate 		case NSL_ERR_DEL_FAILED:
4467c478bd9Sstevel@tonic-gate 		{
4477c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s %s\n",
4487c478bd9Sstevel@tonic-gate 				gettext("Failed to delete printer:"),
4497c478bd9Sstevel@tonic-gate 					printerName);
4507c478bd9Sstevel@tonic-gate 			break;
4517c478bd9Sstevel@tonic-gate 		}
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate 		case NSL_ERR_UNKNOWN_PRINTER:
4557c478bd9Sstevel@tonic-gate 		{
4567c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s %s\n",
4577c478bd9Sstevel@tonic-gate 				gettext("Unknown printer:"), printerName);
4587c478bd9Sstevel@tonic-gate 			break;
4597c478bd9Sstevel@tonic-gate 		}
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate 		case NSL_ERR_CREDENTIALS:
4627c478bd9Sstevel@tonic-gate 		{
4637c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s\n",
4647c478bd9Sstevel@tonic-gate 		gettext("Missing LDAP credential information for printer:"));
4657c478bd9Sstevel@tonic-gate 			break;
4667c478bd9Sstevel@tonic-gate 		}
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 		case NSL_ERR_CONNECT:
4697c478bd9Sstevel@tonic-gate 		{
4707c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s\n",
4717c478bd9Sstevel@tonic-gate 				gettext("Failed to connect to LDAP server"));
4727c478bd9Sstevel@tonic-gate 			break;
4737c478bd9Sstevel@tonic-gate 		}
4747c478bd9Sstevel@tonic-gate 
4757c478bd9Sstevel@tonic-gate 		case NSL_ERR_BIND:
4767c478bd9Sstevel@tonic-gate 		{
4777c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext("LDAP bind failed\n"));
4787c478bd9Sstevel@tonic-gate 			break;
4797c478bd9Sstevel@tonic-gate 		}
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate 		case NSL_ERR_RENAME:
4827c478bd9Sstevel@tonic-gate 		{
4837c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s %s\n",
4847c478bd9Sstevel@tonic-gate 			    gettext("Object rename not allowed for printer:"),
4857c478bd9Sstevel@tonic-gate 			    printerName);
4867c478bd9Sstevel@tonic-gate 			break;
4877c478bd9Sstevel@tonic-gate 		}
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 		case NSL_ERR_KVP:
4907c478bd9Sstevel@tonic-gate 		{
4917c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s",
4927c478bd9Sstevel@tonic-gate 			    gettext("Setting sun-printer-kvp attribute is "
4937c478bd9Sstevel@tonic-gate 				"not supported through this command.\n"));
4947c478bd9Sstevel@tonic-gate 			break;
4957c478bd9Sstevel@tonic-gate 		}
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate 		case NSL_ERR_BSDADDR:
4987c478bd9Sstevel@tonic-gate 		{
4997c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s",
5007c478bd9Sstevel@tonic-gate 			    gettext("Setting sun-printer-bsdaddr attribute is "
5017c478bd9Sstevel@tonic-gate 				"not supported through this command.\n"
5027c478bd9Sstevel@tonic-gate 				"Use the bsaddr attribute instead.\n"));
5037c478bd9Sstevel@tonic-gate 			break;
5047c478bd9Sstevel@tonic-gate 		}
5057c478bd9Sstevel@tonic-gate 
5067c478bd9Sstevel@tonic-gate 		case NSL_ERR_PNAME:
5077c478bd9Sstevel@tonic-gate 		{
5087c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s",
5097c478bd9Sstevel@tonic-gate 			    gettext("Setting printer-name attribute is "
5107c478bd9Sstevel@tonic-gate 				"not supported through this command.\n"));
5117c478bd9Sstevel@tonic-gate 			break;
5127c478bd9Sstevel@tonic-gate 		}
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate 		case NSL_ERR_MEMORY:
5157c478bd9Sstevel@tonic-gate 		{
5167c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
5177c478bd9Sstevel@tonic-gate 					gettext("Memory allocation error\n"));
5187c478bd9Sstevel@tonic-gate 			break;
5197c478bd9Sstevel@tonic-gate 		}
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate 		case NSL_ERR_MULTIOP:
5227c478bd9Sstevel@tonic-gate 		{
5237c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
5247c478bd9Sstevel@tonic-gate 				gettext("Delete and add operation on the "
5257c478bd9Sstevel@tonic-gate 					"same key attribute is not allowed\n"));
5267c478bd9Sstevel@tonic-gate 			break;
5277c478bd9Sstevel@tonic-gate 		}
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate 		case NSL_ERR_NOTALLOWED:
5307c478bd9Sstevel@tonic-gate 		{
5317c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
5327c478bd9Sstevel@tonic-gate 				gettext("KVP attribute is not allowed\n"));
5337c478bd9Sstevel@tonic-gate 			break;
5347c478bd9Sstevel@tonic-gate 		}
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate 		default:
5377c478bd9Sstevel@tonic-gate 		{
5387c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
5397c478bd9Sstevel@tonic-gate 					gettext("Error code = %d\n"), result);
5407c478bd9Sstevel@tonic-gate 			break;
5417c478bd9Sstevel@tonic-gate 		}
5427c478bd9Sstevel@tonic-gate 	}
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate } /* _decode_ldapResult */
545