This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-mbse/mbcico/mbout.c

378 lines
8.8 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
* $Id$
* Purpose: MBSE BBS Outbound Manager
2001-08-17 05:46:24 +00:00
*
*****************************************************************************
2002-01-07 19:16:03 +00:00
* Copyright (C) 1997-2002
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
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
2002-06-30 12:48:44 +00:00
#include "../config.h"
2001-08-17 05:46:24 +00:00
#include "../lib/libs.h"
2002-06-30 12:48:44 +00:00
#include "../lib/memwatch.h"
2001-08-17 05:46:24 +00:00
#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"
#include "../lib/clcomm.h"
#include "../lib/dbcfg.h"
#include "../lib/dbnode.h"
#include "../lib/dbftn.h"
#include "outstat.h"
#include "nlinfo.h"
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 */
2001-08-17 05:46:24 +00:00
int e_pid = 0; /* Pid of child */
extern int show_log; /* Show logging */
time_t t_start; /* Start time */
time_t t_end; /* End time */
void ProgName(void);
void ProgName()
{
if (do_quiet)
return;
colour(15, 0);
printf("\nMBOUT: MBSE BBS %s Outbound Manager\n", VERSION);
colour(14, 0);
printf(" %s\n", COPYRIGHT);
2001-08-17 05:46:24 +00:00
}
void die(int);
void die(int onsig)
{
/*
* 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);
}
/*
* In case the child had the tty in raw mode...
*/
system("stty sane");
}
signal(onsig, SIG_IGN);
if (show_log)
do_quiet = FALSE;
if (!do_quiet)
colour(3, 0);
if (onsig) {
if (onsig <= NSIG)
2002-05-10 18:14:27 +00:00
WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]);
2001-08-17 05:46:24 +00:00
else
WriteError("Terminated with error %d", onsig);
}
2001-12-23 16:44:18 +00:00
t_end = time(NULL);
2001-08-17 05:46:24 +00:00
Syslog(' ', "MBOUT finished in %s", t_elapsed(t_start, t_end));
if (!do_quiet) {
colour(7, 0);
printf("\n");
}
ExitClient(onsig);
}
void Help(void);
void Help()
{
do_quiet = FALSE;
ProgName();
colour(11, 0);
printf("\nUsage: mbout [command] <params> <options>\n\n");
colour(9, 0);
printf(" Commands are:\n\n");
colour(3, 0);
2002-03-17 12:14:40 +00:00
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");
2002-03-17 12:34:38 +00:00
printf(" res reset <node> [node..node] Reset node(s) \"try\" counter\n");
2001-08-17 05:46:24 +00:00
printf(" sta stat Show outbound status\n");
2002-03-17 12:34:38 +00:00
printf(" sto stop <node> [node..node] Stop polling node(s)\n");
2001-08-17 05:46:24 +00:00
printf("\n");
2002-03-17 12:34:38 +00:00
printf(" <node> Should be in domain form, e.g. f16.n2801.z2.domain\n");
printf(" <flavor> Flavor's are: crash | immediate | normal | hold\n");
2001-08-17 05:46:24 +00:00
colour(9, 0);
printf("\n Options are:\n\n");
colour(3, 0);
printf(" -quiet Quiet mode\n");
colour(7, 0);
die(0);
}
void Fatal(char *);
void Fatal(char *msg)
{
show_log = TRUE;
if (!do_quiet) {
colour(12, 0);
printf("%s\n", msg);
}
WriteError(msg);
die(100);
}
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;
2001-08-17 05:46:24 +00:00
#ifdef MEMWATCH
2002-08-05 20:43:29 +00:00
mwInit();
2001-08-17 05:46:24 +00:00
#endif
2002-08-05 20:43:29 +00:00
InitConfig();
InitNode();
InitFidonet();
TermInit(1);
t_start = time(NULL);
umask(002);
/*
* Catch all signals we can, and ignore the rest.
*/
for (i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM) || (i == SIGKILL))
signal(i, (void (*))die);
else
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());
InitClient(pw->pw_name, (char *)"mbout", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log);
Syslog(' ', " ");
Syslog(' ', "MBOUT v%s", VERSION);
Syslog(' ', cmd);
free(cmd);
if (!do_quiet) {
colour(3, 0);
printf("\n");
}
if (strcmp(pw->pw_name, "mbse"))
Fatal((char *)"You are not user 'mbse'");
if (do_stat) {
rc = outstat();
if (rc)
rc += 100;
die(rc);
}
/*
* Get node number from commandline
*/
if (do_attach || do_node || do_poll || do_stop || do_req || do_reset) {
if (argc < 3)
Fatal((char *)"Not enough parameters");
}
if (do_attach || do_node || do_req || do_reset) {
if ((addr = parsefaddr(argv[2])) == NULL)
Fatal((char *)"Unrecognizable address");
}
if (do_node) {
rc = nlinfo(addr);
tidy_faddr(addr);
if (rc)
rc += 100;
die(rc);
}
if (do_poll || do_stop) {
for (i = 3; i <= argc; i++) {
if (strncasecmp(argv[i-1], "-q", 2)) {
if ((addr = parsefaddr(argv[i-1])) == NULL)
Fatal((char *)"Unrecognizable address");
j = poll(addr, do_stop);
2001-08-17 05:46:24 +00:00
tidy_faddr(addr);
2002-08-05 20:43:29 +00:00
if (j > rc)
rc = j;
}
2001-08-17 05:46:24 +00:00
}
2002-08-05 20:43:29 +00:00
if (rc)
rc = 100;
die(rc);
}
if (do_reset) {
for (i = 3; i <= argc; i++) {
if (strncasecmp(argv[i-1], "-q", 2)) {
if ((addr = parsefaddr(argv[i-1])) == NULL)
Fatal((char *)"Unrecognizable address");
j = reset(addr);
tidy_faddr(addr);
if (j > rc)
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
if (rc)
rc = 100;
die(rc);
}
if (do_attach) {
if (argc < 5)
Fatal((char *)"Not enough parameters");
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;
default : Fatal((char *)"Invalid flavor, must be: immediate, crash, normal or hold");
2001-08-17 05:46:24 +00:00
}
2002-08-05 20:43:29 +00:00
nlent = getnlent(addr);
if (nlent->pflag == NL_DUMMY)
Fatal((char *)"Node is not in nodelist");
if (nlent->pflag == NL_DOWN)
Fatal((char *)"Node has status Down");
if (nlent->pflag == NL_HOLD)
Fatal((char *)"Node has status Hold");
if (((nlent->oflags & OL_CM) == 0) && (flavor == 'c'))
Fatal((char *)"Node is not CM, must use Immediate, Normal or Hold flavor");
if (argv[4][0] == '-')
Fatal((char *)"Invalid filename given");
if (file_exist(argv[4], R_OK) != 0)
Fatal((char *)"File doesn't exist");
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) {
Fatal((char *)"File attach failed");
} else {
fprintf(fl, "%c LEAVE %s\n", flavor, argv[4]);
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);
die(0);
2001-08-17 05:46:24 +00:00
}
2002-08-05 20:43:29 +00:00
free(cmd);
}
if (do_req) {
if (argc < 4)
Fatal((char *)"Not enough parameters");
for (i = 4; i <= argc; i++) {
if (strncasecmp(argv[i-1], "-q", 2)) {
rc = freq(addr, argv[i-1]);
if (rc)
break;
}
}
if (rc)
rc += 100;
die(rc);
}
2001-08-17 05:46:24 +00:00
2002-08-05 20:43:29 +00:00
Help();
2001-08-17 05:46:24 +00:00
#ifdef MEMWATCH
2002-08-05 20:43:29 +00:00
mwTerm();
2001-08-17 05:46:24 +00:00
#endif
2002-08-05 20:43:29 +00:00
return 0;
2001-08-17 05:46:24 +00:00
}