Initial revision

This commit is contained in:
Ken Bowley
2001-08-17 05:46:24 +00:00
commit 40420d900a
750 changed files with 177485 additions and 0 deletions

34
mbtask/Makefile.am Normal file
View File

@@ -0,0 +1,34 @@
## Process this file with automake to produce Makefile.in
SUBDIRS = .
EXTRA_DIST = issue
noinst_PROGRAMS = mbtask
mbtask_SOURCES = mbtask.c mbtask.h signame.c signame.h taskutil.c taskutil.h \
taskcomm.c taskcomm.h taskstat.c taskstat.h taskdisk.c taskdisk.h \
taskregs.c taskregs.h taskinfo.c taskinfo.h outstat.c outstat.h \
scanout.c scanout.h nodelist.c nodelist.h callstat.c callstat.h libs.h
LDADD = ../lib/libmemwatch.a
install-exec-local:
@if [ "$(shell whoami)" != "root" ] ; then \
echo; echo " Must be root to install!"; echo; exit 3; \
fi
$(INSTALL) -s -o root -g root -m 6711 mbtask $(bindir)
@if [ -f $(sysconfdir)/mbsed.conf ]; then \
rm $(sysconfdir)/mbsed.conf ; \
fi
@if [ -f $(sysconfdir)/client.conf ]; then \
rm $(sysconfdir)/client.conf ; \
fi
@if [ -f $(bindir)/mbsed ]; then \
rm $(bindir)/mbsed ; \
fi
@if [ ! -f $(sysconfdir)/issue ]; then \
$(INSTALL) -o @OWNER@ -g @GROUP@ -m 0644 issue $(sysconfdir) ; \
echo "$(INSTALL) -o @OWNER@ -g @GROUP@ -m 0644 issue $(sysconfdir)"; \
fi

396
mbtask/Makefile.in Normal file
View File

@@ -0,0 +1,396 @@
# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
AWK = @AWK@
CC = @CC@
COMPRESS = @COMPRESS@
GROUP = @GROUP@
GZIP = @GZIP@
LEX = @LEX@
LOG_COMPRESS = @LOG_COMPRESS@
LOG_COMPRESSEXT = @LOG_COMPRESSEXT@
MAKEINFO = @MAKEINFO@
OWNER = @OWNER@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
VERSION = @VERSION@
YACC = @YACC@
SUBDIRS = .
EXTRA_DIST = issue
noinst_PROGRAMS = mbtask
mbtask_SOURCES = mbtask.c mbtask.h signame.c signame.h taskutil.c taskutil.h taskcomm.c taskcomm.h taskstat.c taskstat.h taskdisk.c taskdisk.h taskregs.c taskregs.h taskinfo.c taskinfo.h outstat.c outstat.h scanout.c scanout.h nodelist.c nodelist.h callstat.c callstat.h libs.h
LDADD = ../lib/libmemwatch.a
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../config.h
CONFIG_CLEAN_FILES =
PROGRAMS = $(noinst_PROGRAMS)
DEFS = @DEFS@ -I. -I$(srcdir) -I..
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
mbtask_OBJECTS = mbtask.o signame.o taskutil.o taskcomm.o taskstat.o \
taskdisk.o taskregs.o taskinfo.o outstat.o scanout.o nodelist.o \
callstat.o
mbtask_LDADD = $(LDADD)
mbtask_DEPENDENCIES = ../lib/libmemwatch.a
mbtask_LDFLAGS =
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
DIST_COMMON = Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
GZIP_ENV = --best
SOURCES = $(mbtask_SOURCES)
OBJECTS = $(mbtask_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .S .c .o .s
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps mbtask/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
mostlyclean-noinstPROGRAMS:
clean-noinstPROGRAMS:
-test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS)
distclean-noinstPROGRAMS:
maintainer-clean-noinstPROGRAMS:
.c.o:
$(COMPILE) -c $<
.s.o:
$(COMPILE) -c $<
.S.o:
$(COMPILE) -c $<
mostlyclean-compile:
-rm -f *.o core *.core
clean-compile:
distclean-compile:
-rm -f *.tab.c
maintainer-clean-compile:
mbtask: $(mbtask_OBJECTS) $(mbtask_DEPENDENCIES)
@rm -f mbtask
$(LINK) $(mbtask_LDFLAGS) $(mbtask_OBJECTS) $(mbtask_LDADD) $(LIBS)
# This directory's subdirectories are mostly independent; you can cd
# into them and run `make' without going through this Makefile.
# To change the values of `make' variables: instead of editing Makefiles,
# (1) if the variable is set in `config.status', edit `config.status'
# (which will cause the Makefiles to be regenerated when you run `make');
# (2) otherwise, pass the desired values on the `make' command line.
@SET_MAKE@
all-recursive install-data-recursive install-exec-recursive \
installdirs-recursive install-recursive uninstall-recursive \
check-recursive installcheck-recursive info-recursive dvi-recursive:
@set fnord $(MAKEFLAGS); amf=$$2; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
list='$(SUBDIRS)'; for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done; \
if test "$$dot_seen" = "no"; then \
$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
fi; test -z "$$fail"
mostlyclean-recursive clean-recursive distclean-recursive \
maintainer-clean-recursive:
@set fnord $(MAKEFLAGS); amf=$$2; \
dot_seen=no; \
rev=''; list='$(SUBDIRS)'; for subdir in $$list; do \
rev="$$subdir $$rev"; \
test "$$subdir" = "." && dot_seen=yes; \
done; \
test "$$dot_seen" = "no" && rev=". $$rev"; \
target=`echo $@ | sed s/-recursive//`; \
for subdir in $$rev; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done && test -z "$$fail"
tags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
done
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP)
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
here=`pwd` && cd $(srcdir) \
&& mkid -f$$here/ID $$unique $(LISP)
TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SUBDIRS)'; for subdir in $$list; do \
if test "$$subdir" = .; then :; else \
test -f $$subdir/TAGS && tags="$$tags -i $$here/$$subdir/TAGS"; \
fi; \
done; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
mostlyclean-tags:
clean-tags:
distclean-tags:
-rm -f TAGS ID
maintainer-clean-tags:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = mbtask
distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
for subdir in $(SUBDIRS); do \
if test "$$subdir" = .; then :; else \
test -d $(distdir)/$$subdir \
|| mkdir $(distdir)/$$subdir \
|| exit 1; \
chmod 777 $(distdir)/$$subdir; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$(top_distdir) distdir=../$(distdir)/$$subdir distdir) \
|| exit 1; \
fi; \
done
callstat.o: callstat.c libs.h ../config.h ../lib/memwatch.h \
../lib/structs.h taskutil.h callstat.h
mbtask.o: mbtask.c libs.h ../config.h ../lib/memwatch.h ../lib/structs.h \
signame.h taskstat.h taskutil.h taskregs.h taskcomm.h outstat.h \
nodelist.h mbtask.h
nodelist.o: nodelist.c libs.h ../config.h ../lib/memwatch.h \
../lib/structs.h taskutil.h nodelist.h
outstat.o: outstat.c libs.h ../config.h ../lib/memwatch.h \
../lib/structs.h taskutil.h scanout.h nodelist.h callstat.h \
outstat.h
scanout.o: scanout.c libs.h ../config.h ../lib/memwatch.h \
../lib/structs.h taskutil.h scanout.h
signame.o: signame.c signame.h
taskcomm.o: taskcomm.c libs.h ../config.h ../lib/memwatch.h taskstat.h \
taskregs.h taskdisk.h taskinfo.h taskutil.h taskcomm.h
taskdisk.o: taskdisk.c libs.h ../config.h ../lib/memwatch.h taskdisk.h \
taskutil.h
taskinfo.o: taskinfo.c libs.h ../config.h ../lib/memwatch.h \
../lib/structs.h taskinfo.h
taskregs.o: taskregs.c libs.h ../config.h ../lib/memwatch.h taskstat.h \
taskregs.h taskutil.h
taskstat.o: taskstat.c libs.h ../config.h ../lib/memwatch.h \
../lib/structs.h taskstat.h outstat.h taskutil.h
taskutil.o: taskutil.c libs.h ../config.h ../lib/memwatch.h \
../lib/structs.h signame.h scanout.h taskutil.h
info-am:
info: info-recursive
dvi-am:
dvi: dvi-recursive
check-am: all-am
check: check-recursive
installcheck-am:
installcheck: installcheck-recursive
install-exec-am: install-exec-local
install-exec: install-exec-recursive
install-data-am:
install-data: install-data-recursive
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-recursive
uninstall-am:
uninstall: uninstall-recursive
all-am: Makefile $(PROGRAMS)
all-redirect: all-recursive
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs: installdirs-recursive
installdirs-am:
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-noinstPROGRAMS mostlyclean-compile \
mostlyclean-tags mostlyclean-generic
mostlyclean: mostlyclean-recursive
clean-am: clean-noinstPROGRAMS clean-compile clean-tags clean-generic \
mostlyclean-am
clean: clean-recursive
distclean-am: distclean-noinstPROGRAMS distclean-compile distclean-tags \
distclean-generic clean-am
distclean: distclean-recursive
maintainer-clean-am: maintainer-clean-noinstPROGRAMS \
maintainer-clean-compile maintainer-clean-tags \
maintainer-clean-generic distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-recursive
.PHONY: mostlyclean-noinstPROGRAMS distclean-noinstPROGRAMS \
clean-noinstPROGRAMS maintainer-clean-noinstPROGRAMS \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile install-data-recursive \
uninstall-data-recursive install-exec-recursive \
uninstall-exec-recursive installdirs-recursive uninstalldirs-recursive \
all-recursive check-recursive installcheck-recursive info-recursive \
dvi-recursive mostlyclean-recursive distclean-recursive clean-recursive \
maintainer-clean-recursive tags tags-recursive mostlyclean-tags \
distclean-tags clean-tags maintainer-clean-tags distdir info-am info \
dvi-am dvi check check-am installcheck-am installcheck \
install-exec-local install-exec-am install-exec install-data-am \
install-data install-am install uninstall-am uninstall all-redirect \
all-am all installdirs-am installdirs mostlyclean-generic \
distclean-generic clean-generic maintainer-clean-generic clean \
mostlyclean distclean maintainer-clean
install-exec-local:
@if [ "$(shell whoami)" != "root" ] ; then \
echo; echo " Must be root to install!"; echo; exit 3; \
fi
$(INSTALL) -s -o root -g root -m 6711 mbtask $(bindir)
@if [ -f $(sysconfdir)/mbsed.conf ]; then \
rm $(sysconfdir)/mbsed.conf ; \
fi
@if [ -f $(sysconfdir)/client.conf ]; then \
rm $(sysconfdir)/client.conf ; \
fi
@if [ -f $(bindir)/mbsed ]; then \
rm $(bindir)/mbsed ; \
fi
@if [ ! -f $(sysconfdir)/issue ]; then \
$(INSTALL) -o @OWNER@ -g @GROUP@ -m 0644 issue $(sysconfdir) ; \
echo "$(INSTALL) -o @OWNER@ -g @GROUP@ -m 0644 issue $(sysconfdir)"; \
fi
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

135
mbtask/callstat.c Normal file
View File

@@ -0,0 +1,135 @@
/*****************************************************************************
*
* File ..................: mbtask/callstat.c
* Purpose ...............: Read mailer last call status
* Last modification date : 08-Jul-2001
*
*****************************************************************************
* Copyright (C) 1997-2001
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MBSE BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MBSE BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
#include "libs.h"
#include "../lib/structs.h"
#include "taskutil.h"
#include "callstat.h"
extern struct sysconfig CFG;
char *stsname(faddr *);
char *stsname(faddr *addr)
{
static char buf[PATH_MAX];
char *p, *domain=NULL;
char zpref[8];
int i;
sprintf(buf, "%s", CFG.outbound);
if (CFG.addr4d) {
if ((addr->zone == 0) || (addr->zone == CFG.aka[0].zone))
zpref[0] = '\0';
else
sprintf(zpref, ".%03x", addr->zone);
} else {
/*
* If we got a 5d address we use the given domain, if
* we got a 4d address, we look for a matching domain name.
*/
if (addr->domain)
domain = xstrcpy(addr->domain);
else
for (i = 0; i < 40; i++)
if (CFG.aka[i].zone == addr->zone) {
domain = xstrcpy(CFG.aka[i].domain);
break;
}
if ((domain != NULL) && (strlen(CFG.aka[0].domain) != 0) &&
(strcasecmp(domain,CFG.aka[0].domain) != 0)) {
if ((p = strrchr(buf,'/')))
p++;
else
p = buf;
strcpy(p, domain);
for (; *p; p++)
*p = tolower(*p);
for (i = 0; i < 40; i++)
if ((strlen(CFG.aka[i].domain)) &&
(strcasecmp(CFG.aka[i].domain, domain) == 0))
break;
/*
* The default zone must be the first one in the
* setup, other zones get the hexadecimal zone
* number appended.
*/
if (CFG.aka[i].zone == addr->zone)
zpref[0] = '\0';
else
sprintf(zpref, ".%03x", addr->zone);
} else {
/*
* this is our primary domain
*/
if ((addr->zone == 0) || (addr->zone == CFG.aka[0].zone))
zpref[0]='\0';
else
sprintf(zpref,".%03x",addr->zone);
}
}
p = buf + strlen(buf);
if (addr->point)
sprintf(p,"%s/%04x%04x.pnt/%08x.sts", zpref,addr->net,addr->node,addr->point);
else
sprintf(p,"%s/%04x%04x.sts",zpref,addr->net,addr->node);
if (domain)
free(domain);
return buf;
}
callstat *getstatus(faddr *addr)
{
static callstat cst;
FILE *fp;
cst.trytime = 0L;
cst.tryno = 0;
cst.trystat = 0;
if ((fp = fopen(stsname(addr), "r"))) {
fread(&cst, sizeof(callstat), 1, fp);
fclose(fp);
}
return &cst;
}

26
mbtask/callstat.h Normal file
View File

@@ -0,0 +1,26 @@
#ifndef CALLSTAT_H
#define CALLSTAT_H
#define ST_PORTERR 1
#define ST_NOCONN 2
#define ST_MDMERR 3
#define ST_LOCKED 4
#define ST_LOOKUP 6
#define ST_NOCALL7 7
#define ST_NOCALL8 8
#define ST_NOPORT 9
#define ST_NOTZMH 10
#define ST_SESSION 30
typedef struct _callstat {
time_t trytime;
int tryno;
int trystat;
} callstat;
callstat *getstatus(faddr*);
#endif

12
mbtask/issue Normal file
View File

@@ -0,0 +1,12 @@
.--. Welcome at MBSE BBS Professional
|o_o | --------------------------------
|:_/ |
// \\ \\ Abandon all hope ye who have entered cyberspace.
(| | )
/'\\_ _/\`\\
\\___)=(___/
Powered by Linux.
To start the bbs login with "bbs" without quotes.

166
mbtask/libs.h Normal file
View File

@@ -0,0 +1,166 @@
/*****************************************************************************
*
* File ..................: libs.h
* Purpose ...............: Libraries include list
* Last modification date : 05-jul-2001
*
*****************************************************************************
* Copyright (C) 1997-2001
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 Internet: mbse@user.sourceforge.net
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MBSE BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MBSE BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
#ifndef _LIBS_H
#define _LIBS_H
#define TRUE 1
#define FALSE 0
#define SS_BUFSIZE 1024 /* Streams socket buffersize */
#include "../config.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/poll.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <string.h>
#include <errno.h>
#include <sys/fcntl.h>
#include <sys/utsname.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <stdarg.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/vfs.h>
#include <wait.h>
#include <pwd.h>
#include <stddef.h>
#include <fcntl.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include "../lib/memwatch.h"
/*
* Some older systems don;t have this
*/
#ifndef ICMP_FILTER
#define ICMP_FILTER 1
struct icmp_filter {
u_int32_t data;
};
#endif
/* some older glibc versions seem to lack this. */
# ifndef IP_PKTINFO
# define IP_PKTINFO 8
# endif
# ifndef CMSG_LEN
/* ---- from glibc 2.1.2 */
/* Ancillary data object manipulation macros. */
# if !defined __STRICT_ANSI__ && defined __GNUC__ && __GNUC__ >= 2
# define CMSG_DATA(cmsg) ((cmsg)->__cmsg_data)
# else
# define CMSG_DATA(cmsg) ((unsigned char *) ((struct cmsghdr *) (cmsg) + 1))
# endif
# define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr (mhdr, cmsg)
# define CMSG_FIRSTHDR(mhdr) \
((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) \
? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) NULL)
# define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) \
& ~(sizeof (size_t) - 1))
# define CMSG_SPACE(len) (CMSG_ALIGN (len) \
+ CMSG_ALIGN (sizeof (struct cmsghdr)))
# define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
extern struct cmsghdr *__cmsg_nxthdr __P ((struct msghdr *__mhdr,
struct cmsghdr *__cmsg));
# ifdef __USE_EXTERN_INLINES
# ifndef _EXTERN_INLINE
# define _EXTERN_INLINE extern __inline
# endif
_EXTERN_INLINE struct cmsghdr *
__cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg) __THROW
{
if ((size_t) __cmsg->cmsg_len < sizeof (struct cmsghdr))
/* The kernel header does this so there may be a reason. */
return 0;
__cmsg = (struct cmsghdr *) ((unsigned char *) __cmsg
+ CMSG_ALIGN (__cmsg->cmsg_len));
if ((unsigned char *) (__cmsg + 1) >= ((unsigned char *) __mhdr->msg_control
+ __mhdr->msg_controllen)
|| ((unsigned char *) __cmsg + CMSG_ALIGN (__cmsg->cmsg_len)
>= ((unsigned char *) __mhdr->msg_control + __mhdr->msg_controllen)))
/* No more entries. */
return 0;
return __cmsg;
}
# endif /* Use `extern inline'. */
# endif
/* A macro to extract the pointer to the address of a struct sockaddr (_in or _in6) */
#define SOCKA_A4(a) ((void *)&((struct sockaddr_in *)(a))->sin_addr)
/* Some old libs don't have socklen_t */
#ifndef socklen_t
#define socklen_t unsigned int
#endif
#pragma pack(1)
#define MAXNAME 35
#define MAXUFLAGS 16
typedef struct _faddr {
char *name;
unsigned int point;
unsigned int node;
unsigned int net;
unsigned int zone;
char *domain;
} faddr;
#endif

1440
mbtask/mbtask.c Normal file

File diff suppressed because it is too large Load Diff

52
mbtask/mbtask.h Normal file
View File

@@ -0,0 +1,52 @@
#ifndef _MBTASK_H
#define _MBTASK_H
typedef enum {CALL_POTS, CALL_ISDN, CALL_IP, MBFIDO, MBINDEX, MBFILE} TASKTYPE;
/*
* Running tasks information
*/
typedef struct _onetask {
char name[16]; /* Name of the task */
char cmd[PATH_MAX]; /* Command to binary */
char opts[128]; /* Commandline opts */
int tasktype; /* Type of task */
pid_t pid; /* Pid of task */
int running; /* Running or not */
int status; /* Waitpid status */
int rc; /* Exit code */
} onetask;
/*
* Logging flagbits, ' ' ? ! + -
*/
#define DLOG_ALLWAYS 0x00000001
#define DLOG_ERROR 0x00000002
#define DLOG_ATTENT 0x00000004
#define DLOG_NORMAL 0x00000008
#define DLOG_VERBOSE 0x00000010
time_t file_time(char *);
void load_maincfg(void);
void load_taskcfg(void);
pid_t launch(char *, char *, char *, int);
int runtasktype(int);
int checktasks(int);
void die(int);
static int icmp4_errcmp(char *, int, struct in_addr *, char *, int, int);
unsigned short get_rand16(void);
int ping_send(struct in_addr);
int ping_receive(struct in_addr);
void scheduler(void);
int locktask(char *);
void ulocktask(void);
#endif

572
mbtask/nodelist.c Normal file
View File

@@ -0,0 +1,572 @@
/*****************************************************************************
*
* File ..................: nodelist.c
* Purpose ...............: Read nodelists information
* Last modification date : 06-Jul-2001
*
*****************************************************************************
* Copyright (C) 1997-2001
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MBSE BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MBSE BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
#include "libs.h"
#include "../lib/structs.h"
#include "taskutil.h"
#include "nodelist.h"
#define NULLDOMAIN "nulldomain"
struct _pkey pkey[] = {
{(char *)"Down", NL_NODE, NL_DOWN},
{(char *)"Hold", NL_NODE, NL_HOLD},
{(char *)"Region", NL_REGION, NL_REGION},
{(char *)"Host", NL_HOST, NL_HOST},
{(char *)"Hub", NL_HUB, NL_HUB},
{(char *)"Point", NL_POINT, NL_POINT},
{(char *)"Pvt", NL_NODE, NL_NODE},
{NULL, 0, 0}
};
struct _okey okey[] = {
{(char *)"CM", OL_CM},
{(char *)"MO", OL_MO},
{(char *)"LO", OL_LO},
{(char *)"MN", OL_MN},
{NULL, 0}
};
struct _fkey fkey[] = {
{(char *)"V22", NL_V22},
{(char *)"V29", NL_V29},
{(char *)"V32", NL_V32},
{(char *)"V32B",NL_V32B | NL_V32},
{(char *)"V34", NL_V34},
{(char *)"V42", NL_V42 | NL_MNP},
{(char *)"V42B",NL_V42B | NL_V42 | NL_MNP},
{(char *)"MNP", NL_MNP},
{(char *)"H96", NL_H96},
{(char *)"HST", NL_HST | NL_MNP},
{(char *)"H14", NL_H14 | NL_HST | NL_MNP},
{(char *)"H16", NL_H16 | NL_H14 | NL_HST | NL_MNP | NL_V42 | NL_V42B},
{(char *)"MAX", NL_MAX},
{(char *)"PEP", NL_PEP},
{(char *)"CSP", NL_CSP},
{(char *)"V32T",NL_V32T | NL_V32B | NL_V32},
{(char *)"VFC", NL_VFC},
{(char *)"ZYX", NL_ZYX | NL_V32B | NL_V32 | NL_V42B | NL_V42 | NL_MNP},
{(char *)"X2C", NL_X2C | NL_X2S | NL_V34},
{(char *)"X2S", NL_X2S | NL_V34},
{(char *)"V90C",NL_V90C | NL_V90S | NL_V34},
{(char *)"V90S",NL_V90S | NL_V34},
{(char *)"Z19", NL_Z19 | NL_V32B | NL_V32 | NL_V42B | NL_V42 | NL_MNP | NL_ZYX},
{NULL, 0}
};
struct _xkey xkey [] = {
{(char *)"XA", RQ_XA},
{(char *)"XB", RQ_XB},
{(char *)"XC", RQ_XC},
{(char *)"XP", RQ_XP},
{(char *)"XR", RQ_XR},
{(char *)"XW", RQ_XW},
{(char *)"XX", RQ_XX},
{NULL, 0}
};
struct _dkey dkey [] = {
{(char *)"V110L", ND_V110L},
{(char *)"V110H", ND_V110H},
{(char *)"V120L", ND_V120L},
{(char *)"V120H", ND_V120H},
{(char *)"X75", ND_X75},
{NULL, 0}
};
struct _ikey ikey [] = {
{(char *)"IBN", IP_IBN},
{(char *)"IFC", IP_IFC},
{(char *)"ITN", IP_ITN},
{(char *)"IVM", IP_IVM},
{(char *)"IP", IP_IP},
{(char *)"IFT", IP_IFT},
{NULL, 0}
};
extern struct sysconfig CFG;
int initnl(void)
{
int rc = 0;
FILE *dbf, *fp;
char *filexnm, *path;
struct _nlfil fdx;
filexnm = xstrcpy(CFG.nodelists);
filexnm = xstrcat(filexnm,(char *)"/node.files");
if ((dbf = fopen(filexnm, "r")) == NULL) {
tasklog('?', "$Can't open %s", filexnm);
rc = 101;
} else {
path = calloc(PATH_MAX, sizeof(char));
while (fread(&fdx, sizeof(fdx), 1, dbf) == 1) {
sprintf(path, "%s/%s", CFG.nodelists, fdx.filename);
if ((fp = fopen(path, "r")) == NULL) {
tasklog('?', "$Can't open %s", path);
rc = 101;
} else {
fclose(fp);
}
}
fclose(dbf);
free(path);
}
free(filexnm);
return rc;
}
int comp_node(struct _nlidx, struct _ixentry);
int comp_node(struct _nlidx fap1, struct _ixentry fap2)
{
if (fap1.zone != fap2.zone)
return (fap1.zone - fap2.zone);
else if (fap1.net != fap2.net)
return (fap1.net - fap2.net);
else if (fap1.node != fap2.node)
return (fap1.node - fap2.node);
else
return (fap1.point - fap2.point);
}
node *getnlent(faddr *addr)
{
FILE *fp;
static node nodebuf;
static char buf[256], *p, *q;
struct _ixentry xaddr;
int i, j, Found = FALSE;
int ixflag, stdflag;
char *mydomain, *path;
struct _nlfil fdx;
struct _nlidx ndx;
long lowest, highest, current;
tasklog('s', "getnlent: %s", ascfnode(addr,0xff));
mydomain = xstrcpy(CFG.aka[0].domain);
if (mydomain == NULL)
mydomain = (char *)NULLDOMAIN;
nodebuf.addr.domain = NULL;
nodebuf.addr.zone = 0;
nodebuf.addr.net = 0;
nodebuf.addr.node = 0;
nodebuf.addr.point = 0;
nodebuf.addr.name = NULL;
nodebuf.upnet = 0;
nodebuf.upnode = 0;
nodebuf.region = 0;
nodebuf.type = 0;
nodebuf.pflag = 0;
nodebuf.name = NULL;
nodebuf.location = NULL;
nodebuf.sysop = NULL;
nodebuf.phone = NULL;
nodebuf.speed = 0;
nodebuf.mflags = 0L;
nodebuf.oflags = 0L;
nodebuf.xflags = 0L;
nodebuf.iflags = 0L;
nodebuf.dflags = 0L;
nodebuf.uflags[0] = NULL;
if (addr == NULL)
goto retdummy;
if (addr->zone == 0)
addr->zone = CFG.aka[0].zone;
xaddr.zone = addr->zone;
nodebuf.addr.zone = addr->zone;
xaddr.net = addr->net;
nodebuf.addr.net = addr->net;
xaddr.node = addr->node;
nodebuf.addr.node = addr->node;
xaddr.point = addr->point;
nodebuf.addr.point = addr->point;
if (initnl())
goto retdummy;
/*
* First, lookup node in index. NOTE -- NOT 5D YET
*/
path = calloc(128, sizeof(char));
sprintf(path, "%s/%s", CFG.nodelists, "node.index");
if ((fp = fopen(path, "r")) == NULL) {
tasklog('?', "$Can't open %s", path);
free(path);
goto retdummy;
}
fseek(fp, 0, SEEK_END);
highest = ftell(fp) / sizeof(ndx);
lowest = 0;
while (TRUE) {
current = ((highest - lowest) / 2) + lowest;
fseek(fp, current * sizeof(ndx), SEEK_SET);
if (fread(&ndx, sizeof(ndx), 1, fp) != 1)
break;
if (comp_node(ndx, xaddr) == 0) {
Found = TRUE;
break;
}
if (comp_node(ndx, xaddr) < 0)
lowest = current;
else
highest = current;
if ((highest - lowest) <= 1)
break;
}
fclose(fp);
if (!Found) {
free(path);
goto retdummy;
}
sprintf(path, "%s/%s", CFG.nodelists, "node.files");
if ((fp = fopen(path, "r")) == NULL) {
tasklog('?', "$Can't open %s", path);
free(path);
goto retdummy;
}
/*
* Get filename from node.files
*/
for (i = 0; i < (ndx.fileno +1); i++)
fread(&fdx, sizeof(fdx), 1, fp);
fclose(fp);
/* CHECK DOMAIN HERE */
/*
* Open and read in real nodelist
*/
sprintf(path, "%s/%s", CFG.nodelists, fdx.filename);
if ((fp = fopen(path, "r")) == NULL) {
tasklog('?', "$Can't open %s", path);
free(path);
goto retdummy;
}
free(path);
if (fseek(fp, ndx.offset, SEEK_SET) != 0) {
tasklog('?', "$Seek failed for nodelist entry");
fclose(fp);
goto retdummy;
}
if (fgets(buf, sizeof(buf)-1, fp) == NULL) {
tasklog('?', "$fgets failed for nodelist entry");
fclose(fp);
goto retdummy;
}
fclose(fp);
nodebuf.type = ndx.type;
nodebuf.pflag = ndx.pflag;
if (*(p = buf + strlen(buf) -1) == '\n')
*p = '\0';
if (*(p = buf + strlen(buf) -1) == '\r')
*p = '\0';
for (p = buf; *p; p++)
if (*p == '_')
*p = ' ';
p = buf;
if ((q = strchr(p,',')))
*q++ = '\0';
p = q;
if (p == NULL)
goto badsyntax;
if ((q=strchr(p,',')))
*q++ = '\0';
p = q;
if (p == NULL)
goto badsyntax;
if ((q=strchr(p,',')))
*q++ = '\0';
nodebuf.name = p;
p = q;
if (p == NULL)
goto badsyntax;
if ((q=strchr(p,',')))
*q++ = '\0';
nodebuf.location = p;
p = q;
if (p == NULL)
goto badsyntax;
if ((q=strchr(p,',')))
*q++ = '\0';
nodebuf.sysop = p;
p = q;
if (p == NULL)
goto badsyntax;
if ((q=strchr(p,',')))
*q++ = '\0';
if (strcasecmp(p, "-Unpublished-") == 0)
nodebuf.phone = NULL;
else
nodebuf.phone = p;
p = q;
if (p == NULL)
goto badsyntax;
if ((q=strchr(p,',')))
*q++ = '\0';
nodebuf.speed = atoi(p);
/*
* Process the nodelist flags.
*/
ixflag = 0;
stdflag = TRUE;
for (p = q; p; p = q) {
if ((q = strchr(p, ',')))
*q++ = '\0';
if ((strncasecmp(p, "U", 1) == 0) && (strlen(p) == 1)) {
stdflag = FALSE;
} else {
/*
* Experimental: process authorized flags and
* User flags both as authorized.
*/
for (j = 0; fkey[j].key; j++)
if (strcasecmp(p, fkey[j].key) == 0)
nodebuf.mflags |= fkey[j].flag;
for (j = 0; okey[j].key; j++)
if (strcasecmp(p, okey[j].key) == 0)
nodebuf.oflags |= okey[j].flag;
for (j = 0; dkey[j].key; j++)
if (strcasecmp(p, dkey[j].key) == 0)
nodebuf.dflags |= dkey[j].flag;
for (j = 0; ikey[j].key; j++)
if (strncasecmp(p, ikey[j].key, strlen(ikey[j].key)) == 0)
nodebuf.iflags |= ikey[j].flag;
for (j = 0; xkey[j].key; j++)
if (strcasecmp(p, xkey[j].key) == 0)
nodebuf.xflags |= xkey[j].flag;
if (!stdflag) {
if (ixflag < MAXUFLAGS) {
nodebuf.uflags[ixflag++] = p;
if (ixflag < MAXUFLAGS)
nodebuf.uflags[ixflag] = NULL;
}
}
}
}
nodebuf.addr.name = nodebuf.sysop;
nodebuf.addr.domain = xstrcpy(fdx.domain);
nodebuf.upnet = ndx.upnet;
nodebuf.upnode = ndx.upnode;
nodebuf.region = ndx.region;
if (addr->domain == NULL)
addr->domain = xstrcpy(nodebuf.addr.domain);
moflags(nodebuf.mflags);
diflags(nodebuf.dflags);
ipflags(nodebuf.iflags);
olflags(nodebuf.oflags);
free(mydomain);
return &nodebuf;
badsyntax:
tasklog('?', "nodelist %d offset +%lu: bad syntax in line \"%s\"",
ndx.fileno, (unsigned long)ndx.offset, buf);
/* fallthrough */
retdummy:
memset(&nodebuf, 0, sizeof(nodebuf));
nodebuf.pflag = NL_DUMMY;
nodebuf.name = (char *)"Unknown";
nodebuf.location = (char *)"Nowhere";
nodebuf.sysop = (char *)"Sysop";
nodebuf.phone = NULL;
nodebuf.speed = 2400;
free(mydomain);
return &nodebuf;
}
void olflags(unsigned long flags)
{
char *t;
t = xstrcpy((char *)"Mailer flags :");
if (flags & OL_CM)
t = xstrcat(t, (char *)" CM");
if (flags & OL_MO)
t = xstrcat(t, (char *)" MO");
if (flags & OL_LO)
t = xstrcat(t, (char *)" LO");
if (flags & OL_MN)
t = xstrcat(t, (char *)" MN");
tasklog('s', "%s", t);
free(t);
}
void moflags(unsigned long flags)
{
char *t;
if (!flags)
return;
t = xstrcpy((char *)"Modem flags :");
if (flags & NL_V22)
t = xstrcat(t, (char *)" V22");
if (flags & NL_V29)
t = xstrcat(t, (char *)" V29");
if (flags & NL_V32)
t = xstrcat(t, (char *)" V32");
if (flags & NL_V32B)
t = xstrcat(t, (char *)" V32B");
if (flags & NL_V34)
t = xstrcat(t, (char *)" V34");
if (flags & NL_V42)
t = xstrcat(t, (char *)" V42");
if (flags & NL_V42B)
t = xstrcat(t, (char *)" V42B");
if (flags & NL_MNP)
t = xstrcat(t, (char *)" MNP");
if (flags & NL_H96)
t = xstrcat(t, (char *)" H96");
if (flags & NL_HST)
t = xstrcat(t, (char *)" HST");
if (flags & NL_H14)
t = xstrcat(t, (char *)" H14");
if (flags & NL_H16)
t = xstrcat(t, (char *)" H16");
if (flags & NL_MAX)
t = xstrcat(t, (char *)" MAX");
if (flags & NL_PEP)
t = xstrcat(t, (char *)" PEP");
if (flags & NL_CSP)
t = xstrcat(t, (char *)" CSP");
if (flags & NL_V32T)
t = xstrcat(t, (char *)" V32T");
if (flags & NL_VFC)
t = xstrcat(t, (char *)" VFC");
if (flags & NL_ZYX)
t = xstrcat(t, (char *)" ZYX");
if (flags & NL_X2C)
t = xstrcat(t, (char *)" X2C");
if (flags & NL_X2S)
t = xstrcat(t, (char *)" X2S");
if (flags & NL_V90C)
t = xstrcat(t, (char *)" V90C");
if (flags & NL_V90S)
t = xstrcat(t, (char *)" V90S");
tasklog('s', "%s", t);
free(t);
}
void diflags(unsigned long flags)
{
char *t;
if (!flags)
return;
t = xstrcpy((char *)"ISDN flags :");
if (flags & ND_V110L)
t = xstrcat(t, (char *)" V110L");
if (flags & ND_V110H)
t = xstrcat(t, (char *)" V110H");
if (flags & ND_V120L)
t = xstrcat(t, (char *)" V120L");
if (flags & ND_V120H)
t = xstrcat(t, (char *)" V120H");
if (flags & ND_X75)
t = xstrcat(t, (char *)" X75");
tasklog('s', "%s", t);
free(t);
}
void ipflags(unsigned long flags)
{
char *t;
if (!flags)
return;
t = xstrcpy((char *)"TCP/IP flags :");
if (flags & IP_IBN)
t = xstrcat(t, (char *)" IBN");
if (flags & IP_IFC)
t = xstrcat(t, (char *)" IFC");
if (flags & IP_ITN)
t = xstrcat(t, (char *)" ITN");
if (flags & IP_IVM)
t = xstrcat(t, (char *)" IVM");
if (flags & IP_IP)
t = xstrcat(t, (char *)" IP");
tasklog('s', "%s", t);
free(t);
}

189
mbtask/nodelist.h Normal file
View File

@@ -0,0 +1,189 @@
#ifndef _NODELIST_H
#define _NODELIST_H
/*
#include "../config.h"
#pragma pack(1)
*/
#define MAXNAME 35
#define MAXUFLAGS 16
/*
* Analogue Modem flag values, order is important, first the
* compresion capabilities, then the linespeeds. This is late
* tested by portsel to find the fastest common connection
* speed for a given line if you have multiple dialout modems.
*/
#define NL_MNP 0x00000001L
#define NL_V42 0x00000002L
#define NL_V42B 0x00000004L
#define NL_V22 0x00000008L
#define NL_V29 0x00000010L
#define NL_V32 0x00000020L
#define NL_H96 0x00000040L
#define NL_HST 0x00000080L
#define NL_MAX 0x00000100L
#define NL_PEP 0x00000200L
#define NL_CSP 0x00000400L
#define NL_V32B 0x00000800L
#define NL_H14 0x00001000L
#define NL_V32T 0x00002000L
#define NL_H16 0x00004000L
#define NL_ZYX 0x00008000L
#define NL_Z19 0x00010000L
#define NL_VFC 0x00020000L
#define NL_V34 0x00040000L
#define NL_X2C 0x00080000L
#define NL_X2S 0x00100000L
#define NL_V90C 0x00200000L
#define NL_V90S 0x00400000L
/*
* ISDN Flags
*/
#define ND_V110L 0x00000001L
#define ND_V110H 0x00000002L
#define ND_V120L 0x00000004L
#define ND_V120H 0x00000008L
#define ND_X75 0x00000010L
/*
* TCP/IP flags
*/
#define IP_IBN 0x00000001L
#define IP_IFC 0x00000002L
#define IP_ITN 0x00000004L
#define IP_IVM 0x00000008L
#define IP_IP 0x00000010L
#define IP_IFT 0x00000020L
/*
* Online special flags
*/
#define OL_CM 0x00000001L
#define OL_MO 0x00000002L
#define OL_LO 0x00000004L
#define OL_MN 0x00000008L
/*
* Request flags
*/
#define RQ_RQMODE 0x0000000fL
#define RQ_RQ_BR 0x00000001L
#define RQ_RQ_BU 0x00000002L
#define RQ_RQ_WR 0x00000004L
#define RQ_RQ_WU 0x00000008L
#define RQ_XA (RQ_RQ_BR | RQ_RQ_BU | RQ_RQ_WR | RQ_RQ_WU)
#define RQ_XB (RQ_RQ_BR | RQ_RQ_BU | RQ_RQ_WR )
#define RQ_XC (RQ_RQ_BR | RQ_RQ_WR | RQ_RQ_WU)
#define RQ_XP (RQ_RQ_BR | RQ_RQ_BU )
#define RQ_XR (RQ_RQ_BR | RQ_RQ_WR )
#define RQ_XW ( RQ_RQ_WR )
#define RQ_XX ( RQ_RQ_WR | RQ_RQ_WU)
/*
* Nodelist entry
*/
typedef struct _node {
faddr addr; /* Node address */
unsigned short upnet; /* Uplink netnumber */
unsigned short upnode; /* Uplink nodenumber */
unsigned short region; /* Region belongin to */
unsigned char type;
unsigned char pflag;
char *name; /* System name */
char *location; /* System location */
char *sysop; /* Sysop name */
char *phone; /* Phone number */
unsigned speed; /* Baudrate */
unsigned long mflags; /* Modem flags */
unsigned long dflags; /* ISDN flags */
unsigned long iflags; /* TCP-IP flags */
unsigned long oflags; /* Online flags */
unsigned long xflags; /* Request flags */
char *uflags[MAXUFLAGS]; /* User flags */
} node;
extern struct _fkey {
char *key;
unsigned long flag;
} fkey[];
extern struct _dkey {
char *key;
unsigned long flag;
} dkey[];
extern struct _ikey {
char *key;
unsigned long flag;
} ikey[];
extern struct _okey {
char *key;
unsigned long flag;
} okey[];
extern struct _xkey {
char *key;
unsigned long flag;
} xkey[];
extern struct _nodelist {
char *domain;
FILE *fp;
} *nodevector;
struct _ixentry {
unsigned short zone;
unsigned short net;
unsigned short node;
unsigned short point;
};
extern struct _pkey {
char *key;
unsigned char type;
unsigned char pflag;
} pkey[];
int initnl(void);
node *getnlent(faddr *);
void olflags(unsigned long);
void moflags(unsigned long);
void diflags(unsigned long);
void ipflags(unsigned long);
#endif

249
mbtask/outstat.c Normal file
View File

@@ -0,0 +1,249 @@
/*****************************************************************************
*
* File ..................: mbtask/outstat.c
* Purpose ...............: Scan mail outbound status
* Last modification date : 08-Jul-2001
*
*****************************************************************************
* Copyright (C) 1997-2001
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MBSE BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MBSE BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
#include "libs.h"
#include "../lib/structs.h"
#include "taskutil.h"
#include "scanout.h"
#include "nodelist.h"
#include "callstat.h"
#include "outstat.h"
extern int do_quiet;
extern struct sysconfig CFG;
static struct _alist
{
struct _alist *next; /* Next entry */
faddr addr; /* Node address */
int flavors; /* ORed flavors of mail/files */
time_t time; /* Date/time of mail/files */
off_t size; /* Total size of mail/files */
callstat cst; /* Last call status */
unsigned long olflags; /* Nodelist online flags */
unsigned long moflags; /* Nodelist modem flags */
unsigned long diflags; /* Nodelist ISDN flags */
unsigned long ipflags; /* Nodelist TCP/IP flags */
} *alist = NULL;
#define F_NORMAL 1
#define F_CRASH 2
#define F_IMM 4
#define F_HOLD 8
#define F_FREQ 16
#define F_POLL 32
int outstat()
{
int rc, first = TRUE;
struct _alist *tmp, *old;
char flstr[6];
char temp[81];
tasklog('+', "Scanning outbound");
/*
* Clear current table
*/
for (tmp = alist; tmp; tmp = old) {
old = tmp->next;
free(tmp->addr.domain);
free(tmp);
}
alist = NULL;
if ((rc = scanout(each))) {
tasklog('?', "Error scanning outbound, aborting");
return rc;
}
for (tmp = alist; tmp; tmp = tmp->next) {
if (first) {
tasklog('+', "Flavor Size Online Modem ISDN TCP/IP Calls Status Address");
first = FALSE;
}
strcpy(flstr,"......");
if ((tmp->flavors) & F_IMM ) flstr[0]='I';
if ((tmp->flavors) & F_CRASH ) flstr[1]='C';
if ((tmp->flavors) & F_NORMAL) flstr[2]='N';
if ((tmp->flavors) & F_HOLD ) flstr[3]='H';
if ((tmp->flavors) & F_FREQ ) flstr[4]='R';
if ((tmp->flavors) & F_POLL ) flstr[5]='P';
sprintf(temp, "%s %8lu %08x %08x %08x %08x %5d %6d %s", flstr, (long)tmp->size,
(unsigned int)tmp->olflags, (unsigned int)tmp->moflags,
(unsigned int)tmp->diflags, (unsigned int)tmp->ipflags,
tmp->cst.tryno, tmp->cst.trystat, ascfnode(&(tmp->addr), 0x1f));
tasklog('+', "%s", temp);
}
return 0;
}
int each(faddr *addr, char flavor, int isflo, char *fname)
{
struct _alist **tmp;
struct stat st;
FILE *fp;
char buf[256], *p;
node *nlent;
callstat *cst;
if ((isflo != OUT_PKT) && (isflo != OUT_FLO) && (isflo != OUT_REQ) && (isflo != OUT_POL))
return 0;
for (tmp = &alist; *tmp; tmp = &((*tmp)->next))
if (((*tmp)->addr.zone == addr->zone) && ((*tmp)->addr.net == addr->net) &&
((*tmp)->addr.node == addr->node) && ((*tmp)->addr.point == addr->point) &&
(((*tmp)->addr.domain == NULL) || (addr->domain == NULL) ||
(strcasecmp((*tmp)->addr.domain,addr->domain) == 0)))
break;
if (*tmp == NULL) {
nlent = getnlent(addr);
*tmp = (struct _alist *)malloc(sizeof(struct _alist));
(*tmp)->next = NULL;
(*tmp)->addr.name = NULL;
(*tmp)->addr.zone = addr->zone;
(*tmp)->addr.net = addr->net;
(*tmp)->addr.node = addr->node;
(*tmp)->addr.point = addr->point;
(*tmp)->addr.domain = xstrcpy(addr->domain);
if (nlent->addr.domain)
free(nlent->addr.domain);
(*tmp)->flavors = 0;
if (nlent->pflag != NL_DUMMY) {
(*tmp)->olflags = nlent->oflags;
(*tmp)->moflags = nlent->mflags;
(*tmp)->diflags = nlent->dflags;
(*tmp)->ipflags = nlent->iflags;
} else {
(*tmp)->olflags = 0L;
(*tmp)->moflags = 0L;
(*tmp)->diflags = 0L;
(*tmp)->ipflags = 0L;
}
time(&((*tmp)->time));
(*tmp)->size = 0L;
}
cst = getstatus(addr);
(*tmp)->cst.trytime = cst->trytime;
(*tmp)->cst.tryno = cst->tryno;
(*tmp)->cst.trystat = cst->trystat;
if ((isflo == OUT_FLO) || (isflo == OUT_PKT))
switch (flavor) {
case '?': break;
case 'i': (*tmp)->flavors |= F_IMM; break;
case 'o': (*tmp)->flavors |= F_NORMAL; break;
case 'c': (*tmp)->flavors |= F_CRASH; break;
case 'h': (*tmp)->flavors |= F_HOLD; break;
default: tasklog('?', "Unknown flavor: '%c'\n",flavor); break;
}
if (stat(fname,&st) != 0) {
tasklog('?', "$Can't stat %s", fname);
st.st_size = 0L;
(void)time(&st.st_mtime);
}
/*
* Find the oldest time
*/
if (st.st_mtime < (*tmp)->time)
(*tmp)->time = st.st_mtime;
if (isflo == OUT_FLO) {
if ((fp = fopen(fname,"r"))) {
while (fgets(buf, sizeof(buf) - 1, fp)) {
if (*(p = buf + strlen(buf) - 1) == '\n')
*p-- = '\0';
while (isspace(*p))
*p-- = '\0';
for (p = buf; *p; p++)
if (*p == '\\')
*p='/';
for (p = buf; *p && isspace(*p); p++);
if (*p == '~') continue;
if ((*p == '#') || (*p == '-') || (*p == '^') || (*p == '@'))
p++;
if (stat(p, &st) != 0) {
if (strlen(CFG.dospath)) {
if (stat(Dos2Unix(p), &st) != 0) {
/*
* Fileattach dissapeared, maybe
* the node doesn't poll enough and
* is losing mail or files.
*/
st.st_size = 0L;
(void)time(&st.st_mtime);
}
} else {
if (stat(p, &st) != 0) {
st.st_size = 0L;
(void)time(&st.st_mtime);
}
}
}
if ((p = strrchr(fname,'/')))
p++;
else
p = fname;
if ((strlen(p) == 12) && (strspn(p,"0123456789abcdefABCDEF") == 8) && (p[8] == '.')) {
if (st.st_mtime < (*tmp)->time)
(*tmp)->time = st.st_mtime;
}
(*tmp)->size += st.st_size;
}
fclose(fp);
} else
tasklog('?', "Can't open %s", fname);
} else if (isflo == OUT_PKT) {
(*tmp)->size += st.st_size;
} else if (isflo == OUT_REQ) {
(*tmp)->flavors |= F_FREQ;
} else if (isflo == OUT_POL) {
(*tmp)->flavors |= F_POLL;
}
return 0;
}

10
mbtask/outstat.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef _OUTSTAT_H
#define _OUTSTAT_H
int each(faddr *, char, int, char *);
int outstat(void);
#endif

242
mbtask/scanout.c Normal file
View File

@@ -0,0 +1,242 @@
/*****************************************************************************
*
* File ..................: mbtask/scanout.c
* Purpose ...............: Outbound scanning
* Last modification date : 09-Jul-2001
*
*****************************************************************************
* Copyright (C) 1997-2001
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MBSE BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MBSE BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
#include "libs.h"
#include "../lib/structs.h"
#include "taskutil.h"
#include "scanout.h"
#ifndef PATH_MAX
#define PATH_MAX 512
#endif
static faddr addr = {
NULL,
0,0,0,0,
NULL
};
extern struct sysconfig CFG;
extern struct _fidonet fidonet;
static int scan_dir(int (*)(faddr*,char,int,char*),char*,int);
static int scan_dir(int (*fn)(faddr *, char, int, char *), char *dname, int ispoint)
{
char fname[PATH_MAX];
char flavor = '?';
DIR *dp = NULL;
struct dirent *de;
int rc = 0, isflo, fage;
time_t t_start;
t_start = time(NULL);
// tasklog('o' ,"scan_dir \"%s\" (%s)",MBSE_SS(dname),ispoint?"point":"node");
if ((dp = opendir(dname)) == NULL) {
tasklog('-', "Creating directory %s", dname);
/*
* Create a fake filename, mkdirs() likes that.
*/
sprintf(fname, "%s/foo", dname);
(void)mkdirs(fname);
if ((dp = opendir(dname)) == NULL) {
tasklog('o' ,"\"%s\" cannot be opened, proceed",MBSE_SS(dname));
return 0;
}
}
while ((de=readdir(dp)))
if ((strlen(de->d_name) == 12) && (de->d_name[8] == '.') &&
(strspn(de->d_name,"0123456789abcdefABCDEF") == 8)) {
// tasklog('o' ,"checking: \"%s\"",de->d_name);
addr.point= 0;
strncpy(fname,dname,PATH_MAX-2);
strcat(fname,"/");
strncat(fname,de->d_name,PATH_MAX-strlen(fname)-2);
if ((strcasecmp(de->d_name+9,"pnt") == 0) && !ispoint) {
sscanf(de->d_name,"%04x%04x",&addr.net,&addr.node);
if ((rc = scan_dir(fn, fname, 1)))
goto exout;
} else if ((strcasecmp(de->d_name+8,".out") == 0) ||
(strcasecmp(de->d_name+8,".cut") == 0) ||
(strcasecmp(de->d_name+8,".hut") == 0) ||
(strcasecmp(de->d_name+8,".iut") == 0) ||
(strcasecmp(de->d_name+8,".opk") == 0) ||
(strcasecmp(de->d_name+8,".cpk") == 0) ||
(strcasecmp(de->d_name+8,".hpk") == 0) ||
(strcasecmp(de->d_name+8,".ipk") == 0) ||
(strcasecmp(de->d_name+8,".flo") == 0) ||
(strcasecmp(de->d_name+8,".clo") == 0) ||
(strcasecmp(de->d_name+8,".hlo") == 0) ||
(strcasecmp(de->d_name+8,".ilo") == 0) ||
(strcasecmp(de->d_name+8,".req") == 0) ||
(strcasecmp(de->d_name+8,".pol") == 0)) {
if (ispoint)
sscanf(de->d_name,"%08x", &addr.point);
else
sscanf(de->d_name,"%04x%04x", &addr.net,&addr.node);
flavor = tolower(de->d_name[9]);
if (flavor == 'f')
flavor='o';
if (strcasecmp(de->d_name+10,"ut") == 0)
isflo=OUT_PKT;
else if (strcasecmp(de->d_name+10,"pk") == 0)
isflo=OUT_DIR;
else if (strcasecmp(de->d_name+10,"lo") == 0)
isflo=OUT_FLO;
else if (strcasecmp(de->d_name+9,"req") == 0)
isflo=OUT_REQ;
else if (strcasecmp(de->d_name+9,"pol") == 0)
isflo=OUT_POL;
else
isflo=-1;
// tasklog('o' ,"%s \"%s\"", (isflo == OUT_FLO) ? "flo file" : "packet", de->d_name);
if ((rc=fn(&addr,flavor,isflo,fname)))
goto exout;
} else if ((strncasecmp(de->d_name+9,"su",2) == 0) ||
(strncasecmp(de->d_name+9,"mo",2) == 0) ||
(strncasecmp(de->d_name+9,"tu",2) == 0) ||
(strncasecmp(de->d_name+9,"we",2) == 0) ||
(strncasecmp(de->d_name+9,"th",2) == 0) ||
(strncasecmp(de->d_name+9,"fr",2) == 0) ||
(strncasecmp(de->d_name+9,"sa",2) == 0)) {
isflo = OUT_ARC;
if ((rc = fn(&addr, flavor, isflo, fname)))
goto exout;
// tasklog('o' ,"arcmail file \"%s\"",de->d_name);
sprintf(fname, "%s/%s", dname, de->d_name);
fage = (int)((t_start - file_time(fname)) / 86400);
if (file_size(fname) == 0) {
// tasklog('o', "Age %d days", fage);
/*
* Remove truncated ARCmail that has a day extension
* other then the current day or if the file is older
* then 6 days.
*/
if ((strncasecmp(de->d_name+9, dayname(), 2)) || (fage > 6)) {
if (unlink(fname) == 0)
tasklog('-', "Removed truncated ARCmail file %s", fname);
}
}
if (CFG.toss_days && (fage > CFG.toss_days)) {
/*
* Remove ARCmail that is on hold too long.
*/
if (unlink(fname) == 0)
tasklog('+', "Removed ARCmail %s, %d days", fname, fage);
}
} else {
// tasklog('o' ,"skipping \"%s\"",de->d_name);
}
}
exout:
closedir(dp);
return rc;
}
int scanout(int (*fn)(faddr *, char, int, char *))
{
int i, j, rc = 0;
unsigned short zone = 0;
char fext[5];
char *p = NULL, *q = NULL;
DIR *dp;
if ((dp = opendir(CFG.outbound)) == NULL) {
tasklog('?', "$Can't open outbound directory \"%s\" for reading", MBSE_SS(CFG.outbound));
return 1;
}
closedir(dp);
/*
* Build outbound directory names with zone numbers.
*/
for (i = 0; i < 40; i++) {
if ((CFG.aka[i].zone) && (CFG.aka[i].zone != zone)) {
zone = CFG.aka[i].zone;
if (SearchFidonet(zone)) {
for (j = 0; j < 6; j++) {
/*
* Create outbound directory name for
* the primary aka of that zone.
*/
p = xstrcpy(CFG.outbound);
if (zone != CFG.aka[0].zone) {
if ((q = strrchr(p, '/')))
*q = '\0';
p = xstrcat(p, (char *)"/");
p = xstrcat(p, fidonet.domain);
}
/*
* Not primary zones in the domain get
* a directory extension.
*/
if (fidonet.zone[j]) {
if (j) {
sprintf(fext, ".%03x", fidonet.zone[j]);
p = xstrcat(p, fext);
}
// tasklog('o', "Zone %d Dir %s", fidonet.zone[j], p);
addr.zone = fidonet.zone[j];
addr.domain = fidonet.domain;
if ((rc = scan_dir(fn, p, 0))) {
if (p)
free(p);
p = NULL;
return rc;
}
}
if (p)
free(p);
p = NULL;
}
}
}
}
return rc;
}

13
mbtask/scanout.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef SCANOUT_H
#define SCANOUT_H
#define OUT_PKT 0
#define OUT_DIR 1
#define OUT_FLO 2
#define OUT_ARC 3
#define OUT_REQ 4
#define OUT_POL 5
extern int scanout(int (*)(faddr*,char,int,char*));
#endif

94
mbtask/signame.c Normal file
View File

@@ -0,0 +1,94 @@
/*****************************************************************************
*
* File ..................: signame.c
* Purpose ...............: Signal names
* Last modification date : 24-May-2001
*
*****************************************************************************
* Copyright (C) 1997-2001
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MBSE BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MBSE BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
#include "signame.h"
/*
* Signal handler signal names.
*/
#ifdef __i386__
char SigName[32][16] = { "NOSIGNAL",
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
"SIGTRAP", "SIGIOT", "SIGBUS", "SIGFPE",
"SIGKILL", "SIGUSR1", "SIGSEGV", "SIGUSR2",
"SIGPIPE", "SIGALRM", "SIGTERM", "SIGSTKFLT",
"SIGCHLD", "SIGCONT", "SIGSTOP", "SIGTSTP",
"SIGTTIN", "SIGTTOU", "SIGURG", "SIGXCPU",
"SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH",
"SIGIO", "SIGPWR", "SIGUNUSED"};
#endif
#ifdef __PPC__
char SigName[32][16] = { "NOSIGNAL",
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
"SIGTRAP", "SIGIOT", "SIGBUS", "SIGFPE",
"SIGKILL", "SIGUSR1", "SIGSEGV", "SIGUSR2",
"SIGPIPE", "SIGALRM", "SIGTERM", "SIGSTKFLT",
"SIGCHLD", "SIGCONT", "SIGSTOP", "SIGTSTP",
"SIGTTIN", "SIGTTOU", "SIGURG", "SIGXCPU",
"SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH",
"SIGIO", "SIGPWR", "SIGUNUSED"};
#endif
#ifdef __sparc__
char SigName[32][16] = { "NOSIGNAL",
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
"SIGTRAP", "SIGIOT", "SIGEMT", "SIGFPE",
"SIGKILL", "SIGBUS", "SIGSEGV", "SIGSYS",
"SIGPIPE", "SIGALRM", "SIGTERM", "SIGURG",
"SIGSTOP", "SIGTSTP", "SIGCONT", "SIGCHLD",
"SIGTTIN", "SIGTTOU", "SIGIO", "SIGXCPU",
"SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH",
"SIGLOST", "SIGUSR1", "SIGUSR2"};
#endif
#ifdef __alpha__
char SigName[32][16] = { "NOSIGNAL",
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL",
"SIGTRAP", "SIGABRT", "SIGEMT", "SIGFPE",
"SIGKILL", "SIGBUS", "SIGSEGV", "SIGSYS",
"SIGPIPE", "SIGALRM", "SIGTERM", "SIGURG",
"SIGSTOP", "SIGTSTP", "SIGCONT", "SIGCHLD",
"SIGTTIN", "SIGTTOU", "SIGIO", "SIGXCPU",
"SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH",
"SIGINFO", "SIGUSR1", "SIGUSR2"};
#endif

9
mbtask/signame.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef _SIGNAME_H
#define _SIGNAME_H
char SigName[32][16];
#endif

466
mbtask/taskcomm.c Normal file
View File

@@ -0,0 +1,466 @@
/*****************************************************************************
*
* File ..................: mbtask/taskcomm.c
* Purpose ...............: MBSE BBS Daemon
* Last modification date : 05-Jul-2001
*
*****************************************************************************
* Copyright (C) 1997-2001
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MB BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MB BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************
*
* This program uses the BSD IPC stream sockets mechanism. This is the
* server program. You need an entry in /etc/services for tcp service
* "mbse" on port 60180. Yes, this is 1 higher as for ifcico. You don't
* need an entry in inetd.conf, because this program is written as a
* daemon for fast access.
*
*****************************************************************************/
#include "libs.h"
#include "taskstat.h"
#include "taskregs.h"
#include "taskdisk.h"
#include "taskinfo.h"
#include "taskutil.h"
#include "taskcomm.h"
extern int oserr; /* Copy of Unix error */
extern int sock; /* Server socket */
extern struct sockaddr_un from; /* From socket address */
extern int fromlen; /* From address length */
extern int logtrans; /* Log transactions */
/************************************************************************
*
* Logging procedures.
*/
int userlog(char *);
int userlog(char *param)
{
char *prname, *prpid, *grade, *msg;
static char lfn[64], token[14];
lfn[0] = '\0';
strcpy(token, strtok(param, ","));
strcpy(token, strtok(NULL, ","));
sprintf(lfn, "%s/log/%s", getenv("MBSE_ROOT"), token);
prname = strtok(NULL, ",");
prpid = strtok(NULL, ",");
grade = strtok(NULL, ",");
msg = strtok(NULL, "\0");
msg[strlen(msg) -1] = '\0';
return ulog(lfn, grade, prname, prpid, msg);
}
/*
* Process command received from the client.
*/
char *exe_cmd(char *);
char *exe_cmd(char *in)
{
static char obuf[SS_BUFSIZE];
static char ibuf[SS_BUFSIZE];
static char cmd[4];
static char token[SS_BUFSIZE];
static char ebuf[19];
static char *cnt, var1[16];
int result;
strcpy(ibuf, in);
strncpy(cmd, ibuf, 4);
token[0] = '\0';
strcpy(ebuf, "200:1,Syntax error;");
/*
* Split the commandline after the colon so we can give the
* options directly to the actual functions. Also set a default
* and most used answer.
*/
strcpy(token, &ibuf[5]);
strcpy(obuf, "100:0;");
/*
* The A(counting) commands.
*
* AINI:5,pid,tty,user,program,city;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "AINI", 4) == 0) {
if (reg_newcon(token) != -1)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
}
/*
* ACLO:1,pid;
* 107:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd ,"ACLO", 4) == 0) {
if (reg_closecon(token) == 0) {
strcpy(obuf, "107:0;");
return obuf;
} else {
stat_inc_serr();
return ebuf;
}
}
/*
* ADOI:2,pid,doing;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "ADOI", 4) == 0) {
if (reg_doing(token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
}
/*
* ATTY:2,pid,tty;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "ATTY", 4) == 0) {
if (reg_tty(token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
}
/*
* ALOG:5,file,program,pid,grade,text;
* 100:0;
* 201:1,errno;
*/
if (strncmp(cmd, "ALOG", 4) == 0) {
if (userlog(token) != 0)
sprintf(obuf, "201:1,%d;", oserr);
return obuf;
}
/*
* AUSR:3,pid,user,city;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "AUSR", 4) == 0) {
if (reg_user(token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
}
/*
* ADIS:2,pid,flag; (set Do Not Disturb).
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "ADIS", 4) == 0) {
if (reg_silent(token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
}
/*
* ATIM:2,pid,seconds;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "ATIM", 4) == 0) {
if (reg_timer(TRUE, token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
}
/*
* ADEF:1,pid;
* 100:0;
*/
if (strncmp(cmd, "ADEF", 4) == 0) {
if (reg_timer(FALSE, token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
}
/*
* The chat commands
*
* CIPM:1,pid; (Is personal message present)
* 100:2,fromname,message;
* 100:0;
*/
if (strncmp(cmd, "CIPM", 4) == 0) {
return reg_ipm(token);
}
/*
* CSPM:3,fromuser,touser,text; (Send personal message).
* 100:1,n; n: 0=oke, 1=donotdisturb 2=buffer full 3=error
* 100:0;
*/
if (strncmp(cmd, "CSPM", 4) == 0) {
if ((result = reg_spm(token))) {
sprintf(obuf, "100:1,%d;", result);
return obuf;
} else
return obuf;
}
/*
* The G(lobal) commands.
*
* GNOP:1,pid;
* 100:0;
*/
if (strncmp(cmd ,"GNOP", 4) == 0) {
reg_nop(token);
return obuf;
}
/*
* GPNG:n,data;
* 100:n,data;
*/
if (strncmp(cmd, "GPNG", 4) == 0) {
sprintf(obuf, "100:%s", token);
return obuf;
}
/*
* GVER:0;
* 100:1,Version ...;
*/
if (strncmp(cmd, "GVER", 4) == 0) {
sprintf(obuf, "100:1,Version %s;", VERSION);
return obuf;
}
/*
* GSTA:0;
* 100:19,start,laststart,daily,startups,clients,tot_clients,tot_peak,tot_syntax,tot_comerr,
* today_clients,today_peak,today_syntax,today_comerr,!BBSopen,ZMH,internet,Processing,Load,sequence;
* 201:1,16;
*/
if (strncmp(cmd, "GSTA", 4) == 0) {
return stat_status();
}
/*
* GMON:1,n; n=1 First time
* 100:7,pid,tty,user,program,city,isdoing,starttime;
* 100:0;
*/
if (strncmp(cmd, "GMON", 4) == 0) {
cnt = strtok(token, ",");
strcpy(var1, strtok(NULL, ";"));
return get_reginfo(atoi(var1));
}
/*
* GDST:0;
* 100:n,data1,..,data10;
*/
if (strncmp(cmd, "GDST", 4) == 0) {
return get_diskstat();
}
/*
* GSYS:0;
* 100:7,calls,pots_calls,isdn_calls,network_calls,local_calls,startdate,last_caller;
* 201:1,16;
*/
if (strncmp(cmd, "GSYS", 4) == 0) {
return get_sysinfo();
}
/*
* GLCC:0;
* 100:1,n;
*/
if (strncmp(cmd, "GLCC", 4) == 0) {
return get_lastcallercount();
}
/*
* GLCR:1,recno;
* 100:9,user,location,level,device,time,mins,calls,speed,actions;
* 201:1,16;
*/
if (strncmp(cmd, "GLCR", 4) == 0) {
cnt = strtok(token, ",");
strcpy(var1, strtok(NULL, ";"));
return get_lastcallerrec(atoi(var1));
}
/*
* The (S)tatus commands.
*
* SBBS:0;
* 100:2,n,status message;
*/
if (strncmp(cmd, "SBBS", 4) == 0) {
switch(stat_bbs_stat()) {
case 0:
sprintf(obuf, "100:2,0,The system is open for use;");
break;
case 1:
sprintf(obuf, "100:2,1,The system is closed right now!;");
break;
case 2:
sprintf(obuf, "100:2,2,The system is closed for Zone Mail Hour!;");
break;
}
return obuf;
}
/*
* SOPE:0;
* 100:0;
*/
if (strncmp(cmd, "SOPE", 4) == 0) {
stat_set_open(1);
return obuf;
}
/*
* SCLO:1,message;
* 100:0;
*/
if (strncmp(cmd, "SCLO", 4) == 0) {
stat_set_open(0);
return obuf;
}
/*
* SFRE:0;
* 100:1,Running utilities: n Active users: n;
* 100:0;
* 201:1,16;
*/
if (strncmp(cmd, "SFRE", 4) == 0) {
return reg_fre();
}
/*
* SSEQ:0;
* 100:1,number;
* 200:1,16;
*/
if (strncmp(cmd, "SSEQ", 4) == 0) {
return getseq();
}
/*
* SEST:1,semafore; Get status of semafore
* 100:1,n; 1 = set, 0 = not set
* 200:1,16;
*/
if (strncmp(cmd, "SEST", 4) == 0) {
return sem_status(token);
}
/*
* SECR:1,semafore; Set semafore
* 100:0;
* 200:1,16;
*/
if (strncmp(cmd, "SECR", 4) == 0) {
return sem_create(token);
}
/*
* SERM:1,semafore; Remove semafore
* 100:0;
* 200:1,16;
*/
if (strncmp(cmd, "SERM", 4) == 0) {
return sem_remove(token);
}
/*
* If we got this far, there must be an error.
*/
stat_inc_serr();
return ebuf;
}
void do_cmd(char *cmd)
{
char buf[SS_BUFSIZE];
int slen, tries = 0;
sprintf(buf, "%s", exe_cmd(cmd));
if (logtrans) {
tasklog('-', "< %s", cmd);
tasklog('-', "> %s", buf);
}
for (;;) {
slen = sendto(sock, buf, strlen(buf), 0, &from, fromlen);
if (slen == -1)
tasklog('?', "$do_cmd(): sendto error %d %s", tries, from.sun_path);
else if (slen != strlen(buf))
tasklog('?', "do_cmd(): send %d of %d bytes, try=%d", slen, strlen(buf), tries);
else
return;
tries++;
if (tries == 3)
return;
sleep(1);
}
}

7
mbtask/taskcomm.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef _TASKCOMM_H
#define _TASKCOMM_H
void do_cmd(char *);
#endif

93
mbtask/taskdisk.c Normal file
View File

@@ -0,0 +1,93 @@
/*****************************************************************************
*
* File ..................: mbtask/statdisk.c
* Purpose ...............: Give status of all filesystems
* Last modification date : 23-May-2001
*
*****************************************************************************
* Copyright (C) 1997-2001
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 Internet: mbse@user.sourceforge.net
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MB BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MB BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
#include "libs.h"
#include "taskdisk.h"
#include "taskutil.h"
/*
* This function returns the information of all mounted filesystems,
* but no more then 10 filesystems.
*/
char *get_diskstat()
{
char *mtab, *dev, *fs, *type, *tmp = NULL;
FILE *fp;
int i = 0;
static char buf[SS_BUFSIZE];
struct statfs sfs;
char tt[80];
unsigned long temp;
buf[0] = '\0';
mtab = calloc(256, sizeof(char));
if ((fp = fopen((char *)"/etc/mtab", "r")) == 0) {
sprintf(buf, "100:0;");
return buf;
}
while (fgets(mtab, 255, fp)) {
dev = strtok(mtab, " ");
fs = strtok(NULL, " ");
type = strtok(NULL, " ");
if (strncmp((char *)"/dev/", dev, 5) == 0) {
if (statfs(fs, &sfs) == 0) {
i++;
if (tmp == NULL)
tmp = xstrcpy((char *)",");
else
tmp = xstrcat(tmp, (char *)",");
tt[0] = '\0';
temp = (unsigned long)(sfs.f_bsize / 512L);
sprintf(tt, "%lu %lu %s %s",
(unsigned long)(sfs.f_blocks * temp) / 2048L,
(unsigned long)(sfs.f_bavail * temp) / 2048L,
fs, type);
tmp = xstrcat(tmp, tt);
}
if (i == 10) /* No more then 10 filesystems */
break;
}
}
fclose(fp);
if (strlen(tmp) > (SS_BUFSIZE - 8))
sprintf(buf, "100:0;");
else
sprintf(buf, "100:%d%s;", i, tmp);
return buf;
}

8
mbtask/taskdisk.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef _TASKDISK_H
#define _TASKDISK_H
char *get_diskstat(void); /* Get disk status */
#endif

138
mbtask/taskinfo.c Normal file
View File

@@ -0,0 +1,138 @@
/*****************************************************************************
*
* File ..................: mbtask/taskinfo.c
* Purpose ...............: Give system information
* Last modification date : 24-May-2001
*
*****************************************************************************
* Copyright (C) 1997-2001
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MB BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MB BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
#include "libs.h"
#include "../lib/structs.h"
#include "taskinfo.h"
/*
* Get BBS System info.
*/
char *get_sysinfo(void)
{
FILE *fp;
static char buf[SS_BUFSIZE];
char *temp;
struct sysrec SYSINFO;
sprintf(buf, "201:1,16;");
temp = calloc(128, sizeof(char));
sprintf(temp, "%s/etc/sysinfo.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r")) == NULL) {
free(temp);
return buf;
}
free(temp);
if (fread(&SYSINFO, sizeof(SYSINFO), 1, fp) == 1)
sprintf(buf, "100:7,%ld,%ld,%ld,%ld,%ld,%s,%s;", SYSINFO.SystemCalls,
SYSINFO.Pots, SYSINFO.ISDN, SYSINFO.Network, SYSINFO.Local,
ctime(&SYSINFO.StartDate), SYSINFO.LastCaller);
fclose(fp);
return buf;
}
char *get_lastcallercount(void)
{
static char buf[SS_BUFSIZE];
char *temp;
FILE *fp;
struct lastcallershdr LCALLhdr;
sprintf(buf, "201:1,16;");
temp = calloc(128, sizeof(char));
sprintf(temp, "%s/etc/lastcall.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r")) == NULL) {
free(temp);
return buf;
}
fread(&LCALLhdr, sizeof(LCALLhdr), 1, fp);
fseek(fp, 0, SEEK_END);
sprintf(buf, "100:1,%ld;", ((ftell(fp) - LCALLhdr.hdrsize) / LCALLhdr.recsize));
fclose(fp);
return buf;
}
char *get_lastcallerrec(int Rec)
{
static char buf[SS_BUFSIZE];
char *temp, action[8];
FILE *fp;
struct lastcallershdr LCALLhdr;
struct lastcallers LCALL;
sprintf(buf, "201:1,16;");
temp = calloc(128, sizeof(char));
sprintf(temp, "%s/etc/lastcall.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r")) == NULL) {
free(temp);
return buf;
}
fread(&LCALLhdr, sizeof(LCALLhdr), 1, fp);
fseek(fp, ((Rec -1) * LCALLhdr.recsize) + LCALLhdr.hdrsize, SEEK_SET);
if (fread(&LCALL, LCALLhdr.recsize, 1, fp) == 1) {
LCALL.UserName[15] = '\0';
LCALL.Location[12] = '\0';
strcpy(action, "-------");
if (LCALL.Hidden)
action[0] = 'H';
if (LCALL.Download)
action[1] = 'D';
if (LCALL.Upload)
action[2] = 'U';
if (LCALL.Read)
action[3] = 'R';
if (LCALL.Wrote)
action[4] = 'W';
if (LCALL.Chat)
action[5] = 'C';
if (LCALL.Olr)
action[6] = 'O';
action[7] = '\0';
sprintf(buf, "100:9,%s,%s,%d,%s,%s,%d,%d,%s,%s;", LCALL.UserName, LCALL.Location,
LCALL.SecLevel, LCALL.Device, LCALL.TimeOn,
LCALL.CallTime, LCALL.Calls, LCALL.Speed, action);
}
fclose(fp);
return buf;
}

10
mbtask/taskinfo.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef _TASKINFO_H
#define _TASKINFO_H
char *get_sysinfo(void); /* Get System Info */
char *get_lastcallercount(void); /* Get Lastcallers count */
char *get_lastcallerrec(int); /* Get Lastcaller record */
#endif

478
mbtask/taskregs.c Normal file
View File

@@ -0,0 +1,478 @@
/*****************************************************************************
*
* File ..................: mbtask/taskregs.c
* Purpose ...............: Buffers for registration information.
* Last modification date : 07-Jun-2001
*
*****************************************************************************
* Copyright (C) 1997-2001
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MB BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MB BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
#include "libs.h"
#include "taskstat.h"
#include "taskregs.h"
#include "taskutil.h"
extern reg_info reginfo[MAXCLIENT]; /* Array with clients */
static int entrypos = 0; /* Status pointer */
/***********************************************************************
*
* Search for a pid.
*/
int reg_find(char *);
int reg_find(char *pids)
{
int i;
for (i = 0; i < MAXCLIENT; i++) {
if ((int)reginfo[i].pid == atoi(pids))
return i;
}
tasklog('?', "Panic, pid %s not found", pids);
return -1;
}
/***********************************************************************
*
* Registrate a new connection and fill the data.
*/
int reg_newcon(char *data)
{
char *cnt, *pid, *tty, *uid, *prg, *city;
int retval;
cnt = strtok(data, ",");
pid = strtok(NULL, ",");
tty = strtok(NULL, ",");
uid = strtok(NULL, ",");
prg = strtok(NULL, ",");
city = strtok(NULL, ";");
/*
* Abort if no empty record is found
*/
if ((retval = reg_find((char *)"0")) == -1) {
tasklog('?', "Maximum clients (%d) reached", MAXCLIENT);
return -1;
}
memset((char *)&reginfo[retval], 0, sizeof(reg_info));
reginfo[retval].pid = atoi(pid);
strncpy((char *)&reginfo[retval].tty, tty, 6);
strncpy((char *)&reginfo[retval].uname, uid, 35);
strncpy((char *)&reginfo[retval].prg, prg, 14);
strncpy((char *)&reginfo[retval].city, city, 35);
strcpy((char *)&reginfo[retval].doing, "-");
reginfo[retval].started = time(NULL);
reginfo[retval].lastcon = time(NULL);
reginfo[retval].altime = 600;
/*
* Everyone says do not disturb, unless the flag
* is cleared by the owner of this process.
*/
reginfo[retval].silent = 1;
tasklog('-', "Registered client pgm \"%s\", pid %s, slot %d", prg, pid, retval);
stat_inc_clients();
return retval;
}
int reg_closecon(char *data)
{
char *cnt, *pid;
int rec;
cnt = strtok(data, ",");
pid = strtok(NULL, ";");
if ((rec = reg_find(pid)) == -1)
return -1;
tasklog('-', "Unregistered client pgm \"%s\", pid %s, slot %d", reginfo[rec].prg, pid, rec);
memset(&reginfo[rec], 0, sizeof(reg_info));
stat_dec_clients();
return 0;
}
/*
* Check all registred connections.
*/
void reg_check(void)
{
int i;
time_t Now;
Now = time(NULL);
for (i = 1; i < MAXCLIENT; i++) {
if (reginfo[i].pid) {
if (kill(reginfo[i].pid, 0) == -1) {
if (errno == ESRCH) {
tasklog('?', "Stale registration found for pid %d (%s)", reginfo[i].pid, reginfo[i].prg);
memset(&reginfo[i], 0, sizeof(reg_info));
stat_dec_clients();
}
} else {
/*
* Check timeout
*/
if ((Now - reginfo[i].lastcon) >= reginfo[i].altime) {
if (reginfo[i].altime < 600) {
kill(reginfo[i].pid, SIGKILL);
tasklog('+', "Send SIGKILL to pid %d", reginfo[i].pid);
} else {
kill(reginfo[i].pid, SIGTERM);
tasklog('+', "Send SIGTERM to pid %d", reginfo[i].pid);
}
/*
* 10 seconds to the next kill
*/
reginfo[i].altime = 10;
reginfo[i].lastcon = time(NULL);
}
}
}
}
}
/*
* Update doing information for this process.
*/
int reg_doing(char *data)
{
char *cnt, *pid, *line;
int rec;
cnt = strtok(data, ",");
pid = strtok(NULL, ",");
line = strtok(NULL, ";");
if ((rec = reg_find(pid)) == -1)
return -1;
strncpy(reginfo[rec].doing, line, 35);
reginfo[rec].lastcon = time(NULL);
return 0;
}
/*
* Update timer using NOP
*/
int reg_nop(char *data)
{
char *cnt, *pid;
int rec;
cnt = strtok(data, ",");
pid = strtok(NULL, ";");
if ((rec = reg_find(pid)) == -1)
return -1;
reginfo[rec].lastcon = time(NULL);
return 0;
}
/*
* Set new timer value
*/
int reg_timer(int Set, char *data)
{
char *pid;
int cnt, rec, val;
cnt = atoi(strtok(data, ","));
if (Set) {
if (cnt != 2)
return -1;
pid = strtok(NULL, ",");
val = atoi(strtok(NULL, ";"));
if (val < 600)
val = 600;
} else {
if (cnt != 1)
return -1;
pid = strtok(NULL, ";");
val = 600;
}
if ((rec = reg_find(pid)) == -1)
return -1;
reginfo[rec].altime = val;
reginfo[rec].lastcon = time(NULL);
tasklog('r', "Set timeout value for %d to %d", reginfo[rec].pid, val);
return 0;
}
/*
* Update tty information for this process.
*/
int reg_tty(char *data)
{
char *cnt, *pid, *tty;
int rec;
cnt = strtok(data, ",");
pid = strtok(NULL, ",");
tty = strtok(NULL, ";");
if ((rec = reg_find(pid)) == -1)
return -1;
strncpy((char *)&reginfo[rec].tty, tty, 6);
reginfo[rec].lastcon = time(NULL);
return 0;
}
/*
* Update the "do not disturb" flag.
*/
int reg_silent(char *data)
{
char *cnt, *pid, *line;
int rec;
cnt = strtok(data, ",");
pid = strtok(NULL, ",");
line = strtok(NULL, ";");
if ((rec = reg_find(pid)) == -1)
return -1;
reginfo[rec].silent = atoi(line);
reginfo[rec].lastcon = time(NULL);
return 0;
}
/*
* Update username and city for this process.
*/
int reg_user(char *data)
{
char *cnt, *pid, *user, *city;
int rec;
cnt = strtok(data, ",");
pid = strtok(NULL, ",");
user = strtok(NULL, ",");
city = strtok(NULL, ";");
if ((rec = reg_find(pid)) == -1)
return -1;
strncpy((char *)&reginfo[rec].uname, user, 35);
strncpy((char *)&reginfo[rec].city, city, 35);
reginfo[rec].lastcon = time(NULL);
return 0;
}
/*
* Check for personal message
*/
char *reg_ipm(char *data)
{
char *cnt, *pid;
static char buf[128];
int rec;
buf[0] = '\0';
sprintf(buf, "100:0;");
cnt = strtok(data, ",");
pid = strtok(NULL, ";");
if ((rec = reg_find(pid)) == -1)
return buf;
reginfo[rec].lastcon = time(NULL);
if (!reginfo[rec].ismsg)
return buf;
buf[0] = '\0';
sprintf(buf, "100:2,%s,%s;", reginfo[rec].fname[reginfo[rec].ptr_out], reginfo[rec].msg[reginfo[rec].ptr_out]);
if (reginfo[rec].ptr_out < RB)
reginfo[rec].ptr_out++;
else
reginfo[rec].ptr_out = 0;
if (reginfo[rec].ptr_out == reginfo[rec].ptr_in)
reginfo[rec].ismsg = FALSE;
tasklog('+', "reg_ipm: in=%d out=%d ismsg=%d", reginfo[rec].ptr_in, reginfo[rec].ptr_out, reginfo[rec].ismsg);
return buf;
}
/*
* Send personal message
*/
int reg_spm(char *data)
{
char *cnt, *from, *too, *txt;
int i;
cnt = strtok(data, ",");
from = strtok(NULL, ",");
too = strtok(NULL, ",");
txt = strtok(NULL, ";");
for (i = 1; i < MAXCLIENT; i++) {
if (reginfo[i].pid && (strcasecmp(reginfo[i].uname, too) == 0)) {
/*
* If the in and out pointers are the same and the
* message present flag is still set, then this user
* can't get anymore new messages.
*/
if (reginfo[i].ismsg && (reginfo[i].ptr_in == reginfo[i].ptr_out)) {
return 2;
}
/*
* If user has the "do not distrurb" flag set.
*/
if (reginfo[i].silent) {
return 1;
}
/*
* If all is well, insert the new message.
*/
strncpy((char *)&reginfo[i].fname[reginfo[i].ptr_in], from, 35);
strncpy((char *)&reginfo[i].msg[reginfo[i].ptr_in], txt, 80);
if (reginfo[i].ptr_in < RB)
reginfo[i].ptr_in++;
else
reginfo[i].ptr_in = 0;
reginfo[i].ismsg = TRUE;
tasklog('+', "reg_spm: in=%d out=%d ismsg=%d", reginfo[i].ptr_in, reginfo[i].ptr_out, reginfo[i].ismsg);
return 0;
}
}
/*
* User not found
*/
return 3;
}
char *reg_fre(void)
{
static char buf[80];
int i, users = 0, utils = 0;
buf[0] = '\0';
for (i = 1; i < MAXCLIENT; i++) {
if (reginfo[i].pid) {
if ((!strncmp(reginfo[i].prg, "mbsebbs", 7)) ||
(!strncmp(reginfo[i].prg, "mbftpd", 6)))
users++;
if ((!strncmp(reginfo[i].prg, "mbfido", 6)) ||
(!strncmp(reginfo[i].prg, "mbmail", 6)) ||
(!strncmp(reginfo[i].prg, "mball", 5)) ||
(!strncmp(reginfo[i].prg, "mbaff", 5)) ||
(!strncmp(reginfo[i].prg, "mbcico", 6)) ||
(!strncmp(reginfo[i].prg, "mbfile", 6)) ||
(!strncmp(reginfo[i].prg, "mbmsg", 5)) ||
(!strncmp(reginfo[i].prg, "mbindex", 7)) ||
(!strncmp(reginfo[i].prg, "mbdiff", 6)) ||
(!strncmp(reginfo[i].prg, "mbuser", 6)))
utils++;
}
}
if (users || utils)
sprintf(buf, "100:1,Running utilities: %02d Active users: %02d;", utils, users);
else
sprintf(buf, "100:0;");
return buf;
}
/*
* Get registration information. The first time the parameter
* must be 1, for the next searches 0. Returns 100:0; if there
* is an error or the end of file is reached.
*/
char *get_reginfo(int first)
{
static char buf[256];
memset(&buf, 0, sizeof(buf));
sprintf(buf, "100:0;");
/*
* Loop forever until an error occours, eof is reached or
* the data is valid. Only in the last case valid data is
* returned to the caller.
*/
for (;;) {
if (first == 1)
entrypos = 0;
else
entrypos++;
if (entrypos == MAXCLIENT)
return buf;
if ((int)reginfo[entrypos].pid != 0) {
sprintf(buf, "100:7,%d,%s,%s,%s,%s,%s,%d;",
reginfo[entrypos].pid, reginfo[entrypos].tty,
reginfo[entrypos].uname, reginfo[entrypos].prg,
reginfo[entrypos].city, reginfo[entrypos].doing,
(int)reginfo[entrypos].started);
return buf;
}
}
/* never reached */
}

49
mbtask/taskregs.h Normal file
View File

@@ -0,0 +1,49 @@
#ifndef _TASKREGS_H
#define _TASKREGS_H
#define MAXCLIENT 100
/*
* Connected clients information
*/
#define RB 5
typedef struct _reg_info {
pid_t pid; /* Pid or zero if free */
char tty[7]; /* Connected tty */
char uname[36]; /* User name */
char prg[15]; /* Program name */
char city[36]; /* Users city */
char doing[36]; /* What is going on */
time_t started; /* Startime connection */
time_t lastcon; /* Last connection */
int altime; /* Alarm time */
unsigned silent : 1; /* Do not disturb */
unsigned chatting : 1; /* User is chatting */
unsigned ismsg : 1; /* Message waiting */
int channel; /* Chat channel */
int ptr_in; /* Input buffer pointer */
int ptr_out; /* Output buffer ptr */
char fname[RB][36]; /* Message from user */
char msg[RB][81]; /* The message itself */
} reg_info;
void reg_init(void);
int reg_newcon(char *);
int reg_closecon(char *);
void reg_check(void);
int reg_doing(char *);
int reg_nop(char *);
int reg_timer(int, char *);
int reg_tty(char *);
int reg_user(char *);
int reg_silent(char *);
char *reg_ipm(char *);
int reg_spm(char *);
char *reg_fre(void);
char *get_reginfo(int);
#endif

438
mbtask/taskstat.c Normal file
View File

@@ -0,0 +1,438 @@
/*****************************************************************************
*
* File ..................: mbtask/taskstat.c
* Purpose ...............: Keep track of server status
* Last modification date : 09-Jul-2001
*
*****************************************************************************
* Copyright (C) 1997-2001
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MB BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MB BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
#include "libs.h"
#include "../lib/structs.h"
#include "taskstat.h"
#include "outstat.h"
#include "taskutil.h"
/*
* Semafores
*/
int s_scanout = FALSE;
int s_mailout = FALSE;
int s_mailin = FALSE;
int s_reqindex = FALSE;
int s_index = FALSE;
int s_msglink = FALSE;
int s_newnews = FALSE;
int s_bbsopen = FALSE;
extern int UPSalarm;
extern struct taskrec TCFG;
extern int internet;
extern int ZMH;
typedef struct {
long tot_clt; /* Total client connects */
long peak_clt; /* Peak simultaneous tot_cltes */
long s_error; /* Syntax errors from clients */
long c_error; /* Comms errors from clients */
} cl_stat;
typedef struct {
time_t start; /* Start date/time */
time_t laststart; /* Last start date/time */
time_t daily; /* Last daily update */
long startups; /* Total starts */
long clients; /* Connected clients */
cl_stat total; /* Total statistics */
cl_stat today; /* Todays statistics */
unsigned open : 1; /* Is BBS open */
unsigned long sequence; /* Sequencer counter */
} status_r;
static char stat_fn[PATH_MAX]; /* Statusfile name */
static status_r status; /* Status data */
extern float Load; /* System Load */
extern int Processing; /* Is system running */
/************************************************************************
*
* Initialize the statusfile, create it if necesary.
*/
void status_init()
{
size_t cnt;
int stat_fd;
sprintf(stat_fn, "%s/var/status.mbsed", getenv("MBSE_ROOT"));
/*
* First check if this is the very first time we start the show.
* If so, we generate an empty status file with only the start
* date in it.
*/
stat_fd = open(stat_fn, O_RDWR);
if (stat_fd == -1) {
memset((char *)&status, 0, sizeof(status_r));
status.start = time(NULL);
status.daily = time(NULL);
status.sequence = (unsigned long)time(NULL);
stat_fd = open(stat_fn, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
cnt = write(stat_fd, &status, sizeof(status_r));
tasklog('+', "New statusfile created");
lseek(stat_fd, 0, SEEK_SET);
}
cnt = read(stat_fd, &status, sizeof(status_r));
if (cnt != sizeof(status_r)) {
printf("Error reading status file\n");
#ifdef MEMWATCH
mwTerm();
#endif
exit(1);
}
status.startups++;
status.laststart = time(NULL);
status.clients = 1; /* We are a client ourself */
s_bbsopen = status.open;
lseek(stat_fd, 0, SEEK_SET);
cnt = write(stat_fd, &status, sizeof(status_r));
if (cnt != sizeof(status_r)) {
tasklog('?', "$Error rewrite status file\n");
#ifdef MEMWATCH
mwTerm();
#endif
exit(1);
}
close(stat_fd);
}
/*
* Writeback the updated status record.
*/
void status_write(void);
void status_write(void)
{
int d, stat_fd;
struct tm ttm, ytm;
time_t temp;
temp = time(NULL);
ttm = *localtime(&temp);
ytm = *localtime(&status.daily);
/*
* If we passed to the next day, zero the today counters
*/
if (ttm.tm_yday != ytm.tm_yday) {
tasklog('+', "Last days statistics:");
tasklog('+', "Total clients : %lu", status.today.tot_clt);
tasklog('+', "Peak clients : %lu", status.today.peak_clt);
tasklog('+', "Syntax errors : %lu", status.today.s_error);
tasklog('+', "Comms errors : %lu", status.today.c_error);
memset((char *)&status.today, 0, sizeof(cl_stat));
status.daily = time(NULL);
tasklog('+', "Zeroed todays status counters");
}
stat_fd = open(stat_fn, O_RDWR);
d = lseek(stat_fd, 0, SEEK_SET);
d = write(stat_fd, &status, sizeof(status_r));
if (d != sizeof(status_r))
tasklog('?', "Error writing statusfile, only %d bytes", d);
/*
* CLose the statusfile
*/
if (close(stat_fd) != 0)
tasklog('?', "$Error closing statusfile");
}
/*************************************************************************
*
* Various actions on the statusfile.
*/
/*
* Check for Zone Mail Hour, return TRUE if it is.
*/
int get_zmh()
{
struct tm *l_date;
char sstime[6];
time_t Now;
Now = time(NULL);
l_date = gmtime(&Now);
sprintf(sstime, "%02d:%02d", l_date->tm_hour, l_date->tm_min);
if ((strncmp(sstime, TCFG.zmh_start, 5) >= 0) && (strncmp(sstime, TCFG.zmh_end, 5) < 0)) {
if (!ZMH) {
CreateSema((char *)"zmh");
sem_set((char *)"scanout", TRUE);
tasklog('!', "Start of Zone Mail Hour");
ZMH = TRUE;
}
} else {
if (ZMH) {
RemoveSema((char *)"zmh");
sem_set((char *)"scanout", TRUE);
tasklog('!', "End of Zone Mail Hour");
ZMH = FALSE;
}
}
return ZMH;
}
void stat_inc_clients()
{
status.clients++;
status.total.tot_clt++;
status.today.tot_clt++;
if (status.clients >= status.total.peak_clt)
status.total.peak_clt = status.clients;
if (status.clients >= status.today.peak_clt)
status.today.peak_clt = status.clients;
status_write();
}
void stat_dec_clients()
{
status.clients--;
status_write();
}
void stat_set_open(int op)
{
if (op) {
if (!s_bbsopen) {
tasklog('!', "The bbs is open");
sem_set((char *)"scanout", TRUE);
}
} else {
if (s_bbsopen) {
tasklog('!', "The bbs is closed");
}
}
s_bbsopen = status.open = op;
status_write();
}
void stat_inc_serr()
{
status.total.s_error++;
status.today.s_error++;
status_write();
}
void stat_inc_cerr()
{
status.total.c_error++;
status.today.c_error++;
status_write();
}
char *stat_status()
{
static char buf[160];
buf[0] = '\0';
sprintf(buf, "100:19,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%d,%d,%d,%d,%2.2f,%lu;",
status.start, status.laststart, status.daily,
status.startups, status.clients,
status.total.tot_clt, status.total.peak_clt,
status.total.s_error, status.total.c_error,
status.today.tot_clt, status.today.peak_clt,
status.today.s_error, status.today.c_error,
status.open, get_zmh(), internet, Processing, Load, status.sequence);
return buf;
}
/*
* Return open status:
* 0 = open.
* 1 = closed.
* 2 = Zone Mail Hour.
*/
int stat_bbs_stat()
{
if (!status.open)
return 1;
if (get_zmh())
return 2;
return 0;
}
/*
* Get next sequence number
*/
char *getseq(void)
{
static char buf[80];
buf[0] = '\0';
status.sequence++;
status_write();
sprintf(buf, "100:1,%lu;", status.sequence);
return buf;
}
int sem_set(char *sem, int value)
{
int rc = TRUE;
tasklog('s', "sem_set(%s, %s)", sem, value?"TRUE":"FALSE");
if (!strcmp(sem, "scanout")) {
if (value && !s_scanout) {
outstat();
}
s_scanout = value;
} else if (!strcmp(sem, "mailout")) {
s_mailout = value;
} else if (!strcmp(sem, "mailin")) {
s_mailin = value;
} else if (!strcmp(sem, "mbindex")) {
s_index = value;
} else if (!strcmp(sem, "newnews")) {
s_newnews = value;
} else if (!strcmp(sem, "msglink")) {
s_msglink = value;
} else if (!strcmp(sem, "reqindex")) {
s_reqindex = value;
} else {
rc = FALSE;
}
return rc;
}
char *sem_status(char *data)
{
char *cnt, *sem;
static char buf[40];
int value;
buf[0] = '\0';
sprintf(buf, "200:1,16;");
cnt = strtok(data, ",");
sem = strtok(NULL, ";");
if (!strcmp(sem, "scanout")) {
value = s_scanout;
} else if (!strcmp(sem, "mailout")) {
value = s_mailout;
} else if (!strcmp(sem, "mailin")) {
value = s_mailin;
} else if (!strcmp(sem, "mbindex")) {
value = s_index;
} else if (!strcmp(sem, "newnews")) {
value = s_newnews;
} else if (!strcmp(sem, "msglink")) {
value = s_msglink;
} else if (!strcmp(sem, "reqindex")) {
value = s_reqindex;
} else if (!strcmp(sem, "upsalarm")) {
value = UPSalarm;
} else {
tasklog('s', "sem_status(%s) buf=%s", sem, buf);
return buf;
}
sprintf(buf, "100:1,%s;", value ? "1":"0");
tasklog('s', "sem_status(%s) = %d buf=%s", sem, value, buf);
return buf;
}
char *sem_create(char *data)
{
static char buf[40];
char *cnt, *sem;
cnt = strtok(data, ",");
sem = strtok(NULL, ";");
buf[0] = '\0';
sprintf(buf, "200:1,16;");
if (sem_set(sem, TRUE))
sprintf(buf, "100:0;");
return buf;
}
char *sem_remove(char *data)
{
static char buf[40];
char *cnt, *sem;
cnt = strtok(data, ",");
sem = strtok(NULL, ";");
buf[0] = '\0';
sprintf(buf, "200:1,16;");
if (sem_set(sem, FALSE))
sprintf(buf, "100:0;");
return buf;
}

20
mbtask/taskstat.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef _TASKSTAT_H
#define _TASKSTAT_H
void status_init(void); /* Initialize status module */
void stat_inc_clients(void); /* Increase connected clients */
void stat_dec_clients(void); /* Decrease connected clients */
void stat_set_open(int); /* Set BBS open status */
void stat_inc_serr(void); /* Increase syntax error */
void stat_inc_cerr(void); /* Increase comms error */
char *stat_status(void); /* Return status record */
int stat_bbs_stat(void); /* Get BBS open status */
char *getseq(void); /* Get next sequence number */
int get_zmh(void); /* Check Zone Mail Hour */
int sem_set(char *, int); /* Set/Reset semafore */
char *sem_status(char *); /* Get semafore status */
char *sem_create(char *); /* Create semafore */
char *sem_remove(char *); /* Remove semafore */
#endif

439
mbtask/taskutil.c Normal file
View File

@@ -0,0 +1,439 @@
/*****************************************************************************
*
* File ..................: mbtask/taskutil.c
* Purpose ...............: MBSE BBS Task Manager, utilities
* Last modification date : 06-Jul-2001
*
*****************************************************************************
* Copyright (C) 1997-2001
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MBSE BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MBSE BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
#include "libs.h"
#include "../lib/structs.h"
#include "signame.h"
#include "scanout.h"
#include "taskutil.h"
pid_t mypid; /* Original parent pid if child */
int oserr; /* Last OS error number */
extern struct sysconfig CFG;
extern struct _fidonethdr fidonethdr;
extern struct _fidonet fidonet;
extern struct taskrec TCFG;
static char *mon[] = {
(char *)"Jan",(char *)"Feb",(char *)"Mar",
(char *)"Apr",(char *)"May",(char *)"Jun",
(char *)"Jul",(char *)"Aug",(char *)"Sep",
(char *)"Oct",(char *)"Nov",(char *)"Dec"
};
/************************************************************************
*
* Loging procedures.
*/
char *date(void);
char *date(void)
{
struct tm ptm;
time_t now;
static char buf[20];
now = time(NULL);
ptm = *localtime(&now);
sprintf(buf,"%02d-%s-%04d %02d:%02d:%02d", ptm.tm_mday, mon[ptm.tm_mon], ptm.tm_year+1900,
ptm.tm_hour, ptm.tm_min, ptm.tm_sec);
return(buf);
}
/*
* general log for this server
*/
void tasklog(int grade, const char *format, ...)
{
va_list va_ptr;
char outstr[1024];
int oldmask;
FILE *logfile;
char *logname;
if (grade == '+' || grade == '-' || grade == '!' || grade == '?' || grade == ' ' || TCFG.debug) {
va_start(va_ptr, format);
vsprintf(outstr, format, va_ptr);
va_end(va_ptr);
logname = calloc(PATH_MAX, sizeof(char));
oldmask=umask(066);
sprintf(logname, "%s/log/mbtask.log", getenv("MBSE_ROOT"));
logfile = fopen(logname, "a");
umask(oldmask);
if (logfile == NULL) {
printf("Cannot open logfile \"%s\"\n", logname);
free(logname);
return;
}
fprintf(logfile, "%c %s mbtask[%d] ", grade, date(), getpid());
fprintf(logfile, *outstr == '$' ? outstr+1 : outstr);
if (*outstr == '$')
fprintf(logfile, ": %s\n", strerror(errno));
else
fprintf(logfile, "\n");
fflush(logfile);
if (fclose(logfile) != 0)
printf("Cannot close logfile \"%s\"\n", logname);
free(logname);
}
return;
}
/*
* user log process
*/
int ulog(char *fn, char *grade, char *prname, char *prpid, char *format)
{
int oldmask;
FILE *log;
oldmask = umask(066);
log = fopen(fn, "a");
umask(oldmask);
if (log == NULL) {
oserr = errno;
tasklog('!', "$Cannot open user logfile %s", fn);
return -1;
}
fprintf(log, "%s %s %s[%s] ", grade, date(), prname, prpid);
fwrite(format, strlen(format), 1, log);
fprintf(log, "\n");
fflush(log);
if (fclose(log) != 0) {
oserr = errno;
tasklog('!', "$Cannot close user logfile %s", fn);
return -1;
}
return 0;
}
char *xstrcpy(char *src)
{
char *tmp;
if (src == NULL)
return(NULL);
tmp = malloc(strlen(src)+1);
strcpy(tmp, src);
return tmp;
}
char *xstrcat(char *src, char *add)
{
char *tmp;
size_t size = 0;
if ((add == NULL) || (strlen(add) == 0))
return src;
if (src)
size = strlen(src);
size += strlen(add);
tmp = malloc(size + 1);
*tmp = '\0';
if (src) {
strcpy(tmp, src);
free(src);
}
strcat(tmp, add);
return tmp;
}
void CreateSema(char *sem)
{
char temp[PATH_MAX];
int fd;
sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem);
if (access(temp, F_OK) == 0)
return;
if ((fd = open(temp, O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)) >= 0)
close(fd);
else
tasklog('?', "Can't create semafore %s", temp);
}
void TouchSema(char *sem)
{
char temp[PATH_MAX];
int fd;
sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem);
if ((fd = open(temp, O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)) >= 0) {
close(fd);
} else
tasklog('?', "Can't touch semafore %s", temp);
}
void RemoveSema(char *sem)
{
char temp[PATH_MAX];
sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem);
if (access(temp, F_OK))
return;
if (unlink(temp) == -1)
tasklog('?', "Can't remove semafore %s", temp);
}
int IsSema(char *sem)
{
char temp[PATH_MAX];
sprintf(temp, "%s/sema/%s", getenv("MBSE_ROOT"), sem);
return (access(temp, F_OK) == 0);
}
/*
* Test if the given file exists. The second option is:
* R_OK - test for Read rights
* W_OK - test for Write rights
* X_OK - test for eXecute rights
* F_OK - test file presence only
*/
int file_exist(char *path, int mode)
{
if (access(path, mode) != 0)
return errno;
return 0;
}
/*
* Make directory tree, the name must end with a /
*/
int mkdirs(char *name)
{
char buf[PATH_MAX], *p, *q;
int rc, last = 0, oldmask;
memset(&buf, 0, sizeof(buf));
strncpy(buf, name, sizeof(buf)-1);
buf[sizeof(buf)-1] = '\0';
p = buf+1;
oldmask = umask(000);
while ((q = strchr(p, '/'))) {
*q = '\0';
rc = mkdir(buf, 0775);
last = errno;
*q = '/';
p = q+1;
}
umask(oldmask);
if ((last == 0) || (last == EEXIST)) {
return TRUE;
} else {
tasklog('?', "$mkdirs(%s)", name);
return FALSE;
}
}
/*
* Return size of file, or -1 if file doesn't exist
*/
long file_size(char *path)
{
static struct stat sb;
if (stat(path, &sb) == -1)
return -1;
return sb.st_size;
}
/*
* Return time of file, or -1 if file doen't exist, which is
* the same as 1 second before 1 jan 1970. You may test the
* result on -1 since time_t is actualy a long integer.
*/
time_t file_time(char *path)
{
static struct stat sb;
if (stat(path, &sb) == -1)
return -1;
return sb.st_mtime;
}
/*
* Return ASCII string for node, the bits in 'fl' set the
* output format.
*/
char *ascfnode(faddr *a, int fl)
{
static char buf[128];
if (a == NULL) {
strcpy(buf, "<none>");
return buf;
}
buf[0] = '\0';
if ((fl & 0x40) && (a->name))
sprintf(buf+strlen(buf),"%s of ",a->name);
if ((fl & 0x08) && (a->zone))
sprintf(buf+strlen(buf),"%u:",a->zone);
if (fl & 0x04)
sprintf(buf+strlen(buf),"%u/",a->net);
if (fl & 0x02)
sprintf(buf+strlen(buf),"%u",a->node);
if ((fl & 0x01) && (a->point))
sprintf(buf+strlen(buf),".%u",a->point);
if ((fl & 0x10) && (a->domain))
sprintf(buf+strlen(buf),"@%s",a->domain);
return buf;
}
char *Dos2Unix(char *dosname)
{
char buf[PATH_MAX];
static char buf2[PATH_MAX];
char *p, *q;
memset(&buf, 0, sizeof(buf));
memset(&buf2, 0, sizeof(buf2));
sprintf(buf, "%s", dosname);
p = buf;
if (strlen(CFG.dospath)) {
if (strncasecmp(p, CFG.dospath, strlen(CFG.dospath)) == 0) {
strcpy((char *)buf2, CFG.uxpath);
for (p+=strlen(CFG.dospath), q = buf2 + strlen(buf2); *p; p++, q++)
*q = ((*p) == '\\')?'/':tolower(*p);
*q = '\0';
p = buf2;
} else {
if (strncasecmp(p, CFG.uxpath, strlen(CFG.uxpath)) == 0) {
for (p+=strlen(CFG.uxpath), q = buf2 + strlen(buf2); *p; p++, q++)
*q = ((*p) == '\\')?'/':tolower(*p);
*q = '\0';
p = buf2;
}
}
}
return buf2;
}
static char *dow[] = {(char *)"su", (char *)"mo", (char *)"tu", (char *)"we",
(char *)"th", (char *)"fr", (char *)"sa"};
char *dayname(void)
{
time_t tt;
struct tm *ptm;
static char buf[3];
(void)time(&tt);
ptm = localtime(&tt);
sprintf(buf, "%s", dow[ptm->tm_wday]);
return buf;
}
void InitFidonet(void)
{
memset(&fidonet, 0, sizeof(fidonet));
}
int SearchFidonet(unsigned short zone)
{
FILE *fil;
char fidonet_fil[PATH_MAX];
int i;
sprintf(fidonet_fil, "%s/etc/fidonet.data", getenv("MBSE_ROOT"));
if ((fil = fopen(fidonet_fil, "r")) == NULL) {
return FALSE;
}
fread(&fidonethdr, sizeof(fidonethdr), 1, fil);
while (fread(&fidonet, fidonethdr.recsize, 1, fil) == 1) {
for (i = 0; i < 6; i++) {
if (zone == fidonet.zone[i]) {
fclose(fil);
return TRUE;
}
}
}
fclose(fil);
return FALSE;
}

42
mbtask/taskutil.h Normal file
View File

@@ -0,0 +1,42 @@
#ifndef _TASKUTIL_H
#define _TASKUTIL_H
#define TRUE 1
#define FALSE 0
#define SS_BUFSIZE 1024 /* Socket buffersize */
#define MBSE_SS(x) (x)?(x):"(null)"
typedef struct _srv_auth {
struct _srv_auth *next;
char *hostname;
char *authcode;
} srv_auth;
/*
* Function prototypes
*/
void tasklog(int, const char *, ...);
int ulog(char *, char *, char *, char *, char*);
char *xstrcpy(char *);
char *xstrcat(char *, char *);
void CreateSema(char *);
void TouchSema(char *);
void RemoveSema(char *);
int IsSema(char *);
int file_exist(char *, int);
int mkdirs(char *);
long file_size(char *);
time_t file_time(char *);
char *ascfnode(faddr *, int);
char *Dos2Unix(char *);
char *dayname(void);
void InitFidonet(void);
int SearchFidonet(unsigned short);
#endif