diff --git a/include/misc.h b/include/misc.h index e805cf68..68b7ebee 100644 --- a/include/misc.h +++ b/include/misc.h @@ -59,9 +59,24 @@ typedef int pid_t; #define mkdir(dir,perm) _mkdir((dir)) #define random rand #define srandom srand - +#define S_IRUSR _S_IREAD +#define S_IWUSR _S_IWRITE +#define S_IXUSR _S_IREAD +#define S_IRGRP _S_IREAD +#define S_IWGRP _S_IWRITE +#define S_IXGRP _S_IREAD +#define S_IROTH _S_IREAD +#define S_IWOTH _S_IWRITE +#define S_IXOTH _S_IREAD +#define S_IRWXU S_IRUSR | S_IWUSR | S_IXUSR +#define S_IRWXG S_IRGRP | S_IWGRP | S_IXGRP +#define S_IRWXO S_IROTH | S_IWOTH | S_IXOTH #endif /* _WIN32 */ +#ifndef S_IRWUG +#define S_IRWUG S_IRGRP | S_IWGRP | S_IRUSR | S_IWUSR +#endif + /* This is the structure we use to keep track of the global mobility things, such as when the server is supposed to start/stop updating mobility and the timestamp of when the game was last up. These diff --git a/src/lib/commands/add.c b/src/lib/commands/add.c index efd99ecb..16e2b77d 100644 --- a/src/lib/commands/add.c +++ b/src/lib/commands/add.c @@ -37,6 +37,7 @@ #if defined(_WIN32) #include #endif +#include #include "commands.h" #include "land.h" @@ -213,7 +214,7 @@ add(void) natp->nat_rejects[i] = 0; natp->nat_newstim = 0; natp->nat_annotim = 0; - (void)creat(mailbox(buf, coun), 0660); + (void)creat(mailbox(buf, coun), S_IRWUG); } else pr("No special initializations done...\n"); diff --git a/src/lib/commands/disa.c b/src/lib/commands/disa.c index 2aa9184b..ca2534d5 100644 --- a/src/lib/commands/disa.c +++ b/src/lib/commands/disa.c @@ -37,6 +37,7 @@ #include #endif #include +#include #if !defined(_WIN32) #include #endif @@ -48,7 +49,7 @@ disa(void) { int fd; - if ((fd = open(disablefil, O_RDWR | O_CREAT | O_TRUNC, 0660)) < 0) + if ((fd = open(disablefil, O_RDWR | O_CREAT | O_TRUNC, S_IRWUG)) < 0) return RET_FAIL; close(fd); pr("Updates are disabled\n"); diff --git a/src/lib/common/file.c b/src/lib/common/file.c index f43dda0b..2ed507b0 100644 --- a/src/lib/common/file.c +++ b/src/lib/common/file.c @@ -41,6 +41,7 @@ #include #endif #include +#include #include #include #if !defined(_WIN32) @@ -90,12 +91,12 @@ ef_open(int type, int how) oflags |= O_BINARY; if ((fd = sopen(ep->file, oflags, how & EFF_RDONLY ? SH_DENYNO : SH_DENYWR, - 0660)) < 0) { + S_IRWUG)) < 0) { logerror("Can't open %s (%s)", ep->file, strerror(errno)); return 0; } #else - if ((fd = open(ep->file, oflags, 0660)) < 0) { + if ((fd = open(ep->file, oflags, S_IRWUG)) < 0) { logerror("Can't open %s (%s)", ep->file, strerror(errno)); return 0; } diff --git a/src/lib/common/log.c b/src/lib/common/log.c index b7eda713..52869112 100644 --- a/src/lib/common/log.c +++ b/src/lib/common/log.c @@ -40,6 +40,7 @@ #include #endif #include +#include #include #include #include @@ -93,7 +94,8 @@ logerror(char *format, ...) time(&now); memcpy(buf, ctime(&now), ctime_len); buf[ctime_len] = ' '; - if ((logf = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0660)) < 0) + if ((logf = open(logfile, O_WRONLY | O_CREAT | O_APPEND, + S_IRWUG)) < 0) return; write(logf, buf, strlen(buf)); close(logf); diff --git a/src/util/files.c b/src/util/files.c index c4436977..9da0132b 100644 --- a/src/util/files.c +++ b/src/util/files.c @@ -36,13 +36,13 @@ #include #include +#include #include #if defined(_WIN32) #include #include #include "../lib/gen/getopt.h" #else -#include #include #endif @@ -117,7 +117,7 @@ main(int argc, char *argv[]) ef_init(); - if (mkdir(gamedir, 0770) < 0 && errno != EEXIST) { + if (mkdir(gamedir, S_IRWXU | S_IRWXG) < 0 && errno != EEXIST) { perror(gamedir); printf("Can't make game directory\n"); exit(1); @@ -171,17 +171,17 @@ main(int argc, char *argv[]) putrealm(&realm); } } - if (mkdir(teldir, 0770) < 0 && errno != EEXIST) { + if (mkdir(teldir, S_IRWXU | S_IRWXG) < 0 && errno != EEXIST) { perror(teldir); printf("Can't make telegram directory\n"); exit(1); } for (x = MAXNOC - 1; x >= 0; x--) { filename = mailbox(buf, x); - close(creat(filename, 0660)); + close(creat(filename, S_IRWUG)); } - close(creat(timestampfil, 0660)); - close(creat(annfil, 0660)); + close(creat(timestampfil, S_IRWUG)); + close(creat(annfil, S_IRWUG)); /* create a zero-filled sector file */ memset(&sct, 0, sizeof(sct));