diff options
-rw-r--r-- | ssh-add.c | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh-add.c,v 1.123 2015/07/03 03:43:18 djm Exp $ */ | 1 | /* $OpenBSD: ssh-add.c,v 1.124 2015/09/13 13:48:19 tim Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -93,7 +93,7 @@ static int lifetime = 0; | |||
93 | /* User has to confirm key use */ | 93 | /* User has to confirm key use */ |
94 | static int confirm = 0; | 94 | static int confirm = 0; |
95 | 95 | ||
96 | /* we keep a cache of one passphrases */ | 96 | /* we keep a cache of one passphrase */ |
97 | static char *pass = NULL; | 97 | static char *pass = NULL; |
98 | static void | 98 | static void |
99 | clear_pass(void) | 99 | clear_pass(void) |
@@ -234,19 +234,17 @@ add_file(int agent_fd, const char *filename, int key_only) | |||
234 | goto fail_load; | 234 | goto fail_load; |
235 | } | 235 | } |
236 | } | 236 | } |
237 | if (comment == NULL) | ||
238 | comment = xstrdup(filename); | ||
239 | if (private == NULL) { | 237 | if (private == NULL) { |
240 | /* clear passphrase since it did not work */ | 238 | /* clear passphrase since it did not work */ |
241 | clear_pass(); | 239 | clear_pass(); |
242 | snprintf(msg, sizeof msg, "Enter passphrase for %.200s%s: ", | 240 | snprintf(msg, sizeof msg, "Enter passphrase for %s%s: ", |
243 | comment, confirm ? " (will confirm each use)" : ""); | 241 | filename, confirm ? " (will confirm each use)" : ""); |
244 | for (;;) { | 242 | for (;;) { |
245 | pass = read_passphrase(msg, RP_ALLOW_STDIN); | 243 | pass = read_passphrase(msg, RP_ALLOW_STDIN); |
246 | if (strcmp(pass, "") == 0) | 244 | if (strcmp(pass, "") == 0) |
247 | goto fail_load; | 245 | goto fail_load; |
248 | if ((r = sshkey_parse_private_fileblob(keyblob, pass, | 246 | if ((r = sshkey_parse_private_fileblob(keyblob, pass, |
249 | filename, &private, NULL)) == 0) | 247 | filename, &private, &comment)) == 0) |
250 | break; | 248 | break; |
251 | else if (r != SSH_ERR_KEY_WRONG_PASSPHRASE) { | 249 | else if (r != SSH_ERR_KEY_WRONG_PASSPHRASE) { |
252 | fprintf(stderr, | 250 | fprintf(stderr, |
@@ -254,16 +252,17 @@ add_file(int agent_fd, const char *filename, int key_only) | |||
254 | filename, ssh_err(r)); | 252 | filename, ssh_err(r)); |
255 | fail_load: | 253 | fail_load: |
256 | clear_pass(); | 254 | clear_pass(); |
257 | free(comment); | ||
258 | sshbuf_free(keyblob); | 255 | sshbuf_free(keyblob); |
259 | return -1; | 256 | return -1; |
260 | } | 257 | } |
261 | clear_pass(); | 258 | clear_pass(); |
262 | snprintf(msg, sizeof msg, | 259 | snprintf(msg, sizeof msg, |
263 | "Bad passphrase, try again for %.200s%s: ", comment, | 260 | "Bad passphrase, try again for %s%s: ", filename, |
264 | confirm ? " (will confirm each use)" : ""); | 261 | confirm ? " (will confirm each use)" : ""); |
265 | } | 262 | } |
266 | } | 263 | } |
264 | if (comment == NULL || *comment == '\0') | ||
265 | comment = xstrdup(filename); | ||
267 | sshbuf_free(keyblob); | 266 | sshbuf_free(keyblob); |
268 | 267 | ||
269 | if ((r = ssh_add_identity_constrained(agent_fd, private, comment, | 268 | if ((r = ssh_add_identity_constrained(agent_fd, private, comment, |