]> git.pond.sub.org Git - empserver/commitdiff
(add, disa, ef_open, logerror, main): Switch permissions to
authorRon Koenderink <rkoenderink@yahoo.ca>
Sat, 10 Mar 2007 16:29:51 +0000 (16:29 +0000)
committerRon Koenderink <rkoenderink@yahoo.ca>
Sat, 10 Mar 2007 16:29:51 +0000 (16:29 +0000)
standard defines instead of magic numbers to improve portability.
Also define WIN32 equivalents to the standard defines.

include/misc.h
src/lib/commands/add.c
src/lib/commands/disa.c
src/lib/common/file.c
src/lib/common/log.c
src/util/files.c

index e805cf68f5d68ae02868bef85a9635d796c96c81..68b7ebee8045d6f304200c52cfb5e4177009b9e9 100644 (file)
@@ -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
index efd99ecb56b764e0a8306c55a0b8de95cb9b5f6f..16e2b77daecc54593e39b1314e229523f1c748dd 100644 (file)
@@ -37,6 +37,7 @@
 #if defined(_WIN32)
 #include <io.h>
 #endif
+#include <sys/stat.h>
 
 #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");
 
index 2aa9184b836953dfd5592af9b6f9d767d64d6a30..ca2534d5786d620116296167bc107941c75463a7 100644 (file)
@@ -37,6 +37,7 @@
 #include <io.h>
 #endif
 #include <fcntl.h>
+#include <sys/stat.h>
 #if !defined(_WIN32)
 #include <unistd.h>
 #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");
index f43dda0b489b009278ee78f16b35675862b36413..2ed507b04b0b8b658468fbcd9ea76f3fd4d2cc0b 100644 (file)
@@ -41,6 +41,7 @@
 #include <share.h>
 #endif
 #include <fcntl.h>
+#include <sys/stat.h>
 #include <signal.h>
 #include <sys/types.h>
 #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;
     }
index b7eda713efe96a7f51839ced8636b226128947e4..52869112c45cdce7e3bfb0a29d384d9f950ef656 100644 (file)
@@ -40,6 +40,7 @@
 #include <unistd.h>
 #endif
 #include <fcntl.h>
+#include <sys/stat.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <time.h>
@@ -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);
index c4436977e1a81190442ba469e9c29e82983308b2..9da0132b39d059ca3be2586bc4f376cbdae4005a 100644 (file)
 #include <config.h>
 
 #include <fcntl.h>
+#include <sys/stat.h>
 #include <errno.h>
 #if defined(_WIN32)
 #include <direct.h>
 #include <io.h>
 #include "../lib/gen/getopt.h"
 #else
-#include <sys/stat.h>
 #include <unistd.h>
 #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));