aboutsummaryrefslogtreecommitdiff
path: root/libssh/misc.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2008-12-19 15:29:33 +0000
committerAris Adamantiadis <aris@0xbadc0de.be>2008-12-19 15:29:33 +0000
commita104c2eda38d2fbf81285e0223ed755783792169 (patch)
tree16e4022a9db38976ae0685e3a2011ba4575a7afb /libssh/misc.c
parent16a3379a610ec41a5bed1755fc9eeabf9c8b37b4 (diff)
downloadlibssh-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/misc.c')
-rw-r--r--libssh/misc.c54
1 files changed, 11 insertions, 43 deletions
diff --git a/libssh/misc.c b/libssh/misc.c
index 963748fb..0ec37b2b 100644
--- a/libssh/misc.c
+++ b/libssh/misc.c
@@ -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;
-}
+char *ssh_get_user_home_dir(){
+ static char szPath[PATH_MAX] = {0};
+ struct passwd *pwd = NULL;
-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;
- }
+ pwd = getpwuid(getuid());
+ if (pwd == NULL) {
+ return NULL;
}
- 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);
- }
- return get_homedir_from_uid(getuid());
+ snprintf(szPath, PATH_MAX - 1, "%s", pwd->pw_dir);
+
+ return szPath;
}
#else /* _WIN32 */