summaryrefslogtreecommitdiff
path: root/src/ubpasswd.sh
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2017-05-18 16:16:52 -0500
committerJohn Klug <john.klug@multitech.com>2017-05-18 16:16:52 -0500
commitc2da95882ea7a4218a4432ee5da8165aa61addfc (patch)
tree7627909dc2c7e27e004fc7f5bfdd229c7e09f11e /src/ubpasswd.sh
parent3f8c91c9cd7f9f36da061057a8445bc5809c22cc (diff)
downloadmts-id-eeprom-c2da95882ea7a4218a4432ee5da8165aa61addfc.tar.gz
mts-id-eeprom-c2da95882ea7a4218a4432ee5da8165aa61addfc.tar.bz2
mts-id-eeprom-c2da95882ea7a4218a4432ee5da8165aa61addfc.zip
Allow a variety of user-ids to be updated by mts-ubpasswd0.3.1
Diffstat (limited to 'src/ubpasswd.sh')
-rwxr-xr-xsrc/ubpasswd.sh50
1 files changed, 44 insertions, 6 deletions
diff --git a/src/ubpasswd.sh b/src/ubpasswd.sh
index 1a32ef4..9fea52d 100755
--- a/src/ubpasswd.sh
+++ b/src/ubpasswd.sh
@@ -6,8 +6,22 @@
# and salt. But the password is printed
# for reference.
# ubpasswd -h will print usage.
+#
+# Command changes the password based on the following
+# user list. The first user in this list that is found in
+# /etc/shadow is changed. root is only changed if mtadm
+# or admin is not found.
+ADMINLIST="mtadm admin root"
+MTS=/sys/devices/platform/mts-io
+
+if (( $(id -u) != 0 )) ; then
+ echo "Must have root privilege to procede."
+ exit 1
+fi
+
if ! [[ -x /sbin/mts-hashpwd ]] ; then
echo Need /sbin/mts-hashpwd to proceed.
+ exit 1
fi
usage() {
echo "ubpasswd [-u] [-d] [-s salt] [password]"
@@ -54,9 +68,6 @@ fi
len=8
saltlen=128
-mts=/sys/devices/platform/mts-io
-did=$(cat "${mts}/device-id")
-mac=$(cat "${mts}/mac-eth")
if ! /bin/fgrep "mts password protected" /dev/mtdblock2 >/dev/null 2>&1; then
echo "U-Boot does not support password protection."
@@ -71,8 +82,19 @@ echo "salt: $salt"
((debug)) && echo upwd is $upwd
((debug)) && echo did length is ${#did}
if ((upwd == 0)) ; then
+ if ! [[ -f "${MTS}/device-id" ]] ; then
+ echo "${MTS}/device-id not found. Maybe mts-io driver is not loaded?"
+ exit 1
+ fi
+ if ! [[ -f "${MTS}/mac-eth" ]] ; then
+ echo "${MTS}/mac-eth not found. Maybe mts-io driver is not loaded?"
+ exit 1
+ fi
+
+ did=$(cat "${MTS}/device-id")
+ mac=$(cat "${MTS}/mac-eth")
if ((${#did} == 0)) ; then
- echo "${mts}/device-id must have a non-zero length value"
+ echo "${MTS}/device-id must have a non-zero length value"
usage
fi
if ((${#mac} == 0)) ; then
@@ -99,8 +121,24 @@ pass="${BASH_REMATCH[1]}"
password_hash="${BASH_REMATCH[2]}"
echo "uboot password hash: \"$password_hash\""
if ((ubonly == 0)) ; then
- echo "setting root password to ${pass}"
- echo -e "${pass}\n${pass}" | /usr/bin/passwd >/dev/null 2>&1
+ rstring="^"${ADMINLIST// /:|^}":"
+ list=" "$(egrep "${rstring}" /etc/shadow | sed 's/:.*//')" "
+ for u in $ADMINLIST ; do
+ ((debug)) && echo "list is: $list, u: is $u"
+ if [[ $list =~ [[:space:]]${u}[[:space:]] ]] ; then
+ USER="${u}"
+ ((debug)) && echo Change password of $USER
+ break
+ fi
+ done
+ if ((${#USER} == 0)) ; then
+ echo "No administrator user found"
+ echo "Cannot change the administrator password"
+ echo "Suggest using the \"-u\" option"
+ exit 1
+ fi
+ echo "setting ${USER} password to ${pass}"
+ echo -e "${pass}\n${pass}" | /usr/bin/passwd "${USER}" >/dev/null 2>&1
fi
echo "u-boot password is ${pass}"
set -x