diff --git a/ChangeLog b/ChangeLog index 92360810..c9e36a16 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ v0.35.03 06-Jul-2002 common.a: Added nodelist override to the nodelist lookup function. + Added protection against emty rfc headers with only a space. lang: Corrected a spelling error in the Dutch language file. @@ -17,6 +18,10 @@ v0.35.03 06-Jul-2002 mbout: Makes use of the node nodelist override settings. + mbfido: + Rollover now only sets IsDoing when it really does a date + rollover. + newuser: Check for Unix accounts is now case sensitive. Check existing usernames now also checks handles. diff --git a/lib/rfcmsg.c b/lib/rfcmsg.c index e52d3fe3..fbc61b7a 100644 --- a/lib/rfcmsg.c +++ b/lib/rfcmsg.c @@ -129,6 +129,10 @@ rfcmsg *parsrfc(FILE *fp) Syslog('!', "Header line %s without key value", buffer); cur->key = xstrcpy(buffer); cur->val = xstrcpy((char *)" "); + } else if ((p=strchr(buffer,':')) && (p > buffer) && isspace(*(p+1))) { /* space past ':' */ + Syslog('!', "Header line %s without key value (but with a Space)", buffer); + cur->key = xstrcpy(buffer); + cur->val = xstrcpy((char *)" "); } else { Syslog('M', "Non-header line: \"%s\"",buffer); cur->key = xstrcpy((char *)"X-Body-Start"); diff --git a/mbfido/rollover.c b/mbfido/rollover.c index ae89cf80..fae51e8a 100644 --- a/mbfido/rollover.c +++ b/mbfido/rollover.c @@ -44,10 +44,10 @@ extern int do_quiet; void StatAdd(statcnt *S, unsigned long V) { - S->total += V; - S->tweek += V; - S->tdow[Diw] += V; - S->month[Miy] += V; + S->total += V; + S->tweek += V; + S->tdow[Diw] += V; + S->month[Miy] += V; } @@ -55,18 +55,18 @@ void StatAdd(statcnt *S, unsigned long V) void RollWeek(statcnt *); void RollWeek(statcnt *S) { - int i; + int i; - for (i = 0; i < 7; i++) { - S->ldow[i] = S->tdow[i]; - S->tdow[i] = 0L; - } + for (i = 0; i < 7; i++) { + S->ldow[i] = S->tdow[i]; + S->tdow[i] = 0L; + } - S->lweek = S->tweek; - S->tweek = 0L; + S->lweek = S->tweek; + S->tweek = 0L; - if (CFG.slow_util && do_quiet) - usleep(1); + if (CFG.slow_util && do_quiet) + usleep(1); } @@ -74,20 +74,20 @@ void RollWeek(statcnt *S) FILE *OpenData(char *); FILE *OpenData(char *Name) { - char *temp; - FILE *fp; + char *temp; + FILE *fp; - temp = calloc(128, sizeof(char)); - - sprintf(temp, "%s/etc/%s", getenv("MBSE_ROOT"), Name); - if ((fp = fopen(temp, "r+")) == NULL) { - WriteError("$Can't open %s", temp); - free(temp); - return NULL; - } + temp = calloc(PATH_MAX, sizeof(char)); + sprintf(temp, "%s/etc/%s", getenv("MBSE_ROOT"), Name); + if ((fp = fopen(temp, "r+")) == NULL) { + WriteError("$Can't open %s", temp); free(temp); - return fp; + return NULL; + } + + free(temp); + return fp; } @@ -99,328 +99,328 @@ FILE *OpenData(char *Name) */ void Rollover() { - time_t Now, Temp; - struct tm *t; - FILE *fp, *ft; - int do_week, do_month, Day, i; - char *temp, *temp1; - struct _history history; + time_t Now, Temp; + struct tm *t; + FILE *fp, *ft; + int do_week, do_month, Day, i; + char *temp, *temp1; + struct _history history; - IsDoing("Date rollover"); - Now = time(NULL); - t = localtime(&Now); + Now = time(NULL); + t = localtime(&Now); - Diw = t->tm_wday; - Miy = t->tm_mon; - Day = t->tm_yday; + Diw = t->tm_wday; + Miy = t->tm_mon; + Day = t->tm_yday; - if ((fp = OpenData((char *)"nodes.data")) != NULL) { - fread(&nodeshdr, sizeof(nodeshdr), 1, fp); - Temp = nodeshdr.lastupd; - t = localtime(&Temp); + if ((fp = OpenData((char *)"nodes.data")) != NULL) { + fread(&nodeshdr, sizeof(nodeshdr), 1, fp); + Temp = nodeshdr.lastupd; + t = localtime(&Temp); - /* - * Test if it's sunday, and the last update wasn't today. - * If it's not sunday, and the last update was more then - * 7 days ago, we maybe missed last sunday and the update - * is still done. - */ - if (((Diw == 0) && (Day != t->tm_yday)) || ((Day - t->tm_yday) > 7)) - do_week = TRUE; - else - do_week = FALSE; + /* + * Test if it's sunday, and the last update wasn't today. + * If it's not sunday, and the last update was more then + * 7 days ago, we maybe missed last sunday and the update + * is still done. + */ + if (((Diw == 0) && (Day != t->tm_yday)) || ((Day - t->tm_yday) > 7)) + do_week = TRUE; + else + do_week = FALSE; - /* - * If the month is different then the last update, we must - * be in a new month. - */ - if (Miy != t->tm_mon) - do_month = TRUE; - else - do_month = FALSE; + /* + * If the month is different then the last update, we must + * be in a new month. + */ + if (Miy != t->tm_mon) + do_month = TRUE; + else + do_month = FALSE; - if (do_week || do_month) { - Syslog('+', "Rollover nodes.data"); + if (do_week || do_month) { + IsDoing("Date rollover"); + Syslog('+', "Rollover nodes.data"); - while (fread(&nodes, nodeshdr.recsize, 1, fp) == 1) { - if (do_week) { - RollWeek(&nodes.FilesSent); - RollWeek(&nodes.FilesRcvd); - RollWeek(&nodes.F_KbSent); - RollWeek(&nodes.F_KbRcvd); - RollWeek(&nodes.MailSent); - RollWeek(&nodes.MailRcvd); - } - if (do_month) { - nodes.FilesSent.month[Miy] = 0; - nodes.FilesRcvd.month[Miy] = 0; - nodes.F_KbSent.month[Miy] = 0; - nodes.F_KbRcvd.month[Miy] = 0; - nodes.MailSent.month[Miy] = 0; - nodes.MailRcvd.month[Miy] = 0; - if (CFG.slow_util && do_quiet) - usleep(1); - } - fseek(fp, - nodeshdr.recsize, SEEK_CUR); - fwrite(&nodes, nodeshdr.recsize, 1, fp); - fseek(fp, nodeshdr.filegrp + nodeshdr.mailgrp, SEEK_CUR); - } - - fseek(fp, 0, SEEK_SET); - nodeshdr.lastupd = time(NULL); - fwrite(&nodeshdr, nodeshdr.hdrsize, 1, fp); + while (fread(&nodes, nodeshdr.recsize, 1, fp) == 1) { + if (do_week) { + RollWeek(&nodes.FilesSent); + RollWeek(&nodes.FilesRcvd); + RollWeek(&nodes.F_KbSent); + RollWeek(&nodes.F_KbRcvd); + RollWeek(&nodes.MailSent); + RollWeek(&nodes.MailRcvd); } + if (do_month) { + nodes.FilesSent.month[Miy] = 0; + nodes.FilesRcvd.month[Miy] = 0; + nodes.F_KbSent.month[Miy] = 0; + nodes.F_KbRcvd.month[Miy] = 0; + nodes.MailSent.month[Miy] = 0; + nodes.MailRcvd.month[Miy] = 0; + if (CFG.slow_util && do_quiet) + usleep(1); + } + fseek(fp, - nodeshdr.recsize, SEEK_CUR); + fwrite(&nodes, nodeshdr.recsize, 1, fp); + fseek(fp, nodeshdr.filegrp + nodeshdr.mailgrp, SEEK_CUR); + } + fseek(fp, 0, SEEK_SET); + nodeshdr.lastupd = time(NULL); + fwrite(&nodeshdr, nodeshdr.hdrsize, 1, fp); + } + + fclose(fp); + } + + if ((fp = OpenData((char *)"mareas.data")) != NULL) { + fread(&msgshdr, sizeof(msgshdr), 1, fp); + Temp = msgshdr.lastupd; + t = localtime(&Temp); + + if (((Diw == 0) && (Day != t->tm_yday)) || ((Day - t->tm_yday) > 7)) + do_week = TRUE; + else + do_week = FALSE; + if (Miy != t->tm_mon) + do_month = TRUE; + else + do_month = FALSE; + + if (do_week || do_month) { + Syslog('+', "Rollover mareas.data"); + + while (fread(&msgs, msgshdr.recsize, 1, fp) == 1) { + if (do_week) { + RollWeek(&msgs.Received); + RollWeek(&msgs.Posted); + } + if (do_month) { + msgs.Received.month[Miy] = 0; + msgs.Posted.month[Miy] = 0; + if (CFG.slow_util && do_quiet) + usleep(1); + } + fseek(fp, - msgshdr.recsize, SEEK_CUR); + fwrite(&msgs, msgshdr.recsize, 1, fp); + fseek(fp, msgshdr.syssize, SEEK_CUR); + } + + msgshdr.lastupd = time(NULL); + fseek(fp, 0, SEEK_SET); + fwrite(&msgshdr, msgshdr.hdrsize, 1, fp); + } + fclose(fp); + } + + if ((fp = OpenData((char *)"mgroups.data")) != NULL) { + fread(&mgrouphdr, sizeof(mgrouphdr), 1, fp); + Temp = mgrouphdr.lastupd; + t = localtime(&Temp); + + if (((Diw == 0) && (Day != t->tm_yday)) || ((Day - t->tm_yday) > 7)) + do_week = TRUE; + else + do_week = FALSE; + if (Miy != t->tm_mon) + do_month = TRUE; + else + do_month = FALSE; + + if (do_week || do_month) { + Syslog('+', "Rollover mgroups.data"); + + while (fread(&mgroup, mgrouphdr.recsize, 1, fp) == 1) { + if (do_week) { + RollWeek(&mgroup.MsgsRcvd); + RollWeek(&mgroup.MsgsSent); + } + if (do_month) { + mgroup.MsgsRcvd.month[Miy] = 0; + mgroup.MsgsSent.month[Miy] = 0; + if (CFG.slow_util && do_quiet) + usleep(1); + } + fseek(fp, - mgrouphdr.recsize, SEEK_CUR); + fwrite(&mgroup, mgrouphdr.recsize, 1, fp); + } + + mgrouphdr.lastupd = time(NULL); + fseek(fp, 0, SEEK_SET); + fwrite(&mgrouphdr, mgrouphdr.hdrsize, 1, fp); + } + fclose(fp); + } + + if ((fp = OpenData((char *)"tic.data")) != NULL) { + fread(&tichdr, sizeof(tichdr), 1, fp); + Temp = tichdr.lastupd; + t = localtime(&Temp); + + if (((Diw == 0) && (Day != t->tm_yday)) || ((Day - t->tm_yday) > 7)) + do_week = TRUE; + else + do_week = FALSE; + if (Miy != t->tm_mon) + do_month = TRUE; + else + do_month = FALSE; + + if (do_week || do_month) { + Syslog('+', "Rollover tic.data"); + + while (fread(&tic, tichdr.recsize, 1, fp) == 1) { + if (do_week) { + RollWeek(&tic.Files); + RollWeek(&tic.KBytes); + } + if (do_month) { + tic.Files.month[Miy] = 0; + tic.KBytes.month[Miy] = 0; + if (CFG.slow_util && do_quiet) + usleep(1); + } + fseek(fp, - tichdr.recsize, SEEK_CUR); + fwrite(&tic, tichdr.recsize, 1, fp); + fseek(fp, tichdr.syssize, SEEK_CUR); + } + + tichdr.lastupd = time(NULL); + fseek(fp, 0, SEEK_SET); + fwrite(&tichdr, tichdr.hdrsize, 1, fp); + } + fclose(fp); + } + + if ((fp = OpenData((char *)"fgroups.data")) != NULL) { + fread(&fgrouphdr, sizeof(fgrouphdr), 1, fp); + Temp = fgrouphdr.lastupd; + t = localtime(&Temp); + + if (((Diw == 0) && (Day != t->tm_yday)) || ((Day - t->tm_yday) > 7)) + do_week = TRUE; + else + do_week = FALSE; + if (Miy != t->tm_mon) + do_month = TRUE; + else + do_month = FALSE; + + if (do_week || do_month) { + Syslog('+', "Rollover fgroups.data"); + + while (fread(&fgroup, fgrouphdr.recsize, 1, fp) == 1) { + if (do_week) { + RollWeek(&fgroup.Files); + RollWeek(&fgroup.KBytes); + } + if (do_month) { + fgroup.Files.month[Miy] = 0; + fgroup.KBytes.month[Miy] = 0; + if (CFG.slow_util && do_quiet) + usleep(1); + } + fseek(fp, - fgrouphdr.recsize, SEEK_CUR); + fwrite(&fgroup, fgrouphdr.recsize, 1, fp); + } + + fgrouphdr.lastupd = time(NULL); + fseek(fp, 0, SEEK_SET); + fwrite(&fgrouphdr, fgrouphdr.hdrsize, 1, fp); + } + fclose(fp); + } + + if ((fp = OpenData((char *)"hatch.data")) != NULL) { + fread(&hatchhdr, sizeof(hatchhdr), 1, fp); + Temp = hatchhdr.lastupd; + t = localtime(&Temp); + + if (((Diw == 0) && (Day != t->tm_yday)) || ((Day - t->tm_yday) > 7)) + do_week = TRUE; + else + do_week = FALSE; + if (Miy != t->tm_mon) + do_month = TRUE; + else + do_month = FALSE; + + if (do_week || do_month) { + Syslog('+', "Rollover hatch.data"); + + while (fread(&hatch, hatchhdr.recsize, 1, fp) == 1) { + if (do_week) + RollWeek(&hatch.Hatched); + if (do_month) { + hatch.Hatched.month[Miy] = 0; + if (CFG.slow_util && do_quiet) + usleep(1); + } + fseek(fp, - hatchhdr.recsize, SEEK_CUR); + fwrite(&hatch, hatchhdr.recsize, 1, fp); + } + + hatchhdr.lastupd = time(NULL); + fseek(fp, 0, SEEK_SET); + fwrite(&hatchhdr, hatchhdr.hdrsize, 1, fp); + } + fclose(fp); + } + + temp = calloc(PATH_MAX, sizeof(char)); + temp1 = calloc(PATH_MAX, sizeof(char)); + sprintf(temp, "%s/var/mailer.hist", getenv("MBSE_ROOT")); + if ((fp = fopen(temp, "r"))) { + fread(&history, sizeof(history), 1, fp); + Temp = history.online; + t = localtime(&Temp); + if (t->tm_mon != Miy) { + /* + * Calculate date/time for records to delete + */ + t = localtime(&Now); + if (t->tm_mon == 0) { + t->tm_mon = 11; + t->tm_year--; + } else { + t->tm_mon--; + } + t->tm_mday = 1; + t->tm_hour = 0; + t->tm_min = 0; + t->tm_sec = 0; + Now = mktime(t); + Syslog('+', "Packing mailer history since %s", rfcdate(Now)); + sprintf(temp1, "%s/var/mailer.temp", getenv("MBSE_ROOT")); + if ((ft = fopen(temp1, "a")) == NULL) { + WriteError("$Can't create %s", temp1); fclose(fp); - } + } else { + memset(&history, 0, sizeof(history)); + history.online = time(NULL); + history.offline = time(NULL); + fwrite(&history, sizeof(history), 1, ft); - if ((fp = OpenData((char *)"mareas.data")) != NULL) { - fread(&msgshdr, sizeof(msgshdr), 1, fp); - Temp = msgshdr.lastupd; - t = localtime(&Temp); - - if (((Diw == 0) && (Day != t->tm_yday)) || ((Day - t->tm_yday) > 7)) - do_week = TRUE; - else - do_week = FALSE; - if (Miy != t->tm_mon) - do_month = TRUE; - else - do_month = FALSE; - - if (do_week || do_month) { - Syslog('+', "Rollover mareas.data"); - - while (fread(&msgs, msgshdr.recsize, 1, fp) == 1) { - if (do_week) { - RollWeek(&msgs.Received); - RollWeek(&msgs.Posted); - } - if (do_month) { - msgs.Received.month[Miy] = 0; - msgs.Posted.month[Miy] = 0; - if (CFG.slow_util && do_quiet) - usleep(1); - } - fseek(fp, - msgshdr.recsize, SEEK_CUR); - fwrite(&msgs, msgshdr.recsize, 1, fp); - fseek(fp, msgshdr.syssize, SEEK_CUR); - } - - msgshdr.lastupd = time(NULL); - fseek(fp, 0, SEEK_SET); - fwrite(&msgshdr, msgshdr.hdrsize, 1, fp); + i = 0; + while (fread(&history, sizeof(history), 1, fp)) { + if (history.online >= Now) { + fwrite(&history, sizeof(history), 1, ft); + i++; + } } + fclose(ft); fclose(fp); + unlink(temp); + rename(temp1, temp); + Syslog('+', "Written %d records", i); + } + } else { + fclose(fp); } - - if ((fp = OpenData((char *)"mgroups.data")) != NULL) { - fread(&mgrouphdr, sizeof(mgrouphdr), 1, fp); - Temp = mgrouphdr.lastupd; - t = localtime(&Temp); - - if (((Diw == 0) && (Day != t->tm_yday)) || ((Day - t->tm_yday) > 7)) - do_week = TRUE; - else - do_week = FALSE; - if (Miy != t->tm_mon) - do_month = TRUE; - else - do_month = FALSE; - - if (do_week || do_month) { - Syslog('+', "Rollover mgroups.data"); - - while (fread(&mgroup, mgrouphdr.recsize, 1, fp) == 1) { - if (do_week) { - RollWeek(&mgroup.MsgsRcvd); - RollWeek(&mgroup.MsgsSent); - } - if (do_month) { - mgroup.MsgsRcvd.month[Miy] = 0; - mgroup.MsgsSent.month[Miy] = 0; - if (CFG.slow_util && do_quiet) - usleep(1); - } - fseek(fp, - mgrouphdr.recsize, SEEK_CUR); - fwrite(&mgroup, mgrouphdr.recsize, 1, fp); - } - - mgrouphdr.lastupd = time(NULL); - fseek(fp, 0, SEEK_SET); - fwrite(&mgrouphdr, mgrouphdr.hdrsize, 1, fp); - } - fclose(fp); - } - - if ((fp = OpenData((char *)"tic.data")) != NULL) { - fread(&tichdr, sizeof(tichdr), 1, fp); - Temp = tichdr.lastupd; - t = localtime(&Temp); - - if (((Diw == 0) && (Day != t->tm_yday)) || ((Day - t->tm_yday) > 7)) - do_week = TRUE; - else - do_week = FALSE; - if (Miy != t->tm_mon) - do_month = TRUE; - else - do_month = FALSE; - - if (do_week || do_month) { - Syslog('+', "Rollover tic.data"); - - while (fread(&tic, tichdr.recsize, 1, fp) == 1) { - if (do_week) { - RollWeek(&tic.Files); - RollWeek(&tic.KBytes); - } - if (do_month) { - tic.Files.month[Miy] = 0; - tic.KBytes.month[Miy] = 0; - if (CFG.slow_util && do_quiet) - usleep(1); - } - fseek(fp, - tichdr.recsize, SEEK_CUR); - fwrite(&tic, tichdr.recsize, 1, fp); - fseek(fp, tichdr.syssize, SEEK_CUR); - } - - tichdr.lastupd = time(NULL); - fseek(fp, 0, SEEK_SET); - fwrite(&tichdr, tichdr.hdrsize, 1, fp); - } - fclose(fp); - } - - if ((fp = OpenData((char *)"fgroups.data")) != NULL) { - fread(&fgrouphdr, sizeof(fgrouphdr), 1, fp); - Temp = fgrouphdr.lastupd; - t = localtime(&Temp); - - if (((Diw == 0) && (Day != t->tm_yday)) || ((Day - t->tm_yday) > 7)) - do_week = TRUE; - else - do_week = FALSE; - if (Miy != t->tm_mon) - do_month = TRUE; - else - do_month = FALSE; - - if (do_week || do_month) { - Syslog('+', "Rollover fgroups.data"); - - while (fread(&fgroup, fgrouphdr.recsize, 1, fp) == 1) { - if (do_week) { - RollWeek(&fgroup.Files); - RollWeek(&fgroup.KBytes); - } - if (do_month) { - fgroup.Files.month[Miy] = 0; - fgroup.KBytes.month[Miy] = 0; - if (CFG.slow_util && do_quiet) - usleep(1); - } - fseek(fp, - fgrouphdr.recsize, SEEK_CUR); - fwrite(&fgroup, fgrouphdr.recsize, 1, fp); - } - - fgrouphdr.lastupd = time(NULL); - fseek(fp, 0, SEEK_SET); - fwrite(&fgrouphdr, fgrouphdr.hdrsize, 1, fp); - } - fclose(fp); - } - - if ((fp = OpenData((char *)"hatch.data")) != NULL) { - fread(&hatchhdr, sizeof(hatchhdr), 1, fp); - Temp = hatchhdr.lastupd; - t = localtime(&Temp); - - if (((Diw == 0) && (Day != t->tm_yday)) || ((Day - t->tm_yday) > 7)) - do_week = TRUE; - else - do_week = FALSE; - if (Miy != t->tm_mon) - do_month = TRUE; - else - do_month = FALSE; - - if (do_week || do_month) { - Syslog('+', "Rollover hatch.data"); - - while (fread(&hatch, hatchhdr.recsize, 1, fp) == 1) { - if (do_week) - RollWeek(&hatch.Hatched); - if (do_month) { - hatch.Hatched.month[Miy] = 0; - if (CFG.slow_util && do_quiet) - usleep(1); - } - fseek(fp, - hatchhdr.recsize, SEEK_CUR); - fwrite(&hatch, hatchhdr.recsize, 1, fp); - } - - hatchhdr.lastupd = time(NULL); - fseek(fp, 0, SEEK_SET); - fwrite(&hatchhdr, hatchhdr.hdrsize, 1, fp); - } - fclose(fp); - } - - temp = calloc(128, sizeof(char)); - temp1 = calloc(128, sizeof(char)); - sprintf(temp, "%s/var/mailer.hist", getenv("MBSE_ROOT")); - if ((fp = fopen(temp, "r"))) { - fread(&history, sizeof(history), 1, fp); - Temp = history.online; - t = localtime(&Temp); - if (t->tm_mon != Miy) { - /* - * Calculate date/time for records to delete - */ - t = localtime(&Now); - if (t->tm_mon == 0) { - t->tm_mon = 11; - t->tm_year--; - } else { - t->tm_mon--; - } - t->tm_mday = 1; - t->tm_hour = 0; - t->tm_min = 0; - t->tm_sec = 0; - Now = mktime(t); - Syslog('+', "Packing mailer history since %s", rfcdate(Now)); - sprintf(temp1, "%s/var/mailer.temp", getenv("MBSE_ROOT")); - if ((ft = fopen(temp1, "a")) == NULL) { - WriteError("$Can't create %s", temp1); - fclose(fp); - } else { - memset(&history, 0, sizeof(history)); - history.online = time(NULL); - history.offline = time(NULL); - fwrite(&history, sizeof(history), 1, ft); - - i = 0; - while (fread(&history, sizeof(history), 1, fp)) { - if (history.online >= Now) { - fwrite(&history, sizeof(history), 1, ft); - i++; - } - } - fclose(ft); - fclose(fp); - unlink(temp); - rename(temp1, temp); - Syslog('+', "Written %d records", i); - } - } else { - fclose(fp); - } - } - free(temp); - free(temp1); + } + free(temp); + free(temp1); } diff --git a/mbsebbs/offline.c b/mbsebbs/offline.c index 441ab5ef..dfb587ce 100644 --- a/mbsebbs/offline.c +++ b/mbsebbs/offline.c @@ -1694,7 +1694,6 @@ void BlueWave_Fetch() Msg.Private = TRUE; if (msgs.MsgKinds == PRIVATE) Msg.Private = TRUE; -// Msg.Written = Upr.unix_date; Msg.Written = Upr.unix_date - (gmt_offset((time_t)0) * 60); Msg.Arrived = time(NULL) - (gmt_offset((time_t)0) * 60); Msg.Local = TRUE; @@ -2195,209 +2194,223 @@ unsigned long BlueWave_PackArea(unsigned long ulLast, long Area) void OLR_DownQWK(void) { - struct tm *tp; - time_t Now; - char Pktname[32]; - long Area = 0; - char *Work, *Temp; - int i, rc = 0; - FILE *fp = NULL, *tf, *mf, *af; - unsigned long Start, High; - msg_high *tmp, *mhl = NULL; + struct tm *tp; + time_t Now; + char Pktname[32]; + long Area = 0; + char *Work, *Temp; + int i, rc = 0; + FILE *fp = NULL, *tf, *mf, *af; + unsigned long Start, High; + msg_high *tmp, *mhl = NULL; - if (!OLR_Prescan()) - return; + if (!OLR_Prescan()) + return; - Total = TotalPersonal = 0L; - clear(); - colour(9, 0); - /* QWK Offline Download */ - printf("%s\n", (char *)Language(458)); + Total = TotalPersonal = 0L; + clear(); + colour(9, 0); + /* QWK Offline Download */ + printf("%s\n", (char *)Language(458)); - Work = calloc(PATH_MAX, sizeof(char)); - Temp = calloc(PATH_MAX, sizeof(char)); + Work = calloc(PATH_MAX, sizeof(char)); + Temp = calloc(PATH_MAX, sizeof(char)); - Now = time(NULL); - tp = localtime(&Now); - Syslog('+', "Preparing QWK packet"); + Now = time(NULL); + tp = localtime(&Now); + Syslog('+', "Preparing QWK packet"); - sprintf(Temp, "%s.QWK", CFG.bbsid); - sprintf(Pktname, "%s", tl(Temp)); - Syslog('m', "Packet name %s", Pktname); - sprintf(Work, "%s/%s/tmp", CFG.bbs_usersdir, exitinfo.Name); - Syslog('m', "Work path %s", Work); - - sprintf(Temp, "%s/etc/mareas.data", getenv("MBSE_ROOT")); - if ((mf = fopen(Temp, "r")) == NULL) { - WriteError("$Can't open %s", Temp); - fclose(fp); - return; - } - fread(&msgshdr, sizeof(msgshdr), 1, mf); - - sprintf(Temp, "%s/%s/.olrtags", CFG.bbs_usersdir, exitinfo.Name); - if ((tf = fopen(Temp, "r")) == NULL) { - WriteError("$Can't open %s", Temp); - fclose(fp); - fclose(mf); - return; - } - - Area = 0; - DrawBar(Pktname); - fseek(mf, sizeof(msgshdr), SEEK_SET); - fseek(tf, 0, SEEK_SET); - - while (fread(&msgs, msgshdr.recsize, 1, mf) == 1) { - fseek(mf, msgshdr.syssize, SEEK_CUR); - fread(&olrtagrec, sizeof(olrtagrec), 1, tf); - Area++; - if (olrtagrec.Tagged) { - if (Msg_Open(msgs.Base)) { - Current = Personal = 0; - if (Msg_Highest() != 0) { - memset(&LR, 0, sizeof(LR)); - LR.UserID = grecno; - if (Msg_GetLastRead(&LR)) - Start = LR.HighReadMsg; - else - Start = Msg_Lowest() -1; - if (Start > Msg_Highest()) - Start = Msg_Highest(); - if (Start < Msg_Highest()) { - Syslog('m', "First %lu, Last %lu, Start %lu", Msg_Lowest(), Msg_Highest(), Start); - High = QWK_PackArea(Start, Area); - fill_high(&mhl, Area, High, Personal); - } - } - Syslog('+', "Area %-20s %5ld (%ld personal)", msgs.QWKname, Current, Personal); - Msg_Close(); - } - } - } - - sprintf(Temp, "%s/CONTROL.DAT", Work); - if ((fp = fopen(Temp, "w+")) != NULL) { - fprintf(fp, "%s\n", CFG.bbs_name); - fprintf(fp, "%s\n", CFG.location); - fprintf(fp, "%s\n", CFG.Phone); - fprintf(fp, "%s\n", CFG.sysop_name); - fprintf(fp, "00000,%s\n", CFG.bbsid); - - fprintf(fp, "%02d-%02d-%04d,%02d:%02d:%02d\n", tp->tm_mday, tp->tm_mon+1, tp->tm_year+1900, - tp->tm_hour, tp->tm_min, tp->tm_sec); - sprintf(Temp, "%s", exitinfo.sUserName); - fprintf(fp, "%s\n", tu(Temp)); - fprintf(fp, " \n"); - fprintf(fp, "0\n"); - fprintf(fp, "%lu\n", Total); - - /* - * Count available areas. - */ - i = 0; - fseek(mf, msgshdr.hdrsize, SEEK_SET); - fseek(tf, 0, SEEK_SET); - while (fread(&msgs, msgshdr.recsize, 1, mf) == 1) { - fseek(mf, msgshdr.syssize, SEEK_CUR); - if (msgs.Active && Access(exitinfo.Security, msgs.RDSec) && strlen(msgs.QWKname)) - i++; - } - fprintf(fp, "%d\n", i - 1); - - /* - * Write available areas - */ - i = 0; - fseek(mf, msgshdr.hdrsize, SEEK_SET); - fseek(tf, 0, SEEK_SET); - while (fread(&msgs, msgshdr.recsize, 1, mf) == 1) { - fseek(mf, msgshdr.syssize, SEEK_CUR); - i++; - if (msgs.Active && Access(exitinfo.Security, msgs.RDSec) && strlen(msgs.QWKname)) { - fprintf(fp, "%d\n%s\n", i, msgs.QWKname); - } - } - - fprintf(fp, "WELCOME\n"); - fprintf(fp, "NEWS\n"); - fprintf(fp, "GOODBYE\n"); - fclose(fp); - } - - sprintf(Temp, "%s/DOOR.ID", Work); - if ((fp = fopen(Temp, "w+")) != 0) { - fprintf(fp, "DOOR = MBSE BBS QWK\n"); - fprintf(fp, "VERSION = %s\n", VERSION); - fprintf(fp, "SYSTEM = %s\n", CFG.bbs_name); - fprintf(fp, "CONTROLNAME = MBSEQWK\n"); - fprintf(fp, "CONTROLTYPE = ADD\n"); - fprintf(fp, "CONTROLTYPE = DROP\n"); - fclose(fp); - } - - Syslog('+', "Packed %ld messages (%ld personal)", Total, TotalPersonal); - fclose(tf); - - if (Total) { - /* Packing with */ - printf("\n%s ", (char *)Language(446)); - sprintf(Temp, "%s/etc/archiver.data", getenv("MBSE_ROOT")); - if ((af = fopen(Temp, "r")) != NULL) { - fread(&archiverhdr, sizeof(archiverhdr), 1, af); - while (fread(&archiver, archiverhdr.recsize, 1, af) == 1) { - if (archiver.available && (!strcmp(archiver.name, exitinfo.Archiver))) { - Syslog('+', "Archiver %s", archiver.comment); - printf("%s ", archiver.comment); - sprintf(Temp, "%s/CONTROL.DAT", Work); - AddArc(Temp, Pktname); - alarm_on(); - sprintf(Temp, "%s/MESSAGES.DAT", Work); - AddArc(Temp, Pktname); - - for (tmp = mhl; tmp; tmp = tmp->next) { - sprintf(Temp, "%s/%03ld.NDX", Work, tmp->Area); - AddArc(Temp, Pktname); - } - - sprintf(Temp, "%s/PERSONAL.NDX", Work); - if (TotalPersonal) { - AddArc(Temp, Pktname); - } else - unlink(Temp); - - sprintf(Temp, "%s/DOOR.ID", Work); - AddArc(Temp, Pktname); - sprintf(Temp, "%s/%s/%s", CFG.bbs_usersdir, exitinfo.Name, Pktname); - rc = DownloadDirect(Temp, FALSE); - Syslog('m', "Download result %d", rc); - unlink(Temp); - } - } - fclose(af); - } - } - - colour(CFG.HiliteF, CFG.HiliteB); - if (rc == FALSE) { - Syslog('+', "QWK download failed"); - /* Download failed */ - printf("%s", (char *)Language(447)); - } else { - Syslog('+', "QWK download successfull"); - /* Download successfull */ - printf("\r%s\n", (char *)Language(448)); - - if (mhl != NULL) - UpdateLR(mhl, mf); - } - fclose(mf); - tidy_high(&mhl); + sprintf(Temp, "%s.QWK", CFG.bbsid); + sprintf(Pktname, "%s", tl(Temp)); + Syslog('m', "Packet name %s", Pktname); + sprintf(Work, "%s/%s/tmp", CFG.bbs_usersdir, exitinfo.Name); + Syslog('m', "Work path %s", Work); + sprintf(Temp, "%s/etc/mareas.data", getenv("MBSE_ROOT")); + if ((mf = fopen(Temp, "r")) == NULL) { + WriteError("$Can't open %s", Temp); + fclose(fp); free(Temp); free(Work); - printf("\n\n"); - Pause(); + return; + } + fread(&msgshdr, sizeof(msgshdr), 1, mf); + + sprintf(Temp, "%s/%s/.olrtags", CFG.bbs_usersdir, exitinfo.Name); + if ((tf = fopen(Temp, "r")) == NULL) { + WriteError("$Can't open %s", Temp); + fclose(fp); + fclose(mf); + free(Temp); + free(Work); + return; + } + + Area = 0; + DrawBar(Pktname); + fseek(mf, sizeof(msgshdr), SEEK_SET); + fseek(tf, 0, SEEK_SET); + + while (fread(&msgs, msgshdr.recsize, 1, mf) == 1) { + fseek(mf, msgshdr.syssize, SEEK_CUR); + fread(&olrtagrec, sizeof(olrtagrec), 1, tf); + Area++; + if (olrtagrec.Tagged) { + if (Msg_Open(msgs.Base)) { + Current = Personal = 0; + if (Msg_Highest() != 0) { + memset(&LR, 0, sizeof(LR)); + LR.UserID = grecno; + if (Msg_GetLastRead(&LR)) + Start = LR.HighReadMsg; + else + Start = Msg_Lowest() -1; + if (Start > Msg_Highest()) + Start = Msg_Highest(); + if (Start < Msg_Highest()) { + Syslog('m', "First %lu, Last %lu, Start %lu", Msg_Lowest(), Msg_Highest(), Start); + High = QWK_PackArea(Start, Area); + fill_high(&mhl, Area, High, Personal); + } + } + Syslog('+', "Area %-20s %5ld (%ld personal)", msgs.QWKname, Current, Personal); + Msg_Close(); + } + } + } + + sprintf(Temp, "%s/CONTROL.DAT", Work); + if ((fp = fopen(Temp, "w+")) != NULL) { + fprintf(fp, "%s\n", CFG.bbs_name); + fprintf(fp, "%s\n", CFG.location); + fprintf(fp, "%s\n", CFG.Phone); + fprintf(fp, "%s\n", CFG.sysop_name); + fprintf(fp, "00000,%s\n", CFG.bbsid); + + fprintf(fp, "%02d-%02d-%04d,%02d:%02d:%02d\n", tp->tm_mday, tp->tm_mon+1, tp->tm_year+1900, + tp->tm_hour, tp->tm_min, tp->tm_sec); + sprintf(Temp, "%s", exitinfo.sUserName); + fprintf(fp, "%s\n", tu(Temp)); + fprintf(fp, " \n"); + fprintf(fp, "0\n"); + fprintf(fp, "%lu\n", Total); + + /* + * Count available areas. + */ + i = 0; + fseek(mf, msgshdr.hdrsize, SEEK_SET); + fseek(tf, 0, SEEK_SET); + while (fread(&msgs, msgshdr.recsize, 1, mf) == 1) { + fseek(mf, msgshdr.syssize, SEEK_CUR); + if (msgs.Active && Access(exitinfo.Security, msgs.RDSec) && strlen(msgs.QWKname)) + i++; + } + fprintf(fp, "%d\n", i - 1); + + /* + * Write available areas + */ + i = 0; + fseek(mf, msgshdr.hdrsize, SEEK_SET); + fseek(tf, 0, SEEK_SET); + while (fread(&msgs, msgshdr.recsize, 1, mf) == 1) { + fseek(mf, msgshdr.syssize, SEEK_CUR); + i++; + if (msgs.Active && Access(exitinfo.Security, msgs.RDSec) && strlen(msgs.QWKname)) { + fprintf(fp, "%d\n%s\n", i, msgs.QWKname); + } + } + + fprintf(fp, "WELCOME\n"); + fprintf(fp, "NEWS\n"); + fprintf(fp, "GOODBYE\n"); + fclose(fp); + } + + sprintf(Temp, "%s/DOOR.ID", Work); + if ((fp = fopen(Temp, "w+")) != 0) { + fprintf(fp, "DOOR = MBSE BBS QWK\n"); + fprintf(fp, "VERSION = %s\n", VERSION); + fprintf(fp, "SYSTEM = %s\n", CFG.bbs_name); + fprintf(fp, "CONTROLNAME = MBSEQWK\n"); + fprintf(fp, "CONTROLTYPE = ADD\n"); + fprintf(fp, "CONTROLTYPE = DROP\n"); + /* + * QWKE extensions + */ +// fprintf(fp, "CONTROLTYPE = MAXKEYWORDS 0\n"); +// fprintf(fp, "CONTROLTYPE = MAXFILTERS 0\n"); +// fprintf(fp, "CONTROLTYPE = MAXTWITS 0\n"); +// fprintf(fp, "CONTROLTYPE = ALLOWATTACH\n"); +// fprintf(fp, "CONTROLTYPE = ALLOWFILES\n"); +// fprintf(fp, "CONTROLTYPE = ALLOWREQUESTS\n"); +// fprintf(fp, "CONTROLTYPE = MAXREQUESTS 0\n"); + fclose(fp); + } + + Syslog('+', "Packed %ld messages (%ld personal)", Total, TotalPersonal); + fclose(tf); + + if (Total) { + /* Packing with */ + printf("\n%s ", (char *)Language(446)); + sprintf(Temp, "%s/etc/archiver.data", getenv("MBSE_ROOT")); + if ((af = fopen(Temp, "r")) != NULL) { + fread(&archiverhdr, sizeof(archiverhdr), 1, af); + while (fread(&archiver, archiverhdr.recsize, 1, af) == 1) { + if (archiver.available && (!strcmp(archiver.name, exitinfo.Archiver))) { + Syslog('+', "Archiver %s", archiver.comment); + printf("%s ", archiver.comment); + sprintf(Temp, "%s/CONTROL.DAT", Work); + AddArc(Temp, Pktname); + alarm_on(); + sprintf(Temp, "%s/MESSAGES.DAT", Work); + AddArc(Temp, Pktname); + + for (tmp = mhl; tmp; tmp = tmp->next) { + sprintf(Temp, "%s/%03ld.NDX", Work, tmp->Area); + AddArc(Temp, Pktname); + } + + sprintf(Temp, "%s/PERSONAL.NDX", Work); + if (TotalPersonal) { + AddArc(Temp, Pktname); + } else + unlink(Temp); + + sprintf(Temp, "%s/DOOR.ID", Work); + AddArc(Temp, Pktname); + sprintf(Temp, "%s/%s/%s", CFG.bbs_usersdir, exitinfo.Name, Pktname); + rc = DownloadDirect(Temp, FALSE); + Syslog('m', "Download result %d", rc); + unlink(Temp); + } + } + fclose(af); + } + } + + colour(CFG.HiliteF, CFG.HiliteB); + if (rc == FALSE) { + Syslog('+', "QWK download failed"); + /* Download failed */ + printf("%s", (char *)Language(447)); + } else { + Syslog('+', "QWK download successfull"); + /* Download successfull */ + printf("\r%s\n", (char *)Language(448)); + + if (mhl != NULL) + UpdateLR(mhl, mf); + } + fclose(mf); + tidy_high(&mhl); + + free(Temp); + free(Work); + printf("\n\n"); + Pause(); }