Skip to content

Commit 6a200be

Browse files
committed
[_362][_522][_523] allow '=' and ';' in PAM passwords
1 parent 108661b commit 6a200be

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

irods/api_number.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,5 +179,7 @@
179179
"GET_RESOURCE_INFO_FOR_OPERATION_AN": 10220,
180180
"ATOMIC_APPLY_METADATA_OPERATIONS_APN": 20002,
181181
"GET_FILE_DESCRIPTOR_INFO_APN": 20000,
182-
"REPLICA_CLOSE_APN": 20004
182+
"REPLICA_CLOSE_APN": 20004,
183+
184+
"AUTH_PLUG_REQ_AN": 1201
183185
}

irods/connection.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
from irods.message import (PamAuthRequest, PamAuthRequestOut)
2626

2727

28-
29-
ALLOW_PAM_LONG_TOKENS = True # True to fix [#279]
3028
# Message to be logged when the connection
3129
# destructor is called. Used in a unit test
3230
DESTRUCTOR_MSG = "connection __del__() called"
@@ -493,9 +491,10 @@ def _login_pam(self):
493491
if getattr(self,'DISALLOWING_PAM_PLAINTEXT',True):
494492
raise PlainTextPAMPasswordError
495493

496-
Pam_Long_Tokens = (ALLOW_PAM_LONG_TOKENS and (len(ctx) >= MAX_NAME_LEN))
494+
use_dedicated_pam_api = len(ctx) >= MAX_NAME_LEN or \
495+
{';','='}.intersection(set(new_pam_password))
497496

498-
if Pam_Long_Tokens:
497+
if use_dedicated_pam_api:
499498
message_body = PamAuthRequest( pamUser = self.account.client_user,
500499
pamPassword = new_pam_password,
501500
timeToLive = time_to_live_in_hours)
@@ -505,7 +504,7 @@ def _login_pam(self):
505504
auth_req = iRODSMessage(
506505
msg_type='RODS_API_REQ',
507506
msg=message_body,
508-
int_info=(725 if Pam_Long_Tokens else 1201)
507+
int_info=api_number['PAM_AUTH_REQUEST_AN' if use_dedicated_pam_api else 'AUTH_PLUG_REQ_AN']
509508
)
510509

511510
self.send(auth_req)
@@ -516,8 +515,7 @@ def _login_pam(self):
516515
# TODO (#480): In Python3 will be able to do: 'raise RuntimeError(...) from exc' for more succinct error messages
517516
raise RuntimeError('Client-configured TTL is outside server parameters (password min and max times)')
518517

519-
Pam_Response_Class = (PamAuthRequestOut if Pam_Long_Tokens
520-
else AuthPluginOut)
518+
Pam_Response_Class = (PamAuthRequestOut if use_dedicated_pam_api else AuthPluginOut)
521519

522520
auth_out = output_message.get_main_message( Pam_Response_Class )
523521

irods/test/PRC_issue_362.bats

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# The tests in this BATS module must be run as a (passwordless) sudo-enabled user.
22
# It is also required that the python irodsclient be installed under irods' ~/.local environment.
33

4+
. $BATS_TEST_DIRNAME/scripts/funcs
45

56
setup() {
67
local -A chars=(
@@ -12,25 +13,43 @@ setup() {
1213
[ $BATS_TEST_NUMBER = 1 ] && echo "---" >/tmp/PRC_test_issue_362
1314
local name=${BATS_TEST_DESCRIPTION##*_}
1415
CHR="${chars[$name]}"
15-
}
1616

17-
TEST_THE_TEST=""
17+
## Arrange for secrets file to be generated internally by the Python client
18+
cat >~/.python_irodsclient <<-EOF
19+
legacy_auth.pam.store_password_to_environment True
20+
legacy_auth.pam.password_for_auto_renew 'my${CHR}pass'
21+
legacy_auth.pam.time_to_live_in_hours 1
22+
EOF
23+
24+
iinit_as_rods
25+
26+
if [ ! -e /tmp/rodsuser_alissa_created ]; then
27+
iadmin mkuser alissa rodsuser
28+
fi
29+
touch /tmp/rodsuser_alissa_created
30+
31+
_begin_pam_environment_and_password "" alissa
32+
rm -f ~/.irods/.irodsA
33+
34+
cat >~/test_get_home_coll.py <<-EOF
35+
import irods.test.helpers as h
36+
ses = h.make_session()
37+
home_coll = h.home_collection(ses)
38+
exit(0 if ses.collections.get(home_coll).path == home_coll
39+
and ses.pool.account._original_authentication_scheme.lower().startswith('pam')
40+
else 1)
41+
EOF
42+
}
1843

1944
prc_test()
2045
{
2146
local USER="alissa"
22-
local PASSWORD=$(tr "." "$CHR" <<<"my.pass")
23-
echo "$USER:$PASSWORD" | sudo chpasswd
24-
if [ "$TEST_THE_TEST" = 1 ]; then
25-
echo -n `date`: "" >&2
26-
{ su - "$USER" -c "id" <<<"$PASSWORD" 2>/dev/null | grep $USER ; } >&2
27-
else
28-
sudo su - irods -c "env PYTHON_IRODSCLIENT_TEST_PAM_PW_OVERRIDE='$PASSWORD' python -m unittest \
29-
irods.test.login_auth_test.TestLogins.test_escaped_pam_password_chars__362"
30-
fi
31-
} 2>> /tmp/PRC_test_issue_362
47+
local PASSWORD="my${CHR}pass"
48+
sudo chpasswd <<<"$USER:$PASSWORD"
49+
env PYTHON_IRODSCLIENT_CONFIGURATION_PATH='' python ~/test_get_home_coll.py
50+
}
3251

33-
@test "test_with_atsymbol" { prc_test; }
34-
@test "test_with_semicolon" { prc_test; }
35-
@test "test_with_equals" { prc_test; }
36-
@test "test_with_ampersand" { prc_test; }
52+
@test "test_with_atsymbol" { prc_test; }
53+
@test "test_with_semicolon" { prc_test; }
54+
@test "test_with_equals" { prc_test; }
55+
@test "test_with_ampersand" { prc_test; }

0 commit comments

Comments
 (0)