Skip to content

Commit

Permalink
Attempt to use getent to check for users/group.
Browse files Browse the repository at this point in the history
This should hopefully help in the case of users being in ldap instead
of on the system. The original checks in issue ossec#1278 didn't quite work
for me, so broke them out a bit more.
  • Loading branch information
ddpbsd committed Oct 10, 2017
1 parent 1b791c8 commit 9a6add8
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/init/adduser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ else
OSMYSHELL="/sbin/nologin"
fi

if ! grep "^${GROUP}" /etc/group > /dev/null 2>&1; then
if [ -x /usr/bin/getent ]; then
if [ `getent group ossec | wc -l` -lt 1 ]; then
${GROUPADD} "${GROUP}"
fi
elif ! grep "^${GROUP}" /etc/group > /dev/null 2>&1; then
${GROUPADD} "${GROUP}"
fi

Expand All @@ -77,12 +81,20 @@ else
fi

for U in ${USER} ${USER_MAIL} ${USER_REM}; do
if ! grep "^${U}" /etc/passwd > /dev/null 2>&1; then
if [ "$UNAME" = "OpenBSD" ] || [ "$UNAME" = "SunOS" ]; then
${USERADD} -d "${DIR}" -s ${OSMYSHELL} -g "${GROUP}" "${U}"
else
${USERADD} "${U}" -d "${DIR}" -s ${OSMYSHELL} -g "${GROUP}"
fi
if [ -x /usr/bin/getent ]; then
if [ `getent passwd ${U} | wc -l` -lt 1 ]; then
if [ "$UNAME" = "OpenBSD" ] || [ "$UNAME" = "SunOS" ]; then
${USERADD} -d "${DIR}" -s ${OSMYSHELL} -g "${GROUP}" "${U}"
else
${USERADD} "${U}" -d "${DIR}" -s ${OSMYSHELL} -g "${GROUP}"
fi
fi
elif [ ! `grep "^${U}" /etc/passwd > /dev/null 2>&1` ]; then
if [ "$UNAME" = "OpenBSD" ] || [ "$UNAME" = "SunOS" ]; then
${USERADD} -d "${DIR}" -s ${OSMYSHELL} -g "${GROUP}" "${U}"
else
${USERADD} "${U}" -d "${DIR}" -s ${OSMYSHELL} -g "${GROUP}"
fi
fi
done
fi
Expand Down

0 comments on commit 9a6add8

Please sign in to comment.