diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2008-12-19 15:29:33 +0000 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2008-12-19 15:29:33 +0000 |
commit | a104c2eda38d2fbf81285e0223ed755783792169 (patch) | |
tree | 16e4022a9db38976ae0685e3a2011ba4575a7afb /libssh/options.c | |
parent | 16a3379a610ec41a5bed1755fc9eeabf9c8b37b4 (diff) | |
download | libssh-a104c2eda38d2fbf81285e0223ed755783792169.tar.gz libssh-a104c2eda38d2fbf81285e0223ed755783792169.tar.xz libssh-a104c2eda38d2fbf81285e0223ed755783792169.zip |
http://www.cynapses.org/tmp/patches/libssh/0001-Replace-getenv-USER-with-getpwuid-functions.patch
from andreas (mostly userdirectory cleaning)
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@193 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/options.c')
-rw-r--r-- | libssh/options.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/libssh/options.c b/libssh/options.c index d95b329..762980d 100644 --- a/libssh/options.c +++ b/libssh/options.c @@ -294,32 +294,28 @@ int ssh_options_set_wanted_algos(SSH_OPTIONS *opt, int algo, const char *list){ } #ifndef _WIN32 -static char *get_username_from_uid(SSH_OPTIONS *opt, int uid){ - struct passwd *pwd; - char *user; - while((pwd=getpwent())){ - if(pwd->pw_uid == uid){ - user=strdup(pwd->pw_name); - endpwent(); - return user; - } +static char *get_username_from_uid(SSH_OPTIONS *opt, uid_t uid){ + struct passwd *pwd = NULL; + + pwd = getpwuid(uid); + + if (pwd == NULL) { + ssh_set_error(opt,SSH_FATAL,"uid %d doesn't exist !",uid); + return NULL; } - endpwent(); - ssh_set_error(opt,SSH_FATAL,"uid %d doesn't exist !",uid); - return NULL; + + return strdup(pwd->pw_name); } #endif /* this function must be called when no specific username has been asked. it has to guess it */ int ssh_options_default_username(SSH_OPTIONS *opt){ - char *user; - if(opt->username) - return 0; - user=getenv("USER"); - if(user){ - opt->username=strdup(user); + char *user = NULL; + + if (opt->username) { return 0; } + #ifndef _WIN32 user=get_username_from_uid(opt,getuid()); if(user){ |