Commit d330f155 authored by Tom Lane's avatar Tom Lane

Clean up libpq's pollution of application namespace by renaming the

exported routines of ip.c, md5.c, and fe-auth.c to begin with 'pg_'.
Also get rid of the vestigial fe_setauthsvc/fe_getauthsvc routines
altogether.
parent 8ffdcbf2
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.193 2005/10/13 17:55:18 momjian Exp $ $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.194 2005/10/17 16:24:18 tgl Exp $
--> -->
<chapter id="libpq"> <chapter id="libpq">
...@@ -4049,15 +4049,13 @@ passed around freely between threads. ...@@ -4049,15 +4049,13 @@ passed around freely between threads.
<para> <para>
The deprecated functions The deprecated functions
<function>PQrequestCancel</function>, <function>PQrequestCancel</function> and
<function>PQoidStatus</function> and <function>PQoidStatus</function>
<function>fe_setauthsvc</function>
are not thread-safe and should not be used in multithread programs. are not thread-safe and should not be used in multithread programs.
<function>PQrequestCancel</function> can be replaced by <function>PQrequestCancel</function> can be replaced by
<function>PQcancel</function>. <function>PQcancel</function>.
<function>PQoidStatus</function> can be replaced by <function>PQoidStatus</function> can be replaced by
<function>PQoidValue</function>. <function>PQoidValue</function>.
There is no good reason to call <function>fe_setauthsvc</function> at all.
</para> </para>
<para> <para>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.161 2005/10/15 02:49:16 momjian Exp $ * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.162 2005/10/17 16:24:18 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -313,8 +313,8 @@ CreateRole(CreateRoleStmt *stmt) ...@@ -313,8 +313,8 @@ CreateRole(CreateRoleStmt *stmt)
DirectFunctionCall1(textin, CStringGetDatum(password)); DirectFunctionCall1(textin, CStringGetDatum(password));
else else
{ {
if (!EncryptMD5(password, stmt->role, strlen(stmt->role), if (!pg_md5_encrypt(password, stmt->role, strlen(stmt->role),
encrypted_password)) encrypted_password))
elog(ERROR, "password encryption failed"); elog(ERROR, "password encryption failed");
new_record[Anum_pg_authid_rolpassword - 1] = new_record[Anum_pg_authid_rolpassword - 1] =
DirectFunctionCall1(textin, CStringGetDatum(encrypted_password)); DirectFunctionCall1(textin, CStringGetDatum(encrypted_password));
...@@ -642,8 +642,8 @@ AlterRole(AlterRoleStmt *stmt) ...@@ -642,8 +642,8 @@ AlterRole(AlterRoleStmt *stmt)
DirectFunctionCall1(textin, CStringGetDatum(password)); DirectFunctionCall1(textin, CStringGetDatum(password));
else else
{ {
if (!EncryptMD5(password, stmt->role, strlen(stmt->role), if (!pg_md5_encrypt(password, stmt->role, strlen(stmt->role),
encrypted_password)) encrypted_password))
elog(ERROR, "password encryption failed"); elog(ERROR, "password encryption failed");
new_record[Anum_pg_authid_rolpassword - 1] = new_record[Anum_pg_authid_rolpassword - 1] =
DirectFunctionCall1(textin, CStringGetDatum(encrypted_password)); DirectFunctionCall1(textin, CStringGetDatum(encrypted_password));
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.131 2005/10/15 21:27:19 momjian Exp $ * $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.132 2005/10/17 16:24:19 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -376,10 +376,10 @@ ClientAuthentication(Port *port) ...@@ -376,10 +376,10 @@ ClientAuthentication(Port *port)
{ {
char hostinfo[NI_MAXHOST]; char hostinfo[NI_MAXHOST];
getnameinfo_all(&port->raddr.addr, port->raddr.salen, pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
hostinfo, sizeof(hostinfo), hostinfo, sizeof(hostinfo),
NULL, 0, NULL, 0,
NI_NUMERICHOST); NI_NUMERICHOST);
#ifdef USE_SSL #ifdef USE_SSL
ereport(FATAL, ereport(FATAL,
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/libpq/crypt.c,v 1.66 2005/10/15 02:49:17 momjian Exp $ * $PostgreSQL: pgsql/src/backend/libpq/crypt.c,v 1.67 2005/10/17 16:24:19 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -76,9 +76,9 @@ md5_crypt_verify(const Port *port, const char *role, char *client_pass) ...@@ -76,9 +76,9 @@ md5_crypt_verify(const Port *port, const char *role, char *client_pass)
if (isMD5(shadow_pass)) if (isMD5(shadow_pass))
{ {
/* stored password already encrypted, only do salt */ /* stored password already encrypted, only do salt */
if (!EncryptMD5(shadow_pass + strlen("md5"), if (!pg_md5_encrypt(shadow_pass + strlen("md5"),
(char *) port->md5Salt, (char *) port->md5Salt,
sizeof(port->md5Salt), crypt_pwd)) sizeof(port->md5Salt), crypt_pwd))
{ {
pfree(crypt_pwd); pfree(crypt_pwd);
return STATUS_ERROR; return STATUS_ERROR;
...@@ -89,19 +89,19 @@ md5_crypt_verify(const Port *port, const char *role, char *client_pass) ...@@ -89,19 +89,19 @@ md5_crypt_verify(const Port *port, const char *role, char *client_pass)
/* stored password is plain, double-encrypt */ /* stored password is plain, double-encrypt */
char *crypt_pwd2 = palloc(MD5_PASSWD_LEN + 1); char *crypt_pwd2 = palloc(MD5_PASSWD_LEN + 1);
if (!EncryptMD5(shadow_pass, if (!pg_md5_encrypt(shadow_pass,
port->user_name, port->user_name,
strlen(port->user_name), strlen(port->user_name),
crypt_pwd2)) crypt_pwd2))
{ {
pfree(crypt_pwd); pfree(crypt_pwd);
pfree(crypt_pwd2); pfree(crypt_pwd2);
return STATUS_ERROR; return STATUS_ERROR;
} }
if (!EncryptMD5(crypt_pwd2 + strlen("md5"), if (!pg_md5_encrypt(crypt_pwd2 + strlen("md5"),
port->md5Salt, port->md5Salt,
sizeof(port->md5Salt), sizeof(port->md5Salt),
crypt_pwd)) crypt_pwd))
{ {
pfree(crypt_pwd); pfree(crypt_pwd);
pfree(crypt_pwd2); pfree(crypt_pwd2);
...@@ -123,10 +123,10 @@ md5_crypt_verify(const Port *port, const char *role, char *client_pass) ...@@ -123,10 +123,10 @@ md5_crypt_verify(const Port *port, const char *role, char *client_pass)
{ {
/* Encrypt user-supplied password to match stored MD5 */ /* Encrypt user-supplied password to match stored MD5 */
crypt_client_pass = palloc(MD5_PASSWD_LEN + 1); crypt_client_pass = palloc(MD5_PASSWD_LEN + 1);
if (!EncryptMD5(client_pass, if (!pg_md5_encrypt(client_pass,
port->user_name, port->user_name,
strlen(port->user_name), strlen(port->user_name),
crypt_client_pass)) crypt_client_pass))
{ {
pfree(crypt_client_pass); pfree(crypt_client_pass);
return STATUS_ERROR; return STATUS_ERROR;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.148 2005/10/15 02:49:17 momjian Exp $ * $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.149 2005/10/17 16:24:19 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -756,7 +756,7 @@ parse_hba(List *line, int line_num, hbaPort *port, ...@@ -756,7 +756,7 @@ parse_hba(List *line, int line_num, hbaPort *port,
hints.ai_addr = NULL; hints.ai_addr = NULL;
hints.ai_next = NULL; hints.ai_next = NULL;
ret = getaddrinfo_all(token, NULL, &hints, &gai_result); ret = pg_getaddrinfo_all(token, NULL, &hints, &gai_result);
if (ret || !gai_result) if (ret || !gai_result)
{ {
ereport(LOG, ereport(LOG,
...@@ -767,7 +767,7 @@ parse_hba(List *line, int line_num, hbaPort *port, ...@@ -767,7 +767,7 @@ parse_hba(List *line, int line_num, hbaPort *port,
if (cidr_slash) if (cidr_slash)
*cidr_slash = '/'; *cidr_slash = '/';
if (gai_result) if (gai_result)
freeaddrinfo_all(hints.ai_family, gai_result); pg_freeaddrinfo_all(hints.ai_family, gai_result);
goto hba_other_error; goto hba_other_error;
} }
...@@ -775,12 +775,13 @@ parse_hba(List *line, int line_num, hbaPort *port, ...@@ -775,12 +775,13 @@ parse_hba(List *line, int line_num, hbaPort *port,
*cidr_slash = '/'; *cidr_slash = '/';
memcpy(&addr, gai_result->ai_addr, gai_result->ai_addrlen); memcpy(&addr, gai_result->ai_addr, gai_result->ai_addrlen);
freeaddrinfo_all(hints.ai_family, gai_result); pg_freeaddrinfo_all(hints.ai_family, gai_result);
/* Get the netmask */ /* Get the netmask */
if (cidr_slash) if (cidr_slash)
{ {
if (SockAddr_cidr_mask(&mask, cidr_slash + 1, addr.ss_family) < 0) if (pg_sockaddr_cidr_mask(&mask, cidr_slash + 1,
addr.ss_family) < 0)
goto hba_syntax; goto hba_syntax;
} }
else else
...@@ -791,7 +792,7 @@ parse_hba(List *line, int line_num, hbaPort *port, ...@@ -791,7 +792,7 @@ parse_hba(List *line, int line_num, hbaPort *port,
goto hba_syntax; goto hba_syntax;
token = lfirst(line_item); token = lfirst(line_item);
ret = getaddrinfo_all(token, NULL, &hints, &gai_result); ret = pg_getaddrinfo_all(token, NULL, &hints, &gai_result);
if (ret || !gai_result) if (ret || !gai_result)
{ {
ereport(LOG, ereport(LOG,
...@@ -800,12 +801,12 @@ parse_hba(List *line, int line_num, hbaPort *port, ...@@ -800,12 +801,12 @@ parse_hba(List *line, int line_num, hbaPort *port,
token, HbaFileName, line_num, token, HbaFileName, line_num,
gai_strerror(ret)))); gai_strerror(ret))));
if (gai_result) if (gai_result)
freeaddrinfo_all(hints.ai_family, gai_result); pg_freeaddrinfo_all(hints.ai_family, gai_result);
goto hba_other_error; goto hba_other_error;
} }
memcpy(&mask, gai_result->ai_addr, gai_result->ai_addrlen); memcpy(&mask, gai_result->ai_addr, gai_result->ai_addrlen);
freeaddrinfo_all(hints.ai_family, gai_result); pg_freeaddrinfo_all(hints.ai_family, gai_result);
if (addr.ss_family != mask.ss_family) if (addr.ss_family != mask.ss_family)
{ {
...@@ -828,8 +829,8 @@ parse_hba(List *line, int line_num, hbaPort *port, ...@@ -828,8 +829,8 @@ parse_hba(List *line, int line_num, hbaPort *port,
if (addr.ss_family == AF_INET && if (addr.ss_family == AF_INET &&
port->raddr.addr.ss_family == AF_INET6) port->raddr.addr.ss_family == AF_INET6)
{ {
promote_v4_to_v6_addr(&addr); pg_promote_v4_to_v6_addr(&addr);
promote_v4_to_v6_mask(&mask); pg_promote_v4_to_v6_mask(&mask);
} }
else else
#endif /* HAVE_IPV6 */ #endif /* HAVE_IPV6 */
...@@ -840,7 +841,7 @@ parse_hba(List *line, int line_num, hbaPort *port, ...@@ -840,7 +841,7 @@ parse_hba(List *line, int line_num, hbaPort *port,
} }
/* Ignore line if client port is not in the matching addr range. */ /* Ignore line if client port is not in the matching addr range. */
if (!rangeSockAddr(&port->raddr.addr, &addr, &mask)) if (!pg_range_sockaddr(&port->raddr.addr, &addr, &mask))
return; return;
/* Read the rest of the line. */ /* Read the rest of the line. */
...@@ -1296,14 +1297,14 @@ ident_inet(const SockAddr remote_addr, ...@@ -1296,14 +1297,14 @@ ident_inet(const SockAddr remote_addr,
* Might look a little weird to first convert it to text and then back to * Might look a little weird to first convert it to text and then back to
* sockaddr, but it's protocol independent. * sockaddr, but it's protocol independent.
*/ */
getnameinfo_all(&remote_addr.addr, remote_addr.salen, pg_getnameinfo_all(&remote_addr.addr, remote_addr.salen,
remote_addr_s, sizeof(remote_addr_s), remote_addr_s, sizeof(remote_addr_s),
remote_port, sizeof(remote_port), remote_port, sizeof(remote_port),
NI_NUMERICHOST | NI_NUMERICSERV); NI_NUMERICHOST | NI_NUMERICSERV);
getnameinfo_all(&local_addr.addr, local_addr.salen, pg_getnameinfo_all(&local_addr.addr, local_addr.salen,
local_addr_s, sizeof(local_addr_s), local_addr_s, sizeof(local_addr_s),
local_port, sizeof(local_port), local_port, sizeof(local_port),
NI_NUMERICHOST | NI_NUMERICSERV); NI_NUMERICHOST | NI_NUMERICSERV);
snprintf(ident_port, sizeof(ident_port), "%d", IDENT_PORT); snprintf(ident_port, sizeof(ident_port), "%d", IDENT_PORT);
hints.ai_flags = AI_NUMERICHOST; hints.ai_flags = AI_NUMERICHOST;
...@@ -1314,11 +1315,11 @@ ident_inet(const SockAddr remote_addr, ...@@ -1314,11 +1315,11 @@ ident_inet(const SockAddr remote_addr,
hints.ai_canonname = NULL; hints.ai_canonname = NULL;
hints.ai_addr = NULL; hints.ai_addr = NULL;
hints.ai_next = NULL; hints.ai_next = NULL;
rc = getaddrinfo_all(remote_addr_s, ident_port, &hints, &ident_serv); rc = pg_getaddrinfo_all(remote_addr_s, ident_port, &hints, &ident_serv);
if (rc || !ident_serv) if (rc || !ident_serv)
{ {
if (ident_serv) if (ident_serv)
freeaddrinfo_all(hints.ai_family, ident_serv); pg_freeaddrinfo_all(hints.ai_family, ident_serv);
return false; /* we don't expect this to happen */ return false; /* we don't expect this to happen */
} }
...@@ -1330,11 +1331,11 @@ ident_inet(const SockAddr remote_addr, ...@@ -1330,11 +1331,11 @@ ident_inet(const SockAddr remote_addr,
hints.ai_canonname = NULL; hints.ai_canonname = NULL;
hints.ai_addr = NULL; hints.ai_addr = NULL;
hints.ai_next = NULL; hints.ai_next = NULL;
rc = getaddrinfo_all(local_addr_s, NULL, &hints, &la); rc = pg_getaddrinfo_all(local_addr_s, NULL, &hints, &la);
if (rc || !la) if (rc || !la)
{ {
if (la) if (la)
freeaddrinfo_all(hints.ai_family, la); pg_freeaddrinfo_all(hints.ai_family, la);
return false; /* we don't expect this to happen */ return false; /* we don't expect this to happen */
} }
...@@ -1422,8 +1423,8 @@ ident_inet(const SockAddr remote_addr, ...@@ -1422,8 +1423,8 @@ ident_inet(const SockAddr remote_addr,
ident_inet_done: ident_inet_done:
if (sock_fd >= 0) if (sock_fd >= 0)
closesocket(sock_fd); closesocket(sock_fd);
freeaddrinfo_all(remote_addr.addr.ss_family, ident_serv); pg_freeaddrinfo_all(remote_addr.addr.ss_family, ident_serv);
freeaddrinfo_all(local_addr.addr.ss_family, la); pg_freeaddrinfo_all(local_addr.addr.ss_family, la);
return ident_return; return ident_return;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/libpq/ip.c,v 1.31 2004/12/31 21:59:50 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/libpq/ip.c,v 1.32 2005/10/17 16:24:19 tgl Exp $
* *
* This file and the IPV6 implementation were initially provided by * This file and the IPV6 implementation were initially provided by
* Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design * Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design
...@@ -38,22 +38,22 @@ ...@@ -38,22 +38,22 @@
#include "libpq/ip.h" #include "libpq/ip.h"
static int rangeSockAddrAF_INET(const struct sockaddr_in * addr, static int range_sockaddr_AF_INET(const struct sockaddr_in *addr,
const struct sockaddr_in * netaddr, const struct sockaddr_in *netaddr,
const struct sockaddr_in * netmask); const struct sockaddr_in *netmask);
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
static int rangeSockAddrAF_INET6(const struct sockaddr_in6 * addr, static int range_sockaddr_AF_INET6(const struct sockaddr_in6 *addr,
const struct sockaddr_in6 * netaddr, const struct sockaddr_in6 *netaddr,
const struct sockaddr_in6 * netmask); const struct sockaddr_in6 *netmask);
#endif #endif
#ifdef HAVE_UNIX_SOCKETS #ifdef HAVE_UNIX_SOCKETS
static int getaddrinfo_unix(const char *path, static int getaddrinfo_unix(const char *path,
const struct addrinfo * hintsp, const struct addrinfo *hintsp,
struct addrinfo ** result); struct addrinfo **result);
static int getnameinfo_unix(const struct sockaddr_un * sa, int salen, static int getnameinfo_unix(const struct sockaddr_un *sa, int salen,
char *node, int nodelen, char *node, int nodelen,
char *service, int servicelen, char *service, int servicelen,
int flags); int flags);
...@@ -61,11 +61,11 @@ static int getnameinfo_unix(const struct sockaddr_un * sa, int salen, ...@@ -61,11 +61,11 @@ static int getnameinfo_unix(const struct sockaddr_un * sa, int salen,
/* /*
* getaddrinfo_all - get address info for Unix, IPv4 and IPv6 sockets * pg_getaddrinfo_all - get address info for Unix, IPv4 and IPv6 sockets
*/ */
int int
getaddrinfo_all(const char *hostname, const char *servname, pg_getaddrinfo_all(const char *hostname, const char *servname,
const struct addrinfo * hintp, struct addrinfo ** result) const struct addrinfo *hintp, struct addrinfo **result)
{ {
/* not all versions of getaddrinfo() zero *result on failure */ /* not all versions of getaddrinfo() zero *result on failure */
*result = NULL; *result = NULL;
...@@ -82,7 +82,7 @@ getaddrinfo_all(const char *hostname, const char *servname, ...@@ -82,7 +82,7 @@ getaddrinfo_all(const char *hostname, const char *servname,
/* /*
* freeaddrinfo_all - free addrinfo structures for IPv4, IPv6, or Unix * pg_freeaddrinfo_all - free addrinfo structures for IPv4, IPv6, or Unix
* *
* Note: the ai_family field of the original hint structure must be passed * Note: the ai_family field of the original hint structure must be passed
* so that we can tell whether the addrinfo struct was built by the system's * so that we can tell whether the addrinfo struct was built by the system's
...@@ -91,12 +91,12 @@ getaddrinfo_all(const char *hostname, const char *servname, ...@@ -91,12 +91,12 @@ getaddrinfo_all(const char *hostname, const char *servname,
* not safe to look at ai_family in the addrinfo itself. * not safe to look at ai_family in the addrinfo itself.
*/ */
void void
freeaddrinfo_all(int hint_ai_family, struct addrinfo * ai) pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
{ {
#ifdef HAVE_UNIX_SOCKETS #ifdef HAVE_UNIX_SOCKETS
if (hint_ai_family == AF_UNIX) if (hint_ai_family == AF_UNIX)
{ {
/* struct was built by getaddrinfo_unix (see getaddrinfo_all) */ /* struct was built by getaddrinfo_unix (see pg_getaddrinfo_all) */
while (ai != NULL) while (ai != NULL)
{ {
struct addrinfo *p = ai; struct addrinfo *p = ai;
...@@ -117,7 +117,7 @@ freeaddrinfo_all(int hint_ai_family, struct addrinfo * ai) ...@@ -117,7 +117,7 @@ freeaddrinfo_all(int hint_ai_family, struct addrinfo * ai)
/* /*
* getnameinfo_all - get name info for Unix, IPv4 and IPv6 sockets * pg_getnameinfo_all - get name info for Unix, IPv4 and IPv6 sockets
* *
* The API of this routine differs from the standard getnameinfo() definition * The API of this routine differs from the standard getnameinfo() definition
* in two ways: first, the addr parameter is declared as sockaddr_storage * in two ways: first, the addr parameter is declared as sockaddr_storage
...@@ -125,10 +125,10 @@ freeaddrinfo_all(int hint_ai_family, struct addrinfo * ai) ...@@ -125,10 +125,10 @@ freeaddrinfo_all(int hint_ai_family, struct addrinfo * ai)
* guaranteed to be filled with something even on failure return. * guaranteed to be filled with something even on failure return.
*/ */
int int
getnameinfo_all(const struct sockaddr_storage * addr, int salen, pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen,
char *node, int nodelen, char *node, int nodelen,
char *service, int servicelen, char *service, int servicelen,
int flags) int flags)
{ {
int rc; int rc;
...@@ -168,8 +168,8 @@ getnameinfo_all(const struct sockaddr_storage * addr, int salen, ...@@ -168,8 +168,8 @@ getnameinfo_all(const struct sockaddr_storage * addr, int salen,
* ------- * -------
*/ */
static int static int
getaddrinfo_unix(const char *path, const struct addrinfo * hintsp, getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
struct addrinfo ** result) struct addrinfo **result)
{ {
struct addrinfo hints; struct addrinfo hints;
struct addrinfo *aip; struct addrinfo *aip;
...@@ -234,7 +234,7 @@ getaddrinfo_unix(const char *path, const struct addrinfo * hintsp, ...@@ -234,7 +234,7 @@ getaddrinfo_unix(const char *path, const struct addrinfo * hintsp,
* Convert an address to a hostname. * Convert an address to a hostname.
*/ */
static int static int
getnameinfo_unix(const struct sockaddr_un * sa, int salen, getnameinfo_unix(const struct sockaddr_un *sa, int salen,
char *node, int nodelen, char *node, int nodelen,
char *service, int servicelen, char *service, int servicelen,
int flags) int flags)
...@@ -267,38 +267,39 @@ getnameinfo_unix(const struct sockaddr_un * sa, int salen, ...@@ -267,38 +267,39 @@ getnameinfo_unix(const struct sockaddr_un * sa, int salen,
return 0; return 0;
} }
#endif /* HAVE_UNIX_SOCKETS */ #endif /* HAVE_UNIX_SOCKETS */
/* /*
* rangeSockAddr - is addr within the subnet specified by netaddr/netmask ? * pg_range_sockaddr - is addr within the subnet specified by netaddr/netmask ?
* *
* Note: caller must already have verified that all three addresses are * Note: caller must already have verified that all three addresses are
* in the same address family; and AF_UNIX addresses are not supported. * in the same address family; and AF_UNIX addresses are not supported.
*/ */
int int
rangeSockAddr(const struct sockaddr_storage * addr, pg_range_sockaddr(const struct sockaddr_storage *addr,
const struct sockaddr_storage * netaddr, const struct sockaddr_storage *netaddr,
const struct sockaddr_storage * netmask) const struct sockaddr_storage *netmask)
{ {
if (addr->ss_family == AF_INET) if (addr->ss_family == AF_INET)
return rangeSockAddrAF_INET((struct sockaddr_in *) addr, return range_sockaddr_AF_INET((struct sockaddr_in *) addr,
(struct sockaddr_in *) netaddr, (struct sockaddr_in *) netaddr,
(struct sockaddr_in *) netmask); (struct sockaddr_in *) netmask);
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
else if (addr->ss_family == AF_INET6) else if (addr->ss_family == AF_INET6)
return rangeSockAddrAF_INET6((struct sockaddr_in6 *) addr, return range_sockaddr_AF_INET6((struct sockaddr_in6 *) addr,
(struct sockaddr_in6 *) netaddr, (struct sockaddr_in6 *) netaddr,
(struct sockaddr_in6 *) netmask); (struct sockaddr_in6 *) netmask);
#endif #endif
else else
return 0; return 0;
} }
static int static int
rangeSockAddrAF_INET(const struct sockaddr_in * addr, range_sockaddr_AF_INET(const struct sockaddr_in *addr,
const struct sockaddr_in * netaddr, const struct sockaddr_in *netaddr,
const struct sockaddr_in * netmask) const struct sockaddr_in *netmask)
{ {
if (((addr->sin_addr.s_addr ^ netaddr->sin_addr.s_addr) & if (((addr->sin_addr.s_addr ^ netaddr->sin_addr.s_addr) &
netmask->sin_addr.s_addr) == 0) netmask->sin_addr.s_addr) == 0)
...@@ -309,10 +310,11 @@ rangeSockAddrAF_INET(const struct sockaddr_in * addr, ...@@ -309,10 +310,11 @@ rangeSockAddrAF_INET(const struct sockaddr_in * addr,
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
static int static int
rangeSockAddrAF_INET6(const struct sockaddr_in6 * addr, range_sockaddr_AF_INET6(const struct sockaddr_in6 *addr,
const struct sockaddr_in6 * netaddr, const struct sockaddr_in6 *netaddr,
const struct sockaddr_in6 * netmask) const struct sockaddr_in6 *netmask)
{ {
int i; int i;
...@@ -325,10 +327,11 @@ rangeSockAddrAF_INET6(const struct sockaddr_in6 * addr, ...@@ -325,10 +327,11 @@ rangeSockAddrAF_INET6(const struct sockaddr_in6 * addr,
return 1; return 1;
} }
#endif
#endif /* HAVE_IPV6 */
/* /*
* SockAddr_cidr_mask - make a network mask of the appropriate family * pg_sockaddr_cidr_mask - make a network mask of the appropriate family
* and required number of significant bits * and required number of significant bits
* *
* The resulting mask is placed in *mask, which had better be big enough. * The resulting mask is placed in *mask, which had better be big enough.
...@@ -336,7 +339,7 @@ rangeSockAddrAF_INET6(const struct sockaddr_in6 * addr, ...@@ -336,7 +339,7 @@ rangeSockAddrAF_INET6(const struct sockaddr_in6 * addr,
* Return value is 0 if okay, -1 if not. * Return value is 0 if okay, -1 if not.
*/ */
int int
SockAddr_cidr_mask(struct sockaddr_storage * mask, char *numbits, int family) pg_sockaddr_cidr_mask(struct sockaddr_storage *mask, char *numbits, int family)
{ {
long bits; long bits;
char *endptr; char *endptr;
...@@ -403,15 +406,15 @@ SockAddr_cidr_mask(struct sockaddr_storage * mask, char *numbits, int family) ...@@ -403,15 +406,15 @@ SockAddr_cidr_mask(struct sockaddr_storage * mask, char *numbits, int family)
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
/* /*
* promote_v4_to_v6_addr --- convert an AF_INET addr to AF_INET6, using * pg_promote_v4_to_v6_addr --- convert an AF_INET addr to AF_INET6, using
* the standard convention for IPv4 addresses mapped into IPv6 world * the standard convention for IPv4 addresses mapped into IPv6 world
* *
* The passed addr is modified in place; be sure it is large enough to * The passed addr is modified in place; be sure it is large enough to
* hold the result! Note that we only worry about setting the fields * hold the result! Note that we only worry about setting the fields
* that rangeSockAddr will look at. * that pg_range_sockaddr will look at.
*/ */
void void
promote_v4_to_v6_addr(struct sockaddr_storage * addr) pg_promote_v4_to_v6_addr(struct sockaddr_storage *addr)
{ {
struct sockaddr_in addr4; struct sockaddr_in addr4;
struct sockaddr_in6 addr6; struct sockaddr_in6 addr6;
...@@ -435,18 +438,18 @@ promote_v4_to_v6_addr(struct sockaddr_storage * addr) ...@@ -435,18 +438,18 @@ promote_v4_to_v6_addr(struct sockaddr_storage * addr)
} }
/* /*
* promote_v4_to_v6_mask --- convert an AF_INET netmask to AF_INET6, using * pg_promote_v4_to_v6_mask --- convert an AF_INET netmask to AF_INET6, using
* the standard convention for IPv4 addresses mapped into IPv6 world * the standard convention for IPv4 addresses mapped into IPv6 world
* *
* This must be different from promote_v4_to_v6_addr because we want to * This must be different from pg_promote_v4_to_v6_addr because we want to
* set the high-order bits to 1's not 0's. * set the high-order bits to 1's not 0's.
* *
* The passed addr is modified in place; be sure it is large enough to * The passed addr is modified in place; be sure it is large enough to
* hold the result! Note that we only worry about setting the fields * hold the result! Note that we only worry about setting the fields
* that rangeSockAddr will look at. * that pg_range_sockaddr will look at.
*/ */
void void
promote_v4_to_v6_mask(struct sockaddr_storage * addr) pg_promote_v4_to_v6_mask(struct sockaddr_storage *addr)
{ {
struct sockaddr_in addr4; struct sockaddr_in addr4;
struct sockaddr_in6 addr6; struct sockaddr_in6 addr6;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/libpq/md5.c,v 1.29 2005/10/15 02:49:18 momjian Exp $ * $PostgreSQL: pgsql/src/backend/libpq/md5.c,v 1.30 2005/10/17 16:24:19 tgl Exp $
*/ */
...@@ -272,12 +272,12 @@ bytesToHex(uint8 b[16], char *s) ...@@ -272,12 +272,12 @@ bytesToHex(uint8 b[16], char *s)
*/ */
/* /*
* md5_hash * pg_md5_hash
* *
* Calculates the MD5 sum of the bytes in a buffer. * Calculates the MD5 sum of the bytes in a buffer.
* *
* SYNOPSIS #include "crypt.h" * SYNOPSIS #include "crypt.h"
* int md5_hash(const void *buff, size_t len, char *hexsum) * int pg_md5_hash(const void *buff, size_t len, char *hexsum)
* *
* INPUT buff the buffer containing the bytes that you want * INPUT buff the buffer containing the bytes that you want
* the MD5 sum of. * the MD5 sum of.
...@@ -298,7 +298,7 @@ bytesToHex(uint8 b[16], char *s) ...@@ -298,7 +298,7 @@ bytesToHex(uint8 b[16], char *s)
* *
*/ */
bool bool
md5_hash(const void *buff, size_t len, char *hexsum) pg_md5_hash(const void *buff, size_t len, char *hexsum)
{ {
uint8 sum[16]; uint8 sum[16];
...@@ -321,8 +321,8 @@ md5_hash(const void *buff, size_t len, char *hexsum) ...@@ -321,8 +321,8 @@ md5_hash(const void *buff, size_t len, char *hexsum)
* Returns TRUE if okay, FALSE on error (out of memory). * Returns TRUE if okay, FALSE on error (out of memory).
*/ */
bool bool
EncryptMD5(const char *passwd, const char *salt, size_t salt_len, pg_md5_encrypt(const char *passwd, const char *salt, size_t salt_len,
char *buf) char *buf)
{ {
size_t passwd_len = strlen(passwd); size_t passwd_len = strlen(passwd);
char *crypt_buf = palloc(passwd_len + salt_len); char *crypt_buf = palloc(passwd_len + salt_len);
...@@ -336,7 +336,7 @@ EncryptMD5(const char *passwd, const char *salt, size_t salt_len, ...@@ -336,7 +336,7 @@ EncryptMD5(const char *passwd, const char *salt, size_t salt_len,
memcpy(crypt_buf + passwd_len, salt, salt_len); memcpy(crypt_buf + passwd_len, salt, salt_len);
strcpy(buf, "md5"); strcpy(buf, "md5");
ret = md5_hash(crypt_buf, passwd_len + salt_len, buf + 3); ret = pg_md5_hash(crypt_buf, passwd_len + salt_len, buf + 3);
pfree(crypt_buf); pfree(crypt_buf);
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.181 2005/10/15 02:49:18 momjian Exp $ * $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.182 2005/10/17 16:24:19 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -262,7 +262,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber, ...@@ -262,7 +262,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
service = portNumberStr; service = portNumberStr;
} }
ret = getaddrinfo_all(hostName, service, &hint, &addrs); ret = pg_getaddrinfo_all(hostName, service, &hint, &addrs);
if (ret || !addrs) if (ret || !addrs)
{ {
if (hostName) if (hostName)
...@@ -274,7 +274,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber, ...@@ -274,7 +274,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
(errmsg("could not translate service \"%s\" to address: %s", (errmsg("could not translate service \"%s\" to address: %s",
service, gai_strerror(ret)))); service, gai_strerror(ret))));
if (addrs) if (addrs)
freeaddrinfo_all(hint.ai_family, addrs); pg_freeaddrinfo_all(hint.ai_family, addrs);
return STATUS_ERROR; return STATUS_ERROR;
} }
...@@ -425,7 +425,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber, ...@@ -425,7 +425,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
added++; added++;
} }
freeaddrinfo_all(hint.ai_family, addrs); pg_freeaddrinfo_all(hint.ai_family, addrs);
if (!added) if (!added)
return STATUS_ERROR; return STATUS_ERROR;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* Copyright (c) 2001-2005, PostgreSQL Global Development Group * Copyright (c) 2001-2005, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.110 2005/10/15 02:49:23 momjian Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.111 2005/10/17 16:24:19 tgl Exp $
* ---------- * ----------
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -255,7 +255,7 @@ pgstat_init(void) ...@@ -255,7 +255,7 @@ pgstat_init(void)
hints.ai_addr = NULL; hints.ai_addr = NULL;
hints.ai_canonname = NULL; hints.ai_canonname = NULL;
hints.ai_next = NULL; hints.ai_next = NULL;
ret = getaddrinfo_all("localhost", NULL, &hints, &addrs); ret = pg_getaddrinfo_all("localhost", NULL, &hints, &addrs);
if (ret || !addrs) if (ret || !addrs)
{ {
ereport(LOG, ereport(LOG,
...@@ -265,12 +265,12 @@ pgstat_init(void) ...@@ -265,12 +265,12 @@ pgstat_init(void)
} }
/* /*
* On some platforms, getaddrinfo_all() may return multiple addresses only * On some platforms, pg_getaddrinfo_all() may return multiple addresses
* one of which will actually work (eg, both IPv6 and IPv4 addresses when * only one of which will actually work (eg, both IPv6 and IPv4 addresses
* kernel will reject IPv6). Worse, the failure may occur at the bind() * when kernel will reject IPv6). Worse, the failure may occur at the
* or perhaps even connect() stage. So we must loop through the results * bind() or perhaps even connect() stage. So we must loop through the
* till we find a working combination. We will generate LOG messages, but * results till we find a working combination. We will generate LOG
* no error, for bogus combinations. * messages, but no error, for bogus combinations.
*/ */
for (addr = addrs; addr; addr = addr->ai_next) for (addr = addrs; addr; addr = addr->ai_next)
{ {
...@@ -433,7 +433,7 @@ pgstat_init(void) ...@@ -433,7 +433,7 @@ pgstat_init(void)
goto startup_failed; goto startup_failed;
} }
freeaddrinfo_all(hints.ai_family, addrs); pg_freeaddrinfo_all(hints.ai_family, addrs);
return; return;
...@@ -442,7 +442,7 @@ startup_failed: ...@@ -442,7 +442,7 @@ startup_failed:
(errmsg("disabling statistics collector for lack of working socket"))); (errmsg("disabling statistics collector for lack of working socket")));
if (addrs) if (addrs)
freeaddrinfo_all(hints.ai_family, addrs); pg_freeaddrinfo_all(hints.ai_family, addrs);
if (pgStatSock >= 0) if (pgStatSock >= 0)
closesocket(pgStatSock); closesocket(pgStatSock);
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.469 2005/10/15 02:49:23 momjian Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.470 2005/10/17 16:24:19 tgl Exp $
* *
* NOTES * NOTES
* *
...@@ -2663,20 +2663,20 @@ BackendRun(Port *port) ...@@ -2663,20 +2663,20 @@ BackendRun(Port *port)
*/ */
remote_host[0] = '\0'; remote_host[0] = '\0';
remote_port[0] = '\0'; remote_port[0] = '\0';
if (getnameinfo_all(&port->raddr.addr, port->raddr.salen, if (pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
remote_host, sizeof(remote_host), remote_host, sizeof(remote_host),
remote_port, sizeof(remote_port), remote_port, sizeof(remote_port),
(log_hostname ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV)) (log_hostname ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV))
{ {
int ret = getnameinfo_all(&port->raddr.addr, port->raddr.salen, int ret = pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
remote_host, sizeof(remote_host), remote_host, sizeof(remote_host),
remote_port, sizeof(remote_port), remote_port, sizeof(remote_port),
NI_NUMERICHOST | NI_NUMERICSERV); NI_NUMERICHOST | NI_NUMERICSERV);
if (ret) if (ret)
ereport(WARNING, ereport(WARNING,
(errmsg("getnameinfo_all() failed: %s", (errmsg_internal("pg_getnameinfo_all() failed: %s",
gai_strerror(ret)))); gai_strerror(ret))));
} }
snprintf(remote_ps_data, sizeof(remote_ps_data), snprintf(remote_ps_data, sizeof(remote_ps_data),
remote_port[0] == '\0' ? "%s" : "%s(%s)", remote_port[0] == '\0' ? "%s" : "%s(%s)",
......
/* /*
* PostgreSQL type definitions for the INET and CIDR types. * PostgreSQL type definitions for the INET and CIDR types.
* *
* $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.55 2005/10/15 02:49:29 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.56 2005/10/17 16:24:19 tgl Exp $
* *
* Jon Postel RIP 16 Oct 1998 * Jon Postel RIP 16 Oct 1998
*/ */
...@@ -1013,10 +1013,10 @@ inet_client_addr(PG_FUNCTION_ARGS) ...@@ -1013,10 +1013,10 @@ inet_client_addr(PG_FUNCTION_ARGS)
remote_host[0] = '\0'; remote_host[0] = '\0';
ret = getnameinfo_all(&port->raddr.addr, port->raddr.salen, ret = pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
remote_host, sizeof(remote_host), remote_host, sizeof(remote_host),
NULL, 0, NULL, 0,
NI_NUMERICHOST | NI_NUMERICSERV); NI_NUMERICHOST | NI_NUMERICSERV);
if (ret) if (ret)
PG_RETURN_NULL(); PG_RETURN_NULL();
...@@ -1050,10 +1050,10 @@ inet_client_port(PG_FUNCTION_ARGS) ...@@ -1050,10 +1050,10 @@ inet_client_port(PG_FUNCTION_ARGS)
remote_port[0] = '\0'; remote_port[0] = '\0';
ret = getnameinfo_all(&port->raddr.addr, port->raddr.salen, ret = pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
NULL, 0, NULL, 0,
remote_port, sizeof(remote_port), remote_port, sizeof(remote_port),
NI_NUMERICHOST | NI_NUMERICSERV); NI_NUMERICHOST | NI_NUMERICSERV);
if (ret) if (ret)
PG_RETURN_NULL(); PG_RETURN_NULL();
...@@ -1087,10 +1087,10 @@ inet_server_addr(PG_FUNCTION_ARGS) ...@@ -1087,10 +1087,10 @@ inet_server_addr(PG_FUNCTION_ARGS)
local_host[0] = '\0'; local_host[0] = '\0';
ret = getnameinfo_all(&port->laddr.addr, port->laddr.salen, ret = pg_getnameinfo_all(&port->laddr.addr, port->laddr.salen,
local_host, sizeof(local_host), local_host, sizeof(local_host),
NULL, 0, NULL, 0,
NI_NUMERICHOST | NI_NUMERICSERV); NI_NUMERICHOST | NI_NUMERICSERV);
if (ret) if (ret)
PG_RETURN_NULL(); PG_RETURN_NULL();
...@@ -1124,10 +1124,10 @@ inet_server_port(PG_FUNCTION_ARGS) ...@@ -1124,10 +1124,10 @@ inet_server_port(PG_FUNCTION_ARGS)
local_port[0] = '\0'; local_port[0] = '\0';
ret = getnameinfo_all(&port->laddr.addr, port->laddr.salen, ret = pg_getnameinfo_all(&port->laddr.addr, port->laddr.salen,
NULL, 0, NULL, 0,
local_port, sizeof(local_port), local_port, sizeof(local_port),
NI_NUMERICHOST | NI_NUMERICSERV); NI_NUMERICHOST | NI_NUMERICSERV);
if (ret) if (ret)
PG_RETURN_NULL(); PG_RETURN_NULL();
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.25 2005/10/15 02:49:29 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.26 2005/10/17 16:24:19 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -417,10 +417,10 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS) ...@@ -417,10 +417,10 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
} }
remote_host[0] = '\0'; remote_host[0] = '\0';
ret = getnameinfo_all(&beentry->clientaddr.addr, beentry->clientaddr.salen, ret = pg_getnameinfo_all(&beentry->clientaddr.addr, beentry->clientaddr.salen,
remote_host, sizeof(remote_host), remote_host, sizeof(remote_host),
NULL, 0, NULL, 0,
NI_NUMERICHOST | NI_NUMERICSERV); NI_NUMERICHOST | NI_NUMERICSERV);
if (ret) if (ret)
PG_RETURN_NULL(); PG_RETURN_NULL();
...@@ -462,11 +462,11 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS) ...@@ -462,11 +462,11 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
} }
remote_port[0] = '\0'; remote_port[0] = '\0';
ret = getnameinfo_all(&beentry->clientaddr.addr, ret = pg_getnameinfo_all(&beentry->clientaddr.addr,
beentry->clientaddr.salen, beentry->clientaddr.salen,
NULL, 0, NULL, 0,
remote_port, sizeof(remote_port), remote_port, sizeof(remote_port),
NI_NUMERICHOST | NI_NUMERICSERV); NI_NUMERICHOST | NI_NUMERICSERV);
if (ret) if (ret)
PG_RETURN_NULL(); PG_RETURN_NULL();
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.136 2005/10/15 02:49:30 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.137 2005/10/17 16:24:19 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2613,7 +2613,7 @@ md5_text(PG_FUNCTION_ARGS) ...@@ -2613,7 +2613,7 @@ md5_text(PG_FUNCTION_ARGS)
len = VARSIZE(in_text) - VARHDRSZ; len = VARSIZE(in_text) - VARHDRSZ;
/* get the hash result */ /* get the hash result */
if (md5_hash(VARDATA(in_text), len, hexsum) == false) if (pg_md5_hash(VARDATA(in_text), len, hexsum) == false)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY), (errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory"))); errmsg("out of memory")));
...@@ -2636,7 +2636,7 @@ md5_bytea(PG_FUNCTION_ARGS) ...@@ -2636,7 +2636,7 @@ md5_bytea(PG_FUNCTION_ARGS)
text *result_text; text *result_text;
len = VARSIZE(in) - VARHDRSZ; len = VARSIZE(in) - VARHDRSZ;
if (md5_hash(VARDATA(in), len, hexsum) == false) if (pg_md5_hash(VARDATA(in), len, hexsum) == false)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY), (errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory"))); errmsg("out of memory")));
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/libpq/auth.h,v 1.30 2005/10/15 02:49:44 momjian Exp $ * $PostgreSQL: pgsql/src/include/libpq/auth.h,v 1.31 2005/10/17 16:24:20 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -16,18 +16,11 @@ ...@@ -16,18 +16,11 @@
#include "libpq/libpq-be.h" #include "libpq/libpq-be.h"
/*----------------------------------------------------------------
* Common routines and definitions
*----------------------------------------------------------------
*/
extern void ClientAuthentication(Port *port);
#define PG_KRB5_VERSION "PGVER5.1" /* at most KRB_SENDAUTH_VLEN chars */
extern char *pg_krb_server_keyfile; extern char *pg_krb_server_keyfile;
extern char *pg_krb_srvnam; extern char *pg_krb_srvnam;
extern bool pg_krb_caseins_users; extern bool pg_krb_caseins_users;
extern char *pg_krb_server_hostname; extern char *pg_krb_server_hostname;
extern void ClientAuthentication(Port *port);
#endif /* AUTH_H */ #endif /* AUTH_H */
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/libpq/crypt.h,v 1.31 2005/05/25 21:40:42 momjian Exp $ * $PostgreSQL: pgsql/src/include/libpq/crypt.h,v 1.32 2005/10/17 16:24:20 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -21,12 +21,13 @@ ...@@ -21,12 +21,13 @@
strlen(passwd) == MD5_PASSWD_LEN) strlen(passwd) == MD5_PASSWD_LEN)
/* in crypt.c */
extern int md5_crypt_verify(const Port *port, const char *user, extern int md5_crypt_verify(const Port *port, const char *user,
char *client_pass); char *client_pass);
extern bool md5_hash(const void *buff, size_t len, char *hexsum);
extern bool CheckMD5Pwd(char *passwd, char *storedpwd, char *seed);
extern bool EncryptMD5(const char *passwd, const char *salt, /* in md5.c --- these are also present in frontend libpq */
extern bool pg_md5_hash(const void *buff, size_t len, char *hexsum);
extern bool pg_md5_encrypt(const char *passwd, const char *salt,
size_t salt_len, char *buf); size_t salt_len, char *buf);
#endif #endif
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* Copyright (c) 2003-2005, PostgreSQL Global Development Group * Copyright (c) 2003-2005, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/include/libpq/ip.h,v 1.14 2005/01/01 20:44:27 tgl Exp $ * $PostgreSQL: pgsql/src/include/libpq/ip.h,v 1.15 2005/10/17 16:24:20 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -16,26 +16,26 @@ ...@@ -16,26 +16,26 @@
#include "libpq/pqcomm.h" #include "libpq/pqcomm.h"
extern int getaddrinfo_all(const char *hostname, const char *servname, extern int pg_getaddrinfo_all(const char *hostname, const char *servname,
const struct addrinfo * hintp, const struct addrinfo *hintp,
struct addrinfo ** result); struct addrinfo **result);
extern void freeaddrinfo_all(int hint_ai_family, struct addrinfo * ai); extern void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai);
extern int getnameinfo_all(const struct sockaddr_storage * addr, int salen, extern int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen,
char *node, int nodelen, char *node, int nodelen,
char *service, int servicelen, char *service, int servicelen,
int flags); int flags);
extern int rangeSockAddr(const struct sockaddr_storage * addr, extern int pg_range_sockaddr(const struct sockaddr_storage *addr,
const struct sockaddr_storage * netaddr, const struct sockaddr_storage *netaddr,
const struct sockaddr_storage * netmask); const struct sockaddr_storage *netmask);
extern int SockAddr_cidr_mask(struct sockaddr_storage * mask, extern int pg_sockaddr_cidr_mask(struct sockaddr_storage *mask,
char *numbits, int family); char *numbits, int family);
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
extern void promote_v4_to_v6_addr(struct sockaddr_storage * addr); extern void pg_promote_v4_to_v6_addr(struct sockaddr_storage *addr);
extern void promote_v4_to_v6_mask(struct sockaddr_storage * addr); extern void pg_promote_v4_to_v6_mask(struct sockaddr_storage *addr);
#endif #endif
#ifdef HAVE_UNIX_SOCKETS #ifdef HAVE_UNIX_SOCKETS
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes). * exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.105 2005/10/15 02:49:48 momjian Exp $ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.106 2005/10/17 16:24:20 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -18,14 +18,9 @@ ...@@ -18,14 +18,9 @@
/* /*
* INTERFACE ROUTINES * INTERFACE ROUTINES
* frontend (client) routines: * frontend (client) routines:
* fe_sendauth send authentication information * pg_fe_sendauth send authentication information
* fe_getauthname get user's name according to the client side * pg_fe_getauthname get user's name according to the client side
* of the authentication system * of the authentication system
* fe_setauthsvc set frontend authentication service
* fe_getauthsvc get current frontend authentication service
*
*
*
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -35,7 +30,6 @@ ...@@ -35,7 +30,6 @@
#else #else
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/param.h> /* for MAXHOSTNAMELEN on most */ #include <sys/param.h> /* for MAXHOSTNAMELEN on most */
#include <sys/socket.h> #include <sys/socket.h>
...@@ -59,51 +53,6 @@ ...@@ -59,51 +53,6 @@
#include "libpq/crypt.h" #include "libpq/crypt.h"
/*
* common definitions for generic fe/be routines
*/
#define STARTUP_MSG 7 /* Initialise a connection */
#define STARTUP_KRB4_MSG 10 /* krb4 session follows. Not supported any
* more. */
#define STARTUP_KRB5_MSG 11 /* krb5 session follows */
#define STARTUP_PASSWORD_MSG 14 /* Password follows */
struct authsvc
{
const char *name; /* service nickname (for command line) */
MsgType msgtype; /* startup packet header type */
int allowed; /* initially allowed (before command line
* option parsing)? */
};
/*
* Command-line parsing routines use this structure to map nicknames
* onto service types (and the startup packets to use with them).
*
* Programs receiving an authentication request use this structure to
* decide which authentication service types are currently permitted.
* By default, all authentication systems compiled into the system are
* allowed. Unauthenticated connections are disallowed unless there
* isn't any authentication system.
*/
static const struct authsvc authsvcs[] = {
#ifdef KRB5
{"krb5", STARTUP_KRB5_MSG, 1},
{"kerberos", STARTUP_KRB5_MSG, 1},
#endif /* KRB5 */
{UNAUTHNAME, STARTUP_MSG,
#ifdef KRB5
0
#else /* !KRB5 */
1
#endif /* !KRB5 */
},
{"password", STARTUP_PASSWORD_MSG, 0}
};
static const int n_authsvcs = sizeof(authsvcs) / sizeof(struct authsvc);
#ifdef KRB5 #ifdef KRB5
/* /*
* MIT Kerberos authentication system - protocol version 5 * MIT Kerberos authentication system - protocol version 5
...@@ -329,8 +278,10 @@ pg_krb5_sendauth(char *PQerrormsg, int sock, const char *hostname, const char *s ...@@ -329,8 +278,10 @@ pg_krb5_sendauth(char *PQerrormsg, int sock, const char *hostname, const char *s
return ret; return ret;
} }
#endif /* KRB5 */ #endif /* KRB5 */
/* /*
* Respond to AUTH_REQ_SCM_CREDS challenge. * Respond to AUTH_REQ_SCM_CREDS challenge.
* *
...@@ -417,14 +368,14 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq) ...@@ -417,14 +368,14 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
} }
crypt_pwd2 = crypt_pwd + MD5_PASSWD_LEN + 1; crypt_pwd2 = crypt_pwd + MD5_PASSWD_LEN + 1;
if (!EncryptMD5(password, conn->pguser, if (!pg_md5_encrypt(password, conn->pguser,
strlen(conn->pguser), crypt_pwd2)) strlen(conn->pguser), crypt_pwd2))
{ {
free(crypt_pwd); free(crypt_pwd);
return STATUS_ERROR; return STATUS_ERROR;
} }
if (!EncryptMD5(crypt_pwd2 + strlen("md5"), conn->md5Salt, if (!pg_md5_encrypt(crypt_pwd2 + strlen("md5"), conn->md5Salt,
sizeof(conn->md5Salt), crypt_pwd)) sizeof(conn->md5Salt), crypt_pwd))
{ {
free(crypt_pwd); free(crypt_pwd);
return STATUS_ERROR; return STATUS_ERROR;
...@@ -457,11 +408,12 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq) ...@@ -457,11 +408,12 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
} }
/* /*
* fe_sendauth -- client demux routine for outgoing authentication information * pg_fe_sendauth
* client demux routine for outgoing authentication information
*/ */
int int
fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname, pg_fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
const char *password, char *PQerrormsg) const char *password, char *PQerrormsg)
{ {
#ifndef KRB5 #ifndef KRB5
(void) hostname; /* not used */ (void) hostname; /* not used */
...@@ -526,68 +478,18 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname, ...@@ -526,68 +478,18 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
return STATUS_OK; return STATUS_OK;
} }
/*
* fe_setauthsvc
* fe_getauthsvc
*
* Set/return the authentication service currently selected for use by the
* frontend. (You can only use one in the frontend, obviously.)
*
* NB: This is not thread-safe if different threads try to select different
* authentication services! It's OK for fe_getauthsvc to select the default,
* since that will be the same for all threads, but direct application use
* of fe_setauthsvc is not thread-safe. However, use of fe_setauthsvc is
* deprecated anyway...
*/
static int pg_authsvc = -1;
void
fe_setauthsvc(const char *name, char *PQerrormsg)
{
int i;
for (i = 0; i < n_authsvcs; ++i)
if (strcmp(name, authsvcs[i].name) == 0)
{
pg_authsvc = i;
break;
}
if (i == n_authsvcs)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
libpq_gettext("invalid authentication service name \"%s\", ignored\n"),
name);
}
return;
}
MsgType
fe_getauthsvc(char *PQerrormsg)
{
if (pg_authsvc < 0 || pg_authsvc >= n_authsvcs)
{
fe_setauthsvc(DEFAULT_CLIENT_AUTHSVC, PQerrormsg);
if (pg_authsvc < 0 || pg_authsvc >= n_authsvcs)
{
/* Can only get here if DEFAULT_CLIENT_AUTHSVC is misdefined */
return 0;
}
}
return authsvcs[pg_authsvc].msgtype;
}
/* /*
* fe_getauthname -- returns a pointer to dynamic space containing whatever * pg_fe_getauthname -- returns a pointer to dynamic space containing whatever
* name the user has authenticated to the system * name the user has authenticated to the system
* if there is an error, return the error message in PQerrormsg *
* if there is an error, return NULL with an error message in PQerrormsg
*/ */
char * char *
fe_getauthname(char *PQerrormsg) pg_fe_getauthname(char *PQerrormsg)
{ {
const char *name = NULL; const char *name = NULL;
char *authn; char *authn;
MsgType authsvc;
#ifdef WIN32 #ifdef WIN32
char username[128]; char username[128];
...@@ -598,21 +500,13 @@ fe_getauthname(char *PQerrormsg) ...@@ -598,21 +500,13 @@ fe_getauthname(char *PQerrormsg)
struct passwd *pw = NULL; struct passwd *pw = NULL;
#endif #endif
authsvc = fe_getauthsvc(PQerrormsg);
/* this just guards against broken DEFAULT_CLIENT_AUTHSVC, see above */
if (authsvc == 0)
return NULL; /* leave original error message in place */
pglock_thread(); pglock_thread();
#ifdef KRB5 #ifdef KRB5
if (authsvc == STARTUP_KRB5_MSG) name = pg_krb5_authname(PQerrormsg);
name = pg_krb5_authname(PQerrormsg);
#endif #endif
if (authsvc == STARTUP_MSG if (!name)
|| (authsvc == STARTUP_KRB5_MSG && !name))
{ {
#ifdef WIN32 #ifdef WIN32
if (GetUserName(username, &namesize)) if (GetUserName(username, &namesize))
...@@ -623,11 +517,6 @@ fe_getauthname(char *PQerrormsg) ...@@ -623,11 +517,6 @@ fe_getauthname(char *PQerrormsg)
#endif #endif
} }
if (authsvc != STARTUP_MSG && authsvc != STARTUP_KRB5_MSG)
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
libpq_gettext("fe_getauthname: invalid authentication system: %d\n"),
authsvc);
authn = name ? strdup(name) : NULL; authn = name ? strdup(name) : NULL;
pgunlock_thread(); pgunlock_thread();
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.h,v 1.22 2005/10/15 02:49:48 momjian Exp $ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.h,v 1.23 2005/10/17 16:24:20 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -18,27 +18,8 @@ ...@@ -18,27 +18,8 @@
#include "libpq-int.h" #include "libpq-int.h"
/*---------------------------------------------------------------- extern int pg_fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
* Common routines and definitions
*----------------------------------------------------------------
*/
/* what we call "no authentication system" */
#define UNAUTHNAME "unauth"
/* what a frontend uses by default */
#ifndef KRB5
#define DEFAULT_CLIENT_AUTHSVC UNAUTHNAME
#else
#define DEFAULT_CLIENT_AUTHSVC "kerberos"
#endif /* KRB5 */
extern int fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
const char *password, char *PQerrormsg); const char *password, char *PQerrormsg);
extern MsgType fe_getauthsvc(char *PQerrormsg); extern char *pg_fe_getauthname(char *PQerrormsg);
extern void fe_setauthsvc(const char *name, char *PQerrormsg);
extern char *fe_getauthname(char *PQerrormsg);
#define PG_KRB5_VERSION "PGVER5.1" /* at most KRB_SENDAUTH_VLEN chars */
#endif /* FE_AUTH_H */ #endif /* FE_AUTH_H */
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.322 2005/10/15 02:49:48 momjian Exp $ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.323 2005/10/17 16:24:20 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -98,7 +98,7 @@ ...@@ -98,7 +98,7 @@
* *
* The value for the username is treated specially in conninfo_parse. * The value for the username is treated specially in conninfo_parse.
* If the Compiled-in resource is specified as a NULL value, the * If the Compiled-in resource is specified as a NULL value, the
* user is determined by fe_getauthname(). * user is determined by pg_fe_getauthname().
* *
* The Label and Disp-Char entries are provided for applications that * The Label and Disp-Char entries are provided for applications that
* want to use PQconndefaults() to create a generic database connection * want to use PQconndefaults() to create a generic database connection
...@@ -680,16 +680,14 @@ connectFailureMessage(PGconn *conn, int errorno) ...@@ -680,16 +680,14 @@ connectFailureMessage(PGconn *conn, int errorno)
{ {
char service[NI_MAXHOST]; char service[NI_MAXHOST];
getnameinfo_all(&conn->raddr.addr, conn->raddr.salen, pg_getnameinfo_all(&conn->raddr.addr, conn->raddr.salen,
NULL, 0, NULL, 0,
service, sizeof(service), service, sizeof(service),
NI_NUMERICSERV); NI_NUMERICSERV);
printfPQExpBuffer(&conn->errorMessage, printfPQExpBuffer(&conn->errorMessage,
libpq_gettext( libpq_gettext("could not connect to server: %s\n"
"could not connect to server: %s\n"
"\tIs the server running locally and accepting\n" "\tIs the server running locally and accepting\n"
"\tconnections on Unix domain socket \"%s\"?\n" "\tconnections on Unix domain socket \"%s\"?\n"),
),
SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)), SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)),
service); service);
} }
...@@ -697,11 +695,9 @@ connectFailureMessage(PGconn *conn, int errorno) ...@@ -697,11 +695,9 @@ connectFailureMessage(PGconn *conn, int errorno)
#endif /* HAVE_UNIX_SOCKETS */ #endif /* HAVE_UNIX_SOCKETS */
{ {
printfPQExpBuffer(&conn->errorMessage, printfPQExpBuffer(&conn->errorMessage,
libpq_gettext( libpq_gettext("could not connect to server: %s\n"
"could not connect to server: %s\n"
"\tIs the server running on host \"%s\" and accepting\n" "\tIs the server running on host \"%s\" and accepting\n"
"\tTCP/IP connections on port %s?\n" "\tTCP/IP connections on port %s?\n"),
),
SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)), SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)),
conn->pghostaddr conn->pghostaddr
? conn->pghostaddr ? conn->pghostaddr
...@@ -738,7 +734,7 @@ connectDBStart(PGconn *conn) ...@@ -738,7 +734,7 @@ connectDBStart(PGconn *conn)
conn->outCount = 0; conn->outCount = 0;
/* /*
* Determine the parameters to pass to getaddrinfo_all. * Determine the parameters to pass to pg_getaddrinfo_all.
*/ */
/* Initialize hint structure */ /* Initialize hint structure */
...@@ -780,8 +776,8 @@ connectDBStart(PGconn *conn) ...@@ -780,8 +776,8 @@ connectDBStart(PGconn *conn)
#endif /* HAVE_UNIX_SOCKETS */ #endif /* HAVE_UNIX_SOCKETS */
} }
/* Use getaddrinfo_all() to resolve the address */ /* Use pg_getaddrinfo_all() to resolve the address */
ret = getaddrinfo_all(node, portstr, &hint, &addrs); ret = pg_getaddrinfo_all(node, portstr, &hint, &addrs);
if (ret || !addrs) if (ret || !addrs)
{ {
if (node) if (node)
...@@ -793,7 +789,7 @@ connectDBStart(PGconn *conn) ...@@ -793,7 +789,7 @@ connectDBStart(PGconn *conn)
libpq_gettext("could not translate Unix-domain socket path \"%s\" to address: %s\n"), libpq_gettext("could not translate Unix-domain socket path \"%s\" to address: %s\n"),
portstr, gai_strerror(ret)); portstr, gai_strerror(ret));
if (addrs) if (addrs)
freeaddrinfo_all(hint.ai_family, addrs); pg_freeaddrinfo_all(hint.ai_family, addrs);
goto connect_errReturn; goto connect_errReturn;
} }
...@@ -1006,8 +1002,8 @@ keep_going: /* We will come back to here until there is ...@@ -1006,8 +1002,8 @@ keep_going: /* We will come back to here until there is
{ {
/* /*
* Try to initiate a connection to one of the addresses * Try to initiate a connection to one of the addresses
* returned by getaddrinfo_all(). conn->addr_cur is the next * returned by pg_getaddrinfo_all(). conn->addr_cur is the
* one to try. We fail when we run out of addresses * next one to try. We fail when we run out of addresses
* (reporting the error returned for the *last* alternative, * (reporting the error returned for the *last* alternative,
* which may not be what users expect :-(). * which may not be what users expect :-().
*/ */
...@@ -1631,8 +1627,8 @@ keep_going: /* We will come back to here until there is ...@@ -1631,8 +1627,8 @@ keep_going: /* We will come back to here until there is
* XXX fe-auth.c has not been fixed to support PQExpBuffers, * XXX fe-auth.c has not been fixed to support PQExpBuffers,
* so: * so:
*/ */
if (fe_sendauth(areq, conn, conn->pghost, conn->pgpass, if (pg_fe_sendauth(areq, conn, conn->pghost, conn->pgpass,
conn->errorMessage.data) != STATUS_OK) conn->errorMessage.data) != STATUS_OK)
{ {
conn->errorMessage.len = strlen(conn->errorMessage.data); conn->errorMessage.len = strlen(conn->errorMessage.data);
goto error_return; goto error_return;
...@@ -1640,9 +1636,9 @@ keep_going: /* We will come back to here until there is ...@@ -1640,9 +1636,9 @@ keep_going: /* We will come back to here until there is
conn->errorMessage.len = strlen(conn->errorMessage.data); conn->errorMessage.len = strlen(conn->errorMessage.data);
/* /*
* Just make sure that any data sent by fe_sendauth is flushed * Just make sure that any data sent by pg_fe_sendauth is
* out. Although this theoretically could block, it really * flushed out. Although this theoretically could block, it
* shouldn't since we don't send large auth responses. * really shouldn't since we don't send large auth responses.
*/ */
if (pqFlush(conn)) if (pqFlush(conn))
goto error_return; goto error_return;
...@@ -1707,7 +1703,7 @@ keep_going: /* We will come back to here until there is ...@@ -1707,7 +1703,7 @@ keep_going: /* We will come back to here until there is
} }
/* We can release the address list now. */ /* We can release the address list now. */
freeaddrinfo_all(conn->addrlist_family, conn->addrlist); pg_freeaddrinfo_all(conn->addrlist_family, conn->addrlist);
conn->addrlist = NULL; conn->addrlist = NULL;
conn->addr_cur = NULL; conn->addr_cur = NULL;
...@@ -1910,7 +1906,7 @@ freePGconn(PGconn *conn) ...@@ -1910,7 +1906,7 @@ freePGconn(PGconn *conn)
free(conn->krbsrvname); free(conn->krbsrvname);
#endif #endif
/* Note that conn->Pfdebug is not ours to close or free */ /* Note that conn->Pfdebug is not ours to close or free */
freeaddrinfo_all(conn->addrlist_family, conn->addrlist); pg_freeaddrinfo_all(conn->addrlist_family, conn->addrlist);
notify = conn->notifyHead; notify = conn->notifyHead;
while (notify != NULL) while (notify != NULL)
{ {
...@@ -1985,7 +1981,7 @@ closePGconn(PGconn *conn) ...@@ -1985,7 +1981,7 @@ closePGconn(PGconn *conn)
* absent */ * absent */
conn->asyncStatus = PGASYNC_IDLE; conn->asyncStatus = PGASYNC_IDLE;
pqClearAsyncResult(conn); /* deallocate result and curTuple */ pqClearAsyncResult(conn); /* deallocate result and curTuple */
freeaddrinfo_all(conn->addrlist_family, conn->addrlist); pg_freeaddrinfo_all(conn->addrlist_family, conn->addrlist);
conn->addrlist = NULL; conn->addrlist = NULL;
conn->addr_cur = NULL; conn->addr_cur = NULL;
notify = conn->notifyHead; notify = conn->notifyHead;
...@@ -2720,7 +2716,7 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage) ...@@ -2720,7 +2716,7 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage)
*/ */
if (strcmp(option->keyword, "user") == 0) if (strcmp(option->keyword, "user") == 0)
{ {
option->val = fe_getauthname(errortmp); option->val = pg_fe_getauthname(errortmp);
/* note any error message is thrown away */ /* note any error message is thrown away */
continue; continue;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment