diff options
author | John Klug <john.klug@multitech.com> | 2018-06-28 14:39:33 -0500 |
---|---|---|
committer | John Klug <john.klug@multitech.com> | 2018-06-28 14:39:33 -0500 |
commit | 2e4ef5a43bf42e64f7b082e595445dcaa592cf9a (patch) | |
tree | 0365cf3d339acd370c3817629932a47dfc32e49b /src | |
parent | 7172a72ac22f4ed7380f603c9519299ded612bb8 (diff) | |
download | mts-id-eeprom-2e4ef5a43bf42e64f7b082e595445dcaa592cf9a.tar.gz mts-id-eeprom-2e4ef5a43bf42e64f7b082e595445dcaa592cf9a.tar.bz2 mts-id-eeprom-2e4ef5a43bf42e64f7b082e595445dcaa592cf9a.zip |
mts-ubpasswd to use uuid and device-id rather than MAC by default #2
Diffstat (limited to 'src')
-rwxr-xr-x | src/ubpasswd.sh | 73 |
1 files changed, 56 insertions, 17 deletions
diff --git a/src/ubpasswd.sh b/src/ubpasswd.sh index 65e35eb..4383c90 100755 --- a/src/ubpasswd.sh +++ b/src/ubpasswd.sh @@ -24,25 +24,37 @@ if ! [[ -x /sbin/mts-hashpwd ]] ; then exit 1 fi usage() { - echo "ubpasswd [-u] [-d] [-s salt] [password]" - echo " -u means u-boot only (not UNIX password)" - echo " -s salt is user supplied salt" - echo " -r returns true if U-Boot password" - echo " is currently required" + echo "ubpasswd [-c] [-m] [-n] [-r] [-u] [-d] [-s salt] [password]" + echo " -c clear the U-Boot password" + echo " -d debug" echo " -f returns true if U-Boot password" echo " feature is available." - echo " -d debug" + echo " -m means use the mac to generate the password (obsolete)." + echo " -n dryrun for setting password" + echo " -r returns true if U-Boot password" + echo " is currently required" + echo " -s salt is user supplied salt" + echo " -u means u-boot only (not UNIX password)" echo " password is a user supplied password" echo "A salt not supplied is generated." echo "If a password is not supplied, it is generated" + echo "If generating a password, and -m is not supplied," + echo "the UUID is used for generating the password" exit 1 } ((ubonly=0)) +((usemac=0)) ((hassalt=0)) ((debug=0)) ((upwd=0)) -while getopts ":dfrs:u" opt; do +((dryrun=0)) +while getopts ":cdfmnrs:u" opt; do case $opt in + c) + u-boot setenv mtsp + u-boot setenv mtss + exit 0 + ;; f) if ! /bin/fgrep "mts password protected" /dev/mtdblock2 >/dev/null 2>&1; then echo "U-Boot does not support password protection." @@ -52,6 +64,16 @@ while getopts ":dfrs:u" opt; do exit 0 fi ;; + m) + ((usemac=1)) + mac=$(cat "${MTS}/mac-eth") + if ((${#mac} == 0)) ; then + echo "${MTS}/mac-eth must have a non-zero length value" + usage + fi + ;; + n) + ((dryrun=1)) u) ((ubonly=1)) ;; @@ -114,20 +136,33 @@ if ((upwd == 0)) ; then 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" usage fi - if ((${#mac} == 0)) ; then - echo "${mts}/mac-eth must have a non-zero length value" - usage + + + + if ((usemac == 0)) ; then + if ! [[ -f "${MTS}/uuid" ]] ; then + echo "${MTS}/uuid not found. Maybe mts-io driver is not loaded?" + exit 1 + fi + uuid=$(cat "${MTS}/uuid") + if ((${#uuid} == 0)) ; then + echo "${MTS}/uuid must have a non-zero length value" + usage + fi + pwdsrc="-d ${did} -u ${uuid}" + else + pwdsrc="-d ${did} -m ${mac}" fi if ((debug)) ; then echo Try this: - echo "/sbin/mts-hashpwd -d ${did} -m ${mac} ${salt}" + echo "/sbin/mts-hashpwd ${pwdsrc} ${salt}" fi - result=$(/sbin/mts-hashpwd -d ${did} -m ${mac} ${salt}) + result=$(/sbin/mts-hashpwd ${pwdsrc} ${salt}) else result=$(/sbin/mts-hashpwd -p "${pass}" ${salt}) fi @@ -160,9 +195,13 @@ if ((ubonly == 0)) ; then exit 1 fi echo "setting ${USER} password to ${pass}" - echo -e "${pass}\n${pass}" | /usr/bin/passwd "${USER}" >/dev/null 2>&1 + if ((dryrun == 0)) ; then + echo -e "${pass}\n${pass}" | /usr/bin/passwd "${USER}" >/dev/null 2>&1 + fi fi echo "u-boot password is ${pass}" -set -x -/usr/bin/u-boot setenv mtss "$salt" -/usr/bin/u-boot setenv mtsp "$password_hash" +if ((dryrun == 0)) ; then + /usr/bin/u-boot setenv mtss "$salt" + /usr/bin/u-boot setenv mtsp "$password_hash" +fi + |