summaryrefslogtreecommitdiff
path: root/ssh-add.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh-add.c')
-rw-r--r--ssh-add.c54
1 files changed, 35 insertions, 19 deletions
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();