Debian Codegraph @

sbin/drbl-client-root-passwd

raw symbols SCIP
1 #!/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 usage() {
26 echo "Usage:"
27 echo "To set the root's password for clients:"
28 echo "`basename $0` [OPTION]"
29 echo " Options:"
30 echo " --stdin PASSWORD set the root's password for clients as PASSWORD"
31 echo " -h, --host IP_ADDRESS: set only for the host with IP_ADDRESS instead of all DRBL clients"
32 echo " -g, --no-gen-ssi Do NOT generate DRBL SSI template tarball."
33 echo " -v, --verbose prints out extra information"
34 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/null
42
43 # Parse command-line options
44 while [ $# -gt 0 ]; do
45 case "$1" in
46 --stdin)
47 shift;
48 if [ -z "$(echo $1 |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 -*) echo "${0}: ${1}: invalid option" >&2
64 usage >& 2
65 exit 2 ;;
66 *) break ;;
67 esac
68 done
69
70 if [ -z "$client_root_password" ]; then
71 # interactive
72 echo "New password: (It will not be echoed in the screen)"
73 read -s pass1
74 echo "Retype new password: (It will not be echoed in the screen)"
75 read -s pass2
76 while [ "$pass1" != "$pass2" ]; do
77 echo "Sorry, passwords do not match"
78 echo "New password: (It will not be echoed in the screen)"
79 read -s pass1
80 echo "Retype new password: (It will not be echoed in the screen)"
81 read -s pass2
82 done
83 #
84 [ -z "$pass1" ] && 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 [ -n "$specified_host" ]; then
92 [ ! -d "$drblroot/$specified_host" ] && echo "Can NOT find DRBL client $specified_host (i.e. no $drblroot/$specified_host)! Program terminated!" && exit 1
93 [ -n "$verbose" ] && 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 [ -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 [ -d "$ihost" ] && host_list="$host_list $ihost"
106 done
107 fi
108
109 #
110 for ihost in $host_list; do
111 echo -n "Change the root's password for DRBL client `basename $ihost`..."
112 create_chpasswd_env $ihost
113 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 chmod u+x $ihost/pwd_tmp.sh
118 # For SuSE, it seems /dev/urandom is necessary.
119 [ ! -e $ihost/dev/urandom ] && cp -a /dev/urandom $ihost/dev/
120 chroot $ihost/ /pwd_tmp.sh
121 [ -f $ihost/pwd_tmp.sh ] && rm -f $ihost/pwd_tmp.sh
122 #clean_chpasswd_env $ihost
123 echo "done!"
124 done
125
126 #
127 if [ "$gen_ssi" != "no" ]; then
128 echo "-------------------------------------------------------"
129 echo "Since some config files are modified in template client, creating template tarball for DRBL SSI..."
130 drbl-gen-ssi-files
131 fi