[asterisk-commits] tilghman: branch 1.4 r172438 - in /branches/1.4: ./ apps/ autoconf/ build_too...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jan 29 16:54:30 CST 2009
Author: tilghman
Date: Thu Jan 29 16:54:29 2009
New Revision: 172438
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=172438
Log:
Lose the CAP_NET_ADMIN at every fork, instead of at startup. Otherwise, if
Asterisk runs as a non-root user and the administrator does a 'restart now',
Asterisk loses the ability to set QOS on packets.
(closes issue #14004)
Reported by: nemo
Patches:
20090105__bug14004.diff.txt uploaded by Corydon76 (license 14)
Tested by: Corydon76
Modified:
branches/1.4/apps/app_dahdiras.c
branches/1.4/apps/app_externalivr.c
branches/1.4/apps/app_festival.c
branches/1.4/apps/app_ices.c
branches/1.4/apps/app_mp3.c
branches/1.4/apps/app_nbscat.c
branches/1.4/autoconf/ast_func_fork.m4
branches/1.4/build_tools/menuselect-deps.in
branches/1.4/configure
branches/1.4/main/asterisk.c
branches/1.4/res/res_agi.c
branches/1.4/res/res_musiconhold.c
Modified: branches/1.4/apps/app_dahdiras.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/apps/app_dahdiras.c?view=diff&rev=172438&r1=172437&r2=172438
==============================================================================
--- branches/1.4/apps/app_dahdiras.c (original)
+++ branches/1.4/apps/app_dahdiras.c Thu Jan 29 16:54:29 2009
@@ -27,6 +27,7 @@
/*** MODULEINFO
<depend>dahdi</depend>
+ <depend>working_fork</depend>
***/
#include "asterisk.h"
@@ -48,6 +49,9 @@
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
+#ifdef HAVE_CAP
+#include <sys/capability.h>
+#endif /* HAVE_CAP */
#include "asterisk/lock.h"
#include "asterisk/file.h"
@@ -92,6 +96,9 @@
int argc = 0;
char *stringp=NULL;
sigset_t fullset, oldset;
+#ifdef HAVE_CAP
+ cap_t cap;
+#endif
sigfillset(&fullset);
pthread_sigmask(SIG_BLOCK, &fullset, &oldset);
@@ -102,6 +109,16 @@
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
return pid;
}
+
+#ifdef HAVE_CAP
+ cap = cap_from_text("cap_net_admin-eip");
+
+ if (cap_set_proc(cap)) {
+ /* Careful with order! Logging cannot happen after we close FDs */
+ ast_log(LOG_WARNING, "Unable to remove capabilities.\n");
+ }
+ cap_free(cap);
+#endif
/* Restore original signal handlers */
for (x=0;x<NSIG;x++)
Modified: branches/1.4/apps/app_externalivr.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/apps/app_externalivr.c?view=diff&rev=172438&r1=172437&r2=172438
==============================================================================
--- branches/1.4/apps/app_externalivr.c (original)
+++ branches/1.4/apps/app_externalivr.c Thu Jan 29 16:54:29 2009
@@ -30,6 +30,10 @@
*
* \ingroup applications
*/
+
+/*** MODULEINFO
+ <depend>working_fork</depend>
+ ***/
#include "asterisk.h"
@@ -41,6 +45,9 @@
#include <unistd.h>
#include <errno.h>
#include <signal.h>
+#ifdef HAVE_CAP
+#include <sys/capability.h>
+#endif /* HAVE_CAP */
#include "asterisk/lock.h"
#include "asterisk/file.h"
@@ -317,6 +324,15 @@
if (!pid) {
/* child process */
int i;
+#ifdef HAVE_CAP
+ cap_t cap = cap_from_text("cap_net_admin-eip");
+
+ if (cap_set_proc(cap)) {
+ /* Careful with order! Logging cannot happen after we close FDs */
+ ast_log(LOG_WARNING, "Unable to remove capabilities.\n");
+ }
+ cap_free(cap);
+#endif
signal(SIGPIPE, SIG_DFL);
pthread_sigmask(SIG_UNBLOCK, &fullset, NULL);
Modified: branches/1.4/apps/app_festival.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/apps/app_festival.c?view=diff&rev=172438&r1=172437&r2=172438
==============================================================================
--- branches/1.4/apps/app_festival.c (original)
+++ branches/1.4/apps/app_festival.c Thu Jan 29 16:54:29 2009
@@ -25,6 +25,10 @@
* \ingroup applications
*/
+/*** MODULEINFO
+ <depend>working_fork</depend>
+ ***/
+
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
@@ -46,6 +50,9 @@
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
+#ifdef HAVE_CAP
+#include <sys/capability.h>
+#endif /* HAVE_CAP */
#include "asterisk/file.h"
#include "asterisk/logger.h"
@@ -132,21 +139,33 @@
char c;
#endif
sigset_t fullset, oldset;
+#ifdef HAVE_CAP
+ cap_t cap;
+#endif
sigfillset(&fullset);
pthread_sigmask(SIG_BLOCK, &fullset, &oldset);
- res = fork();
- if (res < 0)
- ast_log(LOG_WARNING, "Fork failed\n");
- if (res) {
+ res = fork();
+ if (res < 0)
+ ast_log(LOG_WARNING, "Fork failed\n");
+ if (res) {
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
- return res;
- }
- for (x=0;x<256;x++) {
- if (x != fd)
- close(x);
- }
+ return res;
+ }
+#ifdef HAVE_CAP
+ cap = cap_from_text("cap_net_admin-eip");
+
+ if (cap_set_proc(cap)) {
+ /* Careful with order! Logging cannot happen after we close FDs */
+ ast_log(LOG_WARNING, "Unable to remove capabilities.\n");
+ }
+ cap_free(cap);
+#endif
+ for (x=0;x<256;x++) {
+ if (x != fd)
+ close(x);
+ }
if (ast_opt_high_priority)
ast_set_priority(0);
signal(SIGPIPE, SIG_DFL);
Modified: branches/1.4/apps/app_ices.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/apps/app_ices.c?view=diff&rev=172438&r1=172437&r2=172438
==============================================================================
--- branches/1.4/apps/app_ices.c (original)
+++ branches/1.4/apps/app_ices.c Thu Jan 29 16:54:29 2009
@@ -25,6 +25,10 @@
* \ingroup applications
*/
+/*** MODULEINFO
+ <depend>working_fork</depend>
+ ***/
+
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
@@ -37,6 +41,9 @@
#include <fcntl.h>
#include <sys/time.h>
#include <errno.h>
+#ifdef HAVE_CAP
+#include <sys/capability.h>
+#endif /* HAVE_CAP */
#include "asterisk/lock.h"
#include "asterisk/file.h"
@@ -65,6 +72,9 @@
int res;
int x;
sigset_t fullset, oldset;
+#ifdef HAVE_CAP
+ cap_t cap;
+#endif
sigfillset(&fullset);
pthread_sigmask(SIG_BLOCK, &fullset, &oldset);
@@ -80,6 +90,16 @@
/* Stop ignoring PIPE */
signal(SIGPIPE, SIG_DFL);
pthread_sigmask(SIG_UNBLOCK, &fullset, NULL);
+
+#ifdef HAVE_CAP
+ cap = cap_from_text("cap_net_admin-eip");
+
+ if (cap_set_proc(cap)) {
+ /* Careful with order! Logging cannot happen after we close FDs */
+ ast_log(LOG_WARNING, "Unable to remove capabilities.\n");
+ }
+ cap_free(cap);
+#endif
if (ast_opt_high_priority)
ast_set_priority(0);
Modified: branches/1.4/apps/app_mp3.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/apps/app_mp3.c?view=diff&rev=172438&r1=172437&r2=172438
==============================================================================
--- branches/1.4/apps/app_mp3.c (original)
+++ branches/1.4/apps/app_mp3.c Thu Jan 29 16:54:29 2009
@@ -25,6 +25,10 @@
* \ingroup applications
*/
+/*** MODULEINFO
+ <depend>working_fork</depend>
+ ***/
+
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
@@ -36,6 +40,9 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/time.h>
+#ifdef HAVE_CAP
+#include <sys/capability.h>
+#endif /* HAVE_CAP */
#include "asterisk/lock.h"
#include "asterisk/file.h"
@@ -65,6 +72,9 @@
int res;
int x;
sigset_t fullset, oldset;
+#ifdef HAVE_CAP
+ cap_t cap;
+#endif
sigfillset(&fullset);
pthread_sigmask(SIG_BLOCK, &fullset, &oldset);
@@ -76,6 +86,15 @@
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
return res;
}
+#ifdef HAVE_CAP
+ cap = cap_from_text("cap_net_admin-eip");
+
+ if (cap_set_proc(cap)) {
+ /* Careful with order! Logging cannot happen after we close FDs */
+ ast_log(LOG_WARNING, "Unable to remove capabilities.\n");
+ }
+ cap_free(cap);
+#endif
if (ast_opt_high_priority)
ast_set_priority(0);
signal(SIGPIPE, SIG_DFL);
@@ -83,8 +102,7 @@
dup2(fd, STDOUT_FILENO);
for (x=STDERR_FILENO + 1;x<256;x++) {
- if (x != STDOUT_FILENO)
- close(x);
+ close(x);
}
/* Execute mpg123, but buffer if it's a net connection */
if (!strncasecmp(filename, "http://", 7)) {
Modified: branches/1.4/apps/app_nbscat.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/apps/app_nbscat.c?view=diff&rev=172438&r1=172437&r2=172438
==============================================================================
--- branches/1.4/apps/app_nbscat.c (original)
+++ branches/1.4/apps/app_nbscat.c Thu Jan 29 16:54:29 2009
@@ -25,6 +25,10 @@
* \ingroup applications
*/
+/*** MODULEINFO
+ <depend>working_fork</depend>
+ ***/
+
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
@@ -37,6 +41,9 @@
#include <fcntl.h>
#include <sys/time.h>
#include <sys/socket.h>
+#ifdef HAVE_CAP
+#include <sys/capability.h>
+#endif /* HAVE_CAP */
#include "asterisk/lock.h"
#include "asterisk/file.h"
@@ -69,6 +76,9 @@
int res;
int x;
sigset_t fullset, oldset;
+#ifdef HAVE_CAP
+ cap_t cap;
+#endif
sigfillset(&fullset);
pthread_sigmask(SIG_BLOCK, &fullset, &oldset);
@@ -83,6 +93,15 @@
signal(SIGPIPE, SIG_DFL);
pthread_sigmask(SIG_UNBLOCK, &fullset, NULL);
+#ifdef HAVE_CAP
+ cap = cap_from_text("cap_net_admin-eip");
+
+ if (cap_set_proc(cap)) {
+ /* Careful with order! Logging cannot happen after we close FDs */
+ ast_log(LOG_WARNING, "Unable to remove capabilities.\n");
+ }
+ cap_free(cap);
+#endif
if (ast_opt_high_priority)
ast_set_priority(0);
Modified: branches/1.4/autoconf/ast_func_fork.m4
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/autoconf/ast_func_fork.m4?view=diff&rev=172438&r1=172437&r2=172438
==============================================================================
--- branches/1.4/autoconf/ast_func_fork.m4 (original)
+++ branches/1.4/autoconf/ast_func_fork.m4 Thu Jan 29 16:54:29 2009
@@ -39,6 +39,8 @@
fi
if test "x$ac_cv_func_fork_works" = xyes; then
AC_DEFINE(HAVE_WORKING_FORK, 1, [Define to 1 if `fork' works.])
+ PBX_WORKING_FORK=1
+ AC_SUBST(PBX_WORKING_FORK)
fi
])# AST_FUNC_FORK
Modified: branches/1.4/build_tools/menuselect-deps.in
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/build_tools/menuselect-deps.in?view=diff&rev=172438&r1=172437&r2=172438
==============================================================================
--- branches/1.4/build_tools/menuselect-deps.in (original)
+++ branches/1.4/build_tools/menuselect-deps.in Thu Jan 29 16:54:29 2009
@@ -39,3 +39,4 @@
MISDN=@PBX_MISDN@
SUPPSERV=@PBX_SUPPSERV@
GNU_LD=@GNU_LD@
+WORKING_FORK=@PBX_WORKING_FORK@
Modified: branches/1.4/main/asterisk.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/main/asterisk.c?view=diff&rev=172438&r1=172437&r2=172438
==============================================================================
--- branches/1.4/main/asterisk.c (original)
+++ branches/1.4/main/asterisk.c Thu Jan 29 16:54:29 2009
@@ -818,6 +818,15 @@
#endif
if (pid == 0) {
+#ifdef HAVE_CAP
+ cap_t cap = cap_from_text("cap_net_admin-eip");
+
+ if (cap_set_proc(cap)) {
+ /* Careful with order! Logging cannot happen after we close FDs */
+ ast_log(LOG_WARNING, "Unable to remove capabilities.\n");
+ }
+ cap_free(cap);
+#endif
#ifdef HAVE_WORKING_FORK
if (ast_opt_high_priority)
ast_set_priority(0);
@@ -842,7 +851,7 @@
}
ast_unreplace_sigchld();
-#else
+#else /* !defined(HAVE_WORKING_FORK) && !defined(HAVE_WORKING_VFORK) */
res = -1;
#endif
@@ -2914,7 +2923,7 @@
if (has_cap) {
cap_t cap;
- cap = cap_from_text("cap_net_admin=ep");
+ cap = cap_from_text("cap_net_admin=eip");
if (cap_set_proc(cap))
ast_log(LOG_WARNING, "Unable to install capabilities.\n");
Modified: branches/1.4/res/res_agi.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/res/res_agi.c?view=diff&rev=172438&r1=172437&r2=172438
==============================================================================
--- branches/1.4/res/res_agi.c (original)
+++ branches/1.4/res/res_agi.c Thu Jan 29 16:54:29 2009
@@ -23,6 +23,10 @@
* \author Mark Spencer <markster at digium.com>
*/
+/*** MODULEINFO
+ <depend>working_fork</depend>
+ ***/
+
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
@@ -44,6 +48,9 @@
#include <fcntl.h>
#include <errno.h>
#include <sys/wait.h>
+#ifdef HAVE_CAP
+#include <sys/capability.h>
+#endif /* HAVE_CAP */
#include "asterisk/file.h"
#include "asterisk/logger.h"
@@ -308,6 +315,16 @@
return AGI_RESULT_FAILURE;
}
if (!pid) {
+#ifdef HAVE_CAP
+ cap_t cap = cap_from_text("cap_net_admin-eip");
+
+ if (cap_set_proc(cap)) {
+ /* Careful with order! Logging cannot happen after we close FDs */
+ ast_log(LOG_WARNING, "Unable to remove capabilities.\n");
+ }
+ cap_free(cap);
+#endif
+
/* Pass paths to AGI via environmental variables */
setenv("AST_CONFIG_DIR", ast_config_AST_CONFIG_DIR, 1);
setenv("AST_CONFIG_FILE", ast_config_AST_CONFIG_FILE, 1);
Modified: branches/1.4/res/res_musiconhold.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/res/res_musiconhold.c?view=diff&rev=172438&r1=172437&r2=172438
==============================================================================
--- branches/1.4/res/res_musiconhold.c (original)
+++ branches/1.4/res/res_musiconhold.c Thu Jan 29 16:54:29 2009
@@ -28,6 +28,7 @@
/*** MODULEINFO
<conflict>win32</conflict>
<use>dahdi</use>
+ <depend>working_fork</depend>
***/
#include "asterisk.h"
@@ -51,6 +52,9 @@
#ifdef SOLARIS
#include <thread.h>
#endif
+#ifdef HAVE_CAP
+#include <sys/capability.h>
+#endif /* HAVE_CAP */
#include "asterisk/lock.h"
#include "asterisk/file.h"
@@ -450,7 +454,15 @@
return -1;
}
if (!class->pid) {
+ /* Child */
int x;
+#ifdef HAVE_CAP
+ cap_t cap;
+#endif
+ if (strcasecmp(class->dir, "nodir") && chdir(class->dir) < 0) {
+ ast_log(LOG_WARNING, "chdir() failed: %s\n", strerror(errno));
+ _exit(1);
+ }
if (ast_opt_high_priority)
ast_set_priority(0);
@@ -459,6 +471,14 @@
signal(SIGPIPE, SIG_DFL);
pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL);
+#ifdef HAVE_CAP
+ cap = cap_from_text("cap_net_admin-eip");
+
+ if (cap_set_proc(cap)) {
+ ast_log(LOG_WARNING, "Unable to remove capabilities.\n");
+ }
+ cap_free(cap);
+#endif
close(fds[0]);
/* Stdout goes to pipe */
dup2(fds[1], STDOUT_FILENO);
@@ -468,12 +488,8 @@
close(x);
}
}
- /* Child */
- if (strcasecmp(class->dir, "nodir") && chdir(class->dir) < 0) {
- ast_log(LOG_WARNING, "chdir() failed: %s\n", strerror(errno));
- _exit(1);
- }
setpgid(0, getpid());
+
if (ast_test_flag(class, MOH_CUSTOM)) {
execv(argv[0], argv);
} else {
More information about the asterisk-commits
mailing list