aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-12-21 12:32:58 +0100
committerAndreas Schneider <mail@cynapses.org>2009-12-21 12:32:58 +0100
commit23dcc2c7f35d575aefa051aab676233cf734c076 (patch)
treedd7b559fe62f239c1f1148a357f5a153c2b7f804
parent91f7d127ea57a2f8ed1b2aa002bbec0d1ee64424 (diff)
downloadlibssh-23dcc2c7f35d575aefa051aab676233cf734c076.tar.gz
libssh-23dcc2c7f35d575aefa051aab676233cf734c076.tar.xz
libssh-23dcc2c7f35d575aefa051aab676233cf734c076.zip
Fixed ssh_get_user_home_dir() to be thread safe.
-rw-r--r--libssh/misc.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/libssh/misc.c b/libssh/misc.c
index 71679d40..b94241a4 100644
--- a/libssh/misc.c
+++ b/libssh/misc.c
@@ -112,16 +112,23 @@ int gettimeofday(struct timeval *__p, void *__t) {
return (0);
}
#else /* _WIN32 */
+#ifndef NSS_BUFLEN_PASSWD
+#define NSS_BUFLEN_PASSWD 4096
+#endif
+
char *ssh_get_user_home_dir(void) {
char *szPath = NULL;
- struct passwd *pwd = NULL;
+ struct passwd pwd;
+ struct passwd *pwdbuf;
+ char buf[NSS_BUFLEN_PASSWD];
+ int rc;
- pwd = getpwuid(getuid());
- if (pwd == NULL) {
+ rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
+ if (rc != 0) {
return NULL;
}
- szPath = strdup(pwd->pw_dir);
+ szPath = strdup(pwd.pw_dir);
return szPath;
}