mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
pgindent run.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.89 2002/09/02 02:47:02 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.90 2002/09/04 20:31:18 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -130,7 +130,6 @@ pg_krb4_recvauth(Port *port)
|
||||
elog(LOG, "pg_krb4_recvauth: Kerberos not implemented on this server");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
#endif /* KRB4 */
|
||||
|
||||
|
||||
@@ -310,7 +309,6 @@ pg_krb5_recvauth(Port *port)
|
||||
elog(LOG, "pg_krb5_recvauth: Kerberos not implemented on this server");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
#endif /* KRB5 */
|
||||
|
||||
|
||||
@@ -416,7 +414,7 @@ ClientAuthentication(Port *port)
|
||||
if (port->raddr.sa.sa_family == AF_INET)
|
||||
hostinfo = inet_ntoa(port->raddr.in.sin_addr);
|
||||
elog(FATAL,
|
||||
"No pg_hba.conf entry for host %s, user %s, database %s",
|
||||
"No pg_hba.conf entry for host %s, user %s, database %s",
|
||||
hostinfo, port->user, port->database);
|
||||
break;
|
||||
}
|
||||
@@ -513,8 +511,8 @@ sendAuthRequest(Port *port, AuthRequest areq)
|
||||
pq_endmessage(&buf);
|
||||
|
||||
/*
|
||||
* Flush message so client will see it, except for AUTH_REQ_OK,
|
||||
* which need not be sent until we are ready for queries.
|
||||
* Flush message so client will see it, except for AUTH_REQ_OK, which
|
||||
* need not be sent until we are ready for queries.
|
||||
*/
|
||||
if (areq != AUTH_REQ_OK)
|
||||
pq_flush();
|
||||
@@ -688,7 +686,7 @@ CheckPAMAuth(Port *port, char *user, char *password)
|
||||
pam_strerror(pamh, retval));
|
||||
}
|
||||
|
||||
pam_passwd = NULL; /* Unset pam_passwd */
|
||||
pam_passwd = NULL; /* Unset pam_passwd */
|
||||
|
||||
return (retval == PAM_SUCCESS ? STATUS_OK : STATUS_ERROR);
|
||||
}
|
||||
@@ -714,13 +712,14 @@ recv_and_check_password_packet(Port *port)
|
||||
pfree(buf.data);
|
||||
return STATUS_EOF;
|
||||
}
|
||||
|
||||
/*
|
||||
* We don't actually use the password packet length the frontend
|
||||
* sent us; however, it's a reasonable sanity check to ensure that
|
||||
* we actually read as much data as we expected to.
|
||||
* We don't actually use the password packet length the frontend sent
|
||||
* us; however, it's a reasonable sanity check to ensure that we
|
||||
* actually read as much data as we expected to.
|
||||
*
|
||||
* The password packet size is the length of the buffer, plus the
|
||||
* size field itself (4 bytes), plus a 1-byte terminator.
|
||||
* The password packet size is the length of the buffer, plus the size
|
||||
* field itself (4 bytes), plus a 1-byte terminator.
|
||||
*/
|
||||
if (len != (buf.len + 4 + 1))
|
||||
elog(LOG, "unexpected password packet size: read %d, expected %d",
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.12 2002/09/02 02:47:02 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.13 2002/09/04 20:31:19 momjian Exp $
|
||||
*
|
||||
* Since the server static private key ($DataDir/server.key)
|
||||
* will normally be stored unencrypted so that the database
|
||||
@@ -30,13 +30,13 @@
|
||||
* impersonations.
|
||||
*
|
||||
* Another benefit of EDH is that it allows the backend and
|
||||
* clients to use DSA keys. DSA keys can only provide digital
|
||||
* clients to use DSA keys. DSA keys can only provide digital
|
||||
* signatures, not encryption, and are often acceptable in
|
||||
* jurisdictions where RSA keys are unacceptable.
|
||||
*
|
||||
* The downside to EDH is that it makes it impossible to
|
||||
* use ssldump(1) if there's a problem establishing an SSL
|
||||
* session. In this case you'll need to temporarily disable
|
||||
* session. In this case you'll need to temporarily disable
|
||||
* EDH by commenting out the callback.
|
||||
*
|
||||
* ...
|
||||
@@ -49,7 +49,7 @@
|
||||
* milestone 1: fix basic coding errors
|
||||
* [*] existing SSL code pulled out of existing files.
|
||||
* [*] SSL_get_error() after SSL_read() and SSL_write(),
|
||||
* SSL_shutdown(), default to TLSv1.
|
||||
* SSL_shutdown(), default to TLSv1.
|
||||
*
|
||||
* milestone 2: provide endpoint authentication (server)
|
||||
* [*] client verifies server cert
|
||||
@@ -112,22 +112,22 @@
|
||||
extern void ExitPostmaster(int);
|
||||
extern void postmaster_error(const char *fmt,...);
|
||||
|
||||
int secure_initialize(void);
|
||||
void secure_destroy(void);
|
||||
int secure_open_server(Port *);
|
||||
void secure_close(Port *);
|
||||
ssize_t secure_read(Port *, void *ptr, size_t len);
|
||||
ssize_t secure_write(Port *, const void *ptr, size_t len);
|
||||
int secure_initialize(void);
|
||||
void secure_destroy(void);
|
||||
int secure_open_server(Port *);
|
||||
void secure_close(Port *);
|
||||
ssize_t secure_read(Port *, void *ptr, size_t len);
|
||||
ssize_t secure_write(Port *, const void *ptr, size_t len);
|
||||
|
||||
#ifdef USE_SSL
|
||||
static DH *load_dh_file(int keylength);
|
||||
static DH *load_dh_buffer(const char *, size_t);
|
||||
static DH *tmp_dh_cb(SSL *s, int is_export, int keylength);
|
||||
static int verify_cb(int, X509_STORE_CTX *);
|
||||
static DH *load_dh_file(int keylength);
|
||||
static DH *load_dh_buffer(const char *, size_t);
|
||||
static DH *tmp_dh_cb(SSL *s, int is_export, int keylength);
|
||||
static int verify_cb(int, X509_STORE_CTX *);
|
||||
static void info_cb(SSL *ssl, int type, int args);
|
||||
static int initialize_SSL(void);
|
||||
static int initialize_SSL(void);
|
||||
static void destroy_SSL(void);
|
||||
static int open_server_SSL(Port *);
|
||||
static int open_server_SSL(Port *);
|
||||
static void close_SSL(Port *);
|
||||
static const char *SSLerrmessage(void);
|
||||
#endif
|
||||
@@ -137,13 +137,13 @@ static const char *SSLerrmessage(void);
|
||||
* How much data can be sent across a secure connection
|
||||
* (total in both directions) before we require renegotiation.
|
||||
*/
|
||||
#define RENEGOTIATION_LIMIT (64 * 1024)
|
||||
#define CA_PATH NULL
|
||||
#define RENEGOTIATION_LIMIT (64 * 1024)
|
||||
#define CA_PATH NULL
|
||||
static SSL_CTX *SSL_context = NULL;
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* Hardcoded values */
|
||||
/* Hardcoded values */
|
||||
/* ------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
@@ -207,16 +207,16 @@ KWbuHn491xNO25CQWMtem80uKw+pTnisBRF/454n1Jnhub144YRBoN8CAQI=\n\
|
||||
-----END DH PARAMETERS-----\n";
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* Procedures common to all secure sessions */
|
||||
/* Procedures common to all secure sessions */
|
||||
/* ------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
* Initialize global context
|
||||
*/
|
||||
int
|
||||
secure_initialize (void)
|
||||
secure_initialize(void)
|
||||
{
|
||||
int r = 0;
|
||||
int r = 0;
|
||||
|
||||
#ifdef USE_SSL
|
||||
r = initialize_SSL();
|
||||
@@ -229,7 +229,7 @@ secure_initialize (void)
|
||||
* Destroy global context
|
||||
*/
|
||||
void
|
||||
secure_destroy (void)
|
||||
secure_destroy(void)
|
||||
{
|
||||
#ifdef USE_SSL
|
||||
destroy_SSL();
|
||||
@@ -240,9 +240,9 @@ secure_destroy (void)
|
||||
* Attempt to negotiate secure session.
|
||||
*/
|
||||
int
|
||||
secure_open_server (Port *port)
|
||||
secure_open_server(Port *port)
|
||||
{
|
||||
int r = 0;
|
||||
int r = 0;
|
||||
|
||||
#ifdef USE_SSL
|
||||
r = open_server_SSL(port);
|
||||
@@ -255,7 +255,7 @@ secure_open_server (Port *port)
|
||||
* Close secure session.
|
||||
*/
|
||||
void
|
||||
secure_close (Port *port)
|
||||
secure_close(Port *port)
|
||||
{
|
||||
#ifdef USE_SSL
|
||||
if (port->ssl)
|
||||
@@ -267,9 +267,9 @@ secure_close (Port *port)
|
||||
* Read data from a secure connection.
|
||||
*/
|
||||
ssize_t
|
||||
secure_read (Port *port, void *ptr, size_t len)
|
||||
secure_read(Port *port, void *ptr, size_t len)
|
||||
{
|
||||
ssize_t n;
|
||||
ssize_t n;
|
||||
|
||||
#ifdef USE_SSL
|
||||
if (port->ssl)
|
||||
@@ -283,28 +283,28 @@ secure_read (Port *port, void *ptr, size_t len)
|
||||
n = SSL_read(port->ssl, ptr, len);
|
||||
switch (SSL_get_error(port->ssl, n))
|
||||
{
|
||||
case SSL_ERROR_NONE:
|
||||
port->count += n;
|
||||
break;
|
||||
case SSL_ERROR_WANT_READ:
|
||||
break;
|
||||
case SSL_ERROR_SYSCALL:
|
||||
errno = get_last_socket_error();
|
||||
elog(ERROR, "SSL SYSCALL error: %s", strerror(errno));
|
||||
break;
|
||||
case SSL_ERROR_SSL:
|
||||
elog(ERROR, "SSL error: %s", SSLerrmessage());
|
||||
/* fall through */
|
||||
case SSL_ERROR_ZERO_RETURN:
|
||||
secure_close(port);
|
||||
errno = ECONNRESET;
|
||||
n = -1;
|
||||
break;
|
||||
case SSL_ERROR_NONE:
|
||||
port->count += n;
|
||||
break;
|
||||
case SSL_ERROR_WANT_READ:
|
||||
break;
|
||||
case SSL_ERROR_SYSCALL:
|
||||
errno = get_last_socket_error();
|
||||
elog(ERROR, "SSL SYSCALL error: %s", strerror(errno));
|
||||
break;
|
||||
case SSL_ERROR_SSL:
|
||||
elog(ERROR, "SSL error: %s", SSLerrmessage());
|
||||
/* fall through */
|
||||
case SSL_ERROR_ZERO_RETURN:
|
||||
secure_close(port);
|
||||
errno = ECONNRESET;
|
||||
n = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
n = recv(port->sock, ptr, len, 0);
|
||||
n = recv(port->sock, ptr, len, 0);
|
||||
|
||||
return n;
|
||||
}
|
||||
@@ -313,12 +313,12 @@ secure_read (Port *port, void *ptr, size_t len)
|
||||
* Write data to a secure connection.
|
||||
*/
|
||||
ssize_t
|
||||
secure_write (Port *port, const void *ptr, size_t len)
|
||||
secure_write(Port *port, const void *ptr, size_t len)
|
||||
{
|
||||
ssize_t n;
|
||||
ssize_t n;
|
||||
|
||||
#ifndef WIN32
|
||||
pqsigfunc oldsighandler = pqsignal(SIGPIPE, SIG_IGN);
|
||||
pqsigfunc oldsighandler = pqsignal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
|
||||
#ifdef USE_SSL
|
||||
@@ -333,28 +333,28 @@ secure_write (Port *port, const void *ptr, size_t len)
|
||||
n = SSL_write(port->ssl, ptr, len);
|
||||
switch (SSL_get_error(port->ssl, n))
|
||||
{
|
||||
case SSL_ERROR_NONE:
|
||||
port->count += n;
|
||||
break;
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
break;
|
||||
case SSL_ERROR_SYSCALL:
|
||||
errno = get_last_socket_error();
|
||||
elog(ERROR, "SSL SYSCALL error: %s", strerror(errno));
|
||||
break;
|
||||
case SSL_ERROR_SSL:
|
||||
elog(ERROR, "SSL error: %s", SSLerrmessage());
|
||||
/* fall through */
|
||||
case SSL_ERROR_ZERO_RETURN:
|
||||
secure_close(port);
|
||||
errno = ECONNRESET;
|
||||
n = -1;
|
||||
break;
|
||||
case SSL_ERROR_NONE:
|
||||
port->count += n;
|
||||
break;
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
break;
|
||||
case SSL_ERROR_SYSCALL:
|
||||
errno = get_last_socket_error();
|
||||
elog(ERROR, "SSL SYSCALL error: %s", strerror(errno));
|
||||
break;
|
||||
case SSL_ERROR_SSL:
|
||||
elog(ERROR, "SSL error: %s", SSLerrmessage());
|
||||
/* fall through */
|
||||
case SSL_ERROR_ZERO_RETURN:
|
||||
secure_close(port);
|
||||
errno = ECONNRESET;
|
||||
n = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
n = send(port->sock, ptr, len, 0);
|
||||
n = send(port->sock, ptr, len, 0);
|
||||
|
||||
#ifndef WIN32
|
||||
pqsignal(SIGPIPE, oldsighandler);
|
||||
@@ -364,7 +364,7 @@ secure_write (Port *port, const void *ptr, size_t len)
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* SSL specific code */
|
||||
/* SSL specific code */
|
||||
/* ------------------------------------------------------------ */
|
||||
#ifdef USE_SSL
|
||||
/*
|
||||
@@ -374,13 +374,13 @@ secure_write (Port *port, const void *ptr, size_t len)
|
||||
* to verify that the DBA-generated DH parameters file contains
|
||||
* what we expect it to contain.
|
||||
*/
|
||||
static DH *
|
||||
load_dh_file (int keylength)
|
||||
static DH *
|
||||
load_dh_file(int keylength)
|
||||
{
|
||||
FILE *fp;
|
||||
char fnbuf[2048];
|
||||
DH *dh = NULL;
|
||||
int codes;
|
||||
FILE *fp;
|
||||
char fnbuf[2048];
|
||||
DH *dh = NULL;
|
||||
int codes;
|
||||
|
||||
/* attempt to open file. It's not an error if it doesn't exist. */
|
||||
snprintf(fnbuf, sizeof fnbuf, "%s/dh%d.pem", DataDir, keylength);
|
||||
@@ -393,10 +393,10 @@ load_dh_file (int keylength)
|
||||
fclose(fp);
|
||||
|
||||
/* is the prime the correct size? */
|
||||
if (dh != NULL && 8*DH_size(dh) < keylength)
|
||||
if (dh != NULL && 8 * DH_size(dh) < keylength)
|
||||
{
|
||||
elog(LOG, "DH errors (%s): %d bits expected, %d bits found",
|
||||
fnbuf, keylength, 8*DH_size(dh));
|
||||
fnbuf, keylength, 8 * DH_size(dh));
|
||||
dh = NULL;
|
||||
}
|
||||
|
||||
@@ -417,8 +417,8 @@ load_dh_file (int keylength)
|
||||
(codes & DH_CHECK_P_NOT_SAFE_PRIME))
|
||||
{
|
||||
elog(LOG,
|
||||
"DH error (%s): neither suitable generator or safe prime",
|
||||
fnbuf);
|
||||
"DH error (%s): neither suitable generator or safe prime",
|
||||
fnbuf);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -432,11 +432,11 @@ load_dh_file (int keylength)
|
||||
* To prevent problems if the DH parameters files don't even
|
||||
* exist, we can load DH parameters hardcoded into this file.
|
||||
*/
|
||||
static DH *
|
||||
load_dh_buffer (const char *buffer, size_t len)
|
||||
static DH *
|
||||
load_dh_buffer(const char *buffer, size_t len)
|
||||
{
|
||||
BIO *bio;
|
||||
DH *dh = NULL;
|
||||
BIO *bio;
|
||||
DH *dh = NULL;
|
||||
|
||||
bio = BIO_new_mem_buf((char *) buffer, len);
|
||||
if (bio == NULL)
|
||||
@@ -462,58 +462,58 @@ load_dh_buffer (const char *buffer, size_t len)
|
||||
* the OpenSSL library can efficiently generate random keys from
|
||||
* the information provided.
|
||||
*/
|
||||
static DH *
|
||||
tmp_dh_cb (SSL *s, int is_export, int keylength)
|
||||
static DH *
|
||||
tmp_dh_cb(SSL *s, int is_export, int keylength)
|
||||
{
|
||||
DH *r = NULL;
|
||||
static DH *dh = NULL;
|
||||
static DH *dh512 = NULL;
|
||||
static DH *dh1024 = NULL;
|
||||
static DH *dh2048 = NULL;
|
||||
static DH *dh4096 = NULL;
|
||||
DH *r = NULL;
|
||||
static DH *dh = NULL;
|
||||
static DH *dh512 = NULL;
|
||||
static DH *dh1024 = NULL;
|
||||
static DH *dh2048 = NULL;
|
||||
static DH *dh4096 = NULL;
|
||||
|
||||
switch (keylength)
|
||||
{
|
||||
case 512:
|
||||
if (dh512 == NULL)
|
||||
dh512 = load_dh_file(keylength);
|
||||
if (dh512 == NULL)
|
||||
dh512 = load_dh_buffer(file_dh512, sizeof file_dh512);
|
||||
r = dh512;
|
||||
break;
|
||||
case 512:
|
||||
if (dh512 == NULL)
|
||||
dh512 = load_dh_file(keylength);
|
||||
if (dh512 == NULL)
|
||||
dh512 = load_dh_buffer(file_dh512, sizeof file_dh512);
|
||||
r = dh512;
|
||||
break;
|
||||
|
||||
case 1024:
|
||||
if (dh1024 == NULL)
|
||||
dh1024 = load_dh_file(keylength);
|
||||
if (dh1024 == NULL)
|
||||
dh1024 = load_dh_buffer(file_dh1024, sizeof file_dh1024);
|
||||
r = dh1024;
|
||||
break;
|
||||
case 1024:
|
||||
if (dh1024 == NULL)
|
||||
dh1024 = load_dh_file(keylength);
|
||||
if (dh1024 == NULL)
|
||||
dh1024 = load_dh_buffer(file_dh1024, sizeof file_dh1024);
|
||||
r = dh1024;
|
||||
break;
|
||||
|
||||
case 2048:
|
||||
if (dh2048 == NULL)
|
||||
dh2048 = load_dh_file(keylength);
|
||||
if (dh2048 == NULL)
|
||||
dh2048 = load_dh_buffer(file_dh2048, sizeof file_dh2048);
|
||||
r = dh2048;
|
||||
break;
|
||||
case 2048:
|
||||
if (dh2048 == NULL)
|
||||
dh2048 = load_dh_file(keylength);
|
||||
if (dh2048 == NULL)
|
||||
dh2048 = load_dh_buffer(file_dh2048, sizeof file_dh2048);
|
||||
r = dh2048;
|
||||
break;
|
||||
|
||||
case 4096:
|
||||
if (dh4096 == NULL)
|
||||
dh4096 = load_dh_file(keylength);
|
||||
if (dh4096 == NULL)
|
||||
dh4096 = load_dh_buffer(file_dh4096, sizeof file_dh4096);
|
||||
r = dh4096;
|
||||
break;
|
||||
case 4096:
|
||||
if (dh4096 == NULL)
|
||||
dh4096 = load_dh_file(keylength);
|
||||
if (dh4096 == NULL)
|
||||
dh4096 = load_dh_buffer(file_dh4096, sizeof file_dh4096);
|
||||
r = dh4096;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (dh == NULL)
|
||||
dh = load_dh_file(keylength);
|
||||
r = dh;
|
||||
default:
|
||||
if (dh == NULL)
|
||||
dh = load_dh_file(keylength);
|
||||
r = dh;
|
||||
}
|
||||
|
||||
/* this may take a long time, but it may be necessary... */
|
||||
if (r == NULL || 8*DH_size(r) < keylength)
|
||||
if (r == NULL || 8 * DH_size(r) < keylength)
|
||||
{
|
||||
elog(DEBUG1, "DH: generating parameters (%d bits)....", keylength);
|
||||
r = DH_generate_parameters(keylength, DH_GENERATOR_2, NULL, NULL);
|
||||
@@ -534,7 +534,7 @@ tmp_dh_cb (SSL *s, int is_export, int keylength)
|
||||
* for now we accept the default checks.
|
||||
*/
|
||||
static int
|
||||
verify_cb (int ok, X509_STORE_CTX *ctx)
|
||||
verify_cb(int ok, X509_STORE_CTX *ctx)
|
||||
{
|
||||
return ok;
|
||||
}
|
||||
@@ -544,7 +544,7 @@ verify_cb (int ok, X509_STORE_CTX *ctx)
|
||||
* into the PostgreSQL log.
|
||||
*/
|
||||
static void
|
||||
info_cb (SSL *ssl, int type, int args)
|
||||
info_cb(SSL *ssl, int type, int args)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
@@ -579,9 +579,9 @@ info_cb (SSL *ssl, int type, int args)
|
||||
* Initialize global SSL context.
|
||||
*/
|
||||
static int
|
||||
initialize_SSL (void)
|
||||
initialize_SSL(void)
|
||||
{
|
||||
char fnbuf[2048];
|
||||
char fnbuf[2048];
|
||||
struct stat buf;
|
||||
|
||||
if (!SSL_context)
|
||||
@@ -597,7 +597,7 @@ initialize_SSL (void)
|
||||
}
|
||||
|
||||
/*
|
||||
* Load and verify certificate and private key
|
||||
* Load and verify certificate and private key
|
||||
*/
|
||||
snprintf(fnbuf, sizeof(fnbuf), "%s/server.crt", DataDir);
|
||||
if (!SSL_CTX_use_certificate_file(SSL_context, fnbuf, SSL_FILETYPE_PEM))
|
||||
@@ -647,7 +647,7 @@ initialize_SSL (void)
|
||||
ExitPostmaster(1);
|
||||
}
|
||||
SSL_CTX_set_verify(SSL_context,
|
||||
SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, verify_cb);
|
||||
SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, verify_cb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -656,7 +656,7 @@ initialize_SSL (void)
|
||||
* Destroy global SSL context.
|
||||
*/
|
||||
static void
|
||||
destroy_SSL (void)
|
||||
destroy_SSL(void)
|
||||
{
|
||||
if (SSL_context)
|
||||
{
|
||||
@@ -669,7 +669,7 @@ destroy_SSL (void)
|
||||
* Attempt to negotiate SSL connection.
|
||||
*/
|
||||
static int
|
||||
open_server_SSL (Port *port)
|
||||
open_server_SSL(Port *port)
|
||||
{
|
||||
if (!(port->ssl = SSL_new(SSL_context)) ||
|
||||
!SSL_set_fd(port->ssl, port->sock) ||
|
||||
@@ -685,17 +685,17 @@ open_server_SSL (Port *port)
|
||||
port->peer = SSL_get_peer_certificate(port->ssl);
|
||||
if (port->peer == NULL)
|
||||
{
|
||||
strncpy(port->peer_dn, "(anonymous)", sizeof (port->peer_dn));
|
||||
strncpy(port->peer_cn, "(anonymous)", sizeof (port->peer_cn));
|
||||
strncpy(port->peer_dn, "(anonymous)", sizeof(port->peer_dn));
|
||||
strncpy(port->peer_cn, "(anonymous)", sizeof(port->peer_cn));
|
||||
}
|
||||
else
|
||||
{
|
||||
X509_NAME_oneline(X509_get_subject_name(port->peer),
|
||||
port->peer_dn, sizeof (port->peer_dn));
|
||||
port->peer_dn[sizeof(port->peer_dn)-1] = '\0';
|
||||
port->peer_dn, sizeof(port->peer_dn));
|
||||
port->peer_dn[sizeof(port->peer_dn) - 1] = '\0';
|
||||
X509_NAME_get_text_by_NID(X509_get_subject_name(port->peer),
|
||||
NID_commonName, port->peer_cn, sizeof (port->peer_cn));
|
||||
port->peer_cn[sizeof(port->peer_cn)-1] = '\0';
|
||||
NID_commonName, port->peer_cn, sizeof(port->peer_cn));
|
||||
port->peer_cn[sizeof(port->peer_cn) - 1] = '\0';
|
||||
}
|
||||
elog(DEBUG1, "secure connection from '%s'", port->peer_cn);
|
||||
|
||||
@@ -709,7 +709,7 @@ open_server_SSL (Port *port)
|
||||
* Close SSL connection.
|
||||
*/
|
||||
static void
|
||||
close_SSL (Port *port)
|
||||
close_SSL(Port *port)
|
||||
{
|
||||
if (port->ssl)
|
||||
{
|
||||
@@ -729,9 +729,9 @@ close_SSL (Port *port)
|
||||
static const char *
|
||||
SSLerrmessage(void)
|
||||
{
|
||||
unsigned long errcode;
|
||||
const char *errreason;
|
||||
static char errbuf[32];
|
||||
unsigned long errcode;
|
||||
const char *errreason;
|
||||
static char errbuf[32];
|
||||
|
||||
errcode = ERR_get_error();
|
||||
if (errcode == 0)
|
||||
@@ -743,4 +743,4 @@ SSLerrmessage(void)
|
||||
return errbuf;
|
||||
}
|
||||
|
||||
#endif /* USE_SSL */
|
||||
#endif /* USE_SSL */
|
||||
|
||||
@@ -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.48 2002/06/20 20:29:28 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/crypt.c,v 1.49 2002/09/04 20:31:19 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -35,9 +35,9 @@ md5_crypt_verify(const Port *port, const char *user, const char *pgpass)
|
||||
*valuntil = NULL,
|
||||
*crypt_pwd;
|
||||
int retval = STATUS_ERROR;
|
||||
List **line;
|
||||
List *token;
|
||||
|
||||
List **line;
|
||||
List *token;
|
||||
|
||||
if ((line = get_user_line(user)) == NULL)
|
||||
return STATUS_ERROR;
|
||||
|
||||
@@ -50,7 +50,7 @@ md5_crypt_verify(const Port *port, const char *user, const char *pgpass)
|
||||
if (token)
|
||||
valuntil = lfirst(token);
|
||||
}
|
||||
|
||||
|
||||
if (passwd == NULL || *passwd == '\0')
|
||||
return STATUS_ERROR;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.86 2002/09/02 02:47:02 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.87 2002/09/04 20:31:19 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -41,7 +41,7 @@
|
||||
/* Max size of username ident server can return */
|
||||
|
||||
/* This is used to separate values in multi-valued column strings */
|
||||
#define MULTI_VALUE_SEP "\001"
|
||||
#define MULTI_VALUE_SEP "\001"
|
||||
|
||||
/*
|
||||
* These variables hold the pre-parsed contents of the hba and ident
|
||||
@@ -54,14 +54,16 @@
|
||||
*/
|
||||
static List *hba_lines = NIL; /* pre-parsed contents of hba file */
|
||||
static List *ident_lines = NIL; /* pre-parsed contents of ident file */
|
||||
static List *group_lines = NIL; /* pre-parsed contents of group file */
|
||||
static List *user_lines = NIL; /* pre-parsed contents of user password file */
|
||||
static List *group_lines = NIL; /* pre-parsed contents of group file */
|
||||
static List *user_lines = NIL; /* pre-parsed contents of user password
|
||||
* file */
|
||||
|
||||
/* sorted entries so we can do binary search lookups */
|
||||
static List **user_sorted = NULL; /* sorted user list, for bsearch() */
|
||||
static List **group_sorted = NULL; /* sorted group list, for bsearch() */
|
||||
static int user_length;
|
||||
static int group_length;
|
||||
static List **user_sorted = NULL; /* sorted user list, for bsearch() */
|
||||
static List **group_sorted = NULL; /* sorted group list, for
|
||||
* bsearch() */
|
||||
static int user_length;
|
||||
static int group_length;
|
||||
|
||||
static List *tokenize_file(FILE *file);
|
||||
static char *tokenize_inc_file(const char *inc_filename);
|
||||
@@ -78,14 +80,14 @@ isblank(const char c)
|
||||
|
||||
|
||||
/*
|
||||
* Grab one token out of fp. Tokens are strings of non-blank
|
||||
* characters bounded by blank characters, beginning of line, and
|
||||
* end of line. Blank means space or tab. Return the token as
|
||||
* *buf. Leave file positioned to character immediately after the
|
||||
* token or EOF, whichever comes first. If no more tokens on line,
|
||||
* return null string as *buf and position file to beginning of
|
||||
* next line or EOF, whichever comes first. Allow spaces in quoted
|
||||
* strings. Terminate on unquoted commas. Handle comments.
|
||||
* Grab one token out of fp. Tokens are strings of non-blank
|
||||
* characters bounded by blank characters, beginning of line, and
|
||||
* end of line. Blank means space or tab. Return the token as
|
||||
* *buf. Leave file positioned to character immediately after the
|
||||
* token or EOF, whichever comes first. If no more tokens on line,
|
||||
* return null string as *buf and position file to beginning of
|
||||
* next line or EOF, whichever comes first. Allow spaces in quoted
|
||||
* strings. Terminate on unquoted commas. Handle comments.
|
||||
*/
|
||||
void
|
||||
next_token(FILE *fp, char *buf, const int bufsz)
|
||||
@@ -102,8 +104,8 @@ next_token(FILE *fp, char *buf, const int bufsz)
|
||||
if (c != EOF && c != '\n')
|
||||
{
|
||||
/*
|
||||
* Build a token in buf of next characters up to EOF, EOL, unquoted
|
||||
* comma, or unquoted whitespace.
|
||||
* Build a token in buf of next characters up to EOF, EOL,
|
||||
* unquoted comma, or unquoted whitespace.
|
||||
*/
|
||||
while (c != EOF && c != '\n' &&
|
||||
(!isblank(c) || in_quote == true))
|
||||
@@ -156,9 +158,9 @@ next_token(FILE *fp, char *buf, const int bufsz)
|
||||
}
|
||||
|
||||
/*
|
||||
* Tokenize file and handle file inclusion and comma lists. We have
|
||||
* to break apart the commas to expand any file names then
|
||||
* reconstruct with commas.
|
||||
* Tokenize file and handle file inclusion and comma lists. We have
|
||||
* to break apart the commas to expand any file names then
|
||||
* reconstruct with commas.
|
||||
*/
|
||||
static char *
|
||||
next_token_expand(FILE *file)
|
||||
@@ -174,17 +176,17 @@ next_token_expand(FILE *file)
|
||||
if (!*buf)
|
||||
break;
|
||||
|
||||
if (buf[strlen(buf)-1] == ',')
|
||||
if (buf[strlen(buf) - 1] == ',')
|
||||
{
|
||||
trailing_comma = true;
|
||||
buf[strlen(buf)-1] = '\0';
|
||||
buf[strlen(buf) - 1] = '\0';
|
||||
}
|
||||
else
|
||||
trailing_comma = false;
|
||||
|
||||
/* Is this referencing a file? */
|
||||
if (buf[0] == '@')
|
||||
incbuf = tokenize_inc_file(buf+1);
|
||||
incbuf = tokenize_inc_file(buf + 1);
|
||||
else
|
||||
incbuf = pstrdup(buf);
|
||||
|
||||
@@ -238,7 +240,7 @@ tokenize_inc_file(const char *inc_filename)
|
||||
{
|
||||
char *inc_fullname;
|
||||
FILE *inc_file;
|
||||
List *inc_lines;
|
||||
List *inc_lines;
|
||||
List *line;
|
||||
char *comma_str = pstrdup("");
|
||||
|
||||
@@ -279,7 +281,7 @@ tokenize_inc_file(const char *inc_filename)
|
||||
strcat(comma_str, MULTI_VALUE_SEP);
|
||||
}
|
||||
comma_str = repalloc(comma_str,
|
||||
strlen(comma_str) + strlen(lfirst(token)) + 1);
|
||||
strlen(comma_str) + strlen(lfirst(token)) + 1);
|
||||
strcat(comma_str, lfirst(token));
|
||||
}
|
||||
}
|
||||
@@ -341,9 +343,9 @@ tokenize_file(FILE *file)
|
||||
static int
|
||||
user_group_qsort_cmp(const void *list1, const void *list2)
|
||||
{
|
||||
/* first node is line number */
|
||||
char *user1 = lfirst(lnext(*(List **)list1));
|
||||
char *user2 = lfirst(lnext(*(List **)list2));
|
||||
/* first node is line number */
|
||||
char *user1 = lfirst(lnext(*(List **) list1));
|
||||
char *user2 = lfirst(lnext(*(List **) list2));
|
||||
|
||||
return strcmp(user1, user2);
|
||||
}
|
||||
@@ -357,8 +359,8 @@ user_group_qsort_cmp(const void *list1, const void *list2)
|
||||
static int
|
||||
user_group_bsearch_cmp(const void *user, const void *list)
|
||||
{
|
||||
/* first node is line number */
|
||||
char *user2 = lfirst(lnext(*(List **)list));
|
||||
/* first node is line number */
|
||||
char *user2 = lfirst(lnext(*(List **) list));
|
||||
|
||||
return strcmp(user, user2);
|
||||
}
|
||||
@@ -371,24 +373,24 @@ static List **
|
||||
get_group_line(const char *group)
|
||||
{
|
||||
return (List **) bsearch((void *) group,
|
||||
(void *) group_sorted,
|
||||
group_length,
|
||||
sizeof(List *),
|
||||
user_group_bsearch_cmp);
|
||||
(void *) group_sorted,
|
||||
group_length,
|
||||
sizeof(List *),
|
||||
user_group_bsearch_cmp);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Lookup a user name in the pg_shadow file
|
||||
*/
|
||||
List **
|
||||
List **
|
||||
get_user_line(const char *user)
|
||||
{
|
||||
return (List **) bsearch((void *) user,
|
||||
(void *) user_sorted,
|
||||
user_length,
|
||||
sizeof(List *),
|
||||
user_group_bsearch_cmp);
|
||||
(void *) user_sorted,
|
||||
user_length,
|
||||
sizeof(List *),
|
||||
user_group_bsearch_cmp);
|
||||
}
|
||||
|
||||
|
||||
@@ -398,13 +400,14 @@ get_user_line(const char *user)
|
||||
static int
|
||||
check_group(char *group, char *user)
|
||||
{
|
||||
List **line, *l;
|
||||
List **line,
|
||||
*l;
|
||||
|
||||
if ((line = get_group_line(group)) != NULL)
|
||||
{
|
||||
foreach(l, lnext(lnext(*line)))
|
||||
if (strcmp(lfirst(l), user) == 0)
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -416,17 +419,17 @@ check_group(char *group, char *user)
|
||||
static int
|
||||
check_user(char *user, char *param_str)
|
||||
{
|
||||
char *tok;
|
||||
char *tok;
|
||||
|
||||
for (tok = strtok(param_str, MULTI_VALUE_SEP); tok != NULL; tok = strtok(NULL, MULTI_VALUE_SEP))
|
||||
{
|
||||
if (tok[0] == '+')
|
||||
{
|
||||
if (check_group(tok+1, user))
|
||||
if (check_group(tok + 1, user))
|
||||
return 1;
|
||||
}
|
||||
else if (strcmp(tok, user) == 0 ||
|
||||
strcmp(tok, "all") == 0)
|
||||
strcmp(tok, "all") == 0)
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -439,7 +442,7 @@ check_user(char *user, char *param_str)
|
||||
static int
|
||||
check_db(char *dbname, char *user, char *param_str)
|
||||
{
|
||||
char *tok;
|
||||
char *tok;
|
||||
|
||||
for (tok = strtok(param_str, MULTI_VALUE_SEP); tok != NULL; tok = strtok(NULL, MULTI_VALUE_SEP))
|
||||
{
|
||||
@@ -744,7 +747,7 @@ void
|
||||
load_group()
|
||||
{
|
||||
FILE *group_file;
|
||||
List *line;
|
||||
List *line;
|
||||
|
||||
if (group_lines)
|
||||
free_lines(&group_lines);
|
||||
@@ -761,7 +764,7 @@ load_group()
|
||||
group_length = length(group_lines);
|
||||
if (group_length)
|
||||
{
|
||||
int i = 0;
|
||||
int i = 0;
|
||||
|
||||
group_sorted = palloc(group_length * sizeof(List *));
|
||||
|
||||
@@ -799,7 +802,7 @@ load_user()
|
||||
user_length = length(user_lines);
|
||||
if (user_length)
|
||||
{
|
||||
int i = 0;
|
||||
int i = 0;
|
||||
|
||||
user_sorted = palloc(user_length * sizeof(List *));
|
||||
|
||||
@@ -825,7 +828,7 @@ load_hba(void)
|
||||
{
|
||||
int bufsize;
|
||||
FILE *file; /* The config file we have to read */
|
||||
char *conf_file; /* The name of the config file */
|
||||
char *conf_file; /* The name of the config file */
|
||||
|
||||
if (hba_lines)
|
||||
free_lines(&hba_lines);
|
||||
@@ -935,8 +938,8 @@ check_ident_usermap(const char *usermap_name,
|
||||
if (usermap_name[0] == '\0')
|
||||
{
|
||||
elog(LOG, "check_ident_usermap: hba configuration file does not "
|
||||
"have the usermap field filled in in the entry that pertains "
|
||||
"to this connection. That field is essential for Ident-based "
|
||||
"have the usermap field filled in in the entry that pertains "
|
||||
"to this connection. That field is essential for Ident-based "
|
||||
"authentication.");
|
||||
found_entry = false;
|
||||
}
|
||||
@@ -999,7 +1002,7 @@ load_ident(void)
|
||||
/*
|
||||
* Parse the string "*ident_response" as a response from a query to an Ident
|
||||
* server. If it's a normal response indicating a user name, return true
|
||||
* and store the user name at *ident_user. If it's anything else,
|
||||
* and store the user name at *ident_user. If it's anything else,
|
||||
* return false.
|
||||
*/
|
||||
static bool
|
||||
@@ -1140,7 +1143,7 @@ ident_inet(const struct in_addr remote_ip_addr,
|
||||
if (rc != 0)
|
||||
{
|
||||
/* save_errno is in case inet_ntoa changes errno */
|
||||
int save_errno = errno;
|
||||
int save_errno = errno;
|
||||
|
||||
elog(LOG, "Unable to connect to Ident server on the host which is "
|
||||
"trying to connect to Postgres "
|
||||
@@ -1157,12 +1160,13 @@ ident_inet(const struct in_addr remote_ip_addr,
|
||||
snprintf(ident_query, 80, "%d,%d\n",
|
||||
ntohs(remote_port), ntohs(local_port));
|
||||
/* loop in case send is interrupted */
|
||||
do {
|
||||
do
|
||||
{
|
||||
rc = send(sock_fd, ident_query, strlen(ident_query), 0);
|
||||
} while (rc < 0 && errno == EINTR);
|
||||
if (rc < 0)
|
||||
{
|
||||
int save_errno = errno;
|
||||
int save_errno = errno;
|
||||
|
||||
elog(LOG, "Unable to send query to Ident server on the host which is "
|
||||
"trying to connect to Postgres (Host %s, Port %d), "
|
||||
@@ -1179,11 +1183,11 @@ ident_inet(const struct in_addr remote_ip_addr,
|
||||
sizeof(ident_response) - 1, 0);
|
||||
if (rc < 0)
|
||||
{
|
||||
int save_errno = errno;
|
||||
int save_errno = errno;
|
||||
|
||||
elog(LOG, "Unable to receive response from Ident server "
|
||||
"on the host which is "
|
||||
"trying to connect to Postgres (Host %s, Port %d), "
|
||||
"trying to connect to Postgres (Host %s, Port %d), "
|
||||
"even though we successfully sent our query to it: %s",
|
||||
inet_ntoa(remote_ip_addr), IDENT_PORT,
|
||||
strerror(save_errno));
|
||||
@@ -1369,4 +1373,3 @@ hba_getauthmethod(hbaPort *port)
|
||||
else
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.17 2002/06/20 20:29:28 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/md5.c,v 1.18 2002/09/04 20:31:19 momjian Exp $
|
||||
*/
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
* NOTE:
|
||||
*
|
||||
* There are two copies of this file, one in backend/libpq and another
|
||||
* in interfaces/odbc. They should be identical. This is done so ODBC
|
||||
* in interfaces/odbc. They should be identical. This is done so ODBC
|
||||
* can be compiled stand-alone.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MD5_ODBC
|
||||
#include "postgres.h"
|
||||
#include "libpq/crypt.h"
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pqcomm.c,v 1.139 2002/09/03 21:45:42 petere Exp $
|
||||
* $Id: pqcomm.c,v 1.140 2002/09/04 20:31:19 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -469,10 +469,9 @@ pq_recvbuf(void)
|
||||
continue; /* Ok if interrupted */
|
||||
|
||||
/*
|
||||
* Careful: an elog() 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 elog() 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.
|
||||
*/
|
||||
elog(COMMERROR, "pq_recvbuf: recv() failed: %m");
|
||||
return EOF;
|
||||
@@ -574,12 +573,12 @@ pq_getstring(StringInfo s)
|
||||
s->data[0] = '\0';
|
||||
|
||||
/* Read until we get the terminating '\0' */
|
||||
for(;;)
|
||||
for (;;)
|
||||
{
|
||||
while (PqRecvPointer >= PqRecvLength)
|
||||
{
|
||||
if (pq_recvbuf()) /* If nothing in buffer, then recv some */
|
||||
return EOF; /* Failed to recv data */
|
||||
if (pq_recvbuf()) /* If nothing in buffer, then recv some */
|
||||
return EOF; /* Failed to recv data */
|
||||
}
|
||||
|
||||
for (i = PqRecvPointer; i < PqRecvLength; i++)
|
||||
@@ -589,7 +588,7 @@ pq_getstring(StringInfo s)
|
||||
/* does not copy the \0 */
|
||||
appendBinaryStringInfo(s, PqRecvBuffer + PqRecvPointer,
|
||||
i - PqRecvPointer);
|
||||
PqRecvPointer = i + 1; /* advance past \0 */
|
||||
PqRecvPointer = i + 1; /* advance past \0 */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -639,7 +638,7 @@ pq_putbytes(const char *s, size_t len)
|
||||
int
|
||||
pq_flush(void)
|
||||
{
|
||||
static int last_reported_send_errno = 0;
|
||||
static int last_reported_send_errno = 0;
|
||||
|
||||
unsigned char *bufptr = PqSendBuffer;
|
||||
unsigned char *bufend = PqSendBuffer + PqSendPointer;
|
||||
@@ -656,13 +655,12 @@ pq_flush(void)
|
||||
continue; /* Ok if we were interrupted */
|
||||
|
||||
/*
|
||||
* Careful: an elog() 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 elog() 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
|
||||
* 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
|
||||
* query abort point. So, suppress duplicate log messages.
|
||||
*/
|
||||
if (errno != last_reported_send_errno)
|
||||
@@ -679,7 +677,7 @@ pq_flush(void)
|
||||
return EOF;
|
||||
}
|
||||
|
||||
last_reported_send_errno = 0; /* reset after any successful send */
|
||||
last_reported_send_errno = 0; /* reset after any successful send */
|
||||
bufptr += r;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user