lpsystem.c revision e2738c5e21a9e5d9a6525e48af4738deda3df455
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.8 */
/*==================================================================*/
/*
*/
#include <stdio.h>
#include <tiuser.h>
#include <netconfig.h>
#include <netdir.h>
#include <locale.h>
#include "lp.h"
#include "systems.h"
#include "msgs.h"
#include "boolean.h"
#include "access.h"
#define WHO_AM_I I_AM_LPSYSTEM
#include "oam.h"
#define DEFAULT_TIMEOUT -1
#define DEFAULT_RETRY 10
static int Timeout;
static int Retry;
static char *Sysnamep;
static char *Protocolp;
static char *Timeoutp;
static char *Retryp;
static char *Commentp;
#ifdef __STDC__
static void SecurityCheck (void);
static void TcpIpAddress (void);
static void ListSystems (char * []);
static void RemoveSystems (char * []);
static void AddModifySystems (char * []);
static void usage (void);
#else
static void SecurityCheck ();
static void TcpIpAddress ();
static void ListSystems ();
static void RemoveSystems ();
static void AddModifySystems ();
static void formatsys ();
static void usage ();
#endif
/*==================================================================*/
/*==================================================================*/
/*
*/
#ifdef __STDC__
int
#else
int
int argc;
char *argv [];
#endif
{
int c;
badOptions = False;
extern int opterr,
extern char *optarg;
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
if (argc == 1) {
usage();
exit(1);
}
switch (c & 0xFF)
{
case 't':
if (Protocolp)
{
gettext("ERROR: Too many -t options.\n"));
return 1;
}
{
return 1;
}
break;
case 'T':
if (Timeoutp)
{
gettext("ERROR: Too many -T options.\n"));
return 1;
}
if (*Timeoutp == 'n')
Timeout = -1;
else
{
gettext("ERROR: Bad timeout argument: %s\n"),
Timeoutp);
return 1;
}
break;
case 'R':
if (Retryp)
{
gettext("ERROR: Too many -R options.\n"));
return 1;
}
if (*Retryp == 'n')
Retry = -1;
else
{
return 1;
}
break;
case 'y':
if (Commentp)
{
gettext("ERROR: Too many -y options.\n"));
return 1;
}
break;
case 'l':
if (lflag)
{
gettext("ERROR: Too many -l options.\n"));
return 1;
}
lflag++;
break;
case 'r':
if (rflag)
{
gettext("ERROR: Too many -r options.\n"));
return 1;
}
rflag++;
break;
case 'A':
if (Aflag)
{
gettext("ERROR: Too many -A options.\n"));
return 1;
}
Aflag++;
break;
default:
return 1;
case '?':
usage ();
return 1;
}
/*
** Check for valid option combinations.
**
** The '-A' option is mutually exclusive.
** The '-l' option is mutually exclusive.
** The '-r' option is mutually exclusive.
*/
badOptions = True;
if (lflag &&
badOptions = True;
badOptions = True;
if (badOptions)
{
return 1;
}
/*
** Lets do some processing.
** We'll start with the flags.
*/
if (Aflag)
{
TcpIpAddress ();
/*NOTREACHED*/
}
if (lflag)
{
/*NOTREACHED*/
}
if (rflag)
{
/*NOTREACHED*/
}
return 0;
}
/*==================================================================*/
/*==================================================================*/
/*
*/
#ifdef __STDC__
static void
SecurityCheck (void)
#else
static void
#endif
{
/* On labeled systems check that user has print admin authorization */
if (is_system_labeled()) {
if (is_user_admin() == 0) {
"You are not authorized to administer printing.\n"\
));
(void) exit (1);
}
} else {
if (geteuid () != 0)
{
gettext("ERROR: You must be root.\n"));
(void) exit (1);
}
}
}
/*==================================================================*/
/*==================================================================*/
/*
*/
#ifdef __STDC__
static void
TcpIpAddress (void)
#else
static void
TcpIpAddress ()
#endif
{
int i;
struct nd_hostserv hostserv;
struct nd_addrlist *addrsp;
struct netconfig *getnetconfigent ();
if (! configp)
{
/*
** (void) fprintf (stderr,
*/
(void) exit (2);
}
{
(void) perror ("netdir_getbyname");
(void) exit (2);
}
(void) printf ("\n");
(void) exit (0);
}
/*==================================================================*/
/*==================================================================*/
/*
*/
#ifdef __STDC__
static void
ListSystems (char *syslistp [])
#else
static void
char *syslistp [];
#endif
{
char *sysnamep;
if (! *syslistp)
{
}
else
{
{
gettext("WARNING: \"%s\" is a reserved word "
"and may not be used for a system name.\n"),
sysnamep);
continue;
}
{
gettext("WARNING: \"%s\" not found.\n"),
sysnamep);
continue;
}
}
(void) exit (0);
}
/*==================================================================*/
/*==================================================================*/
/*
*/
#ifdef __STDC__
static void
RemoveSystems (char *syslistp [])
#else
static void
char *syslistp [];
#endif
{
char *sysnamep;
SecurityCheck ();
{
(void) exit (1);
}
{
{
gettext("WARNING: \"%s\" is a reserved word "
"and may not be used for a system name.\n"),
sysnamep);
continue;
}
{
gettext("WARNING: \"%s\" not found.\n"),
sysnamep);
continue;
}
{
gettext("ERROR: Could not remove \"%s\".\n"),
sysnamep);
(void) exit (2);
}
else
sysnamep);
}
(void) exit (0);
}
/*==================================================================*/
/*==================================================================*/
/*
*/
#ifdef __STDC__
static void
AddModifySystems (char *syslistp [])
#else
static void
char *syslistp [];
#endif
{
char *sysnamep;
static SYSTEM DefaultSystem =
{
};
SecurityCheck ();
{
int changed = 0;
{
modifiedFlag = True;
}
else
{
}
if (Protocolp)
{
changed++;
}
if (Timeoutp)
{
changed++;
}
if (Retryp)
{
changed++;
}
if (Commentp)
{
changed++;
}
continue;
}
{
if (modifiedFlag) {
}else {
}
(void) exit (2);
}
if (modifiedFlag)
{
sysnamep);
}
else
{
sysnamep);
}
}
(void) exit (0);
}
/*==================================================================*/
/*==================================================================*/
/*
*/
#if defined(__STDC__)
static void
usage (void)
#else
static void
usage ()
#endif
{
gettext("Usage: lpsystem [ options ] [system-name ... ]\n"
"\nTo add or modify an existing system:\n"
" lpsystem [ -t type ] [ -T timeout ]\n"
" [ -R retry ] [ -y comment ] system-name ...\n"
"\nTo list a system (or all systems):\n"
" lpsystem -l [ system-name ...]\n"
"\nTo remove a system:\n"
" lpsystem -r system-name ...\n"
" lpsystem -A\n"));
}
/*==================================================================*/
/*==================================================================*/
/*
*/
#ifdef __STDC__
static void
#else
static void
#endif
{
else
else
(void) printf (
gettext("Retry failed connections: after %d minutes\n"),
else
(void) printf ("\n");
}
/*==================================================================*/