Skip to content

Commit 676b1f8

Browse files
d-w-mooretrel
authored andcommitted
[#362] escape special characters in PAM passwords
1 parent 72be9c8 commit 676b1f8

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

irods/connection.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
import irods.password_obfuscation as obf
1111
from irods import MAX_NAME_LEN
1212
from ast import literal_eval as safe_eval
13+
import re
14+
15+
16+
PAM_PW_ESC_PATTERN = re.compile(r'([@=&;])')
1317

1418

1519
from irods.message import (
@@ -425,8 +429,10 @@ def _login_pam(self):
425429

426430
time_to_live_in_seconds = 60
427431

432+
pam_password = PAM_PW_ESC_PATTERN.sub(lambda m: '\\'+m.group(1), self.account.password)
433+
428434
ctx_user = '%s=%s' % (AUTH_USER_KEY, self.account.client_user)
429-
ctx_pwd = '%s=%s' % (AUTH_PWD_KEY, self.account.password)
435+
ctx_pwd = '%s=%s' % (AUTH_PWD_KEY, pam_password)
430436
ctx_ttl = '%s=%s' % (AUTH_TTL_KEY, str(time_to_live_in_seconds))
431437

432438
ctx = ";".join([ctx_user, ctx_pwd, ctx_ttl])
@@ -441,7 +447,7 @@ def _login_pam(self):
441447

442448
message_body = PamAuthRequest(
443449
pamUser=self.account.client_user,
444-
pamPassword=self.account.password,
450+
pamPassword=pam_password,
445451
timeToLive=time_to_live_in_seconds)
446452
else:
447453

@@ -546,6 +552,7 @@ def _login_native(self, password=None):
546552
encoded_pwd_array = bytearray(encoded_pwd)
547553
encoded_pwd = bytes(encoded_pwd_array.replace(b'\x00', b'\x01'))
548554

555+
549556
pwd_msg = AuthResponse(
550557
response=encoded_pwd, username=self.account.proxy_user)
551558
pwd_request = iRODSMessage(

irods/exception.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,10 @@ class SYS_INVALID_INPUT_PARAM(SystemException):
554554
code = -130000
555555

556556

557+
class SYS_BAD_INPUT(iRODSException):
558+
code = -158000
559+
560+
557561
class SYS_REPLICA_DOES_NOT_EXIST(iRODSException):
558562
code = -164000
559563

0 commit comments

Comments
 (0)