593
593
#if defined(HAVE_POSIX_CAPABILITIES)
595
/* This define hasn't made it into the glibc capabilities header yet. */
596
#ifndef SECURE_NO_SETUID_FIXUP
597
#define SECURE_NO_SETUID_FIXUP 2
600
595
/**************************************************************************
601
596
Try and abstract process capabilities (for systems that have them).
602
597
****************************************************************************/
630
#if defined(HAVE_PRCTL) && defined(PR_SET_SECUREBITS) && defined(SECURE_NO_SETUID_FIXUP)
631
/* New way of setting capabilities as "sticky". */
634
* Use PR_SET_SECUREBITS to prevent setresuid()
635
* atomically dropping effective capabilities on
636
* uid change. Only available in Linux kernels
640
* http://www.kernel.org/doc/man-pages/online/pages/man7/capabilities.7.html
643
* Specifically the CAP_KILL capability we need
644
* to allow Linux threads under different euids
645
* to send signals to each other.
648
if (prctl(PR_SET_SECUREBITS, 1 << SECURE_NO_SETUID_FIXUP)) {
649
DEBUG(0,("set_process_capability: "
650
"prctl PR_SET_SECUREBITS failed with error %s\n",
656
625
cap = cap_get_proc();
657
626
if (cap == NULL) {
658
627
DEBUG(0,("set_process_capability: cap_get_proc failed: %s\n",
699
* Ensure the capability is effective. We assume that as a root
700
* process it's always permitted.
703
if (cap_set_flag(cap, CAP_EFFECTIVE, num_cap_vals, cap_vals,
704
enable ? CAP_SET : CAP_CLEAR) == -1) {
705
DEBUG(0, ("set_process_capability: cap_set_flag effective "
662
cap_set_flag(cap, CAP_EFFECTIVE, num_cap_vals, cap_vals,
663
enable ? CAP_SET : CAP_CLEAR);
713
665
/* We never want to pass capabilities down to our children, so make
714
666
* sure they are not inherited.
716
if (cap_set_flag(cap, CAP_INHERITABLE, num_cap_vals,
717
cap_vals, CAP_CLEAR) == -1) {
718
DEBUG(0, ("set_process_capability: cap_set_flag inheritable "
668
cap_set_flag(cap, CAP_INHERITABLE, num_cap_vals, cap_vals, CAP_CLEAR);
726
670
if (cap_set_proc(cap) == -1) {
727
DEBUG(0, ("set_process_capability: cap_set_flag (%d) failed: %s\n",
671
DEBUG(0, ("set_process_capability: cap_set_proc failed: %s\n",
729
672
strerror(errno)));