xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/pam/utilities.kshlib.in (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
3#
4# CDDL HEADER START
5#
6# The contents of this file are subject to the terms of the
7# Common Development and Distribution License (the "License").
8# You may not use this file except in compliance with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or https://opensource.org/licenses/CDDL-1.0.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23
24. $STF_SUITE/include/libtest.shlib
25
26username="pamtestuser"
27runstatedir="${TESTDIR}_run"
28pammodule="@pammoduledir@/pam_zfs_key.so"
29pamservice="pam_zfs_key_test"
30pamconfig="/etc/pam.d/${pamservice}"
31
32function keystatus {
33    log_must [ "$(get_prop keystatus "$TESTPOOL/pam/${username}")" = "$1" ]
34}
35
36function genconfig {
37    printf '%s\trequired\tpam_permit.so\n%s\toptional\t%s\t%s\n' \
38        password password "$pammodule" "$1" \
39        auth     auth     "$pammodule" "$1" \
40        session  session  "$pammodule" "$1" > "${pamconfig}"
41}
42
43function rmconfig {
44    log_must rm -f "${pamconfig}"
45}
46
47function references {
48    log_must [ "$(<"${runstatedir}/$(id -u ${username})")" = "$1" ]
49}
50