Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit a9ea591

Browse files
committed
Improve pid directory handling
fix security issue with mode 777 for pid directory take default user for pid directory from config file make pid handling configurable via /etc/default/newrelic_plugin_agent
1 parent cc44edb commit a9ea591

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

etc/init.d/newrelic_plugin_agent.deb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ DAEMON=/usr/local/bin/newrelic_plugin_agent
1818
DAEMON_OPTS="-c $CONFIG"
1919
DESC="New Relic Plugin Agent"
2020
TIMEOUT=5
21+
PIDDIR_MODE=755
22+
PIDDIR_OWNER=
23+
PIDDIR_OWNER_FALLBACK="root"
2124

2225
# Include newrelic plugin agent defaults if available
2326
if [ -f /etc/default/$NAME ] ; then
@@ -45,23 +48,31 @@ check_config() {
4548

4649
check_pid() {
4750
PIDDIR=$(dirname $PIDFILE)
51+
if [ ! id -u $PIDDIR_OWNER > /dev/null 2>&1 ]; then
52+
PIDDIR_OWNER=$PIDDIR_OWNER_FALLBACK
53+
fi
4854
if [ ! -d $PIDDIR ]; then
49-
install -m 777 -o newrelic -g newrelic -d $PIDDIR
55+
install -m $PIDDIR_MODE -o $PIDDIR_OWNER -g $PIDDIR_OWNER -d $PIDDIR
5056
log_action_msg "PID directory was not found and created" || true
5157
fi;
5258
}
5359

54-
PIDFILE=$(sed -n -e 's/^[ ]*pidfile[ ]*:[ ]*//p' -e 's/[ ]*$//' $CONFIG)
60+
if [ -e $CONFIG ]; then
61+
PIDFILE=$(sed -n -e 's/^[ ]*pidfile[ ]*:[ ]*//p' -e 's/[ ]*$//' $CONFIG)
62+
if [ -z "${PIDDIR_OWNER}" ]; then
63+
PIDDIR_OWNER=$(sed -n -e 's/^[ ]*user[ ]*:[ ]*//p' -e 's/[ ]*$//' $CONFIG)
64+
fi
65+
fi
5566

5667
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin/:usr/local/sbin:/usr/local/bin"
5768

5869
case "$1" in
5970
start)
60-
log_daemon_msg "Starting $DESC" "$NAME" || true
6171
check_daemon
6272
check_config
6373
check_pid
6474

75+
log_daemon_msg "Starting $DESC" "$NAME" || true
6576
if [ -s $PIDFILE ] && kill -0 $(cat $PIDFILE) > /dev/null 2>&1; then
6677
log_action_msg "apparently already running" || true
6778
log_end_msg 0 || true

0 commit comments

Comments
 (0)