From 4cd3c7b229defa1368a80d176f735387b2a4c0c1 Mon Sep 17 00:00:00 2001 From: djm Date: Mon, 17 Jan 2022 21:41:04 +0000 Subject: [PATCH] make most of the sftp errors more idiomatic, following the general form of "[local/remote] operation path: error message"; ok markus --- usr.bin/ssh/sftp-client.c | 183 +++++++++++++++++++++++--------------- 1 file changed, 110 insertions(+), 73 deletions(-) diff --git a/usr.bin/ssh/sftp-client.c b/usr.bin/ssh/sftp-client.c index 8eb5247a071..0666a9fdd1b 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.160 2022/01/08 07:37:32 djm Exp $ */ +/* $OpenBSD: sftp-client.c,v 1.161 2022/01/17 21:41:04 djm Exp $ */ /* * Copyright (c) 2001-2004 Damien Miller * @@ -347,9 +347,9 @@ get_decode_stat(struct sftp_conn *conn, u_int expected_id, int quiet) if ((r = sshbuf_get_u32(msg, &status)) != 0) fatal_fr(r, "parse status"); if (quiet) - debug("Couldn't stat remote file: %s", fx2txt(status)); + debug("stat remote: %s", fx2txt(status)); else - error("Couldn't stat remote file: %s", fx2txt(status)); + error("stat remote: %s", fx2txt(status)); sshbuf_free(msg); return(NULL); } else if (type != SSH2_FXP_ATTRS) { @@ -395,9 +395,9 @@ get_decode_statvfs(struct sftp_conn *conn, struct sftp_statvfs *st, if ((r = sshbuf_get_u32(msg, &status)) != 0) fatal_fr(r, "parse status"); if (quiet) - debug("Couldn't statvfs: %s", fx2txt(status)); + debug("remote statvfs: %s", fx2txt(status)); else - error("Couldn't statvfs: %s", fx2txt(status)); + error("remote statvfs: %s", fx2txt(status)); sshbuf_free(msg); return -1; } else if (type != SSH2_FXP_EXTENDED_REPLY) { @@ -648,7 +648,7 @@ do_close(struct sftp_conn *conn, const u_char *handle, u_int handle_len) status = get_status(conn, id); if (status != SSH2_FX_OK) - error("Couldn't close file: %s", fx2txt(status)); + error("close remote: %s", fx2txt(status)); sshbuf_free(msg); @@ -830,7 +830,7 @@ do_rm(struct sftp_conn *conn, const char *path) send_string_request(conn, id, SSH2_FXP_REMOVE, path, strlen(path)); status = get_status(conn, id); if (status != SSH2_FX_OK) - error("Couldn't delete file: %s", fx2txt(status)); + error("remote delete %s: %s", path, fx2txt(status)); return status == SSH2_FX_OK ? 0 : -1; } @@ -839,13 +839,15 @@ do_mkdir(struct sftp_conn *conn, const char *path, Attrib *a, int print_flag) { u_int status, id; + debug2("Sending SSH2_FXP_MKDIR \"%s\"", path); + id = conn->msg_id++; send_string_attrs_request(conn, id, SSH2_FXP_MKDIR, path, strlen(path), a); status = get_status(conn, id); if (status != SSH2_FX_OK && print_flag) - error("Couldn't create directory: %s", fx2txt(status)); + error("remote mkdir \"%s\": %s", path, fx2txt(status)); return status == SSH2_FX_OK ? 0 : -1; } @@ -855,13 +857,15 @@ do_rmdir(struct sftp_conn *conn, const char *path) { u_int status, id; + debug2("Sending SSH2_FXP_RMDIR \"%s\"", path); + id = conn->msg_id++; send_string_request(conn, id, SSH2_FXP_RMDIR, path, strlen(path)); status = get_status(conn, id); if (status != SSH2_FX_OK) - error("Couldn't remove directory: %s", fx2txt(status)); + error("remote rmdir \"%s\": %s", path, fx2txt(status)); return status == SSH2_FX_OK ? 0 : -1; } @@ -871,6 +875,8 @@ do_stat(struct sftp_conn *conn, const char *path, int quiet) { u_int id; + debug2("Sending SSH2_FXP_STAT \"%s\"", path); + id = conn->msg_id++; send_string_request(conn, id, @@ -907,6 +913,8 @@ do_fstat(struct sftp_conn *conn, const u_char *handle, u_int handle_len, { u_int id; + debug2("Sending SSH2_FXP_FSTAT \"%s\""); + id = conn->msg_id++; send_string_request(conn, id, SSH2_FXP_FSTAT, handle, handle_len); @@ -920,14 +928,15 @@ do_setstat(struct sftp_conn *conn, const char *path, Attrib *a) { u_int status, id; + debug2("Sending SSH2_FXP_SETSTAT \"%s\"", path); + id = conn->msg_id++; send_string_attrs_request(conn, id, SSH2_FXP_SETSTAT, path, strlen(path), a); status = get_status(conn, id); if (status != SSH2_FX_OK) - error("Couldn't setstat on \"%s\": %s", path, - fx2txt(status)); + error("remote setstat \"%s\": %s", path, fx2txt(status)); return status == SSH2_FX_OK ? 0 : -1; } @@ -938,13 +947,15 @@ do_fsetstat(struct sftp_conn *conn, const u_char *handle, u_int handle_len, { u_int status, id; + debug2("Sending SSH2_FXP_FSETSTAT"); + id = conn->msg_id++; send_string_attrs_request(conn, id, SSH2_FXP_FSETSTAT, handle, handle_len, a); status = get_status(conn, id); if (status != SSH2_FX_OK) - error("Couldn't fsetstat: %s", fx2txt(status)); + error("remote fsetstat: %s", fx2txt(status)); return status == SSH2_FX_OK ? 0 : -1; } @@ -968,6 +979,8 @@ do_realpath_expand(struct sftp_conn *conn, const char *path, int expand) expected_id = id = conn->msg_id++; if (expand) { + debug2("Sending SSH2_FXP_EXTENDED(expand-path@openssh.com) " + "\"%s\"", path); if ((r = sshbuf_put_u8(msg, SSH2_FXP_EXTENDED)) != 0 || (r = sshbuf_put_u32(msg, id)) != 0 || (r = sshbuf_put_cstring(msg, @@ -976,6 +989,7 @@ do_realpath_expand(struct sftp_conn *conn, const char *path, int expand) fatal_fr(r, "compose %s", what); send_msg(conn, msg); } else { + debug2("Sending SSH2_FXP_REALPATH \"%s\"", path); send_string_request(conn, id, SSH2_FXP_REALPATH, path, strlen(path)); } @@ -1058,12 +1072,16 @@ do_rename(struct sftp_conn *conn, const char *oldpath, const char *newpath, /* Send rename request */ id = conn->msg_id++; if (use_ext) { + debug2("Sending SSH2_FXP_EXTENDED(posix-rename@openssh.com) " + "\"%s\" to \"%s\"", oldpath, newpath); if ((r = sshbuf_put_u8(msg, SSH2_FXP_EXTENDED)) != 0 || (r = sshbuf_put_u32(msg, id)) != 0 || (r = sshbuf_put_cstring(msg, "posix-rename@openssh.com")) != 0) fatal_fr(r, "compose posix-rename"); } else { + debug2("Sending SSH2_FXP_RENAME \"%s\" to \"%s\"", + oldpath, newpath); if ((r = sshbuf_put_u8(msg, SSH2_FXP_RENAME)) != 0 || (r = sshbuf_put_u32(msg, id)) != 0) fatal_fr(r, "compose rename"); @@ -1079,7 +1097,7 @@ do_rename(struct sftp_conn *conn, const char *oldpath, const char *newpath, status = get_status(conn, id); if (status != SSH2_FX_OK) - error("Couldn't rename file \"%s\" to \"%s\": %s", oldpath, + error("remote rename \"%s\" to \"%s\": %s", oldpath, newpath, fx2txt(status)); return status == SSH2_FX_OK ? 0 : -1; @@ -1096,6 +1114,8 @@ do_hardlink(struct sftp_conn *conn, const char *oldpath, const char *newpath) error("Server does not support hardlink@openssh.com extension"); return -1; } + debug2("Sending SSH2_FXP_EXTENDED(hardlink@openssh.com) " + "\"%s\" to \"%s\"", oldpath, newpath); if ((msg = sshbuf_new()) == NULL) fatal_f("sshbuf_new failed"); @@ -1115,7 +1135,7 @@ do_hardlink(struct sftp_conn *conn, const char *oldpath, const char *newpath) status = get_status(conn, id); if (status != SSH2_FX_OK) - error("Couldn't link file \"%s\" to \"%s\": %s", oldpath, + error("remote link \"%s\" to \"%s\": %s", oldpath, newpath, fx2txt(status)); return status == SSH2_FX_OK ? 0 : -1; @@ -1132,6 +1152,7 @@ do_symlink(struct sftp_conn *conn, const char *oldpath, const char *newpath) error("This server does not support the symlink operation"); return(SSH2_FX_OP_UNSUPPORTED); } + debug2("Sending SSH2_FXP_SYMLINK \"%s\" to \"%s\"", oldpath, newpath); if ((msg = sshbuf_new()) == NULL) fatal_f("sshbuf_new failed"); @@ -1150,7 +1171,7 @@ do_symlink(struct sftp_conn *conn, const char *oldpath, const char *newpath) status = get_status(conn, id); if (status != SSH2_FX_OK) - error("Couldn't symlink file \"%s\" to \"%s\": %s", oldpath, + error("remote symlink file \"%s\" to \"%s\": %s", oldpath, newpath, fx2txt(status)); return status == SSH2_FX_OK ? 0 : -1; @@ -1166,6 +1187,7 @@ do_fsync(struct sftp_conn *conn, u_char *handle, u_int handle_len) /* Silently return if the extension is not supported */ if ((conn->exts & SFTP_EXT_FSYNC) == 0) return -1; + debug2("Sending SSH2_FXP_EXTENDED(fsync@openssh.com)"); /* Send fsync request */ if ((msg = sshbuf_new()) == NULL) @@ -1182,7 +1204,7 @@ do_fsync(struct sftp_conn *conn, u_char *handle, u_int handle_len) status = get_status(conn, id); if (status != SSH2_FX_OK) - error("Couldn't sync file: %s", fx2txt(status)); + error("remote fsync: %s", fx2txt(status)); return status == SSH2_FX_OK ? 0 : -1; } @@ -1198,6 +1220,8 @@ do_readlink(struct sftp_conn *conn, const char *path) u_char type; int r; + debug2("Sending SSH2_FXP_READLINK \"%s\"", path); + expected_id = id = conn->msg_id++; send_string_request(conn, id, SSH2_FXP_READLINK, path, strlen(path)); @@ -1257,6 +1281,8 @@ do_statvfs(struct sftp_conn *conn, const char *path, struct sftp_statvfs *st, return -1; } + debug2("Sending SSH2_FXP_EXTENDED(statvfs@openssh.com) \"%s\"", path); + id = conn->msg_id++; if ((msg = sshbuf_new()) == NULL) @@ -1285,6 +1311,8 @@ do_fstatvfs(struct sftp_conn *conn, const u_char *handle, u_int handle_len, return -1; } + debug2("Sending SSH2_FXP_EXTENDED(fstatvfs@openssh.com)"); + id = conn->msg_id++; if ((msg = sshbuf_new()) == NULL) @@ -1313,6 +1341,8 @@ do_lsetstat(struct sftp_conn *conn, const char *path, Attrib *a) return -1; } + debug2("Sending SSH2_FXP_EXTENDED(lsetstat@openssh.com) \"%s\"", path); + id = conn->msg_id++; if ((msg = sshbuf_new()) == NULL) fatal_f("sshbuf_new failed"); @@ -1327,8 +1357,7 @@ do_lsetstat(struct sftp_conn *conn, const char *path, Attrib *a) status = get_status(conn, id); if (status != SSH2_FX_OK) - error("Couldn't setstat on \"%s\": %s", path, - fx2txt(status)); + error("remote lsetstat \"%s\": %s", path, fx2txt(status)); return status == SSH2_FX_OK ? 0 : -1; } @@ -1363,6 +1392,8 @@ send_open(struct sftp_conn *conn, const char *path, const char *tag, int r; u_int id; + debug2("Sending SSH2_FXP_OPEN \"%s\"", path); + *handlep = NULL; *handle_lenp = 0; @@ -1424,6 +1455,9 @@ do_download(struct sftp_conn *conn, const char *remote_path, struct request *req; u_char type; + debug2_f("download remote \"%s\" to local \"%s\"", + remote_path, local_path); + TAILQ_INIT(&requests); if (a == NULL && (a = do_stat(conn, remote_path, 0)) == NULL) @@ -1437,7 +1471,7 @@ do_download(struct sftp_conn *conn, const char *remote_path, if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) && (!S_ISREG(a->perm))) { - error("Cannot download non-regular file: %s", remote_path); + error("download %s: not a regular file", remote_path); return(-1); } @@ -1456,14 +1490,13 @@ do_download(struct sftp_conn *conn, const char *remote_path, 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)); + error("open local \"%s\": %s", local_path, strerror(errno)); goto fail; } offset = highwater = 0; if (resume_flag) { if (fstat(local_fd, &st) == -1) { - error("Unable to stat local file \"%s\": %s", + error("stat local \"%s\": %s", local_path, strerror(errno)); goto fail; } @@ -1624,16 +1657,15 @@ do_download(struct sftp_conn *conn, const char *remote_path, } debug("truncating at %llu", (unsigned long long)highwater); if (ftruncate(local_fd, highwater) == -1) - error("ftruncate \"%s\": %s", local_path, + error("local ftruncate \"%s\": %s", local_path, strerror(errno)); } if (read_error) { - error("Couldn't read from remote file \"%s\" : %s", - remote_path, fx2txt(status)); + error("read remote \"%s\" : %s", remote_path, fx2txt(status)); status = -1; do_close(conn, handle, handle_len); } else if (write_error) { - error("Couldn't write to \"%s\": %s", local_path, + error("write local \"%s\": %s", local_path, strerror(write_errno)); status = SSH2_FX_FAILURE; do_close(conn, handle, handle_len); @@ -1644,7 +1676,7 @@ do_download(struct sftp_conn *conn, const char *remote_path, status = SSH2_FX_OK; /* Override umask and utimes if asked */ if (preserve_flag && fchmod(local_fd, mode) == -1) - error("Couldn't set mode on \"%s\": %s", local_path, + error("local chmod \"%s\": %s", local_path, strerror(errno)); if (preserve_flag && (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME)) { @@ -1653,7 +1685,7 @@ do_download(struct sftp_conn *conn, const char *remote_path, tv[1].tv_sec = a->mtime; tv[0].tv_usec = tv[1].tv_usec = 0; if (utimes(local_path, tv) == -1) - error("Can't set times on \"%s\": %s", + error("local set times \"%s\": %s", local_path, strerror(errno)); } if (resume_flag && !lmodified) @@ -1661,7 +1693,7 @@ do_download(struct sftp_conn *conn, const char *remote_path, else if (fsync_flag) { debug("syncing \"%s\"", local_path); if (fsync(local_fd) == -1) - error("Couldn't sync file \"%s\": %s", + error("local sync \"%s\": %s", local_path, strerror(errno)); } } @@ -1687,9 +1719,11 @@ download_dir_internal(struct sftp_conn *conn, const char *src, const char *dst, return -1; } + debug2_f("download dir remote \"%s\" to local \"%s\"", src, dst); + if (dirattrib == NULL && (dirattrib = do_stat(conn, src, 1)) == NULL) { - error("Unable to stat remote directory \"%s\"", src); + error("stat remote \"%s\" directory failed", src); return -1; } if (!S_ISDIR(dirattrib->perm)) { @@ -1703,8 +1737,8 @@ download_dir_internal(struct sftp_conn *conn, const char *src, const char *dst, mode = dirattrib->perm & 01777; tmpmode = mode | (S_IWUSR|S_IXUSR); } else { - debug("Server did not send permissions for " - "directory \"%s\"", dst); + debug("download remote \"%s\": server " + "did not send permissions", dst); } if (mkdir(dst, tmpmode) == -1 && errno != EEXIST) { @@ -1713,7 +1747,7 @@ download_dir_internal(struct sftp_conn *conn, const char *src, const char *dst, } if (do_readdir(conn, src, &dir_entries) == -1) { - error("%s: Failed to get directory contents", src); + error("remote readdir \"%s\" failed", src); return -1; } @@ -1750,7 +1784,7 @@ download_dir_internal(struct sftp_conn *conn, const char *src, const char *dst, ret = -1; } } else - logit("%s: not a regular file\n", new_src); + logit("download \"%s\": not a regular file", new_src); } free(new_dst); @@ -1763,7 +1797,7 @@ download_dir_internal(struct sftp_conn *conn, const char *src, const char *dst, tv[1].tv_sec = dirattrib->mtime; tv[0].tv_usec = tv[1].tv_usec = 0; if (utimes(dst, tv) == -1) - error("Can't set times on \"%s\": %s", + error("local set times on \"%s\": %s", dst, strerror(errno)); } else debug("Server did not send times for directory " @@ -1771,7 +1805,7 @@ download_dir_internal(struct sftp_conn *conn, const char *src, const char *dst, } if (mode != tmpmode && chmod(dst, mode) == -1) - error("Can't set final mode on \"%s\": %s", dst, + error("local chmod directory \"%s\": %s", dst, strerror(errno)); free_sftp_dirents(dir_entries); @@ -1788,7 +1822,7 @@ download_dir(struct sftp_conn *conn, const char *src, const char *dst, int ret; if ((src_canon = do_realpath(conn, src)) == NULL) { - error("Unable to canonicalize path \"%s\"", src); + error("download \"%s\": path canonicalization failed", src); return -1; } @@ -1818,21 +1852,22 @@ do_upload(struct sftp_conn *conn, const char *local_path, struct requests acks; size_t handle_len; + debug2_f("upload local \"%s\" to remote \"%s\"", + local_path, remote_path); + TAILQ_INIT(&acks); if ((local_fd = open(local_path, O_RDONLY)) == -1) { - error("Couldn't open local file \"%s\" for reading: %s", - local_path, strerror(errno)); + error("open local \"%s\": %s", local_path, strerror(errno)); return(-1); } if (fstat(local_fd, &sb) == -1) { - error("Couldn't fstat local file \"%s\": %s", - local_path, strerror(errno)); + error("fstat local \"%s\": %s", local_path, strerror(errno)); close(local_fd); return(-1); } if (!S_ISREG(sb.st_mode)) { - error("%s is not a regular file", local_path); + error("local \"%s\" is not a regular file", local_path); close(local_fd); return(-1); } @@ -1852,8 +1887,8 @@ do_upload(struct sftp_conn *conn, const char *local_path, } if ((off_t)c->size >= sb.st_size) { - error("destination file bigger or same size as " - "source file"); + error("resume \"%s\": destination file " + "same size or larger", local_path); close(local_fd); return -1; } @@ -1900,11 +1935,10 @@ do_upload(struct sftp_conn *conn, const char *local_path, len = read(local_fd, data, conn->upload_buflen); while ((len == -1) && (errno == EINTR || errno == EAGAIN)); - if (len == -1) - fatal("Couldn't read from \"%s\": %s", local_path, - strerror(errno)); - - if (len != 0) { + if (len == -1) { + fatal("read local \"%s\": %s", + local_path, strerror(errno)); + } else if (len != 0) { ack = request_enqueue(&acks, ++id, len, offset); sshbuf_reset(msg); if ((r = sshbuf_put_u8(msg, SSH2_FXP_WRITE)) != 0 || @@ -1962,14 +1996,12 @@ do_upload(struct sftp_conn *conn, const char *local_path, free(data); if (status != SSH2_FX_OK) { - error("Couldn't write to remote file \"%s\": %s", - remote_path, fx2txt(status)); + error("write remote \"%s\": %s", remote_path, fx2txt(status)); status = SSH2_FX_FAILURE; } if (close(local_fd) == -1) { - error("Couldn't close local file \"%s\": %s", local_path, - strerror(errno)); + error("close local \"%s\": %s", local_path, strerror(errno)); status = SSH2_FX_FAILURE; } @@ -2001,14 +2033,15 @@ upload_dir_internal(struct sftp_conn *conn, const char *src, const char *dst, Attrib a, *dirattrib; u_int32_t saved_perm; + debug2_f("upload local dir \"%s\" to remote \"%s\"", src, dst); + if (depth >= MAX_DIR_DEPTH) { error("Maximum directory depth exceeded: %d levels", depth); return -1; } if (stat(src, &sb) == -1) { - error("Couldn't stat directory \"%s\": %s", - src, strerror(errno)); + error("stat local \"%s\": %s", src, strerror(errno)); return -1; } if (!S_ISDIR(sb.st_mode)) { @@ -2044,7 +2077,7 @@ upload_dir_internal(struct sftp_conn *conn, const char *src, const char *dst, a.perm = saved_perm; if ((dirp = opendir(src)) == NULL) { - error("Failed to open dir \"%s\": %s", src, strerror(errno)); + error("local opendir \"%s\": %s", src, strerror(errno)); return -1; } @@ -2058,7 +2091,7 @@ upload_dir_internal(struct sftp_conn *conn, const char *src, const char *dst, new_src = path_append(src, filename); if (lstat(new_src, &sb) == -1) { - logit("%s: lstat failed: %s", filename, + logit("local lstat \"%s\": %s", filename, strerror(errno)); ret = -1; } else if (S_ISDIR(sb.st_mode)) { @@ -2074,12 +2107,12 @@ upload_dir_internal(struct sftp_conn *conn, const char *src, const char *dst, (follow_link_flag && S_ISLNK(sb.st_mode))) { if (do_upload(conn, new_src, new_dst, preserve_flag, resume, fsync_flag) == -1) { - error("Uploading of file %s to %s failed!", + error("upload \"%s\" to \"%s\" failed", new_src, new_dst); ret = -1; } } else - logit("%s: not a regular file\n", filename); + logit("%s: not a regular file", filename); } free(new_dst); free(new_src); @@ -2099,7 +2132,7 @@ upload_dir(struct sftp_conn *conn, const char *src, const char *dst, int ret; if ((dst_canon = do_realpath(conn, dst)) == NULL) { - error("Unable to canonicalize path \"%s\"", dst); + error("upload \"%s\": path canonicalization failed", dst); return -1; } @@ -2194,6 +2227,8 @@ do_crossload(struct sftp_conn *from, struct sftp_conn *to, struct request *req; u_char type; + debug2_f("crossload src \"%s\" to dst \"%s\"", from_path, to_path); + TAILQ_INIT(&requests); if (a == NULL && (a = do_stat(from, from_path, 0)) == NULL) @@ -2201,7 +2236,7 @@ do_crossload(struct sftp_conn *from, struct sftp_conn *to, if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) && (!S_ISREG(a->perm))) { - error("Cannot download non-regular file: %s", from_path); + error("download \"%s\": not a regular file", from_path); return(-1); } if (a->flags & SSH2_FILEXFER_ATTR_SIZE) @@ -2382,20 +2417,18 @@ do_crossload(struct sftp_conn *from, struct sftp_conn *to, if (send_open(to, to_path, "dest", SSH2_FXF_WRITE|SSH2_FXF_CREAT|SSH2_FXF_TRUNC, a, &to_handle, &to_handle_len) != 0) { - error("truncation failed for \"%s\"", to_path); + error("dest truncate \"%s\" failed", to_path); to_handle = NULL; } } if (read_error) { - error("Couldn't read from origin file \"%s\" : %s", - from_path, fx2txt(status)); + error("read origin \"%s\": %s", from_path, fx2txt(status)); status = -1; do_close(from, from_handle, from_handle_len); if (to_handle != NULL) do_close(to, to_handle, to_handle_len); } else if (write_error) { - error("Couldn't write to \"%s\": %s", - to_path, fx2txt(write_error)); + error("write dest \"%s\": %s", to_path, fx2txt(write_error)); status = SSH2_FX_FAILURE; do_close(from, from_handle, from_handle_len); if (to_handle != NULL) @@ -2432,6 +2465,8 @@ crossload_dir_internal(struct sftp_conn *from, struct sftp_conn *to, mode_t mode = 0777; Attrib curdir; + debug2_f("crossload dir src \"%s\" to dst \"%s\"", from_path, to_path); + if (depth >= MAX_DIR_DEPTH) { error("Maximum directory depth exceeded: %d levels", depth); return -1; @@ -2439,7 +2474,7 @@ crossload_dir_internal(struct sftp_conn *from, struct sftp_conn *to, if (dirattrib == NULL && (dirattrib = do_stat(from, from_path, 1)) == NULL) { - error("Unable to stat remote directory \"%s\"", from_path); + error("stat remote \"%s\" failed", from_path); return -1; } if (!S_ISDIR(dirattrib->perm)) { @@ -2479,7 +2514,7 @@ crossload_dir_internal(struct sftp_conn *from, struct sftp_conn *to, curdir.perm = mode; if (do_readdir(from, from_path, &dir_entries) == -1) { - error("%s: Failed to get directory contents", from_path); + error("origin readdir \"%s\" failed", from_path); return -1; } @@ -2510,13 +2545,14 @@ crossload_dir_internal(struct sftp_conn *from, struct sftp_conn *to, if (do_crossload(from, to, new_from_path, new_to_path, S_ISLNK(dir_entries[i]->a.perm) ? NULL : &(dir_entries[i]->a), preserve_flag) == -1) { - error("Transfer of file %s to %s failed", + error("crossload \"%s\" to \"%s\" failed", new_from_path, new_to_path); ret = -1; } - } else - logit("%s: not a regular file\n", new_from_path); - + } else { + logit("origin \"%s\": not a regular file", + new_from_path); + } } free(new_to_path); free(new_from_path); @@ -2537,7 +2573,8 @@ crossload_dir(struct sftp_conn *from, struct sftp_conn *to, int ret; if ((from_path_canon = do_realpath(from, from_path)) == NULL) { - error("Unable to canonicalize path \"%s\"", from_path); + error("crossload \"%s\": path canonicalization failed", + from_path); return -1; } -- 2.20.1