from andreas (mostly userdirectory cleaning) git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@193 7dcaeef0-15fb-0310-b436-a5af3365683c
Этот коммит содержится в:
родитель
16a3379a61
Коммит
a104c2eda3
@ -20,6 +20,8 @@ You should have received a copy of the GNU Lesser General Public License
|
||||
along with the SSH Library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA. */
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
@ -37,52 +39,18 @@ MA 02111-1307, USA. */
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
/* if the program was executed suid root, don't trust the user ! */
|
||||
static int is_trusted(){
|
||||
if(geteuid()!=getuid())
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char *get_homedir_from_uid(int uid){
|
||||
struct passwd *pwd;
|
||||
char *home;
|
||||
while((pwd=getpwent())){
|
||||
if(pwd->pw_uid == uid){
|
||||
home=strdup(pwd->pw_dir);
|
||||
endpwent();
|
||||
return home;
|
||||
}
|
||||
}
|
||||
endpwent();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *get_homedir_from_login(char *user){
|
||||
struct passwd *pwd;
|
||||
char *home;
|
||||
while((pwd=getpwent())){
|
||||
if(!strcmp(pwd->pw_name,user)){
|
||||
home=strdup(pwd->pw_dir);
|
||||
endpwent();
|
||||
return home;
|
||||
}
|
||||
}
|
||||
endpwent();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *ssh_get_user_home_dir(){
|
||||
char *home;
|
||||
char *user;
|
||||
int trusted=is_trusted();
|
||||
if(trusted){
|
||||
if((home=getenv("HOME")))
|
||||
return strdup(home);
|
||||
if((user=getenv("USER")))
|
||||
return get_homedir_from_login(user);
|
||||
static char szPath[PATH_MAX] = {0};
|
||||
struct passwd *pwd = NULL;
|
||||
|
||||
pwd = getpwuid(getuid());
|
||||
if (pwd == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return get_homedir_from_uid(getuid());
|
||||
|
||||
snprintf(szPath, PATH_MAX - 1, "%s", pwd->pw_dir);
|
||||
|
||||
return szPath;
|
||||
}
|
||||
|
||||
#else /* _WIN32 */
|
||||
|
@ -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){
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user