Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc PR/29849, PR/29850: Add getpwent_r and getgrent_r
details: https://anonhg.NetBSD.org/src/rev/478d0acb5f7c
branches: trunk
changeset: 579947:478d0acb5f7c
user: christos <christos%NetBSD.org@localhost>
date: Sat Apr 02 04:53:53 2005 +0000
description:
PR/29849, PR/29850: Add getpwent_r and getgrent_r
diffstat:
lib/libc/gen/getgrent.c | 142 +++++++++++++++++++++++-
lib/libc/gen/getpwent.c | 250 ++++++++++++++++++++++++++++++++++++++++--
lib/libc/include/namespace.h | 4 +-
lib/libc/shlib_version | 4 +-
4 files changed, 377 insertions(+), 23 deletions(-)
diffs (truncated from 581 to 300 lines):
diff -r 30461b8bad15 -r 478d0acb5f7c lib/libc/gen/getgrent.c
--- a/lib/libc/gen/getgrent.c Sat Apr 02 03:03:23 2005 +0000
+++ b/lib/libc/gen/getgrent.c Sat Apr 02 04:53:53 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getgrent.c,v 1.55 2005/03/31 23:58:28 lukem Exp $ */
+/* $NetBSD: getgrent.c,v 1.56 2005/04/02 04:53:53 christos Exp $ */
/*-
* Copyright (c) 1999-2000, 2004-2005 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
#if 0
static char sccsid[] = "@(#)getgrent.c 8.2 (Berkeley) 3/21/94";
#else
-__RCSID("$NetBSD: getgrent.c,v 1.55 2005/03/31 23:58:28 lukem Exp $");
+__RCSID("$NetBSD: getgrent.c,v 1.56 2005/04/02 04:53:53 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -130,6 +130,7 @@
#ifdef __weak_alias
__weak_alias(endgrent,_endgrent)
__weak_alias(getgrent,_getgrent)
+__weak_alias(getgrent_r,_getgrent_r)
__weak_alias(getgrgid,_getgrgid)
__weak_alias(getgrgid_r,_getgrgid_r)
__weak_alias(getgrnam,_getgrnam)
@@ -459,6 +460,32 @@
/*ARGSUSED*/
static int
+_files_getgrent_r(void *nsrv, void *nscb, va_list ap)
+{
+ int *retval = va_arg(ap, int *);
+ struct group *grp = va_arg(ap, struct group *);
+ char *buffer = va_arg(ap, char *);
+ size_t buflen = va_arg(ap, size_t);
+ struct group **result = va_arg(ap, struct group **);
+
+ int rv;
+
+ _DIAGASSERT(retval != NULL);
+ _DIAGASSERT(grp != NULL);
+ _DIAGASSERT(buffer != NULL);
+ _DIAGASSERT(result != NULL);
+
+ rv = __grscan_files(retval, grp, buffer, buflen,
+ &_files_state, 0, NULL, 0);
+ if (rv == NS_SUCCESS)
+ *result = grp;
+ else
+ *result = NULL;
+ return rv;
+}
+
+/*ARGSUSED*/
+static int
_files_getgrgid(void *nsrv, void *nscb, va_list ap)
{
struct group **retval = va_arg(ap, struct group **);
@@ -749,6 +776,31 @@
/*ARGSUSED*/
static int
+_dns_getgrent_r(void *nsrv, void *nscb, va_list ap)
+{
+ int *retval = va_arg(ap, int *);
+ struct group *grp = va_arg(ap, struct group *);
+ char *buffer = va_arg(ap, char *);
+ size_t buflen = va_arg(ap, size_t);
+ struct group **result = va_arg(ap, struct group **);
+
+ int rv;
+
+ _DIAGASSERT(retval != NULL);
+ _DIAGASSERT(grp != NULL);
+ _DIAGASSERT(buffer != NULL);
+ _DIAGASSERT(result != NULL);
+
+ rv = __grscan_dns(retval, grp, buffer, buflen,
+ &_dns_state, 0, NULL, 0);
+ if (rv == NS_SUCCESS)
+ *result = grp;
+ else
+ *result = NULL;
+ return rv;
+}
+/*ARGSUSED*/
+static int
_dns_getgrgid(void *nsrv, void *nscb, va_list ap)
{
struct group **retval = va_arg(ap, struct group **);
@@ -1065,6 +1117,32 @@
/*ARGSUSED*/
static int
+_nis_getgrent_r(void *nsrv, void *nscb, va_list ap)
+{
+ int *retval = va_arg(ap, int *);
+ struct group *grp = va_arg(ap, struct group *);
+ char *buffer = va_arg(ap, char *);
+ size_t buflen = va_arg(ap, size_t);
+ struct group **result = va_arg(ap, struct group **);
+
+ int rv;
+
+ _DIAGASSERT(retval != NULL);
+ _DIAGASSERT(grp != NULL);
+ _DIAGASSERT(buffer != NULL);
+ _DIAGASSERT(result != NULL);
+
+ rv = __grscan_nis(retval, grp, buffer, buflen,
+ &_nis_state, 0, NULL, 0);
+ if (rv == NS_SUCCESS)
+ *result = grp;
+ else
+ *result = NULL;
+ return rv;
+}
+
+/*ARGSUSED*/
+static int
_nis_getgrgid(void *nsrv, void *nscb, va_list ap)
{
struct group **retval = va_arg(ap, struct group **);
@@ -1256,8 +1334,8 @@
static const ns_dtab compatentdtab[] = {
NS_FILES_CB(__grbad_compat, "files")
- NS_DNS_CB(_dns_getgrent, NULL)
- NS_NIS_CB(_nis_getgrent, NULL)
+ NS_DNS_CB(_dns_getgrent_r, NULL)
+ NS_NIS_CB(_nis_getgrent_r, NULL)
NS_COMPAT_CB(__grbad_compat, "compat")
{ 0 }
};
@@ -1306,15 +1384,15 @@
free(state->name); /* (only check 1 grp) */
state->name = NULL;
} else if (!search) { /* any group */
-/* XXXREENTRANT: need to implement and use getgrent_r() */
if (searchfunc) {
crv = searchfunc(searchcookie,
&cgrpres);
} else {
crv = nsdispatch(NULL, compatentdtab,
- NSDB_GROUP_COMPAT, "getgrent",
+ NSDB_GROUP_COMPAT, "getgrent_r",
__nsdefaultnis,
- &cgrpres);
+ &cretval, &cgrp, filebuf,
+ sizeof(filebuf), &cgrpres);
}
} else if (name) { /* specific group */
crv = nsdispatch(NULL, compatnamdtab,
@@ -1501,6 +1579,32 @@
/*ARGSUSED*/
static int
+_compat_getgrent_r(void *nsrv, void *nscb, va_list ap)
+{
+ int *retval = va_arg(ap, int *);
+ struct group *grp = va_arg(ap, struct group *);
+ char *buffer = va_arg(ap, char *);
+ size_t buflen = va_arg(ap, size_t);
+ struct group **result = va_arg(ap, struct group **);
+
+ int rv;
+
+ _DIAGASSERT(retval != NULL);
+ _DIAGASSERT(grp != NULL);
+ _DIAGASSERT(buffer != NULL);
+ _DIAGASSERT(result != NULL);
+
+ rv = __grscan_compat(retval, grp, buffer, buflen,
+ &_compat_state, 0, NULL, 0, NULL, NULL);
+ if (rv == NS_SUCCESS)
+ *result = grp;
+ else
+ *result = NULL;
+ return rv;
+}
+
+/*ARGSUSED*/
+static int
_compat_getgrgid(void *nsrv, void *nscb, va_list ap)
{
struct group **retval = va_arg(ap, struct group **);
@@ -1632,9 +1736,31 @@
rv = nsdispatch(NULL, dtab, NSDB_GROUP, "getgrent", __nsdefaultcompat,
&retval);
mutex_unlock(&__grmutex);
- return (rv == NS_SUCCESS) ? retval : NULL;
+ return (rv == NS_SUCCESS) ? 0 : retval;
}
+int
+getgrent_r(struct group *grp, char *buffer, size_t buflen,
+ struct group **result)
+{
+ int rv, retval;
+
+ static const ns_dtab dtab[] = {
+ NS_FILES_CB(_files_getgrent_r, NULL)
+ NS_DNS_CB(_dns_getgrent_r, NULL)
+ NS_NIS_CB(_nis_getgrent_r, NULL)
+ NS_COMPAT_CB(_compat_getgrent_r, NULL)
+ { 0 }
+ };
+
+ mutex_lock(&__grmutex);
+ rv = nsdispatch(NULL, dtab, NSDB_GROUP, "getgrent_r", __nsdefaultcompat,
+ &retval, grp, buffer, buflen, result);
+ mutex_unlock(&__grmutex);
+ return (rv == NS_SUCCESS) ? 0 : retval;
+}
+
+
struct group *
getgrgid(gid_t gid)
{
diff -r 30461b8bad15 -r 478d0acb5f7c lib/libc/gen/getpwent.c
--- a/lib/libc/gen/getpwent.c Sat Apr 02 03:03:23 2005 +0000
+++ b/lib/libc/gen/getpwent.c Sat Apr 02 04:53:53 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getpwent.c,v 1.66 2005/02/28 00:40:05 lukem Exp $ */
+/* $NetBSD: getpwent.c,v 1.67 2005/04/02 04:53:53 christos Exp $ */
/*-
* Copyright (c) 1997-2000, 2004-2005 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
#if 0
static char sccsid[] = "@(#)getpwent.c 8.2 (Berkeley) 4/27/95";
#else
-__RCSID("$NetBSD: getpwent.c,v 1.66 2005/02/28 00:40:05 lukem Exp $");
+__RCSID("$NetBSD: getpwent.c,v 1.67 2005/04/02 04:53:53 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -137,6 +137,7 @@
#ifdef __weak_alias
__weak_alias(endpwent,_endpwent)
__weak_alias(getpwent,_getpwent)
+__weak_alias(getpwent_r,_getpwent_r)
__weak_alias(getpwnam,_getpwnam)
__weak_alias(getpwnam_r,_getpwnam_r)
__weak_alias(getpwuid,_getpwuid)
@@ -566,6 +567,32 @@
/*ARGSUSED*/
static int
+_files_getpwent_r(void *nsrv, void *nscb, va_list ap)
+{
+ int *retval = va_arg(ap, int *);
+ struct passwd *pw = va_arg(ap, struct passwd *);
+ char *buffer = va_arg(ap, char *);
+ size_t buflen = va_arg(ap, size_t);
+ struct passwd **result = va_arg(ap, struct passwd **);
+
+ int rv;
+
+ _DIAGASSERT(retval != NULL);
+ _DIAGASSERT(pw != NULL);
+ _DIAGASSERT(buffer != NULL);
+ _DIAGASSERT(result != NULL);
+
+ rv = _files_pwscan(retval, pw, buffer, buflen, &_files_state,
+ _PW_KEYBYNUM, NULL, 0);
+ if (rv == NS_SUCCESS)
+ *result = pw;
+ else
+ *result = NULL;
+ return rv;
+}
+
+/*ARGSUSED*/
+static int
_files_getpwnam(void *nsrv, void *nscb, va_list ap)
{
struct passwd **retval = va_arg(ap, struct passwd **);
@@ -868,6 +895,71 @@
return rv;
}
+/*ARGSUSED*/
+static int
+_dns_getpwent_r(void *nsrv, void *nscb, va_list ap)
+{
+ int *retval = va_arg(ap, int *);
+ struct passwd *pw = va_arg(ap, struct passwd *);
+ char *buffer = va_arg(ap, char *);
+ size_t buflen = va_arg(ap, size_t);
+ struct passwd **result = va_arg(ap, struct passwd **);
+
+ char **hp, *ep;
+ int rv;
+
+ _DIAGASSERT(retval != NULL);
+ _DIAGASSERT(pw != NULL);
+ _DIAGASSERT(buffer != NULL);
+ _DIAGASSERT(result != NULL);
Home |
Main Index |
Thread Index |
Old Index