2001-08-17 05:46:24 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2001-11-04 16:41:54 +00:00
|
|
|
* $Id$
|
|
|
|
* Purpose: MBSE BBS Outbound Manager
|
2001-08-17 05:46:24 +00:00
|
|
|
*
|
|
|
|
*****************************************************************************
|
2005-08-19 20:48:54 +00:00
|
|
|
* Copyright (C) 1997-2005
|
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"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbselib.h"
|
2002-12-28 17:29:06 +00:00
|
|
|
#include "../lib/nodelist.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/users.h"
|
|
|
|
#include "../lib/mbsedb.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "outstat.h"
|
|
|
|
#include "nlinfo.h"
|
|
|
|
|
2003-12-04 22:07:33 +00:00
|
|
|
extern int most_debug;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-06-19 20:31:35 +00:00
|
|
|
extern int do_quiet; /* Suppress screen output */
|
2001-08-17 05:46:24 +00:00
|
|
|
int do_attach = FALSE; /* Send file attaches */
|
|
|
|
int do_node = FALSE; /* Query the nodelist */
|
|
|
|
int do_poll = FALSE; /* Poll a node */
|
|
|
|
int do_req = FALSE; /* Request files from a node */
|
|
|
|
int do_stat = FALSE; /* Show outbound status */
|
|
|
|
int do_stop = FALSE; /* Stop polling a node */
|
2002-03-17 12:14:40 +00:00
|
|
|
int do_reset = FALSE; /* Reset node's try counter */
|
2004-03-02 20:47:23 +00:00
|
|
|
extern pid_t e_pid; /* Pid of child */
|
2001-08-17 05:46:24 +00:00
|
|
|
extern int show_log; /* Show logging */
|
|
|
|
time_t t_start; /* Start time */
|
|
|
|
time_t t_end; /* End time */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ProgName(void);
|
|
|
|
void ProgName()
|
|
|
|
{
|
2005-08-19 20:48:54 +00:00
|
|
|
if (do_quiet)
|
|
|
|
return;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2005-08-19 20:48:54 +00:00
|
|
|
mbse_colour(WHITE, BLACK);
|
|
|
|
printf("\nMBOUT: MBSE BBS %s Outbound Manager\n", VERSION);
|
|
|
|
mbse_colour(YELLOW, BLACK);
|
|
|
|
printf(" %s\n", COPYRIGHT);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void die(int);
|
|
|
|
void die(int onsig)
|
|
|
|
{
|
2002-12-30 22:13:33 +00:00
|
|
|
deinitnl();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First check if a child is running, if so, kill it.
|
|
|
|
*/
|
|
|
|
if (e_pid) {
|
|
|
|
if ((kill(e_pid, SIGTERM)) == 0)
|
|
|
|
Syslog('+', "SIGTERM to pid %d succeeded", e_pid);
|
|
|
|
else {
|
|
|
|
if ((kill(e_pid, SIGKILL)) == 0)
|
|
|
|
Syslog('+', "SIGKILL to pid %d succeded", e_pid);
|
|
|
|
else
|
|
|
|
WriteError("$Failed to kill pid %d", e_pid);
|
|
|
|
}
|
|
|
|
|
2001-08-17 05:46:24 +00:00
|
|
|
/*
|
2002-12-30 22:13:33 +00:00
|
|
|
* In case the child had the tty in raw mode...
|
2001-08-17 05:46:24 +00:00
|
|
|
*/
|
2004-03-02 20:47:23 +00:00
|
|
|
execute_pth((char *)"stty", (char *)"sane", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
2002-12-30 22:13:33 +00:00
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-12-30 22:13:33 +00:00
|
|
|
signal(onsig, SIG_IGN);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-12-30 22:13:33 +00:00
|
|
|
if (show_log)
|
|
|
|
do_quiet = FALSE;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-12-30 22:13:33 +00:00
|
|
|
if (!do_quiet)
|
2005-08-19 20:48:54 +00:00
|
|
|
mbse_colour(CYAN, BLACK);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-12-30 22:13:33 +00:00
|
|
|
if (onsig) {
|
|
|
|
if (onsig <= NSIG)
|
|
|
|
WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]);
|
|
|
|
else
|
|
|
|
WriteError("Terminated with error %d", onsig);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-12-30 22:13:33 +00:00
|
|
|
t_end = time(NULL);
|
|
|
|
Syslog(' ', "MBOUT finished in %s", t_elapsed(t_start, t_end));
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-12-30 22:13:33 +00:00
|
|
|
if (!do_quiet) {
|
2005-08-19 20:48:54 +00:00
|
|
|
mbse_colour(LIGHTGRAY, BLACK);
|
2002-12-30 22:13:33 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
ExitClient(onsig);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Help(void);
|
|
|
|
void Help()
|
|
|
|
{
|
2005-08-19 20:48:54 +00:00
|
|
|
do_quiet = FALSE;
|
|
|
|
ProgName();
|
|
|
|
|
|
|
|
mbse_colour(LIGHTCYAN, BLACK);
|
|
|
|
printf("\nUsage: mbout [command] <params> <options>\n\n");
|
|
|
|
mbse_colour(LIGHTBLUE, BLACK);
|
|
|
|
printf(" Commands are:\n\n");
|
|
|
|
mbse_colour(CYAN, BLACK);
|
|
|
|
printf(" a att <node> <flavor> <file> Attach a file to a node\n");
|
|
|
|
printf(" n node <node> Show nodelist information\n");
|
|
|
|
printf(" p poll <node> [node..node] Poll node(s) (always crash)\n");
|
|
|
|
printf(" req req <node> <file> [file..file] Request file(s) from node\n");
|
|
|
|
printf(" res reset <node> [node..node] Reset node(s) \"try\" counter\n");
|
|
|
|
printf(" sta stat Show outbound status\n");
|
|
|
|
printf(" sto stop <node> [node..node] Stop polling node(s)\n");
|
|
|
|
printf("\n");
|
|
|
|
printf(" <node> Should be in domain form, e.g. f16.n2801.z2.domain\n");
|
|
|
|
printf(" <flavor> Flavor's are: crash | immediate | normal | hold\n");
|
|
|
|
mbse_colour(LIGHTBLUE, BLACK);
|
|
|
|
printf("\n Options are:\n\n");
|
|
|
|
mbse_colour(CYAN, BLACK);
|
|
|
|
printf(" -quiet Quiet mode\n");
|
|
|
|
mbse_colour(LIGHTGRAY, BLACK);
|
|
|
|
die(MBERR_OK);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-20 20:58:55 +00:00
|
|
|
void Fatal(char *, int);
|
|
|
|
void Fatal(char *msg, int error)
|
2001-08-17 05:46:24 +00:00
|
|
|
{
|
2002-10-20 20:58:55 +00:00
|
|
|
show_log = TRUE;
|
|
|
|
if (!do_quiet) {
|
2005-08-19 20:48:54 +00:00
|
|
|
mbse_colour(LIGHTRED, BLACK);
|
2002-10-20 20:58:55 +00:00
|
|
|
printf("%s\n", msg);
|
|
|
|
}
|
|
|
|
WriteError(msg);
|
|
|
|
die(error);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2002-08-05 20:43:29 +00:00
|
|
|
char *cmd, flavor = 'x';
|
|
|
|
int i, j, rc = 0;
|
|
|
|
struct passwd *pw;
|
|
|
|
faddr *addr = NULL;
|
|
|
|
node *nlent;
|
|
|
|
FILE *fl;
|
2002-12-30 22:13:33 +00:00
|
|
|
|
2003-12-04 22:07:33 +00:00
|
|
|
most_debug = TRUE;
|
|
|
|
|
2002-08-05 20:43:29 +00:00
|
|
|
InitConfig();
|
|
|
|
InitNode();
|
|
|
|
InitFidonet();
|
2004-10-27 11:08:09 +00:00
|
|
|
mbse_TermInit(1, 80, 25);
|
2002-08-05 20:43:29 +00:00
|
|
|
t_start = time(NULL);
|
|
|
|
umask(002);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Catch all signals we can, and ignore the rest.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < NSIG; i++) {
|
2003-12-08 18:01:25 +00:00
|
|
|
if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
|
2002-08-05 20:43:29 +00:00
|
|
|
signal(i, (void (*))die);
|
2003-12-08 18:01:25 +00:00
|
|
|
else if ((i != SIGKILL) && (i != SIGSTOP))
|
2002-08-05 20:43:29 +00:00
|
|
|
signal(i, SIG_IGN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(argc < 2)
|
|
|
|
Help();
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-05 20:43:29 +00:00
|
|
|
cmd = xstrcpy((char *)"Command line: mbout");
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
cmd = xstrcat(cmd, (char *)" ");
|
|
|
|
cmd = xstrcat(cmd, argv[1]);
|
|
|
|
|
|
|
|
if (!strncasecmp(argv[1], "a", 1))
|
|
|
|
do_attach = TRUE;
|
|
|
|
if (!strncasecmp(argv[1], "n", 1))
|
|
|
|
do_node = TRUE;
|
|
|
|
if (!strncasecmp(argv[1], "p", 1))
|
|
|
|
do_poll = TRUE;
|
|
|
|
if (!strncasecmp(argv[1], "req", 3))
|
|
|
|
do_req = TRUE;
|
|
|
|
if (!strncasecmp(argv[1], "res", 3))
|
|
|
|
do_reset = TRUE;
|
|
|
|
if (!strncasecmp(argv[1], "sta", 3))
|
|
|
|
do_stat = TRUE;
|
|
|
|
if (!strncasecmp(argv[1], "sto", 3))
|
|
|
|
do_stop = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 2; i < argc; i++) {
|
|
|
|
|
|
|
|
cmd = xstrcat(cmd, (char *)" ");
|
|
|
|
cmd = xstrcat(cmd, argv[i]);
|
|
|
|
|
|
|
|
if (!strncasecmp(argv[i], "-q", 2))
|
|
|
|
do_quiet = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgName();
|
|
|
|
pw = getpwuid(getuid());
|
2003-09-09 19:39:51 +00:00
|
|
|
InitClient(pw->pw_name, (char *)"mbout", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
|
2002-08-05 20:43:29 +00:00
|
|
|
Syslog(' ', " ");
|
|
|
|
Syslog(' ', "MBOUT v%s", VERSION);
|
|
|
|
Syslog(' ', cmd);
|
|
|
|
free(cmd);
|
|
|
|
|
|
|
|
if (!do_quiet) {
|
2005-08-19 20:48:54 +00:00
|
|
|
mbse_colour(CYAN, BLACK);
|
2002-08-05 20:43:29 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(pw->pw_name, "mbse"))
|
2002-10-20 20:58:55 +00:00
|
|
|
Fatal((char *)"You are not user 'mbse'", MBERR_COMMANDLINE);
|
2002-08-05 20:43:29 +00:00
|
|
|
|
|
|
|
if (do_stat) {
|
|
|
|
rc = outstat();
|
|
|
|
die(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get node number from commandline
|
|
|
|
*/
|
|
|
|
if (do_attach || do_node || do_poll || do_stop || do_req || do_reset) {
|
|
|
|
if (argc < 3)
|
2002-10-20 20:58:55 +00:00
|
|
|
Fatal((char *)"Not enough parameters", MBERR_COMMANDLINE);
|
2002-08-05 20:43:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (do_attach || do_node || do_req || do_reset) {
|
|
|
|
if ((addr = parsefaddr(argv[2])) == NULL)
|
2002-10-20 20:58:55 +00:00
|
|
|
Fatal((char *)"Unrecognizable address", MBERR_COMMANDLINE);
|
2002-08-05 20:43:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (do_node) {
|
|
|
|
rc = nlinfo(addr);
|
|
|
|
tidy_faddr(addr);
|
|
|
|
die(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_poll || do_stop) {
|
2003-12-08 18:01:25 +00:00
|
|
|
tidy_faddr(addr);
|
2002-08-05 20:43:29 +00:00
|
|
|
for (i = 3; i <= argc; i++) {
|
|
|
|
if (strncasecmp(argv[i-1], "-q", 2)) {
|
|
|
|
if ((addr = parsefaddr(argv[i-1])) == NULL)
|
2002-10-20 20:58:55 +00:00
|
|
|
Fatal((char *)"Unrecognizable address", MBERR_COMMANDLINE);
|
2004-02-21 17:22:00 +00:00
|
|
|
j = pollnode(addr, do_stop);
|
2001-08-17 05:46:24 +00:00
|
|
|
tidy_faddr(addr);
|
2002-10-20 20:58:55 +00:00
|
|
|
if (j)
|
2002-08-05 20:43:29 +00:00
|
|
|
rc = j;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2002-08-05 20:43:29 +00:00
|
|
|
die(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_reset) {
|
2003-12-08 18:01:25 +00:00
|
|
|
tidy_faddr(addr);
|
2002-08-05 20:43:29 +00:00
|
|
|
for (i = 3; i <= argc; i++) {
|
|
|
|
if (strncasecmp(argv[i-1], "-q", 2)) {
|
|
|
|
if ((addr = parsefaddr(argv[i-1])) == NULL)
|
2002-10-20 20:58:55 +00:00
|
|
|
Fatal((char *)"Unrecognizable address", MBERR_COMMANDLINE);
|
2002-08-05 20:43:29 +00:00
|
|
|
j = reset(addr);
|
|
|
|
tidy_faddr(addr);
|
2002-10-20 20:58:55 +00:00
|
|
|
if (j)
|
2002-08-05 20:43:29 +00:00
|
|
|
rc = j;
|
2002-03-17 12:34:38 +00:00
|
|
|
}
|
2002-03-17 12:14:40 +00:00
|
|
|
}
|
2002-08-05 20:43:29 +00:00
|
|
|
die(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_attach) {
|
|
|
|
if (argc < 5)
|
2002-10-20 20:58:55 +00:00
|
|
|
Fatal((char *)"Not enough parameters", MBERR_COMMANDLINE);
|
2002-08-05 20:43:29 +00:00
|
|
|
flavor = tolower(argv[3][0]);
|
|
|
|
switch (flavor) {
|
|
|
|
case 'n' : flavor = 'f'; break;
|
|
|
|
case 'i' : flavor = 'i'; break;
|
|
|
|
case 'c' : flavor = 'c'; break;
|
|
|
|
case 'h' : flavor = 'h'; break;
|
2002-10-20 20:58:55 +00:00
|
|
|
default : Fatal((char *)"Invalid flavor, must be: immediate, crash, normal or hold", MBERR_COMMANDLINE);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
2002-08-05 20:43:29 +00:00
|
|
|
nlent = getnlent(addr);
|
2003-12-08 18:01:25 +00:00
|
|
|
if (nlent->addr.domain)
|
|
|
|
free(nlent->addr.domain);
|
|
|
|
nlent->addr.domain = NULL;
|
|
|
|
if (nlent->url)
|
|
|
|
free(nlent->url);
|
|
|
|
nlent->url = NULL;
|
|
|
|
|
2002-08-05 20:43:29 +00:00
|
|
|
if (nlent->pflag == NL_DUMMY)
|
2002-10-20 20:58:55 +00:00
|
|
|
Fatal((char *)"Node is not in nodelist", MBERR_NODE_NOT_IN_LIST);
|
2002-08-05 20:43:29 +00:00
|
|
|
if (nlent->pflag == NL_DOWN)
|
2002-10-20 20:58:55 +00:00
|
|
|
Fatal((char *)"Node has status Down", MBERR_NODE_MAY_NOT_CALL);
|
2002-08-05 20:43:29 +00:00
|
|
|
if (nlent->pflag == NL_HOLD)
|
2002-10-20 20:58:55 +00:00
|
|
|
Fatal((char *)"Node has status Hold", MBERR_NODE_MAY_NOT_CALL);
|
2004-06-18 19:54:13 +00:00
|
|
|
if (((nlent->can_pots && nlent->is_cm) == FALSE) && ((nlent->can_ip && nlent->is_icm) == FALSE) && (flavor == 'c'))
|
2002-10-20 20:58:55 +00:00
|
|
|
Fatal((char *)"Node is not CM, must use Immediate, Normal or Hold flavor", MBERR_NODE_MAY_NOT_CALL);
|
2002-08-05 20:43:29 +00:00
|
|
|
|
|
|
|
if (argv[4][0] == '-')
|
2002-10-20 20:58:55 +00:00
|
|
|
Fatal((char *)"Invalid filename given", MBERR_COMMANDLINE);
|
2002-08-05 20:43:29 +00:00
|
|
|
if (file_exist(argv[4], R_OK) != 0)
|
2002-10-20 20:58:55 +00:00
|
|
|
Fatal((char *)"File doesn't exist", MBERR_COMMANDLINE);
|
2002-08-05 20:43:29 +00:00
|
|
|
|
|
|
|
cmd = calloc(PATH_MAX, sizeof(char));
|
|
|
|
sprintf(cmd, "%s/%d.%d.%d.%d/.filelist", CFG.out_queue, addr->zone, addr->net, addr->node, addr->point);
|
|
|
|
mkdirs(cmd, 0750);
|
|
|
|
if ((fl = fopen(cmd, "a+")) == NULL) {
|
2002-10-20 20:58:55 +00:00
|
|
|
Fatal((char *)"File attach failed", MBERR_ATTACH_FAILED);
|
2002-08-05 20:43:29 +00:00
|
|
|
} else {
|
2004-07-16 10:57:32 +00:00
|
|
|
fprintf(fl, "%c LEAVE NOR %s\n", flavor, argv[4]);
|
2002-08-05 20:43:29 +00:00
|
|
|
Syslog('+', "File attach %s is successfull", argv[4]);
|
|
|
|
if (!do_quiet)
|
|
|
|
printf("File attach %s is successfull", argv[4]);
|
|
|
|
CreateSema((char *)"mailin");
|
|
|
|
tidy_faddr(addr);
|
|
|
|
fsync(fileno(fl));
|
|
|
|
fclose(fl);
|
|
|
|
free(cmd);
|
2002-10-20 20:58:55 +00:00
|
|
|
die(MBERR_OK);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2002-08-05 20:43:29 +00:00
|
|
|
free(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_req) {
|
|
|
|
if (argc < 4)
|
2002-10-20 20:58:55 +00:00
|
|
|
Fatal((char *)"Not enough parameters", MBERR_COMMANDLINE);
|
2002-08-05 20:43:29 +00:00
|
|
|
for (i = 4; i <= argc; i++) {
|
|
|
|
if (strncasecmp(argv[i-1], "-q", 2)) {
|
|
|
|
rc = freq(addr, argv[i-1]);
|
|
|
|
if (rc)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-12-08 18:01:25 +00:00
|
|
|
tidy_faddr(addr);
|
2002-08-05 20:43:29 +00:00
|
|
|
die(rc);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-05 20:43:29 +00:00
|
|
|
Help();
|
2002-10-20 20:58:55 +00:00
|
|
|
return MBERR_OK;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|