|
Lines 63-68
Link Here
|
| 63 |
struct passwd *pw = NULL; |
63 |
struct passwd *pw = NULL; |
| 64 |
char *client_addr = NULL; |
64 |
char *client_addr = NULL; |
| 65 |
|
65 |
|
|
|
66 |
/* Only basic operations allowed for client; RestrictSFtpSysToBasics in config */ |
| 67 |
int restrict_to_basics; |
| 68 |
|
| 66 |
/* input and output queue */ |
69 |
/* input and output queue */ |
| 67 |
Buffer iqueue; |
70 |
Buffer iqueue; |
| 68 |
Buffer oqueue; |
71 |
Buffer oqueue; |
|
Lines 771-777
Link Here
|
| 771 |
name = get_string(NULL); |
774 |
name = get_string(NULL); |
| 772 |
a = get_attrib(); |
775 |
a = get_attrib(); |
| 773 |
debug("request %u: setstat name \"%s\"", id, name); |
776 |
debug("request %u: setstat name \"%s\"", id, name); |
| 774 |
if (readonly) { |
777 |
if (readonly || restrict_to_basics) { |
| 775 |
status = SSH2_FX_PERMISSION_DENIED; |
778 |
status = SSH2_FX_PERMISSION_DENIED; |
| 776 |
a->flags = 0; |
779 |
a->flags = 0; |
| 777 |
} |
780 |
} |
|
Lines 825-831
Link Here
|
| 825 |
fd = handle_to_fd(handle); |
828 |
fd = handle_to_fd(handle); |
| 826 |
if (fd < 0) |
829 |
if (fd < 0) |
| 827 |
status = SSH2_FX_FAILURE; |
830 |
status = SSH2_FX_FAILURE; |
| 828 |
else if (readonly) |
831 |
else if (readonly || restrict_to_basics) |
| 829 |
status = SSH2_FX_PERMISSION_DENIED; |
832 |
status = SSH2_FX_PERMISSION_DENIED; |
| 830 |
else { |
833 |
else { |
| 831 |
char *name = handle_to_name(handle); |
834 |
char *name = handle_to_name(handle); |
|
Lines 1000-1006
Link Here
|
| 1000 |
a->perm & 07777 : 0777; |
1003 |
a->perm & 07777 : 0777; |
| 1001 |
debug3("request %u: mkdir", id); |
1004 |
debug3("request %u: mkdir", id); |
| 1002 |
logit("mkdir name \"%s\" mode 0%o", name, mode); |
1005 |
logit("mkdir name \"%s\" mode 0%o", name, mode); |
| 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 = mkdir(name, mode); |
1009 |
ret = mkdir(name, mode); |
|
Lines 1021-1027
Link Here
|
| 1021 |
name = get_string(NULL); |
1024 |
name = get_string(NULL); |
| 1022 |
debug3("request %u: rmdir", id); |
1025 |
debug3("request %u: rmdir", id); |
| 1023 |
logit("rmdir name \"%s\"", name); |
1026 |
logit("rmdir name \"%s\"", name); |
| 1024 |
if (readonly) |
1027 |
if (readonly || restrict_to_basics) |
| 1025 |
status = SSH2_FX_PERMISSION_DENIED; |
1028 |
status = SSH2_FX_PERMISSION_DENIED; |
| 1026 |
else { |
1029 |
else { |
| 1027 |
ret = rmdir(name); |
1030 |
ret = rmdir(name); |
|
Lines 1071-1077
Link Here
|
| 1071 |
debug3("request %u: rename", id); |
1074 |
debug3("request %u: rename", id); |
| 1072 |
logit("rename old \"%s\" new \"%s\"", oldpath, newpath); |
1075 |
logit("rename old \"%s\" new \"%s\"", oldpath, newpath); |
| 1073 |
status = SSH2_FX_FAILURE; |
1076 |
status = SSH2_FX_FAILURE; |
| 1074 |
if (readonly) |
1077 |
if (readonly || restrict_to_basics) |
| 1075 |
status = SSH2_FX_PERMISSION_DENIED; |
1078 |
status = SSH2_FX_PERMISSION_DENIED; |
| 1076 |
else if (lstat(oldpath, &sb) == -1) |
1079 |
else if (lstat(oldpath, &sb) == -1) |
| 1077 |
status = errno_to_portable(errno); |
1080 |
status = errno_to_portable(errno); |
|
Lines 1157-1163
Link Here
|
| 1157 |
debug3("request %u: symlink", id); |
1160 |
debug3("request %u: symlink", id); |
| 1158 |
logit("symlink old \"%s\" new \"%s\"", oldpath, newpath); |
1161 |
logit("symlink old \"%s\" new \"%s\"", oldpath, newpath); |
| 1159 |
/* this will fail if 'newpath' exists */ |
1162 |
/* this will fail if 'newpath' exists */ |
| 1160 |
if (readonly) |
1163 |
if (readonly || restrict_to_basics) |
| 1161 |
status = SSH2_FX_PERMISSION_DENIED; |
1164 |
status = SSH2_FX_PERMISSION_DENIED; |
| 1162 |
else { |
1165 |
else { |
| 1163 |
ret = symlink(oldpath, newpath); |
1166 |
ret = symlink(oldpath, newpath); |
|
Lines 1178-1184
Link Here
|
| 1178 |
newpath = get_string(NULL); |
1181 |
newpath = get_string(NULL); |
| 1179 |
debug3("request %u: posix-rename", id); |
1182 |
debug3("request %u: posix-rename", id); |
| 1180 |
logit("posix-rename old \"%s\" new \"%s\"", oldpath, newpath); |
1183 |
logit("posix-rename old \"%s\" new \"%s\"", oldpath, newpath); |
| 1181 |
if (readonly) |
1184 |
if (readonly || restrict_to_basics) |
| 1182 |
status = SSH2_FX_PERMISSION_DENIED; |
1185 |
status = SSH2_FX_PERMISSION_DENIED; |
| 1183 |
else { |
1186 |
else { |
| 1184 |
ret = rename(oldpath, newpath); |
1187 |
ret = rename(oldpath, newpath); |
|
Lines 1199-1205
Link Here
|
| 1199 |
debug3("request %u: statfs", id); |
1202 |
debug3("request %u: statfs", id); |
| 1200 |
logit("statfs \"%s\"", path); |
1203 |
logit("statfs \"%s\"", path); |
| 1201 |
|
1204 |
|
| 1202 |
if (statvfs(path, &st) != 0) |
1205 |
if (restrict_to_basics) |
|
|
1206 |
send_status(id, SSH2_FX_PERMISSION_DENIED); |
| 1207 |
else if (statvfs(path, &st) != 0) |
| 1203 |
send_status(id, errno_to_portable(errno)); |
1208 |
send_status(id, errno_to_portable(errno)); |
| 1204 |
else |
1209 |
else |
| 1205 |
send_statvfs(id, &st); |
1210 |
send_statvfs(id, &st); |
|
Lines 1219-1225
Link Here
|
| 1219 |
send_status(id, SSH2_FX_FAILURE); |
1224 |
send_status(id, SSH2_FX_FAILURE); |
| 1220 |
return; |
1225 |
return; |
| 1221 |
} |
1226 |
} |
| 1222 |
if (fstatvfs(fd, &st) != 0) |
1227 |
if (restrict_to_basics) |
|
|
1228 |
send_status(id, SSH2_FX_PERMISSION_DENIED); |
| 1229 |
else if (fstatvfs(fd, &st) != 0) |
| 1223 |
send_status(id, errno_to_portable(errno)); |
1230 |
send_status(id, errno_to_portable(errno)); |
| 1224 |
else |
1231 |
else |
| 1225 |
send_statvfs(id, &st); |
1232 |
send_statvfs(id, &st); |
|
Lines 1235-1241
Link Here
|
| 1235 |
newpath = get_string(NULL); |
1242 |
newpath = get_string(NULL); |
| 1236 |
debug3("request %u: hardlink", id); |
1243 |
debug3("request %u: hardlink", id); |
| 1237 |
logit("hardlink old \"%s\" new \"%s\"", oldpath, newpath); |
1244 |
logit("hardlink old \"%s\" new \"%s\"", oldpath, newpath); |
| 1238 |
if (readonly) |
1245 |
if (readonly || restrict_to_basics) |
| 1239 |
status = SSH2_FX_PERMISSION_DENIED; |
1246 |
status = SSH2_FX_PERMISSION_DENIED; |
| 1240 |
else { |
1247 |
else { |
| 1241 |
ret = link(oldpath, newpath); |
1248 |
ret = link(oldpath, newpath); |
|
Lines 1396-1402
Link Here
|
| 1396 |
} |
1403 |
} |
| 1397 |
|
1404 |
|
| 1398 |
int |
1405 |
int |
| 1399 |
sftp_server_main(int argc, char **argv, struct passwd *user_pw) |
1406 |
sftp_server_main(int argc, char **argv, struct passwd *user_pw, int restrict_client_to_basics) |
| 1400 |
{ |
1407 |
{ |
| 1401 |
fd_set *rset, *wset; |
1408 |
fd_set *rset, *wset; |
| 1402 |
int in, out, max, ch, skipargs = 0, log_stderr = 0; |
1409 |
int in, out, max, ch, skipargs = 0, log_stderr = 0; |
|
Lines 1464-1469
Link Here
|
| 1464 |
client_addr = xstrdup("UNKNOWN"); |
1471 |
client_addr = xstrdup("UNKNOWN"); |
| 1465 |
|
1472 |
|
| 1466 |
pw = pwcopy(user_pw); |
1473 |
pw = pwcopy(user_pw); |
|
|
1474 |
restrict_to_basics = restrict_client_to_basics; |
| 1467 |
|
1475 |
|
| 1468 |
logit("session opened for local user %s from [%s]", |
1476 |
logit("session opened for local user %s from [%s]", |
| 1469 |
pw->pw_name, client_addr); |
1477 |
pw->pw_name, client_addr); |