summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2010-01-15 12:38:30 +1100
committerDarren Tucker <dtucker@zip.com.au>2010-01-15 12:38:30 +1100
commit909a390bb812b49f283a4b02e0cc8d582f020fb2 (patch)
tree0d4783272f979ef6d289cd585421f33a2483060c
parent9d1fd5bc1017c09bc9ff8b28511b0851fd3472a4 (diff)
- (dtucker) [configure.ac openbsd-compat/{Makefile.in,pwcache.c} Portability
for pwcache. Also, added caching of negative hits.
-rw-r--r--ChangeLog2
-rw-r--r--configure.ac8
-rw-r--r--openbsd-compat/Makefile.in4
-rw-r--r--openbsd-compat/pwcache.c29
4 files changed, 31 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 5e2caf338..d7b082248 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -23,6 +23,8 @@
23 ok dtucker@ 23 ok dtucker@
24 - (dtucker) [openbsd-compat.c/pwcache.c] Pull in pwcache.c from OpenBSD (no 24 - (dtucker) [openbsd-compat.c/pwcache.c] Pull in pwcache.c from OpenBSD (no
25 changes yet but there will be some to come). 25 changes yet but there will be some to come).
26 - (dtucker) [configure.ac openbsd-compat/{Makefile.in,pwcache.c} Portability
27 for pwcache. Also, added caching of negative hits.
26 28
2720100114 2920100114
28 - (djm) [platform.h] Add missing prototype for 30 - (djm) [platform.h] Add missing prototype for
diff --git a/configure.ac b/configure.ac
index e6e6259bd..3293e61c6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
1# $Id: configure.ac,v 1.434 2010/01/09 23:26:58 dtucker Exp $ 1# $Id: configure.ac,v 1.435 2010/01/15 01:38:30 dtucker Exp $
2# 2#
3# Copyright (c) 1999-2004 Damien Miller 3# Copyright (c) 1999-2004 Damien Miller
4# 4#
@@ -15,7 +15,7 @@
15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 16
17AC_INIT(OpenSSH, Portable, openssh-unix-dev@mindrot.org) 17AC_INIT(OpenSSH, Portable, openssh-unix-dev@mindrot.org)
18AC_REVISION($Revision: 1.434 $) 18AC_REVISION($Revision: 1.435 $)
19AC_CONFIG_SRCDIR([ssh.c]) 19AC_CONFIG_SRCDIR([ssh.c])
20 20
21AC_CONFIG_HEADER(config.h) 21AC_CONFIG_HEADER(config.h)
@@ -1351,6 +1351,7 @@ AC_CHECK_FUNCS( \
1351 getrlimit \ 1351 getrlimit \
1352 getttyent \ 1352 getttyent \
1353 glob \ 1353 glob \
1354 group_from_gid \
1354 inet_aton \ 1355 inet_aton \
1355 inet_ntoa \ 1356 inet_ntoa \
1356 inet_ntop \ 1357 inet_ntop \
@@ -1377,8 +1378,10 @@ AC_CHECK_FUNCS( \
1377 setegid \ 1378 setegid \
1378 setenv \ 1379 setenv \
1379 seteuid \ 1380 seteuid \
1381 setgroupent \
1380 setgroups \ 1382 setgroups \
1381 setlogin \ 1383 setlogin \
1384 setpassent\
1382 setpcred \ 1385 setpcred \
1383 setproctitle \ 1386 setproctitle \
1384 setregid \ 1387 setregid \
@@ -1407,6 +1410,7 @@ AC_CHECK_FUNCS( \
1407 truncate \ 1410 truncate \
1408 unsetenv \ 1411 unsetenv \
1409 updwtmpx \ 1412 updwtmpx \
1413 user_from_uid \
1410 vasprintf \ 1414 vasprintf \
1411 vhangup \ 1415 vhangup \
1412 vsnprintf \ 1416 vsnprintf \
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in
index a60e5a68d..d65b77b5b 100644
--- a/openbsd-compat/Makefile.in
+++ b/openbsd-compat/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.43 2008/06/08 17:32:29 dtucker Exp $ 1# $Id: Makefile.in,v 1.44 2010/01/15 01:38:30 dtucker Exp $
2 2
3sysconfdir=@sysconfdir@ 3sysconfdir=@sysconfdir@
4piddir=@piddir@ 4piddir=@piddir@
@@ -16,7 +16,7 @@ RANLIB=@RANLIB@
16INSTALL=@INSTALL@ 16INSTALL=@INSTALL@
17LDFLAGS=-L. @LDFLAGS@ 17LDFLAGS=-L. @LDFLAGS@
18 18
19OPENBSD=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 19OPENBSD=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
20 20
21COMPAT=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 21COMPAT=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
22 22
diff --git a/openbsd-compat/pwcache.c b/openbsd-compat/pwcache.c
index 6f8e6447e..472505d02 100644
--- a/openbsd-compat/pwcache.c
+++ b/openbsd-compat/pwcache.c
@@ -28,22 +28,26 @@
28 * SUCH DAMAGE. 28 * SUCH DAMAGE.
29 */ 29 */
30 30
31/* OPENBSD ORIGINAL: lib/libc/gen/pwcache.c */
32
31#include <sys/types.h> 33#include <sys/types.h>
32 34
33#include <grp.h> 35#include <grp.h>
34#include <pwd.h> 36#include <pwd.h>
35#include <stdio.h> 37#include <stdio.h>
38#include <stdlib.h>
36#include <string.h> 39#include <string.h>
37 40
38#define NCACHE 64 /* power of 2 */ 41#define NCACHE 64 /* power of 2 */
39#define MASK (NCACHE - 1) /* bits to store with */ 42#define MASK (NCACHE - 1) /* bits to store with */
40 43
44#ifndef HAVE_USER_FROM_UID
41char * 45char *
42user_from_uid(uid_t uid, int nouser) 46user_from_uid(uid_t uid, int nouser)
43{ 47{
44 static struct ncache { 48 static struct ncache {
45 uid_t uid; 49 uid_t uid;
46 char name[_PW_NAME_LEN + 1]; 50 char *name;
47 } c_uid[NCACHE]; 51 } c_uid[NCACHE];
48 static int pwopen; 52 static int pwopen;
49 static char nbuf[15]; /* 32 bits == 10 digits */ 53 static char nbuf[15]; /* 32 bits == 10 digits */
@@ -51,29 +55,34 @@ user_from_uid(uid_t uid, int nouser)
51 struct ncache *cp; 55 struct ncache *cp;
52 56
53 cp = c_uid + (uid & MASK); 57 cp = c_uid + (uid & MASK);
54 if (cp->uid != uid || !*cp->name) { 58 if (cp->uid != uid || cp->name == NULL) {
59#ifdef HAVE_SETPASSENT
55 if (pwopen == 0) { 60 if (pwopen == 0) {
56 setpassent(1); 61 setpassent(1);
57 pwopen = 1; 62 pwopen = 1;
58 } 63 }
64#endif
59 if ((pw = getpwuid(uid)) == NULL) { 65 if ((pw = getpwuid(uid)) == NULL) {
60 if (nouser) 66 if (nouser)
61 return (NULL); 67 return (NULL);
62 (void)snprintf(nbuf, sizeof(nbuf), "%u", uid); 68 (void)snprintf(nbuf, sizeof(nbuf), "%u", uid);
63 return (nbuf);
64 } 69 }
65 cp->uid = uid; 70 cp->uid = uid;
66 strlcpy(cp->name, pw->pw_name, sizeof(cp->name)); 71 if (cp->name != NULL)
72 free(cp->name);
73 cp->name = strdup(pw ? pw->pw_name : nbuf);
67 } 74 }
68 return (cp->name); 75 return (cp->name);
69} 76}
77#endif
70 78
79#ifndef HAVE_GROUP_FROM_GID
71char * 80char *
72group_from_gid(gid_t gid, int nogroup) 81group_from_gid(gid_t gid, int nogroup)
73{ 82{
74 static struct ncache { 83 static struct ncache {
75 gid_t gid; 84 gid_t gid;
76 char name[_PW_NAME_LEN + 1]; 85 char *name;
77 } c_gid[NCACHE]; 86 } c_gid[NCACHE];
78 static int gropen; 87 static int gropen;
79 static char nbuf[15]; /* 32 bits == 10 digits */ 88 static char nbuf[15]; /* 32 bits == 10 digits */
@@ -81,19 +90,23 @@ group_from_gid(gid_t gid, int nogroup)
81 struct ncache *cp; 90 struct ncache *cp;
82 91
83 cp = c_gid + (gid & MASK); 92 cp = c_gid + (gid & MASK);
84 if (cp->gid != gid || !*cp->name) { 93 if (cp->gid != gid || cp->name == NULL) {
94#ifdef HAVE_SETGROUPENT
85 if (gropen == 0) { 95 if (gropen == 0) {
86 setgroupent(1); 96 setgroupent(1);
87 gropen = 1; 97 gropen = 1;
88 } 98 }
99#endif
89 if ((gr = getgrgid(gid)) == NULL) { 100 if ((gr = getgrgid(gid)) == NULL) {
90 if (nogroup) 101 if (nogroup)
91 return (NULL); 102 return (NULL);
92 (void)snprintf(nbuf, sizeof(nbuf), "%u", gid); 103 (void)snprintf(nbuf, sizeof(nbuf), "%u", gid);
93 return (nbuf);
94 } 104 }
95 cp->gid = gid; 105 cp->gid = gid;
96 strlcpy(cp->name, gr->gr_name, sizeof(cp->name)); 106 if (cp->name != NULL)
107 free(cp->name);
108 cp->name = strdup(gr ? gr->gr_name : nbuf);
97 } 109 }
98 return (cp->name); 110 return (cp->name);
99} 111}
112#endif