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

Commit40f2eec

Browse files
committed
> > > > If you want to put in security restrictions that are actually useful,
> > > > where is the code to verify that PGPASSWORDFILE points at a> > > > non-world-readable file? That needs to be there now, not later, or> > > > we'll have people moaning about backward compatibility when we finally> > > > do plug that hole.Alvaro Herrera
1 parent9858a3a commit40f2eec

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.198 2002/08/2907:22:29 ishii Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.199 2002/08/2923:06:32 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
1515

1616
#include"postgres_fe.h"
1717

1818
#include<sys/types.h>
19+
#include<sys/stat.h>
1920
#include<fcntl.h>
2021
#include<errno.h>
2122
#include<ctype.h>
2223
#include<time.h>
24+
#include<unistd.h>
2325

2426
#include"libpq-fe.h"
2527
#include"libpq-int.h"
@@ -2904,6 +2906,7 @@ PasswordFromFile(char *hostname, char *port, char *dbname,
29042906
FILE*fp;
29052907
#defineLINELEN NAMEDATALEN*5
29062908
charbuf[LINELEN];
2909+
structstatstat_buf;
29072910

29082911
if (pwdfile==NULL||strcmp(pwdfile,"")==0)
29092912
returnNULL;
@@ -2920,6 +2923,19 @@ PasswordFromFile(char *hostname, char *port, char *dbname,
29202923
if (port==NULL)
29212924
port=DEF_PGPORT_STR;
29222925

2926+
/* If password file cannot be opened, ignore it. */
2927+
if (stat(pwdfile,&stat_buf)==-1)
2928+
returnNULL;
2929+
2930+
/* If password file is insecure, alert the user and ignore it. */
2931+
if (stat_buf.st_mode& (S_IRWXG |S_IRWXO))
2932+
{
2933+
fprintf(stderr,
2934+
libpq_gettext("WARNING: Password file %s has world or group read access; permission should be u=rw (0600)"),
2935+
pwdfile);
2936+
returnNULL;
2937+
}
2938+
29232939
fp=fopen(pwdfile,"r");
29242940
if (fp==NULL)
29252941
returnNULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp