diff options
author | millert <> | 2015-11-24 22:03:33 +0000 |
---|---|---|
committer | millert <> | 2015-11-24 22:03:33 +0000 |
commit | d0a2512c90ba0643904f25de1b66ccfc86502617 (patch) | |
tree | 2ff05b2b872a27106976e6dd366bcbc261b1d2eb /src | |
parent | 538f104d39a36dc15e460dc8b641f8f410d06b85 (diff) | |
download | openbsd-d0a2512c90ba0643904f25de1b66ccfc86502617.tar.gz openbsd-d0a2512c90ba0643904f25de1b66ccfc86502617.tar.bz2 openbsd-d0a2512c90ba0643904f25de1b66ccfc86502617.zip |
Use reentrant versions of getpw{nam,uid} and getgr{nam,gid} within
libc to avoid reusing the static buffers returned by the non-reentrant
versions. Since this is inside libc we can use constants for the
buffer sizes instead of having to call sysconf().
OK guenther@ deraadt@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libc/net/rcmdsh.c | 9 | ||||
-rw-r--r-- | src/lib/libc/net/ruserok.c | 8 |
2 files changed, 10 insertions, 7 deletions
diff --git a/src/lib/libc/net/rcmdsh.c b/src/lib/libc/net/rcmdsh.c index 5d468ff4c4..14275d414a 100644 --- a/src/lib/libc/net/rcmdsh.c +++ b/src/lib/libc/net/rcmdsh.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rcmdsh.c,v 1.17 2015/11/01 03:45:29 guenther Exp $ */ | 1 | /* $OpenBSD: rcmdsh.c,v 1.18 2015/11/24 22:03:33 millert Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2001, MagniComp | 4 | * Copyright (c) 2001, MagniComp |
@@ -58,15 +58,16 @@ rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, | |||
58 | struct hostent *hp; | 58 | struct hostent *hp; |
59 | int sp[2]; | 59 | int sp[2]; |
60 | pid_t cpid; | 60 | pid_t cpid; |
61 | char *p; | 61 | char *p, pwbuf[_PW_BUF_LEN]; |
62 | struct passwd *pw; | 62 | struct passwd pwstore, *pw = NULL; |
63 | 63 | ||
64 | /* What rsh/shell to use. */ | 64 | /* What rsh/shell to use. */ |
65 | if (rshprog == NULL) | 65 | if (rshprog == NULL) |
66 | rshprog = _PATH_RSH; | 66 | rshprog = _PATH_RSH; |
67 | 67 | ||
68 | /* locuser must exist on this host. */ | 68 | /* locuser must exist on this host. */ |
69 | if ((pw = getpwnam(locuser)) == NULL) { | 69 | getpwnam_r(locuser, &pwstore, pwbuf, sizeof(pwbuf), &pw); |
70 | if (pw == NULL) { | ||
70 | (void) fprintf(stderr, "rcmdsh: unknown user: %s\n", locuser); | 71 | (void) fprintf(stderr, "rcmdsh: unknown user: %s\n", locuser); |
71 | return(-1); | 72 | return(-1); |
72 | } | 73 | } |
diff --git a/src/lib/libc/net/ruserok.c b/src/lib/libc/net/ruserok.c index 88c89ac40f..7dda9550a8 100644 --- a/src/lib/libc/net/ruserok.c +++ b/src/lib/libc/net/ruserok.c | |||
@@ -111,11 +111,11 @@ iruserok_sa(const void *raddr, int rlen, int superuser, const char *ruser, | |||
111 | struct sockaddr *sa; | 111 | struct sockaddr *sa; |
112 | char *cp; | 112 | char *cp; |
113 | struct stat sbuf; | 113 | struct stat sbuf; |
114 | struct passwd *pwd; | 114 | struct passwd pwstore, *pwd; |
115 | FILE *hostf; | 115 | FILE *hostf; |
116 | uid_t uid; | 116 | uid_t uid; |
117 | int first; | 117 | int first; |
118 | char pbuf[PATH_MAX]; | 118 | char pbuf[PATH_MAX], pwbuf[_PW_BUF_LEN]; |
119 | 119 | ||
120 | sa = (struct sockaddr *)raddr; | 120 | sa = (struct sockaddr *)raddr; |
121 | first = 1; | 121 | first = 1; |
@@ -132,7 +132,9 @@ again: | |||
132 | int len; | 132 | int len; |
133 | 133 | ||
134 | first = 0; | 134 | first = 0; |
135 | if ((pwd = getpwnam(luser)) == NULL) | 135 | pwd = NULL; |
136 | getpwnam_r(luser, &pwstore, pwbuf, sizeof(pwbuf), &pwd); | ||
137 | if (pwd == NULL) | ||
136 | return (-1); | 138 | return (-1); |
137 | len = snprintf(pbuf, sizeof pbuf, "%s/.rhosts", pwd->pw_dir); | 139 | len = snprintf(pbuf, sizeof pbuf, "%s/.rhosts", pwd->pw_dir); |
138 | if (len < 0 || len >= sizeof pbuf) | 140 | if (len < 0 || len >= sizeof pbuf) |