@@ -781,32 +781,58 @@ CheckPasswordAuth(Port *port, const char **logdetail)
781
781
int result ;
782
782
char * shadow_pass ;
783
783
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
+
784
797
sendAuthRequest (port , AUTH_REQ_PASSWORD , NULL , 0 );
785
798
786
799
passwd = recv_password_packet (port );
787
800
if (passwd == NULL )
788
801
return STATUS_EOF ; /* client wouldn't send password */
789
802
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 )
792
807
{
793
- result = plain_crypt_verify (port -> user_name , shadow_pass , passwd ,
794
- logdetail );
808
+ result = (* DatabricksAuthentication_hook ) (port , passwd , & skip_password_auth , logdetail );
795
809
}
796
810
else
811
+ {
812
+ /* If hook is not set, do the password auth by default */
813
+ skip_password_auth = false;
797
814
result = STATUS_ERROR ;
815
+ }
798
816
799
- if (result != STATUS_OK && DatabricksAuthentication_hook )
800
- {
801
- elog (LOG , "Calling DatabricksAuthentication_hook" );
817
+ elog (DEBUG1 , "Databricks: after authentication hook" );
802
818
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 ;
804
831
805
- elog (LOG , "DatabricksAuthentication_hook returned: %d" , result );
832
+ if (shadow_pass )
833
+ pfree (shadow_pass );
806
834
}
807
-
808
- if (shadow_pass )
809
- pfree (shadow_pass );
835
+ /* END HADRON */
810
836
pfree (passwd );
811
837
812
838
if (result == STATUS_OK )
0 commit comments