From 92ae5c022abb4b21e303c91de29faedd3c205536 Mon Sep 17 00:00:00 2001 From: Dmitry Tyzhnenko Date: Wed, 8 Nov 2017 01:50:51 +0200 Subject: [PATCH] Add GRANT_SUDO parameter to context If use a $GRANT_SUDO variable with $USERNAME, the regular user will have a sudo privileges --- src/etc/one-context.d/loc-20-set-username-password | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/etc/one-context.d/loc-20-set-username-password b/src/etc/one-context.d/loc-20-set-username-password index 89fbb27..d2a196f 100755 --- a/src/etc/one-context.d/loc-20-set-username-password +++ b/src/etc/one-context.d/loc-20-set-username-password @@ -24,6 +24,13 @@ if ! getent passwd "${USERNAME}" > /dev/null 2>&1; then useradd -m "${USERNAME}" fi +if [ "${GRANT_SUDO}" == "YES" -a "${USERNAME}" != "root" ]; then + if [ ! -f /etc/sudoers.d/${USERNAME} ]; then + echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${USERNAME} + chmod 644 /etc/sudoers.d/${USERNAME} + fi +fi + if [ -n "${CRYPTED_PASSWORD_BASE64}" ]; then CRYPTED_PASSWORD=$(echo $CRYPTED_PASSWORD_BASE64 | base64 -d) usermod -p "${CRYPTED_PASSWORD}" "${USERNAME}"