xref: /netbsd-src/usr.bin/innetgr/innetgr.c (revision e7afde8f0f4d5721d2d8b6539e609f46368a961f)
1*e7afde8fSdholland /*	$NetBSD: innetgr.c,v 1.10 2016/09/03 05:50:06 dholland Exp $	*/
27a3f6c58Schristos 
37a3f6c58Schristos /*-
47a3f6c58Schristos  * Copyright (c) 1999 The NetBSD Foundation, Inc.
57a3f6c58Schristos  * All rights reserved.
67a3f6c58Schristos  *
77a3f6c58Schristos  * This code is derived from software contributed to The NetBSD Foundation
87a3f6c58Schristos  * by Christos Zoulas.
97a3f6c58Schristos  *
107a3f6c58Schristos  * Redistribution and use in source and binary forms, with or without
117a3f6c58Schristos  * modification, are permitted provided that the following conditions
127a3f6c58Schristos  * are met:
137a3f6c58Schristos  * 1. Redistributions of source code must retain the above copyright
147a3f6c58Schristos  *    notice, this list of conditions and the following disclaimer.
157a3f6c58Schristos  * 2. Redistributions in binary form must reproduce the above copyright
167a3f6c58Schristos  *    notice, this list of conditions and the following disclaimer in the
177a3f6c58Schristos  *    documentation and/or other materials provided with the distribution.
187a3f6c58Schristos  *
197a3f6c58Schristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
207a3f6c58Schristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
217a3f6c58Schristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
227a3f6c58Schristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
237a3f6c58Schristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
247a3f6c58Schristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
257a3f6c58Schristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
267a3f6c58Schristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
277a3f6c58Schristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
287a3f6c58Schristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
297a3f6c58Schristos  * POSSIBILITY OF SUCH DAMAGE.
307a3f6c58Schristos  */
317a3f6c58Schristos 
327a3f6c58Schristos #include <sys/cdefs.h>
33*e7afde8fSdholland __RCSID("$NetBSD: innetgr.c,v 1.10 2016/09/03 05:50:06 dholland Exp $");
347a3f6c58Schristos 
357a3f6c58Schristos #include <stdio.h>
36fcd0fb11Smatt #include <stdlib.h>
377a3f6c58Schristos #include <unistd.h>
387a3f6c58Schristos #include <netgroup.h>
397a3f6c58Schristos 
40*e7afde8fSdholland static __dead void
usage(void)41d34c2845Smatt usage(void)
427a3f6c58Schristos {
43a8ec668dScgd 
447a3f6c58Schristos 	(void)fprintf(stderr,
45d771b2e2Swiz 	    "usage: %s [-v] [-d domain] [-h host] [-u user] netgroup\n",
46a8ec668dScgd 	    getprogname());
477a3f6c58Schristos 	exit(2);
487a3f6c58Schristos }
497a3f6c58Schristos 
507a3f6c58Schristos int
main(int argc,char * argv[])51d34c2845Smatt main(int argc, char *argv[])
527a3f6c58Schristos {
537a3f6c58Schristos 	int c, ok, verbose = 0;
547a3f6c58Schristos 	char *user = NULL;
557a3f6c58Schristos 	char *host = NULL;
567a3f6c58Schristos 	char *domain = NULL;
577a3f6c58Schristos 
587a3f6c58Schristos 	while ((c = getopt(argc, argv, "h:u:d:v")) != -1)
597a3f6c58Schristos 		switch (c) {
607a3f6c58Schristos 		case 'u':
617a3f6c58Schristos 		   	user = optarg;
627a3f6c58Schristos 			break;
637a3f6c58Schristos 		case 'h':
647a3f6c58Schristos 			host = optarg;
657a3f6c58Schristos 			break;
667a3f6c58Schristos 		case 'd':
677a3f6c58Schristos 			domain = optarg;
687a3f6c58Schristos 			break;
697a3f6c58Schristos 		case 'v':
707a3f6c58Schristos 			verbose = 1;
717a3f6c58Schristos 			break;
727a3f6c58Schristos 		default:
737a3f6c58Schristos 			usage();
747a3f6c58Schristos 		}
757a3f6c58Schristos 
767a3f6c58Schristos 	if (optind >= argc)
777a3f6c58Schristos 		usage();
787a3f6c58Schristos 
797a3f6c58Schristos 	for(; optind < argc; optind++) {
807a3f6c58Schristos 		ok = innetgr(argv[optind], host, user, domain);
817a3f6c58Schristos 		if (verbose)
827a3f6c58Schristos 			printf("%s: %d\n", argv[optind], ok);
837a3f6c58Schristos 		if (ok)
847a3f6c58Schristos 			return 0;
857a3f6c58Schristos 	}
867a3f6c58Schristos 	return 1;
877a3f6c58Schristos }
88