Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/crypto/dist/ssh PR/13738: Johan Danielsson: ssh doesn't look...



details:   https://anonhg.NetBSD.org/src/rev/af46e871f9e4
branches:  trunk
changeset: 584457:af46e871f9e4
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Sep 18 18:39:05 2005 +0000

description:
PR/13738: Johan Danielsson: ssh doesn't look at $HOME

diffstat:

 crypto/dist/ssh/tildexpand.c |  30 +++++++++++++++++++-----------
 1 files changed, 19 insertions(+), 11 deletions(-)

diffs (73 lines):

diff -r 4aa3b9d71ee5 -r af46e871f9e4 crypto/dist/ssh/tildexpand.c
--- a/crypto/dist/ssh/tildexpand.c      Sun Sep 18 18:27:28 2005 +0000
+++ b/crypto/dist/ssh/tildexpand.c      Sun Sep 18 18:39:05 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tildexpand.c,v 1.8 2005/02/13 05:57:27 christos Exp $  */
+/*     $NetBSD: tildexpand.c,v 1.9 2005/09/18 18:39:05 christos Exp $  */
 /*
  * Author: Tatu Ylonen <ylo%cs.hut.fi@localhost>
  * Copyright (c) 1995 Tatu Ylonen <ylo%cs.hut.fi@localhost>, Espoo, Finland
@@ -13,7 +13,7 @@
 
 #include "includes.h"
 RCSID("$OpenBSD: tildexpand.c,v 1.15 2004/05/21 08:43:03 markus Exp $");
-__RCSID("$NetBSD: tildexpand.c,v 1.8 2005/02/13 05:57:27 christos Exp $");
+__RCSID("$NetBSD: tildexpand.c,v 1.9 2005/09/18 18:39:05 christos Exp $");
 
 #include "xmalloc.h"
 #include "log.h"
@@ -31,6 +31,7 @@
        char *expanded;
        struct passwd *pw;
        char user[100];
+       const char *homedir = NULL;
        int len;
 
        /* Return immediately if no tilde. */
@@ -46,30 +47,37 @@
                userlen = cp - filename;        /* Something after username. */
        else
                userlen = strlen(filename);     /* Nothing after username. */
-       if (userlen == 0)
-               pw = getpwuid(my_uid);          /* Own home directory. */
-       else {
+       if (userlen == 0) {
+               if ((homedir = getenv("HOME")) == NULL) {
+                       pw = getpwuid(my_uid);  /* Own home directory. */
+                       if (!pw)
+                               fatal("No password entry for uid %d.",
+                                   (int)my_uid);
+                       homedir = pw->pw_dir;
+               }
+       } else {
                /* Tilde refers to someone elses home directory. */
                if (userlen > sizeof(user) - 1)
                        fatal("User name after tilde too long.");
                memcpy(user, filename, userlen);
                user[userlen] = 0;
                pw = getpwnam(user);
+               if (!pw)
+                       fatal("Unknown user %100s.", user);
+               homedir = pw->pw_dir;
        }
-       if (!pw)
-               fatal("Unknown user %100s.", user);
 
        /* If referring to someones home directory, return it now. */
        if (!cp) {
                /* Only home directory specified */
-               return xstrdup(pw->pw_dir);
+               return xstrdup(homedir);
        }
        /* Build a path combining the specified directory and path. */
-       len = strlen(pw->pw_dir) + strlen(cp + 1) + 2;
+       len = strlen(homedir) + strlen(cp + 1) + 2;
        if (len > MAXPATHLEN)
                fatal("Home directory too long (%d > %d", len-1, MAXPATHLEN-1);
        expanded = xmalloc(len);
-       snprintf(expanded, len, "%s%s%s", pw->pw_dir,
-           strcmp(pw->pw_dir, "/") ? "/" : "", cp + 1);
+       snprintf(expanded, len, "%s%s%s", homedir,
+           strcmp(homedir, "/") ? "/" : "", cp + 1);
        return expanded;
 }



Home | Main Index | Thread Index | Old Index