Mercurial > dropbear
comparison cli-kex.c @ 322:84aa4e60bd3c
Look at HOME before /etc/passwd when looking for ~/.ssh/known_hosts
file, so people can workaround broken /etc/passwds. Print
the full path in error messages.
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 07 Jun 2006 13:41:19 +0000 |
parents | 9916350d7d8b |
children | 454a34b2dfd1 |
comparison
equal
deleted
inserted
replaced
321:fa9c45d09727 | 322:84aa4e60bd3c |
---|---|
150 unsigned long len; | 150 unsigned long len; |
151 const char *algoname = NULL; | 151 const char *algoname = NULL; |
152 buffer * line = NULL; | 152 buffer * line = NULL; |
153 int ret; | 153 int ret; |
154 | 154 |
155 pw = getpwuid(getuid()); | 155 homedir = getenv("HOME"); |
156 | 156 |
157 if (pw) | 157 if (!homedir) { |
158 homedir = pw->pw_dir; | 158 pw = getpwuid(getuid()); |
159 } | 159 if (pw) { |
160 pw = NULL; | 160 homedir = pw->pw_dir; |
161 | 161 } |
162 if (!homedir) | 162 pw = NULL; |
163 homedir = getenv("HOME"); | |
164 } | 163 } |
165 | 164 |
166 if (homedir) { | 165 if (homedir) { |
167 | 166 |
168 len = strlen(homedir); | 167 len = strlen(homedir); |
170 | 169 |
171 snprintf(filename, len+18, "%s/.ssh", homedir); | 170 snprintf(filename, len+18, "%s/.ssh", homedir); |
172 /* Check that ~/.ssh exists - easiest way is just to mkdir */ | 171 /* Check that ~/.ssh exists - easiest way is just to mkdir */ |
173 if (mkdir(filename, S_IRWXU) != 0) { | 172 if (mkdir(filename, S_IRWXU) != 0) { |
174 if (errno != EEXIST) { | 173 if (errno != EEXIST) { |
175 dropbear_log(LOG_INFO, "Warning: failed creating ~/.ssh: %s", | 174 dropbear_log(LOG_INFO, "Warning: failed creating %s/.ssh: %s", |
176 strerror(errno)); | 175 homedir, strerror(errno)); |
177 TRACE(("mkdir didn't work: %s", strerror(errno))) | 176 TRACE(("mkdir didn't work: %s", strerror(errno))) |
178 ask_to_confirm(keyblob, keybloblen); | 177 ask_to_confirm(keyblob, keybloblen); |
179 goto out; /* only get here on success */ | 178 goto out; /* only get here on success */ |
180 } | 179 } |
181 } | 180 } |
195 } | 194 } |
196 } | 195 } |
197 | 196 |
198 if (hostsfile == NULL) { | 197 if (hostsfile == NULL) { |
199 TRACE(("hostsfile didn't open: %s", strerror(errno))) | 198 TRACE(("hostsfile didn't open: %s", strerror(errno))) |
200 dropbear_log(LOG_WARNING, "Failed to open ~/.ssh/known_hosts"); | 199 dropbear_log(LOG_WARNING, "Failed to open %s/.ssh/known_hosts", |
200 homedir); | |
201 ask_to_confirm(keyblob, keybloblen); | 201 ask_to_confirm(keyblob, keybloblen); |
202 goto out; /* We only get here on success */ | 202 goto out; /* We only get here on success */ |
203 } | 203 } |
204 | 204 |
205 line = buf_new(MAX_KNOWNHOSTS_LINE); | 205 line = buf_new(MAX_KNOWNHOSTS_LINE); |