mirror of
https://github.com/postgres/postgres.git
synced 2025-11-12 05:01:15 +03:00
pgindent run over code.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.35 1999/04/16 04:59:03 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.36 1999/05/25 16:08:55 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -75,13 +75,13 @@ static int map_old_to_new(Port *port, UserAuth old, int status);
|
||||
static int
|
||||
pg_krb4_recvauth(Port *port)
|
||||
{
|
||||
long krbopts = 0; /* one-way authentication */
|
||||
KTEXT_ST clttkt;
|
||||
char instance[INST_SZ+1],
|
||||
version[KRB_SENDAUTH_VLEN+1];
|
||||
AUTH_DAT auth_data;
|
||||
Key_schedule key_sched;
|
||||
int status;
|
||||
long krbopts = 0; /* one-way authentication */
|
||||
KTEXT_ST clttkt;
|
||||
char instance[INST_SZ + 1],
|
||||
version[KRB_SENDAUTH_VLEN + 1];
|
||||
AUTH_DAT auth_data;
|
||||
Key_schedule key_sched;
|
||||
int status;
|
||||
|
||||
strcpy(instance, "*"); /* don't care, but arg gets expanded
|
||||
* anyway */
|
||||
@@ -99,7 +99,7 @@ pg_krb4_recvauth(Port *port)
|
||||
if (status != KSUCCESS)
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"pg_krb4_recvauth: kerberos error: %s\n", krb_err_txt[status]);
|
||||
"pg_krb4_recvauth: kerberos error: %s\n", krb_err_txt[status]);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
return STATUS_ERROR;
|
||||
@@ -107,7 +107,7 @@ pg_krb4_recvauth(Port *port)
|
||||
if (strncmp(version, PG_KRB4_VERSION, KRB_SENDAUTH_VLEN))
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"pg_krb4_recvauth: protocol version != \"%s\"\n", PG_KRB4_VERSION);
|
||||
"pg_krb4_recvauth: protocol version != \"%s\"\n", PG_KRB4_VERSION);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
return STATUS_ERROR;
|
||||
@@ -115,8 +115,8 @@ pg_krb4_recvauth(Port *port)
|
||||
if (strncmp(port->user, auth_data.pname, SM_USER))
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"pg_krb4_recvauth: name \"%s\" != \"%s\"\n",
|
||||
port->user, auth_data.pname);
|
||||
"pg_krb4_recvauth: name \"%s\" != \"%s\"\n",
|
||||
port->user, auth_data.pname);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
return STATUS_ERROR;
|
||||
@@ -129,7 +129,7 @@ static int
|
||||
pg_krb4_recvauth(Port *port)
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"pg_krb4_recvauth: Kerberos not implemented on this server.\n");
|
||||
"pg_krb4_recvauth: Kerberos not implemented on this server.\n");
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
|
||||
@@ -223,7 +223,7 @@ pg_krb5_recvauth(Port *port)
|
||||
if (code = krb5_parse_name(servbuf, &server))
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"pg_krb5_recvauth: Kerberos error %d in krb5_parse_name\n", code);
|
||||
"pg_krb5_recvauth: Kerberos error %d in krb5_parse_name\n", code);
|
||||
com_err("pg_krb5_recvauth", code, "in krb5_parse_name");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
@@ -256,7 +256,7 @@ pg_krb5_recvauth(Port *port)
|
||||
(krb5_authenticator **) NULL))
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"pg_krb5_recvauth: Kerberos error %d in krb5_recvauth\n", code);
|
||||
"pg_krb5_recvauth: Kerberos error %d in krb5_recvauth\n", code);
|
||||
com_err("pg_krb5_recvauth", code, "in krb5_recvauth");
|
||||
krb5_free_principal(server);
|
||||
return STATUS_ERROR;
|
||||
@@ -271,7 +271,7 @@ pg_krb5_recvauth(Port *port)
|
||||
if ((code = krb5_unparse_name(client, &kusername)))
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"pg_krb5_recvauth: Kerberos error %d in krb5_unparse_name\n", code);
|
||||
"pg_krb5_recvauth: Kerberos error %d in krb5_unparse_name\n", code);
|
||||
com_err("pg_krb5_recvauth", code, "in krb5_unparse_name");
|
||||
krb5_free_principal(client);
|
||||
return STATUS_ERROR;
|
||||
@@ -280,7 +280,7 @@ pg_krb5_recvauth(Port *port)
|
||||
if (!kusername)
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"pg_krb5_recvauth: could not decode username\n");
|
||||
"pg_krb5_recvauth: could not decode username\n");
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
return STATUS_ERROR;
|
||||
@@ -289,7 +289,7 @@ pg_krb5_recvauth(Port *port)
|
||||
if (strncmp(username, kusername, SM_USER))
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"pg_krb5_recvauth: name \"%s\" != \"%s\"\n", port->user, kusername);
|
||||
"pg_krb5_recvauth: name \"%s\" != \"%s\"\n", port->user, kusername);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
pfree(kusername);
|
||||
@@ -304,7 +304,7 @@ static int
|
||||
pg_krb5_recvauth(Port *port)
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"pg_krb5_recvauth: Kerberos not implemented on this server.\n");
|
||||
"pg_krb5_recvauth: Kerberos not implemented on this server.\n");
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
|
||||
@@ -359,7 +359,7 @@ pg_passwordv0_recvauth(void *arg, PacketLen len, void *pkt)
|
||||
if (user == NULL || password == NULL)
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"pg_password_recvauth: badly formed password packet.\n");
|
||||
"pg_password_recvauth: badly formed password packet.\n");
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
|
||||
@@ -405,7 +405,7 @@ pg_passwordv0_recvauth(void *arg, PacketLen len, void *pkt)
|
||||
void
|
||||
auth_failed(Port *port)
|
||||
{
|
||||
char buffer[512];
|
||||
char buffer[512];
|
||||
const char *authmethod = "Unknown auth method:";
|
||||
|
||||
switch (port->auth_method)
|
||||
@@ -449,9 +449,9 @@ be_recvauth(Port *port)
|
||||
|
||||
/*
|
||||
* Get the authentication method to use for this frontend/database
|
||||
* combination. Note: a failure return indicates a problem with
|
||||
* the hba config file, not with the request. hba.c should have
|
||||
* dropped an error message into the postmaster logfile if it failed.
|
||||
* combination. Note: a failure return indicates a problem with the
|
||||
* hba config file, not with the request. hba.c should have dropped
|
||||
* an error message into the postmaster logfile if it failed.
|
||||
*/
|
||||
|
||||
if (hba_getauthmethod(&port->raddr, port->user, port->database,
|
||||
@@ -470,27 +470,28 @@ be_recvauth(Port *port)
|
||||
{
|
||||
/* Handle new style authentication. */
|
||||
|
||||
AuthRequest areq = AUTH_REQ_OK;
|
||||
PacketDoneProc auth_handler = NULL;
|
||||
AuthRequest areq = AUTH_REQ_OK;
|
||||
PacketDoneProc auth_handler = NULL;
|
||||
|
||||
switch (port->auth_method)
|
||||
{
|
||||
case uaReject:
|
||||
|
||||
/*
|
||||
* This could have come from an explicit "reject" entry
|
||||
* in pg_hba.conf, but more likely it means there was no
|
||||
* matching entry. Take pity on the poor user and issue
|
||||
* a helpful error message. NOTE: this is not a security
|
||||
* breach, because all the info reported here is known
|
||||
* at the frontend and must be assumed known to bad guys.
|
||||
* This could have come from an explicit "reject" entry in
|
||||
* pg_hba.conf, but more likely it means there was no
|
||||
* matching entry. Take pity on the poor user and issue a
|
||||
* helpful error message. NOTE: this is not a security
|
||||
* breach, because all the info reported here is known at
|
||||
* the frontend and must be assumed known to bad guys.
|
||||
* We're merely helping out the less clueful good guys.
|
||||
* NOTE 2: libpq-be.h defines the maximum error message
|
||||
* length as 99 characters. It probably wouldn't hurt
|
||||
* anything to increase it, but there might be some
|
||||
* client out there that will fail. So, be terse.
|
||||
* anything to increase it, but there might be some client
|
||||
* out there that will fail. So, be terse.
|
||||
*/
|
||||
{
|
||||
char buffer[512];
|
||||
char buffer[512];
|
||||
const char *hostinfo = "localhost";
|
||||
|
||||
if (port->raddr.sa.sa_family == AF_INET)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: be-dumpdata.c,v 1.23 1999/05/10 00:45:08 momjian Exp $
|
||||
* $Id: be-dumpdata.c,v 1.24 1999/05/25 16:08:57 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -130,8 +130,8 @@ static u_int be_portalcnt = 0;
|
||||
PortalEntry *
|
||||
be_newportal(void)
|
||||
{
|
||||
PortalEntry *entry;
|
||||
char buf[PortalNameLength];
|
||||
PortalEntry *entry;
|
||||
char buf[PortalNameLength];
|
||||
|
||||
/* ----------------
|
||||
* generate a new name
|
||||
@@ -208,7 +208,7 @@ be_typeinit(PortalEntry *entry,
|
||||
* ----------------
|
||||
*/
|
||||
void
|
||||
be_printtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver* self)
|
||||
be_printtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver * self)
|
||||
{
|
||||
int i;
|
||||
Datum attr;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.32 1999/05/10 00:45:09 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.33 1999/05/25 16:08:57 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* This should be moved to a more appropriate place. It is here
|
||||
@@ -131,8 +131,8 @@ lo_close(int fd)
|
||||
int
|
||||
lo_read(int fd, char *buf, int len)
|
||||
{
|
||||
MemoryContext currentContext;
|
||||
int status;
|
||||
MemoryContext currentContext;
|
||||
int status;
|
||||
|
||||
if (fd < 0 || fd >= MAX_LOBJ_FDS)
|
||||
{
|
||||
@@ -144,19 +144,19 @@ lo_read(int fd, char *buf, int len)
|
||||
elog(ERROR, "lo_read: invalid large obj descriptor (%d)", fd);
|
||||
return -3;
|
||||
}
|
||||
currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
|
||||
currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
|
||||
|
||||
status = inv_read(cookies[fd], buf, len);
|
||||
|
||||
MemoryContextSwitchTo(currentContext);
|
||||
return(status);
|
||||
return (status);
|
||||
}
|
||||
|
||||
int
|
||||
lo_write(int fd, char *buf, int len)
|
||||
{
|
||||
MemoryContext currentContext;
|
||||
int status;
|
||||
MemoryContext currentContext;
|
||||
int status;
|
||||
|
||||
if (fd < 0 || fd >= MAX_LOBJ_FDS)
|
||||
{
|
||||
@@ -168,12 +168,12 @@ lo_write(int fd, char *buf, int len)
|
||||
elog(ERROR, "lo_write: invalid large obj descriptor (%d)", fd);
|
||||
return -3;
|
||||
}
|
||||
currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
|
||||
currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
|
||||
|
||||
status = inv_write(cookies[fd], buf, len);
|
||||
|
||||
MemoryContextSwitchTo(currentContext);
|
||||
return(status);
|
||||
return (status);
|
||||
}
|
||||
|
||||
|
||||
@@ -374,9 +374,7 @@ lo_export(Oid lobjId, text *filename)
|
||||
*/
|
||||
lobj = inv_open(lobjId, INV_READ);
|
||||
if (lobj == NULL)
|
||||
{
|
||||
elog(ERROR, "lo_export: can't open inv object %u", lobjId);
|
||||
}
|
||||
|
||||
/*
|
||||
* open the file to be written to
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* crypt.c
|
||||
* Look into pg_shadow and check the encrypted password with
|
||||
* Look into pg_shadow and check the encrypted password with
|
||||
* the one passed in from the frontend.
|
||||
*
|
||||
* Modification History
|
||||
@@ -9,7 +9,7 @@
|
||||
* Dec 17, 1997 - Todd A. Brandys
|
||||
* Orignal Version Completed.
|
||||
*
|
||||
* $Id: crypt.c,v 1.16 1999/05/09 00:54:30 tgl Exp $
|
||||
* $Id: crypt.c,v 1.17 1999/05/25 16:08:58 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -38,8 +38,8 @@ char *
|
||||
crypt_getpwdfilename()
|
||||
{
|
||||
|
||||
static char *pfnam = NULL;
|
||||
int bufsize;
|
||||
static char *pfnam = NULL;
|
||||
int bufsize;
|
||||
|
||||
bufsize = strlen(DataDir) + strlen(CRYPT_PWD_FILE) + 2;
|
||||
pfnam = (char *) palloc(bufsize);
|
||||
@@ -54,9 +54,9 @@ char *
|
||||
crypt_getpwdreloadfilename()
|
||||
{
|
||||
|
||||
static char *rpfnam = NULL;
|
||||
char *pwdfilename;
|
||||
int bufsize;
|
||||
static char *rpfnam = NULL;
|
||||
char *pwdfilename;
|
||||
int bufsize;
|
||||
|
||||
pwdfilename = crypt_getpwdfilename();
|
||||
bufsize = strlen(pwdfilename) + strlen(CRYPT_PWD_RELOAD_SUFX) + 1;
|
||||
@@ -147,9 +147,7 @@ crypt_loadpwdfile()
|
||||
{ /* free the old data only if this is a
|
||||
* reload */
|
||||
while (pwd_cache_count--)
|
||||
{
|
||||
pfree((void *) pwd_cache[pwd_cache_count]);
|
||||
}
|
||||
pfree((void *) pwd_cache);
|
||||
pwd_cache = NULL;
|
||||
pwd_cache_count = 0;
|
||||
@@ -226,9 +224,9 @@ int
|
||||
crypt_getloginfo(const char *user, char **passwd, char **valuntil)
|
||||
{
|
||||
|
||||
char *pwd,
|
||||
*valdate;
|
||||
void *fakeout;
|
||||
char *pwd,
|
||||
*valdate;
|
||||
void *fakeout;
|
||||
|
||||
*passwd = NULL;
|
||||
*valuntil = NULL;
|
||||
@@ -236,8 +234,8 @@ crypt_getloginfo(const char *user, char **passwd, char **valuntil)
|
||||
|
||||
if (pwd_cache)
|
||||
{
|
||||
char **pwd_entry;
|
||||
char user_search[NAMEDATALEN + 2];
|
||||
char **pwd_entry;
|
||||
char user_search[NAMEDATALEN + 2];
|
||||
|
||||
snprintf(user_search, NAMEDATALEN + 2, "%s\t", user);
|
||||
fakeout = (void *) &user_search;
|
||||
@@ -261,28 +259,22 @@ int
|
||||
crypt_verify(Port *port, const char *user, const char *pgpass)
|
||||
{
|
||||
|
||||
char *passwd,
|
||||
*valuntil,
|
||||
*crypt_pwd;
|
||||
int retval = STATUS_ERROR;
|
||||
AbsoluteTime vuntil,
|
||||
current;
|
||||
char *passwd,
|
||||
*valuntil,
|
||||
*crypt_pwd;
|
||||
int retval = STATUS_ERROR;
|
||||
AbsoluteTime vuntil,
|
||||
current;
|
||||
|
||||
if (crypt_getloginfo(user, &passwd, &valuntil) == STATUS_ERROR)
|
||||
{
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
if (passwd == NULL || *passwd == '\0')
|
||||
{
|
||||
if (passwd)
|
||||
{
|
||||
pfree((void *) passwd);
|
||||
}
|
||||
if (valuntil)
|
||||
{
|
||||
pfree((void *) valuntil);
|
||||
}
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
@@ -291,38 +283,29 @@ crypt_verify(Port *port, const char *user, const char *pgpass)
|
||||
* authentication method being used for this connection.
|
||||
*/
|
||||
|
||||
crypt_pwd =
|
||||
(port->auth_method == uaCrypt ? crypt(passwd, port->salt) : passwd);
|
||||
crypt_pwd =
|
||||
(port->auth_method == uaCrypt ? crypt(passwd, port->salt) : passwd);
|
||||
|
||||
if (!strcmp(pgpass, crypt_pwd))
|
||||
{
|
||||
|
||||
/*
|
||||
* check here to be sure we are not past valuntil
|
||||
*/
|
||||
if (!valuntil || strcmp(valuntil, "\\N") == 0)
|
||||
{
|
||||
vuntil = INVALID_ABSTIME;
|
||||
}
|
||||
else
|
||||
{
|
||||
vuntil = nabstimein(valuntil);
|
||||
}
|
||||
current = GetCurrentAbsoluteTime();
|
||||
if (vuntil != INVALID_ABSTIME && vuntil < current)
|
||||
{
|
||||
retval = STATUS_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = STATUS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
pfree((void *) passwd);
|
||||
if (valuntil)
|
||||
{
|
||||
pfree((void *) valuntil);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* wherein you authenticate a user by seeing what IP address the system
|
||||
* says he comes from and possibly using ident).
|
||||
*
|
||||
* $Id: hba.c,v 1.42 1999/05/10 15:17:16 momjian Exp $
|
||||
* $Id: hba.c,v 1.43 1999/05/25 16:08:59 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -286,7 +286,7 @@ process_hba_record(FILE *file, SockAddr *raddr, const char *user,
|
||||
|
||||
syntax:
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"process_hba_record: invalid syntax in pg_hba.conf file\n");
|
||||
"process_hba_record: invalid syntax in pg_hba.conf file\n");
|
||||
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
@@ -305,14 +305,15 @@ process_open_config_file(FILE *file, SockAddr *raddr, const char *user,
|
||||
This function does the same thing as find_hba_entry, only with
|
||||
the config file already open on stream descriptor "file".
|
||||
----------------------------------------------------------------------------*/
|
||||
bool found_entry = false; /* found an applicable entry? */
|
||||
bool error = false; /* found an erroneous entry? */
|
||||
bool eof = false; /* end of hba file */
|
||||
bool found_entry = false; /* found an applicable entry? */
|
||||
bool error = false; /* found an erroneous entry? */
|
||||
bool eof = false; /* end of hba file */
|
||||
|
||||
while (!eof && !found_entry && !error)
|
||||
{
|
||||
/* Process a line from the config file */
|
||||
int c = getc(file);
|
||||
int c = getc(file);
|
||||
|
||||
if (c == EOF)
|
||||
eof = true;
|
||||
else
|
||||
@@ -347,7 +348,7 @@ find_hba_entry(SockAddr *raddr, const char *user, const char *database,
|
||||
* Read the config file and find an entry that allows connection from
|
||||
* host "raddr", user "user", to database "database". If found,
|
||||
* return *hba_ok_p = true and *userauth_p and *auth_arg representing
|
||||
* the contents of that entry. If there is no matching entry, we
|
||||
* the contents of that entry. If there is no matching entry, we
|
||||
* set *hba_ok_p = true, *userauth_p = uaReject.
|
||||
*
|
||||
* If the config file is unreadable or contains invalid syntax, we
|
||||
@@ -355,15 +356,15 @@ find_hba_entry(SockAddr *raddr, const char *user, const char *database,
|
||||
* and return without changing *hba_ok_p.
|
||||
*
|
||||
* If we find a file by the old name of the config file (pg_hba), we issue
|
||||
* an error message because it probably needs to be converted. He didn't
|
||||
* an error message because it probably needs to be converted. He didn't
|
||||
* follow directions and just installed his old hba file in the new database
|
||||
* system.
|
||||
*/
|
||||
|
||||
int fd,
|
||||
int fd,
|
||||
bufsize;
|
||||
FILE *file; /* The config file we have to read */
|
||||
char *old_conf_file;
|
||||
FILE *file; /* The config file we have to read */
|
||||
char *old_conf_file;
|
||||
|
||||
/* The name of old config file that better not exist. */
|
||||
|
||||
@@ -387,14 +388,15 @@ find_hba_entry(SockAddr *raddr, const char *user, const char *database,
|
||||
"A file exists by the name used for host-based authentication "
|
||||
"in prior releases of Postgres (%s). The name and format of "
|
||||
"the configuration file have changed, so this file should be "
|
||||
"converted.\n",
|
||||
old_conf_file);
|
||||
"converted.\n",
|
||||
old_conf_file);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
char *conf_file; /* The name of the config file we have to read */
|
||||
char *conf_file; /* The name of the config file we have to
|
||||
* read */
|
||||
|
||||
/* put together the full pathname to the config file */
|
||||
bufsize = (strlen(DataDir) + strlen(CONF_FILE) + 2) * sizeof(char);
|
||||
@@ -407,17 +409,17 @@ find_hba_entry(SockAddr *raddr, const char *user, const char *database,
|
||||
/* The open of the config file failed. */
|
||||
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"find_hba_entry: Host-based authentication config file "
|
||||
"does not exist or permissions are not setup correctly! "
|
||||
"Unable to open file \"%s\".\n",
|
||||
conf_file);
|
||||
"find_hba_entry: Host-based authentication config file "
|
||||
"does not exist or permissions are not setup correctly! "
|
||||
"Unable to open file \"%s\".\n",
|
||||
conf_file);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
process_open_config_file(file, raddr, user, database, hba_ok_p,
|
||||
userauth_p, auth_arg);
|
||||
process_open_config_file(file, raddr, user, database, hba_ok_p,
|
||||
userauth_p, auth_arg);
|
||||
FreeFile(file);
|
||||
}
|
||||
pfree(conf_file);
|
||||
@@ -531,16 +533,18 @@ ident(const struct in_addr remote_ip_addr, const struct in_addr local_ip_addr,
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
int sock_fd, /* File descriptor for socket on which we talk to Ident */
|
||||
rc; /* Return code from a locally called function */
|
||||
int sock_fd, /* File descriptor for socket on which we
|
||||
* talk to Ident */
|
||||
rc; /* Return code from a locally called
|
||||
* function */
|
||||
|
||||
sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
|
||||
if (sock_fd == -1)
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"Failed to create socket on which to talk to Ident server. "
|
||||
"socket() returned errno = %s (%d)\n",
|
||||
strerror(errno), errno);
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"Failed to create socket on which to talk to Ident server. "
|
||||
"socket() returned errno = %s (%d)\n",
|
||||
strerror(errno), errno);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
}
|
||||
@@ -559,66 +563,66 @@ ident(const struct in_addr remote_ip_addr, const struct in_addr local_ip_addr,
|
||||
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
memset(&la, 0, sizeof(la));
|
||||
la.sin_family = AF_INET;
|
||||
la.sin_addr = local_ip_addr;
|
||||
rc = bind(sock_fd, (struct sockaddr *) &la, sizeof(la));
|
||||
rc = bind(sock_fd, (struct sockaddr *) & la, sizeof(la));
|
||||
if (rc == 0)
|
||||
{
|
||||
rc = connect(sock_fd,
|
||||
(struct sockaddr *) & ident_server, sizeof(ident_server));
|
||||
(struct sockaddr *) & ident_server, sizeof(ident_server));
|
||||
}
|
||||
if (rc != 0)
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"Unable to connect to Ident server on the host which is "
|
||||
"trying to connect to Postgres "
|
||||
"(IP address %s, Port %d). "
|
||||
"errno = %s (%d)\n",
|
||||
inet_ntoa(remote_ip_addr), IDENT_PORT, strerror(errno), errno);
|
||||
"Unable to connect to Ident server on the host which is "
|
||||
"trying to connect to Postgres "
|
||||
"(IP address %s, Port %d). "
|
||||
"errno = %s (%d)\n",
|
||||
inet_ntoa(remote_ip_addr), IDENT_PORT, strerror(errno), errno);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
*ident_failed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
char ident_query[80];
|
||||
char ident_query[80];
|
||||
|
||||
/* The query we send to the Ident server */
|
||||
snprintf(ident_query, 80, "%d,%d\n",
|
||||
ntohs(remote_port), ntohs(local_port));
|
||||
ntohs(remote_port), ntohs(local_port));
|
||||
rc = send(sock_fd, ident_query, strlen(ident_query), 0);
|
||||
if (rc < 0)
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"Unable to send query to Ident server on the host which is "
|
||||
"Unable to send query to Ident server on the host which is "
|
||||
"trying to connect to Postgres (Host %s, Port %d),"
|
||||
"even though we successfully connected to it. "
|
||||
"errno = %s (%d)\n",
|
||||
inet_ntoa(remote_ip_addr), IDENT_PORT, strerror(errno), errno);
|
||||
"even though we successfully connected to it. "
|
||||
"errno = %s (%d)\n",
|
||||
inet_ntoa(remote_ip_addr), IDENT_PORT, strerror(errno), errno);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
*ident_failed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
char ident_response[80 + IDENT_USERNAME_MAX];
|
||||
char ident_response[80 + IDENT_USERNAME_MAX];
|
||||
|
||||
rc = recv(sock_fd, ident_response, sizeof(ident_response) - 1, 0);
|
||||
if (rc < 0)
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"Unable to receive response from Ident server "
|
||||
"on the host which is "
|
||||
"trying to connect to Postgres (Host %s, Port %d),"
|
||||
"even though we successfully sent our query to it. "
|
||||
"errno = %s (%d)\n",
|
||||
inet_ntoa(remote_ip_addr), IDENT_PORT,
|
||||
strerror(errno), errno);
|
||||
"Unable to receive response from Ident server "
|
||||
"on the host which is "
|
||||
"trying to connect to Postgres (Host %s, Port %d),"
|
||||
"even though we successfully sent our query to it. "
|
||||
"errno = %s (%d)\n",
|
||||
inet_ntoa(remote_ip_addr), IDENT_PORT,
|
||||
strerror(errno), errno);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
*ident_failed = true;
|
||||
@@ -676,8 +680,8 @@ parse_map_record(FILE *file,
|
||||
return;
|
||||
}
|
||||
}
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"Incomplete line in pg_ident: %s", file_map);
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"Incomplete line in pg_ident: %s", file_map);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
}
|
||||
@@ -760,29 +764,26 @@ verify_against_usermap(const char *pguser,
|
||||
{
|
||||
*checks_out_p = false;
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"verify_against_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 "
|
||||
"authentication.\n");
|
||||
"verify_against_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 "
|
||||
"authentication.\n");
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
}
|
||||
else if (strcmp(usermap_name, "sameuser") == 0)
|
||||
{
|
||||
if (strcmp(ident_username, pguser) == 0)
|
||||
{
|
||||
*checks_out_p = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*checks_out_p = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FILE *file; /* The map file we have to read */
|
||||
char *map_file; /* The name of the map file we have to read */
|
||||
int bufsize;
|
||||
FILE *file; /* The map file we have to read */
|
||||
char *map_file; /* The name of the map file we have to
|
||||
* read */
|
||||
int bufsize;
|
||||
|
||||
/* put together the full pathname to the map file */
|
||||
bufsize = (strlen(DataDir) + strlen(USERMAP_FILE) + 2) * sizeof(char);
|
||||
@@ -801,11 +802,11 @@ verify_against_usermap(const char *pguser,
|
||||
*checks_out_p = false;
|
||||
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"verify_against_usermap: usermap file for Ident-based "
|
||||
"authentication "
|
||||
"does not exist or permissions are not setup correctly! "
|
||||
"Unable to open file \"%s\".\n",
|
||||
map_file);
|
||||
"verify_against_usermap: usermap file for Ident-based "
|
||||
"authentication "
|
||||
"does not exist or permissions are not setup correctly! "
|
||||
"Unable to open file \"%s\".\n",
|
||||
map_file);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
}
|
||||
@@ -945,21 +946,21 @@ InRange(char *buf, int host)
|
||||
void
|
||||
GetCharSetByHost(char *TableName, int host, const char *DataDir)
|
||||
{
|
||||
FILE *file;
|
||||
char buf[MAX_TOKEN],
|
||||
FILE *file;
|
||||
char buf[MAX_TOKEN],
|
||||
BaseCharset[MAX_TOKEN],
|
||||
OrigCharset[MAX_TOKEN],
|
||||
DestCharset[MAX_TOKEN],
|
||||
HostCharset[MAX_TOKEN],
|
||||
c,
|
||||
eof = false,
|
||||
*map_file;
|
||||
int key = 0,
|
||||
*map_file;
|
||||
int key = 0,
|
||||
ChIndex = 0,
|
||||
i,
|
||||
bufsize;
|
||||
|
||||
struct CharsetItem *ChArray[MAX_CHARSETS];
|
||||
struct CharsetItem *ChArray[MAX_CHARSETS];
|
||||
|
||||
*TableName = '\0';
|
||||
bufsize = (strlen(DataDir) + strlen(CHARSET_FILE) + 2) * sizeof(char);
|
||||
@@ -971,9 +972,7 @@ GetCharSetByHost(char *TableName, int host, const char *DataDir)
|
||||
file = AllocateFile(map_file, "rb");
|
||||
#endif
|
||||
if (file == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
while (!eof)
|
||||
{
|
||||
c = getc(file);
|
||||
@@ -1033,8 +1032,8 @@ GetCharSetByHost(char *TableName, int host, const char *DataDir)
|
||||
next_token(file, buf, sizeof(buf));
|
||||
if (buf[0] != '\0')
|
||||
{
|
||||
ChArray[ChIndex] =
|
||||
(struct CharsetItem *) palloc(sizeof(struct CharsetItem));
|
||||
ChArray[ChIndex] =
|
||||
(struct CharsetItem *) palloc(sizeof(struct CharsetItem));
|
||||
strcpy(ChArray[ChIndex]->Orig, OrigCharset);
|
||||
strcpy(ChArray[ChIndex]->Dest, DestCharset);
|
||||
strcpy(ChArray[ChIndex]->Table, buf);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
/*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: password.c,v 1.20 1999/01/17 06:18:26 momjian Exp $
|
||||
* $Id: password.c,v 1.21 1999/05/25 16:09:00 momjian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,8 +35,8 @@ verify_password(char *auth_arg, char *user, char *password)
|
||||
if (!pw_file)
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"verify_password: couldn't open password file '%s'\n",
|
||||
pw_file_fullname);
|
||||
"verify_password: couldn't open password file '%s'\n",
|
||||
pw_file_fullname);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
|
||||
@@ -80,8 +80,8 @@ verify_password(char *auth_arg, char *user, char *password)
|
||||
}
|
||||
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"verify_password: password mismatch for '%s'.\n",
|
||||
user);
|
||||
"verify_password: password mismatch for '%s'.\n",
|
||||
user);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
|
||||
@@ -92,8 +92,8 @@ verify_password(char *auth_arg, char *user, char *password)
|
||||
}
|
||||
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"verify_password: user '%s' not found in password file.\n",
|
||||
user);
|
||||
"verify_password: user '%s' not found in password file.\n",
|
||||
user);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: portal.c,v 1.21 1999/04/25 03:19:20 tgl Exp $
|
||||
* $Id: portal.c,v 1.22 1999/05/25 16:09:01 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -50,7 +50,7 @@
|
||||
* see utils/mmgr/portalmem.c for why. -cim 2/22/91
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <postgres.h>
|
||||
@@ -71,7 +71,7 @@ in_range(char *msg, int value, int min, int max)
|
||||
if (value < min || value >= max)
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"FATAL: %s, %d is not in range [%d,%d)\n", msg, value, min, max);
|
||||
"FATAL: %s, %d is not in range [%d,%d)\n", msg, value, min, max);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
fputs(PQerrormsg, stderr);
|
||||
return 0;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portalbuf.c,v 1.13 1999/02/13 23:15:46 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portalbuf.c,v 1.14 1999/05/25 16:09:02 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -63,7 +63,7 @@ size_t portals_array_size = 0;
|
||||
/* GlobalMemory portals_mmcxt = (GlobalMemory) NULL; */
|
||||
|
||||
/* -------------------------------
|
||||
* portals_realloc
|
||||
* portals_realloc
|
||||
* grow the size of the portals array by size
|
||||
*
|
||||
* also ensures that elements are initially NULL
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pqcomm.c,v 1.71 1999/05/21 01:25:06 tgl Exp $
|
||||
* $Id: pqcomm.c,v 1.72 1999/05/25 16:09:02 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -53,7 +53,7 @@
|
||||
*
|
||||
* message-level I/O (and COPY OUT cruft):
|
||||
* pq_putmessage - send a normal message (suppressed in COPY OUT mode)
|
||||
* pq_startcopyout - inform libpq that a COPY OUT transfer is beginning
|
||||
* pq_startcopyout - inform libpq that a COPY OUT transfer is beginning
|
||||
* pq_endcopyout - end a COPY OUT transfer
|
||||
*
|
||||
*------------------------
|
||||
@@ -90,7 +90,7 @@
|
||||
#define SOMAXCONN 5 /* from Linux listen(2) man page */
|
||||
#endif /* SOMAXCONN */
|
||||
|
||||
extern FILE * debug_port; /* in util.c */
|
||||
extern FILE *debug_port; /* in util.c */
|
||||
|
||||
/*
|
||||
* Buffers for low-level I/O
|
||||
@@ -99,11 +99,13 @@ extern FILE * debug_port; /* in util.c */
|
||||
#define PQ_BUFFER_SIZE 8192
|
||||
|
||||
static unsigned char PqSendBuffer[PQ_BUFFER_SIZE];
|
||||
static int PqSendPointer; /* Next index to store a byte in PqSendBuffer */
|
||||
static int PqSendPointer; /* Next index to store a byte in
|
||||
* PqSendBuffer */
|
||||
|
||||
static unsigned char PqRecvBuffer[PQ_BUFFER_SIZE];
|
||||
static int PqRecvPointer; /* Next index to read a byte from PqRecvBuffer */
|
||||
static int PqRecvLength; /* End of data available in PqRecvBuffer */
|
||||
static int PqRecvPointer; /* Next index to read a byte from
|
||||
* PqRecvBuffer */
|
||||
static int PqRecvLength; /* End of data available in PqRecvBuffer */
|
||||
|
||||
/*
|
||||
* Message status
|
||||
@@ -121,7 +123,7 @@ pq_init(void)
|
||||
PqSendPointer = PqRecvPointer = PqRecvLength = 0;
|
||||
DoingCopyOut = false;
|
||||
if (getenv("LIBPQ_DEBUG"))
|
||||
debug_port = stderr;
|
||||
debug_port = stderr;
|
||||
}
|
||||
|
||||
/* --------------------------------
|
||||
@@ -187,8 +189,10 @@ StreamServerPort(char *hostName, short portName, int *fdP)
|
||||
family;
|
||||
size_t len;
|
||||
int one = 1;
|
||||
|
||||
#ifdef HAVE_FCNTL_SETLK
|
||||
int lock_fd;
|
||||
|
||||
#endif
|
||||
|
||||
family = ((hostName != NULL) ? AF_INET : AF_UNIX);
|
||||
@@ -204,19 +208,20 @@ StreamServerPort(char *hostName, short portName, int *fdP)
|
||||
}
|
||||
|
||||
#ifdef ONLY_REUSE_INET_SOCKETS
|
||||
if (family == AF_INET) {
|
||||
if (family == AF_INET)
|
||||
{
|
||||
#endif
|
||||
|
||||
if ((setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &one,
|
||||
sizeof(one))) == -1)
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"FATAL: StreamServerPort: setsockopt(SO_REUSEADDR) failed: %s\n",
|
||||
strerror(errno));
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
if ((setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &one,
|
||||
sizeof(one))) == -1)
|
||||
{
|
||||
snprintf(PQerrormsg, ERROR_MSG_LENGTH,
|
||||
"FATAL: StreamServerPort: setsockopt(SO_REUSEADDR) failed: %s\n",
|
||||
strerror(errno));
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
#ifdef ONLY_REUSE_INET_SOCKETS
|
||||
}
|
||||
@@ -240,9 +245,10 @@ StreamServerPort(char *hostName, short portName, int *fdP)
|
||||
if ((lock_fd = open(sock_path, O_WRONLY | O_NONBLOCK | O_BINARY, 0666)) >= 0)
|
||||
#endif
|
||||
{
|
||||
struct flock lck;
|
||||
|
||||
lck.l_whence = SEEK_SET; lck.l_start = lck.l_len = 0;
|
||||
struct flock lck;
|
||||
|
||||
lck.l_whence = SEEK_SET;
|
||||
lck.l_start = lck.l_len = 0;
|
||||
lck.l_type = F_WRLCK;
|
||||
if (fcntl(lock_fd, F_SETLK, &lck) == 0)
|
||||
{
|
||||
@@ -253,7 +259,7 @@ StreamServerPort(char *hostName, short portName, int *fdP)
|
||||
TPRINTF(TRACE_VERBOSE, "flock failed for %s", sock_path);
|
||||
close(lock_fd);
|
||||
}
|
||||
#endif /* HAVE_FCNTL_SETLK */
|
||||
#endif /* HAVE_FCNTL_SETLK */
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -277,9 +283,7 @@ StreamServerPort(char *hostName, short portName, int *fdP)
|
||||
sock_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcat(PQerrormsg, "\tIf not, wait a few seconds and retry.\n");
|
||||
}
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
return STATUS_ERROR;
|
||||
@@ -300,14 +304,15 @@ StreamServerPort(char *hostName, short portName, int *fdP)
|
||||
if ((lock_fd = open(sock_path, O_WRONLY | O_NONBLOCK | O_BINARY, 0666)) >= 0)
|
||||
#endif
|
||||
{
|
||||
struct flock lck;
|
||||
|
||||
lck.l_whence = SEEK_SET; lck.l_start = lck.l_len = 0;
|
||||
struct flock lck;
|
||||
|
||||
lck.l_whence = SEEK_SET;
|
||||
lck.l_start = lck.l_len = 0;
|
||||
lck.l_type = F_WRLCK;
|
||||
if (fcntl(lock_fd, F_SETLK, &lck) != 0)
|
||||
TPRINTF(TRACE_VERBOSE, "flock error for %s", sock_path);
|
||||
}
|
||||
#endif /* HAVE_FCNTL_SETLK */
|
||||
#endif /* HAVE_FCNTL_SETLK */
|
||||
}
|
||||
|
||||
listen(fd, SOMAXCONN);
|
||||
@@ -339,7 +344,7 @@ StreamServerPort(char *hostName, short portName, int *fdP)
|
||||
int
|
||||
StreamConnection(int server_fd, Port *port)
|
||||
{
|
||||
SOCKET_SIZE_TYPE addrlen;
|
||||
SOCKET_SIZE_TYPE addrlen;
|
||||
|
||||
/* accept connection (and fill in the client (remote) address) */
|
||||
addrlen = sizeof(port->raddr);
|
||||
@@ -419,8 +424,8 @@ pq_recvbuf(void)
|
||||
if (PqRecvLength > PqRecvPointer)
|
||||
{
|
||||
/* still some unread data, left-justify it in the buffer */
|
||||
memmove(PqRecvBuffer, PqRecvBuffer+PqRecvPointer,
|
||||
PqRecvLength-PqRecvPointer);
|
||||
memmove(PqRecvBuffer, PqRecvBuffer + PqRecvPointer,
|
||||
PqRecvLength - PqRecvPointer);
|
||||
PqRecvLength -= PqRecvPointer;
|
||||
PqRecvPointer = 0;
|
||||
}
|
||||
@@ -431,16 +436,19 @@ pq_recvbuf(void)
|
||||
/* Can fill buffer from PqRecvLength and upwards */
|
||||
for (;;)
|
||||
{
|
||||
int r = recv(MyProcPort->sock, PqRecvBuffer + PqRecvLength,
|
||||
PQ_BUFFER_SIZE - PqRecvLength, 0);
|
||||
int r = recv(MyProcPort->sock, PqRecvBuffer + PqRecvLength,
|
||||
PQ_BUFFER_SIZE - PqRecvLength, 0);
|
||||
|
||||
if (r < 0)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
continue; /* Ok if interrupted */
|
||||
/* We would like to use elog() here, but dare not because elog
|
||||
* tries to write to the client, which will cause problems
|
||||
* if we have a hard communications failure ...
|
||||
* So just write the message to the postmaster log.
|
||||
|
||||
/*
|
||||
* We would like to use elog() here, but dare not because elog
|
||||
* tries to write to the client, which will cause problems if
|
||||
* we have a hard communications failure ... So just write the
|
||||
* message to the postmaster log.
|
||||
*/
|
||||
fprintf(stderr, "pq_recvbuf: recv() failed: %s\n",
|
||||
strerror(errno));
|
||||
@@ -499,7 +507,7 @@ pq_peekbyte(void)
|
||||
int
|
||||
pq_getbytes(char *s, size_t len)
|
||||
{
|
||||
size_t amount;
|
||||
size_t amount;
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
@@ -539,8 +547,8 @@ pq_getstring(char *s, size_t len)
|
||||
int c;
|
||||
|
||||
/*
|
||||
* Keep on reading until we get the terminating '\0',
|
||||
* discarding any bytes we don't have room for.
|
||||
* Keep on reading until we get the terminating '\0', discarding any
|
||||
* bytes we don't have room for.
|
||||
*/
|
||||
|
||||
while ((c = pq_getbyte()) != EOF && c != '\0')
|
||||
@@ -570,7 +578,7 @@ pq_getstring(char *s, size_t len)
|
||||
int
|
||||
pq_putbytes(const char *s, size_t len)
|
||||
{
|
||||
size_t amount;
|
||||
size_t amount;
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
@@ -602,19 +610,24 @@ pq_flush(void)
|
||||
|
||||
while (bufptr < bufend)
|
||||
{
|
||||
int r = send(MyProcPort->sock, bufptr, bufend - bufptr, 0);
|
||||
int r = send(MyProcPort->sock, bufptr, bufend - bufptr, 0);
|
||||
|
||||
if (r <= 0)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
continue; /* Ok if we were interrupted */
|
||||
/* We would like to use elog() here, but cannot because elog
|
||||
|
||||
/*
|
||||
* We would like to use elog() here, but cannot because elog
|
||||
* tries to write to the client, which would cause a recursive
|
||||
* flush attempt! So just write it out to the postmaster log.
|
||||
*/
|
||||
fprintf(stderr, "pq_flush: send() failed: %s\n",
|
||||
strerror(errno));
|
||||
/* We drop the buffered data anyway so that processing
|
||||
* can continue, even though we'll probably quit soon.
|
||||
|
||||
/*
|
||||
* We drop the buffered data anyway so that processing can
|
||||
* continue, even though we'll probably quit soon.
|
||||
*/
|
||||
PqSendPointer = 0;
|
||||
return EOF;
|
||||
@@ -661,7 +674,7 @@ pq_putmessage(char msgtype, const char *s, size_t len)
|
||||
}
|
||||
|
||||
/* --------------------------------
|
||||
* pq_startcopyout - inform libpq that a COPY OUT transfer is beginning
|
||||
* pq_startcopyout - inform libpq that a COPY OUT transfer is beginning
|
||||
* --------------------------------
|
||||
*/
|
||||
void
|
||||
@@ -682,7 +695,7 @@ pq_startcopyout(void)
|
||||
void
|
||||
pq_endcopyout(bool errorAbort)
|
||||
{
|
||||
if (! DoingCopyOut)
|
||||
if (!DoingCopyOut)
|
||||
return;
|
||||
if (errorAbort)
|
||||
pq_putbytes("\n\n\\.\n", 5);
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pqformat.c,v 1.3 1999/04/25 21:50:56 tgl Exp $
|
||||
* $Id: pqformat.c,v 1.4 1999/05/25 16:09:02 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
* INTERFACE ROUTINES
|
||||
* Message assembly and output:
|
||||
* pq_beginmessage - initialize StringInfo buffer
|
||||
* pq_beginmessage - initialize StringInfo buffer
|
||||
* pq_sendbyte - append a raw byte to a StringInfo buffer
|
||||
* pq_sendint - append a binary integer to a StringInfo buffer
|
||||
* pq_sendbytes - append raw data to a StringInfo buffer
|
||||
@@ -126,6 +126,7 @@ pq_sendcountedtext(StringInfo buf, const char *str, int slen)
|
||||
{
|
||||
#ifdef MULTIBYTE
|
||||
const char *p;
|
||||
|
||||
p = (const char *) pg_server_to_client((unsigned char *) str, slen);
|
||||
if (p != str) /* actual conversion has been done? */
|
||||
{
|
||||
@@ -147,9 +148,11 @@ pq_sendcountedtext(StringInfo buf, const char *str, int slen)
|
||||
void
|
||||
pq_sendstring(StringInfo buf, const char *str)
|
||||
{
|
||||
int slen = strlen(str);
|
||||
int slen = strlen(str);
|
||||
|
||||
#ifdef MULTIBYTE
|
||||
const char *p;
|
||||
|
||||
p = (const char *) pg_server_to_client((unsigned char *) str, slen);
|
||||
if (p != str) /* actual conversion has been done? */
|
||||
{
|
||||
@@ -157,7 +160,7 @@ pq_sendstring(StringInfo buf, const char *str)
|
||||
slen = strlen(str);
|
||||
}
|
||||
#endif
|
||||
appendBinaryStringInfo(buf, str, slen+1);
|
||||
appendBinaryStringInfo(buf, str, slen + 1);
|
||||
}
|
||||
|
||||
/* --------------------------------
|
||||
@@ -167,9 +170,9 @@ pq_sendstring(StringInfo buf, const char *str)
|
||||
void
|
||||
pq_sendint(StringInfo buf, int i, int b)
|
||||
{
|
||||
unsigned char n8;
|
||||
uint16 n16;
|
||||
uint32 n32;
|
||||
unsigned char n8;
|
||||
uint16 n16;
|
||||
uint32 n32;
|
||||
|
||||
switch (b)
|
||||
{
|
||||
@@ -225,9 +228,11 @@ pq_endmessage(StringInfo buf)
|
||||
int
|
||||
pq_puttextmessage(char msgtype, const char *str)
|
||||
{
|
||||
int slen = strlen(str);
|
||||
int slen = strlen(str);
|
||||
|
||||
#ifdef MULTIBYTE
|
||||
const char *p;
|
||||
|
||||
p = (const char *) pg_server_to_client((unsigned char *) str, slen);
|
||||
if (p != str) /* actual conversion has been done? */
|
||||
{
|
||||
@@ -235,7 +240,7 @@ pq_puttextmessage(char msgtype, const char *str)
|
||||
slen = strlen(str);
|
||||
}
|
||||
#endif
|
||||
return pq_putmessage(msgtype, str, slen+1);
|
||||
return pq_putmessage(msgtype, str, slen + 1);
|
||||
}
|
||||
|
||||
/* --------------------------------
|
||||
@@ -247,10 +252,10 @@ pq_puttextmessage(char msgtype, const char *str)
|
||||
int
|
||||
pq_getint(int *result, int b)
|
||||
{
|
||||
int status;
|
||||
unsigned char n8;
|
||||
uint16 n16;
|
||||
uint32 n32;
|
||||
int status;
|
||||
unsigned char n8;
|
||||
uint16 n16;
|
||||
uint32 n32;
|
||||
|
||||
switch (b)
|
||||
{
|
||||
@@ -269,8 +274,10 @@ pq_getint(int *result, int b)
|
||||
ntoh_l(n32) : ntohl(n32));
|
||||
break;
|
||||
default:
|
||||
/* if we elog(ERROR) here, we will lose sync with the frontend,
|
||||
* so just complain to postmaster log instead...
|
||||
|
||||
/*
|
||||
* if we elog(ERROR) here, we will lose sync with the
|
||||
* frontend, so just complain to postmaster log instead...
|
||||
*/
|
||||
fprintf(stderr, "pq_getint: unsupported size %d\n", b);
|
||||
status = EOF;
|
||||
@@ -293,23 +300,26 @@ int
|
||||
pq_getstr(char *s, int maxlen)
|
||||
{
|
||||
int c;
|
||||
|
||||
#ifdef MULTIBYTE
|
||||
char *p;
|
||||
|
||||
#endif
|
||||
|
||||
c = pq_getstring(s, maxlen);
|
||||
|
||||
#ifdef MULTIBYTE
|
||||
p = (char*) pg_client_to_server((unsigned char *) s, strlen(s));
|
||||
p = (char *) pg_client_to_server((unsigned char *) s, strlen(s));
|
||||
if (p != s) /* actual conversion has been done? */
|
||||
{
|
||||
int newlen = strlen(p);
|
||||
int newlen = strlen(p);
|
||||
|
||||
if (newlen < maxlen)
|
||||
strcpy(s, p);
|
||||
else
|
||||
{
|
||||
strncpy(s, p, maxlen);
|
||||
s[maxlen-1] = '\0';
|
||||
s[maxlen - 1] = '\0';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: util.c,v 1.8 1999/02/13 23:15:49 momjian Exp $
|
||||
* $Id: util.c,v 1.9 1999/05/25 16:09:03 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -17,7 +17,7 @@
|
||||
* PQuntrace - turn off pqdebug() tracing
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <postgres.h>
|
||||
|
||||
Reference in New Issue
Block a user