Remove building with NOCRYPTO option
[minix3.git] / lib / libc / gen / getnetgrent.c
blob410ef1c7bca3534edf7b8f91297af249776ad1bd
1 /* $NetBSD: getnetgrent.c,v 1.42 2012/03/20 16:36:05 matt Exp $ */
3 /*
4 * Copyright (c) 1994 Christos Zoulas
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 #if defined(LIBC_SCCS) && !defined(lint)
31 __RCSID("$NetBSD: getnetgrent.c,v 1.42 2012/03/20 16:36:05 matt Exp $");
32 #endif /* LIBC_SCCS and not lint */
34 #include "namespace.h"
35 #include <sys/types.h>
37 #include <assert.h>
38 #include <ctype.h>
39 #include <db.h>
40 #include <err.h>
41 #include <fcntl.h>
42 #define _NETGROUP_PRIVATE
43 #include <stringlist.h>
44 #include <netgroup.h>
45 #include <nsswitch.h>
46 #include <stdarg.h>
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <string.h>
51 #ifdef YP
52 #include <rpc/rpc.h>
53 #include <rpcsvc/ypclnt.h>
54 #include <rpcsvc/yp_prot.h>
55 #endif
57 #ifdef __weak_alias
58 __weak_alias(endnetgrent,_endnetgrent)
59 __weak_alias(getnetgrent,_getnetgrent)
60 __weak_alias(innetgr,_innetgr)
61 __weak_alias(setnetgrent,_setnetgrent)
62 #endif
64 #define _NG_STAR(s) (((s) == NULL || *(s) == '\0') ? _ngstar : s)
65 #define _NG_EMPTY(s) ((s) == NULL ? "" : s)
66 #define _NG_ISSPACE(p) (isspace((unsigned char) (p)) || (p) == '\n')
68 static const char _ngstar[] = "*";
69 static struct netgroup *_nghead = NULL;
70 static struct netgroup *_nglist = NULL;
71 static DB *_ng_db;
73 static int getstring(char **, int, __aconst char **);
74 static struct netgroup *getnetgroup(char **);
75 static int lookup(char *, char **, int);
76 static int addgroup(StringList *, char *);
77 static int in_check(const char *, const char *, const char *,
78 struct netgroup *);
79 static int in_find(StringList *, char *, const char *, const char *,
80 const char *);
81 static char *in_lookup1(const char *, const char *, int);
82 static int in_lookup(const char *, const char *, const char *, int);
84 #ifdef NSSRC_FILES
85 static const ns_src default_files_nis[] = {
86 { NSSRC_FILES, NS_SUCCESS | NS_NOTFOUND },
87 #ifdef YP
88 { NSSRC_NIS, NS_SUCCESS },
89 #endif
90 { 0, 0 },
92 #endif
95 * getstring(): Get a string delimited by the character, skipping leading and
96 * trailing blanks and advancing the pointer
98 static int
99 getstring(char **pp, int del, char __aconst **str)
101 size_t len;
102 char *sp, *ep, *dp;
104 _DIAGASSERT(pp != NULL);
105 _DIAGASSERT(str != NULL);
107 /* skip leading blanks */
108 for (sp = *pp; *sp && _NG_ISSPACE(*sp); sp++)
109 continue;
111 /* accumulate till delimiter or space */
112 for (ep = sp; *ep && *ep != del && !_NG_ISSPACE(*ep); ep++)
113 continue;
115 /* hunt for the delimiter */
116 for (dp = ep; *dp && *dp != del && _NG_ISSPACE(*dp); dp++)
117 continue;
119 if (*dp != del) {
120 *str = NULL;
121 return 0;
124 *pp = ++dp;
126 len = (ep - sp) + 1;
127 if (len > 1) {
128 dp = malloc(len);
129 if (dp == NULL)
130 return 0;
131 (void)memcpy(dp, sp, len);
132 dp[len - 1] = '\0';
133 } else
134 dp = NULL;
136 *str = dp;
137 return 1;
142 * getnetgroup(): Parse a netgroup, and advance the pointer
144 static struct netgroup *
145 getnetgroup(char **pp)
147 struct netgroup *ng;
149 _DIAGASSERT(pp != NULL);
150 _DIAGASSERT(*pp != NULL);
152 ng = malloc(sizeof(struct netgroup));
153 if (ng == NULL)
154 return NULL;
156 (*pp)++; /* skip '(' */
157 if (!getstring(pp, ',', &ng->ng_host))
158 goto badhost;
160 if (!getstring(pp, ',', &ng->ng_user))
161 goto baduser;
163 if (!getstring(pp, ')', &ng->ng_domain))
164 goto baddomain;
166 #ifdef DEBUG_NG
168 char buf[1024];
169 (void) fprintf(stderr, "netgroup %s\n",
170 _ng_print(buf, sizeof(buf), ng));
172 #endif
173 return ng;
175 baddomain:
176 if (ng->ng_user)
177 free(ng->ng_user);
178 baduser:
179 if (ng->ng_host)
180 free(ng->ng_host);
181 badhost:
182 free(ng);
183 return NULL;
186 void
187 _ng_cycle(const char *grp, const StringList *sl)
189 size_t i;
190 warnx("netgroup: Cycle in group `%s'", grp);
191 (void)fprintf(stderr, "groups: ");
192 for (i = 0; i < sl->sl_cur; i++)
193 (void)fprintf(stderr, "%s ", sl->sl_str[i]);
194 (void)fprintf(stderr, "\n");
197 static int _local_lookup(void *, void *, va_list);
199 /*ARGSUSED*/
200 static int
201 _local_lookup(void *rv, void *cb_data, va_list ap)
203 char *name = va_arg(ap, char *);
204 char **line = va_arg(ap, char **);
205 int bywhat = va_arg(ap, int);
207 DBT key, data;
208 size_t len;
209 char *ks;
210 int r;
212 if (_ng_db == NULL)
213 return NS_UNAVAIL;
215 len = strlen(name) + 2;
216 ks = malloc(len);
217 if (ks == NULL)
218 return NS_UNAVAIL;
220 ks[0] = bywhat;
221 (void)memcpy(&ks[1], name, len - 1);
223 key.data = (u_char *)ks;
224 key.size = len;
226 r = (*_ng_db->get)(_ng_db, &key, &data, 0);
227 free(ks);
228 switch (r) {
229 case 0:
230 break;
231 case 1:
232 return NS_NOTFOUND;
233 case -1:
234 /* XXX: call endnetgrent() here ? */
235 return NS_UNAVAIL;
238 *line = strdup(data.data);
239 if (*line == NULL)
240 return NS_UNAVAIL;
241 return NS_SUCCESS;
244 #ifdef YP
245 static int _nis_lookup(void *, void *, va_list);
247 /*ARGSUSED*/
248 static int
249 _nis_lookup(void *rv, void *cb_data, va_list ap)
251 char *name = va_arg(ap, char *);
252 char **line = va_arg(ap, char **);
253 int bywhat = va_arg(ap, int);
255 static char *__ypdomain;
256 int i;
257 const char *map = NULL;
259 if(__ypdomain == NULL) {
260 switch (yp_get_default_domain(&__ypdomain)) {
261 case 0:
262 break;
263 case YPERR_RESRC:
264 return NS_TRYAGAIN;
265 default:
266 return NS_UNAVAIL;
270 switch (bywhat) {
271 case _NG_KEYBYNAME:
272 map = "netgroup";
273 break;
275 case _NG_KEYBYUSER:
276 map = "netgroup.byuser";
277 break;
279 case _NG_KEYBYHOST:
280 map = "netgroup.byhost";
281 break;
283 default:
284 abort();
287 *line = NULL;
288 switch (yp_match(__ypdomain, map, name, (int)strlen(name), line, &i)) {
289 case 0:
290 return NS_SUCCESS;
291 case YPERR_KEY:
292 if (*line)
293 free(*line);
294 return NS_NOTFOUND;
295 default:
296 if (*line)
297 free(*line);
298 return NS_UNAVAIL;
300 /* NOTREACHED */
302 #endif
304 #ifdef NSSRC_FILES
306 * lookup(): Find the given key in the database or yp, and return its value
307 * in *line; returns 1 if key was found, 0 otherwise
309 static int
310 lookup(char *name, char **line, int bywhat)
312 int r;
313 static const ns_dtab dtab[] = {
314 NS_FILES_CB(_local_lookup, NULL)
315 NS_NIS_CB(_nis_lookup, NULL)
316 NS_NULL_CB
319 _DIAGASSERT(name != NULL);
320 _DIAGASSERT(line != NULL);
322 r = nsdispatch(NULL, dtab, NSDB_NETGROUP, "lookup", default_files_nis,
323 name, line, bywhat);
324 return (r == NS_SUCCESS) ? 1 : 0;
326 #else
327 static int
328 _local_lookupv(int *rv, void *cbdata, ...)
330 int e;
331 va_list ap;
332 va_start(ap, cbdata);
333 e = _local_lookup(rv, cbdata, ap);
334 va_end(ap);
335 return e;
338 static int
339 lookup(name, line, bywhat)
340 char *name;
341 char **line;
342 int bywhat;
344 return _local_lookupv(NULL, NULL, name, line, bywhat) == NS_SUCCESS;
346 #endif
349 * _ng_parse(): Parse a line and return: _NG_ERROR: Syntax Error _NG_NONE:
350 * line was empty or a comment _NG_GROUP: line had a netgroup definition,
351 * returned in ng _NG_NAME: line had a netgroup name, returned in name
353 * Public since used by netgroup_mkdb
356 _ng_parse(char **p, char **name, struct netgroup **ng)
359 _DIAGASSERT(p != NULL);
360 _DIAGASSERT(*p != NULL);
361 _DIAGASSERT(name != NULL);
362 _DIAGASSERT(ng != NULL);
364 while (**p) {
365 if (**p == '#')
366 /* comment */
367 return _NG_NONE;
369 while (**p && _NG_ISSPACE(**p))
370 /* skipblank */
371 (*p)++;
373 if (**p == '(') {
374 if ((*ng = getnetgroup(p)) == NULL)
375 return _NG_ERROR;
376 return _NG_GROUP;
377 } else {
378 char *np;
379 size_t i;
381 for (np = *p; **p && !_NG_ISSPACE(**p); (*p)++)
382 continue;
383 if (np != *p) {
384 i = (*p - np) + 1;
385 *name = malloc(i);
386 if (*name == NULL)
387 return _NG_ERROR;
388 (void)memcpy(*name, np, i);
389 (*name)[i - 1] = '\0';
390 return _NG_NAME;
394 return _NG_NONE;
399 * addgroup(): Recursively add all the members of the netgroup to this group.
400 * returns 0 upon failure, nonzero upon success.
401 * grp is not a valid pointer after return (either free(3)ed or allocated
402 * to a stringlist). in either case, it shouldn't be used again.
404 static int
405 addgroup(StringList *sl, char *grp)
407 char *line, *p;
408 struct netgroup *ng;
409 char *name;
411 _DIAGASSERT(sl != NULL);
412 _DIAGASSERT(grp != NULL);
414 #ifdef DEBUG_NG
415 (void)fprintf(stderr, "addgroup(%s)\n", grp);
416 #endif
417 /* check for cycles */
418 if (sl_find(sl, grp) != NULL) {
419 _ng_cycle(grp, sl);
420 free(grp);
421 return 0;
423 if (sl_add(sl, grp) == -1) {
424 free(grp);
425 return 0;
428 /* Lookup this netgroup */
429 line = NULL;
430 if (!lookup(grp, &line, _NG_KEYBYNAME)) {
431 if (line)
432 free(line);
433 return 0;
436 p = line;
438 for (;;) {
439 switch (_ng_parse(&p, &name, &ng)) {
440 case _NG_NONE:
441 /* Done with the line */
442 free(line);
443 return 1;
445 case _NG_GROUP:
446 /* new netgroup */
447 /* add to the list */
448 ng->ng_next = _nglist;
449 _nglist = ng;
450 break;
452 case _NG_NAME:
453 /* netgroup name */
454 if (!addgroup(sl, name))
455 return 0;
456 break;
458 case _NG_ERROR:
459 return 0;
461 default:
462 abort();
469 * in_check(): Compare the spec with the netgroup
471 static int
472 in_check(const char *host, const char *user, const char *domain,
473 struct netgroup *ng)
476 /* host may be NULL */
477 /* user may be NULL */
478 /* domain may be NULL */
479 _DIAGASSERT(ng != NULL);
481 if ((host != NULL) && (ng->ng_host != NULL)
482 && strcmp(ng->ng_host, host) != 0)
483 return 0;
485 if ((user != NULL) && (ng->ng_user != NULL)
486 && strcmp(ng->ng_user, user) != 0)
487 return 0;
489 if ((domain != NULL) && (ng->ng_domain != NULL)
490 && strcmp(ng->ng_domain, domain) != 0)
491 return 0;
493 return 1;
498 * in_find(): Find a match for the host, user, domain spec.
499 * grp is not a valid pointer after return (either free(3)ed or allocated
500 * to a stringlist). in either case, it shouldn't be used again.
502 static int
503 in_find(StringList *sl, char *grp, const char *host, const char *user,
504 const char *domain)
506 char *line, *p;
507 int i;
508 struct netgroup *ng;
509 char *name;
511 _DIAGASSERT(sl != NULL);
512 _DIAGASSERT(grp != NULL);
513 /* host may be NULL */
514 /* user may be NULL */
515 /* domain may be NULL */
517 #ifdef DEBUG_NG
518 (void)fprintf(stderr, "in_find(%s)\n", grp);
519 #endif
520 /* check for cycles */
521 if (sl_find(sl, grp) != NULL) {
522 _ng_cycle(grp, sl);
523 free(grp);
524 return 0;
526 if (sl_add(sl, grp) == -1) {
527 free(grp);
528 return 0;
531 /* Lookup this netgroup */
532 line = NULL;
533 if (!lookup(grp, &line, _NG_KEYBYNAME)) {
534 if (line)
535 free(line);
536 return 0;
539 p = line;
541 for (;;) {
542 switch (_ng_parse(&p, &name, &ng)) {
543 case _NG_NONE:
544 /* Done with the line */
545 free(line);
546 return 0;
548 case _NG_GROUP:
549 /* new netgroup */
550 i = in_check(host, user, domain, ng);
551 if (ng->ng_host != NULL)
552 free(ng->ng_host);
553 if (ng->ng_user != NULL)
554 free(ng->ng_user);
555 if (ng->ng_domain != NULL)
556 free(ng->ng_domain);
557 free(ng);
558 if (i) {
559 free(line);
560 return 1;
562 break;
564 case _NG_NAME:
565 /* netgroup name */
566 if (in_find(sl, name, host, user, domain)) {
567 free(line);
568 return 1;
570 break;
572 case _NG_ERROR:
573 free(line);
574 return 0;
576 default:
577 abort();
583 * _ng_makekey(): Make a key from the two names given. The key is of the form
584 * <name1>.<name2> Names strings are replaced with * if they are empty;
585 * Returns NULL if there's a problem.
587 char *
588 _ng_makekey(const char *s1, const char *s2, size_t len)
590 char *buf;
592 /* s1 may be NULL */
593 /* s2 may be NULL */
595 buf = malloc(len);
596 if (buf != NULL)
597 (void)snprintf(buf, len, "%s.%s", _NG_STAR(s1), _NG_STAR(s2));
598 return buf;
601 void
602 _ng_print(char *buf, size_t len, const struct netgroup *ng)
604 _DIAGASSERT(buf != NULL);
605 _DIAGASSERT(ng != NULL);
607 (void)snprintf(buf, len, "(%s,%s,%s)", _NG_EMPTY(ng->ng_host),
608 _NG_EMPTY(ng->ng_user), _NG_EMPTY(ng->ng_domain));
613 * in_lookup1(): Fast lookup for a key in the appropriate map
615 static char *
616 in_lookup1(const char *key, const char *domain, int map)
618 char *line;
619 size_t len;
620 char *ptr;
621 int res;
623 /* key may be NULL */
624 /* domain may be NULL */
626 len = (key ? strlen(key) : 1) + (domain ? strlen(domain) : 1) + 2;
627 ptr = _ng_makekey(key, domain, len);
628 if (ptr == NULL)
629 return NULL;
630 res = lookup(ptr, &line, map);
631 free(ptr);
632 return res ? line : NULL;
637 * in_lookup(): Fast lookup for a key in the appropriate map
639 static int
640 in_lookup(const char *group, const char *key, const char *domain, int map)
642 size_t len;
643 char *ptr, *line;
645 _DIAGASSERT(group != NULL);
646 /* key may be NULL */
647 /* domain may be NULL */
649 if (domain != NULL) {
650 /* Domain specified; look in "group.domain" and "*.domain" */
651 if ((line = in_lookup1(key, domain, map)) == NULL)
652 line = in_lookup1(NULL, domain, map);
653 } else
654 line = NULL;
656 if (line == NULL) {
658 * domain not specified or domain lookup failed; look in
659 * "group.*" and "*.*"
661 if (((line = in_lookup1(key, NULL, map)) == NULL) &&
662 ((line = in_lookup1(NULL, NULL, map)) == NULL))
663 return 0;
666 len = strlen(group);
668 for (ptr = line; (ptr = strstr(ptr, group)) != NULL;)
669 /* Make sure we did not find a substring */
670 if ((ptr != line && ptr[-1] != ',') ||
671 (ptr[len] != '\0' && strchr("\n\t ,", ptr[len]) == NULL))
672 ptr++;
673 else {
674 free(line);
675 return 1;
678 free(line);
679 return 0;
682 /*ARGSUSED*/
683 static int
684 _local_endnetgrent(void *rv, void *cb_data, va_list ap)
686 for (_nglist = _nghead; _nglist != NULL; _nglist = _nghead) {
687 _nghead = _nglist->ng_next;
688 if (_nglist->ng_host != NULL)
689 free(_nglist->ng_host);
690 if (_nglist->ng_user != NULL)
691 free(_nglist->ng_user);
692 if (_nglist->ng_domain != NULL)
693 free(_nglist->ng_domain);
694 free(_nglist);
697 if (_ng_db) {
698 (void)(*_ng_db->close)(_ng_db);
699 _ng_db = NULL;
702 return NS_SUCCESS;
705 /*ARGSUSED*/
706 static int
707 _local_setnetgrent(void *rv, void *cb_data, va_list ap)
709 const char *ng = va_arg(ap, const char *);
710 StringList *sl;
711 char *ng_copy;
713 _DIAGASSERT(ng != NULL);
715 sl = sl_init();
716 if (sl == NULL)
717 return NS_TRYAGAIN;
719 /* Cleanup any previous storage */
720 if (_nghead != NULL)
721 endnetgrent();
723 if (_ng_db == NULL)
724 _ng_db = dbopen(_PATH_NETGROUP_DB, O_RDONLY, 0, DB_HASH, NULL);
726 ng_copy = strdup(ng);
727 if (ng_copy != NULL)
728 addgroup(sl, ng_copy);
729 _nghead = _nglist;
730 sl_free(sl, 1);
732 return NS_SUCCESS;
735 /*ARGSUSED*/
736 static int
737 _local_getnetgrent(void *rv, void *cb_data, va_list ap)
739 int *retval = va_arg(ap, int *);
740 const char **host = va_arg(ap, const char **);
741 const char **user = va_arg(ap, const char **);
742 const char **domain = va_arg(ap, const char **);
744 _DIAGASSERT(host != NULL);
745 _DIAGASSERT(user != NULL);
746 _DIAGASSERT(domain != NULL);
748 *retval = 0;
750 if (_nglist == NULL)
751 return NS_TRYAGAIN;
753 *host = _nglist->ng_host;
754 *user = _nglist->ng_user;
755 *domain = _nglist->ng_domain;
757 _nglist = _nglist->ng_next;
759 *retval = 1;
761 return NS_SUCCESS;
764 /*ARGSUSED*/
765 static int
766 _local_innetgr(void *rv, void *cb_data, va_list ap)
768 int *retval = va_arg(ap, int *);
769 const char *grp = va_arg(ap, const char *);
770 const char *host = va_arg(ap, const char *);
771 const char *user = va_arg(ap, const char *);
772 const char *domain = va_arg(ap, const char *);
774 int found;
775 StringList *sl;
776 char *grcpy;
778 _DIAGASSERT(grp != NULL);
779 /* host may be NULL */
780 /* user may be NULL */
781 /* domain may be NULL */
783 if (_ng_db == NULL)
784 _ng_db = dbopen(_PATH_NETGROUP_DB, O_RDONLY, 0, DB_HASH, NULL);
786 /* Try the fast lookup first */
787 if (host != NULL && user == NULL) {
788 if (in_lookup(grp, host, domain, _NG_KEYBYHOST)) {
789 *retval = 1;
790 return NS_SUCCESS;
792 } else if (host == NULL && user != NULL) {
793 if (in_lookup(grp, user, domain, _NG_KEYBYUSER)) {
794 *retval = 1;
795 return NS_SUCCESS;
798 /* If a domainname is given, we would have found a match */
799 if (domain != NULL) {
800 *retval = 0;
801 return NS_SUCCESS;
804 /* Too bad need the slow recursive way */
805 sl = sl_init();
806 if (sl == NULL) {
807 *retval = 0;
808 return NS_SUCCESS;
810 if ((grcpy = strdup(grp)) == NULL) {
811 sl_free(sl, 1);
812 *retval = 0;
813 return NS_SUCCESS;
815 found = in_find(sl, grcpy, host, user, domain);
816 sl_free(sl, 1);
818 *retval = found;
819 return NS_SUCCESS;
822 #ifdef YP
824 /*ARGSUSED*/
825 static int
826 _nis_endnetgrent(void *rv, void *cb_data, va_list ap)
828 return _local_endnetgrent(rv, cb_data, ap);
831 /*ARGSUSED*/
832 static int
833 _nis_setnetgrent(void *rv, void *cb_data, va_list ap)
835 return _local_setnetgrent(rv, cb_data, ap);
838 /*ARGSUSED*/
839 static int
840 _nis_getnetgrent(void *rv, void *cb_data, va_list ap)
842 return _local_getnetgrent(rv, cb_data, ap);
845 /*ARGSUSED*/
846 static int
847 _nis_innetgr(void *rv, void *cb_data, va_list ap)
849 return _local_innetgr(rv, cb_data, ap);
852 #endif
855 #ifdef NSSRC_FILES
856 void
857 endnetgrent(void)
859 static const ns_dtab dtab[] = {
860 NS_FILES_CB(_local_endnetgrent, NULL)
861 NS_NIS_CB(_nis_endnetgrent, NULL)
862 NS_NULL_CB
865 (void) nsdispatch(NULL, dtab, NSDB_NETGROUP, "endnetgrent",
866 __nsdefaultcompat);
868 #else
869 static int
870 _local_endnetgrentv(int *rv, void *cbdata, ...)
872 int e;
873 va_list ap;
874 va_start(ap, cbdata);
875 e = _local_endnetgrent(rv, cbdata, ap);
876 va_end(ap);
877 return e;
880 void
881 endnetgrent(void)
883 (void)_local_endnetgrentv(NULL, NULL, NULL);
885 #endif
887 #ifdef NSSRC_FILES
888 void
889 setnetgrent(const char *ng)
891 static const ns_dtab dtab[] = {
892 NS_FILES_CB(_local_setnetgrent, NULL)
893 NS_NIS_CB(_nis_setnetgrent, NULL)
894 NS_NULL_CB
897 (void) nsdispatch(NULL, dtab, NSDB_NETGROUP, "setnetgrent",
898 __nsdefaultnis, ng);
900 #else
901 static int
902 _local_setnetgrentv(int *rv, void *cbdata, ...)
904 int e;
905 va_list ap;
906 va_start(ap, cbdata);
907 e = _local_setnetgrent(rv, cbdata, ap);
908 va_end(ap);
909 return e;
912 void
913 setnetgrent(const char *ng)
915 (void) _local_setnetgrentv(NULL, NULL,ng);
918 #endif
920 #ifdef NSSRC_FILES
922 getnetgrent(const char **host, const char **user, const char **domain)
924 int r, retval;
925 static const ns_dtab dtab[] = {
926 NS_FILES_CB(_local_getnetgrent, NULL)
927 NS_NIS_CB(_nis_getnetgrent, NULL)
928 NS_NULL_CB
931 r = nsdispatch(NULL, dtab, NSDB_NETGROUP, "getnetgrent",
932 __nsdefaultnis, &retval, host, user, domain);
934 return (r == NS_SUCCESS) ? retval : 0;
936 #else
937 static int
938 _local_getnetgrentv(int *rv, void *cbdata, ...)
940 int e;
941 va_list ap;
942 va_start(ap, cbdata);
943 e = _local_getnetgrent(rv, cbdata, ap);
944 va_end(ap);
945 return e;
949 getnetgrent(const char **host, const char **user, const char **domain)
951 return _local_getnetgrentv(NULL, NULL, host, user, domain) == NS_SUCCESS;
953 #endif
955 #ifdef NSSRC_FILES
957 innetgr(const char *grp, const char *host, const char *user,
958 const char *domain)
960 int r, retval;
961 static const ns_dtab dtab[] = {
962 NS_FILES_CB(_local_innetgr, NULL)
963 NS_NIS_CB(_nis_innetgr, NULL)
964 NS_NULL_CB
967 r = nsdispatch(NULL, dtab, NSDB_NETGROUP, "innetgr",
968 __nsdefaultnis, &retval, grp, host, user, domain);
970 return (r == NS_SUCCESS) ? retval : 0;
972 #else
973 static int
974 _local_innetgrv(int *rv, void *cbdata, ...)
976 int e;
977 va_list ap;
978 va_start(ap, cbdata);
979 e = _local_innetgr(rv, cbdata, ap);
980 va_end(ap);
981 return e;
985 innetgr(const char *grp, const char *host, const char *user,
986 const char *domain)
988 return _local_innetgrv(NULL, NULL, grp, host, user, domain) == NS_SUCCESS;
990 #endif