@@ -23,8 +23,11 @@ def login(conn, **extra_opt):
2323_scheme = 'pam_password'
2424
2525
26+ _logger = logging .getLogger (__name__ )
27+
28+
2629def authenticate_pam_password (conn , req ):
27- logging . info ('----------- %s (begin)' , _scheme )
30+ _logger . debug ('----------- %s (begin)' , _scheme )
2831
2932 # By design, we persist this "depot" object over the whole of the authentication
3033 # exchange with the iRODS server as a means of sending password information to the
@@ -33,14 +36,14 @@ def authenticate_pam_password(conn, req):
3336 # are authenticating without the help of iCommand-type client env/auth files.
3437 _ = AuthStorage .create_temp_pw_storage (conn )
3538
36- pam_password_ClientAuthState (
39+ _pam_password_ClientAuthState (
3740 conn ,
3841 scheme = _scheme
3942 ).authenticate_client (
4043 initial_request = req
4144 )
4245
43- logging . info ('----------- %s (end)' , _scheme )
46+ _logger . debug ('----------- %s (end)' , _scheme )
4447
4548
4649def get_pam_password_from_stdin (file_like_object = None ):
@@ -61,30 +64,39 @@ def get_pam_password_from_stdin(file_like_object = None):
6164AUTH_PASSWORD_KEY = "a_pw"
6265
6366
64- class pam_password_ClientAuthState (authentication_base ):
67+ class _pam_password_ClientAuthState (authentication_base ):
68+
69+ # Client define
70+ AUTH_CLIENT_AUTH_REQUEST = "pam_password_auth_client_request"
71+
72+ # Server define
73+ AUTH_AGENT_AUTH_REQUEST = "auth_agent_auth_request"
6574
6675 def __init__ (self ,* _ ,check_ssl = True ,** _kw ):
6776 super ().__init__ (* _ ,** _kw )
6877 self .check_ssl = check_ssl
69- self ._l = None
78+ self ._list_for_request_result_return = None
7079
7180 def auth_client_start (self , request ):
7281
73- self ._l = request .pop (CLIENT_GET_REQUEST_RESULT , False )
82+ # This list reference is popped and cached for the purpose of returning the request_result value
83+ # to the caller upon request.
84+ self ._list_for_request_result_return = request .pop (CLIENT_GET_REQUEST_RESULT , False )
7485
7586 if self .check_ssl :
7687 if not isinstance (self .conn .socket , ssl .SSLSocket ):
77- msg = 'Need to be connected via SSL.'
88+ msg = "pam_password auth scheme requires secure communications (TLS/ SSL) with the server."
7889 raise RuntimeError (msg )
7990
8091 resp = request .copy ()
8192
82- obj = resp .pop (FORCE_PASSWORD_PROMPT , None )
93+ password_input_obj = resp .pop (FORCE_PASSWORD_PROMPT , None )
8394
84- if obj :
85- obj = None if isinstance (obj ,(int ,bool )) else obj
86- # Like with the C++ plugin, we offer the user a chance
87- resp [AUTH_PASSWORD_KEY ] = get_pam_password_from_stdin (file_like_object = obj )
95+ if password_input_obj :
96+ if isinstance (password_input_obj ,(int ,bool )):
97+ password_input_obj = None
98+ # Like with the C++ plugin, we offer the user a chance to enter a password.
99+ resp [AUTH_PASSWORD_KEY ] = get_pam_password_from_stdin (file_like_object = password_input_obj )
88100 else :
89101 # Password from .irodsA in environment.
90102 if self .conn .account ._auth_file :
@@ -97,12 +109,6 @@ def auth_client_start(self, request):
97109 resp [__NEXT_OPERATION__ ] = self .AUTH_CLIENT_AUTH_REQUEST
98110 return resp
99111
100- # Client define
101- AUTH_CLIENT_AUTH_REQUEST = "pam_password_auth_client_request"
102-
103- # Server define
104- AUTH_AGENT_AUTH_REQUEST = "auth_agent_auth_request"
105-
106112 def pam_password_auth_client_request (self , request ):
107113 server_req = request .copy ()
108114 server_req [__NEXT_OPERATION__ ] = self .AUTH_AGENT_AUTH_REQUEST
@@ -113,14 +119,15 @@ def pam_password_auth_client_request(self, request):
113119 depot = AuthStorage .get_temp_pw_storage (self .conn )
114120 if depot :
115121 if resp .get (STORE_PASSWORD_IN_MEMORY , None ):
122+ # Prevent use of an .irodsA to store an encoded password.
116123 depot .use_client_auth_file (None )
117124 depot .store_pw (resp ["request_result" ])
118125 else :
119126 msg = "auth storage object was either not set, or allowed to expire prematurely."
120127 raise RuntimeError (msg )
121128
122- if isinstance (self ._l ,list ):
123- self ._l [:] = (resp ["request_result" ],)
129+ if isinstance (self ._list_for_request_result_return ,list ):
130+ self ._list_for_request_result_return [:] = (resp ["request_result" ],)
124131
125132 resp [__NEXT_OPERATION__ ] = self .perform_native_auth
126133 return resp
0 commit comments