2002-02-13 20:08:35 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
* Purpose ...............: Create Message Area
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
|
|
|
* Copyright (C) 1997-2002
|
|
|
|
*
|
|
|
|
* Michiel Broek FIDO: 2:280/2802
|
|
|
|
* Beekmansbos 10
|
|
|
|
* 1971 BV IJmuiden
|
|
|
|
* the Netherlands
|
|
|
|
*
|
|
|
|
* This file is part of MBSE BBS.
|
|
|
|
*
|
|
|
|
* This BBS 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, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* MBSE BBS 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MBSE BBS; see the file COPYING. If not, write to the Free
|
|
|
|
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2002-06-30 12:48:44 +00:00
|
|
|
#include "../config.h"
|
2002-02-13 20:08:35 +00:00
|
|
|
#include "../lib/libs.h"
|
2002-06-30 12:48:44 +00:00
|
|
|
#include "../lib/memwatch.h"
|
2002-02-13 20:08:35 +00:00
|
|
|
#include "../lib/structs.h"
|
|
|
|
#include "../lib/users.h"
|
|
|
|
#include "../lib/records.h"
|
|
|
|
#include "../lib/common.h"
|
|
|
|
#include "../lib/clcomm.h"
|
2002-04-27 21:06:51 +00:00
|
|
|
#include "../lib/msg.h"
|
2002-03-03 16:28:10 +00:00
|
|
|
#include "mgrutil.h"
|
2002-02-13 20:08:35 +00:00
|
|
|
#include "createm.h"
|
|
|
|
|
2002-02-14 21:24:27 +00:00
|
|
|
|
|
|
|
#define MCHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
|
|
|
|
|
|
|
|
|
|
|
int create_msgarea(char *marea, faddr *p_from)
|
|
|
|
{
|
2002-03-03 16:28:10 +00:00
|
|
|
char *temp;
|
|
|
|
FILE *gp;
|
2002-02-14 21:24:27 +00:00
|
|
|
|
2002-03-25 12:24:24 +00:00
|
|
|
Syslog('m', "create_msgarea(%s)", marea);
|
2002-02-14 21:24:27 +00:00
|
|
|
temp = calloc(PATH_MAX, sizeof(char));
|
|
|
|
sprintf(temp, "%s/etc/mgroups.data", getenv("MBSE_ROOT"));
|
|
|
|
if ((gp = fopen(temp, "r")) == NULL) {
|
2002-03-25 12:24:24 +00:00
|
|
|
WriteError("Can't open %s", temp);
|
2002-02-14 21:24:27 +00:00
|
|
|
free(temp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
fread(&mgrouphdr, sizeof(mgrouphdr), 1, gp);
|
2002-03-03 16:28:10 +00:00
|
|
|
free(temp);
|
2002-02-14 21:24:27 +00:00
|
|
|
|
|
|
|
fseek(gp, mgrouphdr.hdrsize, SEEK_SET);
|
|
|
|
while ((fread(&mgroup, mgrouphdr.recsize, 1, gp)) == 1) {
|
|
|
|
if ((mgroup.UpLink.zone == p_from->zone) && (mgroup.UpLink.net == p_from->net) &&
|
|
|
|
(mgroup.UpLink.node == p_from->node) && (mgroup.UpLink.point == p_from->point) &&
|
|
|
|
strlen(mgroup.AreaFile)) {
|
2002-03-03 16:28:10 +00:00
|
|
|
if (CheckEchoGroup(marea, FALSE, p_from) == 0) {
|
2002-02-14 21:24:27 +00:00
|
|
|
fclose(gp);
|
2002-03-03 16:28:10 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(gp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-02-16 14:39:53 +00:00
|
|
|
|
|
|
|
|
2002-03-03 16:28:10 +00:00
|
|
|
/*
|
|
|
|
* Check echomail group AREAS file if requested area exists.
|
|
|
|
* If so, create echomail area and if SendUplink is TRUE,
|
|
|
|
* send the uplink a AreaMgr request to connect this area.
|
|
|
|
* The echomail group record (mgroup) must be in memory.
|
|
|
|
* Return codes:
|
|
|
|
* 0 - All Seems Well
|
|
|
|
* 1 - Some error
|
|
|
|
*
|
2002-03-15 21:16:16 +00:00
|
|
|
* The current nodes record may be destroyed after this,
|
|
|
|
* make sure it is saved.
|
2002-03-03 16:28:10 +00:00
|
|
|
*/
|
|
|
|
int CheckEchoGroup(char *Area, int SendUplink, faddr *f)
|
|
|
|
{
|
|
|
|
char *temp, *buf, *tag, *desc, *p;
|
|
|
|
FILE *ap, *mp;
|
|
|
|
long offset;
|
|
|
|
int i, rc = 0;
|
|
|
|
sysconnect System;
|
2002-06-17 20:36:06 +00:00
|
|
|
faddr *From, *To;
|
2002-03-03 16:28:10 +00:00
|
|
|
|
|
|
|
temp = calloc(PATH_MAX, sizeof(char));
|
|
|
|
Syslog('m', "Checking echogroup %s %s", mgroup.Name, mgroup.Comment);
|
|
|
|
sprintf(temp, "%s/%s", CFG.alists_path , mgroup.AreaFile);
|
|
|
|
if ((ap = fopen(temp, "r")) == NULL) {
|
2002-03-25 12:24:24 +00:00
|
|
|
WriteError("Echogroup %s: area taglist %s not found", mgroup.Name, temp);
|
2002-03-03 16:28:10 +00:00
|
|
|
free(temp);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = calloc(4097, sizeof(char));
|
|
|
|
while (fgets(buf, 4096, ap)) {
|
2002-03-27 20:12:30 +00:00
|
|
|
if (strlen(buf) && isalnum(buf[0])) {
|
|
|
|
tag = strtok(buf, "\t \r\n\0");
|
|
|
|
p = strtok(NULL, "\r\n\0");
|
2002-06-24 21:55:03 +00:00
|
|
|
if (p == NULL)
|
|
|
|
p = tag; /* If no description after the TAG, use TAG as description */
|
2002-03-27 20:12:30 +00:00
|
|
|
desc = p;
|
|
|
|
while ((*desc == ' ') || (*desc == '\t'))
|
|
|
|
desc++;
|
|
|
|
if (strcmp(tag, Area) == 0) {
|
|
|
|
Syslog('m', "Found tag \"%s\" desc \"%s\"", tag, desc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Area is in AREAS file, now create area.
|
|
|
|
* If needed, connect at uplink.
|
|
|
|
*/
|
|
|
|
if (SendUplink) {
|
|
|
|
sprintf(temp, "+%s", Area);
|
2002-06-17 20:36:06 +00:00
|
|
|
From = fido2faddr(mgroup.UseAka);
|
|
|
|
To = fido2faddr(mgroup.UpLink);
|
|
|
|
if (UplinkRequest(To, From, FALSE, temp)) {
|
2002-03-27 20:12:30 +00:00
|
|
|
WriteError("Can't send netmail to uplink");
|
|
|
|
fclose(ap);
|
|
|
|
free(buf);
|
|
|
|
free(temp);
|
2002-06-17 20:36:06 +00:00
|
|
|
tidy_faddr(From);
|
|
|
|
tidy_faddr(To);
|
2002-03-27 20:12:30 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2002-06-17 20:36:06 +00:00
|
|
|
tidy_faddr(From);
|
|
|
|
tidy_faddr(To);
|
2002-03-27 20:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(temp, "%s/etc/mareas.data", getenv("MBSE_ROOT"));
|
|
|
|
if ((mp = fopen(temp, "r+")) == NULL) {
|
|
|
|
WriteError("$Can't open %s", temp);
|
2002-03-03 16:28:10 +00:00
|
|
|
fclose(ap);
|
|
|
|
free(buf);
|
|
|
|
free(temp);
|
|
|
|
return 1;
|
2002-02-14 21:24:27 +00:00
|
|
|
}
|
2002-03-27 20:12:30 +00:00
|
|
|
fread(&msgshdr, sizeof(msgshdr), 1, mp);
|
2002-05-22 17:48:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify the file is large enough
|
|
|
|
*/
|
2002-05-29 19:53:42 +00:00
|
|
|
fseek(mp, 0, SEEK_END);
|
|
|
|
offset = msgshdr.hdrsize + ((mgroup.StartArea -1) * (msgshdr.recsize + msgshdr.syssize));
|
|
|
|
Syslog('+', "file end at %ld, offset needed %ld", ftell(mp), offset);
|
|
|
|
|
2002-05-22 17:48:11 +00:00
|
|
|
if (ftell(mp) < offset) {
|
|
|
|
Syslog('m', "Database too small, expanding...");
|
|
|
|
memset(&msgs, 0, sizeof(msgs));
|
|
|
|
memset(&System, 0, sizeof(System));
|
|
|
|
while (TRUE) {
|
|
|
|
fwrite(&msgs, sizeof(msgs), 1, mp);
|
|
|
|
for (i = 0; i < (msgshdr.syssize / sizeof(System)); i++)
|
|
|
|
fwrite(&System, sizeof(System), 1, mp);
|
|
|
|
if (ftell(mp) >= msgshdr.hdrsize + ((mgroup.StartArea -1) * (msgshdr.recsize + msgshdr.syssize)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-27 20:12:30 +00:00
|
|
|
if (fseek(mp, offset, SEEK_SET)) {
|
2002-05-29 19:53:42 +00:00
|
|
|
WriteError("$Can't seek in %s to position %ld", temp, offset);
|
2002-03-27 20:12:30 +00:00
|
|
|
fclose(ap);
|
|
|
|
fclose(mp);
|
|
|
|
free(buf);
|
|
|
|
free(temp);
|
|
|
|
return 1;
|
2002-03-03 16:28:10 +00:00
|
|
|
}
|
2002-03-27 20:12:30 +00:00
|
|
|
|
2002-03-03 16:28:10 +00:00
|
|
|
/*
|
2002-03-27 20:12:30 +00:00
|
|
|
* Search a free record
|
2002-03-03 16:28:10 +00:00
|
|
|
*/
|
2002-03-27 20:12:30 +00:00
|
|
|
while (fread(&msgs, sizeof(msgs), 1, mp) == 1) {
|
|
|
|
if (!msgs.Active) {
|
|
|
|
fseek(mp, - msgshdr.recsize, SEEK_CUR);
|
|
|
|
offset = ((ftell(mp) - msgshdr.hdrsize) / (msgshdr.recsize + msgshdr.syssize)) + 1;
|
|
|
|
Syslog('m', "Found free slot at %ld", offset);
|
|
|
|
rc = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Skip systems
|
|
|
|
*/
|
|
|
|
fseek(mp, msgshdr.syssize, SEEK_CUR);
|
|
|
|
}
|
2002-03-03 16:28:10 +00:00
|
|
|
|
2002-03-27 20:12:30 +00:00
|
|
|
if (!rc) {
|
|
|
|
Syslog('m', "No free slot, append after last record");
|
|
|
|
fseek(mp, 0, SEEK_END);
|
|
|
|
if (ftell(mp) < msgshdr.hdrsize + ((mgroup.StartArea -1) * (msgshdr.recsize + msgshdr.syssize))) {
|
|
|
|
Syslog('m', "Database too small, expanding...");
|
|
|
|
memset(&msgs, 0, sizeof(msgs));
|
|
|
|
memset(&System, 0, sizeof(System));
|
|
|
|
while (TRUE) {
|
|
|
|
fwrite(&msgs, sizeof(msgs), 1, mp);
|
|
|
|
for (i = 0; i < (msgshdr.syssize / sizeof(System)); i++)
|
|
|
|
fwrite(&System, sizeof(System), 1, mp);
|
|
|
|
if (ftell(mp) >= msgshdr.hdrsize + ((mgroup.StartArea -1) * (msgshdr.recsize + msgshdr.syssize)))
|
|
|
|
break;
|
|
|
|
}
|
2002-03-03 16:28:10 +00:00
|
|
|
}
|
2002-03-27 20:12:30 +00:00
|
|
|
rc = 1;
|
2002-03-03 16:28:10 +00:00
|
|
|
}
|
|
|
|
|
2002-03-27 20:12:30 +00:00
|
|
|
/*
|
|
|
|
* Create the record with the defaults from the group record.
|
|
|
|
*/
|
|
|
|
offset = ((ftell(mp) - msgshdr.hdrsize) / (msgshdr.recsize + msgshdr.syssize)) + 1;
|
|
|
|
memset(&msgs, 0, sizeof(msgs));
|
|
|
|
strncpy(msgs.Tag, tag, 50);
|
|
|
|
strncpy(msgs.Name, desc, 40);
|
|
|
|
strncpy(msgs.QWKname, tag, 20);
|
|
|
|
msgs.MsgKinds = PUBLIC;
|
|
|
|
msgs.Type = ECHOMAIL;
|
|
|
|
msgs.DaysOld = CFG.defdays;
|
|
|
|
msgs.MaxMsgs = CFG.defmsgs;
|
|
|
|
msgs.UsrDelete = mgroup.UsrDelete;
|
|
|
|
msgs.RDSec = mgroup.RDSec;
|
|
|
|
msgs.WRSec = mgroup.WRSec;
|
|
|
|
msgs.SYSec = mgroup.SYSec;
|
2002-09-29 20:08:32 +00:00
|
|
|
msgs.LinkSec = mgroup.LinkSec;
|
2002-03-27 20:12:30 +00:00
|
|
|
strncpy(msgs.Group, mgroup.Name, 12);
|
|
|
|
msgs.Aka = mgroup.UseAka;
|
|
|
|
strncpy(msgs.Origin, CFG.origin, 50);
|
|
|
|
msgs.Aliases = mgroup.Aliases;
|
|
|
|
msgs.NetReply = mgroup.NetReply;
|
|
|
|
msgs.Active = TRUE;
|
|
|
|
msgs.Quotes = mgroup.Quotes;
|
|
|
|
msgs.Rfccode = CHRS_DEFAULT_RFC;
|
|
|
|
msgs.Ftncode = CHRS_DEFAULT_FTN;
|
|
|
|
msgs.MaxArticles = CFG.maxarticles;
|
|
|
|
tag = tl(tag);
|
|
|
|
for (i = 0; i < strlen(tag); i++)
|
|
|
|
if (tag[i] == '.')
|
|
|
|
tag[i] = '/';
|
|
|
|
sprintf(msgs.Base, "%s/%s", mgroup.BasePath, tag);
|
|
|
|
fwrite(&msgs, sizeof(msgs), 1, mp);
|
2002-04-27 21:06:51 +00:00
|
|
|
mkdirs(msgs.Base, 0770);
|
|
|
|
if (Msg_Open(msgs.Base))
|
|
|
|
Msg_Close();
|
2002-03-03 16:28:10 +00:00
|
|
|
|
2002-03-27 20:12:30 +00:00
|
|
|
memset(&System, 0, sizeof(System));
|
|
|
|
System.aka = mgroup.UpLink;
|
|
|
|
System.sendto = System.receivefrom = TRUE;
|
2002-03-03 16:28:10 +00:00
|
|
|
fwrite(&System, sizeof(System), 1, mp);
|
2002-03-27 20:12:30 +00:00
|
|
|
memset(&System, 0, sizeof(System));
|
|
|
|
for (i = 1; i < (msgshdr.syssize / sizeof(System)); i++)
|
|
|
|
fwrite(&System, sizeof(System), 1, mp);
|
2002-03-03 16:28:10 +00:00
|
|
|
|
2002-03-27 20:12:30 +00:00
|
|
|
fclose(mp);
|
|
|
|
fclose(ap);
|
|
|
|
free(buf);
|
|
|
|
free(temp);
|
2002-04-27 21:06:51 +00:00
|
|
|
if (f == NULL)
|
2002-09-28 22:22:50 +00:00
|
|
|
Mgrlog("Auto created echo %s, group %s, area %ld", msgs.Tag, msgs.Group, offset);
|
2002-04-27 21:06:51 +00:00
|
|
|
else
|
2002-09-28 22:22:50 +00:00
|
|
|
Mgrlog("Auto created echo %s, group %s, area %ld, for node %s",
|
2002-04-27 21:06:51 +00:00
|
|
|
msgs.Tag, msgs.Group, offset, ascfnode(f , 0x1f));
|
2002-03-27 20:12:30 +00:00
|
|
|
return 0;
|
|
|
|
} /* if (strcmp(tag, Area) == 0) */
|
|
|
|
} /* if (strlen(buf) && isalnum(buf[0])) */
|
2002-03-03 16:28:10 +00:00
|
|
|
} /* while (fgets(buf, 4096, ap)) */
|
|
|
|
|
2002-03-25 12:24:24 +00:00
|
|
|
Syslog('m', "Area %s not found in taglist", Area);
|
2002-03-03 16:28:10 +00:00
|
|
|
free(buf);
|
|
|
|
fclose(ap);
|
|
|
|
free(temp);
|
|
|
|
return 1;
|
2002-02-14 21:24:27 +00:00
|
|
|
}
|
|
|
|
|
2002-03-03 16:28:10 +00:00
|
|
|
|