1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-12 05:01:15 +03:00

pgindent run before 6.3 release, with Thomas' requested changes.

This commit is contained in:
Bruce Momjian
1998-02-26 04:46:47 +00:00
parent 757bf69a2e
commit a32450a585
430 changed files with 12390 additions and 10292 deletions

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.26 1998/02/25 13:06:49 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.27 1998/02/26 04:31:42 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -40,16 +40,16 @@
#include <libpq/crypt.h>
static void sendAuthRequest(Port *port, AuthRequest areq, void (*handler)());
static void sendAuthRequest(Port *port, AuthRequest areq, void (*handler) ());
static void handle_done_auth(Port *port);
static void handle_krb4_auth(Port *port);
static void handle_krb5_auth(Port *port);
static void handle_password_auth(Port *port);
static void readPasswordPacket(char *arg, PacketLen len, char *pkt);
static void pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt);
static int checkPassword(Port *port, char *user, char *password);
static int old_be_recvauth(Port *port);
static int map_old_to_new(Port *port, UserAuth old, int status);
static int checkPassword(Port *port, char *user, char *password);
static int old_be_recvauth(Port *port);
static int map_old_to_new(Port *port, UserAuth old, int status);
#ifdef KRB4
@@ -327,14 +327,18 @@ pg_krb5_recvauth(Port *port)
* Handle a v0 password packet.
*/
static void pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt)
static void
pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt)
{
Port *port;
Port *port;
PasswordPacketV0 *pp;
char *user, *password, *cp, *start;
char *user,
*password,
*cp,
*start;
port = (Port *)arg;
pp = (PasswordPacketV0 *)pkt;
port = (Port *) arg;
pp = (PasswordPacketV0 *) pkt;
/*
* The packet is supposed to comprise the user name and the password
@@ -343,7 +347,7 @@ static void pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt)
user = password = NULL;
len -= sizeof (pp->unused);
len -= sizeof(pp->unused);
cp = start = pp->data;
@@ -372,8 +376,8 @@ static void pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt)
}
else
{
int status;
UserAuth saved;
int status;
UserAuth saved;
/* Check the password. */
@@ -396,7 +400,8 @@ static void pg_passwordv0_recvauth(char *arg, PacketLen len, char *pkt)
* Tell the user the authentication failed, but not why.
*/
void auth_failed(Port *port)
void
auth_failed(Port *port)
{
PacketSendError(&port->pktInfo, "User authentication failed");
}
@@ -405,15 +410,17 @@ void auth_failed(Port *port)
/*
* be_recvauth -- server demux routine for incoming authentication information
*/
void be_recvauth(Port *port)
void
be_recvauth(Port *port)
{
/*
* Get the authentication method to use for this frontend/database
* combination.
*/
if (hba_getauthmethod(&port->raddr, port->database, port->auth_arg,
&port->auth_method) != STATUS_OK)
&port->auth_method) != STATUS_OK)
PacketSendError(&port->pktInfo, "Missing or mis-configured pg_hba.conf file");
else if (PG_PROTOCOL_MAJOR(port->proto) == 0)
@@ -426,7 +433,7 @@ void be_recvauth(Port *port)
else
{
AuthRequest areq;
void (*auth_handler)();
void (*auth_handler) ();
/* Keep the compiler quiet. */
@@ -438,44 +445,44 @@ void be_recvauth(Port *port)
switch (port->auth_method)
{
case uaReject:
break;
case uaKrb4:
areq = AUTH_REQ_KRB4;
auth_handler = handle_krb4_auth;
break;
case uaReject:
break;
case uaKrb5:
areq = AUTH_REQ_KRB5;
auth_handler = handle_krb5_auth;
break;
case uaKrb4:
areq = AUTH_REQ_KRB4;
auth_handler = handle_krb4_auth;
break;
case uaTrust:
areq = AUTH_REQ_OK;
auth_handler = handle_done_auth;
break;
case uaKrb5:
areq = AUTH_REQ_KRB5;
auth_handler = handle_krb5_auth;
break;
case uaIdent:
if (authident(&port->raddr.in, &port->laddr.in,
port->user, port->auth_arg) == STATUS_OK)
{
case uaTrust:
areq = AUTH_REQ_OK;
auth_handler = handle_done_auth;
}
break;
break;
case uaIdent:
if (authident(&port->raddr.in, &port->laddr.in,
port->user, port->auth_arg) == STATUS_OK)
{
areq = AUTH_REQ_OK;
auth_handler = handle_done_auth;
}
case uaPassword:
areq = AUTH_REQ_PASSWORD;
auth_handler = handle_password_auth;
break;
break;
case uaCrypt:
areq = AUTH_REQ_CRYPT;
auth_handler = handle_password_auth;
break;
}
case uaPassword:
areq = AUTH_REQ_PASSWORD;
auth_handler = handle_password_auth;
break;
case uaCrypt:
areq = AUTH_REQ_CRYPT;
auth_handler = handle_password_auth;
break;
}
/* Tell the frontend what we want next. */
@@ -485,24 +492,26 @@ void be_recvauth(Port *port)
auth_failed(port);
}
}
/*
* Send an authentication request packet to the frontend.
*/
static void sendAuthRequest(Port *port, AuthRequest areq, void (*handler)())
static void
sendAuthRequest(Port *port, AuthRequest areq, void (*handler) ())
{
char *dp, *sp;
int i;
uint32 net_areq;
char *dp,
*sp;
int i;
uint32 net_areq;
/* Convert to a byte stream. */
net_areq = htonl(areq);
dp = port->pktInfo.pkt.ar.data;
sp = (char *)&net_areq;
sp = (char *) &net_areq;
*dp++ = 'R';
@@ -518,7 +527,7 @@ static void sendAuthRequest(Port *port, AuthRequest areq, void (*handler)())
i += 2;
}
PacketSendSetup(&port -> pktInfo, i, handler, (char *)port);
PacketSendSetup(&port->pktInfo, i, handler, (char *) port);
}
@@ -526,8 +535,10 @@ static void sendAuthRequest(Port *port, AuthRequest areq, void (*handler)())
* Called when we have told the front end that it is authorised.
*/
static void handle_done_auth(Port *port)
static void
handle_done_auth(Port *port)
{
/*
* Don't generate any more traffic. This will cause the backend to
* start.
@@ -542,7 +553,8 @@ static void handle_done_auth(Port *port)
* authentication.
*/
static void handle_krb4_auth(Port *port)
static void
handle_krb4_auth(Port *port)
{
if (pg_krb4_recvauth(port) != STATUS_OK)
auth_failed(port);
@@ -556,7 +568,8 @@ static void handle_krb4_auth(Port *port)
* authentication.
*/
static void handle_krb5_auth(Port *port)
static void
handle_krb5_auth(Port *port)
{
if (pg_krb5_recvauth(port) != STATUS_OK)
auth_failed(port);
@@ -570,11 +583,12 @@ static void handle_krb5_auth(Port *port)
* authentication.
*/
static void handle_password_auth(Port *port)
static void
handle_password_auth(Port *port)
{
/* Set up the read of the password packet. */
PacketReceiveSetup(&port->pktInfo, readPasswordPacket, (char *)port);
PacketReceiveSetup(&port->pktInfo, readPasswordPacket, (char *) port);
}
@@ -582,19 +596,20 @@ static void handle_password_auth(Port *port)
* Called when we have received the password packet.
*/
static void readPasswordPacket(char *arg, PacketLen len, char *pkt)
static void
readPasswordPacket(char *arg, PacketLen len, char *pkt)
{
char password[sizeof (PasswordPacket) + 1];
Port *port;
char password[sizeof(PasswordPacket) + 1];
Port *port;
port = (Port *)arg;
port = (Port *) arg;
/* Silently truncate a password that is too big. */
if (len > sizeof (PasswordPacket))
len = sizeof (PasswordPacket);
StrNCpy(password, ((PasswordPacket *)pkt)->passwd, len);
if (len > sizeof(PasswordPacket))
len = sizeof(PasswordPacket);
StrNCpy(password, ((PasswordPacket *) pkt)->passwd, len);
if (checkPassword(port, port->user, password) != STATUS_OK)
auth_failed(port);
@@ -609,7 +624,8 @@ static void readPasswordPacket(char *arg, PacketLen len, char *pkt)
* not.
*/
static int checkPassword(Port *port, char *user, char *password)
static int
checkPassword(Port *port, char *user, char *password)
{
if (port->auth_method == uaPassword && port->auth_arg[0] != '\0')
return verify_password(port->auth_arg, user, password);
@@ -622,83 +638,85 @@ static int checkPassword(Port *port, char *user, char *password)
* Server demux routine for incoming authentication information for protocol
* version 0.
*/
static int old_be_recvauth(Port *port)
static int
old_be_recvauth(Port *port)
{
int status;
MsgType msgtype = (MsgType)port->proto;
int status;
MsgType msgtype = (MsgType) port->proto;
/* Handle the authentication that's offered. */
switch (msgtype)
{
case STARTUP_KRB4_MSG:
status = map_old_to_new(port,uaKrb4,pg_krb4_recvauth(port));
break;
{
case STARTUP_KRB4_MSG:
status = map_old_to_new(port, uaKrb4, pg_krb4_recvauth(port));
break;
case STARTUP_KRB5_MSG:
status = map_old_to_new(port,uaKrb5,pg_krb5_recvauth(port));
break;
case STARTUP_KRB5_MSG:
status = map_old_to_new(port, uaKrb5, pg_krb5_recvauth(port));
break;
case STARTUP_MSG:
status = map_old_to_new(port,uaTrust,STATUS_OK);
break;
case STARTUP_MSG:
status = map_old_to_new(port, uaTrust, STATUS_OK);
break;
case STARTUP_PASSWORD_MSG:
PacketReceiveSetup(&port->pktInfo, pg_passwordv0_recvauth,
(char *)port);
case STARTUP_PASSWORD_MSG:
PacketReceiveSetup(&port->pktInfo, pg_passwordv0_recvauth,
(char *) port);
return STATUS_OK;
return STATUS_OK;
default:
fprintf(stderr, "Invalid startup message type: %u\n", msgtype);
default:
fprintf(stderr, "Invalid startup message type: %u\n", msgtype);
return STATUS_OK;
}
return STATUS_OK;
}
return status;
}
/*
* The old style authentication has been done. Modify the result of this (eg.
* The old style authentication has been done. Modify the result of this (eg.
* allow the connection anyway, disallow it anyway, or use the result)
* depending on what authentication we really want to use.
*/
static int map_old_to_new(Port *port, UserAuth old, int status)
static int
map_old_to_new(Port *port, UserAuth old, int status)
{
switch (port->auth_method)
{
case uaCrypt:
case uaReject:
status = STATUS_ERROR;
break;
case uaKrb4:
if (old != uaKrb4)
case uaCrypt:
case uaReject:
status = STATUS_ERROR;
break;
break;
case uaKrb5:
if (old != uaKrb5)
status = STATUS_ERROR;
break;
case uaKrb4:
if (old != uaKrb4)
status = STATUS_ERROR;
break;
case uaTrust:
status = STATUS_OK;
break;
case uaKrb5:
if (old != uaKrb5)
status = STATUS_ERROR;
break;
case uaIdent:
status = authident(&port->raddr.in, &port->laddr.in,
port->user, port->auth_arg);
break;
case uaTrust:
status = STATUS_OK;
break;
case uaPassword:
if (old != uaPassword)
status = STATUS_ERROR;
case uaIdent:
status = authident(&port->raddr.in, &port->laddr.in,
port->user, port->auth_arg);
break;
break;
case uaPassword:
if (old != uaPassword)
status = STATUS_ERROR;
break;
}
return status;
}

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-dumpdata.c,v 1.13 1998/02/10 16:03:12 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-dumpdata.c,v 1.14 1998/02/26 04:31:44 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -313,8 +313,8 @@ be_printtup(HeapTuple tuple, TupleDesc typeinfo)
if (!isnull && OidIsValid(typoutput))
{
values[i] = fmgr(typoutput, attr,
gettypelem(typeinfo->attrs[i]->atttypid),
typeinfo->attrs[i]->atttypmod);
gettypelem(typeinfo->attrs[i]->atttypid),
typeinfo->attrs[i]->atttypmod);
}
else
values[i] = NULL;

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-pqexec.c,v 1.14 1998/01/26 01:41:06 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-pqexec.c,v 1.15 1998/02/26 04:31:45 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -58,7 +58,7 @@ static char *strmake(char *str, int len);
* This code scavanged from HandleFunctionRequest() in tcop/fastpath.h
* ----------------
*/
char *
char *
PQfn(int fnid,
int *result_buf, /* can't use void, dec compiler barfs */
int result_len,
@@ -129,7 +129,7 @@ PQfn(int fnid,
* returns because the system longjmp's back to the main loop.
* ----------------
*/
char *
char *
PQexec(char *query)
{
PortalEntry *entry = NULL;

View File

@@ -1,8 +1,8 @@
/*-------------------------------------------------------------------------
*
* crypt.c--
* Look into pg_shadow and check the encrypted password with the one
* passed in from the frontend.
* Look into pg_shadow and check the encrypted password with the one
* passed in from the frontend.
*
* Modification History
*
@@ -28,262 +28,313 @@
#include <crypt.h>
#endif
char** pwd_cache = NULL;
int pwd_cache_count = 0;
char **pwd_cache = NULL;
int pwd_cache_count = 0;
/*-------------------------------------------------------------------------*/
char* crypt_getpwdfilename() {
char *
crypt_getpwdfilename()
{
static char* pfnam = NULL;
static char *pfnam = NULL;
if (!pfnam) {
pfnam = (char*)malloc(strlen(DataDir) + strlen(CRYPT_PWD_FILE) + 2);
sprintf(pfnam, "%s/%s", DataDir, CRYPT_PWD_FILE);
}
if (!pfnam)
{
pfnam = (char *) malloc(strlen(DataDir) + strlen(CRYPT_PWD_FILE) + 2);
sprintf(pfnam, "%s/%s", DataDir, CRYPT_PWD_FILE);
}
return pfnam;
return pfnam;
}
/*-------------------------------------------------------------------------*/
char* crypt_getpwdreloadfilename() {
char *
crypt_getpwdreloadfilename()
{
static char* rpfnam = NULL;
static char *rpfnam = NULL;
if (!rpfnam) {
char* pwdfilename;
if (!rpfnam)
{
char *pwdfilename;
pwdfilename = crypt_getpwdfilename();
rpfnam = (char*)malloc(strlen(pwdfilename) + strlen(CRYPT_PWD_RELOAD_SUFX) + 1);
sprintf(rpfnam, "%s%s", pwdfilename, CRYPT_PWD_RELOAD_SUFX);
}
pwdfilename = crypt_getpwdfilename();
rpfnam = (char *) malloc(strlen(pwdfilename) + strlen(CRYPT_PWD_RELOAD_SUFX) + 1);
sprintf(rpfnam, "%s%s", pwdfilename, CRYPT_PWD_RELOAD_SUFX);
}
return rpfnam;
return rpfnam;
}
/*-------------------------------------------------------------------------*/
static
FILE* crypt_openpwdfile() {
char* filename;
FILE* pwdfile;
FILE *
crypt_openpwdfile()
{
char *filename;
FILE *pwdfile;
filename = crypt_getpwdfilename();
pwdfile = AllocateFile(filename, "r");
filename = crypt_getpwdfilename();
pwdfile = AllocateFile(filename, "r");
return pwdfile;
return pwdfile;
}
/*-------------------------------------------------------------------------*/
static
int compar_user(const void* user_a, const void* user_b) {
int
compar_user(const void *user_a, const void *user_b)
{
int min,
value;
char* login_a;
char* login_b;
int min,
value;
char *login_a;
char *login_b;
login_a = *((char**)user_a);
login_b = *((char**)user_b);
login_a = *((char **) user_a);
login_b = *((char **) user_b);
/* We only really want to compare the user logins which are first. We look
* for the first SEPSTR char getting the number of chars there are before it.
* We only need to compare to the min count from the two strings.
*/
min = strcspn(login_a, CRYPT_PWD_FILE_SEPSTR);
value = strcspn(login_b, CRYPT_PWD_FILE_SEPSTR);
if (value < min)
min = value;
/*
* We only really want to compare the user logins which are first. We
* look for the first SEPSTR char getting the number of chars there
* are before it. We only need to compare to the min count from the
* two strings.
*/
min = strcspn(login_a, CRYPT_PWD_FILE_SEPSTR);
value = strcspn(login_b, CRYPT_PWD_FILE_SEPSTR);
if (value < min)
min = value;
/* We add one to min so that the separator character is included in the
* comparison. Why? I believe this will prevent logins that are proper
* prefixes of other logins from being 'masked out'. Being conservative!
*/
return strncmp(login_a, login_b, min + 1);
/*
* We add one to min so that the separator character is included in
* the comparison. Why? I believe this will prevent logins that are
* proper prefixes of other logins from being 'masked out'. Being
* conservative!
*/
return strncmp(login_a, login_b, min + 1);
}
/*-------------------------------------------------------------------------*/
static
void crypt_loadpwdfile() {
void
crypt_loadpwdfile()
{
char* filename;
int result;
FILE* pwd_file;
char buffer[256];
char *filename;
int result;
FILE *pwd_file;
char buffer[256];
filename = crypt_getpwdreloadfilename();
result = unlink(filename);
filename = crypt_getpwdreloadfilename();
result = unlink(filename);
/* We want to delete the flag file before reading the contents of the pg_pwd
* file. If result == 0 then the unlink of the reload file was successful.
* This means that a backend performed a COPY of the pg_shadow file to
* pg_pwd. Therefore we must now do a reload.
*/
if (!pwd_cache || !result) {
if (pwd_cache) { /* free the old data only if this is a reload */
while (pwd_cache_count--) {
free((void*)pwd_cache[pwd_cache_count]);
}
free((void*)pwd_cache);
pwd_cache = NULL;
pwd_cache_count = 0;
}
/*
* We want to delete the flag file before reading the contents of the
* pg_pwd file. If result == 0 then the unlink of the reload file was
* successful. This means that a backend performed a COPY of the
* pg_shadow file to pg_pwd. Therefore we must now do a reload.
*/
if (!pwd_cache || !result)
{
if (pwd_cache)
{ /* free the old data only if this is a
* reload */
while (pwd_cache_count--)
{
free((void *) pwd_cache[pwd_cache_count]);
}
free((void *) pwd_cache);
pwd_cache = NULL;
pwd_cache_count = 0;
}
if (!(pwd_file = crypt_openpwdfile()))
return;
if (!(pwd_file = crypt_openpwdfile()))
return;
/* Here is where we load the data from pg_pwd.
*/
while (fgets(buffer, 256, pwd_file) != NULL) {
/* We must remove the return char at the end of the string, as this will
* affect the correct parsing of the password entry.
*/
if (buffer[(result = strlen(buffer) - 1)] == '\n')
buffer[result] = '\0';
/*
* Here is where we load the data from pg_pwd.
*/
while (fgets(buffer, 256, pwd_file) != NULL)
{
pwd_cache = (char**)realloc((void*)pwd_cache, sizeof(char*) * (pwd_cache_count + 1));
pwd_cache[pwd_cache_count++] = strdup(buffer);
}
fclose(pwd_file);
/*
* We must remove the return char at the end of the string, as
* this will affect the correct parsing of the password entry.
*/
if (buffer[(result = strlen(buffer) - 1)] == '\n')
buffer[result] = '\0';
/* Now sort the entries in the cache for faster searching later.
*/
qsort((void*)pwd_cache, pwd_cache_count, sizeof(char*), compar_user);
}
pwd_cache = (char **) realloc((void *) pwd_cache, sizeof(char *) * (pwd_cache_count + 1));
pwd_cache[pwd_cache_count++] = strdup(buffer);
}
fclose(pwd_file);
/*
* Now sort the entries in the cache for faster searching later.
*/
qsort((void *) pwd_cache, pwd_cache_count, sizeof(char *), compar_user);
}
}
/*-------------------------------------------------------------------------*/
static
void crypt_parsepwdentry(char* buffer, char** pwd, char** valdate) {
void
crypt_parsepwdentry(char *buffer, char **pwd, char **valdate)
{
char* parse = buffer;
int count,
i;
char *parse = buffer;
int count,
i;
/* skip to the password field
*/
for (i = 0; i < 6; i++)
parse += (strcspn(parse, CRYPT_PWD_FILE_SEPSTR) + 1);
/*
* skip to the password field
*/
for (i = 0; i < 6; i++)
parse += (strcspn(parse, CRYPT_PWD_FILE_SEPSTR) + 1);
/* store a copy of user password to return
*/
count = strcspn(parse, CRYPT_PWD_FILE_SEPSTR);
*pwd = (char*)malloc(count + 1);
strncpy(*pwd, parse, count);
(*pwd)[count] = '\0';
parse += (count + 1);
/*
* store a copy of user password to return
*/
count = strcspn(parse, CRYPT_PWD_FILE_SEPSTR);
*pwd = (char *) malloc(count + 1);
strncpy(*pwd, parse, count);
(*pwd)[count] = '\0';
parse += (count + 1);
/* store a copy of date login becomes invalid
*/
count = strcspn(parse, CRYPT_PWD_FILE_SEPSTR);
*valdate = (char*)malloc(count + 1);
strncpy(*valdate, parse, count);
(*valdate)[count] = '\0';
parse += (count + 1);
/*
* store a copy of date login becomes invalid
*/
count = strcspn(parse, CRYPT_PWD_FILE_SEPSTR);
*valdate = (char *) malloc(count + 1);
strncpy(*valdate, parse, count);
(*valdate)[count] = '\0';
parse += (count + 1);
}
/*-------------------------------------------------------------------------*/
static
int crypt_getloginfo(const char* user, char** passwd, char** valuntil) {
int
crypt_getloginfo(const char *user, char **passwd, char **valuntil)
{
char* pwd;
char* valdate;
void* fakeout;
char *pwd;
char *valdate;
void *fakeout;
*passwd = NULL;
*valuntil = NULL;
crypt_loadpwdfile();
*passwd = NULL;
*valuntil = NULL;
crypt_loadpwdfile();
if (pwd_cache) {
char** pwd_entry;
char user_search[NAMEDATALEN + 2];
if (pwd_cache)
{
char **pwd_entry;
char user_search[NAMEDATALEN + 2];
sprintf(user_search, "%s\t", user);
fakeout = (void*)&user_search;
if ((pwd_entry = (char**)bsearch((void*)&fakeout, (void*)pwd_cache, pwd_cache_count, sizeof(char*), compar_user))) {
crypt_parsepwdentry(*pwd_entry, &pwd, &valdate);
*passwd = pwd;
*valuntil = valdate;
return STATUS_OK;
}
sprintf(user_search, "%s\t", user);
fakeout = (void *) &user_search;
if ((pwd_entry = (char **) bsearch((void *) &fakeout, (void *) pwd_cache, pwd_cache_count, sizeof(char *), compar_user)))
{
crypt_parsepwdentry(*pwd_entry, &pwd, &valdate);
*passwd = pwd;
*valuntil = valdate;
return STATUS_OK;
}
return STATUS_OK;
}
return STATUS_OK;
}
return STATUS_ERROR;
return STATUS_ERROR;
}
/*-------------------------------------------------------------------------*/
#if 0
MsgType crypt_salt(const char* user) {
MsgType
crypt_salt(const char *user)
{
char* passwd;
char* valuntil;
char *passwd;
char *valuntil;
if (crypt_getloginfo(user, &passwd, &valuntil) == STATUS_ERROR)
return STARTUP_UNSALT_MSG;
if (crypt_getloginfo(user, &passwd, &valuntil) == STATUS_ERROR)
return STARTUP_UNSALT_MSG;
if (passwd == NULL || *passwd == '\0' || !strcmp(passwd, "\\N")) {
if (passwd) free((void*)passwd);
if (valuntil) free((void*)valuntil);
return STARTUP_UNSALT_MSG;
}
if (passwd == NULL || *passwd == '\0' || !strcmp(passwd, "\\N"))
{
if (passwd)
free((void *) passwd);
if (valuntil)
free((void *) valuntil);
return STARTUP_UNSALT_MSG;
}
free((void*)passwd);
if (valuntil) free((void*)valuntil);
return STARTUP_SALT_MSG;
free((void *) passwd);
if (valuntil)
free((void *) valuntil);
return STARTUP_SALT_MSG;
}
#endif
/*-------------------------------------------------------------------------*/
int crypt_verify(Port* port, const char* user, const char* pgpass) {
int
crypt_verify(Port *port, const char *user, const char *pgpass)
{
char* passwd;
char* valuntil;
char* crypt_pwd;
int retval = STATUS_ERROR;
AbsoluteTime vuntil,
current;
char *passwd;
char *valuntil;
char *crypt_pwd;
int retval = STATUS_ERROR;
AbsoluteTime vuntil,
current;
if (crypt_getloginfo(user, &passwd, &valuntil) == STATUS_ERROR)
return STATUS_ERROR;
if (crypt_getloginfo(user, &passwd, &valuntil) == STATUS_ERROR)
return STATUS_ERROR;
if (passwd == NULL || *passwd == '\0') {
if (passwd) free((void*)passwd);
if (valuntil) free((void*)valuntil);
return STATUS_ERROR;
}
if (passwd == NULL || *passwd == '\0')
{
if (passwd)
free((void *) passwd);
if (valuntil)
free((void *) valuntil);
return STATUS_ERROR;
}
/*
* Compare with the encrypted or plain password depending on the
* authentication method being used for this connection.
*/
/*
* Compare with the encrypted or plain password depending on the
* 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;
}
if (!strcmp(pgpass, crypt_pwd))
{
free((void*)passwd);
if (valuntil) free((void*)valuntil);
return retval;
/*
* 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;
}
free((void *) passwd);
if (valuntil)
free((void *) valuntil);
return retval;
}

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.28 1998/02/24 15:18:41 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.29 1998/02/26 04:31:49 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -97,8 +97,8 @@ read_through_eol(FILE *file)
static void
read_hba_entry2(FILE *file, UserAuth * userauth_p, char auth_arg[],
bool *error_p)
read_hba_entry2(FILE *file, UserAuth *userauth_p, char auth_arg[],
bool *error_p)
{
/*--------------------------------------------------------------------------
Read from file FILE the rest of a host record, after the mask field,
@@ -156,7 +156,7 @@ read_hba_entry2(FILE *file, UserAuth * userauth_p, char auth_arg[],
static void
process_hba_record(FILE *file, SockAddr *raddr, const char database[],
bool *matches_p, bool *error_p,
UserAuth * userauth_p, char auth_arg[])
UserAuth *userauth_p, char auth_arg[])
{
/*---------------------------------------------------------------------------
Process the non-comment record in the config file that is next on the file.
@@ -167,7 +167,8 @@ process_hba_record(FILE *file, SockAddr *raddr, const char database[],
return *error_p true, after issuing a message to stderr. If no error,
leave *error_p as it was.
---------------------------------------------------------------------------*/
char db[MAX_TOKEN], buf[MAX_TOKEN];
char db[MAX_TOKEN],
buf[MAX_TOKEN];
/* Read the record type field. */
@@ -196,9 +197,9 @@ process_hba_record(FILE *file, SockAddr *raddr, const char database[],
*/
if (!*error_p &&
(*userauth_p == uaIdent ||
*userauth_p == uaKrb4 ||
*userauth_p == uaKrb5))
(*userauth_p == uaIdent ||
*userauth_p == uaKrb4 ||
*userauth_p == uaKrb5))
*error_p = true;
if (*error_p)
@@ -210,12 +211,13 @@ process_hba_record(FILE *file, SockAddr *raddr, const char database[],
*/
if ((strcmp(db, database) != 0 && strcmp(db, "all") != 0) ||
raddr->sa.sa_family != AF_UNIX)
raddr->sa.sa_family != AF_UNIX)
return;
}
else if (strcmp(buf, "host") == 0)
{
struct in_addr file_ip_addr, mask;
struct in_addr file_ip_addr,
mask;
/* Get the database. */
@@ -284,7 +286,7 @@ process_hba_record(FILE *file, SockAddr *raddr, const char database[],
syntax:
sprintf(PQerrormsg,
"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);
@@ -296,8 +298,8 @@ syntax:
static void
process_open_config_file(FILE *file, SockAddr *raddr, const char database[],
bool *host_ok_p, UserAuth * userauth_p,
char auth_arg[])
bool *host_ok_p, UserAuth *userauth_p,
char auth_arg[])
{
/*---------------------------------------------------------------------------
This function does the same thing as find_hba_entry, only with
@@ -332,7 +334,7 @@ process_open_config_file(FILE *file, SockAddr *raddr, const char database[],
else
{
process_hba_record(file, raddr, database,
&found_entry, &error, userauth_p, auth_arg);
&found_entry, &error, userauth_p, auth_arg);
}
}
}
@@ -352,7 +354,7 @@ process_open_config_file(FILE *file, SockAddr *raddr, const char database[],
static void
find_hba_entry(SockAddr *raddr, const char database[], bool *host_ok_p,
UserAuth * userauth_p, char auth_arg[])
UserAuth *userauth_p, char auth_arg[])
{
/*--------------------------------------------------------------------------
Read the config file and find an entry that allows connection from
@@ -812,7 +814,7 @@ verify_against_usermap(const char pguser[],
int
authident(struct sockaddr_in *raddr, struct sockaddr_in *laddr,
authident(struct sockaddr_in * raddr, struct sockaddr_in * laddr,
const char postgres_username[],
const char auth_arg[])
{
@@ -840,7 +842,7 @@ authident(struct sockaddr_in *raddr, struct sockaddr_in *laddr,
return STATUS_ERROR;
verify_against_usermap(postgres_username, ident_username, auth_arg,
&checks_out);
&checks_out);
return (checks_out ? STATUS_OK : STATUS_ERROR);
}
@@ -849,193 +851,207 @@ authident(struct sockaddr_in *raddr, struct sockaddr_in *laddr,
#ifdef CYR_RECODE
#define CHARSET_FILE "charset.conf"
#define MAX_CHARSETS 10
#define KEY_HOST 1
#define KEY_BASE 2
#define KEY_TABLE 3
#define KEY_HOST 1
#define KEY_BASE 2
#define KEY_TABLE 3
struct CharsetItem
{
char Orig[MAX_TOKEN];
char Dest[MAX_TOKEN];
char Table[MAX_TOKEN];
char Orig[MAX_TOKEN];
char Dest[MAX_TOKEN];
char Table[MAX_TOKEN];
};
int InRange(char *buf,int host)
int
InRange(char *buf, int host)
{
int valid,i,FromAddr,ToAddr,tmp;
struct in_addr file_ip_addr;
char *p;
unsigned int one=0x80000000,NetMask=0;
unsigned char mask;
p = strchr(buf,'/');
if(p)
{
*p++ = '\0';
valid = inet_aton(buf, &file_ip_addr);
if(valid)
{
mask = strtoul(p,0,0);
FromAddr = ntohl(file_ip_addr.s_addr);
ToAddr = ntohl(file_ip_addr.s_addr);
for(i=0;i<mask;i++)
{
NetMask |= one;
one >>= 1;
}
FromAddr &= NetMask;
ToAddr = ToAddr | ~NetMask;
tmp = ntohl(host);
return ((unsigned)tmp>=(unsigned)FromAddr &&
(unsigned)tmp<=(unsigned)ToAddr);
}
}
else
{
p = strchr(buf,'-');
if(p)
{
*p++ = '\0';
valid = inet_aton(buf, &file_ip_addr);
if(valid)
{
FromAddr = ntohl(file_ip_addr.s_addr);
valid = inet_aton(p, &file_ip_addr);
if(valid)
{
ToAddr = ntohl(file_ip_addr.s_addr);
tmp = ntohl(host);
return ((unsigned)tmp>=(unsigned)FromAddr &&
(unsigned)tmp<=(unsigned)ToAddr);
}
}
}
else
{
valid = inet_aton(buf, &file_ip_addr);
if(valid)
{
FromAddr = file_ip_addr.s_addr;
return ((unsigned)FromAddr == (unsigned)host);
}
}
}
return false;
int valid,
i,
FromAddr,
ToAddr,
tmp;
struct in_addr file_ip_addr;
char *p;
unsigned int one = 0x80000000,
NetMask = 0;
unsigned char mask;
p = strchr(buf, '/');
if (p)
{
*p++ = '\0';
valid = inet_aton(buf, &file_ip_addr);
if (valid)
{
mask = strtoul(p, 0, 0);
FromAddr = ntohl(file_ip_addr.s_addr);
ToAddr = ntohl(file_ip_addr.s_addr);
for (i = 0; i < mask; i++)
{
NetMask |= one;
one >>= 1;
}
FromAddr &= NetMask;
ToAddr = ToAddr | ~NetMask;
tmp = ntohl(host);
return ((unsigned) tmp >= (unsigned) FromAddr &&
(unsigned) tmp <= (unsigned) ToAddr);
}
}
else
{
p = strchr(buf, '-');
if (p)
{
*p++ = '\0';
valid = inet_aton(buf, &file_ip_addr);
if (valid)
{
FromAddr = ntohl(file_ip_addr.s_addr);
valid = inet_aton(p, &file_ip_addr);
if (valid)
{
ToAddr = ntohl(file_ip_addr.s_addr);
tmp = ntohl(host);
return ((unsigned) tmp >= (unsigned) FromAddr &&
(unsigned) tmp <= (unsigned) ToAddr);
}
}
}
else
{
valid = inet_aton(buf, &file_ip_addr);
if (valid)
{
FromAddr = file_ip_addr.s_addr;
return ((unsigned) FromAddr == (unsigned) host);
}
}
}
return false;
}
void GetCharSetByHost(char TableName[],int host, const char DataDir[])
void
GetCharSetByHost(char TableName[], int host, const char DataDir[])
{
FILE *file;
char buf[MAX_TOKEN],BaseCharset[MAX_TOKEN],
OrigCharset[MAX_TOKEN],DestCharset[MAX_TOKEN],HostCharset[MAX_TOKEN];
char c,eof=false;
char *map_file;
int key=0,i;
struct CharsetItem* ChArray[MAX_CHARSETS];
int ChIndex=0;
FILE *file;
char buf[MAX_TOKEN],
BaseCharset[MAX_TOKEN],
OrigCharset[MAX_TOKEN],
DestCharset[MAX_TOKEN],
HostCharset[MAX_TOKEN];
char c,
eof = false;
char *map_file;
int key = 0,
i;
struct CharsetItem *ChArray[MAX_CHARSETS];
int ChIndex = 0;
*TableName = '\0';
map_file = (char *) malloc((strlen(DataDir) +
strlen(CHARSET_FILE)+2)*sizeof(char));
sprintf(map_file, "%s/%s", DataDir, CHARSET_FILE);
file = fopen(map_file, "r");
if (file == NULL)
return;
while (!eof)
{
c = getc(file);
ungetc(c, file);
if (c == EOF)
eof = true;
else
{
if (c == '#')
read_through_eol(file);
else
{
/* Read the key */
next_token(file, buf, sizeof(buf));
if (buf[0] != '\0')
{
if (strcasecmp(buf, "HostCharset") == 0)
key = KEY_HOST;
if (strcasecmp(buf, "BaseCharset") == 0)
key = KEY_BASE;
if (strcasecmp(buf, "RecodeTable") == 0)
key = KEY_TABLE;
switch(key)
{
case KEY_HOST:
/* Read the host */
next_token(file, buf, sizeof(buf));
if (buf[0] != '\0')
{
if (InRange(buf,host))
{
/* Read the charset */
next_token(file, buf, sizeof(buf));
if (buf[0] != '\0')
{
strcpy(HostCharset,buf);
}
}
}
break;
case KEY_BASE:
/* Read the base charset */
next_token(file, buf, sizeof(buf));
if (buf[0] != '\0')
{
strcpy(BaseCharset,buf);
}
break;
case KEY_TABLE:
/* Read the original charset */
next_token(file, buf, sizeof(buf));
if (buf[0] != '\0')
{
strcpy(OrigCharset,buf);
/* Read the destination charset */
next_token(file, buf, sizeof(buf));
if (buf[0] != '\0')
{
strcpy(DestCharset,buf);
/* Read the table filename */
next_token(file, buf, sizeof(buf));
if (buf[0] != '\0')
{
ChArray[ChIndex] = (struct CharsetItem *) malloc(sizeof(struct CharsetItem));
strcpy(ChArray[ChIndex]->Orig,OrigCharset);
strcpy(ChArray[ChIndex]->Dest,DestCharset);
strcpy(ChArray[ChIndex]->Table,buf);
ChIndex++;
}
}
}
break;
}
read_through_eol(file);
}
}
}
}
fclose(file);
free(map_file);
for(i=0; i<ChIndex; i++)
{
if(!strcasecmp(BaseCharset,ChArray[i]->Orig) &&
!strcasecmp(HostCharset,ChArray[i]->Dest))
{
strncpy(TableName,ChArray[i]->Table,79);
}
free((struct CharsetItem *) ChArray[i]);
}
*TableName = '\0';
map_file = (char *) malloc((strlen(DataDir) +
strlen(CHARSET_FILE) + 2) * sizeof(char));
sprintf(map_file, "%s/%s", DataDir, CHARSET_FILE);
file = fopen(map_file, "r");
if (file == NULL)
return;
while (!eof)
{
c = getc(file);
ungetc(c, file);
if (c == EOF)
eof = true;
else
{
if (c == '#')
read_through_eol(file);
else
{
/* Read the key */
next_token(file, buf, sizeof(buf));
if (buf[0] != '\0')
{
if (strcasecmp(buf, "HostCharset") == 0)
key = KEY_HOST;
if (strcasecmp(buf, "BaseCharset") == 0)
key = KEY_BASE;
if (strcasecmp(buf, "RecodeTable") == 0)
key = KEY_TABLE;
switch (key)
{
case KEY_HOST:
/* Read the host */
next_token(file, buf, sizeof(buf));
if (buf[0] != '\0')
{
if (InRange(buf, host))
{
/* Read the charset */
next_token(file, buf, sizeof(buf));
if (buf[0] != '\0')
{
strcpy(HostCharset, buf);
}
}
}
break;
case KEY_BASE:
/* Read the base charset */
next_token(file, buf, sizeof(buf));
if (buf[0] != '\0')
{
strcpy(BaseCharset, buf);
}
break;
case KEY_TABLE:
/* Read the original charset */
next_token(file, buf, sizeof(buf));
if (buf[0] != '\0')
{
strcpy(OrigCharset, buf);
/* Read the destination charset */
next_token(file, buf, sizeof(buf));
if (buf[0] != '\0')
{
strcpy(DestCharset, buf);
/* Read the table filename */
next_token(file, buf, sizeof(buf));
if (buf[0] != '\0')
{
ChArray[ChIndex] = (struct CharsetItem *) malloc(sizeof(struct CharsetItem));
strcpy(ChArray[ChIndex]->Orig, OrigCharset);
strcpy(ChArray[ChIndex]->Dest, DestCharset);
strcpy(ChArray[ChIndex]->Table, buf);
ChIndex++;
}
}
}
break;
}
read_through_eol(file);
}
}
}
}
fclose(file);
free(map_file);
for (i = 0; i < ChIndex; i++)
{
if (!strcasecmp(BaseCharset, ChArray[i]->Orig) &&
!strcasecmp(HostCharset, ChArray[i]->Dest))
{
strncpy(TableName, ChArray[i]->Table, 79);
}
free((struct CharsetItem *) ChArray[i]);
}
}
#endif
extern int
hba_getauthmethod(SockAddr *raddr, char *database, char *auth_arg,
UserAuth *auth_method)
UserAuth *auth_method)
{
/*---------------------------------------------------------------------------
Determine what authentication method should be used when accessing database

View File

@@ -12,8 +12,8 @@
int
verify_password(char *auth_arg, char *user, char *password)
{
char *pw_file_fullname;
FILE *pw_file;
char *pw_file_fullname;
FILE *pw_file;
pw_file_fullname = (char *) palloc(strlen(DataDir) + strlen(auth_arg) + 2);
strcpy(pw_file_fullname, DataDir);
@@ -36,9 +36,12 @@ verify_password(char *auth_arg, char *user, char *password)
while (!feof(pw_file))
{
char pw_file_line[255], *p, *test_user, *test_pw;
char pw_file_line[255],
*p,
*test_user,
*test_pw;
fgets(pw_file_line, sizeof (pw_file_line), pw_file);
fgets(pw_file_line, sizeof(pw_file_line), pw_file);
p = pw_file_line;
test_user = strtok(p, ":");

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portal.c,v 1.12 1997/12/09 03:10:43 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portal.c,v 1.13 1998/02/26 04:31:51 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -295,7 +295,7 @@ PQfnumberGroup(PortalBuffer *portal, int group_index, char *field_name)
* the group index and field index.
* --------------------------------
*/
char *
char *
PQfnameGroup(PortalBuffer *portal, int group_index, int field_number)
{
GroupBuffer *gbp;
@@ -451,7 +451,7 @@ PQfnumber(PortalBuffer *portal, int tuple_index, char *field_name)
* PQfname - Return the name of a field
* --------------------------------
*/
char *
char *
PQfname(PortalBuffer *portal, int tuple_index, int field_number)
{
GroupBuffer *gbp;
@@ -578,7 +578,7 @@ PQGetTupleBlock(PortalBuffer *portal,
* PQgetvalue - Return an attribute (field) value
* --------------------------------
*/
char *
char *
PQgetvalue(PortalBuffer *portal,
int tuple_index,
int field_number)
@@ -598,7 +598,7 @@ PQgetvalue(PortalBuffer *portal,
* a copy. The CALLER is responsible for free'ing the data returned.
* --------------------------------
*/
char *
char *
PQgetAttr(PortalBuffer *portal,
int tuple_index,
int field_number)

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portalbuf.c,v 1.9 1997/12/09 03:10:45 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portalbuf.c,v 1.10 1998/02/26 04:31:52 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -235,7 +235,7 @@ pbuf_addTuple(int n)
* pbuf_addTupleValueLengths - Allocate a tuple of n lengths (attributes)
* --------------------------------
*/
int *
int *
pbuf_addTupleValueLengths(int n)
{
return (int *)
@@ -246,7 +246,7 @@ pbuf_addTupleValueLengths(int n)
* pbuf_addValues - Allocate n bytes for a value
* --------------------------------
*/
char *
char *
pbuf_addValues(int n)
{
return
@@ -510,7 +510,7 @@ pbuf_checkFnumber(GroupBuffer *group,
* pbuf_findFname - Find the field name given the field index
* --------------------------------
*/
char *
char *
pbuf_findFname(GroupBuffer *group,
int field_number)
{

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.38 1998/02/24 04:01:53 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.39 1998/02/26 04:31:53 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -38,9 +38,9 @@
#include <stdio.h>
#if defined(HAVE_STRING_H)
# include <string.h>
#include <string.h>
#else
# include <strings.h>
#include <strings.h>
#endif
#include <signal.h>
#include <errno.h>
@@ -558,7 +558,7 @@ pq_async_notify()
* RETURNS: STATUS_OK or STATUS_ERROR
*/
static char sock_path[MAXPGPATH+1] = "";
static char sock_path[MAXPGPATH + 1] = "";
/* do_unlink()
* Shutdown routine for backend connection
@@ -574,7 +574,7 @@ do_unlink()
int
StreamServerPort(char *hostName, short portName, int *fdP)
{
SockAddr saddr;
SockAddr saddr;
int fd,
err,
family;
@@ -613,22 +613,22 @@ StreamServerPort(char *hostName, short portName, int *fdP)
{
saddr.in.sin_addr.s_addr = htonl(INADDR_ANY);
saddr.in.sin_port = htons(portName);
len = sizeof (struct sockaddr_in);
len = sizeof(struct sockaddr_in);
}
err = bind(fd, &saddr.sa, len);
if (err < 0)
{
sprintf(PQerrormsg,
"FATAL: StreamServerPort: bind() failed: errno=%d\n",
errno);
pqdebug("%s", PQerrormsg);
strcat(PQerrormsg, "\tIs another postmaster already running on that port?\n");
if (family == AF_UNIX)
strcat(PQerrormsg, "\tIf not, remove socket node (/tmp/.s.PGSQL.<portnr>)and retry.\n");
else
strcat(PQerrormsg, "\tIf not, wait a few seconds and retry.\n");
fputs(PQerrormsg, stderr);
return (STATUS_ERROR);
sprintf(PQerrormsg,
"FATAL: StreamServerPort: bind() failed: errno=%d\n",
errno);
pqdebug("%s", PQerrormsg);
strcat(PQerrormsg, "\tIs another postmaster already running on that port?\n");
if (family == AF_UNIX)
strcat(PQerrormsg, "\tIf not, remove socket node (/tmp/.s.PGSQL.<portnr>)and retry.\n");
else
strcat(PQerrormsg, "\tIf not, wait a few seconds and retry.\n");
fputs(PQerrormsg, stderr);
return (STATUS_ERROR);
}
listen(fd, SOMAXCONN);
@@ -643,10 +643,10 @@ StreamServerPort(char *hostName, short portName, int *fdP)
*fdP = fd;
if (family == AF_UNIX)
{
chmod(sock_path, 0777);
atexit(do_unlink);
}
{
chmod(sock_path, 0777);
atexit(do_unlink);
}
return (STATUS_OK);
}

View File

@@ -63,12 +63,12 @@
int
pqPutShort(int integer, FILE *f)
{
uint16 n;
uint16 n;
#ifdef FRONTEND
n = htons((uint16)integer);
n = htons((uint16) integer);
#else
n = ((PG_PROTOCOL_MAJOR(FrontendProtocol) == 0) ? hton_s(integer) : htons((uint16)integer));
n = ((PG_PROTOCOL_MAJOR(FrontendProtocol) == 0) ? hton_s(integer) : htons((uint16) integer));
#endif
if (fwrite(&n, 2, 1, f) != 1)
@@ -81,12 +81,12 @@ pqPutShort(int integer, FILE *f)
int
pqPutLong(int integer, FILE *f)
{
uint32 n;
uint32 n;
#ifdef FRONTEND
n = htonl((uint32)integer);
n = htonl((uint32) integer);
#else
n = ((PG_PROTOCOL_MAJOR(FrontendProtocol) == 0) ? hton_l(integer) : htonl((uint32)integer));
n = ((PG_PROTOCOL_MAJOR(FrontendProtocol) == 0) ? hton_l(integer) : htonl((uint32) integer));
#endif
if (fwrite(&n, 4, 1, f) != 1)
@@ -99,15 +99,15 @@ pqPutLong(int integer, FILE *f)
int
pqGetShort(int *result, FILE *f)
{
uint16 n;
uint16 n;
if (fread(&n, 2, 1, f) != 1)
return EOF;
#ifdef FRONTEND
*result = (int)ntohs(n);
*result = (int) ntohs(n);
#else
*result = (int)((PG_PROTOCOL_MAJOR(FrontendProtocol) == 0) ? ntoh_s(n) : ntohs(n));
*result = (int) ((PG_PROTOCOL_MAJOR(FrontendProtocol) == 0) ? ntoh_s(n) : ntohs(n));
#endif
return 0;
@@ -117,15 +117,15 @@ pqGetShort(int *result, FILE *f)
int
pqGetLong(int *result, FILE *f)
{
uint32 n;
uint32 n;
if (fread(&n, 4, 1, f) != 1)
return EOF;
#ifdef FRONTEND
*result = (int)ntohl(n);
*result = (int) ntohl(n);
#else
*result = (int)((PG_PROTOCOL_MAJOR(FrontendProtocol) == 0) ? ntoh_l(n) : ntohl(n));
*result = (int) ((PG_PROTOCOL_MAJOR(FrontendProtocol) == 0) ? ntoh_l(n) : ntohl(n));
#endif
return 0;
@@ -139,7 +139,7 @@ pqGetLong(int *result, FILE *f)
int
pqGetNBytes(char *s, size_t len, FILE *f)
{
int cnt;
int cnt;
if (f == NULL)
return EOF;
@@ -167,7 +167,7 @@ pqPutNBytes(const char *s, size_t len, FILE *f)
int
pqGetString(char *s, size_t len, FILE *f)
{
int c;
int c;
if (f == NULL)
return EOF;

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.14 1998/01/31 20:12:09 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.15 1998/02/26 04:31:56 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -33,30 +33,31 @@
* Set up a packet read for the postmaster event loop.
*/
void PacketReceiveSetup(Packet *pkt, void (*iodone)(), char *arg)
void PacketReceiveSetup(Packet *pkt, void (*iodone) (), char *arg)
{
pkt->nrtodo = sizeof (pkt->len);
pkt->ptr = (char *)&pkt->len;
pkt->nrtodo = sizeof(pkt->len);
pkt->ptr = (char *) &pkt->len;
pkt->iodone = iodone;
pkt->arg = arg;
pkt->state = ReadingPacketLength;
/* Clear the destination. */
MemSet(&pkt->pkt, 0, sizeof (pkt->pkt));
MemSet(&pkt->pkt, 0, sizeof(pkt->pkt));
}
/*
* Read a packet fragment. Return STATUS_OK if the connection should stay
* Read a packet fragment. Return STATUS_OK if the connection should stay
* open.
*/
int PacketReceiveFragment(Packet *pkt, int sock)
int
PacketReceiveFragment(Packet *pkt, int sock)
{
int got;
int got;
if ((got = read(sock,pkt->ptr,pkt->nrtodo)) > 0)
if ((got = read(sock, pkt->ptr, pkt->nrtodo)) > 0)
{
pkt->nrtodo -= got;
pkt->ptr += got;
@@ -67,18 +68,18 @@ int PacketReceiveFragment(Packet *pkt, int sock)
{
pkt->len = ntohl(pkt->len);
if (pkt->len < sizeof (pkt->len) ||
pkt->len > sizeof (pkt->len) + sizeof (pkt->pkt))
if (pkt->len < sizeof(pkt->len) ||
pkt->len > sizeof(pkt->len) + sizeof(pkt->pkt))
{
PacketSendError(pkt,"Invalid packet length");
PacketSendError(pkt, "Invalid packet length");
return STATUS_OK;
}
/* Set up for the rest of the packet. */
pkt->nrtodo = pkt->len - sizeof (pkt->len);
pkt->ptr = (char *)&pkt->pkt;
pkt->nrtodo = pkt->len - sizeof(pkt->len);
pkt->ptr = (char *) &pkt->pkt;
pkt->state = ReadingPacket;
}
@@ -93,8 +94,8 @@ int PacketReceiveFragment(Packet *pkt, int sock)
if (pkt->iodone == NULL)
return STATUS_ERROR;
(*pkt->iodone)(pkt->arg, pkt->len - sizeof (pkt->len),
(char *)&pkt->pkt);
(*pkt->iodone) (pkt->arg, pkt->len - sizeof(pkt->len),
(char *) &pkt->pkt);
}
return STATUS_OK;
@@ -116,10 +117,10 @@ int PacketReceiveFragment(Packet *pkt, int sock)
* Set up a packet write for the postmaster event loop.
*/
void PacketSendSetup(Packet *pkt, int nbytes, void (*iodone)(), char *arg)
void PacketSendSetup(Packet *pkt, int nbytes, void (*iodone) (), char *arg)
{
pkt->nrtodo = nbytes;
pkt->ptr = (char *)&pkt->pkt;
pkt->ptr = (char *) &pkt->pkt;
pkt->iodone = iodone;
pkt->arg = arg;
pkt->state = WritingPacket;
@@ -131,11 +132,12 @@ void PacketSendSetup(Packet *pkt, int nbytes, void (*iodone)(), char *arg)
* open.
*/
int PacketSendFragment(Packet *pkt, int sock)
int
PacketSendFragment(Packet *pkt, int sock)
{
int done;
int done;
if ((done = write(sock,pkt->ptr,pkt->nrtodo)) > 0)
if ((done = write(sock, pkt->ptr, pkt->nrtodo)) > 0)
{
pkt->nrtodo -= done;
pkt->ptr += done;
@@ -151,7 +153,7 @@ int PacketSendFragment(Packet *pkt, int sock)
if (pkt->iodone == NULL)
return STATUS_ERROR;
(*pkt->iodone)(pkt->arg);
(*pkt->iodone) (pkt->arg);
}
return STATUS_OK;
@@ -173,12 +175,13 @@ int PacketSendFragment(Packet *pkt, int sock)
* Send an error message from the postmaster to the frontend.
*/
void PacketSendError(Packet *pkt, char *errormsg)
void
PacketSendError(Packet *pkt, char *errormsg)
{
fprintf(stderr, "%s\n", errormsg);
pkt->pkt.em.data[0] = 'E';
StrNCpy(&pkt->pkt.em.data[1], errormsg, sizeof (pkt->pkt.em.data) - 2);
StrNCpy(&pkt->pkt.em.data[1], errormsg, sizeof(pkt->pkt.em.data) - 2);
/*
* The NULL i/o callback will cause the connection to be broken when