summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2013-10-15 12:05:58 +1100
committerDamien Miller <djm@mindrot.org>2013-10-15 12:05:58 +1100
commitbda5c8445713ae592d969a5105ed1a65da22bc96 (patch)
tree0ec77bc4af1037a717a33481a0e7c57473237328
parent61ee4d68ca0fcc793a826fc7ec70f3b8ffd12ab6 (diff)
- djm@cvs.openbsd.org 2013/10/11 02:45:36
[sftp-client.c] rename flag arguments to be more clear and consistent. reorder some internal function arguments to make adding additional flags easier. no functional change
-rw-r--r--ChangeLog6
-rw-r--r--sftp-client.c73
2 files changed, 44 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index ee3ede1b4..3e60d045c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,12 @@
13 [sshd.c] 13 [sshd.c]
14 bz#2139: fix re-exec fallback by ensuring that startup_pipe is correctly 14 bz#2139: fix re-exec fallback by ensuring that startup_pipe is correctly
15 updated; ok dtucker@ 15 updated; ok dtucker@
16 - djm@cvs.openbsd.org 2013/10/11 02:45:36
17 [sftp-client.c]
18 rename flag arguments to be more clear and consistent.
19 reorder some internal function arguments to make adding additional flags
20 easier.
21 no functional change
16 22
1720131010 2320131010
18 - (dtucker) OpenBSD CVS Sync 24 - (dtucker) OpenBSD CVS Sync
diff --git a/sftp-client.c b/sftp-client.c
index eb8930802..e815499fe 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-client.c,v 1.104 2013/09/19 00:49:12 djm Exp $ */ 1/* $OpenBSD: sftp-client.c,v 1.105 2013/10/11 02:45:36 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 *
@@ -448,7 +448,7 @@ do_close(struct sftp_conn *conn, char *handle, u_int handle_len)
448 448
449 449
450static int 450static int
451do_lsreaddir(struct sftp_conn *conn, char *path, int printflag, 451do_lsreaddir(struct sftp_conn *conn, char *path, int print_flag,
452 SFTP_DIRENT ***dir) 452 SFTP_DIRENT ***dir)
453{ 453{
454 Buffer msg; 454 Buffer msg;
@@ -530,7 +530,7 @@ do_lsreaddir(struct sftp_conn *conn, char *path, int printflag,
530 longname = buffer_get_string(&msg, NULL); 530 longname = buffer_get_string(&msg, NULL);
531 a = decode_attrib(&msg); 531 a = decode_attrib(&msg);
532 532
533 if (printflag) 533 if (print_flag)
534 printf("%s\n", longname); 534 printf("%s\n", longname);
535 535
536 /* 536 /*
@@ -606,7 +606,7 @@ do_rm(struct sftp_conn *conn, char *path)
606} 606}
607 607
608int 608int
609do_mkdir(struct sftp_conn *conn, char *path, Attrib *a, int printflag) 609do_mkdir(struct sftp_conn *conn, char *path, Attrib *a, int print_flag)
610{ 610{
611 u_int status, id; 611 u_int status, id;
612 612
@@ -615,7 +615,7 @@ do_mkdir(struct sftp_conn *conn, char *path, Attrib *a, int printflag)
615 strlen(path), a); 615 strlen(path), a);
616 616
617 status = get_status(conn, id); 617 status = get_status(conn, id);
618 if (status != SSH2_FX_OK && printflag) 618 if (status != SSH2_FX_OK && print_flag)
619 error("Couldn't create directory: %s", fx2txt(status)); 619 error("Couldn't create directory: %s", fx2txt(status));
620 620
621 return(status); 621 return(status);
@@ -991,7 +991,7 @@ send_read_request(struct sftp_conn *conn, u_int id, u_int64_t offset,
991 991
992int 992int
993do_download(struct sftp_conn *conn, char *remote_path, char *local_path, 993do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
994 Attrib *a, int pflag, int resume) 994 Attrib *a, int preserve_flag, int resume_flag)
995{ 995{
996 Attrib junk; 996 Attrib junk;
997 Buffer msg; 997 Buffer msg;
@@ -1054,15 +1054,15 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
1054 return(-1); 1054 return(-1);
1055 } 1055 }
1056 1056
1057 local_fd = open(local_path, O_WRONLY | O_CREAT | (resume ? 0 : O_TRUNC), 1057 local_fd = open(local_path,
1058 mode | S_IWUSR); 1058 O_WRONLY | O_CREAT | (resume_flag ? 0 : O_TRUNC), mode | S_IWUSR);
1059 if (local_fd == -1) { 1059 if (local_fd == -1) {
1060 error("Couldn't open local file \"%s\" for writing: %s", 1060 error("Couldn't open local file \"%s\" for writing: %s",
1061 local_path, strerror(errno)); 1061 local_path, strerror(errno));
1062 goto fail; 1062 goto fail;
1063 } 1063 }
1064 offset = highwater = 0; 1064 offset = highwater = 0;
1065 if (resume) { 1065 if (resume_flag) {
1066 if (fstat(local_fd, &st) == -1) { 1066 if (fstat(local_fd, &st) == -1) {
1067 error("Unable to stat local file \"%s\": %s", 1067 error("Unable to stat local file \"%s\": %s",
1068 local_path, strerror(errno)); 1068 local_path, strerror(errno));
@@ -1212,7 +1212,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
1212 fatal("Transfer complete, but requests still in queue"); 1212 fatal("Transfer complete, but requests still in queue");
1213 /* Truncate at highest contiguous point to avoid holes on interrupt */ 1213 /* Truncate at highest contiguous point to avoid holes on interrupt */
1214 if (read_error || write_error || interrupted) { 1214 if (read_error || write_error || interrupted) {
1215 if (reordered && resume) { 1215 if (reordered && resume_flag) {
1216 error("Unable to resume download of \"%s\": " 1216 error("Unable to resume download of \"%s\": "
1217 "server reordered requests", local_path); 1217 "server reordered requests", local_path);
1218 } 1218 }
@@ -1235,13 +1235,14 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
1235 status = -1; 1235 status = -1;
1236 /* Override umask and utimes if asked */ 1236 /* Override umask and utimes if asked */
1237#ifdef HAVE_FCHMOD 1237#ifdef HAVE_FCHMOD
1238 if (pflag && fchmod(local_fd, mode) == -1) 1238 if (preserve_flag && fchmod(local_fd, mode) == -1)
1239#else 1239#else
1240 if (pflag && chmod(local_path, mode) == -1) 1240 if (preserve_flag && chmod(local_path, mode) == -1)
1241#endif /* HAVE_FCHMOD */ 1241#endif /* HAVE_FCHMOD */
1242 error("Couldn't set mode on \"%s\": %s", local_path, 1242 error("Couldn't set mode on \"%s\": %s", local_path,
1243 strerror(errno)); 1243 strerror(errno));
1244 if (pflag && (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME)) { 1244 if (preserve_flag &&
1245 (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME)) {
1245 struct timeval tv[2]; 1246 struct timeval tv[2];
1246 tv[0].tv_sec = a->atime; 1247 tv[0].tv_sec = a->atime;
1247 tv[1].tv_sec = a->mtime; 1248 tv[1].tv_sec = a->mtime;
@@ -1259,8 +1260,8 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
1259} 1260}
1260 1261
1261static int 1262static int
1262download_dir_internal(struct sftp_conn *conn, char *src, char *dst, 1263download_dir_internal(struct sftp_conn *conn, char *src, char *dst, int depth,
1263 Attrib *dirattrib, int pflag, int printflag, int depth, int resume) 1264 Attrib *dirattrib, int preserve_flag, int print_flag, int resume_flag)
1264{ 1265{
1265 int i, ret = 0; 1266 int i, ret = 0;
1266 SFTP_DIRENT **dir_entries; 1267 SFTP_DIRENT **dir_entries;
@@ -1281,7 +1282,7 @@ download_dir_internal(struct sftp_conn *conn, char *src, char *dst,
1281 error("\"%s\" is not a directory", src); 1282 error("\"%s\" is not a directory", src);
1282 return -1; 1283 return -1;
1283 } 1284 }
1284 if (printflag) 1285 if (print_flag)
1285 printf("Retrieving %s\n", src); 1286 printf("Retrieving %s\n", src);
1286 1287
1287 if (dirattrib->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) 1288 if (dirattrib->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)
@@ -1312,12 +1313,12 @@ download_dir_internal(struct sftp_conn *conn, char *src, char *dst,
1312 strcmp(filename, "..") == 0) 1313 strcmp(filename, "..") == 0)
1313 continue; 1314 continue;
1314 if (download_dir_internal(conn, new_src, new_dst, 1315 if (download_dir_internal(conn, new_src, new_dst,
1315 &(dir_entries[i]->a), pflag, printflag, 1316 depth + 1, &(dir_entries[i]->a), preserve_flag,
1316 depth + 1, resume) == -1) 1317 print_flag, resume_flag) == -1)
1317 ret = -1; 1318 ret = -1;
1318 } else if (S_ISREG(dir_entries[i]->a.perm) ) { 1319 } else if (S_ISREG(dir_entries[i]->a.perm) ) {
1319 if (do_download(conn, new_src, new_dst, 1320 if (do_download(conn, new_src, new_dst,
1320 &(dir_entries[i]->a), pflag, resume) == -1) { 1321 &(dir_entries[i]->a), preserve_flag, resume_flag) == -1) {
1321 error("Download of file %s to %s failed", 1322 error("Download of file %s to %s failed",
1322 new_src, new_dst); 1323 new_src, new_dst);
1323 ret = -1; 1324 ret = -1;
@@ -1329,7 +1330,7 @@ download_dir_internal(struct sftp_conn *conn, char *src, char *dst,
1329 free(new_src); 1330 free(new_src);
1330 } 1331 }
1331 1332
1332 if (pflag) { 1333 if (preserve_flag) {
1333 if (dirattrib->flags & SSH2_FILEXFER_ATTR_ACMODTIME) { 1334 if (dirattrib->flags & SSH2_FILEXFER_ATTR_ACMODTIME) {
1334 struct timeval tv[2]; 1335 struct timeval tv[2];
1335 tv[0].tv_sec = dirattrib->atime; 1336 tv[0].tv_sec = dirattrib->atime;
@@ -1350,7 +1351,7 @@ download_dir_internal(struct sftp_conn *conn, char *src, char *dst,
1350 1351
1351int 1352int
1352download_dir(struct sftp_conn *conn, char *src, char *dst, 1353download_dir(struct sftp_conn *conn, char *src, char *dst,
1353 Attrib *dirattrib, int pflag, int printflag, int resume) 1354 Attrib *dirattrib, int preserve_flag, int print_flag, int resume_flag)
1354{ 1355{
1355 char *src_canon; 1356 char *src_canon;
1356 int ret; 1357 int ret;
@@ -1360,15 +1361,15 @@ download_dir(struct sftp_conn *conn, char *src, char *dst,
1360 return -1; 1361 return -1;
1361 } 1362 }
1362 1363
1363 ret = download_dir_internal(conn, src_canon, dst, 1364 ret = download_dir_internal(conn, src_canon, dst, 0,
1364 dirattrib, pflag, printflag, 0, resume); 1365 dirattrib, preserve_flag, print_flag, resume_flag);
1365 free(src_canon); 1366 free(src_canon);
1366 return ret; 1367 return ret;
1367} 1368}
1368 1369
1369int 1370int
1370do_upload(struct sftp_conn *conn, char *local_path, char *remote_path, 1371do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
1371 int pflag) 1372 int preserve_flag)
1372{ 1373{
1373 int local_fd; 1374 int local_fd;
1374 int status = SSH2_FX_OK; 1375 int status = SSH2_FX_OK;
@@ -1412,7 +1413,7 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
1412 a.flags &= ~SSH2_FILEXFER_ATTR_SIZE; 1413 a.flags &= ~SSH2_FILEXFER_ATTR_SIZE;
1413 a.flags &= ~SSH2_FILEXFER_ATTR_UIDGID; 1414 a.flags &= ~SSH2_FILEXFER_ATTR_UIDGID;
1414 a.perm &= 0777; 1415 a.perm &= 0777;
1415 if (!pflag) 1416 if (!preserve_flag)
1416 a.flags &= ~SSH2_FILEXFER_ATTR_ACMODTIME; 1417 a.flags &= ~SSH2_FILEXFER_ATTR_ACMODTIME;
1417 1418
1418 buffer_init(&msg); 1419 buffer_init(&msg);
@@ -1541,7 +1542,7 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
1541 } 1542 }
1542 1543
1543 /* Override umask and utimes if asked */ 1544 /* Override umask and utimes if asked */
1544 if (pflag) 1545 if (preserve_flag)
1545 do_fsetstat(conn, handle, handle_len, &a); 1546 do_fsetstat(conn, handle, handle_len, &a);
1546 1547
1547 if (do_close(conn, handle, handle_len) != SSH2_FX_OK) 1548 if (do_close(conn, handle, handle_len) != SSH2_FX_OK)
@@ -1552,8 +1553,8 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
1552} 1553}
1553 1554
1554static int 1555static int
1555upload_dir_internal(struct sftp_conn *conn, char *src, char *dst, 1556upload_dir_internal(struct sftp_conn *conn, char *src, char *dst, int depth,
1556 int pflag, int printflag, int depth) 1557 int preserve_flag, int print_flag)
1557{ 1558{
1558 int ret = 0, status; 1559 int ret = 0, status;
1559 DIR *dirp; 1560 DIR *dirp;
@@ -1576,7 +1577,7 @@ upload_dir_internal(struct sftp_conn *conn, char *src, char *dst,
1576 error("\"%s\" is not a directory", src); 1577 error("\"%s\" is not a directory", src);
1577 return -1; 1578 return -1;
1578 } 1579 }
1579 if (printflag) 1580 if (print_flag)
1580 printf("Entering %s\n", src); 1581 printf("Entering %s\n", src);
1581 1582
1582 attrib_clear(&a); 1583 attrib_clear(&a);
@@ -1584,7 +1585,7 @@ upload_dir_internal(struct sftp_conn *conn, char *src, char *dst,
1584 a.flags &= ~SSH2_FILEXFER_ATTR_SIZE; 1585 a.flags &= ~SSH2_FILEXFER_ATTR_SIZE;
1585 a.flags &= ~SSH2_FILEXFER_ATTR_UIDGID; 1586 a.flags &= ~SSH2_FILEXFER_ATTR_UIDGID;
1586 a.perm &= 01777; 1587 a.perm &= 01777;
1587 if (!pflag) 1588 if (!preserve_flag)
1588 a.flags &= ~SSH2_FILEXFER_ATTR_ACMODTIME; 1589 a.flags &= ~SSH2_FILEXFER_ATTR_ACMODTIME;
1589 1590
1590 status = do_mkdir(conn, dst, &a, 0); 1591 status = do_mkdir(conn, dst, &a, 0);
@@ -1622,10 +1623,11 @@ upload_dir_internal(struct sftp_conn *conn, char *src, char *dst,
1622 continue; 1623 continue;
1623 1624
1624 if (upload_dir_internal(conn, new_src, new_dst, 1625 if (upload_dir_internal(conn, new_src, new_dst,
1625 pflag, printflag, depth + 1) == -1) 1626 depth + 1, preserve_flag, print_flag) == -1)
1626 ret = -1; 1627 ret = -1;
1627 } else if (S_ISREG(sb.st_mode)) { 1628 } else if (S_ISREG(sb.st_mode)) {
1628 if (do_upload(conn, new_src, new_dst, pflag) == -1) { 1629 if (do_upload(conn, new_src, new_dst,
1630 preserve_flag) == -1) {
1629 error("Uploading of file %s to %s failed!", 1631 error("Uploading of file %s to %s failed!",
1630 new_src, new_dst); 1632 new_src, new_dst);
1631 ret = -1; 1633 ret = -1;
@@ -1643,8 +1645,8 @@ upload_dir_internal(struct sftp_conn *conn, char *src, char *dst,
1643} 1645}
1644 1646
1645int 1647int
1646upload_dir(struct sftp_conn *conn, char *src, char *dst, int pflag, 1648upload_dir(struct sftp_conn *conn, char *src, char *dst, int preserve_flag,
1647 int printflag) 1649 int print_flag)
1648{ 1650{
1649 char *dst_canon; 1651 char *dst_canon;
1650 int ret; 1652 int ret;
@@ -1654,7 +1656,8 @@ upload_dir(struct sftp_conn *conn, char *src, char *dst, int pflag,
1654 return -1; 1656 return -1;
1655 } 1657 }
1656 1658
1657 ret = upload_dir_internal(conn, src, dst_canon, pflag, printflag, 0); 1659 ret = upload_dir_internal(conn, src, dst_canon, preserve_flag,
1660 print_flag, 0);
1658 free(dst_canon); 1661 free(dst_canon);
1659 return ret; 1662 return ret;
1660} 1663}