@@ -791,32 +791,59 @@ CheckPasswordAuth(Port *port, char **logdetail)
791791 int result ;
792792 char * shadow_pass ;
793793
794+ /* BEGIN NEON */
795+
796+ /*
797+ * This flag is passed to databricks auth hook and is updated by the hook
798+ * to false if we should continue with password auth. This is by default
799+ * true so that we don't accidentally do password auth if there is some
800+ * bug in the hook. It's better to rely on the hook to set it explicitly
801+ * false to continue with password auth.
802+ */
803+ bool skip_password_auth = true;
804+
805+ /* END NEON */
806+
794807 sendAuthRequest (port , AUTH_REQ_PASSWORD , NULL , 0 );
795808
796809 passwd = recv_password_packet (port );
797810 if (passwd == NULL )
798811 return STATUS_EOF ; /* client wouldn't send password */
799812
800- shadow_pass = get_role_password (port -> user_name , logdetail );
801- if (shadow_pass )
813+ /* BEGIN NEON */
814+ elog (DEBUG1 , "Databricks: before authentication hook" );
815+
816+ if (DatabricksAuthentication_hook )
802817 {
803- result = plain_crypt_verify ( port -> user_name , shadow_pass , passwd ,
804- logdetail );
818+ result = ( * DatabricksAuthentication_hook )
819+ ( port , passwd , & skip_password_auth , ( const char * * ) logdetail );
805820 }
806821 else
822+ {
823+ /* If hook is not set, do the password auth by default */
824+ skip_password_auth = false;
807825 result = STATUS_ERROR ;
826+ }
808827
809- if (result != STATUS_OK && DatabricksAuthentication_hook )
810- {
811- elog (LOG , "Calling DatabricksAuthentication_hook" );
828+ elog (DEBUG1 , "Databricks: after authentication hook" );
812829
813- result = (* DatabricksAuthentication_hook )(port , passwd );
830+ /* only try PG password auth if the hook didn't return STATUS_OK and */
831+ /* the hook set the skip_password_auth flag to false */
832+ if (result != STATUS_OK && !skip_password_auth )
833+ {
834+ shadow_pass = get_role_password (port -> user_name , logdetail );
835+ if (shadow_pass )
836+ {
837+ result = plain_crypt_verify (port -> user_name , shadow_pass , passwd ,
838+ logdetail );
839+ }
840+ else
841+ result = STATUS_ERROR ;
814842
815- elog (LOG , "DatabricksAuthentication_hook returned: %d" , result );
843+ if (shadow_pass )
844+ pfree (shadow_pass );
816845 }
817-
818- if (shadow_pass )
819- pfree (shadow_pass );
846+ /* END NEON */
820847 pfree (passwd );
821848
822849 if (result == STATUS_OK )
0 commit comments