Skip to content

Commit

Permalink
[_517] allow generating a pam-password based .irodsA if not pre-existing
Browse files Browse the repository at this point in the history
  • Loading branch information
d-w-moore committed Mar 23, 2024
1 parent cdd47ab commit 4b6b3e8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
12 changes: 11 additions & 1 deletion irods/account.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import os

class iRODSAccount(object):

@property
def derived_auth_file(self):
return '' if not self.env_file else os.path.join(os.path.dirname(self.env_file),'.irodsA')

def __init__(self, irods_host, irods_port, irods_user_name, irods_zone_name,
irods_authentication_scheme='native',
password=None, client_user=None,
server_dn=None, client_zone=None, **kwargs):
server_dn=None, client_zone=None,
env_file = '',
**kwargs):


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

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

Expand Down
6 changes: 3 additions & 3 deletions irods/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ def _login_gsi(self):
logger.info("GSI authorization validated")

def _login_pam(self):

import irods.client_configuration as cfg
inline_password = (self.account.authentication_scheme == self.account._original_authentication_scheme)
# By default, let server determine the TTL.
Expand Down Expand Up @@ -533,8 +532,9 @@ def _login_pam(self):
self._login_native(password = auth_out.result_)

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

Expand Down
15 changes: 9 additions & 6 deletions irods/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,9 @@ def cleanup(self, new_host = ''):
self.__configured = self.configure(**self.do_configure)

def _configure_account(self, **kwargs):

env_file = None
try:
env_file = kwargs['irods_env_file']

except KeyError:
# For backward compatibility
for key in ['host', 'port', 'authentication_scheme']:
Expand All @@ -217,6 +216,9 @@ def _configure_account(self, **kwargs):
# Update with new keywords arguments only
creds.update((key, value) for key, value in kwargs.items() if key not in creds)

if env_file:
creds['env_file'] = env_file

# Get auth scheme
try:
auth_scheme = creds['irods_authentication_scheme']
Expand Down Expand Up @@ -244,10 +246,11 @@ def _configure_account(self, **kwargs):
missing_file_path = []
error_args = []
pw = creds['password'] = self.get_irods_password(session_ = self, file_path_if_not_found = missing_file_path, **creds)
if not pw and creds.get('irods_user_name') != 'anonymous':
if missing_file_path:
error_args += ["Authentication file not found at {!r}".format(missing_file_path[0])]
raise NonAnonymousLoginWithoutPassword(*error_args)
if auth_scheme.lower() not in PAM_AUTH_SCHEMES:
if not pw and creds.get('irods_user_name') != 'anonymous':
if missing_file_path:
error_args += ["Authentication file not found at {!r}".format(missing_file_path[0])]
raise NonAnonymousLoginWithoutPassword(*error_args)

return iRODSAccount(**creds)

Expand Down

0 comments on commit 4b6b3e8

Please sign in to comment.