*
* Copyright (c) 1994, Regents of the University of California
*
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/xid.c,v 1.19 1998/12/14 05:18:33 scrappy Exp $
+ * $Id: xid.c,v 1.20 1998/12/14 06:50:17 scrappy Exp $
*
* OLD COMMENTS
* XXX WARNING
char *
xidout(TransactionId transactionId)
{
-/* return(TransactionIdFormString(transactionId)); */
- char *representation;
-
/* maximum 32 bit unsigned integer representation takes 10 chars */
- representation = palloc(11);
+ char *representation = palloc(11);
- sprintf(representation, "%u", transactionId);
+ snprintf(representation, 11, "%u", transactionId);
return representation;
*
* Copyright (c) 1994, Regents of the University of California
*
- * The version stuff has not been tested under postgres95 and probably doesn't
- * work! - jolly 8/19/95
+ * The version stuff has not been tested under postgres95 and probably
+ * doesn't work! - jolly 8/19/95
*
*
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/_deadcode/Attic/version.c,v 1.16 1998/12/14 05:18:44 scrappy Exp $
+ * $Id: version.c,v 1.17 1998/12/14 06:50:19 scrappy Exp $
*
* NOTES
- * At the point the version is defined, 2 physical relations are created
- * <vname>_added and <vname>_deleted.
+ * At the point the version is defined, 2 physical relations are created
+ * <vname>_added and <vname>_deleted.
*
- * In addition, 4 rules are defined which govern the semantics of versions
- * w.r.t retrieves, appends, replaces and deletes.
+ * In addition, 4 rules are defined which govern the semantics of
+ * versions w.r.t retrieves, appends, replaces and deletes.
*
*-------------------------------------------------------------------------
*/
*
* Copyright (c) 1994, Regents of the University of California
*
- *
+ * $Id: user.c,v 1.21 1998/12/14 06:50:18 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
static void CheckPgUserAclNotNull(void);
+#define SQL_LENGTH 512
+
/*---------------------------------------------------------------------
* UpdatePgPwdFile
*
UpdatePgPwdFile(char *sql)
{
- char *filename;
- char *tempname;
+ char *filename,
+ *tempname;
+ int bufsize;
/*
* Create a temporary filename to be renamed later. This prevents the
* be reading from it.
*/
filename = crypt_getpwdfilename();
- tempname = (char *) malloc(strlen(filename) + 12);
- sprintf(tempname, "%s.%d", filename, MyProcPid);
+ bufsize = strlen(filename) + 12;
+ tempname = (char *) palloc(bufsize);
+ snprintf(tempname, bufsize, "%s.%d", filename, MyProcPid);
/*
* Copy the contents of pg_shadow to the pg_pwd ASCII file using a the
* SEPCHAR character as the delimiter between fields. Then rename the
* file to its final name.
*/
- sprintf(sql, "copy %s to '%s' using delimiters %s", ShadowRelationName, tempname, CRYPT_PWD_FILE_SEPCHAR);
+ snprintf(sql, QRY_LENGTH,
+ "copy %s to '%s' using delimiters %s",
+ ShadowRelationName, tempname, CRYPT_PWD_FILE_SEPCHAR);
pg_exec_query(sql);
rename(tempname, filename);
- free((void *) tempname);
+ pfree((void *) tempname);
/*
* Create a flag file the postmaster will detect the next time it
DefineUser(CreateUserStmt *stmt)
{
- char *pg_shadow;
- Relation pg_shadow_rel;
- TupleDesc pg_shadow_dsc;
- HeapScanDesc scan;
- HeapTuple tuple;
- Datum datum;
- char sql[512];
- char *sql_end;
- bool exists = false,
- n,
- inblock;
- int max_id = -1;
+ char *pg_shadow,
+ sql[SQL_LENGTH];
+ Relation pg_shadow_rel;
+ TupleDesc pg_shadow_dsc;
+ HeapScanDesc scan;
+ HeapTuple tuple;
+ Datum datum;
+ bool exists = false,
+ n,
+ inblock;
+ int max_id = -1;
if (stmt->password)
CheckPgUserAclNotNull();
RelationUnsetLockForWrite(pg_shadow_rel);
heap_close(pg_shadow_rel);
UserAbortTransactionBlock();
- elog(ERROR, "defineUser: user \"%s\" has already been created", stmt->user);
+ elog(ERROR,
+ "defineUser: user \"%s\" has already been created", stmt->user);
return;
}
/*
* Build the insert statment to be executed.
*/
- sprintf(sql, "insert into %s(usename,usesysid,usecreatedb,usetrace,usesuper,usecatupd,passwd", ShadowRelationName);
-/* if (stmt->password)
- strcat(sql, ",passwd"); -- removed so that insert empty string when no password */
- if (stmt->validUntil)
- strcat(sql, ",valuntil");
-
- sql_end = sql + strlen(sql);
- sprintf(sql_end, ") values('%s',%d", stmt->user, max_id + 1);
- if (stmt->createdb && *stmt->createdb)
- strcat(sql_end, ",'t','t'");
- else
- strcat(sql_end, ",'f','t'");
- if (stmt->createuser && *stmt->createuser)
- strcat(sql_end, ",'t','t'");
- else
- strcat(sql_end, ",'f','t'");
- sql_end += strlen(sql_end);
- if (stmt->password)
- {
- sprintf(sql_end, ",'%s'", stmt->password);
- sql_end += strlen(sql_end);
- }
- else
- {
- strcpy(sql_end, ",''");
- sql_end += strlen(sql_end);
- }
- if (stmt->validUntil)
- {
- sprintf(sql_end, ",'%s'", stmt->validUntil);
- sql_end += strlen(sql_end);
- }
- strcat(sql_end, ")");
+ snprintf(sql, SQL_LENGTH,
+ "insert into %s(usename,usesysid,usecreatedb,usetrace,usesuper,"
+ "usecatupd,passwd,valuntil) values('%s',%d%s%s,'%s','%s')",
+ ShadowRelationName,
+ stmt->user, max_id + 1,
+ (stmt->createdb && *stmt->createdb) ? ",'t','t'" : ",'f','t'",
+ (stmt->createuser && *stmt->createuser) ? ",'t','t'" : ",'f','t'",
+ stmt->password ? stmt->password : "''",
+ stmt->validUntil ? stmt->valudUntil : "");
pg_exec_query(sql);
AlterUser(AlterUserStmt *stmt)
{
- char *pg_shadow;
+ char *pg_shadow,
+ sql[SQL_LENGTH];
Relation pg_shadow_rel;
TupleDesc pg_shadow_dsc;
HeapTuple tuple;
- char sql[512];
- char *sql_end;
- bool inblock;
+ bool inblock;
if (stmt->password)
CheckPgUserAclNotNull();
/*
* Create the update statement to modify the user.
*/
- sprintf(sql, "update %s set", ShadowRelationName);
- sql_end = sql;
+ snprintf(sql, SQL_LENGTH, "update %s set", ShadowRelationName);
+
if (stmt->password)
{
- sql_end += strlen(sql_end);
- sprintf(sql_end, " passwd = '%s'", stmt->password);
+ snprintf(sql, SQL_LENGTH, "%s passwd = '%s'", sql, stmt->password);
}
+
if (stmt->createdb)
{
- if (sql_end != sql)
- strcat(sql_end, ",");
- sql_end += strlen(sql_end);
- if (*stmt->createdb)
- strcat(sql_end, " usecreatedb = 't'");
- else
- strcat(sql_end, " usecreatedb = 'f'");
+ snprintf(sql, SQL_LENGTH, "%s %susecreatedb='%s'",
+ stmt->password ? "," : "",
+ *stmt->createdb ? "t" : "f");
}
+
if (stmt->createuser)
{
- if (sql_end != sql)
- strcat(sql_end, ",");
- sql_end += strlen(sql_end);
- if (*stmt->createuser)
- strcat(sql_end, " usesuper = 't'");
- else
- strcat(sql_end, " usesuper = 'f'");
+ snprintf(sql, SQL_LENGTH, "%s %susesuper='%s'",
+ (stmt->password || stmt->createdb) ? "," : "",
+ *stmt->createuser ? "t" : "f");
}
+
if (stmt->validUntil)
{
- if (sql_end != sql)
- strcat(sql_end, ",");
- sql_end += strlen(sql_end);
- sprintf(sql_end, " valuntil = '%s'", stmt->validUntil);
- }
- if (sql_end != sql)
- {
- sql_end += strlen(sql_end);
- sprintf(sql_end, " where usename = '%s'", stmt->user);
- pg_exec_query(sql);
+ snprintf(sql, SQL_LENGTH, "%s %svaluntil='%s'",
+ (stmt->password || stmt->createdb || stmt->createuser) ? "," : "",
+ stmt->validUntil);
}
+ snprintf(sql, SQL_LENGTH, "%s where usename = '%s'", sql, stmt->user);
+
+ pg_exec_query(sql);
+
/* do the pg_group stuff here */
UpdatePgPwdFile(sql);
datum = heap_getattr(tuple, Anum_pg_database_datname, pg_dsc, &n);
if (memcmp((void *) datum, "template1", 9))
{
- dbase = (char **) realloc((void *) dbase, sizeof(char *) * (ndbase + 1));
- dbase[ndbase] = (char *) malloc(NAMEDATALEN + 1);
+ dbase =
+ (char **) repalloc((void *) dbase, sizeof(char *) * (ndbase + 1));
+ dbase[ndbase] = (char *) palloc(NAMEDATALEN + 1);
memcpy((void *) dbase[ndbase], (void *) datum, NAMEDATALEN);
dbase[ndbase++][NAMEDATALEN] = '\0';
}
while (ndbase--)
{
elog(NOTICE, "Dropping database %s", dbase[ndbase]);
- sprintf(sql, "drop database %s", dbase[ndbase]);
- free((void *) dbase[ndbase]);
+ snprintf(sql, SQL_LENGTH, "drop database %s", dbase[ndbase]);
+ pfree((void *) dbase[ndbase]);
pg_exec_query(sql);
}
if (dbase)
- free((void *) dbase);
+ pfree((void *) dbase);
/*
* Since pg_shadow is global over all databases, one of two things
/*
* Remove the user from the pg_shadow table
*/
- sprintf(sql, "delete from %s where usename = '%s'", ShadowRelationName, user);
+ snprintf(sql, SQL_LENGTH,
+ "delete from %s where usename = '%s'", ShadowRelationName, user);
pg_exec_query(sql);
UpdatePgPwdFile(sql);
*
* Copyright (c) 1994, Regents of the University of California
*
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/view.c,v 1.27 1998/12/14 05:18:44 scrappy Exp $
+ * $Id: view.c,v 1.28 1998/12/14 06:50:18 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
*
* Copyright (c) 1994, Regents of the University of California
*
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/execAmi.c,v 1.26 1998/12/14 05:18:49 scrappy Exp $
+ * $Id: execAmi.c,v 1.27 1998/12/14 06:50:20 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
* Copyright (c) 1994, Regents of the University of California
*
*
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/nodeHash.c,v 1.25 1998/12/14 05:18:50 scrappy Exp $
+ * $Id: nodeHash.c,v 1.26 1998/12/14 06:50:21 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
* Copyright (c) 1994, Regents of the University of California
*
* DESCRIPTION
- * This code provides support for a tee node, which allows multiple
- * parent in a megaplan.
+ * This code provides support for a tee node, which allows
+ * multiple parent in a megaplan.
*
* INTERFACE ROUTINES
* ExecTee
* ExecInitTee
* ExecEndTee
*
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/Attic/nodeTee.c,v 1.26 1998/12/14 05:18:51 scrappy Exp $
+ * $Id: nodeTee.c,v 1.27 1998/12/14 06:50:22 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
*
* Copyright (c) 1994, Regents of the University of California
*
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-dumpdata.c,v 1.18 1998/11/27 19:52:05 vadim Exp $
+ * $Id: be-dumpdata.c,v 1.19 1998/12/14 06:50:23 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
PortalEntry *
be_newportal(void)
{
- PortalEntry *entry;
- char buf[PortalNameLength];
+ PortalEntry *entry;
+ char buf[PortalNameLength];
/* ----------------
* generate a new name
if (be_portalcnt == 0)
be_portaloid = newoid();
be_portalcnt++;
- sprintf(buf, "be_%d_%d", be_portaloid, be_portalcnt);
+ snprintf(buf, PortalNameLength, "be_%d_%d", be_portaloid, be_portalcnt);
/* ----------------
* initialize the new portal entry and keep track
/*-------------------------------------------------------------------------
*
* 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
*
* Dec 17, 1997 - Todd A. Brandys
* Orignal Version Completed.
*
+ * $Id: crypt.c,v 1.13 1998/12/14 06:50:24 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
crypt_getpwdfilename()
{
- static char *pfnam = NULL;
+ static char *pfnam = NULL;
+ int bufsize;
- if (!pfnam)
- {
- pfnam = (char *) malloc(strlen(DataDir) + strlen(CRYPT_PWD_FILE) + 2);
- sprintf(pfnam, "%s/%s", DataDir, CRYPT_PWD_FILE);
- }
+ bufsize = strlen(DataDir) + strlen(CRYPT_PWD_FILE) + 2;
+ pfnam = (char *) palloc(bufsize);
+ snprintf(pfnam, bufsize, "%s/%s", DataDir, CRYPT_PWD_FILE);
return pfnam;
}
crypt_getpwdreloadfilename()
{
- static char *rpfnam = NULL;
+ static char *rpfnam = NULL;
+ char *pwdfilename;
+ int bufsize;
- 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();
+ bufsize = strlen(pwdfilename) + strlen(CRYPT_PWD_RELOAD_SUFX) + 1;
+ rpfnam = (char *) palloc(bufsize);
+ snprintf(rpfnam, bufsize, "%s%s", pwdfilename, CRYPT_PWD_RELOAD_SUFX);
return rpfnam;
}
{ /* 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);
+ {
+ pfree((void *) pwd_cache[pwd_cache_count]);
+ }
+ pfree((void *) pwd_cache);
pwd_cache = NULL;
pwd_cache_count = 0;
}
buffer[result] = '\0';
pwd_cache = (char **) realloc((void *) pwd_cache, sizeof(char *) * (pwd_cache_count + 1));
- pwd_cache[pwd_cache_count++] = strdup(buffer);
+ pwd_cache[pwd_cache_count++] = pstrdup(buffer);
}
fclose(pwd_file);
* store a copy of user password to return
*/
count = strcspn(parse, CRYPT_PWD_FILE_SEPSTR);
- *pwd = (char *) malloc(count + 1);
+ *pwd = (char *) palloc(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);
+ *valdate = (char *) palloc(count + 1);
strncpy(*valdate, parse, count);
(*valdate)[count] = '\0';
parse += (count + 1);
crypt_getloginfo(const char *user, char **passwd, char **valuntil)
{
- char *pwd;
- char *valdate;
- void *fakeout;
+ char *pwd,
+ *valdate;
+ void *fakeout;
*passwd = NULL;
*valuntil = NULL;
if (pwd_cache)
{
- char **pwd_entry;
- char user_search[NAMEDATALEN + 2];
+ char **pwd_entry;
+ char user_search[NAMEDATALEN + 2];
- sprintf(user_search, "%s\t", user);
+ snprintf(user_search, NAMEDATALEN + 2, "%s\t", user);
fakeout = (void *) &user_search;
if ((pwd_entry = (char **) bsearch((void *) &fakeout, (void *) pwd_cache, pwd_cache_count, sizeof(char *), compar_user)))
{
/*-------------------------------------------------------------------------*/
-#if 0
-MsgType
-crypt_salt(const char *user)
-{
-
- char *passwd;
- char *valuntil;
-
- 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;
- }
-
- free((void *) passwd);
- if (valuntil)
- free((void *) valuntil);
- return STARTUP_SALT_MSG;
-}
-
-#endif
-
-/*-------------------------------------------------------------------------*/
-
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,
+ *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)
- free((void *) passwd);
+ {
+ pfree((void *) passwd);
+ }
if (valuntil)
- free((void *) valuntil);
+ {
+ pfree((void *) valuntil);
+ }
return STATUS_ERROR;
}
* 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;
+ }
}
- free((void *) passwd);
+ pfree((void *) passwd);
if (valuntil)
- free((void *) valuntil);
+ {
+ pfree((void *) valuntil);
+ }
return retval;
}
* wherein you authenticate a user by seeing what IP address the system
* says he comes from and possibly using ident).
*
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.36 1998/10/02 16:18:20 momjian Exp $
+ * $Id: hba.c,v 1.37 1998/12/14 06:50:25 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
return;
syntax:
- sprintf(PQerrormsg,
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
"process_hba_record: invalid syntax in pg_hba.conf file\n");
fputs(PQerrormsg, stderr);
find_hba_entry(SockAddr *raddr, const char *user, const char *database,
bool *host_ok_p, UserAuth *userauth_p, char *auth_arg)
{
-/*--------------------------------------------------------------------------
- Read the config file and find an entry that allows connection from
- host "*raddr" to database "database". If found, return *host_ok_p == true
- and *userauth_p and *auth_arg representing the contents of that entry.
-
- When a record has invalid syntax, we either ignore it or reject the
- connection (depending on where it's invalid). No message or anything.
- We need to fix that some day.
-
- If we don't find or can't access the config file, we issue an error
- message and deny the connection.
-
- 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
- follow directions and just installed his old hba file in the new database
- system.
-
----------------------------------------------------------------------------*/
- int fd;
-
- FILE *file; /* The config file we have to read */
+/*
+ * Read the config file and find an entry that allows connection from
+ * host "*raddr" to database "database". If found, return *host_ok_p == true
+ * and *userauth_p and *auth_arg representing the contents of that entry.
+ *
+ * When a record has invalid syntax, we either ignore it or reject the
+ * connection (depending on where it's invalid). No message or anything.
+ * We need to fix that some day.
+ *
+ * If we don't find or can't access the config file, we issue an error
+ * message and deny the connection.
+ *
+ * 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
+ * follow directions and just installed his old hba file in the new database
+ * system.
+ *
+ */
- char *old_conf_file;
+ int fd,
+ bufsize;
+ FILE *file; /* The config file we have to read */
+ char *old_conf_file;
/* The name of old config file that better not exist. */
/* put together the full pathname to the old config file */
- old_conf_file = (char *) palloc((strlen(DataDir) +
- strlen(OLD_CONF_FILE) + 2) * sizeof(char));
- sprintf(old_conf_file, "%s/%s", DataDir, OLD_CONF_FILE);
+ bufsize = (strlen(DataDir) + strlen(OLD_CONF_FILE) + 2) * sizeof(char);
+ old_conf_file = (char *) palloc(bufsize);
+ snprintf(old_conf_file, bufsize, "%s/%s", DataDir, OLD_CONF_FILE);
if ((fd = open(old_conf_file, O_RDONLY, 0)) != -1)
{
/* Old config file exists. Tell this guy he needs to upgrade. */
close(fd);
- sprintf(PQerrormsg,
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
"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 "
}
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 */
- conf_file = (char *) palloc((strlen(DataDir) +
- strlen(CONF_FILE) + 2) * sizeof(char));
- sprintf(conf_file, "%s/%s", DataDir, CONF_FILE);
+ bufsize = (strlen(DataDir) + strlen(CONF_FILE) + 2) * sizeof(char);
+ conf_file = (char *) palloc(bufsize);
+ snprintf(conf_file, bufsize, "%s/%s", DataDir, CONF_FILE);
file = AllocateFile(conf_file, "r");
if (file == NULL)
{
/* The open of the config file failed. */
- sprintf(PQerrormsg,
- "find_hba_entry: Host-based authentication config file "
- "does not exist or permissions are not setup correctly! "
+ 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);
fputs(PQerrormsg, stderr);
}
else
{
- process_open_config_file(file, raddr, user, database, host_ok_p, userauth_p,
- auth_arg);
+ process_open_config_file(file, raddr, user, database, host_ok_p,
+ userauth_p, auth_arg);
FreeFile(file);
}
pfree(conf_file);
*ident_failed == true (and *ident_username undefined).
----------------------------------------------------------------------------*/
- int sock_fd;
-
- /* File descriptor for socket on which we talk to Ident */
- int 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)
{
- sprintf(PQerrormsg,
- "Failed to create socket on which to talk to Ident server. "
+ 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);
}
if (rc != 0)
{
- sprintf(PQerrormsg,
- "Unable to connect to Ident server on the host which is "
+ 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",
}
else
{
- char ident_query[80];
+ char ident_query[80];
/* The query we send to the Ident server */
- sprintf(ident_query, "%d,%d\n",
+ snprintf(ident_query, 80, "%d,%d\n",
ntohs(remote_port), ntohs(local_port));
rc = send(sock_fd, ident_query, strlen(ident_query), 0);
if (rc < 0)
{
- sprintf(PQerrormsg,
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
"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. "
}
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)
{
- sprintf(PQerrormsg,
- "Unable to receive response from Ident server "
+ 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. "
+ "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);
return;
}
}
- sprintf(PQerrormsg, "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);
}
if (usermap_name[0] == '\0')
{
*checks_out_p = false;
- sprintf(PQerrormsg,
+ 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 "
+ "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 */
+ 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 */
- map_file = (char *) palloc((strlen(DataDir) +
- strlen(MAP_FILE) + 2) * sizeof(char));
- sprintf(map_file, "%s/%s", DataDir, MAP_FILE);
+ bufsize = (strlen(DataDir) + strlen(MAP_FILE) + 2) * sizeof(char);
+ map_file = (char *) palloc(bufsize);
+ snprintf(map_file, bufsize, "%s/%s", DataDir, MAP_FILE);
file = AllocateFile(map_file, "r");
if (file == NULL)
*checks_out_p = false;
- sprintf(PQerrormsg,
- "verify_against_usermap: usermap file for Ident-based "
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
+ "verify_against_usermap: usermap file for Ident-based "
"authentication "
- "does not exist or permissions are not setup correctly! "
+ "does not exist or permissions are not setup correctly! "
"Unable to open file \"%s\".\n",
map_file);
fputs(PQerrormsg, stderr);
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];
- char c,
- eof = false;
- char *map_file;
- int key = 0,
- i;
- struct CharsetItem *ChArray[MAX_CHARSETS];
- int ChIndex = 0;
+ HostCharset[MAX_TOKEN],
+ c,
+ eof = false,
+ *map_file;
+ int key = 0,
+ ChIndex = 0,
+ i,
+ bufsize;
+
+ struct CharsetItem *ChArray[MAX_CHARSETS];
*TableName = '\0';
- map_file = (char *) malloc((strlen(DataDir) +
- strlen(CHARSET_FILE) + 2) * sizeof(char));
- sprintf(map_file, "%s/%s", DataDir, CHARSET_FILE);
+ bufsize = (strlen(DataDir) + strlen(CHARSET_FILE) + 2) * sizeof(char);
+ map_file = (char *) palloc(bufsize);
+ snprintf(map_file, bufsize, "%s/%s", DataDir, CHARSET_FILE);
file = fopen(map_file, "r");
if (file == NULL)
+ {
return;
+ }
while (!eof)
{
c = getc(file);
next_token(file, buf, sizeof(buf));
if (buf[0] != '\0')
{
- ChArray[ChIndex] = (struct CharsetItem *) malloc(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);
}
}
fclose(file);
- free(map_file);
+ pfree(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]);
+ pfree((struct CharsetItem *) ChArray[i]);
}
}
+/*
+ * Copyright (c) 1994, Regents of the University of California
+ *
+ * $Id: password.c,v 1.19 1998/12/14 06:50:26 scrappy Exp $
+ *
+ */
+
#include <postgres.h>
#include <miscadmin.h>
#include <libpq/password.h>
pw_file = AllocateFile(pw_file_fullname, "r");
if (!pw_file)
{
- sprintf(PQerrormsg,
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
"verify_password: couldn't open password file '%s'\n",
pw_file_fullname);
fputs(PQerrormsg, stderr);
return STATUS_OK;
}
- sprintf(PQerrormsg,
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
"verify_password: password mismatch for '%s'.\n",
user);
fputs(PQerrormsg, stderr);
}
}
- sprintf(PQerrormsg,
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
"verify_password: user '%s' not found in password file.\n",
user);
fputs(PQerrormsg, stderr);
*
* Copyright (c) 1994, Regents of the University of California
*
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portal.c,v 1.17 1998/09/01 04:28:50 momjian Exp $
+ * $Id: portal.c,v 1.18 1998/12/14 06:50:26 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
{
if (value < min || value >= max)
{
- sprintf(PQerrormsg, "FATAL: %s, %d is not in range [%d,%d)\n",
- msg, value, min, max);
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
+ "FATAL: %s, %d is not in range [%d,%d)\n", msg, value, min, max);
pqdebug("%s", PQerrormsg);
fputs(PQerrormsg, stderr);
return 0;
{
if (!ptr)
{
- sprintf(PQerrormsg, "FATAL: %s\n", msg);
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH, "FATAL: %s\n", msg);
pqdebug("%s", PQerrormsg);
fputs(PQerrormsg, stderr);
return 0;
*
* Copyright (c) 1994, Regents of the University of California
*
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.58 1998/11/29 01:47:42 tgl Exp $
+ * $Id: pqcomm.c,v 1.59 1998/12/14 06:50:27 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
* declarations
* ----------------
*/
-FILE *Pfout,
- *Pfin;
-FILE *Pfdebug; /* debugging libpq */
+FILE *Pfout,
+ *Pfin,
+ *Pfdebug; /* debugging libpq */
/* --------------------------------
* pq_init - open portal file descriptors
if (status)
{
- sprintf(PQerrormsg,
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
"FATAL: pq_getint failed: errno=%d\n", errno);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
if (pqPutString(s, Pfout))
#endif
{
- sprintf(PQerrormsg,
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
"FATAL: pq_putstr: fputs() failed: errno=%d\n", errno);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
{
if (pqPutNBytes(s, n, Pfout))
{
- sprintf(PQerrormsg,
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
"FATAL: pq_putnchar: fputc() failed: errno=%d\n",
errno);
fputs(PQerrormsg, stderr);
if (status)
{
- sprintf(PQerrormsg,
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
"FATAL: pq_putint failed: errno=%d\n", errno);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
}
if (hs->h_addrtype != AF_INET)
{
- sprintf(PQerrormsg,
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
"FATAL: pq_getinaddr: %s not on Internet\n",
host);
fputs(PQerrormsg, stderr);
return pq_getinaddr(sin, host, atoi(serv));
if (!(ss = getservbyname(serv, NULL)))
{
- sprintf(PQerrormsg,
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
"FATAL: pq_getinserv: unknown service: %s\n",
serv);
fputs(PQerrormsg, stderr);
if ((fd = socket(family, SOCK_STREAM, 0)) < 0)
{
- sprintf(PQerrormsg,
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
"FATAL: StreamServerPort: socket() failed: errno=%d\n",
errno);
fputs(PQerrormsg, stderr);
if ((setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &one,
sizeof(one))) == -1)
{
- sprintf(PQerrormsg,
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
"FATAL: StreamServerPort: setsockopt (SO_REUSEADDR) failed: errno=%d\n",
errno);
fputs(PQerrormsg, stderr);
err = bind(fd, &saddr.sa, len);
if (err < 0)
{
- sprintf(PQerrormsg,
- "FATAL: StreamServerPort: bind() failed: errno=%d\n",
- errno);
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
+ "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)
- sprintf(PQerrormsg + strlen(PQerrormsg),
- "\tIf not, remove socket node (%s) and retry.\n",
- sock_path);
+ {
+ snprintf(PQerrormsg + strlen(PQerrormsg), ERROR_MSG_LENGTH,
+ "\tIf not, remove socket node (%s) and retry.\n", sock_path);
+ }
else
+ {
strcat(PQerrormsg, "\tIf not, wait a few seconds and retry.\n");
+ }
fputs(PQerrormsg, stderr);
return STATUS_ERROR;
}
{
if (!(hp = gethostbyname(hostName)) || hp->h_addrtype != AF_INET)
{
- sprintf(PQerrormsg,
- "FATAL: StreamOpen: unknown hostname: %s\n",
- hostName);
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
+ "FATAL: StreamOpen: unknown hostname: %s\n", hostName);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
return STATUS_ERROR;
/* connect to the server */
if ((port->sock = socket(port->raddr.sa.sa_family, SOCK_STREAM, 0)) < 0)
{
- sprintf(PQerrormsg,
- "FATAL: StreamOpen: socket() failed: errno=%d\n",
- errno);
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
+ "FATAL: StreamOpen: socket() failed: errno=%d\n", errno);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
return STATUS_ERROR;
err = connect(port->sock, &port->raddr.sa, len);
if (err < 0)
{
- sprintf(PQerrormsg,
- "FATAL: StreamOpen: connect() failed: errno=%d\n",
- errno);
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
+ "FATAL: StreamOpen: connect() failed: errno=%d\n", errno);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
return STATUS_ERROR;
/* fill in the client address */
if (getsockname(port->sock, &port->laddr.sa, &len) < 0)
{
- sprintf(PQerrormsg,
- "FATAL: StreamOpen: getsockname() failed: errno=%d\n",
- errno);
+ snprintf(PQerrormsg, ERROR_MSG_LENGTH,
+ "FATAL: StreamOpen: getsockname() failed: errno=%d\n", errno);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
return STATUS_ERROR;
*
* Copyright (c) 1994, Regents of the University of California
*
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/util.c,v 1.5 1997/09/08 02:23:21 momjian Exp $
+ * $Id: util.c,v 1.6 1998/12/14 06:50:27 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
*
* Copyright (c) 1994, Regents of the University of California
*
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.50 1998/12/14 00:01:47 thomas Exp $
+ * $Id: outfuncs.c,v 1.51 1998/12/14 06:50:28 scrappy Exp $
*
* NOTES
* Every (plan) node in POSTGRES has an associated "out" routine which
*
* Copyright (c) 1994, Regents of the University of California
*
- *
- * IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.90 1998/12/04 15:34:28 thomas Exp $
+ * $Id: analyze.c,v 1.91 1998/12/14 06:50:32 scrappy Exp $
*
*-------------------------------------------------------------------------
*/