From a631bc6fbafd8e46f9a7b6f577ebdfc3ab94e46a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 3 Sep 2026 20:39:08 -0300 Subject: [PATCH] fix(sudoer): take the user name and password from options The sudoer postscript created the xcat account with the fixed password rootpw. Take the user name and the password from the -u and -p options. This is the change from #6166, rebased onto master. (cherry picked from commit 986052a6382b513046e4926abb778d5fec6efaf9) Co-authored-by: Casandra Qiu --- xCAT/postscripts/sudoer | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/xCAT/postscripts/sudoer b/xCAT/postscripts/sudoer index f2f42e21d..dd481af21 100755 --- a/xCAT/postscripts/sudoer +++ b/xCAT/postscripts/sudoer @@ -7,6 +7,28 @@ # #------------------------------------------------------------------------------ +function usage() { + echo "" + echo "Usage: $0 -u username -p password" + echo -e "\t-u sudoer user name" + echo -e "\t-p sudoer password" + exit 1 +} + +while getopts "u:p:" opt; +do + case $opt in + u) SUDOER="$OPTARG";; + p) SUDOERPW="$OPTARG";; + esac +done + +if [ -z "$SUDOER" ] || [ -z $SUDOERPW ] +then + usage; +fi + + if [ -n "$LOGLABEL" ]; then log_label=$LOGLABEL else @@ -19,14 +41,12 @@ if [ "$(uname -s|tr 'A-Z' 'a-z')" = "linux" ];then fi # Configuration for the sudoer -SUDOER="xcat" -SUDOERPW="rootpw" PRIV="$SUDOER ALL=(ALL) NOPASSWD: ALL" SEED=`date "+%s"` ENCRYPT=`perl -e "print crypt($SUDOERPW, $SEED)"` # Create sudoer -/usr/sbin/userdel $SUDOER +/usr/sbin/userdel $SUDOER &> /dev/null /usr/sbin/useradd -p $ENCRYPT -m $SUDOER echo "$PRIV" >> /etc/sudoers if [ -e "/etc/redhat-release" ]; then