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 105 106 107 108
|
dot_to_space() {
sed 's/\./ /g'<<<"$1"
}
CLEANUP=$':\n'
GT() { (return 1); echo $?; }
LT() { (return -1); echo $?; }
EQ() { (return 0); echo $?; }
compare_int_tuple() {
local x=($1) y=($2)
local lx=${#x[@]} ly=${#y[@]}
local i maxlen=$((lx > ly ? lx : ly))
for ((i=0;i<maxlen;i++)) {
if [ $i -ge $lx ]; then return `LT`; fi
if [ $i -ge $ly ]; then return `GT`; fi
if [ ${x[$i]} -lt ${y[$i]} ]; then return `LT`; fi
if [ ${x[$i]} -gt ${y[$i]} ]; then return `GT`; fi
}
return `EQ`
}
irods_version()
{
local X=''
[[ `ihelp -h|tail -1` =~ [0-9]+(\.[0-9]+)+ ]] && X=${BASH_REMATCH[0]}
echo "$X"
}
pam_test_would_take_too_long()
{
compare_int_tuple "$(dot_to_space `irods_version`)" "$(dot_to_space 4.3.1)"
[ $? = `LT` ]
}
get_auth_param () { iadmin get_grid_configuration authentication $1; }
with_change_auth_params_for_test()
{
local restore_cmd=""
# Use saved environment (must be rodsadmin).
if [ -e ~/.irods.$$ ]; then
export IRODS_ENVIRONMENT_FILE=~/.irods.$$/irods_environment.json
export IRODS_AUTHENTICATION_FILE=~/.irods.$$/.irodsA
fi
while [ $# -ge 2 ]; do
local reset_value=$(iadmin get_grid_configuration authentication $1)
restore_cmd+=$'\n'"iadmin set_grid_configuration authentication $1 $reset_value"
[ -n "$2" ] && iadmin set_grid_configuration authentication $1 $2
shift 2
done
unset IRODS_ENVIRONMENT_FILE IRODS_AUTHENTICATION_FILE
if [[ $SET_CLEANUP = [yY]* ]]; then
CLEANUP+="$restore_cmd"
fi
}
_begin_pam_environment_and_password() {
local ENV='{
"irods_host": "localhost",
"irods_zone_name": "tempZone",
"irods_port": 1247,
"irods_user_name": "alice",
"irods_authentication_scheme": "pam_password",
"irods_client_server_negotiation": "request_server_negotiation",
"irods_client_server_policy": "CS_NEG_REQUIRE",
"irods_ssl_ca_certificate_file": "/etc/irods/ssl/irods.crt",
"irods_ssl_verify_server": "cert",
"irods_encryption_key_size": 16,
"irods_encryption_salt_size": 8,
"irods_encryption_num_hash_rounds": 16,
"irods_encryption_algorithm": "AES-256-CBC"
}'
rm -fr ~/.irods.$$
mv ~/.irods ~/.irods.$$
mkdir ~/.irods
echo "$ENV" > ~/.irods/irods_environment.json
iinit <<<"$1" 2>/dev/tty
}
_end_pam_environment_and_password() {
rm -fr ~/.irods
mv ~/.irods.$$ ~/.irods
}
setup_pam_login_for_alice() {
sudo useradd alice --create-home
local PASSWD=${1:-test123}
sudo chpasswd <<<"alice:$PASSWD"
iadmin mkuser alice rodsuser
_begin_pam_environment_and_password "$PASSWD"
}
finalize_pam_login_for_alice() {
_end_pam_environment_and_password
iadmin rmuser alice
sudo userdel alice --remove
}
test_specific_cleanup() {
eval "$CLEANUP"
}
|