Skip to content

Commit 651f603

Browse files
committed
[_517] allow generating a pam-password based .irodsA if not pre-existing
1 parent 527417d commit 651f603

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,9 @@ def _login_pam(self):
532532
self._login_native(password = auth_out.result_)
533533

534534
# Store new password in .irodsA if requested.
535-
if self.account._auth_file and cfg.legacy_auth.pam.store_password_to_environment:
536-
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:
537538
f.write(obf.encode(auth_out.result_))
538539
logger.debug('new PAM pw write succeeded')
539540

irods/session.py

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

212212
def _configure_account(self, **kwargs):
213-
213+
env_file = None
214214
try:
215215
env_file = kwargs['irods_env_file']
216-
217216
except KeyError:
218217
# For backward compatibility
219218
for key in ['host', 'port', 'authentication_scheme']:
@@ -232,6 +231,9 @@ def _configure_account(self, **kwargs):
232231
# Update with new keywords arguments only
233232
creds.update((key, value) for key, value in kwargs.items() if key not in creds)
234233

234+
if env_file:
235+
creds['env_file'] = env_file
236+
235237
# Get auth scheme
236238
try:
237239
auth_scheme = creds['irods_authentication_scheme']
@@ -259,10 +261,11 @@ def _configure_account(self, **kwargs):
259261
missing_file_path = []
260262
error_args = []
261263
pw = creds['password'] = self.get_irods_password(session_ = self, file_path_if_not_found = missing_file_path, **creds)
262-
if not pw and creds.get('irods_user_name') != 'anonymous':
263-
if missing_file_path:
264-
error_args += ["Authentication file not found at {!r}".format(missing_file_path[0])]
265-
raise NonAnonymousLoginWithoutPassword(*error_args)
264+
if auth_scheme.lower() not in PAM_AUTH_SCHEMES:
265+
if not pw and creds.get('irods_user_name') != 'anonymous':
266+
if missing_file_path:
267+
error_args += ["Authentication file not found at {!r}".format(missing_file_path[0])]
268+
raise NonAnonymousLoginWithoutPassword(*error_args)
266269

267270
return iRODSAccount(**creds)
268271

0 commit comments

Comments
 (0)