mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +09:00
Improve ssh_options_default_username().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@360 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -545,34 +545,38 @@ static char *get_username_from_uid(SSH_OPTIONS *opt, uid_t uid){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* this function must be called when no specific username has been asked. it has to guess it */
|
/* 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){
|
int ssh_options_default_username(SSH_OPTIONS *opt) {
|
||||||
char *user = NULL;
|
char *user = NULL;
|
||||||
|
|
||||||
if (opt->username) {
|
if (opt == NULL) {
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opt->username) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
user=get_username_from_uid(opt,getuid());
|
user = get_username_from_uid(opt,getuid());
|
||||||
if(user){
|
if (user) {
|
||||||
opt->username=user;
|
opt->username = user;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
DWORD Size = 0;
|
DWORD Size = 0;
|
||||||
GetUserName(NULL, &Size); //Get Size
|
GetUserName(NULL, &Size); //Get Size
|
||||||
user = malloc(Size);
|
user = malloc(Size);
|
||||||
if (user == NULL) {
|
if (user == NULL) {
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (GetUserName(user, &Size)){
|
|
||||||
opt->username=user;
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
free(user);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return -1;
|
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){
|
int ssh_options_default_ssh_dir(SSH_OPTIONS *opt){
|
||||||
|
|||||||
Reference in New Issue
Block a user