Reorder MD5/crypt so MD5 comes first in the code.

This commit is contained in:
Bruce Momjian 2001-08-17 15:40:07 +00:00
parent 2637f887e7
commit 0a3094b6f3
3 changed files with 45 additions and 45 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.60 2001/08/17 02:59:19 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.61 2001/08/17 15:40:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -420,8 +420,8 @@ auth_failed(Port *port)
authmethod = "IDENT";
break;
case uaPassword:
case uaCrypt:
case uaMD5:
case uaCrypt:
authmethod = "Password";
break;
}
@ -501,13 +501,13 @@ ClientAuthentication(Port *port)
status = recv_and_check_password_packet(port);
break;
case uaCrypt:
sendAuthRequest(port, AUTH_REQ_CRYPT);
case uaMD5:
sendAuthRequest(port, AUTH_REQ_MD5);
status = recv_and_check_password_packet(port);
break;
case uaMD5:
sendAuthRequest(port, AUTH_REQ_MD5);
case uaCrypt:
sendAuthRequest(port, AUTH_REQ_CRYPT);
status = recv_and_check_password_packet(port);
break;
@ -643,8 +643,8 @@ map_old_to_new(Port *port, UserAuth old, int status)
{
switch (port->auth_method)
{
case uaCrypt:
case uaMD5:
case uaCrypt:
case uaReject:
status = STATUS_ERROR;
break;

View File

@ -9,7 +9,7 @@
* Dec 17, 1997 - Todd A. Brandys
* Orignal Version Completed.
*
* $Id: crypt.c,v 1.36 2001/08/17 03:09:31 momjian Exp $
* $Id: crypt.c,v 1.37 2001/08/17 15:40:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -294,13 +294,6 @@ md5_crypt_verify(const Port *port, const char *user, const char *pgpass)
*/
switch (port->auth_method)
{
case uaCrypt:
{
char salt[3];
StrNCpy(salt, port->cryptSalt,3);
crypt_pwd = crypt(passwd, salt);
break;
}
case uaMD5:
crypt_pwd = palloc(MD5_PASSWD_LEN+1);
if (isMD5(passwd))
@ -334,6 +327,13 @@ md5_crypt_verify(const Port *port, const char *user, const char *pgpass)
pfree(crypt_pwd2);
}
break;
case uaCrypt:
{
char salt[3];
StrNCpy(salt, port->cryptSalt,3);
crypt_pwd = crypt(passwd, salt);
break;
}
default:
crypt_pwd = passwd;
break;

View File

@ -10,7 +10,7 @@
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.54 2001/08/17 15:11:15 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.55 2001/08/17 15:40:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -438,6 +438,33 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
switch (areq)
{
case AUTH_REQ_MD5:
{
char *crypt_pwd2;
if (!(crypt_pwd = malloc(MD5_PASSWD_LEN+1)) ||
!(crypt_pwd2 = malloc(MD5_PASSWD_LEN+1)))
{
perror("malloc");
return STATUS_ERROR;
}
if (!EncryptMD5(password, conn->pguser,
strlen(conn->pguser), crypt_pwd2))
{
free(crypt_pwd);
free(crypt_pwd2);
return STATUS_ERROR;
}
if (!EncryptMD5(crypt_pwd2 + strlen("md5"), conn->md5Salt,
sizeof(conn->md5Salt), crypt_pwd))
{
free(crypt_pwd);
free(crypt_pwd2);
return STATUS_ERROR;
}
free(crypt_pwd2);
break;
}
case AUTH_REQ_CRYPT:
{
char salt[3];
@ -446,33 +473,6 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
crypt_pwd = crypt(password, salt);
break;
}
case AUTH_REQ_MD5:
{
char *crypt_pwd2;
if (!(crypt_pwd = malloc(MD5_PASSWD_LEN+1)) ||
!(crypt_pwd2 = malloc(MD5_PASSWD_LEN+1)))
{
perror("malloc");
return STATUS_ERROR;
}
if (!EncryptMD5(password, conn->pguser,
strlen(conn->pguser), crypt_pwd2))
{
free(crypt_pwd);
free(crypt_pwd2);
return STATUS_ERROR;
}
if (!EncryptMD5(crypt_pwd2 + strlen("md5"), conn->md5Salt,
sizeof(conn->md5Salt), crypt_pwd))
{
free(crypt_pwd);
free(crypt_pwd2);
return STATUS_ERROR;
}
free(crypt_pwd2);
break;
}
default:
/* discard const so we can assign it */
crypt_pwd = (char *)password;
@ -535,9 +535,9 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
return STATUS_ERROR;
#endif
case AUTH_REQ_PASSWORD:
case AUTH_REQ_CRYPT:
case AUTH_REQ_MD5:
case AUTH_REQ_CRYPT:
case AUTH_REQ_PASSWORD:
if (password == NULL || *password == '\0')
{
(void) sprintf(PQerrormsg,