summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/Makefile.in4
-rw-r--r--openbsd-compat/pwcache.c29
2 files changed, 23 insertions, 10 deletions
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