mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
Use symbolic names not octal constants for file permission flags.
Purely cosmetic patch to make our coding standards more consistent --- we were doing symbolic some places and octal other places. This patch fixes all C-coded uses of mkdir, chmod, and umask. There might be some other calls I missed. Inconsistency noted while researching tablespace directory permissions issue.
This commit is contained in:
parent
244407a710
commit
04f4e10cfc
@ -3451,7 +3451,7 @@ ValidateXLOGDirectoryStructure(void)
|
|||||||
{
|
{
|
||||||
ereport(LOG,
|
ereport(LOG,
|
||||||
(errmsg("creating missing WAL directory \"%s\"", path)));
|
(errmsg("creating missing WAL directory \"%s\"", path)));
|
||||||
if (mkdir(path, 0700) < 0)
|
if (mkdir(path, S_IRWXU) < 0)
|
||||||
ereport(FATAL,
|
ereport(FATAL,
|
||||||
(errmsg("could not create missing directory \"%s\": %m",
|
(errmsg("could not create missing directory \"%s\": %m",
|
||||||
path)));
|
path)));
|
||||||
|
@ -1269,7 +1269,7 @@ DoCopyTo(CopyState cstate)
|
|||||||
(errcode(ERRCODE_INVALID_NAME),
|
(errcode(ERRCODE_INVALID_NAME),
|
||||||
errmsg("relative path not allowed for COPY to file")));
|
errmsg("relative path not allowed for COPY to file")));
|
||||||
|
|
||||||
oumask = umask((mode_t) 022);
|
oumask = umask(S_IWGRP | S_IWOTH);
|
||||||
cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
|
cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
|
||||||
umask(oumask);
|
umask(oumask);
|
||||||
|
|
||||||
|
@ -552,7 +552,7 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
|
|||||||
* Attempt to coerce target directory to safe permissions. If this fails,
|
* Attempt to coerce target directory to safe permissions. If this fails,
|
||||||
* it doesn't exist or has the wrong owner.
|
* it doesn't exist or has the wrong owner.
|
||||||
*/
|
*/
|
||||||
if (chmod(location, 0700) != 0)
|
if (chmod(location, S_IRWXU) != 0)
|
||||||
{
|
{
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
|
@ -399,7 +399,7 @@ lo_import_internal(text *filename, Oid lobjOid)
|
|||||||
* open the file to be read in
|
* open the file to be read in
|
||||||
*/
|
*/
|
||||||
text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
|
text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
|
||||||
fd = PathNameOpenFile(fnamebuf, O_RDONLY | PG_BINARY, 0666);
|
fd = PathNameOpenFile(fnamebuf, O_RDONLY | PG_BINARY, S_IRWXU);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
@ -474,8 +474,9 @@ lo_export(PG_FUNCTION_ARGS)
|
|||||||
* world-writable export files doesn't seem wise.
|
* world-writable export files doesn't seem wise.
|
||||||
*/
|
*/
|
||||||
text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
|
text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
|
||||||
oumask = umask((mode_t) 0022);
|
oumask = umask(S_IWGRP | S_IWOTH);
|
||||||
fd = PathNameOpenFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY, 0666);
|
fd = PathNameOpenFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY,
|
||||||
|
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||||
umask(oumask);
|
umask(oumask);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
|
@ -494,7 +494,7 @@ PostmasterMain(int argc, char *argv[])
|
|||||||
/*
|
/*
|
||||||
* for security, no dir or file created can be group or other accessible
|
* for security, no dir or file created can be group or other accessible
|
||||||
*/
|
*/
|
||||||
umask((mode_t) 0077);
|
umask(S_IRWXG | S_IRWXO);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fire up essential subsystems: memory management
|
* Fire up essential subsystems: memory management
|
||||||
@ -1274,7 +1274,7 @@ pmdaemonize(void)
|
|||||||
progname, DEVNULL, strerror(errno));
|
progname, DEVNULL, strerror(errno));
|
||||||
ExitPostmaster(1);
|
ExitPostmaster(1);
|
||||||
}
|
}
|
||||||
pmlog = open(pmlogname, O_CREAT | O_WRONLY | O_APPEND, 0600);
|
pmlog = open(pmlogname, O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR);
|
||||||
if (pmlog < 0)
|
if (pmlog < 0)
|
||||||
{
|
{
|
||||||
write_stderr("%s: could not open log file \"%s/%s\": %s\n",
|
write_stderr("%s: could not open log file \"%s/%s\": %s\n",
|
||||||
|
@ -73,7 +73,7 @@ int Log_RotationSize = 10 * 1024;
|
|||||||
char *Log_directory = NULL;
|
char *Log_directory = NULL;
|
||||||
char *Log_filename = NULL;
|
char *Log_filename = NULL;
|
||||||
bool Log_truncate_on_rotation = false;
|
bool Log_truncate_on_rotation = false;
|
||||||
int Log_file_mode = 0600;
|
int Log_file_mode = S_IRUSR | S_IWUSR;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Globally visible state (used by elog.c)
|
* Globally visible state (used by elog.c)
|
||||||
@ -511,7 +511,7 @@ SysLogger_Start(void)
|
|||||||
/*
|
/*
|
||||||
* Create log directory if not present; ignore errors
|
* Create log directory if not present; ignore errors
|
||||||
*/
|
*/
|
||||||
mkdir(Log_directory, 0700);
|
mkdir(Log_directory, S_IRWXU);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The initial logfile is created right in the postmaster, to verify that
|
* The initial logfile is created right in the postmaster, to verify that
|
||||||
@ -1020,7 +1020,7 @@ logfile_open(const char *filename, const char *mode, bool allow_errors)
|
|||||||
* Note we do not let Log_file_mode disable IWUSR, since we certainly
|
* Note we do not let Log_file_mode disable IWUSR, since we certainly
|
||||||
* want to be able to write the files ourselves.
|
* want to be able to write the files ourselves.
|
||||||
*/
|
*/
|
||||||
oumask = umask((mode_t) ((~(Log_file_mode | S_IWUSR)) & 0777));
|
oumask = umask((mode_t) ((~(Log_file_mode | S_IWUSR)) & (S_IRWXU | S_IRWXG | S_IRWXO)));
|
||||||
fh = fopen(filename, mode);
|
fh = fopen(filename, mode);
|
||||||
umask(oumask);
|
umask(oumask);
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ copydir(char *fromdir, char *todir, bool recurse)
|
|||||||
char fromfile[MAXPGPATH];
|
char fromfile[MAXPGPATH];
|
||||||
char tofile[MAXPGPATH];
|
char tofile[MAXPGPATH];
|
||||||
|
|
||||||
if (mkdir(todir, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
|
if (mkdir(todir, S_IRWXU) != 0)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not create directory \"%s\": %m", todir)));
|
errmsg("could not create directory \"%s\": %m", todir)));
|
||||||
|
@ -126,8 +126,8 @@ proc_exit(int code)
|
|||||||
else
|
else
|
||||||
snprintf(gprofDirName, 32, "gprof/%d", (int) getpid());
|
snprintf(gprofDirName, 32, "gprof/%d", (int) getpid());
|
||||||
|
|
||||||
mkdir("gprof", 0777);
|
mkdir("gprof", S_IRWXU | S_IRWXG | S_IRWXO);
|
||||||
mkdir(gprofDirName, 0777);
|
mkdir(gprofDirName, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||||
chdir(gprofDirName);
|
chdir(gprofDirName);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -870,7 +870,7 @@ mkdatadir(const char *subdir)
|
|||||||
else
|
else
|
||||||
strcpy(path, pg_data);
|
strcpy(path, pg_data);
|
||||||
|
|
||||||
if (mkdir_p(path, 0700) == 0)
|
if (mkdir_p(path, S_IRWXU) == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
|
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
|
||||||
@ -1166,7 +1166,7 @@ setup_config(void)
|
|||||||
snprintf(path, sizeof(path), "%s/postgresql.conf", pg_data);
|
snprintf(path, sizeof(path), "%s/postgresql.conf", pg_data);
|
||||||
|
|
||||||
writefile(path, conflines);
|
writefile(path, conflines);
|
||||||
chmod(path, 0600);
|
chmod(path, S_IRUSR | S_IWUSR);
|
||||||
|
|
||||||
free(conflines);
|
free(conflines);
|
||||||
|
|
||||||
@ -1237,7 +1237,7 @@ setup_config(void)
|
|||||||
snprintf(path, sizeof(path), "%s/pg_hba.conf", pg_data);
|
snprintf(path, sizeof(path), "%s/pg_hba.conf", pg_data);
|
||||||
|
|
||||||
writefile(path, conflines);
|
writefile(path, conflines);
|
||||||
chmod(path, 0600);
|
chmod(path, S_IRUSR | S_IWUSR);
|
||||||
|
|
||||||
free(conflines);
|
free(conflines);
|
||||||
|
|
||||||
@ -1248,7 +1248,7 @@ setup_config(void)
|
|||||||
snprintf(path, sizeof(path), "%s/pg_ident.conf", pg_data);
|
snprintf(path, sizeof(path), "%s/pg_ident.conf", pg_data);
|
||||||
|
|
||||||
writefile(path, conflines);
|
writefile(path, conflines);
|
||||||
chmod(path, 0600);
|
chmod(path, S_IRUSR | S_IWUSR);
|
||||||
|
|
||||||
free(conflines);
|
free(conflines);
|
||||||
|
|
||||||
@ -2904,7 +2904,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
umask(077);
|
umask(S_IRWXG | S_IRWXO);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* now we are starting to do real work, trap signals so we can clean up
|
* now we are starting to do real work, trap signals so we can clean up
|
||||||
@ -2951,7 +2951,7 @@ main(int argc, char *argv[])
|
|||||||
pg_data);
|
pg_data);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
if (chmod(pg_data, 0700) != 0)
|
if (chmod(pg_data, S_IRWXU) != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
|
fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
|
||||||
progname, pg_data, strerror(errno));
|
progname, pg_data, strerror(errno));
|
||||||
@ -3004,7 +3004,7 @@ main(int argc, char *argv[])
|
|||||||
xlog_dir);
|
xlog_dir);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
if (mkdir_p(xlog_dir, 0700) != 0)
|
if (mkdir_p(xlog_dir, S_IRWXU) != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
|
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
|
||||||
progname, xlog_dir, strerror(errno));
|
progname, xlog_dir, strerror(errno));
|
||||||
@ -3021,7 +3021,7 @@ main(int argc, char *argv[])
|
|||||||
xlog_dir);
|
xlog_dir);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
if (chmod(xlog_dir, 0700) != 0)
|
if (chmod(xlog_dir, S_IRWXU) != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
|
fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
|
||||||
progname, xlog_dir, strerror(errno));
|
progname, xlog_dir, strerror(errno));
|
||||||
|
@ -1769,7 +1769,7 @@ main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
argv0 = argv[0];
|
argv0 = argv[0];
|
||||||
|
|
||||||
umask(077);
|
umask(S_IRWXG | S_IRWXO);
|
||||||
|
|
||||||
/* support --help and --version even if invoked as root */
|
/* support --help and --version even if invoked as root */
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user