- (dtucker) [configure.ac openbsd-compat/{Makefile.in,pwcache.c} Portability

for pwcache.  Also, added caching of negative hits.
This commit is contained in:
Darren Tucker 2010-01-15 12:38:30 +11:00
parent 9d1fd5bc10
commit 909a390bb8
4 changed files with 31 additions and 12 deletions

View File

@ -23,6 +23,8 @@
ok dtucker@ ok dtucker@
- (dtucker) [openbsd-compat.c/pwcache.c] Pull in pwcache.c from OpenBSD (no - (dtucker) [openbsd-compat.c/pwcache.c] Pull in pwcache.c from OpenBSD (no
changes yet but there will be some to come). changes yet but there will be some to come).
- (dtucker) [configure.ac openbsd-compat/{Makefile.in,pwcache.c} Portability
for pwcache. Also, added caching of negative hits.
20100114 20100114
- (djm) [platform.h] Add missing prototype for - (djm) [platform.h] Add missing prototype for

View File

@ -1,4 +1,4 @@
# $Id: configure.ac,v 1.434 2010/01/09 23:26:58 dtucker Exp $ # $Id: configure.ac,v 1.435 2010/01/15 01:38:30 dtucker Exp $
# #
# Copyright (c) 1999-2004 Damien Miller # Copyright (c) 1999-2004 Damien Miller
# #
@ -15,7 +15,7 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
AC_INIT(OpenSSH, Portable, openssh-unix-dev@mindrot.org) AC_INIT(OpenSSH, Portable, openssh-unix-dev@mindrot.org)
AC_REVISION($Revision: 1.434 $) AC_REVISION($Revision: 1.435 $)
AC_CONFIG_SRCDIR([ssh.c]) AC_CONFIG_SRCDIR([ssh.c])
AC_CONFIG_HEADER(config.h) AC_CONFIG_HEADER(config.h)
@ -1351,6 +1351,7 @@ AC_CHECK_FUNCS( \
getrlimit \ getrlimit \
getttyent \ getttyent \
glob \ glob \
group_from_gid \
inet_aton \ inet_aton \
inet_ntoa \ inet_ntoa \
inet_ntop \ inet_ntop \
@ -1377,8 +1378,10 @@ AC_CHECK_FUNCS( \
setegid \ setegid \
setenv \ setenv \
seteuid \ seteuid \
setgroupent \
setgroups \ setgroups \
setlogin \ setlogin \
setpassent\
setpcred \ setpcred \
setproctitle \ setproctitle \
setregid \ setregid \
@ -1407,6 +1410,7 @@ AC_CHECK_FUNCS( \
truncate \ truncate \
unsetenv \ unsetenv \
updwtmpx \ updwtmpx \
user_from_uid \
vasprintf \ vasprintf \
vhangup \ vhangup \
vsnprintf \ vsnprintf \

View File

@ -1,4 +1,4 @@
# $Id: Makefile.in,v 1.43 2008/06/08 17:32:29 dtucker Exp $ # $Id: Makefile.in,v 1.44 2010/01/15 01:38:30 dtucker Exp $
sysconfdir=@sysconfdir@ sysconfdir=@sysconfdir@
piddir=@piddir@ piddir=@piddir@
@ -16,7 +16,7 @@ RANLIB=@RANLIB@
INSTALL=@INSTALL@ INSTALL=@INSTALL@
LDFLAGS=-L. @LDFLAGS@ LDFLAGS=-L. @LDFLAGS@
OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o strtonum.o strtoll.o strtoul.o vis.o OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o strtonum.o strtoll.o strtoul.o vis.o
COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o

View File

@ -28,22 +28,26 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
/* OPENBSD ORIGINAL: lib/libc/gen/pwcache.c */
#include <sys/types.h> #include <sys/types.h>
#include <grp.h> #include <grp.h>
#include <pwd.h> #include <pwd.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#define NCACHE 64 /* power of 2 */ #define NCACHE 64 /* power of 2 */
#define MASK (NCACHE - 1) /* bits to store with */ #define MASK (NCACHE - 1) /* bits to store with */
#ifndef HAVE_USER_FROM_UID
char * char *
user_from_uid(uid_t uid, int nouser) user_from_uid(uid_t uid, int nouser)
{ {
static struct ncache { static struct ncache {
uid_t uid; uid_t uid;
char name[_PW_NAME_LEN + 1]; char *name;
} c_uid[NCACHE]; } c_uid[NCACHE];
static int pwopen; static int pwopen;
static char nbuf[15]; /* 32 bits == 10 digits */ static char nbuf[15]; /* 32 bits == 10 digits */
@ -51,29 +55,34 @@ user_from_uid(uid_t uid, int nouser)
struct ncache *cp; struct ncache *cp;
cp = c_uid + (uid & MASK); cp = c_uid + (uid & MASK);
if (cp->uid != uid || !*cp->name) { if (cp->uid != uid || cp->name == NULL) {
#ifdef HAVE_SETPASSENT
if (pwopen == 0) { if (pwopen == 0) {
setpassent(1); setpassent(1);
pwopen = 1; pwopen = 1;
} }
#endif
if ((pw = getpwuid(uid)) == NULL) { if ((pw = getpwuid(uid)) == NULL) {
if (nouser) if (nouser)
return (NULL); return (NULL);
(void)snprintf(nbuf, sizeof(nbuf), "%u", uid); (void)snprintf(nbuf, sizeof(nbuf), "%u", uid);
return (nbuf);
} }
cp->uid = uid; cp->uid = uid;
strlcpy(cp->name, pw->pw_name, sizeof(cp->name)); if (cp->name != NULL)
free(cp->name);
cp->name = strdup(pw ? pw->pw_name : nbuf);
} }
return (cp->name); return (cp->name);
} }
#endif
#ifndef HAVE_GROUP_FROM_GID
char * char *
group_from_gid(gid_t gid, int nogroup) group_from_gid(gid_t gid, int nogroup)
{ {
static struct ncache { static struct ncache {
gid_t gid; gid_t gid;
char name[_PW_NAME_LEN + 1]; char *name;
} c_gid[NCACHE]; } c_gid[NCACHE];
static int gropen; static int gropen;
static char nbuf[15]; /* 32 bits == 10 digits */ static char nbuf[15]; /* 32 bits == 10 digits */
@ -81,19 +90,23 @@ group_from_gid(gid_t gid, int nogroup)
struct ncache *cp; struct ncache *cp;
cp = c_gid + (gid & MASK); cp = c_gid + (gid & MASK);
if (cp->gid != gid || !*cp->name) { if (cp->gid != gid || cp->name == NULL) {
#ifdef HAVE_SETGROUPENT
if (gropen == 0) { if (gropen == 0) {
setgroupent(1); setgroupent(1);
gropen = 1; gropen = 1;
} }
#endif
if ((gr = getgrgid(gid)) == NULL) { if ((gr = getgrgid(gid)) == NULL) {
if (nogroup) if (nogroup)
return (NULL); return (NULL);
(void)snprintf(nbuf, sizeof(nbuf), "%u", gid); (void)snprintf(nbuf, sizeof(nbuf), "%u", gid);
return (nbuf);
} }
cp->gid = gid; cp->gid = gid;
strlcpy(cp->name, gr->gr_name, sizeof(cp->name)); if (cp->name != NULL)
free(cp->name);
cp->name = strdup(gr ? gr->gr_name : nbuf);
} }
return (cp->name); return (cp->name);
} }
#endif