summaryrefslogtreecommitdiff
path: root/lib/libc/gen
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2000-04-25 19:11:49 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2000-04-25 19:11:49 +0000
commit0189da9e7093ccf446208cd8975e69c83a8c8556 (patch)
tree562343545cd6fa4f413fafac58c8b2dde429e3e5 /lib/libc/gen
parent3cc0268ca1c600add3a8d5d6885aebf543f096ae (diff)
well if you cannot do a libc commit properly a week before 2.7 tree lock, surely it can wait till after 2.7
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/Makefile.inc5
-rw-r--r--lib/libc/gen/getpwent.345
-rw-r--r--lib/libc/gen/getpwent.c142
3 files changed, 13 insertions, 179 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index 963b3c6afab..439a2bda54b 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.23 2000/04/25 12:21:05 d Exp $
+# $OpenBSD: Makefile.inc,v 1.24 2000/04/25 19:11:48 deraadt Exp $
# gen sources
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/gen ${LIBCSRCDIR}/gen
@@ -83,8 +83,7 @@ MLINKS+=gethostname.3 sethostname.3
MLINKS+=getnetgrent.3 endnetgrent.3 getnetgrent.3 innetgr.3 \
getnetgrent.3 setnetgrent.3
MLINKS+=getpwent.3 endpwent.3 getpwent.3 setpassent.3 getpwent.3 getpwnam.3 \
- getpwent.3 getpwuid.3 getpwent.3 setpwent.3 getpwent.3 setpwfile.3 \
- getpwent.3 getpwuid_r.3 getpwent.3 getpwnam_r.3
+ getpwent.3 getpwuid.3 getpwent.3 setpwent.3 getpwent.3 setpwfile.3
MLINKS+=getttyent.3 endttyent.3 getttyent.3 getttynam.3 getttyent.3 setttyent.3
MLINKS+=getusershell.3 endusershell.3 getusershell.3 setusershell.3
MLINKS+=glob.3 globfree.3
diff --git a/lib/libc/gen/getpwent.3 b/lib/libc/gen/getpwent.3
index 96e8bebfb4d..41ae1b44597 100644
--- a/lib/libc/gen/getpwent.3
+++ b/lib/libc/gen/getpwent.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: getpwent.3,v 1.12 2000/04/25 12:21:05 d Exp $
+.\" $OpenBSD: getpwent.3,v 1.13 2000/04/25 19:11:48 deraadt Exp $
.\"
.\" Copyright (c) 1988, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -37,9 +37,7 @@
.Sh NAME
.Nm getpwent ,
.Nm getpwnam ,
-.Nm getpwnam_r ,
.Nm getpwuid ,
-.Nm getpwuid_r ,
.Nm setpassent ,
.Nm setpwent ,
.Nm endpwent
@@ -51,13 +49,9 @@
.Fn getpwent void
.Ft struct passwd *
.Fn getpwnam "const char *login"
-.Ft int
-.Fn getpwnam_r "const char *login" "struct passwd *pwd" "char *buffer" "size_t bufsize" "struct passwd **result"
.Ft struct passwd *
.Fn getpwuid "uid_t uid"
.Ft int
-.Fn getpwuid_r "uid_t uid" "struct passwd *pwd" "char *buffer" "size_t bufsize" "struct passwd **result"
-.Ft int
.Fn setpassent "int stayopen"
.Ft void
.Fn setpwent void
@@ -135,29 +129,6 @@ If the process which calls them has an effective UID of 0, the encrypted
password will be returned, otherwise, the password field of the returned
structure will point to the string
.Ql * .
-.Pp
-The
-.Fn getpwuid_r
-and
-.Fn getpwnam_r
-functions both update the passwd structure pointed to by
-.Fa pwd
-and store a pointer to that structure at the location pointed to by
-.Fa result .
-The structure shall contain an entry from the user database with a matching
-.Fa uid
-or
-.Fa login .
-Storage referenced by the structure shall be allocated from the memory
-provided with the
-.Fa buffer
-parameter, which is
-.Fa bufsize
-characters in size.
-.\" The maximum size needed for this buffer can be determined with the
-.\" _SC_GETPW_R_SIZE_MAX
-.\" .Xr sysconf 2
-.\" parameter.
.Sh RETURN VALUES
The functions
.Fn getpwent ,
@@ -175,20 +146,6 @@ and
.Fn setpwent
functions
have no return value.
-The functions
-.Fn getpwuid_r
-and
-.Fn getpwnam_r
-return a null pointer in the location pointed to by
-.Fa result
-and return the error number
-on error or if the requested entry is not found.
-The error value
-.Ev ERANGE
-is returned if insufficient storage was supplied via
-.Fa buffer
-and
-.Fa bufsize.
.Sh FILES
.Bl -tag -width /etc/master.passwd -compact
.It Pa /etc/pwd.db
diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c
index 3b2cc4082ae..1ff377ee9ea 100644
--- a/lib/libc/gen/getpwent.c
+++ b/lib/libc/gen/getpwent.c
@@ -33,7 +33,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: getpwent.c,v 1.18 2000/04/25 12:21:05 d Exp $";
+static char rcsid[] = "$OpenBSD: getpwent.c,v 1.19 2000/04/25 19:11:48 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -56,9 +56,6 @@ static char rcsid[] = "$OpenBSD: getpwent.c,v 1.18 2000/04/25 12:21:05 d Exp $";
#include <rpcsvc/ypclnt.h>
#include "ypinternal.h"
#endif
-#include "thread_private.h"
-
-_THREAD_PRIVATE_MUTEX(pw);
static struct passwd _pw_passwd; /* password structure */
static DB *_pw_db; /* password database */
@@ -100,9 +97,6 @@ struct _ypexclude {
};
static struct _ypexclude *__ypexclude = (struct _ypexclude *)NULL;
-static struct passwd *getpwnam_unlocked __P((const char *));
-static struct passwd *getpwuid_unlocked __P((uid_t));
-
/*
* Using DB for this just wastes too damn much memory.
*/
@@ -326,13 +320,8 @@ getpwent()
const char *user, *host, *dom;
#endif
- _THREAD_PRIVATE_MUTEX_LOCK(pw);
-
- if (!_pw_db && !__initdb()) {
- _THREAD_PRIVATE_MUTEX_UNLOCK(pw);
+ if (!_pw_db && !__initdb())
return ((struct passwd *)NULL);
- }
-
#ifdef YP
if (__getpwent_has_yppw == -1)
@@ -437,7 +426,6 @@ again:
__ypline[datalen] = '\0';
if (__ypparse(&_pw_passwd, __ypline))
goto again;
- _THREAD_PRIVATE_MUTEX_UNLOCK(pw);
return &_pw_passwd;
}
#endif
@@ -491,10 +479,8 @@ again:
}
}
#endif
- _THREAD_PRIVATE_MUTEX_UNLOCK(pw);
return &_pw_passwd;
}
- _THREAD_PRIVATE_MUTEX_UNLOCK(pw);
return (struct passwd *)NULL;
}
@@ -580,8 +566,8 @@ __has_ypmaster()
}
#endif
-static struct passwd *
-getpwnam_unlocked(name)
+struct passwd *
+getpwnam(name)
const char *name;
{
DBT key;
@@ -758,9 +744,13 @@ pwnam_netgrp:
return (rval ? &_pw_passwd : (struct passwd *)NULL);
}
-static struct passwd *
-getpwuid_unlocked (uid)
+struct passwd *
+#ifdef __STDC__
+getpwuid(uid_t uid)
+#else
+getpwuid(uid)
uid_t uid;
+#endif
{
DBT key;
char bf[sizeof(_pw_keynum) + 1];
@@ -934,119 +924,10 @@ pwuid_netgrp:
return (rval ? &_pw_passwd : (struct passwd *)NULL);
}
-/* XXX copy static storage into user's buffer */
-static int
-fill_reent(src, pwd, buffer, bufsize, result)
- struct passwd *src;
- struct passwd *pwd;
- char *buffer;
- size_t bufsize;
- struct passwd **result;
-{
- int len;
-
- *result = NULL;
- if (src == NULL) {
- if (errno == 0)
- return ENOENT;
- return errno;
- }
-
-#define fill_alloc(field) \
- if (src->field == NULL) \
- pwd->field = NULL; \
- else { \
- len = strlen(src->field) + 1; \
- if (len > bufsize) \
- return ERANGE; \
- memcpy(buffer, src->field, len); \
- pwd->field = buffer; \
- buffer += len; \
- bufsize -= len; \
- }
-
- fill_alloc(pw_name)
- fill_alloc(pw_passwd)
- pwd->pw_uid = src->pw_uid;
- pwd->pw_gid = src->pw_gid;
- pwd->pw_change = src->pw_change;
- fill_alloc(pw_class)
- fill_alloc(pw_gecos)
- fill_alloc(pw_dir)
- fill_alloc(pw_shell)
- pwd->pw_expire = src->pw_expire;
-
-#undef fill_alloc
-
- *result = pwd;
- return 0;
-}
-
-struct passwd *
-getpwnam(name)
- const char *name;
-{
- struct passwd *ret;
-
- _THREAD_PRIVATE_MUTEX_LOCK(pw);
- ret = getpwnam_unlocked(name);
- _THREAD_PRIVATE_MUTEX_UNLOCK(pw);
- return ret;
-}
-
-int
-getpwnam_r(name, pwd, buffer, bufsize, result)
- const char *name;
- struct passwd *pwd;
- char *buffer;
- size_t bufsize;
- struct passwd **result;
-{
- int error;
- struct passwd *pw;
-
- _THREAD_PRIVATE_MUTEX_LOCK(pw);
- pw = getpwnam_unlocked(name);
- error = fill_reent(pw, pwd, buffer, bufsize, result);
- _THREAD_PRIVATE_MUTEX_UNLOCK(pw);
- return error;
-}
-
-struct passwd *
-getpwuid(uid)
- uid_t uid;
-{
- struct passwd *ret;
-
- _THREAD_PRIVATE_MUTEX_LOCK(pw);
- ret = getpwuid_unlocked(uid);
- _THREAD_PRIVATE_MUTEX_UNLOCK(pw);
- return ret;
-}
-
-int
-getpwuid_r(uid, pwd, buffer, bufsize, result)
- uid_t uid;
- struct passwd *pwd;
- char *buffer;
- size_t bufsize;
- struct passwd **result;
-{
- int error;
- struct passwd *pw;
-
- _THREAD_PRIVATE_MUTEX_LOCK(pw);
- pw = getpwuid_unlocked(uid);
- error = fill_reent(pw, pwd, buffer, bufsize, result);
- _THREAD_PRIVATE_MUTEX_UNLOCK(pw);
- return error;
-}
-
int
setpassent(stayopen)
int stayopen;
{
- _THREAD_PRIVATE_MUTEX_LOCK(pw);
_pw_keynum = 0;
_pw_stayopen = stayopen;
#ifdef YP
@@ -1057,7 +938,6 @@ setpassent(stayopen)
__ypexclude_free();
__ypproto = (struct passwd *)NULL;
#endif
- _THREAD_PRIVATE_MUTEX_UNLOCK(pw);
return (1);
}
@@ -1070,7 +950,6 @@ setpwent()
void
endpwent()
{
- _THREAD_PRIVATE_MUTEX_LOCK(pw);
_pw_keynum = 0;
if (_pw_db) {
(void)(_pw_db->close)(_pw_db);
@@ -1084,7 +963,6 @@ endpwent()
__ypexclude_free();
__ypproto = (struct passwd *)NULL;
#endif
- _THREAD_PRIVATE_MUTEX_UNLOCK(pw);
}
static int