Skip to content
Snippets Groups Projects
Commit 4c8d2f7f authored by Tom Lane's avatar Tom Lane
Browse files

Clean up callers of AllocateFile and BasicOpenFile to ensure that

a reasonable error message (including the kernel errno message)
is reported on any file open failure.
parent 5ba9d8c2
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.66 2000/08/03 16:34:01 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.67 2000/08/27 21:50:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -72,7 +72,7 @@ write_password_file(Relation rel)
fp = AllocateFile(tempname, "w");
umask(oumask);
if (fp == NULL)
elog(ERROR, "%s: %m", tempname);
elog(ERROR, "write_password_file: unable to write %s: %m", tempname);
/* read table */
scan = heap_beginscan(rel, false, SnapshotSelf, 0, NULL);
......@@ -156,7 +156,7 @@ write_password_file(Relation rel)
filename = crypt_getpwdreloadfilename();
flagfd = BasicOpenFile(filename, O_WRONLY | O_CREAT, 0600);
if (flagfd < 0)
elog(NOTICE, "%s: %m", filename);
elog(NOTICE, "write_password_file: unable to write %s: %m", filename);
else
close(flagfd);
pfree((void *) filename);
......
......@@ -9,11 +9,12 @@
* Dec 17, 1997 - Todd A. Brandys
* Orignal Version Completed.
*
* $Id: crypt.c,v 1.28 2000/07/12 22:58:59 petere Exp $
* $Id: crypt.c,v 1.29 2000/08/27 21:50:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include <errno.h>
#include <unistd.h>
#include "postgres.h"
......@@ -32,11 +33,10 @@ int pwd_cache_count = 0;
/*-------------------------------------------------------------------------*/
char *
crypt_getpwdfilename()
crypt_getpwdfilename(void)
{
static char *pfnam = NULL;
int bufsize;
char *pfnam;
bufsize = strlen(DataDir) + 8 + strlen(CRYPT_PWD_FILE) + 1;
pfnam = (char *) palloc(bufsize);
......@@ -48,12 +48,11 @@ crypt_getpwdfilename()
/*-------------------------------------------------------------------------*/
char *
crypt_getpwdreloadfilename()
crypt_getpwdreloadfilename(void)
{
static char *rpfnam = NULL;
char *pwdfilename;
int bufsize;
char *rpfnam;
pwdfilename = crypt_getpwdfilename();
bufsize = strlen(pwdfilename) + strlen(CRYPT_PWD_RELOAD_SUFX) + 1;
......@@ -65,9 +64,8 @@ crypt_getpwdreloadfilename()
/*-------------------------------------------------------------------------*/
static
FILE *
crypt_openpwdfile()
static FILE *
crypt_openpwdfile(void)
{
char *filename;
FILE *pwdfile;
......@@ -75,13 +73,16 @@ crypt_openpwdfile()
filename = crypt_getpwdfilename();
pwdfile = AllocateFile(filename, PG_BINARY_R);
if (pwdfile == NULL)
fprintf(stderr, "Couldn't read %s: %s\n",
filename, strerror(errno));
return pwdfile;
}
/*-------------------------------------------------------------------------*/
static
int
static int
compar_user(const void *user_a, const void *user_b)
{
......@@ -115,9 +116,8 @@ compar_user(const void *user_a, const void *user_b)
/*-------------------------------------------------------------------------*/
static
void
crypt_loadpwdfile()
static void
crypt_loadpwdfile(void)
{
char *filename;
......@@ -176,8 +176,7 @@ crypt_loadpwdfile()
/*-------------------------------------------------------------------------*/
static
void
static void
crypt_parsepwdentry(char *buffer, char **pwd, char **valdate)
{
......@@ -212,11 +211,9 @@ crypt_parsepwdentry(char *buffer, char **pwd, char **valdate)
/*-------------------------------------------------------------------------*/
static
int
static int
crypt_getloginfo(const char *user, char **passwd, char **valuntil)
{
char *pwd,
*valdate;
void *fakeout;
......
......@@ -5,7 +5,7 @@
* wherein you authenticate a user by seeing what IP address the system
* says he comes from and possibly using ident).
*
* $Id: hba.c,v 1.53 2000/07/08 03:04:39 tgl Exp $
* $Id: hba.c,v 1.54 2000/08/27 21:50:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -427,10 +427,8 @@ find_hba_entry(hbaPort *port, bool *hba_ok_p)
/* The open of the config file failed. */
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"find_hba_entry: Host-based authentication config file "
"does not exist or permissions are not setup correctly! "
"Unable to open file \"%s\".\n",
conf_file);
"find_hba_entry: Unable to open authentication config file \"%s\": %s\n",
conf_file, strerror(errno));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
}
......@@ -812,16 +810,13 @@ verify_against_usermap(const char *pguser,
{
/* The open of the map file failed. */
*checks_out_p = false;
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"verify_against_usermap: usermap file for Ident-based "
"authentication "
"does not exist or permissions are not setup correctly! "
"Unable to open file \"%s\".\n",
map_file);
"verify_against_usermap: Unable to open usermap file \"%s\": %s\n",
map_file, strerror(errno));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
*checks_out_p = false;
}
else
{
......@@ -981,7 +976,10 @@ GetCharSetByHost(char *TableName, int host, const char *DataDir)
snprintf(map_file, bufsize, "%s/%s", DataDir, CHARSET_FILE);
file = AllocateFile(map_file, PG_BINARY_R);
if (file == NULL)
{
/* XXX should we log a complaint? */
return;
}
while (!eof)
{
c = getc(file);
......
......@@ -2,10 +2,11 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: password.c,v 1.31 2000/07/08 03:04:40 tgl Exp $
* $Id: password.c,v 1.32 2000/08/27 21:50:18 tgl Exp $
*
*/
#include <errno.h>
#include <unistd.h>
#include "postgres.h"
......@@ -36,8 +37,8 @@ verify_password(const Port *port, const char *user, const char *password)
if (!pw_file)
{
snprintf(PQerrormsg, PQERRORMSG_LENGTH,
"verify_password: couldn't open password file '%s'\n",
pw_file_fullname);
"verify_password: Unable to open password file \"%s\": %s\n",
pw_file_fullname, strerror(errno));
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment