diff options
| author | Bruce Momjian | 2010-02-26 02:01:40 +0000 |
|---|---|---|
| committer | Bruce Momjian | 2010-02-26 02:01:40 +0000 |
| commit | 65e806cba1f0f154d51caa7478e7192ce58d1056 (patch) | |
| tree | 99a656d7b4ec6d038d4c24e07fadf75db4c37e79 /src/backend/libpq | |
| parent | 16040575a04486d8e0823b4e304f4933144baf90 (diff) | |
pgindent run for 9.0
Diffstat (limited to 'src/backend/libpq')
| -rw-r--r-- | src/backend/libpq/auth.c | 177 | ||||
| -rw-r--r-- | src/backend/libpq/be-fsstubs.c | 12 | ||||
| -rw-r--r-- | src/backend/libpq/be-secure.c | 8 | ||||
| -rw-r--r-- | src/backend/libpq/crypt.c | 12 | ||||
| -rw-r--r-- | src/backend/libpq/hba.c | 46 | ||||
| -rw-r--r-- | src/backend/libpq/ip.c | 129 | ||||
| -rw-r--r-- | src/backend/libpq/md5.c | 6 | ||||
| -rw-r--r-- | src/backend/libpq/pqcomm.c | 24 |
8 files changed, 217 insertions, 197 deletions
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index 01b6851e358..70b0f665665 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.194 2010/02/02 19:09:36 mha Exp $ + * $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.195 2010/02/26 02:00:42 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -313,9 +313,9 @@ ClientAuthentication(Port *port) errhint("See server log for details."))); /* - * Enable immediate response to SIGTERM/SIGINT/timeout interrupts. - * (We don't want this during hba_getauthmethod() because it might - * have to do database access, eg for role membership checks.) + * Enable immediate response to SIGTERM/SIGINT/timeout interrupts. (We + * don't want this during hba_getauthmethod() because it might have to do + * database access, eg for role membership checks.) */ ImmediateInterruptOK = true; /* And don't forget to detect one that already arrived */ @@ -1960,7 +1960,7 @@ pam_passwd_conv_proc(int num_msg, const struct pam_message ** msg, if (strlen(passwd) == 0) { ereport(LOG, - (errmsg("empty password returned by client"))); + (errmsg("empty password returned by client"))); goto fail; } } @@ -2243,20 +2243,21 @@ CheckLDAPAuth(Port *port) if (port->hba->ldapbasedn) { /* - * First perform an LDAP search to find the DN for the user we are trying to log - * in as. + * First perform an LDAP search to find the DN for the user we are + * trying to log in as. */ - char *filter; - LDAPMessage *search_message; - LDAPMessage *entry; - char *attributes[2]; - char *dn; - char *c; + char *filter; + LDAPMessage *search_message; + LDAPMessage *entry; + char *attributes[2]; + char *dn; + char *c; /* - * Disallow any characters that we would otherwise need to escape, since they - * aren't really reasonable in a username anyway. Allowing them would make it - * possible to inject any kind of custom filters in the LDAP filter. + * Disallow any characters that we would otherwise need to escape, + * since they aren't really reasonable in a username anyway. Allowing + * them would make it possible to inject any kind of custom filters in + * the LDAP filter. */ for (c = port->user_name; *c; c++) { @@ -2273,17 +2274,17 @@ CheckLDAPAuth(Port *port) } /* - * Bind with a pre-defined username/password (if available) for searching. If - * none is specified, this turns into an anonymous bind. + * Bind with a pre-defined username/password (if available) for + * searching. If none is specified, this turns into an anonymous bind. */ r = ldap_simple_bind_s(ldap, - port->hba->ldapbinddn ? port->hba->ldapbinddn : "", - port->hba->ldapbindpasswd ? port->hba->ldapbindpasswd : ""); + port->hba->ldapbinddn ? port->hba->ldapbinddn : "", + port->hba->ldapbindpasswd ? port->hba->ldapbindpasswd : ""); if (r != LDAP_SUCCESS) { ereport(LOG, (errmsg("could not perform initial LDAP bind for ldapbinddn \"%s\" on server \"%s\": error code %d", - port->hba->ldapbinddn, port->hba->ldapserver, r))); + port->hba->ldapbinddn, port->hba->ldapserver, r))); return STATUS_ERROR; } @@ -2291,10 +2292,10 @@ CheckLDAPAuth(Port *port) attributes[0] = port->hba->ldapsearchattribute ? port->hba->ldapsearchattribute : "uid"; attributes[1] = NULL; - filter = palloc(strlen(attributes[0])+strlen(port->user_name)+4); + filter = palloc(strlen(attributes[0]) + strlen(port->user_name) + 4); sprintf(filter, "(%s=%s)", - attributes[0], - port->user_name); + attributes[0], + port->user_name); r = ldap_search_s(ldap, port->hba->ldapbasedn, @@ -2323,7 +2324,7 @@ CheckLDAPAuth(Port *port) ereport(LOG, (errmsg("LDAP search failed for filter \"%s\" on server \"%s\": user is not unique (%ld matches)", filter, port->hba->ldapserver, - (long) ldap_count_entries(ldap, search_message)))); + (long) ldap_count_entries(ldap, search_message)))); pfree(filter); ldap_msgfree(search_message); @@ -2334,11 +2335,12 @@ CheckLDAPAuth(Port *port) dn = ldap_get_dn(ldap, entry); if (dn == NULL) { - int error; - (void)ldap_get_option(ldap, LDAP_OPT_ERROR_NUMBER, &error); + int error; + + (void) ldap_get_option(ldap, LDAP_OPT_ERROR_NUMBER, &error); ereport(LOG, (errmsg("could not get dn for the first entry matching \"%s\" on server \"%s\": %s", - filter, port->hba->ldapserver, ldap_err2string(error)))); + filter, port->hba->ldapserver, ldap_err2string(error)))); pfree(filter); ldap_msgfree(search_message); return STATUS_ERROR; @@ -2353,18 +2355,19 @@ CheckLDAPAuth(Port *port) r = ldap_unbind_s(ldap); if (r != LDAP_SUCCESS) { - int error; - (void)ldap_get_option(ldap, LDAP_OPT_ERROR_NUMBER, &error); + int error; + + (void) ldap_get_option(ldap, LDAP_OPT_ERROR_NUMBER, &error); ereport(LOG, (errmsg("could not unbind after searching for user \"%s\" on server \"%s\": %s", - fulluser, port->hba->ldapserver, ldap_err2string(error)))); + fulluser, port->hba->ldapserver, ldap_err2string(error)))); pfree(fulluser); return STATUS_ERROR; } /* - * Need to re-initialize the LDAP connection, so that we can bind - * to it with a different username. + * Need to re-initialize the LDAP connection, so that we can bind to + * it with a different username. */ if (InitializeLDAPConnection(port, &ldap) == STATUS_ERROR) { @@ -2378,13 +2381,13 @@ CheckLDAPAuth(Port *port) { fulluser = palloc((port->hba->ldapprefix ? strlen(port->hba->ldapprefix) : 0) + strlen(port->user_name) + - (port->hba->ldapsuffix ? strlen(port->hba->ldapsuffix) : 0) + + (port->hba->ldapsuffix ? strlen(port->hba->ldapsuffix) : 0) + 1); sprintf(fulluser, "%s%s%s", - port->hba->ldapprefix ? port->hba->ldapprefix : "", - port->user_name, - port->hba->ldapsuffix ? port->hba->ldapsuffix : ""); + port->hba->ldapprefix ? port->hba->ldapprefix : "", + port->user_name, + port->hba->ldapsuffix ? port->hba->ldapsuffix : ""); } r = ldap_simple_bind_s(ldap, fulluser, passwd); @@ -2429,7 +2432,6 @@ CheckCertAuth(Port *port) /* Just pass the certificate CN to the usermap check */ return check_usermap(port->hba->usermap, port->user_name, port->peer_cn, false); } - #endif @@ -2448,17 +2450,17 @@ CheckCertAuth(Port *port) typedef struct { - uint8 attribute; - uint8 length; - uint8 data[1]; + uint8 attribute; + uint8 length; + uint8 data[1]; } radius_attribute; typedef struct { - uint8 code; - uint8 id; - uint16 length; - uint8 vector[RADIUS_VECTOR_LENGTH]; + uint8 code; + uint8 id; + uint16 length; + uint8 vector[RADIUS_VECTOR_LENGTH]; } radius_packet; /* RADIUS packet types */ @@ -2484,14 +2486,15 @@ typedef struct static void radius_add_attribute(radius_packet *packet, uint8 type, const unsigned char *data, int len) { - radius_attribute *attr; + radius_attribute *attr; if (packet->length + len > RADIUS_BUFFER_SIZE) { /* - * With remotely realistic data, this can never happen. But catch it just to make - * sure we don't overrun a buffer. We'll just skip adding the broken attribute, - * which will in the end cause authentication to fail. + * With remotely realistic data, this can never happen. But catch it + * just to make sure we don't overrun a buffer. We'll just skip adding + * the broken attribute, which will in the end cause authentication to + * fail. */ elog(WARNING, "Adding attribute code %i with length %i to radius packet would create oversize packet, ignoring", @@ -2500,9 +2503,9 @@ radius_add_attribute(radius_packet *packet, uint8 type, const unsigned char *dat } - attr = (radius_attribute *) ((unsigned char *)packet + packet->length); + attr = (radius_attribute *) ((unsigned char *) packet + packet->length); attr->attribute = type; - attr->length = len + 2; /* total size includes type and length */ + attr->length = len + 2; /* total size includes type and length */ memcpy(attr->data, data, len); packet->length += attr->length; } @@ -2510,31 +2513,33 @@ radius_add_attribute(radius_packet *packet, uint8 type, const unsigned char *dat static int CheckRADIUSAuth(Port *port) { - char *passwd; - char *identifier = "postgresql"; - char radius_buffer[RADIUS_BUFFER_SIZE]; - char receive_buffer[RADIUS_BUFFER_SIZE]; - radius_packet *packet = (radius_packet *)radius_buffer; - radius_packet *receivepacket = (radius_packet *)receive_buffer; - int32 service = htonl(RADIUS_AUTHENTICATE_ONLY); - uint8 *cryptvector; - uint8 encryptedpassword[RADIUS_VECTOR_LENGTH]; - int packetlength; - pgsocket sock; + char *passwd; + char *identifier = "postgresql"; + char radius_buffer[RADIUS_BUFFER_SIZE]; + char receive_buffer[RADIUS_BUFFER_SIZE]; + radius_packet *packet = (radius_packet *) radius_buffer; + radius_packet *receivepacket = (radius_packet *) receive_buffer; + int32 service = htonl(RADIUS_AUTHENTICATE_ONLY); + uint8 *cryptvector; + uint8 encryptedpassword[RADIUS_VECTOR_LENGTH]; + int packetlength; + pgsocket sock; + #ifdef HAVE_IPV6 struct sockaddr_in6 localaddr; struct sockaddr_in6 remoteaddr; #else - struct sockaddr_in localaddr; - struct sockaddr_in remoteaddr; + struct sockaddr_in localaddr; + struct sockaddr_in remoteaddr; #endif - struct addrinfo hint; - struct addrinfo *serveraddrs; - char portstr[128]; - ACCEPT_TYPE_ARG3 addrsize; - fd_set fdset; - struct timeval timeout; - int i,r; + struct addrinfo hint; + struct addrinfo *serveraddrs; + char portstr[128]; + ACCEPT_TYPE_ARG3 addrsize; + fd_set fdset; + struct timeval timeout; + int i, + r; /* Make sure struct alignment is correct */ Assert(offsetof(radius_packet, vector) == 4); @@ -2619,8 +2624,8 @@ CheckRADIUSAuth(Port *port) radius_add_attribute(packet, RADIUS_NAS_IDENTIFIER, (unsigned char *) identifier, strlen(identifier)); /* - * RADIUS password attributes are calculated as: - * e[0] = p[0] XOR MD5(secret + vector) + * RADIUS password attributes are calculated as: e[0] = p[0] XOR + * MD5(secret + vector) */ cryptvector = palloc(RADIUS_VECTOR_LENGTH + strlen(port->hba->radiussecret)); memcpy(cryptvector, port->hba->radiussecret, strlen(port->hba->radiussecret)); @@ -2668,7 +2673,7 @@ CheckRADIUSAuth(Port *port) localaddr.sin_addr.s_addr = INADDR_ANY; addrsize = sizeof(struct sockaddr_in); #endif - if (bind(sock, (struct sockaddr *) &localaddr, addrsize)) + if (bind(sock, (struct sockaddr *) & localaddr, addrsize)) { ereport(LOG, (errmsg("could not bind local RADIUS socket: %m"))); @@ -2694,7 +2699,8 @@ CheckRADIUSAuth(Port *port) timeout.tv_sec = RADIUS_TIMEOUT; timeout.tv_usec = 0; FD_ZERO(&fdset); - FD_SET(sock, &fdset); + FD_SET (sock, &fdset); + while (true) { r = select(sock + 1, &fdset, NULL, NULL, &timeout); @@ -2724,7 +2730,7 @@ CheckRADIUSAuth(Port *port) /* Read the response packet */ addrsize = sizeof(remoteaddr); packetlength = recvfrom(sock, receive_buffer, RADIUS_BUFFER_SIZE, 0, - (struct sockaddr *) &remoteaddr, &addrsize); + (struct sockaddr *) & remoteaddr, &addrsize); if (packetlength < 0) { ereport(LOG, @@ -2763,8 +2769,8 @@ CheckRADIUSAuth(Port *port) if (packetlength != ntohs(receivepacket->length)) { ereport(LOG, - (errmsg("RADIUS response has corrupt length: %i (actual length %i)", - ntohs(receivepacket->length), packetlength))); + (errmsg("RADIUS response has corrupt length: %i (actual length %i)", + ntohs(receivepacket->length), packetlength))); return STATUS_ERROR; } @@ -2783,23 +2789,26 @@ CheckRADIUSAuth(Port *port) cryptvector = palloc(packetlength + strlen(port->hba->radiussecret)); memcpy(cryptvector, receivepacket, 4); /* code+id+length */ - memcpy(cryptvector+4, packet->vector, RADIUS_VECTOR_LENGTH); /* request authenticator, from original packet */ - if (packetlength > RADIUS_HEADER_LENGTH) /* there may be no attributes at all */ - memcpy(cryptvector+RADIUS_HEADER_LENGTH, receive_buffer + RADIUS_HEADER_LENGTH, packetlength-RADIUS_HEADER_LENGTH); - memcpy(cryptvector+packetlength, port->hba->radiussecret, strlen(port->hba->radiussecret)); + memcpy(cryptvector + 4, packet->vector, RADIUS_VECTOR_LENGTH); /* request + * authenticator, from + * original packet */ + if (packetlength > RADIUS_HEADER_LENGTH) /* there may be no attributes + * at all */ + memcpy(cryptvector + RADIUS_HEADER_LENGTH, receive_buffer + RADIUS_HEADER_LENGTH, packetlength - RADIUS_HEADER_LENGTH); + memcpy(cryptvector + packetlength, port->hba->radiussecret, strlen(port->hba->radiussecret)); if (!pg_md5_binary(cryptvector, packetlength + strlen(port->hba->radiussecret), encryptedpassword)) { ereport(LOG, - (errmsg("could not perform md5 encryption of received packet"))); + (errmsg("could not perform md5 encryption of received packet"))); pfree(cryptvector); return STATUS_ERROR; } pfree(cryptvector); - if (memcmp(receivepacket->vector, encryptedpassword, RADIUS_VECTOR_LENGTH) != 0) + if (memcmp(receivepacket->vector, encryptedpassword, RADIUS_VECTOR_LENGTH) != 0) { ereport(LOG, (errmsg("RADIUS response has incorrect MD5 signature"))); diff --git a/src/backend/libpq/be-fsstubs.c b/src/backend/libpq/be-fsstubs.c index 2a317a6a9a4..464183da783 100644 --- a/src/backend/libpq/be-fsstubs.c +++ b/src/backend/libpq/be-fsstubs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/libpq/be-fsstubs.c,v 1.93 2010/01/02 16:57:45 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/libpq/be-fsstubs.c,v 1.94 2010/02/26 02:00:42 momjian Exp $ * * NOTES * This should be moved to a more appropriate place. It is here @@ -55,7 +55,7 @@ /* * compatibility flag for permission checks */ -bool lo_compat_privileges; +bool lo_compat_privileges; /*#define FSDB 1*/ #define BUFSIZE 8192 @@ -167,7 +167,7 @@ lo_read(int fd, char *buf, int len) pg_largeobject_aclcheck_snapshot(cookies[fd]->id, GetUserId(), ACL_SELECT, - cookies[fd]->snapshot) != ACLCHECK_OK) + cookies[fd]->snapshot) != ACLCHECK_OK) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("permission denied for large object %u", @@ -199,9 +199,9 @@ lo_write(int fd, const char *buf, int len) pg_largeobject_aclcheck_snapshot(cookies[fd]->id, GetUserId(), ACL_UPDATE, - cookies[fd]->snapshot) != ACLCHECK_OK) + cookies[fd]->snapshot) != ACLCHECK_OK) ereport(ERROR, - (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("permission denied for large object %u", cookies[fd]->id))); @@ -522,7 +522,7 @@ lo_truncate(PG_FUNCTION_ARGS) pg_largeobject_aclcheck_snapshot(cookies[fd]->id, GetUserId(), ACL_UPDATE, - cookies[fd]->snapshot) != ACLCHECK_OK) + cookies[fd]->snapshot) != ACLCHECK_OK) ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("permission denied for large object %u", diff --git a/src/backend/libpq/be-secure.c b/src/backend/libpq/be-secure.c index 6dac77bff78..19047bd148a 100644 --- a/src/backend/libpq/be-secure.c +++ b/src/backend/libpq/be-secure.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.98 2010/02/25 13:26:15 mha Exp $ + * $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.99 2010/02/26 02:00:42 momjian Exp $ * * Since the server static private key ($DataDir/server.key) * will normally be stored unencrypted so that the database @@ -98,7 +98,7 @@ static const char *SSLerrmessage(void); * (total in both directions) before we require renegotiation. * Set to 0 to disable renegotiation completely. */ -int ssl_renegotiation_limit; +int ssl_renegotiation_limit; #ifdef USE_SSL static SSL_CTX *SSL_context = NULL; @@ -973,8 +973,8 @@ aloop: else { /* - * Reject embedded NULLs in certificate common name to prevent attacks like - * CVE-2009-4034. + * Reject embedded NULLs in certificate common name to prevent + * attacks like CVE-2009-4034. */ if (r != strlen(port->peer_cn)) { diff --git a/src/backend/libpq/crypt.c b/src/backend/libpq/crypt.c index 56a20a67491..c956bf10a41 100644 --- a/src/backend/libpq/crypt.c +++ b/src/backend/libpq/crypt.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/libpq/crypt.c,v 1.80 2010/02/14 18:42:15 rhaas Exp $ + * $PostgreSQL: pgsql/src/backend/libpq/crypt.c,v 1.81 2010/02/26 02:00:42 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -41,8 +41,8 @@ md5_crypt_verify(const Port *port, const char *role, char *client_pass) bool isnull; /* - * Disable immediate interrupts while doing database access. (Note - * we don't bother to turn this back on if we hit one of the failure + * Disable immediate interrupts while doing database access. (Note we + * don't bother to turn this back on if we hit one of the failure * conditions, since we can expect we'll just exit right away anyway.) */ ImmediateInterruptOK = false; @@ -50,14 +50,14 @@ md5_crypt_verify(const Port *port, const char *role, char *client_pass) /* Get role info from pg_authid */ roleTup = SearchSysCache1(AUTHNAME, PointerGetDatum(role)); if (!HeapTupleIsValid(roleTup)) - return STATUS_ERROR; /* no such user */ + return STATUS_ERROR; /* no such user */ datum = SysCacheGetAttr(AUTHNAME, roleTup, Anum_pg_authid_rolpassword, &isnull); if (isnull) { ReleaseSysCache(roleTup); - return STATUS_ERROR; /* user has no password */ + return STATUS_ERROR; /* user has no password */ } shadow_pass = TextDatumGetCString(datum); @@ -69,7 +69,7 @@ md5_crypt_verify(const Port *port, const char *role, char *client_pass) ReleaseSysCache(roleTup); if (*shadow_pass == '\0') - return STATUS_ERROR; /* empty password */ + return STATUS_ERROR; /* empty password */ /* Re-enable immediate response to SIGTERM/SIGINT/timeout interrupts */ ImmediateInterruptOK = true; diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c index 94cff7cfd57..ae075ed939c 100644 --- a/src/backend/libpq/hba.c +++ b/src/backend/libpq/hba.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.197 2010/02/02 19:09:37 mha Exp $ + * $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.198 2010/02/26 02:00:43 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -56,8 +56,8 @@ static List *parsed_hba_lines = NIL; /* * These variables hold the pre-parsed contents of the ident usermap - * configuration file. ident_lines is a list of sublists, one sublist for - * each (non-empty, non-comment) line of the file. The sublist items are + * configuration file. ident_lines is a list of sublists, one sublist for + * each (non-empty, non-comment) line of the file. The sublist items are * palloc'd strings, one string per token on the line. Note there will always * be at least one token, since blank lines are not entered in the data * structure. ident_line_nums is an integer list containing the actual line @@ -529,14 +529,14 @@ check_db(const char *dbname, const char *role, Oid roleid, char *param_str) * Check to see if a connecting IP matches the given address and netmask. */ static bool -check_ip(SockAddr *raddr, struct sockaddr *addr, struct sockaddr *mask) +check_ip(SockAddr *raddr, struct sockaddr * addr, struct sockaddr * mask) { if (raddr->addr.ss_family == addr->sa_family) { /* Same address family */ if (!pg_range_sockaddr(&raddr->addr, - (struct sockaddr_storage*)addr, - (struct sockaddr_storage*)mask)) + (struct sockaddr_storage *) addr, + (struct sockaddr_storage *) mask)) return false; } #ifdef HAVE_IPV6 @@ -545,8 +545,8 @@ check_ip(SockAddr *raddr, struct sockaddr *addr, struct sockaddr *mask) { /* * If we're connected on IPv6 but the file specifies an IPv4 address - * to match against, promote the latter to an IPv6 address - * before trying to match the client's address. + * to match against, promote the latter to an IPv6 address before + * trying to match the client's address. */ struct sockaddr_storage addrcopy, maskcopy; @@ -573,7 +573,7 @@ check_ip(SockAddr *raddr, struct sockaddr *addr, struct sockaddr *mask) * pg_foreach_ifaddr callback: does client addr match this machine interface? */ static void -check_network_callback(struct sockaddr *addr, struct sockaddr *netmask, +check_network_callback(struct sockaddr * addr, struct sockaddr * netmask, void *cb_data) { check_network_data *cn = (check_network_data *) cb_data; @@ -587,7 +587,7 @@ check_network_callback(struct sockaddr *addr, struct sockaddr *netmask, { /* Make an all-ones netmask of appropriate length for family */ pg_sockaddr_cidr_mask(&mask, NULL, addr->sa_family); - cn->result = check_ip(cn->raddr, addr, (struct sockaddr*) &mask); + cn->result = check_ip(cn->raddr, addr, (struct sockaddr *) & mask); } else { @@ -825,13 +825,13 @@ parse_hba_line(List *line, int line_num, HbaLine *parsedline) if (pg_sockaddr_cidr_mask(&parsedline->mask, cidr_slash + 1, parsedline->addr.ss_family) < 0) { - *cidr_slash = '/'; /* restore token for message */ + *cidr_slash = '/'; /* restore token for message */ ereport(LOG, (errcode(ERRCODE_CONFIG_FILE_ERROR), errmsg("invalid CIDR mask in address \"%s\"", token), - errcontext("line %d of configuration file \"%s\"", - line_num, HbaFileName))); + errcontext("line %d of configuration file \"%s\"", + line_num, HbaFileName))); pfree(token); return false; } @@ -846,9 +846,9 @@ parse_hba_line(List *line, int line_num, HbaLine *parsedline) { ereport(LOG, (errcode(ERRCODE_CONFIG_FILE_ERROR), - errmsg("end-of-line before netmask specification"), - errcontext("line %d of configuration file \"%s\"", - line_num, HbaFileName))); + errmsg("end-of-line before netmask specification"), + errcontext("line %d of configuration file \"%s\"", + line_num, HbaFileName))); return false; } token = lfirst(line_item); @@ -860,8 +860,8 @@ parse_hba_line(List *line, int line_num, HbaLine *parsedline) (errcode(ERRCODE_CONFIG_FILE_ERROR), errmsg("invalid IP mask \"%s\": %s", token, gai_strerror(ret)), - errcontext("line %d of configuration file \"%s\"", - line_num, HbaFileName))); + errcontext("line %d of configuration file \"%s\"", + line_num, HbaFileName))); if (gai_result) pg_freeaddrinfo_all(hints.ai_family, gai_result); return false; @@ -952,7 +952,7 @@ parse_hba_line(List *line, int line_num, HbaLine *parsedline) #else unsupauth = "cert"; #endif - else if (strcmp(token, "radius")== 0) + else if (strcmp(token, "radius") == 0) parsedline->auth_method = uaRADIUS; else { @@ -1234,8 +1234,8 @@ parse_hba_line(List *line, int line_num, HbaLine *parsedline) /* * LDAP can operate in two modes: either with a direct bind, using - * ldapprefix and ldapsuffix, or using a search+bind, - * using ldapbasedn, ldapbinddn, ldapbindpasswd and ldapsearchattribute. + * ldapprefix and ldapsuffix, or using a search+bind, using + * ldapbasedn, ldapbinddn, ldapbindpasswd and ldapsearchattribute. * Disallow mixing these parameters. */ if (parsedline->ldapprefix || parsedline->ldapsuffix) @@ -1336,8 +1336,8 @@ check_hba(hbaPort *port) { case ipCmpMask: if (!check_ip(&port->raddr, - (struct sockaddr *) &hba->addr, - (struct sockaddr *) &hba->mask)) + (struct sockaddr *) & hba->addr, + (struct sockaddr *) & hba->mask)) continue; break; case ipCmpSameHost: diff --git a/src/backend/libpq/ip.c b/src/backend/libpq/ip.c index 778b9f9ea4a..7c17210cbe6 100644 --- a/src/backend/libpq/ip.c +++ b/src/backend/libpq/ip.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/libpq/ip.c,v 1.50 2010/01/10 14:16:07 mha Exp $ + * $PostgreSQL: pgsql/src/backend/libpq/ip.c,v 1.51 2010/02/26 02:00:43 momjian Exp $ * * This file and the IPV6 implementation were initially provided by * Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design @@ -482,7 +482,6 @@ pg_promote_v4_to_v6_mask(struct sockaddr_storage * addr) memcpy(addr, &addr6, sizeof(addr6)); } - #endif /* HAVE_IPV6 */ @@ -492,7 +491,7 @@ pg_promote_v4_to_v6_mask(struct sockaddr_storage * addr) */ static void run_ifaddr_callback(PgIfAddrCallback callback, void *cb_data, - struct sockaddr *addr, struct sockaddr *mask) + struct sockaddr * addr, struct sockaddr * mask) { struct sockaddr_storage fullmask; @@ -508,13 +507,13 @@ run_ifaddr_callback(PgIfAddrCallback callback, void *cb_data, } else if (mask->sa_family == AF_INET) { - if (((struct sockaddr_in*)mask)->sin_addr.s_addr == INADDR_ANY) + if (((struct sockaddr_in *) mask)->sin_addr.s_addr == INADDR_ANY) mask = NULL; } #ifdef HAVE_IPV6 else if (mask->sa_family == AF_INET6) { - if (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6*)mask)->sin6_addr)) + if (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *) mask)->sin6_addr)) mask = NULL; } #endif @@ -524,7 +523,7 @@ run_ifaddr_callback(PgIfAddrCallback callback, void *cb_data, if (!mask) { pg_sockaddr_cidr_mask(&fullmask, NULL, addr->sa_family); - mask = (struct sockaddr*) &fullmask; + mask = (struct sockaddr *) & fullmask; } (*callback) (addr, mask, cb_data); @@ -544,11 +543,13 @@ run_ifaddr_callback(PgIfAddrCallback callback, void *cb_data, int pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) { - INTERFACE_INFO *ptr, *ii = NULL; - unsigned long length, i; + INTERFACE_INFO *ptr, + *ii = NULL; + unsigned long length, + i; unsigned long n_ii = 0; - SOCKET sock; - int error; + SOCKET sock; + int error; sock = WSASocket(AF_INET, SOCK_DGRAM, 0, 0, 0, 0); if (sock == SOCKET_ERROR) @@ -557,7 +558,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) while (n_ii < 1024) { n_ii += 64; - ptr = realloc(ii, sizeof (INTERFACE_INFO) * n_ii); + ptr = realloc(ii, sizeof(INTERFACE_INFO) * n_ii); if (!ptr) { free(ii); @@ -568,8 +569,8 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) ii = ptr; if (WSAIoctl(sock, SIO_GET_INTERFACE_LIST, 0, 0, - ii, n_ii * sizeof (INTERFACE_INFO), - &length, 0, 0) == SOCKET_ERROR) + ii, n_ii * sizeof(INTERFACE_INFO), + &length, 0, 0) == SOCKET_ERROR) { error = WSAGetLastError(); if (error == WSAEFAULT || error == WSAENOBUFS) @@ -584,15 +585,14 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) for (i = 0; i < length / sizeof(INTERFACE_INFO); ++i) run_ifaddr_callback(callback, cb_data, - (struct sockaddr*)&ii[i].iiAddress, - (struct sockaddr*)&ii[i].iiNetmask); + (struct sockaddr *) & ii[i].iiAddress, + (struct sockaddr *) & ii[i].iiNetmask); closesocket(sock); free(ii); return 0; } - -#elif HAVE_GETIFADDRS /* && !WIN32 */ +#elif HAVE_GETIFADDRS /* && !WIN32 */ #ifdef HAVE_IFADDRS_H #include <ifaddrs.h> @@ -608,20 +608,20 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) int pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) { - struct ifaddrs *ifa, *l; + struct ifaddrs *ifa, + *l; if (getifaddrs(&ifa) < 0) return -1; for (l = ifa; l; l = l->ifa_next) run_ifaddr_callback(callback, cb_data, - l->ifa_addr, l->ifa_netmask); + l->ifa_addr, l->ifa_netmask); freeifaddrs(ifa); return 0; } - -#else /* !HAVE_GETIFADDRS && !WIN32 */ +#else /* !HAVE_GETIFADDRS && !WIN32 */ #ifdef HAVE_SYS_IOCTL_H #include <sys/ioctl.h> @@ -652,15 +652,21 @@ int pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) { struct lifconf lifc; - struct lifreq *lifr, lmask; - struct sockaddr *addr, *mask; - char *ptr, *buffer = NULL; - size_t n_buffer = 1024; - pgsocket sock, fd; + struct lifreq *lifr, + lmask; + struct sockaddr *addr, + *mask; + char *ptr, + *buffer = NULL; + size_t n_buffer = 1024; + pgsocket sock, + fd; + #ifdef HAVE_IPV6 - pgsocket sock6; + pgsocket sock6; #endif - int i, total; + int i, + total; sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock == -1) @@ -678,7 +684,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) return -1; } - memset(&lifc, 0, sizeof (lifc)); + memset(&lifc, 0, sizeof(lifc)); lifc.lifc_family = AF_UNSPEC; lifc.lifc_buf = buffer = ptr; lifc.lifc_len = n_buffer; @@ -693,9 +699,9 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) } /* - * Some Unixes try to return as much data as possible, - * with no indication of whether enough space allocated. - * Don't believe we have it all unless there's lots of slop. + * Some Unixes try to return as much data as possible, with no + * indication of whether enough space allocated. Don't believe we have + * it all unless there's lots of slop. */ if (lifc.lifc_len < n_buffer - 1024) break; @@ -716,7 +722,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) lifr = lifc.lifc_req; for (i = 0; i < total; ++i) { - addr = (struct sockaddr*)&lifr[i].lifr_addr; + addr = (struct sockaddr *) & lifr[i].lifr_addr; memcpy(&lmask, &lifr[i], sizeof(struct lifreq)); #ifdef HAVE_IPV6 fd = (addr->sa_family == AF_INET6) ? sock6 : sock; @@ -726,7 +732,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) if (ioctl(fd, SIOCGLIFNETMASK, &lmask) < 0) mask = NULL; else - mask = (struct sockaddr*)&lmask.lifr_addr; + mask = (struct sockaddr *) & lmask.lifr_addr; run_ifaddr_callback(callback, cb_data, addr, mask); } @@ -737,7 +743,6 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) #endif return 0; } - #elif defined(SIOCGIFCONF) /* @@ -754,17 +759,16 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) /* Calculate based on sockaddr.sa_len */ #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN #define _SIZEOF_ADDR_IFREQ(ifr) \ - ((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \ - (sizeof(struct ifreq) - sizeof(struct sockaddr) + \ - (ifr).ifr_addr.sa_len) : sizeof(struct ifreq)) + ((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \ + (sizeof(struct ifreq) - sizeof(struct sockaddr) + \ + (ifr).ifr_addr.sa_len) : sizeof(struct ifreq)) /* Padded ifreq structure, simple */ #else #define _SIZEOF_ADDR_IFREQ(ifr) \ sizeof (struct ifreq) #endif - -#endif /* !_SIZEOF_ADDR_IFREQ */ +#endif /* !_SIZEOF_ADDR_IFREQ */ /* * Enumerate the system's network interface addresses and call the callback @@ -776,10 +780,14 @@ int pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) { struct ifconf ifc; - struct ifreq *ifr, *end, addr, mask; - char *ptr, *buffer = NULL; - size_t n_buffer = 1024; - int sock; + struct ifreq *ifr, + *end, + addr, + mask; + char *ptr, + *buffer = NULL; + size_t n_buffer = 1024; + int sock; sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock == -1) @@ -797,7 +805,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) return -1; } - memset(&ifc, 0, sizeof (ifc)); + memset(&ifc, 0, sizeof(ifc)); ifc.ifc_buf = buffer = ptr; ifc.ifc_len = n_buffer; @@ -811,32 +819,31 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) } /* - * Some Unixes try to return as much data as possible, - * with no indication of whether enough space allocated. - * Don't believe we have it all unless there's lots of slop. + * Some Unixes try to return as much data as possible, with no + * indication of whether enough space allocated. Don't believe we have + * it all unless there's lots of slop. */ if (ifc.ifc_len < n_buffer - 1024) break; } - end = (struct ifreq*)(buffer + ifc.ifc_len); + end = (struct ifreq *) (buffer + ifc.ifc_len); for (ifr = ifc.ifc_req; ifr < end;) { memcpy(&addr, ifr, sizeof(addr)); memcpy(&mask, ifr, sizeof(mask)); if (ioctl(sock, SIOCGIFADDR, &addr, sizeof(addr)) == 0 && - ioctl(sock, SIOCGIFNETMASK, &mask, sizeof(mask)) == 0) + ioctl(sock, SIOCGIFNETMASK, &mask, sizeof(mask)) == 0) run_ifaddr_callback(callback, cb_data, - &addr.ifr_addr, &mask.ifr_addr); - ifr = (struct ifreq*)((char*)ifr + _SIZEOF_ADDR_IFREQ(*ifr)); + &addr.ifr_addr, &mask.ifr_addr); + ifr = (struct ifreq *) ((char *) ifr + _SIZEOF_ADDR_IFREQ(*ifr)); } free(buffer); close(sock); return 0; } - -#else /* !defined(SIOCGIFCONF) */ +#else /* !defined(SIOCGIFCONF) */ /* * Enumerate the system's network interface addresses and call the callback @@ -850,6 +857,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) { struct sockaddr_in addr; struct sockaddr_storage mask; + #ifdef HAVE_IPV6 struct sockaddr_in6 addr6; #endif @@ -861,8 +869,8 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) memset(&mask, 0, sizeof(mask)); pg_sockaddr_cidr_mask(&mask, "8", AF_INET); run_ifaddr_callback(callback, cb_data, - (struct sockaddr*)&addr, - (struct sockaddr*)&mask); + (struct sockaddr *) & addr, + (struct sockaddr *) & mask); #ifdef HAVE_IPV6 /* addr ::1/128 */ @@ -872,13 +880,12 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data) memset(&mask, 0, sizeof(mask)); pg_sockaddr_cidr_mask(&mask, "128", AF_INET6); run_ifaddr_callback(callback, cb_data, - (struct sockaddr*)&addr6, - (struct sockaddr*)&mask); + (struct sockaddr *) & addr6, + (struct sockaddr *) & mask); #endif return 0; } +#endif /* !defined(SIOCGIFCONF) */ -#endif /* !defined(SIOCGIFCONF) */ - -#endif /* !HAVE_GETIFADDRS */ +#endif /* !HAVE_GETIFADDRS */ diff --git a/src/backend/libpq/md5.c b/src/backend/libpq/md5.c index e875f51ed72..ff4f9eaebf1 100644 --- a/src/backend/libpq/md5.c +++ b/src/backend/libpq/md5.c @@ -14,7 +14,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/libpq/md5.c,v 1.39 2010/01/27 12:11:59 mha Exp $ + * $PostgreSQL: pgsql/src/backend/libpq/md5.c,v 1.40 2010/02/26 02:00:43 momjian Exp $ */ /* This is intended to be used in both frontend and backend, so use c.h */ @@ -298,7 +298,8 @@ pg_md5_hash(const void *buff, size_t len, char *hexsum) return true; } -bool pg_md5_binary(const void *buff, size_t len, void *outbuf) +bool +pg_md5_binary(const void *buff, size_t len, void *outbuf) { if (!calculateDigestFromBuffer((uint8 *) buff, len, outbuf)) return false; @@ -320,6 +321,7 @@ pg_md5_encrypt(const char *passwd, const char *salt, size_t salt_len, char *buf) { size_t passwd_len = strlen(passwd); + /* +1 here is just to avoid risk of unportable malloc(0) */ char *crypt_buf = malloc(passwd_len + salt_len + 1); bool ret; diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c index 98b27f1f71a..5826aacaf77 100644 --- a/src/backend/libpq/pqcomm.c +++ b/src/backend/libpq/pqcomm.c @@ -30,7 +30,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.204 2010/02/18 11:13:45 heikki Exp $ + * $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.205 2010/02/26 02:00:43 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -55,7 +55,7 @@ * pq_peekbyte - peek at next byte from connection * pq_putbytes - send bytes to connection (not flushed until pq_flush) * pq_flush - flush pending output - * pq_getbyte_if_available - get a byte if available without blocking + * pq_getbyte_if_available - get a byte if available without blocking * * message-level I/O (and old-style-COPY-OUT cruft): * pq_putmessage - send a normal message (suppressed in COPY OUT mode) @@ -200,7 +200,8 @@ pq_close(int code, Datum arg) * transport layer reports connection closure, and you can be sure the * backend has exited. * - * We do set sock to PGINVALID_SOCKET to prevent any further I/O, though. + * We do set sock to PGINVALID_SOCKET to prevent any further I/O, + * though. */ MyProcPort->sock = PGINVALID_SOCKET; } @@ -818,7 +819,7 @@ pq_peekbyte(void) /* -------------------------------- - * pq_getbyte_if_available - get a single byte from connection, + * pq_getbyte_if_available - get a single byte from connection, * if available * * The received byte is stored in *c. Returns 1 if a byte was read, @@ -828,7 +829,7 @@ pq_peekbyte(void) int pq_getbyte_if_available(unsigned char *c) { - int r; + int r; if (PqRecvPointer < PqRecvLength) { @@ -851,18 +852,19 @@ pq_getbyte_if_available(unsigned char *c) if (r < 0) { /* - * Ok if no data available without blocking or interrupted - * (though EINTR really shouldn't happen with a non-blocking - * socket). Report other errors. + * Ok if no data available without blocking or interrupted (though + * EINTR really shouldn't happen with a non-blocking socket). + * Report other errors. */ if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) r = 0; else { /* - * 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(), |
