1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
14 */
15
16 /*
17 * Test program for files / netgroup support
18 */
19
20 #include <netdb.h>
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 static int verbose;
27
28 /*
29 * Debug magic! See lib/nsswitch/files/common/getnetgrent.c
30 */
31
32 void
33 __nss_files_netgr_debug(const char *fmt, ...)
34 {
35 va_list ap;
36
37 if (!verbose)
38 return;
39
40 va_start(ap, fmt);
41 (void) printf("debug: ");
42 (void) vprintf(fmt, ap);
43 (void) printf("\n");
44 va_end(ap);
45 }
46
47 void
48 __nss_files_netgr_error(const char *fmt, ...)
49 {
50 va_list ap;
51
52 va_start(ap, fmt);
53 (void) printf("error: ");
54 (void) vprintf(fmt, ap);
55 (void) printf("\n");
56 va_end(ap);
57 }
58
59 void
60 usage(char *prog)
61 {
62 (void) fprintf(stderr,
63 "usage: %s [-v] [-h host] [-u user] [-d domain] netgroup\n", prog);
64 exit(1);
65 }
66
67 int
68 main(int argc, char **argv)
69 {
70 char *netgrname;
71 char *host = NULL;
72 char *user = NULL;
73 char *dom = NULL;
74 int c, rc;
75
76 while ((c = getopt(argc, argv, "vh:u:d:")) != EOF) {
77 switch (c) {
78 case 'v':
79 verbose++;
80 break;
81 case 'h':
82 host = optarg;
83 break;
84 case 'u':
85 user = optarg;
86 break;
87 case 'd':
88 dom = optarg;
89 break;
90 case '?':
91 usage(argv[0]);
92 }
93 }
94
95 if ((optind + 1) != argc)
96 usage(argv[0]);
97 netgrname = argv[optind];
98
99 rc = innetgr(netgrname, host, user, dom);
100 (void) printf("%s\n", (rc) ? "yes" : "no");
101
102 #ifdef lint
103 __nss_files_netgr_debug("");
104 __nss_files_netgr_error("");
105 #endif
106
107 return (0);
108 }