diff options
author | Lennart Poettering <lennart@poettering.net> | 2004-09-23 15:47:11 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2004-09-23 15:47:11 +0000 |
commit | 03ee5e2b445becf823dc4dd3db1599849e8c6c06 (patch) | |
tree | 4ae13b6771d823442d4043f6355503906fa14207 /polyp | |
parent | 370ff1d7cd2468c0d776bd43aa81d2d3c3a63e4a (diff) |
add support for capabilities
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@233 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp')
-rw-r--r-- | polyp/Makefile.am | 7 | ||||
-rw-r--r-- | polyp/caps.c | 106 | ||||
-rw-r--r-- | polyp/caps.h | 29 | ||||
-rw-r--r-- | polyp/main.c | 13 | ||||
-rw-r--r-- | polyp/polyplib-def.h | 3 | ||||
-rw-r--r-- | polyp/tagstruct.h | 2 | ||||
-rw-r--r-- | polyp/util.c | 5 | ||||
-rw-r--r-- | polyp/util.h | 1 |
8 files changed, 154 insertions, 12 deletions
diff --git a/polyp/Makefile.am b/polyp/Makefile.am index af324dd3..e52d9ab8 100644 --- a/polyp/Makefile.am +++ b/polyp/Makefile.am @@ -22,7 +22,7 @@ polypconfdir=$(sysconfdir)/polypaudio modlibdir=$(libdir)/polypaudio-@PA_MAJORMINOR@ -AM_CFLAGS=-D_GNU_SOURCE -I$(top_srcdir) $(PTHREAD_CFLAGS) +AM_CFLAGS=-D_GNU_SOURCE -I$(top_srcdir) $(PTHREAD_CFLAGS) AM_CFLAGS+=-DDLSEARCHPATH=\"$(modlibdir)\" AM_CFLAGS+=-DDEFAULT_SCRIPT_FILE=\"$(polypconfdir)/default.pa\" AM_CFLAGS+=-DDEFAULT_CONFIG_FILE=\"$(polypconfdir)/daemon.conf\" @@ -161,11 +161,12 @@ polypaudio_SOURCES = idxset.c idxset.h \ modinfo.c modinfo.h \ daemon-conf.c daemon-conf.h \ dumpmodules.c dumpmodules.h \ - conf-parser.h conf-parser.c + conf-parser.h conf-parser.c \ + caps.h caps.c polypaudio_CFLAGS = $(AM_CFLAGS) $(LIBSAMPLERATE_CFLAGS) $(LIBSNDFILE_CFLAGS) polypaudio_INCLUDES = $(INCLTDL) -polypaudio_LDADD = $(AM_LDADD) $(LIBLTDL) $(LIBSAMPLERATE_LIBS) $(LIBSNDFILE_LIBS) $(LEXLIB) +polypaudio_LDADD = $(AM_LDADD) $(LIBLTDL) $(LIBSAMPLERATE_LIBS) $(LIBSNDFILE_LIBS) $(CAP_LIBS) polypaudio_LDFLAGS=-export-dynamic libprotocol_simple_la_SOURCES = protocol-simple.c protocol-simple.h diff --git a/polyp/caps.c b/polyp/caps.c new file mode 100644 index 00000000..db00c604 --- /dev/null +++ b/polyp/caps.c @@ -0,0 +1,106 @@ +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + polypaudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <assert.h> +#include <unistd.h> +#include <errno.h> +#include <string.h> + +#ifdef HAVE_SYS_CAPABILITY_H +#include <sys/capability.h> +#endif + +#include "log.h" +#include "caps.h" + +void pa_drop_root(void) { + if (getuid() != 0 && geteuid() == 0) { + pa_log(__FILE__": Started SUID root, dropping root rights.\n"); + setuid(getuid()); + seteuid(getuid()); + } +} + +#ifdef HAVE_SYS_CAPABILITY_H +int pa_limit_caps(void) { + int r = -1; + cap_t caps; + cap_value_t nice_cap = CAP_SYS_NICE; + + caps = cap_init(); + assert(caps); + + cap_clear(caps); + cap_set_flag(caps, CAP_EFFECTIVE, 1, &nice_cap, CAP_SET); + cap_set_flag(caps, CAP_PERMITTED, 1, &nice_cap, CAP_SET); + + if (cap_set_proc(caps) < 0) + goto fail; + + pa_log(__FILE__": Started SUID root, capabilities limited.\n"); + + r = 0; + +fail: + cap_free (caps); + + return r; +} + +int pa_drop_caps(void) { + cap_t caps; + int r = -1; + + caps = cap_init(); + assert(caps); + + cap_clear(caps); + + if (cap_set_proc(caps) < 0) + goto fail; + + pa_drop_root(); + + r = 0; + +fail: + cap_free (caps); + + return r; +} + +#else + +int pa_limit_caps(void) { + return 0; +} + +int pa_drop_caps(void) { + pa_drop_root(); + return 0; +} + +#endif + diff --git a/polyp/caps.h b/polyp/caps.h new file mode 100644 index 00000000..473462fb --- /dev/null +++ b/polyp/caps.h @@ -0,0 +1,29 @@ +#ifndef foocapshfoo +#define foocapshfoo + +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + polypaudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +void pa_drop_root(void); +int pa_limit_caps(void); +int pa_drop_caps(void); + +#endif diff --git a/polyp/main.c b/polyp/main.c index dfbd1e4b..2a45ad37 100644 --- a/polyp/main.c +++ b/polyp/main.c @@ -47,17 +47,10 @@ #include "log.h" #include "daemon-conf.h" #include "dumpmodules.h" +#include "caps.h" static struct pa_mainloop *mainloop; -static void drop_root(void) { - if (getuid() != 0 && geteuid() == 0) { - pa_log(__FILE__": Started SUID root, dropping root rights.\n"); - setuid(getuid()); - seteuid(getuid()); - } -} - static void signal_callback(struct pa_mainloop_api*m, struct pa_signal_event *e, int sig, void *userdata) { pa_log(__FILE__": Got signal %s.\n", pa_strsignal(sig)); @@ -95,6 +88,8 @@ int main(int argc, char *argv[]) { int r, retval = 1, d = 0; int daemon_pipe[2] = { -1, -1 }; + pa_limit_caps(); + r = lt_dlinit(); assert(r == 0); @@ -118,7 +113,7 @@ int main(int argc, char *argv[]) { if (conf->high_priority && conf->cmd == PA_CMD_DAEMON) pa_raise_priority(); - drop_root(); + pa_drop_caps(); if (conf->dl_search_path) lt_dlsetsearchpath(conf->dl_search_path); diff --git a/polyp/polyplib-def.h b/polyp/polyplib-def.h index 591d237d..bab23e47 100644 --- a/polyp/polyplib-def.h +++ b/polyp/polyplib-def.h @@ -23,6 +23,9 @@ ***/ #include <inttypes.h> +#include <sys/time.h> +#include <time.h> + #include "cdecl.h" #include "sample.h" diff --git a/polyp/tagstruct.h b/polyp/tagstruct.h index 02df74e4..e50551c4 100644 --- a/polyp/tagstruct.h +++ b/polyp/tagstruct.h @@ -24,6 +24,8 @@ #include <inttypes.h> #include <sys/types.h> +#include <sys/time.h> +#include <time.h> #include "sample.h" diff --git a/polyp/util.c b/polyp/util.c index 9b74ee75..cc132dbb 100644 --- a/polyp/util.c +++ b/polyp/util.c @@ -40,6 +40,11 @@ #include <sched.h> #include <sys/resource.h> #include <limits.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> + #include <samplerate.h> diff --git a/polyp/util.h b/polyp/util.h index c842a1c3..4a387cef 100644 --- a/polyp/util.h +++ b/polyp/util.h @@ -66,4 +66,5 @@ const char *pa_strsignal(int sig); int pa_parse_resample_method(const char *string); + #endif |