diff options
Diffstat (limited to 'sftp.c')
-rw-r--r-- | sftp.c | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sftp.c,v 1.152 2013/08/08 05:04:03 djm Exp $ */ | 1 | /* $OpenBSD: sftp.c,v 1.153 2013/08/09 03:37:25 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> | 3 | * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> |
4 | * | 4 | * |
@@ -519,6 +519,26 @@ parse_df_flags(const char *cmd, char **argv, int argc, int *hflag, int *iflag) | |||
519 | } | 519 | } |
520 | 520 | ||
521 | static int | 521 | static int |
522 | parse_no_flags(const char *cmd, char **argv, int argc) | ||
523 | { | ||
524 | extern int opterr, optind, optopt, optreset; | ||
525 | int ch; | ||
526 | |||
527 | optind = optreset = 1; | ||
528 | opterr = 0; | ||
529 | |||
530 | while ((ch = getopt(argc, argv, "")) != -1) { | ||
531 | switch (ch) { | ||
532 | default: | ||
533 | error("%s: Invalid flag -%c", cmd, optopt); | ||
534 | return -1; | ||
535 | } | ||
536 | } | ||
537 | |||
538 | return optind; | ||
539 | } | ||
540 | |||
541 | static int | ||
522 | is_dir(char *path) | 542 | is_dir(char *path) |
523 | { | 543 | { |
524 | struct stat sb; | 544 | struct stat sb; |
@@ -1240,6 +1260,8 @@ parse_args(const char **cpp, int *aflag, int *hflag, int *iflag, int *lflag, | |||
1240 | return -1; | 1260 | return -1; |
1241 | goto parse_two_paths; | 1261 | goto parse_two_paths; |
1242 | case I_SYMLINK: | 1262 | case I_SYMLINK: |
1263 | if ((optidx = parse_no_flags(cmd, argv, argc)) == -1) | ||
1264 | return -1; | ||
1243 | parse_two_paths: | 1265 | parse_two_paths: |
1244 | if (argc - optidx < 2) { | 1266 | if (argc - optidx < 2) { |
1245 | error("You must specify two paths after a %s " | 1267 | error("You must specify two paths after a %s " |
@@ -1258,6 +1280,8 @@ parse_args(const char **cpp, int *aflag, int *hflag, int *iflag, int *lflag, | |||
1258 | case I_CHDIR: | 1280 | case I_CHDIR: |
1259 | case I_LCHDIR: | 1281 | case I_LCHDIR: |
1260 | case I_LMKDIR: | 1282 | case I_LMKDIR: |
1283 | if ((optidx = parse_no_flags(cmd, argv, argc)) == -1) | ||
1284 | return -1; | ||
1261 | /* Get pathname (mandatory) */ | 1285 | /* Get pathname (mandatory) */ |
1262 | if (argc - optidx < 1) { | 1286 | if (argc - optidx < 1) { |
1263 | error("You must specify a path after a %s command.", | 1287 | error("You must specify a path after a %s command.", |
@@ -1299,6 +1323,8 @@ parse_args(const char **cpp, int *aflag, int *hflag, int *iflag, int *lflag, | |||
1299 | base = 8; | 1323 | base = 8; |
1300 | case I_CHOWN: | 1324 | case I_CHOWN: |
1301 | case I_CHGRP: | 1325 | case I_CHGRP: |
1326 | if ((optidx = parse_no_flags(cmd, argv, argc)) == -1) | ||
1327 | return -1; | ||
1302 | /* Get numeric arg (mandatory) */ | 1328 | /* Get numeric arg (mandatory) */ |
1303 | if (argc - optidx < 1) | 1329 | if (argc - optidx < 1) |
1304 | goto need_num_arg; | 1330 | goto need_num_arg; |
@@ -1329,6 +1355,8 @@ parse_args(const char **cpp, int *aflag, int *hflag, int *iflag, int *lflag, | |||
1329 | case I_HELP: | 1355 | case I_HELP: |
1330 | case I_VERSION: | 1356 | case I_VERSION: |
1331 | case I_PROGRESS: | 1357 | case I_PROGRESS: |
1358 | if ((optidx = parse_no_flags(cmd, argv, argc)) == -1) | ||
1359 | return -1; | ||
1332 | break; | 1360 | break; |
1333 | default: | 1361 | default: |
1334 | fatal("Command not implemented"); | 1362 | fatal("Command not implemented"); |