Debian Codegraph @

setnew-passwd.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # setnew-password.sh: For demonstration purposes only.
3 # Not a good idea to actually run this script.
4 # This script must be run as root.
5
6 ROOT_UID=0 # Root has $UID 0.
7 E_WRONG_USER=65 # Not root?
8
9 E_NOSUCHUSER=70
10 SUCCESS=0
11
12
13 if [scip-shell system . . `[`. "$UID" -ne "$ROOT_UID" ]
14 then
15 echoscip-shell system . . echo.; echoscip-shell system . . echo. "Only root can run this script."; echoscip-shell system . . echo.
16 exit $E_WRONG_USER
17 else
18 echoscip-shell system . . echo.
19 echoscip-shell system . . echo. "You should know better than to run this script, root."
20 echoscip-shell system . . echo. "Even root users get the blues... "
21 echoscip-shell system . . echo.
22 fi
23
24
25 username=bozo
26 NEWPASSWORD=security_violation
27
28 # Check if bozo lives here.
29 grepscip-shell system . . grep. -q "$username" /etc/passwdscip-shell filesystem . . `/etc/passwd`.
30 if [scip-shell system . . `[`. $? -ne $SUCCESS ]
31 then
32 echoscip-shell system . . echo. "User $username does not exist."
33 echoscip-shell system . . echo. "No password changed."
34 exit $E_NOSUCHUSER
35 fi
36
37 echoscip-shell system . . echo. "$NEWPASSWORD" | passwdscip-shell system . . passwd. --stdin "$username"
38 # The '--stdin' option to 'passwd' permits
39 #+ getting a new password from stdin (or a pipe).
40
41 echoscip-shell system . . echo.; echoscip-shell system . . echo. "User $username's password changed!"
42
43 # Using the 'passwd' command in a script is dangerous.
44
45 exit 0