Subject: bin/13738: ssh doesn't look at $HOME
To: None <gnats-bugs@gnats.netbsd.org>
From: Johan Danielsson <joda@pdc.kth.se>
List: netbsd-bugs
Date: 08/17/2001 11:48:05
>Number: 13738
>Category: bin
>Synopsis: ssh doesn't look at $HOME
>Confidential: no
>Severity: non-critical
>Priority: high
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Aug 17 02:44:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Johan Danielsson
>Release: 2001-08-17
>Organization:
>Environment:
<machine, os, target, libraries (multiple lines)>
System: NetBSD blubb.pdc.kth.se 1.5X NetBSD 1.5X (BLUBB) #341: Mon Jul 30 15:17:40 CEST 2001 joda@blubb.pdc.kth.se:/usr/misc/src/netbsd/netbsd-cvs/src/sys/arch/i386/compile/BLUBB i386
Architecture: i386
Machine: i386
>Description:
ssh(1) talks about $HOME/.ssh/this and $HOME/.ssh/that, when it infact
never looks at the $HOME variable, only at what's returned by
getpwuid()
>How-To-Repeat:
Try
HOME=/tmp/foobar ssh host command
and see it complain that it can't add the host key to ~/.ssh/known_hosts
>Fix:
--- tildexpand.c 2001/04/10 08:08:05 1.4
+++ tildexpand.c 2001/08/17 09:40:56
@@ -29,6 +29,7 @@
u_int userlen;
char *expanded;
struct passwd *pw;
+ const char *homedir = NULL;
char user[100];
int len;
@@ -45,8 +46,11 @@
userlen = cp - filename; /* Something after username. */
else
userlen = strlen(filename); /* Nothing after username. */
- if (userlen == 0)
+ if (userlen == 0) {
+ homedir = getenv("HOME");
+ if(homedir == NULL)
pw = getpwuid(my_uid); /* Own home directory. */
+ }
else {
/* Tilde refers to someone elses home directory. */
if (userlen > sizeof(user) - 1)
@@ -55,19 +59,21 @@
user[userlen] = 0;
pw = getpwnam(user);
}
- if (!pw)
+ if (!homedir && !pw)
fatal("Unknown user %100s.", user);
+ if(!homedir)
+ homedir = pw->pw_dir;
/* 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", pw->pw_dir, cp + 1);
+ snprintf(expanded, len, "%s/%s", homedir, cp + 1);
return expanded;
}
>Release-Note:
>Audit-Trail:
>Unformatted: