/*-
* Copyright (c) 2004-2006 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Luke Mewburn.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <netinet/in.h> /* for INET6_ADDRSTRLEN */
#include <rpc/rpcent.h>
#include <disktab.h>
static int usage(void) __attribute__((__noreturn__));
static int parsenum(const char *, unsigned long *);
static int disktab(int, char *[]);
static int gettytab(int, char *[]);
static int ethers(int, char *[]);
static int group(int, char *[]);
static int hosts(int, char *[]);
static int netgroup(int, char *[]);
static int networks(int, char *[]);
static int passwd(int, char *[]);
static int printcap(int, char *[]);
static int protocols(int, char *[]);
static int rpc(int, char *[]);
static int services(int, char *[]);
static int shells(int, char *[]);
switch (error = cgetent(&buf, db_array, name)) {
case -3:
warnx("tc= loop in record `%s' in `%s'", name, db_array[0]);
break;
case -2:
warn("system error fetching record `%s' in `%s'", name,
db_array[0]);
break;
case -1:
case 0:
break;
case 1:
warnx("tc= reference not found in record for `%s' in `%s'",
name, db_array[0]);
break;
default:
warnx("unknown error %d in record `%s' in `%s'", error, name,
db_array[0]);
break;
}
return buf;
}
static char *
mygetone(const char * const * db_array, int first)
{
char *buf = NULL;
int error;
switch (error = (first ? cgetfirst : cgetnext)(&buf, db_array)) {
case -2:
warnx("tc= loop in `%s'", db_array[0]);
break;
case -1:
warn("system error fetching record in `%s'", db_array[0]);
break;
case 0:
case 1:
break;
case 2:
warnx("tc= reference not found in `%s'", db_array[0]);
break;
default:
warnx("unknown error %d in `%s'", error, db_array[0]);
break;
}
return buf;
}
static void
capprint(const char *cap)
{
char *c = strchr(cap, ':');
if (c)
if (c == cap)
(void)printf("true\n");
else {
int l = (int)(c - cap);
(void)printf("%*.*s\n", l, l, cap);
}
else
(void)printf("%s\n", cap);
}
static void
prettyprint(char *b)
{
#define TERMWIDTH 65
int did = 0;
size_t len;
char *s, c;
for (;;) {
len = strlen(b);
if (len <= TERMWIDTH) {
done:
if (did)
printf("\t:");
printf("%s\n", b);
return;
}
for (s = b + TERMWIDTH; s > b && *s != ':'; s--)
continue;
if (*s++ != ':')
goto done;
c = *s;
*s = '\0';
if (did)
printf("\t:");
did++;
printf("%s\\\n", b);
*s = c;
b = s;
}
}
static void
handleone(const char * const *db_array, char *b, int recurse, int pretty,
int level)
{
char *tc;
if (level && pretty)
printf("\n");
if (pretty)
prettyprint(b);
else
printf("%s\n", b);
if (!recurse || cgetstr(b, "tc", &tc) <= 0)
return;