2001-08-17 05:46:24 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2001-11-04 16:41:54 +00:00
|
|
|
* $Id$
|
|
|
|
* Purpose: Fidonet mailer
|
2001-08-17 05:46:24 +00:00
|
|
|
*
|
|
|
|
*****************************************************************************
|
2004-01-02 13:57:48 +00:00
|
|
|
* Copyright (C) 1997-2004
|
2001-08-17 05:46:24 +00:00
|
|
|
*
|
|
|
|
* 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
|
2003-08-15 20:05:34 +00:00
|
|
|
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
2001-08-17 05:46:24 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2002-06-30 12:48:44 +00:00
|
|
|
#include "../config.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "../lib/libs.h"
|
|
|
|
#include "../lib/structs.h"
|
2002-01-07 19:16:03 +00:00
|
|
|
#include "../lib/users.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "../lib/records.h"
|
|
|
|
#include "../lib/common.h"
|
2002-12-28 17:29:06 +00:00
|
|
|
#include "../lib/nodelist.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "../lib/clcomm.h"
|
|
|
|
#include "../lib/dbcfg.h"
|
|
|
|
#include "../lib/dbnode.h"
|
|
|
|
#include "../lib/dbftn.h"
|
2002-10-20 20:58:55 +00:00
|
|
|
#include "../lib/mberrors.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "answer.h"
|
|
|
|
#include "call.h"
|
|
|
|
#include "lutil.h"
|
|
|
|
#include "mbcico.h"
|
|
|
|
#include "session.h"
|
|
|
|
|
2003-09-19 18:32:46 +00:00
|
|
|
#define IEMSI 1
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
int master = 0;
|
|
|
|
int immediatecall = FALSE;
|
|
|
|
char *forcedphone = NULL;
|
|
|
|
char *forcedline = NULL;
|
|
|
|
char *inetaddr = NULL;
|
2003-01-02 16:44:28 +00:00
|
|
|
char *protocol = NULL;
|
2001-08-17 05:46:24 +00:00
|
|
|
char *envptr = NULL;
|
|
|
|
time_t t_start;
|
|
|
|
time_t t_end;
|
|
|
|
time_t c_start;
|
|
|
|
time_t c_end;
|
|
|
|
int online = 0;
|
|
|
|
unsigned long sentbytes = 0;
|
|
|
|
unsigned long rcvdbytes = 0;
|
|
|
|
int tcp_mode = TCPMODE_NONE;
|
|
|
|
int Loaded = FALSE;
|
2003-11-22 21:42:44 +00:00
|
|
|
int telnet = FALSE;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
extern char *myname;
|
|
|
|
char *inbound;
|
2003-08-23 14:57:51 +00:00
|
|
|
char *tempinbound = NULL;
|
2001-08-17 05:46:24 +00:00
|
|
|
char *uxoutbound;
|
|
|
|
char *name;
|
|
|
|
char *phone;
|
|
|
|
char *flags;
|
|
|
|
extern int gotfiles;
|
|
|
|
extern int mypid;
|
|
|
|
|
|
|
|
|
|
|
|
void usage(void)
|
|
|
|
{
|
2003-01-02 16:44:28 +00:00
|
|
|
fprintf(stderr,"ifcico; (c) Eugene G. Crosser, 1993-1997\n");
|
|
|
|
fprintf(stderr,"mbcico ver. %s; (c) %s\n\n", VERSION, SHORTRIGHT);
|
2003-11-26 20:48:48 +00:00
|
|
|
fprintf(stderr,"mbcico [-a inetaddr[:port]] [-n phone] [-l tty] [-t ibn|-t ifc] node\n");
|
2003-11-25 20:04:43 +00:00
|
|
|
fprintf(stderr,"node should be in domain form, e.g. f11.n22.z3\n");
|
|
|
|
fprintf(stderr," (this implies master mode)\n");
|
|
|
|
fprintf(stderr," or:\n");
|
2003-11-26 20:48:48 +00:00
|
|
|
fprintf(stderr,"mbcico tsync|yoohoo|**EMSI_INQC816|-t ibn|-t ifc\n");
|
2003-11-25 20:04:43 +00:00
|
|
|
fprintf(stderr," (this implies slave mode)\n");
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void free_mem(void)
|
|
|
|
{
|
2003-01-02 16:44:28 +00:00
|
|
|
free(inbound);
|
|
|
|
if (name)
|
|
|
|
free(name);
|
|
|
|
if (phone)
|
|
|
|
free(phone);
|
|
|
|
if (flags)
|
|
|
|
free(flags);
|
|
|
|
if (uxoutbound)
|
|
|
|
free(uxoutbound);
|
2003-12-08 18:01:25 +00:00
|
|
|
if (protocol)
|
|
|
|
free(protocol);
|
|
|
|
if ((nlent) && (nlent->url))
|
|
|
|
free(nlent->url);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void die(int onsig)
|
|
|
|
{
|
2003-01-02 16:44:28 +00:00
|
|
|
int total = 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-01-02 16:44:28 +00:00
|
|
|
signal(onsig, SIG_IGN);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-01-02 16:44:28 +00:00
|
|
|
if (onsig) {
|
|
|
|
if (onsig <= NSIG)
|
|
|
|
WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]);
|
|
|
|
else
|
|
|
|
Syslog('+', "Terminated with error %d", onsig);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sentbytes || rcvdbytes) {
|
2004-01-25 10:57:35 +00:00
|
|
|
total = (int)(c_end - c_start -2);
|
|
|
|
if (total < 1)
|
2003-01-02 16:44:28 +00:00
|
|
|
total = 1;
|
|
|
|
Syslog('+', "Sent %lu bytes, received %lu bytes, avg %d cps", sentbytes, rcvdbytes, (sentbytes + rcvdbytes) / total);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (online)
|
|
|
|
Syslog('+', "Connected %s", str_time(online));
|
|
|
|
|
|
|
|
if (gotfiles)
|
|
|
|
CreateSema((char *)"mailin");
|
|
|
|
|
2003-12-08 18:01:25 +00:00
|
|
|
/*
|
|
|
|
* Free memory
|
|
|
|
*/
|
2003-01-02 16:44:28 +00:00
|
|
|
free_mem();
|
2003-12-04 22:07:33 +00:00
|
|
|
deinitnl();
|
|
|
|
|
2004-01-02 13:57:48 +00:00
|
|
|
t_end = time(NULL);
|
|
|
|
Syslog(' ', "MBCICO finished in %s", t_elapsed(t_start, t_end));
|
|
|
|
|
2003-01-02 16:44:28 +00:00
|
|
|
if (envptr)
|
|
|
|
free(envptr);
|
|
|
|
ExitClient(onsig);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2003-01-02 16:44:28 +00:00
|
|
|
faddr *addr = NULL;
|
|
|
|
int i, c, uid, rc, maxrc;
|
|
|
|
char *answermode = NULL, *p = NULL, *cmd = NULL;
|
|
|
|
struct passwd *pw;
|
|
|
|
FILE *fp;
|
2001-12-02 14:01:49 +00:00
|
|
|
#ifdef IEMSI
|
2003-01-02 16:44:28 +00:00
|
|
|
char temp[PATH_MAX];
|
2001-12-02 14:01:49 +00:00
|
|
|
#endif
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-01-02 16:44:28 +00:00
|
|
|
/*
|
|
|
|
* The next trick is to supply a fake environment variable
|
|
|
|
* MBSE_ROOT in case we are started from inetd or mgetty,
|
|
|
|
* this will setup the variable so InitConfig() will work.
|
|
|
|
* The /etc/passwd must point to the correct homedirectory.
|
|
|
|
*/
|
|
|
|
pw = getpwuid(getuid());
|
|
|
|
if (getenv("MBSE_ROOT") == NULL) {
|
|
|
|
envptr = xstrcpy((char *)"MBSE_ROOT=");
|
|
|
|
envptr = xstrcat(envptr, pw->pw_dir);
|
|
|
|
putenv(envptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
usage();
|
|
|
|
if (envptr)
|
|
|
|
free(envptr);
|
|
|
|
exit(MBERR_COMMANDLINE);
|
|
|
|
}
|
|
|
|
|
|
|
|
InitConfig();
|
|
|
|
InitNode();
|
|
|
|
InitFidonet();
|
|
|
|
TermInit(1);
|
|
|
|
t_start = c_start = c_end = time(NULL);
|
|
|
|
|
2003-09-09 19:39:51 +00:00
|
|
|
InitClient(pw->pw_name, (char *)"mbcico", CFG.location, CFG.logfile,
|
|
|
|
CFG.cico_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
|
2003-01-02 16:44:28 +00:00
|
|
|
Syslog(' ', " ");
|
|
|
|
Syslog(' ', "MBCICO v%s", VERSION);
|
|
|
|
|
|
|
|
/*
|
2003-10-13 21:36:30 +00:00
|
|
|
* Catch all signals we can, and ignore the rest.
|
2003-01-02 16:44:28 +00:00
|
|
|
*/
|
|
|
|
for (i = 0; i < NSIG; i++) {
|
2003-12-04 22:07:33 +00:00
|
|
|
if ((i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM)) {
|
2003-01-02 16:44:28 +00:00
|
|
|
signal(i, (void (*))die);
|
2003-12-04 22:07:33 +00:00
|
|
|
} else if ((i != SIGKILL) && (i != SIGSTOP)) {
|
2003-10-13 21:36:30 +00:00
|
|
|
signal(i, SIG_IGN);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2003-01-02 16:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if history file exists, if not create a new one.
|
|
|
|
*/
|
|
|
|
cmd = calloc(PATH_MAX, sizeof(char));
|
|
|
|
sprintf(cmd, "%s/var/mailer.hist", getenv("MBSE_ROOT"));
|
|
|
|
if ((fp = fopen(cmd, "r")) == NULL) {
|
|
|
|
if ((fp = fopen(cmd, "a")) == NULL) {
|
|
|
|
WriteError("$Can't create %s", cmd);
|
2001-08-17 05:46:24 +00:00
|
|
|
} else {
|
2003-01-02 16:44:28 +00:00
|
|
|
memset(&history, 0, sizeof(history));
|
|
|
|
history.online = time(NULL);
|
|
|
|
history.offline = time(NULL);
|
|
|
|
fwrite(&history, sizeof(history), 1, fp);
|
|
|
|
fclose(fp);
|
|
|
|
Syslog('+', "Created new %s", cmd);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2003-01-02 16:44:28 +00:00
|
|
|
} else {
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
free(cmd);
|
|
|
|
memset(&history, 0, sizeof(history));
|
|
|
|
|
|
|
|
cmd = xstrcpy((char *)"Cmd: mbcico");
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
cmd = xstrcat(cmd, (char *)" ");
|
|
|
|
cmd = xstrcat(cmd, argv[i]);
|
|
|
|
}
|
|
|
|
Syslog(' ', cmd);
|
|
|
|
free(cmd);
|
|
|
|
|
|
|
|
setmyname(argv[0]);
|
|
|
|
|
|
|
|
while ((c = getopt(argc,argv,"r:n:l:t:a:I:h")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'r': WriteError("commandline option -r is obsolete");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l': forcedline = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't': p = xstrcpy(optarg);
|
|
|
|
if (strncmp(p, "ifc", 3) == 0) {
|
|
|
|
tcp_mode = TCPMODE_IFC;
|
|
|
|
protocol = xstrcpy((char *)"fido");
|
|
|
|
} else if (strncmp(p, "ibn", 3) == 0) {
|
|
|
|
tcp_mode = TCPMODE_IBN;
|
|
|
|
protocol = xstrcpy((char *)"binkp");
|
2003-11-22 21:42:44 +00:00
|
|
|
} else if (strncmp(p, "itn", 3) == 0) {
|
|
|
|
tcp_mode = TCPMODE_ITN;
|
2003-11-25 20:04:43 +00:00
|
|
|
protocol = xstrcpy((char *)"telnet");
|
2003-11-22 21:42:44 +00:00
|
|
|
telnet = TRUE;
|
2003-01-02 16:44:28 +00:00
|
|
|
} else {
|
|
|
|
usage();
|
|
|
|
die(MBERR_COMMANDLINE);
|
|
|
|
}
|
|
|
|
free(p);
|
|
|
|
RegTCP();
|
|
|
|
break;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-01-02 16:44:28 +00:00
|
|
|
case 'a': inetaddr = optarg;
|
|
|
|
break;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-01-02 16:44:28 +00:00
|
|
|
case 'n': forcedphone = optarg;
|
|
|
|
break;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-01-02 16:44:28 +00:00
|
|
|
default: usage();
|
|
|
|
die(MBERR_COMMANDLINE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load rest of the configuration
|
|
|
|
*/
|
|
|
|
inbound = xstrcpy(CFG.inbound);
|
|
|
|
uxoutbound = xstrcpy(CFG.uxpath);
|
|
|
|
name = xstrcpy(CFG.bbs_name);
|
|
|
|
phone = xstrcpy(CFG.Phone);
|
|
|
|
flags = xstrcpy(CFG.Flags);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-01-02 16:44:28 +00:00
|
|
|
while (argv[optind]) {
|
2001-12-02 14:01:49 +00:00
|
|
|
|
2003-01-02 16:44:28 +00:00
|
|
|
for (p = argv[optind]; (*p) && (*p == '*'); p++);
|
2001-12-02 14:01:49 +00:00
|
|
|
#ifdef IEMSI
|
2003-01-02 16:44:28 +00:00
|
|
|
if (strncasecmp(p, "EMSI_NAKEEC3", 12) == 0) {
|
|
|
|
|
2003-09-19 18:32:46 +00:00
|
|
|
Syslog('+', "Detected IEMSI client, starting mblogin");
|
|
|
|
sprintf(temp, "%s/bin/mblogin", getenv("MBSE_ROOT"));
|
2003-01-02 16:44:28 +00:00
|
|
|
socket_shutdown(mypid);
|
|
|
|
|
2003-09-19 18:32:46 +00:00
|
|
|
if (execl(temp, "mblogin", (char *)NULL) == -1)
|
2003-01-02 16:44:28 +00:00
|
|
|
perror("FATAL: Error loading BBS!");
|
|
|
|
|
2003-09-19 18:32:46 +00:00
|
|
|
InitClient(pw->pw_name, (char *)"mbcico", CFG.location, CFG.logfile,
|
|
|
|
CFG.cico_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
|
2003-01-02 16:44:28 +00:00
|
|
|
/*
|
|
|
|
* If this happens, nothing is logged!
|
|
|
|
*/
|
|
|
|
printf("\n\nFATAL: Loading of the BBS failed!\n\n");
|
|
|
|
sleep(3);
|
|
|
|
free_mem();
|
|
|
|
if (envptr)
|
|
|
|
free(envptr);
|
2003-09-19 18:32:46 +00:00
|
|
|
exit(MBERR_EXEC_FAILED);
|
2003-01-02 16:44:28 +00:00
|
|
|
}
|
2001-12-02 14:01:49 +00:00
|
|
|
#endif
|
2003-01-02 16:44:28 +00:00
|
|
|
if ((strcasecmp(argv[optind],"tsync") == 0) ||
|
|
|
|
(strcasecmp(argv[optind],"yoohoo") == 0) ||
|
|
|
|
(strcasecmp(argv[optind],"ibn") == 0) ||
|
|
|
|
(strncasecmp(p,"EMSI_",5) == 0)) {
|
|
|
|
master = 0;
|
|
|
|
answermode = argv[optind];
|
|
|
|
} else {
|
|
|
|
if ((addr = parsefaddr(argv[optind]))) {
|
|
|
|
immediatecall = TRUE;
|
2001-08-17 05:46:24 +00:00
|
|
|
master = 1;
|
2003-01-02 16:44:28 +00:00
|
|
|
} else {
|
|
|
|
WriteError("Unrecognizable address \"%s\"", argv[optind]);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2003-01-02 16:44:28 +00:00
|
|
|
optind++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
The following witchkraft about uid-s is necessary to make
|
|
|
|
access() work right. Unforunately, access() checks the real
|
|
|
|
uid, if mbcico is invoked with supervisor real uid (as when
|
|
|
|
called by uugetty) it returns X_OK for the magic files that
|
|
|
|
even do not have `x' bit set. Therefore, `reference' magic
|
|
|
|
file requests are taken for `execute' requests (and the
|
|
|
|
actual execution natually fails). Here we set real uid equal
|
|
|
|
to effective. If real uid is not zero, all these fails, but
|
|
|
|
in this case it is not necessary anyway.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uid=geteuid();
|
|
|
|
seteuid(0);
|
|
|
|
setuid(uid);
|
|
|
|
seteuid(uid);
|
|
|
|
|
|
|
|
umask(066); /* packets may contain confidential information */
|
|
|
|
|
|
|
|
maxrc=0;
|
|
|
|
if (master) {
|
2001-08-17 05:46:24 +00:00
|
|
|
/*
|
2003-01-02 16:44:28 +00:00
|
|
|
* Don't do outbound calls if low diskspace
|
|
|
|
*/
|
|
|
|
if (!diskfree(CFG.freespace))
|
|
|
|
die(MBERR_DISK_FULL);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-01-02 16:44:28 +00:00
|
|
|
if (addr == NULL) {
|
|
|
|
WriteError("Calling mbcico without node address not supported anymore");
|
|
|
|
die(MBERR_COMMANDLINE);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-01-02 16:44:28 +00:00
|
|
|
rc = call(addr);
|
|
|
|
Syslog('+', "Call to %s %s (rc=%d)", ascfnode(addr, 0x1f), rc?"failed":"successful", rc);
|
|
|
|
if (rc > maxrc)
|
|
|
|
maxrc=rc;
|
|
|
|
} else {
|
2003-11-26 20:48:48 +00:00
|
|
|
/*
|
|
|
|
* Slave (answer) mode
|
|
|
|
*/
|
2003-01-02 16:44:28 +00:00
|
|
|
if (!answermode && tcp_mode == TCPMODE_IBN)
|
|
|
|
answermode = xstrcpy((char *)"ibn");
|
|
|
|
rc = maxrc = answer(answermode);
|
|
|
|
Syslog('+', "Incoming call %s (rc=%d)", rc?"failed":"successful", rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
tidy_faddr(addr);
|
|
|
|
if (maxrc)
|
|
|
|
die(maxrc);
|
|
|
|
else
|
|
|
|
die(MBERR_OK);
|
|
|
|
return 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|