summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2013-10-11 02:45:37 +0000
committerDamien Miller <djm@cvs.openbsd.org>2013-10-11 02:45:37 +0000
commitc1728a2cdc365615752cb364950dea830c134360 (patch)
tree8dbadda784db1e509c696e69df4c36a19eb8a0c1 /usr.bin
parente94f8520e08500ff04aa4b054545f3f910de3f06 (diff)
rename flag arguments to be more clear and consistent.
reorder some internal function arguments to make adding additional flags easier. no functional change
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/ssh/sftp-client.c71
1 files changed, 37 insertions, 34 deletions
diff --git a/usr.bin/ssh/sftp-client.c b/usr.bin/ssh/sftp-client.c
index 7c1fb8ad92d..90decbc0f2b 100644
--- a/usr.bin/ssh/sftp-client.c
+++ b/usr.bin/ssh/sftp-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-client.c,v 1.104 2013/09/19 00:49:12 djm Exp $ */
+/* $OpenBSD: sftp-client.c,v 1.105 2013/10/11 02:45:36 djm Exp $ */
/*
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
*
@@ -441,7 +441,7 @@ do_close(struct sftp_conn *conn, char *handle, u_int handle_len)
static int
-do_lsreaddir(struct sftp_conn *conn, char *path, int printflag,
+do_lsreaddir(struct sftp_conn *conn, char *path, int print_flag,
SFTP_DIRENT ***dir)
{
Buffer msg;
@@ -523,7 +523,7 @@ do_lsreaddir(struct sftp_conn *conn, char *path, int printflag,
longname = buffer_get_string(&msg, NULL);
a = decode_attrib(&msg);
- if (printflag)
+ if (print_flag)
printf("%s\n", longname);
/*
@@ -599,7 +599,7 @@ do_rm(struct sftp_conn *conn, char *path)
}
int
-do_mkdir(struct sftp_conn *conn, char *path, Attrib *a, int printflag)
+do_mkdir(struct sftp_conn *conn, char *path, Attrib *a, int print_flag)
{
u_int status, id;
@@ -608,7 +608,7 @@ do_mkdir(struct sftp_conn *conn, char *path, Attrib *a, int printflag)
strlen(path), a);
status = get_status(conn, id);
- if (status != SSH2_FX_OK && printflag)
+ if (status != SSH2_FX_OK && print_flag)
error("Couldn't create directory: %s", fx2txt(status));
return(status);
@@ -984,7 +984,7 @@ send_read_request(struct sftp_conn *conn, u_int id, u_int64_t offset,
int
do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
- Attrib *a, int pflag, int resume)
+ Attrib *a, int preserve_flag, int resume_flag)
{
Attrib junk;
Buffer msg;
@@ -1047,15 +1047,15 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
return(-1);
}
- local_fd = open(local_path, O_WRONLY | O_CREAT | (resume ? : O_TRUNC),
- mode | S_IWUSR);
+ local_fd = open(local_path,
+ O_WRONLY | O_CREAT | (resume_flag ? 0 : O_TRUNC), mode | S_IWUSR);
if (local_fd == -1) {
error("Couldn't open local file \"%s\" for writing: %s",
local_path, strerror(errno));
goto fail;
}
offset = highwater = 0;
- if (resume) {
+ if (resume_flag) {
if (fstat(local_fd, &st) == -1) {
error("Unable to stat local file \"%s\": %s",
local_path, strerror(errno));
@@ -1205,7 +1205,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
fatal("Transfer complete, but requests still in queue");
/* Truncate at highest contiguous point to avoid holes on interrupt */
if (read_error || write_error || interrupted) {
- if (reordered && resume) {
+ if (reordered && resume_flag) {
error("Unable to resume download of \"%s\": "
"server reordered requests", local_path);
}
@@ -1227,10 +1227,11 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
if (interrupted || status != SSH2_FX_OK)
status = -1;
/* Override umask and utimes if asked */
- if (pflag && fchmod(local_fd, mode) == -1)
+ if (preserve_flag && fchmod(local_fd, mode) == -1)
error("Couldn't set mode on \"%s\": %s", local_path,
strerror(errno));
- if (pflag && (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME)) {
+ if (preserve_flag &&
+ (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME)) {
struct timeval tv[2];
tv[0].tv_sec = a->atime;
tv[1].tv_sec = a->mtime;
@@ -1248,8 +1249,8 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
}
static int
-download_dir_internal(struct sftp_conn *conn, char *src, char *dst,
- Attrib *dirattrib, int pflag, int printflag, int depth, int resume)
+download_dir_internal(struct sftp_conn *conn, char *src, char *dst, int depth,
+ Attrib *dirattrib, int preserve_flag, int print_flag, int resume_flag)
{
int i, ret = 0;
SFTP_DIRENT **dir_entries;
@@ -1270,7 +1271,7 @@ download_dir_internal(struct sftp_conn *conn, char *src, char *dst,
error("\"%s\" is not a directory", src);
return -1;
}
- if (printflag)
+ if (print_flag)
printf("Retrieving %s\n", src);
if (dirattrib->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)
@@ -1301,12 +1302,12 @@ download_dir_internal(struct sftp_conn *conn, char *src, char *dst,
strcmp(filename, "..") == 0)
continue;
if (download_dir_internal(conn, new_src, new_dst,
- &(dir_entries[i]->a), pflag, printflag,
- depth + 1, resume) == -1)
+ depth + 1, &(dir_entries[i]->a), preserve_flag,
+ print_flag, resume_flag) == -1)
ret = -1;
} else if (S_ISREG(dir_entries[i]->a.perm) ) {
if (do_download(conn, new_src, new_dst,
- &(dir_entries[i]->a), pflag, resume) == -1) {
+ &(dir_entries[i]->a), preserve_flag, resume_flag) == -1) {
error("Download of file %s to %s failed",
new_src, new_dst);
ret = -1;
@@ -1318,7 +1319,7 @@ download_dir_internal(struct sftp_conn *conn, char *src, char *dst,
free(new_src);
}
- if (pflag) {
+ if (preserve_flag) {
if (dirattrib->flags & SSH2_FILEXFER_ATTR_ACMODTIME) {
struct timeval tv[2];
tv[0].tv_sec = dirattrib->atime;
@@ -1339,7 +1340,7 @@ download_dir_internal(struct sftp_conn *conn, char *src, char *dst,
int
download_dir(struct sftp_conn *conn, char *src, char *dst,
- Attrib *dirattrib, int pflag, int printflag, int resume)
+ Attrib *dirattrib, int preserve_flag, int print_flag, int resume_flag)
{
char *src_canon;
int ret;
@@ -1349,15 +1350,15 @@ download_dir(struct sftp_conn *conn, char *src, char *dst,
return -1;
}
- ret = download_dir_internal(conn, src_canon, dst,
- dirattrib, pflag, printflag, 0, resume);
+ ret = download_dir_internal(conn, src_canon, dst, 0,
+ dirattrib, preserve_flag, print_flag, resume_flag);
free(src_canon);
return ret;
}
int
do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
- int pflag)
+ int preserve_flag)
{
int local_fd;
int status = SSH2_FX_OK;
@@ -1401,7 +1402,7 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
a.flags &= ~SSH2_FILEXFER_ATTR_SIZE;
a.flags &= ~SSH2_FILEXFER_ATTR_UIDGID;
a.perm &= 0777;
- if (!pflag)
+ if (!preserve_flag)
a.flags &= ~SSH2_FILEXFER_ATTR_ACMODTIME;
buffer_init(&msg);
@@ -1529,7 +1530,7 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
}
/* Override umask and utimes if asked */
- if (pflag)
+ if (preserve_flag)
do_fsetstat(conn, handle, handle_len, &a);
if (do_close(conn, handle, handle_len) != SSH2_FX_OK)
@@ -1540,8 +1541,8 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
}
static int
-upload_dir_internal(struct sftp_conn *conn, char *src, char *dst,
- int pflag, int printflag, int depth)
+upload_dir_internal(struct sftp_conn *conn, char *src, char *dst, int depth,
+ int preserve_flag, int print_flag)
{
int ret = 0, status;
DIR *dirp;
@@ -1564,7 +1565,7 @@ upload_dir_internal(struct sftp_conn *conn, char *src, char *dst,
error("\"%s\" is not a directory", src);
return -1;
}
- if (printflag)
+ if (print_flag)
printf("Entering %s\n", src);
attrib_clear(&a);
@@ -1572,7 +1573,7 @@ upload_dir_internal(struct sftp_conn *conn, char *src, char *dst,
a.flags &= ~SSH2_FILEXFER_ATTR_SIZE;
a.flags &= ~SSH2_FILEXFER_ATTR_UIDGID;
a.perm &= 01777;
- if (!pflag)
+ if (!preserve_flag)
a.flags &= ~SSH2_FILEXFER_ATTR_ACMODTIME;
status = do_mkdir(conn, dst, &a, 0);
@@ -1610,10 +1611,11 @@ upload_dir_internal(struct sftp_conn *conn, char *src, char *dst,
continue;
if (upload_dir_internal(conn, new_src, new_dst,
- pflag, printflag, depth + 1) == -1)
+ depth + 1, preserve_flag, print_flag) == -1)
ret = -1;
} else if (S_ISREG(sb.st_mode)) {
- if (do_upload(conn, new_src, new_dst, pflag) == -1) {
+ if (do_upload(conn, new_src, new_dst,
+ preserve_flag) == -1) {
error("Uploading of file %s to %s failed!",
new_src, new_dst);
ret = -1;
@@ -1631,8 +1633,8 @@ upload_dir_internal(struct sftp_conn *conn, char *src, char *dst,
}
int
-upload_dir(struct sftp_conn *conn, char *src, char *dst, int pflag,
- int printflag)
+upload_dir(struct sftp_conn *conn, char *src, char *dst, int preserve_flag,
+ int print_flag)
{
char *dst_canon;
int ret;
@@ -1642,7 +1644,8 @@ upload_dir(struct sftp_conn *conn, char *src, char *dst, int pflag,
return -1;
}
- ret = upload_dir_internal(conn, src, dst_canon, pflag, printflag, 0);
+ ret = upload_dir_internal(conn, src, dst_canon, preserve_flag,
+ print_flag, 0);
free(dst_canon);
return ret;
}