Repository navigation
Expand file tree
/
Copy pathpam-test.sh
More file actions
104 lines (80 loc) · 2.31 KB
/
Copy pathpam-test.sh
File metadata and controls
104 lines (80 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
set -e
# load common functions
# shellcheck disable=SC1091
. ./bash_lib.sh
trap 'collect_logs' EXIT
bb_print_env
control_mariadb_server restart
set +e
res=0
#----------------
# Basic pam_unix
#----------------
set -e
sudo tee /etc/pam.d/mariadb <<EOF
auth required pam_unix.so audit
account required pam_unix.so audit
EOF
# PAM v2
sudo mariadb -e "INSTALL SONAME 'auth_pam'; CREATE USER 'buildbot'@'localhost' IDENTIFIED VIA pam USING 'mariadb'"
if ! mysql -ubuildbot -ptest -e "SHOW GRANTS" ; then
res=1
bb_log_err "Authentication with PAM v2 (pam_unix) failed"
fi
sudo mariadb -e "UNINSTALL SONAME 'auth_pam'"
if mysql -ubuildbot -ptest -e "SHOW GRANTS" > /dev/null 2>&1 ; then
res=1
bb_log_err "User authenticated via PAM v2 (pam_unix) could still connect after uninstalling plugin"
fi
if ((res == 0)); then
bb_log_info "PAM v2 Authentication test successful"
fi
# PAM v1
sudo mariadb -e "INSTALL SONAME 'auth_pam_v1'"
set +e
sudo groupadd shadow
sudo usermod -a -G shadow mysql
sudo chown root:shadow /etc/shadow
sudo chmod g+r /etc/shadow
set -e
control_mariadb_server restart
if ! mysql -ubuildbot -ptest -e "SHOW GRANTS" ; then
res=1
bb_log_err "Authentication with PAM v1 (pam_unix) failed"
fi
sudo mariadb -e "UNINSTALL SONAME 'auth_pam_v1'"
if mysql -ubuildbot -ptest -e "SHOW GRANTS" > /dev/null 2>&1 ; then
res=1
bb_log_err "User authenticated via PAM v1 (pam_unix) could still connect after uninstalling plugin"
fi
if ((res == 0)); then
bb_log_info "PAM v1 Authentication test successful"
fi
#----------------
# MTR
#----------------
# PATH can differ between MariaDB versions and distros
for db in mysql mariadb; do
for dir in \
/usr/share/$db-test \
/usr/share/$db/$db-test; do
[[ -d "$dir" ]] && cd "$dir" && break 2
done
done
if [[ -f suite/plugins/pam/pam_mariadb_mtr.so ]]; then
for p in /lib*/security /lib*/*/security ; do
[[ -f "$p/pam_unix.so" ]] && sudo cp -v suite/plugins/pam/pam_mariadb_mtr.so "$p"/
done
fi
if [[ -f suite/plugins/pam/mariadb_mtr ]]; then
sudo cp -v suite/plugins/pam/mariadb_mtr /etc/pam.d/
fi
if ! sudo su mysql -s /bin/sh -c "perl mysql-test-run.pl --verbose-restart --force --vardir=/dev/shm/var_pam --suite=plugins --do-test=pam" ; then
res=1
bb_log_err "MTR PAM tests failed"
fi
set +e
if ((res != 0)); then
exit $res
fi