(add, disa, ef_open, logerror, main): Switch permissions to

standard defines instead of magic numbers to improve portability.
Also define WIN32 equivalents to the standard defines.
This commit is contained in:
Ron Koenderink 2007-03-10 16:29:51 +00:00
parent 32d62797d2
commit c97d79c0ee
6 changed files with 32 additions and 12 deletions

View file

@ -59,9 +59,24 @@ typedef int pid_t;
#define mkdir(dir,perm) _mkdir((dir)) #define mkdir(dir,perm) _mkdir((dir))
#define random rand #define random rand
#define srandom srand #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 */ #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 /* 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 things, such as when the server is supposed to start/stop updating
mobility and the timestamp of when the game was last up. These mobility and the timestamp of when the game was last up. These

View file

@ -37,6 +37,7 @@
#if defined(_WIN32) #if defined(_WIN32)
#include <io.h> #include <io.h>
#endif #endif
#include <sys/stat.h>
#include "commands.h" #include "commands.h"
#include "land.h" #include "land.h"
@ -213,7 +214,7 @@ add(void)
natp->nat_rejects[i] = 0; natp->nat_rejects[i] = 0;
natp->nat_newstim = 0; natp->nat_newstim = 0;
natp->nat_annotim = 0; natp->nat_annotim = 0;
(void)creat(mailbox(buf, coun), 0660); (void)creat(mailbox(buf, coun), S_IRWUG);
} else } else
pr("No special initializations done...\n"); pr("No special initializations done...\n");

View file

@ -37,6 +37,7 @@
#include <io.h> #include <io.h>
#endif #endif
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h>
#if !defined(_WIN32) #if !defined(_WIN32)
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -48,7 +49,7 @@ disa(void)
{ {
int fd; 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; return RET_FAIL;
close(fd); close(fd);
pr("Updates are disabled\n"); pr("Updates are disabled\n");

View file

@ -41,6 +41,7 @@
#include <share.h> #include <share.h>
#endif #endif
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h>
#include <signal.h> #include <signal.h>
#include <sys/types.h> #include <sys/types.h>
#if !defined(_WIN32) #if !defined(_WIN32)
@ -90,12 +91,12 @@ ef_open(int type, int how)
oflags |= O_BINARY; oflags |= O_BINARY;
if ((fd = sopen(ep->file, oflags, if ((fd = sopen(ep->file, oflags,
how & EFF_RDONLY ? SH_DENYNO : SH_DENYWR, how & EFF_RDONLY ? SH_DENYNO : SH_DENYWR,
0660)) < 0) { S_IRWUG)) < 0) {
logerror("Can't open %s (%s)", ep->file, strerror(errno)); logerror("Can't open %s (%s)", ep->file, strerror(errno));
return 0; return 0;
} }
#else #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)); logerror("Can't open %s (%s)", ep->file, strerror(errno));
return 0; return 0;
} }

View file

@ -40,6 +40,7 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
@ -93,7 +94,8 @@ logerror(char *format, ...)
time(&now); time(&now);
memcpy(buf, ctime(&now), ctime_len); memcpy(buf, ctime(&now), ctime_len);
buf[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; return;
write(logf, buf, strlen(buf)); write(logf, buf, strlen(buf));
close(logf); close(logf);

View file

@ -36,13 +36,13 @@
#include <config.h> #include <config.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h>
#include <errno.h> #include <errno.h>
#if defined(_WIN32) #if defined(_WIN32)
#include <direct.h> #include <direct.h>
#include <io.h> #include <io.h>
#include "../lib/gen/getopt.h" #include "../lib/gen/getopt.h"
#else #else
#include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -117,7 +117,7 @@ main(int argc, char *argv[])
ef_init(); ef_init();
if (mkdir(gamedir, 0770) < 0 && errno != EEXIST) { if (mkdir(gamedir, S_IRWXU | S_IRWXG) < 0 && errno != EEXIST) {
perror(gamedir); perror(gamedir);
printf("Can't make game directory\n"); printf("Can't make game directory\n");
exit(1); exit(1);
@ -171,17 +171,17 @@ main(int argc, char *argv[])
putrealm(&realm); putrealm(&realm);
} }
} }
if (mkdir(teldir, 0770) < 0 && errno != EEXIST) { if (mkdir(teldir, S_IRWXU | S_IRWXG) < 0 && errno != EEXIST) {
perror(teldir); perror(teldir);
printf("Can't make telegram directory\n"); printf("Can't make telegram directory\n");
exit(1); exit(1);
} }
for (x = MAXNOC - 1; x >= 0; x--) { for (x = MAXNOC - 1; x >= 0; x--) {
filename = mailbox(buf, x); filename = mailbox(buf, x);
close(creat(filename, 0660)); close(creat(filename, S_IRWUG));
} }
close(creat(timestampfil, 0660)); close(creat(timestampfil, S_IRWUG));
close(creat(annfil, 0660)); close(creat(annfil, S_IRWUG));
/* create a zero-filled sector file */ /* create a zero-filled sector file */
memset(&sct, 0, sizeof(sct)); memset(&sct, 0, sizeof(sct));