diff --git a/ChangeLog b/ChangeLog index 57ca9abd..bd16745c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,8 @@ v0.35.05 19-Oct-2002 general: This may become release 0.36.00 + There is now a mberrors.h file that defines all errorcodes + returned by all programs. diff --git a/lib/Makefile b/lib/Makefile index 4f95c2ec..d2249904 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -33,7 +33,7 @@ DIESEL_OBJS = diesel.o mbdiesel.o MEMWATCH_SRCS = memwatch.c MEMWATCH_OBJS = memwatch.o MEMWATCH_HDRS = memwatch.h -OTHER_HDRS = ansi.h bluewave.h libs.h mbse.h records.h structs.h users.h +OTHER_HDRS = ansi.h bluewave.h libs.h mbse.h records.h structs.h users.h mberrors.h SRCS = ${CLCOMM_SRCS} ${COMMON_SRCS} ${DBASE_SRCS} ${MSGBASE_SRCS} ${MBINET_SRCS} \ ${DIESEL_SRCS} ${MEMWATCH_SRCS} OBJS = ${CLCOMM_OBJS} ${COMMON_OBJS} ${DBASE_OBJS} ${MSGBASE_OBJS} ${MBINET_OBJS} \ @@ -115,7 +115,7 @@ depend: ftscprod.c # DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT # Dependencies generated by make depend -clcomm.o: ../config.h libs.h memwatch.h clcomm.h +clcomm.o: ../config.h libs.h memwatch.h mberrors.h clcomm.h client.o: ../config.h libs.h memwatch.h clcomm.h crc.o: ../config.h libs.h memwatch.h clcomm.h semafore.o: ../config.h libs.h memwatch.h structs.h clcomm.h common.h @@ -139,11 +139,11 @@ dostran.o: ../config.h libs.h memwatch.h structs.h users.h records.h common.h ftnmsg.o: ../config.h libs.h memwatch.h structs.h common.h clcomm.h mbfile.o: ../config.h libs.h memwatch.h structs.h clcomm.h common.h nodelock.o: ../config.h libs.h memwatch.h structs.h clcomm.h common.h -rawio.o: ../config.h libs.h memwatch.h structs.h common.h +rawio.o: ../config.h libs.h memwatch.h structs.h common.h mberrors.h strcasestr.o: ../config.h libs.h memwatch.h charconv_hz.o: ../config.h libs.h memwatch.h structs.h common.h clcomm.h -execute.o: ../config.h libs.h memwatch.h structs.h clcomm.h common.h -expipe.o: ../config.h libs.h memwatch.h structs.h clcomm.h common.h +execute.o: ../config.h libs.h memwatch.h structs.h clcomm.h mberrors.h common.h +expipe.o: ../config.h libs.h memwatch.h structs.h clcomm.h mberrors.h common.h getheader.o: ../config.h libs.h memwatch.h structs.h users.h records.h clcomm.h common.h mime.o: ../config.h libs.h memwatch.h structs.h clcomm.h common.h noderecord.o: ../config.h libs.h memwatch.h structs.h common.h users.h records.h dbnode.h common.h @@ -155,8 +155,8 @@ gmtoffset.o: ../config.h libs.h memwatch.h structs.h common.h packet.o: ../config.h libs.h memwatch.h structs.h users.h records.h clcomm.h common.h dbnode.h rfcdate.o: ../config.h libs.h memwatch.h structs.h common.h clcomm.h term.o: ../config.h libs.h memwatch.h structs.h users.h ansi.h records.h common.h -dbcfg.o: ../config.h libs.h memwatch.h mbse.h structs.h users.h records.h dbcfg.h -dbdupe.o: ../config.h libs.h memwatch.h structs.h clcomm.h dbdupe.h +dbcfg.o: ../config.h libs.h memwatch.h mbse.h structs.h users.h records.h mberrors.h dbcfg.h +dbdupe.o: ../config.h libs.h memwatch.h structs.h clcomm.h mberrors.h dbdupe.h dbftn.o: ../config.h libs.h memwatch.h structs.h users.h records.h dbcfg.h dbftn.h dbmsgs.o: ../config.h libs.h memwatch.h structs.h users.h records.h clcomm.h dbcfg.h dbmsgs.h dbnode.o: ../config.h libs.h memwatch.h structs.h common.h users.h records.h clcomm.h dbcfg.h dbnode.h diff --git a/lib/clcomm.c b/lib/clcomm.c index 9b901471..0a11d39c 100644 --- a/lib/clcomm.c +++ b/lib/clcomm.c @@ -31,6 +31,7 @@ #include "../config.h" #include "libs.h" #include "memwatch.h" +#include "mberrors.h" #include "clcomm.h" @@ -106,7 +107,7 @@ void InitClient(char *user, char *myname, char *where, char *log, long loggr, ch printf("Could not get the MBSE_ROOT environment variable\n"); printf("Please set the environment variable ie:\n"); printf("\"MBSE_ROOT=/opt/mbse; export MBSE_ROOT\"\n\n"); - exit(1); + exit(MBERR_INIT_ERROR); } sprintf(progname, "%s", myname); @@ -125,7 +126,7 @@ void InitClient(char *user, char *myname, char *where, char *log, long loggr, ch mypid = getpid(); if (socket_connect(user, myname, where) == -1) { printf("PANIC: cannot access socket\n"); - exit(1); + exit(MBERR_INIT_ERROR); } } diff --git a/lib/dbcfg.c b/lib/dbcfg.c index b857483b..00795822 100644 --- a/lib/dbcfg.c +++ b/lib/dbcfg.c @@ -35,6 +35,7 @@ #include "structs.h" #include "users.h" #include "records.h" +#include "mberrors.h" #include "dbcfg.h" @@ -46,7 +47,7 @@ void InitConfig(void) printf("Could not get MBSE_ROOT environment variable\n"); printf("Please set the environment variable ie:\n"); printf("\"MBSE_ROOT=/opt/mbse;export MBSE_ROOT\"\n\n"); - exit(1); + exit(MBERR_INIT_ERROR); } LoadConfig(); } @@ -69,7 +70,7 @@ void LoadConfig(void) #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_CONFIG_ERROR); } free(FileName); diff --git a/lib/dbdupe.c b/lib/dbdupe.c index 86b14b71..eac45ec3 100644 --- a/lib/dbdupe.c +++ b/lib/dbdupe.c @@ -33,9 +33,11 @@ #include "memwatch.h" #include "structs.h" #include "clcomm.h" +#include "mberrors.h" #include "dbdupe.h" + typedef struct _dupesrec { unsigned long *crcs; int loaded; @@ -85,7 +87,7 @@ int CheckDupe(unsigned long crc, int idx, int max) if ((fil = fopen(dfile, "w")) == NULL) { WriteError("$PANIC: dbdupe.c, can't create %s", dfile); free(dfile); - exit(1); + exit(MBERR_INIT_ERROR); } fclose(fil); fil = fopen(dfile, "r+"); diff --git a/lib/execute.c b/lib/execute.c index 5e4cc01f..3c6e2d46 100644 --- a/lib/execute.c +++ b/lib/execute.c @@ -1,11 +1,10 @@ /***************************************************************************** * - * File ..................: execute.c + * $Id$ * Purpose ...............: Execute subprogram - * Last modification date : 16-Feb-2001 * ***************************************************************************** - * Copyright (C) 1997-2001 + * Copyright (C) 1997-2002 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -34,6 +33,7 @@ #include "memwatch.h" #include "structs.h" #include "clcomm.h" +#include "mberrors.h" #include "common.h" @@ -43,91 +43,90 @@ int e_pid = 0; /* Execute child pid */ int execute(char *cmd, char *file, char *pkt, char *in, char *out, char *err) { - char buf[512]; - char *vector[16]; - int i; - int pid, status, rc; + char buf[512]; + char *vector[16]; + int i, pid, status, rc; - if (pkt == NULL) - sprintf(buf, "%s %s", cmd, file); - else - sprintf(buf, "%s %s %s", cmd, file, pkt); - Syslog('+', "Execute: %s",buf); + if (pkt == NULL) + sprintf(buf, "%s %s", cmd, file); + else + sprintf(buf, "%s %s %s", cmd, file, pkt); + Syslog('+', "Execute: %s",buf); - i = 0; - vector[i++] = strtok(buf," \t\n"); - while ((vector[i++] = strtok(NULL," \t\n")) && (i<16)); - vector[15] = NULL; - fflush(stdout); - fflush(stderr); + i = 0; + vector[i++] = strtok(buf," \t\n"); + while ((vector[i++] = strtok(NULL," \t\n")) && (i<16)); + vector[15] = NULL; + fflush(stdout); + fflush(stderr); - if ((pid = fork()) == 0) { - if (in) { - close(0); - if (open(in,O_RDONLY) != 0) { - WriteError("$Reopen of stdin to %s failed", MBSE_SS(in)); - exit(-1); - } - } - if (out) { - close(1); - if (open(out,O_WRONLY | O_APPEND | O_CREAT,0600) != 1) { - WriteError("$Reopen of stdout to %s failed", MBSE_SS(out)); - exit(-1); - } - } - if (err) { - close(2); - if (open(err,O_WRONLY | O_APPEND | O_CREAT,0600) != 2) { - WriteError("$Reopen of stderr to %s failed", MBSE_SS(err)); - exit(-1); - } - } - errno = 0; - rc = getpriority(PRIO_PROCESS, 0); - if (errno == 0) { - rc = setpriority(PRIO_PROCESS, 0, 15); - if (rc) - WriteError("$execv can't set priority to 15"); - } - rc = execv(vector[0],vector); - WriteError("$execv \"%s\" returned %d", MBSE_SS(vector[0]), rc); - setpriority(PRIO_PROCESS, 0, 0); - exit(-1); + if ((pid = fork()) == 0) { + if (in) { + close(0); + if (open(in,O_RDONLY) != 0) { + WriteError("$Reopen of stdin to %s failed", MBSE_SS(in)); + exit(MBERR_EXEC_FAILED); + } } - - e_pid = pid; - - do { - rc = wait(&status); - e_pid = 0; - } while (((rc > 0) && (rc != pid)) || ((rc == -1) && (errno == EINTR))); - + if (out) { + close(1); + if (open(out,O_WRONLY | O_APPEND | O_CREAT,0600) != 1) { + WriteError("$Reopen of stdout to %s failed", MBSE_SS(out)); + exit(MBERR_EXEC_FAILED); + } + } + if (err) { + close(2); + if (open(err,O_WRONLY | O_APPEND | O_CREAT,0600) != 2) { + WriteError("$Reopen of stderr to %s failed", MBSE_SS(err)); + exit(MBERR_EXEC_FAILED); + } + } + errno = 0; + rc = getpriority(PRIO_PROCESS, 0); + if (errno == 0) { + rc = setpriority(PRIO_PROCESS, 0, 15); + if (rc) + WriteError("$execv can't set priority to 15"); + } + rc = execv(vector[0],vector); + WriteError("$execv \"%s\" returned %d", MBSE_SS(vector[0]), rc); setpriority(PRIO_PROCESS, 0, 0); - switch (rc) { + exit(MBERR_EXEC_FAILED); + } + + e_pid = pid; + + do { + rc = wait(&status); + e_pid = 0; + } while (((rc > 0) && (rc != pid)) || ((rc == -1) && (errno == EINTR))); + + setpriority(PRIO_PROCESS, 0, 0); + switch (rc) { case -1: WriteError("$Wait returned %d, status %d,%d", rc,status>>8,status&0xff); - return -1; + return MBERR_EXEC_FAILED; case 0: return 0; default: if (WIFEXITED(status)) { - rc = WEXITSTATUS(status); - if (rc) { - WriteError("Execute: returned error %d", rc); - return rc; - } + rc = WEXITSTATUS(status); + if (rc) { + WriteError("Execute: returned error %d", rc); + return (rc + MBERR_EXTERNAL); + } } if (WIFSIGNALED(status)) { - rc = WTERMSIG(status); - WriteError("Wait stopped on signal %d", rc); - return rc; + rc = WTERMSIG(status); + WriteError("Wait stopped on signal %d", rc); + return rc; } if (rc) - WriteError("Wait stopped unknown, rc=%d", rc); + WriteError("Wait stopped unknown, rc=%d", rc); return rc; - } - return 0; + } + return 0; } @@ -136,57 +135,57 @@ int execute(char *cmd, char *file, char *pkt, char *in, char *out, char *err) int execsh(char *cmd, char *in, char *out, char *err) { - int pid, status, rc, sverr; + int pid, status, rc, sverr; - Syslog('+', "Execute shell: %s", MBSE_SS(cmd)); - fflush(stdout); - fflush(stderr); + Syslog('+', "Execute shell: %s", MBSE_SS(cmd)); + fflush(stdout); + fflush(stderr); - if ((pid = fork()) == 0) { - if (in) { - close(0); - if (open(in, O_RDONLY) != 0) { - WriteError("$Reopen of stdin to %s failed",MBSE_SS(in)); - exit(-1); - } - } - if (out) { - close(1); - if (open(out, O_WRONLY | O_APPEND | O_CREAT,0600) != 1) { - WriteError("$Reopen of stdout to %s failed",MBSE_SS(out)); - exit(-1); - } - } - if (err) { - close(2); - if (open(err, O_WRONLY | O_APPEND | O_CREAT,0600) != 2) { - WriteError("$Reopen of stderr to %s failed",MBSE_SS(err)); - exit(-1); - } - } - - rc = execl(SHELL, "sh", "-c", cmd, NULL); - WriteError("$execl \"%s\" returned %d", MBSE_SS(cmd), rc); - exit(-1); + if ((pid = fork()) == 0) { + if (in) { + close(0); + if (open(in, O_RDONLY) != 0) { + WriteError("$Reopen of stdin to %s failed",MBSE_SS(in)); + exit(MBERR_EXEC_FAILED); + } + } + if (out) { + close(1); + if (open(out, O_WRONLY | O_APPEND | O_CREAT,0600) != 1) { + WriteError("$Reopen of stdout to %s failed",MBSE_SS(out)); + exit(MBERR_EXEC_FAILED); + } + } + if (err) { + close(2); + if (open(err, O_WRONLY | O_APPEND | O_CREAT,0600) != 2) { + WriteError("$Reopen of stderr to %s failed",MBSE_SS(err)); + exit(MBERR_EXEC_FAILED); + } } - e_pid = pid; + rc = execl(SHELL, "sh", "-c", cmd, NULL); + WriteError("$execl \"%s\" returned %d", MBSE_SS(cmd), rc); + exit(MBERR_EXEC_FAILED); + } - do { - rc = wait(&status); - e_pid = 0; - sverr = errno; - if (status) - WriteError("$Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff); - } + e_pid = pid; - while (((rc > 0) && (rc != pid)) || ((rc == -1) && (sverr == EINTR))); - if (rc == -1) { - WriteError("$Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff); - return -1; - } + do { + rc = wait(&status); + e_pid = 0; + sverr = errno; + if (status) + WriteError("$Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff); + } - return status; + while (((rc > 0) && (rc != pid)) || ((rc == -1) && (sverr == EINTR))); + if (rc == -1) { + WriteError("$Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff); + return MBERR_EXEC_FAILED; + } + + return status; } diff --git a/lib/expipe.c b/lib/expipe.c index 2dabd15f..4c617d6d 100644 --- a/lib/expipe.c +++ b/lib/expipe.c @@ -33,15 +33,16 @@ #include "memwatch.h" #include "structs.h" #include "clcomm.h" +#include "mberrors.h" #include "common.h" static struct _fppid { - FILE *fp; - int pid; + FILE *fp; + int pid; } fppid[] = { - {NULL, 0}, {NULL, 0}, {NULL, 0} + {NULL, 0}, {NULL, 0}, {NULL, 0} }; #define maxfppid 2 @@ -50,147 +51,142 @@ static struct _fppid { FILE *expipe(char *cmd, char *from, char *to) { - char buf[256], *buflimit; - char *vector[16]; - int i, rc; - char *p, *q, *f=from, *t=to; - int pipedes[2]; - FILE *fp; - int pid, slot; + char buf[256], *buflimit, *vector[16], *p, *q, *f=from, *t=to; + FILE *fp; + int i, rc, pid, slot, pipedes[2]; - buflimit = buf + sizeof(buf) -1 - (f&&t&&(strlen(f)>strlen(t))?strlen(f):t?strlen(t):0); + buflimit = buf + sizeof(buf) -1 - (f&&t&&(strlen(f)>strlen(t))?strlen(f):t?strlen(t):0); - for (slot = 0; slot <= maxfppid; slot++) { - if (fppid[slot].fp == NULL) + for (slot = 0; slot <= maxfppid; slot++) { + if (fppid[slot].fp == NULL) + break; + } + if (slot > maxfppid) { + WriteError("Attempt to pipe more than %d processes", maxfppid + 1); + return NULL; + } + + for (p = cmd, q = buf; (*p); p++) { + if (q > buflimit) { + WriteError("Attempt to pipe too long command"); + return NULL; + } + switch (*p) { + case '$': switch (*(++p)) { + case 'f': + case 'F': if ((f)) + while (*f) + *(q++) = *(f++); + f=from; + break; + case 't': + case 'T': if ((t)) + while (*t) + *(q++) = *(t++); + t=to; + break; + default: *(q++)='$'; + *(q++)=*p; + break; + } + break; + case '\\': *(q++) = *(++p); + break; + default: *(q++) = *p; break; } - if (slot > maxfppid) { - WriteError("Attempt to pipe more than %d processes", maxfppid + 1); - return NULL; + } + + *q = '\0'; + Syslog('+', "Expipe: %s",buf); + i = 0; + vector[i++] = strtok(buf," \t\n"); + while ((vector[i++] = strtok(NULL," \t\n")) && (i<16)); + vector[15] = NULL; + fflush(stdout); + fflush(stderr); + if (pipe(pipedes) != 0) { + WriteError("$Pipe failed for command \"%s\"", MBSE_SS(vector[0])); + return NULL; + } + + Syslog('e', "pipe() returned read=%d, write=%d", pipedes[0], pipedes[1]); + if ((pid = fork()) == 0) { + close(pipedes[1]); + close(0); + if (dup(pipedes[0]) != 0) { + WriteError("$Reopen of stdin for command %s failed", MBSE_SS(vector[0])); + exit(MBERR_EXEC_FAILED); } + rc = execv(vector[0],vector); + WriteError("$Exec \"%s\" returned %d", MBSE_SS(vector[0]), rc); + exit(MBERR_EXEC_FAILED); + } - for (p = cmd, q = buf; (*p); p++) { - if (q > buflimit) { - WriteError("Attempt to pipe too long command"); - return NULL; - } - switch (*p) { - case '$': switch (*(++p)) { - case 'f': - case 'F': if ((f)) - while (*f) - *(q++) = *(f++); - f=from; - break; - case 't': - case 'T': if ((t)) - while (*t) - *(q++) = *(t++); - t=to; - break; - default: *(q++)='$'; - *(q++)=*p; - break; - } - break; - case '\\': *(q++) = *(++p); - break; - default: *(q++) = *p; - break; - } - } + close(pipedes[0]); - *q = '\0'; - Syslog('+', "Expipe: %s",buf); - i = 0; - vector[i++] = strtok(buf," \t\n"); - while ((vector[i++] = strtok(NULL," \t\n")) && (i<16)); - vector[15] = NULL; - fflush(stdout); - fflush(stderr); - if (pipe(pipedes) != 0) { - WriteError("$Pipe failed for command \"%s\"", MBSE_SS(vector[0])); - return NULL; - } + if ((fp = fdopen(pipedes[1],"w")) == NULL) { + WriteError("$fdopen failed for pipe to command \"%s\"", MBSE_SS(vector[0])); + } - Syslog('e', "pipe() returned read=%d, write=%d", pipedes[0], pipedes[1]); - if ((pid = fork()) == 0) { - close(pipedes[1]); - close(0); - if (dup(pipedes[0]) != 0) { - WriteError("$Reopen of stdin for command %s failed", MBSE_SS(vector[0])); - exit(-1); - } - rc = execv(vector[0],vector); - WriteError("$Exec \"%s\" returned %d", MBSE_SS(vector[0]), rc); - exit(-1); - } - - close(pipedes[0]); - - if ((fp = fdopen(pipedes[1],"w")) == NULL) { - WriteError("$fdopen failed for pipe to command \"%s\"", MBSE_SS(vector[0])); - } - - fppid[slot].fp = fp; - fppid[slot].pid = pid; - return fp; + fppid[slot].fp = fp; + fppid[slot].pid = pid; + return fp; } int exclose(FILE *fp) { - int status, rc; - int pid, slot, sverr; + int status, rc, pid, slot, sverr; - for (slot = 0; slot <= maxfppid; slot++) { - if (fppid[slot].fp == fp) - break; - } - if (slot > maxfppid) { - WriteError("Attempt to close unopened pipe"); - return -1; - } - pid = fppid[slot].pid; - fppid[slot].fp = NULL; - fppid[slot].pid = 0; + for (slot = 0; slot <= maxfppid; slot++) { + if (fppid[slot].fp == fp) + break; + } + if (slot > maxfppid) { + WriteError("Attempt to close unopened pipe"); + return -1; + } + pid = fppid[slot].pid; + fppid[slot].fp = NULL; + fppid[slot].pid = 0; - Syslog('e', "Closing pipe to the child process %d",pid); - if ((rc = fclose(fp)) != 0) { - WriteError("$Error closing pipe to transport (rc=%d)", rc); - if ((rc = kill(pid,SIGKILL)) != 0) - WriteError("$kill for pid %d returned %d",pid,rc); - } - Syslog('e', "Waiting for process %d to finish",pid); - do { - rc = wait(&status); - sverr = errno; - if (status) - Syslog('e', "$Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff); - } while (((rc > 0) && (rc != pid)) || ((rc == -1) && (sverr == EINTR))); + Syslog('e', "Closing pipe to the child process %d",pid); + if ((rc = fclose(fp)) != 0) { + WriteError("$Error closing pipe to transport (rc=%d)", rc); + if ((rc = kill(pid,SIGKILL)) != 0) + WriteError("$kill for pid %d returned %d",pid,rc); + } + Syslog('e', "Waiting for process %d to finish",pid); + do { + rc = wait(&status); + sverr = errno; + if (status) + Syslog('e', "$Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff); + } while (((rc > 0) && (rc != pid)) || ((rc == -1) && (sverr == EINTR))); - switch (rc) { + switch (rc) { case -1:WriteError("$Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff); - return -1; + return MBERR_EXEC_FAILED; case 0: return 0; default: if (WIFEXITED(status)) { - rc = WEXITSTATUS(status); - if (rc) { - WriteError("Expipe: returned error %d", rc); - return rc; - } + rc = WEXITSTATUS(status); + if (rc) { + WriteError("Expipe: returned error %d", rc); + return (rc + MBERR_EXTERNAL); + } } if (WIFSIGNALED(status)) { - rc = WTERMSIG(status); - WriteError("Wait stopped on signal %d", rc); - return rc; + rc = WTERMSIG(status); + WriteError("Wait stopped on signal %d", rc); + return rc; } if (rc) - WriteError("Wait stopped unknown, rc=%d", rc); + WriteError("Wait stopped unknown, rc=%d", rc); return rc; - } - return 0; + } + return 0; } diff --git a/lib/mberrors.h b/lib/mberrors.h new file mode 100644 index 00000000..e41fd47e --- /dev/null +++ b/lib/mberrors.h @@ -0,0 +1,47 @@ +#ifndef _MBERRORS_H +#define _MBERRORS_H + +/* $Id$ */ + +/* + * Exit status values + */ +#define MBERR_OK 0 /* No errors */ +#define MBERR_COMMANDLINE 100 /* Commandline error */ +#define MBERR_CONFIG_ERROR 101 /* Configuration error */ +#define MBERR_INIT_ERROR 102 /* Initialisation error */ +#define MBERR_DISK_FULL 103 /* Some disk partition full */ +#define MBERR_UPS_ALARM 104 /* UPS alarm detected */ +#define MBERR_NO_RECIPIENTS 105 /* No valid recipients */ +#define MBERR_EXEC_FAILED 106 /* Execute external prog failed */ +#define MBERR_TTYIO_ERROR 107 /* Set tty failed */ +#define MBERR_FTRANSFER 108 /* File transfer error */ +#define MBERR_ATTACH_FAILED 109 /* File attach failed */ +#define MBERR_NO_PROGLOCK 110 /* Cannot lock program, retry later */ +#define MBERR_NODE_NOT_IN_LIST 111 /* Node not in nodelist */ +#define MBERR_NODE_MAY_NOT_CALL 112 /* Node may not be called */ +#define MBERR_NO_CONNECTION 113 /* Cannot make connection */ +#define MBERR_PORTERROR 114 /* Cannot open tty port */ +#define MBERR_NODE_LOCKED 115 /* Node is locked */ +#define MBERR_NO_IP_ADDRESS 116 /* Node IP address not found */ +#define MBERR_UNKNOWN_SESSION 117 /* Unknown session */ +#define MBERR_NOT_ZMH 118 /* Not Zone Mail Hour */ +#define MBERR_MODEM_ERROR 119 /* Modem error */ +#define MBERR_NO_PORT_AVAILABLE 120 /* No modemport available */ +#define MBERR_SESSION_ERROR 121 /* Session error (password) */ +#define MBERR_EMSI 122 /* EMSI session error */ +#define MBERR_FTSC 123 /* FTSC session error */ +#define MBERR_WAZOO 124 /* WAZOO session error */ +#define MBERR_YOOHOO 125 /* YOOHOO session error */ +#define MBERR_OUTBOUND_SCAN 126 /* Outbound scan error */ +#define MBERR_CANNOT_MAKE_POLL 127 /* Cannot make poll */ +#define MBERR_REQUEST 128 /* File request error */ +#define MBERR_DIFF_ERROR 129 /* Error processing nodediff */ +#define MBERR_VIRUS_FOUND 130 /* Virus found */ +#define MBERR_GENERAL 131 /* General error */ +#define MBERR_TIMEOUT 132 /* Timeout error */ +#define MBERR_TTYIO 200 /* Base for ttyio errors */ +#define MBERR_MEMWATCH 255 /* Memwatch error */ +#define MBERR_EXTERNAL 256 /* Status external prog + 256 */ + +#endif diff --git a/lib/rawio.c b/lib/rawio.c index 46981eb3..24322b1d 100644 --- a/lib/rawio.c +++ b/lib/rawio.c @@ -33,6 +33,7 @@ #include "memwatch.h" #include "structs.h" #include "common.h" +#include "mberrors.h" int rawset = FALSE; @@ -43,31 +44,31 @@ int rawset = FALSE; */ void Setraw() { - int rc; + int rc; - if ((rc = tcgetattr(ttyfd, &tbufs))) { - perror(""); - printf("$tcgetattr(0, save) return %d\n", rc); - exit(1); - } + if ((rc = tcgetattr(ttyfd, &tbufs))) { + perror(""); + printf("$tcgetattr(0, save) return %d\n", rc); + exit(MBERR_TTYIO_ERROR); + } - tbufsavs = tbufs; - tbufs.c_iflag &= ~(INLCR | ICRNL | ISTRIP | IXON ); /* IUCLC removed for FreeBSD */ - /* - * Map CRNL modes strip control characters and flow control - */ - tbufs.c_oflag &= ~OPOST; /* Don't do ouput character translation */ - tbufs.c_lflag &= ~(ICANON | ECHO); /* No canonical input and no echo */ - tbufs.c_cc[VMIN] = 1; /* Receive 1 character at a time */ - tbufs.c_cc[VTIME] = 0; /* No time limit per character */ + tbufsavs = tbufs; + tbufs.c_iflag &= ~(INLCR | ICRNL | ISTRIP | IXON ); /* IUCLC removed for FreeBSD */ + /* + * Map CRNL modes strip control characters and flow control + */ + tbufs.c_oflag &= ~OPOST; /* Don't do ouput character translation */ + tbufs.c_lflag &= ~(ICANON | ECHO); /* No canonical input and no echo */ + tbufs.c_cc[VMIN] = 1; /* Receive 1 character at a time */ + tbufs.c_cc[VTIME] = 0; /* No time limit per character */ - if ((rc = tcsetattr(ttyfd, TCSADRAIN, &tbufs))) { - perror(""); - printf("$tcsetattr(%d, TCSADRAIN, raw) return %d\n", ttyfd, rc); - exit(1); - } + if ((rc = tcsetattr(ttyfd, TCSADRAIN, &tbufs))) { + perror(""); + printf("$tcsetattr(%d, TCSADRAIN, raw) return %d\n", ttyfd, rc); + exit(MBERR_TTYIO_ERROR); + } - rawset = TRUE; + rawset = TRUE; } @@ -77,19 +78,19 @@ void Setraw() */ void Unsetraw() { - int rc; + int rc; - /* - * Only unset the mode if it is set to raw mode - */ - if (rawset == TRUE) { - if ((rc = tcsetattr(ttyfd, TCSAFLUSH, &tbufsavs))) { - perror(""); - printf("$tcsetattr(%d, TCSAFLUSH, save) return %d\n", ttyfd, rc); - exit(1); - } + /* + * Only unset the mode if it is set to raw mode + */ + if (rawset == TRUE) { + if ((rc = tcsetattr(ttyfd, TCSAFLUSH, &tbufsavs))) { + perror(""); + printf("$tcsetattr(%d, TCSAFLUSH, save) return %d\n", ttyfd, rc); + exit(MBERR_TTYIO_ERROR); } - rawset = FALSE; + } + rawset = FALSE; } @@ -104,7 +105,7 @@ unsigned char Getone() if ((ttyfd = open ("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { perror("open 8"); - exit(1); + exit(MBERR_TTYIO_ERROR); } Setraw(); diff --git a/mbcico/Makefile b/mbcico/Makefile index 4ff06775..3f2683a8 100644 --- a/mbcico/Makefile +++ b/mbcico/Makefile @@ -90,15 +90,15 @@ zmmisc.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/co zmrle.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/clcomm.h ../lib/common.h ttyio.h session.h zmodem.h zmrecv.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/clcomm.h ../lib/common.h lutil.h ttyio.h session.h zmodem.h config.h emsi.h openfile.h filelist.h openport.h zmsend.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h ttyio.h session.h zmodem.h lutil.h emsi.h filelist.h -binkp.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbnode.h ../lib/clcomm.h ttyio.h session.h statetbl.h config.h emsi.h openfile.h respfreq.h filelist.h opentcp.h rdoptions.h lutil.h binkp.h config.h +binkp.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbnode.h ../lib/clcomm.h ../lib/mberrors.h ttyio.h session.h statetbl.h config.h emsi.h openfile.h respfreq.h filelist.h opentcp.h rdoptions.h lutil.h binkp.h config.h xmsend.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h session.h ttyio.h statetbl.h xmsend.h m7send.h filelist.h filetime.h xmrecv.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h session.h ttyio.h statetbl.h config.h lutil.h openfile.h m7recv.h xmrecv.h filelist.h filetime.h m7recv.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h statetbl.h ttyio.h m7recv.h m7send.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h statetbl.h ttyio.h m7send.h -hydra.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h session.h filelist.h filetime.h ttyio.h statetbl.h config.h emsi.h openfile.h lutil.h respfreq.h mbcico.h hydra.h -answer.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h lutil.h session.h config.h answer.h openport.h portsel.h dial.h rdoptions.h mbcico.h +hydra.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h session.h filelist.h filetime.h ttyio.h statetbl.h config.h emsi.h openfile.h lutil.h respfreq.h mbcico.h hydra.h +answer.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/mberrors.h lutil.h session.h config.h answer.h openport.h portsel.h dial.h rdoptions.h mbcico.h chat.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h config.h chat.h ttyio.h -dial.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h config.h chat.h ttyio.h session.h dial.h +dial.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/mberrors.h config.h chat.h ttyio.h session.h dial.h dietifna.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h ttyio.h session.h emsi.h dietifna.h respfreq.h filelist.h xmrecv.h xmsend.h emsidat.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h emsi.h session.h lutil.h config.h emsidat.h filetime.h filelist.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h config.h session.h filelist.h @@ -106,27 +106,27 @@ openfile.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/ openport.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h ulock.h ttyio.h openport.h opentcp.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h session.h ttyio.h openport.h opentcp.h rdoptions.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h session.h config.h -yoohoo.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../lib/dbnode.h statetbl.h ttyio.h session.h config.h emsi.h hydra.h rdoptions.h wazoo.h dietifna.h yoohoo.h +yoohoo.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../lib/dbnode.h ../lib/mberrors.h statetbl.h ttyio.h session.h config.h emsi.h hydra.h rdoptions.h wazoo.h dietifna.h yoohoo.h recvbark.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h ttyio.h session.h statetbl.h recvbark.h respfreq.h filelist.h respfreq.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h session.h lutil.h config.h atoul.h respfreq.h filelist.h sendbark.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h ttyio.h session.h statetbl.h sendbark.h xmrecv.h tcp.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h ttyio.h session.h statetbl.h config.h emsi.h respfreq.h filelist.h tcpproto.h tcp.h -tcpproto.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h ttyio.h session.h config.h emsi.h lutil.h openfile.h filelist.h tcpproto.h -wazoo.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h ttyio.h session.h statetbl.h config.h emsi.h respfreq.h filelist.h wazoo.h zmodem.h +tcpproto.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h ttyio.h session.h config.h emsi.h lutil.h openfile.h filelist.h tcpproto.h +wazoo.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h ttyio.h session.h statetbl.h config.h emsi.h respfreq.h filelist.h wazoo.h zmodem.h filetime.o: ../config.h ../lib/libs.h ../lib/memwatch.h filetime.h -ftsc.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h session.h ttyio.h statetbl.h config.h ftsc.h rdoptions.h recvbark.h filelist.h sendbark.h respfreq.h xmrecv.h xmsend.h +ftsc.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h session.h ttyio.h statetbl.h config.h ftsc.h rdoptions.h recvbark.h filelist.h sendbark.h respfreq.h xmrecv.h xmsend.h atoul.o: ../config.h ../lib/libs.h ../lib/memwatch.h atoul.h portsel.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h portsel.h ttyio.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ttyio.h lutil.h lutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h lutil.h scanout.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbftn.h config.h scanout.h lutil.h -emsi.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbnode.h ../lib/clcomm.h ttyio.h session.h statetbl.h config.h emsi.h emsidat.h hydra.h rdoptions.h tcp.h wazoo.h +emsi.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbnode.h ../lib/clcomm.h ../lib/mberrors.h ttyio.h session.h statetbl.h config.h emsi.h emsidat.h hydra.h rdoptions.h tcp.h wazoo.h ulock.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/clcomm.h callstat.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h callstat.h -session.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ttyio.h statetbl.h emsi.h ftsc.h session.h yoohoo.h mbcico.h binkp.h callstat.h -call.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h session.h callstat.h call.h config.h dial.h lutil.h portsel.h openport.h opentcp.h rdoptions.h -mbcico.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbftn.h config.h answer.h call.h lutil.h mbcico.h session.h -outstat.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbftn.h scanout.h callstat.h outstat.h +session.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h ttyio.h statetbl.h emsi.h ftsc.h session.h yoohoo.h mbcico.h binkp.h callstat.h +call.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/mberrors.h session.h callstat.h call.h config.h dial.h lutil.h portsel.h openport.h opentcp.h rdoptions.h +mbcico.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbftn.h ../lib/mberrors.h config.h answer.h call.h lutil.h mbcico.h session.h +outstat.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbftn.h ../lib/mberrors.h scanout.h callstat.h outstat.h nlinfo.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h nlinfo.h -mbout.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbftn.h outstat.h nlinfo.h +mbout.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbftn.h ../lib/mberrors.h outstat.h nlinfo.h # End of generated dependencies diff --git a/mbcico/answer.c b/mbcico/answer.c index 66b14757..21043181 100644 --- a/mbcico/answer.c +++ b/mbcico/answer.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbnode.h" +#include "../lib/mberrors.h" #include "lutil.h" #include "session.h" #include "config.h" @@ -56,109 +57,110 @@ extern int Loaded; int answer(char *stype) { - int st, rc; - char *p, *q; - FILE *fp; + int st, rc; + char *p, *q; + FILE *fp; + /* + * mgetty set's the environment variable CONNECT and CALLER_ID, + * so if they are present, we might as well make log entries. + */ + if ((q = getenv("CONNECT")) != NULL) + Syslog('+', "CONNECT %s", q); + if ((q = getenv("CALLER_ID")) != NULL) + if (strncmp(q, "none", 4)) + Syslog('+', "CALLER %s", q); + + /* + * Incoming calls from modem/ISDN lines do have a tty. + * Network calls don't have a tty attached. + */ + carrier = TRUE; + p = ttyname(0); + if (p) { + q = strrchr(ttyname(0), '/'); + if (q) + p = q + 1; + strncpy(history.tty, p, 6); + if (load_port(p)) + Syslog('d', "Port %s, modem %s", ttyinfo.tty, modem.modem); + else + Syslog('d', "Port and modem not loaded!"); + } + + if ((nlent = getnlent(NULL)) == NULL) { + WriteError("could not get dummy nodelist entry"); + return MBERR_NODE_NOT_IN_LIST; + } + + c_start = time(NULL); + rdoptions(FALSE); + + if (inbound) + free(inbound); + inbound = xstrcpy(CFG.inbound); /* slave session is unsecure by default */ + + if (stype == NULL) { + st=SESSION_UNKNOWN; + } else if (strcmp(stype,"tsync") == 0) { + st=SESSION_FTSC; + IsDoing("Answer ftsc"); + } else if (strcmp(stype,"yoohoo") == 0) { + st=SESSION_YOOHOO; + IsDoing("Answer yoohoo"); + } else if (strncmp(stype,"**EMSI_",7) == 0) { + st=SESSION_EMSI; + IsDoing("Answer EMSI"); + } else if (strncmp(stype,"ibn",3) == 0) { + st=SESSION_BINKP; + IsDoing("Answer binkp"); + } else { + st=SESSION_UNKNOWN; + IsDoing("Answer unknown"); + } + + if ((rc = rawport()) != 0) + WriteError("Unable to set raw mode"); + else { + nolocalport(); + rc = session(NULL,NULL,SESSION_SLAVE,st,stype); + } + + cookedport(); + if (p) { /* - * mgetty set's the environment variable CONNECT and CALLER_ID, - * so if they are present, we might as well make log entries. + * Hangup will write the history record. */ - if ((q = getenv("CONNECT")) != NULL) - Syslog('+', "CONNECT %s", q); - if ((q = getenv("CALLER_ID")) != NULL) - if (strncmp(q, "none", 4)) - Syslog('+', "CALLER %s", q); - + hangup(); + } else { /* - * Incoming calls from modem/ISDN lines do have a tty. - * Network calls don't have a tty attached. + * Network call, write history record. */ - carrier = TRUE; - p = ttyname(0); - if (p) { - q = strrchr(ttyname(0), '/'); - if (q) - p = q + 1; - strncpy(history.tty, p, 6); - if (load_port(p)) - Syslog('d', "Port %s, modem %s", ttyinfo.tty, modem.modem); - else - Syslog('d', "Port and modem not loaded!"); - } + c_end = time(NULL); + online += (c_end - c_start); - if ((nlent = getnlent(NULL)) == NULL) { - WriteError("could not get dummy nodelist entry"); - return 1; - } + history.online = c_start; + history.offline = c_end; + history.sent_bytes = sentbytes; + history.rcvd_bytes = rcvdbytes; + history.inbound = TRUE; - c_start = time(NULL); - rdoptions(FALSE); - - if (inbound) - free(inbound); - inbound = xstrcpy(CFG.inbound); /* slave session is unsecure by default */ - - if (stype == NULL) { - st=SESSION_UNKNOWN; - } else if (strcmp(stype,"tsync") == 0) { - st=SESSION_FTSC; - IsDoing("Answer ftsc"); - } else if (strcmp(stype,"yoohoo") == 0) { - st=SESSION_YOOHOO; - IsDoing("Answer yoohoo"); - } else if (strncmp(stype,"**EMSI_",7) == 0) { - st=SESSION_EMSI; - IsDoing("Answer EMSI"); - } else if (strncmp(stype,"ibn",3) == 0) { - st=SESSION_BINKP; - IsDoing("Answer binkp"); - } else { - st=SESSION_UNKNOWN; - IsDoing("Answer unknown"); - } - - if ((rc = rawport()) != 0) - WriteError("Unable to set raw mode"); + p = calloc(PATH_MAX, sizeof(char)); + sprintf(p, "%s/var/mailer.hist", getenv("MBSE_ROOT")); + if ((fp = fopen(p, "a")) == NULL) + WriteError("$Can't open %s", p); else { - nolocalport(); - rc=session(NULL,NULL,SESSION_SLAVE,st,stype); + fwrite(&history, sizeof(history), 1, fp); + fclose(fp); } - - cookedport(); - if (p) { - /* - * Hangup will write the history record. - */ - hangup(); - } else { - /* - * Network call, write history record. - */ - c_end = time(NULL); - online += (c_end - c_start); - - history.online = c_start; - history.offline = c_end; - history.sent_bytes = sentbytes; - history.rcvd_bytes = rcvdbytes; - history.inbound = TRUE; - - p = calloc(PATH_MAX, sizeof(char)); - sprintf(p, "%s/var/mailer.hist", getenv("MBSE_ROOT")); - if ((fp = fopen(p, "a")) == NULL) - WriteError("$Can't open %s", p); - else { - fwrite(&history, sizeof(history), 1, fp); - fclose(fp); - } - free(p); - if (Loaded) { - nodes.LastDate = time(NULL); - UpdateNode(); - } + free(p); + + if (Loaded) { + nodes.LastDate = time(NULL); + UpdateNode(); } - return rc; + } + return rc; } diff --git a/mbcico/binkp.c b/mbcico/binkp.c index 86ec3723..a156fff4 100644 --- a/mbcico/binkp.c +++ b/mbcico/binkp.c @@ -38,6 +38,7 @@ #include "../lib/common.h" #include "../lib/dbnode.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "ttyio.h" #include "session.h" #include "statetbl.h" @@ -95,96 +96,96 @@ int batchnr = 0, crc_errors = 0; int binkp(int role) { - int rc = 0; - fa_list *eff_remote; - file_list *tosend = NULL, *request = NULL, *respond = NULL, *tmpfl; - char *nonhold_mail; + int rc = MBERR_OK; + fa_list *eff_remote; + file_list *tosend = NULL, *request = NULL, *respond = NULL, *tmpfl; + char *nonhold_mail; - if (role == 1) { - Syslog('+', "BINKP start outbound session"); - if (orgbinkp()) { - rc = 5; - } - } else { - Syslog('+', "BINKP start inbound session"); - if (ansbinkp()) { - rc = 5; - } + if (role == 1) { + Syslog('+', "BINKP start outbound session"); + if (orgbinkp()) { + rc = MBERR_FTRANSFER; } + } else { + Syslog('+', "BINKP start inbound session"); + if (ansbinkp()) { + rc = MBERR_FTRANSFER; + } + } - if (rc) { - Syslog('!', "BINKP session failed"); - return rc; - } - - nonhold_mail = (char *)ALL_MAIL; - eff_remote = remote; - /* - * If remote doesn't have the 8.3 flag set, allow long filenames. - */ - if (!nodes.FNC) - remote_flags &= ~SESSION_FNC; - - tosend = create_filelist(eff_remote, nonhold_mail, 0); - request = create_freqlist(remote); - - if (request != NULL) { - Syslog('b', "Inserting request list"); - tmpfl = tosend; - tosend = request; - for (; request->next; request = request->next); - request->next = tmpfl; - - request = NULL; - } - - rc = binkp_batch(tosend, role); - tidy_filelist(tosend, (rc == 0)); - tosend = NULL; - - if ((rc == 0) && transferred && MBflag) { - /* - * Running Multiple Batch, only if last batch actually - * did transfer some data. - */ - respond = respond_wazoo(); - /* - * Just create the tosend list again, there may be something - * ready again for this node. - */ - tosend = create_filelist(eff_remote, nonhold_mail, 0); - for (tmpfl = tosend; tmpfl->next; tmpfl = tmpfl->next); - tmpfl->next = respond; - rc = binkp_batch(tosend, role); - tmpfl->next = NULL; - } - - Syslog('+', "BINKP end transfer rc=%d", rc); - closetcp(); - - if (!MBflag) { - /* - * In singe batch mode we process filerequests after the batch. - * The results will be put on hold for the calling node. - */ - respond = respond_wazoo(); - for (tmpfl = respond; tmpfl; tmpfl = tmpfl->next) { - if (strncmp(tmpfl->local, "/tmp", 4)) { - attach(*remote->addr, tmpfl->local, LEAVE, 'h'); - Syslog('+', "Put on hold: %s", MBSE_SS(tmpfl->local)); - } else { - file_mv(tmpfl->local, pktname(remote->addr, 'h')); - Syslog('+', "New netmail: %s", pktname(remote->addr, 'h')); - } - } - } - - tidy_filelist(request, (rc == 0)); - tidy_filelist(tosend, (rc == 0)); - tidy_filelist(respond, 0); - - rc = abs(rc); + if (rc) { + Syslog('!', "BINKP session failed"); return rc; + } + + nonhold_mail = (char *)ALL_MAIL; + eff_remote = remote; + /* + * If remote doesn't have the 8.3 flag set, allow long filenames. + */ + if (!nodes.FNC) + remote_flags &= ~SESSION_FNC; + + tosend = create_filelist(eff_remote, nonhold_mail, 0); + request = create_freqlist(remote); + + if (request != NULL) { + Syslog('b', "Inserting request list"); + tmpfl = tosend; + tosend = request; + for (; request->next; request = request->next); + request->next = tmpfl; + + request = NULL; + } + + rc = binkp_batch(tosend, role); + tidy_filelist(tosend, (rc == 0)); + tosend = NULL; + + if ((rc == 0) && transferred && MBflag) { + /* + * Running Multiple Batch, only if last batch actually + * did transfer some data. + */ + respond = respond_wazoo(); + /* + * Just create the tosend list again, there may be something + * ready again for this node. + */ + tosend = create_filelist(eff_remote, nonhold_mail, 0); + for (tmpfl = tosend; tmpfl->next; tmpfl = tmpfl->next); + tmpfl->next = respond; + rc = binkp_batch(tosend, role); + tmpfl->next = NULL; + } + + Syslog('+', "BINKP end transfer rc=%d", rc); + closetcp(); + + if (!MBflag) { + /* + * In singe batch mode we process filerequests after the batch. + * The results will be put on hold for the calling node. + */ + respond = respond_wazoo(); + for (tmpfl = respond; tmpfl; tmpfl = tmpfl->next) { + if (strncmp(tmpfl->local, "/tmp", 4)) { + attach(*remote->addr, tmpfl->local, LEAVE, 'h'); + Syslog('+', "Put on hold: %s", MBSE_SS(tmpfl->local)); + } else { + file_mv(tmpfl->local, pktname(remote->addr, 'h')); + Syslog('+', "New netmail: %s", pktname(remote->addr, 'h')); + } + } + } + + tidy_filelist(request, (rc == 0)); + tidy_filelist(tosend, (rc == 0)); + tidy_filelist(respond, 0); + + rc = abs(rc); + return rc; } @@ -854,7 +855,7 @@ int binkp_batch(file_list *to_send, int role) RxState = RxDone; TxState = TxDone; binkp_send_control(MM_ERR, "Transfer timeout"); - rc = -2; + rc = MBERR_FTRANSFER; break; } @@ -876,7 +877,7 @@ int binkp_batch(file_list *to_send, int role) Syslog('?', "Binkp: receiver status %s", ttystat[c]); TxState = TxDone; RxState = RxDone; - rc = -c; + rc = (MBERR_TTYIO + (-c)); break; } else { switch (rxlen) { @@ -1056,13 +1057,13 @@ int binkp_batch(file_list *to_send, int role) case MM_ERR: Syslog('+', "Binkp: got ERR: %s", rxbuf+1); RxState = RxDone; TxState = TxDone; - rc = -10; + rc = MBERR_FTRANSFER; break; case MM_BSY: Syslog('+', "Binkp: got BSY: %s", rxbuf+1); RxState = RxDone; TxState = TxDone; - rc = -11; + rc = MBERR_FTRANSFER; break; case MM_SKIP: Syslog('+', "Binkp: got SKIP: %s", rxbuf+1); @@ -1151,7 +1152,7 @@ int binkp_batch(file_list *to_send, int role) WriteError("File CRC error nr %d, aborting session", crc_errors); binkp_send_control(MM_ERR, "Too much CRC errors, aborting session"); RxState = RxDone; - rc = -12; + rc = MBERR_FTRANSFER; } closefile(FALSE); } @@ -1205,7 +1206,7 @@ int binkp_batch(file_list *to_send, int role) binkp_send_control(MM_BSY, "Low diskspace, try again later"); RxState = RxDone; TxState = TxDone; - rc = -13; + rc = MBERR_FTRANSFER; break; } diff --git a/mbcico/call.c b/mbcico/call.c index d1e2645d..7442cece 100644 --- a/mbcico/call.c +++ b/mbcico/call.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbnode.h" +#include "../lib/mberrors.h" #include "session.h" #include "callstat.h" #include "call.h" @@ -68,10 +69,10 @@ int portopen(faddr *addr) if ((rc = opentcp(inetaddr))) { Syslog('+', "Cannot connect %s", inetaddr); nodeulock(addr); - putstatus(addr,1,ST_NOCONN); - return ST_NOCONN; + putstatus(addr,1,MBERR_NO_CONNECTION); + return MBERR_NO_CONNECTION; } - return 0; + return MBERR_OK; } if (forcedline) { @@ -83,19 +84,19 @@ int portopen(faddr *addr) if ((rc = openport(p, ttyinfo.portspeed))) { Syslog('+', "Cannot open port %s",p); nodeulock(addr); - putstatus(addr, 10, ST_PORTERR); - return ST_PORTERR; + putstatus(addr, 10, MBERR_PORTERROR); + return MBERR_PORTERROR; } - return ST_PORTOK; + return MBERR_OK; } else { nodeulock(addr); - putstatus(addr, 0, ST_PORTERR); - return ST_PORTERR; + putstatus(addr, 0, MBERR_PORTERROR); + return MBERR_PORTERROR; } } WriteError("No call method available, maybe missing parameters"); - return ST_PORTERR; + return MBERR_NO_CONNECTION; } @@ -116,15 +117,15 @@ int call(faddr *addr) */ if (nodelock(addr)) { Syslog('+', "System %s is locked", ascfnode(addr, 0x1f)); - putstatus(addr, 0, ST_LOCKED); - return ST_LOCKED; + putstatus(addr, 0, MBERR_NODE_LOCKED); + return MBERR_NODE_LOCKED; } if ((nlent = getnlent(addr)) == NULL) { WriteError("Cannot call %s: fatal in nodelist lookup", ascfnode(addr, 0x1f)); - putstatus(addr,0,ST_LOOKUP); + putstatus(addr,0,MBERR_NODE_NOT_IN_LIST); nodeulock(addr); - return ST_LOOKUP; + return MBERR_NODE_NOT_IN_LIST; } /* @@ -215,7 +216,7 @@ int call(faddr *addr) } } else { WriteError("No IP address, abort call"); - rc = ST_NOCALL8; + rc = MBERR_NO_IP_ADDRESS; putstatus(addr, 10, rc); nodeulock(addr); return rc; @@ -244,15 +245,14 @@ int call(faddr *addr) IsDoing("Call %s", ascfnode(addr, 0x0f)); rc = portopen(addr); - if ((rc == 0) && (!inetaddr)) { + if ((rc == MBERR_OK) && (!inetaddr)) { if ((rc = dialphone(forcedphone?forcedphone:nlent->phone))) { Syslog('+', "Dial failed"); nodeulock(addr); - rc+=1; /* rc=2 - dial fail, rc=3 - could not reset */ } } - if (rc == 0) { + if (rc == MBERR_OK) { if (!inetaddr) nolocalport(); @@ -260,9 +260,6 @@ int call(faddr *addr) rc = session(addr,nlent,SESSION_MASTER,SESSION_BINKP,NULL); else rc = session(addr,nlent,SESSION_MASTER,SESSION_UNKNOWN,NULL); - - if (rc) - rc=abs(rc)+10; } IsDoing("Disconnect"); @@ -285,18 +282,15 @@ int call(faddr *addr) } else { IsDoing("NoCall"); Syslog('+', "Cannot call %s (%s, phone %s)", ascfnode(addr,0x1f),MBSE_SS(nlent->name), MBSE_SS(nlent->phone)); - if ((nlent->phone || forcedphone || inetaddr )) - rc=ST_NOCALL8; - else - rc=ST_NOCALL7; + rc = MBERR_NO_CONNECTION; putstatus(addr, 10, rc); nodeulock(addr); return rc; } - if ((rc > 10) && (rc < 20)) /* Session error */ + if ((rc == MBERR_NOT_ZMH) || (rc == MBERR_UNKNOWN_SESSION)) /* Session error */ putstatus(addr, 5, rc); - else if ((rc == 2) || (rc == 30)) + else if ((rc == MBERR_NO_CONNECTION) || (rc == MBERR_SESSION_ERROR)) putstatus(addr,1,rc); else putstatus(addr,0,rc); diff --git a/mbcico/callstat.c b/mbcico/callstat.c index 2888093c..1b59ea65 100644 --- a/mbcico/callstat.c +++ b/mbcico/callstat.c @@ -72,6 +72,7 @@ void putstatus(faddr *addr, int incr, int sts) } else { cst->tryno += incr; srand(getpid()); + Syslog('d', "putstatus %s, incr=%d, tryno=%d, status=%d", ascfnode(addr, 0xf), incr, cst->tryno, sts); while (TRUE) { j = 1+(int) (1.0 * CFG.dialdelay * rand() / (RAND_MAX + 1.0)); if ((j > (CFG.dialdelay / 10)) && (j > 9)) diff --git a/mbcico/dial.c b/mbcico/dial.c index 1df49914..694b4320 100644 --- a/mbcico/dial.c +++ b/mbcico/dial.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbnode.h" +#include "../lib/mberrors.h" #include "config.h" #include "chat.h" #include "ttyio.h" @@ -62,9 +63,9 @@ int initmodem(void) if (strlen(modem.init[i])) if (chat(modem.init[i], CFG.timeoutreset, FALSE, NULL)) { WriteError("dial: could not reset the modem"); - return 1; + return MBERR_MODEM_ERROR; } - return 0; + return MBERR_OK; } @@ -77,7 +78,7 @@ int dialphone(char *Phone) carrier = FALSE; if (initmodem()) - return 2; + return MBERR_MODEM_ERROR; rc = 0; if (strlen(nodes.phone[0])) { @@ -100,11 +101,11 @@ int dialphone(char *Phone) if (rc) { Syslog('+', "Could not connect to the remote"); - return 1; + return MBERR_NO_CONNECTION; } else { c_start = time(NULL); carrier = TRUE; - return 0; + return MBERR_OK; } } @@ -147,7 +148,7 @@ int hangup() } FLUSHIN(); FLUSHOUT(); - return 0; + return MBERR_OK; } diff --git a/mbcico/emsi.c b/mbcico/emsi.c index 09ed5dd1..bac7c680 100644 --- a/mbcico/emsi.c +++ b/mbcico/emsi.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/dbnode.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "ttyio.h" #include "session.h" #include "statetbl.h" @@ -105,7 +106,7 @@ int rx_emsi(char *data) caller=0; if ((rc=rxemsi())) - return rc; + return MBERR_EMSI; Syslog('i', "local lcodes 0x%04x, protos 0x%04x, opts 0x%04x", emsi_local_lcodes,emsi_local_protos,emsi_local_opts); Syslog('i', "remote lcodes 0x%04x, protos 0x%04x, opts 0x%04x", emsi_remote_lcodes,emsi_remote_protos,emsi_remote_opts); @@ -179,7 +180,7 @@ int rx_emsi(char *data) Syslog('i', "local lcodes 0x%04x, protos 0x%04x, opts 0x%04x", emsi_local_lcodes,emsi_local_protos,emsi_local_opts); if ((rc=txemsi())) - return rc; + return MBERR_EMSI; if (denypw || (emsi_local_protos == 0)) { Syslog('+', "Refusing remote: %s", emsi_local_protos?"bad password presented": "no common protocols"); @@ -243,10 +244,10 @@ int tx_emsi(char *data) Syslog('i', "local lcodes 0x%04x, protos 0x%04x, opts 0x%04x", emsi_local_lcodes,emsi_local_protos,emsi_local_opts); if ((rc=txemsi())) - return rc; + return MBERR_EMSI; else { if ((rc=rxemsi())) - return rc; + return MBERR_EMSI; } if ((emsi_remote_opts & OPT_EII) == 0) { diff --git a/mbcico/ftsc.c b/mbcico/ftsc.c index e98d4b76..2462c80f 100644 --- a/mbcico/ftsc.c +++ b/mbcico/ftsc.c @@ -36,6 +36,7 @@ #include "../lib/records.h" #include "../lib/common.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "session.h" #include "ttyio.h" #include "statetbl.h" @@ -62,23 +63,26 @@ extern int Loaded; int rx_ftsc(void) { - int rc; + int rc; - Syslog('+', "Start inbound FTS-0001 session"); - IsDoing("FTS-0001 inbound"); + Syslog('+', "Start inbound FTS-0001 session"); + IsDoing("FTS-0001 inbound"); - session_flags |= SESSION_BARK; - if ((rc = rxftsc())) { - WriteError("Session failed: rc=%d",rc); - PUTCHAR(CAN); - PUTCHAR(CAN); - PUTCHAR(CAN); - } else - Syslog('+', "FTS-0001 session completed"); + session_flags |= SESSION_BARK; + if ((rc = rxftsc())) { + WriteError("Session failed: rc=%d",rc); + PUTCHAR(CAN); + PUTCHAR(CAN); + PUTCHAR(CAN); + } else + Syslog('+', "FTS-0001 session completed"); - tidy_filelist(tosend, (rc == 0)); - tosend = NULL; - return rc; + tidy_filelist(tosend, (rc == 0)); + tosend = NULL; + if (rc) + return MBERR_FTSC; + else + return 0; } @@ -86,22 +90,25 @@ int rx_ftsc(void) int tx_ftsc(void) { - int rc; + int rc; - Syslog('+', "Start outbound FTS-0001 session with %s", ascfnode(remote->addr,0x1f)); - IsDoing("FTS-0001 to %s", ascfnode(remote->addr, 0x0f)); + Syslog('+', "Start outbound FTS-0001 session with %s", ascfnode(remote->addr,0x1f)); + IsDoing("FTS-0001 to %s", ascfnode(remote->addr, 0x0f)); - if ((rc = txftsc())) { - WriteError("Session failed: rc=%d",rc); - PUTCHAR(CAN); - PUTCHAR(CAN); - PUTCHAR(CAN); - } else - Syslog('+', "FTS-0001 session completed"); + if ((rc = txftsc())) { + WriteError("Session failed: rc=%d",rc); + PUTCHAR(CAN); + PUTCHAR(CAN); + PUTCHAR(CAN); + } else + Syslog('+', "FTS-0001 session completed"); - tidy_filelist(tosend, (rc == 0)); - tosend = NULL; - return rc; + tidy_filelist(tosend, (rc == 0)); + tosend = NULL; + if (rc) + return MBERR_FTSC; + else + return 0; } diff --git a/mbcico/hydra.c b/mbcico/hydra.c index 45350f87..4c89a975 100644 --- a/mbcico/hydra.c +++ b/mbcico/hydra.c @@ -47,6 +47,7 @@ #include "../lib/structs.h" #include "../lib/common.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "session.h" #include "filelist.h" #include "filetime.h" @@ -278,7 +279,7 @@ enum HyPktTypes hyrxpkt(char *rxbuf, int *rxlen, int tot) if ((i & ~0x0f) || (n & ~ 0x0f)) { Syslog('+', "Hydra: RXPKT assert"); - die(1); + die(MBERR_FTRANSFER); break; } @@ -295,7 +296,7 @@ enum HyPktTypes hyrxpkt(char *rxbuf, int *rxlen, int tot) case HCHR_UUEPKT: default: Syslog('+', "Hydra: RXPKT assert"); - die(1); + die(MBERR_FTRANSFER); } if ((format != HCHR_HEXPKT) && (rxoptions & HOPT_CRC32)) { @@ -449,7 +450,7 @@ void hytxpkt(enum HyPktTypes pkttype, char *txbuf, int txlen) case HCHR_UUEPKT: default: Syslog('+', "Hydra: TXPKT assert"); - die(1); + die(MBERR_FTRANSFER); } *outbuf++ = H_DLE; @@ -1196,7 +1197,7 @@ int hydra_batch(int role, file_list *to_send) break; default: - die(1); + die(MBERR_FTRANSFER); } /* switch (txstate) */ switch (rxstate) { @@ -1586,10 +1587,10 @@ int hydra_batch(int role, file_list *to_send) sleep(4); /* wait a few seconds... */ FLUSHIN(); - return 2; + return MBERR_FTRANSFER; } - return 0; + return MBERR_OK; } diff --git a/mbcico/mbcico.c b/mbcico/mbcico.c index d0cebe7e..b782d871 100644 --- a/mbcico/mbcico.c +++ b/mbcico/mbcico.c @@ -39,6 +39,7 @@ #include "../lib/dbcfg.h" #include "../lib/dbnode.h" #include "../lib/dbftn.h" +#include "../lib/mberrors.h" #include "config.h" #include "answer.h" #include "call.h" @@ -182,7 +183,7 @@ int main(int argc, char *argv[]) #ifdef MEMWATCH mwTerm(); #endif - exit(101); + exit(MBERR_COMMANDLINE); } InitConfig(); @@ -254,7 +255,7 @@ int main(int argc, char *argv[]) tcp_mode = TCPMODE_IBN; else { usage(); - die(101); + die(MBERR_COMMANDLINE); } free(p); RegTCP(); @@ -267,7 +268,7 @@ int main(int argc, char *argv[]) break; default: usage(); - die(101); + die(MBERR_COMMANDLINE); } /* @@ -305,7 +306,7 @@ int main(int argc, char *argv[]) #ifdef MEMWATCH mwTerm(); #endif - exit(100); + exit(MBERROR_EXEC_FAILED); } #endif if ((strcasecmp(argv[optind],"tsync") == 0) || @@ -364,11 +365,11 @@ int main(int argc, char *argv[]) * Don't do outbound calls if low diskspace */ if (!diskfree(CFG.freespace)) - die(101); + die(MBERR_DISK_FULL); if (callist == NULL) { WriteError("Calling mbcico without node address not supported anymore"); - die(101); + die(MBERR_COMMANDLINE); } for (tmpl = &callist; *tmpl; tmpl = &((*tmpl)->next)) { @@ -401,9 +402,9 @@ int main(int argc, char *argv[]) tidy_falist(&callist); if (maxrc) - die(maxrc+100); + die(maxrc); else - die(0); + die(MBERR_OK); return 0; } diff --git a/mbcico/mbout.c b/mbcico/mbout.c index 57b0ea16..32e0fc6b 100644 --- a/mbcico/mbout.c +++ b/mbcico/mbout.c @@ -39,6 +39,7 @@ #include "../lib/dbcfg.h" #include "../lib/dbnode.h" #include "../lib/dbftn.h" +#include "../lib/mberrors.h" #include "outstat.h" #include "nlinfo.h" @@ -147,21 +148,21 @@ void Help() colour(3, 0); printf(" -quiet Quiet mode\n"); colour(7, 0); - die(0); + die(MBERR_OK); } -void Fatal(char *); -void Fatal(char *msg) +void Fatal(char *, int); +void Fatal(char *msg, int error) { - show_log = TRUE; - if (!do_quiet) { - colour(12, 0); - printf("%s\n", msg); - } - WriteError(msg); - die(100); + show_log = TRUE; + if (!do_quiet) { + colour(12, 0); + printf("%s\n", msg); + } + WriteError(msg); + die(error); } @@ -243,12 +244,10 @@ int main(int argc, char *argv[]) } if (strcmp(pw->pw_name, "mbse")) - Fatal((char *)"You are not user 'mbse'"); + Fatal((char *)"You are not user 'mbse'", MBERR_COMMANDLINE); if (do_stat) { rc = outstat(); - if (rc) - rc += 100; die(rc); } @@ -257,19 +256,17 @@ int main(int argc, char *argv[]) */ if (do_attach || do_node || do_poll || do_stop || do_req || do_reset) { if (argc < 3) - Fatal((char *)"Not enough parameters"); + Fatal((char *)"Not enough parameters", MBERR_COMMANDLINE); } if (do_attach || do_node || do_req || do_reset) { if ((addr = parsefaddr(argv[2])) == NULL) - Fatal((char *)"Unrecognizable address"); + Fatal((char *)"Unrecognizable address", MBERR_COMMANDLINE); } if (do_node) { rc = nlinfo(addr); tidy_faddr(addr); - if (rc) - rc += 100; die(rc); } @@ -277,15 +274,13 @@ int main(int argc, char *argv[]) for (i = 3; i <= argc; i++) { if (strncasecmp(argv[i-1], "-q", 2)) { if ((addr = parsefaddr(argv[i-1])) == NULL) - Fatal((char *)"Unrecognizable address"); + Fatal((char *)"Unrecognizable address", MBERR_COMMANDLINE); j = poll(addr, do_stop); tidy_faddr(addr); - if (j > rc) + if (j) rc = j; } } - if (rc) - rc = 100; die(rc); } @@ -293,50 +288,48 @@ int main(int argc, char *argv[]) for (i = 3; i <= argc; i++) { if (strncasecmp(argv[i-1], "-q", 2)) { if ((addr = parsefaddr(argv[i-1])) == NULL) - Fatal((char *)"Unrecognizable address"); + Fatal((char *)"Unrecognizable address", MBERR_COMMANDLINE); j = reset(addr); tidy_faddr(addr); - if (j > rc) + if (j) rc = j; } } - if (rc) - rc = 100; die(rc); } if (do_attach) { if (argc < 5) - Fatal((char *)"Not enough parameters"); + Fatal((char *)"Not enough parameters", MBERR_COMMANDLINE); 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"); + default : Fatal((char *)"Invalid flavor, must be: immediate, crash, normal or hold", MBERR_COMMANDLINE); } nlent = getnlent(addr); if (nlent->pflag == NL_DUMMY) - Fatal((char *)"Node is not in nodelist"); + Fatal((char *)"Node is not in nodelist", MBERR_NODE_NOT_IN_LIST); if (nlent->pflag == NL_DOWN) - Fatal((char *)"Node has status Down"); + Fatal((char *)"Node has status Down", MBERR_NODE_MAY_NOT_CALL); if (nlent->pflag == NL_HOLD) - Fatal((char *)"Node has status Hold"); + Fatal((char *)"Node has status Hold", MBERR_NODE_MAY_NOT_CALL); if (((nlent->oflags & OL_CM) == 0) && (flavor == 'c')) - Fatal((char *)"Node is not CM, must use Immediate, Normal or Hold flavor"); + Fatal((char *)"Node is not CM, must use Immediate, Normal or Hold flavor", MBERR_NODE_MAY_NOT_CALL); if (argv[4][0] == '-') - Fatal((char *)"Invalid filename given"); + Fatal((char *)"Invalid filename given", MBERR_COMMANDLINE); if (file_exist(argv[4], R_OK) != 0) - Fatal((char *)"File doesn't exist"); + Fatal((char *)"File doesn't exist", MBERR_COMMANDLINE); 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"); + Fatal((char *)"File attach failed", MBERR_ATTACH_FAILED); } else { fprintf(fl, "%c LEAVE %s\n", flavor, argv[4]); Syslog('+', "File attach %s is successfull", argv[4]); @@ -347,14 +340,14 @@ int main(int argc, char *argv[]) fsync(fileno(fl)); fclose(fl); free(cmd); - die(0); + die(MBERR_OK); } free(cmd); } if (do_req) { if (argc < 4) - Fatal((char *)"Not enough parameters"); + Fatal((char *)"Not enough parameters", MBERR_COMMANDLINE); for (i = 4; i <= argc; i++) { if (strncasecmp(argv[i-1], "-q", 2)) { rc = freq(addr, argv[i-1]); @@ -362,8 +355,6 @@ int main(int argc, char *argv[]) break; } } - if (rc) - rc += 100; die(rc); } @@ -371,7 +362,7 @@ int main(int argc, char *argv[]) #ifdef MEMWATCH mwTerm(); #endif - return 0; + return MBERR_OK; } diff --git a/mbcico/outstat.c b/mbcico/outstat.c index a21c39d7..499a3c40 100644 --- a/mbcico/outstat.c +++ b/mbcico/outstat.c @@ -39,6 +39,7 @@ #include "../lib/dbcfg.h" #include "../lib/dbnode.h" #include "../lib/dbftn.h" +#include "../lib/mberrors.h" #include "scanout.h" #include "callstat.h" #include "outstat.h" @@ -82,7 +83,7 @@ int outstat() if ((rc = scanout(each))) { WriteError("Error scanning outbound, aborting"); - return rc; + return MBERR_OUTBOUND_SCAN; } /* @@ -93,7 +94,7 @@ int outstat() if ((fp = fopen(temp, "r")) == NULL) { WriteError("Error open %s, aborting", temp); free(temp); - return 1; + return MBERR_OUTBOUND_SCAN; } fread(&nodeshdr, sizeof(nodeshdr), 1, fp); fseek(fp, 0, SEEK_SET); @@ -364,24 +365,24 @@ int poll(faddr *addr, int stop) Syslog('+', "Node %s not in nodelist", ascfnode(addr, 0x1f)); if (!do_quiet) printf("Node %s not in nodelist", ascfnode(addr, 0x1f)); - return 1; + return MBERR_NODE_NOT_IN_LIST; } if (nlent->pflag == NL_DOWN) { Syslog('+', "Node %s has status Down", ascfnode(addr, 0x1f)); if (!do_quiet) printf("Node %s has status Down", ascfnode(addr, 0x1f)); - return 1; + return MBERR_NODE_MAY_NOT_CALL; } if (nlent->pflag == NL_HOLD) { Syslog('+', "Node %s has status Hold", ascfnode(addr, 0x1f)); if (!do_quiet) printf("Node %s has status Hold", ascfnode(addr, 0x1f)); - return 1; + return MBERR_NODE_MAY_NOT_CALL; } if ((fp = fopen(pol, "w+")) == NULL) { WriteError("$Can't create poll for %s", ascfnode(addr, 0x1f)); - rc = 1; + rc = MBERR_CANNOT_MAKE_POLL; } else { fclose(fp); if (((nlent->oflags & OL_CM) == 0) && (!IsZMH())) { @@ -394,12 +395,13 @@ int poll(faddr *addr, int stop) printf("Created poll for %s\n", ascfnode(addr, 0x1f)); } cst = getstatus(addr); - if ((cst->trystat == 5) || - (cst->trystat == ST_NOTZMH) || - (cst->trystat == ST_NOCONN) || - (cst->trystat == ST_NOCALL7) || - (cst->trystat == ST_NOCALL8) || - (cst->trystat > 10)) { + if ((cst->trystat == MBERR_NODE_LOCKED) || + (cst->trystat == MBERR_NOT_ZMH) || + (cst->trystat == MBERR_NO_CONNECTION) || + (cst->trystat == MBERR_SESSION_ERROR) || + (cst->trystat == MBERR_UNKNOWN_SESSION) || + (cst->trystat == MBERR_NO_PORT_AVAILABLE) || + (cst->trystat == MBERR_MODEM_ERROR)) { putstatus(addr, 0, 0); } CreateSema((char *)"scanout"); @@ -443,7 +445,7 @@ int freq(faddr *addr, char *fname) if (!do_quiet) printf("File request failed\n"); free(req); - return 1; + return MBERR_REQUEST; } fprintf(fp, "%s\r\n", fname); fclose(fp); diff --git a/mbcico/session.c b/mbcico/session.c index 277edd67..32488918 100644 --- a/mbcico/session.c +++ b/mbcico/session.c @@ -36,6 +36,7 @@ #include "../lib/records.h" #include "../lib/common.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "ttyio.h" #include "statetbl.h" #include "emsi.h" @@ -79,7 +80,7 @@ char *typestr(int tp) int session(faddr *a, node *nl, int role, int tp, char *dt) { - int rc = 1; + int rc = MBERR_OK; fa_list *tmpl; struct sockaddr_in peeraddr; int addrlen = sizeof(struct sockaddr_in); @@ -108,7 +109,7 @@ int session(faddr *a, node *nl, int role, int tp, char *dt) IsDoing("Incoming IFC/TCP"); } else if (tcp_mode == TCPMODE_NONE) { WriteError("Unknown TCP connection, parameter missing"); - die(101); + die(MBERR_COMMANDLINE); } } session_flags |= SESSION_TCP; @@ -147,11 +148,11 @@ int session(faddr *a, node *nl, int role, int tp, char *dt) if (type == SESSION_UNKNOWN) (void)tx_define_type(); switch(type) { - case SESSION_UNKNOWN: rc=20; break; - case SESSION_FTSC: rc=tx_ftsc(); break; - case SESSION_YOOHOO: rc=tx_yoohoo(); break; - case SESSION_EMSI: rc=tx_emsi(data); break; - case SESSION_BINKP: rc=binkp(role); break; + case SESSION_UNKNOWN: rc = MBERR_UNKNOWN_SESSION; break; + case SESSION_FTSC: rc = tx_ftsc(); break; + case SESSION_YOOHOO: rc = tx_yoohoo(); break; + case SESSION_EMSI: rc = tx_emsi(data); break; + case SESSION_BINKP: rc = binkp(role); break; } } else { if (type == SESSION_FTSC) @@ -159,11 +160,11 @@ int session(faddr *a, node *nl, int role, int tp, char *dt) if (type == SESSION_UNKNOWN) (void)rx_define_type(); switch(type) { - case SESSION_UNKNOWN: rc=20; break; - case SESSION_FTSC: rc=rx_ftsc(); break; - case SESSION_YOOHOO: rc=rx_yoohoo(); break; - case SESSION_EMSI: rc=rx_emsi(data); break; - case SESSION_BINKP: rc=binkp(role); break; + case SESSION_UNKNOWN: rc = MBERR_UNKNOWN_SESSION; break; + case SESSION_FTSC: rc = rx_ftsc(); break; + case SESSION_YOOHOO: rc = rx_yoohoo(); break; + case SESSION_EMSI: rc = rx_emsi(data); break; + case SESSION_BINKP: rc = binkp(role); break; } } sleep(2); diff --git a/mbcico/tcpproto.c b/mbcico/tcpproto.c index bd626e90..6f7e5ce5 100644 --- a/mbcico/tcpproto.c +++ b/mbcico/tcpproto.c @@ -38,6 +38,7 @@ #include "../lib/structs.h" #include "../lib/common.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "ttyio.h" #include "session.h" #include "config.h" @@ -84,7 +85,7 @@ int tcpsndfiles(file_list *lst) if (getsync()) { WriteError("Can't get synchronization"); - return 1; + return MBERR_FTRANSFER; } for (tmpf = lst; tmpf && (maxrc == 0); tmpf = tmpf->next) { @@ -108,9 +109,11 @@ int tcpsndfiles(file_list *lst) if (rc > maxrc) maxrc=rc; - if (rc) - WriteError("TCP send error: rc=%d",maxrc); - return maxrc; + if (rc) { + WriteError("TCP send error: rc=%d",maxrc); + return MBERR_FTRANSFER; + } else + return 0; } @@ -124,7 +127,7 @@ int tcprcvfiles(void) Syslog('+', "Start TCP receive"); if (getsync()) { WriteError("Can't get synchronization"); - return 1; + return MBERR_FTRANSFER; } next: if ((rc = tcp_rblk(rxbuf, &bufl)) == 0) { @@ -155,9 +158,11 @@ next: goto next; } - if (rc) - WriteError("TCP receive error: rc=%d", rc); - return abs(rc); + if (rc) { + WriteError("TCP receive error: rc=%d", rc); + return MBERR_FTRANSFER; + } else + return 0; } diff --git a/mbcico/wazoo.c b/mbcico/wazoo.c index 58f08600..cf2b7c18 100644 --- a/mbcico/wazoo.c +++ b/mbcico/wazoo.c @@ -34,6 +34,7 @@ #include "../lib/structs.h" #include "../lib/common.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "ttyio.h" #include "session.h" #include "statetbl.h" @@ -50,80 +51,85 @@ extern int made_request; int rxwazoo(void) { - int rc = 0; - fa_list *eff_remote, tmpl; - file_list *tosend = NULL, **tmpfl; + int rc = 0; + fa_list *eff_remote, tmpl; + file_list *tosend = NULL, **tmpfl; - Syslog('+', "Start WaZOO session"); + Syslog('+', "Start WaZOO session"); - if (emsi_remote_lcodes & LCODE_NPU) { - Syslog('+', "Remote requested \"no pickup\", no send"); - eff_remote=NULL; - } else if (emsi_remote_lcodes & LCODE_PUP) { - Syslog('+', "Remote requested \"pickup primary\""); - tmpl.addr = remote->addr; - tmpl.next = NULL; - eff_remote = &tmpl; - } else eff_remote=remote; + if (emsi_remote_lcodes & LCODE_NPU) { + Syslog('+', "Remote requested \"no pickup\", no send"); + eff_remote=NULL; + } else if (emsi_remote_lcodes & LCODE_PUP) { + Syslog('+', "Remote requested \"pickup primary\""); + tmpl.addr = remote->addr; + tmpl.next = NULL; + eff_remote = &tmpl; + } else eff_remote=remote; - tosend = create_filelist(eff_remote,(char *)ALL_MAIL,0); + tosend = create_filelist(eff_remote,(char *)ALL_MAIL,0); - if ((rc = zmrcvfiles()) == 0) { - if ((emsi_local_opts & OPT_NRQ) == 0) { - for (tmpfl = &tosend; *tmpfl; tmpfl = &((*tmpfl)->next)); - *tmpfl = respond_wazoo(); - } - - if ((tosend != NULL) || ((emsi_remote_lcodes & LCODE_NPU) == 0)) - rc = zmsndfiles(tosend); - - if ((rc == 0) && (made_request)) { - Syslog('+', "Freq was made, trying to receive files"); - rc = zmrcvfiles(); - } + if ((rc = zmrcvfiles()) == 0) { + if ((emsi_local_opts & OPT_NRQ) == 0) { + for (tmpfl = &tosend; *tmpfl; tmpfl = &((*tmpfl)->next)); + *tmpfl = respond_wazoo(); } - tidy_filelist(tosend, (rc == 0)); + if ((tosend != NULL) || ((emsi_remote_lcodes & LCODE_NPU) == 0)) + rc = zmsndfiles(tosend); - if (rc) - WriteError("WaZOO session failed: rc=%d", rc); - else - Syslog('+', "WaZOO session completed"); - return rc; + if ((rc == 0) && (made_request)) { + Syslog('+', "Freq was made, trying to receive files"); + rc = zmrcvfiles(); + } + } + + tidy_filelist(tosend, (rc == 0)); + + if (rc) { + WriteError("WaZOO session failed: rc=%d", rc); + return MBERR_WAZOO; + } + + Syslog('+', "WaZOO session completed"); + return MBERR_OK; } int txwazoo(void) { - int rc = 0; - file_list *tosend = NULL, *respond = NULL; - char *nonhold_mail; + int rc = 0; + file_list *tosend = NULL, *respond = NULL; + char *nonhold_mail; - Syslog('+', "Start WaZOO session"); -// if (localoptions & NOHOLD) - nonhold_mail = (char *)ALL_MAIL; -// else -// nonhold_mail = (char *)NONHOLD_MAIL; - if (emsi_remote_lcodes & LCODE_HAT) { - Syslog('+', "Remote asked to \"hold all traffic\", no send"); - tosend = NULL; - } else tosend = create_filelist(remote, nonhold_mail, 0); + Syslog('+', "Start WaZOO session"); +// if (localoptions & NOHOLD) + nonhold_mail = (char *)ALL_MAIL; +// else +// nonhold_mail = (char *)NONHOLD_MAIL; + if (emsi_remote_lcodes & LCODE_HAT) { + Syslog('+', "Remote asked to \"hold all traffic\", no send"); + tosend = NULL; + } else tosend = create_filelist(remote, nonhold_mail, 0); - if ((tosend != NULL) || ((emsi_remote_lcodes & LCODE_NPU) == 0)) - rc = zmsndfiles(tosend); - if (rc == 0) - if ((rc = zmrcvfiles()) == 0) - if ((emsi_local_opts & OPT_NRQ) == 0) - if ((respond = respond_wazoo())) - rc = zmsndfiles(respond); + if ((tosend != NULL) || ((emsi_remote_lcodes & LCODE_NPU) == 0)) + rc = zmsndfiles(tosend); + if (rc == 0) + if ((rc = zmrcvfiles()) == 0) + if ((emsi_local_opts & OPT_NRQ) == 0) + if ((respond = respond_wazoo())) + rc = zmsndfiles(respond); - tidy_filelist(tosend,(rc == 0)); - tidy_filelist(respond,0); - if (rc) - WriteError("WaZOO session failed: rc=%d", rc); - else - Syslog('+', "WaZOO session completed"); - return rc; + tidy_filelist(tosend,(rc == 0)); + tidy_filelist(respond,0); + + if (rc) { + WriteError("WaZOO session failed: rc=%d", rc); + return MBERR_WAZOO; + } + + Syslog('+', "WaZOO session completed"); + return MBERR_OK; } diff --git a/mbcico/yoohoo.c b/mbcico/yoohoo.c index 45fadeea..0e91aa76 100644 --- a/mbcico/yoohoo.c +++ b/mbcico/yoohoo.c @@ -45,6 +45,7 @@ #include "../lib/clcomm.h" #include "../lib/common.h" #include "../lib/dbnode.h" +#include "../lib/mberrors.h" #include "statetbl.h" #include "ttyio.h" #include "session.h" @@ -121,165 +122,166 @@ Hello gethello2(unsigned char[]); int rx_yoohoo(void) { - int rc; - unsigned short capabilities,localcaps; - char *pwd = NULL; + int rc; + unsigned short capabilities,localcaps; + char *pwd = NULL; - Syslog('+', "Start inbound YooHoo session"); + Syslog('+', "Start inbound YooHoo session"); - pwd = NULL; - localcaps = LOCALCAPS; - if (localoptions & NOZMODEM) localcaps &= ~(ZED_ZAPPER|ZED_ZIPPER); - if (localoptions & NOZEDZAP) localcaps &= ~ZED_ZAPPER; - if (localoptions & NOHYDRA) localcaps &= ~DOES_HYDRA; - emsi_local_opts = 0; - emsi_remote_opts = 0; - iscaller = 0; + pwd = NULL; + localcaps = LOCALCAPS; + if (localoptions & NOZMODEM) localcaps &= ~(ZED_ZAPPER|ZED_ZIPPER); + if (localoptions & NOZEDZAP) localcaps &= ~ZED_ZAPPER; + if (localoptions & NOHYDRA) localcaps &= ~DOES_HYDRA; + emsi_local_opts = 0; + emsi_remote_opts = 0; + iscaller = 0; - if ((rc = rxyoohoo()) == 0) { - Loaded = checkhello(); - capabilities = hello2.capabilities; - if (capabilities & WZ_FREQ) - session_flags |= SESSION_WAZOO; - else - session_flags &= ~SESSION_WAZOO; - localcaps &= capabilities; - if (localcaps & DOES_HYDRA) - localcaps &= DOES_HYDRA; - else if (localcaps & ZED_ZAPPER) - localcaps &= ZED_ZAPPER; - else if (localcaps & ZED_ZIPPER) - localcaps &= ZED_ZIPPER; - else if (localcaps & FTB_USER) - localcaps &= FTB_USER; - else if (localcaps & Y_DIETIFNA) - localcaps &= Y_DIETIFNA; - if ((localoptions & NOFREQS) == 0) - localcaps |= WZ_FREQ; - else - emsi_local_opts |= OPT_NRQ; - - if (((nlent=getnlent(remote->addr))) && (nlent->pflag != NL_DUMMY)) { - Syslog('+', "Remote is a listed system"); - if (inbound) - free(inbound); - inbound = xstrcpy(CFG.inbound); - strncpy(history.location, nlent->location, 35); - } - if (nlent) - rdoptions(Loaded); - - if (strlen(nodes.Spasswd)) { - if ((strncasecmp((char*)hello2.my_password, nodes.Spasswd, strlen(nodes.Spasswd)) == 0) && - (strlen((char*)hello2.my_password) == strlen(nodes.Spasswd))) { - Syslog('+', "Password correct, protected mail session"); - if (inbound) - free(inbound); - inbound = xstrcpy(CFG.pinbound); - pwd = xstrcpy(nodes.Spasswd); - } else { - pwd = (char *)"BAD_PASS"; - Syslog('?', "Remote password \"%s\", expected \"%s\"", (char*)hello2.my_password, nodes.Spasswd); - localcaps = 0; - } - } else - Syslog('s', "No YooHoo password check"); - fillhello(localcaps,pwd); - - rc = txyoohoo(); - if (pwd) - free(pwd); - } - - if ((rc == 0) && ((localcaps & LOCALCAPS) == 0)) { - Syslog('+', "No common protocols or bad password"); - return 0; - } - if (rc) - return rc; - - IsDoing("Inbound %s", ascfnode(remote->addr, 0x0f)); - - session_flags |= SESSION_WAZOO; - if (localcaps & DOES_HYDRA) - return hydra(0); - else if ((localcaps & ZED_ZAPPER) || (localcaps & ZED_ZIPPER)) { - if (localcaps & ZED_ZAPPER) - emsi_local_protos = PROT_ZAP; - else - emsi_local_protos = PROT_ZMO; - return rxwazoo(); - } else if (localcaps & Y_DIETIFNA) - return rxdietifna(); + if ((rc = rxyoohoo()) == 0) { + Loaded = checkhello(); + capabilities = hello2.capabilities; + if (capabilities & WZ_FREQ) + session_flags |= SESSION_WAZOO; else - WriteError("YooHoo internal error - no proto for 0x%04xh",localcaps); - return 1; + session_flags &= ~SESSION_WAZOO; + localcaps &= capabilities; + if (localcaps & DOES_HYDRA) + localcaps &= DOES_HYDRA; + else if (localcaps & ZED_ZAPPER) + localcaps &= ZED_ZAPPER; + else if (localcaps & ZED_ZIPPER) + localcaps &= ZED_ZIPPER; + else if (localcaps & FTB_USER) + localcaps &= FTB_USER; + else if (localcaps & Y_DIETIFNA) + localcaps &= Y_DIETIFNA; + if ((localoptions & NOFREQS) == 0) + localcaps |= WZ_FREQ; + else + emsi_local_opts |= OPT_NRQ; + + if (((nlent=getnlent(remote->addr))) && (nlent->pflag != NL_DUMMY)) { + Syslog('+', "Remote is a listed system"); + if (inbound) + free(inbound); + inbound = xstrcpy(CFG.inbound); + strncpy(history.location, nlent->location, 35); + } + if (nlent) + rdoptions(Loaded); + + if (strlen(nodes.Spasswd)) { + if ((strncasecmp((char*)hello2.my_password, nodes.Spasswd, strlen(nodes.Spasswd)) == 0) && + (strlen((char*)hello2.my_password) == strlen(nodes.Spasswd))) { + Syslog('+', "Password correct, protected mail session"); + if (inbound) + free(inbound); + inbound = xstrcpy(CFG.pinbound); + pwd = xstrcpy(nodes.Spasswd); + } else { + pwd = (char *)"BAD_PASS"; + Syslog('?', "Remote password \"%s\", expected \"%s\"", (char*)hello2.my_password, nodes.Spasswd); + localcaps = 0; + } + } else + Syslog('s', "No YooHoo password check"); + + fillhello(localcaps,pwd); + + rc = txyoohoo(); + if (pwd) + free(pwd); + } + + if ((rc == 0) && ((localcaps & LOCALCAPS) == 0)) { + Syslog('+', "No common protocols or bad password"); + return 0; + } + if (rc) + return MBERR_YOOHOO; + + IsDoing("Inbound %s", ascfnode(remote->addr, 0x0f)); + + session_flags |= SESSION_WAZOO; + if (localcaps & DOES_HYDRA) + return hydra(0); + else if ((localcaps & ZED_ZAPPER) || (localcaps & ZED_ZIPPER)) { + if (localcaps & ZED_ZAPPER) + emsi_local_protos = PROT_ZAP; + else + emsi_local_protos = PROT_ZMO; + return rxwazoo(); + } else if (localcaps & Y_DIETIFNA) + return rxdietifna(); + + WriteError("YooHoo internal error - no proto for 0x%04xh",localcaps); + return MBERR_YOOHOO; } int tx_yoohoo(void) { - int rc; - unsigned short capabilities; - char *pwd; + int rc; + unsigned short capabilities; + char *pwd; - Syslog('+', "Start outbound YooHoo session"); + Syslog('+', "Start outbound YooHoo session"); - if (strlen(nodes.Spasswd)) - pwd = xstrcpy(nodes.Spasswd); - else - pwd = NULL; + if (strlen(nodes.Spasswd)) + pwd = xstrcpy(nodes.Spasswd); + else + pwd = NULL; - capabilities = LOCALCAPS; - if (localoptions & NOZMODEM) - capabilities &= ~(ZED_ZAPPER|ZED_ZIPPER); - if (localoptions & NOZEDZAP) - capabilities &= ~ZED_ZAPPER; - if (localoptions & NOHYDRA) - capabilities &= ~DOES_HYDRA; - if ((localoptions & NOFREQS) == 0) - capabilities |= WZ_FREQ; + capabilities = LOCALCAPS; + if (localoptions & NOZMODEM) + capabilities &= ~(ZED_ZAPPER|ZED_ZIPPER); + if (localoptions & NOZEDZAP) + capabilities &= ~ZED_ZAPPER; + if (localoptions & NOHYDRA) + capabilities &= ~DOES_HYDRA; + if ((localoptions & NOFREQS) == 0) + capabilities |= WZ_FREQ; + else + emsi_local_opts |= OPT_NRQ; + + fillhello(capabilities,pwd); + iscaller=1; + + if ((rc = txyoohoo()) == 0) { + rc = rxyoohoo(); + checkhello(); + capabilities = hello2.capabilities; + if (capabilities & WZ_FREQ) + session_flags |= SESSION_WAZOO; else - emsi_local_opts |= OPT_NRQ; + session_flags &= ~SESSION_WAZOO; + } - fillhello(capabilities,pwd); - iscaller=1; + if ((rc == 0) && ((capabilities & LOCALCAPS) == 0)) { + Syslog('+', "No common protocols"); + return 0; + } - if ((rc = txyoohoo()) == 0) { - rc = rxyoohoo(); - checkhello(); - capabilities = hello2.capabilities; - if (capabilities & WZ_FREQ) - session_flags |= SESSION_WAZOO; - else - session_flags &= ~SESSION_WAZOO; - } + if (rc) + return MBERR_YOOHOO; - if ((rc == 0) && ((capabilities & LOCALCAPS) == 0)) { - Syslog('+', "No common protocols"); - return 0; - } + IsDoing("Outbound %s", ascfnode(remote->addr, 0x0f)); - if (rc) - return rc; - - IsDoing("Outbound %s", ascfnode(remote->addr, 0x0f)); - - session_flags |= SESSION_WAZOO; - if (capabilities & DOES_HYDRA) - return hydra(1); - else if ((capabilities & ZED_ZAPPER) || (capabilities & ZED_ZIPPER)) { - if (capabilities & ZED_ZAPPER) - emsi_local_protos = PROT_ZAP; - else - emsi_local_protos = PROT_ZMO; - return txwazoo(); - } else if (capabilities & Y_DIETIFNA) - return txdietifna(); + session_flags |= SESSION_WAZOO; + if (capabilities & DOES_HYDRA) + return hydra(1); + else if ((capabilities & ZED_ZAPPER) || (capabilities & ZED_ZIPPER)) { + if (capabilities & ZED_ZAPPER) + emsi_local_protos = PROT_ZAP; else - WriteError("YooHoo internal error - no proto for 0x%04xh",capabilities); - return 1; + emsi_local_protos = PROT_ZMO; + return txwazoo(); + } else if (capabilities & Y_DIETIFNA) + return txdietifna(); + + WriteError("YooHoo internal error - no proto for 0x%04xh",capabilities); + return MBERR_YOOHOO; } diff --git a/mbfido/Makefile b/mbfido/Makefile index 5090dc67..48d8249a 100644 --- a/mbfido/Makefile +++ b/mbfido/Makefile @@ -139,7 +139,7 @@ addbbs.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/us backalias.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h backalias.h flock.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/clcomm.h flock.h hatch.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbtic.h utic.h rollover.h hatch.h -mbdiff.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbdiff.h +mbdiff.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbdiff.h mgrutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/diesel.h sendmail.h rollover.h addpkt.h createm.h createf.h mgrutil.h ptic.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbtic.h ../lib/clcomm.h ../lib/dbnode.h ../lib/dbdupe.h unpack.h mover.h toberep.h tic.h utic.h addbbs.h magic.h forward.h rollover.h ptic.h magic.h createf.h virscan.h sendmail.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbnode.h ../lib/clcomm.h ../lib/dbmsgs.h addpkt.h rollover.h sendmail.h @@ -148,7 +148,7 @@ addpkt.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/us bwrite.o: ../config.h ../lib/libs.h ../lib/memwatch.h bwrite.h forward.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbnode.h ../lib/dbtic.h ../lib/diesel.h tic.h sendmail.h rollover.h mgrutil.h forward.h lhash.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/clcomm.h lhash.h -mbfido.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbdupe.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/dbuser.h ../lib/dbftn.h ../lib/dbtic.h ../lib/msg.h flock.h tosspkt.h unpack.h tic.h fsort.h scan.h mbfido.h tracker.h notify.h rollover.h hatch.h scannews.h maketags.h makestat.h newspost.h rnews.h mgrutil.h backalias.h rfc2ftn.h dirsession.h dirlock.h queue.h +mbfido.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbdupe.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/dbuser.h ../lib/dbftn.h ../lib/dbtic.h ../lib/msg.h ../lib/mberrors.h flock.h tosspkt.h unpack.h tic.h fsort.h scan.h mbfido.h tracker.h notify.h rollover.h hatch.h scannews.h maketags.h makestat.h newspost.h rnews.h mgrutil.h backalias.h rfc2ftn.h dirsession.h dirlock.h queue.h mkftnhdr.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h atoul.h hash.h msgflags.h aliasdb.h mkftnhdr.h ping.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbtic.h ../lib/dbdupe.h ../lib/dbuser.h ../lib/dbftn.h sendmail.h postnetmail.h ping.h rfc2ftn.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mbinet.h ../lib/dbdupe.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/msg.h ../lib/msgtext.h mkftnhdr.h hash.h rollover.h postnetmail.h postecho.h msgflags.h rfc2ftn.h @@ -157,17 +157,17 @@ unpack.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/us aliasdb.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h aliasdb.h fsort.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/clcomm.h fsort.h magic.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbtic.h tic.h utic.h magic.h -mbfile.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfkill.h mbfadopt.h mbfindex.h mbfcheck.h mbfpack.h mbflist.h mbfimport.h mbftoberep.h mbfmove.h mbfdel.h mbfutil.h mbfile.h +mbfile.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbfkill.h mbfadopt.h mbfindex.h mbfcheck.h mbfpack.h mbflist.h mbfimport.h mbftoberep.h mbfmove.h mbfdel.h mbfutil.h mbfile.h mover.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h tic.h mover.h post.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/msg.h ../lib/msgtext.h post.h -rnews.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mbinet.h ../lib/dbdupe.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/msg.h ../lib/msgtext.h rfc2ftn.h mbfido.h ../paths.h rnews.h +rnews.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mbinet.h ../lib/dbdupe.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/msg.h ../lib/msgtext.h ../lib/mberrors.h rfc2ftn.h mbfido.h ../paths.h rnews.h storenet.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbmsgs.h ../lib/dbuser.h msgflags.h rollover.h storenet.h utic.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h tic.h mover.h tic.h utic.h announce.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/msg.h ../lib/msgtext.h ../lib/diesel.h grlist.h msgutil.h announce.h fflist.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/clcomm.h ../lib/msg.h fflist.h ftn2rfc.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/dbftn.h ../lib/dbdupe.h ../lib/dbuser.h ../lib/common.h ../lib/clcomm.h rollover.h aliasdb.h postemail.h backalias.h msgflags.h ftn2rfc.h makestat.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/diesel.h ../lib/msg.h mgrutil.h makestat.h -mbindex.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/dbftn.h mbindex.h +mbindex.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/dbftn.h ../lib/mberrors.h mbindex.h msgutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/msg.h ../lib/msgtext.h ../lib/diesel.h msgutil.h postecho.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/dbdupe.h ../lib/dbuser.h ../lib/dbftn.h ftn2rfc.h postecho.h storeecho.h addpkt.h rollover.h rollover.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h rollover.h @@ -176,7 +176,7 @@ areamgr.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/u filefind.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/msg.h ../lib/msgtext.h ../lib/diesel.h fflist.h filefind.h msgutil.h grlist.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/clcomm.h grlist.h maketags.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h maketags.h -mbmsg.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/dbcfg.h post.h mbmsg.h +mbmsg.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/dbcfg.h ../lib/mberrors.h post.h mbmsg.h newspost.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mbinet.h newspost.h postemail.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/dbuser.h ../lib/common.h ../lib/clcomm.h ../lib/mbinet.h postemail.h scan.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/msg.h ../lib/clcomm.h ../lib/msgtext.h ../lib/dbnode.h ../lib/dbmsgs.h addpkt.h tracker.h ftn2rfc.h rfc2ftn.h postemail.h scan.h @@ -184,24 +184,24 @@ toberep.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/u atoul.o: ../config.h ../lib/libs.h ../lib/memwatch.h atoul.h filemgr.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbtic.h ../lib/dbdupe.h ../lib/dbuser.h ../lib/dbftn.h ../lib/diesel.h sendmail.h mgrutil.h createf.h filemgr.h hash.o: ../config.h ../lib/libs.h ../lib/memwatch.h hash.h lhash.h -mbaff.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/msg.h announce.h filefind.h mbaff.h +mbaff.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/msg.h ../lib/mberrors.h announce.h filefind.h mbaff.h mbseq.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbseq.h notify.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbnode.h filemgr.h areamgr.h sendmail.h mgrutil.h notify.h postnetmail.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/common.h ../lib/records.h ../lib/dbcfg.h ../lib/dbuser.h ../lib/dbnode.h ../lib/dbftn.h ../lib/clcomm.h tracker.h addpkt.h storenet.h ftn2rfc.h areamgr.h filemgr.h ping.h bounce.h postemail.h scannews.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mbinet.h ../lib/dbdupe.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/msg.h ../lib/msgtext.h mkftnhdr.h hash.h rollover.h storeecho.h rfc2ftn.h scannews.h tosspkt.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/dbdupe.h ../lib/dbuser.h ../lib/dbftn.h tosspkt.h postnetmail.h postecho.h rollover.h createm.h -mbfkill.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfkill.h mbfutil.h -mbfutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfutil.h mbfile.h -mbfindex.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/diesel.h mbfutil.h mbfindex.h -mbfcheck.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfutil.h mbfcheck.h -mbfpack.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfutil.h mbfpack.h -mbflist.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfutil.h mbflist.h -mbfadopt.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h virscan.h mbfutil.h mbflist.h -mbfimport.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h virscan.h mbfutil.h mbfimport.h +mbfkill.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbfkill.h mbfutil.h +mbfutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbfutil.h mbfile.h +mbfindex.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/diesel.h ../lib/mberrors.h mbfutil.h mbfindex.h +mbfcheck.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbfutil.h mbfcheck.h +mbfpack.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbfutil.h mbfpack.h +mbflist.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbfutil.h mbflist.h +mbfadopt.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h virscan.h mbfutil.h mbflist.h +mbfimport.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h virscan.h mbfutil.h mbfimport.h virscan.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h virscan.h mbftoberep.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfutil.h mbftoberep.h -mbfmove.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfutil.h mbfmove.h -mbfdel.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbfutil.h mbfmove.h +mbfmove.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbfutil.h mbfmove.h +mbfdel.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbfutil.h mbfmove.h bounce.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbtic.h ../lib/dbdupe.h ../lib/dbuser.h ../lib/dbftn.h sendmail.h postnetmail.h ping.h createm.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h mgrutil.h createm.h createf.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h mgrutil.h createf.h diff --git a/mbfido/mbaff.c b/mbfido/mbaff.c index 8cfd0a9e..a8a5431a 100644 --- a/mbfido/mbaff.c +++ b/mbfido/mbaff.c @@ -38,6 +38,7 @@ #include "../lib/clcomm.h" #include "../lib/dbcfg.h" #include "../lib/msg.h" +#include "../lib/mberrors.h" #include "announce.h" #include "filefind.h" #include "mbaff.h" @@ -152,7 +153,7 @@ int main(int argc, char **argv) printf("\n"); if (!diskfree(CFG.freespace)) - die(101); + die(MBERR_DISK_FULL); memset(&MsgBase, 0, sizeof(MsgBase)); @@ -169,7 +170,7 @@ int main(int argc, char **argv) CreateSema((char *)"msglink"); } - die(0); + die(MBERR_OK); return 0; } @@ -193,7 +194,7 @@ void Help(void) printf(" -q -quiet Quiet mode\n"); colour(7, 0); printf("\n"); - die(0); + die(MBERR_COMMANDLINE); } diff --git a/mbfido/mbdiff.c b/mbfido/mbdiff.c index 561a9651..c1667008 100644 --- a/mbfido/mbdiff.c +++ b/mbfido/mbdiff.c @@ -38,6 +38,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbcfg.h" +#include "../lib/mberrors.h" #include "mbdiff.h" @@ -115,322 +116,317 @@ void die(int onsig) int main(int argc, char **argv) { - int i, Match; - char *cmd, *nl = NULL, *nd = NULL, *nn; - int rc; - char *p, *q, *arc; - struct passwd *pw; - char *wrk, *onl, *ond; - DIR *dp; - struct dirent *de; + int i, Match, rc; + char *cmd, *nl = NULL, *nd = NULL, *nn, *p, *q, *arc, *wrk, *onl, *ond; + struct passwd *pw; + DIR *dp; + struct dirent *de; #ifdef MEMWATCH - mwInit(); + mwInit(); #endif - InitConfig(); - TermInit(1); - t_start = time(NULL); - umask(002); + InitConfig(); + 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 == SIGKILL)) - signal(i, (void (*))die); - else - signal(i, SIG_IGN); - } + /* + * 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 == SIGKILL)) + signal(i, (void (*))die); + else + signal(i, SIG_IGN); + } - if(argc < 3) + if(argc < 3) + Help(); + + cmd = xstrcpy((char *)"Cmd: mbdiff"); + + for (i = 1; i < argc; i++) { + + cmd = xstrcat(cmd, (char *)" "); + cmd = xstrcat(cmd, argv[i]); + + if (i == 1) + if ((nl = argv[i]) == NULL) Help(); + if (i == 2) + if ((nd = argv[i]) == NULL) + Help(); + if (!strncasecmp(argv[i], "-q", 2)) + do_quiet = TRUE; - cmd = xstrcpy((char *)"Cmd: mbdiff"); + } - for (i = 1; i < argc; i++) { + ProgName(); + pw = getpwuid(getuid()); + InitClient(pw->pw_name, (char *)"mbdiff", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog); - cmd = xstrcat(cmd, (char *)" "); - cmd = xstrcat(cmd, argv[i]); + Syslog(' ', " "); + Syslog(' ', "MBDIFF v%s", VERSION); + Syslog(' ', cmd); + free(cmd); - if (i == 1) - if ((nl = argv[i]) == NULL) - Help(); - if (i == 2) - if ((nd = argv[i]) == NULL) - Help(); - if (!strncasecmp(argv[i], "-q", 2)) - do_quiet = TRUE; + if (!do_quiet) { + colour(12, 0); + printf("\n"); + } + if (!diskfree(CFG.freespace)) + die(MBERR_DISK_FULL); + + /* + * Extract work directory from the first commandline parameter + * and set that directory as default. + */ + show_log = TRUE; + wrk = xstrcpy(nl); + if (strrchr(wrk, '/') == NULL) { + WriteError("No path in nodelist name"); + free(wrk); + die(MBERR_COMMANDLINE); + } + if (strrchr(wrk, '.') != NULL) { + WriteError("Filename extension given for nodelist"); + free(wrk); + die(MBERR_COMMANDLINE); + } + if (strrchr(nd, '/') == NULL) { + WriteError("No path in nodediff name"); + free(wrk); + die(MBERR_COMMANDLINE); + } + show_log = FALSE; + + while (wrk[strlen(wrk) -1] != '/') + wrk[strlen(wrk) -1] = '\0'; + wrk[strlen(wrk) -1] = '\0'; + + show_log = TRUE; + if (access(wrk, R_OK|W_OK)) { + WriteError("$No R/W access in %s", wrk); + free(wrk); + die(MBERR_INIT_ERROR); + } + + if (chdir(wrk)) { + WriteError("$Can't chdir to %s", wrk); + free(wrk); + die(MBERR_INIT_ERROR); + } + show_log = FALSE; + + onl = xstrcpy(strrchr(nl, '/') + 1); + onl = xstrcat(onl, (char *)".???"); + + if ((dp = opendir(wrk)) == 0) { + show_log = TRUE; + free(wrk); + WriteError("$Error opening directory %s", wrk); + die(MBERR_INIT_ERROR); + } + + Match = FALSE; + while ((de = readdir(dp))) { + if (strlen(de->d_name) == strlen(onl)) { + Match = TRUE; + for (i = 0; i < strlen(onl); i++) { + if ((onl[i] != '?') && (onl[i] != de->d_name[i])) + Match = FALSE; + } + if (Match) { + free(onl); + onl = xstrcpy(de->d_name); + break; + } } + } + closedir(dp); + if (!Match) { + show_log = TRUE; + free(wrk); + free(onl); + WriteError("Old nodelist not found"); + die(MBERR_INIT_ERROR); + } - ProgName(); - pw = getpwuid(getuid()); - InitClient(pw->pw_name, (char *)"mbdiff", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog); + /* + * Now try to get the diff file into the workdir. + */ + if ((arc = unpacker(nd)) == NULL) { + show_log = TRUE; + free(onl); + free(wrk); + WriteError("Can't get filetype for %s", nd); + die(MBERR_CONFIG_ERROR); + } - Syslog(' ', " "); - Syslog(' ', "MBDIFF v%s", VERSION); - Syslog(' ', cmd); - free(cmd); + ond = xstrcpy(strrchr(nd, '/') + 1); - if (!do_quiet) { - colour(12, 0); - printf("\n"); + if (strncmp(arc, "ASC", 3)) { + if (!getarchiver(arc)) { + show_log = TRUE; + free(onl); + free(wrk); + free(ond); + WriteError("Can't find unarchiver %s", arc); + die(MBERR_CONFIG_ERROR); } - if (!diskfree(CFG.freespace)) - die(101); - /* - * Extract work directory from the first commandline parameter - * and set that directory as default. + * We may both use the unarchive command for files and mail, + * unarchiving isn't recursive anyway. */ - show_log = TRUE; - wrk = xstrcpy(nl); - if (strrchr(wrk, '/') == NULL) { - WriteError("No path in nodelist name"); - free(wrk); - die(100); - } - if (strrchr(wrk, '.') != NULL) { - WriteError("Filename extension given for nodelist"); - free(wrk); - die(100); - } - if (strrchr(nd, '/') == NULL) { - WriteError("No path in nodediff name"); - free(wrk); - die(100); - } - show_log = FALSE; + if (strlen(archiver.funarc)) + cmd = xstrcpy(archiver.funarc); + else + cmd = xstrcpy(archiver.munarc); - while (wrk[strlen(wrk) -1] != '/') - wrk[strlen(wrk) -1] = '\0'; - wrk[strlen(wrk) -1] = '\0'; - - show_log = TRUE; - if (access(wrk, R_OK|W_OK)) { - WriteError("$No R/W access in %s", wrk); - free(wrk); - die(100); + if ((cmd == NULL) || (cmd == "")) { + show_log = TRUE; + free(cmd); + free(onl); + free(wrk); + free(ond); + WriteError("No unarc command available for %s", arc); + die(MBERR_CONFIG_ERROR); } - if (chdir(wrk)) { - WriteError("$Can't chdir to %s", wrk); - free(wrk); - die(100); - } - show_log = FALSE; - - onl = xstrcpy(strrchr(nl, '/') + 1); - onl = xstrcat(onl, (char *)".???"); - - if ((dp = opendir(wrk)) == 0) { - show_log = TRUE; - free(wrk); - WriteError("$Error opening directory %s", wrk); - die(100); + if (execute(cmd, nd, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")) { + show_log = TRUE; + free(cmd); + free(onl); + free(wrk); + free(ond); + WriteError("Unpack error"); + die(MBERR_EXEC_FAILED); } + free(cmd); + sync(); Match = FALSE; - while ((de = readdir(dp))) { - if (strlen(de->d_name) == strlen(onl)) { - Match = TRUE; - for (i = 0; i < strlen(onl); i++) { - if ((onl[i] != '?') && (onl[i] != de->d_name[i])) - Match = FALSE; - } - if (Match) { - free(onl); - onl = xstrcpy(de->d_name); - break; - } + if ((dp = opendir(wrk)) != NULL) { + while ((de = readdir(dp))) { + if (strlen(ond) == strlen(de->d_name)) { + Match = TRUE; + for (i = 0; i < (strlen(ond) -3); i++) + if (toupper(ond[i]) != toupper(de->d_name[i])) + Match = FALSE; + if (Match) { + free(ond); + ond = xstrcpy(de->d_name); + break; + } } + } + closedir(dp); } - closedir(dp); if (!Match) { - show_log = TRUE; - free(wrk); - free(onl); - WriteError("Old nodelist not found"); - die(100); + show_log = TRUE; + free(ond); + free(onl); + free(wrk); + WriteError("Could not find extracted file"); + die(MBERR_DIFF_ERROR); } - - /* - * Now try to get the diff file into the workdir. - */ - if ((arc = unpacker(nd)) == NULL) { - show_log = TRUE; - free(onl); - free(wrk); - WriteError("Can't get filetype for %s", nd); - die(100); + } else { + if ((rc = file_cp(nd, ond))) { + show_log = TRUE; + free(ond); + free(onl); + free(wrk); + WriteError("Copy %s failed, %s", nd, strerror(rc)); + die(MBERR_DIFF_ERROR); } + Syslog('s', "Copied %s", nd); + } - ond = xstrcpy(strrchr(nd, '/') + 1); - - if (strncmp(arc, "ASC", 3)) { - if (!getarchiver(arc)) { - show_log = TRUE; - free(onl); - free(wrk); - free(ond); - WriteError("Can't find unarchiver %s", arc); - die(100); - } - - /* - * We may both use the unarchive command for files and mail, - * unarchiving isn't recursive anyway. - */ - if (strlen(archiver.funarc)) - cmd = xstrcpy(archiver.funarc); - else - cmd = xstrcpy(archiver.munarc); - - if ((cmd == NULL) || (cmd == "")) { - show_log = TRUE; - free(cmd); - free(onl); - free(wrk); - free(ond); - WriteError("No unarc command available for %s", arc); - die(100); - } - - if (execute(cmd, nd, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")) { - show_log = TRUE; - free(cmd); - free(onl); - free(wrk); - free(ond); - WriteError("Unpack error"); - die(100); - } - free(cmd); - sync(); - - Match = FALSE; - if ((dp = opendir(wrk)) != NULL) { - while ((de = readdir(dp))) { - if (strlen(ond) == strlen(de->d_name)) { - Match = TRUE; - for (i = 0; i < (strlen(ond) -3); i++) - if (toupper(ond[i]) != toupper(de->d_name[i])) - Match = FALSE; - if (Match) { - free(ond); - ond = xstrcpy(de->d_name); - break; - } - } - } - closedir(dp); - } - if (!Match) { - show_log = TRUE; - free(ond); - free(onl); - free(wrk); - WriteError("Could not find extracted file"); - die(100); - } - } else { - if ((rc = file_cp(nd, ond))) { - show_log = TRUE; - free(ond); - free(onl); - free(wrk); - WriteError("Copy %s failed, %s", nd, strerror(rc)); - die(100); - } - Syslog('s', "Copied %s", nd); - } - - if (((p = strrchr(onl, '.'))) && ((q = strrchr(ond, '.'))) && - (strlen(p) == strlen(q))) { - nn = xstrcpy(onl); - p = strrchr(nn, '.') + 1; - q++; - strcpy(p, q); - } else - nn = xstrcpy((char *)"newnodelist"); - - if (strcmp(onl, nn) == 0) { - show_log = TRUE; - WriteError("Attempt to update nodelist to the same version"); - unlink(ond); - free(ond); - free(onl); - free(wrk); - free(nn); - die(100); - } - - Syslog('+', "Apply %s with %s to %s", onl, ond, nn); - if (!do_quiet) { - colour(3, 0); - printf("Apply %s with %s to %s\n", onl, ond, nn); - } - rc = apply(onl, ond, nn); + if (((p = strrchr(onl, '.'))) && ((q = strrchr(ond, '.'))) && (strlen(p) == strlen(q))) { + nn = xstrcpy(onl); + p = strrchr(nn, '.') + 1; + q++; + strcpy(p, q); + } else + nn = xstrcpy((char *)"newnodelist"); + if (strcmp(onl, nn) == 0) { + show_log = TRUE; + WriteError("Attempt to update nodelist to the same version"); unlink(ond); - if (rc) { - unlink(nn); - free(nn); + free(ond); + free(onl); + free(wrk); + free(nn); + die(MBERR_DIFF_ERROR); + } + + Syslog('+', "Apply %s with %s to %s", onl, ond, nn); + if (!do_quiet) { + colour(3, 0); + printf("Apply %s with %s to %s\n", onl, ond, nn); + } + rc = apply(onl, ond, nn); + + unlink(ond); + if (rc) { + unlink(nn); + free(nn); + free(ond); + free(onl); + free(wrk); + die(MBERR_DIFF_ERROR); + } else { + unlink(onl); + cmd = xstrcpy(archiver.farc); + + if ((cmd == NULL) || (!strlen(cmd))) { + free(cmd); + Syslog('+', "No archive command for %s, fallback to ZIP", arc); + if (!getarchiver((char *)"ZIP")) { + WriteError("No ZIP command available"); free(ond); free(onl); free(wrk); - die(rc + 100); - } else { - unlink(onl); + free(nn); + die(MBERR_DIFF_ERROR); + } else { cmd = xstrcpy(archiver.farc); - - if ((cmd == NULL) || (!strlen(cmd))) { - free(cmd); - Syslog('+', "No archive command for %s, fallback to ZIP", arc); - if (!getarchiver((char *)"ZIP")) { - WriteError("No ZIP command available"); - free(ond); - free(onl); - free(wrk); - free(nn); - die(100); - } else { - cmd = xstrcpy(archiver.farc); - } - } else { - free(cmd); - cmd = xstrcpy(archiver.farc); - } - - if ((cmd == NULL) || (!strlen(cmd))) { - WriteError("No archiver command available"); - } else { - free(onl); - onl = xstrcpy(nn); - onl[strlen(onl) -3] = tolower(archiver.name[0]); - tl(onl); - p = xstrcpy(onl); - p = xstrcat(p, (char *)" "); - p = xstrcat(p, nn); - if (execute(cmd, p, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")) - WriteError("Create %s failed", onl); - else { - CreateSema((char *)"mailin"); - } - sync(); - free(p); - free(cmd); - } - - free(onl); - free(ond); - free(wrk); - free(nn); - die(0); + } + } else { + free(cmd); + cmd = xstrcpy(archiver.farc); } - return 0; + + if ((cmd == NULL) || (!strlen(cmd))) { + WriteError("No archiver command available"); + } else { + free(onl); + onl = xstrcpy(nn); + onl[strlen(onl) -3] = tolower(archiver.name[0]); + tl(onl); + p = xstrcpy(onl); + p = xstrcat(p, (char *)" "); + p = xstrcat(p, nn); + if (execute(cmd, p, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")) + WriteError("Create %s failed", onl); + else { + CreateSema((char *)"mailin"); + } + sync(); + free(p); + free(cmd); + } + + free(onl); + free(ond); + free(wrk); + free(nn); + die(MBERR_OK); + } + return 0; } @@ -455,7 +451,7 @@ void Help(void) printf(" -quiet Quiet mode\n"); colour(7, 0); printf("\n"); - die(99); + die(MBERR_COMMANDLINE); } diff --git a/mbfido/mbfadopt.c b/mbfido/mbfadopt.c index cad8b799..1ba24656 100644 --- a/mbfido/mbfadopt.c +++ b/mbfido/mbfadopt.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbcfg.h" +#include "../lib/mberrors.h" #include "virscan.h" #include "mbfutil.h" #include "mbflist.h" @@ -64,7 +65,7 @@ void AdoptFile(int Area, char *File, char *Description) colour(CYAN, BLACK); if (LoadAreaRec(Area) == FALSE) - die(0); + die(MBERR_INIT_ERROR); if (area.Available) { temp = calloc(PATH_MAX, sizeof(char)); @@ -73,7 +74,7 @@ void AdoptFile(int Area, char *File, char *Description) tmpdir = calloc(PATH_MAX, sizeof(char)); if (CheckFDB(Area, area.Path)) - die(0); + die(MBERR_INIT_ERROR); getcwd(pwd, PATH_MAX); if (!do_quiet) { @@ -92,7 +93,7 @@ void AdoptFile(int Area, char *File, char *Description) WriteError("Can't copy file to %s, %s", temp2, strerror(rc)); if (!do_quiet) printf("Can't copy file to %s, %s\n", temp2, strerror(rc)); - die(0); + die(MBERR_INIT_ERROR); } else { if (do_novir == FALSE) { if (!do_quiet) { @@ -109,7 +110,7 @@ void AdoptFile(int Area, char *File, char *Description) WriteError("Virus found"); if (!do_quiet) printf("Virus found\n"); - die(0); + die(MBERR_VIRUS_FOUND); } } } else { @@ -118,7 +119,7 @@ void AdoptFile(int Area, char *File, char *Description) MustRearc = TRUE; UnPacked = UnpackFile(temp); if (!UnPacked) - die(0); + die(MBERR_INIT_ERROR); if (do_novir == FALSE) { if (!do_quiet) { @@ -136,7 +137,7 @@ void AdoptFile(int Area, char *File, char *Description) WriteError("Virus found"); if (!do_quiet) printf("Virus found\n"); - die(0); + die(MBERR_VIRUS_FOUND); } } @@ -221,7 +222,7 @@ void AdoptFile(int Area, char *File, char *Description) if (!do_quiet) printf("No FILE_ID.DIZ and no description on the commandline\n"); DeleteVirusWork(); - die(0); + die(MBERR_COMMANDLINE); } else { /* * Create description from the commandline. @@ -279,7 +280,7 @@ void AdoptFile(int Area, char *File, char *Description) } if (AddFile(fdb, Area, temp2, File) == FALSE) { - die(0); + die(MBERR_GENERAL); } Syslog('+', "File %s added to area %d", File, Area); diff --git a/mbfido/mbfcheck.c b/mbfido/mbfcheck.c index 93272def..0dcf9d24 100644 --- a/mbfido/mbfcheck.c +++ b/mbfido/mbfcheck.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbcfg.h" +#include "../lib/mberrors.h" #include "mbfutil.h" #include "mbfcheck.h" @@ -64,281 +65,278 @@ extern int do_pack; /* Pack filebase */ */ void Check(void) { - FILE *pAreas, *pFile; - int i, iAreas, iAreasNew = 0, Fix, inArea; - int iTotal = 0, iErrors = 0; - char *sAreas, *fAreas, *newdir, *temp; - DIR *dp; - struct dirent *de; - int Found, Update; - char fn[PATH_MAX]; - struct stat stb; - struct passwd *pw; - struct group *gr; + FILE *pAreas, *pFile; + int i, iAreas, iAreasNew = 0, Fix, inArea, iTotal = 0, iErrors = 0; + char *sAreas, *fAreas, *newdir, *temp; + DIR *dp; + struct dirent *de; + int Found, Update; + char fn[PATH_MAX]; + struct stat stb; + struct passwd *pw; + struct group *gr; - sAreas = calloc(PATH_MAX, sizeof(char)); - fAreas = calloc(PATH_MAX, sizeof(char)); - newdir = calloc(PATH_MAX, sizeof(char)); - temp = calloc(PATH_MAX, sizeof(char)); + sAreas = calloc(PATH_MAX, sizeof(char)); + fAreas = calloc(PATH_MAX, sizeof(char)); + newdir = calloc(PATH_MAX, sizeof(char)); + temp = calloc(PATH_MAX, sizeof(char)); - if (!do_quiet) { - colour(3, 0); - printf("Checking file database...\n"); - } + if (!do_quiet) { + colour(3, 0); + printf("Checking file database...\n"); + } - sprintf(sAreas, "%s/etc/fareas.data", getenv("MBSE_ROOT")); + sprintf(sAreas, "%s/etc/fareas.data", getenv("MBSE_ROOT")); - if ((pAreas = fopen (sAreas, "r")) == NULL) { - WriteError("Can't open %s", sAreas); - die(0); - } + if ((pAreas = fopen (sAreas, "r")) == NULL) { + WriteError("Can't open %s", sAreas); + die(MBERR_INIT_ERROR); + } - fread(&areahdr, sizeof(areahdr), 1, pAreas); - fseek(pAreas, 0, SEEK_END); - iAreas = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize; + fread(&areahdr, sizeof(areahdr), 1, pAreas); + fseek(pAreas, 0, SEEK_END); + iAreas = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize; - for (i = 1; i <= iAreas; i++) { + for (i = 1; i <= iAreas; i++) { - fseek(pAreas, ((i-1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET); - fread(&area, areahdr.recsize, 1, pAreas); + fseek(pAreas, ((i-1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET); + fread(&area, areahdr.recsize, 1, pAreas); - if (area.Available) { + if (area.Available) { - IsDoing("Check area %d", i); + IsDoing("Check area %d", i); - if (!do_quiet) { - printf("\r%4d => %-44s \b\b\b\b", i, area.Name); - fflush(stdout); - } + if (!do_quiet) { + printf("\r%4d => %-44s \b\b\b\b", i, area.Name); + fflush(stdout); + } - /* - * Check if download directory exists, - * if not, create the directory. - */ - if (access(area.Path, R_OK) == -1) { - Syslog('!', "No dir: %s", area.Path); - sprintf(newdir, "%s/foobar", area.Path); - mkdirs(newdir, 0775); - } + /* + * Check if download directory exists, + * if not, create the directory. + */ + if (access(area.Path, R_OK) == -1) { + Syslog('!', "No dir: %s", area.Path); + sprintf(newdir, "%s/foobar", area.Path); + mkdirs(newdir, 0775); + } - if (stat(area.Path, &stb) == 0) { - /* - * Very extended directory check - */ - Fix = FALSE; - if ((stb.st_mode & S_IRUSR) == 0) { - Fix = TRUE; - WriteError("No owner read access in %s, mode is %04o", area.Path, stb.st_mode & 0x1ff); - } - if ((stb.st_mode & S_IWUSR) == 0) { - Fix = TRUE; - WriteError("No owner write access in %s, mode is %04o", area.Path, stb.st_mode & 0x1ff); - } - if ((stb.st_mode & S_IRGRP) == 0) { - Fix = TRUE; - WriteError("No group read access in %s, mode is %04o", area.Path, stb.st_mode & 0x1ff); - } - if ((stb.st_mode & S_IWGRP) == 0) { - Fix = TRUE; - WriteError("No group write access in %s, mode is %04o", area.Path, stb.st_mode & 0x1ff); - } - if ((stb.st_mode & S_IROTH) == 0) { - Fix = TRUE; - WriteError("No others read access in %s, mode is %04o", area.Path, stb.st_mode & 0x1ff); - } - if (Fix) { - iErrors++; - if (chmod(area.Path, 0775)) - WriteError("Could not set mode to 0775"); - else - Syslog('+', "Corrected directory mode to 0775"); - } - Fix = FALSE; - pw = getpwuid(stb.st_uid); - if (strcmp(pw->pw_name, (char *)"mbse")) { - WriteError("Directory %s not owned by user mbse", area.Path); - Fix = TRUE; - } - gr = getgrgid(stb.st_gid); - if (strcmp(gr->gr_name, (char *)"bbs")) { - WriteError("Directory %s not owned by group bbs", area.Path); - Fix = TRUE; - } - if (Fix) { - iErrors++; - pw = getpwnam((char *)"mbse"); - gr = getgrnam((char *)"bbs"); - if (chown(area.Path, pw->pw_gid, gr->gr_gid)) - WriteError("Could not set owner to mbse.bbs"); - else - Syslog('+', "Corrected directory owner to mbse.bbs"); - } - } else { - WriteError("Can't stat %s", area.Path); - } + if (stat(area.Path, &stb) == 0) { + /* + * Very extended directory check + */ + Fix = FALSE; + if ((stb.st_mode & S_IRUSR) == 0) { + Fix = TRUE; + WriteError("No owner read access in %s, mode is %04o", area.Path, stb.st_mode & 0x1ff); + } + if ((stb.st_mode & S_IWUSR) == 0) { + Fix = TRUE; + WriteError("No owner write access in %s, mode is %04o", area.Path, stb.st_mode & 0x1ff); + } + if ((stb.st_mode & S_IRGRP) == 0) { + Fix = TRUE; + WriteError("No group read access in %s, mode is %04o", area.Path, stb.st_mode & 0x1ff); + } + if ((stb.st_mode & S_IWGRP) == 0) { + Fix = TRUE; + WriteError("No group write access in %s, mode is %04o", area.Path, stb.st_mode & 0x1ff); + } + if ((stb.st_mode & S_IROTH) == 0) { + Fix = TRUE; + WriteError("No others read access in %s, mode is %04o", area.Path, stb.st_mode & 0x1ff); + } + if (Fix) { + iErrors++; + if (chmod(area.Path, 0775)) + WriteError("Could not set mode to 0775"); + else + Syslog('+', "Corrected directory mode to 0775"); + } + Fix = FALSE; + pw = getpwuid(stb.st_uid); + if (strcmp(pw->pw_name, (char *)"mbse")) { + WriteError("Directory %s not owned by user mbse", area.Path); + Fix = TRUE; + } + gr = getgrgid(stb.st_gid); + if (strcmp(gr->gr_name, (char *)"bbs")) { + WriteError("Directory %s not owned by group bbs", area.Path); + Fix = TRUE; + } + if (Fix) { + iErrors++; + pw = getpwnam((char *)"mbse"); + gr = getgrnam((char *)"bbs"); + if (chown(area.Path, pw->pw_gid, gr->gr_gid)) + WriteError("Could not set owner to mbse.bbs"); + else + Syslog('+', "Corrected directory owner to mbse.bbs"); + } + } else { + WriteError("Can't stat %s", area.Path); + } - sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), i); + sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), i); - /* - * Open the file database, if it doesn't exist, - * create an empty one. - */ - if ((pFile = fopen(fAreas, "r+")) == NULL) { - Syslog('!', "Creating new %s", fAreas); - if ((pFile = fopen(fAreas, "a+")) == NULL) { - WriteError("$Can't create %s", fAreas); - die(0); - } - } + /* + * Open the file database, if it doesn't exist, + * create an empty one. + */ + if ((pFile = fopen(fAreas, "r+")) == NULL) { + Syslog('!', "Creating new %s", fAreas); + if ((pFile = fopen(fAreas, "a+")) == NULL) { + WriteError("$Can't create %s", fAreas); + die(MBERR_GENERAL); + } + } - /* - * Now start checking the files in the filedatabase - * against the contents of the directory. - */ - inArea = 0; - while (fread(&file, sizeof(file), 1, pFile) == 1) { + /* + * Now start checking the files in the filedatabase + * against the contents of the directory. + */ + inArea = 0; + while (fread(&file, sizeof(file), 1, pFile) == 1) { - iTotal++; - inArea++; - sprintf(newdir, "%s/%s", area.Path, file.LName); + iTotal++; + inArea++; + sprintf(newdir, "%s/%s", area.Path, file.LName); - if (file_exist(newdir, R_OK)) { - Syslog('+', "File %s area %d not on disk.", newdir, i); - if (!file.NoKill) { - file.Deleted = TRUE; - do_pack = TRUE; - } + if (file_exist(newdir, R_OK)) { + Syslog('+', "File %s area %d not on disk.", newdir, i); + if (!file.NoKill) { + file.Deleted = TRUE; + do_pack = TRUE; + } + iErrors++; + file.Missing = TRUE; + fseek(pFile, - sizeof(file), SEEK_CUR); + fwrite(&file, sizeof(file), 1, pFile); + } else { + /* + * File exists, now check the file. + */ + Marker(); + Update = FALSE; + + strcpy(temp, file.LName); + name_mangle(temp); + if (strcmp(file.Name, temp)) { + Syslog('!', "Converted %s to %s", file.Name, temp); + strncpy(file.Name, temp, 12); + iErrors++; + Update = TRUE; + } + if (file_time(newdir) != file.FileDate) { + Syslog('!', "Date mismatch area %d file %s", i, file.LName); + file.FileDate = file_time(newdir); + iErrors++; + Update = TRUE; + } + if (file_size(newdir) != file.Size) { + Syslog('!', "Size mismatch area %d file %s", i, file.LName); + file.Size = file_size(newdir); + iErrors++; + Update = TRUE; + } + if (file_crc(newdir, CFG.slow_util && do_quiet) != file.Crc32) { + Syslog('!', "CRC error area %d, file %s", i, file.LName); + file.Crc32 = file_crc(newdir, CFG.slow_util && do_quiet); + iErrors++; + Update = TRUE; + } + Marker(); + if (Update) { + fseek(pFile, - sizeof(file), SEEK_CUR); + fwrite(&file, sizeof(file), 1, pFile); + } + } + } + if (inArea == 0) + Syslog('+', "Warning: area %d (%s) is empty", i, area.Name); + + /* + * Check files in the directory against the database. + * This test is skipped for CD-rom. + */ + if (!area.CDrom) { + if ((dp = opendir(area.Path)) != NULL) { + while ((de = readdir(dp)) != NULL) { + if (de->d_name[0] != '.') { + Marker(); + Found = FALSE; + rewind(pFile); + while (fread(&file, sizeof(file), 1, pFile) == 1) { + if (strcmp(file.LName, de->d_name) == 0) { + if (!Found) { + Found = TRUE; + } else { + /* + * Record has been found before, so this must be + * a double record. + */ + Syslog('!', "Double file record area %d file %s", i, file.LName); iErrors++; - file.Missing = TRUE; + file.Double = TRUE; + do_pack = TRUE; fseek(pFile, - sizeof(file), SEEK_CUR); fwrite(&file, sizeof(file), 1, pFile); - } else { - /* - * File exists, now check the file. - */ - Marker(); - Update = FALSE; - - strcpy(temp, file.LName); - name_mangle(temp); - if (strcmp(file.Name, temp)) { - Syslog('!', "Converted %s to %s", file.Name, temp); - strncpy(file.Name, temp, 12); - iErrors++; - Update = TRUE; - } - if (file_time(newdir) != file.FileDate) { - Syslog('!', "Date mismatch area %d file %s", i, file.LName); - file.FileDate = file_time(newdir); - iErrors++; - Update = TRUE; - } - if (file_size(newdir) != file.Size) { - Syslog('!', "Size mismatch area %d file %s", i, file.LName); - file.Size = file_size(newdir); - iErrors++; - Update = TRUE; - } - if (file_crc(newdir, CFG.slow_util && do_quiet) != file.Crc32) { - Syslog('!', "CRC error area %d, file %s", i, file.LName); - file.Crc32 = file_crc(newdir, CFG.slow_util && do_quiet); - iErrors++; - Update = TRUE; - } - Marker(); - if (Update) { - fseek(pFile, - sizeof(file), SEEK_CUR); - fwrite(&file, sizeof(file), 1, pFile); - } + } } - } - if (inArea == 0) - Syslog('+', "Warning: area %d (%s) is empty", i, area.Name); - - /* - * Check files in the directory against the database. - * This test is skipped for CD-rom. - */ - if (!area.CDrom) { - if ((dp = opendir(area.Path)) != NULL) { - while ((de = readdir(dp)) != NULL) { - if (de->d_name[0] != '.') { - Marker(); - Found = FALSE; - rewind(pFile); - while (fread(&file, sizeof(file), 1, pFile) == 1) { - if (strcmp(file.LName, de->d_name) == 0) { - if (!Found) { - Found = TRUE; - } else { - /* - * Record has been found before, so this must be - * a double record. - */ - Syslog('!', "Double file record area %d file %s", - i, file.LName); - iErrors++; - file.Double = TRUE; - do_pack = TRUE; - fseek(pFile, - sizeof(file), SEEK_CUR); - fwrite(&file, sizeof(file), 1, pFile); - } - } - } - if ((!Found) && - (strncmp(de->d_name, "files.bbs", 9)) && - (strncmp(de->d_name, "files.bak", 9)) && - (strncmp(de->d_name, "00index", 7)) && - (strncmp(de->d_name, "header", 6)) && - (strncmp(de->d_name, "index", 5)) && - (strncmp(de->d_name, "readme", 6))) { - sprintf(fn, "%s/%s", area.Path, de->d_name); - if (stat(fn, &stb) == 0) - if (S_ISREG(stb.st_mode)) { - if (unlink(fn) == 0) { - Syslog('!', "%s not in fdb, deleted from disk", fn); - iErrors++; - } else { - WriteError("$%s not in fdb, cannot delete", fn); - } - } - } - } + } + if ((!Found) && (strncmp(de->d_name, "files.bbs", 9)) && + (strncmp(de->d_name, "files.bak", 9)) && + (strncmp(de->d_name, "00index", 7)) && + (strncmp(de->d_name, "header", 6)) && + (strncmp(de->d_name, "index", 5)) && + (strncmp(de->d_name, "readme", 6))) { + sprintf(fn, "%s/%s", area.Path, de->d_name); + if (stat(fn, &stb) == 0) + if (S_ISREG(stb.st_mode)) { + if (unlink(fn) == 0) { + Syslog('!', "%s not in fdb, deleted from disk", fn); + iErrors++; + } else { + WriteError("$%s not in fdb, cannot delete", fn); } - closedir(dp); - } else { - WriteError("Can't open %s", area.Path); - } - } - - fclose(pFile); - chmod(fAreas, 0660); - iAreasNew++; - - } else { - - if (strlen(area.Name) == 0) { - sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), i); - if (unlink(fAreas) == 0) { - Syslog('+', "Removed obsolete %s", fAreas); + } + } } } + closedir(dp); + } else { + WriteError("Can't open %s", area.Path); + } + } - } /* if area.Available */ - } + fclose(pFile); + chmod(fAreas, 0660); + iAreasNew++; - fclose(pAreas); - if (!do_quiet) { - printf("\r \r"); - fflush(stdout); - } + } else { + + if (strlen(area.Name) == 0) { + sprintf(fAreas, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), i); + if (unlink(fAreas) == 0) { + Syslog('+', "Removed obsolete %s", fAreas); + } + } - free(temp); - free(newdir); - free(sAreas); - free(fAreas); + } /* if area.Available */ + } - Syslog('+', "Check Areas [%5d] Files [%5d] Errors [%5d]", iAreasNew, iTotal, iErrors); + fclose(pAreas); + if (!do_quiet) { + printf("\r \r"); + fflush(stdout); + } + + free(temp); + free(newdir); + free(sAreas); + free(fAreas); + + Syslog('+', "Check Areas [%5d] Files [%5d] Errors [%5d]", iAreasNew, iTotal, iErrors); } diff --git a/mbfido/mbfdel.c b/mbfido/mbfdel.c index c1f42d98..816b0333 100644 --- a/mbfido/mbfdel.c +++ b/mbfido/mbfdel.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbcfg.h" +#include "../lib/mberrors.h" #include "mbfutil.h" #include "mbfmove.h" @@ -67,28 +68,28 @@ void Delete(int UnDel, int Area, char *File) */ if (LoadAreaRec(Area) == FALSE) { WriteError("Can't load record %d", Area); - die(0); + die(MBERR_INIT_ERROR); } if (!area.Available) { WriteError("Area %d not available", Area); if (!do_quiet) printf("Area %d not available\n", Area); - die(0); + die(MBERR_CONFIG_ERROR); } if (area.CDrom) { WriteError("Can't %sdelete from CD-ROM", UnDel?"un":""); if (!do_quiet) printf("Can't %sdelete from CD-ROM\n", UnDel?"un":""); - die(0); + die(MBERR_COMMANDLINE); } if (CheckFDB(Area, area.Path)) - die(0); + die(MBERR_GENERAL); temp = calloc(PATH_MAX, sizeof(char)); sprintf(temp, "%s/fdb/fdb%d.data", getenv("MBSE_ROOT"), Area); if ((fp = fopen(temp, "r+")) == NULL) - die(0); + die(MBERR_GENERAL); colour(CYAN, BLACK); diff --git a/mbfido/mbfido.c b/mbfido/mbfido.c index 9a7eb406..64b96b15 100644 --- a/mbfido/mbfido.c +++ b/mbfido/mbfido.c @@ -45,6 +45,7 @@ #include "../lib/dbftn.h" #include "../lib/dbtic.h" #include "../lib/msg.h" +#include "../lib/mberrors.h" #include "flock.h" #include "tosspkt.h" #include "unpack.h" @@ -147,7 +148,7 @@ void Help(void) printf(" -uns -unsecure Toss unsecure\n"); printf(" -unp -unprotect Toss unprotected inbound\n"); colour(LIGHTGRAY, BLACK); - ExitClient(0); + ExitClient(MBERR_COMMANDLINE); } @@ -189,7 +190,7 @@ void die(int onsig) system("stty sane"); } - if (onsig != 110) + if (onsig != MBERR_NO_PROGLOCK) CloseDupes(); /* @@ -244,7 +245,7 @@ void die(int onsig) * and there should be no lock. We prevent removing the lock of another * mbfido this way. */ - if (onsig != 110) { + if (onsig != MBERR_NO_PROGLOCK) { ulockdir(CFG.inbound); ulockdir(CFG.pinbound); ulockdir(CFG.out_queue); @@ -433,10 +434,10 @@ int main(int argc, char **argv) free(cmd); /* - * Not yet locked, if anything goes wrong, exit with die(110) + * Not yet locked, if anything goes wrong, exit with die(MBERR_NO_PROGLOCK) */ if (!diskfree(CFG.freespace)) - die(110); + die(MBERR_DISK_FULL); if (do_mail) { /* @@ -458,7 +459,7 @@ int main(int argc, char **argv) i--; if (! i) { WriteError("Lock timeout, aborting"); - die(110); + die(MBERR_NO_PROGLOCK); } sleep(20); Nopper(); @@ -470,10 +471,10 @@ int main(int argc, char **argv) */ if (do_unprot) { if (! lockdir(CFG.inbound)) - die(110); + die(MBERR_NO_PROGLOCK); } else { if (! lockdir(CFG.pinbound)) - die(110); + die(MBERR_NO_PROGLOCK); } } @@ -482,7 +483,7 @@ int main(int argc, char **argv) */ if (initnl()) - die(101); + die(MBERR_INIT_ERROR); if (!do_mail && !do_uucp) Rollover(); if (!do_quiet) @@ -500,13 +501,13 @@ int main(int argc, char **argv) if (do_mail) { if (!envrecip_count) { WriteError("No valid receipients specified, aborting"); - die(105); + die(MBERR_NO_RECIPIENTS); } umask(066); if ((ofp = tmpfile()) == NULL) { WriteError("$Can't open tmpfile for RFC message"); - die(104); + die(MBERR_INIT_ERROR); } temp = calloc(10240, sizeof(char)); while (fgets(temp, 10240, stdin)) @@ -520,7 +521,7 @@ int main(int argc, char **argv) fclose(ofp); flush_queue(); - die(0); + die(MBERR_OK); } InitDupes(); @@ -540,7 +541,7 @@ int main(int argc, char **argv) do { Hatch(); switch (Tic()) { - case -1: die(0); + case -1: die(MBERR_OK); break; case 0: Loop = FALSE; break; @@ -559,7 +560,7 @@ int main(int argc, char **argv) if (IsSema((char *)"mailin")) RemoveSema((char *)"mailin"); if (TossMail() == FALSE) - die(0); + die(MBERR_OK); } if (do_tic || do_toss) { /* @@ -586,7 +587,7 @@ int main(int argc, char **argv) if (do_flush) flush_queue(); - die(0); + die(MBERR_OK); return 0; } @@ -613,7 +614,7 @@ int TossMail(void) if (chdir(inbound) == -1) { WriteError("$Can't chdir(%s)", inbound); - die(0); + die(MBERR_INIT_ERROR); } /* @@ -629,7 +630,7 @@ int TossMail(void) */ if ((dp = opendir(inbound)) == NULL) { WriteError("$Can't opendir(%s)", inbound); - die(0); + die(MBERR_INIT_ERROR); } Syslog('+', "Pass: toss ARCmail (%s)", inbound); @@ -662,7 +663,7 @@ int TossMail(void) break; } if (!diskfree(CFG.freespace)) { - rc = 101; + rc = MBERR_DISK_FULL; break; } diff --git a/mbfido/mbfile.c b/mbfido/mbfile.c index d86fc9bc..f7e64e5c 100644 --- a/mbfido/mbfile.c +++ b/mbfido/mbfile.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbcfg.h" +#include "../lib/mberrors.h" #include "mbfkill.h" #include "mbfadopt.h" #include "mbfindex.h" @@ -74,191 +75,190 @@ time_t t_end; /* End time */ int main(int argc, char **argv) { - int i, Area = 0, ToArea = 0, UnDel = FALSE; - char *cmd, *FileName = NULL, *Description = NULL; - struct passwd *pw; + int i, Area = 0, ToArea = 0, UnDel = FALSE; + char *cmd, *FileName = NULL, *Description = NULL; + struct passwd *pw; #ifdef MEMWATCH - mwInit(); + mwInit(); #endif - InitConfig(); - TermInit(1); - t_start = time(NULL); - umask(002); + InitConfig(); + 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 == SIGBUS) || (i == SIGKILL) || - (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM)) - signal(i, (void (*))die); - else - signal(i, SIG_IGN); - } + /* + * Catch all signals we can, and ignore the rest. + */ + for (i = 0; i < NSIG; i++) { + if ((i == SIGHUP) || (i == SIGBUS) || (i == SIGKILL) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM)) + signal(i, (void (*))die); + else + signal(i, SIG_IGN); + } - if(argc < 2) - Help(); + if(argc < 2) + Help(); - cmd = xstrcpy((char *)"Command line: mbfile"); + cmd = xstrcpy((char *)"Command line: mbfile"); - for (i = 1; i < argc; i++) { + for (i = 1; i < argc; i++) { + cmd = xstrcat(cmd, (char *)" "); + cmd = xstrcat(cmd, argv[i]); + + if (!strncasecmp(argv[i], "a", 1)) { + do_adopt = TRUE; + i++; + Area = atoi(argv[i]); + cmd = xstrcat(cmd, (char *)" "); + cmd = xstrcat(cmd, argv[i]); + i++; + FileName = xstrcpy(argv[i]); + cmd = xstrcat(cmd, (char *)" "); + cmd = xstrcat(cmd, argv[i]); + if (argc > (i + 1)) { + i++; cmd = xstrcat(cmd, (char *)" "); cmd = xstrcat(cmd, argv[i]); - - if (!strncasecmp(argv[i], "a", 1)) { - do_adopt = TRUE; - i++; - Area = atoi(argv[i]); - cmd = xstrcat(cmd, (char *)" "); - cmd = xstrcat(cmd, argv[i]); + if (!strncasecmp(argv[i], "-a", 2)) { + do_annon = TRUE; + } else { + Description = xstrcpy(argv[i]); + } + } + } else if ((!strncasecmp(argv[i], "d", 1)) || (!strncasecmp(argv[i], "u", 1))) { + if (!strncasecmp(argv[i], "u", 1)) + UnDel = TRUE; + if (argc > (i + 1)) { + i++; + Area = atoi(argv[i]); + cmd = xstrcat(cmd, (char *)" "); + cmd = xstrcat(cmd, argv[i]); + if (argc > (i + 1)) { + i++; + FileName = xstrcpy(argv[i]); + cmd = xstrcat(cmd, (char *)" "); + cmd = xstrcat(cmd, argv[i]); + do_del = TRUE; + } + } + } else if (!strncasecmp(argv[i], "in", 2)) { + do_index = TRUE; + } else if (!strncasecmp(argv[i], "im", 2)) { + if (argc > (i + 1)) { + do_import = TRUE; + i++; + Area = atoi(argv[i]); + cmd = xstrcat(cmd, (char *)" "); + cmd = xstrcat(cmd, argv[i]); + } + } else if (!strncasecmp(argv[i], "l", 1)) { + do_list = TRUE; + if (argc > (i + 1)) { + i++; + Area = atoi(argv[i]); + cmd = xstrcat(cmd, (char *)" "); + cmd = xstrcat(cmd, argv[i]); + } + } else if (!strncasecmp(argv[i], "m", 1)) { + if (argc > (i + 1)) { + i++; + Area = atoi(argv[i]); + cmd = xstrcat(cmd, (char *)" "); + cmd = xstrcat(cmd, argv[i]); + if (argc > (i + 1)) { + i++; + ToArea = atoi(argv[i]); + cmd = xstrcat(cmd, (char *)" "); + cmd = xstrcat(cmd, argv[i]); + if (argc > (i + 1)) { i++; FileName = xstrcpy(argv[i]); cmd = xstrcat(cmd, (char *)" "); cmd = xstrcat(cmd, argv[i]); - if (argc > (i + 1)) { - i++; - cmd = xstrcat(cmd, (char *)" "); - cmd = xstrcat(cmd, argv[i]); - if (!strncasecmp(argv[i], "-a", 2)) { - do_annon = TRUE; - } else { - Description = xstrcpy(argv[i]); - } - } - } else if ((!strncasecmp(argv[i], "d", 1)) || (!strncasecmp(argv[i], "u", 1))) { - if (!strncasecmp(argv[i], "u", 1)) - UnDel = TRUE; - if (argc > (i + 1)) { - i++; - Area = atoi(argv[i]); - cmd = xstrcat(cmd, (char *)" "); - cmd = xstrcat(cmd, argv[i]); - if (argc > (i + 1)) { - i++; - FileName = xstrcpy(argv[i]); - cmd = xstrcat(cmd, (char *)" "); - cmd = xstrcat(cmd, argv[i]); - do_del = TRUE; - } + do_move = TRUE; } - } else if (!strncasecmp(argv[i], "in", 2)) { - do_index = TRUE; - } else if (!strncasecmp(argv[i], "im", 2)) { - if (argc > (i + 1)) { - do_import = TRUE; - i++; - Area = atoi(argv[i]); - cmd = xstrcat(cmd, (char *)" "); - cmd = xstrcat(cmd, argv[i]); - } - } else if (!strncasecmp(argv[i], "l", 1)) { - do_list = TRUE; - if (argc > (i + 1)) { - i++; - Area = atoi(argv[i]); - cmd = xstrcat(cmd, (char *)" "); - cmd = xstrcat(cmd, argv[i]); - } - } else if (!strncasecmp(argv[i], "m", 1)) { - if (argc > (i + 1)) { - i++; - Area = atoi(argv[i]); - cmd = xstrcat(cmd, (char *)" "); - cmd = xstrcat(cmd, argv[i]); - if (argc > (i + 1)) { - i++; - ToArea = atoi(argv[i]); - cmd = xstrcat(cmd, (char *)" "); - cmd = xstrcat(cmd, argv[i]); - if (argc > (i + 1)) { - i++; - FileName = xstrcpy(argv[i]); - cmd = xstrcat(cmd, (char *)" "); - cmd = xstrcat(cmd, argv[i]); - do_move = TRUE; - } - } - } - } else if (!strncasecmp(argv[i], "p", 1)) { - do_pack = TRUE; - } else if (!strncasecmp(argv[i], "c", 1)) { - do_check = TRUE; - } else if (!strncasecmp(argv[i], "k", 1)) { - do_kill = TRUE; - } else if (!strncasecmp(argv[i], "t", 1)) { - do_tobe = TRUE; - } else if (!strncasecmp(argv[i], "-q", 2)) { - do_quiet = TRUE; - } else if (!strncasecmp(argv[i], "-a", 2)) { - do_annon = TRUE; - } else if (!strncasecmp(argv[i], "-v", 2)) { - do_novir = TRUE; } + } + } else if (!strncasecmp(argv[i], "p", 1)) { + do_pack = TRUE; + } else if (!strncasecmp(argv[i], "c", 1)) { + do_check = TRUE; + } else if (!strncasecmp(argv[i], "k", 1)) { + do_kill = TRUE; + } else if (!strncasecmp(argv[i], "t", 1)) { + do_tobe = TRUE; + } else if (!strncasecmp(argv[i], "-q", 2)) { + do_quiet = TRUE; + } else if (!strncasecmp(argv[i], "-a", 2)) { + do_annon = TRUE; + } else if (!strncasecmp(argv[i], "-v", 2)) { + do_novir = TRUE; } + } - if (!(do_pack || do_check || do_kill || do_index || do_import || do_list || do_adopt || do_del || do_move || do_tobe)) - Help(); + if (!(do_pack || do_check || do_kill || do_index || do_import || do_list || do_adopt || do_del || do_move || do_tobe)) + Help(); - ProgName(); - pw = getpwuid(getuid()); - InitClient(pw->pw_name, (char *)"mbfile", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog); + ProgName(); + pw = getpwuid(getuid()); + InitClient(pw->pw_name, (char *)"mbfile", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog); - Syslog(' ', " "); - Syslog(' ', "MBFILE v%s", VERSION); - Syslog(' ', cmd); - if (do_novir) - Syslog('!', "WARNING: running without virus checking"); - free(cmd); + Syslog(' ', " "); + Syslog(' ', "MBFILE v%s", VERSION); + Syslog(' ', cmd); + if (do_novir) + Syslog('!', "WARNING: running without virus checking"); + free(cmd); - if (!do_quiet) - printf("\n"); + if (!do_quiet) + printf("\n"); - if (!diskfree(CFG.freespace)) - die(101); + if (!diskfree(CFG.freespace)) + die(MBERR_DISK_FULL); - if (do_adopt) { - AdoptFile(Area, FileName, Description); - die(0); - } + if (do_adopt) { + AdoptFile(Area, FileName, Description); + die(MBERR_OK); + } - if (do_import) { - ImportFiles(Area); - die(0); - } + if (do_import) { + ImportFiles(Area); + die(MBERR_OK); + } - if (do_kill) - Kill(); + if (do_kill) + Kill(); - if (do_check) - Check(); + if (do_check) + Check(); - if (do_pack) - PackFileBase(); + if (do_pack) + PackFileBase(); - if (do_index) - Index(); + if (do_index) + Index(); - if (do_move) { - Move(Area, ToArea, FileName); - die(0); - } + if (do_move) { + Move(Area, ToArea, FileName); + die(MBERR_OK); + } - if (do_del) { - Delete(UnDel, Area, FileName); - die(0); - } + if (do_del) { + Delete(UnDel, Area, FileName); + die(MBERR_OK); + } - if (do_list) { - ListFileAreas(Area); - die(0); - } + if (do_list) { + ListFileAreas(Area); + die(MBERR_OK); + } - if (do_tobe) - ToBeRep(); - die(0); - return 0; + if (do_tobe) + ToBeRep(); + die(MBERR_OK); + return 0; } diff --git a/mbfido/mbfimport.c b/mbfido/mbfimport.c index ea330ab5..97e4fc63 100644 --- a/mbfido/mbfimport.c +++ b/mbfido/mbfimport.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbcfg.h" +#include "../lib/mberrors.h" #include "virscan.h" #include "mbfutil.h" #include "mbfimport.h" @@ -63,7 +64,7 @@ void ImportFiles(int Area) colour(CYAN, BLACK); if (LoadAreaRec(Area) == FALSE) - die(0); + die(MBERR_INIT_ERROR); if (area.Available && !area.CDrom) { temp = calloc(PATH_MAX, sizeof(char)); @@ -75,7 +76,7 @@ void ImportFiles(int Area) getcwd(pwd, PATH_MAX); if (CheckFDB(Area, area.Path)) - die(0); + die(MBERR_GENERAL); sprintf(tmpdir, "%s/tmp/arc", getenv("MBSE_ROOT")); IsDoing("Import files"); @@ -92,7 +93,7 @@ void ImportFiles(int Area) WriteError("Can't find files.bbs anywhere"); if (!do_quiet) printf("Can't find files.bbs anywhere\n"); - die(0); + die(MBERR_INIT_ERROR); } } } @@ -165,7 +166,7 @@ void ImportFiles(int Area) * Check diskspace */ if (!diskfree(CFG.freespace)) - die(101); + die(MBERR_DISK_FULL); Files++; memset(&fdb, 0, sizeof(fdb)); diff --git a/mbfido/mbfindex.c b/mbfido/mbfindex.c index a07669d0..a698a349 100644 --- a/mbfido/mbfindex.c +++ b/mbfido/mbfindex.c @@ -38,6 +38,7 @@ #include "../lib/clcomm.h" #include "../lib/dbcfg.h" #include "../lib/diesel.h" +#include "../lib/mberrors.h" #include "mbfutil.h" #include "mbfindex.h" @@ -364,13 +365,13 @@ void Index(void) sprintf(sAreas, "%s/etc/fareas.data", getenv("MBSE_ROOT")); if ((pAreas = fopen (sAreas, "r")) == NULL) { WriteError("$Can't open %s", sAreas); - die(0); + die(MBERR_INIT_ERROR); } sprintf(sIndex, "%s/etc/request.index", getenv("MBSE_ROOT")); if ((pIndex = fopen(sIndex, "w")) == NULL) { WriteError("$Can't create %s", sIndex); - die(0); + die(MBERR_GENERAL); } fread(&areahdr, sizeof(areahdr), 1, pAreas); @@ -422,7 +423,7 @@ void Index(void) if (area.Available) { if (!diskfree(CFG.freespace)) - die(101); + die(MBERR_DISK_FULL); if (!do_quiet) { printf("\r%4ld => %-44s \b\b\b\b", i, area.Name); @@ -452,7 +453,7 @@ void Index(void) Syslog('!', "Creating new %s", fAreas); if ((pFile = fopen(fAreas, "a+")) == NULL) { WriteError("$Can't create %s", fAreas); - die(0); + die(MBERR_GENERAL); } } diff --git a/mbfido/mbfkill.c b/mbfido/mbfkill.c index a933460f..f80de850 100644 --- a/mbfido/mbfkill.c +++ b/mbfido/mbfkill.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbcfg.h" +#include "../lib/mberrors.h" #include "mbfkill.h" #include "mbfutil.h" @@ -79,7 +80,7 @@ void Kill(void) if ((pAreas = fopen (sAreas, "r")) == NULL) { WriteError("Can't open %s", sAreas); - die(0); + die(MBERR_INIT_ERROR); } fread(&areahdr, sizeof(areahdr), 1, pAreas); @@ -95,7 +96,7 @@ void Kill(void) if ((area.Available) && (area.DLdays || area.FDdays) && (!area.CDrom)) { if (!diskfree(CFG.freespace)) - die(101); + die(MBERR_DISK_FULL); if (!do_quiet) { printf("\r%4d => %-44s \b\b\b\b", i, area.Name); @@ -125,7 +126,7 @@ void Kill(void) Syslog('!', "Creating new %s", fAreas); if ((pFile = fopen(fAreas, "a+")) == NULL) { WriteError("$Can't create %s", fAreas); - die(0); + die(MBERR_GENERAL); } } diff --git a/mbfido/mbflist.c b/mbfido/mbflist.c index 41bfc551..e35911ef 100644 --- a/mbfido/mbflist.c +++ b/mbfido/mbflist.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbcfg.h" +#include "../lib/mberrors.h" #include "mbfutil.h" #include "mbflist.h" @@ -69,7 +70,7 @@ void ListFileAreas(int Area) if ((pAreas = fopen (sAreas, "r")) == NULL) { WriteError("Can't open %s", sAreas); printf("Can't open %s\n", sAreas); - die(0); + die(MBERR_INIT_ERROR); } fread(&areahdr, sizeof(areahdr), 1, pAreas); @@ -83,7 +84,7 @@ void ListFileAreas(int Area) if ((pTic = fopen(sTic, "r")) == NULL) { WriteError("Can't open %s", sTic); printf("Can't open %s\n", sTic); - die(0); + die(MBERR_GENERAL); } fread(&tichdr, sizeof(tichdr), 1, pTic); @@ -108,7 +109,7 @@ void ListFileAreas(int Area) Syslog('!', "Creating new %s", fAreas); if ((pFile = fopen(fAreas, "a+")) == NULL) { WriteError("$Can't create %s", fAreas); - die(0); + die(MBERR_GENERAL); } } @@ -204,7 +205,7 @@ void ListFileAreas(int Area) Syslog('!', "Creating new %s", fAreas); if ((pFile = fopen(fAreas, "a+")) == NULL) { WriteError("$Can't create %s", fAreas); - die(0); + die(MBERR_GENERAL); } } diff --git a/mbfido/mbfmove.c b/mbfido/mbfmove.c index dcfcbe51..92993f50 100644 --- a/mbfido/mbfmove.c +++ b/mbfido/mbfmove.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbcfg.h" +#include "../lib/mberrors.h" #include "mbfutil.h" #include "mbfmove.h" @@ -63,7 +64,7 @@ void Move(int From, int To, char *File) WriteError("Area numbers are the same"); if (!do_quiet) printf("Can't move to the same area\n"); - die(0); + die(MBERR_COMMANDLINE); } /* @@ -71,22 +72,22 @@ void Move(int From, int To, char *File) */ if (LoadAreaRec(From) == FALSE) { WriteError("Can't load record %d", From); - die(0); + die(MBERR_INIT_ERROR); } if (!area.Available) { WriteError("Area %d not available", From); if (!do_quiet) printf("Area %d not available\n", From); - die(0); + die(MBERR_COMMANDLINE); } if (area.CDrom) { WriteError("Can't move from CD-ROM"); if (!do_quiet) printf("Can't move from CD-ROM\n"); - die(0); + die(MBERR_COMMANDLINE); } if (CheckFDB(From, area.Path)) - die(0); + die(MBERR_GENERAL); frompath = xstrcpy(area.Path); frompath = xstrcat(frompath, (char *)"/"); frompath = xstrcat(frompath, File); @@ -96,22 +97,22 @@ void Move(int From, int To, char *File) */ if (LoadAreaRec(To) == FALSE) { WriteError("Can't load record %d", To); - die(0); + die(MBERR_GENERAL); } if (!area.Available) { WriteError("Area %d not available", To); if (!do_quiet) printf("Area %d not available\n", To); - die(0); + die(MBERR_GENERAL); } if (area.CDrom) { WriteError("Can't move to CD-ROM"); if (!do_quiet) printf("Can't move to CD-ROM\n"); - die(0); + die(MBERR_COMMANDLINE); } if (CheckFDB(To, area.Path)) - die(0); + die(MBERR_GENERAL); topath = xstrcpy(area.Path); topath = xstrcat(topath, (char *)"/"); topath = xstrcat(topath, File); @@ -122,9 +123,9 @@ void Move(int From, int To, char *File) sprintf(temp2, "%s/fdb/fdb%d.temp", getenv("MBSE_ROOT"), From); if ((fp1 = fopen(temp1, "r")) == NULL) - die(0); + die(MBERR_GENERAL); if ((fp2 = fopen(temp2, "a+")) == NULL) - die(0); + die(MBERR_GENERAL); /* * Search the file if the From area, if found, the diff --git a/mbfido/mbfpack.c b/mbfido/mbfpack.c index 6b5f49ab..8e95a953 100644 --- a/mbfido/mbfpack.c +++ b/mbfido/mbfpack.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbcfg.h" +#include "../lib/mberrors.h" #include "mbfutil.h" #include "mbfpack.h" @@ -71,7 +72,7 @@ void PackFileBase(void) if ((pAreas = fopen (sAreas, "r")) == NULL) { WriteError("Can't open %s", sAreas); - die(0); + die(MBERR_INIT_ERROR); } fread(&areahdr, sizeof(areahdr), 1, pAreas); @@ -86,7 +87,7 @@ void PackFileBase(void) if (area.Available && !area.CDrom) { if (!diskfree(CFG.freespace)) - die(101); + die(MBERR_DISK_FULL); if (!do_quiet) { printf("\r%4d => %-44s", i, area.Name); @@ -101,13 +102,13 @@ void PackFileBase(void) Syslog('!', "Creating new %s", fAreas); if ((pFile = fopen(fAreas, "a+")) == NULL) { WriteError("$Can't create %s", fAreas); - die(0); + die(MBERR_GENERAL); } } if ((fp = fopen(fTmp, "a+")) == NULL) { WriteError("$Can't create %s", fTmp); - die(0); + die(MBERR_GENERAL); } while (fread(&file, sizeof(file), 1, pFile) == 1) { diff --git a/mbfido/mbfutil.c b/mbfido/mbfutil.c index 85d865be..044630df 100644 --- a/mbfido/mbfutil.c +++ b/mbfido/mbfutil.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbcfg.h" +#include "../lib/mberrors.h" #include "mbfutil.h" #include "mbfile.h" @@ -134,7 +135,7 @@ void Help(void) printf(" -a -announce Suppress announce added files\n"); printf(" -q -quiet Quiet mode\n"); printf(" -v -virus Suppress virus scanning, use with care\n"); - die(0); + die(MBERR_COMMANDLINE); } @@ -250,7 +251,7 @@ int UnpackFile(char *File) WriteError("$Can't create %s", temp); if (!do_quiet) printf("Can't create %s\n", temp); - die(0); + die(MBERR_GENERAL); } } @@ -282,7 +283,7 @@ int UnpackFile(char *File) sprintf(temp, "%s/tmp/arc", getenv("MBSE_ROOT")); if (chdir(temp) != 0) { WriteError("$Can't change to %s", temp); - die(0); + die(MBERR_GENERAL); } if (execute(cmd, File, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) { diff --git a/mbfido/mbindex.c b/mbfido/mbindex.c index f41b9ea8..1a8ca425 100644 --- a/mbfido/mbindex.c +++ b/mbfido/mbindex.c @@ -38,6 +38,7 @@ #include "../lib/clcomm.h" #include "../lib/dbcfg.h" #include "../lib/dbftn.h" +#include "../lib/mberrors.h" #define TMPNAME "TMP." @@ -151,7 +152,7 @@ void Help(void) printf(" -quiet Quiet mode\n"); colour(7, 0); printf("\n"); - die(0); + die(MBERR_COMMANDLINE); } @@ -208,7 +209,7 @@ void die(int onsig) int main(int argc,char *argv[]) { - int i, rc; + int i; char *cmd; struct passwd *pw; @@ -258,16 +259,18 @@ int main(int argc,char *argv[]) free(cmd); if (!diskfree(CFG.freespace)) - die(101); + die(MBERR_DISK_FULL); if (lockindex()) { if (!do_quiet) printf("Can't lock mbindex, abort.\n"); - die(104); + die(MBERR_NO_PROGLOCK); } - rc = nodebld(); - die(rc); + if (nodebld()) + die(MBERR_GENERAL); + else + die(MBERR_OK); return 0; } diff --git a/mbfido/mbmsg.c b/mbfido/mbmsg.c index 2defdf45..2af60200 100644 --- a/mbfido/mbmsg.c +++ b/mbfido/mbmsg.c @@ -38,6 +38,7 @@ #include "../lib/clcomm.h" #include "../lib/msg.h" #include "../lib/dbcfg.h" +#include "../lib/mberrors.h" #include "post.h" #include "mbmsg.h" @@ -177,7 +178,7 @@ int main(int argc, char **argv) Post(too, tarea, subj, mfile, flavor); } - die(0); + die(MBERR_OK); return 0; } @@ -205,7 +206,7 @@ void Help() printf(" -q -quiet Quiet mode\n"); printf("\n"); - die(0); + die(MBERR_COMMANDLINE); } @@ -276,7 +277,7 @@ void DoMsgBase() sprintf(sAreas, "%s/etc/mareas.data", getenv("MBSE_ROOT")); if(( pAreas = fopen (sAreas, "r")) == NULL) { WriteError("$Can't open Messages Areas File."); - die(SIGILL); + die(MBERR_INIT_ERROR); } fread(&msgshdr, sizeof(msgshdr), 1, pAreas); @@ -286,7 +287,7 @@ void DoMsgBase() if (msgs.Active) { if (!diskfree(CFG.freespace)) - die(101); + die(MBERR_DISK_FULL); if (!do_quiet) { colour(3, 0); @@ -315,7 +316,7 @@ void DoMsgBase() if (msgs.Active) { if (!diskfree(CFG.freespace)) - die(101); + die(MBERR_DISK_FULL); Nopper(); if (!do_quiet) { @@ -417,7 +418,7 @@ void DoMsgBase() free(sAreas); free(Name); - die(0); + die(MBERR_OK); } diff --git a/mbfido/rnews.c b/mbfido/rnews.c index 11f8ead8..44b8d38a 100644 --- a/mbfido/rnews.c +++ b/mbfido/rnews.c @@ -43,6 +43,7 @@ #include "../lib/dbmsgs.h" #include "../lib/msg.h" #include "../lib/msgtext.h" +#include "../lib/mberrors.h" #include "rfc2ftn.h" #include "mbfido.h" #include "../paths.h" @@ -164,57 +165,56 @@ const char *HeaderFindMem(const char *Article, const int ArtLen, const char *Hea static int StartChild(int, char *, char *[]); static int StartChild(int fd, char *path, char *argv[]) { - int pan[2]; - int i; - pid_t pid; + int pan[2], i; + pid_t pid; - /* Create a pipe. */ - if (pipe(pan) < 0) { - WriteError("%Cant pipe for %s", path); - die(101); + /* Create a pipe. */ + if (pipe(pan) < 0) { + WriteError("%Cant pipe for %s", path); + die(MBERR_EXEC_FAILED); + } + + /* Get a child. */ + for (i = 0; (pid = fork()) < 0; i++) { + if (i == MAX_FORKS) { + WriteError("$Cant fork %s -- spooling", path); + return -1; + } + Syslog('n', "Cant fork %s -- waiting", path); + (void)sleep(60); + } + + /* Run the child, with redirection. */ + if (pid == 0) { + (void)close(pan[PIPE_READ]); + + /* Stdin comes from our old input. */ + if (fd != STDIN) { + if ((i = dup2(fd, STDIN)) != STDIN) { + WriteError("$Cant dup2 %d to 0 got %d", fd, i); + _exit(MBERR_EXEC_FAILED); + } + (void)close(fd); } - /* Get a child. */ - for (i = 0; (pid = fork()) < 0; i++) { - if (i == MAX_FORKS) { - WriteError("$Cant fork %s -- spooling", path); - return -1; - } - Syslog('n', "Cant fork %s -- waiting", path); - (void)sleep(60); + /* Stdout goes down the pipe. */ + if (pan[PIPE_WRITE] != STDOUT) { + if ((i = dup2(pan[PIPE_WRITE], STDOUT)) != STDOUT) { + WriteError("$Cant dup2 %d to 1 got %d", pan[PIPE_WRITE], i); + _exit(MBERR_EXEC_FAILED); + } + (void)close(pan[PIPE_WRITE]); } - /* Run the child, with redirection. */ - if (pid == 0) { - (void)close(pan[PIPE_READ]); + Syslog('n', "execv %s %s", MBSE_SS(path), MBSE_SS(argv[1])); + (void)execv(path, argv); + WriteError("$Cant execv %s", path); + _exit(MBERR_EXEC_FAILED); + } - /* Stdin comes from our old input. */ - if (fd != STDIN) { - if ((i = dup2(fd, STDIN)) != STDIN) { - WriteError("$Cant dup2 %d to 0 got %d", fd, i); - _exit(1); - } - (void)close(fd); - } - - /* Stdout goes down the pipe. */ - if (pan[PIPE_WRITE] != STDOUT) { - if ((i = dup2(pan[PIPE_WRITE], STDOUT)) != STDOUT) { - WriteError("$Cant dup2 %d to 1 got %d", pan[PIPE_WRITE], i); - _exit(1); - } - (void)close(pan[PIPE_WRITE]); - } - - Syslog('n', "execv %s %s", MBSE_SS(path), MBSE_SS(argv[1])); - (void)execv(path, argv); - WriteError("$Cant execv %s", path); - _exit(1); - } - - (void)close(pan[PIPE_WRITE]); - (void)close(fd); - return pan[PIPE_READ]; + (void)close(pan[PIPE_WRITE]); + (void)close(fd); + return pan[PIPE_READ]; } @@ -322,50 +322,50 @@ static int Process(char *article) static int ReadRemainder(register int, char, char); static int ReadRemainder(register int fd, char first, char second) { - register FILE *F; - register char *article; - register int size; - register int used; - register int left; - register int i; - int ok; + register FILE *F; + register char *article; + register int size; + register int used; + register int left; + register int i; + int ok; - /* Turn the descriptor into a stream. */ - if ((F = fdopen(fd, "r")) == NULL) { - WriteError("$Can't fdopen %d", fd); - die(101); + /* Turn the descriptor into a stream. */ + if ((F = fdopen(fd, "r")) == NULL) { + WriteError("$Can't fdopen %d", fd); + die(MBERR_GENERAL); + } + + /* Get an initial allocation, leaving space for the \0. */ + size = BUFSIZ + 1; + article = NEW(char, size + 2); + article[0] = first; + article[1] = second; + used = second ? 2 : 1; + left = size - used; + + /* Read the input. */ + while ((i = fread((POINTER)&article[used], (size_t)1, (size_t)left, F)) != 0) { + if (i < 0) { + WriteError("$Cant fread after %d bytes", used); + die(MBERR_GENERAL); } - - /* Get an initial allocation, leaving space for the \0. */ - size = BUFSIZ + 1; - article = NEW(char, size + 2); - article[0] = first; - article[1] = second; - used = second ? 2 : 1; - left = size - used; - - /* Read the input. */ - while ((i = fread((POINTER)&article[used], (size_t)1, (size_t)left, F)) != 0) { - if (i < 0) { - WriteError("$Cant fread after %d bytes", used); - die(101); - } - used += i; - left -= i; - if (left < SMBUF) { - size += BUFSIZ; - left += BUFSIZ; - RENEW(article, char, size); - } + used += i; + left -= i; + if (left < SMBUF) { + size += BUFSIZ; + left += BUFSIZ; + RENEW(article, char, size); } - if (article[used - 1] != '\n') - article[used++] = '\n'; - article[used] = '\0'; - (void)fclose(F); + } + if (article[used - 1] != '\n') + article[used++] = '\n'; + article[used] = '\0'; + (void)fclose(F); - ok = Process(article); - DISPOSE(article); - return ok; + ok = Process(article); + DISPOSE(article); + return ok; } @@ -421,23 +421,23 @@ static int ReadBytecount(register int fd, int artsize) static int ReadLine(char *, int, int); static int ReadLine(char *p, int size, int fd) { - char *save; + char *save; - /* Fill the buffer, a byte at a time. */ - for (save = p; size > 0; p++, size--) { - if (read(fd, p, 1) != 1) { - *p = '\0'; - WriteError("$Cant read first line got %s", save); - die(101); - } - if (*p == '\n') { - *p = '\0'; - return TRUE; - } + /* Fill the buffer, a byte at a time. */ + for (save = p; size > 0; p++, size--) { + if (read(fd, p, 1) != 1) { + *p = '\0'; + WriteError("$Cant read first line got %s", save); + die(MBERR_GENERAL); } - *p = '\0'; - WriteError("bad_line too long %s", save); - return FALSE; + if (*p == '\n') { + *p = '\0'; + return TRUE; + } + } + *p = '\0'; + WriteError("bad_line too long %s", save); + return FALSE; } diff --git a/mbmon/Makefile b/mbmon/Makefile index b90b3aa0..3e368304 100644 --- a/mbmon/Makefile +++ b/mbmon/Makefile @@ -57,7 +57,7 @@ depend: # DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT # Dependencies generated by make depend -mutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h common.h mutil.h +mutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mberrors.h common.h mutil.h mbmon.o: ../config.h ../lib/libs.h ../lib/memwatch.h common.h mutil.h -common.o: ../config.h ../lib/libs.h ../lib/memwatch.h common.h +common.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mberrors.h common.h # End of generated dependencies diff --git a/mbmon/common.c b/mbmon/common.c index 1b0f1e5c..14be8567 100644 --- a/mbmon/common.c +++ b/mbmon/common.c @@ -31,6 +31,7 @@ #include "../config.h" #include "../lib/libs.h" #include "../lib/memwatch.h" +#include "../lib/mberrors.h" #include #include "common.h" @@ -43,30 +44,30 @@ static int sock = -1; /* TCP/IP socket */ int ttyfd; /* Filedescriptor for raw mode */ struct termios tbufs, tbufsavs; /* Structure for raw mode */ -struct sockaddr_un clntaddr; /* Client socket address */ -struct sockaddr_un servaddr; /* Server socket address */ -struct sockaddr_un from; /* From socket address */ -int fromlen; -static char spath[108]; /* Server socket path */ -static char cpath[108]; /* Client socket path */ +struct sockaddr_un clntaddr; /* Client socket address */ +struct sockaddr_un servaddr; /* Server socket address */ +struct sockaddr_un from; /* From socket address */ +int fromlen; +static char spath[PATH_MAX]; /* Server socket path */ +static char cpath[PATH_MAX]; /* Client socket path */ void InitClient(char *user) { - sprintf(cpath, "%s/tmp/mbmon%d", getenv("MBSE_ROOT"), getpid()); - sprintf(spath, "%s/tmp/mbtask", getenv("MBSE_ROOT")); + sprintf(cpath, "%s/tmp/mbmon%d", getenv("MBSE_ROOT"), getpid()); + sprintf(spath, "%s/tmp/mbtask", getenv("MBSE_ROOT")); - /* - * Store my pid in case a child process is forked and wants to do - * some communications with the mbsed server. - */ - mypid = getpid(); - if (socket_connect(user) == -1) { - printf("PANIC: cannot access socket\n"); - exit(1); - } + /* + * Store my pid in case a child process is forked and wants to do + * some communications with the mbsed server. + */ + mypid = getpid(); + if (socket_connect(user) == -1) { + printf("PANIC: cannot access socket\n"); + exit(MBERR_INIT_ERROR); + } } @@ -456,41 +457,31 @@ int rawset = FALSE; */ void Setraw() { - int rc; + int rc; - if ((rc = tcgetattr(ttyfd, &tbufs))) { - perror(""); - printf("$tcgetattr(0, save) return %d\n", rc); - exit(1); - } + if ((rc = tcgetattr(ttyfd, &tbufs))) { + perror(""); + printf("$tcgetattr(0, save) return %d\n", rc); + exit(MBERR_TTYIO_ERROR); + } -// if (ioctl(ttyfd, TCGETA, &tbuf) == -1) { -// perror("TCGETA Failed"); -// exit(1); /* ERROR - could not set get tty ioctl */ -// } + tbufsavs = tbufs; + tbufs.c_iflag &= ~(INLCR | ICRNL | ISTRIP | IXON ); + /* + * Map CRNL modes strip control characters and flow control + */ + tbufs.c_oflag &= ~OPOST; /* Don't do ouput character translation */ + tbufs.c_lflag &= ~(ICANON | ECHO); /* No canonical input and no echo */ + tbufs.c_cc[VMIN] = 1; /* Receive 1 character at a time */ + tbufs.c_cc[VTIME] = 0; /* No time limit per character */ - tbufsavs = tbufs; - tbufs.c_iflag &= ~(INLCR | ICRNL | ISTRIP | IXON ); - /* - * Map CRNL modes strip control characters and flow control - */ - tbufs.c_oflag &= ~OPOST; /* Don't do ouput character translation */ - tbufs.c_lflag &= ~(ICANON | ECHO); /* No canonical input and no echo */ - tbufs.c_cc[VMIN] = 1; /* Receive 1 character at a time */ - tbufs.c_cc[VTIME] = 0; /* No time limit per character */ + if ((rc = tcsetattr(ttyfd, TCSADRAIN, &tbufs))) { + perror(""); + printf("$tcsetattr(%d, TCSADRAIN, raw) return %d\n", ttyfd, rc); + exit(MBERR_TTYIO_ERROR); + } - if ((rc = tcsetattr(ttyfd, TCSADRAIN, &tbufs))) { - perror(""); - printf("$tcsetattr(%d, TCSADRAIN, raw) return %d\n", ttyfd, rc); - exit(1); - } - -// if (ioctl(ttyfd, TCSETAF, &tbuf) == -1) { -// perror("TCSETAF failed"); -// exit(1); /* ERROR - could not set tty ioctl */ -// } - - rawset = TRUE; + rawset = TRUE; } @@ -500,23 +491,19 @@ void Setraw() */ void Unsetraw() { - int rc; + int rc; - /* - * Only unset the mode if it is set to raw mode - */ - if (rawset == TRUE) { -// if (ioctl(ttyfd, TCSETAF, &tbufsav) == -1) { -// perror("TCSETAF Normal Failed"); -// exit(1); /* ERROR - could not save original tty ioctl */ -// } - if ((rc = tcsetattr(ttyfd, TCSAFLUSH, &tbufsavs))) { - perror(""); - printf("$tcsetattr(%d, TCSAFLUSH, save) return %d\n", ttyfd, rc); - exit(1); - } + /* + * Only unset the mode if it is set to raw mode + */ + if (rawset == TRUE) { + if ((rc = tcsetattr(ttyfd, TCSAFLUSH, &tbufsavs))) { + perror(""); + printf("$tcsetattr(%d, TCSAFLUSH, save) return %d\n", ttyfd, rc); + exit(MBERR_TTYIO_ERROR); } - rawset = FALSE; + } + rawset = FALSE; } diff --git a/mbmon/mutil.c b/mbmon/mutil.c index bc89aee0..cfa53c9b 100644 --- a/mbmon/mutil.c +++ b/mbmon/mutil.c @@ -31,6 +31,7 @@ #include "../config.h" #include "../lib/libs.h" #include "../lib/memwatch.h" +#include "../lib/mberrors.h" #include "common.h" #include "mutil.h" @@ -44,8 +45,8 @@ unsigned char readkey(int y, int x, int fg, int bg) unsigned char ch = 0; if ((ttyfd = open("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { - perror("open 9"); - exit(1); + perror("open /dev/tty"); + exit(MBERR_TTYIO_ERROR); } Setraw(); @@ -87,8 +88,8 @@ unsigned char testkey(int y, int x) fflush(stdout); if ((ttyfd = open("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { - perror("open 9"); - exit(1); + perror("open /dev/tty"); + exit(MBERR_TTYIO_ERROR); } Setraw(); diff --git a/mbsebbs/Makefile b/mbsebbs/Makefile index 921c9184..f37f5e57 100644 --- a/mbsebbs/Makefile +++ b/mbsebbs/Makefile @@ -136,8 +136,8 @@ depend: # Dependencies generated by make depend bank.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h bank.h input.h language.h dispfile.h timeout.h timecheck.h whoson.h exitinfo.h filesub.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h filesub.h funcs.h language.h input.h misc.h timeout.h exitinfo.h change.h -language.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h input.h language.h -mbtoberep.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h +language.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h input.h language.h +mbtoberep.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/mberrors.h msgutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msgtext.h ../lib/msg.h oneline.h msgutil.h oneline.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h oneline.h funcs.h input.h language.h bbslist.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h bbslist.h funcs.h input.h language.h @@ -145,20 +145,20 @@ morefile.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/str email.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/msgtext.h ../lib/msg.h ../lib/common.h ../lib/clcomm.h ../lib/mbinet.h exitinfo.h language.h mail.h timeout.h msgutil.h input.h email.h whoson.h fsedit.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/ansi.h ../lib/common.h ../lib/clcomm.h mail.h input.h language.h timeout.h pinfo.h fsedit.h lineedit.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h mail.h input.h language.h timeout.h lineedit.h -mblang.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h -mbuser.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbuser.h +mblang.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/mberrors.h +mbuser.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbuser.h page.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h dispfile.h input.h chat.h page.h timeout.h mail.h language.h -bye.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h dispfile.h misc.h language.h bye.h -funcs.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/msgtext.h ../lib/msg.h ../lib/clcomm.h funcs.h +bye.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../lib/mberrors.h dispfile.h misc.h language.h bye.h +funcs.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/msgtext.h ../lib/msg.h ../lib/clcomm.h ../lib/mberrors.h funcs.h mail.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/msgtext.h ../lib/clcomm.h ../lib/msg.h mail.h funcs.h input.h language.h misc.h timeout.h oneline.h exitinfo.h lineedit.h fsedit.h filesub.h msgutil.h pop3.h email.h door.h whoson.h -newuser.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h funcs.h input.h newuser.h language.h timeout.h change.h dispfile.h +newuser.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../lib/mberrors.h funcs.h input.h newuser.h language.h timeout.h change.h dispfile.h pinfo.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h pinfo.h input.h -timecheck.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h timecheck.h funcs.h bye.h exitinfo.h language.h input.h +timecheck.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../lib/mberrors.h timecheck.h funcs.h bye.h exitinfo.h language.h input.h change.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h change.h dispfile.h funcs.h input.h language.h misc.h timeout.h exitinfo.h bye.h exitinfo.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h funcs.h input.h language.h oneline.h misc.h bye.h timeout.h timecheck.h exitinfo.h -mball.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/mbse.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbcfg.h ../lib/clcomm.h mball.h -mbsebbs.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h mbsebbs.h user.h dispfile.h language.h menu.h misc.h bye.h timeout.h funcs.h -menu.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h oneline.h mail.h bbslist.h change.h bank.h chat.h file.h funcs.h input.h misc.h nextuser.h safe.h timeout.h menu.h page.h pinfo.h bye.h timecheck.h whoson.h language.h offline.h email.h door.h dispfile.h userlist.h timestats.h logentry.h morefile.h lastcallers.h +mball.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/mbse.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/dbcfg.h ../lib/clcomm.h ../lib/mberrors.h mball.h +mbsebbs.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/mberrors.h mbsebbs.h user.h dispfile.h language.h menu.h misc.h bye.h timeout.h funcs.h +menu.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h oneline.h mail.h bbslist.h change.h bank.h chat.h file.h funcs.h input.h misc.h nextuser.h safe.h timeout.h menu.h page.h pinfo.h bye.h timecheck.h whoson.h language.h offline.h email.h door.h dispfile.h userlist.h timestats.h logentry.h morefile.h lastcallers.h nextuser.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/ansi.h ../lib/clcomm.h ../lib/common.h nextuser.h funcs.h input.h language.h timeout.h pop3.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mbinet.h ../lib/msgtext.h ../lib/msg.h msgutil.h pop3.h lastcallers.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h input.h language.h lastcallers.h @@ -166,15 +166,15 @@ safe.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs timeout.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h timeout.h funcs.h bye.h filesub.h language.h chat.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h chat.h funcs.h input.h language.h misc.h whoson.h file.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h filesub.h file.h funcs.h input.h language.h misc.h timeout.h exitinfo.h whoson.h change.h -mbchat.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h -mbstat.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h mbstat.h -misc.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h funcs.h input.h language.h misc.h timeout.h exitinfo.h +mbchat.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h +mbstat.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/mberrors.h mbstat.h +misc.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../lib/mberrors.h funcs.h input.h language.h misc.h timeout.h exitinfo.h offline.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/mbse.h ../lib/users.h ../lib/records.h ../lib/bluewave.h ../lib/common.h ../lib/clcomm.h ../lib/msgtext.h ../lib/msg.h mail.h funcs.h input.h language.h file.h filesub.h exitinfo.h timeout.h msgutil.h pop3.h offline.h whoson.h -user.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h timeout.h user.h dispfile.h funcs.h input.h misc.h bye.h file.h mail.h change.h menu.h exitinfo.h language.h offline.h email.h -mbnewusr.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h mbnewusr.h funcs.h input.h language.h misc.h timeout.h newuser.h -input.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h input.h timeout.h language.h +user.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h timeout.h user.h dispfile.h funcs.h input.h misc.h bye.h file.h mail.h change.h menu.h exitinfo.h language.h offline.h email.h +mbnewusr.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h mbnewusr.h funcs.h input.h language.h misc.h timeout.h newuser.h +input.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../lib/mberrors.h input.h timeout.h language.h whoson.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h input.h language.h exitinfo.h whoson.h -door.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h input.h timeout.h exitinfo.h whoson.h door.h +door.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h input.h timeout.h exitinfo.h whoson.h door.h dispfile.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/msgtext.h ../lib/msg.h ../lib/clcomm.h funcs.h language.h oneline.h misc.h timeout.h timecheck.h exitinfo.h mail.h email.h dispfile.h userlist.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h userlist.h language.h input.h timeout.h timestats.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mbse.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h timestats.h funcs.h language.h input.h exitinfo.h diff --git a/mbsebbs/bye.c b/mbsebbs/bye.c index 6e15e4f7..340dd95c 100644 --- a/mbsebbs/bye.c +++ b/mbsebbs/bye.c @@ -37,6 +37,7 @@ #include "../lib/records.h" #include "../lib/clcomm.h" #include "../lib/common.h" +#include "../lib/mberrors.h" #include "dispfile.h" #include "misc.h" #include "language.h" @@ -95,7 +96,7 @@ void Good_Bye(int onsig) offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize); if(fseek(pUsrConfig, offset, 0) != 0) { WriteError("Can't move pointer in file %s", temp); - ExitClient(1); + ExitClient(MBERR_GENERAL); } fwrite(&usrconfig, sizeof(usrconfig), 1, pUsrConfig); @@ -160,7 +161,7 @@ void Quick_Bye(int onsig) #ifdef MEMWATCH mwTerm(); #endif - exit(0); + exit(MBERR_OK); } diff --git a/mbsebbs/door.c b/mbsebbs/door.c index 5f457cfe..304ebffd 100644 --- a/mbsebbs/door.c +++ b/mbsebbs/door.c @@ -37,6 +37,7 @@ #include "../lib/records.h" #include "../lib/common.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "input.h" #include "timeout.h" #include "exitinfo.h" @@ -263,7 +264,7 @@ int exec_nosuid(char *mandato) argv[2] = mandato; argv[3] = 0; execve("/bin/sh", argv, environ); - exit(127); + exit(MBERR_EXEC_FAILED); } e_pid = pid; diff --git a/mbsebbs/funcs.c b/mbsebbs/funcs.c index ccc11e7c..275a5c70 100644 --- a/mbsebbs/funcs.c +++ b/mbsebbs/funcs.c @@ -39,6 +39,7 @@ #include "../lib/msgtext.h" #include "../lib/msg.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "funcs.h" @@ -197,7 +198,7 @@ char *ChangeHomeDir(char *Name, int Mailboxes) if ((access(CFG.bbs_usersdir, R_OK)) != 0) { WriteError("$FATAL: Access to %s failed", CFG.bbs_usersdir); free(temp); - ExitClient(1); + ExitClient(MBERR_INIT_ERROR); } sprintf(temp1, "%s/%s", CFG.bbs_usersdir, Name); @@ -208,7 +209,7 @@ char *ChangeHomeDir(char *Name, int Mailboxes) if ((access(temp1, R_OK)) != 0) { WriteError("$FATAL: Users homedir %s doesn't exist", temp1); free(temp); - ExitClient(1); + ExitClient(MBERR_INIT_ERROR); } /* @@ -217,7 +218,7 @@ char *ChangeHomeDir(char *Name, int Mailboxes) if (chdir(temp1) != 0) { WriteError("$FATAL: Can't change to users home dir, aborting: %s", temp1); free(temp); - ExitClient(1); + ExitClient(MBERR_INIT_ERROR); } setenv("HOME", temp1, 1); @@ -319,7 +320,7 @@ void FindMBSE() #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_INIT_ERROR); } sprintf(FileName, "%s/etc/config.data", getenv("MBSE_ROOT")); @@ -331,7 +332,7 @@ void FindMBSE() #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_CONFIG_ERROR); } fread(&CFG, sizeof(CFG), 1, pDataFile); diff --git a/mbsebbs/input.c b/mbsebbs/input.c index 08498b65..62863482 100644 --- a/mbsebbs/input.c +++ b/mbsebbs/input.c @@ -37,6 +37,7 @@ #include "../lib/records.h" #include "../lib/clcomm.h" #include "../lib/common.h" +#include "../lib/mberrors.h" #include "input.h" #include "timeout.h" #include "language.h" @@ -497,7 +498,7 @@ void Getpass(char *theword) */ if ((ttyfd = open ("/dev/tty", O_RDWR)) < 0) { perror("open 7"); - ExitClient(1); + ExitClient(MBERR_TTYIO_ERROR); } /* Set Raw mode so that the characters don't echo */ diff --git a/mbsebbs/language.c b/mbsebbs/language.c index c366d62c..a1b3d962 100644 --- a/mbsebbs/language.c +++ b/mbsebbs/language.c @@ -37,6 +37,7 @@ #include "../lib/records.h" #include "../lib/common.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "input.h" #include "language.h" @@ -132,7 +133,7 @@ void InitLanguage() sprintf(temp, "%s/etc/%s", getenv("MBSE_ROOT"), CFG.current_language); if ((pLang = fopen(temp, "rb")) == NULL) { WriteError("$FATAL: Can't open %s", temp); - ExitClient(1); + ExitClient(MBERR_INIT_ERROR); } while (fread(&ldata, sizeof(ldata), 1, pLang) == 1) { @@ -144,7 +145,7 @@ void InitLanguage() if(iLang >= LANG) { printf("FATAL: Language file has to many lines in it"); - ExitClient(1); + ExitClient(MBERR_INIT_ERROR); } } diff --git a/mbsebbs/mball.c b/mbsebbs/mball.c index 4911ed76..8dbabe88 100644 --- a/mbsebbs/mball.c +++ b/mbsebbs/mball.c @@ -38,6 +38,7 @@ #include "../lib/common.h" #include "../lib/dbcfg.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "mball.h" @@ -124,7 +125,7 @@ void Help() printf(" -z -zip Create .zip archives\n"); colour(7, 0); printf("\n"); - die(0); + die(MBERR_COMMANDLINE); } @@ -148,8 +149,7 @@ int main(int argc, char **argv) * Catch all signals we can, and ignore the rest. */ for (i = 0; i < NSIG; i++) { - if ((i == SIGHUP) || (i == SIGKILL) || (i == SIGBUS) || - (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM)) + if ((i == SIGHUP) || (i == SIGKILL) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM)) signal(i, (void (*))die); else signal(i, SIG_IGN); @@ -200,7 +200,7 @@ int main(int argc, char **argv) if (!do_quiet) printf("Done!\n"); - die(0); + die(MBERR_OK); return 0; } @@ -286,7 +286,7 @@ void Masterlist() if(( pAreas = fopen (sAreas, "r")) == NULL) { WriteError("Can't open File Areas File: %s", sAreas); colour(7,0); - die(1); + die(MBERR_GENERAL); } fread(&areahdr, sizeof(areahdr), 1, pAreas); @@ -295,12 +295,12 @@ void Masterlist() if ((fp = fopen("allfiles.tmp", "a+")) == NULL) { WriteError("$Can't open allfiles.tmp"); - die(1); + die(MBERR_GENERAL); } if ((np = fopen("newfiles.tmp", "a+")) == NULL) { WriteError("$Can't open newfiles.tmp"); fclose(fp); - die(1); + die(MBERR_GENERAL); } TopBox(fp, TRUE); diff --git a/mbsebbs/mbchat.c b/mbsebbs/mbchat.c index 40bfbaa9..dc204365 100644 --- a/mbsebbs/mbchat.c +++ b/mbsebbs/mbchat.c @@ -4,7 +4,7 @@ * Purpose ...............: Sysop chat utility. * ***************************************************************************** - * Copyright (C) 1997-2000 + * Copyright (C) 1997-2002 * * Michiel Broek FIDO: 2:2801/2802 * Beekmansbos 10 @@ -34,6 +34,7 @@ #include "../lib/structs.h" #include "../lib/common.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" char *ttime2(void); /* Returns current time HH:MM */ @@ -72,7 +73,7 @@ int main(int argc, char **argv) #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_INIT_ERROR); } sprintf(FileName, "%s/etc/config.data", BBSpath); @@ -84,7 +85,7 @@ int main(int argc, char **argv) #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_CONFIG_ERROR); } fread(&CFG, sizeof(CFG), 1, pDataFile); fclose(pDataFile); @@ -106,7 +107,7 @@ int main(int argc, char **argv) #ifdef MEMWATCH mwTerm(); #endif - exit(0); + exit(MBERR_COMMANDLINE); } printf("\f"); @@ -130,7 +131,7 @@ int main(int argc, char **argv) #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_COMMANDLINE); } else { fgets(pid1,19,pPid); fclose(pPid); @@ -232,7 +233,7 @@ int main(int argc, char **argv) #ifdef MEMWATCH mwTerm(); #endif - exit(0); + exit(MBERR_OK); } diff --git a/mbsebbs/mblang.c b/mbsebbs/mblang.c index 3bced825..cc20ea06 100644 --- a/mbsebbs/mblang.c +++ b/mbsebbs/mblang.c @@ -34,6 +34,7 @@ #include "../lib/structs.h" #include "../lib/users.h" #include "../lib/records.h" +#include "../lib/mberrors.h" int main(int argc, char **argv) @@ -56,7 +57,7 @@ int main(int argc, char **argv) #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_COMMANDLINE); } sprintf(temp1, "%s", *(argv + 1)); @@ -68,7 +69,7 @@ int main(int argc, char **argv) #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_COMMANDLINE); } sprintf(temp1, "%s", *(argv + 1)); if ((fp = fopen(temp1, "a+")) == NULL) { @@ -76,7 +77,7 @@ int main(int argc, char **argv) #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_COMMANDLINE); } lines = 0; @@ -97,7 +98,7 @@ int main(int argc, char **argv) #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_GENERAL); } /* @@ -115,7 +116,7 @@ int main(int argc, char **argv) #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_GENERAL); } fwrite(&ldata, sizeof(ldata), 1, fp); diff --git a/mbsebbs/mbnewusr.c b/mbsebbs/mbnewusr.c index 6fd39633..4ec8a156 100644 --- a/mbsebbs/mbnewusr.c +++ b/mbsebbs/mbnewusr.c @@ -37,6 +37,7 @@ #include "../lib/records.h" #include "../lib/common.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "mbnewusr.h" #include "funcs.h" #include "input.h" @@ -76,7 +77,7 @@ int main(int argc, char **argv) #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_CONFIG_ERROR); } /* @@ -87,7 +88,7 @@ int main(int argc, char **argv) #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_INIT_ERROR); } /* @@ -98,7 +99,7 @@ int main(int argc, char **argv) #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_INIT_ERROR); } /* @@ -137,7 +138,7 @@ int main(int argc, char **argv) if ((tty = ttyname(0)) == NULL) { WriteError("Not at a tty"); - Fast_Bye(0); + Fast_Bye(MBERR_OK); } if (strncmp("/dev/", tty, 5) == 0) @@ -154,8 +155,7 @@ int main(int argc, char **argv) * Trap signals */ for(i = 0; i < NSIG; i++) { - if ((i == SIGHUP) || (i == SIGBUS) || (i == SIGILL) || - (i == SIGSEGV) || (i == SIGTERM) || (i == SIGKILL)) + if ((i == SIGHUP) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM) || (i == SIGKILL)) signal(i, (void (*))die); else signal(i, SIG_IGN); @@ -173,7 +173,7 @@ int main(int argc, char **argv) */ if (CheckStatus() == FALSE) { Syslog('+', "Kicking user out, the BBS is closed"); - Fast_Bye(0); + Fast_Bye(MBERR_OK); } colour(YELLOW, BLACK); @@ -200,7 +200,7 @@ int main(int argc, char **argv) if ((strcmp(ttyinfo.tty, pTTY) != 0) || (!ttyinfo.available)) { Syslog('+', "No BBS allowed on port \"%s\"", pTTY); printf("No BBS on this port allowed!\n\n"); - Fast_Bye(0); + Fast_Bye(MBERR_OK); } /* @@ -219,7 +219,7 @@ int main(int argc, char **argv) Pause(); newuser(); - Fast_Bye(0); + Fast_Bye(MBERR_OK); return 0; } diff --git a/mbsebbs/mbsebbs.c b/mbsebbs/mbsebbs.c index 51bb956d..e6f51920 100644 --- a/mbsebbs/mbsebbs.c +++ b/mbsebbs/mbsebbs.c @@ -38,6 +38,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/msg.h" +#include "../lib/mberrors.h" #include "mbsebbs.h" #include "user.h" #include "dispfile.h" @@ -78,7 +79,7 @@ int main(int argc, char **argv) strcpy(sUnixName, getenv("USER")); } else { WriteError("No username in environment"); - Quick_Bye(0); + Quick_Bye(MBERR_OK); } /* @@ -128,7 +129,7 @@ int main(int argc, char **argv) if ((tty = ttyname(0)) == NULL) { WriteError("Not at a tty"); - Quick_Bye(0); + Quick_Bye(MBERR_OK); } if (strncmp("/dev/", tty, 5) == 0) @@ -145,8 +146,7 @@ int main(int argc, char **argv) * Trap signals */ for(i = 0; i < NSIG; i++) { - if ((i == SIGHUP) || (i == SIGBUS) || (i == SIGILL) || - (i == SIGSEGV) || (i == SIGTERM) || (i == SIGKILL)) + if ((i == SIGHUP) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM) || (i == SIGKILL)) signal(i, (void (*))die); else signal(i, SIG_IGN); @@ -168,7 +168,7 @@ int main(int argc, char **argv) */ if (CheckStatus() == FALSE) { Syslog('+', "Kicking user out, the BBS is closed"); - Quick_Bye(0); + Quick_Bye(MBERR_OK); } clear(); @@ -200,7 +200,7 @@ int main(int argc, char **argv) if ((strcmp(ttyinfo.tty, pTTY) != 0) || (!ttyinfo.available)) { Syslog('+', "No BBS allowed on port \"%s\"", pTTY); printf("No BBS on this port allowed!\n\n"); - Quick_Bye(0); + Quick_Bye(MBERR_OK); } Syslog('b', "Node number %d", iNode); diff --git a/mbsebbs/mbstat.c b/mbsebbs/mbstat.c index 012a8d9f..499092f4 100644 --- a/mbsebbs/mbstat.c +++ b/mbsebbs/mbstat.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbcfg.h" +#include "../lib/mberrors.h" #include "mbstat.h" @@ -63,7 +64,7 @@ void Help(void) colour(3, 0); printf(" -q -quiet Quiet, no screen output\n"); colour(7, 0); - die(0); + die(MBERR_COMMANDLINE); } @@ -123,9 +124,7 @@ int main(int argc, char **argv) * Catch or ignore signals */ for (i = 0; i < NSIG; i++) { - if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || - (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM) || - (i == SIGKILL)) + if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM)) signal(i, (void (*))die); else signal(i, SIG_IGN); @@ -191,7 +190,7 @@ int main(int argc, char **argv) Help(); usleep(1); - die(0); + die(MBERR_OK); return 0; } diff --git a/mbsebbs/mbtoberep.c b/mbsebbs/mbtoberep.c index d7100b5b..cfed3bcf 100644 --- a/mbsebbs/mbtoberep.c +++ b/mbsebbs/mbtoberep.c @@ -32,6 +32,7 @@ #include "../lib/libs.h" #include "../lib/memwatch.h" #include "../lib/structs.h" +#include "../lib/mberrors.h" int main(int argc, char **argv) @@ -50,7 +51,7 @@ int main(int argc, char **argv) #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_INIT_ERROR); } temp = calloc(PATH_MAX, sizeof(char)); @@ -62,7 +63,7 @@ int main(int argc, char **argv) #ifdef MEMWATCH mwTerm(); #endif - exit(1); + exit(MBERR_INIT_ERROR); } while (fread(&rep, sizeof(rep), 1, fp) == 1) { diff --git a/mbsebbs/mbuser.c b/mbsebbs/mbuser.c index 99ff67e8..fb8198b0 100644 --- a/mbsebbs/mbuser.c +++ b/mbsebbs/mbuser.c @@ -37,6 +37,7 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/dbcfg.h" +#include "../lib/mberrors.h" #include "mbuser.h" @@ -108,7 +109,7 @@ int main(int argc, char **argv) free(cmd); if (!diskfree(CFG.freespace)) - ExitClient(101); + ExitClient(MBERR_DISK_FULL); oldmask = umask(027); if (!do_quiet) @@ -121,7 +122,7 @@ int main(int argc, char **argv) if (!do_quiet) colour(7, 0); - ExitClient(0); + ExitClient(MBERR_OK); return 0; } @@ -163,7 +164,7 @@ void Help(void) colour(7, 0); printf("\n"); - ExitClient(1); + ExitClient(MBERR_COMMANDLINE); } diff --git a/mbsebbs/menu.c b/mbsebbs/menu.c index f890e73c..0b223b90 100644 --- a/mbsebbs/menu.c +++ b/mbsebbs/menu.c @@ -37,6 +37,7 @@ #include "../lib/records.h" #include "../lib/common.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "oneline.h" #include "mail.h" #include "bbslist.h" @@ -92,160 +93,160 @@ void InitMenu() void menu() { - FILE *pMenuFile; - int iFoundKey = FALSE, Key, IsANSI; - char *Input, *Semfile; - char *sMenuPathFileName; + FILE *pMenuFile; + int iFoundKey = FALSE, Key, IsANSI; + char *Input, *Semfile, *sMenuPathFileName; - Input = calloc(81, sizeof(char)); - sMenuPathFileName = calloc(PATH_MAX, sizeof(char)); + Input = calloc(PATH_MAX, sizeof(char)); + sMenuPathFileName = calloc(PATH_MAX, sizeof(char)); - /* - * Loop forever, this is what a BBS should do until a user logs out. + /* + * Loop forever, this is what a BBS should do until a user logs out. + */ + while (TRUE) { + + WhosDoingWhat(BROWSING); + + /* + * Open menufile, first users language menu, if it fails + * try to open the default menu. */ - while (TRUE) { + sprintf(sMenuPathFileName,"%s/%s", lang.MenuPath, Menus[MenuLevel]); + if ((pMenuFile = fopen(sMenuPathFileName, "r")) == NULL) { + sprintf(sMenuPathFileName,"%s/%s", CFG.bbs_menus, Menus[MenuLevel]); + pMenuFile = fopen(sMenuPathFileName,"r"); + if (pMenuFile != NULL) + Syslog('+', "Menu %s (Default)", Menus[MenuLevel]); + } else { + Syslog('+', "Menu %s (%s)", Menus[MenuLevel], lang.Name); + } - WhosDoingWhat(BROWSING); + if (pMenuFile == NULL) { + clear(); + WriteError("Can't open menu file: %s", sMenuPathFileName); + MenuError++; - /* - * Open menufile, first users language menu, if it fails - * try to open the default menu. - */ - sprintf(sMenuPathFileName,"%s/%s", lang.MenuPath, Menus[MenuLevel]); - if ((pMenuFile = fopen(sMenuPathFileName, "r")) == NULL) { - sprintf(sMenuPathFileName,"%s/%s", CFG.bbs_menus, Menus[MenuLevel]); - pMenuFile = fopen(sMenuPathFileName,"r"); - if (pMenuFile != NULL) - Syslog('+', "Menu %s (Default)", Menus[MenuLevel]); - } else { - Syslog('+', "Menu %s (%s)", Menus[MenuLevel], lang.Name); + /* + * Is this the last attempt to open the default menu? + */ + if (MenuError == 10) { + WriteError("FATAL ERROR: Too many menu errors"); + printf("Too many menu errors, notifying Sysop\n\n"); + sleep(3); + die(MBERR_CONFIG_ERROR); + } + + /* + * Switch back to the default menu + */ + MenuLevel = 0; + strcpy(Menus[0], CFG.default_menu); + } else { + /* + * Display Menu Text Fields and Perform all autoexec menus in order of menu file. + * First check if there are any ANSI menus, if not, send a clearscreen first. + */ + IsANSI = FALSE; + while (fread(&menus, sizeof(menus), 1, pMenuFile) == 1) { + if ( Access(exitinfo.Security, menus.MenuSecurity) && (UserAge >= menus.Age)){ + if ((menus.MenuType == 5) || (menus.MenuType == 19) || (menus.MenuType == 20)) + IsANSI = TRUE; } + } + fseek(pMenuFile, 0, SEEK_SET); + if (! IsANSI) + clear(); - if (pMenuFile == NULL) { - clear(); - WriteError("Can't open menu file: %s", sMenuPathFileName); - MenuError++; + while (fread(&menus, sizeof(menus), 1, pMenuFile) == 1) { + if ( Access(exitinfo.Security, menus.MenuSecurity) && (UserAge >= menus.Age)){ + if ( menus.AutoExec ) { + DoMenu( menus.MenuType ); + } + DisplayMenu( ); + } + } - /* - * Is this the last attempt to open the default menu? - */ - if (MenuError == 10) { - WriteError("FATAL ERROR: Too many menu errors"); - printf("Too many menu errors, notifying Sysop\n\n"); - sleep(3); - die(SIGILL); - } + /* + * Check if the BBS closed down for Zone Mail Hour or + * system shutdown. If so, we run the Goodbye show. + */ + if (CheckStatus() == FALSE) { + fclose(pMenuFile); + Syslog('+', "Kicking user out, the BBS is closed."); + sleep(3); + Good_Bye(MBERR_OK); + } - /* - * Switch back to the default menu - */ - MenuLevel = 0; - strcpy(Menus[0], CFG.default_menu); - } else { - /* - * Display Menu Text Fields and Perform all autoexec menus in order of menu file. - * First check if there are any ANSI menus, if not, send a clearscreen first. - */ - IsANSI = FALSE; - while (fread(&menus, sizeof(menus), 1, pMenuFile) == 1) { - if ( Access(exitinfo.Security, menus.MenuSecurity) && (UserAge >= menus.Age)){ - if ((menus.MenuType == 5) || (menus.MenuType == 19) || (menus.MenuType == 20)) - IsANSI = TRUE; - } - } - fseek(pMenuFile, 0, SEEK_SET); - if (! IsANSI) - clear(); + /* + * Check the upsdown semafore + */ + Semfile = calloc(PATH_MAX, sizeof(char)); + sprintf(Semfile, "%s/sema/upsdown", getenv("MBSE_ROOT")); + if (file_exist(Semfile, R_OK) == 0) { + fclose(pMenuFile); + Syslog('+', "Kicking user out, upsdown semafore detected"); + printf("System power failure, closing the bbs\n\n"); + free(Semfile); + sleep(3); + Good_Bye(MBERR_OK); + } + free(Semfile); - while (fread(&menus, sizeof(menus), 1, pMenuFile) == 1) { - if ( Access(exitinfo.Security, menus.MenuSecurity) && (UserAge >= menus.Age)){ - if ( menus.AutoExec ) { - DoMenu( menus.MenuType ); - } - DisplayMenu( ); - } - } + /* + * Check if SysOp wants to chat to user everytime user + * gets prompt. Make sure /tmp/chatdev exists before + * before calling chat(). Make sure if a second user + * logs in, that .BusyChatting does exist. + */ + if(CFG.iChatPromptChk && (access("/tmp/chatdev", R_OK) == 0) && (access("/tmp/.BusyChatting", F_OK) != 0)) + Chat(); - /* - * Check if the BBS closed down for Zone Mail Hour or - * system shutdown. If so, we run the Goodbye show. - */ - if (CheckStatus() == FALSE) { - fclose(pMenuFile); - Syslog('+', "Kicking user out, the BBS is closed."); - sleep(3); - Good_Bye(0); - } + /* + * Check users timeleft + */ + TimeCheck(); - /* - * Check the upsdown semafore - */ - Semfile = calloc(PATH_MAX, sizeof(char)); - sprintf(Semfile, "%s/sema/upsdown", getenv("MBSE_ROOT")); - if (file_exist(Semfile, R_OK) == 0) { - fclose(pMenuFile); - Syslog('+', "Kicking user out, upsdown semafore detected"); - printf("System power failure, closing the bbs\n\n"); - free(Semfile); - sleep(3); - Good_Bye(0); - } - free(Semfile); + alarm_on(); - /* - * Check if SysOp wants to chat to user everytime user - * gets prompt. Make sure /tmp/chatdev exists before - * before calling chat(). Make sure if a second user - * logs in, that .BusyChatting does exist. - */ - if(CFG.iChatPromptChk && (access("/tmp/chatdev", R_OK) == 0) && (access("/tmp/.BusyChatting", F_OK) != 0)) - Chat(); + if (exitinfo.HotKeys) { + fflush(stdout); + Key = Getone(); + sprintf(Input, "%c", Key); + printf("\n"); + } else { + colour(CFG.InputColourF, CFG.InputColourB); + GetstrC(Input, 80); + } - /* - * Check users timeleft - */ - TimeCheck(); + if ((strcmp(Input, "")) != 0) { - alarm_on(); + fseek(pMenuFile, 0, SEEK_SET); - if (exitinfo.HotKeys) { - fflush(stdout); - Key = Getone(); - sprintf(Input, "%c", Key); - printf("\n"); - } else { - colour(CFG.InputColourF, CFG.InputColourB); - GetstrC(Input, 80); - } - - if((strcmp(Input, "")) != 0) { - - fseek(pMenuFile, 0, SEEK_SET); - - while (fread(&menus, sizeof(menus), 1, pMenuFile) == 1) { + while (fread(&menus, sizeof(menus), 1, pMenuFile) == 1) { - if ((strcmp(tu(Input), menus.MenuKey)) == 0) { - if ((Access(exitinfo.Security, menus.MenuSecurity)) && (UserAge >= menus.Age)) { - Syslog('b', "Menu[%d] %d=(%s), Opt: '%s'", MenuLevel, menus.MenuType, menus.TypeDesc, menus.OptionalData); - if (menus.MenuType == 13) { - /* - * Terminate call, cleanup here - */ - free(Input); - free(sMenuPathFileName); - fclose(pMenuFile); - } - DoMenu(menus.MenuType); - iFoundKey = TRUE; - break; - } - } - } + if ((strcmp(tu(Input), menus.MenuKey)) == 0) { + if ((Access(exitinfo.Security, menus.MenuSecurity)) && (UserAge >= menus.Age)) { + Syslog('b', "Menu[%d] %d=(%s), Opt: '%s'", MenuLevel, menus.MenuType, + menus.TypeDesc, menus.OptionalData); + if (menus.MenuType == 13) { + /* + * Terminate call, cleanup here + */ + free(Input); + free(sMenuPathFileName); + fclose(pMenuFile); + } + DoMenu(menus.MenuType); + iFoundKey = TRUE; + break; } - fclose(pMenuFile); + } + } + } + fclose(pMenuFile); - } /* If menu open */ - } /* while true */ + } /* If menu open */ + } /* while true */ } @@ -370,7 +371,7 @@ void DoMenu(int Type) free(sPrompt); free(sPromptBak); free(temp); - Good_Bye(0); + Good_Bye(MBERR_OK); break; case 14: diff --git a/mbsebbs/misc.c b/mbsebbs/misc.c index 96bd02dd..acdb5e35 100644 --- a/mbsebbs/misc.c +++ b/mbsebbs/misc.c @@ -37,6 +37,7 @@ #include "../lib/records.h" #include "../lib/clcomm.h" #include "../lib/common.h" +#include "../lib/mberrors.h" #include "funcs.h" #include "input.h" #include "language.h" @@ -79,7 +80,7 @@ int ChkFiles() if ((pUsersFile = fopen(temp,"rb")) == NULL) { if((pUsersFile = fopen(temp,"wb")) == NULL) { WriteError("$Can't create %s", temp); - ExitClient(1); + ExitClient(MBERR_INIT_ERROR); } else { usrconfighdr.hdrsize = sizeof(usrconfighdr); usrconfighdr.recsize = sizeof(usrconfig); diff --git a/mbsebbs/newuser.c b/mbsebbs/newuser.c index e79e2394..dffdfa68 100644 --- a/mbsebbs/newuser.c +++ b/mbsebbs/newuser.c @@ -38,6 +38,7 @@ #include "../lib/records.h" #include "../lib/clcomm.h" #include "../lib/common.h" +#include "../lib/mberrors.h" #include "funcs.h" #include "input.h" #include "newuser.h" @@ -85,7 +86,7 @@ int newuser() clear(); DisplayFile((char *)"newuser"); if ((iLang = Chg_Language(TRUE)) == 0) - Fast_Bye(1); + Fast_Bye(MBERR_INIT_ERROR); Enter(1); /* MBSE BBS - NEW USER REGISTRATION */ @@ -119,7 +120,7 @@ int newuser() */ if ((strcasecmp(temp, "off")) == 0) { Syslog('+', "Quick \"off\" logout"); - Fast_Bye(0); + Fast_Bye(MBERR_OK); } Count++; @@ -129,7 +130,7 @@ int newuser() language(CFG.HiliteF, CFG.HiliteB, 2); Enter(2); Syslog('!', "Exceeded maximum login attempts"); - Fast_Bye(0); + Fast_Bye(MBERR_OK); } /* @@ -486,7 +487,7 @@ int newuser() sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT")); if ((pUsrConfig = fopen(temp, "r+")) == NULL) { WriteError("Can't open file: %s", temp); - ExitClient(1); + ExitClient(MBERR_GENERAL); } fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig); @@ -582,7 +583,7 @@ void Fast_Bye(int onsig) #ifdef MEMWATCH mwTerm(); #endif - exit(0); + exit(MBERR_OK); } @@ -659,7 +660,7 @@ char *NameCreate(char *Name, char *Comment, char *Password) perror(""); WriteError("Failed to create unix account"); free(progname); - ExitClient(1); + ExitClient(MBERR_GENERAL); } sprintf(progname, "%s/bin/mbpasswd -f %s %s", getenv("MBSE_ROOT"), Name, Password); @@ -671,7 +672,7 @@ char *NameCreate(char *Name, char *Comment, char *Password) perror(""); WriteError("Failed to set unix password"); free(progname); - ExitClient(1); + ExitClient(MBERR_GENERAL); } colour(YELLOW, BLACK); diff --git a/mbsebbs/timecheck.c b/mbsebbs/timecheck.c index ffa56f6c..712dd712 100644 --- a/mbsebbs/timecheck.c +++ b/mbsebbs/timecheck.c @@ -37,6 +37,7 @@ #include "../lib/records.h" #include "../lib/clcomm.h" #include "../lib/common.h" +#include "../lib/mberrors.h" #include "timecheck.h" #include "funcs.h" #include "bye.h" @@ -116,7 +117,7 @@ void TimeCheck(void) sleep(3); Syslog('!', "Users time limit exceeded ... user disconnected!"); iExpired = TRUE; - Good_Bye(1); + Good_Bye(MBERR_TIMEOUT); } /* diff --git a/mbsebbs/user.c b/mbsebbs/user.c index a497cfa6..48c0ae1e 100644 --- a/mbsebbs/user.c +++ b/mbsebbs/user.c @@ -39,6 +39,7 @@ #include "../lib/records.h" #include "../lib/common.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "timeout.h" #include "user.h" #include "dispfile.h" @@ -195,7 +196,7 @@ void user() */ WriteError("$Can't open %s", temp); printf("Can't open userfile, run \"newuser\" first"); - ExitClient(0); + ExitClient(MBERR_OK); } fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig); @@ -215,7 +216,7 @@ void user() printf("%s\n", (char *) Language(390)); Syslog('?', "FATAL: Could not find user in BBS users file."); Syslog('?', " and system is using unix accounts\n"); - ExitClient(0); + ExitClient(MBERR_OK); } /* @@ -411,7 +412,7 @@ void user() * A copy of the userrecord is also in the variable exitinfo. */ if (! InitExitinfo()) - Good_Bye(1); + Good_Bye(MBERR_INIT_ERROR); GetLastUser(); StartTime = xstrcpy(GetLocalHM()); diff --git a/mbsetup/Makefile b/mbsetup/Makefile index 67eafe85..e413a9d5 100644 --- a/mbsetup/Makefile +++ b/mbsetup/Makefile @@ -80,7 +80,7 @@ m_marea.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/u m_new.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h stlist.h m_global.h grlist.h m_new.h m_lang.h m_marea.h m_ngroup.h m_protocol.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/clcomm.h ../lib/common.h ../paths.h screen.h mutil.h ledit.h stlist.h m_global.h m_protocol.h m_ticarea.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h stlist.h grlist.h m_global.h m_node.h m_fgroup.h m_farea.h m_archive.h m_ticarea.h -mbsetup.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h m_global.h m_bbs.h m_farea.h m_fgroup.h m_mail.h m_mgroup.h m_hatch.h m_tic.h m_ticarea.h m_magic.h m_fido.h m_lang.h m_archive.h m_virus.h m_tty.h m_limits.h m_users.h m_node.h m_fdb.h m_new.h m_ol.h m_bbslist.h m_safe.h m_protocol.h m_ff.h m_modem.h m_marea.h m_ngroup.h m_service.h m_domain.h m_task.h m_route.h +mbsetup.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h screen.h mutil.h ledit.h m_global.h m_bbs.h m_farea.h m_fgroup.h m_mail.h m_mgroup.h m_hatch.h m_tic.h m_ticarea.h m_magic.h m_fido.h m_lang.h m_archive.h m_virus.h m_tty.h m_limits.h m_users.h m_node.h m_fdb.h m_new.h m_ol.h m_bbslist.h m_safe.h m_protocol.h m_ff.h m_modem.h m_marea.h m_ngroup.h m_service.h m_domain.h m_task.h m_route.h ledit.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h screen.h mutil.h ledit.h m_farea.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h m_global.h m_fgroup.h m_archive.h m_farea.h m_fgroup.h m_ngroup.h m_fido.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h stlist.h m_global.h m_fido.h @@ -89,10 +89,10 @@ m_menu.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/us m_ngroup.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h stlist.h m_global.h m_ngroup.h m_service.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h stlist.h m_global.h m_service.h m_tty.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h stlist.h m_modem.h m_global.h m_tty.h -mutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h +mutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h screen.h mutil.h m_archive.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../paths.h screen.h mutil.h ledit.h stlist.h m_global.h m_archive.h m_fdb.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h m_global.h m_farea.h m_fdb.h -m_global.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h m_node.h m_marea.h m_ticarea.h m_new.h m_global.h +m_global.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/mberrors.h screen.h mutil.h ledit.h m_node.h m_marea.h m_ticarea.h m_new.h m_global.h m_magic.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h stlist.h m_ticarea.h m_global.h m_magic.h m_mgroup.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h stlist.h m_global.h m_node.h m_marea.h m_mgroup.h m_node.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h grlist.h stlist.h m_global.h m_lang.h m_ticarea.h m_marea.h m_node.h diff --git a/mbsetup/m_global.c b/mbsetup/m_global.c index 4459813f..f8702178 100644 --- a/mbsetup/m_global.c +++ b/mbsetup/m_global.c @@ -36,6 +36,7 @@ #include "../lib/records.h" #include "../lib/common.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "screen.h" #include "mutil.h" #include "ledit.h" @@ -69,7 +70,7 @@ void config_check(char *path) if (some_fd == -1) { perror(""); fprintf(stderr, "Fatal, %s/etc/config.data not found, is mbtask running?\n", path); - exit(1); + exit(MBERR_CONFIG_ERROR); } close(some_fd); } diff --git a/mbsetup/mbsetup.c b/mbsetup/mbsetup.c index 8552a90a..7597345b 100644 --- a/mbsetup/mbsetup.c +++ b/mbsetup/mbsetup.c @@ -36,6 +36,7 @@ #include "../lib/records.h" #include "../lib/common.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "screen.h" #include "mutil.h" #include "ledit.h" @@ -130,7 +131,7 @@ static void die(int onsig) WriteError("MBSETUP finished on signal %s", SigName[onsig]); else Syslog(' ', "MBSETUP finished"); - ExitClient(0); + ExitClient(onsig); } @@ -395,7 +396,7 @@ int main(int argc, char *argv[]) pw = getpwuid(geteuid()); if (strcmp(pw->pw_name, (char *)"mbse")) { printf("ERROR: only user \"mbse\" may use this program\n"); - exit(1); + exit(MBERR_INIT_ERROR); } #ifdef MEMWATCH @@ -534,7 +535,7 @@ int main(int argc, char *argv[]) } while (loop == 1); } - die(0); + die(MBERR_OK); return 0; } diff --git a/mbsetup/mutil.c b/mbsetup/mutil.c index 41890835..310d7148 100644 --- a/mbsetup/mutil.c +++ b/mbsetup/mutil.c @@ -34,6 +34,7 @@ #include "../lib/structs.h" #include "../lib/common.h" #include "../lib/clcomm.h" +#include "../lib/mberrors.h" #include "screen.h" #include "mutil.h" @@ -46,7 +47,7 @@ unsigned char readkey(int y, int x, int fg, int bg) if ((ttyfd = open("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { perror("open 9"); - exit(1); + exit(MBERR_TTYIO_ERROR); } Setraw(); @@ -88,7 +89,7 @@ unsigned char testkey(int y, int x) if ((ttyfd = open("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) { perror("open 9"); - exit(1); + exit(MBERR_TTYIO_ERROR); } Setraw(); diff --git a/mbtask/Makefile b/mbtask/Makefile index 4c4191d3..5634f91f 100644 --- a/mbtask/Makefile +++ b/mbtask/Makefile @@ -82,8 +82,8 @@ nodelist.o: ../config.h libs.h ../lib/structs.h taskutil.h nodelist.h scanout.o: ../config.h libs.h ../lib/structs.h taskutil.h scanout.h taskcomm.o: ../config.h libs.h ../lib/structs.h taskstat.h taskregs.h taskdisk.h taskinfo.h taskutil.h taskcomm.h taskinfo.o: ../config.h libs.h ../lib/structs.h taskinfo.h -taskstat.o: ../config.h libs.h ../lib/structs.h taskstat.h callstat.h outstat.h taskutil.h -mbtask.o: ../config.h libs.h ../lib/structs.h ../paths.h signame.h taskstat.h taskutil.h taskregs.h taskcomm.h callstat.h outstat.h nodelist.h ports.h calllist.h ping.h mbtask.h +taskstat.o: ../config.h libs.h ../lib/structs.h ../lib/mberrors.h taskstat.h callstat.h outstat.h taskutil.h +mbtask.o: ../config.h libs.h ../lib/structs.h ../paths.h ../lib/mberrors.h signame.h taskstat.h taskutil.h taskregs.h taskcomm.h callstat.h outstat.h nodelist.h ports.h calllist.h ping.h mbtask.h outstat.o: ../config.h libs.h ../lib/structs.h taskutil.h taskstat.h scanout.h nodelist.h callstat.h ports.h outstat.h signame.o: ../config.h signame.h taskdisk.o: ../config.h libs.h ../lib/structs.h taskdisk.h taskutil.h @@ -91,6 +91,6 @@ taskregs.o: ../config.h libs.h ../lib/structs.h taskstat.h taskregs.h taskutil.h taskutil.o: ../config.h libs.h ../lib/structs.h signame.h scanout.h crc.h taskutil.h ports.o: ../config.h libs.h ../lib/structs.h taskutil.h nodelist.h ports.h calllist.o: ../config.h libs.h ../lib/structs.h taskstat.h taskutil.h callstat.h outstat.h mbtask.h calllist.h -ping.o: ../config.h libs.h ../lib/structs.h taskstat.h taskutil.h ping.h +ping.o: ../config.h libs.h ../lib/structs.h ../lib/mberrors.h taskstat.h taskutil.h ping.h crc.o: ../config.h libs.h crc.h # End of generated dependencies diff --git a/mbtask/mbtask.c b/mbtask/mbtask.c index ff83ead8..a1bb697e 100644 --- a/mbtask/mbtask.c +++ b/mbtask/mbtask.c @@ -32,6 +32,7 @@ #include "libs.h" #include "../lib/structs.h" #include "../paths.h" +#include "../lib/mberrors.h" #include "signame.h" #include "taskstat.h" #include "taskutil.h" @@ -393,7 +394,7 @@ void load_maincfg(void) if ((fp = fopen(cfgfn, "a+")) == NULL) { perror(""); fprintf(stderr, "Can't create %s\n", cfgfn); - exit(2); + exit(MBERR_INIT_ERROR); } fwrite(&CFG, sizeof(CFG), 1, fp); fclose(fp); @@ -434,7 +435,7 @@ void load_taskcfg(void) sprintf(TCFG.isp_ping2, "192.168.1.1"); if ((fp = fopen(tcfgfn, "a+")) == NULL) { tasklog('?', "$Can't create %s", tcfgfn); - die(2); + die(MBERR_INIT_ERROR); } fwrite(&TCFG, sizeof(TCFG), 1, fp); fclose(fp); @@ -493,22 +494,22 @@ pid_t launch(char *cmd, char *opts, char *name, int tasktype) close(0); if (open("/dev/null", O_RDONLY) != 0) { tasklog('?', "$Launch: \"%s\": reopen of stdin to /dev/null failed", buf); - _exit(-1); + _exit(MBERR_EXEC_FAILED); } close(1); if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 1) { tasklog('?', "$Launch: \"%s\": reopen of stdout to /dev/null failed", buf); - _exit(-1); + _exit(MBERR_EXEC_FAILED); } close(2); if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 2) { tasklog('?', "$Launch: \"%s\": reopen of stderr to /dev/null failed", buf); - _exit(-1); + _exit(MBERR_EXEC_FAILED); } errno = 0; rc = execv(vector[0],vector); tasklog('?', "$Launch: execv \"%s\" failed, returned %d", cmd, rc); - _exit(-1); + _exit(MBERR_EXEC_FAILED); default: /* grandchild's daddy's process */ break; @@ -819,7 +820,7 @@ void check_sema(void) * Since the upsdown semafore is permanent, the system WILL go down * there is no point for this program to stay. Signal all tasks and stop. */ - die(SIGTERM); + die(MBERR_UPS_ALARM); } /* @@ -879,7 +880,7 @@ void scheduler(void) */ if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) { tasklog('?', "$Can't create socket"); - die(1); + die(MBERR_INIT_ERROR); } memset(&servaddr, 0, sizeof(servaddr)); @@ -890,7 +891,7 @@ void scheduler(void) close(sock); sock = -1; tasklog('?', "$Can't bind socket %s", spath); - die(1); + die(MBERR_INIT_ERROR); } /* @@ -1273,19 +1274,19 @@ int main(int argc, char **argv) perror(""); printf("can't setuid to mbse\n"); close(ping_isocket); - exit(1); + exit(MBERR_INIT_ERROR); } if (setgid(pw->pw_gid)) { perror(""); printf("can't setgid to bbs\n"); close(ping_isocket); - exit(1); + exit(MBERR_INIT_ERROR); } umask(007); if (locktask(pw->pw_dir)) { close(ping_isocket); - exit(1); + exit(MBERR_NO_PROGLOCK); } sprintf(cfgfn, "%s/etc/config.data", getenv("MBSE_ROOT")); @@ -1324,14 +1325,14 @@ int main(int argc, char **argv) */ if ((pgrp = setpgid(0, 0)) == -1) { tasklog('?', "$setpgid failed"); - die(0); + die(MBERR_INIT_ERROR); } frk = fork(); switch (frk) { case -1: tasklog('?', "$Unable to fork daemon"); - die(0); + die(MBERR_INIT_ERROR); case 0: /* * Starting the deamon child process here. @@ -1352,7 +1353,7 @@ int main(int argc, char **argv) fclose(fp); } tasklog('+', "Starting daemon with pid %d", frk); - exit(0); + exit(MBERR_OK); } /* diff --git a/mbtask/ping.c b/mbtask/ping.c index 0faf2a59..dd3cd587 100644 --- a/mbtask/ping.c +++ b/mbtask/ping.c @@ -31,6 +31,7 @@ #include "../config.h" #include "libs.h" #include "../lib/structs.h" +#include "../lib/mberrors.h" #include "taskstat.h" #include "taskutil.h" #include "ping.h" @@ -432,7 +433,7 @@ void init_pingsocket(void) } else { fprintf(stderr, "socket init failed\n"); } - exit(1); + exit(MBERR_INIT_ERROR); } /* @@ -440,7 +441,7 @@ void init_pingsocket(void) * It would be nice to issue an error message, but to where? */ if (ping_isocket == STDIN_FILENO || ping_isocket == STDOUT_FILENO || ping_isocket == STDERR_FILENO) { - exit(255); + exit(MBERR_GENERAL); } } diff --git a/mbtask/taskstat.c b/mbtask/taskstat.c index f4c6b445..05b82c73 100644 --- a/mbtask/taskstat.c +++ b/mbtask/taskstat.c @@ -31,6 +31,7 @@ #include "../config.h" #include "libs.h" #include "../lib/structs.h" +#include "../lib/mberrors.h" #include "taskstat.h" #include "callstat.h" #include "outstat.h" @@ -119,7 +120,7 @@ void status_init() cnt = read(stat_fd, &status, sizeof(status_r)); if (cnt != sizeof(status_r)) { printf("Error reading status file\n"); - exit(1); + exit(MBERR_INIT_ERROR); } status.startups++; status.laststart = time(NULL); @@ -129,7 +130,7 @@ void status_init() cnt = write(stat_fd, &status, sizeof(status_r)); if (cnt != sizeof(status_r)) { tasklog('?', "$Error rewrite status file\n"); - exit(1); + exit(MBERR_INIT_ERROR); } close(stat_fd); }