|
Lines 119-124
void do_child(Session *, const char *);
Link Here
|
| 119 |
void do_motd(void); |
119 |
void do_motd(void); |
| 120 |
int check_quietlogin(Session *, const char *); |
120 |
int check_quietlogin(Session *, const char *); |
| 121 |
|
121 |
|
|
|
122 |
int chroot_no_tree = 0; |
| 123 |
|
| 122 |
static void do_authenticated1(Authctxt *); |
124 |
static void do_authenticated1(Authctxt *); |
| 123 |
static void do_authenticated2(Authctxt *); |
125 |
static void do_authenticated2(Authctxt *); |
| 124 |
|
126 |
|
|
Lines 802-807
do_exec(Session *s, const char *command)
Link Here
|
| 802 |
debug("Forced command (key option) '%.900s'", command); |
804 |
debug("Forced command (key option) '%.900s'", command); |
| 803 |
} |
805 |
} |
| 804 |
|
806 |
|
|
|
807 |
if ((s->is_subsystem != SUBSYSTEM_INT_SFTP) && chroot_no_tree) { |
| 808 |
logit("You aren't welcomed, go away!"); |
| 809 |
exit (1); |
| 810 |
} |
| 811 |
|
| 805 |
#ifdef SSH_AUDIT_EVENTS |
812 |
#ifdef SSH_AUDIT_EVENTS |
| 806 |
if (command != NULL) |
813 |
if (command != NULL) |
| 807 |
PRIVSEP(audit_run_command(command)); |
814 |
PRIVSEP(audit_run_command(command)); |
|
Lines 1408-1413
safely_chroot(const char *path, uid_t ui
Link Here
|
| 1408 |
const char *cp; |
1415 |
const char *cp; |
| 1409 |
char component[MAXPATHLEN]; |
1416 |
char component[MAXPATHLEN]; |
| 1410 |
struct stat st; |
1417 |
struct stat st; |
|
|
1418 |
int last; |
| 1411 |
|
1419 |
|
| 1412 |
if (*path != '/') |
1420 |
if (*path != '/') |
| 1413 |
fatal("chroot path does not begin at root"); |
1421 |
fatal("chroot path does not begin at root"); |
|
Lines 1419-1425
safely_chroot(const char *path, uid_t ui
Link Here
|
| 1419 |
* root-owned directory with strict permissions. |
1427 |
* root-owned directory with strict permissions. |
| 1420 |
*/ |
1428 |
*/ |
| 1421 |
for (cp = path; cp != NULL;) { |
1429 |
for (cp = path; cp != NULL;) { |
| 1422 |
if ((cp = strchr(cp, '/')) == NULL) |
1430 |
if (((last = ((cp = strchr(cp, '/')) == NULL)))) |
| 1423 |
strlcpy(component, path, sizeof(component)); |
1431 |
strlcpy(component, path, sizeof(component)); |
| 1424 |
else { |
1432 |
else { |
| 1425 |
cp++; |
1433 |
cp++; |
|
Lines 1432-1446
safely_chroot(const char *path, uid_t ui
Link Here
|
| 1432 |
if (stat(component, &st) != 0) |
1440 |
if (stat(component, &st) != 0) |
| 1433 |
fatal("%s: stat(\"%s\"): %s", __func__, |
1441 |
fatal("%s: stat(\"%s\"): %s", __func__, |
| 1434 |
component, strerror(errno)); |
1442 |
component, strerror(errno)); |
| 1435 |
if (st.st_uid != 0 || (st.st_mode & 022) != 0) |
1443 |
if ((st.st_uid != 0 || (st.st_mode & 022) != 0) && !(last && st.st_uid == uid)) |
| 1436 |
fatal("bad ownership or modes for chroot " |
1444 |
fatal("bad ownership or modes for chroot " |
| 1437 |
"directory %s\"%s\"", |
1445 |
"directory %s\"%s\"", |
| 1438 |
cp == NULL ? "" : "component ", component); |
1446 |
cp == NULL ? "" : "component ", component); |
| 1439 |
if (!S_ISDIR(st.st_mode)) |
1447 |
if (!S_ISDIR(st.st_mode)) |
| 1440 |
fatal("chroot path %s\"%s\" is not a directory", |
1448 |
fatal("chroot path %s\"%s\" is not a directory", |
| 1441 |
cp == NULL ? "" : "component ", component); |
1449 |
cp == NULL ? "" : "component ", component); |
| 1442 |
|
|
|
| 1443 |
} |
1450 |
} |
|
|
1451 |
setenv ("TZ", "/etc/localtime", 0); |
| 1452 |
tzset (); |
| 1453 |
|
| 1454 |
if (st.st_uid != uid) |
| 1455 |
++chroot_no_tree; |
| 1444 |
|
1456 |
|
| 1445 |
if (chdir(path) == -1) |
1457 |
if (chdir(path) == -1) |
| 1446 |
fatal("Unable to chdir to chroot path \"%s\": " |
1458 |
fatal("Unable to chdir to chroot path \"%s\": " |
|
Lines 1450-1455
safely_chroot(const char *path, uid_t ui
Link Here
|
| 1450 |
if (chdir("/") == -1) |
1462 |
if (chdir("/") == -1) |
| 1451 |
fatal("%s: chdir(/) after chroot: %s", |
1463 |
fatal("%s: chdir(/) after chroot: %s", |
| 1452 |
__func__, strerror(errno)); |
1464 |
__func__, strerror(errno)); |
|
|
1465 |
|
| 1466 |
if (access ("/etc/localtime", R_OK) < 0) |
| 1467 |
++chroot_no_tree; |
| 1468 |
|
| 1453 |
verbose("Changed root directory to \"%s\"", path); |
1469 |
verbose("Changed root directory to \"%s\"", path); |
| 1454 |
} |
1470 |
} |
| 1455 |
|
1471 |
|