@@ -781,32 +781,58 @@ CheckPasswordAuth(Port *port, const char **logdetail)
781781 int result ;
782782 char * shadow_pass ;
783783
784+ /* BEGIN HADRON */
785+
786+ /*
787+ * this flag is passed to databricks auth hook and is updated by the hook
788+ * to false if we should continue with password auth. This is by default
789+ * true so that we don't accidentally do password auth if there is some
790+ * bug in the hook. It's better to rely on the hook to set it explicitly
791+ * false to continue with password auth.
792+ */
793+ bool skip_password_auth = true;
794+
795+ /* END HADRON */
796+
784797 sendAuthRequest (port , AUTH_REQ_PASSWORD , NULL , 0 );
785798
786799 passwd = recv_password_packet (port );
787800 if (passwd == NULL )
788801 return STATUS_EOF ; /* client wouldn't send password */
789802
790- shadow_pass = get_role_password (port -> user_name , logdetail );
791- if (shadow_pass )
803+ /* BEGIN HADRON */
804+ elog (DEBUG1 , "Databricks: before authentication hook" );
805+
806+ if (DatabricksAuthentication_hook )
792807 {
793- result = plain_crypt_verify (port -> user_name , shadow_pass , passwd ,
794- logdetail );
808+ result = (* DatabricksAuthentication_hook ) (port , passwd , & skip_password_auth , logdetail );
795809 }
796810 else
811+ {
812+ /* If hook is not set, do the password auth by default */
813+ skip_password_auth = false;
797814 result = STATUS_ERROR ;
815+ }
798816
799- if (result != STATUS_OK && DatabricksAuthentication_hook )
800- {
801- elog (LOG , "Calling DatabricksAuthentication_hook" );
817+ elog (DEBUG1 , "Databricks: after authentication hook" );
802818
803- result = (* DatabricksAuthentication_hook )(port , passwd );
819+ /* only try PG password auth if the hook didn't return STATUS_OK and */
820+ /* the hook set the skip_password_auth flag to false */
821+ if (result != STATUS_OK && !skip_password_auth )
822+ {
823+ shadow_pass = get_role_password (port -> user_name , logdetail );
824+ if (shadow_pass )
825+ {
826+ result = plain_crypt_verify (port -> user_name , shadow_pass , passwd ,
827+ logdetail );
828+ }
829+ else
830+ result = STATUS_ERROR ;
804831
805- elog (LOG , "DatabricksAuthentication_hook returned: %d" , result );
832+ if (shadow_pass )
833+ pfree (shadow_pass );
806834 }
807-
808- if (shadow_pass )
809- pfree (shadow_pass );
835+ /* END HADRON */
810836 pfree (passwd );
811837
812838 if (result == STATUS_OK )
0 commit comments