summaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-auth.c
diff options
context:
space:
mode:
authorPeter Eisentraut2012-03-06 21:20:43 +0000
committerPeter Eisentraut2012-03-06 21:21:43 +0000
commite685a8e6651b0e55996e6eba6917302607866793 (patch)
treea44f78ee94ec5ebdc6fe6fc7aac005734d28b114 /src/interfaces/libpq/fe-auth.c
parent19dbc3463161a142537ba5c569c8e6a073a318de (diff)
libpq: Small code clarification, and avoid casting away const
Diffstat (limited to 'src/interfaces/libpq/fe-auth.c')
-rw-r--r--src/interfaces/libpq/fe-auth.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c
index b7a3a814f04..7c7383cd9d5 100644
--- a/src/interfaces/libpq/fe-auth.c
+++ b/src/interfaces/libpq/fe-auth.c
@@ -739,7 +739,8 @@ static int
pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
{
int ret;
- char *crypt_pwd;
+ char *crypt_pwd = NULL;
+ const char *pwd_to_send;
/* Encrypt the password if needed. */
@@ -771,21 +772,22 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
free(crypt_pwd);
return STATUS_ERROR;
}
+
+ pwd_to_send = crypt_pwd;
break;
}
case AUTH_REQ_PASSWORD:
- /* discard const so we can assign it */
- crypt_pwd = (char *) password;
+ pwd_to_send = password;
break;
default:
return STATUS_ERROR;
}
/* Packet has a message type as of protocol 3.0 */
if (PG_PROTOCOL_MAJOR(conn->pversion) >= 3)
- ret = pqPacketSend(conn, 'p', crypt_pwd, strlen(crypt_pwd) + 1);
+ ret = pqPacketSend(conn, 'p', pwd_to_send, strlen(pwd_to_send) + 1);
else
- ret = pqPacketSend(conn, 0, crypt_pwd, strlen(crypt_pwd) + 1);
- if (areq == AUTH_REQ_MD5)
+ ret = pqPacketSend(conn, 0, pwd_to_send, strlen(pwd_to_send) + 1);
+ if (crypt_pwd)
free(crypt_pwd);
return ret;
}