Commit da72b903 authored by Marc G. Fournier's avatar Marc G. Fournier

Major code cleanup following the pg_password insertion...

	...malloc/free -> palloc/pfree
	...fopen/fclose -> AllocateFile/FreeFile
parent 405740ac
...@@ -176,7 +176,6 @@ extern void AlterUser(AlterUserStmt *stmt) { ...@@ -176,7 +176,6 @@ extern void AlterUser(AlterUserStmt *stmt) {
bool exists = false, bool exists = false,
n, n,
inblock; inblock;
int max_id = -1;
if (!(inblock = IsTransactionBlock())) if (!(inblock = IsTransactionBlock()))
BeginTransactionBlock(); BeginTransactionBlock();
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.19 1997/12/04 00:26:50 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.20 1997/12/09 03:10:31 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -397,10 +397,10 @@ pg_krb5_recvauth(int sock, ...@@ -397,10 +397,10 @@ pg_krb5_recvauth(int sock,
username, kusername); username, kusername);
fputs(PQerrormsg, stderr); fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg); pqdebug("%s", PQerrormsg);
free(kusername); pfree(kusername);
return (STATUS_ERROR); return (STATUS_ERROR);
} }
free(kusername); pfree(kusername);
return (STATUS_OK); return (STATUS_OK);
} }
......
...@@ -16,9 +16,11 @@ ...@@ -16,9 +16,11 @@
#include <crypt.h> #include <crypt.h>
#endif #endif
#include <postgres.h> #include "postgres.h"
#include <libpq/crypt.h> #include "libpq/crypt.h"
#include <utils/nabstime.h> #include "utils/nabstime.h"
#include "utils/palloc.h"
#include "storage/fd.h"
char* crypt_getpwdfilename() { char* crypt_getpwdfilename() {
...@@ -32,7 +34,7 @@ char* crypt_getpwdfilename() { ...@@ -32,7 +34,7 @@ char* crypt_getpwdfilename() {
elog(FATAL, "crypt.c: PGDATA is not defined"); elog(FATAL, "crypt.c: PGDATA is not defined");
exit(-1); exit(-1);
} }
filename = (char*)malloc(strlen(env) + strlen(CRYPT_PWD_FILE) + 2); filename = (char*)palloc(strlen(env) + strlen(CRYPT_PWD_FILE) + 2);
sprintf(filename, "%s/%s", env, CRYPT_PWD_FILE); sprintf(filename, "%s/%s", env, CRYPT_PWD_FILE);
} }
...@@ -47,7 +49,7 @@ FILE* crypt_openpwdfile() { ...@@ -47,7 +49,7 @@ FILE* crypt_openpwdfile() {
char* filename; char* filename;
filename = crypt_getpwdfilename(); filename = crypt_getpwdfilename();
return (fopen(filename, "r")); return (AllocateFile(filename, "r"));
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -66,7 +68,7 @@ void crypt_parsepwdfile(FILE* datafile, char** login, char** pwd, char** valdate ...@@ -66,7 +68,7 @@ void crypt_parsepwdfile(FILE* datafile, char** login, char** pwd, char** valdate
/* store a copy of user login to return /* store a copy of user login to return
*/ */
count = strcspn(parse, "#"); count = strcspn(parse, "#");
*login = (char*)malloc(count + 1); *login = (char*)palloc(count + 1);
strncpy(*login, parse, count); strncpy(*login, parse, count);
(*login)[count] = '\0'; (*login)[count] = '\0';
parse += (count + 1); parse += (count + 1);
...@@ -79,7 +81,7 @@ void crypt_parsepwdfile(FILE* datafile, char** login, char** pwd, char** valdate ...@@ -79,7 +81,7 @@ void crypt_parsepwdfile(FILE* datafile, char** login, char** pwd, char** valdate
/* store a copy of user password to return /* store a copy of user password to return
*/ */
count = strcspn(parse, "#"); count = strcspn(parse, "#");
*pwd = (char*)malloc(count + 1); *pwd = (char*)palloc(count + 1);
strncpy(*pwd, parse, count); strncpy(*pwd, parse, count);
(*pwd)[count] = '\0'; (*pwd)[count] = '\0';
parse += (count + 1); parse += (count + 1);
...@@ -87,7 +89,7 @@ void crypt_parsepwdfile(FILE* datafile, char** login, char** pwd, char** valdate ...@@ -87,7 +89,7 @@ void crypt_parsepwdfile(FILE* datafile, char** login, char** pwd, char** valdate
/* store a copy of date login becomes invalid /* store a copy of date login becomes invalid
*/ */
count = strcspn(parse, "#"); count = strcspn(parse, "#");
*valdate = (char*)malloc(count + 1); *valdate = (char*)palloc(count + 1);
strncpy(*valdate, parse, count); strncpy(*valdate, parse, count);
(*valdate)[count] = '\0'; (*valdate)[count] = '\0';
parse += (count + 1); parse += (count + 1);
...@@ -112,15 +114,15 @@ void crypt_getloginfo(const char* user, char** passwd, char** valuntil) { ...@@ -112,15 +114,15 @@ void crypt_getloginfo(const char* user, char** passwd, char** valuntil) {
while (!feof(datafile)) { while (!feof(datafile)) {
crypt_parsepwdfile(datafile, &login, &pwd, &valdate); crypt_parsepwdfile(datafile, &login, &pwd, &valdate);
if (!strcmp(login, user)) { if (!strcmp(login, user)) {
free((void*)login); pfree((void*)login);
*passwd = pwd; *passwd = pwd;
*valuntil = valdate; *valuntil = valdate;
fclose(datafile); fclose(datafile);
return; return;
} }
free((void*)login); pfree((void*)login);
free((void*)pwd); pfree((void*)pwd);
free((void*)valdate); pfree((void*)valdate);
} }
fclose(datafile); fclose(datafile);
} }
...@@ -135,13 +137,13 @@ MsgType crypt_salt(const char* user) { ...@@ -135,13 +137,13 @@ MsgType crypt_salt(const char* user) {
crypt_getloginfo(user, &passwd, &valuntil); crypt_getloginfo(user, &passwd, &valuntil);
if (passwd == NULL || *passwd == '\0') { if (passwd == NULL || *passwd == '\0') {
if (passwd) free((void*)passwd); if (passwd) pfree((void*)passwd);
if (valuntil) free((void*)valuntil); if (valuntil) pfree((void*)valuntil);
return STARTUP_UNSALT_MSG; return STARTUP_UNSALT_MSG;
} }
free((void*)passwd); pfree((void*)passwd);
if (valuntil) free((void*)valuntil); if (valuntil) pfree((void*)valuntil);
return STARTUP_SALT_MSG; return STARTUP_SALT_MSG;
} }
...@@ -159,8 +161,8 @@ int crypt_verify(Port* port, const char* user, const char* pgpass) { ...@@ -159,8 +161,8 @@ int crypt_verify(Port* port, const char* user, const char* pgpass) {
crypt_getloginfo(user, &passwd, &valuntil); crypt_getloginfo(user, &passwd, &valuntil);
if (passwd == NULL || *passwd == '\0') { if (passwd == NULL || *passwd == '\0') {
if (passwd) free((void*)passwd); if (passwd) pfree((void*)passwd);
if (valuntil) free((void*)valuntil); if (valuntil) pfree((void*)valuntil);
return STATUS_ERROR; return STATUS_ERROR;
} }
...@@ -179,8 +181,8 @@ int crypt_verify(Port* port, const char* user, const char* pgpass) { ...@@ -179,8 +181,8 @@ int crypt_verify(Port* port, const char* user, const char* pgpass) {
retval = STATUS_OK; retval = STATUS_OK;
} }
free((void*)passwd); pfree((void*)passwd);
if (valuntil) free((void*)valuntil); if (valuntil) pfree((void*)valuntil);
return retval; return retval;
} }
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.24 1997/11/10 05:15:52 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.25 1997/12/09 03:10:38 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -404,7 +404,7 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr, ...@@ -404,7 +404,7 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr,
/* put together the full pathname to the old config file */ /* put together the full pathname to the old config file */
old_conf_file = (char *) malloc((strlen(DataDir) + old_conf_file = (char *) palloc((strlen(DataDir) +
strlen(OLD_CONF_FILE) + 2) * sizeof(char)); strlen(OLD_CONF_FILE) + 2) * sizeof(char));
sprintf(old_conf_file, "%s/%s", DataDir, OLD_CONF_FILE); sprintf(old_conf_file, "%s/%s", DataDir, OLD_CONF_FILE);
...@@ -427,7 +427,7 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr, ...@@ -427,7 +427,7 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr,
* read */ * read */
/* put together the full pathname to the config file */ /* put together the full pathname to the config file */
conf_file = (char *) malloc((strlen(DataDir) + conf_file = (char *) palloc((strlen(DataDir) +
strlen(CONF_FILE) + 2) * sizeof(char)); strlen(CONF_FILE) + 2) * sizeof(char));
sprintf(conf_file, "%s/%s", DataDir, CONF_FILE); sprintf(conf_file, "%s/%s", DataDir, CONF_FILE);
...@@ -452,9 +452,9 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr, ...@@ -452,9 +452,9 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr,
usermap_name, find_password_entries); usermap_name, find_password_entries);
FreeFile(file); FreeFile(file);
} }
free(conf_file); pfree(conf_file);
} }
free(old_conf_file); pfree(old_conf_file);
return; return;
} }
...@@ -799,7 +799,7 @@ verify_against_usermap(const char DataDir[], ...@@ -799,7 +799,7 @@ verify_against_usermap(const char DataDir[],
* read */ * read */
/* put together the full pathname to the map file */ /* put together the full pathname to the map file */
map_file = (char *) malloc((strlen(DataDir) + map_file = (char *) palloc((strlen(DataDir) +
strlen(MAP_FILE) + 2) * sizeof(char)); strlen(MAP_FILE) + 2) * sizeof(char));
sprintf(map_file, "%s/%s", DataDir, MAP_FILE); sprintf(map_file, "%s/%s", DataDir, MAP_FILE);
...@@ -826,7 +826,7 @@ verify_against_usermap(const char DataDir[], ...@@ -826,7 +826,7 @@ verify_against_usermap(const char DataDir[],
checks_out_p); checks_out_p);
FreeFile(file); FreeFile(file);
} }
free(map_file); pfree(map_file);
} }
......
...@@ -56,7 +56,7 @@ verify_password(char *user, char *password, Port *port, ...@@ -56,7 +56,7 @@ verify_password(char *user, char *password, Port *port,
return STATUS_ERROR; return STATUS_ERROR;
} }
pw_file_fullname = (char *) malloc(strlen(DataDir) + strlen(pw_file_name) + 2); pw_file_fullname = (char *) palloc(strlen(DataDir) + strlen(pw_file_name) + 2);
strcpy(pw_file_fullname, DataDir); strcpy(pw_file_fullname, DataDir);
strcat(pw_file_fullname, "/"); strcat(pw_file_fullname, "/");
strcat(pw_file_fullname, pw_file_name); strcat(pw_file_fullname, pw_file_name);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portal.c,v 1.11 1997/11/10 05:15:54 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portal.c,v 1.12 1997/12/09 03:10:43 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -612,7 +612,7 @@ PQgetAttr(PortalBuffer *portal, ...@@ -612,7 +612,7 @@ PQgetAttr(PortalBuffer *portal,
if (tbp) if (tbp)
{ {
len = tbp->lengths[tuple_offset][field_number]; len = tbp->lengths[tuple_offset][field_number];
result = malloc(len + 1); result = palloc(len + 1);
memcpy(result, memcpy(result,
tbp->values[tuple_offset][field_number], tbp->values[tuple_offset][field_number],
len); len);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portalbuf.c,v 1.8 1997/10/25 01:09:23 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portalbuf.c,v 1.9 1997/12/09 03:10:45 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
PortalEntry **portals = (PortalEntry **) NULL; PortalEntry **portals = (PortalEntry **) NULL;
size_t portals_array_size = 0; size_t portals_array_size = 0;
/* portals array memory is malloc'd instead of using MemoryContexts */ /* portals array memory is palloc'd instead of using MemoryContexts */
/* since it will be used by both front and backend programs*/ /* since it will be used by both front and backend programs*/
/* GlobalMemory portals_mmcxt = (GlobalMemory) NULL; */ /* GlobalMemory portals_mmcxt = (GlobalMemory) NULL; */
...@@ -83,7 +83,7 @@ portals_realloc(size_t size) ...@@ -83,7 +83,7 @@ portals_realloc(size_t size)
newp = (PortalEntry **) realloc(portals, newp = (PortalEntry **) realloc(portals,
portals_array_size * sizeof(PortalEntry *)); portals_array_size * sizeof(PortalEntry *));
else else
newp = (PortalEntry **) malloc(portals_array_size * sizeof(PortalEntry *)); newp = (PortalEntry **) palloc(portals_array_size * sizeof(PortalEntry *));
if (newp) if (newp)
portals = newp; portals = newp;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.11 1997/11/17 16:18:07 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.12 1997/12/09 03:10:51 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -253,7 +253,7 @@ StartupInfo2PacketBuf(StartupInfo* s) ...@@ -253,7 +253,7 @@ StartupInfo2PacketBuf(StartupInfo* s)
PacketBuf* res; PacketBuf* res;
char* tmp; char* tmp;
res = (PacketBuf*)malloc(sizeof(PacketBuf)); res = (PacketBuf*)palloc(sizeof(PacketBuf));
res->len = htonl(sizeof(PacketBuf)); res->len = htonl(sizeof(PacketBuf));
res->data[0] = '\0'; res->data[0] = '\0';
...@@ -285,7 +285,7 @@ PacketBuf2StartupInfo(PacketBuf* p) ...@@ -285,7 +285,7 @@ PacketBuf2StartupInfo(PacketBuf* p)
StartupInfo* res; StartupInfo* res;
char* tmp; char* tmp;
res = (StartupInfo*)malloc(sizeof(StartupInfo)); res = (StartupInfo*)palloc(sizeof(StartupInfo));
res->database[0]='\0'; res->database[0]='\0';
res->user[0]='\0'; res->user[0]='\0';
......
/* A lexical scanner generated by flex */ /* A lexical scanner generated by flex */
/* Scanner skeleton version: /* Scanner skeleton version:
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.4 1997/11/30 23:05:39 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.5 1997/12/09 03:11:00 scrappy Exp $
*/ */
#define FLEX_SCANNER #define FLEX_SCANNER
...@@ -539,7 +539,7 @@ char *yytext; ...@@ -539,7 +539,7 @@ char *yytext;
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.4 1997/11/30 23:05:39 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.5 1997/12/09 03:11:00 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1212,7 +1212,7 @@ YY_RULE_SETUP ...@@ -1212,7 +1212,7 @@ YY_RULE_SETUP
int i; int i;
ScanKeyword *keyword; ScanKeyword *keyword;
for(i = strlen(yytext); i >= 0; i--) for(i = 0; yytext[i]; i++)
if (isupper(yytext[i])) if (isupper(yytext[i]))
yytext[i] = tolower(yytext[i]); yytext[i] = tolower(yytext[i]);
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.64 1997/12/07 20:57:45 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.65 1997/12/09 03:11:08 scrappy Exp $
* *
* NOTES * NOTES
* *
...@@ -88,6 +88,7 @@ ...@@ -88,6 +88,7 @@
#include "storage/proc.h" #include "storage/proc.h"
#include "utils/elog.h" #include "utils/elog.h"
#include "port-protos.h" /* For gethostname() */ #include "port-protos.h" /* For gethostname() */
#include "storage/fd.h"
#if defined(DBX_VERSION) #if defined(DBX_VERSION)
#define FORK() (0) #define FORK() (0)
...@@ -228,7 +229,7 @@ checkDataDir(const char *DataDir, bool *DataDirOK) ...@@ -228,7 +229,7 @@ checkDataDir(const char *DataDir, bool *DataDirOK)
sprintf(path, "%s%cbase%ctemplate1%cpg_class", sprintf(path, "%s%cbase%ctemplate1%cpg_class",
DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR); DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR);
fp = fopen(path, "r"); fp = AllocateFile(path, "r");
if (fp == NULL) if (fp == NULL)
{ {
fprintf(stderr, "%s does not find the database system. " fprintf(stderr, "%s does not find the database system. "
...@@ -244,7 +245,7 @@ checkDataDir(const char *DataDir, bool *DataDirOK) ...@@ -244,7 +245,7 @@ checkDataDir(const char *DataDir, bool *DataDirOK)
/* reason ValidatePgVersion failed. NULL if didn't */ /* reason ValidatePgVersion failed. NULL if didn't */
fclose(fp); FreeFile(fp);
ValidatePgVersion(DataDir, &reason); ValidatePgVersion(DataDir, &reason);
if (reason) if (reason)
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/initlocation,v 1.1 1997/11/07 06:21:38 thomas Exp $ # $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/initlocation,v 1.2 1997/12/09 03:11:16 scrappy Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -35,11 +35,11 @@ do ...@@ -35,11 +35,11 @@ do
shift shift
done done
if [ ! -z "$badparm" ]; then if [ -n "$badparm" ]; then
echo "$CMDNAME: Unrecognized parameter '$badparm'" echo "$CMDNAME: Unrecognized parameter '$badparm'"
fi fi
if [ ! -z "$usage" ]; then if [ -n "$usage" ]; then
echo "Usage: $CMDNAME [-u SUPERUSER] DATADIR" echo "Usage: $CMDNAME [-u SUPERUSER] DATADIR"
exit 1 exit 1
fi fi
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_user.h,v 1.6 1997/12/04 00:27:54 scrappy Exp $ * $Id: pg_user.h,v 1.7 1997/12/09 03:11:25 scrappy Exp $
* *
* NOTES * NOTES
* the genbki.sh script reads this file and generates .bki * the genbki.sh script reads this file and generates .bki
...@@ -65,7 +65,7 @@ typedef FormData_pg_user *Form_pg_user; ...@@ -65,7 +65,7 @@ typedef FormData_pg_user *Form_pg_user;
* initial contents of pg_user * initial contents of pg_user
* ---------------- * ----------------
*/ */
DATA(insert OID = 0 ( postgres PGUID t t t t postgres 2116994400 )); DATA(insert OID = 0 ( postgres PGUID t t t t "" 2116994400 ));
BKI_BEGIN BKI_BEGIN
#ifdef ALLOW_PG_GROUP #ifdef ALLOW_PG_GROUP
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment