Lines Matching +full:com +full:- +full:offset
1 /* $OpenBSD: sftp-client.c,v 1.175 2023/11/13 09:18:19 tobhe Exp $ */
3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
29 #include "openbsd-compat/sys-queue.h"
65 #include "sftp-common.h"
66 #include "sftp-client.h"
113 /* Tracks in-progress requests during file transfers */
117 u_int64_t offset; member
128 uint64_t offset) in request_enqueue() argument
133 req->id = id; in request_enqueue()
134 req->len = len; in request_enqueue()
135 req->offset = offset; in request_enqueue()
146 req != NULL && req->id != id; in request_find()
179 if (atomiciov6(writev, conn->fd_out, iov, 2, sftpio, in send_msg()
180 conn->limit_kbps > 0 ? &conn->bwlimit_out : NULL) != in send_msg()
197 if (atomicio6(read, conn->fd_in, p, 4, sftpio, in get_msg_extended()
198 conn->limit_kbps > 0 ? &conn->bwlimit_in : NULL) != 4) { in get_msg_extended()
211 "for non-interactive sessions."); in get_msg_extended()
216 if (atomicio6(read, conn->fd_in, p, msg_len, sftpio, in get_msg_extended()
217 conn->limit_kbps > 0 ? &conn->bwlimit_in : NULL) in get_msg_extended()
246 debug3("Sent message fd %d T:%u I:%u", conn->fd_out, code, id); in send_string_request()
266 conn->fd_out, code, id, a->flags, a->perm); in send_string_attrs_request()
376 return -1; in get_decode_stat()
384 return -1; in get_decode_stat()
427 return -1; in get_decode_statvfs()
434 if ((r = sshbuf_get_u64(msg, &st->f_bsize)) != 0 || in get_decode_statvfs()
435 (r = sshbuf_get_u64(msg, &st->f_frsize)) != 0 || in get_decode_statvfs()
436 (r = sshbuf_get_u64(msg, &st->f_blocks)) != 0 || in get_decode_statvfs()
437 (r = sshbuf_get_u64(msg, &st->f_bfree)) != 0 || in get_decode_statvfs()
438 (r = sshbuf_get_u64(msg, &st->f_bavail)) != 0 || in get_decode_statvfs()
439 (r = sshbuf_get_u64(msg, &st->f_files)) != 0 || in get_decode_statvfs()
440 (r = sshbuf_get_u64(msg, &st->f_ffree)) != 0 || in get_decode_statvfs()
441 (r = sshbuf_get_u64(msg, &st->f_favail)) != 0 || in get_decode_statvfs()
442 (r = sshbuf_get_u64(msg, &st->f_fsid)) != 0 || in get_decode_statvfs()
444 (r = sshbuf_get_u64(msg, &st->f_namemax)) != 0) in get_decode_statvfs()
447 st->f_flag = (flag & SSH2_FXE_STATVFS_ST_RDONLY) ? ST_RDONLY : 0; in get_decode_statvfs()
448 st->f_flag |= (flag & SSH2_FXE_STATVFS_ST_NOSUID) ? ST_NOSUID : 0; in get_decode_statvfs()
465 ret->msg_id = 1; in sftp_init()
466 ret->fd_in = fd_in; in sftp_init()
467 ret->fd_out = fd_out; in sftp_init()
468 ret->download_buflen = ret->upload_buflen = in sftp_init()
470 ret->num_requests = in sftp_init()
472 ret->exts = 0; in sftp_init()
473 ret->limit_kbps = 0; in sftp_init()
495 if ((r = sshbuf_get_u32(msg, &ret->version)) != 0) in sftp_init()
498 debug2("Remote version: %u", ret->version); in sftp_init()
510 if (strcmp(name, "posix-rename@openssh.com") == 0 && in sftp_init()
512 ret->exts |= SFTP_EXT_POSIX_RENAME; in sftp_init()
514 } else if (strcmp(name, "statvfs@openssh.com") == 0 && in sftp_init()
516 ret->exts |= SFTP_EXT_STATVFS; in sftp_init()
518 } else if (strcmp(name, "fstatvfs@openssh.com") == 0 && in sftp_init()
520 ret->exts |= SFTP_EXT_FSTATVFS; in sftp_init()
522 } else if (strcmp(name, "hardlink@openssh.com") == 0 && in sftp_init()
524 ret->exts |= SFTP_EXT_HARDLINK; in sftp_init()
526 } else if (strcmp(name, "fsync@openssh.com") == 0 && in sftp_init()
528 ret->exts |= SFTP_EXT_FSYNC; in sftp_init()
530 } else if (strcmp(name, "lsetstat@openssh.com") == 0 && in sftp_init()
532 ret->exts |= SFTP_EXT_LSETSTAT; in sftp_init()
534 } else if (strcmp(name, "limits@openssh.com") == 0 && in sftp_init()
536 ret->exts |= SFTP_EXT_LIMITS; in sftp_init()
538 } else if (strcmp(name, "expand-path@openssh.com") == 0 && in sftp_init()
540 ret->exts |= SFTP_EXT_PATH_EXPAND; in sftp_init()
542 } else if (strcmp(name, "copy-data") == 0 && in sftp_init()
544 ret->exts |= SFTP_EXT_COPY_DATA; in sftp_init()
547 "users-groups-by-id@openssh.com") == 0 && in sftp_init()
549 ret->exts |= SFTP_EXT_GETUSERSGROUPS_BY_ID; in sftp_init()
565 if (ret->exts & SFTP_EXT_LIMITS) { in sftp_init()
572 ret->download_buflen = MINIMUM(limits.read_length, in sftp_init()
573 SFTP_MAX_MSG_LENGTH - 1024); in sftp_init()
574 ret->upload_buflen = MINIMUM(limits.write_length, in sftp_init()
575 SFTP_MAX_MSG_LENGTH - 1024); in sftp_init()
576 ret->download_buflen = MAXIMUM(ret->download_buflen, 64); in sftp_init()
577 ret->upload_buflen = MAXIMUM(ret->upload_buflen, 64); in sftp_init()
582 ret->upload_buflen, ret->download_buflen); in sftp_init()
587 ret->num_requests = in sftp_init()
589 if (ret->num_requests == 0) in sftp_init()
590 ret->num_requests = 1; in sftp_init()
593 ret->num_requests); in sftp_init()
598 if (ret->version == 0) { in sftp_init()
599 ret->download_buflen = MINIMUM(ret->download_buflen, 20480); in sftp_init()
600 ret->upload_buflen = MINIMUM(ret->upload_buflen, 20480); in sftp_init()
603 ret->limit_kbps = limit_kbps; in sftp_init()
604 if (ret->limit_kbps > 0) { in sftp_init()
605 bandwidth_limit_init(&ret->bwlimit_in, ret->limit_kbps, in sftp_init()
606 ret->download_buflen); in sftp_init()
607 bandwidth_limit_init(&ret->bwlimit_out, ret->limit_kbps, in sftp_init()
608 ret->upload_buflen); in sftp_init()
617 return conn->version; in sftp_proto_version()
628 if ((conn->exts & SFTP_EXT_LIMITS) == 0) { in sftp_get_limits()
629 error("Server does not support limits@openssh.com extension"); in sftp_get_limits()
630 return -1; in sftp_get_limits()
636 id = conn->msg_id++; in sftp_get_limits()
639 (r = sshbuf_put_cstring(msg, "limits@openssh.com")) != 0) in sftp_get_limits()
642 debug3("Sent message limits@openssh.com I:%u", id); in sftp_get_limits()
657 conn->exts &= ~SFTP_EXT_LIMITS; in sftp_get_limits()
659 return -1; in sftp_get_limits()
663 if ((r = sshbuf_get_u64(msg, &limits->packet_length)) != 0 || in sftp_get_limits()
664 (r = sshbuf_get_u64(msg, &limits->read_length)) != 0 || in sftp_get_limits()
665 (r = sshbuf_get_u64(msg, &limits->write_length)) != 0 || in sftp_get_limits()
666 (r = sshbuf_get_u64(msg, &limits->open_handles)) != 0) in sftp_get_limits()
684 id = conn->msg_id++; in sftp_close()
698 return status == SSH2_FX_OK ? 0 : -1; in sftp_close()
716 id = conn->msg_id++; in sftp_lsreaddir()
730 return -1; in sftp_lsreaddir()
740 id = expected_id = conn->msg_id++; in sftp_lsreaddir()
815 (*dir)[ents]->filename = xstrdup(filename); in sftp_lsreaddir()
816 (*dir)[ents]->longname = xstrdup(longname); in sftp_lsreaddir()
817 memcpy(&(*dir)[ents]->a, &a, sizeof(a)); in sftp_lsreaddir()
842 return status == SSH2_FX_OK ? 0 : -1; in sftp_lsreaddir()
858 free(s[i]->filename); in sftp_free_dirents()
859 free(s[i]->longname); in sftp_free_dirents()
872 id = conn->msg_id++; in sftp_rm()
877 return status == SSH2_FX_OK ? 0 : -1; in sftp_rm()
887 id = conn->msg_id++; in sftp_mkdir()
895 return status == SSH2_FX_OK ? 0 : -1; in sftp_mkdir()
905 id = conn->msg_id++; in sftp_rmdir()
913 return status == SSH2_FX_OK ? 0 : -1; in sftp_rmdir()
923 id = conn->msg_id++; in sftp_stat()
926 conn->version == 0 ? SSH2_FXP_STAT_VERSION_0 : SSH2_FXP_STAT, in sftp_stat()
937 if (conn->version == 0) { in sftp_lstat()
943 id = conn->msg_id++; in sftp_lstat()
959 id = conn->msg_id++; in sftp_fstat()
974 id = conn->msg_id++; in sftp_setstat()
982 return status == SSH2_FX_OK ? 0 : -1; in sftp_setstat()
993 id = conn->msg_id++; in sftp_fsetstat()
1001 return status == SSH2_FX_OK ? 0 : -1; in sftp_fsetstat()
1004 /* Implements both the realpath and expand-path operations */
1017 what = "expand-path@openssh.com"; in sftp_realpath_expand()
1021 expected_id = id = conn->msg_id++; in sftp_realpath_expand()
1023 debug2("Sending SSH2_FXP_EXTENDED(expand-path@openssh.com) " in sftp_realpath_expand()
1028 "expand-path@openssh.com")) != 0 || in sftp_realpath_expand()
1071 debug3("%s %s -> %s", what, path, filename); in sftp_realpath_expand()
1089 return (conn->exts & SFTP_EXT_PATH_EXPAND) != 0; in sftp_can_expand_path()
1113 if ((conn->exts & SFTP_EXT_COPY_DATA) == 0) { in sftp_copy()
1114 error("Server does not support copy-data extension"); in sftp_copy()
1115 return -1; in sftp_copy()
1120 return -1; in sftp_copy()
1127 error("Cannot copy non-regular file: %s", oldpath); in sftp_copy()
1128 return -1; in sftp_copy()
1146 id = conn->msg_id++; in sftp_copy()
1162 return -1; in sftp_copy()
1166 id = conn->msg_id++; in sftp_copy()
1184 return -1; in sftp_copy()
1188 id = conn->msg_id++; in sftp_copy()
1191 (r = sshbuf_put_cstring(msg, "copy-data")) != 0 || in sftp_copy()
1199 debug3("Sent message copy-data \"%s\" 0 0 -> \"%s\" 0", in sftp_copy()
1214 return status == SSH2_FX_OK ? 0 : -1; in sftp_copy()
1223 int r, use_ext = (conn->exts & SFTP_EXT_POSIX_RENAME) && !force_legacy; in sftp_rename()
1229 id = conn->msg_id++; in sftp_rename()
1231 debug2("Sending SSH2_FXP_EXTENDED(posix-rename@openssh.com) " in sftp_rename()
1236 "posix-rename@openssh.com")) != 0) in sftp_rename()
1237 fatal_fr(r, "compose posix-rename"); in sftp_rename()
1249 debug3("Sent message %s \"%s\" -> \"%s\"", in sftp_rename()
1250 use_ext ? "posix-rename@openssh.com" : in sftp_rename()
1259 return status == SSH2_FX_OK ? 0 : -1; in sftp_rename()
1269 if ((conn->exts & SFTP_EXT_HARDLINK) == 0) { in sftp_hardlink()
1270 error("Server does not support hardlink@openssh.com extension"); in sftp_hardlink()
1271 return -1; in sftp_hardlink()
1273 debug2("Sending SSH2_FXP_EXTENDED(hardlink@openssh.com) " in sftp_hardlink()
1280 id = conn->msg_id++; in sftp_hardlink()
1283 (r = sshbuf_put_cstring(msg, "hardlink@openssh.com")) != 0 || in sftp_hardlink()
1288 debug3("Sent message hardlink@openssh.com \"%s\" -> \"%s\"", in sftp_hardlink()
1297 return status == SSH2_FX_OK ? 0 : -1; in sftp_hardlink()
1307 if (conn->version < 3) { in sftp_symlink()
1317 id = conn->msg_id++; in sftp_symlink()
1324 debug3("Sent message SSH2_FXP_SYMLINK \"%s\" -> \"%s\"", oldpath, in sftp_symlink()
1333 return status == SSH2_FX_OK ? 0 : -1; in sftp_symlink()
1344 if ((conn->exts & SFTP_EXT_FSYNC) == 0) in sftp_fsync()
1345 return -1; in sftp_fsync()
1346 debug2("Sending SSH2_FXP_EXTENDED(fsync@openssh.com)"); in sftp_fsync()
1351 id = conn->msg_id++; in sftp_fsync()
1354 (r = sshbuf_put_cstring(msg, "fsync@openssh.com")) != 0 || in sftp_fsync()
1358 debug3("Sent message fsync@openssh.com I:%u", id); in sftp_fsync()
1365 return status == SSH2_FX_OK ? 0 : -1; in sftp_fsync()
1381 expected_id = id = conn->msg_id++; in sftp_readlink()
1417 debug3("SSH_FXP_READLINK %s -> %s", path, filename); in sftp_readlink()
1435 if ((conn->exts & SFTP_EXT_STATVFS) == 0) { in sftp_statvfs()
1436 error("Server does not support statvfs@openssh.com extension"); in sftp_statvfs()
1437 return -1; in sftp_statvfs()
1440 debug2("Sending SSH2_FXP_EXTENDED(statvfs@openssh.com) \"%s\"", path); in sftp_statvfs()
1442 id = conn->msg_id++; in sftp_statvfs()
1448 (r = sshbuf_put_cstring(msg, "statvfs@openssh.com")) != 0 || in sftp_statvfs()
1465 if ((conn->exts & SFTP_EXT_FSTATVFS) == 0) { in sftp_fstatvfs()
1466 error("Server does not support fstatvfs@openssh.com extension"); in sftp_fstatvfs()
1467 return -1; in sftp_fstatvfs()
1470 debug2("Sending SSH2_FXP_EXTENDED(fstatvfs@openssh.com)"); in sftp_fstatvfs()
1472 id = conn->msg_id++; in sftp_fstatvfs()
1478 (r = sshbuf_put_cstring(msg, "fstatvfs@openssh.com")) != 0 || in sftp_fstatvfs()
1495 if ((conn->exts & SFTP_EXT_LSETSTAT) == 0) { in sftp_lsetstat()
1496 error("Server does not support lsetstat@openssh.com extension"); in sftp_lsetstat()
1497 return -1; in sftp_lsetstat()
1500 debug2("Sending SSH2_FXP_EXTENDED(lsetstat@openssh.com) \"%s\"", path); in sftp_lsetstat()
1502 id = conn->msg_id++; in sftp_lsetstat()
1507 (r = sshbuf_put_cstring(msg, "lsetstat@openssh.com")) != 0 || in sftp_lsetstat()
1518 return status == SSH2_FX_OK ? 0 : -1; in sftp_lsetstat()
1522 send_read_request(struct sftp_conn *conn, u_int id, u_int64_t offset, in send_read_request() argument
1533 (r = sshbuf_put_u64(msg, offset)) != 0 || in send_read_request()
1563 id = conn->msg_id++; in send_open()
1576 return -1; in send_open()
1603 int local_fd = -1, write_error; in sftp_download()
1605 u_int64_t offset = 0, size, highwater = 0, maxack = 0; in sftp_download() local
1622 return -1; in sftp_download()
1627 if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) in sftp_download()
1628 mode = a->perm & 0777; in sftp_download()
1632 if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) && in sftp_download()
1633 (!S_ISREG(a->perm))) { in sftp_download()
1635 return(-1); in sftp_download()
1638 if (a->flags & SSH2_FILEXFER_ATTR_SIZE) in sftp_download()
1639 size = a->size; in sftp_download()
1643 buflen = conn->download_buflen; in sftp_download()
1648 return -1; in sftp_download()
1652 if (local_fd == -1) { in sftp_download()
1657 if (fstat(local_fd, &st) == -1) { in sftp_download()
1672 if (local_fd != -1) in sftp_download()
1674 return -1; in sftp_download()
1676 offset = highwater = maxack = st.st_size; in sftp_download()
1682 progress_counter = offset; in sftp_download()
1708 debug3("Request range %llu -> %llu (%d/%d)", in sftp_download()
1709 (unsigned long long)offset, in sftp_download()
1710 (unsigned long long)offset + buflen - 1, in sftp_download()
1712 req = request_enqueue(&requests, conn->msg_id++, in sftp_download()
1713 buflen, offset); in sftp_download()
1714 offset += buflen; in sftp_download()
1716 send_read_request(conn, req->id, req->offset, in sftp_download()
1717 req->len, handle, handle_len); in sftp_download()
1740 num_req--; in sftp_download()
1745 debug3("Received data %llu -> %llu", in sftp_download()
1746 (unsigned long long)req->offset, in sftp_download()
1747 (unsigned long long)req->offset + len - 1); in sftp_download()
1748 if (len > req->len) in sftp_download()
1750 "%zu > %zu", len, req->len); in sftp_download()
1752 if ((lseek(local_fd, req->offset, SEEK_SET) == -1 || in sftp_download()
1760 * Track both the highest offset acknowledged in sftp_download()
1761 * and the highest *contiguous* offset in sftp_download()
1766 if (maxack < req->offset + len) in sftp_download()
1767 maxack = req->offset + len; in sftp_download()
1768 if (!reordered && req->offset <= highwater) in sftp_download()
1770 else if (!reordered && req->offset > highwater) in sftp_download()
1776 if (len == req->len) { in sftp_download()
1779 num_req--; in sftp_download()
1782 debug3("Short data block, re-requesting " in sftp_download()
1783 "%llu -> %llu (%2d)", in sftp_download()
1784 (unsigned long long)req->offset + len, in sftp_download()
1785 (unsigned long long)req->offset + in sftp_download()
1786 req->len - 1, num_req); in sftp_download()
1787 req->id = conn->msg_id++; in sftp_download()
1788 req->len -= len; in sftp_download()
1789 req->offset += len; in sftp_download()
1790 send_read_request(conn, req->id, in sftp_download()
1791 req->offset, req->len, handle, handle_len); in sftp_download()
1797 if (size > 0 && offset > size) { in sftp_download()
1801 (unsigned long long)offset, in sftp_download()
1804 } else if (max_req < conn->num_requests) { in sftp_download()
1838 if (ftruncate(local_fd, highwater) == -1) in sftp_download()
1844 status = -1; in sftp_download()
1858 if (preserve_flag && fchmod(local_fd, mode) == -1) in sftp_download()
1860 if (preserve_flag && chmod(local_path, mode) == -1) in sftp_download()
1865 (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME)) { in sftp_download()
1867 tv[0].tv_sec = a->atime; in sftp_download()
1868 tv[1].tv_sec = a->mtime; in sftp_download()
1870 if (utimes(local_path, tv) == -1) in sftp_download()
1878 if (fsync(local_fd) == -1) in sftp_download()
1887 return status == SSH2_FX_OK ? 0 : -1; in sftp_download()
1903 return -1; in download_dir_internal()
1911 return -1; in download_dir_internal()
1915 if (!S_ISDIR(dirattrib->perm)) { in download_dir_internal()
1917 return -1; in download_dir_internal()
1922 if (dirattrib->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { in download_dir_internal()
1923 mode = dirattrib->perm & 01777; in download_dir_internal()
1930 if (mkdir(dst, tmpmode) == -1 && errno != EEXIST) { in download_dir_internal()
1932 return -1; in download_dir_internal()
1935 if (sftp_readdir(conn, src, &dir_entries) == -1) { in download_dir_internal()
1937 return -1; in download_dir_internal()
1944 filename = dir_entries[i]->filename; in download_dir_internal()
1948 a = &dir_entries[i]->a; in download_dir_internal()
1949 if (S_ISLNK(a->perm)) { in download_dir_internal()
1958 ret = -1; in download_dir_internal()
1964 if (S_ISDIR(a->perm)) { in download_dir_internal()
1971 fsync_flag, follow_link_flag, inplace_flag) == -1) in download_dir_internal()
1972 ret = -1; in download_dir_internal()
1973 } else if (S_ISREG(a->perm)) { in download_dir_internal()
1976 inplace_flag) == -1) { in download_dir_internal()
1979 ret = -1; in download_dir_internal()
1989 if (dirattrib->flags & SSH2_FILEXFER_ATTR_ACMODTIME) { in download_dir_internal()
1991 tv[0].tv_sec = dirattrib->atime; in download_dir_internal()
1992 tv[1].tv_sec = dirattrib->mtime; in download_dir_internal()
1994 if (utimes(dst, tv) == -1) in download_dir_internal()
2002 if (mode != tmpmode && chmod(dst, mode) == -1) in download_dir_internal()
2021 return -1; in sftp_download_dir()
2038 off_t offset, progress_counter; in sftp_upload() local
2054 if ((local_fd = open(local_path, O_RDONLY)) == -1) { in sftp_upload()
2056 return(-1); in sftp_upload()
2058 if (fstat(local_fd, &sb) == -1) { in sftp_upload()
2061 return(-1); in sftp_upload()
2066 return(-1); in sftp_upload()
2080 return -1; in sftp_upload()
2087 return -1; in sftp_upload()
2090 if (lseek(local_fd, (off_t)c.size, SEEK_SET) == -1) { in sftp_upload()
2092 return -1; in sftp_upload()
2106 return -1; in sftp_upload()
2109 id = conn->msg_id; in sftp_upload()
2111 data = xmalloc(conn->upload_buflen); in sftp_upload()
2114 offset = progress_counter = (resume ? c.size : 0); in sftp_upload()
2134 len = read(local_fd, data, conn->upload_buflen); in sftp_upload()
2135 while ((len == -1) && in sftp_upload()
2138 if (len == -1) { in sftp_upload()
2142 ack = request_enqueue(&acks, ++id, len, offset); in sftp_upload()
2145 (r = sshbuf_put_u32(msg, ack->id)) != 0 || in sftp_upload()
2148 (r = sshbuf_put_u64(msg, offset)) != 0 || in sftp_upload()
2153 id, (unsigned long long)offset, len); in sftp_upload()
2161 id - ackid >= conn->num_requests) { in sftp_upload()
2183 ack->id, ack->len, (unsigned long long)ack->offset); in sftp_upload()
2185 progress_counter += ack->len; in sftp_upload()
2187 * Track both the highest offset acknowledged and the in sftp_upload()
2188 * highest *contiguous* offset acknowledged. in sftp_upload()
2192 if (maxack < ack->offset + ack->len) in sftp_upload()
2193 maxack = ack->offset + ack->len; in sftp_upload()
2194 if (!reordered && ack->offset <= highwater) in sftp_upload()
2196 else if (!reordered && ack->offset > highwater) { in sftp_upload()
2202 offset += len; in sftp_upload()
2203 if (offset < 0) in sftp_upload()
2204 fatal_f("offset < 0"); in sftp_upload()
2229 if (close(local_fd) == -1) { in sftp_upload()
2246 return status == SSH2_FX_OK ? 0 : -1; in sftp_upload()
2266 return -1; in upload_dir_internal()
2269 if (stat(src, &sb) == -1) { in upload_dir_internal()
2271 return -1; in upload_dir_internal()
2275 return -1; in upload_dir_internal()
2297 return -1; in upload_dir_internal()
2300 return -1; in upload_dir_internal()
2307 return -1; in upload_dir_internal()
2311 if (dp->d_ino == 0) in upload_dir_internal()
2315 filename = dp->d_name; in upload_dir_internal()
2321 if (lstat(new_src, &sb) == -1) { in upload_dir_internal()
2324 ret = -1; in upload_dir_internal()
2333 if (stat(new_src, &sb) == -1) { in upload_dir_internal()
2336 ret = -1; in upload_dir_internal()
2343 fsync_flag, follow_link_flag, inplace_flag) == -1) in upload_dir_internal()
2344 ret = -1; in upload_dir_internal()
2348 inplace_flag) == -1) { in upload_dir_internal()
2351 ret = -1; in upload_dir_internal()
2375 return -1; in sftp_upload_dir()
2403 pfd.fd = to->fd_in; in handle_dest_replies()
2405 if ((r = poll(&pfd, 1, 0)) == -1) { in handle_dest_replies()
2434 * high-water mark. ATM the only caller of this function (scp) in handle_dest_replies()
2446 (*nreqsp)--; in handle_dest_replies()
2459 u_int64_t offset = 0, size; in sftp_crossload() local
2476 return -1; in sftp_crossload()
2480 if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) && in sftp_crossload()
2481 (!S_ISREG(a->perm))) { in sftp_crossload()
2483 return(-1); in sftp_crossload()
2485 if (a->flags & SSH2_FILEXFER_ATTR_SIZE) in sftp_crossload()
2486 size = a->size; in sftp_crossload()
2490 buflen = from->download_buflen; in sftp_crossload()
2491 if (buflen > to->upload_buflen) in sftp_crossload()
2492 buflen = to->upload_buflen; in sftp_crossload()
2497 return -1; in sftp_crossload()
2500 a->flags &= ~SSH2_FILEXFER_ATTR_SIZE; in sftp_crossload()
2501 a->flags &= ~SSH2_FILEXFER_ATTR_UIDGID; in sftp_crossload()
2502 a->perm &= 0777; in sftp_crossload()
2504 a->flags &= ~SSH2_FILEXFER_ATTR_ACMODTIME; in sftp_crossload()
2509 return -1; in sftp_crossload()
2513 offset = 0; in sftp_crossload()
2540 debug3("Request range %llu -> %llu (%d/%d)", in sftp_crossload()
2541 (unsigned long long)offset, in sftp_crossload()
2542 (unsigned long long)offset + buflen - 1, in sftp_crossload()
2544 req = request_enqueue(&requests, from->msg_id++, in sftp_crossload()
2545 buflen, offset); in sftp_crossload()
2546 offset += buflen; in sftp_crossload()
2548 send_read_request(from, req->id, req->offset, in sftp_crossload()
2549 req->len, from_handle, from_handle_len); in sftp_crossload()
2577 num_req--; in sftp_crossload()
2582 debug3("Received data %llu -> %llu", in sftp_crossload()
2583 (unsigned long long)req->offset, in sftp_crossload()
2584 (unsigned long long)req->offset + len - 1); in sftp_crossload()
2585 if (len > req->len) in sftp_crossload()
2587 "%zu > %zu", len, req->len); in sftp_crossload()
2592 (r = sshbuf_put_u32(msg, to->msg_id++)) != 0 || in sftp_crossload()
2595 (r = sshbuf_put_u64(msg, req->offset)) != 0 || in sftp_crossload()
2600 id, (unsigned long long)offset, len); in sftp_crossload()
2605 if (len == req->len) { in sftp_crossload()
2608 num_req--; in sftp_crossload()
2611 debug3("Short data block, re-requesting " in sftp_crossload()
2612 "%llu -> %llu (%2d)", in sftp_crossload()
2613 (unsigned long long)req->offset + len, in sftp_crossload()
2614 (unsigned long long)req->offset + in sftp_crossload()
2615 req->len - 1, num_req); in sftp_crossload()
2616 req->id = from->msg_id++; in sftp_crossload()
2617 req->len -= len; in sftp_crossload()
2618 req->offset += len; in sftp_crossload()
2619 send_read_request(from, req->id, in sftp_crossload()
2620 req->offset, req->len, in sftp_crossload()
2627 if (size > 0 && offset > size) { in sftp_crossload()
2631 (unsigned long long)offset, in sftp_crossload()
2634 } else if (max_req < from->num_requests) { in sftp_crossload()
2669 status = -1; in sftp_crossload()
2682 status = -1; in sftp_crossload()
2696 return status == SSH2_FX_OK ? 0 : -1; in sftp_crossload()
2715 return -1; in crossload_dir_internal()
2721 return -1; in crossload_dir_internal()
2725 if (!S_ISDIR(dirattrib->perm)) { in crossload_dir_internal()
2727 return -1; in crossload_dir_internal()
2753 return -1; in crossload_dir_internal()
2756 return -1; in crossload_dir_internal()
2761 if (sftp_readdir(from, from_path, &dir_entries) == -1) { in crossload_dir_internal()
2763 return -1; in crossload_dir_internal()
2770 filename = dir_entries[i]->filename; in crossload_dir_internal()
2774 a = &dir_entries[i]->a; in crossload_dir_internal()
2775 if (S_ISLNK(a->perm)) { in crossload_dir_internal()
2784 ret = -1; in crossload_dir_internal()
2789 if (S_ISDIR(a->perm)) { in crossload_dir_internal()
2796 print_flag, follow_link_flag) == -1) in crossload_dir_internal()
2797 ret = -1; in crossload_dir_internal()
2798 } else if (S_ISREG(a->perm)) { in crossload_dir_internal()
2800 new_to_path, a, preserve_flag) == -1) { in crossload_dir_internal()
2803 ret = -1; in crossload_dir_internal()
2831 return -1; in sftp_crossload_dir()
2843 return (conn->exts & SFTP_EXT_GETUSERSGROUPS_BY_ID) != 0; in sftp_can_get_users_groups_by_id()
2866 expected_id = id = conn->msg_id++; in sftp_get_users_groups_by_id()
2867 debug2("Sending SSH2_FXP_EXTENDED(users-groups-by-id@openssh.com)"); in sftp_get_users_groups_by_id()
2879 "users-groups-by-id@openssh.com")) != 0 || in sftp_get_users_groups_by_id()
2897 error("users-groups-by-id %s", in sftp_get_users_groups_by_id()
2903 return -1; in sftp_get_users_groups_by_id()
2962 if (p1[0] != '\0' && p1[strlen(p1) - 1] != '/') in sftp_path_append()
3007 return l > 0 && pathname[l - 1] == '/'; in sftp_globpath_is_dir()