Skip to content

Commit e1d7b09

Browse files
committed
[_517] allow generating a pam-password based .irodsA if not pre-existing
1 parent 634d7af commit e1d7b09

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

irods/account.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1+
import os
2+
13
class iRODSAccount(object):
24

5+
@property
6+
def derived_auth_file(self):
7+
return '' if not self.env_file else os.path.join(os.path.dirname(self.env_file),'.irodsA')
8+
39
def __init__(self, irods_host, irods_port, irods_user_name, irods_zone_name,
410
irods_authentication_scheme='native',
511
password=None, client_user=None,
6-
server_dn=None, client_zone=None, **kwargs):
12+
server_dn=None, client_zone=None,
13+
env_file = '',
14+
**kwargs):
15+
716

817
# Allowed overrides when cloning sessions. (Currently hostname only.)
918
for k,v in kwargs.pop('_overrides',{}).items():
1019
if k =='irods_host':
1120
irods_host = v
1221

22+
self.env_file = env_file
1323
tuplify = lambda _: _ if isinstance(_,(list,tuple)) else (_,)
1424
schemes = [_.lower() for _ in tuplify(irods_authentication_scheme)]
1525

irods/connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ def _login_gsi(self):
461461
logger.info("GSI authorization validated")
462462

463463
def _login_pam(self):
464-
465464
import irods.client_configuration as cfg
466465
inline_password = (self.account.authentication_scheme == self.account._original_authentication_scheme)
467466
# By default, let server determine the TTL.
@@ -533,8 +532,9 @@ def _login_pam(self):
533532
self._login_native(password = auth_out.result_)
534533

535534
# Store new password in .irodsA if requested.
536-
if self.account._auth_file and cfg.legacy_auth.pam.store_password_to_environment:
537-
with open(self.account._auth_file,'w') as f:
535+
auth_file = (self.account._auth_file or self.account.derived_auth_file)
536+
if auth_file and cfg.legacy_auth.pam.store_password_to_environment:
537+
with open(auth_file,'w') as f:
538538
f.write(obf.encode(auth_out.result_))
539539
logger.debug('new PAM pw write succeeded')
540540

irods/session.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,9 @@ def cleanup(self, new_host = ''):
195195
self.__configured = self.configure(**self.do_configure)
196196

197197
def _configure_account(self, **kwargs):
198-
198+
env_file = None
199199
try:
200200
env_file = kwargs['irods_env_file']
201-
202201
except KeyError:
203202
# For backward compatibility
204203
for key in ['host', 'port', 'authentication_scheme']:
@@ -217,6 +216,9 @@ def _configure_account(self, **kwargs):
217216
# Update with new keywords arguments only
218217
creds.update((key, value) for key, value in kwargs.items() if key not in creds)
219218

219+
if env_file:
220+
creds['env_file'] = env_file
221+
220222
# Get auth scheme
221223
try:
222224
auth_scheme = creds['irods_authentication_scheme']
@@ -244,10 +246,11 @@ def _configure_account(self, **kwargs):
244246
missing_file_path = []
245247
error_args = []
246248
pw = creds['password'] = self.get_irods_password(session_ = self, file_path_if_not_found = missing_file_path, **creds)
247-
if not pw and creds.get('irods_user_name') != 'anonymous':
248-
if missing_file_path:
249-
error_args += ["Authentication file not found at {!r}".format(missing_file_path[0])]
250-
raise NonAnonymousLoginWithoutPassword(*error_args)
249+
if auth_scheme.lower() not in PAM_AUTH_SCHEMES:
250+
if not pw and creds.get('irods_user_name') != 'anonymous':
251+
if missing_file_path:
252+
error_args += ["Authentication file not found at {!r}".format(missing_file_path[0])]
253+
raise NonAnonymousLoginWithoutPassword(*error_args)
251254

252255
return iRODSAccount(**creds)
253256

0 commit comments

Comments
 (0)