Secured sprintf with snprintf

This commit is contained in:
Michiel Broek 2005-08-29 19:19:27 +00:00
parent 2d42daa395
commit f6239fe083
4 changed files with 81 additions and 81 deletions

View File

@ -4,7 +4,7 @@
* Purpose ...............: Edit Files DataBase. * Purpose ...............: Edit Files DataBase.
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2004 * Copyright (C) 1999-2005
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -118,7 +118,7 @@ void E_F(long areanr)
clr_index(); clr_index();
sprintf(temp, "%s/var/fdb/file%ld.data", getenv("MBSE_ROOT"), areanr); snprintf(temp, PATH_MAX, "%s/var/fdb/file%ld.data", getenv("MBSE_ROOT"), areanr);
if ((fil = fopen(temp, "r+")) == NULL) { if ((fil = fopen(temp, "r+")) == NULL) {
working(2, 0, 0); working(2, 0, 0);
return; return;
@ -154,7 +154,7 @@ void E_F(long areanr)
set_color(WHITE, BLACK); set_color(WHITE, BLACK);
mbse_mvprintw(y, 1, (char *)"%4d.", o + i); mbse_mvprintw(y, 1, (char *)"%4d.", o + i);
sprintf(temp, "%s/%s", area.Path, fdb.LName); snprintf(temp, PATH_MAX, "%s/%s", area.Path, fdb.LName);
Ondisk = ((stat(temp, &statfile)) != -1); Ondisk = ((stat(temp, &statfile)) != -1);
if (fdb.Deleted) if (fdb.Deleted)
@ -181,7 +181,7 @@ void E_F(long areanr)
} }
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
sprintf(temp, "%s", fdb.Desc[0]); snprintf(temp, 81, "%s", fdb.Desc[0]);
temp[30] = '\0'; temp[30] = '\0';
mbse_mvprintw(y,49, (char *)"%s", temp); mbse_mvprintw(y,49, (char *)"%s", temp);
y++; y++;
@ -190,11 +190,11 @@ void E_F(long areanr)
if (records) if (records)
if (records > 10) if (records > 10)
sprintf(help, "^1..%d^ Edit, ^-^ Return, ^N^/^P^ Page", records); snprintf(help, 81, "^1..%d^ Edit, ^-^ Return, ^N^/^P^ Page", records);
else else
sprintf(help, "^1..%d^ Edit, ^-^ Return", records); snprintf(help, 81, "^1..%d^ Edit, ^-^ Return", records);
else else
sprintf(help, "^-^ Return"); snprintf(help, 81, "^-^ Return");
showhelp(help); showhelp(help);
@ -234,7 +234,7 @@ void E_F(long areanr)
crc = upd_crc32((char *)&fdb, crc, fdbhdr.recsize); crc = upd_crc32((char *)&fdb, crc, fdbhdr.recsize);
o = ((atoi(menu) - 1) / 10) * 10; o = ((atoi(menu) - 1) / 10) * 10;
sprintf(temp, "%s/%s", area.Path, fdb.LName); snprintf(temp, PATH_MAX, "%s/%s", area.Path, fdb.LName);
EditFile(); EditFile();
crc1 = 0xffffffff; crc1 = 0xffffffff;
@ -285,7 +285,7 @@ void EditFDB()
mbse_mvprintw( 5, 4, "14. EDIT FILES DATABSE"); mbse_mvprintw( 5, 4, "14. EDIT FILES DATABSE");
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
if (records != 0) { if (records != 0) {
sprintf(temp, "%s/etc/fareas.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
working(1, 0, 0); working(1, 0, 0);
if ((fil = fopen(temp, "r")) != NULL) { if ((fil = fopen(temp, "r")) != NULL) {
fread(&areahdr, sizeof(areahdr), 1, fil); fread(&areahdr, sizeof(areahdr), 1, fil);
@ -305,7 +305,7 @@ void EditFDB()
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
else else
set_color(LIGHTBLUE, BLACK); set_color(LIGHTBLUE, BLACK);
sprintf(temp, "%3d. %-32s", o + i, area.Name); snprintf(temp, 81, "%3d. %-32s", o + i, area.Name);
temp[37] = 0; temp[37] = 0;
mbse_mvprintw(y, x, temp); mbse_mvprintw(y, x, temp);
y++; y++;
@ -329,7 +329,7 @@ void EditFDB()
o = o - 20; o = o - 20;
if ((atoi(pick) >= 1) && (atoi(pick) <= records)) { if ((atoi(pick) >= 1) && (atoi(pick) <= records)) {
sprintf(temp, "%s/etc/fareas.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
if ((fil = fopen(temp, "r")) != NULL) { if ((fil = fopen(temp, "r")) != NULL) {
offset = areahdr.hdrsize + ((atoi(pick) - 1) * areahdr.recsize); offset = areahdr.hdrsize + ((atoi(pick) - 1) * areahdr.recsize);
fseek(fil, offset, SEEK_SET); fseek(fil, offset, SEEK_SET);
@ -367,19 +367,19 @@ void InitFDB(void)
return; return;
temp = calloc(PATH_MAX, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/etc/fareas.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
if ((fil = fopen(temp, "r")) != NULL) { if ((fil = fopen(temp, "r")) != NULL) {
fread(&areahdr, sizeof(areahdr), 1, fil); fread(&areahdr, sizeof(areahdr), 1, fil);
while (fread(&area, areahdr.recsize, 1, fil)) { while (fread(&area, areahdr.recsize, 1, fil)) {
Area++; Area++;
if (area.Available) { if (area.Available) {
sprintf(temp, "%s/var/fdb/fdb%ld.data", getenv("MBSE_ROOT"), Area); snprintf(temp, PATH_MAX, "%s/var/fdb/fdb%ld.data", getenv("MBSE_ROOT"), Area);
if ((fp1 = fopen(temp, "r")) != NULL) { if ((fp1 = fopen(temp, "r")) != NULL) {
/* /*
* Old area available, upgrade. * Old area available, upgrade.
*/ */
sprintf(temp, "%s/var/fdb/file%ld.data", getenv("MBSE_ROOT"), Area); snprintf(temp, PATH_MAX, "%s/var/fdb/file%ld.data", getenv("MBSE_ROOT"), Area);
if ((fp2 = fopen(temp, "w+")) == NULL) { if ((fp2 = fopen(temp, "w+")) == NULL) {
WriteError("$Can't create %s", temp); WriteError("$Can't create %s", temp);
} else { } else {
@ -392,7 +392,7 @@ void InitFDB(void)
memset(&fdb, 0, fdbhdr.recsize); memset(&fdb, 0, fdbhdr.recsize);
strncpy(fdb.Name, old.Name, sizeof(fdb.Name) -1); strncpy(fdb.Name, old.Name, sizeof(fdb.Name) -1);
strncpy(fdb.LName, old.LName, sizeof(fdb.LName) -1); strncpy(fdb.LName, old.LName, sizeof(fdb.LName) -1);
sprintf(temp, "%s/etc/tic.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/tic.data", getenv("MBSE_ROOT"));
if ((ft = fopen(temp, "r")) != NULL) { if ((ft = fopen(temp, "r")) != NULL) {
fread(&tichdr, sizeof(tichdr), 1, ft); fread(&tichdr, sizeof(tichdr), 1, ft);
while (fread(&tic, tichdr.recsize, 1, ft)) { while (fread(&tic, tichdr.recsize, 1, ft)) {
@ -418,11 +418,11 @@ void InitFDB(void)
/* /*
* Search the magic directory to see if this file is a magic file. * Search the magic directory to see if this file is a magic file.
*/ */
sprintf(temp, "%s", CFG.req_magic); snprintf(temp, 81, "%s", CFG.req_magic);
if ((dp = opendir(temp)) != NULL) { if ((dp = opendir(temp)) != NULL) {
while ((de = readdir(dp))) { while ((de = readdir(dp))) {
if (de->d_name[0] != '.') { if (de->d_name[0] != '.') {
sprintf(temp, "%s/%s", CFG.req_magic, de->d_name); snprintf(temp, PATH_MAX, "%s/%s", CFG.req_magic, de->d_name);
/* /*
* Only regular files without execute permission are magic requests. * Only regular files without execute permission are magic requests.
*/ */
@ -452,7 +452,7 @@ void InitFDB(void)
Syslog('+', "Upgraded file area database %d", Area); Syslog('+', "Upgraded file area database %d", Area);
} }
fclose(fp1); fclose(fp1);
sprintf(temp, "%s/var/fdb/fdb%ld.data", getenv("MBSE_ROOT"), Area); snprintf(temp, PATH_MAX, "%s/var/fdb/fdb%ld.data", getenv("MBSE_ROOT"), Area);
unlink(temp); unlink(temp);
} // Old area type upgrade. } // Old area type upgrade.

View File

@ -4,7 +4,7 @@
* Purpose ...............: Filefind Setup * Purpose ...............: Filefind Setup
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2004 * Copyright (C) 1997-2005
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -53,7 +53,7 @@ int CountFilefind(void)
char ffile[PATH_MAX]; char ffile[PATH_MAX];
int count; int count;
sprintf(ffile, "%s/etc/scanmgr.data", getenv("MBSE_ROOT")); snprintf(ffile, PATH_MAX, "%s/etc/scanmgr.data", getenv("MBSE_ROOT"));
if ((fil = fopen(ffile, "r")) == NULL) { if ((fil = fopen(ffile, "r")) == NULL) {
if ((fil = fopen(ffile, "a+")) != NULL) { if ((fil = fopen(ffile, "a+")) != NULL) {
Syslog('+', "Created new %s", ffile); Syslog('+', "Created new %s", ffile);
@ -89,8 +89,8 @@ int OpenFilefind(void)
char fnin[PATH_MAX], fnout[PATH_MAX]; char fnin[PATH_MAX], fnout[PATH_MAX];
long oldsize; long oldsize;
sprintf(fnin, "%s/etc/scanmgr.data", getenv("MBSE_ROOT")); snprintf(fnin, PATH_MAX, "%s/etc/scanmgr.data", getenv("MBSE_ROOT"));
sprintf(fnout, "%s/etc/scanmgr.temp", getenv("MBSE_ROOT")); snprintf(fnout, PATH_MAX, "%s/etc/scanmgr.temp", getenv("MBSE_ROOT"));
if ((fin = fopen(fnin, "r")) != NULL) { if ((fin = fopen(fnin, "r")) != NULL) {
if ((fout = fopen(fnout, "w")) != NULL) { if ((fout = fopen(fnout, "w")) != NULL) {
fread(&scanmgrhdr, sizeof(scanmgrhdr), 1, fin); fread(&scanmgrhdr, sizeof(scanmgrhdr), 1, fin);
@ -117,7 +117,7 @@ int OpenFilefind(void)
memset(&scanmgr, 0, sizeof(scanmgr)); memset(&scanmgr, 0, sizeof(scanmgr));
while (fread(&scanmgr, oldsize, 1, fin) == 1) { while (fread(&scanmgr, oldsize, 1, fin) == 1) {
if (!strlen(scanmgr.template)) { if (!strlen(scanmgr.template)) {
sprintf(scanmgr.template, "filefind"); snprintf(scanmgr.template, 15, "filefind");
FilefindUpdated = 1; FilefindUpdated = 1;
} }
if (!scanmgr.keywordlen) { if (!scanmgr.keywordlen) {
@ -145,8 +145,8 @@ void CloseFilefind(int force)
FILE *fi, *fo; FILE *fi, *fo;
st_list *fff = NULL, *tmp; st_list *fff = NULL, *tmp;
sprintf(fin, "%s/etc/scanmgr.data", getenv("MBSE_ROOT")); snprintf(fin, PATH_MAX, "%s/etc/scanmgr.data", getenv("MBSE_ROOT"));
sprintf(fout,"%s/etc/scanmgr.temp", getenv("MBSE_ROOT")); snprintf(fout, PATH_MAX, "%s/etc/scanmgr.temp", getenv("MBSE_ROOT"));
if (FilefindUpdated == 1) { if (FilefindUpdated == 1) {
if (force || (yes_no((char *)"Database is changed, save changes") == 1)) { if (force || (yes_no((char *)"Database is changed, save changes") == 1)) {
@ -190,14 +190,14 @@ int AppendFilefind(void)
FILE *fil; FILE *fil;
char ffile[PATH_MAX]; char ffile[PATH_MAX];
sprintf(ffile, "%s/etc/scanmgr.temp", getenv("MBSE_ROOT")); snprintf(ffile, PATH_MAX, "%s/etc/scanmgr.temp", getenv("MBSE_ROOT"));
if ((fil = fopen(ffile, "a")) != NULL) { if ((fil = fopen(ffile, "a")) != NULL) {
memset(&scanmgr, 0, sizeof(scanmgr)); memset(&scanmgr, 0, sizeof(scanmgr));
/* /*
* Fill in default values * Fill in default values
*/ */
scanmgr.Language = 'E'; scanmgr.Language = 'E';
sprintf(scanmgr.template, "filefind"); snprintf(scanmgr.template, 15, "filefind");
strncpy(scanmgr.Origin, CFG.origin, 50); strncpy(scanmgr.Origin, CFG.origin, 50);
scanmgr.keywordlen = 3; scanmgr.keywordlen = 3;
fwrite(&scanmgr, sizeof(scanmgr), 1, fil); fwrite(&scanmgr, sizeof(scanmgr), 1, fil);
@ -247,7 +247,7 @@ int EditFfRec(int Area)
working(1, 0, 0); working(1, 0, 0);
IsDoing("Edit Filefind"); IsDoing("Edit Filefind");
sprintf(mfile, "%s/etc/scanmgr.temp", getenv("MBSE_ROOT")); snprintf(mfile, PATH_MAX, "%s/etc/scanmgr.temp", getenv("MBSE_ROOT"));
if ((fil = fopen(mfile, "r")) == NULL) { if ((fil = fopen(mfile, "r")) == NULL) {
working(2, 0, 0); working(2, 0, 0);
return -1; return -1;
@ -273,7 +273,7 @@ int EditFfRec(int Area)
show_str( 9,18,35, aka2str(scanmgr.Aka)); show_str( 9,18,35, aka2str(scanmgr.Aka));
show_str( 10,18,50, scanmgr.ScanBoard); show_str( 10,18,50, scanmgr.ScanBoard);
show_str( 11,18,50, scanmgr.ReplBoard); show_str( 11,18,50, scanmgr.ReplBoard);
sprintf(temp1, "%c", scanmgr.Language); snprintf(temp1, 2, "%c", scanmgr.Language);
show_str( 12,18,2, temp1); show_str( 12,18,2, temp1);
show_str( 13,18,14, scanmgr.template); show_str( 13,18,14, scanmgr.template);
show_bool(14,18, scanmgr.Active); show_bool(14,18, scanmgr.Active);
@ -359,7 +359,7 @@ void EditFilefind(void)
mbse_mvprintw( 5, 4, "13. FILEFIND AREAS"); mbse_mvprintw( 5, 4, "13. FILEFIND AREAS");
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
if (records != 0) { if (records != 0) {
sprintf(temp, "%s/etc/scanmgr.temp", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/scanmgr.temp", getenv("MBSE_ROOT"));
working(1, 0, 0); working(1, 0, 0);
if ((fil = fopen(temp, "r")) != NULL) { if ((fil = fopen(temp, "r")) != NULL) {
fread(&scanmgrhdr, sizeof(scanmgrhdr), 1, fil); fread(&scanmgrhdr, sizeof(scanmgrhdr), 1, fil);
@ -379,7 +379,7 @@ void EditFilefind(void)
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
else else
set_color(LIGHTBLUE, BLACK); set_color(LIGHTBLUE, BLACK);
sprintf(temp, "%3d. %-32s", o + i, scanmgr.Comment); snprintf(temp, 81, "%3d. %-32s", o + i, scanmgr.Comment);
temp[37] = 0; temp[37] = 0;
mbse_mvprintw(y, x, temp); mbse_mvprintw(y, x, temp);
y++; y++;
@ -436,7 +436,7 @@ int ff_doc(FILE *fp, FILE *toc, int page)
FILE *ti, *wp, *ip, *no; FILE *ti, *wp, *ip, *no;
int refs, nr, i = 0, j; int refs, nr, i = 0, j;
sprintf(temp, "%s/etc/scanmgr.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/scanmgr.data", getenv("MBSE_ROOT"));
if ((no = fopen(temp, "r")) == NULL) if ((no = fopen(temp, "r")) == NULL)
return page; return page;
@ -460,7 +460,7 @@ int ff_doc(FILE *fp, FILE *toc, int page)
j = 0; j = 0;
} }
sprintf(temp, "filefind_%d.html", i); snprintf(temp, 81, "filefind_%d.html", i);
fprintf(ip, " <LI><A HREF=\"%s\">%3d %s</A></LI>\n", temp, i, scanmgr.Comment); fprintf(ip, " <LI><A HREF=\"%s\">%3d %s</A></LI>\n", temp, i, scanmgr.Comment);
if ((wp = open_webdoc(temp, (char *)"Filefind Area", scanmgr.Comment))) { if ((wp = open_webdoc(temp, (char *)"Filefind Area", scanmgr.Comment))) {
fprintf(wp, "<A HREF=\"index.html\">Main</A>&nbsp;<A HREF=\"filefind.html\">Back</A>\n"); fprintf(wp, "<A HREF=\"index.html\">Main</A>&nbsp;<A HREF=\"filefind.html\">Back</A>\n");
@ -473,7 +473,7 @@ int ff_doc(FILE *fp, FILE *toc, int page)
add_webtable(wp, (char *)"Aka to use", aka2str(scanmgr.Aka)); add_webtable(wp, (char *)"Aka to use", aka2str(scanmgr.Aka));
add_webtable(wp, (char *)"Scan msg board", scanmgr.ScanBoard); add_webtable(wp, (char *)"Scan msg board", scanmgr.ScanBoard);
add_webtable(wp, (char *)"Reply msg board", scanmgr.ReplBoard); add_webtable(wp, (char *)"Reply msg board", scanmgr.ReplBoard);
sprintf(temp, "%c", scanmgr.Language); snprintf(temp, 81, "%c", scanmgr.Language);
add_webtable(wp, (char *)"Language", temp); add_webtable(wp, (char *)"Language", temp);
add_webtable(wp, (char *)"Template file", scanmgr.template); add_webtable(wp, (char *)"Template file", scanmgr.template);
add_webtable(wp, (char *)"Active", getboolean(scanmgr.Active)); add_webtable(wp, (char *)"Active", getboolean(scanmgr.Active));
@ -486,7 +486,7 @@ int ff_doc(FILE *fp, FILE *toc, int page)
fprintf(wp, "<HR>\n"); fprintf(wp, "<HR>\n");
fprintf(wp, "<H3>BBS File Areas Reference</H3>\n"); fprintf(wp, "<H3>BBS File Areas Reference</H3>\n");
nr = refs = 0; nr = refs = 0;
sprintf(temp, "%s/etc/fareas.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
if ((ti = fopen(temp, "r"))) { if ((ti = fopen(temp, "r"))) {
fread(&areahdr, sizeof(areahdr), 1, ti); fread(&areahdr, sizeof(areahdr), 1, ti);
while ((fread(&area, areahdr.recsize, 1, ti)) == 1) { while ((fread(&area, areahdr.recsize, 1, ti)) == 1) {

View File

@ -4,7 +4,7 @@
* Purpose ...............: Setup FGroups. * Purpose ...............: Setup FGroups.
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2004 * Copyright (C) 1997-2005
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -56,7 +56,7 @@ int CountFGroup(void)
char ffile[PATH_MAX]; char ffile[PATH_MAX];
int count; int count;
sprintf(ffile, "%s/etc/fgroups.data", getenv("MBSE_ROOT")); snprintf(ffile, PATH_MAX, "%s/etc/fgroups.data", getenv("MBSE_ROOT"));
if ((fil = fopen(ffile, "r")) == NULL) { if ((fil = fopen(ffile, "r")) == NULL) {
if ((fil = fopen(ffile, "a+")) != NULL) { if ((fil = fopen(ffile, "a+")) != NULL) {
Syslog('+', "Created new %s", ffile); Syslog('+', "Created new %s", ffile);
@ -94,8 +94,8 @@ int OpenFGroup(void)
char fnin[PATH_MAX], fnout[PATH_MAX], temp[13]; char fnin[PATH_MAX], fnout[PATH_MAX], temp[13];
long oldsize; long oldsize;
sprintf(fnin, "%s/etc/fgroups.data", getenv("MBSE_ROOT")); snprintf(fnin, PATH_MAX, "%s/etc/fgroups.data", getenv("MBSE_ROOT"));
sprintf(fnout, "%s/etc/fgroups.temp", getenv("MBSE_ROOT")); snprintf(fnout, PATH_MAX, "%s/etc/fgroups.temp", getenv("MBSE_ROOT"));
if ((fin = fopen(fnin, "r")) != NULL) { if ((fin = fopen(fnin, "r")) != NULL) {
if ((fout = fopen(fnout, "w")) != NULL) { if ((fout = fopen(fnout, "w")) != NULL) {
FGrpUpdated = 0; FGrpUpdated = 0;
@ -142,7 +142,7 @@ int OpenFGroup(void)
fgroup.FileId = TRUE; fgroup.FileId = TRUE;
memset(&temp, 0, sizeof(temp)); memset(&temp, 0, sizeof(temp));
strcpy(temp, fgroup.Name); strcpy(temp, fgroup.Name);
sprintf(fgroup.BasePath, "%s/ftp/pub/%s", getenv("MBSE_ROOT"), tl(temp)); snprintf(fgroup.BasePath, 65, "%s/ftp/pub/%s", getenv("MBSE_ROOT"), tl(temp));
} }
if (FGrpUpdated && !fgroup.LinkSec.level) { if (FGrpUpdated && !fgroup.LinkSec.level) {
fgroup.LinkSec.level = 1; fgroup.LinkSec.level = 1;
@ -170,8 +170,8 @@ void CloseFGroup(int force)
FILE *fi, *fo; FILE *fi, *fo;
st_list *fgr = NULL, *tmp; st_list *fgr = NULL, *tmp;
sprintf(fin, "%s/etc/fgroups.data", getenv("MBSE_ROOT")); snprintf(fin, PATH_MAX, "%s/etc/fgroups.data", getenv("MBSE_ROOT"));
sprintf(fout,"%s/etc/fgroups.temp", getenv("MBSE_ROOT")); snprintf(fout, PATH_MAX, "%s/etc/fgroups.temp", getenv("MBSE_ROOT"));
if (FGrpUpdated == 1) { if (FGrpUpdated == 1) {
if (force || (yes_no((char *)"Database is changed, save changes") == 1)) { if (force || (yes_no((char *)"Database is changed, save changes") == 1)) {
@ -216,7 +216,7 @@ int AppendFGroup(void)
FILE *fil; FILE *fil;
char ffile[PATH_MAX]; char ffile[PATH_MAX];
sprintf(ffile, "%s/etc/fgroups.temp", getenv("MBSE_ROOT")); snprintf(ffile, PATH_MAX, "%s/etc/fgroups.temp", getenv("MBSE_ROOT"));
if ((fil = fopen(ffile, "a")) != NULL) { if ((fil = fopen(ffile, "a")) != NULL) {
memset(&fgroup, 0, sizeof(fgroup)); memset(&fgroup, 0, sizeof(fgroup));
fgroup.StartDate = time(NULL); fgroup.StartDate = time(NULL);
@ -317,7 +317,7 @@ int EditFGrpRec(int Area)
working(1, 0, 0); working(1, 0, 0);
IsDoing("Edit FileGroup"); IsDoing("Edit FileGroup");
sprintf(mfile, "%s/etc/fgroups.temp", getenv("MBSE_ROOT")); snprintf(mfile, PATH_MAX, "%s/etc/fgroups.temp", getenv("MBSE_ROOT"));
if ((fil = fopen(mfile, "r")) == NULL) { if ((fil = fopen(mfile, "r")) == NULL) {
working(2, 0, 0); working(2, 0, 0);
return -1; return -1;
@ -407,7 +407,7 @@ int EditFGrpRec(int Area)
if (isupper(temp[i])) if (isupper(temp[i]))
temp[i] = tolower(temp[i]); temp[i] = tolower(temp[i]);
} }
sprintf(fgroup.BasePath, "%s/%s", CFG.ftp_base, temp); snprintf(fgroup.BasePath, 65, "%s/%s", CFG.ftp_base, temp);
} }
if (strlen(fgroup.BbsGroup) == 0) if (strlen(fgroup.BbsGroup) == 0)
strcpy(fgroup.BbsGroup, fgroup.Name); strcpy(fgroup.BbsGroup, fgroup.Name);
@ -515,7 +515,7 @@ void EditFGroup(void)
mbse_mvprintw( 5, 4, "10.1 FILE GROUPS SETUP"); mbse_mvprintw( 5, 4, "10.1 FILE GROUPS SETUP");
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
if (records != 0) { if (records != 0) {
sprintf(temp, "%s/etc/fgroups.temp", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/fgroups.temp", getenv("MBSE_ROOT"));
working(1, 0, 0); working(1, 0, 0);
if ((fil = fopen(temp, "r")) != NULL) { if ((fil = fopen(temp, "r")) != NULL) {
fread(&fgrouphdr, sizeof(fgrouphdr), 1, fil); fread(&fgrouphdr, sizeof(fgrouphdr), 1, fil);
@ -535,7 +535,7 @@ void EditFGroup(void)
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
else else
set_color(LIGHTBLUE, BLACK); set_color(LIGHTBLUE, BLACK);
sprintf(temp, "%3d. %-12s %-18s", o + i, fgroup.Name, fgroup.Comment); snprintf(temp, 81, "%3d. %-12s %-18s", o + i, fgroup.Name, fgroup.Comment);
temp[38] = '\0'; temp[38] = '\0';
mbse_mvprintw(y, x, temp); mbse_mvprintw(y, x, temp);
y++; y++;
@ -618,11 +618,11 @@ char *PickFGroup(char *shdr)
for (;;) { for (;;) {
clr_index(); clr_index();
set_color(WHITE, BLACK); set_color(WHITE, BLACK);
sprintf(temp, "%s. FILE GROUP SELECT", shdr); snprintf(temp, 81, "%s. FILE GROUP SELECT", shdr);
mbse_mvprintw( 5, 4, temp); mbse_mvprintw( 5, 4, temp);
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
if (records != 0) { if (records != 0) {
sprintf(temp, "%s/etc/fgroups.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/fgroups.data", getenv("MBSE_ROOT"));
working(1, 0, 0); working(1, 0, 0);
if ((fil = fopen(temp, "r")) != NULL) { if ((fil = fopen(temp, "r")) != NULL) {
fread(&fgrouphdr, sizeof(fgrouphdr), 1, fil); fread(&fgrouphdr, sizeof(fgrouphdr), 1, fil);
@ -642,7 +642,7 @@ char *PickFGroup(char *shdr)
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
else else
set_color(LIGHTBLUE, BLACK); set_color(LIGHTBLUE, BLACK);
sprintf(temp, "%3d. %-12s %-18s", o + i, fgroup.Name, fgroup.Comment); snprintf(temp, 81, "%3d. %-12s %-18s", o + i, fgroup.Name, fgroup.Comment);
temp[38] = '\0'; temp[38] = '\0';
mbse_mvprintw(y, x, temp); mbse_mvprintw(y, x, temp);
y++; y++;
@ -666,7 +666,7 @@ char *PickFGroup(char *shdr)
o = o - 20; o = o - 20;
if ((atoi(pick) >= 1) && (atoi(pick) <= records)) { if ((atoi(pick) >= 1) && (atoi(pick) <= records)) {
sprintf(temp, "%s/etc/fgroups.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/fgroups.data", getenv("MBSE_ROOT"));
fil = fopen(temp, "r"); fil = fopen(temp, "r");
offset = fgrouphdr.hdrsize + ((atoi(pick) - 1) * fgrouphdr.recsize); offset = fgrouphdr.hdrsize + ((atoi(pick) - 1) * fgrouphdr.recsize);
fseek(fil, offset, 0); fseek(fil, offset, 0);
@ -687,7 +687,7 @@ int tic_group_doc(FILE *fp, FILE *toc, int page)
int refs, i, First = TRUE;; int refs, i, First = TRUE;;
temp = calloc(PATH_MAX, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/etc/fgroups.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/fgroups.data", getenv("MBSE_ROOT"));
if ((no = fopen(temp, "r")) == NULL) { if ((no = fopen(temp, "r")) == NULL) {
free(temp); free(temp);
return page; return page;
@ -714,7 +714,7 @@ int tic_group_doc(FILE *fp, FILE *toc, int page)
fprintf(fp, "\n\n"); fprintf(fp, "\n\n");
} }
sprintf(temp, "filegroup_%s.html", fgroup.Name); snprintf(temp, 81, "filegroup_%s.html", fgroup.Name);
fprintf(ip, " <TR><TD><A HREF=\"%s\">%s</A></TD><TD>%s</TD><TD>%s</TD></TR>\n", fprintf(ip, " <TR><TD><A HREF=\"%s\">%s</A></TD><TD>%s</TD><TD>%s</TD></TR>\n",
temp, fgroup.Name, fgroup.Comment, getboolean(fgroup.Active)); temp, fgroup.Name, fgroup.Comment, getboolean(fgroup.Active));
@ -730,7 +730,7 @@ int tic_group_doc(FILE *fp, FILE *toc, int page)
add_webtable(wp, (char *)"Use Aka", aka2str(fgroup.UseAka)); add_webtable(wp, (char *)"Use Aka", aka2str(fgroup.UseAka));
add_webtable(wp, (char *)"Uplink Aka", aka2str(fgroup.UpLink)); add_webtable(wp, (char *)"Uplink Aka", aka2str(fgroup.UpLink));
add_webtable(wp, (char *)"Areas file", fgroup.AreaFile); add_webtable(wp, (char *)"Areas file", fgroup.AreaFile);
sprintf(temp, "%ld", fgroup.StartArea); snprintf(temp, 81, "%ld", fgroup.StartArea);
add_webtable(wp, (char *)"Start autocreate BBS area", temp); add_webtable(wp, (char *)"Start autocreate BBS area", temp);
add_webtable(wp, (char *)"Banner file", fgroup.Banner); add_webtable(wp, (char *)"Banner file", fgroup.Banner);
add_webtable(wp, (char *)"Default archiver", fgroup.Convert); add_webtable(wp, (char *)"Default archiver", fgroup.Convert);
@ -756,7 +756,7 @@ int tic_group_doc(FILE *fp, FILE *toc, int page)
fgroup.BbsGroup, fgroup.BbsGroup); fgroup.BbsGroup, fgroup.BbsGroup);
fprintf(wp, "<TR><TH align='left'>Newfiles announce group</TH><TD><A HREF=\"newgroup.html\">%s</A></TD></TH>\n", fprintf(wp, "<TR><TH align='left'>Newfiles announce group</TH><TD><A HREF=\"newgroup.html\">%s</A></TD></TH>\n",
fgroup.AnnGroup); fgroup.AnnGroup);
sprintf(temp, "%d", fgroup.Upload); snprintf(temp, 81, "%d", fgroup.Upload);
add_webtable(wp, (char *)"Upload area", temp); add_webtable(wp, (char *)"Upload area", temp);
add_webtable(wp, (char *)"Start date", ctime(&fgroup.StartDate)); add_webtable(wp, (char *)"Start date", ctime(&fgroup.StartDate));
add_webtable(wp, (char *)"Last active date", ctime(&fgroup.LastDate)); add_webtable(wp, (char *)"Last active date", ctime(&fgroup.LastDate));
@ -765,7 +765,7 @@ int tic_group_doc(FILE *fp, FILE *toc, int page)
fprintf(wp, "<HR>\n"); fprintf(wp, "<HR>\n");
fprintf(wp, "<H3>BBS File Areas Reference</H3>\n"); fprintf(wp, "<H3>BBS File Areas Reference</H3>\n");
i = refs = 0; i = refs = 0;
sprintf(temp, "%s/etc/fareas.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
if ((ti = fopen(temp, "r"))) { if ((ti = fopen(temp, "r"))) {
fread(&areahdr, sizeof(areahdr), 1, ti); fread(&areahdr, sizeof(areahdr), 1, ti);
while ((fread(&area, areahdr.recsize, 1, ti)) == 1) { while ((fread(&area, areahdr.recsize, 1, ti)) == 1) {
@ -791,7 +791,7 @@ int tic_group_doc(FILE *fp, FILE *toc, int page)
fprintf(wp, "<HR>\n"); fprintf(wp, "<HR>\n");
fprintf(wp, "<H3>TIC Areas Reference</H3>\n"); fprintf(wp, "<H3>TIC Areas Reference</H3>\n");
refs = 0; refs = 0;
sprintf(temp, "%s/etc/tic.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/tic.data", getenv("MBSE_ROOT"));
if ((ti = fopen(temp, "r"))) { if ((ti = fopen(temp, "r"))) {
fread(&tichdr, sizeof(tichdr), 1, ti); fread(&tichdr, sizeof(tichdr), 1, ti);
fseek(ti, 0, SEEK_SET); fseek(ti, 0, SEEK_SET);
@ -820,7 +820,7 @@ int tic_group_doc(FILE *fp, FILE *toc, int page)
fprintf(wp, "<HR>\n"); fprintf(wp, "<HR>\n");
fprintf(wp, "<H3>Nodes Reference</H3>\n"); fprintf(wp, "<H3>Nodes Reference</H3>\n");
refs = 0; refs = 0;
sprintf(temp, "%s/etc/nodes.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/nodes.data", getenv("MBSE_ROOT"));
if ((ti = fopen(temp, "r"))) { if ((ti = fopen(temp, "r"))) {
fread(&nodeshdr, sizeof(nodeshdr), 1, ti); fread(&nodeshdr, sizeof(nodeshdr), 1, ti);
fseek(ti, 0, SEEK_SET); fseek(ti, 0, SEEK_SET);

View File

@ -4,7 +4,7 @@
* Purpose ...............: Setup Fidonet structure. * Purpose ...............: Setup Fidonet structure.
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2004 * Copyright (C) 1997-2005
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -53,7 +53,7 @@ int CountFidonet(void)
char ffile[PATH_MAX]; char ffile[PATH_MAX];
int count; int count;
sprintf(ffile, "%s/etc/fidonet.data", getenv("MBSE_ROOT")); snprintf(ffile, PATH_MAX, "%s/etc/fidonet.data", getenv("MBSE_ROOT"));
if ((fil = fopen(ffile, "r")) == NULL) { if ((fil = fopen(ffile, "r")) == NULL) {
if ((fil = fopen(ffile, "a+")) != NULL) { if ((fil = fopen(ffile, "a+")) != NULL) {
Syslog('+', "Created new %s", ffile); Syslog('+', "Created new %s", ffile);
@ -64,10 +64,10 @@ int CountFidonet(void)
* Fill in the defaults * Fill in the defaults
*/ */
memset(&fidonet, 0, sizeof(fidonet)); memset(&fidonet, 0, sizeof(fidonet));
sprintf(fidonet.comment, "Fidonet network"); snprintf(fidonet.comment, 41, "Fidonet network");
sprintf(fidonet.domain, "fidonet"); snprintf(fidonet.domain, 13, "fidonet");
sprintf(fidonet.nodelist, "NODELIST"); snprintf(fidonet.nodelist, 9, "NODELIST");
sprintf(fidonet.seclist[0].nodelist, "REGION28"); snprintf(fidonet.seclist[0].nodelist, 9, "REGION28");
fidonet.seclist[0].zone = 2; fidonet.seclist[0].zone = 2;
fidonet.seclist[0].net = 28; fidonet.seclist[0].net = 28;
fidonet.zone[0] = 2; fidonet.zone[0] = 2;
@ -108,8 +108,8 @@ int OpenFidonet(void)
char fnin[PATH_MAX], fnout[PATH_MAX]; char fnin[PATH_MAX], fnout[PATH_MAX];
long oldsize; long oldsize;
sprintf(fnin, "%s/etc/fidonet.data", getenv("MBSE_ROOT")); snprintf(fnin, PATH_MAX, "%s/etc/fidonet.data", getenv("MBSE_ROOT"));
sprintf(fnout, "%s/etc/fidonet.temp", getenv("MBSE_ROOT")); snprintf(fnout, PATH_MAX, "%s/etc/fidonet.temp", getenv("MBSE_ROOT"));
if ((fin = fopen(fnin, "r")) != NULL) { if ((fin = fopen(fnin, "r")) != NULL) {
if ((fout = fopen(fnout, "w")) != NULL) { if ((fout = fopen(fnout, "w")) != NULL) {
fread(&fidonethdr, sizeof(fidonethdr), 1, fin); fread(&fidonethdr, sizeof(fidonethdr), 1, fin);
@ -157,8 +157,8 @@ void CloseFidonet(int force)
FILE *fi, *fo; FILE *fi, *fo;
st_list *fid = NULL, *tmp; st_list *fid = NULL, *tmp;
sprintf(fin, "%s/etc/fidonet.data", getenv("MBSE_ROOT")); snprintf(fin, PATH_MAX, "%s/etc/fidonet.data", getenv("MBSE_ROOT"));
sprintf(fout,"%s/etc/fidonet.temp", getenv("MBSE_ROOT")); snprintf(fout, PATH_MAX, "%s/etc/fidonet.temp", getenv("MBSE_ROOT"));
if (FidoUpdated == 1) { if (FidoUpdated == 1) {
if (force || (yes_no((char *)"Database is changed, save changes") == 1)) { if (force || (yes_no((char *)"Database is changed, save changes") == 1)) {
@ -171,7 +171,7 @@ void CloseFidonet(int force)
while (fread(&fidonet, fidonethdr.recsize, 1, fi) == 1) while (fread(&fidonet, fidonethdr.recsize, 1, fi) == 1)
if (!fidonet.deleted) { if (!fidonet.deleted) {
sprintf(temp, "%05d", fidonet.zone[0]); snprintf(temp, 10, "%05d", fidonet.zone[0]);
fill_stlist(&fid, temp, ftell(fi) - fidonethdr.recsize); fill_stlist(&fid, temp, ftell(fi) - fidonethdr.recsize);
} }
sort_stlist(&fid); sort_stlist(&fid);
@ -206,7 +206,7 @@ int AppendFidonet(void)
FILE *fil; FILE *fil;
char ffile[PATH_MAX]; char ffile[PATH_MAX];
sprintf(ffile, "%s/etc/fidonet.temp", getenv("MBSE_ROOT")); snprintf(ffile, PATH_MAX, "%s/etc/fidonet.temp", getenv("MBSE_ROOT"));
if ((fil = fopen(ffile, "a")) != NULL) { if ((fil = fopen(ffile, "a")) != NULL) {
memset(&fidonet, 0, sizeof(fidonet)); memset(&fidonet, 0, sizeof(fidonet));
fwrite(&fidonet, sizeof(fidonet), 1, fil); fwrite(&fidonet, sizeof(fidonet), 1, fil);
@ -234,7 +234,7 @@ int EditFidoRec(int Area)
working(1, 0, 0); working(1, 0, 0);
IsDoing("Edit Fidonet"); IsDoing("Edit Fidonet");
sprintf(mfile, "%s/etc/fidonet.temp", getenv("MBSE_ROOT")); snprintf(mfile, PATH_MAX, "%s/etc/fidonet.temp", getenv("MBSE_ROOT"));
if ((fil = fopen(mfile, "r")) == NULL) { if ((fil = fopen(mfile, "r")) == NULL) {
working(2, 0, 0); working(2, 0, 0);
return -1; return -1;
@ -283,7 +283,7 @@ int EditFidoRec(int Area)
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
if ((fidonet.seclist[i].zone) || strlen(fidonet.seclist[i].nodelist)) { if ((fidonet.seclist[i].zone) || strlen(fidonet.seclist[i].nodelist)) {
show_str(i + 12,26,8, fidonet.seclist[i].nodelist); show_str(i + 12,26,8, fidonet.seclist[i].nodelist);
sprintf(temp, "%d:%d/%d", fidonet.seclist[i].zone, fidonet.seclist[i].net, fidonet.seclist[i].node); snprintf(temp, 18, "%d:%d/%d", fidonet.seclist[i].zone, fidonet.seclist[i].net, fidonet.seclist[i].node);
show_str(i + 12, 36,17, temp); show_str(i + 12, 36,17, temp);
} else } else
show_str(i + 12,26,27, (char *)" "); show_str(i + 12,26,27, (char *)" ");
@ -341,7 +341,7 @@ int EditFidoRec(int Area)
(char *)"The secondary ^nodelist^ or ^pointlist^ name for this domain")); (char *)"The secondary ^nodelist^ or ^pointlist^ name for this domain"));
if (strlen(fidonet.seclist[j-6].nodelist)) { if (strlen(fidonet.seclist[j-6].nodelist)) {
do { do {
sprintf(temp, "%d:%d/%d", fidonet.seclist[j-6].zone, snprintf(temp, 18, "%d:%d/%d", fidonet.seclist[j-6].zone,
fidonet.seclist[j-6].net, fidonet.seclist[j-6].node); fidonet.seclist[j-6].net, fidonet.seclist[j-6].node);
strcpy(temp, edit_str(j+6,36,17, temp, strcpy(temp, edit_str(j+6,36,17, temp,
(char *)"The top ^fidonet aka^ for this nodelist (zone:net/node)")); (char *)"The top ^fidonet aka^ for this nodelist (zone:net/node)"));
@ -408,7 +408,7 @@ void EditFidonet(void)
mbse_mvprintw( 5, 4, "2. FIDONET SETUP"); mbse_mvprintw( 5, 4, "2. FIDONET SETUP");
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
if (records != 0) { if (records != 0) {
sprintf(temp, "%s/etc/fidonet.temp", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/fidonet.temp", getenv("MBSE_ROOT"));
if ((fil = fopen(temp, "r")) != NULL) { if ((fil = fopen(temp, "r")) != NULL) {
fread(&fidonethdr, sizeof(fidonethdr), 1, fil); fread(&fidonethdr, sizeof(fidonethdr), 1, fil);
x = 2; x = 2;
@ -426,7 +426,7 @@ void EditFidonet(void)
x = 42; x = 42;
y = 7; y = 7;
} }
sprintf(temp, "%3d. z%d: %-32s", i, fidonet.zone[0], fidonet.comment); snprintf(temp, 81, "%3d. z%d: %-32s", i, fidonet.zone[0], fidonet.comment);
temp[38] = 0; temp[38] = 0;
mbse_mvprintw(y, x, temp); mbse_mvprintw(y, x, temp);
y++; y++;
@ -474,7 +474,7 @@ void gold_akamatch(FILE *fp)
faddr *want, *ta; faddr *want, *ta;
int i; int i;
sprintf(temp, "%s/etc/fidonet.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/fidonet.data", getenv("MBSE_ROOT"));
if ((fido = fopen(temp, "r")) == NULL) if ((fido = fopen(temp, "r")) == NULL)
return; return;
@ -533,7 +533,7 @@ int fido_doc(FILE *fp, FILE *toc, int page)
FILE *wp, *ip, *fido; FILE *wp, *ip, *fido;
int i, j; int i, j;
sprintf(temp, "%s/etc/fidonet.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/fidonet.data", getenv("MBSE_ROOT"));
if ((fido = fopen(temp, "r")) == NULL) if ((fido = fopen(temp, "r")) == NULL)
return page; return page;
@ -558,7 +558,7 @@ int fido_doc(FILE *fp, FILE *toc, int page)
j = 0; j = 0;
} }
sprintf(temp, "fidonet_%d.html", fidonet.zone[0]); snprintf(temp, 81, "fidonet_%d.html", fidonet.zone[0]);
fprintf(ip, " <TR><TD><A HREF=\"%s\">%d</A></TD><TD>%s</TD><TD>%s</TD></TR>\n", fprintf(ip, " <TR><TD><A HREF=\"%s\">%d</A></TD><TD>%s</TD><TD>%s</TD></TR>\n",
temp, fidonet.zone[0], fidonet.comment, getboolean(fidonet.available)); temp, fidonet.zone[0], fidonet.comment, getboolean(fidonet.available));
@ -574,14 +574,14 @@ int fido_doc(FILE *fp, FILE *toc, int page)
add_webtable(wp, (char *)"Nodelist", fidonet.nodelist); add_webtable(wp, (char *)"Nodelist", fidonet.nodelist);
for (i = 0; i < 6; i++) for (i = 0; i < 6; i++)
if (strlen(fidonet.seclist[i].nodelist) || fidonet.seclist[i].zone) { if (strlen(fidonet.seclist[i].nodelist) || fidonet.seclist[i].zone) {
sprintf(temp, "%d %-8s %d:%d/%d", i+1, fidonet.seclist[i].nodelist, fidonet.seclist[i].zone, snprintf(temp, 81, "%d %-8s %d:%d/%d", i+1, fidonet.seclist[i].nodelist, fidonet.seclist[i].zone,
fidonet.seclist[i].net, fidonet.seclist[i].node); fidonet.seclist[i].net, fidonet.seclist[i].node);
add_webtable(wp, (char *)"Merge list", temp); add_webtable(wp, (char *)"Merge list", temp);
} }
sprintf(temp, "%d", fidonet.zone[0]); snprintf(temp, 81, "%d", fidonet.zone[0]);
for (i = 1; i < 6; i++) for (i = 1; i < 6; i++)
if (fidonet.zone[i]) if (fidonet.zone[i])
sprintf(temp, "%s %d", temp, fidonet.zone[i]); snprintf(temp, 81, "%s %d", temp, fidonet.zone[i]);
add_webtable(wp, (char *)"Zone(s)", temp); add_webtable(wp, (char *)"Zone(s)", temp);
fprintf(wp, "</TBODY>\n"); fprintf(wp, "</TBODY>\n");
fprintf(wp, "</TABLE>\n"); fprintf(wp, "</TABLE>\n");