Files
shadow/tests/su/02/run.exp2
nekral-guest 39beb1da3a 105_zn_CN was just applied to upstream repository.
Tag 104_man-sv, 101_ja, and 103_man-de as going to be fixed in 4.0.18.2.
2007-10-27 12:51:13 +00:00

169 lines
3.9 KiB
Plaintext
Executable File

#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export PATH=bar:\$PATH\r"
expect "# "
#=============================================================================
#
# Regular su, preserve environment
# However, PATH is reset
#
#=============================================================================
send "/bin/su myuser $command\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/bin:/usr/bin:/bin:/usr/games\"\r"
expect "$ "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/home/'myuser'myuser'/bin/sh'\r"
expect "$ "
send "exit\r"
expect "# "
#=============================================================================
#
# su -, make a login shell
#
#=============================================================================
send "/bin/su - $command myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/bin:/usr/bin:/bin:/usr/games\"\r"
expect "$ "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/home/'myuser'myuser'/bin/sh'\r"
expect "$ "
send "exit\r"
expect "# "
#=============================================================================
#
# Regular su to root, preserve environment
# However, PATH is reset
#
#=============================================================================
send "/bin/su $command\r"
expect "# "
send "id\n"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"\r"
expect "# "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/root'root'root'/bin/bash'\r"
expect "# "
send "exit\r"
expect "# "
#=============================================================================
#
# su - root, make a login shell
#
#=============================================================================
send "/bin/su $command - root\r"
expect "# "
send "id\n"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"\r"
expect "# "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/root'root'root'/bin/bash'\r"
expect "# "
send "exit\r"
expect "# "
#=============================================================================
#
# su -m, as for regular su, environment is preserved
#
#=============================================================================
send "/bin/su $command -m myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"bar:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"\r"
expect "$ "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/root'root'root'/bin/bash'\r"
expect "$ "
send "exit\r"
expect "# "
#=============================================================================
#
# su -m -, make a login shell, but preserve environment
# However, PATH is not preserved, but set to what it would be with login
#
#=============================================================================
send "/bin/su -p $command - myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/bin:/usr/bin:/bin:/usr/games\"\r"
expect "$ "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/root'root'root'/bin/bash'\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0