summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-02 12:22:28 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-02 12:22:28 +0000
commit30b02325cbb369e92e7f4ee7763afdf07aa6e78b (patch)
tree2932f8bdf37d9f6166703edf8b89f6cca3759836
parent1fceffa4348b0e13c7590b0afd3ababfabe0d2ef (diff)
downloadlibssh-30b02325cbb369e92e7f4ee7763afdf07aa6e78b.tar.gz
libssh-30b02325cbb369e92e7f4ee7763afdf07aa6e78b.tar.xz
libssh-30b02325cbb369e92e7f4ee7763afdf07aa6e78b.zip
Improve ssh_options_default_username().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@360 7dcaeef0-15fb-0310-b436-a5af3365683c
-rw-r--r--libssh/options.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/libssh/options.c b/libssh/options.c
index 8e1f5ce7..844f9f66 100644
--- a/libssh/options.c
+++ b/libssh/options.c
@@ -545,34 +545,38 @@ static char *get_username_from_uid(SSH_OPTIONS *opt, uid_t uid){
#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 = NULL;
+int ssh_options_default_username(SSH_OPTIONS *opt) {
+ char *user = NULL;
- if (opt->username) {
- return 0;
- }
+ if (opt == NULL) {
+ return -1;
+ }
+
+ if (opt->username) {
+ return 0;
+ }
#ifndef _WIN32
- user=get_username_from_uid(opt,getuid());
- if(user){
- opt->username=user;
- return 0;
- }
+ user = get_username_from_uid(opt,getuid());
+ if (user) {
+ opt->username = user;
+ return 0;
+ }
#else
- DWORD Size = 0;
- GetUserName(NULL, &Size); //Get Size
- user = malloc(Size);
- if (user == NULL) {
- return -1;
- }
- if (GetUserName(user, &Size)){
- opt->username=user;
- return 0;
- } else {
- free(user);
- }
-#endif
+ DWORD Size = 0;
+ GetUserName(NULL, &Size); //Get Size
+ user = malloc(Size);
+ if (user == NULL) {
return -1;
+ }
+ if (GetUserName(user, &Size)) {
+ opt->username=user;
+ return 0;
+ } else {
+ SAFE_FREE(user);
+ }
+#endif
+ return -1;
}
int ssh_options_default_ssh_dir(SSH_OPTIONS *opt){