aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/adminproc.c
diff options
context:
space:
mode:
Diffstat (limited to 'FICS/adminproc.c')
-rw-r--r--FICS/adminproc.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/FICS/adminproc.c b/FICS/adminproc.c
index e670d44..dfe528e 100644
--- a/FICS/adminproc.c
+++ b/FICS/adminproc.c
@@ -19,6 +19,8 @@
#include <sys/param.h>
#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
#include <inttypes.h>
#include <stdint.h>
@@ -173,6 +175,7 @@ create_news_file(int p, param_list param, int admin)
{
FILE *fp;
char filename[MAX_FILENAME_SIZE] = { '\0' };
+ int fd;
ASSERT(parray[p].adminLevel >= ADMIN_ADMIN);
@@ -185,10 +188,14 @@ create_news_file(int p, param_list param, int admin)
msnprintf(filename, sizeof filename, "%s/adminnews.%d",
news_dir,
param[0].val.integer);
- if ((fp = fopen(filename, "w")) != NULL) {
+ fd = open(filename, O_WRONLY|O_CREAT, S_IWUSR|S_IRUSR);
+ if (fd < 0)
+ return COM_FAILED;
+ else if ((fp = fdopen(fd, "w")) != NULL) {
fprintf(fp, "%s\n", param[1].val.string);
fclose(fp);
- }
+ } else
+ close(fd);
}
} else {
if (param[0].val.integer > num_news) {
@@ -198,10 +205,14 @@ create_news_file(int p, param_list param, int admin)
msnprintf(filename, sizeof filename, "%s/news.%d",
news_dir,
param[0].val.integer);
- if ((fp = fopen(filename, "w")) != NULL) {
+ fd = open(filename, O_WRONLY|O_CREAT, S_IWUSR|S_IRUSR);
+ if (fd < 0)
+ return COM_FAILED;
+ else if ((fp = fdopen(fd, "w")) != NULL) {
fprintf(fp, "%s\n", param[1].val.string);
fclose(fp);
- }
+ } else
+ close(fd);
}
}
@@ -214,11 +225,19 @@ add_item(char *new_item, char *filename)
FILE *new_fp, *old_fp;
char junk[MAX_LINE_SIZE] = { '\0' };
char tmp_file[MAX_FILENAME_SIZE] = { '\0' };
+ int fd;
msnprintf(tmp_file, sizeof tmp_file, "%s/.tmp.idx", news_dir);
- if ((new_fp = fopen(tmp_file, "w")) == NULL)
+ fd = open(tmp_file, O_WRONLY|O_CREAT, S_IWUSR|S_IRUSR);
+
+ if (fd < 0)
+ return 0;
+ else if ((new_fp = fdopen(fd, "w")) == NULL) {
+ close(fd);
return 0;
+ }
+
fprintf(new_fp, "%s", new_item);
if ((old_fp = fopen(filename, "r")) == NULL)
@@ -373,6 +392,7 @@ com_anews(int p, param_list param)
char filename[MAX_FILENAME_SIZE] = { '\0' };
char junk[MAX_LINE_SIZE] = { '\0' };
char *junkp = NULL;
+ const char *v_scan_junk = "%" SCNd64 " " "%9s";
int found = 0;
int64_t lval = 0;
time_t crtime = 0;
@@ -384,7 +404,6 @@ com_anews(int p, param_list param)
return COM_OK;
}
-#define SCAN_JUNK ("%" SCNd64 " " "%9s")
_Static_assert(9 < ARRAY_SIZE(count), "Array too small");
if (param[0].type == 0) {
@@ -402,7 +421,7 @@ com_anews(int p, param_list param)
fclose(fp);
return COM_FAILED;
}
- if (sscanf(junk, SCAN_JUNK, &lval, count) != 2) {
+ if (sscanf(junk, v_scan_junk, &lval, count) != 2) {
warnx("%s: sscanf() error: too few items", __func__);
fclose(fp);
return COM_FAILED;
@@ -431,7 +450,7 @@ com_anews(int p, param_list param)
fclose(fp);
return COM_FAILED;
}
- if (sscanf(junk, SCAN_JUNK, &lval, count) != 2) {
+ if (sscanf(junk, v_scan_junk, &lval, count) != 2) {
warnx("%s: sscanf() error: too few items", __func__);
fclose(fp);
return COM_FAILED;
@@ -455,8 +474,11 @@ com_anews(int p, param_list param)
break;
if (strlen(junk) > 1) {
- if (sscanf(junkp, SCAN_JUNK, &lval, count) != 2)
- warnx("%s: sscanf() error...", __func__);
+ if (sscanf(junkp, v_scan_junk, &lval,
+ count) != 2) {
+ warnx("%s: sscanf() error...",
+ __func__);
+ }
crtime = lval;