]> andersk Git - openssh.git/commitdiff
- (dtucker) [configure.ac openbsd-compat/{Makefile.in,pwcache.c} Portability
authordtucker <dtucker>
Fri, 15 Jan 2010 01:38:30 +0000 (01:38 +0000)
committerdtucker <dtucker>
Fri, 15 Jan 2010 01:38:30 +0000 (01:38 +0000)
   for pwcache.  Also, added caching of negative hits.

ChangeLog
configure.ac
openbsd-compat/Makefile.in
openbsd-compat/pwcache.c

index 5e2caf33874b6fa30c1f7eec53d3ff8b6712d05d..d7b0822484f1d9129b0cd94cd87423d7559fd8bd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -23,6 +23,8 @@
      ok dtucker@
  - (dtucker) [openbsd-compat.c/pwcache.c] Pull in pwcache.c from OpenBSD (no
    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
  - (djm) [platform.h] Add missing prototype for
index 71b313c5943872262234e623cb31f84dbfec538d..2568c52d9fce52646bfecbf5447a2257b49ebede 100644 (file)
@@ -1351,6 +1351,7 @@ AC_CHECK_FUNCS( \
        getrlimit \
        getttyent \
        glob \
+       group_from_gid \
        inet_aton \
        inet_ntoa \
        inet_ntop \
@@ -1377,8 +1378,10 @@ AC_CHECK_FUNCS( \
        setegid \
        setenv \
        seteuid \
+       setgroupent \
        setgroups \
        setlogin \
+       setpassent\
        setpcred \
        setproctitle \
        setregid \
@@ -1407,6 +1410,7 @@ AC_CHECK_FUNCS( \
        truncate \
        unsetenv \
        updwtmpx \
+       user_from_uid \
        vasprintf \
        vhangup \
        vsnprintf \
index 5668dc337a2be17d37fc51c188f1cef8cfcbd4bd..0a5c571d61d5c58b454bb16ad97d308ffd1ad416 100644 (file)
@@ -16,7 +16,7 @@ RANLIB=@RANLIB@
 INSTALL=@INSTALL@
 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
 
index 6f8e6447e994960f9038665d8e190c4bd0eb2fb5..472505d02915ce43677dd39f93fbb906231173a5 100644 (file)
  * SUCH DAMAGE.
  */
 
+/* OPENBSD ORIGINAL: lib/libc/gen/pwcache.c */
+
 #include <sys/types.h>
 
 #include <grp.h>
 #include <pwd.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #define        NCACHE  64                      /* power of 2 */
 #define        MASK    (NCACHE - 1)            /* bits to store with */
 
+#ifndef HAVE_USER_FROM_UID
 char *
 user_from_uid(uid_t uid, int nouser)
 {
        static struct ncache {
                uid_t   uid;
-               char    name[_PW_NAME_LEN + 1];
+               char    *name;
        } c_uid[NCACHE];
        static int pwopen;
        static char nbuf[15];           /* 32 bits == 10 digits */
@@ -51,29 +55,34 @@ user_from_uid(uid_t uid, int nouser)
        struct ncache *cp;
 
        cp = c_uid + (uid & MASK);
-       if (cp->uid != uid || !*cp->name) {
+       if (cp->uid != uid || cp->name == NULL) {
+#ifdef HAVE_SETPASSENT
                if (pwopen == 0) {
                        setpassent(1);
                        pwopen = 1;
                }
+#endif
                if ((pw = getpwuid(uid)) == NULL) {
                        if (nouser)
                                return (NULL);
                        (void)snprintf(nbuf, sizeof(nbuf), "%u", uid);
-                       return (nbuf);
                }
                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);
 }
+#endif
 
+#ifndef HAVE_GROUP_FROM_GID
 char *
 group_from_gid(gid_t gid, int nogroup)
 {
        static struct ncache {
                gid_t   gid;
-               char    name[_PW_NAME_LEN + 1];
+               char    *name;
        } c_gid[NCACHE];
        static int gropen;
        static char nbuf[15];           /* 32 bits == 10 digits */
@@ -81,19 +90,23 @@ group_from_gid(gid_t gid, int nogroup)
        struct ncache *cp;
 
        cp = c_gid + (gid & MASK);
-       if (cp->gid != gid || !*cp->name) {
+       if (cp->gid != gid || cp->name == NULL) {
+#ifdef HAVE_SETGROUPENT
                if (gropen == 0) {
                        setgroupent(1);
                        gropen = 1;
                }
+#endif
                if ((gr = getgrgid(gid)) == NULL) {
                        if (nogroup)
                                return (NULL);
                        (void)snprintf(nbuf, sizeof(nbuf), "%u", gid);
-                       return (nbuf);
                }
                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);
 }
+#endif
This page took 0.090055 seconds and 5 git commands to generate.