36
36
* Global authentication functions
37
37
*----------------------------------------------------------------
38
38
*/
39
- static void sendAuthRequest (Port * port , AuthRequest areq );
39
+ static void sendAuthRequest (Port * port , AuthRequest areq , char * extradata ,
40
+ int extralen );
40
41
static void auth_failed (Port * port , int status , char * logdetail );
41
42
static char * recv_password_packet (Port * port );
42
43
static int recv_and_check_password_packet (Port * port , char * * logdetail );
@@ -498,7 +499,7 @@ ClientAuthentication(Port *port)
498
499
499
500
case uaGSS :
500
501
#ifdef ENABLE_GSS
501
- sendAuthRequest (port , AUTH_REQ_GSS );
502
+ sendAuthRequest (port , AUTH_REQ_GSS , NULL , 0 );
502
503
status = pg_GSS_recvauth (port );
503
504
#else
504
505
Assert (false);
@@ -507,7 +508,7 @@ ClientAuthentication(Port *port)
507
508
508
509
case uaSSPI :
509
510
#ifdef ENABLE_SSPI
510
- sendAuthRequest (port , AUTH_REQ_SSPI );
511
+ sendAuthRequest (port , AUTH_REQ_SSPI , NULL , 0 );
511
512
status = pg_SSPI_recvauth (port );
512
513
#else
513
514
Assert (false);
@@ -531,12 +532,13 @@ ClientAuthentication(Port *port)
531
532
ereport (FATAL ,
532
533
(errcode (ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION ),
533
534
errmsg ("MD5 authentication is not supported when \"db_user_namespace\" is enabled" )));
534
- sendAuthRequest (port , AUTH_REQ_MD5 );
535
+ /* include the salt to use for computing the response */
536
+ sendAuthRequest (port , AUTH_REQ_MD5 , port -> md5Salt , 4 );
535
537
status = recv_and_check_password_packet (port , & logdetail );
536
538
break ;
537
539
538
540
case uaPassword :
539
- sendAuthRequest (port , AUTH_REQ_PASSWORD );
541
+ sendAuthRequest (port , AUTH_REQ_PASSWORD , NULL , 0 );
540
542
status = recv_and_check_password_packet (port , & logdetail );
541
543
break ;
542
544
@@ -583,7 +585,7 @@ ClientAuthentication(Port *port)
583
585
(* ClientAuthentication_hook ) (port , status );
584
586
585
587
if (status == STATUS_OK )
586
- sendAuthRequest (port , AUTH_REQ_OK );
588
+ sendAuthRequest (port , AUTH_REQ_OK , NULL , 0 );
587
589
else
588
590
auth_failed (port , status , logdetail );
589
591
}
@@ -593,36 +595,16 @@ ClientAuthentication(Port *port)
593
595
* Send an authentication request packet to the frontend.
594
596
*/
595
597
static void
596
- sendAuthRequest (Port * port , AuthRequest areq )
598
+ sendAuthRequest (Port * port , AuthRequest areq , char * extradata , int extralen )
597
599
{
598
600
StringInfoData buf ;
599
601
600
602
CHECK_FOR_INTERRUPTS ();
601
603
602
604
pq_beginmessage (& buf , 'R' );
603
605
pq_sendint (& buf , (int32 ) areq , sizeof (int32 ));
604
-
605
- /* Add the salt for encrypted passwords. */
606
- if (areq == AUTH_REQ_MD5 )
607
- pq_sendbytes (& buf , port -> md5Salt , 4 );
608
-
609
- #if defined(ENABLE_GSS ) || defined(ENABLE
ED4F
_SSPI )
610
-
611
- /*
612
- * Add the authentication data for the next step of the GSSAPI or SSPI
613
- * negotiation.
614
- */
615
- else if (areq == AUTH_REQ_GSS_CONT )
616
- {
617
- if (port -> gss -> outbuf .length > 0 )
618
- {
619
- elog (DEBUG4 , "sending GSS token of length %u" ,
620
- (unsigned int ) port -> gss -> outbuf .length );
621
-
622
- pq_sendbytes (& buf , port -> gss -> outbuf .value , port -> gss -> outbuf .length );
623
- }
624
- }
625
- #endif
606
+ if (extralen > 0 )
607
+ pq_sendbytes (& buf , extradata , extralen );
626
608
627
609
pq_endmessage (& buf );
628
610
@@ -934,7 +916,8 @@ pg_GSS_recvauth(Port *port)
934
916
elog (DEBUG4 , "sending GSS response token of length %u" ,
935
917
(unsigned int ) port -> gss -> outbuf .length );
936
918
937
- sendAuthRequest (port , AUTH_REQ_GSS_CONT );
919
+ sendAuthRequest (port , AUTH_REQ_GSS_CONT ,
920
+ port -> gss -> outbuf .value , port -> gss -> outbuf .length );
938
921
939
922
gss_release_buffer (& lmin_s , & port -> gss -> outbuf );
940
923
}
@@ -1179,7 +1162,8 @@ pg_SSPI_recvauth(Port *port)
1179
1162
port -> gss -> outbuf .length = outbuf .pBuffers [0 ].cbBuffer ;
1180
1163
port -> gss -> outbuf .value = outbuf .pBuffers [0 ].pvBuffer ;
1181
1164
1182
- sendAuthRequest (port , AUTH_REQ_GSS_CONT );
1165
+ sendAuthRequest (port , AUTH_REQ_GSS_CONT ,
1166
+ port -> gss -> outbuf .value , port -> gss -> outbuf .length );
1183
1167
1184
1168
FreeContextBuffer (outbuf .pBuffers [0 ].pvBuffer );
1185
1169
}
@@ -1807,7 +1791,7 @@ pam_passwd_conv_proc(int num_msg, const struct pam_message ** msg,
1807
1791
* let's go ask the client to send a password, which we
1808
1792
* then stuff into PAM.
1809
1793
*/
1810
- sendAuthRequest (pam_port_cludge , AUTH_REQ_PASSWORD );
1794
+ sendAuthRequest (pam_port_cludge , AUTH_REQ_PASSWORD , NULL , 0 );
1811
1795
passwd = recv_password_packet (pam_port_cludge );
1812
1796
if (passwd == NULL )
1813
1797
{
@@ -2137,7 +2121,7 @@ CheckLDAPAuth(Port *port)
2137
2121
if (port -> hba -> ldapport == 0 )
2138
2122
port -> hba -> ldapport = LDAP_PORT ;
2139
2123
2140
- sendAuthRequest (port , AUTH_REQ_PASSWORD );
2124
+ sendAuthRequest (port , AUTH_REQ_PASSWORD , NULL , 0 );
2141
2125
2142
2126
passwd = recv_password_packet (port );
2143
2127
if (passwd == NULL )
@@ -2497,7 +2481,7 @@ CheckRADIUSAuth(Port *port)
2497
2481
identifier = port -> hba -> radiusidentifier ;
2498
2482
2499
2483
/* Send regular password request to client, and get the response */
2500
- sendAuthRequest (port , AUTH_REQ_PASSWORD );
2484
+ sendAuthRequest (port , AUTH_REQ_PASSWORD , NULL , 0 );
2501
2485
2502
2486
passwd = recv_password_packet (port );
2503
2487
if (passwd == NULL )
0 commit comments