]>
code.delx.au - pulseaudio/blob - src/daemon/caps.c
4 This file is part of PulseAudio.
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 #ifdef HAVE_SYS_CAPABILITY_H
32 #include <sys/capability.h>
35 #include <pulsecore/core-error.h>
37 #include <pulsecore/log.h>
41 /* Glibc <= 2.2 has broken unistd.h */
42 #if defined(linux) && (__GLIBC__ <= 2 && __GLIBC_MINOR__ <= 2)
43 int setresgid(gid_t r
, gid_t e
, gid_t s
);
44 int setresuid(uid_t r
, uid_t e
, uid_t s
);
49 /* Drop root rights when called SUID root */
50 void pa_drop_root(void) {
53 if (uid
== 0 || geteuid() != 0)
56 pa_log_info(__FILE__
": dropping root rights.");
58 #if defined(HAVE_SETRESUID)
59 setresuid(uid
, uid
, uid
);
60 #elif defined(HAVE_SETREUID)
70 void pa_drop_root(void) {
75 #ifdef HAVE_SYS_CAPABILITY_H
77 /* Limit capabilities set to CAPSYS_NICE */
78 int pa_limit_caps(void) {
81 cap_value_t nice_cap
= CAP_SYS_NICE
;
88 cap_set_flag(caps
, CAP_EFFECTIVE
, 1, &nice_cap
, CAP_SET
);
89 cap_set_flag(caps
, CAP_PERMITTED
, 1, &nice_cap
, CAP_SET
);
91 if (cap_set_proc(caps
) < 0)
94 pa_log_info(__FILE__
": dropped capabilities successfully.");
104 /* Drop all capabilities, effectively becoming a normal user */
105 int pa_drop_caps(void) {
114 if (cap_set_proc(caps
) < 0) {
115 pa_log(__FILE__
": failed to drop capabilities: %s", pa_cstrerror(errno
));
129 /* NOOPs in case capabilities are not available. */
130 int pa_limit_caps(void) {
134 int pa_drop_caps(void) {