summaryrefslogtreecommitdiff
path: root/ssh-add.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh-add.c')
-rw-r--r--ssh-add.c89
1 files changed, 40 insertions, 49 deletions
diff --git a/ssh-add.c b/ssh-add.c
index dad8beb4c..711dca5ea 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.42 2001/06/26 04:59:59 markus Exp $"); 38RCSID("$OpenBSD: ssh-add.c,v 1.43 2001/06/27 06:26:36 markus Exp $");
39 39
40#include <openssl/evp.h> 40#include <openssl/evp.h>
41 41
@@ -201,20 +201,17 @@ usage(void)
201 printf(" -D : delete all identities\n"); 201 printf(" -D : delete all identities\n");
202 printf(" -s reader_num : add key in the smartcard in reader_num.\n"); 202 printf(" -s reader_num : add key in the smartcard in reader_num.\n");
203 printf(" -e reader_num : remove key in the smartcard in reader_num.\n"); 203 printf(" -e reader_num : remove key in the smartcard in reader_num.\n");
204 exit (1);
205} 204}
206 205
207int 206int
208main(int argc, char **argv) 207main(int argc, char **argv)
209{ 208{
209 extern char *optarg;
210 extern int optind;
210 AuthenticationConnection *ac = NULL; 211 AuthenticationConnection *ac = NULL;
211 struct passwd *pw; 212 struct passwd *pw;
212 char buf[1024]; 213 char buf[1024];
213 int no_files = 1; 214 int i, ch, deleting = 0, sc_reader_num = -1;
214 int i;
215 int deleting = 0;
216 int sc_mode = 0;
217 int sc_reader_num = 0;
218 215
219 __progname = get_progname(argv[0]); 216 __progname = get_progname(argv[0]);
220 init_rng(); 217 init_rng();
@@ -228,55 +225,40 @@ main(int argc, char **argv)
228 fprintf(stderr, "Could not open a connection to your authentication agent.\n"); 225 fprintf(stderr, "Could not open a connection to your authentication agent.\n");
229 exit(1); 226 exit(1);
230 } 227 }
231 for (i = 1; i < argc; i++) { 228 while ((ch = getopt(argc, argv, "lLdDe:s:")) != -1) {
232 if ((strcmp(argv[i], "-l") == 0) || 229 switch (ch) {
233 (strcmp(argv[i], "-L") == 0)) { 230 case 'l':
234 list_identities(ac, argv[i][1] == 'l' ? 1 : 0); 231 case 'L':
235 /* Don't default-add/delete if -l. */ 232 list_identities(ac, ch == 'l' ? 1 : 0);
236 no_files = 0; 233 goto done;
237 continue; 234 break;
238 } 235 case 'd':
239 if (strcmp(argv[i], "-d") == 0) {
240 deleting = 1; 236 deleting = 1;
241 continue; 237 break;
242 } 238 case 'D':
243 if (strcmp(argv[i], "-D") == 0) {
244 delete_all(ac); 239 delete_all(ac);
245 no_files = 0; 240 goto done;
246 continue; 241 break;
247 } 242 case 's':
248 if (strcmp(argv[i], "-s") == 0) { 243 sc_reader_num = atoi(optarg);
249 sc_mode = 1; 244 break;
250 deleting = 0; 245 case 'e':
251 i++;
252 if (i >= argc)
253 usage();
254 sc_reader_num = atoi(argv[i]);
255 continue;
256 }
257 if (strcmp(argv[i], "-e") == 0) {
258 sc_mode = 1;
259 deleting = 1; 246 deleting = 1;
260 i++; 247 sc_reader_num = atoi(optarg);
261 if (i >= argc) 248 break;
262 usage(); 249 default:
263 sc_reader_num = atoi(argv[i]); 250 usage();
264 continue; 251 exit(1);
252 break;
265 } 253 }
266 if (sc_mode == 1)
267 update_card(ac, !deleting, sc_reader_num);
268 no_files = 0;
269 if (deleting)
270 delete_file(ac, argv[i]);
271 else
272 add_file(ac, argv[i]);
273 } 254 }
274 if (sc_mode == 1) { 255 argc -= optind;
256 argv += optind;
257 if (sc_reader_num != -1) {
275 update_card(ac, !deleting, sc_reader_num); 258 update_card(ac, !deleting, sc_reader_num);
276 ssh_close_authentication_connection(ac); 259 goto done;
277 exit(0);
278 } 260 }
279 if (no_files) { 261 if (argc == 0) {
280 pw = getpwuid(getuid()); 262 pw = getpwuid(getuid());
281 if (!pw) { 263 if (!pw) {
282 fprintf(stderr, "No user found with uid %u\n", 264 fprintf(stderr, "No user found with uid %u\n",
@@ -289,8 +271,17 @@ main(int argc, char **argv)
289 delete_file(ac, buf); 271 delete_file(ac, buf);
290 else 272 else
291 add_file(ac, buf); 273 add_file(ac, buf);
274 } else {
275 for (i = 0; i < argc; i++) {
276 if (deleting)
277 delete_file(ac, argv[i]);
278 else
279 add_file(ac, argv[i]);
280 }
292 } 281 }
293 clear_pass(); 282 clear_pass();
283
284done:
294 ssh_close_authentication_connection(ac); 285 ssh_close_authentication_connection(ac);
295 exit(0); 286 exit(0);
296} 287}