Add support for netgroup, based on patch in the PR but made consistent

with existing style.

PR:		bin/132692
This commit is contained in:
Guy Helmer 2013-05-23 20:52:30 +00:00
parent 601848d2b2
commit 08ad1a7ac6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=250942

View File

@ -61,6 +61,7 @@ static int parsenum(const char *, unsigned long *);
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 protocols(int, char *[]);
@ -89,6 +90,7 @@ static struct getentdb {
{ "rpc", rpc, },
{ "services", services, },
{ "shells", shells, },
{ "netgroup", netgroup, },
{ "utmpx", utmpx, },
{ NULL, NULL, },
@ -570,6 +572,47 @@ shells(int argc, char *argv[])
return rv;
}
/*
* netgroup
*/
static int
netgroup(int argc, char *argv[])
{
char *host, *user, *domain;
int first;
int rv, i;
assert(argc > 1);
assert(argv != NULL);
#define NETGROUPPRINT(s) (((s) != NULL) ? (s) : "")
rv = RV_OK;
if (argc == 2) {
fprintf(stderr, "Enumeration not supported on netgroup\n");
rv = RV_NOENUM;
} else {
for (i = 2; i < argc; i++) {
setnetgrent(argv[i]);
first = 1;
while (getnetgrent(&host, &user, &domain) != 0) {
if (first) {
first = 0;
(void)fputs(argv[i], stdout);
}
(void)printf(" (%s,%s,%s)",
NETGROUPPRINT(host),
NETGROUPPRINT(user),
NETGROUPPRINT(domain));
}
if (!first)
(void)putchar('\n');
endnetgrent();
}
}
return rv;
}
/*
* utmpx
*/