| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # Written by Steven Shiau <[email protected]> for using in DRBL |
| 3 | # License: GPL |
| 4 | |
| 5 | # These *.so were found by using strace in create_chpasswd_env function in drbl-functions |
| 6 | # /lib/security/* |
| 7 | # /usr/lib/libcrack.so.2 -> passwd: Module is unknown |
| 8 | # /usr/lib/cracklib_dict.* |
| 9 | # /lib/libnss_files.so.2 is necessary for uid, gid -> username, group. |
| 10 | # /lib/libnsl.so.1 -> without this, will cause this error: |
| 11 | # passwd: Authentication token manipulation error |
| 12 | # /lib*/libcrypt*.so* -> without this, will cause this error: |
| 13 | # pam_chauthtok: Module is unknown |
| 14 | # TODO: |
| 15 | # DRBL client should only have |
| 16 | # dev etc root var |
| 17 | # so have to rm "bin lib usr" |
| 18 | |
| 19 | # Load DRBL setting and functions |
| 20 | DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" |
| 21 | |
| 22 | . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions |
| 23 | |
| 24 | # |
| 25 | usagescip-shell shell shell-project 0.0.0 usage().() { |
| 26 | echoscip-shell system . . echo. "Usage:" |
| 27 | echoscip-shell system . . echo. "To set the root's password for clients:" |
| 28 | echoscip-shell system . . echo. "`basenamescip-shell system . . basename. $0` [OPTION]" |
| 29 | echoscip-shell system . . echo. " Options:" |
| 30 | echoscip-shell system . . echo. " --stdin PASSWORD set the root's password for clients as PASSWORD" |
| 31 | echoscip-shell system . . echo. " -h, --host IP_ADDRESS: set only for the host with IP_ADDRESS instead of all DRBL clients" |
| 32 | echoscip-shell system . . echo. " -g, --no-gen-ssi Do NOT generate DRBL SSI template tarball." |
| 33 | echoscip-shell system . . echo. " -v, --verbose prints out extra information" |
| 34 | echoscip-shell system . . echo. "If option is not given, the interactive mode will be used." |
| 35 | } |
| 36 | |
| 37 | # |
| 38 | check_if_root |
| 39 | |
| 40 | # main |
| 41 | unalias ls 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 42 | |
| 43 | # Parse command-line options |
| 44 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 45 | case "$1" in |
| 46 | --stdin) |
| 47 | shift; |
| 48 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 49 | # skip the -xx option, in case |
| 50 | client_root_password="$1" |
| 51 | fi |
| 52 | shift ;; |
| 53 | -h|--host) |
| 54 | shift; specified_host="$1" |
| 55 | shift |
| 56 | ;; |
| 57 | -g|--no-gen-ssi) |
| 58 | gen_ssi="no" |
| 59 | shift;; |
| 60 | -v|--verbose) |
| 61 | shift; VERBOSE="on" |
| 62 | ;; |
| 63 | -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" >&2 |
| 64 | usagescip-shell shell shell-project 0.0.0 usage(). >& 2 |
| 65 | exit 2 ;; |
| 66 | *) break ;; |
| 67 | esac |
| 68 | done |
| 69 | |
| 70 | if [scip-shell system . . `[`. -z "$client_root_password" ]; then |
| 71 | # interactive |
| 72 | echoscip-shell system . . echo. "New password: (It will not be echoed in the screen)" |
| 73 | read -s pass1 |
| 74 | echoscip-shell system . . echo. "Retype new password: (It will not be echoed in the screen)" |
| 75 | read -s pass2 |
| 76 | while [scip-shell system . . `[`. "$pass1" != "$pass2" ]; do |
| 77 | echoscip-shell system . . echo. "Sorry, passwords do not match" |
| 78 | echoscip-shell system . . echo. "New password: (It will not be echoed in the screen)" |
| 79 | read -s pass1 |
| 80 | echoscip-shell system . . echo. "Retype new password: (It will not be echoed in the screen)" |
| 81 | read -s pass2 |
| 82 | done |
| 83 | # |
| 84 | [scip-shell system . . `[`. -z "$pass1" ] && echoscip-shell system . . echo. "Password can NOT be empty!!! Program terminated" && exit 1 |
| 85 | # set the matched password |
| 86 | new_passwd="$pass1" |
| 87 | else |
| 88 | new_passwd="$client_root_password" |
| 89 | fi |
| 90 | # |
| 91 | if [scip-shell system . . `[`. -n "$specified_host" ]; then |
| 92 | [scip-shell system . . `[`. ! -d "$drblroot/$specified_host" ] && echoscip-shell system . . echo. "Can NOT find DRBL client $specified_host (i.e. no $drblroot/$specified_host)! Program terminated!" && exit 1 |
| 93 | [scip-shell system . . `[`. -n "$verbose" ] && echoscip-shell system . . echo. "specified_host: $specified_host" |
| 94 | fi |
| 95 | |
| 96 | # set the host to be processed |
| 97 | # host_list is the IP address of client, like 192.168.1.1... |
| 98 | host_list="" |
| 99 | if [scip-shell system . . `[`. -n "$specified_host" ]; then |
| 100 | # set the host path |
| 101 | host_list=$drblroot/$specified_host |
| 102 | else |
| 103 | # withoud specified_host, it must be all clients, append each one to $host_list |
| 104 | for ihost in $drblroot/*; do |
| 105 | [scip-shell system . . `[`. -d "$ihost" ] && host_list="$host_list $ihost" |
| 106 | done |
| 107 | fi |
| 108 | |
| 109 | # |
| 110 | for ihost in $host_list; do |
| 111 | echoscip-shell system . . echo. -n "Change the root's password for DRBL client `basename $ihost`..." |
| 112 | create_chpasswd_env $ihost |
| 113 | catscip-shell system . . cat. <<-PWD_END > $ihost/pwd_tmp.sh |
| 114 | # echo "root:$new_passwd" | /usr/bin/strace /usr/sbin/chpasswd |
| 115 | echo "root:$new_passwd" | /usr/sbin/chpasswd |
| 116 | PWD_END |
| 117 | chmodscip-shell system . . chmod. u+x $ihost/pwd_tmp.sh |
| 118 | # For SuSE, it seems /dev/urandom is necessary. |
| 119 | [scip-shell system . . `[`. ! -e $ihost/dev/urandom ] && cpscip-shell system . . cp. -a /dev/urandomscip-shell filesystem . . `/dev/urandom`. $ihost/dev/ |
| 120 | chrootscip-shell system . . chroot. $ihost/ /pwd_tmp.shscip-shell filesystem . . `/pwd_tmp.sh`. |
| 121 | [scip-shell system . . `[`. -f $ihost/pwd_tmp.sh ] && rmscip-shell system . . rm. -f $ihost/pwd_tmp.sh |
| 122 | #clean_chpasswd_env $ihost |
| 123 | echoscip-shell system . . echo. "done!" |
| 124 | done |
| 125 | |
| 126 | # |
| 127 | if [scip-shell system . . `[`. "$gen_ssi" != "no" ]; then |
| 128 | echoscip-shell system . . echo. "-------------------------------------------------------" |
| 129 | echoscip-shell system . . echo. "Since some config files are modified in template client, creating template tarball for DRBL SSI..." |
| 130 | drbl-gen-ssi-files |
| 131 | fi |