|
Lines 54-59
Link Here
|
| 54 |
struct passwd *pw = NULL; |
54 |
struct passwd *pw = NULL; |
| 55 |
char *client_addr = NULL; |
55 |
char *client_addr = NULL; |
| 56 |
|
56 |
|
|
|
57 |
/* Only basic operations allowed for client; RestrictSFtpSysToBasics in config */ |
| 58 |
int restrict_to_basics; |
| 59 |
|
| 57 |
/* input and output queue */ |
60 |
/* input and output queue */ |
| 58 |
Buffer iqueue; |
61 |
Buffer iqueue; |
| 59 |
Buffer oqueue; |
62 |
Buffer oqueue; |
|
Lines 762-768
Link Here
|
| 762 |
name = get_string(NULL); |
765 |
name = get_string(NULL); |
| 763 |
a = get_attrib(); |
766 |
a = get_attrib(); |
| 764 |
debug("request %u: setstat name \"%s\"", id, name); |
767 |
debug("request %u: setstat name \"%s\"", id, name); |
| 765 |
if (readonly) { |
768 |
if (readonly || restrict_to_basics) { |
| 766 |
status = SSH2_FX_PERMISSION_DENIED; |
769 |
status = SSH2_FX_PERMISSION_DENIED; |
| 767 |
a->flags = 0; |
770 |
a->flags = 0; |
| 768 |
} |
771 |
} |
|
Lines 816-822
Link Here
|
| 816 |
fd = handle_to_fd(handle); |
819 |
fd = handle_to_fd(handle); |
| 817 |
if (fd < 0) |
820 |
if (fd < 0) |
| 818 |
status = SSH2_FX_FAILURE; |
821 |
status = SSH2_FX_FAILURE; |
| 819 |
else if (readonly) |
822 |
else if (readonly || restrict_to_basics) |
| 820 |
status = SSH2_FX_PERMISSION_DENIED; |
823 |
status = SSH2_FX_PERMISSION_DENIED; |
| 821 |
else { |
824 |
else { |
| 822 |
char *name = handle_to_name(handle); |
825 |
char *name = handle_to_name(handle); |
|
Lines 979-985
Link Here
|
| 979 |
a->perm & 07777 : 0777; |
982 |
a->perm & 07777 : 0777; |
| 980 |
debug3("request %u: mkdir", id); |
983 |
debug3("request %u: mkdir", id); |
| 981 |
logit("mkdir name \"%s\" mode 0%o", name, mode); |
984 |
logit("mkdir name \"%s\" mode 0%o", name, mode); |
| 982 |
if (readonly) |
985 |
if (readonly || restrict_to_basics) |
| 983 |
status = SSH2_FX_PERMISSION_DENIED; |
986 |
status = SSH2_FX_PERMISSION_DENIED; |
| 984 |
else { |
987 |
else { |
| 985 |
ret = mkdir(name, mode); |
988 |
ret = mkdir(name, mode); |
|
Lines 1000-1006
Link Here
|
| 1000 |
name = get_string(NULL); |
1003 |
name = get_string(NULL); |
| 1001 |
debug3("request %u: rmdir", id); |
1004 |
debug3("request %u: rmdir", id); |
| 1002 |
logit("rmdir name \"%s\"", name); |
1005 |
logit("rmdir name \"%s\"", name); |
| 1003 |
if (readonly) |
1006 |
if (readonly || restrict_to_basics) |
| 1004 |
status = SSH2_FX_PERMISSION_DENIED; |
1007 |
status = SSH2_FX_PERMISSION_DENIED; |
| 1005 |
else { |
1008 |
else { |
| 1006 |
ret = rmdir(name); |
1009 |
ret = rmdir(name); |
|
Lines 1050-1056
Link Here
|
| 1050 |
debug3("request %u: rename", id); |
1053 |
debug3("request %u: rename", id); |
| 1051 |
logit("rename old \"%s\" new \"%s\"", oldpath, newpath); |
1054 |
logit("rename old \"%s\" new \"%s\"", oldpath, newpath); |
| 1052 |
status = SSH2_FX_FAILURE; |
1055 |
status = SSH2_FX_FAILURE; |
| 1053 |
if (readonly) |
1056 |
if (readonly || restrict_to_basics) |
| 1054 |
status = SSH2_FX_PERMISSION_DENIED; |
1057 |
status = SSH2_FX_PERMISSION_DENIED; |
| 1055 |
else if (lstat(oldpath, &sb) == -1) |
1058 |
else if (lstat(oldpath, &sb) == -1) |
| 1056 |
status = errno_to_portable(errno); |
1059 |
status = errno_to_portable(errno); |
|
Lines 1129-1135
Link Here
|
| 1129 |
debug3("request %u: symlink", id); |
1132 |
debug3("request %u: symlink", id); |
| 1130 |
logit("symlink old \"%s\" new \"%s\"", oldpath, newpath); |
1133 |
logit("symlink old \"%s\" new \"%s\"", oldpath, newpath); |
| 1131 |
/* this will fail if 'newpath' exists */ |
1134 |
/* this will fail if 'newpath' exists */ |
| 1132 |
if (readonly) |
1135 |
if (readonly || restrict_to_basics) |
| 1133 |
status = SSH2_FX_PERMISSION_DENIED; |
1136 |
status = SSH2_FX_PERMISSION_DENIED; |
| 1134 |
else { |
1137 |
else { |
| 1135 |
ret = symlink(oldpath, newpath); |
1138 |
ret = symlink(oldpath, newpath); |
|
Lines 1150-1156
Link Here
|
| 1150 |
newpath = get_string(NULL); |
1153 |
newpath = get_string(NULL); |
| 1151 |
debug3("request %u: posix-rename", id); |
1154 |
debug3("request %u: posix-rename", id); |
| 1152 |
logit("posix-rename old \"%s\" new \"%s\"", oldpath, newpath); |
1155 |
logit("posix-rename old \"%s\" new \"%s\"", oldpath, newpath); |
| 1153 |
if (readonly) |
1156 |
if (readonly || restrict_to_basics) |
| 1154 |
status = SSH2_FX_PERMISSION_DENIED; |
1157 |
status = SSH2_FX_PERMISSION_DENIED; |
| 1155 |
else { |
1158 |
else { |
| 1156 |
ret = rename(oldpath, newpath); |
1159 |
ret = rename(oldpath, newpath); |
|
Lines 1171-1177
Link Here
|
| 1171 |
debug3("request %u: statfs", id); |
1174 |
debug3("request %u: statfs", id); |
| 1172 |
logit("statfs \"%s\"", path); |
1175 |
logit("statfs \"%s\"", path); |
| 1173 |
|
1176 |
|
| 1174 |
if (statvfs(path, &st) != 0) |
1177 |
if (restrict_to_basics) |
|
|
1178 |
send_status(id, SSH2_FX_PERMISSION_DENIED); |
| 1179 |
else if (statvfs(path, &st) != 0) |
| 1175 |
send_status(id, errno_to_portable(errno)); |
1180 |
send_status(id, errno_to_portable(errno)); |
| 1176 |
else |
1181 |
else |
| 1177 |
send_statvfs(id, &st); |
1182 |
send_statvfs(id, &st); |
|
Lines 1191-1197
Link Here
|
| 1191 |
send_status(id, SSH2_FX_FAILURE); |
1196 |
send_status(id, SSH2_FX_FAILURE); |
| 1192 |
return; |
1197 |
return; |
| 1193 |
} |
1198 |
} |
| 1194 |
if (fstatvfs(fd, &st) != 0) |
1199 |
if (restrict_to_basics) |
|
|
1200 |
send_status(id, SSH2_FX_PERMISSION_DENIED); |
| 1201 |
else if (fstatvfs(fd, &st) != 0) |
| 1195 |
send_status(id, errno_to_portable(errno)); |
1202 |
send_status(id, errno_to_portable(errno)); |
| 1196 |
else |
1203 |
else |
| 1197 |
send_statvfs(id, &st); |
1204 |
send_statvfs(id, &st); |
|
Lines 1207-1213
Link Here
|
| 1207 |
newpath = get_string(NULL); |
1214 |
newpath = get_string(NULL); |
| 1208 |
debug3("request %u: hardlink", id); |
1215 |
debug3("request %u: hardlink", id); |
| 1209 |
logit("hardlink old \"%s\" new \"%s\"", oldpath, newpath); |
1216 |
logit("hardlink old \"%s\" new \"%s\"", oldpath, newpath); |
| 1210 |
if (readonly) |
1217 |
if (readonly || restrict_to_basics) |
| 1211 |
status = SSH2_FX_PERMISSION_DENIED; |
1218 |
status = SSH2_FX_PERMISSION_DENIED; |
| 1212 |
else { |
1219 |
else { |
| 1213 |
ret = link(oldpath, newpath); |
1220 |
ret = link(oldpath, newpath); |
|
Lines 1368-1374
Link Here
|
| 1368 |
} |
1375 |
} |
| 1369 |
|
1376 |
|
| 1370 |
int |
1377 |
int |
| 1371 |
sftp_server_main(int argc, char **argv, struct passwd *user_pw) |
1378 |
sftp_server_main(int argc, char **argv, struct passwd *user_pw, int restrict_client_to_basics) |
| 1372 |
{ |
1379 |
{ |
| 1373 |
fd_set *rset, *wset; |
1380 |
fd_set *rset, *wset; |
| 1374 |
int in, out, max, ch, skipargs = 0, log_stderr = 0; |
1381 |
int in, out, max, ch, skipargs = 0, log_stderr = 0; |
|
Lines 1435-1440
Link Here
|
| 1435 |
client_addr = xstrdup("UNKNOWN"); |
1442 |
client_addr = xstrdup("UNKNOWN"); |
| 1436 |
|
1443 |
|
| 1437 |
pw = pwcopy(user_pw); |
1444 |
pw = pwcopy(user_pw); |
|
|
1445 |
restrict_to_basics = restrict_client_to_basics; |
| 1438 |
|
1446 |
|
| 1439 |
logit("session opened for local user %s from [%s]", |
1447 |
logit("session opened for local user %s from [%s]", |
| 1440 |
pw->pw_name, client_addr); |
1448 |
pw->pw_name, client_addr); |