diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | sftp-int.c | 90 |
2 files changed, 36 insertions, 59 deletions
@@ -28,6 +28,9 @@ | |||
28 | - djm@cvs.openbsd.org 2003/05/15 03:10:52 | 28 | - djm@cvs.openbsd.org 2003/05/15 03:10:52 |
29 | [ssh-keygen.c] | 29 | [ssh-keygen.c] |
30 | avoid warning; ok jakob@ | 30 | avoid warning; ok jakob@ |
31 | - mouring@cvs.openbsd.org 2003/05/15 03:39:07 | ||
32 | [sftp-int.c] | ||
33 | Make put/get (globed and nonglobed) code more consistant. OK djm@ | ||
31 | - (djm) Always parse UsePAM | 34 | - (djm) Always parse UsePAM |
32 | - (djm) Configure glue for DNS support (code doesn't work in portable yet) | 35 | - (djm) Configure glue for DNS support (code doesn't work in portable yet) |
33 | - (djm) Import getrrsetbyname() function from OpenBSD libc (for DNS support) | 36 | - (djm) Import getrrsetbyname() function from OpenBSD libc (for DNS support) |
@@ -1508,4 +1511,4 @@ | |||
1508 | save auth method before monitor_reset_key_state(); bugzilla bug #284; | 1511 | save auth method before monitor_reset_key_state(); bugzilla bug #284; |
1509 | ok provos@ | 1512 | ok provos@ |
1510 | 1513 | ||
1511 | $Id: ChangeLog,v 1.2712 2003/05/15 03:37:43 djm Exp $ | 1514 | $Id: ChangeLog,v 1.2713 2003/05/15 03:48:59 djm Exp $ |
diff --git a/sftp-int.c b/sftp-int.c index 01a65dec0..25879baf1 100644 --- a/sftp-int.c +++ b/sftp-int.c | |||
@@ -25,7 +25,7 @@ | |||
25 | /* XXX: recursive operations */ | 25 | /* XXX: recursive operations */ |
26 | 26 | ||
27 | #include "includes.h" | 27 | #include "includes.h" |
28 | RCSID("$OpenBSD: sftp-int.c,v 1.58 2003/04/14 21:31:27 mouring Exp $"); | 28 | RCSID("$OpenBSD: sftp-int.c,v 1.59 2003/05/15 03:39:07 mouring Exp $"); |
29 | 29 | ||
30 | #include "buffer.h" | 30 | #include "buffer.h" |
31 | #include "xmalloc.h" | 31 | #include "xmalloc.h" |
@@ -425,29 +425,8 @@ process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd, int pflag) | |||
425 | goto out; | 425 | goto out; |
426 | } | 426 | } |
427 | 427 | ||
428 | /* Only one match, dst may be file, directory or unspecified */ | 428 | /* If multiple matches, dst must be a directory or unspecified */ |
429 | if (g.gl_pathv[0] && g.gl_matchc == 1) { | 429 | if (g.gl_matchc > 1 && dst && !is_dir(dst)) { |
430 | if (dst) { | ||
431 | /* If directory specified, append filename */ | ||
432 | if (is_dir(dst)) { | ||
433 | if (infer_path(g.gl_pathv[0], &tmp)) { | ||
434 | err = 1; | ||
435 | goto out; | ||
436 | } | ||
437 | abs_dst = path_append(dst, tmp); | ||
438 | xfree(tmp); | ||
439 | } else | ||
440 | abs_dst = xstrdup(dst); | ||
441 | } else if (infer_path(g.gl_pathv[0], &abs_dst)) { | ||
442 | err = -1; | ||
443 | goto out; | ||
444 | } | ||
445 | err = do_download(conn, g.gl_pathv[0], abs_dst, pflag); | ||
446 | goto out; | ||
447 | } | ||
448 | |||
449 | /* Multiple matches, dst may be directory or unspecified */ | ||
450 | if (dst && !is_dir(dst)) { | ||
451 | error("Multiple files match, but \"%s\" is not a directory", | 430 | error("Multiple files match, but \"%s\" is not a directory", |
452 | dst); | 431 | dst); |
453 | err = -1; | 432 | err = -1; |
@@ -459,7 +438,19 @@ process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd, int pflag) | |||
459 | err = -1; | 438 | err = -1; |
460 | goto out; | 439 | goto out; |
461 | } | 440 | } |
462 | if (dst) { | 441 | |
442 | if (g.gl_matchc == 1 && dst) { | ||
443 | /* If directory specified, append filename */ | ||
444 | if (is_dir(dst)) { | ||
445 | if (infer_path(g.gl_pathv[0], &tmp)) { | ||
446 | err = 1; | ||
447 | goto out; | ||
448 | } | ||
449 | abs_dst = path_append(dst, tmp); | ||
450 | xfree(tmp); | ||
451 | } else | ||
452 | abs_dst = xstrdup(dst); | ||
453 | } else if (dst) { | ||
463 | abs_dst = path_append(dst, tmp); | 454 | abs_dst = path_append(dst, tmp); |
464 | xfree(tmp); | 455 | xfree(tmp); |
465 | } else | 456 | } else |
@@ -503,38 +494,8 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, int pflag) | |||
503 | goto out; | 494 | goto out; |
504 | } | 495 | } |
505 | 496 | ||
506 | /* Only one match, dst may be file, directory or unspecified */ | 497 | /* If multiple matches, dst may be directory or unspecified */ |
507 | if (g.gl_pathv[0] && g.gl_matchc == 1) { | 498 | if (g.gl_matchc > 1 && tmp_dst && !remote_is_dir(conn, tmp_dst)) { |
508 | if (!is_reg(g.gl_pathv[0])) { | ||
509 | error("Can't upload %s: not a regular file", | ||
510 | g.gl_pathv[0]); | ||
511 | err = 1; | ||
512 | goto out; | ||
513 | } | ||
514 | if (tmp_dst) { | ||
515 | /* If directory specified, append filename */ | ||
516 | if (remote_is_dir(conn, tmp_dst)) { | ||
517 | if (infer_path(g.gl_pathv[0], &tmp)) { | ||
518 | err = 1; | ||
519 | goto out; | ||
520 | } | ||
521 | abs_dst = path_append(tmp_dst, tmp); | ||
522 | xfree(tmp); | ||
523 | } else | ||
524 | abs_dst = xstrdup(tmp_dst); | ||
525 | } else { | ||
526 | if (infer_path(g.gl_pathv[0], &abs_dst)) { | ||
527 | err = -1; | ||
528 | goto out; | ||
529 | } | ||
530 | abs_dst = make_absolute(abs_dst, pwd); | ||
531 | } | ||
532 | err = do_upload(conn, g.gl_pathv[0], abs_dst, pflag); | ||
533 | goto out; | ||
534 | } | ||
535 | |||
536 | /* Multiple matches, dst may be directory or unspecified */ | ||
537 | if (tmp_dst && !remote_is_dir(conn, tmp_dst)) { | ||
538 | error("Multiple files match, but \"%s\" is not a directory", | 499 | error("Multiple files match, but \"%s\" is not a directory", |
539 | tmp_dst); | 500 | tmp_dst); |
540 | err = -1; | 501 | err = -1; |
@@ -551,7 +512,20 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, int pflag) | |||
551 | err = -1; | 512 | err = -1; |
552 | goto out; | 513 | goto out; |
553 | } | 514 | } |
554 | if (tmp_dst) { | 515 | |
516 | if (g.gl_matchc == 1 && tmp_dst) { | ||
517 | /* If directory specified, append filename */ | ||
518 | if (remote_is_dir(conn, tmp_dst)) { | ||
519 | if (infer_path(g.gl_pathv[0], &tmp)) { | ||
520 | err = 1; | ||
521 | goto out; | ||
522 | } | ||
523 | abs_dst = path_append(tmp_dst, tmp); | ||
524 | xfree(tmp); | ||
525 | } else | ||
526 | abs_dst = xstrdup(tmp_dst); | ||
527 | |||
528 | } else if (tmp_dst) { | ||
555 | abs_dst = path_append(tmp_dst, tmp); | 529 | abs_dst = path_append(tmp_dst, tmp); |
556 | xfree(tmp); | 530 | xfree(tmp); |
557 | } else | 531 | } else |