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