Download Securing Debian Manual

Transcript
Chapter 9. Developer’s Best Practices for OS Security
166
--no-create-home \
--disabled-password \
$SERVER_USER 2>/dev/null || true
echo "..done"
fi
# 4. adjust passwd entry
usermod -c "$SERVER_NAME" \
-d $SERVER_HOME
\
-g $SERVER_GROUP \
$SERVER_USER
# 5. adjust file and directory permissions
if ! dpkg-statoverride --list $SERVER_HOME >/dev/null
then
chown -R $SERVER_USER:adm $SERVER_HOME
chmod u=rwx,g=rxs,o= $SERVER_HOME
fi
# 6. Add the user to the ADDGROUP group
if test -n $ADDGROUP
then
if ! groups $SERVER_USER | cut -d: -f2 | \
grep -qw $ADDGROUP; then
adduser $SERVER_USER $ADDGROUP
fi
fi
;;
configure)
[...]
You have to make sure that the init.d script file:
• Starts the daemon dropping privileges: if the software does not do the setuid(2) or
seteuid(2) call itself, you can use the --chuid call of start-stop-daemon.
• Stops the daemon only if the user id matches, you can use the start-stop-daemon
--user option for this.
• Does not run if either the user or the group do not exist:
if ! getent passwd | grep -q "^server_user:"; then
echo "Server user does not exist. Aborting" >&2
exit 1
fi
if ! getent group | grep -q "^server_group:" ; then
echo "Server group does not exist. Aborting" >&2
exit 1
fi