lpset.c revision 53ac4dca2d62281a883fb28d174b000643cd3bfa
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>
#include <syslog.h>
#include <errno.h>
#include <locale.h>
#ifndef SUNOS_4
#include <libintl.h>
#endif
#include <pwd.h>
#include <ns.h>
#include <misc.h>
#include <list.h>
extern char *optarg;
extern char *getenv(const char *);
static int
{
int len;
return (1); /* "root" is authorized */
return (1); /* "lp" is authorized */
return (0); /* intruders are not authorized */
return (1); /* "solaris.print.admin" is authorized */
return (1); /* group 14 is authorized */
return (0); /* nobody else is authorized */
}
static void
{
gettext("Usage: %s [-n files | nisplus | ldap] [-x] "
"[-h ldaphost] [-D binddn] [-w passwd] "
"[-a key=value] [-d key] (printer)\n"),
name);
exit(1);
}
/*
* main() calls the appropriate routine to parse the command line arguments
* and then calls the local remove routine, followed by the remote remove
* routine to remove jobs.
*/
int
{
int result = 0;
int delete_printer = 0;
int c;
*ons = "files";
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
else
program++;
if (ac < 2)
switch (c) {
case 'd':
/* FALLTHRU */
case 'a':
break;
case 'D':
break;
case 'h':
break;
case 'n':
break;
case 'r':
break;
case 'w':
break;
case 'x':
break;
default:
}
/*
* Check required options have been given: [ -x | [ -a | -d ]]
*/
}
"POSIX-Style names are not valid destinations (%s)\n"),
printer);
return (1);
}
/* check / set the name service for writing */
ons = "user";
if (authorized() == 0) {
"Permission denied: not authorized\n"));
return (1);
}
ons = "files";
ons = "nisplus";
gettext("could not initialize credential\n"));
return (1);
}
gettext("Distinguished Name is required.\n"));
return (1);
}
}
/*
* Setup LDAP bind credentials, so that it uses
* the default ldap port, and the NS domain for this
* ldapclient box. Note: passwdType is currently not
* used but once the ldap native function can select
* secure or insure password it will pass the user selected
* security type.
*/
ons = "ldap";
} else {
gettext("%s is not a supported name service.\n"),
ons);
return (1);
}
/* Naming Service is not LDAP */
/* get the printer object */
if (delete_printer != 0) {
printer);
return (1);
}
"could not initialize printer object\n"));
return (1);
}
}
}
/* make the changes to it */
if (*p == '=') {
*p = NULL;
value = ++p;
break;
} else if (*p == '\\')
p++;
(has_equals == 0)) {
gettext("%s: unknown attribute\n"),
key);
result = 1;
} else
}
}
if (delete_printer != 0)
/* write it back */
if (ns_printer_put(printer_obj) != 0) {
gettext("Failed to write into %s database\n"),
ons);
result = 1;
}
}
else {
/*
* Naming Service is LDAP
*
* Action the request by calling ns ldap functions to
* add, modify or delete the printer object.
*/
"could not initialize printer object\n"));
return (1);
}
/*
* Update the LDAP directory for this printer
*/
if (delete_printer != 0) {
/* Delete the printer object */
((NS_LDAPDATA *)
} else {
/* Add or modify the printer object */
((NS_LDAPDATA *)
}
if (result != 0) {
/* display LDAP specific message */
"Failed to update %s database\n"), ons);
result = 1;
}
}
else {
result = 1;
}
}
else {
result = 1;
gettext("Error - no LDAP credentials\n"));
}
if (printer_obj != NULL) {
}
}
}
return (result);
} /* main */
/*
* *****************************************************************************
*
* Function: _decode_ldapResult()
*
* Description: Decode the ldap_put_printer specific error codes and display
* the appropriate error message.
*
* Parameters:
* Input: int result - contains the NSL_RESULT codes
* char *printerName - name of printer
* Output: None
*
* Returns: void
*
* *****************************************************************************
*/
static void
{
/* ------------- */
switch (lresult)
{
case NSL_OK:
{
break;
}
case NSL_ERR_INTERNAL:
{
gettext("Unexpected software error\n"));
break;
}
case NSL_ERR_ADD_FAILED:
{
break;
}
case NSL_ERR_MOD_FAILED:
{
gettext("Failed to modify printer:"),
break;
}
case NSL_ERR_DEL_FAILED:
{
gettext("Failed to delete printer:"),
break;
}
case NSL_ERR_UNKNOWN_PRINTER:
{
break;
}
case NSL_ERR_CREDENTIALS:
{
gettext("Missing LDAP credential information for printer:"));
break;
}
case NSL_ERR_CONNECT:
{
gettext("Failed to connect to LDAP server"));
break;
}
case NSL_ERR_BIND:
{
break;
}
case NSL_ERR_RENAME:
{
gettext("Object rename not allowed for printer:"),
break;
}
case NSL_ERR_KVP:
{
gettext("Setting sun-printer-kvp attribute is "
"not supported through this command.\n"));
break;
}
case NSL_ERR_BSDADDR:
{
gettext("Setting sun-printer-bsdaddr attribute is "
"not supported through this command.\n"
"Use the bsaddr attribute instead.\n"));
break;
}
case NSL_ERR_PNAME:
{
gettext("Setting printer-name attribute is "
"not supported through this command.\n"));
break;
}
case NSL_ERR_MEMORY:
{
gettext("Memory allocation error\n"));
break;
}
case NSL_ERR_MULTIOP:
{
gettext("Delete and add operation on the "
"same key attribute is not allowed\n"));
break;
}
case NSL_ERR_NOTALLOWED:
{
gettext("KVP attribute is not allowed\n"));
break;
}
default:
{
break;
}
}
} /* _decode_ldapResult */