aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/adminproc.c
diff options
context:
space:
mode:
Diffstat (limited to 'FICS/adminproc.c')
-rw-r--r--FICS/adminproc.c177
1 files changed, 106 insertions, 71 deletions
diff --git a/FICS/adminproc.c b/FICS/adminproc.c
index 32746e7..94a9448 100644
--- a/FICS/adminproc.c
+++ b/FICS/adminproc.c
@@ -1,23 +1,25 @@
/*
- * fics - An internet chess server
- * Copyright (c) 1993 Richard V. Nash
- *
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- */
+ fics - An internet chess server.
+ Copyright (C) 1993 Richard V. Nash
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+*/
#include "stdinclude.h"
#include "common.h"
#include <sys/param.h>
+#include <err.h>
+
#include "adminproc.h"
#include "command.h"
#include "comproc.h"
@@ -181,9 +183,10 @@ create_news_file(int p, param_list param, int admin)
msnprintf(filename, sizeof filename, "%s/adminnews.%d",
news_dir,
param[0].val.integer);
- fp = fopen(filename, "w");
- fprintf(fp, "%s\n", param[1].val.string);
- fclose(fp);
+ if ((fp = fopen(filename, "w")) != NULL) {
+ fprintf(fp, "%s\n", param[1].val.string);
+ fclose(fp);
+ }
}
} else {
if (param[0].val.integer > num_news) {
@@ -193,9 +196,10 @@ create_news_file(int p, param_list param, int admin)
msnprintf(filename, sizeof filename, "%s/news.%d",
news_dir,
param[0].val.integer);
- fp = fopen(filename, "w");
- fprintf(fp, "%s\n", param[1].val.string);
- fclose(fp);
+ if ((fp = fopen(filename, "w")) != NULL) {
+ fprintf(fp, "%s\n", param[1].val.string);
+ fclose(fp);
+ }
}
}
@@ -219,21 +223,21 @@ add_item(char *new_item, char *filename)
goto end;
while (1) {
- fgets(junk, MAX_LINE_SIZE, old_fp);
-
- if (feof(old_fp))
+ if (fgets(junk, sizeof junk, old_fp) == NULL ||
+ feof(old_fp))
break;
fprintf(new_fp, "%s", junk);
}
end:
- fclose(new_fp);
+ (void) fclose(new_fp);
+
if (old_fp) {
- fclose(old_fp);
- remove(filename);
+ (void) fclose(old_fp);
+ (void) remove(filename);
}
- rename(tmp_file, filename);
+ (void) rename(tmp_file, filename);
return 1;
}
@@ -362,14 +366,14 @@ com_canewsf(int p, param_list param)
PUBLIC int
com_anews(int p, param_list param)
{
- FILE *fp;
- char *junkp;
- char count[10];
+ FILE *fp = NULL;
+ char *junkp = NULL;
+ char count[10] = { '\0' };
char filename[MAX_FILENAME_SIZE] = { '\0' };
char junk[MAX_LINE_SIZE] = { '\0' };
int found = 0;
- long int lval;
- time_t crtime;
+ long int lval = 0;
+ time_t crtime = 0;
msnprintf(filename, sizeof filename, "%s/newadminnews.index", news_dir);
@@ -378,6 +382,9 @@ com_anews(int p, param_list param)
return COM_OK;
}
+#define SCAN_JUNK "%ld %9s"
+ _Static_assert(9 < ARRAY_SIZE(count), "Array too small");
+
if (param[0].type == 0) {
/*
* No params - then just display index over news.
@@ -387,8 +394,18 @@ com_anews(int p, param_list param)
news_dir);
pprintf(p, "Index of recent admin news items:\n");
- fgets(junk, MAX_LINE_SIZE, fp);
- sscanf(junk, "%ld %s", &lval, count);
+
+ if (fgets(junk, sizeof junk, fp) == NULL) {
+ warnx("%s: fgets() error", __func__);
+ fclose(fp);
+ return COM_FAILED;
+ }
+ if (sscanf(junk, SCAN_JUNK, &lval, count) != 2) {
+ warnx("%s: sscanf() error: too few items", __func__);
+ fclose(fp);
+ return COM_FAILED;
+ }
+
rscan_news2(fp, p, 9);
junkp = junk;
@@ -406,8 +423,18 @@ com_anews(int p, param_list param)
*/
pprintf(p, "Index of all admin news items:\n");
- fgets(junk, MAX_LINE_SIZE, fp);
- sscanf(junk, "%ld %s", &lval, count);
+
+ if (fgets(junk, sizeof junk, fp) == NULL) {
+ warnx("%s: fgets() error", __func__);
+ fclose(fp);
+ return COM_FAILED;
+ }
+ if (sscanf(junk, SCAN_JUNK, &lval, count) != 2) {
+ warnx("%s: sscanf() error: too few items", __func__);
+ fclose(fp);
+ return COM_FAILED;
+ }
+
rscan_news(fp, p, 0);
junkp = junk;
@@ -421,13 +448,14 @@ com_anews(int p, param_list param)
} else {
while (!feof(fp) && !found) {
junkp = junk;
- fgets(junk, MAX_LINE_SIZE, fp);
- if (feof(fp))
+ if (fgets(junk, sizeof junk, fp) == NULL)
break;
if (strlen(junk) > 1) {
- sscanf(junkp, "%ld %s", &lval, count);
+ if (sscanf(junkp, SCAN_JUNK, &lval, count) != 2)
+ warnx("%s: sscanf() error...", __func__);
+
crtime = lval;
if (!strcmp(count, param[0].val.word)) {
@@ -474,9 +502,15 @@ com_anews(int p, param_list param)
PUBLIC int
strcmpwild(char *mainstr, char *searchstr)
{
- if (strlen(mainstr) < strlen(searchstr))
+ size_t len[2];
+
+ len[0] = strlen(mainstr);
+ len[1] = strlen(searchstr);
+
+ if (len[0] < len[1])
return 1;
- for (size_t i = 0; i < strlen(mainstr); i++) {
+
+ for (size_t i = 0; i < len[0]; i++) {
if (searchstr[i] == '*')
return 0;
if (mainstr[i] != searchstr[i])
@@ -564,7 +598,7 @@ com_checkSOCKET(int p, param_list param)
PUBLIC int
com_checkPLAYER(int p, param_list param)
{
- char *player = param[0].val.word;
+ char *v_player = param[0].val.word;
int p1;
ASSERT(parray[p].adminLevel >= ADMIN_ADMIN);
@@ -576,8 +610,8 @@ com_checkPLAYER(int p, param_list param)
if (p1 < 0) {
p1 = (-p1) - 1;
- pprintf(p, "%s is not logged in.\n", player);
- stolower(player);
+ pprintf(p, "%s is not logged in.\n", v_player);
+ stolower(v_player);
pprintf(p, "name = %s\n", parray[p1].name);
pprintf(p, "login = %s\n", parray[p1].login);
@@ -597,7 +631,7 @@ com_checkPLAYER(int p, param_list param)
} else {
p1 = p1 - 1;
- pprintf(p, "%s is number %d in parray of size %d\n", player, p1,
+ pprintf(p, "%s is number %d in parray of size %d\n", v_player, p1,
(p_num + 1));
pprintf(p, "name = %s\n", parray[p1].name);
pprintf(p, "login = %s\n", parray[p1].login);
@@ -688,7 +722,8 @@ com_checkGAME(int p, param_list param)
// than that
for (g = 0; g < g_num; g++) {
- multicol_store(m, tmp);
+ memset(tmp, 0, sizeof tmp); // XXX
+ multicol_store(m, tmp); // is this call right?
if (!strcasecmp(garray[g].white_name,
param[0].val.word)) {
@@ -852,13 +887,13 @@ com_checkGAME(int p, param_list param)
PUBLIC int
com_remplayer(int p, param_list param)
{
- char *player = param[0].val.word;
+ char *v_player = param[0].val.word;
char playerlower[MAX_LOGIN_NAME] = { '\0' };
int p1, lookup;
ASSERT(parray[p].adminLevel >= ADMIN_ADMIN);
- mstrlcpy(playerlower, player, sizeof(playerlower));
+ mstrlcpy(playerlower, v_player, sizeof(playerlower));
stolower(playerlower);
p1 = player_new();
lookup = player_read(p1, playerlower);
@@ -876,7 +911,7 @@ com_remplayer(int p, param_list param)
player_remove(p1);
if (lookup) {
- pprintf(p, "No player by the name %s is registered.\n", player);
+ pprintf(p, "No player by the name %s is registered.\n", v_player);
return COM_OK;
}
@@ -886,10 +921,10 @@ com_remplayer(int p, param_list param)
}
if (!player_kill(playerlower)) {
- pprintf(p, "Player %s removed.\n", player);
- UpdateRank(TYPE_BLITZ, NULL, NULL, player);
- UpdateRank(TYPE_STAND, NULL, NULL, player);
- UpdateRank(TYPE_WILD, NULL, NULL, player);
+ pprintf(p, "Player %s removed.\n", v_player);
+ UpdateRank(TYPE_BLITZ, NULL, NULL, v_player);
+ UpdateRank(TYPE_STAND, NULL, NULL, v_player);
+ UpdateRank(TYPE_WILD, NULL, NULL, v_player);
} else {
pprintf(p, "Remplayer failed.\n");
}
@@ -914,14 +949,14 @@ com_remplayer(int p, param_list param)
PUBLIC int
com_raisedead(int p, param_list param)
{
- char *player = param[0].val.word;
+ char *v_player = param[0].val.word;
char newplayerlower[MAX_LOGIN_NAME] = { '\0' };
char playerlower[MAX_LOGIN_NAME] = { '\0' };
int p1, p2, lookup;
ASSERT(parray[p].adminLevel >= ADMIN_ADMIN);
- mstrlcpy(playerlower, player, sizeof playerlower);
+ mstrlcpy(playerlower, v_player, sizeof playerlower);
stolower(playerlower);
if (player_find_bylogin(playerlower) >= 0) {
@@ -936,7 +971,7 @@ com_raisedead(int p, param_list param)
if (!lookup) {
pprintf(p, "A player by the name %s is already registered.\n",
- player);
+ v_player);
pprintf(p, "Obtain a new handle for the dead person.\n");
pprintf(p, "Then use raisedead [oldname] [newname].\n");
return COM_OK;
@@ -944,22 +979,22 @@ com_raisedead(int p, param_list param)
if (param[1].type == TYPE_NULL) {
if (!player_raise(playerlower)) {
- pprintf(p, "Player %s raised from dead.\n", player);
+ pprintf(p, "Player %s raised from dead.\n", v_player);
p1 = player_new();
if (!player_read(p1, playerlower)) {
if (parray[p1].s_stats.rating > 0) {
- UpdateRank(TYPE_STAND, player,
- &parray[p1].s_stats, player);
+ UpdateRank(TYPE_STAND, v_player,
+ &parray[p1].s_stats, v_player);
}
if (parray[p1].b_stats.rating > 0) {
- UpdateRank(TYPE_BLITZ, player,
- &parray[p1].b_stats, player);
+ UpdateRank(TYPE_BLITZ, v_player,
+ &parray[p1].b_stats, v_player);
}
if (parray[p1].w_stats.rating > 0) {
- UpdateRank(TYPE_WILD, player,
- &parray[p1].w_stats, player);
+ UpdateRank(TYPE_WILD, v_player,
+ &parray[p1].w_stats, v_player);
}
}
@@ -988,14 +1023,14 @@ com_raisedead(int p, param_list param)
if (!lookup) {
pprintf(p, "A player by the name %s is already "
- "registered.\n", player);
+ "registered.\n", v_player);
pprintf(p, "Obtain another new handle for the dead "
"person.\n");
return COM_OK;
}
if (!player_reincarn(playerlower, newplayerlower)) {
- pprintf(p, "Player %s reincarnated to %s.\n", player,
+ pprintf(p, "Player %s reincarnated to %s.\n", v_player,
newplayer);
p2 = player_new();
@@ -1518,14 +1553,14 @@ PUBLIC int
com_asethandle(int p, param_list param)
{
char *newplayer = param[1].val.word;
- char *player = param[0].val.word;
+ char *v_player = param[0].val.word;
char newplayerlower[MAX_LOGIN_NAME] = { '\0' };
char playerlower[MAX_LOGIN_NAME] = { '\0' };
int p1;
ASSERT(parray[p].adminLevel >= ADMIN_ADMIN);
- mstrlcpy(playerlower, player, sizeof playerlower);
+ mstrlcpy(playerlower, v_player, sizeof playerlower);
stolower(playerlower);
mstrlcpy(newplayerlower, newplayer, sizeof newplayerlower);
@@ -1544,7 +1579,7 @@ com_asethandle(int p, param_list param)
p1 = player_new();
if (player_read(p1, playerlower)) {
- pprintf(p, "No player by the name %s is registered.\n", player);
+ pprintf(p, "No player by the name %s is registered.\n", v_player);
player_remove(p1);
return COM_OK;
} else {
@@ -1571,22 +1606,22 @@ com_asethandle(int p, param_list param)
if ((!player_rename(playerlower, newplayerlower)) &&
(!player_read(p1, newplayerlower))) {
- pprintf(p, "Player %s renamed to %s.\n", player, newplayer);
+ pprintf(p, "Player %s renamed to %s.\n", v_player, newplayer);
strfree(parray[p1].name);
parray[p1].name = xstrdup(newplayer);
player_save(p1);
if (parray[p1].s_stats.rating > 0) {
UpdateRank(TYPE_STAND, newplayer, &parray[p1].s_stats,
- player);
+ v_player);
}
if (parray[p1].b_stats.rating > 0) {
UpdateRank(TYPE_BLITZ, newplayer, &parray[p1].b_stats,
- player);
+ v_player);
}
if (parray[p1].w_stats.rating > 0) {
UpdateRank(TYPE_WILD, newplayer, &parray[p1].w_stats,
- player);
+ v_player);
}
} else {
pprintf(p, "Asethandle failed.\n");