|
Lines 96-101
Link Here
|
| 96 |
#include "monitor_wrap.h" |
96 |
#include "monitor_wrap.h" |
| 97 |
#include "sftp.h" |
97 |
#include "sftp.h" |
| 98 |
|
98 |
|
|
|
99 |
#ifdef HAVE_LIBCAP_NG |
| 100 |
#include <cap-ng.h> |
| 101 |
#endif |
| 102 |
|
| 99 |
#if defined(KRB5) && defined(USE_AFS) |
103 |
#if defined(KRB5) && defined(USE_AFS) |
| 100 |
#include <kafs.h> |
104 |
#include <kafs.h> |
| 101 |
#endif |
105 |
#endif |
|
Lines 1520-1525
void
Link Here
|
| 1520 |
do_setusercontext(struct passwd *pw) |
1524 |
do_setusercontext(struct passwd *pw) |
| 1521 |
{ |
1525 |
{ |
| 1522 |
char *chroot_path, *tmp; |
1526 |
char *chroot_path, *tmp; |
|
|
1527 |
int dropped_suid = -1; |
| 1523 |
|
1528 |
|
| 1524 |
platform_setusercontext(pw); |
1529 |
platform_setusercontext(pw); |
| 1525 |
|
1530 |
|
|
Lines 1549-1559
do_setusercontext(struct passwd *pw)
Link Here
|
| 1549 |
|
1554 |
|
| 1550 |
if (!in_chroot && options.chroot_directory != NULL && |
1555 |
if (!in_chroot && options.chroot_directory != NULL && |
| 1551 |
strcasecmp(options.chroot_directory, "none") != 0) { |
1556 |
strcasecmp(options.chroot_directory, "none") != 0) { |
| 1552 |
tmp = tilde_expand_filename(options.chroot_directory, |
1557 |
tmp = tilde_expand_filename(options.chroot_directory, |
| 1553 |
pw->pw_uid); |
1558 |
pw->pw_uid); |
| 1554 |
chroot_path = percent_expand(tmp, "h", pw->pw_dir, |
1559 |
chroot_path = percent_expand(tmp, "h", pw->pw_dir, |
| 1555 |
"u", pw->pw_name, (char *)NULL); |
1560 |
"u", pw->pw_name, (char *)NULL); |
|
|
1561 |
#ifdef HAVE_LIBCAP_NG |
| 1562 |
/* drop suid soon, retain SYS_CHROOT capability */ |
| 1563 |
capng_clear(CAPNG_SELECT_BOTH); |
| 1564 |
capng_update(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED, CAP_SYS_CHROOT); |
| 1565 |
if (dropped_suid = capng_change_id(pw->pw_uid, pw->pw_gid, CAPNG_DROP_SUPP_GRP | CAPNG_CLEAR_BOUNDING)) |
| 1566 |
logit("capng_change_id() = %d (failure): Try to drop UID later", dropped_suid); |
| 1567 |
#endif |
| 1556 |
safely_chroot(chroot_path, pw->pw_uid); |
1568 |
safely_chroot(chroot_path, pw->pw_uid); |
|
|
1569 |
#ifdef HAVE_LIBCAP_NG |
| 1570 |
/* Drop chroot capability. Already used */ |
| 1571 |
if (dropped_suid == 0) { |
| 1572 |
capng_clear(CAPNG_SELECT_BOTH); |
| 1573 |
capng_apply(CAPNG_SELECT_BOTH); |
| 1574 |
} |
| 1575 |
#endif |
| 1557 |
free(tmp); |
1576 |
free(tmp); |
| 1558 |
free(chroot_path); |
1577 |
free(chroot_path); |
| 1559 |
/* Make sure we don't attempt to chroot again */ |
1578 |
/* Make sure we don't attempt to chroot again */ |
|
Lines 1585-1592
do_setusercontext(struct passwd *pw)
Link Here
|
| 1585 |
if (!in_chroot && set_id(pw->pw_name) != 0) |
1604 |
if (!in_chroot && set_id(pw->pw_name) != 0) |
| 1586 |
fatal("set_id(%s) Failed", pw->pw_name); |
1605 |
fatal("set_id(%s) Failed", pw->pw_name); |
| 1587 |
# endif /* USE_LIBIAF */ |
1606 |
# endif /* USE_LIBIAF */ |
| 1588 |
/* Permanently switch to the desired uid. */ |
1607 |
/* Permanently switch to the desired uid if not yet done. */ |
| 1589 |
permanently_set_uid(pw); |
1608 |
if (dropped_suid != 0) |
|
|
1609 |
permanently_set_uid(pw); |
| 1590 |
#endif |
1610 |
#endif |
| 1591 |
} else if (options.chroot_directory != NULL && |
1611 |
} else if (options.chroot_directory != NULL && |
| 1592 |
strcasecmp(options.chroot_directory, "none") != 0) { |
1612 |
strcasecmp(options.chroot_directory, "none") != 0) { |
| 1593 |
- |
|
|