summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2001-12-21 10:06:44 +0000
committerDamien Miller <djm@cvs.openbsd.org>2001-12-21 10:06:44 +0000
commit61322226969582b51c351b2689fde9fbc68a2c9e (patch)
treea15ff1cfaf014b273b6299a6004f50b7e51cd342
parentda616515814da9ec258eda561227d029181560d6 (diff)
Try all standard key files (id_rsa, id_dsa, identity) when invoked with
no arguments; ok markus@
-rw-r--r--usr.bin/ssh/ssh-add.17
-rw-r--r--usr.bin/ssh/ssh-add.c54
2 files changed, 40 insertions, 21 deletions
diff --git a/usr.bin/ssh/ssh-add.1 b/usr.bin/ssh/ssh-add.1
index b842080d632..ef60d0204a6 100644
--- a/usr.bin/ssh/ssh-add.1
+++ b/usr.bin/ssh/ssh-add.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ssh-add.1,v 1.27 2001/08/23 18:08:59 stevesk Exp $
+.\" $OpenBSD: ssh-add.1,v 1.28 2001/12/21 10:06:43 djm Exp $
.\"
.\" -*- nroff -*-
.\"
@@ -55,7 +55,10 @@
.Nm
adds RSA or DSA identities to the authentication agent,
.Xr ssh-agent 1 .
-When run without arguments, it adds the file
+When run without arguments, it adds the files
+.Pa $HOME/.ssh/id_rsa ,
+.Pa $HOME/.ssh/id_dsa
+and
.Pa $HOME/.ssh/identity .
Alternative file names can be given on the command line.
If any file requires a passphrase,
diff --git a/usr.bin/ssh/ssh-add.c b/usr.bin/ssh/ssh-add.c
index f51ff7ee231..ad853f1c074 100644
--- a/usr.bin/ssh/ssh-add.c
+++ b/usr.bin/ssh/ssh-add.c
@@ -35,7 +35,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: ssh-add.c,v 1.47 2001/12/19 07:18:56 deraadt Exp $");
+RCSID("$OpenBSD: ssh-add.c,v 1.48 2001/12/21 10:06:43 djm Exp $");
#include <openssl/evp.h>
@@ -52,6 +52,15 @@ RCSID("$OpenBSD: ssh-add.c,v 1.47 2001/12/19 07:18:56 deraadt Exp $");
/* argv0 */
extern char *__progname;
+/* Default files to add */
+static char *default_files[] = {
+ _PATH_SSH_CLIENT_ID_RSA,
+ _PATH_SSH_CLIENT_ID_DSA,
+ _PATH_SSH_CLIENT_IDENTITY,
+ NULL
+};
+
+
/* we keep a cache of one passphrases */
static char *pass = NULL;
static void
@@ -204,6 +213,19 @@ list_identities(AuthenticationConnection *ac, int do_fp)
printf("The agent has no identities.\n");
}
+static int
+do_file(AuthenticationConnection *ac, int deleting, char *file)
+{
+ if (deleting) {
+ if (delete_file(ac, file) == -1)
+ return -1;
+ } else {
+ if (add_file(ac, file) == -1)
+ return -1;
+ }
+ return 0;
+}
+
static void
usage(void)
{
@@ -225,8 +247,6 @@ main(int argc, char **argv)
extern char *optarg;
extern int optind;
AuthenticationConnection *ac = NULL;
- struct passwd *pw;
- char buf[1024];
char *sc_reader_id = NULL;
int i, ch, deleting = 0, ret = 0;
@@ -274,30 +294,26 @@ main(int argc, char **argv)
goto done;
}
if (argc == 0) {
- pw = getpwuid(getuid());
- if (!pw) {
+ char buf[MAXPATHLEN];
+ struct passwd *pw;
+
+ if ((pw = getpwuid(getuid())) == NULL) {
fprintf(stderr, "No user found with uid %u\n",
(u_int)getuid());
ret = 1;
goto done;
}
- snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, _PATH_SSH_CLIENT_IDENTITY);
- if (deleting) {
- if (delete_file(ac, buf) == -1)
- ret = 1;
- } else {
- if (add_file(ac, buf) == -1)
+
+ for(i = 0; default_files[i]; i++) {
+ snprintf(buf, sizeof(buf), "%s/%s", pw->pw_dir,
+ default_files[i]);
+ if (do_file(ac, deleting, buf) == -1)
ret = 1;
}
} else {
- for (i = 0; i < argc; i++) {
- if (deleting) {
- if (delete_file(ac, argv[i]) == -1)
- ret = 1;
- } else {
- if (add_file(ac, argv[i]) == -1)
- ret = 1;
- }
+ for(i = 0; i < argc; i++) {
+ if (do_file(ac, deleting, argv[1]) == -1)
+ ret = 1;
}
}
clear_pass();