summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2002-01-22 23:05:59 +1100
committerDamien Miller <djm@mindrot.org>2002-01-22 23:05:59 +1100
commit6e1057c2d79de5382efc53ceb3e1213cc273ca12 (patch)
treea176ee5ebb45c5382672f1958368e10494352e66
parentf451e22e2134463062f7134f3e3556ab78ea0661 (diff)
- djm@cvs.openbsd.org 2001/12/21 10:06:43
[ssh-add.1 ssh-add.c] Try all standard key files (id_rsa, id_dsa, identity) when invoked with no arguments; ok markus@
-rw-r--r--ChangeLog6
-rw-r--r--ssh-add.17
-rw-r--r--ssh-add.c54
3 files changed, 45 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index db387db2e..76c3e4cab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,10 @@
16 - djm@cvs.openbsd.org 2001/12/21 08:53:45 16 - djm@cvs.openbsd.org 2001/12/21 08:53:45
17 [readpass.c] 17 [readpass.c]
18 Avoid interruptable passphrase read; ok markus@ 18 Avoid interruptable passphrase read; ok markus@
19 - djm@cvs.openbsd.org 2001/12/21 10:06:43
20 [ssh-add.1 ssh-add.c]
21 Try all standard key files (id_rsa, id_dsa, identity) when invoked with
22 no arguments; ok markus@
19 23
2020020121 2420020121
21 - (djm) Rework ssh-rand-helper: 25 - (djm) Rework ssh-rand-helper:
@@ -7163,4 +7167,4 @@
7163 - Wrote replacements for strlcpy and mkdtemp 7167 - Wrote replacements for strlcpy and mkdtemp
7164 - Released 1.0pre1 7168 - Released 1.0pre1
7165 7169
7166$Id: ChangeLog,v 1.1726 2002/01/22 12:05:31 djm Exp $ 7170$Id: ChangeLog,v 1.1727 2002/01/22 12:05:59 djm Exp $
diff --git a/ssh-add.1 b/ssh-add.1
index b842080d6..ef60d0204 100644
--- a/ssh-add.1
+++ b/ssh-add.1
@@ -1,4 +1,4 @@
1.\" $OpenBSD: ssh-add.1,v 1.27 2001/08/23 18:08:59 stevesk Exp $ 1.\" $OpenBSD: ssh-add.1,v 1.28 2001/12/21 10:06:43 djm Exp $
2.\" 2.\"
3.\" -*- nroff -*- 3.\" -*- nroff -*-
4.\" 4.\"
@@ -55,7 +55,10 @@
55.Nm 55.Nm
56adds RSA or DSA identities to the authentication agent, 56adds RSA or DSA identities to the authentication agent,
57.Xr ssh-agent 1 . 57.Xr ssh-agent 1 .
58When run without arguments, it adds the file 58When run without arguments, it adds the files
59.Pa $HOME/.ssh/id_rsa ,
60.Pa $HOME/.ssh/id_dsa
61and
59.Pa $HOME/.ssh/identity . 62.Pa $HOME/.ssh/identity .
60Alternative file names can be given on the command line. 63Alternative file names can be given on the command line.
61If any file requires a passphrase, 64If any file requires a passphrase,
diff --git a/ssh-add.c b/ssh-add.c
index 91603399a..4a2b65f54 100644
--- a/ssh-add.c
+++ b/ssh-add.c
@@ -35,7 +35,7 @@
35 */ 35 */
36 36
37#include "includes.h" 37#include "includes.h"
38RCSID("$OpenBSD: ssh-add.c,v 1.47 2001/12/19 07:18:56 deraadt Exp $"); 38RCSID("$OpenBSD: ssh-add.c,v 1.48 2001/12/21 10:06:43 djm Exp $");
39 39
40#include <openssl/evp.h> 40#include <openssl/evp.h>
41 41
@@ -58,6 +58,15 @@ char *__progname;
58/* argv0 */ 58/* argv0 */
59extern char *__progname; 59extern char *__progname;
60 60
61/* Default files to add */
62static char *default_files[] = {
63 _PATH_SSH_CLIENT_ID_RSA,
64 _PATH_SSH_CLIENT_ID_DSA,
65 _PATH_SSH_CLIENT_IDENTITY,
66 NULL
67};
68
69
61/* we keep a cache of one passphrases */ 70/* we keep a cache of one passphrases */
62static char *pass = NULL; 71static char *pass = NULL;
63static void 72static void
@@ -210,6 +219,19 @@ list_identities(AuthenticationConnection *ac, int do_fp)
210 printf("The agent has no identities.\n"); 219 printf("The agent has no identities.\n");
211} 220}
212 221
222static int
223do_file(AuthenticationConnection *ac, int deleting, char *file)
224{
225 if (deleting) {
226 if (delete_file(ac, file) == -1)
227 return -1;
228 } else {
229 if (add_file(ac, file) == -1)
230 return -1;
231 }
232 return 0;
233}
234
213static void 235static void
214usage(void) 236usage(void)
215{ 237{
@@ -231,8 +253,6 @@ main(int argc, char **argv)
231 extern char *optarg; 253 extern char *optarg;
232 extern int optind; 254 extern int optind;
233 AuthenticationConnection *ac = NULL; 255 AuthenticationConnection *ac = NULL;
234 struct passwd *pw;
235 char buf[1024];
236 char *sc_reader_id = NULL; 256 char *sc_reader_id = NULL;
237 int i, ch, deleting = 0, ret = 0; 257 int i, ch, deleting = 0, ret = 0;
238 258
@@ -284,30 +304,26 @@ main(int argc, char **argv)
284 goto done; 304 goto done;
285 } 305 }
286 if (argc == 0) { 306 if (argc == 0) {
287 pw = getpwuid(getuid()); 307 char buf[MAXPATHLEN];
288 if (!pw) { 308 struct passwd *pw;
309
310 if ((pw = getpwuid(getuid())) == NULL) {
289 fprintf(stderr, "No user found with uid %u\n", 311 fprintf(stderr, "No user found with uid %u\n",
290 (u_int)getuid()); 312 (u_int)getuid());
291 ret = 1; 313 ret = 1;
292 goto done; 314 goto done;
293 } 315 }
294 snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, _PATH_SSH_CLIENT_IDENTITY); 316
295 if (deleting) { 317 for(i = 0; default_files[i]; i++) {
296 if (delete_file(ac, buf) == -1) 318 snprintf(buf, sizeof(buf), "%s/%s", pw->pw_dir,
297 ret = 1; 319 default_files[i]);
298 } else { 320 if (do_file(ac, deleting, buf) == -1)
299 if (add_file(ac, buf) == -1)
300 ret = 1; 321 ret = 1;
301 } 322 }
302 } else { 323 } else {
303 for (i = 0; i < argc; i++) { 324 for(i = 0; i < argc; i++) {
304 if (deleting) { 325 if (do_file(ac, deleting, argv[1]) == -1)
305 if (delete_file(ac, argv[i]) == -1) 326 ret = 1;
306 ret = 1;
307 } else {
308 if (add_file(ac, argv[i]) == -1)
309 ret = 1;
310 }
311 } 327 }
312 } 328 }
313 clear_pass(); 329 clear_pass();