7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.24 1998/01/29 03:23:05 scrappy Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.25 1998/01/31 20:12:06 scrappy Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -47,6 +47,7 @@ static void handle_krb5_auth(Port *port);
47
47
static void handle_password_auth (Port * port );
48
48
static void readPasswordPacket (char * arg , PacketLen len , char * pkt );
49
49
static void pg_passwordv0_recvauth (char * arg , PacketLen len , char * pkt );
50
+ static int checkPassword (Port * port , char * user , char * password );
50
51
static int old_be_recvauth (Port * port );
51
52
static int map_old_to_new (Port * port , UserAuth old , int status );
52
53
@@ -346,19 +347,19 @@ static void pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt)
346
347
347
348
cp = start = pp -> data ;
348
349
349
- while (len > 0 )
350
- if (* cp ++ == '\0' )
351
- {
352
- if (user == NULL )
353
- user = start ;
354
- else
350
+ while (len -- > 0 )
351
+ if (* cp ++ == '\0' )
355
352
{
356
- password = start ;
357
- break ;
358
- }
353
+ if (user == NULL )
354
+ user = start ;
355
+ else
356
+ {
357
+ password = start ;
358
+ break ;
359
+ }
359
360
360
- start = cp ;
361
- }
361
+ start = cp ;
362
+ }
362
363
363
364
if (user == NULL || password == NULL )
364
365
{
@@ -369,9 +370,25 @@ static void pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt)
369
370
370
371
auth_failed (port );
371
372
}
372
- else if (map_old_to_new (port , uaPassword ,
373
- verify_password (port -> auth_arg , user , password )) != STATUS_OK )
374
- auth_failed (port );
373
+ else
374
+ {
375
+ int status ;
376
+ UserAuth saved ;
377
+
378
+ /* Check the password. */
379
+
380
+ saved = port -> auth_method ;
381
+ port -> auth_method = uaPassword ;
382
+
383
+ status = checkPassword (port , user , password );
384
+
385
+ port -> auth_method = saved ;
386
+
387
+ /* Adjust the result if necessary. */
388
+
389
+ if (map_old_to_new (port , uaPassword , status ) != STATUS_OK )
390
+ auth_failed (port );
391
+ }
375
392
}
376
393
377
394
@@ -579,24 +596,28 @@ static void readPasswordPacket(char *arg, PacketLen len, char *pkt)
579
596
580
597
StrNCpy (password , ((PasswordPacket * )pkt )-> passwd , len );
581
598
582
- /*
583
- * Use the local flat password file if clear passwords are used and the
584
- * file is specified. Otherwise use the password in the pg_user table,
585
- * encrypted or not.
586
- */
587
-
588
- if (port -> auth_method == uaPassword && port -> auth_arg [0 ] != '\0' )
589
- {
590
- if (verify_password (port -> auth_arg , port -> user , password ) != STATUS_OK )
591
- auth_failed (port );
592
- }
593
- else if (crypt_verify (port , port -> user , password ) != STATUS_OK )
599
+ if (checkPassword (port , port -> user , password ) != STATUS_OK )
594
600
auth_failed (port );
595
601
else
596
602
sendAuthRequest (port , AUTH_REQ_OK , handle_done_auth );
597
603
}
598
604
599
605
606
+ /*
607
+ * Use the local flat password file if clear passwords are used and the file is
608
+ * specified. Otherwise use the password in the pg_user table, encrypted or
609
+ * not.
610
+ */
611
+
612
+ static int checkPassword (Port * port , char * user , char * password )
613
+ {
614
+ if (port -> auth_method == uaPassword && port -> auth_arg [0 ] != '\0' )
615
+ return verify_password (port -> auth_arg , user , password );
616
+
617
+ return crypt_verify (port , user , password );
618
+ }
619
+
620
+
600
621
/*
601
622
* Server demux routine for incoming authentication information for protocol
602
623
* version 0.
0 commit comments