1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +03:00

pgindent run.

This commit is contained in:
Bruce Momjian
2003-08-04 00:43:34 +00:00
parent 63354a0228
commit 089003fb46
554 changed files with 24888 additions and 21245 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.108 2003/07/28 06:27:06 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.109 2003/08/04 00:43:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -221,8 +221,8 @@ pg_krb5_init(void)
if (retval)
{
ereport(LOG,
(errmsg("kerberos sname_to_principal(\"%s\") returned error %d",
PG_KRB_SRVNAM, retval)));
(errmsg("kerberos sname_to_principal(\"%s\") returned error %d",
PG_KRB_SRVNAM, retval)));
com_err("postgres", retval,
"while getting server principal for service \"%s\"",
PG_KRB_SRVNAM);
@@ -432,7 +432,7 @@ ClientAuthentication(Port *port)
* out the less clueful good guys.
*/
{
char hostinfo[NI_MAXHOST];
char hostinfo[NI_MAXHOST];
getnameinfo_all(&port->raddr.addr, port->raddr.salen,
hostinfo, sizeof(hostinfo),
@@ -441,15 +441,15 @@ ClientAuthentication(Port *port)
#ifdef USE_SSL
ereport(FATAL,
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
errmsg("no pg_hba.conf entry for host \"%s\", user \"%s\", database \"%s\", %s",
hostinfo, port->user_name, port->database_name,
port->ssl ? gettext("SSL on") : gettext("SSL off"))));
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
errmsg("no pg_hba.conf entry for host \"%s\", user \"%s\", database \"%s\", %s",
hostinfo, port->user_name, port->database_name,
port->ssl ? gettext("SSL on") : gettext("SSL off"))));
#else
ereport(FATAL,
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
errmsg("no pg_hba.conf entry for host \"%s\", user \"%s\", database \"%s\"",
hostinfo, port->user_name, port->database_name)));
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
errmsg("no pg_hba.conf entry for host \"%s\", user \"%s\", database \"%s\"",
hostinfo, port->user_name, port->database_name)));
#endif
break;
}
@@ -460,7 +460,7 @@ ClientAuthentication(Port *port)
|| port->laddr.addr.ss_family != AF_INET)
ereport(FATAL,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("kerberos 4 only supports IPv4 connections")));
errmsg("kerberos 4 only supports IPv4 connections")));
sendAuthRequest(port, AUTH_REQ_KRB4);
status = pg_krb4_recvauth(port);
break;
@@ -492,7 +492,7 @@ ClientAuthentication(Port *port)
if (setsockopt(port->sock, 0, LOCAL_CREDS, &on, sizeof(on)) < 0)
ereport(FATAL,
(errcode_for_socket_access(),
errmsg("failed to enable credential receipt: %m")));
errmsg("failed to enable credential receipt: %m")));
}
#endif
if (port->raddr.addr.ss_family == AF_UNIX)
@@ -755,22 +755,22 @@ recv_password_packet(Port *port)
if (PG_PROTOCOL_MAJOR(port->proto) >= 3)
{
/* Expect 'p' message type */
int mtype;
int mtype;
mtype = pq_getbyte();
if (mtype != 'p')
{
/*
* If the client just disconnects without offering a password,
* don't make a log entry. This is legal per protocol spec and
* in fact commonly done by psql, so complaining just clutters
* the log.
* don't make a log entry. This is legal per protocol spec
* and in fact commonly done by psql, so complaining just
* clutters the log.
*/
if (mtype != EOF)
ereport(COMMERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("expected password response, got msg type %d",
mtype)));
errmsg("expected password response, got msg type %d",
mtype)));
return NULL; /* EOF or bad message type */
}
}
@@ -782,7 +782,7 @@ recv_password_packet(Port *port)
}
initStringInfo(&buf);
if (pq_getmessage(&buf, 1000)) /* receive password */
if (pq_getmessage(&buf, 1000)) /* receive password */
{
/* EOF - pq_getmessage already logged a suitable message */
pfree(buf.data);
@@ -804,7 +804,7 @@ recv_password_packet(Port *port)
(errmsg("received password packet")));
/*
* Return the received string. Note we do not attempt to do any
* Return the received string. Note we do not attempt to do any
* character-set conversion on it; since we don't yet know the
* client's encoding, there wouldn't be much point.
*/

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.66 2003/07/28 00:09:15 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.67 2003/08/04 00:43:18 momjian Exp $
*
* NOTES
* This should be moved to a more appropriate place. It is here
@@ -372,7 +372,7 @@ lo_import(PG_FUNCTION_ARGS)
if (!superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to use server-side lo_import()"),
errmsg("must be superuser to use server-side lo_import()"),
errhint("Anyone can use the client-side lo_import() provided by libpq.")));
#endif
@@ -439,7 +439,7 @@ lo_export(PG_FUNCTION_ARGS)
if (!superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to use server-side lo_export()"),
errmsg("must be superuser to use server-side lo_export()"),
errhint("Anyone can use the client-side lo_export() provided by libpq.")));
#endif

View File

@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.37 2003/07/27 21:49:53 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.38 2003/08/04 00:43:18 momjian Exp $
*
* Since the server static private key ($DataDir/server.key)
* will normally be stored unencrypted so that the database
@@ -187,7 +187,6 @@ OvOzKGtwcTqO/1wV5gKkzu1ZVswVUQd5Gg8lJicwqRWyyNRczDDoG9jVDxmogKTH\n\
AaqLulO7R8Ifa1SwF2DteSGVtgWEN8gDpN3RBmmPTDngyF2DHb5qmpnznwtFKdTL\n\
KWbuHn491xNO25CQWMtem80uKw+pTnisBRF/454n1Jnhub144YRBoN8CAQI=\n\
-----END DH PARAMETERS-----\n";
#endif
/* ------------------------------------------------------------ */
@@ -258,7 +257,7 @@ secure_read(Port *port, void *ptr, size_t len)
#ifdef USE_SSL
if (port->ssl)
{
rloop:
rloop:
n = SSL_read(port->ssl, ptr, len);
switch (SSL_get_error(port->ssl, n))
{
@@ -328,7 +327,7 @@ secure_write(Port *port, void *ptr, size_t len)
if (port->ssl->state != SSL_ST_OK)
ereport(COMMERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("SSL failed to send renegotiation request")));
errmsg("SSL failed to send renegotiation request")));
port->ssl->state |= SSL_ST_ACCEPT;
SSL_do_handshake(port->ssl);
if (port->ssl->state != SSL_ST_OK)
@@ -338,7 +337,7 @@ secure_write(Port *port, void *ptr, size_t len)
port->count = 0;
}
wloop:
wloop:
n = SSL_write(port->ssl, ptr, len);
switch (SSL_get_error(port->ssl, n))
{
@@ -436,7 +435,7 @@ load_dh_file(int keylength)
(codes & DH_CHECK_P_NOT_SAFE_PRIME))
{
elog(LOG,
"DH error (%s): neither suitable generator or safe prime",
"DH error (%s): neither suitable generator or safe prime",
fnbuf);
return NULL;
}
@@ -620,21 +619,21 @@ initialize_SSL(void)
if (!SSL_CTX_use_certificate_file(SSL_context, fnbuf, SSL_FILETYPE_PEM))
ereport(FATAL,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
errmsg("could not load server certificate file \"%s\": %s",
fnbuf, SSLerrmessage())));
errmsg("could not load server certificate file \"%s\": %s",
fnbuf, SSLerrmessage())));
snprintf(fnbuf, sizeof(fnbuf), "%s/server.key", DataDir);
if (stat(fnbuf, &buf) == -1)
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not access private key file \"%s\": %m",
fnbuf)));
errmsg("could not access private key file \"%s\": %m",
fnbuf)));
if (!S_ISREG(buf.st_mode) || (buf.st_mode & (S_IRWXG | S_IRWXO)) ||
buf.st_uid != getuid())
ereport(FATAL,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
errmsg("unsafe permissions on private key file \"%s\"",
fnbuf),
errmsg("unsafe permissions on private key file \"%s\"",
fnbuf),
errdetail("File must be owned by the database user and must have no permissions for \"group\" or \"other\".")));
if (!SSL_CTX_use_PrivateKey_file(SSL_context, fnbuf, SSL_FILETYPE_PEM))

View File

@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/libpq/crypt.c,v 1.54 2003/07/22 19:00:10 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/crypt.c,v 1.55 2003/08/04 00:43:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -119,7 +119,10 @@ md5_crypt_verify(const Port *port, const char *user, char *client_pass)
default:
if (isMD5(shadow_pass))
{
/* Encrypt user-supplied password to match MD5 in pg_shadow */
/*
* Encrypt user-supplied password to match MD5 in
* pg_shadow
*/
crypt_client_pass = palloc(MD5_PASSWD_LEN + 1);
if (!EncryptMD5(client_pass,
port->user_name,

View File

@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.109 2003/08/01 23:24:28 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.110 2003/08/04 00:43:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -392,7 +392,7 @@ get_group_line(const char *group)
/*
* Lookup a user name in the pg_shadow file
*/
List **
List **
get_user_line(const char *user)
{
return (List **) bsearch((void *) user,
@@ -416,7 +416,7 @@ check_group(char *group, char *user)
{
foreach(l, lnext(lnext(*line)))
if (strcmp(lfirst(l), user) == 0)
return true;
return true;
}
return false;
@@ -547,13 +547,14 @@ static void
parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p)
{
int line_number;
char *token;
char *db;
char *user;
struct addrinfo *file_ip_addr = NULL, *file_ip_mask = NULL;
struct addrinfo hints;
struct sockaddr_storage *mask;
char *cidr_slash;
char *token;
char *db;
char *user;
struct addrinfo *file_ip_addr = NULL,
*file_ip_mask = NULL;
struct addrinfo hints;
struct sockaddr_storage *mask;
char *cidr_slash;
int ret;
Assert(line != NIL);
@@ -595,11 +596,11 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p)
return;
}
else if (strcmp(token, "host") == 0
|| strcmp(token, "hostssl") == 0
|| strcmp(token, "hostnossl") == 0)
|| strcmp(token, "hostssl") == 0
|| strcmp(token, "hostnossl") == 0)
{
if (token[4] == 's') /* "hostssl" */
if (token[4] == 's') /* "hostssl" */
{
#ifdef USE_SSL
/* Record does not match if we are not on an SSL connection */
@@ -616,7 +617,7 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p)
#endif
}
#ifdef USE_SSL
else if (token[4] == 'n') /* "hostnossl" */
else if (token[4] == 'n') /* "hostnossl" */
{
/* Record does not match if we are on an SSL connection */
if (port->ssl)
@@ -643,7 +644,7 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p)
token = lfirst(line);
/* Check if it has a CIDR suffix and if so isolate it */
cidr_slash = strchr(token,'/');
cidr_slash = strchr(token, '/');
if (cidr_slash)
*cidr_slash = '\0';
@@ -698,7 +699,7 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p)
if (ret || !file_ip_mask)
goto hba_syntax;
mask = (struct sockaddr_storage *)file_ip_mask->ai_addr;
mask = (struct sockaddr_storage *) file_ip_mask->ai_addr;
if (file_ip_addr->ai_family != mask->ss_family)
goto hba_syntax;
@@ -714,7 +715,7 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p)
/* Must meet network restrictions */
if (!rangeSockAddr(&port->raddr.addr,
(struct sockaddr_storage *)file_ip_addr->ai_addr,
(struct sockaddr_storage *) file_ip_addr->ai_addr,
mask))
goto hba_freeaddr;
@@ -743,8 +744,8 @@ hba_syntax:
else
ereport(LOG,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
errmsg("missing field in pg_hba.conf file at end of line %d",
line_number)));
errmsg("missing field in pg_hba.conf file at end of line %d",
line_number)));
*error_p = true;
@@ -1012,8 +1013,8 @@ ident_syntax:
else
ereport(LOG,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
errmsg("missing entry in pg_ident.conf file at end of line %d",
line_number)));
errmsg("missing entry in pg_ident.conf file at end of line %d",
line_number)));
*error_p = true;
}
@@ -1044,7 +1045,7 @@ check_ident_usermap(const char *usermap_name,
{
ereport(LOG,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
errmsg("cannot use IDENT authentication without usermap field")));
errmsg("cannot use IDENT authentication without usermap field")));
found_entry = false;
}
else if (strcmp(usermap_name, "sameuser") == 0)
@@ -1215,11 +1216,13 @@ ident_inet(const SockAddr remote_addr,
char ident_port[NI_MAXSERV];
char ident_query[80];
char ident_response[80 + IDENT_USERNAME_MAX];
struct addrinfo *ident_serv = NULL, *la = NULL, hints;
struct addrinfo *ident_serv = NULL,
*la = NULL,
hints;
/*
* Might look a little weird to first convert it to text and
* then back to sockaddr, but it's protocol independent.
* 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),
@@ -1254,22 +1257,23 @@ ident_inet(const SockAddr remote_addr,
rc = getaddrinfo_all(local_addr_s, NULL, &hints, &la);
if (rc || !la)
return false; /* we don't expect this to happen */
sock_fd = socket(ident_serv->ai_family, ident_serv->ai_socktype,
ident_serv->ai_protocol);
if (sock_fd < 0)
{
ereport(LOG,
(errcode_for_socket_access(),
errmsg("could not create socket for IDENT connection: %m")));
errmsg("could not create socket for IDENT connection: %m")));
ident_return = false;
goto ident_inet_done;
}
/*
* Bind to the address which the client originally contacted,
* otherwise the ident server won't be able to match up the right
* connection. This is necessary if the PostgreSQL server is
* running on an IP alias.
* connection. This is necessary if the PostgreSQL server is running
* on an IP alias.
*/
rc = bind(sock_fd, la->ai_addr, la->ai_addrlen);
if (rc != 0)
@@ -1282,7 +1286,7 @@ ident_inet(const SockAddr remote_addr,
goto ident_inet_done;
}
rc = connect(sock_fd, ident_serv->ai_addr,
rc = connect(sock_fd, ident_serv->ai_addr,
ident_serv->ai_addrlen);
if (rc != 0)
{
@@ -1354,12 +1358,12 @@ ident_unix(int sock, char *ident_user)
{
#if defined(HAVE_GETPEEREID)
/* OpenBSD style: */
uid_t uid;
gid_t gid;
uid_t uid;
gid_t gid;
struct passwd *pass;
errno = 0;
if (getpeereid(sock,&uid,&gid) != 0)
if (getpeereid(sock, &uid, &gid) != 0)
{
/* We didn't get a valid credentials struct. */
ereport(LOG,
@@ -1491,8 +1495,7 @@ ident_unix(int sock, char *ident_user)
return false;
#endif
}
#endif /* HAVE_UNIX_SOCKETS */
#endif /* HAVE_UNIX_SOCKETS */
/*

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/ip.c,v 1.17 2003/08/01 17:53:41 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/ip.c,v 1.18 2003/08/04 00:43:18 momjian Exp $
*
* This file and the IPV6 implementation were initially provided by
* Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design
@@ -34,30 +34,30 @@
#endif
#include <arpa/inet.h>
#include <sys/file.h>
#endif
#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 rangeSockAddrAF_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 rangeSockAddrAF_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);
static int getaddrinfo_unix(const char *path,
const struct addrinfo * hintsp,
struct addrinfo ** result);
static int getnameinfo_unix(const struct sockaddr_un *sa, int salen,
char *node, int nodelen,
char *service, int servicelen,
int flags);
static int getnameinfo_unix(const struct sockaddr_un * sa, int salen,
char *node, int nodelen,
char *service, int servicelen,
int flags);
#endif
@@ -66,7 +66,7 @@ static int getnameinfo_unix(const struct sockaddr_un *sa, int salen,
*/
int
getaddrinfo_all(const char *hostname, const char *servname,
const struct addrinfo *hintp, struct addrinfo **result)
const struct addrinfo * hintp, struct addrinfo ** result)
{
#ifdef HAVE_UNIX_SOCKETS
if (hintp != NULL && hintp->ai_family == AF_UNIX)
@@ -89,7 +89,7 @@ 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)
freeaddrinfo_all(int hint_ai_family, struct addrinfo * ai)
{
#ifdef HAVE_UNIX_SOCKETS
if (hint_ai_family == AF_UNIX)
@@ -123,12 +123,12 @@ 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,
getnameinfo_all(const struct sockaddr_storage * addr, int salen,
char *node, int nodelen,
char *service, int servicelen,
int flags)
{
int rc;
int rc;
#ifdef HAVE_UNIX_SOCKETS
if (addr && addr->ss_family == AF_UNIX)
@@ -166,8 +166,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;
@@ -178,9 +178,7 @@ getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
MemSet(&hints, 0, sizeof(hints));
if (strlen(path) >= sizeof(unp->sun_path))
{
return EAI_FAIL;
}
if (hintsp == NULL)
{
@@ -234,139 +232,123 @@ 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)
{
int ret = -1;
int ret = -1;
/* Invalid arguments. */
if (sa == NULL || sa->sun_family != AF_UNIX ||
(node == NULL && service == NULL))
{
return EAI_FAIL;
}
/* We don't support those. */
if ((node && !(flags & NI_NUMERICHOST))
|| (service && !(flags & NI_NUMERICSERV)))
{
return EAI_FAIL;
}
if (node)
{
ret = snprintf(node, nodelen, "%s", "localhost");
if (ret == -1 || ret > nodelen)
{
return EAI_MEMORY;
}
}
if (service)
{
ret = snprintf(service, servicelen, "%s", sa->sun_path);
if (ret == -1 || ret > servicelen)
{
return EAI_MEMORY;
}
}
return 0;
}
#endif /* HAVE_UNIX_SOCKETS */
int
rangeSockAddr(const struct sockaddr_storage *addr,
const struct sockaddr_storage *netaddr,
const struct sockaddr_storage *netmask)
rangeSockAddr(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 rangeSockAddrAF_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 rangeSockAddrAF_INET6((struct sockaddr_in6 *) addr,
(struct sockaddr_in6 *) netaddr,
(struct sockaddr_in6 *) netmask);
#endif
else
return 0;
}
/*
* SockAddr_cidr_mask - make a network mask of the appropriate family
* and required number of significant bits
* SockAddr_cidr_mask - make a network mask of the appropriate family
* and required number of significant bits
*
* Note: Returns a static pointer for the mask, so it's not thread safe,
* and a second call will overwrite the data.
* and a second call will overwrite the data.
*/
int
SockAddr_cidr_mask(struct sockaddr_storage **mask, char *numbits, int family)
SockAddr_cidr_mask(struct sockaddr_storage ** mask, char *numbits, int family)
{
long bits;
char *endptr;
static struct sockaddr_storage sock;
struct sockaddr_in mask4;
long bits;
char *endptr;
static struct sockaddr_storage sock;
struct sockaddr_in mask4;
#ifdef HAVE_IPV6
struct sockaddr_in6 mask6;
struct sockaddr_in6 mask6;
#endif
bits = strtol(numbits, &endptr, 10);
if (*numbits == '\0' || *endptr != '\0')
{
return -1;
}
if ((bits < 0) || (family == AF_INET && bits > 32)
#ifdef HAVE_IPV6
|| (family == AF_INET6 && bits > 128)
#endif
)
{
return -1;
}
*mask = &sock;
switch (family)
{
case AF_INET:
mask4.sin_addr.s_addr =
mask4.sin_addr.s_addr =
htonl((0xffffffffUL << (32 - bits))
& 0xffffffffUL);
memcpy(&sock, &mask4, sizeof(mask4));
& 0xffffffffUL);
memcpy(&sock, &mask4, sizeof(mask4));
break;
#ifdef HAVE_IPV6
case AF_INET6:
{
int i;
for (i = 0; i < 16; i++)
{
if (bits <= 0)
int i;
for (i = 0; i < 16; i++)
{
mask6.sin6_addr.s6_addr[i] = 0;
if (bits <= 0)
mask6.sin6_addr.s6_addr[i] = 0;
else if (bits >= 8)
mask6.sin6_addr.s6_addr[i] = 0xff;
else
{
mask6.sin6_addr.s6_addr[i] =
(0xff << (8 - bits)) & 0xff;
}
bits -= 8;
}
else if (bits >= 8)
{
mask6.sin6_addr.s6_addr[i] = 0xff;
}
else
{
mask6.sin6_addr.s6_addr[i] =
(0xff << (8 - bits)) & 0xff;
}
bits -= 8;
memcpy(&sock, &mask6, sizeof(mask6));
break;
}
memcpy(&sock, &mask6, sizeof(mask6));
break;
}
#endif
default:
return -1;
@@ -377,8 +359,8 @@ static struct sockaddr_storage sock;
}
static int
rangeSockAddrAF_INET(const struct sockaddr_in *addr, const struct sockaddr_in *netaddr,
const struct sockaddr_in *netmask)
rangeSockAddrAF_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)
@@ -390,9 +372,9 @@ rangeSockAddrAF_INET(const struct sockaddr_in *addr, const struct sockaddr_in *n
#ifdef HAVE_IPV6
static int
rangeSockAddrAF_INET6(const struct sockaddr_in6 *addr,
const struct sockaddr_in6 *netaddr,
const struct sockaddr_in6 *netmask)
rangeSockAddrAF_INET6(const struct sockaddr_in6 * addr,
const struct sockaddr_in6 * netaddr,
const struct sockaddr_in6 * netmask)
{
int i;
@@ -405,6 +387,5 @@ rangeSockAddrAF_INET6(const struct sockaddr_in6 *addr,
return 1;
}
#endif

View File

@@ -14,7 +14,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/md5.c,v 1.19 2002/10/03 17:09:41 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/md5.c,v 1.20 2003/08/04 00:43:18 momjian Exp $
*/
@@ -35,8 +35,8 @@
#include "postgres_fe.h"
#ifndef WIN32
#include "libpq/crypt.h"
#endif /* WIN32 */
#endif /* FRONTEND */
#endif /* WIN32 */
#endif /* FRONTEND */
#ifdef MD5_ODBC
#include "md5.h"

View File

@@ -30,7 +30,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.161 2003/07/27 21:49:53 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.162 2003/08/04 00:43:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -151,6 +151,7 @@ pq_close(void)
{
/* Cleanly shut down SSL layer */
secure_close(MyProcPort);
/*
* Formerly we did an explicit close() here, but it seems better
* to leave the socket open until the process dies. This allows
@@ -208,10 +209,11 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
int maxconn;
int one = 1;
int ret;
char portNumberStr[64];
char *service;
struct addrinfo *addrs = NULL, *addr;
struct addrinfo hint;
char portNumberStr[64];
char *service;
struct addrinfo *addrs = NULL,
*addr;
struct addrinfo hint;
int listen_index = 0;
int added = 0;
@@ -245,8 +247,8 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
hostName, service, gai_strerror(ret))));
else
ereport(LOG,
(errmsg("could not translate service \"%s\" to address: %s",
service, gai_strerror(ret))));
(errmsg("could not translate service \"%s\" to address: %s",
service, gai_strerror(ret))));
freeaddrinfo_all(hint.ai_family, addrs);
return STATUS_ERROR;
}
@@ -255,9 +257,9 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
{
if (!IS_AF_UNIX(family) && IS_AF_UNIX(addr->ai_family))
{
/* Only set up a unix domain socket when
* they really asked for it. The service/port
* is different in that case.
/*
* Only set up a unix domain socket when they really asked for
* it. The service/port is different in that case.
*/
continue;
}
@@ -285,7 +287,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
if (!IS_AF_UNIX(addr->ai_family))
{
if ((setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
(char *) &one, sizeof(one))) == -1)
(char *) &one, sizeof(one))) == -1)
{
ereport(LOG,
(errcode_for_socket_access(),
@@ -299,7 +301,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
if (addr->ai_family == AF_INET6)
{
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY,
(char *)&one, sizeof(one)) == -1)
(char *) &one, sizeof(one)) == -1)
{
ereport(LOG,
(errcode_for_socket_access(),
@@ -311,10 +313,10 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
#endif
/*
* Note: This might fail on some OS's, like Linux
* older than 2.4.21-pre3, that don't have the IPV6_V6ONLY
* socket option, and map ipv4 addresses to ipv6. It will
* show ::ffff:ipv4 for all ipv4 connections.
* Note: This might fail on some OS's, like Linux older than
* 2.4.21-pre3, that don't have the IPV6_V6ONLY socket option, and
* map ipv4 addresses to ipv6. It will show ::ffff:ipv4 for all
* ipv4 connections.
*/
err = bind(fd, addr->ai_addr, addr->ai_addrlen);
if (err < 0)
@@ -323,12 +325,12 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
(errcode_for_socket_access(),
errmsg("failed to bind server socket: %m"),
(IS_AF_UNIX(addr->ai_family)) ?
errhint("Is another postmaster already running on port %d?"
" If not, remove socket node \"%s\" and retry.",
(int) portNumber, sock_path) :
errhint("Is another postmaster already running on port %d?"
" If not, wait a few seconds and retry.",
(int) portNumber)));
errhint("Is another postmaster already running on port %d?"
" If not, remove socket node \"%s\" and retry.",
(int) portNumber, sock_path) :
errhint("Is another postmaster already running on port %d?"
" If not, wait a few seconds and retry.",
(int) portNumber)));
closesocket(fd);
continue;
}
@@ -345,10 +347,10 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
#endif
/*
* Select appropriate accept-queue length limit. PG_SOMAXCONN
* is only intended to provide a clamp on the request on
* platforms where an overly large request provokes a kernel
* error (are there any?).
* Select appropriate accept-queue length limit. PG_SOMAXCONN is
* only intended to provide a clamp on the request on platforms
* where an overly large request provokes a kernel error (are
* there any?).
*/
maxconn = MaxBackends * 2;
if (maxconn > PG_SOMAXCONN)
@@ -465,7 +467,6 @@ Setup_AF_UNIX(void)
}
return STATUS_OK;
}
#endif /* HAVE_UNIX_SOCKETS */
@@ -485,8 +486,8 @@ StreamConnection(int server_fd, Port *port)
/* accept connection and fill in the client (remote) address */
port->raddr.salen = sizeof(port->raddr.addr);
if ((port->sock = accept(server_fd,
(struct sockaddr *) &port->raddr.addr,
&port->raddr.salen)) < 0)
(struct sockaddr *) & port->raddr.addr,
&port->raddr.salen)) < 0)
{
ereport(LOG,
(errcode_for_socket_access(),
@@ -495,6 +496,7 @@ StreamConnection(int server_fd, Port *port)
}
#ifdef SCO_ACCEPT_BUG
/*
* UnixWare 7+ and OpenServer 5.0.4 are known to have this bug, but it
* shouldn't hurt to catch it for all versions of those platforms.
@@ -571,19 +573,19 @@ TouchSocketFile(void)
if (sock_path[0] != '\0')
{
/*
* utime() is POSIX standard, utimes() is a common alternative.
* If we have neither, there's no way to affect the mod or access
* utime() is POSIX standard, utimes() is a common alternative. If
* we have neither, there's no way to affect the mod or access
* time of the socket :-(
*
* In either path, we ignore errors; there's no point in complaining.
*/
#ifdef HAVE_UTIME
utime(sock_path, NULL);
#else /* !HAVE_UTIME */
#else /* !HAVE_UTIME */
#ifdef HAVE_UTIMES
utimes(sock_path, NULL);
#endif /* HAVE_UTIMES */
#endif /* HAVE_UTIME */
#endif /* HAVE_UTIMES */
#endif /* HAVE_UTIME */
}
}
@@ -634,9 +636,10 @@ pq_recvbuf(void)
continue; /* Ok if interrupted */
/*
* Careful: an ereport() that tries to write to the client would
* cause recursion to here, leading to stack overflow and core
* dump! This message must go *only* to the postmaster log.
* Careful: an ereport() that tries to write to the client
* would cause recursion to here, leading to stack overflow
* and core dump! This message must go *only* to the
* postmaster log.
*/
ereport(COMMERROR,
(errcode_for_socket_access(),
@@ -646,8 +649,8 @@ pq_recvbuf(void)
if (r == 0)
{
/*
* EOF detected. We used to write a log message here, but it's
* better to expect the ultimate caller to do that.
* EOF detected. We used to write a log message here, but
* it's better to expect the ultimate caller to do that.
*/
return EOF;
}
@@ -894,9 +897,10 @@ pq_flush(void)
continue; /* Ok if we were interrupted */
/*
* Careful: an ereport() that tries to write to the client would
* cause recursion to here, leading to stack overflow and core
* dump! This message must go *only* to the postmaster log.
* Careful: an ereport() that tries to write to the client
* would cause recursion to here, leading to stack overflow
* and core dump! This message must go *only* to the
* postmaster log.
*
* If a client disconnects while we're in the midst of output, we
* might write quite a bit of data before we get to a safe

View File

@@ -24,7 +24,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/libpq/pqformat.c,v 1.32 2003/07/22 19:00:10 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/pqformat.c,v 1.33 2003/08/04 00:43:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -58,12 +58,12 @@
* pq_getmsgbyte - get a raw byte from a message buffer
* pq_getmsgint - get a binary integer from a message buffer
* pq_getmsgint64 - get a binary 8-byte int from a message buffer
* pq_getmsgfloat4 - get a float4 from a message buffer
* pq_getmsgfloat8 - get a float8 from a message buffer
* pq_getmsgfloat4 - get a float4 from a message buffer
* pq_getmsgfloat8 - get a float8 from a message buffer
* pq_getmsgbytes - get raw data from a message buffer
* pq_copymsgbytes - copy raw data from a message buffer
* pq_copymsgbytes - copy raw data from a message buffer
* pq_getmsgtext - get a counted text string (with conversion)
* pq_getmsgstring - get a null-terminated text string (with conversion)
* pq_getmsgstring - get a null-terminated text string (with conversion)
* pq_getmsgend - verify message fully consumed
*/
@@ -90,10 +90,12 @@ void
pq_beginmessage(StringInfo buf, char msgtype)
{
initStringInfo(buf);
/*
* We stash the message type into the buffer's cursor field, expecting
* that the pq_sendXXX routines won't touch it. We could alternatively
* make it the first byte of the buffer contents, but this seems easier.
* that the pq_sendXXX routines won't touch it. We could
* alternatively make it the first byte of the buffer contents, but
* this seems easier.
*/
buf->cursor = msgtype;
}
@@ -122,7 +124,7 @@ pq_sendbytes(StringInfo buf, const char *data, int datalen)
* pq_sendcountedtext - append a counted text string (with character set conversion)
*
* The data sent to the frontend by this routine is a 4-byte count field
* followed by the string. The count includes itself or not, as per the
* followed by the string. The count includes itself or not, as per the
* countincludesself flag (pre-3.0 protocol requires it to include itself).
* The passed text string need not be null-terminated, and the data sent
* to the frontend isn't either.
@@ -173,9 +175,7 @@ pq_sendtext(StringInfo buf, const char *str, int slen)
pfree(p);
}
else
{
appendBinaryStringInfo(buf, str, slen);
}
}
/* --------------------------------
@@ -200,9 +200,7 @@ pq_sendstring(StringInfo buf, const char *str)
pfree(p);
}
else
{
appendBinaryStringInfo(buf, str, slen + 1);
}
}
/* --------------------------------
@@ -281,9 +279,9 @@ pq_sendfloat4(StringInfo buf, float4 f)
{
union
{
float4 f;
uint32 i;
} swap;
float4 f;
uint32 i;
} swap;
swap.f = f;
swap.i = htonl(swap.i);
@@ -308,9 +306,9 @@ pq_sendfloat8(StringInfo buf, float8 f)
#ifdef INT64_IS_BUSTED
union
{
float8 f;
uint32 h[2];
} swap;
float8 f;
uint32 h[2];
} swap;
swap.f = f;
swap.h[0] = htonl(swap.h[0]);
@@ -332,9 +330,9 @@ pq_sendfloat8(StringInfo buf, float8 f)
#else
union
{
float8 f;
int64 i;
} swap;
float8 f;
int64 i;
} swap;
swap.f = f;
pq_sendint64(buf, swap.i);
@@ -515,7 +513,7 @@ pq_getmsgint64(StringInfo msg)
}
/* --------------------------------
* pq_getmsgfloat4 - get a float4 from a message buffer
* pq_getmsgfloat4 - get a float4 from a message buffer
*
* See notes for pq_sendfloat4.
* --------------------------------
@@ -525,16 +523,16 @@ pq_getmsgfloat4(StringInfo msg)
{
union
{
float4 f;
uint32 i;
} swap;
float4 f;
uint32 i;
} swap;
swap.i = pq_getmsgint(msg, 4);
return swap.f;
}
/* --------------------------------
* pq_getmsgfloat8 - get a float8 from a message buffer
* pq_getmsgfloat8 - get a float8 from a message buffer
*
* See notes for pq_sendfloat8.
* --------------------------------
@@ -545,9 +543,9 @@ pq_getmsgfloat8(StringInfo msg)
#ifdef INT64_IS_BUSTED
union
{
float8 f;
uint32 h[2];
} swap;
float8 f;
uint32 h[2];
} swap;
/* Have to figure out endianness by testing... */
if (((uint32) 1) == htonl((uint32) 1))
@@ -566,9 +564,9 @@ pq_getmsgfloat8(StringInfo msg)
#else
union
{
float8 f;
int64 i;
} swap;
float8 f;
int64 i;
} swap;
swap.i = pq_getmsgint64(msg);
return swap.f;
@@ -597,7 +595,7 @@ pq_getmsgbytes(StringInfo msg, int datalen)
}
/* --------------------------------
* pq_copymsgbytes - copy raw data from a message buffer
* pq_copymsgbytes - copy raw data from a message buffer
*
* Same as above, except data is copied to caller's buffer.
* --------------------------------
@@ -623,8 +621,8 @@ pq_copymsgbytes(StringInfo msg, char *buf, int datalen)
char *
pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes)
{
char *str;
char *p;
char *str;
char *p;
if (rawbytes < 0 || rawbytes > (msg->len - msg->cursor))
ereport(ERROR,
@@ -635,9 +633,7 @@ pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes)
p = (char *) pg_client_to_server((unsigned char *) str, rawbytes);
if (p != str) /* actual conversion has been done? */
{
*nbytes = strlen(p);
}
else
{
p = (char *) palloc(rawbytes + 1);
@@ -649,7 +645,7 @@ pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes)
}
/* --------------------------------
* pq_getmsgstring - get a null-terminated text string (with conversion)
* pq_getmsgstring - get a null-terminated text string (with conversion)
*
* May return a pointer directly into the message buffer, or a pointer
* to a palloc'd conversion result.
@@ -658,14 +654,15 @@ pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes)
const char *
pq_getmsgstring(StringInfo msg)
{
char *str;
int slen;
char *str;
int slen;
str = &msg->data[msg->cursor];
/*
* It's safe to use strlen() here because a StringInfo is guaranteed
* to have a trailing null byte. But check we found a null inside
* the message.
* to have a trailing null byte. But check we found a null inside the
* message.
*/
slen = strlen(str);
if (msg->cursor + slen >= msg->len)