]> code.delx.au - pulseaudio/commitdiff
add support for capabilities
authorLennart Poettering <lennart@poettering.net>
Thu, 23 Sep 2004 15:47:11 +0000 (15:47 +0000)
committerLennart Poettering <lennart@poettering.net>
Thu, 23 Sep 2004 15:47:11 +0000 (15:47 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@233 fefdeb5f-60dc-0310-8127-8f9354f1896f

configure.ac
doc/modules.html.in
polyp/Makefile.am
polyp/caps.c [new file with mode: 0644]
polyp/caps.h [new file with mode: 0644]
polyp/main.c
polyp/polyplib-def.h
polyp/tagstruct.h
polyp/util.c
polyp/util.h

index e74cc64bb7976b32b35659968da62da913691779..5e63d1e04806c3459faf5069ab77c0fb3172a417 100644 (file)
@@ -78,6 +78,11 @@ AC_HEADER_SYS_WAIT
 
 AC_C_BIGENDIAN
 
+AC_CHECK_LIB(cap, cap_init, [CAP_LIBS='-lcap'], [CAP_LIBS=''])
+AC_SUBST(CAP_LIBS)
+
+AC_CHECK_HEADERS(sys/capability.h)
+
 PKG_CHECK_MODULES(LIBSAMPLERATE, [ samplerate >= 0.1.0 ])
 AC_SUBST(LIBSAMPLERATE_CFLAGS)
 AC_SUBST(LIBSAMPLERATE_LIBS)
index 6967b2a1684dffa38601e5d779637b554191ffff..00fe338877fef9a1bb1a11a00f7c383623437a9c 100644 (file)
@@ -106,8 +106,8 @@ resampling required for this may be very CPU intensive.</p>
   <tr><td><tt>sink_name=</tt></td><td>The name for the combined sink. (defaults to  <tt>combined</tt>)</td></tr>
   <tr><td><tt>master=</tt></td><td>The name of the first sink to link into the combined think. The sample rate/type is taken from this sink.</td></tr>
   <tr><td><tt>slaves=</tt></td><td>Name of additional sinks to link into the combined think, seperated by commas.</td></tr>
-  <tr><td><tt>adjust_time=</td><td>Time in seconds when to readjust the sample rate of all sinks. (defaults to 20)</td></tr>
-  <tr><td><tt>resample_method=</td><td>Resampling algorithm to
+  <tr><td><tt>adjust_time=</tt></td><td>Time in seconds when to readjust the sample rate of all sinks. (defaults to 20)</td></tr>
+  <tr><td><tt>resample_method=</tt></td><td>Resampling algorithm to
 use. See <tt>libsamplerate</tt>'s documentation for more
 information. Use one of <tt>sinc-best-quality</tt>,
 <tt>sinc-medium-quality</tt>, <tt>sinc-fastest</tt>,
index af324dd3eddb9c393e9b1b955c75c1ddcd3c61ba..e52d9ab8582bd2bb6acab74338c0094d55b9a1f4 100644 (file)
@@ -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 (file)
index 0000000..db00c60
--- /dev/null
@@ -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 (file)
index 0000000..473462f
--- /dev/null
@@ -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
index dfbd1e4b150bf462bcdaf9c8924f912033e20b2a..2a45ad37c31d70d0ce0262188d4332c9a5ae6b02 100644 (file)
 #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);
index 591d237d5fb0c20ea2211cc9667acaf0b292303a..bab23e473f1571454c2944c4ce0fbb03e4a92413 100644 (file)
@@ -23,6 +23,9 @@
 ***/
 
 #include <inttypes.h>
+#include <sys/time.h>
+#include <time.h>
+
 #include "cdecl.h"
 #include "sample.h"
 
index 02df74e4d38b89effce1182892bc2609b45ad731..e50551c41490a0585acd82a8c356a5a9daa9bccf 100644 (file)
@@ -24,6 +24,8 @@
 
 #include <inttypes.h>
 #include <sys/types.h>
+#include <sys/time.h>
+#include <time.h>
 
 #include "sample.h"
 
index 9b74ee759517a8f48056c0c779f7fdf79c72ffa7..cc132dbb1656b83541dc4315def85f5923473922 100644 (file)
 #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>
 
index c842a1c38fa2be22c701e3a0734bf1129cd6a902..4a387cef0bc1ac96f8a685358ee3de4da3fc5981 100644 (file)
@@ -66,4 +66,5 @@ const char *pa_strsignal(int sig);
 
 int pa_parse_resample_method(const char *string);
 
+
 #endif