From 147dea105a149930bfb62569ac31cb225cc49649 Mon Sep 17 00:00:00 2001 From: lukem Date: Mon, 25 Jan 1999 01:09:34 +0000 Subject: [PATCH] convert from hes_*() -> hesiod_*() --- lib/libc/gen/getgrent.c | 46 ++++++++++++++++++++++--------------- lib/libc/gen/getpwent.c | 39 +++++++++++++++++-------------- lib/libc/gen/getusershell.c | 36 +++++++++++++++++------------ 3 files changed, 71 insertions(+), 50 deletions(-) diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index 03508b5df07a..ee4ac5445068 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -1,4 +1,4 @@ -/* $NetBSD: getgrent.c,v 1.32 1999/01/20 02:59:37 lukem Exp $ */ +/* $NetBSD: getgrent.c,v 1.33 1999/01/25 01:09:34 lukem Exp $ */ /* * Copyright (c) 1989, 1993 @@ -39,12 +39,15 @@ #if 0 static char sccsid[] = "@(#)getgrent.c 8.2 (Berkeley) 3/21/94"; #else -__RCSID("$NetBSD: getgrent.c,v 1.32 1999/01/20 02:59:37 lukem Exp $"); +__RCSID("$NetBSD: getgrent.c,v 1.33 1999/01/25 01:09:34 lukem Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include "namespace.h" + #include + +#include #include #include #include @@ -52,6 +55,7 @@ __RCSID("$NetBSD: getgrent.c,v 1.32 1999/01/20 02:59:37 lukem Exp $"); #include #include #include + #ifdef HESIOD #include #endif @@ -237,6 +241,12 @@ _dns_grscan(rv, cb_data, ap) const char *name = va_arg(ap, const char *); char **hp; + void *context; + int r; + + r = NS_UNAVAIL; + if (hesiod_init(&context) == -1) + return (r); for (;;) { if (search) { @@ -251,33 +261,33 @@ _dns_grscan(rv, cb_data, ap) } line[sizeof(line) - 1] = '\0'; - hp = hes_resolve(line, "group"); + hp = hesiod_resolve(context, line, "group"); if (hp == NULL) { - switch (hes_error()) { - case HES_ER_NOTFOUND: + if (errno == ENOENT) { if (!search) { __gr_hesnum = 0; _gr_nomore = 1; - return NS_SUCCESS; - } - return NS_NOTFOUND; - case HES_ER_OK: - abort(); - break; - default: - return NS_UNAVAIL; + r = NS_SUCCESS; + } else + r = NS_NOTFOUND; } + break; } /* only check first elem */ strncpy(line, hp[0], sizeof(line)); line[sizeof(line) - 1] = '\0'; - hes_free(hp); - if (matchline(search, gid, name)) - return NS_SUCCESS; - else if (search) - return NS_NOTFOUND; + hesiod_free_list(context, hp); + if (matchline(search, gid, name)) { + r = NS_SUCCESS; + break; + } else if (search) { + r = NS_NOTFOUND; + break; + } } + hesiod_end(context); + return (r); } #endif diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index 5ff75a9a396c..6927bde68da8 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -1,4 +1,4 @@ -/* $NetBSD: getpwent.c,v 1.38 1999/01/21 12:42:06 mycroft Exp $ */ +/* $NetBSD: getpwent.c,v 1.39 1999/01/25 01:09:34 lukem Exp $ */ /* * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)getpwent.c 8.2 (Berkeley) 4/27/95"; #else -__RCSID("$NetBSD: getpwent.c,v 1.38 1999/01/21 12:42:06 mycroft Exp $"); +__RCSID("$NetBSD: getpwent.c,v 1.39 1999/01/25 01:09:34 lukem Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -445,9 +445,11 @@ _dns_getpw(rv, cb_data, ap) const char *name; uid_t uid; int search; + char *map; char **hp; - + void *context; + int r; search = va_arg(ap, int); switch (search) { @@ -471,30 +473,33 @@ _dns_getpw(rv, cb_data, ap) } line[sizeof(line) - 1] = '\0'; - hp = hes_resolve(line, map); + r = NS_UNAVAIL; + if (hesiod_init(&context) == -1) + return (r); + + hp = hesiod_resolve(context, line, map); if (hp == NULL) { - switch (hes_error()) { - case HES_ER_NOTFOUND: + if (errno == ENOENT) { if (search == _PW_KEYBYNUM) { _pw_hesnum = 0; _pw_none = 1; - return NS_SUCCESS; - } - return NS_NOTFOUND; - case HES_ER_OK: - abort(); - break; - default: - return NS_UNAVAIL; + r = NS_SUCCESS; + } else + r = NS_NOTFOUND; } + goto cleanup_dns_getpw; } strncpy(line, hp[0], sizeof(line)); /* only check first elem */ line[sizeof(line) - 1] = '\0'; - hes_free(hp); + hesiod_free_list(context, hp); if (__pwparse(&_pw_passwd, line)) - return NS_UNAVAIL; - return NS_SUCCESS; + r = NS_UNAVAIL; + else + r = NS_SUCCESS; + cleanup_dns_getpw: + hesiod_end(context); + return (r); } #endif diff --git a/lib/libc/gen/getusershell.c b/lib/libc/gen/getusershell.c index 2a09ccf2ca13..260a9efe8aa7 100644 --- a/lib/libc/gen/getusershell.c +++ b/lib/libc/gen/getusershell.c @@ -1,4 +1,4 @@ -/* $NetBSD: getusershell.c,v 1.16 1999/01/20 13:11:18 christos Exp $ */ +/* $NetBSD: getusershell.c,v 1.17 1999/01/25 01:09:34 lukem Exp $ */ /* * Copyright (c) 1985, 1993 @@ -38,21 +38,24 @@ #if 0 static char sccsid[] = "@(#)getusershell.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getusershell.c,v 1.16 1999/01/20 13:11:18 christos Exp $"); +__RCSID("$NetBSD: getusershell.c,v 1.17 1999/01/25 01:09:34 lukem Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include #include -#include + #include +#include #include -#include -#include #include +#include +#include #include #include +#include + #ifdef HESIOD #include #endif @@ -160,33 +163,36 @@ _dns_initshells(rv, cb_data, ap) va_list ap; { char shellname[] = "shells-XXXXX"; - int hsindex, hpi; + int hsindex, hpi, r; char **hp; + void *context; if (sl) sl_free(sl, 1); sl = sl_init(); + r = NS_UNAVAIL; + if (hesiod_init(&context) == -1) + return (r); for (hsindex = 0; ; hsindex++) { snprintf(shellname, sizeof(shellname)-1, "shells-%d", hsindex); - hp = hes_resolve(shellname, "shells"); + hp = hesiod_resolve(context, shellname, "shells"); if (hp == NULL) { - switch(hes_error()) { - case HES_ER_OK: - break; - case HES_ER_NOTFOUND: + if (errno == ENOENT) { if (hsindex == 0) - return NS_NOTFOUND; - return NS_SUCCESS; - default: - return NS_UNAVAIL; + r = NS_NOTFOUND; + else + r = NS_SUCCESS; } + break; } else { for (hpi = 0; hp[hpi]; hpi++) sl_add(sl, hp[hpi]); free(hp); } } + hesiod_end(context); + return (r); } #endif /* HESIOD */