|
Packit |
6bd9ab |
/*
|
|
Packit |
6bd9ab |
lookup_netgroup.c - simple lookup code for netgroups
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
Copyright (C) 2012, 2013 Arthur de Jong
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
This library is free software; you can redistribute it and/or
|
|
Packit |
6bd9ab |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6bd9ab |
License as published by the Free Software Foundation; either
|
|
Packit |
6bd9ab |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
This library is distributed in the hope that it will be useful,
|
|
Packit |
6bd9ab |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6bd9ab |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6bd9ab |
Lesser General Public License for more details.
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6bd9ab |
License along with this library; if not, write to the Free Software
|
|
Packit |
6bd9ab |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit |
6bd9ab |
02110-1301 USA
|
|
Packit |
6bd9ab |
*/
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#include "config.h"
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#include <string.h>
|
|
Packit |
6bd9ab |
#include <stdio.h>
|
|
Packit |
6bd9ab |
#include <errno.h>
|
|
Packit |
6bd9ab |
#include <netdb.h>
|
|
Packit |
6bd9ab |
#include <stdlib.h>
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* the main program... */
|
|
Packit |
6bd9ab |
int main(int argc,char *argv[])
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
char *host, *user, *domain;
|
|
Packit |
6bd9ab |
/* check arguments */
|
|
Packit |
6bd9ab |
if (argc != 2)
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
fprintf(stderr, "Usage: %s NETGROUP\n", argv[0]);
|
|
Packit |
6bd9ab |
exit(EXIT_FAILURE);
|
|
Packit |
6bd9ab |
}
|
|
Packit |
6bd9ab |
/* start lookup */
|
|
Packit |
6bd9ab |
#ifdef SETNETGRENT_RETURNS_VOID
|
|
Packit |
6bd9ab |
setnetgrent(argv[1]);
|
|
Packit |
6bd9ab |
#else /* not SETNETGRENT_RETURNS_VOID */
|
|
Packit |
6bd9ab |
if (setnetgrent(argv[1]) != 0)
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
/* output nothing */
|
|
Packit |
6bd9ab |
exit(EXIT_FAILURE);
|
|
Packit |
6bd9ab |
}
|
|
Packit |
6bd9ab |
#endif /* not SETNETGRENT_RETURNS_VOID */
|
|
Packit |
6bd9ab |
fprintf(stdout, "%-20s", argv[1]);
|
|
Packit |
6bd9ab |
while (getnetgrent(&host, &user, &domain) != 0)
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
fprintf(stdout, " (%s, %s, %s)", host, user, domain);
|
|
Packit |
6bd9ab |
}
|
|
Packit |
6bd9ab |
fprintf(stdout, "\n");
|
|
Packit |
6bd9ab |
endnetgrent();
|
|
Packit |
6bd9ab |
return 0;
|
|
Packit |
6bd9ab |
}
|