@@ -782,32 +782,58 @@ CheckPasswordAuth(Port *port, const char **logdetail)
782782 int result ;
783783 char * shadow_pass ;
784784
785+ /* BEGIN HADRON */
786+
787+ /*
788+ * this flag is passed to databricks auth hook and is updated by the hook
789+ * to false if we should continue with password auth. This is by default
790+ * true so that we don't accidentally do password auth if there is some
791+ * bug in the hook. It's better to rely on the hook to set it explicitly
792+ * false to continue with password auth.
793+ */
794+ bool skip_password_auth = true;
795+
796+ /* END HADRON */
797+
785798 sendAuthRequest (port , AUTH_REQ_PASSWORD , NULL , 0 );
786799
787800 passwd = recv_password_packet (port );
788801 if (passwd == NULL )
789802 return STATUS_EOF ; /* client wouldn't send password */
790803
791- shadow_pass = get_role_password (port -> user_name , logdetail );
792- if (shadow_pass )
804+ /* BEGIN HADRON */
805+ elog (DEBUG1 , "Databricks: before authentication hook" );
806+
807+ if (DatabricksAuthentication_hook )
793808 {
794- result = plain_crypt_verify (port -> user_name , shadow_pass , passwd ,
795- logdetail );
809+ result = (* DatabricksAuthentication_hook ) (port , passwd , & skip_password_auth , logdetail );
796810 }
797811 else
812+ {
813+ /* If hook is not set, do the password auth by default */
814+ skip_password_auth = false;
798815 result = STATUS_ERROR ;
816+ }
799817
800- if (result != STATUS_OK && DatabricksAuthentication_hook )
801- {
802- elog (LOG , "Calling DatabricksAuthentication_hook" );
818+ elog (DEBUG1 , "Databricks: after authentication hook" );
803819
804- result = (* DatabricksAuthentication_hook )(port , passwd );
820+ /* only try PG password auth if the hook didn't return STATUS_OK and */
821+ /* the hook set the skip_password_auth flag to false */
822+ if (result != STATUS_OK && !skip_password_auth )
823+ {
824+ shadow_pass = get_role_password (port -> user_name , logdetail );
825+ if (shadow_pass )
826+ {
827+ result = plain_crypt_verify (port -> user_name , shadow_pass , passwd ,
828+ logdetail );
829+ }
830+ else
831+ result = STATUS_ERROR ;
805832
806- elog (LOG , "DatabricksAuthentication_hook returned: %d" , result );
833+ if (shadow_pass )
834+ pfree (shadow_pass );
807835 }
808-
809- if (shadow_pass )
810- pfree (shadow_pass );
836+ /* END HADRON */
811837 pfree (passwd );
812838
813839 if (result == STATUS_OK )
0 commit comments