Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src - Implement pwcache_userdb(3), which changes the routines that
details: https://anonhg.NetBSD.org/src/rev/d8db3e9ca598
branches: trunk
changeset: 521119:d8db3e9ca598
user: lukem <lukem%NetBSD.org@localhost>
date: Thu Jan 24 02:46:32 2002 +0000
description:
- Implement pwcache_userdb(3), which changes the routines that
user_from_uid(3) and uid_from_user(3) use to lookup user information.
- Implement pwcache_groupdb(3), which changes the routines that
group_from_gid(3) and gid_from_group(3) use to lookup group information.
- Ensure that private functions in pwcache.c are declared static
- Use strlcpy(3) instead of strncpy(3)
diffstat:
include/grp.h | 5 +-
include/pwd.h | 5 +-
lib/libc/gen/Makefile.inc | 3 +-
lib/libc/gen/pwcache.3 | 90 +++++++++++++-
lib/libc/gen/pwcache.c | 276 +++++++++++++++++++++++++++++++++++-------
lib/libc/include/namespace.h | 6 +-
lib/libc/shlib_version | 4 +-
7 files changed, 330 insertions(+), 59 deletions(-)
diffs (truncated from 669 to 300 lines):
diff -r 37f40855332e -r d8db3e9ca598 include/grp.h
--- a/include/grp.h Thu Jan 24 02:44:11 2002 +0000
+++ b/include/grp.h Thu Jan 24 02:46:32 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: grp.h,v 1.14 1998/07/28 16:27:48 mycroft Exp $ */
+/* $NetBSD: grp.h,v 1.15 2002/01/24 02:46:33 lukem Exp $ */
/*-
* Copyright (c) 1989, 1993
@@ -71,6 +71,9 @@
int setgroupent __P((int));
const char *group_from_gid __P((gid_t, int));
int gid_from_group __P((const char *, gid_t *));
+int pwcache_groupdb(int (*)(int), void (*)(void),
+ struct group * (*)(const char *),
+ struct group * (*)(gid_t));
#endif
__END_DECLS
diff -r 37f40855332e -r d8db3e9ca598 include/pwd.h
--- a/include/pwd.h Thu Jan 24 02:44:11 2002 +0000
+++ b/include/pwd.h Thu Jan 24 02:46:32 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pwd.h,v 1.23 2001/10/23 00:25:20 lukem Exp $ */
+/* $NetBSD: pwd.h,v 1.24 2002/01/24 02:46:32 lukem Exp $ */
/*-
* Copyright (c) 1989, 1993
@@ -110,6 +110,9 @@
int setpassent __P((int));
const char *user_from_uid __P((uid_t, int));
int uid_from_user __P((const char *, uid_t *));
+int pwcache_userdb(int (*)(int), void (*)(void),
+ struct passwd * (*)(const char *),
+ struct passwd * (*)(uid_t));
#endif
__END_DECLS
diff -r 37f40855332e -r d8db3e9ca598 lib/libc/gen/Makefile.inc
--- a/lib/libc/gen/Makefile.inc Thu Jan 24 02:44:11 2002 +0000
+++ b/lib/libc/gen/Makefile.inc Thu Jan 24 02:46:32 2002 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.108 2001/05/07 17:25:57 kleink Exp $
+# $NetBSD: Makefile.inc,v 1.109 2002/01/24 02:46:35 lukem Exp $
# from: @(#)Makefile.inc 8.6 (Berkeley) 5/4/95
# gen sources
@@ -94,6 +94,7 @@
MLINKS+=psignal.3 sys_siglist.3 psignal.3 sys_signame.3
MLINKS+=pwcache.3 user_from_uid.3 pwcache.3 group_from_gid.3
MLINKS+=pwcache.3 uid_from_user.3 pwcache.3 gid_from_group.3
+MLINKS+=pwcache.3 pwcache_userdb.3 pwcache.3 pwcache_groupdb.3
MLINKS+=scandir.3 alphasort.3
MLINKS+=setjmp.3 _longjmp.3 setjmp.3 _setjmp.3 setjmp.3 longjmp.3 \
setjmp.3 longjmperror.3 setjmp.3 sigsetjmp.3 setjmp.3 siglongjmp.3
diff -r 37f40855332e -r d8db3e9ca598 lib/libc/gen/pwcache.3
--- a/lib/libc/gen/pwcache.3 Thu Jan 24 02:44:11 2002 +0000
+++ b/lib/libc/gen/pwcache.3 Thu Jan 24 02:46:32 2002 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: pwcache.3,v 1.10 2001/09/16 02:30:25 wiz Exp $
+.\" $NetBSD: pwcache.3,v 1.11 2002/01/24 02:46:35 lukem Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -31,9 +31,42 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
+.\"
+.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\"
.\" @(#)pwcache.3 8.1 (Berkeley) 6/9/93
.\"
-.Dd July 28, 1998
+.Dd January 24, 2002
.Dt PWCACHE 3
.Os
.Sh NAME
@@ -49,11 +82,15 @@
.Fn user_from_uid "uid_t uid" "int nouser"
.Ft int
.Fn uid_from_user "const char *name" "uid_t *uid"
+.Ft int
+.Fn pwcache_userdb "int (*setpassent)(int)" "void (*endpwent)(void)" "struct passwd * (*getpwnam)(const char *)" "struct passwd * (*getpwuid)(uid_t)"
.Fd #include <grp.h>
.Ft const char *
.Fn group_from_gid "gid_t gid" "int nogroup"
.Ft int
.Fn gid_from_group "const char *name" "gid_t *gid"
+.Ft int
+.Fn pwcache_groupdb "int (*setgroupent)(int)" "void (*endgrent)(void)" "struct group * (*getgrnam)(const char *)" "struct group * (*getgrgid)(gid_t)"
.Sh DESCRIPTION
The
.Fn user_from_uid
@@ -124,6 +161,48 @@
function returns -1; otherwise it stores the gid at the location pointed to by
.Fa gid
and returns 0.
+.Pp
+The
+.Fn pwcache_userdb
+function changes the user database access routines which
+.Fn user_from_uid
+and
+.Fn uid_from_user
+call to search for users.
+The caches are flushed and the existing
+.Fn endpwent
+method is called before switching to the new routines.
+.Fa getpwnam
+and
+.Fa getpwuid
+must be provided, and
+.Fa setpassent
+and
+.Fa endpwent
+may be
+.Dv NULL
+pointers.
+.Pp
+The
+.Fn pwcache_groupdb
+function changes the group database access routines which
+.Fn group_from_gid
+and
+.Fn gid_from_group
+call to search for groups.
+The caches are flushed and the existing
+.Fn endgrent
+method is called before switching to the new routines.
+.Fa getgrnam
+and
+.Fa getgrgid
+must be provided, and
+.Fa setgroupent
+and
+.Fa endgrent
+may be
+.Dv NULL
+pointers.
.Sh SEE ALSO
.Xr getgrgid 3 ,
.Xr getgrnam 3 ,
@@ -143,3 +222,10 @@
.Fn gid_from_group
functions first appeared in
.Nx 1.4 .
+.Pp
+The
+.Fn pwcache_userdb
+and
+.Fn pwcache_groupdb
+functions first appeared in
+.Nx 1.6 .
diff -r 37f40855332e -r d8db3e9ca598 lib/libc/gen/pwcache.c
--- a/lib/libc/gen/pwcache.c Thu Jan 24 02:44:11 2002 +0000
+++ b/lib/libc/gen/pwcache.c Thu Jan 24 02:46:32 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pwcache.c,v 1.16 2002/01/04 14:50:29 lukem Exp $ */
+/* $NetBSD: pwcache.c,v 1.17 2002/01/24 02:46:35 lukem Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@@ -37,12 +37,45 @@
* SUCH DAMAGE.
*/
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)cache.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: pwcache.c,v 1.16 2002/01/04 14:50:29 lukem Exp $");
+__RCSID("$NetBSD: pwcache.c,v 1.17 2002/01/24 02:46:35 lukem Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -64,6 +97,8 @@
#ifdef __weak_alias
__weak_alias(user_from_uid,_user_from_uid)
__weak_alias(group_from_gid,_group_from_gid)
+__weak_alias(pwcache_userdb,_pwcache_userdb)
+__weak_alias(pwcache_groupdb,_pwcache_groupdb)
#endif
/*
@@ -73,18 +108,41 @@
* these routines cache BOTH hits and misses, a major performance improvement
*/
-static int pwopn = 0; /* is password file open */
-static int gropn = 0; /* is group file open */
-static UIDC **uidtb = NULL; /* uid to name cache */
-static GIDC **gidtb = NULL; /* gid to name cache */
-static UIDC **usrtb = NULL; /* user name to uid cache */
-static GIDC **grptb = NULL; /* group name to gid cache */
+/*
+ * function pointers to various name lookup routines.
+ * these may be changed as necessary.
+ */
+static int (*_pwcache_setgroupent)(int) = setgroupent;
+static void (*_pwcache_endgrent)(void) = endgrent;
+static struct group * (*_pwcache_getgrnam)(const char *) = getgrnam;
+static struct group * (*_pwcache_getgrgid)(gid_t) = getgrgid;
+static int (*_pwcache_setpassent)(int) = setpassent;
+static void (*_pwcache_endpwent)(void) = endpwent;
+static struct passwd * (*_pwcache_getpwnam)(const char *) = getpwnam;
+static struct passwd * (*_pwcache_getpwuid)(uid_t) = getpwuid;
-static u_int st_hash(const char *, size_t, int);
-static int uidtb_start(void);
-static int gidtb_start(void);
-static int usrtb_start(void);
-static int grptb_start(void);
+/*
+ * internal state
+ */
+static int pwopn; /* is password file open */
+static int gropn; /* is group file open */
+static UIDC **uidtb; /* uid to name cache */
+static GIDC **gidtb; /* gid to name cache */
+static UIDC **usrtb; /* user name to uid cache */
+static GIDC **grptb; /* group name to gid cache */
+
+static int uidtb_fail; /* uidtb_start() failed ? */
+static int gidtb_fail; /* gidtb_start() failed ? */
+static int usrtb_fail; /* usrtb_start() failed ? */
+static int grptb_fail; /* grptb_start() failed ? */
+
+
+static u_int st_hash(const char *, size_t, int);
+static int uidtb_start(void);
+static int gidtb_start(void);
+static int usrtb_start(void);
+static int grptb_start(void);
+
Home |
Main Index |
Thread Index |
Old Index