Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4c8d2f7

Browse files
committed
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.
1 parent5ba9d8c commit4c8d2f7

File tree

4 files changed

+34
-38
lines changed

4 files changed

+34
-38
lines changed

‎src/backend/commands/user.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.66 2000/08/03 16:34:01 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.67 2000/08/27 21:50:17 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -72,7 +72,7 @@ write_password_file(Relation rel)
7272
fp=AllocateFile(tempname,"w");
7373
umask(oumask);
7474
if (fp==NULL)
75-
elog(ERROR,"%s: %m",tempname);
75+
elog(ERROR,"write_password_file: unable to write%s: %m",tempname);
7676

7777
/* read table */
7878
scan=heap_beginscan(rel, false,SnapshotSelf,0,NULL);
@@ -156,7 +156,7 @@ write_password_file(Relation rel)
156156
filename=crypt_getpwdreloadfilename();
157157
flagfd=BasicOpenFile(filename,O_WRONLY |O_CREAT,0600);
158158
if (flagfd<0)
159-
elog(NOTICE,"%s: %m",filename);
159+
elog(NOTICE,"write_password_file: unable to write%s: %m",filename);
160160
else
161161
close(flagfd);
162162
pfree((void*)filename);

‎src/backend/libpq/crypt.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
* Dec 17, 1997 - Todd A. Brandys
1010
*Orignal Version Completed.
1111
*
12-
* $Id: crypt.c,v 1.28 2000/07/12 22:58:59 petere Exp $
12+
* $Id: crypt.c,v 1.29 2000/08/27 21:50:18 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
1616

17+
#include<errno.h>
1718
#include<unistd.h>
1819

1920
#include"postgres.h"
@@ -32,11 +33,10 @@ intpwd_cache_count = 0;
3233
/*-------------------------------------------------------------------------*/
3334

3435
char*
35-
crypt_getpwdfilename()
36+
crypt_getpwdfilename(void)
3637
{
37-
38-
staticchar*pfnam=NULL;
3938
intbufsize;
39+
char*pfnam;
4040

4141
bufsize=strlen(DataDir)+8+strlen(CRYPT_PWD_FILE)+1;
4242
pfnam= (char*)palloc(bufsize);
@@ -48,12 +48,11 @@ crypt_getpwdfilename()
4848
/*-------------------------------------------------------------------------*/
4949

5050
char*
51-
crypt_getpwdreloadfilename()
51+
crypt_getpwdreloadfilename(void)
5252
{
53-
54-
staticchar*rpfnam=NULL;
5553
char*pwdfilename;
5654
intbufsize;
55+
char*rpfnam;
5756

5857
pwdfilename=crypt_getpwdfilename();
5958
bufsize=strlen(pwdfilename)+strlen(CRYPT_PWD_RELOAD_SUFX)+1;
@@ -65,23 +64,25 @@ crypt_getpwdreloadfilename()
6564

6665
/*-------------------------------------------------------------------------*/
6766

68-
static
69-
FILE*
70-
crypt_openpwdfile()
67+
staticFILE*
68+
crypt_openpwdfile(void)
7169
{
7270
char*filename;
7371
FILE*pwdfile;
7472

7573
filename=crypt_getpwdfilename();
7674
pwdfile=AllocateFile(filename,PG_BINARY_R);
7775

76+
if (pwdfile==NULL)
77+
fprintf(stderr,"Couldn't read %s: %s\n",
78+
filename,strerror(errno));
79+
7880
returnpwdfile;
7981
}
8082

8183
/*-------------------------------------------------------------------------*/
8284

83-
static
84-
int
85+
staticint
8586
compar_user(constvoid*user_a,constvoid*user_b)
8687
{
8788

@@ -115,9 +116,8 @@ compar_user(const void *user_a, const void *user_b)
115116

116117
/*-------------------------------------------------------------------------*/
117118

118-
static
119-
void
120-
crypt_loadpwdfile()
119+
staticvoid
120+
crypt_loadpwdfile(void)
121121
{
122122

123123
char*filename;
@@ -176,8 +176,7 @@ crypt_loadpwdfile()
176176

177177
/*-------------------------------------------------------------------------*/
178178

179-
static
180-
void
179+
staticvoid
181180
crypt_parsepwdentry(char*buffer,char**pwd,char**valdate)
182181
{
183182

@@ -212,11 +211,9 @@ crypt_parsepwdentry(char *buffer, char **pwd, char **valdate)
212211

213212
/*-------------------------------------------------------------------------*/
214213

215-
static
216-
int
214+
staticint
217215
crypt_getloginfo(constchar*user,char**passwd,char**valuntil)
218216
{
219-
220217
char*pwd,
221218
*valdate;
222219
void*fakeout;

‎src/backend/libpq/hba.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* wherein you authenticate a user by seeing what IP address the system
66
* says he comes from and possibly using ident).
77
*
8-
*$Id: hba.c,v 1.53 2000/07/08 03:04:39 tgl Exp $
8+
*$Id: hba.c,v 1.54 2000/08/27 21:50:18 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -427,10 +427,8 @@ find_hba_entry(hbaPort *port, bool *hba_ok_p)
427427
/* The open of the config file failed.*/
428428

429429
snprintf(PQerrormsg,PQERRORMSG_LENGTH,
430-
"find_hba_entry: Host-based authentication config file "
431-
"does not exist or permissions are not setup correctly! "
432-
"Unable to open file \"%s\".\n",
433-
conf_file);
430+
"find_hba_entry: Unable to open authentication config file \"%s\": %s\n",
431+
conf_file,strerror(errno));
434432
fputs(PQerrormsg,stderr);
435433
pqdebug("%s",PQerrormsg);
436434
}
@@ -812,16 +810,13 @@ verify_against_usermap(const char *pguser,
812810
{
813811
/* The open of the map file failed. */
814812

815-
*checks_out_p= false;
816-
817813
snprintf(PQerrormsg,PQERRORMSG_LENGTH,
818-
"verify_against_usermap: usermap file for Ident-based "
819-
"authentication "
820-
"does not exist or permissions are not setup correctly! "
821-
"Unable to open file \"%s\".\n",
822-
map_file);
814+
"verify_against_usermap: Unable to open usermap file \"%s\": %s\n",
815+
map_file,strerror(errno));
823816
fputs(PQerrormsg,stderr);
824817
pqdebug("%s",PQerrormsg);
818+
819+
*checks_out_p= false;
825820
}
826821
else
827822
{
@@ -981,7 +976,10 @@ GetCharSetByHost(char *TableName, int host, const char *DataDir)
981976
snprintf(map_file,bufsize,"%s/%s",DataDir,CHARSET_FILE);
982977
file=AllocateFile(map_file,PG_BINARY_R);
983978
if (file==NULL)
979+
{
980+
/* XXX should we log a complaint? */
984981
return;
982+
}
985983
while (!eof)
986984
{
987985
c=getc(file);

‎src/backend/libpq/password.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
33
* Portions Copyright (c) 1994, Regents of the University of California
44
*
5-
* $Id: password.c,v 1.31 2000/07/08 03:04:40 tgl Exp $
5+
* $Id: password.c,v 1.32 2000/08/27 21:50:18 tgl Exp $
66
*
77
*/
88

9+
#include<errno.h>
910
#include<unistd.h>
1011

1112
#include"postgres.h"
@@ -36,8 +37,8 @@ verify_password(const Port *port, const char *user, const char *password)
3637
if (!pw_file)
3738
{
3839
snprintf(PQerrormsg,PQERRORMSG_LENGTH,
39-
"verify_password:couldn'topen password file'%s'\n",
40-
pw_file_fullname);
40+
"verify_password:Unable toopen password file\"%s\": %s\n",
41+
pw_file_fullname,strerror(errno));
4142
fputs(PQerrormsg,stderr);
4243
pqdebug("%s",PQerrormsg);
4344

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp