pam_zfs_key: tests: clean up the generated pam service config file

Remove the generated pam service config file
`/etc/pam.d/pam_zfs_key_test` on test cleanup, since the tests
shouldn't alter system state.

While here, move the pam service config file name into a variable.

Reviewed-by: Felix Dörre <felix@dogcraft.de>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Attila Fülöp <attila@fueloep.org>
Closes #12765
This commit is contained in:
Attila Fülöp 2021-11-14 17:36:12 +01:00 committed by Brian Behlendorf
parent b5c16861e9
commit 307db92823
4 changed files with 17 additions and 9 deletions

View File

@ -22,6 +22,7 @@
. $STF_SUITE/tests/functional/pam/utilities.kshlib . $STF_SUITE/tests/functional/pam/utilities.kshlib
rmconfig
destroy_pool $TESTPOOL destroy_pool $TESTPOOL
del_user ${username} del_user ${username}
del_group pamtestgroup del_group pamtestgroup

View File

@ -26,22 +26,22 @@ log_mustnot ismounted "$TESTPOOL/pam/${username}"
keystatus unavailable keystatus unavailable
genconfig "homes=$TESTPOOL/pam runstatedir=${runstatedir}" genconfig "homes=$TESTPOOL/pam runstatedir=${runstatedir}"
echo "testpass" | pamtester pam_zfs_key_test ${username} open_session echo "testpass" | pamtester ${pamservice} ${username} open_session
references 1 references 1
log_must ismounted "$TESTPOOL/pam/${username}" log_must ismounted "$TESTPOOL/pam/${username}"
keystatus available keystatus available
echo "testpass" | pamtester pam_zfs_key_test ${username} open_session echo "testpass" | pamtester ${pamservice} ${username} open_session
references 2 references 2
log_must ismounted "$TESTPOOL/pam/${username}" log_must ismounted "$TESTPOOL/pam/${username}"
keystatus available keystatus available
log_must pamtester pam_zfs_key_test ${username} close_session log_must pamtester ${pamservice} ${username} close_session
references 1 references 1
log_must ismounted "$TESTPOOL/pam/${username}" log_must ismounted "$TESTPOOL/pam/${username}"
keystatus available keystatus available
log_must pamtester pam_zfs_key_test ${username} close_session log_must pamtester ${pamservice} ${username} close_session
references 0 references 0
log_mustnot ismounted "$TESTPOOL/pam/${username}" log_mustnot ismounted "$TESTPOOL/pam/${username}"
keystatus unavailable keystatus unavailable

View File

@ -26,22 +26,22 @@ log_mustnot ismounted "$TESTPOOL/pam/${username}"
keystatus unavailable keystatus unavailable
genconfig "homes=$TESTPOOL/pam runstatedir=${runstatedir} nounmount" genconfig "homes=$TESTPOOL/pam runstatedir=${runstatedir} nounmount"
echo "testpass" | pamtester pam_zfs_key_test ${username} open_session echo "testpass" | pamtester ${pamservice} ${username} open_session
references 1 references 1
log_must ismounted "$TESTPOOL/pam/${username}" log_must ismounted "$TESTPOOL/pam/${username}"
keystatus available keystatus available
echo "testpass" | pamtester pam_zfs_key_test ${username} open_session echo "testpass" | pamtester ${pamservice} ${username} open_session
references 2 references 2
keystatus available keystatus available
log_must ismounted "$TESTPOOL/pam/${username}" log_must ismounted "$TESTPOOL/pam/${username}"
log_must pamtester pam_zfs_key_test ${username} close_session log_must pamtester ${pamservice} ${username} close_session
references 1 references 1
keystatus available keystatus available
log_must ismounted "$TESTPOOL/pam/${username}" log_must ismounted "$TESTPOOL/pam/${username}"
log_must pamtester pam_zfs_key_test ${username} close_session log_must pamtester ${pamservice} ${username} close_session
references 0 references 0
keystatus available keystatus available
log_must ismounted "$TESTPOOL/pam/${username}" log_must ismounted "$TESTPOOL/pam/${username}"

View File

@ -24,6 +24,9 @@
username="pamtestuser" username="pamtestuser"
runstatedir="${TESTDIR}_run" runstatedir="${TESTDIR}_run"
pamservice="pam_zfs_key_test"
pamconfig="/etc/pam.d/${pamservice}"
function keystatus { function keystatus {
log_must [ "$(zfs list -Ho keystatus "$TESTPOOL/pam/${username}")" == "$1" ] log_must [ "$(zfs list -Ho keystatus "$TESTPOOL/pam/${username}")" == "$1" ]
} }
@ -31,7 +34,11 @@ function keystatus {
function genconfig { function genconfig {
for i in password auth session; do for i in password auth session; do
printf "%s\trequired\tpam_permit.so\n%s\toptional\tpam_zfs_key.so\t%s\n" "$i" "$i" "$1" printf "%s\trequired\tpam_permit.so\n%s\toptional\tpam_zfs_key.so\t%s\n" "$i" "$i" "$1"
done > /etc/pam.d/pam_zfs_key_test done > "${pamconfig}"
}
function rmconfig {
log_must rm "${pamconfig}"
} }
function references { function references {