summaryrefslogtreecommitdiff
path: root/sftp-server.c
diff options
context:
space:
mode:
Diffstat (limited to 'sftp-server.c')
-rw-r--r--sftp-server.c76
1 files changed, 6 insertions, 70 deletions
diff --git a/sftp-server.c b/sftp-server.c
index aeff1aa17..7d09504d9 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -969,9 +969,9 @@ process_fsetstat(u_int32_t id)
969 if (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { 969 if (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) {
970 logit("set \"%s\" mode %04o", name, a.perm); 970 logit("set \"%s\" mode %04o", name, a.perm);
971#ifdef HAVE_FCHMOD 971#ifdef HAVE_FCHMOD
972 ret = fchmod(fd, a->perm & 07777); 972 r = fchmod(fd, a.perm & 07777);
973#else 973#else
974 ret = chmod(name, a->perm & 07777); 974 r = chmod(name, a.perm & 07777);
975#endif 975#endif
976 if (r == -1) 976 if (r == -1)
977 status = errno_to_portable(errno); 977 status = errno_to_portable(errno);
@@ -984,9 +984,9 @@ process_fsetstat(u_int32_t id)
984 localtime(&t)); 984 localtime(&t));
985 logit("set \"%s\" modtime %s", name, buf); 985 logit("set \"%s\" modtime %s", name, buf);
986#ifdef HAVE_FUTIMES 986#ifdef HAVE_FUTIMES
987 ret = futimes(fd, attrib_to_tv(a)); 987 r = futimes(fd, attrib_to_tv(&a));
988#else 988#else
989 ret = utimes(name, attrib_to_tv(a)); 989 r = utimes(name, attrib_to_tv(&a));
990#endif 990#endif
991 if (r == -1) 991 if (r == -1)
992 status = errno_to_portable(errno); 992 status = errno_to_portable(errno);
@@ -995,9 +995,9 @@ process_fsetstat(u_int32_t id)
995 logit("set \"%s\" owner %lu group %lu", name, 995 logit("set \"%s\" owner %lu group %lu", name,
996 (u_long)a.uid, (u_long)a.gid); 996 (u_long)a.uid, (u_long)a.gid);
997#ifdef HAVE_FCHOWN 997#ifdef HAVE_FCHOWN
998 ret = fchown(fd, a->uid, a->gid); 998 r = fchown(fd, a.uid, a.gid);
999#else 999#else
1000 ret = chown(name, a->uid, a->gid); 1000 r = chown(name, a.uid, a.gid);
1001#endif 1001#endif
1002 if (r == -1) 1002 if (r == -1)
1003 status = errno_to_portable(errno); 1003 status = errno_to_portable(errno);
@@ -1005,70 +1005,6 @@ process_fsetstat(u_int32_t id)
1005 } 1005 }
1006 send_status(id, status); 1006 send_status(id, status);
1007} 1007}
1008static void
1009process_fsetstat(u_int32_t id)
1010{
1011 Attrib a;
1012 int handle, fd, r;
1013 int status = SSH2_FX_OK;
1014
1015 if ((r = get_handle(iqueue, &handle)) != 0 ||
1016 (r = decode_attrib(iqueue, &a)) != 0)
1017 fatal("%s: buffer error: %s", __func__, ssh_err(r));
1018
1019 debug("request %u: fsetstat handle %d", id, handle);
1020 fd = handle_to_fd(handle);
1021 if (fd < 0)
1022 status = SSH2_FX_FAILURE;
1023 else {
1024 char *name = handle_to_name(handle);
1025
1026 if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {
1027 logit("set \"%s\" size %llu",
1028 name, (unsigned long long)a->size);
1029 ret = ftruncate(fd, a->size);
1030 if (ret == -1)
1031 status = errno_to_portable(errno);
1032 }
1033 if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) {
1034 logit("set \"%s\" mode %04o", name, a->perm);
1035#ifdef HAVE_FCHMOD
1036 ret = fchmod(fd, a->perm & 07777);
1037#else
1038 ret = chmod(name, a->perm & 07777);
1039#endif
1040 if (ret == -1)
1041 status = errno_to_portable(errno);
1042 }
1043 if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) {
1044 char buf[64];
1045 time_t t = a->mtime;
1046
1047 strftime(buf, sizeof(buf), "%Y%m%d-%H:%M:%S",
1048 localtime(&t));
1049 logit("set \"%s\" modtime %s", name, buf);
1050#ifdef HAVE_FUTIMES
1051 ret = futimes(fd, attrib_to_tv(a));
1052#else
1053 ret = utimes(name, attrib_to_tv(a));
1054#endif
1055 if (ret == -1)
1056 status = errno_to_portable(errno);
1057 }
1058 if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) {
1059 logit("set \"%s\" owner %lu group %lu", name,
1060 (u_long)a->uid, (u_long)a->gid);
1061#ifdef HAVE_FCHOWN
1062 ret = fchown(fd, a->uid, a->gid);
1063#else
1064 ret = chown(name, a->uid, a->gid);
1065#endif
1066 if (ret == -1)
1067 status = errno_to_portable(errno);
1068 }
1069 }
1070 send_status(id, status);
1071}
1072 1008
1073static void 1009static void
1074process_opendir(u_int32_t id) 1010process_opendir(u_int32_t id)