Commit f487e3da authored by Peter Eisentraut's avatar Peter Eisentraut

Check that the data directory does not have group or world access; remove

a similar check on postgresql.conf.
parent 46e25214
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.73 2001/07/03 16:49:48 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.74 2001/08/06 13:45:15 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -120,6 +120,7 @@ void ...@@ -120,6 +120,7 @@ void
SetDataDir(const char *dir) SetDataDir(const char *dir)
{ {
char *new; char *new;
struct stat stat_buf;
AssertArg(dir); AssertArg(dir);
...@@ -162,6 +163,21 @@ SetDataDir(const char *dir) ...@@ -162,6 +163,21 @@ SetDataDir(const char *dir)
if (!new) if (!new)
elog(FATAL, "out of memory"); elog(FATAL, "out of memory");
} }
/*
* Check if the directory has group or world access. If so, reject.
*/
if (stat(new, &stat_buf) == -1)
{
free(new);
elog(FATAL, "could not read permissions of directory %s: %s", new, strerror(errno));
}
if (stat_buf.st_mode & (S_IRWXG | S_IRWXO))
{
free(new);
elog(FATAL, "data directory %s has group or world access; permissions should be u=rwx (0700)", new);
}
if (DataDir) if (DataDir)
free(DataDir); free(DataDir);
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v 1.8 2001/06/07 04:50:57 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v 1.9 2001/08/06 13:45:15 petere Exp $
*/ */
%{ %{
...@@ -130,7 +130,6 @@ ProcessConfigFile(GucContext context) ...@@ -130,7 +130,6 @@ ProcessConfigFile(GucContext context)
int token, parse_state; int token, parse_state;
char *opt_name, *opt_value; char *opt_name, *opt_value;
char *filename; char *filename;
struct stat stat_buf;
struct name_value_pair *item, *head, *tail; struct name_value_pair *item, *head, *tail;
int elevel; int elevel;
FILE * fp; FILE * fp;
...@@ -161,25 +160,6 @@ ProcessConfigFile(GucContext context) ...@@ -161,25 +160,6 @@ ProcessConfigFile(GucContext context)
return; return;
} }
/*
* Check if the file is group or world writeable. If so, reject.
*/
if (fstat(fileno(fp), &stat_buf) == -1)
{
FreeFile(fp);
free(filename);
elog(elevel, "could not stat configuration file `" CONFIG_FILENAME "': %s", strerror(errno));
return;
}
if (stat_buf.st_mode & (S_IWGRP | S_IXGRP | S_IWOTH | S_IXOTH))
{
FreeFile(fp);
free(filename);
elog(elevel, "configuration file `" CONFIG_FILENAME "' has wrong permissions");
return;
}
/* /*
* Parse * Parse
*/ */
......
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