Skip to content

Commit 122ba40

Browse files
Updates to pwchange.bat and pwchange.sh
Updated password change scripts to not print the automatically-generated password by default.
1 parent 1dd6382 commit 122ba40

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

bin/pwchange.bat

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ REM Define the original and new passwords here. To use automatic password genera
33
SET OLDPASS=changeme
44
SET NEWPASS=auto
55

6+
REM Configure if the random password generated should be printed into the output that is sent back to Splunk. Default is "0" which means it's NOT printed. Change to "1" to print.
7+
SET PRINT_PASS=0
8+
69
REM Settings for automatic password generation. Not used if NEWPASS is not set to 'auto'
710
Setlocal EnableDelayedExpansion
811
SET _RNDLength=16
@@ -58,7 +61,11 @@ IF NOT "%LOGIN%"=="Failed" (
5861
REM Create the checkpoint file and log success. This will print the password in the log message passed back to Splunk.
5962
:AUTOSUCCESS
6063
echo %date% %time% %HOST%: Splunk account password successfully changed. > "%CHECKPOINT%"
64+
IF NOT "%PRINT_PASS%"=="0" (
6165
echo %date% %time% %HOST%: Splunk account password successfully changed. Automatic password: %NEWPASS%
66+
) ELSE (
67+
echo "%date% %time% %HOST%: Splunk account password successfully changed. Automatic password: **********"
68+
)
6269
exit
6370

6471
REM Create the checkpoint file and log success.

bin/pwchange.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
OLDPASS=changeme
44
NEWPASS=auto
55

6+
# Configure if the random password generated should be printed into the output that is sent back to Splunk. Default is "0" which means it's NOT printed. Change to "1" to print.
7+
PRINT_PASS=0
8+
69
# Look for the checkpoint file and error out if it exists
710
if [ -f $SPLUNK_HOME/etc/pwd_changed ]
811
then
@@ -13,18 +16,20 @@ fi
1316
if [ "$NEWPASS" = "auto" ]
1417
then
1518
NEWPASS=$(head -c 500 /dev/urandom | sha256sum | base64 | head -c 16 ; echo)
16-
NEWPASSAUTO=$(echo Automatic password: $NEWPASS)
19+
if [ "$PRINT_PASS" = "0" ]; then
20+
NEWPASSAUTO=$(echo "Automatic password: $NEWPASS")
21+
else
22+
NEWPASSAUTO=$(echo "Automatic password: **************")
23+
fi
1724
fi
1825

1926
# Change the password
2027
$SPLUNK_HOME/bin/splunk edit user admin -password $NEWPASS -auth admin:$OLDPASS > /dev/null 2>&1
2128

2229
# Check splunkd.log for any error messages relating to login during the script and determine whether the change was successful or not
2330
CHANGED=$(tail -n 10 $SPLUNK_HOME/var/log/splunk/splunkd.log | grep pwchange | grep Login)
24-
if [ -z "$CHANGED" ]
25-
then
26-
echo $(date -R) $HOSTNAME: Splunk account password successfully changed. $NEWPASSAUTO
27-
echo $(date -R) $HOSTNAME: Splunk account password successfully changed. > $SPLUNK_HOME/etc/pwd_changed
31+
if [ -z "$CHANGED" ]; then
32+
echo "$(date -R) $HOSTNAME: Splunk account password successfully changed. $NEWPASSAUTO"
2833
else
2934
echo $(date -R) $HOSTNAME: Splunk account login failed. Old password is not correct for this host.
3035
fi

0 commit comments

Comments
 (0)