(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:
parent
32d62797d2
commit
c97d79c0ee
6 changed files with 32 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -36,13 +36,13 @@
|
|||
#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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue