mirror of https://github.com/postgres/postgres
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.
This commit is contained in:
parent
8ffdcbf23b
commit
d330f1554d
|
@ -1,5 +1,5 @@
|
|||
<!--
|
||||
$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">
|
||||
|
@ -4049,15 +4049,13 @@ passed around freely between threads.
|
|||
|
||||
<para>
|
||||
The deprecated functions
|
||||
<function>PQrequestCancel</function>,
|
||||
<function>PQoidStatus</function> and
|
||||
<function>fe_setauthsvc</function>
|
||||
<function>PQrequestCancel</function> and
|
||||
<function>PQoidStatus</function>
|
||||
are not thread-safe and should not be used in multithread programs.
|
||||
<function>PQrequestCancel</function> can be replaced by
|
||||
<function>PQcancel</function>.
|
||||
<function>PQoidStatus</function> can be replaced by
|
||||
<function>PQoidValue</function>.
|
||||
There is no good reason to call <function>fe_setauthsvc</function> at all.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* 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)
|
|||
DirectFunctionCall1(textin, CStringGetDatum(password));
|
||||
else
|
||||
{
|
||||
if (!EncryptMD5(password, stmt->role, strlen(stmt->role),
|
||||
encrypted_password))
|
||||
if (!pg_md5_encrypt(password, stmt->role, strlen(stmt->role),
|
||||
encrypted_password))
|
||||
elog(ERROR, "password encryption failed");
|
||||
new_record[Anum_pg_authid_rolpassword - 1] =
|
||||
DirectFunctionCall1(textin, CStringGetDatum(encrypted_password));
|
||||
|
@ -642,8 +642,8 @@ AlterRole(AlterRoleStmt *stmt)
|
|||
DirectFunctionCall1(textin, CStringGetDatum(password));
|
||||
else
|
||||
{
|
||||
if (!EncryptMD5(password, stmt->role, strlen(stmt->role),
|
||||
encrypted_password))
|
||||
if (!pg_md5_encrypt(password, stmt->role, strlen(stmt->role),
|
||||
encrypted_password))
|
||||
elog(ERROR, "password encryption failed");
|
||||
new_record[Anum_pg_authid_rolpassword - 1] =
|
||||
DirectFunctionCall1(textin, CStringGetDatum(encrypted_password));
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
*
|
||||
* 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)
|
|||
{
|
||||
char hostinfo[NI_MAXHOST];
|
||||
|
||||
getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
||||
hostinfo, sizeof(hostinfo),
|
||||
NULL, 0,
|
||||
NI_NUMERICHOST);
|
||||
pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
||||
hostinfo, sizeof(hostinfo),
|
||||
NULL, 0,
|
||||
NI_NUMERICHOST);
|
||||
|
||||
#ifdef USE_SSL
|
||||
ereport(FATAL,
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* 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)
|
|||
if (isMD5(shadow_pass))
|
||||
{
|
||||
/* stored password already encrypted, only do salt */
|
||||
if (!EncryptMD5(shadow_pass + strlen("md5"),
|
||||
(char *) port->md5Salt,
|
||||
sizeof(port->md5Salt), crypt_pwd))
|
||||
if (!pg_md5_encrypt(shadow_pass + strlen("md5"),
|
||||
(char *) port->md5Salt,
|
||||
sizeof(port->md5Salt), crypt_pwd))
|
||||
{
|
||||
pfree(crypt_pwd);
|
||||
return STATUS_ERROR;
|
||||
|
@ -89,19 +89,19 @@ md5_crypt_verify(const Port *port, const char *role, char *client_pass)
|
|||
/* stored password is plain, double-encrypt */
|
||||
char *crypt_pwd2 = palloc(MD5_PASSWD_LEN + 1);
|
||||
|
||||
if (!EncryptMD5(shadow_pass,
|
||||
port->user_name,
|
||||
strlen(port->user_name),
|
||||
crypt_pwd2))
|
||||
if (!pg_md5_encrypt(shadow_pass,
|
||||
port->user_name,
|
||||
strlen(port->user_name),
|
||||
crypt_pwd2))
|
||||
{
|
||||
pfree(crypt_pwd);
|
||||
pfree(crypt_pwd2);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
if (!EncryptMD5(crypt_pwd2 + strlen("md5"),
|
||||
port->md5Salt,
|
||||
sizeof(port->md5Salt),
|
||||
crypt_pwd))
|
||||
if (!pg_md5_encrypt(crypt_pwd2 + strlen("md5"),
|
||||
port->md5Salt,
|
||||
sizeof(port->md5Salt),
|
||||
crypt_pwd))
|
||||
{
|
||||
pfree(crypt_pwd);
|
||||
pfree(crypt_pwd2);
|
||||
|
@ -123,10 +123,10 @@ md5_crypt_verify(const Port *port, const char *role, char *client_pass)
|
|||
{
|
||||
/* Encrypt user-supplied password to match stored MD5 */
|
||||
crypt_client_pass = palloc(MD5_PASSWD_LEN + 1);
|
||||
if (!EncryptMD5(client_pass,
|
||||
port->user_name,
|
||||
strlen(port->user_name),
|
||||
crypt_client_pass))
|
||||
if (!pg_md5_encrypt(client_pass,
|
||||
port->user_name,
|
||||
strlen(port->user_name),
|
||||
crypt_client_pass))
|
||||
{
|
||||
pfree(crypt_client_pass);
|
||||
return STATUS_ERROR;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
*
|
||||
*
|
||||
* 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,
|
|||
hints.ai_addr = 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)
|
||||
{
|
||||
ereport(LOG,
|
||||
|
@ -767,7 +767,7 @@ parse_hba(List *line, int line_num, hbaPort *port,
|
|||
if (cidr_slash)
|
||||
*cidr_slash = '/';
|
||||
if (gai_result)
|
||||
freeaddrinfo_all(hints.ai_family, gai_result);
|
||||
pg_freeaddrinfo_all(hints.ai_family, gai_result);
|
||||
goto hba_other_error;
|
||||
}
|
||||
|
||||
|
@ -775,12 +775,13 @@ parse_hba(List *line, int line_num, hbaPort *port,
|
|||
*cidr_slash = '/';
|
||||
|
||||
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 */
|
||||
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;
|
||||
}
|
||||
else
|
||||
|
@ -791,7 +792,7 @@ parse_hba(List *line, int line_num, hbaPort *port,
|
|||
goto hba_syntax;
|
||||
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)
|
||||
{
|
||||
ereport(LOG,
|
||||
|
@ -800,12 +801,12 @@ parse_hba(List *line, int line_num, hbaPort *port,
|
|||
token, HbaFileName, line_num,
|
||||
gai_strerror(ret))));
|
||||
if (gai_result)
|
||||
freeaddrinfo_all(hints.ai_family, gai_result);
|
||||
pg_freeaddrinfo_all(hints.ai_family, gai_result);
|
||||
goto hba_other_error;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -828,8 +829,8 @@ parse_hba(List *line, int line_num, hbaPort *port,
|
|||
if (addr.ss_family == AF_INET &&
|
||||
port->raddr.addr.ss_family == AF_INET6)
|
||||
{
|
||||
promote_v4_to_v6_addr(&addr);
|
||||
promote_v4_to_v6_mask(&mask);
|
||||
pg_promote_v4_to_v6_addr(&addr);
|
||||
pg_promote_v4_to_v6_mask(&mask);
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_IPV6 */
|
||||
|
@ -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. */
|
||||
if (!rangeSockAddr(&port->raddr.addr, &addr, &mask))
|
||||
if (!pg_range_sockaddr(&port->raddr.addr, &addr, &mask))
|
||||
return;
|
||||
|
||||
/* Read the rest of the line. */
|
||||
|
@ -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
|
||||
* sockaddr, but it's protocol independent.
|
||||
*/
|
||||
getnameinfo_all(&remote_addr.addr, remote_addr.salen,
|
||||
remote_addr_s, sizeof(remote_addr_s),
|
||||
remote_port, sizeof(remote_port),
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
getnameinfo_all(&local_addr.addr, local_addr.salen,
|
||||
local_addr_s, sizeof(local_addr_s),
|
||||
local_port, sizeof(local_port),
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
pg_getnameinfo_all(&remote_addr.addr, remote_addr.salen,
|
||||
remote_addr_s, sizeof(remote_addr_s),
|
||||
remote_port, sizeof(remote_port),
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
pg_getnameinfo_all(&local_addr.addr, local_addr.salen,
|
||||
local_addr_s, sizeof(local_addr_s),
|
||||
local_port, sizeof(local_port),
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
|
||||
snprintf(ident_port, sizeof(ident_port), "%d", IDENT_PORT);
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
|
@ -1314,11 +1315,11 @@ ident_inet(const SockAddr remote_addr,
|
|||
hints.ai_canonname = NULL;
|
||||
hints.ai_addr = 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 (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 */
|
||||
}
|
||||
|
||||
|
@ -1330,11 +1331,11 @@ ident_inet(const SockAddr remote_addr,
|
|||
hints.ai_canonname = NULL;
|
||||
hints.ai_addr = 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 (la)
|
||||
freeaddrinfo_all(hints.ai_family, la);
|
||||
pg_freeaddrinfo_all(hints.ai_family, la);
|
||||
return false; /* we don't expect this to happen */
|
||||
}
|
||||
|
||||
|
@ -1422,8 +1423,8 @@ ident_inet(const SockAddr remote_addr,
|
|||
ident_inet_done:
|
||||
if (sock_fd >= 0)
|
||||
closesocket(sock_fd);
|
||||
freeaddrinfo_all(remote_addr.addr.ss_family, ident_serv);
|
||||
freeaddrinfo_all(local_addr.addr.ss_family, la);
|
||||
pg_freeaddrinfo_all(remote_addr.addr.ss_family, ident_serv);
|
||||
pg_freeaddrinfo_all(local_addr.addr.ss_family, la);
|
||||
return ident_return;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
*
|
||||
* 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
|
||||
* Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design
|
||||
|
@ -38,22 +38,22 @@
|
|||
#include "libpq/ip.h"
|
||||
|
||||
|
||||
static int rangeSockAddrAF_INET(const struct sockaddr_in * addr,
|
||||
const struct sockaddr_in * netaddr,
|
||||
const struct sockaddr_in * netmask);
|
||||
static int range_sockaddr_AF_INET(const struct sockaddr_in *addr,
|
||||
const struct sockaddr_in *netaddr,
|
||||
const struct sockaddr_in *netmask);
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
static int rangeSockAddrAF_INET6(const struct sockaddr_in6 * addr,
|
||||
const struct sockaddr_in6 * netaddr,
|
||||
const struct sockaddr_in6 * netmask);
|
||||
static int range_sockaddr_AF_INET6(const struct sockaddr_in6 *addr,
|
||||
const struct sockaddr_in6 *netaddr,
|
||||
const struct sockaddr_in6 *netmask);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNIX_SOCKETS
|
||||
static int getaddrinfo_unix(const char *path,
|
||||
const struct addrinfo * hintsp,
|
||||
struct addrinfo ** result);
|
||||
const struct addrinfo *hintsp,
|
||||
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 *service, int servicelen,
|
||||
int flags);
|
||||
|
@ -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
|
||||
getaddrinfo_all(const char *hostname, const char *servname,
|
||||
const struct addrinfo * hintp, struct addrinfo ** result)
|
||||
pg_getaddrinfo_all(const char *hostname, const char *servname,
|
||||
const struct addrinfo *hintp, struct addrinfo **result)
|
||||
{
|
||||
/* not all versions of getaddrinfo() zero *result on failure */
|
||||
*result = NULL;
|
||||
|
@ -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
|
||||
* 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,
|
|||
* not safe to look at ai_family in the addrinfo itself.
|
||||
*/
|
||||
void
|
||||
freeaddrinfo_all(int hint_ai_family, struct addrinfo * ai)
|
||||
pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
|
||||
{
|
||||
#ifdef HAVE_UNIX_SOCKETS
|
||||
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)
|
||||
{
|
||||
struct addrinfo *p = 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
|
||||
* 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)
|
|||
* guaranteed to be filled with something even on failure return.
|
||||
*/
|
||||
int
|
||||
getnameinfo_all(const struct sockaddr_storage * addr, int salen,
|
||||
char *node, int nodelen,
|
||||
char *service, int servicelen,
|
||||
int flags)
|
||||
pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen,
|
||||
char *node, int nodelen,
|
||||
char *service, int servicelen,
|
||||
int flags)
|
||||
{
|
||||
int rc;
|
||||
|
||||
|
@ -168,8 +168,8 @@ getnameinfo_all(const struct sockaddr_storage * addr, int salen,
|
|||
* -------
|
||||
*/
|
||||
static int
|
||||
getaddrinfo_unix(const char *path, const struct addrinfo * hintsp,
|
||||
struct addrinfo ** result)
|
||||
getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
|
||||
struct addrinfo **result)
|
||||
{
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *aip;
|
||||
|
@ -234,7 +234,7 @@ getaddrinfo_unix(const char *path, const struct addrinfo * hintsp,
|
|||
* Convert an address to a hostname.
|
||||
*/
|
||||
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 *service, int servicelen,
|
||||
int flags)
|
||||
|
@ -267,38 +267,39 @@ getnameinfo_unix(const struct sockaddr_un * sa, int salen,
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#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
|
||||
* in the same address family; and AF_UNIX addresses are not supported.
|
||||
*/
|
||||
int
|
||||
rangeSockAddr(const struct sockaddr_storage * addr,
|
||||
const struct sockaddr_storage * netaddr,
|
||||
const struct sockaddr_storage * netmask)
|
||||
pg_range_sockaddr(const struct sockaddr_storage *addr,
|
||||
const struct sockaddr_storage *netaddr,
|
||||
const struct sockaddr_storage *netmask)
|
||||
{
|
||||
if (addr->ss_family == AF_INET)
|
||||
return rangeSockAddrAF_INET((struct sockaddr_in *) addr,
|
||||
(struct sockaddr_in *) netaddr,
|
||||
(struct sockaddr_in *) netmask);
|
||||
return range_sockaddr_AF_INET((struct sockaddr_in *) addr,
|
||||
(struct sockaddr_in *) netaddr,
|
||||
(struct sockaddr_in *) netmask);
|
||||
#ifdef HAVE_IPV6
|
||||
else if (addr->ss_family == AF_INET6)
|
||||
return rangeSockAddrAF_INET6((struct sockaddr_in6 *) addr,
|
||||
(struct sockaddr_in6 *) netaddr,
|
||||
(struct sockaddr_in6 *) netmask);
|
||||
return range_sockaddr_AF_INET6((struct sockaddr_in6 *) addr,
|
||||
(struct sockaddr_in6 *) netaddr,
|
||||
(struct sockaddr_in6 *) netmask);
|
||||
#endif
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
rangeSockAddrAF_INET(const struct sockaddr_in * addr,
|
||||
const struct sockaddr_in * netaddr,
|
||||
const struct sockaddr_in * netmask)
|
||||
range_sockaddr_AF_INET(const struct sockaddr_in *addr,
|
||||
const struct sockaddr_in *netaddr,
|
||||
const struct sockaddr_in *netmask)
|
||||
{
|
||||
if (((addr->sin_addr.s_addr ^ netaddr->sin_addr.s_addr) &
|
||||
netmask->sin_addr.s_addr) == 0)
|
||||
|
@ -309,10 +310,11 @@ rangeSockAddrAF_INET(const struct sockaddr_in * addr,
|
|||
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
|
||||
static int
|
||||
rangeSockAddrAF_INET6(const struct sockaddr_in6 * addr,
|
||||
const struct sockaddr_in6 * netaddr,
|
||||
const struct sockaddr_in6 * netmask)
|
||||
range_sockaddr_AF_INET6(const struct sockaddr_in6 *addr,
|
||||
const struct sockaddr_in6 *netaddr,
|
||||
const struct sockaddr_in6 *netmask)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -325,10 +327,11 @@ rangeSockAddrAF_INET6(const struct sockaddr_in6 * addr,
|
|||
|
||||
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
|
||||
*
|
||||
* The resulting mask is placed in *mask, which had better be big enough.
|
||||
|
@ -336,7 +339,7 @@ rangeSockAddrAF_INET6(const struct sockaddr_in6 * addr,
|
|||
* Return value is 0 if okay, -1 if not.
|
||||
*/
|
||||
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;
|
||||
char *endptr;
|
||||
|
@ -403,15 +406,15 @@ SockAddr_cidr_mask(struct sockaddr_storage * mask, char *numbits, int family)
|
|||
#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 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
|
||||
* that rangeSockAddr will look at.
|
||||
* that pg_range_sockaddr will look at.
|
||||
*/
|
||||
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_in6 addr6;
|
||||
|
@ -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
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
* that rangeSockAddr will look at.
|
||||
* that pg_range_sockaddr will look at.
|
||||
*/
|
||||
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_in6 addr6;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* 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)
|
|||
*/
|
||||
|
||||
/*
|
||||
* md5_hash
|
||||
* pg_md5_hash
|
||||
*
|
||||
* Calculates the MD5 sum of the bytes in a buffer.
|
||||
*
|
||||
* 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
|
||||
* the MD5 sum of.
|
||||
|
@ -298,7 +298,7 @@ bytesToHex(uint8 b[16], char *s)
|
|||
*
|
||||
*/
|
||||
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];
|
||||
|
||||
|
@ -321,8 +321,8 @@ md5_hash(const void *buff, size_t len, char *hexsum)
|
|||
* Returns TRUE if okay, FALSE on error (out of memory).
|
||||
*/
|
||||
bool
|
||||
EncryptMD5(const char *passwd, const char *salt, size_t salt_len,
|
||||
char *buf)
|
||||
pg_md5_encrypt(const char *passwd, const char *salt, size_t salt_len,
|
||||
char *buf)
|
||||
{
|
||||
size_t passwd_len = strlen(passwd);
|
||||
char *crypt_buf = palloc(passwd_len + 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);
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* 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,
|
|||
service = portNumberStr;
|
||||
}
|
||||
|
||||
ret = getaddrinfo_all(hostName, service, &hint, &addrs);
|
||||
ret = pg_getaddrinfo_all(hostName, service, &hint, &addrs);
|
||||
if (ret || !addrs)
|
||||
{
|
||||
if (hostName)
|
||||
|
@ -274,7 +274,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
|
|||
(errmsg("could not translate service \"%s\" to address: %s",
|
||||
service, gai_strerror(ret))));
|
||||
if (addrs)
|
||||
freeaddrinfo_all(hint.ai_family, addrs);
|
||||
pg_freeaddrinfo_all(hint.ai_family, addrs);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
|
@ -425,7 +425,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
|
|||
added++;
|
||||
}
|
||||
|
||||
freeaddrinfo_all(hint.ai_family, addrs);
|
||||
pg_freeaddrinfo_all(hint.ai_family, addrs);
|
||||
|
||||
if (!added)
|
||||
return STATUS_ERROR;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* 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"
|
||||
|
@ -255,7 +255,7 @@ pgstat_init(void)
|
|||
hints.ai_addr = NULL;
|
||||
hints.ai_canonname = NULL;
|
||||
hints.ai_next = NULL;
|
||||
ret = getaddrinfo_all("localhost", NULL, &hints, &addrs);
|
||||
ret = pg_getaddrinfo_all("localhost", NULL, &hints, &addrs);
|
||||
if (ret || !addrs)
|
||||
{
|
||||
ereport(LOG,
|
||||
|
@ -265,12 +265,12 @@ pgstat_init(void)
|
|||
}
|
||||
|
||||
/*
|
||||
* On some platforms, getaddrinfo_all() may return multiple addresses only
|
||||
* one of which will actually work (eg, both IPv6 and IPv4 addresses when
|
||||
* kernel will reject IPv6). Worse, the failure may occur at the bind()
|
||||
* or perhaps even connect() stage. So we must loop through the results
|
||||
* till we find a working combination. We will generate LOG messages, but
|
||||
* no error, for bogus combinations.
|
||||
* On some platforms, pg_getaddrinfo_all() may return multiple addresses
|
||||
* only one of which will actually work (eg, both IPv6 and IPv4 addresses
|
||||
* when kernel will reject IPv6). Worse, the failure may occur at the
|
||||
* bind() or perhaps even connect() stage. So we must loop through the
|
||||
* results till we find a working combination. We will generate LOG
|
||||
* messages, but no error, for bogus combinations.
|
||||
*/
|
||||
for (addr = addrs; addr; addr = addr->ai_next)
|
||||
{
|
||||
|
@ -433,7 +433,7 @@ pgstat_init(void)
|
|||
goto startup_failed;
|
||||
}
|
||||
|
||||
freeaddrinfo_all(hints.ai_family, addrs);
|
||||
pg_freeaddrinfo_all(hints.ai_family, addrs);
|
||||
|
||||
return;
|
||||
|
||||
|
@ -442,7 +442,7 @@ startup_failed:
|
|||
(errmsg("disabling statistics collector for lack of working socket")));
|
||||
|
||||
if (addrs)
|
||||
freeaddrinfo_all(hints.ai_family, addrs);
|
||||
pg_freeaddrinfo_all(hints.ai_family, addrs);
|
||||
|
||||
if (pgStatSock >= 0)
|
||||
closesocket(pgStatSock);
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
*
|
||||
*
|
||||
* 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
|
||||
*
|
||||
|
@ -2663,20 +2663,20 @@ BackendRun(Port *port)
|
|||
*/
|
||||
remote_host[0] = '\0';
|
||||
remote_port[0] = '\0';
|
||||
if (getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
||||
remote_host, sizeof(remote_host),
|
||||
remote_port, sizeof(remote_port),
|
||||
(log_hostname ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV))
|
||||
if (pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
||||
remote_host, sizeof(remote_host),
|
||||
remote_port, sizeof(remote_port),
|
||||
(log_hostname ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV))
|
||||
{
|
||||
int ret = getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
||||
remote_host, sizeof(remote_host),
|
||||
remote_port, sizeof(remote_port),
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
int ret = pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
||||
remote_host, sizeof(remote_host),
|
||||
remote_port, sizeof(remote_port),
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
|
||||
if (ret)
|
||||
ereport(WARNING,
|
||||
(errmsg("getnameinfo_all() failed: %s",
|
||||
gai_strerror(ret))));
|
||||
(errmsg_internal("pg_getnameinfo_all() failed: %s",
|
||||
gai_strerror(ret))));
|
||||
}
|
||||
snprintf(remote_ps_data, sizeof(remote_ps_data),
|
||||
remote_port[0] == '\0' ? "%s" : "%s(%s)",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
|
@ -1013,10 +1013,10 @@ inet_client_addr(PG_FUNCTION_ARGS)
|
|||
|
||||
remote_host[0] = '\0';
|
||||
|
||||
ret = getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
||||
remote_host, sizeof(remote_host),
|
||||
NULL, 0,
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
ret = pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
||||
remote_host, sizeof(remote_host),
|
||||
NULL, 0,
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
if (ret)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
|
@ -1050,10 +1050,10 @@ inet_client_port(PG_FUNCTION_ARGS)
|
|||
|
||||
remote_port[0] = '\0';
|
||||
|
||||
ret = getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
||||
NULL, 0,
|
||||
remote_port, sizeof(remote_port),
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
ret = pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
||||
NULL, 0,
|
||||
remote_port, sizeof(remote_port),
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
if (ret)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
|
@ -1087,10 +1087,10 @@ inet_server_addr(PG_FUNCTION_ARGS)
|
|||
|
||||
local_host[0] = '\0';
|
||||
|
||||
ret = getnameinfo_all(&port->laddr.addr, port->laddr.salen,
|
||||
local_host, sizeof(local_host),
|
||||
NULL, 0,
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
ret = pg_getnameinfo_all(&port->laddr.addr, port->laddr.salen,
|
||||
local_host, sizeof(local_host),
|
||||
NULL, 0,
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
if (ret)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
|
@ -1124,10 +1124,10 @@ inet_server_port(PG_FUNCTION_ARGS)
|
|||
|
||||
local_port[0] = '\0';
|
||||
|
||||
ret = getnameinfo_all(&port->laddr.addr, port->laddr.salen,
|
||||
NULL, 0,
|
||||
local_port, sizeof(local_port),
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
ret = pg_getnameinfo_all(&port->laddr.addr, port->laddr.salen,
|
||||
NULL, 0,
|
||||
local_port, sizeof(local_port),
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
if (ret)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
*
|
||||
* 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)
|
|||
}
|
||||
|
||||
remote_host[0] = '\0';
|
||||
ret = getnameinfo_all(&beentry->clientaddr.addr, beentry->clientaddr.salen,
|
||||
remote_host, sizeof(remote_host),
|
||||
NULL, 0,
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
ret = pg_getnameinfo_all(&beentry->clientaddr.addr, beentry->clientaddr.salen,
|
||||
remote_host, sizeof(remote_host),
|
||||
NULL, 0,
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
if (ret)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
|
@ -462,11 +462,11 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
|
|||
}
|
||||
|
||||
remote_port[0] = '\0';
|
||||
ret = getnameinfo_all(&beentry->clientaddr.addr,
|
||||
beentry->clientaddr.salen,
|
||||
NULL, 0,
|
||||
remote_port, sizeof(remote_port),
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
ret = pg_getnameinfo_all(&beentry->clientaddr.addr,
|
||||
beentry->clientaddr.salen,
|
||||
NULL, 0,
|
||||
remote_port, sizeof(remote_port),
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
if (ret)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
*
|
||||
* 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)
|
|||
len = VARSIZE(in_text) - VARHDRSZ;
|
||||
|
||||
/* 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,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
|
@ -2636,7 +2636,7 @@ md5_bytea(PG_FUNCTION_ARGS)
|
|||
text *result_text;
|
||||
|
||||
len = VARSIZE(in) - VARHDRSZ;
|
||||
if (md5_hash(VARDATA(in), len, hexsum) == false)
|
||||
if (pg_md5_hash(VARDATA(in), len, hexsum) == false)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* 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 @@
|
|||
|
||||
#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_srvnam;
|
||||
extern bool pg_krb_caseins_users;
|
||||
extern char *pg_krb_server_hostname;
|
||||
|
||||
extern void ClientAuthentication(Port *port);
|
||||
|
||||
#endif /* AUTH_H */
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* 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 @@
|
|||
strlen(passwd) == MD5_PASSWD_LEN)
|
||||
|
||||
|
||||
/* in crypt.c */
|
||||
extern int md5_crypt_verify(const Port *port, const char *user,
|
||||
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);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*
|
||||
* 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 @@
|
|||
#include "libpq/pqcomm.h"
|
||||
|
||||
|
||||
extern int getaddrinfo_all(const char *hostname, const char *servname,
|
||||
const struct addrinfo * hintp,
|
||||
struct addrinfo ** result);
|
||||
extern void freeaddrinfo_all(int hint_ai_family, struct addrinfo * ai);
|
||||
extern int pg_getaddrinfo_all(const char *hostname, const char *servname,
|
||||
const struct addrinfo *hintp,
|
||||
struct addrinfo **result);
|
||||
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 *service, int servicelen,
|
||||
int flags);
|
||||
|
||||
extern int rangeSockAddr(const struct sockaddr_storage * addr,
|
||||
const struct sockaddr_storage * netaddr,
|
||||
const struct sockaddr_storage * netmask);
|
||||
extern int pg_range_sockaddr(const struct sockaddr_storage *addr,
|
||||
const struct sockaddr_storage *netaddr,
|
||||
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);
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
extern void 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_addr(struct sockaddr_storage *addr);
|
||||
extern void pg_promote_v4_to_v6_mask(struct sockaddr_storage *addr);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNIX_SOCKETS
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
|
||||
*
|
||||
* 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 @@
|
|||
/*
|
||||
* INTERFACE ROUTINES
|
||||
* frontend (client) routines:
|
||||
* fe_sendauth send authentication information
|
||||
* fe_getauthname get user's name according to the client side
|
||||
* pg_fe_sendauth send authentication information
|
||||
* pg_fe_getauthname get user's name according to the client side
|
||||
* of the authentication system
|
||||
* fe_setauthsvc set frontend authentication service
|
||||
* fe_getauthsvc get current frontend authentication service
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "postgres_fe.h"
|
||||
|
@ -35,7 +30,6 @@
|
|||
#else
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h> /* for MAXHOSTNAMELEN on most */
|
||||
#include <sys/socket.h>
|
||||
|
@ -59,51 +53,6 @@
|
|||
#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
|
||||
/*
|
||||
* MIT Kerberos authentication system - protocol version 5
|
||||
|
@ -329,8 +278,10 @@ pg_krb5_sendauth(char *PQerrormsg, int sock, const char *hostname, const char *s
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* KRB5 */
|
||||
|
||||
|
||||
/*
|
||||
* Respond to AUTH_REQ_SCM_CREDS challenge.
|
||||
*
|
||||
|
@ -417,14 +368,14 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
|
|||
}
|
||||
|
||||
crypt_pwd2 = crypt_pwd + MD5_PASSWD_LEN + 1;
|
||||
if (!EncryptMD5(password, conn->pguser,
|
||||
strlen(conn->pguser), crypt_pwd2))
|
||||
if (!pg_md5_encrypt(password, conn->pguser,
|
||||
strlen(conn->pguser), crypt_pwd2))
|
||||
{
|
||||
free(crypt_pwd);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
if (!EncryptMD5(crypt_pwd2 + strlen("md5"), conn->md5Salt,
|
||||
sizeof(conn->md5Salt), crypt_pwd))
|
||||
if (!pg_md5_encrypt(crypt_pwd2 + strlen("md5"), conn->md5Salt,
|
||||
sizeof(conn->md5Salt), crypt_pwd))
|
||||
{
|
||||
free(crypt_pwd);
|
||||
return STATUS_ERROR;
|
||||
|
@ -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
|
||||
fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
|
||||
const char *password, char *PQerrormsg)
|
||||
pg_fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
|
||||
const char *password, char *PQerrormsg)
|
||||
{
|
||||
#ifndef KRB5
|
||||
(void) hostname; /* not used */
|
||||
|
@ -526,68 +478,18 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
|
|||
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
|
||||
* 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 *
|
||||
fe_getauthname(char *PQerrormsg)
|
||||
pg_fe_getauthname(char *PQerrormsg)
|
||||
{
|
||||
const char *name = NULL;
|
||||
char *authn;
|
||||
MsgType authsvc;
|
||||
|
||||
#ifdef WIN32
|
||||
char username[128];
|
||||
|
@ -598,21 +500,13 @@ fe_getauthname(char *PQerrormsg)
|
|||
struct passwd *pw = NULL;
|
||||
#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();
|
||||
|
||||
#ifdef KRB5
|
||||
if (authsvc == STARTUP_KRB5_MSG)
|
||||
name = pg_krb5_authname(PQerrormsg);
|
||||
name = pg_krb5_authname(PQerrormsg);
|
||||
#endif
|
||||
|
||||
if (authsvc == STARTUP_MSG
|
||||
|| (authsvc == STARTUP_KRB5_MSG && !name))
|
||||
if (!name)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if (GetUserName(username, &namesize))
|
||||
|
@ -623,11 +517,6 @@ fe_getauthname(char *PQerrormsg)
|
|||
#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;
|
||||
|
||||
pgunlock_thread();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* 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 @@
|
|||
#include "libpq-int.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* 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,
|
||||
extern int pg_fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
|
||||
const char *password, char *PQerrormsg);
|
||||
extern MsgType fe_getauthsvc(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 */
|
||||
extern char *pg_fe_getauthname(char *PQerrormsg);
|
||||
|
||||
#endif /* FE_AUTH_H */
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
*
|
||||
* 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 @@
|
|||
*
|
||||
* The value for the username is treated specially in conninfo_parse.
|
||||
* 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
|
||||
* want to use PQconndefaults() to create a generic database connection
|
||||
|
@ -680,16 +680,14 @@ connectFailureMessage(PGconn *conn, int errorno)
|
|||
{
|
||||
char service[NI_MAXHOST];
|
||||
|
||||
getnameinfo_all(&conn->raddr.addr, conn->raddr.salen,
|
||||
NULL, 0,
|
||||
service, sizeof(service),
|
||||
NI_NUMERICSERV);
|
||||
pg_getnameinfo_all(&conn->raddr.addr, conn->raddr.salen,
|
||||
NULL, 0,
|
||||
service, sizeof(service),
|
||||
NI_NUMERICSERV);
|
||||
printfPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext(
|
||||
"could not connect to server: %s\n"
|
||||
libpq_gettext("could not connect to server: %s\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)),
|
||||
service);
|
||||
}
|
||||
|
@ -697,11 +695,9 @@ connectFailureMessage(PGconn *conn, int errorno)
|
|||
#endif /* HAVE_UNIX_SOCKETS */
|
||||
{
|
||||
printfPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext(
|
||||
"could not connect to server: %s\n"
|
||||
libpq_gettext("could not connect to server: %s\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)),
|
||||
conn->pghostaddr
|
||||
? conn->pghostaddr
|
||||
|
@ -738,7 +734,7 @@ connectDBStart(PGconn *conn)
|
|||
conn->outCount = 0;
|
||||
|
||||
/*
|
||||
* Determine the parameters to pass to getaddrinfo_all.
|
||||
* Determine the parameters to pass to pg_getaddrinfo_all.
|
||||
*/
|
||||
|
||||
/* Initialize hint structure */
|
||||
|
@ -780,8 +776,8 @@ connectDBStart(PGconn *conn)
|
|||
#endif /* HAVE_UNIX_SOCKETS */
|
||||
}
|
||||
|
||||
/* Use getaddrinfo_all() to resolve the address */
|
||||
ret = getaddrinfo_all(node, portstr, &hint, &addrs);
|
||||
/* Use pg_getaddrinfo_all() to resolve the address */
|
||||
ret = pg_getaddrinfo_all(node, portstr, &hint, &addrs);
|
||||
if (ret || !addrs)
|
||||
{
|
||||
if (node)
|
||||
|
@ -793,7 +789,7 @@ connectDBStart(PGconn *conn)
|
|||
libpq_gettext("could not translate Unix-domain socket path \"%s\" to address: %s\n"),
|
||||
portstr, gai_strerror(ret));
|
||||
if (addrs)
|
||||
freeaddrinfo_all(hint.ai_family, addrs);
|
||||
pg_freeaddrinfo_all(hint.ai_family, addrs);
|
||||
goto connect_errReturn;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
* returned by getaddrinfo_all(). conn->addr_cur is the next
|
||||
* one to try. We fail when we run out of addresses
|
||||
* returned by pg_getaddrinfo_all(). conn->addr_cur is the
|
||||
* next one to try. We fail when we run out of addresses
|
||||
* (reporting the error returned for the *last* alternative,
|
||||
* which may not be what users expect :-().
|
||||
*/
|
||||
|
@ -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,
|
||||
* so:
|
||||
*/
|
||||
if (fe_sendauth(areq, conn, conn->pghost, conn->pgpass,
|
||||
conn->errorMessage.data) != STATUS_OK)
|
||||
if (pg_fe_sendauth(areq, conn, conn->pghost, conn->pgpass,
|
||||
conn->errorMessage.data) != STATUS_OK)
|
||||
{
|
||||
conn->errorMessage.len = strlen(conn->errorMessage.data);
|
||||
goto error_return;
|
||||
|
@ -1640,9 +1636,9 @@ keep_going: /* We will come back to here until there is
|
|||
conn->errorMessage.len = strlen(conn->errorMessage.data);
|
||||
|
||||
/*
|
||||
* Just make sure that any data sent by fe_sendauth is flushed
|
||||
* out. Although this theoretically could block, it really
|
||||
* shouldn't since we don't send large auth responses.
|
||||
* Just make sure that any data sent by pg_fe_sendauth is
|
||||
* flushed out. Although this theoretically could block, it
|
||||
* really shouldn't since we don't send large auth responses.
|
||||
*/
|
||||
if (pqFlush(conn))
|
||||
goto error_return;
|
||||
|
@ -1707,7 +1703,7 @@ keep_going: /* We will come back to here until there is
|
|||
}
|
||||
|
||||
/* 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->addr_cur = NULL;
|
||||
|
||||
|
@ -1910,7 +1906,7 @@ freePGconn(PGconn *conn)
|
|||
free(conn->krbsrvname);
|
||||
#endif
|
||||
/* 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;
|
||||
while (notify != NULL)
|
||||
{
|
||||
|
@ -1985,7 +1981,7 @@ closePGconn(PGconn *conn)
|
|||
* absent */
|
||||
conn->asyncStatus = PGASYNC_IDLE;
|
||||
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->addr_cur = NULL;
|
||||
notify = conn->notifyHead;
|
||||
|
@ -2720,7 +2716,7 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage)
|
|||
*/
|
||||
if (strcmp(option->keyword, "user") == 0)
|
||||
{
|
||||
option->val = fe_getauthname(errortmp);
|
||||
option->val = pg_fe_getauthname(errortmp);
|
||||
/* note any error message is thrown away */
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue