Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change adduser to useradd #61

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ENV PATH="/container/scripts:${PATH}"
RUN apk add --no-cache runit \
avahi \
samba \
shadow \
\
&& sed -i 's/#enable-dbus=.*/enable-dbus=no/g' /etc/avahi/avahi-daemon.conf \
&& rm -vf /etc/avahi/services/* \
Expand Down
4 changes: 2 additions & 2 deletions scripts/create-hash.sh

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kjeldflarup, you missed addgroup on L113.

-addgroup "$ACCOUNT_NAME" "$GRP"
+usermod -aG "$GRP" "$ACCOUNT_NAME"

Copy link
Author

@kjeldflarup kjeldflarup Oct 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I just pushed a commit with that change, but I did not test it :-)
But according to my man page, this addgroup command also seems to be incorrect, or at least not portable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not test it :-)

I tested it on Ubutu and Alipine Linux, it works as expected. 😉

But according to my man page, this addgroup command also seems to be incorrect, or at least not portable.

The old adduser command works on Alpine Linux, where it is installed as part of Busybox which is quite limited and uses different options from its other implementations.

Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ echo

if [ "$PASSWORD_1" == "$PASSWORD_2" ] && [ "$PASSWORD_1" != "" ] && [ "$USERNAME" != "" ]
then
adduser -D -H -s /bin/false "$USERNAME" 2> /dev/null >/dev/null
useradd -u "$ACCOUNT_UID" -s /bin/false "$ACCOUNT_NAME" 2> /dev/null >/dev/null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you have a mistake: ACCOUNT_UID is not defined in this file. And you are missing -M.

Suggested change
useradd -u "$ACCOUNT_UID" -s /bin/false "$ACCOUNT_NAME" 2> /dev/null >/dev/null
useradd -Ms /bin/false "$ACCOUNT_NAME" 2> /dev/null >/dev/null

smbpasswd -a -n "$USERNAME" 2> /dev/null >/dev/null
echo -e "$PASSWORD_1\n$PASSWORD_1" | passwd "$USERNAME" 2> /dev/null >/dev/null
echo -e "$PASSWORD_1\n$PASSWORD_1" | smbpasswd "$USERNAME" 2> /dev/null >/dev/null
cat /var/lib/samba/private/smbpasswd | grep ':$' | grep '^'"$USERNAME"':[0-9]*:'
exit 0
fi

exit 1
exit 1
6 changes: 3 additions & 3 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ if [ ! -f "$INITALIZED" ]; then
GROUP_NAME=$(echo "$I_CONF" | sed 's/^GROUP_//g' | sed 's/=.*//g')
GROUP_ID=$(echo "$I_CONF" | sed 's/^[^=]*=//g')
echo ">> GROUP: adding group $GROUP_NAME with GID: $GROUP_ID"
addgroup -g "$GROUP_ID" "$GROUP_NAME"
groupadd -g "$GROUP_ID" "$GROUP_NAME"
done

##
Expand All @@ -87,10 +87,10 @@ if [ ! -f "$INITALIZED" ]; then
if [ "$ACCOUNT_UID" -gt 0 ] 2>/dev/null
then
echo ">> ACCOUNT: adding account: $ACCOUNT_NAME with UID: $ACCOUNT_UID"
adduser -D -H -u "$ACCOUNT_UID" -s /bin/false "$ACCOUNT_NAME"
useradd -u "$ACCOUNT_UID" -s /bin/false "$ACCOUNT_NAME"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are missing -M (Do not create the user's home directory, even if the system wide setting from /etc/login.defs (CREATE_HOME) is set to yes.).

Suggested change
useradd -u "$ACCOUNT_UID" -s /bin/false "$ACCOUNT_NAME"
useradd -Mu "$ACCOUNT_UID" -s /bin/false "$ACCOUNT_NAME"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we probably want to add -N to not create user group. 🤔

else
echo ">> ACCOUNT: adding account: $ACCOUNT_NAME"
adduser -D -H -s /bin/false "$ACCOUNT_NAME"
useradd -s /bin/false "$ACCOUNT_NAME"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
useradd -s /bin/false "$ACCOUNT_NAME"
useradd -Ms /bin/false "$ACCOUNT_NAME"

fi
smbpasswd -a -n "$ACCOUNT_NAME"

Expand Down