Initial revision

This commit is contained in:
Evgeniy Kozhuhovskiy
2004-12-30 16:00:36 +00:00
commit 69f117bf78
169 changed files with 50779 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
0.22.8.ugenk4
+185
View File
@@ -0,0 +1,185 @@
#
# Copyright (c) 1999-2000, Alexander Belkin <adb@newmail.ru>
#
# $Id$
#
CC = gcc
INCLUDES = -I./include
CFLAGS = -g -O2
LIBS =
YACC = bison -y
INSTALL = /usr/bin/install -c
INSTALL_PROGRAM = ${INSTALL}
INSTALL_DATA = ${INSTALL} -m 644
SRCDIR = .
SRCDIRCONF = $(SRCDIR)/../examples
CONTRIBDIR = $(SRCDIR)/../contrib
OWNER = uucp
GROUP = news
CONFDIR = /usr/local/etc
BINDIR = /usr/local/bin
LOGDIR = /var/log/bforce
SPOOLDIR = /var/spool/bforce
DAEMON_LOGFILE = $(LOGDIR)/bf-daemon
BFORCE_LOGFILE = $(LOGDIR)/bf-log
BFORCE_DEBFILE = $(LOGDIR)/bf-debug
BFORCE_CFGFILE = $(CONFDIR)/bforce.conf
DEFINES = -DDAEMON_LOGFILE=\"$(DAEMON_LOGFILE)\" \
-DBFORCE_LOGFILE=\"$(BFORCE_LOGFILE)\" \
-DBFORCE_DEBFILE=\"$(BFORCE_DEBFILE)\" \
-DBFORCE_CFGFILE=\"$(BFORCE_CFGFILE)\" \
-DBF_OS=\"linux-gnu\" -DHAVE_CONFIG_H
SUBDIRS = bforce bfutil
BFINDEX_OBJS = bfutil/bfindex.o \
bforce/conf_deinit.o bforce/conf_proc.o \
bforce/conf_read.o bforce/conf_get.o \
bforce/logger.o bforce/nodelist.o \
bforce/u_file.o bforce/u_ftn.o \
bforce/u_misc.o bforce/u_string.o \
bforce/u_time.o
NLOOKUP_OBJS = bfutil/nlookup.o \
bforce/conf_deinit.o bforce/conf_proc.o \
bforce/conf_read.o bforce/conf_get.o \
bforce/logger.o bforce/nodelist.o \
bforce/u_file.o bforce/u_ftn.o \
bforce/u_misc.o bforce/u_string.o \
bforce/u_time.o
BFSTAT_OBJS = bfutil/bfstat.o \
bforce/conf_deinit.o bforce/conf_proc.o \
bforce/conf_read.o bforce/conf_get.o \
bforce/outb_flo.o bforce/outb_fsqueue.o \
bforce/sess_stat.o \
bforce/outb_getname.o bforce/outb_sysqueue.o \
bforce/outb_scan.o bforce/logger.o \
bforce/u_file.o \
bforce/u_ftn.o bforce/u_misc.o \
bforce/u_string.o bforce/u_time.o \
bforce/u_plock.o
BFORCE_OBJS = bforce/bforce.o \
bforce/daemon.o bforce/daemon_branch.o \
bforce/daemon_call.o bforce/daemon_lines.o \
bforce/conf_deinit.o \
bforce/conf_proc.o bforce/conf_read.o \
bforce/conf_get.o bforce/expression.o \
bforce/freq_bark.o bforce/freq_proc.o \
bforce/freq_srif.o bforce/freq_wazoo.o \
bforce/io_modem.o bforce/io_tcpip.o \
bforce/io_unix_lock.o bforce/io_unix_modem.o \
bforce/io_unix_tio.o bforce/io_unix_tty.o \
bforce/logger.o bforce/nodelist.o \
bforce/os_unix.o bforce/outb_bsy.o \
bforce/outb_flo.o bforce/outb_fsqueue.o \
bforce/outb_getname.o bforce/outb_sysqueue.o \
bforce/outb_scan.o bforce/prot_common.o \
bforce/prot_binkp.o bforce/prot_binkp_api.o \
bforce/prot_binkp_misc.o bforce/prot_hydra.o \
bforce/prot_xmrecv.o bforce/prot_xmsend.o \
bforce/prot_zmmisc.o bforce/prot_zmrecv.o \
bforce/prot_zmsend.o \
bforce/prot_yoohoo.o bforce/prot_yoohoo_api.o \
bforce/prot_emsi.o bforce/prot_emsi_misc.o \
bforce/prot_emsi_api.o \
bforce/sess_common.o bforce/sess_stat.o \
bforce/sess_call.o bforce/sess_answ.o \
bforce/sess_init.o bforce/sess_main.o \
bforce/u_crc.o bforce/u_ftn.o \
bforce/u_md5.o \
bforce/u_misc.o bforce/u_string.o \
bforce/u_time.o bforce/u_file.o \
bforce/u_pkt.o bforce/u_recode.o \
bforce/u_plock.o
.c.o:
@echo Compiling $*.c
@$(CC) $(CFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
all: bin/bforce bin/bfindex bin/bfstat bin/nlookup
expression.c: bforce/expression.y
$(YACC) bforce/expression.y
mv y.tab.c bforce/expression.c
bin/bforce: $(BFLIB_OBJS) $(BFORCE_OBJS)
@echo "Linking $@"
@$(CC) $(BFLIB_OBJS) $(BFORCE_OBJS) $(LIBS) -o $@
bin/bfindex: $(BFLIB_OBJS) $(BFINDEX_OBJS)
@echo "Linking $@"
@$(CC) $(BFLIB_OBJS) $(BFINDEX_OBJS) $(LIBS) -o $@
bin/nlookup: $(BFLIB_OBJS) $(NLOOKUP_OBJS)
@echo "Linking $@"
@$(CC) $(BFLIB_OBJS) $(NLOOKUP_OBJS) $(LIBS) -o $@
bin/bfstat: $(BFLIB_OBJS) $(BFSTAT_OBJS)
@echo "Linking $@"
@$(CC) $(BFLIB_OBJS) $(BFSTAT_OBJS) $(LIBS) -o $@
clean:
@for i in $(SUBDIRS); do (rm -f $$i/*.o || exit 1); done
rm -f ./bforce/expression.c
rm -f ./bin/bforce
rm -f ./bin/bfindex
rm -f ./bin/bfstat
rm -f ./bin/nlookup
rm -f ./bin/core
clean-am:
rm -f ./Makefile
rm -f ./include/config.h
rm -f ./config.log
rm -f ./config.status
clean-ac:
rm -f ./configure
distclean: clean clean-am
distclean-m: distclean clean-ac
ifnames:
@for i in $(SUBDIRS); do (ifnames $$i/*.c || exit 1); done
bforce/expression.y.o: bforce/expression.y.c bforce/expression.l.c
bforce/expression.l.o: bforce/expression.y.c bforce/expression.l.c
installdirs:
if [ ! -d $(CONFDIR) ]; then mkdir -p $(CONFDIR); fi
if [ ! -d $(BINDIR) ]; then mkdir -p $(BINDIR); fi
if [ ! -d $(LOGDIR) ]; then mkdir -p $(LOGDIR); fi
if [ ! -d $(SPOOLDIR) ]; then mkdir -p $(SPOOLDIR); fi
if [ ! -d $(SPOOLDIR)/bt/in ]; then mkdir -p $(SPOOLDIR)/bt/in; fi
if [ ! -d $(SPOOLDIR)/bt/pin ]; then mkdir -p $(SPOOLDIR)/bt/pin; fi
if [ ! -d $(SPOOLDIR)/bt/out ]; then mkdir -p $(SPOOLDIR)/bt/out; fi
if [ ! -d $(SPOOLDIR)/ndl ]; then mkdir -p $(SPOOLDIR)/ndl; fi
if [ ! -d $(SPOOLDIR)/bforce ]; then mkdir -p $(SPOOLDIR); fi
chown $(OWNER).$(GROUP) $(CONFDIR)
chown $(OWNER).$(GROUP) $(LOGDIR)
chown $(OWNER).$(GROUP) $(SPOOLDIR)/bt/in
chown $(OWNER).$(GROUP) $(SPOOLDIR)/bt/pin
chown $(OWNER).$(GROUP) $(SPOOLDIR)/bt/out
chown $(OWNER).$(GROUP) $(SPOOLDIR)/ndl
chown $(OWNER).$(GROUP) $(SPOOLDIR)
install:
$(INSTALL_PROGRAM) -o $(OWNER) -g $(GROUP) $(SRCDIR)/bin/bforce $(BINDIR)/bforce
$(INSTALL_PROGRAM) -o $(OWNER) -g $(GROUP) $(SRCDIR)/bin/bfindex $(BINDIR)/bfindex
$(INSTALL_PROGRAM) -o $(OWNER) -g $(GROUP) $(SRCDIR)/bin/bfstat $(BINDIR)/bfstat
$(INSTALL_PROGRAM) -o $(OWNER) -g $(GROUP) $(SRCDIR)/bin/nlookup $(BINDIR)/nlookup
$(INSTALL_PROGRAM) -o $(OWNER) -g $(GROUP) $(CONTRIBDIR)/outman $(BINDIR)/outman
$(INSTALL_DATA) -o $(OWNER) -g $(GROUP) $(SRCDIRCONF)/bforce.conf $(CONFDIR)/bforce.conf.sample
$(INSTALL_DATA) -o $(OWNER) -g $(GROUP) $(SRCDIRCONF)/bforce.subst $(CONFDIR)/bforce.subst.sample
$(INSTALL_DATA) -o $(OWNER) -g $(GROUP) $(SRCDIRCONF)/bforce.passwd $(CONFDIR)/bforce.passwd.sample
$(INSTALL_DATA) -o $(OWNER) -g $(GROUP) $(SRCDIRCONF)/freq.aliases $(CONFDIR)/freq.aliases.sample
$(INSTALL_DATA) -o $(OWNER) -g $(GROUP) $(SRCDIRCONF)/freq.dirs $(CONFDIR)/freq.dirs.sample
@echo "Please, edit $(BINDIR)/outman"
+185
View File
@@ -0,0 +1,185 @@
#
# Copyright (c) 1999-2000, Alexander Belkin <adb@newmail.ru>
#
# $Id$
#
CC = @CC@
INCLUDES = -I./include
CFLAGS = @CFLAGS@
LIBS = @LIBS@
YACC = @YACC@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
SRCDIR = @srcdir@
SRCDIRCONF = $(SRCDIR)/../examples
CONTRIBDIR = $(SRCDIR)/../contrib
OWNER = @OWNER@
GROUP = @GROUP@
CONFDIR = @prefix@/etc
BINDIR = @prefix@/bin
LOGDIR = /var/log/bforce
SPOOLDIR = /var/spool/bforce
DAEMON_LOGFILE = $(LOGDIR)/bf-daemon
BFORCE_LOGFILE = $(LOGDIR)/bf-log
BFORCE_DEBFILE = $(LOGDIR)/bf-debug
BFORCE_CFGFILE = $(CONFDIR)/bforce.conf
DEFINES = -DDAEMON_LOGFILE=\"$(DAEMON_LOGFILE)\" \
-DBFORCE_LOGFILE=\"$(BFORCE_LOGFILE)\" \
-DBFORCE_DEBFILE=\"$(BFORCE_DEBFILE)\" \
-DBFORCE_CFGFILE=\"$(BFORCE_CFGFILE)\" \
-DBF_OS=\"@build_os@\" @DEFS@
SUBDIRS = bforce bfutil
BFINDEX_OBJS = bfutil/bfindex.o \
bforce/conf_deinit.o bforce/conf_proc.o \
bforce/conf_read.o bforce/conf_get.o \
bforce/logger.o bforce/nodelist.o \
bforce/u_file.o bforce/u_ftn.o \
bforce/u_misc.o bforce/u_string.o \
bforce/u_time.o
NLOOKUP_OBJS = bfutil/nlookup.o \
bforce/conf_deinit.o bforce/conf_proc.o \
bforce/conf_read.o bforce/conf_get.o \
bforce/logger.o bforce/nodelist.o \
bforce/u_file.o bforce/u_ftn.o \
bforce/u_misc.o bforce/u_string.o \
bforce/u_time.o
BFSTAT_OBJS = bfutil/bfstat.o \
bforce/conf_deinit.o bforce/conf_proc.o \
bforce/conf_read.o bforce/conf_get.o \
bforce/outb_flo.o bforce/outb_fsqueue.o \
bforce/sess_stat.o \
bforce/outb_getname.o bforce/outb_sysqueue.o \
bforce/outb_scan.o bforce/logger.o \
bforce/u_file.o \
bforce/u_ftn.o bforce/u_misc.o \
bforce/u_string.o bforce/u_time.o \
bforce/u_plock.o
BFORCE_OBJS = bforce/bforce.o \
bforce/daemon.o bforce/daemon_branch.o \
bforce/daemon_call.o bforce/daemon_lines.o \
bforce/conf_deinit.o \
bforce/conf_proc.o bforce/conf_read.o \
bforce/conf_get.o bforce/expression.o \
bforce/freq_bark.o bforce/freq_proc.o \
bforce/freq_srif.o bforce/freq_wazoo.o \
bforce/io_modem.o bforce/io_tcpip.o \
bforce/io_unix_lock.o bforce/io_unix_modem.o \
bforce/io_unix_tio.o bforce/io_unix_tty.o \
bforce/logger.o bforce/nodelist.o \
bforce/os_unix.o bforce/outb_bsy.o \
bforce/outb_flo.o bforce/outb_fsqueue.o \
bforce/outb_getname.o bforce/outb_sysqueue.o \
bforce/outb_scan.o bforce/prot_common.o \
bforce/prot_binkp.o bforce/prot_binkp_api.o \
bforce/prot_binkp_misc.o bforce/prot_hydra.o \
bforce/prot_xmrecv.o bforce/prot_xmsend.o \
bforce/prot_zmmisc.o bforce/prot_zmrecv.o \
bforce/prot_zmsend.o \
bforce/prot_yoohoo.o bforce/prot_yoohoo_api.o \
bforce/prot_emsi.o bforce/prot_emsi_misc.o \
bforce/prot_emsi_api.o \
bforce/sess_common.o bforce/sess_stat.o \
bforce/sess_call.o bforce/sess_answ.o \
bforce/sess_init.o bforce/sess_main.o \
bforce/u_crc.o bforce/u_ftn.o \
bforce/u_md5.o \
bforce/u_misc.o bforce/u_string.o \
bforce/u_time.o bforce/u_file.o \
bforce/u_pkt.o bforce/u_recode.o \
bforce/u_plock.o
.c.o:
@echo Compiling $*.c
@$(CC) $(CFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
all: bin/bforce bin/bfindex bin/bfstat bin/nlookup
expression.c: bforce/expression.y
$(YACC) bforce/expression.y
mv y.tab.c bforce/expression.c
bin/bforce: $(BFLIB_OBJS) $(BFORCE_OBJS)
@echo "Linking $@"
@$(CC) $(BFLIB_OBJS) $(BFORCE_OBJS) $(LIBS) -o $@
bin/bfindex: $(BFLIB_OBJS) $(BFINDEX_OBJS)
@echo "Linking $@"
@$(CC) $(BFLIB_OBJS) $(BFINDEX_OBJS) $(LIBS) -o $@
bin/nlookup: $(BFLIB_OBJS) $(NLOOKUP_OBJS)
@echo "Linking $@"
@$(CC) $(BFLIB_OBJS) $(NLOOKUP_OBJS) $(LIBS) -o $@
bin/bfstat: $(BFLIB_OBJS) $(BFSTAT_OBJS)
@echo "Linking $@"
@$(CC) $(BFLIB_OBJS) $(BFSTAT_OBJS) $(LIBS) -o $@
clean:
@for i in $(SUBDIRS); do (rm -f $$i/*.o || exit 1); done
rm -f ./bforce/expression.c
rm -f ./bin/bforce
rm -f ./bin/bfindex
rm -f ./bin/bfstat
rm -f ./bin/nlookup
rm -f ./bin/core
clean-am:
rm -f ./Makefile
rm -f ./include/config.h
rm -f ./config.log
rm -f ./config.status
clean-ac:
rm -f ./configure
distclean: clean clean-am
distclean-m: distclean clean-ac
ifnames:
@for i in $(SUBDIRS); do (ifnames $$i/*.c || exit 1); done
bforce/expression.y.o: bforce/expression.y.c bforce/expression.l.c
bforce/expression.l.o: bforce/expression.y.c bforce/expression.l.c
installdirs:
if [ ! -d $(CONFDIR) ]; then mkdir -p $(CONFDIR); fi
if [ ! -d $(BINDIR) ]; then mkdir -p $(BINDIR); fi
if [ ! -d $(LOGDIR) ]; then mkdir -p $(LOGDIR); fi
if [ ! -d $(SPOOLDIR) ]; then mkdir -p $(SPOOLDIR); fi
if [ ! -d $(SPOOLDIR)/bt/in ]; then mkdir -p $(SPOOLDIR)/bt/in; fi
if [ ! -d $(SPOOLDIR)/bt/pin ]; then mkdir -p $(SPOOLDIR)/bt/pin; fi
if [ ! -d $(SPOOLDIR)/bt/out ]; then mkdir -p $(SPOOLDIR)/bt/out; fi
if [ ! -d $(SPOOLDIR)/ndl ]; then mkdir -p $(SPOOLDIR)/ndl; fi
if [ ! -d $(SPOOLDIR)/bforce ]; then mkdir -p $(SPOOLDIR); fi
chown $(OWNER).$(GROUP) $(CONFDIR)
chown $(OWNER).$(GROUP) $(LOGDIR)
chown $(OWNER).$(GROUP) $(SPOOLDIR)/bt/in
chown $(OWNER).$(GROUP) $(SPOOLDIR)/bt/pin
chown $(OWNER).$(GROUP) $(SPOOLDIR)/bt/out
chown $(OWNER).$(GROUP) $(SPOOLDIR)/ndl
chown $(OWNER).$(GROUP) $(SPOOLDIR)
install:
$(INSTALL_PROGRAM) -o $(OWNER) -g $(GROUP) $(SRCDIR)/bin/bforce $(BINDIR)/bforce
$(INSTALL_PROGRAM) -o $(OWNER) -g $(GROUP) $(SRCDIR)/bin/bfindex $(BINDIR)/bfindex
$(INSTALL_PROGRAM) -o $(OWNER) -g $(GROUP) $(SRCDIR)/bin/bfstat $(BINDIR)/bfstat
$(INSTALL_PROGRAM) -o $(OWNER) -g $(GROUP) $(SRCDIR)/bin/nlookup $(BINDIR)/nlookup
$(INSTALL_PROGRAM) -o $(OWNER) -g $(GROUP) $(CONTRIBDIR)/outman $(BINDIR)/outman
$(INSTALL_DATA) -o $(OWNER) -g $(GROUP) $(SRCDIRCONF)/bforce.conf $(CONFDIR)/bforce.conf.sample
$(INSTALL_DATA) -o $(OWNER) -g $(GROUP) $(SRCDIRCONF)/bforce.subst $(CONFDIR)/bforce.subst.sample
$(INSTALL_DATA) -o $(OWNER) -g $(GROUP) $(SRCDIRCONF)/bforce.passwd $(CONFDIR)/bforce.passwd.sample
$(INSTALL_DATA) -o $(OWNER) -g $(GROUP) $(SRCDIRCONF)/freq.aliases $(CONFDIR)/freq.aliases.sample
$(INSTALL_DATA) -o $(OWNER) -g $(GROUP) $(SRCDIRCONF)/freq.dirs $(CONFDIR)/freq.dirs.sample
@echo "Please, edit $(BINDIR)/outman"
+485
View File
@@ -0,0 +1,485 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "version.h"
#include "logger.h"
#include "util.h"
#include "bforce.h"
#include "nodelist.h"
#include "session.h"
/* PID of our child process (if use fork) */
pid_t child_pid = 0;
const char *BFERR[] = {
/* 00 */ "Successfull",
/* 01 */ "Fatal error occured",
/* 02 */ "Unknown phone number(or ip address)",
/* 03 */ "Modem port busy (or open error)",
/* 04 */ "System locked now",
/* 05 */ "Try later",
/* 06 */ "Modem not response",
/* 07 */ "Not working now",
/* 08 */ "Unused entry",
/* 09 */ "Unused entry",
/* 10 */ "Can't connect to remote",
/* 11 */ "Can't connect to remote: busy",
/* 12 */ "Can't connect to remote: nocarrier",
/* 13 */ "Can't connect to remote: nodialtone",
/* 14 */ "Can't connect to remote: noanswer",
/* 15 */ "Can't connect to remote: error",
/* 16 */ "Can't connect to remote: user defined 16",
/* 17 */ "Can't connect to remote: user defined 17",
/* 18 */ "Can't connect to remote: user defined 18",
/* 19 */ "Can't connect to remote: user defined 19",
/* 20 */ "Connect speed too low",
/* 21 */ "Cannot handshake with remote",
/* 22 */ "Xmiting error",
/* 23 */ "CPS too low",
/* 24 */ "Reached stop time",
/* 25 */ "Unused entry",
/* 26 */ "Unused entry",
/* 27 */ "Unused entry"
};
static void deinit_opts(s_bforce_opts *opts);
/*
static void print_compiled_configuration(void)
{
printf("BFORCE_LOGFILE = "BFORCE_LOGFILE"\n");
printf("BFORCE_DEBFILE = "BFORCE_DEBFILE"\n");
printf("DAEMON_LOGFILE = "DAEMON_LOGFILE"\n");
printf("BFORCE_CFGFILE = "BFORCE_CFGFILE"\n");
printf("BF_OS = "BF_OS"\n");
}
*/
static void usage(void)
{
printf_usage(NULL,
"usage: bforce [-fmh] [-I<include>] [-n<phone>] [-l<line_number>]\n"
" [-a<ip_address>] [-S<connect>] [-p<device>] <node>\n"
" bforce [-ih] [-I<include>] [-S<connect>]\n"
" <tsync|yoohoo|emsi|binkp|auto> (this implies slave mode)\n"
" bforce [-dh] [-C<config>] [-I<include>]\n"
"\n"
"options:\n"
" -d run as daemon\n"
" -q terminate daemon\n"
" -i run from inetd (for slave mode only)\n"
" -f ignore system's work time\n"
" -o starts outgoing session on stdin/stdout\n"
" -C <config> main config file name (\"%s\")\n"
" -I <config> additional config file name\n"
" -n <phone> override phone number\n"
" -l <line_number> call on this hidden line (default is 0) \n"
" -a <ip_address> override internet address\n"
" -S <connect_str> connect string (for slave mode only)\n"
" -p <port> override modem port (must be defined in config)\n"
" -h show this help message\n"
"\n",
conf_getconfname()
);
}
int bforce_create_dirs(void)
{
const char *p_dirname = conf_string(cf_status_directory);
if( p_dirname )
{
if( access(p_dirname, F_OK) == -1 || !is_directory(p_dirname) )
{
if( directory_create(p_dirname, 0700) == -1 )
{
logerr("cannot create spool directory \"%s\"", p_dirname);
return -1;
}
}
}
return 0;
}
/*
* Universal signal handler for parent processes :) Will resend
* signals to child process
*/
static RETSIGTYPE parent_sighandler(int sig)
{
/* Send this signal to our child */
if( child_pid ) kill(child_pid, sig);
}
/*
* Return non-zero value to indicate error, on success - return zero
* to child process and NEVER return to parent process
*/
static int usefork(void)
{
pid_t cpid; /* child PID */
pid_t wpid; /* waitpid() returned value */
int status = 0;
cpid = fork();
if( cpid == 0 )
{ return 0; }
if( cpid < 0 )
{ logerr("failed fork() call"); return 1; }
/*
* Now we are parent process
*/
/* Put PID into global variable */
child_pid = cpid;
/* Setup signals handling */
signal(SIGHUP, parent_sighandler);
signal(SIGINT, parent_sighandler);
signal(SIGTERM, parent_sighandler);
signal(SIGUSR1, parent_sighandler);
signal(SIGUSR2, parent_sighandler);
/* Wait until child die */
while( (wpid = waitpid(cpid, &status, 0)) < 0 && errno == EINTR )
{
/* EMPTY LOOP */
}
if( wpid == cpid && WIFEXITED(status) )
{
/* Child was terminated with _exit() */
exit(WEXITSTATUS(status));
}
else if( wpid < 0 && WIFSIGNALED(status) )
{
/* Child was terminated by signal */
kill(getpid(), WTERMSIG(status));
}
exit(BFERR_FATALERROR);
}
static int bforce_master(const s_bforce_opts *opts)
{
s_falist *tmpl;
int rc, maxrc = BFERR_NOERROR;
#ifdef GETPGRP_VOID
if( getpgrp() == getpid() )
#else
if( getpgrp(0) == getpid() )
#endif
{
/* We are process group leader -> fork() */
if( usefork() ) return BFERR_FATALERROR;
}
for( tmpl = opts->addrlist; tmpl; tmpl = tmpl->next )
{
int callopt = 0;
if( opts->iaddr ) callopt |= CALLOPT_INET;
if( opts->force ) callopt |= CALLOPT_FORCE;
rc = call_system(tmpl->addr, opts);
if( rc > maxrc ) maxrc = rc;
}
return maxrc;
}
static int bforce_slave(const s_bforce_opts *opts)
{
return answ_system(opts->stype, opts->connect, opts->inetd);
}
static int bforce_daemon(const s_bforce_opts *opts)
{
int forkrc = fork();
if( forkrc == -1 )
{
logerr("cannot run daemon: failed fork() call");
return BFERR_FATALERROR;
}
else if( forkrc > 0 )
{
return BFERR_NOERROR;
}
/*
* We are inside a child process.
* Create new session and run daemon
*/
setsid();
return daemon_run(opts->confname, opts->incname, opts->quit);
}
int main(int argc, char *argv[], char *envp[])
{
s_bforce_opts opts;
int rc = 0;
int ch = 0;
int role = 0;
memset(&opts, '\0', sizeof(s_bforce_opts));
while( (ch=getopt(argc, argv, "hodqr:ifC:I:n:l:a:S:p:")) != EOF )
{
switch( ch ) {
case 'h':
usage();
exit(BFERR_NOERROR);
case 'd':
if( opts.inetd || opts.force || opts.phone
|| opts.hiddline || opts.iaddr || opts.connect
|| opts.device || opts.quit )
{ usage(); exit(BFERR_FATALERROR); }
else
{ opts.daemon = 1; }
break;
case 'q':
if( opts.inetd || opts.force || opts.phone
|| opts.hiddline || opts.iaddr || opts.connect
|| opts.device || opts.daemon )
{ usage(); exit(BFERR_FATALERROR); }
else
{ opts.daemon = 1; opts.quit = 1; }
break;
case 'i':
if( opts.daemon )
{ usage(); exit(BFERR_FATALERROR); }
else
{ opts.inetd = 1; }
break;
case 'f':
if( opts.daemon )
{ usage(); exit(BFERR_FATALERROR); }
else
{ opts.force = 1; }
break;
case 'o':
if( opts.dontcall )
{ usage(); exit(BFERR_FATALERROR); }
else
{ opts.dontcall = TRUE; }
break;
case 'C':
if( opts.confname ) free(opts.confname);
if( optarg ) opts.confname = (char *)xstrcpy(optarg);
break;
case 'I':
if( opts.incname ) free(opts.incname);
if( optarg ) opts.incname = (char *)xstrcpy(optarg);
break;
case 'n':
if( opts.daemon )
{ usage(); exit(BFERR_FATALERROR); }
else
{
if( opts.phone ) free(opts.phone);
if( optarg ) opts.phone = (char *)xstrcpy(optarg);
}
break;
case 'l':
if( ISDEC(optarg) && opts.daemon == 0 )
opts.hiddline = atoi(optarg);
else
{ usage(); exit(BFERR_FATALERROR); }
break;
case 'a':
if( opts.daemon )
{ usage(); exit(BFERR_FATALERROR); }
else
{
if( opts.iaddr ) free(opts.iaddr);
if( optarg ) opts.iaddr = (char *)xstrcpy(optarg);
}
break;
case 'S':
if( opts.daemon )
{ usage(); exit(BFERR_FATALERROR); }
else
{
if( opts.connect ) free(opts.connect);
if( optarg ) opts.connect = (char *)xstrcpy(optarg);
}
break;
case 'p':
if( opts.daemon )
{ usage(); exit(BFERR_FATALERROR); }
else
{
if( opts.device ) free(opts.device);
if( optarg ) opts.device = (char *)xstrcpy(optarg);
}
break;
default :
usage();
exit(BFERR_FATALERROR);
}
}
/* Expression checker use it, so init first */
init_state(&state);
/* Set space available for process title */
#ifndef HAVE_SETPROCTITLE
setargspace(argv, envp);
#endif
/* Initialise random number generation */
(void)srand((unsigned)time(NULL));
/* Initialise current locale */
(void)setlocale(LC_ALL, "");
/* Set secure process umask */
(void)umask(~(S_IRUSR|S_IWUSR));
/* Now process non-option arguments */
if( opts.daemon == FALSE )
{
const char *p;
s_faddr addr;
s_falist **alist = &opts.addrlist;
while( (optind < argc) && (p = argv[optind++]) )
{
for( ; *p == '*'; p++ );
if( strcasecmp(p, "tsync") == 0 )
{
role = 0;
opts.stype = SESSION_FTSC;
}
else if( strcasecmp(p, "yoohoo") == 0 )
{
role = 0;
opts.stype = SESSION_YOOHOO;
}
else if( strcasecmp(p, "**EMSI_INQC816") == 0 )
{
role = 0;
opts.stype = SESSION_EMSI;
}
else if( strncasecmp(p, "emsi", 4) == 0 )
{
role = 0;
opts.stype = SESSION_EMSI;
}
else if( strcasecmp(p, "binkp") == 0 )
{
role = 0;
opts.stype = SESSION_BINKP;
}
else if( strcasecmp(p, "auto") == 0 )
{
role = 0;
opts.stype = SESSION_UNKNOWN;
}
else if( ftn_addrparse(&addr, p, FALSE) == 0 )
{
role = 1;
(*alist) = (s_falist*)xmalloc(sizeof(s_falist));
memset(*alist, '\0', sizeof(s_falist));
(*alist)->addr = addr;
alist = &(*alist)->next;
}
else
{
printf("invalid address \"%s\"", p);
usage();
exit(BFERR_FATALERROR);
}
}
if( opts.dontcall && role == 0 )
{
usage();
exit(BFERR_FATALERROR);
}
}
/* if( (rc = log_open(log_getfilename(LOG_FILE_SESSION), NULL, NULL)) )
{
log("can't continue without logging");
gotoexit(BFERR_FATALERROR);
}
*/
/* Process primary config file */
if( opts.confname && *opts.confname )
rc = conf_readconf(opts.confname, 0);
else
rc = conf_readconf(conf_getconfname(), 0);
if( rc ) gotoexit(BFERR_FATALERROR);
/* Process additional config file, ignore errors */
if( opts.incname && *opts.incname )
(void)conf_readconf(opts.incname, 1);
/* Reopen log file if it was defined in config */
if( log_open(log_getfilename(LOG_FILE_SESSION), NULL, NULL) )
{
log("can't continue without logging");
gotoexit(BFERR_FATALERROR);
}
#ifdef DEBUG
/* Same for the debug file */
(void)debug_setfilename(log_getfilename(LOG_FILE_DEBUG));
#endif
if( opts.daemon )
rc = bforce_daemon(&opts);
else if( role )
rc = bforce_master(&opts);
else
rc = bforce_slave(&opts);
exit:
deinit_conf();
deinit_opts(&opts);
/* Shutdown logging services */
if( log_isopened() ) log_close();
#ifdef DEBUG
if( debug_isopened() ) debug_close();
#endif
exit(rc);
}
static void deinit_opts(s_bforce_opts *opts)
{
if( opts->confname ) free(opts->confname);
if( opts->incname ) free(opts->incname);
if( opts->phone ) free(opts->phone);
if( opts->iaddr ) free(opts->iaddr);
if( opts->connect ) free(opts->connect);
if( opts->device ) free(opts->device);
if( opts->addrlist ) deinit_falist(opts->addrlist);
memset(opts, '\0', sizeof(s_bforce_opts));
}
+135
View File
@@ -0,0 +1,135 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
void deinit_conf(void)
{
s_cval_entry *ptrl;
s_cval_entry *next;
int i;
for( i = 0; bforce_config[i].name; i++ )
{
for( ptrl = bforce_config[i].data; ptrl; ptrl = next )
{
next = ptrl->next;
deinit_cval_entry(ptrl, bforce_config[i].type);
free(ptrl);
}
bforce_config[i].data = NULL;
}
}
void deinit_cval_entry(s_cval_entry *dest, bforce_config_keyword type)
{
/*
* Other config variables doesn't use allocated memory
*/
switch(type) {
case CT_ADDRESS:
case CT_NODELIST:
case CT_PASSWORD:
if( dest->d.falist.what )
free(dest->d.falist.what);
break;
case CT_DOMAIN:
deinit_domain(&dest->d.domain);
break;
case CT_DIALRESP:
deinit_dialresp(&dest->d.dialresp);
break;
case CT_MODEMPORT:
deinit_modemport(&dest->d.modemport);
break;
case CT_OVERRIDE:
deinit_override(&dest->d.override);
break;
case CT_PATH:
case CT_STRING:
deinit_string(&dest->d.string);
break;
case CT_TRANSLATE:
deinit_translate(&dest->d.translate);
break;
default:
DEB((D_CONFIG, "deinit_cval_entry: type %d doesn't use dynamic memory",
type));
}
}
void deinit_dialresp(s_dialresp *dest)
{
if( dest->mstr ) free(dest->mstr);
}
void deinit_domain(s_domain *dest)
{
if( dest->domain ) free(dest->domain);
if( dest->path ) free(dest->path);
}
void deinit_expr(s_expr *dest)
{
if( dest->expr ) free(dest->expr);
}
void deinit_falist(s_falist *dest)
{
s_falist *ptrl, *next;
for( ptrl = dest; ptrl; ptrl = next )
{
next = ptrl->next;
if( ptrl->what ) free(ptrl->what);
free(ptrl);
}
}
void deinit_modemport(s_modemport *dest)
{
if( dest->name ) free(dest->name);
}
void deinit_override(s_override *dest)
{
s_override *ptrl, *next;
if( dest->sIpaddr ) free(dest->sIpaddr);
if( dest->sPhone ) free(dest->sPhone);
if( dest->sFlags ) free(dest->sFlags);
for( ptrl = dest->hidden; ptrl; ptrl = next )
{
next = ptrl->hidden;
if( ptrl->sIpaddr ) free(ptrl->sIpaddr);
if( ptrl->sPhone ) free(ptrl->sPhone);
if( ptrl->sFlags ) free(ptrl->sFlags);
free(ptrl);
}
}
void deinit_string(s_string *dest)
{
if( dest->str ) free(dest->str);
}
void deinit_translate(s_translate *dest)
{
if( dest->find ) free(dest->find);
if( dest->repl ) free(dest->repl);
}
+108
View File
@@ -0,0 +1,108 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
s_cval_entry *conf_first(bforce_config_keyword keyword)
{
s_cval_entry *ptrl;
for( ptrl = bforce_config[keyword].data; ptrl; ptrl = ptrl->next )
if( !ptrl->expr.expr || eventexpr(&ptrl->expr) )
return ptrl;
return NULL;
}
s_cval_entry *conf_next(s_cval_entry *ptrl)
{
ASSERT(ptrl);
for( ptrl = ptrl->next; ptrl; ptrl = ptrl->next )
if( !ptrl->expr.expr || eventexpr(&ptrl->expr) )
return ptrl;
return NULL;
}
bool conf_boolean(bforce_config_keyword keyword)
{
s_cval_entry *ptrl = conf_first(keyword);
return ptrl ? ptrl->d.boolean.istrue : FALSE;
}
mode_t conf_filemode(bforce_config_keyword keyword)
{
s_cval_entry *ptrl = conf_first(keyword);
return ptrl ? ptrl->d.filemode.mode : (mode_t)0;
}
long conf_options(bforce_config_keyword keyword)
{
long result = 0L;
s_cval_entry *ptrl;
for( ptrl = conf_first(keyword); ptrl; ptrl = conf_next(ptrl) )
result = ((~ptrl->d.options.mask) & result) | ptrl->d.options.value;
return result;
}
long conf_connlist(bforce_config_keyword keyword, long speed)
{
s_cval_entry *ptrl;
for( ptrl = conf_first(keyword); ptrl; ptrl = conf_next(ptrl) )
if( ptrl->d.connlist.speed == speed )
return ptrl->d.connlist.value;
return 0;
}
char *conf_string(bforce_config_keyword keyword)
{
s_cval_entry *ptrl = conf_first(keyword);
return ptrl ? ptrl->d.string.str : (char*)NULL;
}
long conf_number(bforce_config_keyword keyword)
{
s_cval_entry *ptrl = conf_first(keyword);
return ptrl ? ptrl->d.number.num : (long)0L;
}
s_override *conf_override(bforce_config_keyword keyword, s_faddr addr)
{
s_cval_entry *ptrl;
for( ptrl = conf_first(keyword); ptrl; ptrl = conf_next(ptrl) )
if( !ftn_addrcomp(ptrl->d.override.addr, addr) )
return &ptrl->d.override;
return NULL;
}
s_tries *conf_tries(bforce_config_keyword keyword)
{
s_cval_entry *ptrl = conf_first(keyword);
return ptrl ? &ptrl->d.tries : NULL;
}
+997
View File
@@ -0,0 +1,997 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "outbound.h" /* Required only for ``proc_filebox()'' */
struct tab_options {
const char *keystr;
unsigned long value_no;
unsigned long value_yes;
} options[] = {
{ "Zmodem", OPTIONS_NO_ZMODEM, 0 },
{ "ZedZap", OPTIONS_NO_ZEDZAP, 0 },
{ "DirZap", OPTIONS_NO_DIRZAP, 0 },
{ "Janus", OPTIONS_NO_JANUS, 0 },
{ "Hydra", OPTIONS_NO_HYDRA, 0 },
{ "BinkP", OPTIONS_NO_BINKP, 0 },
{ "TCP", OPTIONS_NO_TCP, 0 },
{ "Chat", OPTIONS_NO_CHAT, 0 },
{ "FTS1", OPTIONS_NO_FTS1, 0 },
{ "YooHoo", OPTIONS_NO_YOOHOO, 0 },
{ "EMSI", OPTIONS_NO_EMSI, 0 },
{ "EMSI-II", OPTIONS_NO_EMSI_II, 0 },
{ "Freqs", OPTIONS_NO_FREQS, 0 },
{ "MailOnly", 0, OPTIONS_MAILONLY },
{ "HoldXT" , 0, OPTIONS_HOLDXT },
{ "HoldReq", 0, OPTIONS_HOLDREQ },
{ "HoldAll", 0, OPTIONS_HOLDALL },
{ "HoldHold", 0, OPTIONS_HOLDHOLD },
{ "PickUp", OPTIONS_NO_PICKUP, 0 },
{ "RH1", OPTIONS_NO_RH1, 0 },
{ "Intro", OPTIONS_NO_INTRO, 0 },
{ NULL, 0, 0 }
};
struct tab_resptypes {
const char *str;
int value;
int retv;
} resptypes[] = {
{ "Connect", RESPTYPE_CONNECT, 0 },
{ "Busy", RESPTYPE_BUSY, 11 },
{ "Nocarrier", RESPTYPE_NOCARRIER, 12 },
{ "Nodialtone", RESPTYPE_NODIALTONE, 13 },
{ "Noanswer", RESPTYPE_NOANSWER, 14 },
{ "Error", RESPTYPE_ERROR, 15 },
{ NULL, 0, 0 }
};
#define CONF_KEY(name, type) { #name, type, NULL, cf_##name }
#define CONF_END() { NULL, 0, NULL, 0 }
s_conf_entry bforce_config[BFORCE_NUMBER_OF_KEYWORDS+1] = {
CONF_KEY(address, CT_ADDRESS),
CONF_KEY(amiga_outbound_directory, CT_PATH),
CONF_KEY(binkp_timeout, CT_NUMBER),
CONF_KEY(daemon_circle, CT_NUMBER),
CONF_KEY(daemon_circle_crash, CT_NUMBER),
CONF_KEY(daemon_circle_direct, CT_NUMBER),
CONF_KEY(daemon_circle_immed, CT_NUMBER),
CONF_KEY(daemon_circle_modem, CT_NUMBER),
CONF_KEY(daemon_circle_normal, CT_NUMBER),
CONF_KEY(daemon_circle_rescan, CT_NUMBER),
CONF_KEY(daemon_maxclients_modem, CT_NUMBER),
CONF_KEY(daemon_maxclients_tcpip, CT_NUMBER),
CONF_KEY(daemon_pid_file, CT_STRING),
CONF_KEY(delay_files_recv, CT_STRING),
CONF_KEY(delay_files_send, CT_STRING),
CONF_KEY(disable_aka_matching, CT_BOOLEAN),
CONF_KEY(domain, CT_DOMAIN),
CONF_KEY(emsi_FR_time, CT_STRING),
CONF_KEY(emsi_OH_time, CT_STRING),
CONF_KEY(emsi_slave_sends_nak, CT_BOOLEAN),
CONF_KEY(filebox, CT_FILEBOX),
CONF_KEY(filebox_directory, CT_PATH),
CONF_KEY(flags, CT_STRING),
CONF_KEY(flo_translate, CT_TRANSLATE),
CONF_KEY(freq_alias_list, CT_STRING),
CONF_KEY(freq_dir_list, CT_STRING),
CONF_KEY(freq_ignore_masks, CT_STRING),
CONF_KEY(freq_limit_number, CT_NUMBER),
CONF_KEY(freq_limit_size, CT_NUMBER),
CONF_KEY(freq_limit_time, CT_NUMBER),
CONF_KEY(freq_min_speed, CT_NUMBER),
CONF_KEY(freq_srif_command, CT_STRING),
CONF_KEY(hide_our_aka, CT_ADDRESS),
CONF_KEY(history_file, CT_STRING),
CONF_KEY(hydra_options, CT_OPTIONS),
CONF_KEY(hydra_mincps_recv, CT_CONNLIST),
CONF_KEY(hydra_mincps_send, CT_CONNLIST),
CONF_KEY(hydra_tx_window, CT_NUMBER),
CONF_KEY(hydra_rx_window, CT_NUMBER),
CONF_KEY(inbound_directory, CT_PATH),
CONF_KEY(location, CT_STRING),
CONF_KEY(log_file, CT_STRING),
CONF_KEY(log_file_daemon, CT_STRING),
CONF_KEY(max_speed, CT_NUMBER),
CONF_KEY(maxtries, CT_TRIES),
CONF_KEY(maxtries_nodial, CT_TRIES),
CONF_KEY(maxtries_noansw, CT_TRIES),
CONF_KEY(maxtries_noconn, CT_TRIES),
CONF_KEY(maxtries_hshake, CT_TRIES),
CONF_KEY(maxtries_sessions, CT_TRIES),
CONF_KEY(min_cps_recv, CT_NUMBER),
CONF_KEY(min_cps_send, CT_NUMBER),
CONF_KEY(min_cps_time, CT_NUMBER),
CONF_KEY(min_free_space, CT_NUMBER),
CONF_KEY(min_speed_in, CT_NUMBER),
CONF_KEY(min_speed_out, CT_NUMBER),
CONF_KEY(mode_netmail, CT_FILEMODE),
CONF_KEY(mode_arcmail, CT_FILEMODE),
CONF_KEY(mode_request, CT_FILEMODE),
CONF_KEY(mode_ticfile, CT_FILEMODE),
CONF_KEY(mode_default, CT_FILEMODE),
CONF_KEY(modem_can_send_break, CT_BOOLEAN),
CONF_KEY(modem_dial_prefix, CT_STRING),
CONF_KEY(modem_dial_suffix, CT_STRING),
CONF_KEY(modem_dial_response, CT_DIALRESP),
CONF_KEY(modem_hangup_command, CT_STRING),
CONF_KEY(modem_port, CT_MODEMPORT),
CONF_KEY(modem_reset_command, CT_STRING),
CONF_KEY(modem_stat_command, CT_STRING),
CONF_KEY(nodelist, CT_NODELIST),
CONF_KEY(nodelist_directory, CT_PATH),
CONF_KEY(nodial_flag, CT_STRING),
CONF_KEY(override, CT_OVERRIDE),
CONF_KEY(options, CT_OPTIONS),
CONF_KEY(outbound_directory, CT_PATH),
CONF_KEY(password, CT_PASSWORD),
CONF_KEY(phone, CT_STRING),
CONF_KEY(phone_translate, CT_TRANSLATE),
CONF_KEY(recode_file_in, CT_STRING),
CONF_KEY(recode_file_out, CT_STRING),
CONF_KEY(recode_intro_in, CT_STRING),
CONF_KEY(recv_buffer_size, CT_NUMBER),
CONF_KEY(rescan_delay, CT_NUMBER),
CONF_KEY(run_after_handshake, CT_STRING),
CONF_KEY(run_after_session, CT_STRING),
CONF_KEY(session_limit_in, CT_NUMBER),
CONF_KEY(session_limit_out, CT_NUMBER),
CONF_KEY(skip_files_recv, CT_STRING),
CONF_KEY(status_directory, CT_PATH),
CONF_KEY(system_name, CT_STRING),
CONF_KEY(sysop_name, CT_STRING),
CONF_KEY(uucp_lock_directory, CT_PATH),
CONF_KEY(wait_carrier_in, CT_NUMBER),
CONF_KEY(wait_carrier_out, CT_NUMBER),
CONF_KEY(zmodem_mincps_recv, CT_CONNLIST),
CONF_KEY(zmodem_mincps_send, CT_CONNLIST),
CONF_KEY(zmodem_send_dummy_pkt, CT_BOOLEAN),
CONF_KEY(zmodem_skip_by_pos, CT_BOOLEAN),
CONF_KEY(zmodem_start_block_size, CT_NUMBER),
CONF_KEY(zmodem_tx_window, CT_NUMBER),
CONF_KEY(nomail_flag, CT_STRING),
CONF_KEY(bind_ip, CT_STRING),
#ifdef USE_SYSLOG
CONF_KEY(syslog_facility, CT_NUMBER),
#endif
#ifdef DEBUG
CONF_KEY(debug_file, CT_STRING),
CONF_KEY(debug_level, CT_DEBLEVEL),
#endif
CONF_END()
};
static int proc_override(s_override *dest, char *value);
static int proc_options(s_options *options, char *value);
static int proc_string(s_string *dest, char *value);
static int proc_number(s_number *dest, char *value);
static int proc_filemode(s_filemode *dest, char *value);
static int proc_boolean(s_boolean *dest, char *value);
static int proc_address(s_falist *dest, char *value);
static int proc_nodelist(s_falist *dest, char *value);
static int proc_modemport(s_modemport *dest, char *value);
static int proc_domain(s_domain *dest, char *value);
static int proc_password(s_falist *dest, char *value);
static int proc_path(s_string *dest, char *value);
static int proc_dialresp(s_dialresp *dest, char *value);
static int proc_translate(s_translate *dest, char *value);
static int proc_speeddep(s_connlist *dest, char *value);
static int proc_tries(s_tries *dest, char *value);
#ifdef DEBUG
static int proc_debuglevel(s_number *dest, char *value);
#endif
static int proc_filebox(s_filebox *dest, char *value);
static int append_config_entry(s_conf_entry *conf_ent, s_cval_entry *cval_entry)
{
s_cval_entry **ptrl;
for( ptrl = &conf_ent->data; *ptrl; ptrl = &(*ptrl)->next );
*ptrl = (s_cval_entry *)xmalloc(sizeof(s_cval_entry));
memcpy(*ptrl, cval_entry, sizeof(s_cval_entry));
return 0;
}
int proc_configline(const char *k, const char *e, const char *v)
{
s_cval_entry temp_value;
int rc = PROC_RC_ABORT;
int i;
char *copy;
ASSERT(k != NULL && v != NULL );
DEB((D_CONFIG, "conf_proc: key \"%s\" expr \"%s\" value \"%s\"",
k, e, v));
copy = xstrcpy(v);
for( i = 0; bforce_config[i].name; i++ )
if( !strcmp(bforce_config[i].name, k) )
break;
if( bforce_config[i].name )
{
/*
* Make all changes in temp_value structure
*/
memset(&temp_value, '\0', sizeof(s_cval_entry));
switch(bforce_config[i].type) {
case CT_ADDRESS:
rc = proc_address(&temp_value.d.falist, copy);
break;
case CT_BOOLEAN:
rc = proc_boolean(&temp_value.d.boolean, copy);
break;
case CT_CONNLIST:
rc = proc_speeddep(&temp_value.d.connlist, copy);
break;
case CT_DIALRESP:
rc = proc_dialresp(&temp_value.d.dialresp, copy);
break;
case CT_DOMAIN:
rc = proc_domain(&temp_value.d.domain, copy);
break;
case CT_FILEMODE:
rc = proc_filemode(&temp_value.d.filemode, copy);
break;
case CT_MODEMPORT:
rc = proc_modemport(&temp_value.d.modemport, copy);
break;
case CT_NODELIST:
rc = proc_nodelist(&temp_value.d.falist, copy);
break;
case CT_NUMBER:
rc = proc_number(&temp_value.d.number, copy);
break;
case CT_OPTIONS:
rc = proc_options(&temp_value.d.options, copy);
break;
case CT_OVERRIDE:
rc = proc_override(&temp_value.d.override, copy);
break;
case CT_PATH:
rc = proc_path(&temp_value.d.string, copy);
break;
case CT_PASSWORD:
rc = proc_password(&temp_value.d.falist, copy);
break;
case CT_STRING:
rc = proc_string(&temp_value.d.string, copy);
break;
case CT_TRANSLATE:
rc = proc_translate(&temp_value.d.translate, copy);
break;
case CT_TRIES:
rc = proc_tries(&temp_value.d.tries, copy);
break;
#ifdef DEBUG
case CT_DEBLEVEL:
rc = proc_debuglevel(&temp_value.d.number, copy);
break;
#endif
case CT_FILEBOX:
rc = proc_filebox(&temp_value.d.filebox, copy);
break;
default:
log("internal error, unknown keyword type = %d",
bforce_config[i].type);
ASSERT(0);
}
if( rc == PROC_RC_OK || rc == PROC_RC_WARN )
{
if( e && *e )
{
temp_value.expr.expr = xstrcpy(e);
temp_value.expr.error = 0;
}
append_config_entry(&bforce_config[i], &temp_value);
}
}
else
{
log("unknown keyword \"%s\"", k);
rc = PROC_RC_IGNORE;
}
free(copy);
return rc;
}
/*
* Line format: Override <Address> <Overrides..> [Hidden <Overrides>]
*/
static int proc_override(s_override *dest, char *value)
{
s_override **p = &dest;
s_faddr addr;
int rc = PROC_RC_OK;
char *key = NULL;
char *arg = NULL;
char *n = NULL;
char *p_addr = NULL;
bool neednew = FALSE;
ASSERT(dest != NULL && value != NULL);
p_addr = string_token(value, &n, NULL, 0);
if( p_addr == NULL || *p_addr == '\0' || ftn_addrparse(&addr, p_addr, FALSE) )
return(PROC_RC_IGNORE);
memset(dest, '\0', sizeof(s_override));
dest->addr = addr;
while( key || (key = string_token(NULL, &n, NULL, 1)) )
{
if( (arg = string_token(NULL, &n, NULL, 1)) == NULL || *arg == '\0' )
{
log("no argument(s) for override \"%s\"", key);
if( rc < PROC_RC_WARN )
rc = PROC_RC_WARN;
break;
}
if( neednew )
{
(*p) = (s_override*)xmalloc(sizeof(s_override));
memset(*p, '\0', sizeof(s_override));
(*p)->addr = addr;
neednew = FALSE;
}
if( strcasecmp(key, "phone") == 0 )
{
if( (*p)->sPhone )
free((*p)->sPhone);
(*p)->sPhone = xstrcpy(arg);
key = NULL;
}
else if( strcasecmp(key, "ipaddr") == 0 )
{
if( (*p)->sIpaddr )
free((*p)->sIpaddr);
(*p)->sIpaddr = xstrcpy(arg);
key = NULL;
}
else if( strcasecmp(key, "worktime") == 0 )
{
if( timevec_parse_list(&((*p)->worktime), arg) == -1 )
{
log("invalid work time \"%s\"", arg);
if( rc < PROC_RC_WARN )
rc = PROC_RC_WARN;
}
key = NULL;
}
else if( strcasecmp(key, "freqtime") == 0 )
{
if( timevec_parse_list(&((*p)->freqtime), arg) == -1 )
{
log("invalid freq time \"%s\"", arg);
if( rc < PROC_RC_WARN )
rc = PROC_RC_WARN;
}
key = NULL;
}
else if( strcasecmp(key, "flags") == 0 )
{
if( (*p)->sFlags )
free((*p)->sFlags);
(*p)->sFlags = xstrcpy(arg);
key = NULL;
}
else if( strcasecmp(key, "hidden") == 0 )
{
neednew = TRUE;
p = &((*p)->hidden);
key = arg;
}
else
{
log("unknown keyword \"%s\" in override", key);
if( rc < PROC_RC_WARN )
rc = PROC_RC_WARN;
key = arg;
}
}
return(rc);
}
/*
* Line format: Options <options..>
*/
static int proc_options(s_options *dest, char *value)
{
int i, rc = PROC_RC_OK;
char *key = NULL, *n = NULL;
ASSERT(dest != NULL && value != NULL);
for( key = string_token(value, &n, NULL, 0); key;
key = string_token(NULL, &n, NULL, 0) )
{
for( i = 0; options[i].keystr; i++ )
{
if( strcasecmp(key, options[i].keystr) == 0 )
{
if( options[i].value_no )
{
dest->value &= ~options[i].value_no;
dest->mask |= options[i].value_no;
}
if( options[i].value_yes )
{
dest->value |= options[i].value_yes;
dest->mask |= options[i].value_yes;
}
#ifdef DEBUG
if( options[i].value_no == 0 && options[i].value_yes == 0 )
ASSERT_MSG();
#endif
break;
}
else if( (strncasecmp(key, "no", 2) == 0
&& strcasecmp(key+2, options[i].keystr) == 0)
|| (*key == '!'
&& strcasecmp(key+1, options[i].keystr) == 0) )
{
if( options[i].value_no )
{
dest->value |= options[i].value_no;
dest->mask |= options[i].value_no;
}
if( options[i].value_yes )
{
dest->value &= ~options[i].value_yes;
dest->mask |= options[i].value_yes;
}
#ifdef DEBUG
if( !options[i].value_no && !options[i].value_yes )
ASSERT_MSG();
#endif
break;
}
}
if( !options[i].keystr )
{
log("unknown option \"%s\"", key);
if( rc < PROC_RC_WARN )
rc = PROC_RC_WARN;
}
}
return(rc);
}
/*
* Line format: <Keyword> <Any value>
*/
static int proc_string(s_string *dest, char *value)
{
ASSERT(dest != NULL && value != NULL);
dest->str = xstrcpy(value);
return PROC_RC_OK;
}
/*
* Line format: <Keyword> <Number>
*/
static int proc_number(s_number *dest, char *value)
{
ASSERT(dest != NULL && value != NULL);
if( !ISDEC(value) )
{
log("value \"%s\" isn't numeric", value);
return(PROC_RC_IGNORE);
}
dest->num = atol(value);
return(PROC_RC_OK);
}
/*
* Line format: <Keyword> <Octal permissions>
*/
static int proc_filemode(s_filemode *dest, char *value)
{
int rc = PROC_RC_OK;
ASSERT(dest != NULL && value != NULL);
if( !ISOCT(value) )
{
log("value \"%s\" isn't octal number", value);
return(PROC_RC_IGNORE);
}
sscanf(value, "%o", (unsigned int *)&dest->mode);
return(rc);
}
/*
* Line format: <Keyword> <Yes|No|True|False>
*/
static int proc_boolean(s_boolean *dest, char *value)
{
ASSERT(dest != NULL && value != NULL);
if( !strcasecmp(value, "yes")
|| !strcasecmp(value, "true") )
{
dest->istrue = 1;
return(PROC_RC_OK);
}
else if( !strcasecmp(value, "no")
|| !strcasecmp(value, "false") )
{
dest->istrue = 0;
return(PROC_RC_OK);
}
log("unexpected argument \"%s\", must be \"Yes\" or \"No\"", value);
return(PROC_RC_IGNORE);
}
/*
* Line format: <Keyword> <FTN address|Inet address>
*/
static int proc_address(s_falist *dest, char *value)
{
s_faddr addr;
ASSERT(dest != NULL && value != NULL);
if( ftn_addrparse(&addr, value, FALSE) )
{
log("can't parse address \"%s\"", value);
return(PROC_RC_IGNORE);
}
dest->addr = addr;
return(PROC_RC_OK);
}
/*
* Line format: <Keyword> <File name> <Address>
*/
static int proc_nodelist(s_falist *dest, char *value)
{
s_faddr addr;
char *n = NULL;
char *p_name = NULL;
char *p_addr = NULL;
ASSERT(dest != NULL && value != NULL);
p_name = string_token(value, &n, NULL, 1);
p_addr = string_token(NULL, &n, NULL, 1);
if( p_name && *p_name && p_addr && *p_addr )
{
if( ftn_addrparse(&addr, p_addr, TRUE) == 0 )
{
dest->addr = addr;
dest->what = xstrcpy(p_name);
return(PROC_RC_OK);
}
else
{
log("can't parse address \"%s\"", p_addr);
return(PROC_RC_IGNORE);
}
}
log("incorrect nodelist specification");
return(PROC_RC_IGNORE);
}
/*
* Line format: <Keyword> <domain> <path> <zone>
*/
static int proc_domain(s_domain *dest, char *value)
{
char *n = NULL;
char *p_domn = NULL;
char *p_path = NULL;
char *p_zone = NULL;
ASSERT(dest != NULL && value != NULL);
p_domn = string_token(value, &n, NULL, 1);
p_path = string_token(NULL, &n, NULL, 1);
p_zone = string_token(NULL, &n, NULL, 1);
if( p_domn && *p_domn && p_path && *p_path && p_zone && *p_zone )
{
if( ISDEC(p_zone) )
{
dest->domain = xstrcpy(p_domn);
dest->zone = atoi(p_zone);
if( p_path[strlen(p_path)-1] == DIRSEPCHR )
dest->path = xstrcpy(p_path);
else
dest->path = string_concat(p_path, DIRSEPSTR, NULL);
return(PROC_RC_OK);
}
else
{
log("zone isn't numeric value in domain specification");
return(PROC_RC_IGNORE);
}
}
log("incorrect domain specification");
return(PROC_RC_IGNORE);
}
/*
* Line format: <Keyword> <port>[:<lockspeed>]
*/
static int proc_modemport(s_modemport *dest, char *value)
{
char *p_speed = NULL;
long speed = 0;
ASSERT(dest != NULL && value != NULL);
p_speed = strrchr(value, ':');
if( p_speed ) {
if( ISDEC(p_speed+1) )
{
p_speed[0] = '\0';
speed = atol(p_speed+1);
}
else
{
log("incorrect modem port \"%s\": bad lock speed", value);
return(PROC_RC_IGNORE);
}
}
dest->name = xstrcpy(value);
dest->speed = speed;
return(PROC_RC_OK);
}
/*
* Line format: <Keyword> <Address> <Password>
*/
static int proc_password(s_falist *dest, char *value)
{
s_faddr addr;
char *n = NULL;
char *p_addr = NULL;
char *p_passwd = NULL;
ASSERT(dest != NULL && value != NULL);
p_addr = string_token(value, &n, NULL, 1);
p_passwd = string_token(NULL, &n, NULL, 1);
if( p_addr && *p_addr && p_passwd && *p_passwd )
{
if( ftn_addrparse(&addr, p_addr, FALSE) == 0 )
{
dest->addr = addr;
dest->what = xstrcpy(p_passwd);
return(PROC_RC_OK);
}
else
{
log("can't parse address \"%s\"", value);
return(PROC_RC_IGNORE);
}
}
log("incorrect password specification");
return(PROC_RC_IGNORE);
}
/*
* Line format: <Keyword> <Path>
*/
static int proc_path(s_string *dest, char *value)
{
ASSERT(dest != NULL && value != NULL);
if( value[strlen(value)-1] == DIRSEPCHR )
dest->str = xstrcpy(value);
else
dest->str = string_concat(value, DIRSEPSTR, NULL);
return(PROC_RC_OK);
}
/*
* Line format: <Keyword> <<String1[:RC]> [String2[:RC]] ..>
*/
static int proc_dialresp(s_dialresp *dest, char *value)
{
int i;
char *n = NULL;
char *p_mstr = NULL;
char *p_type = NULL;
char *p_retv = NULL;
ASSERT(dest != NULL && value != NULL);
p_mstr = string_token(value, &n, NULL, 1);
p_type = string_token(NULL, &n, NULL, 1);
p_retv = string_token(NULL, &n, NULL, 1);
if( p_mstr && *p_mstr && p_type && *p_type )
{
if( p_retv && !ISDEC(p_retv) )
{
log("return code isn't numeric in modem response specification");
return(PROC_RC_IGNORE);
}
for( i = 0; resptypes[i].str; i++ )
if( strcasecmp(p_type, resptypes[i].str) == 0 )
break;
if( resptypes[i].str )
{
dest->mstr = xstrcpy(p_mstr);
dest->type = resptypes[i].value;
dest->retv = p_retv ? atoi(p_retv) : resptypes[i].retv;
return(PROC_RC_OK);
}
log("unknown response type \"%s\"", p_type);
return(PROC_RC_IGNORE);
}
log("incorrect modem response specification");
return(PROC_RC_IGNORE);
}
/*
* Line format: <Keyword> <Search value> <Replace value>
*/
static int proc_translate(s_translate *dest, char *value)
{
char *n = NULL;
char *p_find = NULL;
char *p_repl = NULL;
ASSERT(dest != NULL && value != NULL);
p_find = string_token(value, &n, NULL, 1);
p_repl = string_token(NULL, &n, NULL, 1);
if( p_find && *p_find )
{
dest->find = xstrcpy(p_find);
if( p_repl )
dest->repl = xstrcpy(p_repl);
return(PROC_RC_OK);
}
log("incorrect translation rule specification");
return(PROC_RC_IGNORE);
}
/*
* Line format: <Keyword> <Connect speed> <Number>
*/
static int proc_speeddep(s_connlist *dest, char *value)
{
char *n = NULL;
char *p_speed = NULL;
char *p_value = NULL;
ASSERT(dest != NULL && value != NULL);
p_speed = string_token(value, &n, NULL, 1);
p_value = string_token(NULL, &n, NULL, 1);
if( p_speed && *p_speed && p_value && *p_value )
{
if( ISDEC(p_speed) && ISDEC(p_value) )
{
dest->speed = atoi(p_speed);
dest->value = atoi(p_value);
return(PROC_RC_OK);
}
log("non-numeric value \"%s\" or \"%s\"", p_speed, p_value);
return(PROC_RC_IGNORE);
}
log("incorrect speed dependent config string");
return(PROC_RC_IGNORE);
}
/*
* Line format: <Keyword> <Tries number> [<Action> <Action argument(s)>]
*/
static int proc_tries(s_tries *dest, char *value)
{
int rc = PROC_RC_OK;
char *n = NULL;
char *p_tries = NULL;
char *p_action = NULL;
char *p_arg = NULL;
int action = TRIES_ACTION_UNDIALABLE;
int arg = 0;
ASSERT(dest != NULL && value != NULL);
p_tries = string_token(value, &n, NULL, 0);
p_action = string_token(NULL, &n, NULL, 0);
p_arg = string_token(NULL, &n, NULL, 0);
if( p_tries && *p_tries && ISDEC(p_tries) )
{
if( p_action && *p_action )
{
if( strcasecmp(p_action, "undialable") == 0 )
{
if( p_arg && *p_arg )
{
log("no argument needed for action 'undialable'");
rc = PROC_RC_WARN;
}
action = TRIES_ACTION_UNDIALABLE;
arg = 0;
}
else if( strcasecmp(p_action, "hold") == 0 )
{
if( p_arg && *p_arg && !ISDEC(p_arg) )
{
log("non-numeric argument for action 'hold'");
return PROC_RC_IGNORE;
}
else if( p_arg == NULL )
{
log("no argument for action 'hold'");
return PROC_RC_IGNORE;
}
action = TRIES_ACTION_HOLDSYSTEM;
arg = atoi(p_arg);
}
else if( strcasecmp(p_action, "holdall") == 0 )
{
if( p_arg && *p_arg && !ISDEC(p_arg) )
{
log("non-numeric argument for action 'holdall'");
return PROC_RC_IGNORE;
}
else if( p_arg == NULL )
{
log("no argument for action 'holdall'");
return PROC_RC_IGNORE;
}
action = TRIES_ACTION_HOLDALL;
arg = atoi(p_arg);
}
else
{
log("unknown action '%s'", p_action);
return PROC_RC_IGNORE;
}
}
dest->tries = atoi(p_tries);
dest->action = action;
dest->arg = arg;
return(rc);
}
log("non-numeric tries number \"%s\"", p_tries);
return(PROC_RC_IGNORE);
}
/*
* Line format: DebugLevel <Level> [<Level>]..
*/
#ifdef DEBUG
static int proc_debuglevel(s_number *dest, char *value)
{
int rc = PROC_RC_OK;
long deblevel = 0L;
ASSERT(dest != NULL && value != NULL);
if( debug_parsestring(value, &deblevel) ) rc = PROC_RC_WARN;
dest->num = deblevel;
return(rc);
}
#endif
/*
* Line format: <Keyword> <Directory> <Address>
*/
static int proc_filebox(s_filebox *dest, char *value)
{
s_faddr addr;
char *n = NULL;
char *p_path = NULL;
char *p_addr = NULL;
char *p_flav = NULL;
ASSERT(dest != NULL && value != NULL);
p_path = string_token(value, &n, NULL, 1);
p_addr = string_token(NULL, &n, NULL, 1);
p_flav = string_token(NULL, &n, NULL, 1);
if( p_path && *p_path && p_addr && *p_addr )
{
if( ftn_addrparse(&addr, p_addr, TRUE) == 0 )
{
int flavor = FLAVOR_HOLD;
int rc = PROC_RC_OK;
if( !is_directory(p_path) )
{
log("filebox directory \"%s\" doesn't exist", p_path);
rc = PROC_RC_WARN;
}
if( p_flav && *p_flav )
{
if( strcasecmp(p_flav, "hold") == 0 )
flavor = FLAVOR_HOLD;
else if( strcasecmp(p_flav, "normal") == 0 )
flavor = FLAVOR_NORMAL;
else if( strcasecmp(p_flav, "crash") == 0 )
flavor = FLAVOR_CRASH;
else if( strcasecmp(p_flav, "immediate") == 0 )
flavor = FLAVOR_IMMED;
else
{
log("unknown filebox flavor \"%s\"", p_flav);
rc = PROC_RC_WARN;
}
}
dest->addr = addr;
if( p_path[strlen(p_path)-1] == DIRSEPCHR )
dest->path = xstrcpy(p_path);
else
dest->path = string_concat(p_path, DIRSEPSTR, NULL);
dest->flavor = flavor;
return rc;
}
else
{
log("can't parse address \"%s\"", p_addr);
return PROC_RC_IGNORE;
}
}
log("incorrect filebox specification");
return PROC_RC_IGNORE;
}
+457
View File
@@ -0,0 +1,457 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#define COMMENTCHR '#'
#define PREPROCCHR '$'
#define ESCAPECHR '\\'
int conf_postreadcheck(void)
{
return 0;
}
const char *conf_getconfname(void)
{
const char *name = getenv("BFCONFIG");
if( name == NULL || *name == '\0' ) name = BFORCE_CFGFILE;
return(name);
}
int conf_readpasswdlist(s_falist **pwdlist, char *fname)
{
return(0);
}
/*
* Prepare config string for parsing, check for comments
* Return: zero - good string, non-zero - .. (you know)
*/
static int conf_checkstr(char *str)
{
int rc = 0;
char *p = NULL;
ASSERT(str != NULL);
if( isspace(*str) ) string_trimleft(str);
if( *str == '\0' || *str == COMMENTCHR )
{ rc = 1; }
if( (p = strrchr(str, COMMENTCHR)) && *(p-1) != ESCAPECHR )
{ *p = '\0'; }
string_trimright(str);
return rc;
}
/*
* Parse config string on: keyword, expression and value
* Return: zero - no errors, non-zero - incorrect syntax
*/
static void conf_parsestr(char *str, char **key, char **expr, char **value)
{
char *k = NULL; /* Keyword */
char *e = NULL; /* Expression */
char *v = NULL; /* Value */
char *p = NULL;
int brackets = 0;
ASSERT(str != NULL && key != NULL && expr != NULL && value != NULL);
*key = NULL; *expr = NULL; *value = NULL;
/* Get config keyword */
k = str;
while( isspace(*k) ) k++;
p = k;
while( !isspace(*p) && *p ) p++;
if( *p == '\0' )
{ *key = k; return; }
*p++ = '\0';
while( isspace(*p) ) p++;
v = p;
/* Get config expression (if specified) */
if( *p == '(' )
{
++p;
while( isspace(*p) ) p++;
for( e = p, brackets = 1; brackets > 0 && *p; )
{
if( *(p-1) != ESCAPECHR )
{
switch( *p ) {
case '(':
++brackets; break;
case ')':
--brackets; break;
}
}
if( brackets > 0 ) ++p;
}
if( *p != ')' ) return; /* No closing bracket */
/* Remove trailing spaces */
v = p--;
while( p > e && isspace(*p) ) *p-- = '\0';
*v++ = '\0';
}
/* Get config value */
while( isspace(*v) ) v++;
if( *v == '\0' )
{ *key = k; *expr = e; return; }
/* Remove trailing spaces */
p = v + strlen(v+1);
while( p > v && isspace(*p) ) *p-- = '\0';
/* Return information to function caller */
*key = k;
*expr = e;
*value = v;
return;
}
int conf_readconf(const char *confname, int inclevel)
{
FILE *fp = NULL;
char tmp[BF_MAXCFGLINE + 1];
int rc, maxrc = 0;
int line = 0;
char *fullstr = NULL; /* Result of strings concatenation */
char *value = NULL;
char *expr = NULL;
char *p_key = NULL;
char *p_expr = NULL;
char *p_value = NULL;
char *p = NULL;
char *ifexpr = NULL; /* Pointer to the `common' block expression */
bool isappend = FALSE; /* Append new string to the previous? */
bool isifexpr = FALSE; /* We are in `common' config block! */
if( inclevel == 0 )
{
int i;
/* Check config table correctness */
for( i = 0; bforce_config[i].name; i++ )
{
if( i != (int)bforce_config[i].real_key )
{
log("invalid config table: found %d instead of %d",
bforce_config[i].real_key, i);
return -1;
}
}
}
if( (fp = file_open(confname,"r")) == NULL )
{
logerr("can't open config file \"%s\"", confname);
return(PROC_RC_IGNORE);
}
DEB((D_CONFIG, "readconfig: start reading config \"%s\"", confname));
while( fgets(tmp, sizeof(tmp), fp) )
{
++line;
string_chomp(tmp);
if( conf_checkstr(tmp) )
{
if( isifexpr )
{
log("warning: automatically close expression at empty line %d", line);
if( ifexpr ) { free(ifexpr); ifexpr = NULL; }
isifexpr = FALSE;
}
if( !isappend )
continue;
log("warning: appending empty or comment line %d", line);
isappend = FALSE;
}
p = tmp + strlen(tmp+1);
if( *p == '\\' && *(p-1) != ESCAPECHR )
{
*p = '\0';
if( fullstr && isappend )
{
fullstr = xstrcat(fullstr, tmp);
}
else
{
if( fullstr ) free(fullstr);
fullstr = xstrcpy(tmp);
isappend = TRUE;
}
continue;
}
else if( isappend )
{
if( fullstr )
{ fullstr = xstrcat(fullstr, tmp); }
else
{ ASSERT_MSG(); }
isappend = FALSE;
}
/*
* Now we have string without comments
* and trailing/leading spaces in:
* - if single string than in $tmp[]
* - if concatanated strings than look $fullstr
*/
p_key = NULL;
p_expr = NULL;
p_value = NULL;
conf_parsestr(fullstr ? fullstr : tmp, &p_key, &p_expr, &p_value);
DEB((D_CONFIG, "conf_readconf: [%d] key \"%s\" expr \"%s\" value \"%s\"",
line, p_key, p_expr, p_value));
if( p_value )
{
value = xstrcpy(p_value);
string_dequote(value, p_value);
}
if( p_expr )
{
expr = xstrcpy(p_expr);
string_dequote(expr, p_expr);
}
if( p_key && *p_key == PREPROCCHR )
{
/* Preprocessor directives */
rc = PROC_RC_OK;
if( strcasecmp(p_key+1, "include") == 0 )
{
if( value == NULL || expr )
{
log("incorrect usage of `%s' directive", p_key);
rc = PROC_RC_IGNORE;
}
else if( inclevel < MAXINCLUDELEVEL )
{
DEB((D_CONFIG, "conf_readconf: process inlude file \"%s\"", value));
rc = conf_readconf(value, inclevel + 1);
if( rc ) rc = PROC_RC_IGNORE;
}
else
{
DEB((D_CONFIG, "conf_readconf: too deep include"));
log("including level too deep");
rc = PROC_RC_IGNORE;
}
}
else if( strcasecmp(p_key+1, "ifexp") == 0 )
{
if( value || isifexpr )
{
log("incorrect usage of `%s' directive", p_key);
rc = PROC_RC_ABORT;
}
else
{
if( ifexpr )
{ free(ifexpr); ifexpr = NULL; }
if( expr )
ifexpr = xstrcpy(expr);
isifexpr = TRUE;
}
}
else if( strcasecmp(p_key+1, "endif") == 0 )
{
if( value || expr || !isifexpr )
{
log("incorrect usage of `%s' directive", p_key);
rc = PROC_RC_IGNORE;
}
else
{
if( ifexpr ) { free(ifexpr); ifexpr = NULL; }
isifexpr = FALSE;
}
}
else if( strcasecmp(p_key+1, "logfile") == 0 )
{
if( value == NULL || expr )
{
log("incorrect usage of `%s' directive", p_key);
rc = PROC_RC_IGNORE;
}
else
{
if( log_reopen(value, NULL, NULL) )
{
log("can't continue without logging");
rc = PROC_RC_ABORT;
}
}
}
else if( strcasecmp(p_key+1, "debugfile") == 0 )
{
if( value == NULL || expr )
{
log("incorrect usage of `%s' directive", p_key);
rc = PROC_RC_IGNORE;
}
else
#ifdef DEBUG
{
if( debug_isopened() ) debug_close();
debug_setfilename(value);
}
#else
{
log("incorrect directive `%s': no debug code", p_key);
rc = PROC_RC_IGNORE;
}
#endif
}
else if( strcasecmp(p_key+1, "debuglevel") == 0 )
{
if( value == NULL || expr )
{
rc = PROC_RC_IGNORE;
}
else
#ifdef DEBUG
{
unsigned long newlevel = 0L;
if( debug_parsestring(value, &newlevel) )
{
rc = PROC_RC_WARN;
}
debug_setlevel(newlevel, 1);
}
#else
{
log("incorrect directive `%s': no debug code", p_key);
rc = PROC_RC_IGNORE;
}
#endif
}
else
{
log("unknown directive `%s'", p_key);
rc = PROC_RC_IGNORE;
}
}
else if( p_key && value )
{
if( isifexpr && expr )
{
log("can't use expressions inside $ifexpr block");
rc = PROC_RC_IGNORE;
}
else if( isifexpr )
{
rc = proc_configline(p_key, ifexpr, value);
}
else
{
rc = proc_configline(p_key, expr, value);
}
}
else
{
log("incorrect config string");
rc = PROC_RC_IGNORE;
}
if( fullstr )
{ free(fullstr); fullstr = NULL; }
if( value )
{ free(value); value = NULL; }
if( expr )
{ free(expr); expr = NULL; }
switch(rc) {
case PROC_RC_OK:
break;
case PROC_RC_WARN:
log("warning in config \"%s\" line %d", confname, line);
break;
case PROC_RC_IGNORE:
log("ignore line %d in config \"%s\"", line, confname);
break;
case PROC_RC_ABORT:
log("fatal error in config \"%s\" in line %d", confname, line);
break;
default:
ASSERT_MSG();
break;
}
if( rc == PROC_RC_ABORT ) { maxrc = 1; break; }
} /* end of while */
file_close(fp);
if( isifexpr )
{ maxrc = 1; log("unterminated directive `#ifexp'"); }
if( fullstr )
free(fullstr);
if( ifexpr )
free(ifexpr);
DEB((D_CONFIG, "readconfig: exit with maxrc = %d", maxrc));
return maxrc;
}
#ifdef DEBUG
void debug_override(void)
{
s_cval_entry *ptrl;
char abuf[BF_MAXADDRSTR+1];
DEB((D_CONFIG, "debug_override: BEGIN"));
for( ptrl = bforce_config[cf_override].data; ptrl; ptrl = ptrl->next )
{
DEB((D_CONFIG, "log_overridelist: address %s",
ftn_addrstr(abuf, ptrl->d.override.addr)));
DEB((D_CONFIG, "log_overridelist: \tIpaddr = \"%s\"",
ptrl->d.override.sIpaddr));
DEB((D_CONFIG, "log_overridelist: \tPhone = \"%s\"",
ptrl->d.override.sPhone));
DEB((D_CONFIG, "log_overridelist: \tWorktime = \"%s\"",
timevec_string(abuf, &ptrl->d.override.worktime, sizeof(abuf))));
DEB((D_CONFIG, "log_overridelist: \tFlags = \"%s\"",
ptrl->d.override.sFlags));
}
DEB((D_CONFIG, "debug_override: END"));
}
#endif /* DEBUG */
File diff suppressed because it is too large Load Diff
+161
View File
@@ -0,0 +1,161 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "daemon.h"
static s_daemon_branch *daemon_branch_tab = NULL;
static signed int daemon_branch_num = 0;
#define ASSERT_POS(pos) ASSERT((pos) >= 0 && ((pos) + 1) <= daemon_branch_num \
&& daemon_branch_tab)
bool daemon_branch_exist(s_faddr addr)
{
int i;
for( i = 0; i < daemon_branch_num; i++ )
if( !ftn_addrcomp(daemon_branch_tab[i].addr, addr) )
return TRUE;
return FALSE;
}
void daemon_branch_check_stop_timers(void)
{
int i;
time_t now = time(0);
for( i = 0; i < daemon_branch_num; i++ )
if( daemon_branch_tab[i].stop && !daemon_branch_tab[i].wait
&& now >= daemon_branch_tab[i].stop )
{
if( kill(daemon_branch_tab[i].pid, SIGKILL) == -1 )
logerr("cannot kill branch with PID %d",
(int)daemon_branch_tab[i].pid);
}
}
int daemon_branch_exit(pid_t pid, int rc)
{
int i;
for( i = 0; i < daemon_branch_num; i++ )
if( daemon_branch_tab[i].pid == pid )
{
daemon_branch_tab[i].rc = rc;
daemon_branch_tab[i].wait = TRUE;
return 0;
}
return -1;
}
int daemon_branch_get_first_waiting(void)
{
int i;
for( i = 0; i < daemon_branch_num; i++ )
if( daemon_branch_tab[i].wait )
return i;
return -1;
}
s_daemon_branch *daemon_branch_get_pointer(int pos)
{
ASSERT_POS(pos);
if( pos + 1 > daemon_branch_num )
{
log("internal error: branch position is out of range");
return NULL;
}
return &daemon_branch_tab[pos];
}
void daemon_branch_add(s_faddr addr, pid_t pid, bool tcpip, const char *pname)
{
if( daemon_branch_tab )
{
daemon_branch_tab =
(s_daemon_branch *)xrealloc(daemon_branch_tab,
sizeof(s_daemon_branch)*(daemon_branch_num + 1));
memset(&daemon_branch_tab[daemon_branch_num], '\0',
sizeof(s_daemon_branch));
}
else
{
daemon_branch_tab =
(s_daemon_branch *)xmalloc(sizeof(s_daemon_branch));
memset(daemon_branch_tab, '\0', sizeof(s_daemon_branch));
daemon_branch_num = 0;
}
daemon_branch_tab[daemon_branch_num].addr = addr;
daemon_branch_tab[daemon_branch_num].wait = FALSE;
daemon_branch_tab[daemon_branch_num].tcpip = tcpip;
daemon_branch_tab[daemon_branch_num].pid = pid;
daemon_branch_tab[daemon_branch_num].start = time(NULL);
if( pname )
daemon_branch_tab[daemon_branch_num].portname = xstrcpy(pname);
daemon_branch_num++;
}
void daemon_branch_remove(int pos)
{
ASSERT_POS(pos);
if( daemon_branch_tab[pos].portname )
free(daemon_branch_tab[pos].portname);
if( daemon_branch_num > 1 )
{
memmove(&daemon_branch_tab[pos],
&daemon_branch_tab[pos+1],
sizeof(s_daemon_branch)*(daemon_branch_num - pos - 1));
daemon_branch_tab =
(s_daemon_branch *)xrealloc(daemon_branch_tab,
sizeof(s_daemon_branch)*(daemon_branch_num - 1));
daemon_branch_num--;
}
else
{
free(daemon_branch_tab);
daemon_branch_tab = NULL;
daemon_branch_num = 0;
}
}
int daemon_branch_number(void)
{
return daemon_branch_num;
}
void daemon_branch_deinit(void)
{
if( daemon_branch_tab )
free(daemon_branch_tab);
daemon_branch_tab = NULL;
daemon_branch_num = 0;
}
+202
View File
@@ -0,0 +1,202 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "nodelist.h"
#include "io.h"
#include "session.h"
#include "outbound.h"
#include "daemon.h"
static s_modemport *daemon_getfree_port(const char *lockdir)
{
s_cval_entry *ptrl;
/* Find first not locked modem device */
for( ptrl = conf_first(cf_modem_port); ptrl; ptrl = conf_next(ptrl) )
{
if( port_checklock(lockdir, &ptrl->d.modemport) == LOCKCHECK_NOLOCK
&& modem_candialout(ptrl->d.modemport.name) == TRUE
&& daemon_line_isready(ptrl->d.modemport.name) )
return &ptrl->d.modemport;
}
return NULL;
}
static int daemon_call_branch(s_sysentry *syst, const char *lockdir, s_modemport *port)
{
int rc = BFERR_NOERROR;
char abuf[BF_MAXADDRSTR+1];
/*
* First of all restore the default signal handlers
*/
signal(SIGCHLD, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL);
signal(SIGUSR1, SIG_DFL);
signal(SIGUSR2, SIG_DFL);
/*
* Initialise ``state'' information structure
*/
init_state(&state);
state.caller = TRUE;
state.valid = TRUE;
state.node = syst->node;
state.listed = syst->node.listed;
state.modemport = (!syst->tcpip) ? port : NULL;
if( syst->lineptr )
state.override = *syst->lineptr;
if( *state.node.addr.domain )
*state.node.addr.domain = '\0';
/*
* Apply overrides to the node information
*/
if( state.override.sFlags )
{
strnxcat(state.node.flags, ",", sizeof(state.node.flags));
strnxcat(state.node.flags, state.override.sFlags, sizeof(state.node.flags));
}
if( !syst->tcpip && state.override.sPhone )
(void)strnxcpy(state.node.phone, state.override.sPhone, sizeof(state.node.phone));
else if( syst->tcpip && state.override.sIpaddr )
(void)strnxcpy(state.node.phone, state.override.sIpaddr, sizeof(state.node.phone));
/*
* Try to lock address of system we are going to call
*/
#ifdef BFORCE_USE_CSY
if( out_bsy_lock(state.node.addr, TRUE) )
#else
if( out_bsy_lock(state.node.addr) )
#endif
gotoexit(BFERR_SYSTEM_LOCKED);
setproctitle("bforce calling %s, %s",
ftn_addrstr(abuf, state.node.addr), state.node.phone);
if( syst->tcpip )
{
rc = call_system_tcpip();
}
else /* via Modem */
{
state.modemport = port;
if( port_lock(lockdir, state.modemport) )
{
log("cannot lock modem port");
rc = BFERR_PORTBUSY;
}
else /* Locked port */
{
rc = call_system_modem();
port_unlock(lockdir, state.modemport);
}
}
exit:
out_bsy_unlockall();
log("session rc = %d (\"%s\")", rc, BFERR_NAME(rc));
(void)session_stat_update(&state.node.addr,
&state.sess_stat, TRUE, rc);
deinit_state(&state);
return rc;
}
int daemon_call(s_sysentry *syst)
{
pid_t chld_pid;
const char *p_lockdir = NULL;
char abuf[BF_MAXADDRSTR+1];
s_modemport *modemport = NULL;
/*
* Check number of allowed clients
*/
if( (syst->tcpip == TRUE && max_tcpip && max_tcpip <= tcpip_clients)
|| (syst->tcpip == FALSE && max_modem && max_modem <= modem_clients) )
{
DEB((D_DAEMON, "daemon_call: too many clients!"));
return 1;
}
/*
* Check whether this node is allready locked
*/
if( out_bsy_check(syst->node.addr) )
return 0;
/*
* Set state structure to make expressions works properly now
*/
state.caller = TRUE;
state.valid = TRUE;
state.node = syst->node;
state.listed = syst->node.listed;
state.inet = syst->tcpip;
if( syst->tcpip == FALSE )
{
if( (p_lockdir = conf_string(cf_uucp_lock_directory)) == NULL )
p_lockdir = BFORCE_LOCK_DIR;
if( (modemport = daemon_getfree_port(p_lockdir)) == NULL )
{
init_state(&state);
return 1;
}
}
log("call %s line %d via %s",
ftn_addrstr(abuf, syst->node.addr), syst->line,
syst->tcpip ? "TCP/IP" : modemport->name);
chld_pid = fork();
if( chld_pid > 0 )
{
(void)daemon_branch_add(syst->node.addr, chld_pid, syst->tcpip,
syst->tcpip ? NULL : modemport->name);
init_state(&state);
if( syst->tcpip )
++tcpip_clients;
else
++modem_clients;
return 0;
}
else if( chld_pid < 0 )
{
logerr("failed fork() call");
return 1;
}
/* Now we are in child process */
exit(daemon_call_branch(syst, p_lockdir, modemport));
}
+106
View File
@@ -0,0 +1,106 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
enum { LINE_TYPE_MODEM, LINE_TYPE_TCPIP };
typedef struct {
char *name;
time_t holdtimer;
int type;
} s_line;
static s_line *lines_tab = NULL;
static int lines_num = 0;
int daemon_line_add(const char *name, int type)
{
int i;
for( i = 0; i < lines_num; i++ )
if( !strcmp(lines_tab[i].name, name) )
return i;
log("register new line \"%s\"", name);
if( lines_tab )
{
lines_tab = (s_line *)xrealloc(lines_tab, sizeof(s_line)*(lines_num+1));
memset(&lines_tab[lines_num], '\0', sizeof(s_line));
}
else
{
lines_tab = (s_line *)xmalloc(sizeof(s_line));
memset(lines_tab, '\0', sizeof(s_line));
}
lines_tab[lines_num].name = xstrcpy(name);
lines_tab[lines_num].type = type;
return lines_num++;
}
void daemon_line_hold(const char *name, int holdtime)
{
int i;
for( i = 0; i < lines_num; i++ )
if( !strcmp(lines_tab[i].name, name) )
{
timer_set(&lines_tab[i].holdtimer, holdtime);
return;
}
i = daemon_line_add(name, 0);
timer_set(&lines_tab[i].holdtimer, holdtime);
}
bool daemon_line_isready(const char *name)
{
int i;
for( i = 0; i < lines_num; i++ )
if( !strcmp(lines_tab[i].name, name) )
{
if( !timer_running(lines_tab[i].holdtimer)
|| timer_expired(lines_tab[i].holdtimer) )
return TRUE;
return FALSE;
}
(void)daemon_line_add(name, 0);
return TRUE;
}
void daemon_lines_deinit(void)
{
int i;
for( i = 0; i < lines_num; i++ )
if( lines_tab[i].name )
free(lines_tab[i].name);
if( lines_tab )
{
free(lines_tab);
lines_tab = NULL;
}
lines_num = 0;
}
File diff suppressed because it is too large Load Diff
+443
View File
@@ -0,0 +1,443 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
%token COMMA
%token TEXT
%token NUMBER
%token INCOMING
%token OUTGOING
%token LISTED
%token PROTECTED
%token CONNSPEED
%token EXEC
%token EXIST
%token PORT
%token MAILER
%token TZ
%token FLAG
%token SPEED
%token PHONE
%token TIME
%token ADDRESS
%token EQ
%token NE
%token GT
%token GE
%token LT
%token LE
%token AND
%token OR
%token NOT
%token XOR
%token OPENB
%token CLOSEB
%token AROP
%token LOGOP
%expect 2
%{
#include "includes.h"
#include "confread.h"
#include "util.h"
#include "logger.h"
#include "session.h"
#include "nodelist.h"
#include "io.h"
static struct tm *now = NULL;
static int expr_result = 0;
static char *expr_p_pos = NULL;
static char *expr_p_text = NULL;
/*
* These are expression element checkers (not only)
* Return values:
* 0 - FALSE
* 1 - TRUE
* -1 - cannot check, because some data is not available yet
* -2 - invalid element (we should not check this expression more)
*/
static int expr_check_incoming(void);
static int expr_check_outgoing(void);
static int expr_check_protected(void);
static int expr_check_listed(void);
static int expr_check_logic(int e1, int op, int e2);
static int expr_check_phone(const char *phone);
static int expr_check_arop(int num1, int op, int num2);
static int expr_check_flag(const char *str);
static int expr_check_exec(const char *str);
static int expr_check_exist(const char *str);
static int expr_check_port(const char *str);
static int expr_check_mailer(const char *str);
static int expr_check_addr(const char *str);
static int expr_check_time(const char *str);
static int yylex(void);
static int yyparse(void);
static int yyerror(const char *s);
%}
%%
fullline : expression
{
DEB((D_EVENT, "[yacc] expression return %d", $1));
expr_result = $1;
}
;
expression : elemexp
{
DEB((D_EVENT, "[yacc] elemexp return %d", $1));
$$ = $1;
}
| NOT expression
{
DEB((D_EVENT, "[yacc] not exprression %d", $2));
if( ($2) < 0 )
$$ = 0;
else
$$ = !($2);
}
| expression LOGOP expression
{
$$ = expr_check_logic($1, $2, $3);
}
| OPENB expression CLOSEB
{
DEB((D_EVENT, "eventexp: [yacc] backeted.expr %d", $2));
$$ = $2;
}
;
elemexp : INCOMING
{
$$ = expr_check_incoming();
}
| OUTGOING
{
$$ = expr_check_outgoing();
}
| LISTED
{
$$ = expr_check_listed();
}
| PROTECTED
{
$$ = expr_check_protected();
}
| FLAG flagstring
{
$$ = $2;
}
| CONNSPEED AROP NUMBER
{
if( state.valid && state.connspeed > 0 )
$$ = expr_check_arop(state.connspeed, $2, $3);
else
$$ = -1;
}
| SPEED AROP NUMBER
{
if( state.valid && state.node.speed > 0 )
$$ = expr_check_arop(state.node.speed, $2, $3);
else
$$ = -1;
}
| TZ AROP NUMBER
{
$$ = expr_check_arop(time_gmtoffset(), $2, $3);
}
| PHONE TEXT
{
$$ = expr_check_phone(expr_p_text);
}
| TIME timestring
{
$$ = $2;
}
| EXEC TEXT
{
$$ = expr_check_exec(expr_p_text);
}
| EXIST TEXT
{
$$ = expr_check_exist(expr_p_text);
}
| PORT TEXT
{
$$ = expr_check_port(expr_p_text);
}
| MAILER TEXT
{
$$ = expr_check_mailer(expr_p_text);
}
| TEXT
{
$$ = expr_check_addr(expr_p_text);
if( $$ == -2 )
YYABORT;
}
;
flagstring : TEXT
{
$$ = expr_check_flag(expr_p_text);
}
| TEXT COMMA flagstring
{
$$ = expr_check_logic($1, OR, $3);
}
;
timestring : TEXT
{
$$ = expr_check_time(expr_p_text);
if( $$ == -2 )
YYABORT;
}
| TEXT COMMA timestring
{
$$ = expr_check_logic($1, OR, $3);
}
;
%%
#include "expression_lex.c"
static int expr_check_incoming(void)
{
if( !state.valid )
return -1;
return state.caller ? 0 : 1;
}
static int expr_check_outgoing(void)
{
if( !state.valid )
return -1;
return state.caller ? 1 : 0;
}
static int expr_check_protected(void)
{
if( !state.valid || !state.node.addr.zone )
return -1;
return state.protected ? 1 : 0;
}
static int expr_check_listed(void)
{
if( !state.valid || !state.node.addr.zone )
return -1;
return state.node.listed ? 1 : 0;
}
static int expr_check_logic(int e1, int op, int e2)
{
DEB((D_EVENT, "[yacc] logic: %d %d %d", e1, op, e2));
if( e1 < 0 ) e1 = 0;
if( e2 < 0 ) e2 = 0;
switch(op) {
case AND:
return (e1 && e2);
case OR:
return (e1 || e2);
case XOR:
return (e1 ^ e2);
}
log("invalid logical operator in expression");
return 0;
}
static int expr_check_phone(const char *phone)
{
DEB((D_EVENT, "[yacc] phone: is %s in %s",
phone, state.node.phone));
if( !state.valid )
return 0;
return strstr(state.node.phone, phone) ? 1 : 0;
}
static int expr_check_arop(int num1, int op, int num2)
{
DEB((D_EVENT, "[yacc] arop: %d %d %d", num1, op, num2));
switch(op) {
case EQ: return (num1 == num2);
case NE: return (num1 != num2);
case GT: return (num1 > num2);
case GE: return (num1 >= num2);
case LT: return (num1 < num2);
case LE: return (num1 <= num2);
}
log("invalid arithmetic operator in expression");
return 0;
}
static int expr_check_flag(const char *str)
{
DEB((D_EVENT, "[yacc] flag: \"%s\"", str));
if( !state.valid )
return 0;
return !nodelist_checkflag(state.node.flags, str);
}
static int expr_check_exec(const char *str)
{
DEB((D_EVENT, "[yacc] exec: \"%s\"", str));
return session_run_command(str) ? 0 : 1;
}
static int expr_check_exist(const char *str)
{
DEB((D_EVENT, "[yacc] exist: \"%s\"", str));
return access(str, F_OK) ? 1 : 0;
}
static int expr_check_port(const char *str)
{
DEB((D_EVENT, "[yacc] port: \"%s\"", str));
if( !state.valid )
return -1;
if( !strcasecmp(str, "tcpip") )
{
return state.inet ? 1 : 0;
}
else if( state.modemport && state.modemport->name )
{
return strstr(state.modemport->name, str) ? 1 : 0;
}
else if( isatty(0) )
{
return strstr(ttyname(0), str) ? 1 : 0;
}
return -1;
}
static int expr_check_mailer(const char *str)
{
char *p;
DEB((D_EVENT, "[yacc] mailer: \"%s\"", str));
if( !state.valid )
return -1;
if( state.handshake && state.handshake->remote_mailer )
p = state.handshake->remote_mailer(state.handshake);
else
return -1;
return (p && string_casestr(p, str)) ? 1 : 0;
}
static int expr_check_addr(const char *str)
{
s_faddr addr;
#ifdef DEBUG
char abuf1[BF_MAXADDRSTR+1];
char abuf2[BF_MAXADDRSTR+1];
DEB((D_EVENT, "[yacc] addr: \"%s\" (session with \"%s\")",
ftn_addrstr(abuf1, addr),
ftn_addrstr(abuf2, state.node.addr)));
#endif
if( !state.valid )
return -1;
if( ftn_addrparse(&addr, str, TRUE) )
{
log("invalid address \"%s\"", str);
return -2;
}
return !ftn_addrcomp_mask(state.node.addr, addr);
}
static int expr_check_time(const char *str)
{
DEB((D_EVENT, "[yacc] time: \"%s\"", str));
switch( time_check(str, now) ) {
case -1:
log("invalid time string \"%s\"", str);
return -2;
case 0:
return 1;
}
return 0;
}
bool eventexpr(s_expr *expr)
{
time_t tt;
char *tmp;
if( !expr || !expr->expr )
return 1;
if( expr->error )
return 0;
DEB((D_EVENT, "eventexpr: [yacc] check expression \"%s\"",
expr->expr));
tt = time(NULL);
now = localtime(&tt);
tmp = (char*)xstrcpy(expr->expr);
expr_p_pos = tmp;
expr_result = 0;
if( yyparse() )
{
expr->error = TRUE;
log("cannot parse expression \"%s\"", expr->expr);
DEB((D_EVENT, "eventexpr: [yacc] $yyparse return error"));
expr_result = 0;
}
free(tmp);
DEB((D_EVENT, "eventexpr: [yacc] checking result is \"%s\" (%d)",
(expr_result == 1) ? "TRUE" : "FALSE", expr_result));
return (expr_result == 1) ? TRUE : FALSE;
}
static int yyerror(const char *str)
{
log("expression check failure: %s", str);
return 0;
}
+174
View File
@@ -0,0 +1,174 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
typedef struct lextable {
const char *str;
int value;
int retc;
int len;
} s_lextable;
static bool initialised = FALSE;
static s_lextable *next = NULL;
static s_lextable operators[] =
{
{ "==", EQ, AROP, 0 },
{ "!=", NE, AROP, 0 },
{ ">", GT, AROP, 0 },
{ ">=", GE, AROP, 0 },
{ "<", LT, AROP, 0 },
{ "<=", LE, AROP, 0 },
{ "(", OPENB, OPENB, 0 },
{ ")", CLOSEB, CLOSEB, 0 },
{ "&&", AND, LOGOP, 0 },
{ "&", AND, LOGOP, 0 },
{ "||", OR, LOGOP, 0 },
{ "|", OR, LOGOP, 0 },
{ "Xor", XOR, LOGOP, 0 },
{ "!", NOT, NOT, 0 },
{ ",", COMMA, COMMA, 0 },
{ NULL, 0, 0, 0 }
};
s_lextable elements[] =
{
{ "TZ", TZ, TZ, 0 },
{ "Address", ADDRESS, ADDRESS, 0 },
{ "Time", TIME, TIME, 0 },
{ "Phone", PHONE, PHONE, 0 },
{ "Flag", FLAG, FLAG, 0 },
{ "Incoming", INCOMING, INCOMING, 0 },
{ "Outgoing", OUTGOING, OUTGOING, 0 },
{ "Listed", LISTED, LISTED, 0 },
{ "Protected", PROTECTED, PROTECTED, 0 },
{ "Connspeed", CONNSPEED, CONNSPEED, 0 },
{ "Exec", EXEC, EXEC, 0 },
{ "Exist", EXIST, EXIST, 0 },
{ "Port", PORT, PORT, 0 },
{ "Mailer", MAILER, MAILER, 0 },
{ NULL, 0, 0, 0 }
};
static void expr_inittables(void)
{
int i;
for( i = 0; operators[i].str; i++ )
operators[i].len = strlen(operators[i].str);
for( i = 0; elements[i].str; i++ )
elements[i].len = strlen(elements[i].str);
}
static int yylex(void)
{
int i, retc = 0;
s_lextable *entry = NULL;
ASSERT(expr_p_pos != NULL);
if( !initialised )
{ expr_inittables(); initialised = TRUE; }
if( next )
{
/*
* Found operator left from previous call to yylex()
*/
yylval = next->value;
DEB((D_EVENT, "yylex: got next \"%s\", yylval = %d, ret = %d",
next->str, next->value, next->retc));
retc = next->retc;
next = NULL;
return retc;
}
while( isspace(*expr_p_pos) ) expr_p_pos++;
if( *expr_p_pos == '\0' ) return 0;
for( i = 0; operators[i].str; i++ )
{
if( strncasecmp(expr_p_pos, operators[i].str, operators[i].len) == 0 )
{ entry = &operators[i]; break; }
}
if( entry == NULL )
{
for( i = 0; elements[i].str; i++ )
{
if( strncasecmp(expr_p_pos, elements[i].str, elements[i].len) == 0 )
{ entry = &elements[i]; break; }
}
}
if( entry )
{
expr_p_pos += entry->len;
yylval = entry->value;
DEB((D_EVENT, "yylex: got token \"%s\", yylval = %d, ret = %d",
entry->str, entry->value, entry->retc));
return entry->retc;
}
else
{
if( *expr_p_pos == '"' )
{
expr_p_text = ++expr_p_pos;
while( *expr_p_pos != '"' && *expr_p_pos )
++expr_p_pos;
}
else
{
expr_p_text = expr_p_pos++;
while( !isspace(*expr_p_pos) && *expr_p_pos )
{
for( i = 0; operators[i].str; i++ )
if( strncasecmp(expr_p_pos, operators[i].str, operators[i].len) == 0 )
{
next = &operators[i];
goto enough;
}
expr_p_pos++;
}
}
enough:
if( *expr_p_pos )
{
*expr_p_pos = '\0';
if( next && next->len > 1 )
expr_p_pos += next->len;
else
expr_p_pos += 1;
}
if( ISDEC(expr_p_text) )
{
/* It is decimal number */
yylval = atol(expr_p_text);
DEB((D_EVENT, "yylex: got NUMBER %d", yylval));
return NUMBER;
}
else
{
/* It is text */
DEB((D_EVENT, "yylex: got TEXT \"%s\"", expr_p_text));
return(yylval = TEXT);
}
}
}
+18
View File
@@ -0,0 +1,18 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "freq.h"
+406
View File
@@ -0,0 +1,406 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "outbound.h"
#include "freq.h"
static void deinit_reqlist(s_reqlist *dest);
static void deinit_frlist(s_frlist *dest);
/* ------------------------------------------------------------------------- */
/* Log requested files, passwords and other specified information */
/* ------------------------------------------------------------------------- */
static void req_logreqlist(s_reqlist *reqlist)
{
s_reqlist *rlist;
char *p = NULL;
char buf[100];
for( rlist = reqlist; rlist; rlist = rlist->next )
{
if( rlist->fmask == NULL ) continue;
p = xstrcpy("requested \"");
p = xstrcat(p, rlist->fmask);
p = xstrcat(p, "\"");
if( rlist->passwd )
{
p = xstrcat(p, ", password \"");
p = xstrcat(p, rlist->passwd);
p = xstrcat(p, "\"");
}
if( rlist->newer )
{
p = xstrcat(p, ", newer \"");
p = xstrcat(p, time_string_long(buf, sizeof(buf), rlist->newer));
p = xstrcat(p, "\"");
}
if( rlist->older )
{
p = xstrcat(p, ", older \"");
p = xstrcat(p, time_string_long(buf, sizeof(buf), rlist->older));
p = xstrcat(p, "\"");
}
log("FREQ: %s", string_printable(p));
if( p ) { free(p); p = NULL; }
}
}
/* ------------------------------------------------------------------------- */
/* Read files containing list of public dirs and file aliases */
/* ------------------------------------------------------------------------- */
static void req_readfrlist(char *fname, s_frlist **frlist, int magic)
{
FILE *fp;
s_frlist **ptrl;
char sbuf[BF_MAXREQLINE+1];
char *magc = NULL;
char *path = NULL;
char *pwd = NULL;
char *n = NULL;
DEB((D_FREQ, "req_readfrlist: reading \"%s\", magic = %d", fname, magic));
if( (fp = file_open(fname, "r")) == NULL )
{
logerr("FREQ: can't open dirlist \"%s\"", fname);
return;
}
for( ptrl = frlist; *ptrl; ptrl = &(*ptrl)->next )
{
/* EMPTY LOOP */
}
while( fgets(sbuf, sizeof(sbuf), fp) )
{
string_chomp(sbuf);
if( *sbuf == '#' ) continue;
if( magic )
{
magc = string_token(sbuf, &n, NULL, 1);
path = string_token(NULL, &n, NULL, 1);
}
else
{
path = string_token(sbuf, &n, NULL, 1);
}
pwd = string_token(NULL, &n, NULL, 1);
/* make sure it is password */
if( pwd && *pwd == '!' ) pwd++; else pwd = NULL;
if( path && *path && (!magic || (magc && *magc)) )
{
DEB((D_FREQ, "req_readfrlist: add path = \"%s\", magic = \"%s\", passwd = \"%s\"",
path, magc, pwd));
(*ptrl) = (s_frlist*)xmalloc(sizeof(s_frlist));
memset(*ptrl, '\0', sizeof(s_frlist));
if( path && *path ) (*ptrl)->path = xstrcpy(path);
if( !magic && *(path + strlen(path) - 1) != DIRSEPCHR )
{
/* add trailing DIRSEP ('/' or ..) to paths */
(*ptrl)->path = xstrcat((*ptrl)->path, DIRSEPSTR);
}
if( magc && *magc ) (*ptrl)->magic = xstrcpy(magc);
if( pwd && *pwd ) (*ptrl)->passwd = xstrcpy(pwd);
ptrl = &(*ptrl)->next;
}
}
file_close(fp);
}
/* ------------------------------------------------------------------------- */
/* Add files to send files list, check limits. Return non-zero value */
/* if can't send more files. */
/* ------------------------------------------------------------------------- */
static int req_addfile(char *fname, s_freq *freq)
{
struct stat st;
DEB((D_FREQ, "req_addfile: try to add \"%s\"", fname));
if( stat(fname, &st) )
{
logerr("FREQ: can't stat requested file \"%s\"", fname);
}
else
{
if( S_ISREG(st.st_mode) == 0 )
{
log("FREQ: requested file isn't regular \"%s\"", fname);
}
else if( (freq->sizelimit > 0)
&& ((freq->fsize + st.st_size) > freq->sizelimit) )
{
DEB((D_FREQ, "req_addfile:sending FREQ file \"%s\" exceed size limit", fname));
}
else
{
freq->fnumber += 1;
freq->fsize += st.st_size;
log("FREQ: send \"%s\", %d byte(s)", fname, st.st_size);
(*freq->flast) = (s_filelist*)xmalloc(sizeof(s_filelist));
memset(*freq->flast, '\0', sizeof(s_filelist));
(*freq->flast)->fname = fname ? xstrcpy(fname) : NULL;
(*freq->flast)->size = st.st_size;
(*freq->flast)->type = TYPE_REQANSW;
(*freq->flast)->status = STATUS_WILLSEND;
(*freq->flast)->action = ACTION_NOTHING;
freq->flast = &(*freq->flast)->next;
}
}
if( (freq->fileslimit > 0) && (freq->fnumber >= freq->fileslimit) )
{
log("FREQ: reached files number limit (%d file(s))", freq->fileslimit);
return(1);
}
return(0);
}
/* ------------------------------------------------------------------------- */
/* Return non-zero if got incorrect password for password protected file */
/* ------------------------------------------------------------------------- */
static int checkpasswd(char *ourpwd, char *gotpwd)
{
if( ourpwd == NULL || *ourpwd == '\0' ) return(0);
if( gotpwd && strcasecmp(ourpwd, gotpwd) == 0 ) return(0);
return(1);
}
/* ------------------------------------------------------------------------- */
/* Run external (SRIF compartible) FREQ processor */
/* ------------------------------------------------------------------------- */
static void req_proc_ext(s_freq *freq, char *reqname)
{
char srfname[L_tmpnam+5];
char rspname[L_tmpnam+5];
char *comline = NULL;
if( tmpnam(srfname) )
{
strncpy(rspname, srfname, L_tmpnam+4);
rspname[L_tmpnam+4] = '\0';
strcat(srfname, ".srf");
strcat(rspname, ".rsp");
if( req_createsrif(srfname, reqname, rspname) == 0 )
{
comline = xstrcpy(freq->srifproc);
comline = xstrcat(comline, " ");
comline = xstrcat(comline, srfname);
if( session_run_command(comline) == 0 )
{
req_addfilelist(rspname, freq);
}
unlink(srfname);
unlink(rspname);
if( comline ) { free(comline); }
}
}
else
{
logerr("FREQ: can't generate temp name for SRIF");
}
}
/* ------------------------------------------------------------------------- */
/* Run internal FREQ processor */
/* ------------------------------------------------------------------------- */
static void req_proc_int(s_freq *freq)
{
s_reqlist *rlist;
s_frlist *frl;
struct dirent *dirent;
DIR *dirp;
char *fname = NULL;
int stop = 0; /* Stop processing FREQs */
int msg = 0; /* Show "incorrect password" message only once */
for( frl = freq->frlist; !stop && frl; frl = frl->next )
{
if( frl->magic && *frl->magic )
{
/* MAGIC */
DEB((D_FREQ, "req_proc_int: checking our magic \"%s\"", frl->magic));
for( rlist = freq->reqlist; rlist; rlist = rlist->next )
{
if( !strcasecmp(frl->magic, rlist->fmask) )
{
if( 0 == checkpasswd(frl->passwd, rlist->passwd) )
{
rlist->skip = 1;
stop = req_addfile(frl->path, freq);
}
else
{
log("FREQ: incorrect password for magic \"%s\"", frl->magic);
}
break;
}
}
if( stop == 0 )
{
/* Check - may be there is no more */
/* requests - so break it out */
for( rlist = freq->reqlist; rlist; rlist = rlist->next )
{
if( rlist->skip == 0 ) break;
}
stop = (rlist == NULL);
}
}
else if( frl->path && *frl->path )
{
/* FREQ DIR */
if( (dirp = opendir(frl->path)) == NULL )
{
logerr("FREQ: can't open freq dir \"%s\"", frl->path);
}
else
{
/* REGULAR DIR */
DEB((D_FREQ, "req_proc_int: checking dir \"%s\"", frl->path));
while( !stop && (dirent = readdir(dirp)) )
{
if( *dirent->d_name == '.' ) continue;
for( rlist = freq->reqlist; rlist; rlist = rlist->next )
{
if( rlist->skip == 0
&& 0 == strcasemask(dirent->d_name, rlist->fmask) )
{
if( 0 == checkpasswd(frl->passwd, rlist->passwd) )
{
fname = xstrcpy(frl->path);
fname = xstrcat(fname, dirent->d_name);
stop = req_addfile(fname, freq);
free(fname);
}
else if( msg == 0 )
{
log("FREQ: incorrect password");
++msg;
}
break;
}
}
}
closedir(dirp);
}
}
}
}
/* ------------------------------------------------------------------------- */
/* Start FREQs processing, run int. or ext. processor */
/* ------------------------------------------------------------------------- */
void req_proc(char *reqname, s_filelist **filelist)
{
char *p = NULL;
time_t timer = time(NULL);
s_freq freq;
/* Init FREQ information structure */
memset(&freq, '\0', sizeof(s_freq));
freq.fileslimit = conf_number(cf_freq_limit_number);
freq.sizelimit = conf_number(cf_freq_limit_size);
freq.filelist = filelist;
freq.flast = filelist;
if( (p = conf_string(cf_freq_srif_command)) && *p )
{
/* Try external (SRIF) FREQ processor */
log("FREQ: starting external processor");
freq.srifproc = xstrcpy(p);
req_proc_ext(&freq, reqname);
if( freq.srifproc )
free(freq.srifproc);
}
else
{
/* Run internal FREQ processor */
log("FREQ: starting internal processor");
if( req_readwazooreq(reqname, &freq.reqlist) == 0 )
{
req_logreqlist(freq.reqlist);
if( (p = conf_string(cf_freq_alias_list)) && *p )
req_readfrlist(p, &freq.frlist, 1);
if( (p = conf_string(cf_freq_dir_list)) && *p )
req_readfrlist(p, &freq.frlist, 0);
if( freq.frlist )
{
req_proc_int(&freq);
deinit_frlist(freq.frlist);
}
deinit_reqlist(freq.reqlist);
}
}
log("FREQ: stat %d file(s), %d byte(s), %d second(s)",
freq.fnumber, freq.fsize, time(NULL)-timer);
#ifdef DEBUG
if( freq.filelist )
log_filelist(*freq.filelist);
#endif
}
static void deinit_reqlist(s_reqlist *dest)
{
s_reqlist *ptrl, *next;
for( ptrl = dest; ptrl; ptrl = next )
{
next = ptrl->next;
if( ptrl->fmask ) free(ptrl->fmask);
if( ptrl->passwd ) free(ptrl->passwd);
free(ptrl);
}
}
static void deinit_frlist(s_frlist *dest)
{
s_frlist *ptrl, *next;
for( ptrl = dest; ptrl; ptrl = next )
{
next = ptrl->next;
if( ptrl->magic ) free(ptrl->magic);
if( ptrl->path ) free(ptrl->path);
if( ptrl->passwd ) free(ptrl->passwd);
if( ptrl->expr ) free(ptrl->expr);
free(ptrl);
}
}
+153
View File
@@ -0,0 +1,153 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "freq.h"
#include "session.h"
int req_createsrif(char *sname, char *req, char *rsp)
{
FILE *fp;
char *cptr;
s_faddr *aptr;
char abuf[BF_MAXADDRSTR+1];
if( (fp = file_open(sname, "w")) == NULL )
{
logerr("can't create srif file \"%s\"", sname);
return -1;
}
switch(state.session) {
case SESSION_EMSI:
fprintf(fp, "SessionType EMSI\n");
break;
case SESSION_BINKP:
fprintf(fp, "SessionType OTHER\n");
break;
case SESSION_YOOHOO:
fprintf(fp, "SessionType WAZOO\n");
break;
case SESSION_FTSC:
fprintf(fp, "SessionType FTSC0001\n");
break;
case SESSION_UNKNOWN:
ASSERT_MSG();
break;
}
fprintf(fp, "Baud %ld\n",
state.connspeed ? state.connspeed : 115200);
fprintf(fp, "Time -1\n");
fprintf(fp, "RequestList %s\n", req);
fprintf(fp, "ResponseList %s\n", rsp);
fprintf(fp, "RemoteStatus %s\n",
state.protected ? "PROTECTED" : "UNPROTECTED");
fprintf(fp, "SystemStatus %s\n",
state.listed ? "LISTED" : "UNLISTED");
if( state.handshake && state.handshake->remote_sysop_name
&& (cptr = state.handshake->remote_sysop_name(state.handshake)) )
fprintf(fp, "Sysop %s\n", cptr);
else
fprintf(fp, "Sysop SysOp\n");
if( state.handshake && state.handshake->remote_address
&& (aptr = state.handshake->remote_address(state.handshake)) )
fprintf(fp, "AKA %s\n", ftn_addrstr(abuf, *aptr));
else
return -1;
if( state.handshake && state.handshake->remote_system_name
&& (cptr = state.handshake->remote_system_name(state.handshake)) )
fprintf(fp, "Site %s\n", cptr);
if( state.handshake && state.handshake->remote_location
&& (cptr = state.handshake->remote_location(state.handshake)) )
fprintf(fp, "Location %s\n", cptr);
if( state.handshake && state.handshake->remote_phone
&& (cptr = state.handshake->remote_phone(state.handshake)) )
fprintf(fp, "Phone %s\n", cptr);
if( state.handshake && state.handshake->remote_mailer
&& (cptr = state.handshake->remote_mailer(state.handshake)) )
fprintf(fp, "Mailer %s\n", cptr);
file_close(fp);
return(0);
}
void req_addfilelist(char *listname, s_freq *freq)
{
FILE *fp;
char fnbuf[BF_MAXPATH+1], *p;
int action = ACTION_NOTHING;
struct stat st;
if( (fp = file_open(listname, "r")) == NULL )
{
logerr("can't open freq answer list \"%s\" (%d)", listname, strlen(listname));
return;
}
while( fgets(fnbuf, sizeof(fnbuf), fp) )
{
p = fnbuf;
action = ACTION_NOTHING;
string_chomp(fnbuf);
/*
* We won't remove leading and trailing spaces
*/
if( *p == '\0' )
continue; /* Empty line! */
switch(*p) {
case '=': ++p; action = ACTION_UNLINK; break;
case '+': ++p; action = ACTION_NOTHING; break;
case '-': ++p; action = ACTION_FORCEUNLINK; break;
}
if( stat(p, &st) == 0 )
{
DEB((D_FREQ, "adding file \"%s\", %d", p, st.st_size));
(*freq->flast) = (s_filelist*)xmalloc(sizeof(s_filelist));
memset(*freq->flast, '\0', sizeof(s_filelist));
(*freq->flast)->fname = xstrcpy(p);
(*freq->flast)->size = st.st_size;
(*freq->flast)->action = action;
(*freq->flast)->status = STATUS_WILLSEND;
freq->flast = &(*freq->flast)->next;
freq->fnumber += 1;
freq->fsize += st.st_size;
}
else
logerr("can't stat file from answer list \"%s\"", p);
}
file_close(fp);
}
+113
View File
@@ -0,0 +1,113 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "freq.h"
int req_readwazooreq(char *reqname, s_reqlist **reqlist)
{
s_reqlist **tmpl;
char s[BF_MAXPATH+1];
char *p, *fname, *pwd = NULL, *older = NULL, *newer = NULL;
char *p_ignorelist = NULL;
FILE *fp;
DEB((D_FREQ, "req_readreq: open '.req' file = \"%s\"", reqname));
if( (fp = file_open(reqname, "r")) == NULL )
{
logerr("can't open req file \"%s\"", reqname);
return(1);
}
/* $tmpl must point to last entry's next field */
for( tmpl = reqlist; *tmpl; tmpl = &(*tmpl)->next )
{
/* EMPTY LOOP */
}
/* Get file masks that we should ignore */
p_ignorelist = conf_string(cf_freq_ignore_masks);
while( fgets(s, sizeof(s), fp) )
{
p = s;
fname = NULL;
pwd = NULL;
older = NULL;
newer = NULL;
string_chomp(s);
/* Remove leading spaces */
while( isspace(*p) ) ++p;
if( *p == '\0' ) continue; /* Empty line :( */
/* Get file name */
fname = p;
while( *p && !isspace(*p) ) ++p;
if( *p ) *p++ = '\0';
/* Check our ignore list */
if( p_ignorelist && *p_ignorelist && fname && *fname )
{
if( !checkmasks(p_ignorelist, fname) )
{
log("FREQ: ignore request \"%s\"", fname);
continue;
}
}
/* Is there possible password or update time? */
while( *p )
{
/* Remove spaces between fields */
while( isspace(*p) ) ++p;
switch( *p ) {
case '!' : pwd = ++p; break;
case '+' : older = ++p; break;
case '-' : newer = ++p; break;
}
/* Get field */
while( *p && !isspace(*p) ) ++p;
if( *p ) *p++ = '\0';
}
if( fname && *fname )
{
DEB((D_FREQ, "req_readreq: file=\"%s\", pwd=\"%s\", newer=\"%s\", older=\"%s\"", fname, pwd, newer, older));
*(tmpl) = (s_reqlist*)xmalloc(sizeof(s_reqlist));
memset(*tmpl, '\0', sizeof(s_reqlist));
(*tmpl)->fmask = (char*)xstrcpy(fname);
if( pwd && *pwd ) (*tmpl)->passwd = (char*)xstrcpy(pwd);
if( newer && *newer ) (*tmpl)->newer = atol(newer);
if( older && *older ) (*tmpl)->older = atol(older);
/* prepare $tmpl for next entry */
tmpl = &(*tmpl)->next;
}
}
DEB((D_FREQ, "req_readreq: close '.req' file"));
file_close(fp);
return(0);
}
+465
View File
@@ -0,0 +1,465 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "io.h"
const char *modem_errlist[] =
{
"No error",
"Modem return ERROR",
"Can't send string to modem",
"Modem not response",
NULL
};
/* ------------------------------------------------------------------------- */
/* Get connect speed from connect string returned by modem */
/* ------------------------------------------------------------------------- */
long modem_getconnspeed(const char *connstr)
{
const char *p;
for( p = connstr; *p; p++ )
{
if( isdigit(*p) )
return atol(p);
}
return 0L;
}
bool modem_isgood_phone(const char *str)
{
if( !str || !str[0] )
return FALSE;
if( str[0] == '-' && str[1] == '\0' )
return FALSE;
if( string_casestr(str, "unpublished") )
return FALSE;
if( string_casestr(str, "unknown") )
return FALSE;
if( string_casestr(str, "none") )
return FALSE;
return TRUE;
}
/* ------------------------------------------------------------------------- */
/* Translate phone number using given rules, returned value must be free'ed! */
/* ------------------------------------------------------------------------- */
char *modem_transphone(char *buffer, const char *phone, size_t buflen)
{
const char *p;
s_cval_entry *ptrl;
ASSERT(phone != NULL);
DEB((D_MODEM, "translate_phone: want translate \"%s\"", phone));
for( ptrl = conf_first(cf_phone_translate); ptrl;
ptrl = conf_next(ptrl) )
{
if( !ptrl->d.translate.find )
continue;
if( (p = strstr(phone, ptrl->d.translate.find)) )
{
DEB((D_MODEM, "translate_phone: replace \"%s\" with \"%s\"",
ptrl->d.translate.find, ptrl->d.translate.repl));
strnxcpy(buffer, phone, buflen);
if( p - phone < buflen - 1 )
{
buffer[p - phone] = '\0';
if( ptrl->d.translate.repl )
strnxcat(buffer, ptrl->d.translate.repl, buflen);
strnxcat(buffer, p + strlen(ptrl->d.translate.find), buflen);
}
DEB((D_MODEM, "translate_phone: result is \"%s\"", buffer));
return buffer;
}
}
return strnxcpy(buffer, phone, buflen);
}
/* ------------------------------------------------------------------------- */
/* Send string to modem, using some control character sequences, like */
/* '\r' - CR, '\P' - phone number, etc.. */
/* ------------------------------------------------------------------------- */
int modem_putstr(const char *str)
{
const char *ptr;
int rc;
bool flushed = FALSE;
DEB((D_MODEM, "modem_putstr: want to send \"%s\"", str));
rc = TTY_SUCCESS;
ptr = str;
while( *ptr )
{
/* Flush buffer before "special" operations */
if( !flushed && strchr("~`^v", *ptr) )
{
flushed = TRUE;
if( (rc = tty_flushout()) < 0 )
return rc;
}
switch( *ptr ) {
case '~':
sleep(1);
break;
case '`':
usleep(250000L);
break;
case '^':
rc = tio_set_dtr(0, 1);
break;
case 'v':
rc = tio_set_dtr(0, 0);
break;
case '|':
case '\r':
rc = tty_putc('\r', 2);
if( !rc && !(rc = tty_flushout()) )
{
/*
* Make sure that we will never send
* anything to the modem immediately
* after CR
*/
/* i changed value for my modem
* (from 250000 */
usleep(500000);
flushed = TRUE;
}
break;
case '\\':
++ptr;
switch(*ptr) {
case '\0':
rc = tty_putc('\\', 2);
break;
case 'r':
rc = tty_putc('\r', 2);
break;
case 'n':
rc = tty_putc('\n', 2);
break;
default:
rc = tty_putc(*ptr, 2);
}
flushed = FALSE;
break;
default:
rc = tty_putc(*ptr, 2);
flushed = FALSE;
}
if( rc < 0 )
return rc;
++ptr;
}
if( !flushed && (rc = tty_flushout()) < 0 )
return rc;
return 0;
}
void modem_clearin(int timeout)
{
time_t timer;
timer_set(&timer, timeout);
while( CHARWAIT(1) )
{
CLEARIN();
if( timer_expired(timer) )
return;
usleep(100000); /* 0.1 seconds delay */
}
}
/* ------------------------------------------------------------------------- */
/* Reads in at most one less than $bufsize characters from modem and */
/* stores them into the buffer pointed to by $buf, check for timeout. */
/* $timer must be set with tty_settimer() call! */
/* ------------------------------------------------------------------------- */
int modem_getline(char *buf, int bufsize, time_t timer)
{
int rc = 0, pos = 0;
ASSERT(buf != NULL || bufsize == 0);
while(1)
{
if( timer_expired(timer) )
return TTY_TIMEOUT;
if( (rc = tty_getc(1)) < 0 && rc != TTY_TIMEOUT )
return rc;
else if( rc == '\r' || rc == '\n' )
return pos;
else if( rc > 0 )
{
if( pos < bufsize-1 )
{
buf[pos++] = rc;
buf[pos ] = '\0';
} else
return pos;
}
}
}
/* ------------------------------------------------------------------------- */
/* Dial using phone number $phone, if connection will be established - */
/* put connect string to *connstr (must be freed) */
/* ------------------------------------------------------------------------- */
int modem_dial(const char *dialstr, int timeout, char **connstr)
{
s_cval_entry *ptrl;
char buf[MODEM_MAX_RESP+1];
time_t timer;
int len = 0;
ASSERT(dialstr != NULL && connstr != NULL);
*connstr = NULL;
if( modem_putstr(dialstr) != TTY_SUCCESS )
{
log("error sending dial string \"%s\"", dialstr);
return -1;
}
timer_set(&timer, timeout);
while(1)
{
if( timer_expired(timer) )
{
log("dialing timed out");
return -1;
}
if( (len = modem_getline(buf, sizeof(buf), timer)) < 0 )
{
if( len == TTY_TIMEOUT )
log("dialing timed out");
return -1;
}
else if( len > 0 )
{
DEB((D_MODEM, "modem_dial: got \"%s\"", buf));
for( ptrl = conf_first(cf_modem_dial_response); ptrl;
ptrl = conf_next(ptrl) )
{
if( ptrl->d.dialresp.mstr && strstr(buf, ptrl->d.dialresp.mstr) )
{
if( ptrl->d.dialresp.retv == RESPTYPE_CONNECT )
{
*connstr = xstrcpy(buf);
return 0;
}
return ptrl->d.dialresp.retv;
}
}
if( *buf )
log("modem: \"%s\"", string_printable(buf));
}
}
}
int modem_command(const char *command, int timeout, bool logit)
{
time_t timer;
size_t count = 0;
int len = 0;
char buffer[MODEM_MAX_RESP+1];
char cmdstr[MODEM_MAX_COMMAND+1];
char *n;
char *p;
ASSERT(command != NULL);
strnxcpy(cmdstr, command, sizeof(cmdstr));
DEB((D_MODEM, "modem_command: command string \"%s\"", cmdstr));
CLEARIN();
for( p = string_token(cmdstr, &n, NULL, 1); p;
p = string_token(NULL, &n, NULL, 1) )
{
DEB((D_MODEM, "modem_command: send \"%s\"",
string_printable(p)));
if( modem_putstr(p) < 0 )
return MODEM_CANTSEND;
count = 0;
timer_set(&timer, timeout);
while(1)
{
if( timer_expired(timer) )
return MODEM_NORESP;
if( (len = modem_getline(buffer, sizeof(buffer), timer)) < 0 )
{
return MODEM_NORESP;
}
else if( len > 0 )
{
count += len;
if( count > MODEM_MAX_RESP_SIZE )
{
log("modem response exceeds limit %ld bytes",
(long)count);
return MODEM_NORESP;
}
DEB((D_MODEM, "modem_command: got \"%s\"",
string_printable(buffer)));
if( !strcmp(buffer, "ERROR") )
return MODEM_ERROR;
else if( !strcmp(buffer, "OK") )
break;
else if( logit )
log("modem: \"%s\"", string_printable(buffer));
}
}
}
return MODEM_OK;
}
int modem_hangup(const char *command, int timeout)
{
#ifdef MODEM_HANGUP_WATCH_CARRIER
time_t timer;
ASSERT(command != NULL);
if( tio_get_dcd(0) == 1 )
{
DEB((D_MODEM, "modem_hangup: send \"%s\"", command));
if( modem_putstr(command) < 0 )
return MODEM_CANTSEND;
timer_set(&timer, timeout);
while( tio_get_dcd(0) == 1 )
{
if( timer_expired(timer) )
return MODEM_NORESP;
sleep(1);
}
}
sleep(2); CLEARIN(); CLEAROUT();
return MODEM_OK;
#else /* MODEM_HANGUP_WATCH_CARRIER */
return modem_command(command, timeout, FALSE);
#endif
}
bool modem_candialout(const char *modemdev)
{
char tmp[BF_MAXPATH+1];
const char *p_nodial = conf_string(cf_nodial_flag);
char *p = NULL;
if( p_nodial && *p_nodial )
{
if( access(p_nodial, F_OK) == 0 )
return FALSE;
strnxcpy(tmp, p_nodial, sizeof(tmp));
strnxcat(tmp, ".", sizeof(tmp));
strnxcat(tmp, (p = port_get_name(modemdev)), sizeof(tmp));
if( p )
free(p);
if( access(tmp, F_OK) == 0 )
return FALSE;
}
return TRUE;
}
/* ------------------------------------------------------------------------- */
/* Return pointer to the first not locked now tty */
/* ------------------------------------------------------------------------- */
s_modemport *modem_getfree_port(const char *lockdir)
{
s_cval_entry *ptrl;
/* Find first not locked modem device */
for( ptrl = conf_first(cf_modem_port); ptrl; ptrl = conf_next(ptrl) )
{
if( port_checklock(lockdir, &ptrl->d.modemport) == LOCKCHECK_NOLOCK
&& modem_candialout(ptrl->d.modemport.name) == TRUE )
return &ptrl->d.modemport;
}
return NULL;
}
/* ------------------------------------------------------------------------- */
/* Return pointer to the first tty whose name contain substring `ttyname' */
/* ------------------------------------------------------------------------- */
s_modemport *modem_getmatch_port(const char *substr)
{
s_cval_entry *ptrl;
/* Find first matching modem device */
for( ptrl = conf_first(cf_modem_port); ptrl; ptrl = conf_next(ptrl) )
{
if( strstr(ptrl->d.modemport.name, substr) )
return &ptrl->d.modemport;
}
return NULL;
}
+250
View File
@@ -0,0 +1,250 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "io.h"
#define DEFAULT_PORT 60179 /* Birthday .. mother fucker :) */
static RETSIGTYPE tcpip_interrupt(int sig)
{
tty_abort = TRUE;
log("terminating on signal %d", sig);
}
static RETSIGTYPE tcpip_brokenpipe(int sig)
{
tty_abort = TRUE;
if( tty_online )
log("connection closed");
else
log("terminating on signal %d", sig);
}
static int tcpip_connect2(struct sockaddr_in server)
{
int fd;
DEB((D_INFO, "tcpip_connect2: trying \"%s\" at port %d",
inet_ntoa(server.sin_addr), (int)ntohs(server.sin_port)));
if( (fd = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
{
logerr("can't create socket");
return(1);
}
/* make new fd == stdin if it isn't already */
if( fd > 0 )
{
(void)close(0);
if( dup(fd) != 0 )
{
logerr("cannot dup socket to stdin");
return(1);
}
}
/* make stdout and stderr, too */
(void)close(1);
(void)close(2);
if( dup(0) != 1 )
{
logerr("cannot dup stdin to stdout");
return(1);
}
if( dup(0) != 2 )
{
logerr("cannot dup stdin to stderr");
return(1);
}
if( fd > 2 ) (void)close(fd);
/* switch off stdio buffering */
setbuf(stdin, (char *)NULL);
setbuf(stdout, (char *)NULL);
setbuf(stderr, (char *)NULL);
clearerr(stdin);
clearerr(stdout);
clearerr(stderr);
if( connect(0, (struct sockaddr*)&server, sizeof(server)) == -1 )
{
logerr("can't connect to %s", inet_ntoa(server.sin_addr));
close(0);
close(1);
close(2);
return 1;
}
if( tcpip_init() )
{
tcpip_shutdown();
return 1;
}
log("TCP/IP connect to %s on port %d",
inet_ntoa(server.sin_addr), (int)ntohs(server.sin_port));
return(0);
}
int tcpip_connect(const char *hostname, e_tcpmode tcpmode)
{
int rc = 0;
struct hostent *he = NULL;
struct servent *se = NULL;
struct sockaddr_in server;
char *host = xstrcpy(hostname);
char *p = strrchr(host, ':');
const char *port = NULL;
server.sin_family = AF_INET;
if( p )
{ *p++ = '\0'; port = p; }
else if( tcpmode == TCPMODE_BINKP )
port = "binkp";
else if( tcpmode == TCPMODE_TELNET )
port = "telnet";
else /* Default service name is "fido" */
port = "fido";
if( ISDEC(port) )
server.sin_port = htons(atoi(port));
else if( (se = getservbyname(port, "tcp")) )
server.sin_port = se->s_port;
else
{ log("invalid port or service name \"%s\"", port); rc = 1; }
if( rc == 0 )
{
if( (he = gethostbyname(host)) )
{
memcpy(&server.sin_addr, he->h_addr, he->h_length);
}
else
{
rc = 1;
switch(h_errno) {
case HOST_NOT_FOUND:
log("host \"%s\" not found", host);
break;
case NO_ADDRESS:
log("no IP address found for host \"%s\"", host);
break;
case NO_RECOVERY:
log("non-recoverable name server error occured");
break;
case TRY_AGAIN:
log("temporary error occured on name server");
break;
default:
log("unknown error while resolving host \"%s\"", host);
break;
}
}
}
if( host ) { free(host); host = NULL; }
return rc ? rc : tcpip_connect2(server);
}
int tcpip_init(void)
{
int nbio_arg = 1;
int alive_arg = 1;
struct linger lingeropt;
tty_online = TRUE;
tty_abort = FALSE;
tty_hangup = FALSE;
tty_modem = FALSE;
/*
* Set sockets I/O to the non-blocking mode
*/
if( ioctl(0, FIONBIO, (char *)&nbio_arg, sizeof(nbio_arg)) == -1 )
{
logerr("failed to set non-blocking mode for stdin");
return 1;
}
if( ioctl(1, FIONBIO, (char *)&nbio_arg, sizeof(nbio_arg)) == -1 )
{
logerr("failed to set non-blocking mode for stdout");
return 1;
}
/*
* Set SO_LONGER socket option, so then we will close
* socket the system will block our close() call and
* try to deliver queued data.
*/
memset(&lingeropt, '\0', sizeof(struct linger));
lingeropt.l_onoff = 1;
lingeropt.l_linger = 5*100; /* 5 seconds */
if( setsockopt(1, SOL_SOCKET, SO_LINGER, (char*)&lingeropt, sizeof(struct linger)) == -1 )
{
logerr("failed to set SO_LINGER socket option for the stdout");
return 1;
}
/*
* Set SO_KEEPALIVE socket option. The connection will be
* considered broken if remote side fail to respond on
* periodicaly transmitted message. We should not hang
* even without such features.
*/
if( setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, (char*)&alive_arg, sizeof(alive_arg)) == -1 )
{
logerr("failed to set SO_KEEPALIVE socket option");
return 1;
}
signal(SIGHUP, tcpip_interrupt);
signal(SIGINT, tcpip_interrupt);
signal(SIGTERM, tcpip_interrupt);
signal(SIGPIPE, tcpip_brokenpipe);
return(0);
}
int tcpip_shutdown(void)
{
close(0);
close(1);
close(2);
return 0;
}
bool tcpip_isgood_host(const char *str)
{
if( !str || !str[0] )
return FALSE;
if( str[0] == '-' && str[1] == '\0' )
return FALSE;
return TRUE;
}
+379
View File
@@ -0,0 +1,379 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "io.h"
/*
* Set lock files type: Ascii, binary or SVR4? (not implemented yet)
*/
#if (BFORCE_LOCK_TYPE == 1)
# define LOCK_ASCII
#elif (BFORCE_LOCK_TYPE == 2)
# define LOCK_BIN
#else
# error "Not implemented lock files type (BFORCE_LOCK_TYPE)"
#endif
/*
* Set lock files directory
*/
#ifndef BFORCE_LOCK_DIR
# error "Not defined lock files directory (BFORCE_LOCK_DIR)"
#endif
/*
* Set prefix for lock file names
*/
#ifndef BFORCE_LOCK_PREFIX
# define BFORCE_LOCK_PREFIX "LCK.."
#endif
/*
* How much times we will try to lock (if device
* is allready locked by another process)
*/
#ifndef BFORCE_LOCK_TRIES
# define BFORCE_LOCK_TRIES 2
#endif
/*
* Delay in seconds between tries
*/
#ifndef BFORCE_LOCK_DELAY
# define BFORCE_LOCK_DELAY 1
#endif
/* ========================================================================= */
/* "Low level" interface for tty lock files access (private) */
/* */
/* char *lock_getname(const char *lockdir, const s_modemport *modemport) */
/* pid_t lock_read_pid(const char *lckname) */
/* int lock_check(const char *lckname) */
/* int lock_create(const char *lckname, const char *tmpname) */
/* */
/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/* Get lock file name with full path (this value must be free'ed) */
/* ------------------------------------------------------------------------- */
static char *lock_getname(const char *lockdir, const s_modemport *modemport)
{
char *lckname;
char *p = NULL;
ASSERT(modemport != NULL);
if( lockdir && *lockdir )
lckname = (char *)xstrcpy(lockdir);
else
lckname = (char *)xstrcpy(BFORCE_LOCK_DIR);
lckname = (char *)xstrcat(lckname, BFORCE_LOCK_PREFIX);
lckname = (char *)xstrcat(lckname, (p = port_get_name(modemport->name)));
if( p )
free(p);
return lckname;
}
/* ------------------------------------------------------------------------- */
/* Get lock file's PID. Return zero on error and leave errno with last error */
/* ------------------------------------------------------------------------- */
static pid_t lock_read_pid(const char *lckname)
{
int len, fd;
pid_t pid;
char buf[32];
ASSERT(lckname != NULL);
if( (fd = open(lckname, O_RDONLY)) < 0 )
return 0;
if( (len = read(fd, buf, sizeof(buf)-1)) < 0 )
{
close(fd);
return 0;
}
buf[len] = '\0';
if( len == sizeof(pid) || sscanf(buf, "%d", &pid) != 1 || pid == 0 )
{
/* We found binary lock file? */
pid = *((int *)buf);
#ifndef LOCK_BINARY
log("warning: found binary lock file %s", lckname);
#endif
}
#ifdef LOCK_BINARY
else
{
/* Found ASCII lock file */
log("warning: found ascii lock file %s", lckname);
}
#endif
close(fd);
return pid;
}
/* ------------------------------------------------------------------------- */
/* Validate lock file, check it's process still lives. */
/* Return: */
/* CHECKLOCK_NOLOCK - no lock file found */
/* CHECKLOCK_LOCKED - valid lock file */
/* CHECKLOCK_ERROR - invalid lock file name, access error, etc. */
/* CHECKLOCK_OURLOCK - if it is our lock file (with our PID) */
/* ------------------------------------------------------------------------- */
static int lock_check(const char *lckname)
{
pid_t pid = 0;
struct stat st;
ASSERT(lckname != NULL);
if( stat(lckname, &st) && errno == ENOENT )
return LOCKCHECK_NOLOCK;
if( (pid = lock_read_pid(lckname)) == 0 )
{
if( errno == ENOENT )
return LOCKCHECK_NOLOCK;
return LOCKCHECK_LOCKED;
}
DEB((D_MODEM, "lock_check: lock PID = %d", pid));
if( pid == getpid() )
{ return LOCKCHECK_OURLOCK; }
if( kill(pid, 0) == -1 )
{
if( errno == ESRCH )
{
/*
* That process no longer exists, remove lock file
*/
log("found stale lock file with PID %d", pid);
if( unlink(lckname) == -1 )
{
logerr("cannot remove lockfile \"%s\", lckname");
return LOCKCHECK_ERROR;
} else
return LOCKCHECK_NOLOCK;
}
else
{
return LOCKCHECK_ERROR;
}
}
/* locking process still lives */
return LOCKCHECK_LOCKED;
}
/* ------------------------------------------------------------------------- */
/* Create lock file using link(tmpname, lckname). Return zero on success. */
/* ------------------------------------------------------------------------- */
static int lock_create(const char *lckname, const char *tmpname)
{
int rc, fd;
int tries;
#ifdef LOCK_BINARY
pid_t pid;
#else
char buf[32];
#endif
ASSERT(lckname != NULL && tmpname != NULL);
if( (fd = open(tmpname, O_CREAT | O_RDWR, 0644)) < 0 )
{
logerr("can't open temp file \"%s\"", tmpname);
return 1;
}
chmod(tmpname, 0644);
#ifdef LOCK_BINARY
pid = getpid();
rc = ( write(fd, (char *)&pid, sizeof(pid)) != sizeof(pid) );
#else
sprintf(buf, "%10d\n", (int)getpid());
rc = ( write(fd, (char *)buf, strlen(buf)) != strlen(buf) );
#endif
close(fd);
if( rc )
{
logerr("can't write PID to temp. lock file \"%s\"", tmpname);
unlink(tmpname);
return 1;
}
for( tries = 0; tries < BFORCE_LOCK_TRIES; tries++ )
{
if( link(tmpname, lckname) == -1 )
{
if( errno == EEXIST )
{
rc = lock_check(lckname);
if( rc == LOCKCHECK_ERROR )
{
break;
}
else if( rc == LOCKCHECK_OURLOCK )
{
/* There is our lock! :) */
unlink(tmpname);
return 0;
}
else if( rc == LOCKCHECK_LOCKED )
{
/* sleep some time */
sleep(BFORCE_LOCK_DELAY);
}
}
else
{
log("can't create link to temp. lock file \"%s\"", lckname);
break;
}
}
else
{
/* Successful lock */
unlink(tmpname);
return 0;
}
}
/* Can't create lock file */
unlink(tmpname);
return 1;
}
/* ========================================================================= */
/* PUBLIC functions for tty lock files access */
/* */
/* int port_checklock(const char *lockdir, const char *dev) */
/* int port_lock(char *lockdir, char *dev) */
/* int port_unlock(const char *lockdir, const char *dev) */
/* */
/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/* Check, is tty locked? Return one of return values of lock_check() */
/* ------------------------------------------------------------------------- */
int port_checklock(const char *lockdir, const s_modemport *modemport)
{
int rc;
char *lckname;
if( (lckname = lock_getname(lockdir, modemport)) == NULL )
{
log("can't get lock file name");
return LOCKCHECK_ERROR;
}
DEB((D_MODEM, "checkttylock: lock device = \"%s\", lockfile = \"%s\"",
modemport->name, lckname));
rc = lock_check(lckname);
if( lckname )
free(lckname);
return rc;
}
/* ------------------------------------------------------------------------- */
/* Lock serial port. On success return zero value */
/* ------------------------------------------------------------------------- */
int port_lock(const char *lockdir, const s_modemport *modemport)
{
int rc;
char *lckname;
char *tmpname, *p_tmpname;
if( lockdir && *lockdir )
tmpname = xstrcpy(lockdir);
else
tmpname = xstrcpy(BFORCE_LOCK_DIR);
tmpname = xstrcat(tmpname, "bfXXXXXX");
if( (p_tmpname = mktemp(tmpname)) == NULL )
{
logerr("can't generate unique file name from \"%s\"", tmpname);
free(tmpname); return 1;
}
if( (lckname = lock_getname(lockdir, modemport)) == NULL )
{
log("can't get lock file name");
return(1);
}
DEB((D_MODEM, "locktty: lock device = \"%s\", tmpfile = \"%s\", lockfile = \"%s\"",
modemport->name, p_tmpname, lckname));
rc = lock_create(lckname, p_tmpname);
if( tmpname )
free(tmpname);
if( lckname )
free(lckname);
return rc;
}
/* ------------------------------------------------------------------------- */
/* Unlock serial port. Return zero on success. */
/* ------------------------------------------------------------------------- */
int port_unlock(const char *lockdir, const s_modemport *modemport)
{
pid_t pid = 0;
char *lckname;
if( (lckname = lock_getname(lockdir, modemport)) == NULL )
return 1;
DEB((D_MODEM, "unlocktty: unlock device = \"%s\", lockfile = \"%s\"",
modemport->name, lckname));
if( (pid = lock_read_pid(lckname)) == 0 )
{
free(lckname);
return 1;
}
if( pid == getpid() && unlink(lckname) == -1 )
{
free(lckname);
return 1;
}
free(lckname);
return 0;
}
+242
View File
@@ -0,0 +1,242 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "io.h"
/*
* Get verbal device name, remove "/dev/" part and replace all '/'
* characters by the '-' character. Returned value must be freed.
*/
char *port_get_name(const char *devname)
{
char *yield = NULL;
if( !devname )
yield = xstrcpy("unknown");
else if( !strncmp(devname, "/dev/", 5) )
yield = xstrcpy(devname + 5);
else
yield = xstrcpy(devname);
string_replchar(yield, '/', '-');
return yield;
}
#ifndef MODEM_WATCH_CARRIER
static RETSIGTYPE linedrop(int sig)
{
if( tty_online )
{
log("carrier lost");
tty_hangup = TRUE;
}
else
{
log("terminating on signal %d", sig);
tty_abort = TRUE;
}
}
#endif
static RETSIGTYPE interrupt(int sig)
{
tty_abort = TRUE;
log("terminating on signal %d", sig);
}
/*
* Open modem device $port, save old termios to $oldtio
*/
int port_open(const s_modemport *port, int detach, TIO *oldtio)
{
int fd;
ASSERT(port != NULL);
DEB((D_MODEM, "openport: open device \"%s\" locked at %ld",
port->name, (long)port->speed));
if( (fd = open(port->name, O_RDWR | O_NONBLOCK)) < 0 )
{ logerr("cannot open device \"%s\"", port->name); return 1; }
/* make new fd == stdin if it isn't already */
if( fd > 0 )
{
if( detach )
(void)close(0);
if( dup(fd) != 0 )
{ logerr("cannot make device \"%s\" stdin", port->name); return(1); }
}
/* make stdout and stderr, too */
if( detach )
{ (void)close(1); (void)close(2); }
if( dup(0) != 1 )
{ logerr("cannot dup stdin to stdout"); return(1); }
if( dup(0) != 2 )
{ logerr("cannot dup stdin to stderr"); return(1); }
if( fd > 2 )
(void)close(fd);
/* Set port modes (LOCAL mode) */
if( port_init(0, port->speed, oldtio, TRUE) )
return(1);
/* Make it controlling tty */
if( detach )
tio_ctty(0);
/*
* Switch off stdio buffering. We are
* not going to use streamed I/O, but..
*/
setbuf(stdin, (char *)NULL);
setbuf(stdout, (char *)NULL);
setbuf(stderr, (char *)NULL);
return(0);
}
/*
* Set terminal options as required. Don't forget that settings of
* the file descriptor copies made with dup() are shared.
*/
int port_init(int fd, int portspeed, TIO *oldtio, bool local)
{
TIO tio;
/* Install signal handlers */
#ifdef MODEM_WATCH_CARRIER
signal(SIGHUP, interrupt);
#else
signal(SIGHUP, linedrop);
#endif
signal(SIGINT, interrupt);
signal(SIGTERM, interrupt);
/*
* Set descriptor I/O to the non-blocking mode
*/
if( fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK) == -1 )
{
logerr("cannot set non-blocking mode for stdin");
return -1;
}
if( isatty(fd) )
{
/* Report to tty I/O routines that we are using modem */
tty_modem = 1;
if( tio_get(fd, &tio) == -1 )
{
logerr("initport error: cannot get terminal settings");
return -1;
}
/*
* Save old settings. We will restore them on exit.
*/
if( oldtio )
*oldtio = tio;
/* Set "raw" mode */
tio_set_raw_mode(&tio);
/* Set hardware flow control */
if( tio_set_flow_control(fd, &tio, FLOW_HARD) == -1 )
return -1;
/* Should we ignore DCD? */
#ifdef MODEM_WATCH_CARRIER
tio_set_local(&tio, TRUE);
#else
tio_set_local(&tio, local);
#endif
/* Set port speed */
if( portspeed )
{
/* set bit rate */
tio_set_speed(&tio, portspeed);
}
if( tio_set(fd, &tio) == -1 )
{
logerr("initport error: cannot set terminal settings");
return -1;
}
}
return 0;
}
int port_carrier(int fd, bool online)
{
tty_online = online;
#ifndef MODEM_WATCH_CARRIER
if( isatty(fd) )
{
TIO tio;
if( tio_get(fd, &tio) == -1 )
{
logerr("port_carrier error: cannot get terminal settings");
return -1;
}
tio_set_local(&tio, online ? FALSE : TRUE);
if( tio_set(fd, &tio) == -1 )
{
logerr("port_carrier error: cannot set terminal settings");
return -1;
}
}
#endif
return 0;
}
/*
* Restore old terminal settings
*/
int port_deinit(int fd, TIO *oldtio)
{
if( tio_set(fd, oldtio) == -1 )
{
logerr("deinitport error: cannot restore terminal settings");
return -1;
}
return 0;
}
/*
* Close port
*/
void port_close(void)
{
DEB((D_MODEM, "closeport: close modem port"));
/* Do nothing */
}
+336
View File
@@ -0,0 +1,336 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "io.h"
/*
* Hardware handshake flags (stolen from mgetty)
*/
#ifdef CRTSCTS
# define TIO_FLOW_HARD CRTSCTS /* linux, SunOS */
#else
# ifdef CRTSFL
# define TIO_FLOW_HARD CRTSFL /* SCO 3.2v4.2 */
# else
# ifdef RTSFLOW
# define TIO_FLOW_HARD RTSFLOW | CTSFLOW /* SCO 3.2v2 */
# else
# ifdef CTSCD
# define TIO_FLOW_HARD CTSCD /* AT&T 3b1? */
# else
# define TIO_FLOW_HARD 0
# endif
# endif
# endif
#endif
/*
* Software hadshake flags
*/
#define TIO_FLOW_SOFT (IXON | IXOFF)
/*
* Supported baud rates
*/
static struct speedtab {
#ifdef HAVE_TERMIOS_H
speed_t bspeed;
#else
unsigned short bspeed;
#endif
int nspeed;
const char *speed;
} speedtab[] = {
{ B300, 300, "300" },
#ifdef B600
{ B600, 600, "600" },
#endif
#ifdef B900
{ B900, 900, "900" },
#endif
{ B1200, 1200, "1200" },
#ifdef B1800
{ B1800, 1800, "1800" },
#endif
{ B2400, 2400, "2400" },
#ifdef B3600
{ B3600, 3600, "3600" },
#endif
{ B4800, 4800, "4800" },
#ifdef B7200
{ B7200, 7200, "7200" },
#endif
{ B9600, 9600, "9600" },
#ifdef B14400
{ B14400, 14400, "14400" },
#endif
#ifdef B19200
{ B19200, 19200, "19200" },
#endif /* B19200 */
#ifdef B28800
{ B28800, 28800, "28800" },
#endif
#ifdef B38400
{ B38400, 38400, "38400" },
#endif /* B38400 */
#ifdef EXTA
{ EXTA, 19200, "EXTA" },
#endif
#ifdef EXTB
{ EXTB, 38400, "EXTB" },
#endif
#ifdef B57600
{ B57600, 57600, "57600" },
#endif
#ifdef B76800
{ B76800, 76800, "76800" },
#endif
#ifdef B115200
{ B115200, 115200, "115200" },
#endif
#ifdef B230400
{ B230400, 230400, "230400" },
#endif
#ifdef B460800
{ B460800, 460800, "460800" },
#endif
{ 0, 0, "" }
};
/* get current tio settings for given filedescriptor */
int tio_get(int fd, TIO *tio)
{
#ifdef HAVE_TERMIOS_H
return tcgetattr(fd, tio);
#endif
}
/* set current tio settings for given filedescriptor */
int tio_set(int fd, TIO *tio)
{
#ifdef HAVE_TERMIOS_H
return tcsetattr(fd, TCSANOW, tio);
#endif
}
int tio_set_speed(TIO *tio, unsigned int speed)
{
int i;
#ifdef HAVE_TERMIOS_H
speed_t bspeed = -1;
#else
int bspeed = -1;
#endif
for( i = 0; speedtab[i].nspeed; i++ )
{
if( speedtab[i].nspeed == speed )
{
bspeed = speedtab[i].bspeed;
break;
}
}
if( bspeed == -1 )
{
log("unsupported speed %d", speed);
return -1;
}
#ifdef HAVE_TERMIOS_H
cfsetospeed(tio, bspeed);
cfsetispeed(tio, bspeed);
#endif
return 0;
}
/* get port speed. Return integer value, not symbolic constant */
int tio_get_speed(TIO *tio)
{
int i;
#ifdef HAVE_TERMIOS_H
speed_t bspeed = cfgetospeed(tio);
#endif
for( i = 0; speedtab[i].nspeed; i++ )
{
if( speedtab[i].bspeed == bspeed )
return speedtab[i].nspeed;
}
return-1;
}
int tio_set_flow_control(int fd, TIO *tio, int flow)
{
#if defined(HAVE_SYS_TERMIOX_H)
struct termiox tix;
#endif
DEB((D_MODEM, "tio_set_flow_control: setting HARD=%s, SOFT=%s",
(flow & FLOW_HARD) ? "On" : "Off",
(flow & FLOW_SOFT) ? "On" : "Off"));
#if defined(HAVE_TERMIOS_H)
tio->c_cflag &= ~TIO_FLOW_HARD;
tio->c_iflag &= ~TIO_FLOW_SOFT;
#ifdef IXANY
tio->c_iflag &= ~IXANY;
#endif
if( flow & FLOW_HARD )
tio->c_cflag |= TIO_FLOW_HARD;
if( flow & FLOW_SOFT )
tio->c_iflag |= TIO_FLOW_SOFT;
#endif /* HAVE_TERMIOS_H */
#if defined(HAVE_SYS_TERMIOX_H)
if( ioctl(fd, TCGETX, &tix) == -1 )
{
logerr("failed ioctl(TCGETX)");
return -1;
}
if( flow & FLOW_HARD )
tix.x_hflag |= (RTSXOFF | CTSXON);
else
tix.x_hflag &= ~(RTSXOFF | CTSXON);
if( ioctl(fd, TCSETX, &tix) == -1 )
{
logerr("failed ioctl(TCSETX)");
return -1;
}
#endif /* HAVE_SYS_TERMIOX_H */
return 0;
}
void tio_set_raw_mode(TIO *tio)
{
#if defined(HAVE_TERMIOS_H)
tio->c_cflag &= ~(CSTOPB | PARENB | PARODD);
tio->c_cflag |= (CS8 | CREAD | HUPCL);
tio->c_iflag = TIO_FLOW_SOFT;
tio->c_oflag = 0;
tio->c_lflag = 0;
tio->c_cc[VMIN] = 128;
tio->c_cc[VTIME] = 1;
#endif
}
void tio_set_local(TIO *tio, bool local)
{
#if defined(HAVE_TERMIOS_H)
if( local )
tio->c_cflag |= CLOCAL;
else
tio->c_cflag &= ~CLOCAL;
#endif
}
int tio_set_dtr(int fd, bool on)
{
int mctl = TIO_RS232_DTR;
DEB((D_MODEM, "tio_setdtr: setting DTR = %s", on ? "On" : "Off"));
if( on )
{
if( ioctl(fd, TIOCMBIS, &mctl ) < 0 )
{
logerr("cannot set DTR = On: TIOCMBIS failed");
return -1;
}
}
else
{
if( ioctl(fd, TIOCMBIC, &mctl ) < 0 )
{
logerr("cannot set DTR = Off: TIOCMBIC failed");
return -1;
}
}
return 0;
}
int tio_ctty(int fd)
{
if( setsid() < 0 )
logerr("cannot make myself session leader (setsid)");
#ifdef TIOCSCTTY
if( ioctl(fd, TIOCSCTTY, 0) < 0 )
{
logerr("cannot set controlling tty (ioctl)");
return -1;
}
#endif
return 0;
}
int tio_send_break(void)
{
#ifdef HAVE_TERMIOS_H
if( tcsendbreak(1, 0) < 0 )
{
logerr("tcsendbreak(1,0) failed");
#else
if( ioctl(1, TCSBRK) < 0 )
{
logerr("ioctl(1,TCSBRK) failed");
#endif
return -1;
}
return 0;
}
int tio_get_dcd(int fd)
{
int flags;
if( ioctl(fd, TIOCMGET, &flags ) < 0 )
return -1;
return (flags & TIO_RS232_DCD) ? 1 : 0;
}
int tio_get_rs232_state(void)
{
int flags;
if( ioctl(0, TIOCMGET, &flags ) < 0 )
return -1;
DEB((D_MODEM, "tio_getrs232: [%s]-[%s]-[%s]-[%s]-[%s]-[%s]",
( flags & TIO_RS232_RTS ) ? "RTS" : "rts",
( flags & TIO_RS232_CTS ) ? "CTS" : "cts",
( flags & TIO_RS232_DSR ) ? "DSR" : "dsr",
( flags & TIO_RS232_DTR ) ? "DTR" : "dtr",
( flags & TIO_RS232_DCD ) ? "DCD" : "dcd",
( flags & TIO_RS232_RNG ) ? "RNG" : "rng"));
return flags;
}
+438
View File
@@ -0,0 +1,438 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "io.h"
#ifndef RX_BUFSIZE
#define RX_BUFSIZE 4096
#endif
#ifndef TX_BUFSIZE
#define TX_BUFSIZE 4096
#endif
int tty_status = TTY_SUCCESS;
int tty_hangup = 0;
int tty_abort = 0;
int tty_online = 0;
int tty_modem = 0;
static unsigned char rx_buf[RX_BUFSIZE];
static unsigned char tx_buf[TX_BUFSIZE];
static unsigned int rx_pos = 0;
static unsigned int tx_pos = 0;
static unsigned int rx_left = 0; /* Received bytes left */
static unsigned int tx_left = TX_BUFSIZE; /* Free space left */
#ifdef MODEM_WATCH_CARRIER
# define CARRIER_CHECK() if( tty_modem && tty_online && !tty_hangup \
&& !tio_get_dcd(0) ) { \
log("carrier lost"); tty_hangup = 1; }
#else
# define CARRIER_CHECK()
#endif
const char *tty_errstr(int status)
{
const char *msg;
switch(status) {
case TTY_SUCCESS: msg = "No errors"; break;
case TTY_TIMEOUT: msg = "Time Out"; break;
case TTY_HANGUP: msg = "Hanged Up"; break;
case TTY_ERROR: msg = "IO Error"; break;
default: msg = "Unknown error"; break;
}
return msg;
}
/*
* On success, tty_select() return zero value and set/reset
* rd and wr to the appropriate values
*/
int tty_select(bool *rd, bool *wr, int timeout)
{
fd_set rfds, wfds;
struct timeval tv;
int rc;
FD_ZERO(&rfds);
FD_ZERO(&wfds);
if( rd ) { FD_SET(0,&rfds); *rd = FALSE; }
if( wr ) { FD_SET(1,&wfds); *wr = FALSE; }
tv.tv_sec = timeout;
tv.tv_usec = 0;
CARRIER_CHECK();
if( (tty_online && tty_hangup) || tty_abort )
{ return( tty_status = TTY_HANGUP ); }
rc = select(2, &rfds, &wfds, NULL, &tv);
CARRIER_CHECK();
if( rc < 0 )
{
if( errno == EINTR )
if( (tty_online && tty_hangup) || tty_abort )
{ tty_status = TTY_HANGUP; }
else
{ tty_status = TTY_SUCCESS; }
else
{ tty_status = TTY_ERROR; }
}
else if( rc == 0 )
{
tty_status = TTY_TIMEOUT;
}
else /* ( rc > 0 ) */
{
tty_status = TTY_ERROR;
if( rd && FD_ISSET(0,&rfds) )
{ tty_status = TTY_SUCCESS; *rd = TRUE; }
if( wr && FD_ISSET(1,&wfds) )
{ tty_status = TTY_SUCCESS; *wr = TRUE; }
}
DEB((D_TTYIO, "tty_select: return code = %s, rc = %d (rd=%s, wr=%s)",
tty_errstr(tty_status), rc,
rd ? *rd ? "true" : "false" : "null",
wr ? *wr ? "true" : "false" : "null"));
return tty_status;
}
/*
* It is a frontend to tty_select(), that also checks our program buffer
*/
int tty_xselect(bool *rd, bool *wr, int timeout)
{
if( rd && rx_pos > 0 )
{
(void)tty_select(NULL, wr, 0); *rd = TRUE;
return TTY_SUCCESS;
}
return tty_select(rd, wr, timeout);
}
/*
* Return non-zero value if some data available for reading
* in input queue OR in our RX buffer
*/
int tty_charwait(int timeout)
{
bool rd = FALSE;
if( rx_pos > 0 )
return 1;
else if( tty_select(&rd, NULL, timeout) == 0 && rd == TRUE )
return 1;
else
return 0;
}
/*
* On success return number of bytes received
*/
int tty_read(unsigned char *buf, size_t size)
{
int rc;
DEB((D_TTYIO, "tty_read: want read %d byte(s)", size));
CARRIER_CHECK();
if( (tty_online && tty_hangup) || tty_abort )
{ return( tty_status = TTY_HANGUP ); }
rc = read(0, buf, size);
CARRIER_CHECK();
if( (tty_online && tty_hangup) || tty_abort )
{
tty_status = TTY_HANGUP;
}
else if( rc < 0 )
{
if( errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK )
{ tty_status = TTY_TIMEOUT; }
else
{ tty_status = TTY_ERROR; }
}
else /* ( rc >= 0 ) */
tty_status = TTY_SUCCESS;
DEB((D_TTYIO, "tty_read: return code = %s, rc = %d",
tty_errstr(tty_status), rc));
return tty_status == TTY_SUCCESS ? rc : tty_status;
}
/*
* On success return number of bytes received
*/
int tty_read_timeout(unsigned char *buf, size_t size, int timeout)
{
int rc;
bool rd = FALSE;
tty_status = TTY_SUCCESS;
DEB((D_TTYIO, "tty_read_timeout: want read %d byte(s), timeout = %d", size, timeout));
if( timeout > 0 )
{
if( (rc = tty_select(&rd, NULL, timeout)) < 0 )
return rc;
if( rd )
{
if( (rc = tty_read(buf, size)) == 0 )
return TTY_ERROR;
return rc;
}
return TTY_TIMEOUT;
}
return tty_read(buf, size);
}
int tty_write(const unsigned char *buf, size_t size)
{
int rc;
DEB((D_TTYIO, "tty_write: want write %d byte(s)", size));
CARRIER_CHECK();
if( (tty_online && tty_hangup) || tty_abort )
{ return(tty_status = TTY_HANGUP); }
rc = write(1, buf, size);
CARRIER_CHECK();
if( rc < 0 )
{
if( errno == EINTR )
{
if( (tty_online && tty_hangup) || tty_abort )
{ tty_status = TTY_HANGUP; }
else
{ tty_status = TTY_TIMEOUT; }
}
else if( errno == EAGAIN || errno == EWOULDBLOCK )
{
tty_status = TTY_TIMEOUT;
}
else if( errno == EPIPE )
{
tty_hangup = 1;
tty_status = TTY_HANGUP;
}
else
{
tty_status = TTY_ERROR;
}
}
else if( rc == 0 )
tty_status = TTY_TIMEOUT;
else /* ( rc > 0 ) */
tty_status = TTY_SUCCESS;
DEB((D_TTYIO, "tty_write: return code = %s, rc = %d",
tty_errstr(tty_status), rc));
return (tty_status == TTY_SUCCESS) ? rc : tty_status;
}
/*
* On success return number of bytes sent
*/
int tty_write_timeout(const unsigned char *buf, size_t size, int timeout)
{
time_t timer;
int rc, pos = 0;
DEB((D_TTYIO, "tty_write_timeout: want write %d byte(s), timeout = %d", size, timeout));
tty_status = TTY_SUCCESS;
timer_set(&timer, timeout);
while( pos < size )
{
if( timer_expired(timer) )
{
break;
}
else if( (rc = tty_write(buf + pos, size - pos)) < 0 )
{
if( rc == TTY_TIMEOUT )
usleep(10000); /* 0.01 sec */
else
return rc;
}
else /* ( rc > 0 ) */
{
DEB((D_TTYIO, "tty_write_timeout: written %d byte(s)", rc));
pos += rc;
}
}
return (pos > 0) ? pos : TTY_TIMEOUT;
}
int tty_putc(unsigned char ch, int timeout)
{
return tty_write_timeout(&ch, 1, timeout);
}
int tty_puts(const unsigned char *s, int timeout)
{
return tty_write_timeout(s, strlen(s), timeout);
}
int tty_getc(int timeout)
{
int rc;
tty_status = TTY_SUCCESS;
if( rx_left == 0 )
{
rx_pos = 0;
if( (rc = tty_read_timeout(rx_buf, sizeof(rx_buf), timeout)) < 0 )
{
DEB((D_TTYIO, "tty_getc: tty_read() result \"%s\"", tty_errstr(rc)));
return rc;
}
else if( rc == 0 )
return TTY_ERROR; /* Isn't it? */
rx_left = rc;
}
rx_left--;
return rx_buf[rx_pos++];
}
int tty_bufc(unsigned char ch, int timeout)
{
int rc;
if( tx_left == 0 )
{
if( (rc = tty_flushbuf(timeout)) < 0 ) return rc;
else if( rc == 0 ) return TTY_TIMEOUT;
}
tx_buf[tx_pos++] = ch;
--tx_left;
return(tty_status = TTY_SUCCESS);
}
int tty_flushout(void)
{
DEB((D_TTYIO, "tty_flushout: flushing out"));
CARRIER_CHECK();
if( (tty_online && tty_hangup) || tty_abort )
return(tty_status = TTY_HANGUP);
#ifdef FUCKING_TCDRAIN
if( tty_modem )
{
while( tcdrain(1) == -1 )
{
if( errno == EINTR )
{
if( (tty_online && tty_hangup) || tty_abort )
return(tty_status = TTY_HANGUP);
}
else if( errno == EPIPE )
return(tty_status = TTY_HANGUP);
else if( errno == EAGAIN || errno == EWOULDBLOCK )
return(tty_status = TTY_SUCCESS);
else
return(tty_status = TTY_ERROR);
}
}
#endif /* FUCKING_TCDRAIN */
return(tty_status = TTY_SUCCESS);
}
int tty_flushbuf(int timeout)
{
int rc = 0;
tty_status = TTY_SUCCESS;
DEB((D_TTYIO, "tty_flushbuf: flushing internal TX buffer"));
if( tx_pos )
{
if( (rc = tty_write_timeout(tx_buf, tx_pos, timeout)) < 0 )
{
return rc;
}
tx_pos -= rc;
tx_left += rc;
}
return rc;
}
int tty_clearin(void)
{
DEB((D_TTYIO, "tty_clearin: clear RX buffers"));
tcflush(0, TCIFLUSH);
rx_left = 0;
rx_pos = 0;
CARRIER_CHECK();
if( (tty_online && tty_hangup) || tty_abort )
return(tty_status = TTY_HANGUP);
return(tty_status = TTY_SUCCESS);
}
int tty_clearout(void)
{
DEB((D_TTYIO, "tty_clearout: clear TX buffers"));
tcflush(1, TCOFLUSH);
tx_left = TX_BUFSIZE;
tx_pos = 0;
CARRIER_CHECK();
if( (tty_online && tty_hangup) || tty_abort )
return(tty_status = TTY_HANGUP);
return(tty_status = TTY_SUCCESS);
}
+570
View File
@@ -0,0 +1,570 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "version.h"
#include "logger.h"
#include "util.h"
/*
* Local variables for logger
*/
static FILE *log_fp = NULL;
static char log_name[BF_MAXPATH+1] = BFORCE_LOGFILE;
static char log_extension[32] = "";
static char log_ident[32] = "";
static char log_ttyname[32] = "";
#ifdef DEBUG
/*
* Local variables needed to make debug work
*/
static FILE *debug_fp = NULL;
static long debug_current_debuglevel = 0L;
static char debug_name[BF_MAXPATH+1] = BFORCE_DEBFILE;
static bool debug_invalid_name = FALSE;
/*
* Debug level names
*/
struct debuglevel {
const char *keystr;
unsigned long value;
} debuglevels[] = {
{ "Config", D_CONFIG },
{ "Override", D_OVERRIDE },
{ "Event", D_EVENT },
{ "Nodelist", D_NODELIST },
{ "Outbound", D_OUTBOUND },
{ "Info", D_INFO },
{ "HShake", D_HSHAKE },
{ "TtyIO", D_TTYIO },
{ "Modem", D_MODEM },
{ "Prot", D_PROT },
{ "Freq", D_FREQ },
{ "Statem", D_STATEM },
{ "Daemon", D_DAEMON },
{ "Full", D_FULL },
{ NULL, 0 }
};
#endif /* DEBUG */
#ifdef USE_SYSLOG
#include <syslog.h>
#endif /* ifdef USE_SYSLOG */
#ifndef USE_SYSLOG
const char *log_getfilename(int whatfor)
{
const char *p = NULL;
switch(whatfor) {
case LOG_FILE_DAEMON:
if( (p = conf_string(cf_log_file_daemon)) == NULL )
p = DAEMON_LOGFILE;
break;
case LOG_FILE_SESSION:
if( (p = conf_string(cf_log_file)) == NULL )
p = BFORCE_LOGFILE;
break;
#ifdef DEBUG
case LOG_FILE_DEBUG:
if( (p = conf_string(cf_debug_file)) == NULL )
p = BFORCE_DEBFILE;
break;
#endif
case LOG_FILE_HISTORY:
break;
}
return p;
}
/*
* Logging part
*/
bool log_isopened(void)
{
return log_fp ? TRUE : FALSE;
}
int log_open(const char *logname, const char *ext, const char *tty)
{
if( log_fp )
log("warning: opening new log file, but previous was not closed");
if( logname )
{
/* Reset previous settings */
*log_name = '\0';
*log_extension = '\0';
*log_ttyname = '\0';
strnxcpy(log_name, logname, sizeof(log_name));
if( tty && *tty )
strnxcpy(log_ttyname, tty, sizeof(log_ttyname));
if( ext && *ext )
{
strnxcpy(log_extension, ext, sizeof(log_extension));
strnxcat(log_name, ".", sizeof(log_name));
strnxcat(log_name, ext, sizeof(log_name));
}
if( (log_fp = fopen(log_name, "a")) == NULL )
{
logerr("can't open log file \"%s\"", log_name);
return -1;
}
}
else if( log_name )
{
/* Open previously set log file */
if( (log_fp = fopen(log_name, "a")) == NULL )
{
logerr("can't open log file \"%s\"", log_name);
return -1;
}
} else
return -1;
return 0;
}
int log_close(void)
{
int rc = 0;
ASSERT(log_fp);
if( log_fp )
{
rc = fclose(log_fp); log_fp = NULL;
}
return rc;
}
int log_reopen(const char *logname, const char *ext, const char *tty)
{
ASSERT(logname != NULL);
if( log_isopened() )
{
if( !strcmp(logname, log_name)
&& !strcmp(log_extension ? log_extension : "", ext ? ext : "") )
{
return 0;
}
log_close();
}
return log_open(logname, ext, tty);
}
/* void log_setident(const char *ident)
{
if( ident )
strnxcpy(log_ident, ident, sizeof(log_ident));
else
*log_ident = '\0';
} */
int log(const char *s, ...)
{
char timestr[40];
va_list args;
time_string_log(timestr, sizeof(timestr), 0);
va_start(args, s);
/*
* If log file is not opened print messages to the stderr
*/
if( log_fp == NULL )
{
fprintf(stderr, "%s ", timestr);
vfprintf(stderr, s, args);
putc('\n', stderr);
fflush(stderr);
}
else
{
int mypid = getpid();
if( log_ident[0] && log_ttyname[0] )
fprintf(log_fp, "%s %s.%s[%d] ", timestr, log_ident, log_ttyname, mypid);
else if( log_ident[0] )
fprintf(log_fp, "%s %s[%d] ", timestr, log_ident, mypid);
else if( log_ttyname[0] )
fprintf(log_fp, "%s %s[%d] ", timestr, log_ttyname, mypid);
else
fprintf(log_fp, "%s [%d] ", timestr, mypid);
vfprintf(log_fp, s, args);
putc('\n', log_fp);
fflush(log_fp);
}
va_end(args);
return 0;
}
int logerr(const char *s, ...)
{
char timestr[40];
va_list args;
time_string_log(timestr, sizeof(timestr), 0);
va_start(args, s);
/*
* If log file is not opened print messages to the stderr
*/
if( log_fp == NULL )
{
fprintf(stderr, "%s ", timestr);
vfprintf(stderr, s, args);
putc('\n', stderr);
if( errno == EACCES )
{
fprintf(stderr, "\tmessage: \"%s\" : errno = %d (euid = %d, egid = %d)\n",
strerror(errno), errno, geteuid(), getegid());
}
else
{
fprintf(stderr, "\tmessage: \"%s\" : errno = %d\n",
strerror(errno), errno);
}
fflush(stderr);
}
else
{
int mypid = getpid();
if( *log_ident && *log_ttyname )
fprintf(log_fp, "%s %s.%s[%d] ", timestr, log_ident, log_ttyname, mypid);
else if( *log_ident )
fprintf(log_fp, "%s %s[%d] ", timestr, log_ident, mypid);
else if( *log_ttyname )
fprintf(log_fp, "%s %s[%d] ", timestr, log_ttyname, mypid);
else
fprintf(log_fp, "%s [%d] ", timestr, mypid);
vfprintf(log_fp, s, args);
putc('\n', log_fp);
/*
* Print error message according to the errno value
*/
if( errno == EACCES )
{
fprintf(log_fp, "\tmessage: \"%s\" : errno = %d (euid = %d, egid = %d)\n",
strerror(errno), errno, geteuid(), getegid());
}
else if( errno )
{
fprintf(log_fp, "\tmessage: \"%s\" : errno = %d\n",
strerror(errno), errno);
}
fflush(log_fp);
}
va_end(args);
return 0;
}
#endif /* ifndef USE_SYSLOG */
#ifdef USE_SYSLOG
const char *log_getfilename(int whatfor)
{
const char *p = "/dev/null";
return p;
}
bool log_isopened(void)
{
return TRUE;
}
int log_open(const char *logname, const char *ext, const char *tty)
{
char *p = "bforce";
int fac = conf_number(cf_syslog_facility);
if( tty && *tty )
strncpy(p, tty, sizeof(p));
openlog(p, LOG_PID, fac);
return 0;
}
int log_reopen(const char *logname, const char *ext, const char *tty)
{
return 0;
}
int log_close(void)
{
closelog();
return 0;
}
int log(const char *s, ...)
{
char timestr[40];
va_list args;
int fac = conf_number(cf_syslog_facility);
const int LP_TTY = fac || LOG_INFO;
const int LP_A = fac || LOG_NOTICE;
const int LP_O = fac || LOG_DEBUG;
const int log_priority = fac || LOG_ERR;
time_string_log(timestr, sizeof(timestr), 0);
va_start(args, s);
int mypid = getpid();
if( log_ident[0] && log_ttyname[0] )
syslog(LP_TTY, "%s %s.%s[%d] ", timestr, log_ident, log_ttyname, mypid);
else if( log_ident[0] )
syslog(LP_A, "%s %s[%d] ", timestr, log_ident, mypid);
else if( log_ttyname[0] )
syslog(LP_O, "%s %s[%d] ", timestr, log_ttyname, mypid);
else
fprintf(log_priority, "%s [%d] ", timestr, mypid);
/* vsyslog(log_priority, s, args);*/
/* putc('\n', log_fp);
fflush(log_fp);
} */
va_end(args);
return 0;
}
int logerr(const char *s, ...)
{
char timestr[40];
va_list args;
int fac = conf_number(cf_syslog_facility);
const int log_priority = fac || LOG_ERR;
time_string_log(timestr, sizeof(timestr), 0);
va_start(args, s);
int mypid = getpid();
/* if( log_ident[0] && log_ttyname[0] )
syslog(log_priority, "%s %s.%s[%d] ", timestr, log_ident, log_ttyname, mypid);
else if( log_ident[0] )
syslog(log_priority, "%s %s[%d] ", timestr, log_ident, mypid);
else if( log_ttyname[0] )
fprintf(log_priority, "%s %s[%d] ", timestr, log_ttyname, mypid);
else
fprintf(log_priority, "%s [%d] ", timestr, mypid);
*/
vsyslog(log_priority, s, args);
/* putc('\n', log_fp);
fflush(log_fp);
} */
va_end(args);
return 0;
}
#endif /* ifdef USE_SYSLOG */
/*
* Debugging part
*/
#ifdef DEBUG
void debug_setlevel(long newlevel, bool logit)
{
if( logit && newlevel != debug_current_debuglevel )
{
log("changing debug level from 0x%07x to 0x%07x",
debug_current_debuglevel, newlevel);
debug_current_debuglevel = newlevel;
}
}
bool debug_isopened(void)
{
return debug_fp ? TRUE : FALSE;
}
int debug_parsestring(char *str, unsigned long *deblevel)
{
int i, rc = 0;
char *n;
char *p_str = NULL;
ASSERT(str != NULL);
*deblevel = 0L;
for( p_str = string_token(str, &n, NULL, 0); p_str;
p_str = string_token(NULL, &n, NULL, 0) )
{
for( i = 0; debuglevels[i].keystr; i++ )
{
if( strcasecmp(p_str, debuglevels[i].keystr) == 0 )
{
*deblevel |= debuglevels[i].value;
break;
}
}
if( debuglevels[i].keystr == NULL )
{
log("unknown debug level \"%s\"", p_str);
rc = 1;
}
}
return rc;
}
void debug_setfilename(const char *debugname)
{
ASSERT(debugname != NULL);
if( !strcmp(debug_name, debugname) ) return;
if( debug_isopened() ) debug_close();
/* Reset ignore flag */
if( debug_invalid_name )
debug_invalid_name = FALSE;
strnxcpy(debug_name, debugname, sizeof(debug_name));
}
int debug_open(const char *debugname)
{
char buf[40];
ASSERT(debug_fp == NULL);
if( debugname )
{
if( (debug_fp = fopen(debugname, "a")) == NULL )
{
logerr("can't open debug file \"%s\"", debugname);
return -1;
}
strnxcpy(debug_name, debugname, sizeof(debug_name));
}
else if( debug_name )
{
if( (debug_fp = fopen(debug_name, "a")) == NULL )
{
/* Don't try to open it next time */
debug_invalid_name = TRUE;
logerr("can't open debug file \"%s\"", debug_name);
return -1;
}
} else
return -1;
/* Put banner */
fprintf(debug_fp, "****************************************************\n");
fprintf(debug_fp, " Starting binkleyforce version %s\n", BF_VERSION);
fprintf(debug_fp, " Time: %s, PID: %d, UID: %d, GID: %d, EUID: %d, EGID %d\n",
time_string_long(buf, sizeof(buf), 0), getpid(),
getuid(), getgid(), geteuid(), getegid());
fprintf(debug_fp, "****************************************************\n");
fflush(debug_fp);
return 0;
}
int debug_close(void)
{
char buf[40];
int rc = 0;
ASSERT(debug_fp != NULL);
if( debug_fp )
{
fprintf(debug_fp, "****************************************************\n");
fprintf(debug_fp, " Closing Binkley-Force debug file at %s\n",
time_string_long(buf, sizeof(buf), 0));
fprintf(debug_fp, "****************************************************\n");
rc = fclose(debug_fp) ? 0 : -1; debug_fp = NULL;
}
return rc;
}
int debug(unsigned long what, const char *str, ...)
{
char buf[40];
va_list args;
if( (what == 0 && debug_current_debuglevel)
|| (debug_current_debuglevel & what) )
{
if( debug_fp == NULL && debug_invalid_name == FALSE )
{
debug_open(NULL);
}
if( debug_fp )
{
fprintf(debug_fp, "%s ", time_string_log(buf, sizeof(buf), 0));
va_start(args, str);
vfprintf(debug_fp, str, args);
va_end(args);
putc('\n', debug_fp);
fflush(debug_fp);
}
}
return 0;
}
#endif /* DEBUG */
+585
View File
@@ -0,0 +1,585 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "nodelist.h"
#define NODELIST_LOCK_TRIES 3
#define NODELIST_LOCK_DELAY 1 /* seconds */
struct keyword {
const char *keystr;
const int keyval;
} keywords[] = {
{ "", KEYWORD_EMPTY },
{ "Zone", KEYWORD_ZONE },
{ "Region", KEYWORD_REGION },
{ "Host", KEYWORD_HOST },
{ "Hub", KEYWORD_HUB },
{ "Pvt", KEYWORD_PVT },
{ "Hold", KEYWORD_HOLD },
{ "Down", KEYWORD_DOWN },
{ "Boss", KEYWORD_BOSS },
{ "Point", KEYWORD_POINT },
{ NULL, 0 }
};
/*****************************************************************************
* Check flag for existing in nodelist flags string
*
* Arguments:
* nodeflags pointer to the node's nodelist flags string
* flag pointer to the flag that we want to check
*
* Return value:
* zero value if flag is presented in flags, and non-zero if not
*/
int nodelist_checkflag(const char *nodeflags, const char *flag)
{
char *p, *q;
if( (p = strstr(nodeflags, flag)) )
{
if( p == nodeflags || *(p-1) == ',' )
{
if( (q = strchr(p, ',')) == NULL || (q - p) == strlen(flag) )
return 0;
}
}
return 1;
}
/*****************************************************************************
* Get nodelist keyword (e.g. Host, Hub, Point, etc.) value
* (e.g. KEYWORD_HOST, KEYWORD_HUB, etc.)
*
* Arguments:
* keywordval pointer to the keyword string
*
* Return value:
* One of KEYWORD_* values, and -1 for unknown keywords
*/
int nodelist_keywordval(const char *keyword)
{
int i;
for( i = 0; keywords[i].keystr; i++ )
{
if( strcmp(keyword, keywords[i].keystr) == 0 )
{
return keywords[i].keyval;
}
}
return -1;
}
int nodelist_parse_Txy(s_node *node, const char *xy)
{
long beg;
long end;
long tz;
if( xy[0] >= 'A' && xy[0] <= 'X' )
beg = (xy[0] - 'A') * 60;
else if( xy[0] >= 'a' && xy[0] <= 'x' )
beg = (xy[0] - 'a') * 60 + 30;
else
return -1;
if( xy[1] >= 'A' && xy[1] <= 'X' )
end = (xy[1] - 'A') * 60;
else if( xy[1] >= 'a' && xy[1] <= 'x' )
end = (xy[1] - 'a') * 60 + 30;
else
return -1;
if( beg == end )
return -1;
/* Convert it to local time */
if( (tz = time_gmtoffset()) )
{
beg -= tz;
if( beg > 1440 )
beg = beg - 1440;
else if( beg < 0 )
beg = beg + 1440;
else if( beg == 1440 )
beg = 0;
end -= tz;
if( end > 1440 )
end = end - 1440;
else if( end < 0 )
end = end + 1440;
else if( end == 1440 )
end = 0;
}
timevec_add(&node->worktime, DAY_MONDAY, DAY_SUNDAY, beg, end);
return 0;
}
/*****************************************************************************
* Nodelist string parser
*
* Arguments:
* node put here all obtained information
* str pointer to the nodelist string
*
* Return value:
* zero value if string was parsed successfuly, and non-zero if wasn't
*/
int nodelist_parsestring(s_node *node, char *str)
{
char *argv[NODELIST_POSFLAGS+1];
char *p;
if( string_parse(argv, NODELIST_POSFLAGS+1, str, ',') != NODELIST_POSFLAGS+1 )
return -1;
if( !ISDEC(argv[NODELIST_POSNUMBER]) || !ISDEC(argv[NODELIST_POSSPEED]) )
return -1;
if( (node->keyword = nodelist_keywordval(argv[NODELIST_POSKEYWORD])) == -1 )
return -1;
if( node->addr.zone )
{
int number = atoi(argv[NODELIST_POSNUMBER]);
bool goodstr = FALSE;
switch(node->keyword) {
case KEYWORD_ZONE:
goodstr = (node->addr.zone == number);
break;
case KEYWORD_REGION:
case KEYWORD_HOST:
goodstr = (node->addr.net == number);
break;
case KEYWORD_POINT:
goodstr = (node->addr.point == number);
break;
default:
goodstr = (node->addr.node == number);
break;
}
if( !goodstr ) return -1;
}
strnxcpy(node->name, argv[NODELIST_POSNAME], sizeof(node->name));
strnxcpy(node->location, argv[NODELIST_POSLOCATION], sizeof(node->location));
strnxcpy(node->sysop, argv[NODELIST_POSSYSOP], sizeof(node->sysop));
strnxcpy(node->phone, argv[NODELIST_POSPHONE], sizeof(node->phone));
strnxcpy(node->flags, argv[NODELIST_POSFLAGS], sizeof(node->flags));
node->speed = atoi(argv[NODELIST_POSSPEED]);
/*
* Replace all '_' by space character
*/
string_replchar(node->name, '_', ' ');
string_replchar(node->location, '_', ' ');
string_replchar(node->sysop, '_', ' ');
/*
* Get system work time (usefull flags: CM,Txy)
*/
if( nodelist_checkflag(node->flags, "CM") == 0 )
{
timevec_add(&node->worktime, DAY_MONDAY, DAY_SUNDAY, 0, 1440);
}
else
{
for( p = node->flags; p && *p; p = strchr(p, ',') )
{
if( p[1] == 'T' && p[2] && p[3] && (p[4] == ',' || p[4] == '\0') )
{
if( nodelist_parse_Txy(node, p+2) == -1 )
log("invalid nodelist Txy flag in \"%s\"", node->flags);
break;
}
p++;
}
/*
* Set default work time according to ZMH
*/
if( node->addr.point == 0 )
{
switch(node->addr.zone) {
case 1: nodelist_parse_Txy(node, "JK"); break;
case 2: nodelist_parse_Txy(node, "cd"); break;
case 3: nodelist_parse_Txy(node, "ST"); break;
case 4: nodelist_parse_Txy(node, "IJ"); break;
case 5: nodelist_parse_Txy(node, "BC"); break;
case 6: nodelist_parse_Txy(node, "UV"); break;
}
}
}
return 0;
}
/*****************************************************************************
* Open nodelist, nodelist index, do some checks
*
* Arguments:
* dir pointer to the nodelist's directory
* name pointer to the nodelist file name
* mode are we going to read nodelist index? Or write?
*
* Return value:
* pointer to the allocated nodelist structure (will be used with all
* nodelist operations), and NULL to indicate errors.
*/
s_nodelist *nodelist_open(const char *dir, const char *name, int mode)
{
s_nodelist tmp;
const char *openmode;
int lockmode;
memset(&tmp, '\0', sizeof(s_nodelist));
/*
* Select nodelist index open mode
*/
if( mode == NODELIST_READ )
{
openmode = "r";
lockmode = FILELOCK_READ;
}
else if( mode == NODELIST_WRITE )
{
openmode = "w";
lockmode = FILELOCK_WRITE;
}
else
ASSERT(0);
/*
* Get nodelist and nodelist index file names
*/
if( *name == DIRSEPCHR )
{
strnxcpy(tmp.name_nodelist, name, sizeof(tmp.name_nodelist));
strnxcpy(tmp.name_index, name, sizeof(tmp.name_index));
}
else
{
strnxcpy(tmp.name_nodelist, dir, sizeof(tmp.name_nodelist));
strnxcat(tmp.name_nodelist, name, sizeof(tmp.name_nodelist));
strnxcpy(tmp.name_index, tmp.name_nodelist, sizeof(tmp.name_index));
}
strnxcat(tmp.name_index, ".index", sizeof(tmp.name_index));
DEB((D_NODELIST, "nodelist_open: nodelist name = \"%s\"", tmp.name_nodelist));
DEB((D_NODELIST, "nodelist_open: nodelist index = \"%s\"", tmp.name_index));
DEB((D_NODELIST, "nodelist_open: open mode = \"%s\"", openmode));
/*
* Try to open and lock nodelist
*/
if( (tmp.fp_nodelist = file_open(tmp.name_nodelist, "r")) == NULL )
{
logerr("cannot open nodelist \"%s\"", tmp.name_nodelist);
return NULL;
}
/*
* Try to open and lock nodelist index
*/
if( (tmp.fp_index = file_open(tmp.name_index, openmode)) == NULL )
{
logerr("cannot open nodelist index \"%s\"", tmp.name_index);
fclose(tmp.fp_nodelist);
return NULL;
}
/*
* If we open nodelist for reading then we should check that
* nodelist index has correct header and up to date
*/
if( mode == NODELIST_READ )
{
if( nodelist_checkheader(&tmp) == -1 )
{
file_close(tmp.fp_nodelist);
file_close(tmp.fp_index);
return NULL;
}
}
return xmemcpy(&tmp, sizeof(s_nodelist));
}
/*****************************************************************************
* Check nodelist index header for valid nodelist date and size
*
* Arguments:
* nlp opened nodelist
*
* Return value:
* zero value if header is correct, and -1 if not
*/
int nodelist_checkheader(s_nodelist *nlp)
{
unsigned long nltime;
unsigned long nlsize;
struct stat nlstat;
char buffer[NODELIST_HDRSIZE];
if( fread(buffer, sizeof(buffer), 1, nlp->fp_index) != 1 )
{
logerr("cannot read header from nodelist index \"%s\"", nlp->name_index);
return -1;
}
if( fstat(fileno(nlp->fp_nodelist), &nlstat) == -1 )
{
logerr("cannot stat nodelist \"%s\"", nlp->name_nodelist);
return -1;
}
nltime = buffer_getlong(buffer + 0);
nlsize = buffer_getlong(buffer + 4);
if( (unsigned long)nlstat.st_mtime != nltime )
{
log("invalid nodelist index: incorrect nodelist date %ld (expected %ld)",
(long)nlstat.st_mtime, (long)nltime);
return -1;
}
if( (unsigned long)nlstat.st_size != nlsize )
{
log("invalid nodelist index: incorrect nodelist size %ld (expected %ld)",
(long)nlstat.st_size, (long)nlsize);
return -1;
}
return 0;
}
/*****************************************************************************
* Create/update nodelist index header. Nodelist must be opened for
* writing. Now nodelist index header contain nodelist modification
* time and nodelist size.
*
* Arguments:
* nlp opened nodelist
*
* Return value:
* zero value on success, and -1 at errors
*/
int nodelist_createheader(s_nodelist *nlp)
{
struct stat nlstat;
char hdrbuf[NODELIST_HDRSIZE];
memset(&hdrbuf, '\0', sizeof(hdrbuf));
if( fstat(fileno(nlp->fp_nodelist), &nlstat) == -1 )
{
logerr("cannot stat nodelist \"%s\"", nlp->name_nodelist);
return -1;
}
buffer_putlong(hdrbuf + 0, nlstat.st_mtime);
buffer_putlong(hdrbuf + 4, nlstat.st_size);
if( fseek(nlp->fp_index, 0L, SEEK_SET) == -1 )
{
logerr("cannot seek to zero offset of index");
return -1;
}
if( fwrite(hdrbuf, sizeof(hdrbuf), 1, nlp->fp_index) != 1 )
{
logerr("cannot write nodelist index header");
return -1;
}
return 0;
}
/*****************************************************************************
* Close nodelist and nodelist index files
*
* Arguments:
* nlp pointer to the opened nodelist
*
* Return value:
* Zero value if close was successful, and non-zero if not
*/
int nodelist_close(s_nodelist *nlp)
{
int rc = 0;
ASSERT(nlp && nlp->fp_nodelist && nlp->fp_index);
if( nlp->fp_nodelist && file_close(nlp->fp_nodelist) )
logerr("cannot close nodelist \"%s\"", nlp->name_nodelist);
if( nlp->fp_index && file_close(nlp->fp_index) )
{
logerr("cannot close nodelist index \"%s\"", nlp->name_index);
rc = 1;
}
free(nlp);
return rc;
}
int nodelist_putindex(s_nodelist *nlp, const s_bni *bni)
{
char buffer[NODELIST_ENTRYSIZE];
ASSERT(nlp && nlp->fp_index);
buffer_putint(buffer + 0, bni->zone);
buffer_putint(buffer + 2, bni->net);
buffer_putint(buffer + 4, bni->node);
buffer_putint(buffer + 6, bni->point);
buffer_putint(buffer + 8, bni->hub);
buffer_putlong(buffer + 10, bni->offset);
if( fwrite(buffer, sizeof(buffer), 1, nlp->fp_index) != 1 )
{
logerr("error writing nodelist index file \"%s\"", nlp->name_index);
return -1;
}
return 0;
}
int nodelist_findindex(s_nodelist *nlp, s_bni *bni, s_faddr addr)
{
long readitems;
char buffer[NODELIST_ENTRYSIZE * NODELIST_READAHEAD];
char *p;
if( fseek(nlp->fp_index, NODELIST_HDRSIZE, SEEK_SET) ) return -1;
while(1)
{
if( (readitems = fread(buffer, NODELIST_ENTRYSIZE, NODELIST_READAHEAD, nlp->fp_index)) > 0 )
{
for( p = buffer; readitems > 0; readitems-- )
{
if( buffer_getint(p + 0) == addr.zone
&& buffer_getint(p + 2) == addr.net
&& buffer_getint(p + 4) == addr.node
&& buffer_getint(p + 6) == addr.point )
{
bni->zone = buffer_getint(p + 0);
bni->net = buffer_getint(p + 2);
bni->node = buffer_getint(p + 4);
bni->point = buffer_getint(p + 6);
bni->hub = buffer_getint(p + 8);
bni->offset = buffer_getlong(p + 10);
return 0;
}
p += NODELIST_ENTRYSIZE;
}
} else
return -1;
}
return -1;
}
int nodelist_getstr(s_nodelist *nlp, size_t offset, char *buffer, size_t buflen)
{
ASSERT(nlp && nlp->fp_nodelist);
if( fseek(nlp->fp_nodelist, offset, SEEK_SET) == 0
&& fgets(buffer, buflen, nlp->fp_nodelist) )
{
string_chomp(buffer);
return 0;
}
return -1;
}
int nodelist_lookup_string(char *buffer, size_t buflen, s_faddr addr)
{
s_bni bni;
s_cval_entry *ptrl;
s_nodelist *nlp;
const char *ndldir = NULL;
ndldir = conf_string(cf_nodelist_directory);
/*
* Try all nodelists with matching address mask
*/
for( ptrl = conf_first(cf_nodelist); ptrl; ptrl = conf_next(ptrl) )
{
if( ftn_addrcomp_mask(addr, ptrl->d.falist.addr) == 0 )
{
if( (nlp = nodelist_open(ndldir, ptrl->d.falist.what, NODELIST_READ)) )
{
int rc = nodelist_findindex(nlp, &bni, addr);
if( !rc )
rc = nodelist_getstr(nlp, bni.offset, buffer, buflen);
nodelist_close(nlp);
if( !rc )
return 0;
}
}
}
return -1;
}
int nodelist_lookup(s_node *node, s_faddr addr)
{
char buf[512];
char abuf[BF_MAXADDRSTR+1];
nodelist_initnode(node, addr);
if( nodelist_lookup_string(buf, sizeof(buf), addr) == 0 )
{
node->listed = TRUE;
if( nodelist_parsestring(node, buf) == -1 )
{
log("invalid nodelist string for address %s",
ftn_addrstr(abuf, addr));
}
return 0;
}
return -1;
}
void nodelist_initnode(s_node *node, s_faddr addr)
{
memset(node, '\0', sizeof(s_node));
node->addr = addr;
strcpy(node->name, "<none>");
strcpy(node->sysop, "<none>");
strcpy(node->location, "<none>");
strcpy(node->phone, "<none>");
}
+15
View File
@@ -0,0 +1,15 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
+469
View File
@@ -0,0 +1,469 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
struct {
char *name;
int value;
} exec_options_names[] = {
{ "nowait", EXEC_OPT_NOWAIT },
{ "setsid", EXEC_OPT_SETSID },
{ "logout", EXEC_OPT_LOGOUT },
{ "useshell", EXEC_OPT_USESHELL },
{ NULL, 0 }
};
int exec_file_exist(const char *command)
{
const char *p;
ASSERT(command);
if( *command == '[' )
{
p = strchr(command + 1, ']');
if( !p )
return -1;
++p;
}
else
p = command;
if( !access(p, X_OK) )
return 0;
return -1;
}
int exec_options_parse(char *str)
{
int yield = 0;
char *p;
char *n;
int i;
for( p = string_token(str, &n, ", \t", 0); p;
p = string_token(NULL, &n, ", \t", 0) )
{
for( i = 0; exec_options_names[i].name; i++ )
if( !strcasecmp(p, exec_options_names[i].name) )
{
yield |= exec_options_names[i].value;
break;
}
if( !exec_options_names[i].name )
log("unknown exec option '%s'", p);
}
return yield;
}
void exec_options_init(s_exec_options *eopt)
{
memset(eopt, '\0', sizeof(s_exec_options));
eopt->umask = EXEC_DEFAULT_UMASK;
eopt->envp[0] = NULL;
}
void exec_options_deinit(s_exec_options *eopt)
{
int i;
if( eopt->command )
free(eopt->command);
for( i = 0; eopt->envp[i]; i++ )
free(eopt->envp[i]);
memset(eopt, '\0', sizeof(s_exec_options));
}
void exec_env_add(s_exec_options *eopt, const char *name, const char *value)
{
int i;
for( i = 0; eopt->envp[i]; i++ ); /* Empty Loop */
if( i < EXEC_MAX_NUM_ENVS )
{
eopt->envp[i] = xmalloc(strlen(name) + strlen(value) + 2);
sprintf(eopt->envp[i], "%s=%s", name, value);
eopt->envp[i+1] = NULL;
}
}
void exec_options_set_command(s_exec_options *eopt, const char *command)
{
char *copy, *p;
if( *command == '[' )
{
copy = xstrcpy(command);
p = strchr(copy, ']');
if( !p )
eopt->command = copy;
else
{
*p++ = '\0';
eopt->command = xstrcpy(string_trimleft(p));
eopt->options = exec_options_parse(copy+1);
free(copy);
}
}
else
eopt->command = xstrcpy(command);
}
int exec_redirect_descriptor(int desc, const char *fname, int flags)
{
int fd;
(void)close(desc);
if( (fd = open(fname, flags, S_IRUSR|S_IWUSR)) == -1 )
{
logerr("exec error: cannot open \"%s\"", fname);
return -1;
}
if( fd != desc )
{
log("exec error: cannot open \"%s\" <--> %d (got %d)",
fname, desc, fd);
return -1;
}
return 0;
}
int exec_command(s_exec_options *eopt)
{
pid_t pid = 0;
int status = 0;
time_t starttime = 0;
time_t timer = 0;
char *tempfile = NULL;
struct sigaction new_chld;
struct sigaction old_chld;
sigset_t new_mask;
sigset_t old_mask;
if( eopt->command == NULL )
return -1;
if( eopt->options & EXEC_OPT_LOGOUT )
{
tempfile = file_gettmp();
if( !tempfile )
log("cannot generate temporary file name");
}
/* Block SIGCHLD */
sigemptyset(&new_mask);
sigaddset(&new_mask, SIGCHLD);
sigprocmask(SIG_BLOCK, &new_mask, NULL);
/* Set the default SIGCHLD handler */
new_chld.sa_handler = SIG_DFL;
sigaction(SIGCHLD, &new_chld, &old_chld);
if( (pid = fork()) == -1 )
{
logerr("exec error: cannot fork()");
return -1;
}
if( !pid )
{
if( exec_redirect_descriptor(0, "/dev/null", O_RDONLY) == -1 )
exit(128);
if( tempfile )
{
if( exec_redirect_descriptor(1, tempfile, O_WRONLY|O_CREAT|O_TRUNC) == -1
|| exec_redirect_descriptor(2, tempfile, O_WRONLY) == -1 )
exit(128);
}
else
{
if( exec_redirect_descriptor(1, "/dev/null", O_WRONLY) == -1
|| exec_redirect_descriptor(2, "/dev/null", O_WRONLY) == -1 )
exit(128);
}
if( eopt->options & EXEC_OPT_SETSID )
setsid();
if( eopt->options & EXEC_OPT_USESHELL )
execle("/bin/sh", "sh", "-c", eopt->command, NULL, eopt->envp);
else
{
char *argv[EXEC_MAX_NUM_ARGS+1];
int argc = string_parse_regular(argv, EXEC_MAX_NUM_ARGS,
eopt->command);
if( argc > 0 )
{
argv[argc] = NULL;
execve(argv[0], argv, eopt->envp);
}
/* eopt->command is corrupted now */
}
/* We get here only in case of errors */
logerr("cannot execute \"%s\"", eopt->command);
exit(128);
}
/*
* We are inside parent process, do:
*
* 1) if OUTMODE_LOGPIPE is used than log child process ouput
* 2) wait for child process to exit
*/
log("running \"%s\", PID %d",
string_printable(eopt->command), (int)pid);
if( !(eopt->options & EXEC_OPT_NOWAIT) )
{
starttime = time(NULL); /* Set process start time */
if( waitpid(pid, &status, 0) > 0 )
{
eopt->runtime = time(NULL) - starttime;
if( eopt->runtime < 0 )
eopt->runtime = 0;
/*
* Write process's output to the log file
*/
if( tempfile )
{
char buf[256];
FILE *fp = file_open(tempfile, "r");
if( !fp )
logerr("cannot open temporary file \"%s\"", tempfile);
else
{
while( fgets(buf, sizeof(buf), fp) )
{
string_chomp(buf);
log("[%d] %s", pid, string_printable(buf));
}
file_close(fp);
}
}
if( WIFEXITED(status) )
{
eopt->retc = WEXITSTATUS(status);
log("process %d exit with code %d (%d seconds)",
(int)pid, eopt->retc, eopt->runtime);
}
else if( WIFSIGNALED(status) )
{
eopt->retc = -1;
log("process %d terminated on signal %d (%d seconds)",
(int)pid, WTERMSIG(status), eopt->runtime);
}
else
{
eopt->retc = -1;
log("process %d return with unknown status (%d seconds)",
(int)pid, eopt->runtime);
}
}
else
{
eopt->retc = -1;
logerr("waitpid return error for PID %d", (int)pid);
}
}
if( tempfile )
{
if( unlink(tempfile) == -1 && errno != ENOENT )
logerr("cannot unlink temporary file \"%s\"", tempfile);
free(tempfile);
}
/* Restore the original SIGCHLD handler */
sigaction(SIGCHLD, &old_chld, NULL);
/* Unblock SIGCHLD */
sigprocmask(SIG_UNBLOCK, &new_mask, NULL);
return eopt->retc;
}
/*
* Return -1 if error occured while excuting command, other values
* are return codes of your command
*/
int xsystem(const char *command, const char *p_input, const char *p_output)
{
pid_t pid;
int status;
ASSERT(command != NULL);
DEB((D_INFO, "xsystem: command \"%s\", input \"%s\", output \"%s\"",
command, p_input, p_output));
switch(pid=fork()) {
case -1:
return(-1);
case 0:
if( p_input )
{
close(0);
if( open(p_input, O_RDONLY) != 0 )
{
logerr("can't open stdin \"%s\"", p_input);
exit(-1);
}
}
if( p_output )
{
close(1);
if( open(p_output, O_WRONLY|O_APPEND|O_CREAT, 0600) != 1 )
{
logerr("can't open stdout \"%s\"", p_output);
exit(-1);
}
}
if( p_output )
{
close(2);
if( open(p_output, O_WRONLY|O_APPEND|O_CREAT, 0600) != 2 )
{
logerr("can't open stderr \"%s\"", p_output);
exit(-1);
}
}
#ifdef SHELL
execl(SHELL, "sh", "-c", command, NULL);
#else
execl("/bin/sh", "sh", "-c", command, NULL);
#endif
exit( (errno == 0)?0:-1 );
}
if( waitpid(pid, &status, 0) == pid && WIFEXITED(status) )
{
return(WEXITSTATUS(status));
}
return(-1);
}
#ifndef HAVE_RENAME
int rename(const char *old_name, const char *new_name)
{
int rc;
ASSERT(old_name != NULL && new_name != NULL);
if( (rc = link(old_name, new_name)) == 0 )
{
if( (rc = unlink(old_name)) == -1 )
{ logerr("can't unlink file \"%s\"", old_name); }
return 0;
}
else
{
return -1;
}
}
#endif
/* ------------------------------------------------------------------------- */
/* Get free space on device mounted at path $path */
/* ------------------------------------------------------------------------- */
#if defined(HAVE_STATFS) || defined(HAVE_STATVFS)
size_t getfreespace(const char *path)
{
#ifdef HAVE_STATVFS
struct statvfs sfs;
#else
struct statfs sfs;
#endif
ASSERT(path != NULL);
#ifdef HAVE_STATVFS
if( statvfs(path, &sfs) == 0 )
#else
if( statfs(path, &sfs) == 0 )
#endif
{
return(sfs.f_bsize * sfs.f_bavail);
}
else
{
logerr("can't statfs \"%s\", assume enough space", path);
return(~0L);
}
}
#else
size_t getfreespace(const char *path)
{
ASSERT(path != NULL);
log("warning: fake getfreespace - assume enough space");
return(~0L);
}
#endif
#ifndef HAVE_SETPROCTITLE
/*
* clobber argv so ps will show what we're doing.
* (stolen from BSD ftpd where it was stolen from sendmail)
* warning, since this is usually started from inetd.conf, it
* often doesn't have much of an environment or arglist to overwrite.
*/
static char *cmdstr = NULL;
static char *cmdstrend = NULL;
void setargspace(char *argv[], char *envp[])
{
cmdstr = argv[0];
while( *envp ) envp++;
envp--;
cmdstrend = (*envp) + strlen(*envp);
}
void setproctitle(const char *fmt, ...)
{
va_list args;
char buf[256]; /* I hope it will be large enough */
char *d = cmdstr;
char *s = buf;
va_start(args, fmt);
vsprintf(buf, fmt, args);
va_end(args);
/* Make ps print our process name */
while( d < cmdstrend && *s ) { *d = *s; d++; s++; }
while( d < cmdstrend ) *d++ = ' ';
}
#endif /* HAVE_SETPROCTITLE */
+15
View File
@@ -0,0 +1,15 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
+424
View File
@@ -0,0 +1,424 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "outbound.h"
typedef struct bsylist {
s_faddr addr;
char *name_4d;
char *name_domain;
char *name_amiga;
struct bsylist *next;
#ifdef BFORCE_USE_CSY
bool is_csy;
#endif
} s_bsylist;
s_bsylist *bsylist = NULL;
static int out_bsy_convert_csy_to_bsy(s_bsylist *ptrl);
/* ========================================================================= */
/* PRIVATE part */
/* ========================================================================= */
static int out_bsy_file_check(const char *name, const char *ext)
{
char lockname[BFORCE_MAX_PATH+1];
ASSERT(name != NULL && ext != NULL);
strnxcpy(lockname, name, sizeof(lockname));
strnxcat(lockname, ext, sizeof(lockname));
return plock_check(lockname);
}
static int out_bsy_file_create(const char *name, const char *ext)
{
char lockname[BFORCE_MAX_PATH+1];
ASSERT(name != NULL && ext != NULL);
strnxcpy(lockname, name, sizeof(lockname));
strnxcat(lockname, ext, sizeof(lockname));
return plock_create(lockname);
}
static int out_bsy_file_link(const char *oldname, const char *oldext,
const char *newname, const char *newext)
{
char old_lockname[BFORCE_MAX_PATH+1];
char new_lockname[BFORCE_MAX_PATH+1];
ASSERT(oldname != NULL && oldext != NULL);
ASSERT(newname != NULL && newext != NULL);
strnxcpy(old_lockname, oldname, sizeof(old_lockname));
strnxcat(old_lockname, oldext, sizeof(old_lockname));
strnxcpy(new_lockname, newname, sizeof(new_lockname));
strnxcat(new_lockname, newext, sizeof(new_lockname));
return plock_link(new_lockname, old_lockname);
}
static int out_bsy_file_unlink(const char *name, const char *ext)
{
char lockname[BFORCE_MAX_PATH+1];
ASSERT(name != NULL && ext != NULL);
strnxcpy(lockname, name, sizeof(lockname));
strnxcat(lockname, ext, sizeof(lockname));
return plock_remove(lockname);
}
/* ========================================================================= */
/* PUBLIC part */
/* ========================================================================= */
int out_bsy_check(s_faddr addr)
{
bool isfailed = FALSE;
char *name_4d = NULL;
char *name_domain = NULL;
char *name_amiga = NULL;
name_4d = out_getname_4d(addr);
name_domain = out_getname_domain(addr);
name_amiga = out_getname_amiga(addr);
DEB((D_OUTBOUND, "out_bsy_check: name_4d = \"%s\"", name_4d));
DEB((D_OUTBOUND, "out_bsy_check: name_domain = \"%s\"", name_domain));
DEB((D_OUTBOUND, "out_bsy_check: name_amiga = \"%s\"", name_amiga));
/* Check for BSY files in all outbounds */
if( (name_4d && out_bsy_file_check(name_4d, ".bsy") == PLOCK_EXIST)
|| (name_domain && out_bsy_file_check(name_domain, ".bsy") == PLOCK_EXIST)
|| (name_amiga && out_bsy_file_check(name_amiga, ".bsy") == PLOCK_EXIST) )
isfailed = TRUE;
#ifdef BFORCE_USE_CSY
if( !isfailed )
{
/* Check for CSY files in all outbounds */
if( (name_4d && out_bsy_file_check(name_4d, ".csy") == PLOCK_EXIST)
|| (name_domain && out_bsy_file_check(name_domain, ".csy") == PLOCK_EXIST)
|| (name_amiga && out_bsy_file_check(name_amiga, ".csy") == PLOCK_EXIST) )
isfailed = TRUE;
}
#endif
if( name_4d )
free(name_4d);
if( name_domain )
free(name_domain);
if( name_amiga )
free(name_amiga);
return isfailed ? -1 : 0;
}
#ifdef BFORCE_USE_CSY
int out_bsy_lock(s_faddr addr, bool csy_locks)
#else
int out_bsy_lock(s_faddr addr)
#endif
{
char *name_4d = NULL;
char *name_domain = NULL;
char *name_amiga = NULL;
bool locked_4d = FALSE;
bool locked_domain = FALSE;
bool locked_amiga = FALSE;
s_bsylist bsytmp, **bsylst;
bool isfailed = FALSE;
#ifdef DEBUG
char abuf[BF_MAXADDRSTR+1];
#endif
#ifdef BFORCE_USE_CSY
const char *lockext = csy_locks ? ".csy" : ".bsy";
#else
const char *lockext = ".bsy";
#endif
DEB((D_OUTBOUND, "out_bsy_lock: lock address %s",
ftn_addrstr(abuf, addr)));
/*
* Check, may be we've allready locked this address.
*/
for( bsylst = &bsylist; *bsylst; bsylst = &(*bsylst)->next )
{
if( !ftn_addrcomp((*bsylst)->addr, addr) )
{
DEB((D_OUTBOUND, "out_bsy_lock: address is allready locked"));
#ifdef BFORCE_USE_CSY
if( (*bsylst)->is_csy && !csy_locks )
return out_bsy_convert_csy_to_bsy(*bsylst);
#else
return 0;
#endif
}
}
name_4d = out_getname_4d(addr);
name_domain = out_getname_domain(addr);
name_amiga = out_getname_amiga(addr);
DEB((D_OUTBOUND, "out_bsy_lock: name_4d = \"%s\"", name_4d));
DEB((D_OUTBOUND, "out_bsy_lock: name_domain = \"%s\"", name_domain));
DEB((D_OUTBOUND, "out_bsy_lock: name_amiga = \"%s\"", name_amiga));
/* Check for BSY files in all outbounds */
if( (name_4d && out_bsy_file_check(name_4d, ".bsy") == PLOCK_EXIST)
|| (name_domain && out_bsy_file_check(name_domain, ".bsy") == PLOCK_EXIST)
|| (name_amiga && out_bsy_file_check(name_amiga, ".bsy") == PLOCK_EXIST) )
isfailed = TRUE;
#ifdef BFORCE_USE_CSY
if( !isfailed )
{
/* Check for CSY files in all outbounds */
if( (name_4d && out_bsy_file_check(name_4d, ".csy") == PLOCK_EXIST)
|| (name_domain && out_bsy_file_check(name_domain, ".csy") == PLOCK_EXIST)
|| (name_amiga && out_bsy_file_check(name_amiga, ".csy") == PLOCK_EXIST) )
isfailed = TRUE;
}
#endif
DEB((D_OUTBOUND, "out_bsy_lock: lock check result: %s",
isfailed ? "Locked" : "Not locked"));
/* Create ?SY file in 4D outbound */
if( !isfailed && name_4d )
{
switch( out_bsy_file_create(name_4d, lockext) ) {
case PLOCK_OK: locked_4d = TRUE; break;
case PLOCK_EXIST: isfailed = TRUE; break;
case PLOCK_ERROR: locked_4d = FALSE; break;
}
}
/* Create ?SY file in domain outbound */
if( !isfailed && name_domain )
{
switch( out_bsy_file_create(name_domain, lockext) ) {
case PLOCK_OK: locked_domain = TRUE; break;
case PLOCK_EXIST: isfailed = TRUE; break;
case PLOCK_ERROR: locked_domain = FALSE; break;
}
}
/* Create ?SY file in "AmigaDos" outbound */
if( !isfailed && name_amiga )
{
switch( out_bsy_file_create(name_amiga, lockext) ) {
case PLOCK_OK: locked_amiga = TRUE; break;
case PLOCK_EXIST: isfailed = TRUE; break;
case PLOCK_ERROR: locked_amiga = FALSE; break;
}
}
#ifdef BFORCE_USE_CSY
if( !isfailed )
{
/* Check for BSY files in all outbounds */
if( (name_4d && out_bsy_file_check(name_4d, ".bsy") == PLOCK_EXIST)
|| (name_domain && out_bsy_file_check(name_domain, ".bsy") == PLOCK_EXIST)
|| (name_amiga && out_bsy_file_check(name_amiga, ".bsy") == PLOCK_EXIST) )
isfailed = TRUE;
}
#endif
DEB((D_OUTBOUND, "out_bsy_lock: lock create result: %s",
isfailed ? "Failed" : "Successful"));
/* Somebody else create BSY before us?! */
if( isfailed )
{
if( locked_4d )
out_bsy_file_unlink(name_4d, lockext);
if( locked_domain )
out_bsy_file_unlink(name_domain, lockext);
if( locked_amiga )
out_bsy_file_unlink(name_amiga, lockext);
if( name_4d )
free(name_4d);
if( name_domain )
free(name_domain);
if( name_amiga )
free(name_amiga);
return -1;
}
/*
* Successful locking. Add new entry to the ``bsylist''.
*/
memset(&bsytmp, '\0', sizeof(s_bsylist));
bsytmp.addr = addr;
#ifdef BFORCE_USE_CSY
bsytmp.is_csy = csy_locks;
#endif
if( locked_4d )
bsytmp.name_4d = name_4d;
if( locked_domain )
bsytmp.name_domain = name_domain;
if( locked_amiga )
bsytmp.name_amiga = name_amiga;
for( bsylst = &bsylist; *bsylst; bsylst = &(*bsylst)->next )
{
/* EMPTY LOOP */
}
(*bsylst) = (s_bsylist*)xmalloc(sizeof(s_bsylist));
**bsylst = bsytmp;
return 0;
}
int out_bsy_unlockall(void)
{
s_bsylist *ptrl, *next;
#ifdef DEBUG
char abuf[BFORCE_MAX_ADDRSTR+1];
#endif
for( ptrl = bsylist; ptrl; ptrl = next )
{
#ifdef BFORCE_USE_CSY
const char *lockext = ptrl->is_csy ? ".csy" : ".bsy";
#else
const char *lockext = ".bsy";
#endif
next = ptrl->next;
DEB((D_OUTBOUND, "out_bsy_unlockall: unlock address %s",
ftn_addrstr(abuf, ptrl->addr)));
if( ptrl->name_4d )
{
out_bsy_file_unlink(ptrl->name_4d, lockext);
free(ptrl->name_4d);
}
if( ptrl->name_domain )
{
out_bsy_file_unlink(ptrl->name_domain, lockext);
free(ptrl->name_domain);
}
if( ptrl->name_amiga )
{
out_bsy_file_unlink(ptrl->name_amiga, lockext);
free(ptrl->name_amiga);
}
free(ptrl);
}
bsylist = NULL;
return 0;
}
#ifdef BFORCE_USE_CSY
static int out_bsy_convert_csy_to_bsy(s_bsylist *ptrl)
{
bool locked_4d = FALSE;
bool locked_domain = FALSE;
bool locked_amiga = FALSE;
bool isfailed = FALSE;
#ifdef DEBUG
char abuf[BF_MAXADDRSTR+1];
#endif
DEB((D_OUTBOUND, "out_bsy_convert_csy_to_bsy: process address %s",
ftn_addrstr(abuf, ptrl->addr)));
if( !ptrl->is_csy )
{
DEB((D_OUTBOUND, "out_bsy_convert_csy_to_bsy: skip (no csy locks)"));
return 0;
}
#define LINK_CSY_TO_BSY(lockname) \
out_bsy_file_link(lockname, ".csy", lockname, ".bsy")
/* Create BSY file in 4D outbound */
if( !isfailed && ptrl->name_4d )
{
switch( LINK_CSY_TO_BSY(ptrl->name_4d) ) {
case PLOCK_OK: locked_4d = TRUE; break;
case PLOCK_EXIST: isfailed = TRUE; break;
case PLOCK_ERROR: locked_4d = FALSE; break;
}
}
/* Create BSY file in domain outbound */
if( !isfailed && ptrl->name_domain )
{
switch( LINK_CSY_TO_BSY(ptrl->name_domain) ) {
case PLOCK_OK: locked_domain = TRUE; break;
case PLOCK_EXIST: isfailed = TRUE; break;
case PLOCK_ERROR: locked_domain = FALSE; break;
}
}
/* Create BSY file in "AmigaDos" outbound */
if( !isfailed && ptrl->name_amiga )
{
switch( LINK_CSY_TO_BSY(ptrl->name_amiga) ) {
case PLOCK_OK: locked_amiga = TRUE; break;
case PLOCK_EXIST: isfailed = TRUE; break;
case PLOCK_ERROR: locked_amiga = FALSE; break;
}
}
DEB((D_OUTBOUND, "out_csy_to_bsy: lock create result: %s",
isfailed ? "Failed" : "Successful"));
/* Somebody else create BSY before us?! */
if( isfailed )
{
if( locked_4d )
out_bsy_file_unlink(ptrl->name_4d, ".bsy");
if( locked_domain )
out_bsy_file_unlink(ptrl->name_domain, ".bsy");
if( locked_amiga )
out_bsy_file_unlink(ptrl->name_amiga, ".bsy");
/* Leave ``.csy'' files untouched! */
return 1;
}
ptrl->is_csy = FALSE;
return 0;
}
#endif /* BFORCE_USE_CSY */
+228
View File
@@ -0,0 +1,228 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "outbound.h"
char *flo_translate(char *buffer, size_t buflen)
{
char *p;
s_cval_entry *ptrl;
ASSERT(buffer && buflen);
for( ptrl = conf_first(cf_flo_translate); ptrl;
ptrl = conf_next(ptrl) )
{
ASSERT(ptrl->d.translate.find);
if( (p = strstr(buffer, ptrl->d.translate.find)) )
{
char *new = string_translate(buffer,
ptrl->d.translate.find,
ptrl->d.translate.repl);
if( new )
{
strnxcpy(buffer, new, buflen);
free(new);
}
/*
* I don't want to test it
*/
#ifdef XXX
int find_len = strlen(ptrl->d.translate.find);
if( ptrl->d.translate.repl )
{
int repl_len = strlen(ptrl->d.translate.repl);
if( repl_len < find_len )
{
memcpy(p, ptrl->d.translate.repl, repl_len);
memmove(p+repl_len, p+find_len, strlen(p+find_len)+1);
}
else if( repl_len == find_len )
{
memcpy(p, ptrl->d.translate.repl, repl_len);
}
else /* ( repl_len > find_len ) */
{
/* TODO =) */
}
}
else
memmove(p, p+find_len, strlen(p+find_len)+1);
#endif /* XXX */
}
}
return buffer;
}
s_FLO *flo_open(const char *path, const char *mode)
{
FILE *fp;
s_FLO *FLO;
if( (fp = file_open(path, mode)) == NULL )
return NULL;
FLO = (s_FLO *)xmalloc(sizeof(s_FLO));
memset(FLO, 0, sizeof(s_FLO));
FLO->fp = fp;
return FLO;
}
int flo_next(s_FLO *FLO)
{
restart:
FLO->att_offs = ftell(FLO->fp);
if( FLO->att_offs == -1 )
return -1;
if( fgets(FLO->att_path, BFORCE_MAX_PATH, FLO->fp) == NULL )
return -1;
if( string_is_empty(FLO->att_path) || *FLO->att_path == '~' )
goto restart;
string_chomp(FLO->att_path);
switch(*FLO->att_path) {
case '@':
FLO->att_action = ACTION_NOTHING;
memmove(FLO->att_path, FLO->att_path+1, strlen(FLO->att_path+1)+1);
break;
case '^':
case '-':
FLO->att_action = ACTION_UNLINK;
memmove(FLO->att_path, FLO->att_path+1, strlen(FLO->att_path+1)+1);
break;
case '#':
FLO->att_action = ACTION_TRUNCATE;
memmove(FLO->att_path, FLO->att_path+1, strlen(FLO->att_path+1)+1);
break;
default:
FLO->att_action = ACTION_NOTHING;
}
flo_translate(FLO->att_path, BFORCE_MAX_PATH);
return 0;
}
int flo_mark_sent(s_FLO *FLO)
{
long myoffs = ftell(FLO->fp);
if( fseek(FLO->fp, (long)FLO->att_offs, SEEK_SET) == -1
|| fputc('~', FLO->fp) == EOF )
return -1;
if( myoffs >= 0 )
fseek(FLO->fp, myoffs, SEEK_SET);
return 0;
}
int flo_eof(s_FLO *FLO)
{
return feof(FLO->fp);
}
int flo_close(s_FLO *FLO)
{
int rc = file_close(FLO->fp);
free(FLO);
return rc;
}
/*
* Return "TRUE" if no more files to send left in the FLO
*/
bool out_flo_isempty(const char *path)
{
bool rc;
s_FLO *FLO;
if( (FLO = flo_open(path, "r")) == NULL )
return FALSE;
while( flo_next(FLO) == 0 )
{
if( access(FLO->att_path, F_OK) == 0 )
return FALSE;
}
rc = flo_eof(FLO) ? TRUE : FALSE;
flo_close(FLO);
return rc;
}
/*
* Mark the file name in FLO file as sent ( with '~' prefix )
*/
int out_flo_marksent(const char *fname, const char *floname)
{
int rc = -1;
s_FLO *FLO;
if( (FLO = flo_open(floname, "r+")) == NULL )
{
logerr("can't open flo file \"%s\"", floname);
return -1;
}
while( flo_next(FLO) == 0 )
{
if( strcmp(fname, FLO->att_path) == 0 )
{
if( flo_mark_sent(FLO) == -1 )
logerr("can't mark \"%s\" as sent in \"%s\"",
fname, floname);
else
rc = 0;
break;
}
}
if( rc == -1 && flo_eof(FLO) )
rc = 0;
flo_close(FLO);
return rc;
}
/*
* Unlink empty .?lo files
*/
int out_flo_unlinkempty(const s_flofile *flotab, int flonum)
{
int i;
for( i = 0; i < flonum; i++ )
{
if( out_flo_isempty(flotab[i].fname) )
{
if( unlink(flotab[i].fname) == -1 )
logerr("cannot unlink empty flo file \"%s\"",
flotab[i].fname);
}
}
return 0;
}
+255
View File
@@ -0,0 +1,255 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "outbound.h"
int out_filetype(const char *fname)
{
const char *p_nam;
const char *p_ext;
int i;
/*
* Get only file name, w/o dir part
*/
if( (p_nam = strrchr(fname, DIRSEPCHR)) )
p_nam++;
else
p_nam = fname;
/*
* Get file name extension
*/
if( (p_ext = strrchr(p_nam, '.')) == NULL )
return TYPE_UNKNOWN;
for( i = 0; outtab[i].ext; i++ )
if( strcasemask(p_ext, outtab[i].ext) == 0 )
return outtab[i].type;
for( i = 0; exttab[i].ext; i++ )
if( strcasemask(p_ext, exttab[i].ext) == 0 )
return exttab[i].type;
return TYPE_UNKNOWN;
}
/* ------------------------------------------------------------------------- */
/* Read FLO file line by line and call handler proc for each file in FLO */
/* ------------------------------------------------------------------------- */
static int out_readflo(s_filelist **fslist, const char *floname,
int flavor, bool aso, int flodsc)
{
s_FLO *FLO;
s_filelist **tmpl;
struct stat st;
int type;
DEB((D_OUTBOUND, "out_readflo: opening flo file \"%s\"", floname));
if( (FLO = flo_open(floname, "r")) == NULL )
{
logerr("can't open flo \"%s\"", floname);
return -1;
}
for( tmpl = fslist; *tmpl; tmpl = &(*tmpl)->next );
while( flo_next(FLO) == 0 )
{
if( stat(FLO->att_path, &st) == 0 )
{
type = out_filetype(FLO->att_path);
type |= TYPE_FROMFLO;
type |= aso ? TYPE_ASONAME : 0;
(*tmpl) = (s_filelist*)xmalloc(sizeof(s_filelist));
memset(*tmpl, '\0', sizeof(s_filelist));
(*tmpl)->fname = (char *)xstrcpy(FLO->att_path);
(*tmpl)->size = st.st_size;
(*tmpl)->type = type;
(*tmpl)->flavor = flavor;
(*tmpl)->action = FLO->att_action;
(*tmpl)->status = STATUS_WILLSEND;
(*tmpl)->flodsc = flodsc;
tmpl = &(*tmpl)->next;
}
else
logerr("can't stat file \"%s\" from flo \"%s\"",
FLO->att_path, floname);
}
flo_close(FLO);
return 0;
}
/*
* Add new entry to the flo files table, return it's index number
*/
static int out_addfloentry(s_fsqueue *q, const char *floname, int flavor)
{
q->flotab = (s_flofile*)xrealloc(q->flotab, sizeof(s_flofile)*(q->flonum+1));
memset(&q->flotab[q->flonum], '\0', sizeof(s_flofile));
q->flotab[q->flonum].fname = xstrcpy(floname);
q->flotab[q->flonum].flavor = flavor;
q->flonum++;
return q->flonum-1;
}
/* ------------------------------------------------------------------------- */
/* Handle each file $fi found in outbound. Usually it called by outbound */
/* scanner.. Pointer to result information will be stored at dst */
/* ------------------------------------------------------------------------- */
int out_handle_fsqueue(s_outbound_callback_data *callback)
{
s_fsqueue *queue;
int type;
int flavor;
int action;
ASSERT(callback);
ASSERT(callback->path);
ASSERT(callback->dest);
queue = (s_fsqueue*)callback->dest;
DEB((D_OUTBOUND, "out_handle_fsqueue: process file \"%s\"",
callback->path));
if( callback->type != OUTB_TYPE_FBOX )
{
int i;
const char *p_ext = strrchr(callback->path, '.');
if( !p_ext )
return -1;
for( i = 0; outtab[i].ext && strcasecmp(p_ext, outtab[i].ext); i++ );
if( !outtab[i].ext )
return -1;
type = outtab[i].type;
flavor = outtab[i].flavor;
action = outtab[i].action;
}
else
{
type = out_filetype(callback->path) | TYPE_FILEBOX;
if( callback->flavor != -1 )
flavor = callback->flavor;
else
flavor = FLAVOR_HOLD;
action = ACTION_UNLINK;
}
if( (type & TYPE_NETMAIL) == TYPE_NETMAIL
|| (type & TYPE_REQUEST) == TYPE_REQUEST
|| (type & TYPE_FILEBOX) == TYPE_FILEBOX )
{
struct stat st;
if( stat(callback->path, &st) == 0 )
{
s_filelist **tmpl;
for( tmpl = &queue->fslist; *tmpl; tmpl = &(*tmpl)->next );
(*tmpl) = (s_filelist*)xmalloc(sizeof(s_filelist));
memset(*tmpl, '\0', sizeof(s_filelist));
(*tmpl)->fname = xstrcpy(callback->path);
(*tmpl)->size = st.st_size;
(*tmpl)->type = type |
(callback->type == OUTB_TYPE_ASO ? TYPE_ASONAME : 0);
(*tmpl)->flavor = flavor;
(*tmpl)->action = action;
(*tmpl)->status = STATUS_WILLSEND;
(*tmpl)->flodsc = -1;
}
else
logerr("can't stat file \"%s\"", callback->path);
}
else if( (type & TYPE_FLOFILE) == TYPE_FLOFILE )
{
out_readflo(&queue->fslist, callback->path,
flavor, (callback->type == OUTB_TYPE_ASO),
out_addfloentry(queue, callback->path, flavor));
}
return 0;
}
void deinit_filelist(s_filelist *filelist)
{
struct filelist *ptrl, *next;
for( ptrl = filelist; ptrl; ptrl = next )
{
next = ptrl->next;
if( ptrl->fname ) free(ptrl->fname);
free(ptrl);
}
}
void deinit_fsqueue(s_fsqueue *q)
{
int i;
if( q->fslist )
deinit_filelist(q->fslist);
if( q->flotab )
{
for( i = 0; i < q->flonum; i++ )
if( q->flotab[i].fname ) free(q->flotab[i].fname);
free(q->flotab);
}
memset(q, '\0', sizeof(s_fsqueue));
}
#ifdef DEBUG
void log_filelist(const s_filelist *filelist)
{
const s_filelist *ptrl;
DEB((D_OUTBOUND, "log_filelist: BEGIN"));
for( ptrl = filelist; ptrl; ptrl = ptrl->next )
{
DEB((D_OUTBOUND, "log_filelist: \tfile \"%s\", %ld byte(s), flodsc = %d, status: \"%s\"",
ptrl->fname, (long)ptrl->size, ptrl->flodsc,
ptrl->status == STATUS_WILLSEND ? "WILLSEND" :
ptrl->status == STATUS_SKIP ? "SKIP" :
ptrl->status == STATUS_SKIP ? "SENDING" :
ptrl->status == STATUS_SENT ? "SENT" : "?"));
}
DEB((D_OUTBOUND, "log_filelist: END"));
}
void log_fsqueue(const s_fsqueue *q)
{
int i;
DEB((D_OUTBOUND, "log_queue_long: BEGIN"));
log_filelist(q->fslist);
for( i = 0; i < q->flonum; i++ )
DEB((D_OUTBOUND, "log_queue_long: FLO file \"%s\"", q->flotab[i].fname));
DEB((D_OUTBOUND, "log_queue_long: END"));
}
#endif
+111
View File
@@ -0,0 +1,111 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "outbound.h"
char *out_getname_4d(s_faddr addr)
{
s_cval_entry *cfptr = NULL;
char *p_outbound = NULL;
char *out_root = NULL;
char *out_main = NULL;
char *dest = NULL;
char buf[128];
s_faddr mainaddr;
p_outbound = conf_string(cf_outbound_directory);
if( (cfptr = conf_first(cf_address)) )
mainaddr = cfptr->d.falist.addr;
else
memset(&mainaddr, '\0', sizeof(s_faddr));
if( p_outbound && *p_outbound && cfptr
&& out_get_root(p_outbound, &out_root, &out_main) == 0
&& out_root && *out_root && out_main && *out_main )
{
if( addr.zone == mainaddr.zone )
{
/* It is our primary outbound */
if( addr.point == 0 )
sprintf(buf, "%04x%04x", addr.net, addr.node);
else
sprintf(buf, "%04x%04x.pnt/%08x", addr.net, addr.node, addr.point);
dest = string_concat(p_outbound, buf, NULL);
}
else
{
if( addr.point == 0 )
sprintf(buf, ".%03x/%04x%04x", addr.zone, addr.net, addr.node);
else
sprintf(buf, ".%03x/%04x%04x.pnt/%08x", addr.zone, addr.net, addr.node, addr.point);
dest = string_concat(out_root, out_main, buf, NULL);
}
}
if( out_root ) free(out_root);
if( out_main ) free(out_main);
return(dest);
}
char *out_getname_domain(s_faddr addr)
{
s_cval_entry *cfptr;
char buf[128];
char *dest = NULL;
/* find corresponding domain outbound.. */
for( cfptr = conf_first(cf_domain); cfptr;
cfptr = conf_next(cfptr) )
{
if( cfptr->d.domain.zone == addr.zone )
{
/* first of all get file name */
if( addr.point == 0 )
sprintf(buf, "%04x%04x", addr.net, addr.node);
else
sprintf(buf, "%04x%04x.pnt/%08x", addr.net, addr.node, addr.point);
dest = string_concat(cfptr->d.domain.path, buf, NULL);
break;
}
}
return dest;
}
char *out_getname_amiga(s_faddr addr)
{
char buf[128];
char *p_amigaoutbound = NULL;
char *dest = NULL;
p_amigaoutbound = conf_string(cf_amiga_outbound_directory);
if( p_amigaoutbound && *p_amigaoutbound )
{
sprintf(buf, "%d.%d.%d.%d", addr.zone, addr.net, addr.node, addr.point);
dest = string_concat(p_amigaoutbound, buf, NULL);
}
return dest;
}
/* end */
+522
View File
@@ -0,0 +1,522 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "outbound.h"
s_exttab outtab[] =
{
{ ".iut", TYPE_NETMAIL, FLAVOR_IMMED, ACTION_UNLINK },
{ ".cut", TYPE_NETMAIL, FLAVOR_CRASH, ACTION_UNLINK },
{ ".dut", TYPE_NETMAIL, FLAVOR_DIRECT, ACTION_UNLINK },
{ ".out", TYPE_NETMAIL, FLAVOR_NORMAL, ACTION_UNLINK },
{ ".hut", TYPE_NETMAIL, FLAVOR_HOLD, ACTION_UNLINK },
{ ".ikt", TYPE_NETMAIL, FLAVOR_IMMED, ACTION_UNLINK },
{ ".ckt", TYPE_NETMAIL, FLAVOR_CRASH, ACTION_UNLINK },
{ ".dkt", TYPE_NETMAIL, FLAVOR_DIRECT, ACTION_UNLINK },
{ ".pkt", TYPE_NETMAIL, FLAVOR_NORMAL, ACTION_UNLINK },
{ ".hkt", TYPE_NETMAIL, FLAVOR_HOLD, ACTION_UNLINK },
{ ".ilo", TYPE_FLOFILE, FLAVOR_IMMED, ACTION_NOTHING },
{ ".clo", TYPE_FLOFILE, FLAVOR_CRASH, ACTION_NOTHING },
{ ".dlo", TYPE_FLOFILE, FLAVOR_DIRECT, ACTION_NOTHING },
{ ".flo", TYPE_FLOFILE, FLAVOR_NORMAL, ACTION_NOTHING },
{ ".hlo", TYPE_FLOFILE, FLAVOR_HOLD, ACTION_NOTHING },
{ ".req", TYPE_REQUEST, FLAVOR_NONE, ACTION_NOTHING },
{ NULL, 0, 0, 0 }
};
s_exttab exttab[] =
{
{ ".tic", TYPE_TICFILE, FLAVOR_NORMAL, ACTION_TRUNCATE },
{ ".su?", TYPE_ARCMAIL, FLAVOR_NORMAL, ACTION_TRUNCATE },
{ ".mo?", TYPE_ARCMAIL, FLAVOR_NORMAL, ACTION_TRUNCATE },
{ ".tu?", TYPE_ARCMAIL, FLAVOR_NORMAL, ACTION_TRUNCATE },
{ ".we?", TYPE_ARCMAIL, FLAVOR_NORMAL, ACTION_TRUNCATE },
{ ".th?", TYPE_ARCMAIL, FLAVOR_NORMAL, ACTION_TRUNCATE },
{ ".fr?", TYPE_ARCMAIL, FLAVOR_NORMAL, ACTION_TRUNCATE },
{ ".sa?", TYPE_ARCMAIL, FLAVOR_NORMAL, ACTION_TRUNCATE },
{ NULL, 0, 0, 0 }
};
/*****************************************************************************
* Devide full outbound path on "root" directory, there other oubound
* directories created, and main outbound directory name
*
* Arguments:
* path pointer to the null-terminated outbound path string
* out_root pointer to the pointer for the resulting root directory
* out_main pointer to the pointer for the resulting main outbound
* name w/o path
*
* Return value:
* Zero on success (*out_root and *out_main must be freed)
*/
int out_get_root(const char *path, char **out_root, char **out_main)
{
char *p, *outb;
ASSERT(path != NULL && out_root != NULL && out_main != NULL);
*out_root = NULL;
*out_main = NULL;
outb = (char *)xstrcpy(path);
p = outb + strlen(outb) - 1;
if( *p == DIRSEPCHR )
*p = '\0';
/* Ohh.. where is no full path for outbound directory */
if( (p=strrchr(outb, DIRSEPCHR)) == NULL )
{
free(outb);
return -1;
}
*p = '\0';
*out_main = xstrcpy(p+1);
*out_root = xstrcat(outb, "/");
DEB((D_OUTBOUND, "out_getroot: out_root \"%s\", out_main \"%s\"",
*out_root, *out_main));
return 0;
}
/*****************************************************************************
* Scan Binkley Style Outbound directory, for each file for requested
* addresses call callback function
*
* Arguments:
* callback pointer to the callback information structure
* fa_list pointer to the requested addresses list
* addr current address (most time it is partially filled)
* path path for the outbound to scan
* point point number for the current outbound
*
* Return value:
* Zero on success
*/
static int out_scan_bso_dir(s_outbound_callback_data *callback,
const s_falist *fa_list, s_faddr *addr, const char *path, int point)
{
DIR *dir;
struct dirent *dirent;
char *p;
const s_falist *alst;
ASSERT(callback);
ASSERT(callback->dest);
ASSERT(addr && path);
DEB((D_OUTBOUND, "out_scan_bso_dir: BSO: scan dir \"%s\"", path));
if( (dir=opendir(path)) == NULL )
{
logerr("can't open outbound directory \"%s\"", path);
return(1);
}
while( (dirent=readdir(dir)) != NULL )
{
if( strlen(dirent->d_name) == 12 &&
strspn(dirent->d_name, "0123456789abcdefABCDEF") == 8 )
{
if((strncasecmp(dirent->d_name+8, ".PNT", 4) != 0) &&
( strncasecmp(dirent->d_name+8, ".REQ", 4) != 0) &&
( strncasecmp(dirent->d_name+10, "UT", 2) != 0) &&
( strncasecmp(dirent->d_name+10, "LO", 2) != 0) ) continue;
if( point == 0 && strncasecmp(dirent->d_name+8, ".PNT", 4) == 0 )
{
DEB((D_OUTBOUND, "scan_dir: BSO: found point directory \"%s\"",
dirent->d_name));
/*
* Congratulation, we found point's direcory
*/
sscanf(dirent->d_name, "%04x%04x", &addr->net, &addr->node);
for( alst = fa_list; alst; alst = alst->next )
if( addr->net == alst->addr.net
&& addr->node == alst->addr.node )
break;
if( alst || !fa_list )
{
p = string_concat(path, dirent->d_name, "/", NULL);
out_scan_bso_dir(callback, fa_list, addr, p, 1);
if( p ) { free(p); p = NULL; }
}
}
else
{
if( point )
{
sscanf(dirent->d_name, "%08x", &addr->point);
}
else
{
addr->point = 0;
sscanf(dirent->d_name, "%04x%04x", &addr->net, &addr->node);
}
/* Check, does we really need in this file? */
for( alst = fa_list; alst && ftn_addrcomp(*addr, alst->addr);
alst = alst->next );
if( alst || !fa_list )
{
callback->path = string_concat(path, dirent->d_name, NULL);
callback->addr = *addr;
callback->type = OUTB_TYPE_BSO;
callback->flavor = -1;
callback->callback(callback);
if( callback->path )
free(callback->path);
}
}
}
}
closedir(dir);
return(0);
}
static int out_scan_bso(s_outbound_callback_data *callback,
const s_falist *mailfor, const char *path)
{
DIR *dir;
struct dirent *dirent;
const s_falist *alst;
s_faddr addr;
char *newpath;
char *out_root = NULL; /* Root for outbound directories tree */
char *out_main = NULL; /* Main outbound directory name */
int len;
ASSERT(path);
if( out_get_root(path, &out_root, &out_main) )
return -1;
ASSERT(out_root && out_main);
if( (dir = opendir(out_root)) == NULL )
{
logerr("can't open outbound directory \"%s\"", out_root);
free(out_root); free(out_main);
return -1;
}
/* Scan outbound (only 4D) */
while( (dirent = readdir(dir)) )
{
memset(&addr, '\0', sizeof(s_faddr));
if( strcmp(dirent->d_name, out_main) == 0 )
{
/* Our main outbound */
s_cval_entry *cfptr = conf_first(cf_address);
if( cfptr )
addr.zone = cfptr->d.falist.addr.zone;
else
addr.zone = 666;
}
else if( strncmp(dirent->d_name, out_main, len=strlen(out_main)) == 0
&& dirent->d_name[len] == '.'
&& strspn(dirent->d_name+len+1,"0123456789abcdefABCDEF") == 3 )
{
/* Ooutbound with zone ext. (like /outbound.308/) */
sscanf(dirent->d_name+len+1, "%03x", &addr.zone);
}
if( addr.zone )
{
for( alst = mailfor;
alst && addr.zone != alst->addr.zone;
alst = alst->next );
if( alst || mailfor == NULL )
{
newpath = string_concat(out_root, dirent->d_name, "/", NULL);
out_scan_bso_dir(callback, mailfor, &addr, newpath, 0);
free(newpath);
}
}
}
closedir(dir);
free(out_root);
free(out_main);
return 0;
}
static int out_parse_name_lbox(s_faddr *addr, const char *filename)
{
s_faddr tmp;
ASSERT(addr && filename);
memset(&tmp, '\0', sizeof(s_faddr));
if( sscanf(filename, "%d.%d.%d.%d",
&tmp.zone, &tmp.net, &tmp.node, &tmp.point) == 4 )
{
*addr = tmp;
return 0;
}
return -1;
}
static int out_scan_fbox_dir(s_outbound_callback_data *callback,
const char *path, s_faddr addr, int flavor)
{
DIR *dir;
struct dirent *dirent;
if( (dir = opendir(path)) == NULL )
{
logerr("can't open filebox directory \"%s\"", path);
return -1;
}
while( (dirent = readdir(dir)) )
{
callback->path = string_concat(path, dirent->d_name, NULL);
if( is_regfile(callback->path) )
{
callback->addr = addr;
callback->type = OUTB_TYPE_FBOX;
callback->flavor = flavor;
callback->callback(callback);
}
free(callback->path);
callback->path = NULL;
}
closedir(dir);
return 0;
}
static int out_scan_lbox(s_outbound_callback_data *callback,
const s_falist *mailfor, const char *path)
{
DIR *dir;
struct dirent *dirent;
const s_falist *alst;
s_faddr addr;
char *newpath;
if( (dir = opendir(path)) == NULL )
{
logerr("can't open filebox directory \"%s\"", path);
return -1;
}
while( (dirent = readdir(dir)) )
{
if( out_parse_name_lbox(&addr, dirent->d_name) == 0 )
{
if( mailfor )
{
/* Scan only this fileboxes */
for( alst = mailfor;
alst && ftn_addrcomp(addr, alst->addr);
alst = alst->next );
if( alst )
{
newpath = string_concat(path, dirent->d_name, "/", NULL);
(void)out_scan_fbox_dir(callback, newpath, addr, FLAVOR_HOLD);
free(newpath);
}
}
else
{
/* Scan all fileboxes */
newpath = string_concat(path, dirent->d_name, "/", NULL);
(void)out_scan_fbox_dir(callback, newpath, addr, FLAVOR_HOLD);
free(newpath);
}
}
}
closedir(dir);
return 0;
}
/*****************************************************************************
* Parse file name from AmigaDos Style Outbound
*
* Arguments:
* name pointer to the null-terminated file name
* addr pointer to the memory where to store resulting address
*
* Return value:
* Zero on success
*/
int out_parse_name_aso(s_faddr *addr, const char *filename)
{
s_faddr tmp;
ASSERT(addr && filename);
memset(&tmp, '\0', sizeof(s_faddr));
if( sscanf(filename, "%d.%d.%d.%d.%*s", &tmp.zone,
&tmp.net, &tmp.node, &tmp.point) == 4 )
{
*addr = tmp;
return 0;
}
return -1;
}
static int out_scan_aso(s_outbound_callback_data *callback,
const s_falist *mailfor, const char *path)
{
DIR *dir;
struct dirent *dirent;
const s_falist *alst;
s_faddr addr = { FALSE, 0, 0, 0, 0, "" };
#ifdef DEBUG
char abuf[BF_MAXADDRSTR+1];
#endif
ASSERT(callback);
ASSERT(callback->dest);
ASSERT(path);
DEB((D_OUTBOUND, "out_scandir_aso: scan dir \"%s\"", path));
if( (dir = opendir(path)) == NULL )
{
logerr("can't open outbound directory \"%s\"", path);
return -1;
}
while( (dirent = readdir(dir)) )
{
memset(&addr, '\0', sizeof(s_faddr));
if( out_parse_name_aso(&addr, dirent->d_name) == 0 )
{
DEB((D_OUTBOUND, "out_scandir_aso: file \"%s\" for address %s",
dirent->d_name, ftn_addrstr(abuf, addr)));
for( alst = mailfor; alst && ftn_addrcomp(addr, alst->addr);
alst = alst->next );
if( alst || !mailfor )
{
callback->path = string_concat(path, dirent->d_name, NULL);
callback->addr = addr;
callback->type = OUTB_TYPE_ASO;
callback->flavor = -1;
callback->callback(callback);
if( callback->path )
free(callback->path);
}
}
}
closedir(dir);
return 0;
}
/* ------------------------------------------------------------------------- */
/* Scan outbound for addresses fa_list, use handler proc */
/* ------------------------------------------------------------------------- */
int out_scan(s_outbound_callback_data *callback, const s_falist *fa_list)
{
const s_falist *alst;
s_faddr addr = { FALSE, 0, 0, 0, 0, "" };
s_cval_entry *cfptr;
char *path;
ASSERT(callback);
ASSERT(callback->callback);
ASSERT(callback->dest);
/*
* 1st - try out 4D outbound
*/
path = conf_string(cf_outbound_directory);
if( path && *path )
(void)out_scan_bso(callback, fa_list, path);
/*
* 2th - Scan domain outbounds
*/
for( cfptr = conf_first(cf_domain); cfptr; cfptr = conf_next(cfptr) )
{
memset(&addr, '\0', sizeof(s_faddr));
for( alst = fa_list; alst; alst = alst->next )
{
if( cfptr->d.domain.zone == alst->addr.zone
|| alst->addr.zone == -1 )
{
addr.zone = cfptr->d.domain.zone;
out_scan_bso_dir(callback, fa_list, &addr,
cfptr->d.domain.path, 0);
break;
}
}
}
/*
* 3th - Scan AmigaDOS outbound
*/
path = conf_string(cf_amiga_outbound_directory);
if( path && *path )
(void)out_scan_aso(callback, fa_list, path);
/*
* 4th - Scan personal fileboxes
*/
if( fa_list )
{
/* Scan only listed fileboxes */
for( cfptr = conf_first(cf_filebox); cfptr; cfptr = conf_next(cfptr) )
{
for( alst = fa_list; alst; alst = alst->next )
{
if( !ftn_addrcomp(alst->addr, cfptr->d.filebox.addr) )
out_scan_fbox_dir(callback, cfptr->d.filebox.path,
cfptr->d.filebox.addr, cfptr->d.filebox.flavor);
}
}
}
else
{
/* Scan all fileboxes */
for( cfptr = conf_first(cf_filebox); cfptr; cfptr = conf_next(cfptr) )
out_scan_fbox_dir(callback, cfptr->d.filebox.path,
cfptr->d.filebox.addr, cfptr->d.filebox.flavor);
}
/*
* 5th - Scan "long" fileboxes
*/
path = conf_string(cf_filebox_directory);
if( path && *path )
(void)out_scan_lbox(callback, fa_list, path);
return(0);
}
+302
View File
@@ -0,0 +1,302 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "outbound.h"
/*
* Will call this function than add new entry to the queue
*/
int (*sysqueue_add_callback)(s_sysentry *) = NULL;
/*
* Will call this function than remove entry from the queue
*/
int (*sysqueue_rem_callback)(s_sysentry *) = NULL;
/*
* Set this to disable mail/files size count
*/
bool sysqueue_dont_count_sizes = FALSE;
/*
* Return TRUE if 'chk' entry must be before 'max' in the queue
*/
static bool out_sysqueue_sort_comp(s_sysentry *max, s_sysentry *chk, int opts)
{
if( opts & QUEUE_SORT_ADDRESS )
{
if( opts & QUEUE_SORT_REVERSE )
return !ftn_addrcomp_logic(max->node.addr, ADDR_LT, chk->node.addr);
else
return !ftn_addrcomp_logic(max->node.addr, ADDR_GT, chk->node.addr);
}
else if( opts & QUEUE_SORT_SIZE )
{
size_t size_max = max->netmail_size + max->arcmail_size
+ max->request_size + max->files_size;
size_t size_chk = chk->netmail_size + chk->arcmail_size
+ chk->request_size + chk->files_size;
if( opts & QUEUE_SORT_REVERSE )
return size_max > size_chk;
else
return size_max < size_chk;
}
return FALSE;
}
void out_sysqueue_sort(s_sysqueue *q, int opts)
{
int i, j, max;
s_sysentry tmp;
if( q->sysnum < 2 ) return;
for( i = 0; i < q->sysnum - 1; i++ )
{
for( max = i, j = i + 1; j < q->sysnum; j++ )
if( out_sysqueue_sort_comp(&q->systab[max], &q->systab[j], opts) )
max = j;
if( max > i )
{
tmp = q->systab[max];
q->systab[max] = q->systab[i];
q->systab[i] = tmp;
}
}
}
void out_reset_sysqueue(s_sysqueue *q)
{
int i;
for( i = 0; i < q->sysnum; i++ )
{
q->systab[i].netmail_size = 0;
q->systab[i].request_size = 0;
q->systab[i].arcmail_size = 0;
q->systab[i].files_size = 0;
q->systab[i].flavors = 0;
q->systab[i].types = 0;
}
}
void out_remove_from_sysqueue(s_sysqueue *q, int pos)
{
ASSERT(q && pos >= 0 && pos < q->sysnum);
if( sysqueue_rem_callback )
(void)sysqueue_rem_callback(&q->systab[pos]);
if( q->sysnum > 1 )
{
memmove(&q->systab[pos], &q->systab[pos + 1],
sizeof(s_sysentry)*(q->sysnum - pos - 1));
q->systab = xrealloc(q->systab,
sizeof(s_sysentry)*(q->sysnum - 1));
--q->sysnum;
}
else
{
free(q->systab);
q->systab = NULL;
q->sysnum = 0;
}
}
/*
* Return pointer to entry in systems list for address addr
*/
static s_sysentry *out_getsysentry(s_sysqueue *q, s_faddr addr)
{
int i;
for( i = 0; i < q->sysnum; i++ )
if( ftn_addrcomp(q->systab[i].node.addr, addr) == 0 )
return &q->systab[i];
/* Add new entry for new address */
q->systab = (s_sysentry*)xrealloc(q->systab, sizeof(s_sysentry)*(q->sysnum+1));
memset(&q->systab[q->sysnum], '\0', sizeof(s_sysentry));
q->systab[q->sysnum].node.addr = addr;
if( sysqueue_add_callback )
(void)sysqueue_add_callback(&q->systab[i]);
return &q->systab[q->sysnum++];
}
/* ------------------------------------------------------------------------- */
/* Handle each file $fi found in outbound. Usually it called by outbound */
/* scanner.. Pointer to result information will be stored at dst */
/* ------------------------------------------------------------------------- */
int out_handle_sysqueue(s_outbound_callback_data *callback)
{
s_sysentry *sentry;
int type;
int flavor;
ASSERT(callback);
ASSERT(callback->path);
ASSERT(callback->dest);
DEB((D_OUTBOUND, "out_handle_sysqueue: process file \"%s\"",
callback->path));
if( callback->type != OUTB_TYPE_FBOX )
{
int i;
const char *p_ext = strrchr(callback->path, '.');
if( !p_ext )
return -1;
for( i = 0; outtab[i].ext && strcasecmp(p_ext, outtab[i].ext); i++ );
if( !outtab[i].ext )
return -1;
type = outtab[i].type;
flavor = outtab[i].flavor;
}
else
{
type = TYPE_FILEBOX;
if( callback->flavor != -1 )
flavor = callback->flavor;
else
flavor = FLAVOR_HOLD;
}
/* Try to found existing entry for this address */
if( (sentry = out_getsysentry((s_sysqueue*)callback->dest,
callback->addr)) == NULL )
return -1;
if( type == TYPE_NETMAIL || type == TYPE_REQUEST || type == TYPE_FILEBOX )
{
struct stat st;
sentry->flavors |= flavor;
sentry->types |= type;
if( !sysqueue_dont_count_sizes )
{
if( stat(callback->path, &st) == 0 )
{
/* Update mail age */
if( st.st_mtime > sentry->mailage )
sentry->mailage = st.st_mtime;
/* Update mail size */
if( type & TYPE_NETMAIL )
sentry->netmail_size += st.st_size;
else if( type & TYPE_ARCMAIL )
sentry->arcmail_size += st.st_size;
else if( type & TYPE_REQUEST )
sentry->request_size += st.st_size;
else
sentry->files_size += st.st_size;
}
else
logerr("can't stat file \"%s\"", callback->path);
}
}
else if( type == TYPE_FLOFILE )
{
sentry->flavors |= flavor;
if( !sysqueue_dont_count_sizes )
{
s_FLO *FLO;
if( (FLO = flo_open(callback->path, "r")) == NULL )
{
logerr("can't open flo \"%s\"", callback->path);
return -1;
}
while( flo_next(FLO) == 0 )
{
struct stat st;
if( stat(FLO->att_path, &st) == 0 )
{
/* Update mail age */
if( st.st_mtime > sentry->mailage )
sentry->mailage = st.st_mtime;
/* Update mail size */
if( out_filetype(FLO->att_path) & TYPE_ARCMAIL )
sentry->arcmail_size += st.st_size;
else
sentry->files_size += st.st_size;
}
}
flo_close(FLO);
}
}
else
log("skipping file of unknown type \"%s\"", callback->path);
return 0;
}
void deinit_sysqueue(s_sysqueue *q)
{
if( q->systab ) free(q->systab);
memset(q, '\0', sizeof(s_sysqueue));
}
#ifdef DEBUG
void log_sysqueue(const s_sysqueue *q)
{
char abuf[BF_MAXADDRSTR+1];
char tmp[256] = "";
int i;
DEB((D_OUTBOUND, "log_sysqueue: BEGIN"));
for( i = 0; i < q->sysnum; i++ )
{
DEB((D_OUTBOUND, "log_sysqueue: address %s", ftn_addrstr(abuf, q->systab[i].node.addr)));
tmp[0] = '\0';
if( q->systab[i].flavors & FLAVOR_IMMED ) strcat(tmp, "Immediate,");
if( q->systab[i].flavors & FLAVOR_CRASH ) strcat(tmp, "Crash,");
if( q->systab[i].flavors & FLAVOR_NORMAL ) strcat(tmp, "Normal,");
if( q->systab[i].flavors & FLAVOR_HOLD ) strcat(tmp, "Hold,");
if( tmp[0] ) tmp[strlen(tmp)-1] = '\0';
DEB((D_OUTBOUND, "log_sysqueue: \tflavors: \"%s\"", tmp));
tmp[0] = '\0';
if( q->systab[i].types & TYPE_NETMAIL ) strcat(tmp, "netmail,");
if( q->systab[i].types & TYPE_FLOFILE ) strcat(tmp, "flofile,");
if( q->systab[i].types & TYPE_ARCMAIL ) strcat(tmp, "arcmail,");
if( q->systab[i].types & TYPE_REQUEST ) strcat(tmp, "request,");
if( q->systab[i].types & TYPE_FILEECHO ) strcat(tmp, "fileecho,");
if( q->systab[i].types & TYPE_FILEBOX ) strcat(tmp, "filebox,");
if( q->systab[i].types & TYPE_FROMFLO ) strcat(tmp, "fromflo,");
if( tmp[0] ) tmp[strlen(tmp)-1] = '\0';
DEB((D_OUTBOUND, "log_sysqueue: \ttypes: \"%s\"", tmp));
}
DEB((D_OUTBOUND, "log_sysqueue: END"));
}
#endif
+698
View File
@@ -0,0 +1,698 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "io.h"
#include "session.h"
#include "outbound.h"
#include "prot_common.h"
#include "prot_binkp.h"
typedef enum {
BPI_SendSysInfo,
BPI_WaitADR,
BPI_WaitPWD,
BPI_Auth
} binkp_incoming_state;
typedef enum {
BPO_SendSysInfo,
BPO_WaitNUL,
BPO_SendPWD,
BPO_WaitADR,
BPO_Auth,
BPO_WaitOK
} binkp_outgoing_state;
#define GOTO(label,newrc) { rc = (newrc); goto label; }
void binkp_process_NUL(s_binkp_sysinfo *remote_data, char *buffer)
{
char *p, *q;
if( strncmp(buffer, "SYS ", 4) == 0 )
strnxcpy(remote_data->systname, buffer+4, sizeof(remote_data->systname));
else if( strncmp(buffer, "ZYZ ", 4) == 0 )
strnxcpy(remote_data->sysop, buffer+4, sizeof(remote_data->sysop));
else if( strncmp(buffer, "LOC ", 4) == 0 )
strnxcpy(remote_data->location, buffer+4, sizeof(remote_data->location));
else if( strncmp(buffer, "PHN ", 4) == 0 )
strnxcpy(remote_data->phone, buffer+4, sizeof(remote_data->phone));
else if( strncmp(buffer, "NDL ", 4) == 0 )
strnxcpy(remote_data->flags, buffer+4, sizeof(remote_data->flags));
else if( strncmp(buffer, "TIME ", 5) == 0 )
strnxcpy(remote_data->timestr, buffer+5, sizeof(remote_data->timestr));
else if( strncmp(buffer, "OPT ", 4) == 0 )
{
if( *remote_data->opt )
{
strnxcat(remote_data->opt, " ", sizeof(remote_data->opt));
strnxcat(remote_data->opt, buffer+4, sizeof(remote_data->opt));
}
else
strnxcpy(remote_data->opt, buffer+4, sizeof(remote_data->opt));
binkp_parse_options(remote_data, buffer+4);
}
else if( strncmp(buffer, "VER ", 4) == 0 )
{
/* <mailer> [<protocol>/<vermaj>.<vermin>] */
if( (p = strchr(buffer+4, ' ')) )
{
strnxcpy(remote_data->progname, buffer+4,
MIN(sizeof(remote_data->progname), p - (buffer+4) + 1));
++p;
if( (q = strchr(p, '/')) )
{
strnxcpy(remote_data->protname, p,
MIN(sizeof(remote_data->protname), q - p + 1));
sscanf(q+1, "%d.%d",
&remote_data->majorver,
&remote_data->minorver);
}
}
else
strnxcpy(remote_data->progname, buffer+4, sizeof(remote_data->progname));
}
else
log("BinkP got invalid NUL: \"%s\"", string_printable(buffer));
}
void binkp_process_ADR(s_binkp_sysinfo *remote_data, char *buffer)
{
s_faddr addr;
char *p, *q;
for( p = string_token(buffer, &q, NULL, 0); p;
p = string_token(NULL, &q, NULL, 0) )
{
if( ftn_addrparse(&addr, p, FALSE) )
log("BinkP got unparsable address \"%s\"", string_printable(p));
else
session_addrs_add(&remote_data->addrs, &remote_data->anum, addr);
}
}
int binkp_outgoing(s_binkp_sysinfo *local_data, s_binkp_sysinfo *remote_data)
{
s_bpinfo bpi;
binkp_outgoing_state binkp_state = BPO_SendSysInfo;
int rc = HRC_OK;
int recv_rc = 0;
int send_rc = 0;
bool send_ready = FALSE;
bool recv_ready = FALSE;
binkp_init_bpinfo(&bpi);
while(1)
{
switch(binkp_state) {
case BPO_SendSysInfo:
binkp_queue_sysinfo(&bpi, local_data);
binkp_state = BPO_WaitNUL;
break;
case BPO_SendPWD:
if( *local_data->passwd == '\0' )
{
binkp_queuemsg(&bpi, BPMSG_PWD, NULL, "-");
}
else if( remote_data->options & BINKP_OPT_MD5 )
{
char digest_bin[16];
char digest_hex[33];
md5_cram_get(local_data->passwd, remote_data->challenge,
remote_data->challenge_length, digest_bin);
/* Encode digest to the hex string */
string_bin_to_hex(digest_hex, digest_bin, 16);
binkp_queuemsg(&bpi, BPMSG_PWD, "CRAM-MD5-", digest_hex);
}
else
binkp_queuemsg(&bpi, BPMSG_PWD, NULL, local_data->passwd);
binkp_state = BPO_WaitADR;
break;
case BPO_Auth:
/* Set remote password same as local */
strncpy(remote_data->passwd, local_data->passwd, BINKP_MAXPASSWD);
remote_data->passwd[BINKP_MAXPASSWD] = '\0';
if( !remote_data->anum )
{
binkp_queuemsg(&bpi, BPMSG_BSY, NULL, "No addresses was presented");
GOTO(Exit, HRC_BUSY);
}
else if( session_addrs_check_genuine(remote_data->addrs, remote_data->anum,
state.node.addr) )
{
binkp_queuemsg(&bpi, BPMSG_ERR, NULL, "Sorry, you are not who I need");
GOTO(Exit, HRC_NO_ADDRESS);
}
else if( session_addrs_check(remote_data->addrs, remote_data->anum,
remote_data->passwd, NULL, 0) )
{
binkp_queuemsg(&bpi, BPMSG_ERR, NULL, "Security violation");
GOTO(Exit, HRC_BAD_PASSWD);
}
else if( session_addrs_lock(remote_data->addrs, remote_data->anum) )
{
binkp_queuemsg(&bpi, BPMSG_BSY, NULL, "All addresses are busy");
GOTO(Exit, HRC_BUSY);
}
binkp_state = BPO_WaitOK;
break;
default:
break;
}
/*
* Receive/Send next data block
*/
send_ready = recv_ready = FALSE;
if( tty_select(&recv_ready, (bpi.opos || bpi.n_msgs) ?
&send_ready : NULL, bpi.timeout) < 0 )
GOTO(Abort, HRC_OTHER_ERR);
recv_rc = BPMSG_NONE;
send_rc = 0;
if( recv_ready && (recv_rc = binkp_recv(&bpi)) == BPMSG_EXIT )
GOTO(Abort, HRC_OTHER_ERR);
if( send_ready && (send_rc = binkp_send(&bpi)) < 0 )
GOTO(Abort, HRC_OTHER_ERR);
/*
* Handle received message
*/
switch(recv_rc) {
case BPMSG_NONE:
break;
case BPMSG_NUL:
if( binkp_state == BPO_WaitNUL || binkp_state == BPO_WaitADR )
{
binkp_process_NUL(remote_data, bpi.ibuf+1);
if( binkp_state == BPO_WaitNUL )
binkp_state = BPO_SendPWD;
}
break;
case BPMSG_ADR:
if( binkp_state == BPO_WaitADR )
{
binkp_process_ADR(remote_data, bpi.ibuf+1);
binkp_state = BPO_Auth;
}
break;
case BPMSG_OK:
if( binkp_state == BPO_WaitOK )
GOTO(Exit, HRC_OK);
break;
case BPMSG_ERR:
log("BinkP error: \"%s\"", string_printable(bpi.ibuf+1));
GOTO(Abort, HRC_FATAL_ERR);
case BPMSG_BSY:
log("BinkP busy: \"%s\"", string_printable(bpi.ibuf+1));
GOTO(Abort, HRC_TEMP_ERR);
}
}
Exit:
if( binkp_flush_queue(&bpi, bpi.timeout) && rc == HRC_OK )
rc = HRC_OTHER_ERR;
Abort:
binkp_deinit_bpinfo(&bpi);
return rc;
}
int binkp_auth_incoming(s_binkp_sysinfo *remote_data)
{
if( remote_data->challenge_length > 0
&& strncmp(remote_data->passwd, "CRAM-MD5-", 9) == 0 )
{
return session_addrs_check(remote_data->addrs,
remote_data->anum,
remote_data->passwd + 9,
remote_data->challenge,
remote_data->challenge_length);
}
return session_addrs_check(remote_data->addrs, remote_data->anum,
remote_data->passwd, NULL, 0);
}
int binkp_incoming(s_binkp_sysinfo *local_data, s_binkp_sysinfo *remote_data)
{
s_bpinfo bpi;
binkp_incoming_state binkp_state = BPI_SendSysInfo;
int rc = HRC_OK;
int recv_rc = 0;
int send_rc = 0;
bool send_ready = FALSE;
bool recv_ready = FALSE;
binkp_init_bpinfo(&bpi);
while(1)
{
switch(binkp_state) {
case BPI_SendSysInfo:
binkp_queue_sysinfo(&bpi, local_data);
binkp_state = BPI_WaitADR;
break;
case BPI_Auth:
/* Set challenge string same as local */
memcpy(remote_data->challenge, local_data->challenge,
sizeof(remote_data->challenge));
remote_data->challenge_length = local_data->challenge_length;
/* Do authorization */
if( !remote_data->anum )
{
binkp_queuemsg(&bpi, BPMSG_BSY, NULL, "No addresses was presented");
GOTO(Exit, HRC_BUSY);
}
else if( binkp_auth_incoming(remote_data) )
{
binkp_queuemsg(&bpi, BPMSG_ERR, NULL, "Security violation");
GOTO(Exit, HRC_BAD_PASSWD);
}
else if( session_addrs_lock(remote_data->addrs, remote_data->anum) )
{
binkp_queuemsg(&bpi, BPMSG_BSY, NULL, "All addresses are busy");
GOTO(Exit, HRC_BUSY);
}
else
{
binkp_queuemsg(&bpi, BPMSG_OK, NULL, NULL);
GOTO(Exit, HRC_OK);
}
break;
default:
break;
}
/*
* Receive/Send next data block
*/
send_ready = recv_ready = FALSE;
if( tty_select(&recv_ready, (bpi.opos || bpi.n_msgs) ?
&send_ready : NULL, bpi.timeout) < 0 )
GOTO(Abort, HRC_OTHER_ERR);
recv_rc = BPMSG_NONE;
send_rc = 0;
if( recv_ready && (recv_rc = binkp_recv(&bpi)) == BPMSG_EXIT )
GOTO(Abort, HRC_OTHER_ERR);
if( send_ready && (send_rc = binkp_send(&bpi)) < 0 )
GOTO(Abort, HRC_OTHER_ERR);
/*
* Handle received message
*/
switch(recv_rc) {
case BPMSG_NONE:
break;
case BPMSG_NUL:
if( binkp_state == BPI_WaitADR )
binkp_process_NUL(remote_data, bpi.ibuf+1);
break;
case BPMSG_ADR:
if( binkp_state == BPI_WaitADR )
{
binkp_process_ADR(remote_data, bpi.ibuf+1);
binkp_state = BPI_WaitPWD;
}
break;
case BPMSG_PWD:
if( binkp_state == BPI_WaitPWD )
{
strnxcpy(remote_data->passwd, bpi.ibuf+1, sizeof(remote_data->passwd));
binkp_state = BPI_Auth;
}
break;
case BPMSG_ERR:
log("BinkP error: \"%s\"", string_printable(bpi.ibuf+1));
GOTO(Abort, HRC_FATAL_ERR);
case BPMSG_BSY:
log("BinkP busy: \"%s\"", string_printable(bpi.ibuf+1));
GOTO(Abort, HRC_TEMP_ERR);
}
}
Exit:
if( binkp_flush_queue(&bpi, bpi.timeout) && rc == HRC_OK )
rc = HRC_OTHER_ERR;
Abort:
binkp_deinit_bpinfo(&bpi);
return rc;
}
int binkp_transfer(s_protinfo *pi)
{
int i, n, rc = PRC_NOERROR;
bool recv_ready = FALSE;
bool send_ready = FALSE;
bool sent_EOB = FALSE;
bool rcvd_EOB = FALSE;
bool send_file = FALSE;
bool recv_file = FALSE;
bool wait_got = FALSE;
bool nofiles = FALSE;
int recv_rc = 0;
int send_rc = 0;
char *fname = NULL;
size_t fsize = 0;
time_t ftime = 0;
size_t foffs = 0;
s_bpinfo bpi;
binkp_init_bpinfo(&bpi);
while( !sent_EOB || !rcvd_EOB )
{
if( !send_file && !sent_EOB && bpi.opos == 0 && bpi.n_msgs == 0 )
{
if( !p_tx_fopen(pi) )
{
send_file = TRUE;
binkp_queuemsgf(&bpi, BPMSG_FILE, "%s %ld %ld 0",
pi->send->net_name, (long)pi->send->bytes_total,
(long)pi->send->mod_time);
}
else
/* No more files */
nofiles = TRUE;
}
if( send_file && bpi.opos == 0 && bpi.n_msgs == 0 )
{
if( (n = p_tx_readfile(bpi.obuf + BINKP_BLK_HDRSIZE,
4096, pi)) < 0 )
{
p_tx_fclose(pi);
send_file = FALSE;
}
else
{
binkp_puthdr(bpi.obuf, (unsigned)(n & 0x7fff));
bpi.opos = n + BINKP_BLK_HDRSIZE;
pi->send->bytes_sent += n;
if( pi->send->eofseen )
{
wait_got = TRUE; send_file = FALSE;
pi->send->status = FSTAT_WAITACK;
}
}
}
if( nofiles && !wait_got && !sent_EOB )
{
sent_EOB = TRUE;
binkp_queuemsg(&bpi, BPMSG_EOB, NULL, NULL);
}
recv_ready = send_ready = FALSE;
if( tty_select(&recv_ready, (bpi.opos || bpi.n_msgs) ?
&send_ready : NULL, bpi.timeout) < 0 )
gotoexit(PRC_ERROR);
recv_rc = BPMSG_NONE;
send_rc = 0;
if( recv_ready && (recv_rc = binkp_recv(&bpi)) == BPMSG_EXIT )
gotoexit(PRC_ERROR);
if( send_ready && (send_rc = binkp_send(&bpi)) < 0 )
gotoexit(PRC_ERROR);
switch(recv_rc) {
case BPMSG_NONE:
break;
case BPMSG_DATA: /* Got new data block */
if( recv_file )
{
if( (n = p_rx_writefile(bpi.ibuf, bpi.isize, pi)) < 0 )
{
/* error writing file */
if( n == -2 )
{
binkp_queuemsgf(&bpi, BPMSG_GOT, "%s %ld %ld",
pi->recv->net_name, (long)pi->recv->bytes_total,
(long)pi->recv->mod_time);
}
else
{
binkp_queuemsgf(&bpi, BPMSG_SKIP, "%s %ld %ld",
pi->recv->net_name, (long)pi->recv->bytes_total,
(long)pi->recv->mod_time);
}
recv_file = FALSE;
p_rx_fclose(pi);
}
else
{
pi->recv->bytes_received += bpi.isize;
/* Was it the last data block? */
if( pi->recv->bytes_received > pi->recv->bytes_total )
{
log("binkp got too many data (%ld, %ld expected)",
(long)pi->recv->bytes_received,
(long)pi->recv->bytes_total);
recv_file = FALSE;
pi->recv->status = FSTAT_REFUSED;
(void)p_rx_fclose(pi);
binkp_queuemsgf(&bpi, BPMSG_SKIP, "%s %ld %ld",
pi->recv->net_name, (long)pi->recv->bytes_total,
(long)pi->recv->mod_time);
}
else if( pi->recv->bytes_received == pi->recv->bytes_total )
{
recv_file = FALSE;
pi->recv->status = FSTAT_SUCCESS;
if( !p_rx_fclose(pi) )
{
binkp_queuemsgf(&bpi, BPMSG_GOT, "%s %ld %ld",
pi->recv->net_name, (long)pi->recv->bytes_total,
(long)pi->recv->mod_time);
}
else
{
binkp_queuemsgf(&bpi, BPMSG_SKIP, "%s %ld %ld",
pi->recv->net_name, (long)pi->recv->bytes_total,
(long)pi->recv->mod_time);
}
}
}
}
#ifdef DEBUG
else
DEB((D_PROT, "ignore received data block"));
#endif
break;
case BPMSG_FILE:
if( recv_file )
{ p_rx_fclose(pi); recv_file = FALSE; }
if( binkp_parsfinfo(bpi.ibuf+1, &fname,
&fsize, &ftime, &foffs) )
{
binkp_queuemsg(&bpi, BPMSG_ERR, "FILE: ", "unparsable arguments");
goto FinishSession;
}
if( pi->recv && !p_compfinfo(pi->recv, fname, fsize, ftime)
&& pi->recv->bytes_skipped == foffs )
{
recv_file = TRUE;
break;
}
switch(p_rx_fopen(pi, fname, fsize, ftime, 0)) {
case 0:
if( pi->recv->bytes_skipped == 0 )
{
recv_file = TRUE;
break;
}
binkp_queuemsgf(&bpi, BPMSG_GET, "%s %ld %ld %ld",
pi->recv->net_name, (long)pi->recv->bytes_total,
(long)pi->recv->mod_time,
(long)pi->recv->bytes_skipped);
break;
case 1:
/* SKIP (non-destructive) */
binkp_queuemsgf(&bpi, BPMSG_SKIP, "%s %ld %ld",
pi->recv->net_name, (long)pi->recv->bytes_total,
(long)pi->recv->mod_time);
break;
case 2:
/* SKIP (destructive) */
binkp_queuemsgf(&bpi, BPMSG_GOT, "%s %ld %ld",
pi->recv->net_name, (long)pi->recv->bytes_total,
(long)pi->recv->mod_time);
break;
default:
ASSERT_MSG();
}
break;
case BPMSG_EOB: /* End Of Batch */
if( recv_file )
{
p_rx_fclose(pi);
recv_file = FALSE;
}
rcvd_EOB = TRUE;
break;
case BPMSG_GOT:
case BPMSG_SKIP:
if( binkp_parsfinfo(bpi.ibuf+1, &fname, &fsize, &ftime, NULL) == 0 )
{
if( send_file && !p_compfinfo(pi->send, fname, fsize, ftime) )
{
/* We got GOT/SKIP for current file! */
if( recv_rc == BPMSG_GOT )
pi->send->status = FSTAT_SKIPPED;
else
pi->send->status = FSTAT_REFUSED;
p_tx_fclose(pi);
send_file = FALSE;
break;
}
wait_got = FALSE;
for( i = 0; i < pi->n_sentfiles; i++ )
{
if( pi->sentfiles[i].status == FSTAT_WAITACK
&& !p_compfinfo(&pi->sentfiles[i], fname, fsize, ftime) )
{
s_finfo *tmp = pi->send;
pi->send = &pi->sentfiles[i];
if( recv_rc == BPMSG_GOT )
pi->send->status = FSTAT_SUCCESS;
else
pi->send->status = FSTAT_REFUSED;
p_tx_fclose(pi);
pi->send = tmp;
break;
}
else if( pi->sentfiles[i].status == FSTAT_WAITACK )
wait_got = TRUE;
}
/*
* Check, maybe there are files still
* waiting for the GOT/SKIP acknwoledge
*/
while( i < pi->n_sentfiles && !wait_got )
{
if( pi->sentfiles[i].status == FSTAT_WAITACK )
wait_got = TRUE;
++i;
}
}
break;
case BPMSG_ERR:
log("remote report error: \"%s\"", bpi.ibuf+1);
gotoexit(PRC_ERROR);
break;
case BPMSG_BSY:
log("remote busy error: \"%s\"", bpi.ibuf+1);
gotoexit(PRC_ERROR);
break;
case BPMSG_GET:
if( binkp_parsfinfo(bpi.ibuf+1, &fname, &fsize, &ftime, &foffs) == 0 )
{
if( send_file && !p_compfinfo(pi->send, fname, fsize, ftime) )
{
if( fseek(pi->send->fp, foffs, SEEK_SET) == -1 )
{
log("cannot send file from requested offset %ld", (long)foffs);
p_tx_fclose(pi);
send_file = FALSE;
}
else
{
log("sending \"%s\" from %ld offset",
pi->send->fname, (long)foffs);
pi->send->bytes_skipped = foffs;
pi->send->bytes_sent = foffs;
binkp_queuemsgf(&bpi, BPMSG_FILE, "%s %ld %ld %ld",
pi->send->net_name, (long)pi->send->bytes_total,
(long)pi->send->mod_time, (long)foffs);
}
}
}
break;
default:
log("binkp got unhandled msg #%d", recv_rc);
break;
}
} /* end of while( !sent_EOB || !rcvd_EOB ) */
FinishSession:
if( binkp_flush_queue(&bpi, bpi.timeout) && rc == PRC_NOERROR )
rc = PRC_ERROR;
exit:
if( pi->send && pi->send->fp ) p_tx_fclose(pi);
if( pi->recv && pi->recv->fp ) p_rx_fclose(pi);
binkp_deinit_bpinfo(&bpi);
DEB((D_PROT, "binkp: BINKP exit = %d", rc));
return rc;
}
+283
View File
@@ -0,0 +1,283 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "version.h"
#include "logger.h"
#include "util.h"
#include "nodelist.h"
#include "session.h"
#include "prot_binkp.h"
void binkp_init(s_handshake_protocol *THIS);
void binkp_deinit(s_handshake_protocol *THIS);
int binkp_incoming2(s_handshake_protocol *THIS);
int binkp_outgoing2(s_handshake_protocol *THIS);
s_faddr *binkp_remote_address(s_handshake_protocol *THIS);
char *binkp_remote_password(s_handshake_protocol *THIS);
char *binkp_remote_sysop_name(s_handshake_protocol *THIS);
char *binkp_remote_system_name(s_handshake_protocol *THIS);
char *binkp_remote_location(s_handshake_protocol *THIS);
char *binkp_remote_phone(s_handshake_protocol *THIS);
char *binkp_remote_flags(s_handshake_protocol *THIS);
char *binkp_remote_mailer(s_handshake_protocol *THIS);
s_faddr *binkp_local_address(s_handshake_protocol *THIS);
char *binkp_local_password(s_handshake_protocol *THIS);
s_handshake_protocol handshake_protocol_binkp = {
/* Section 1 */
"BinkP",
"",
"",
NULL,
NULL,
0,
binkp_init,
binkp_deinit,
binkp_incoming2,
binkp_outgoing2,
/* Section 2 */
binkp_remote_address,
binkp_remote_password,
binkp_remote_sysop_name,
binkp_remote_system_name,
binkp_remote_location,
binkp_remote_phone,
binkp_remote_flags,
binkp_remote_mailer,
NULL,
/* Section 3 */
binkp_local_address,
binkp_local_password
};
void binkp_init(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data == NULL);
ASSERT(THIS->local_data == NULL);
THIS->remote_data = (char *)xmalloc(sizeof(s_binkp_sysinfo));
THIS->local_data = (char *)xmalloc(sizeof(s_binkp_sysinfo));
THIS->protocol = PROT_BINKP;
memset(THIS->remote_data, '\0', sizeof(s_binkp_sysinfo));
memset(THIS->local_data, '\0', sizeof(s_binkp_sysinfo));
}
void binkp_deinit(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
ASSERT(THIS->local_data);
if( THIS->remote_data )
{
memset(THIS->remote_data, '\0', sizeof(s_binkp_sysinfo));
free(THIS->remote_data);
}
if( THIS->local_data )
{
memset(THIS->local_data, '\0', sizeof(s_binkp_sysinfo));
free(THIS->local_data);
}
}
int binkp_incoming2(s_handshake_protocol *THIS)
{
int rc = -1;
s_binkp_sysinfo *remote_data = NULL;
s_binkp_sysinfo *local_data = NULL;
ASSERT(THIS);
ASSERT(THIS->remote_data);
ASSERT(THIS->local_data);
remote_data = (s_binkp_sysinfo *)THIS->remote_data;
local_data = (s_binkp_sysinfo *)THIS->local_data;
binkp_set_sysinfo(local_data, NULL, FALSE);
rc = binkp_incoming(local_data, remote_data);
binkp_log_sysinfo(remote_data);
if( remote_data->anum > 0 )
{
session_remote_lookup(remote_data->addrs, remote_data->anum);
session_remote_log_status();
}
if( rc == HRC_OK )
{
/*
* Create mail/files queue
*/
session_create_files_queue(remote_data->addrs,
remote_data->anum);
session_set_send_options();
session_set_inbound();
}
return rc;
}
int binkp_outgoing2(s_handshake_protocol *THIS)
{
int rc = HRC_OTHER_ERR;
s_binkp_sysinfo *remote_data = NULL;
s_binkp_sysinfo *local_data = NULL;
ASSERT(THIS);
ASSERT(THIS->remote_data);
ASSERT(THIS->local_data);
remote_data = (s_binkp_sysinfo *)THIS->remote_data;
local_data = (s_binkp_sysinfo *)THIS->local_data;
binkp_set_sysinfo(local_data, &state.node.addr, TRUE);
rc = binkp_outgoing(local_data, remote_data);
binkp_log_sysinfo(remote_data);
if( remote_data->anum > 0 )
{
session_remote_lookup(remote_data->addrs, remote_data->anum);
session_remote_log_status();
}
if( rc == HRC_OK )
{
/*
* Create mail/files queue
*/
session_create_files_queue(remote_data->addrs,
remote_data->anum);
session_set_send_options();
session_set_inbound();
}
return rc;
}
s_faddr *binkp_remote_address(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_binkp_sysinfo *)THIS->remote_data)->anum > 0 )
return &((s_binkp_sysinfo *)THIS->remote_data)->addrs[0].addr;
return NULL;
}
char *binkp_remote_password(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_binkp_sysinfo *)THIS->remote_data)->passwd[0] )
return ((s_binkp_sysinfo *)THIS->remote_data)->passwd;
return NULL;
}
char *binkp_remote_sysop_name(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_binkp_sysinfo *)THIS->remote_data)->sysop[0] )
return ((s_binkp_sysinfo *)THIS->remote_data)->sysop;
return NULL;
}
char *binkp_remote_system_name(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_binkp_sysinfo *)THIS->remote_data)->systname[0] )
return ((s_binkp_sysinfo *)THIS->remote_data)->systname;
return NULL;
}
char *binkp_remote_location(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_binkp_sysinfo *)THIS->remote_data)->location[0] )
return ((s_binkp_sysinfo *)THIS->remote_data)->location;
return NULL;
}
char *binkp_remote_phone(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_binkp_sysinfo *)THIS->remote_data)->phone[0] )
return ((s_binkp_sysinfo *)THIS->remote_data)->phone;
return NULL;
}
char *binkp_remote_flags(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_binkp_sysinfo *)THIS->remote_data)->flags[0] )
return ((s_binkp_sysinfo *)THIS->remote_data)->flags;
return NULL;
}
char *binkp_remote_mailer(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_binkp_sysinfo *)THIS->remote_data)->progname[0] )
return ((s_binkp_sysinfo *)THIS->remote_data)->progname;
return NULL;
}
s_faddr *binkp_local_address(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->local_data);
if( ((s_binkp_sysinfo *)THIS->local_data)->anum > 0 )
return &((s_binkp_sysinfo *)THIS->local_data)->addrs[0].addr;
return NULL;
}
char *binkp_local_password(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->local_data);
if( ((s_binkp_sysinfo *)THIS->local_data)->passwd[0] )
return ((s_binkp_sysinfo *)THIS->local_data)->passwd;
return NULL;
}
+740
View File
@@ -0,0 +1,740 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "io.h"
#include "session.h"
#include "outbound.h"
#include "prot_common.h"
#include "prot_binkp.h"
/*****************************************************************************
* Initialise binkp state structure, allocate memory for buffers, etc.
*
* Arguments:
* bpi pointer to the binkp state structure (s_bpinfo)
*
* Return value:
* None
*/
void binkp_init_bpinfo(s_bpinfo *bpi)
{
memset(bpi, '\0', sizeof(s_bpinfo));
bpi->obuf = (char*)xmalloc(BINKP_MAX_BLKSIZE + BINKP_BLK_HDRSIZE + 1);
bpi->opos = 0;
bpi->optr = bpi->obuf;
bpi->inew = TRUE;
bpi->isize = -1;
bpi->ibuf = (char*)xmalloc(BINKP_MAX_BLKSIZE + BINKP_BLK_HDRSIZE + 1);
bpi->timeout = conf_number(cf_binkp_timeout);
if( !bpi->timeout )
bpi->timeout = 300;
}
/*****************************************************************************
* DeInitialise binkp state structure, release allocated memory, etc.
*
* Arguments:
* bpi pointer to the binkp state structure (s_bpinfo)
*
* Return value:
* None
*/
void binkp_deinit_bpinfo(s_bpinfo *bpi)
{
if( bpi->obuf )
free(bpi->obuf);
if( bpi->ibuf )
free(bpi->ibuf);
if( bpi->msgqueue )
free(bpi->msgqueue);
memset(bpi, '\0', sizeof(s_bpinfo));
}
/*****************************************************************************
* Fills s[0] and s[1] with binkp frame header using value of u
*
* Arguments:
* s pointer to the binkp's frame header (2 bytes)
* val value to put
*
* Return value:
* None
*/
void binkp_puthdr(char *s, unsigned int val)
{
s[0] = ( (unsigned long) val >> 8 ) & 0xff;
s[1] = ( (unsigned long) val ) & 0xff;
}
/*****************************************************************************
* Fills s[0] with binkp message type value
*
* Arguments:
* s pointer to the destination buffer
* msg message type
*
* Return value:
* None
*/
void binkp_putmsgtype(char *s, e_bpmsg msg)
{
s[0] = ( (unsigned int) msg ) & 0xff;
}
/*****************************************************************************
* Extract size from binkp frame header
*
* Arguments:
* s pointer to the source buffer
*
* Return value:
* Value, extracted from binkp header
*/
int binkp_gethdr(const char *s)
{
return ( (unsigned int) (((unsigned char) s[0]) & 0x7f) << 8 )
| ( (unsigned int) (((unsigned char) s[1]) & 0xff) );
}
/*****************************************************************************
* Extract message type from s[0]
*
* Arguments:
* s pointer to the source buffer (1 byte)
*
* Return value:
* Value, extracted from binkp header, or -1 if extracted message type is
* out of range
*/
int binkp_getmsgtype(char ch)
{
int val = ( ((unsigned char)ch) & 0x7f );
if( BPMSG_MIN > val || val > BPMSG_MAX )
return -1;
else
return val;
}
/*****************************************************************************
* Puts a message to the output messages queue. These msgs will be send
* right after the current data block
*
* Arguments:
* bpi binkp state structure
* msg message type
* s1 message text
* s2 message text (will be concatenated with s1)
*
* Return value:
* None
*/
void binkp_queuemsg(s_bpinfo *bpi, e_bpmsg msg, const char *s1, const char *s2)
{
bpi->msgqueue = xrealloc(bpi->msgqueue, sizeof(s_bpmsg)*(bpi->n_msgs + 1));
memset(&bpi->msgqueue[bpi->n_msgs], '\0', sizeof(s_bpmsg));
/* Set message type */
bpi->msgqueue[bpi->n_msgs].type = msg;
/* Set message data size (without frame header) */
bpi->msgqueue[bpi->n_msgs].size = 1;
if( s1 ) bpi->msgqueue[bpi->n_msgs].size += strlen(s1);
if( s2 ) bpi->msgqueue[bpi->n_msgs].size += strlen(s2);
/* Set message data */
bpi->msgqueue[bpi->n_msgs].data = xmalloc(bpi->msgqueue[bpi->n_msgs].size+3);
binkp_puthdr(bpi->msgqueue[bpi->n_msgs].data,
(unsigned)(bpi->msgqueue[bpi->n_msgs].size | 0x8000));
binkp_putmsgtype(bpi->msgqueue[bpi->n_msgs].data + 2, msg);
bpi->msgqueue[bpi->n_msgs].data[3] = '\0';
if( s1 ) strcat(bpi->msgqueue[bpi->n_msgs].data + 3, s1);
if( s2 ) strcat(bpi->msgqueue[bpi->n_msgs].data + 3, s2);
DEB((D_PROT, "binkp_queuemsg: queued message #%d, %ld bytes, \"%s\"",
(int)bpi->msgqueue[bpi->n_msgs].type,
(long)bpi->msgqueue[bpi->n_msgs].size,
(char*)bpi->msgqueue[bpi->n_msgs].data+3));
++bpi->n_msgs;
}
/*****************************************************************************
* Sends a message using format string
*
* Arguments:
* bpi binkp state structure
* msg message type
* fmt pointer to the format string, (man printf)
*
* Return value:
* None
*/
void binkp_queuemsgf(s_bpinfo *bpi, e_bpmsg msg, const char *fmt, ...)
{
char msg_text[2048];
va_list ap;
va_start(ap, fmt);
#ifdef HAVE_SNPRINTF
vsnprintf(msg_text, sizeof(msg_text), fmt, ap);
#else
vsprintf(msg_text, fmt, ap);
#endif
va_end(ap);
binkp_queuemsg(bpi, msg, msg_text, NULL);
}
/*****************************************************************************
* Parse most common message arguments, send error message to remote
* if needed.
*
* Arguments:
* s pointer to the string to parse
* fn pointer to the pointer for extracted file name
* sz pointer to the extracted file size
* tm pointer to the extracted file modification time
* offs pointer to the extracted file offset
*
* Return value:
* non-zero value on error, zero on success
*/
int binkp_parsfinfo(char *s, char **fn, size_t *sz, time_t *tm, size_t *offs)
{
char *n;
char *p_fname = NULL;
char *p_size = NULL;
char *p_time = NULL;
char *p_offs = NULL;
/* Attention, offs may be NULL! */
ASSERT(s != NULL && fn != NULL && sz != NULL && tm != NULL);
DEB((D_PROT, "binkp_parsemsg: want parse \"%s\"", s));
p_fname = string_token(s, &n, NULL, 0);
p_size = string_token(NULL, &n, NULL, 0);
p_time = string_token(NULL, &n, NULL, 0);
if( offs ) p_offs = string_token(NULL, &n, NULL, 0);
if( p_fname && p_size && p_time && (!offs || p_offs) )
{
if( ISDEC(p_size) && ISDEC(p_time) && (!offs || ISDEC(p_offs)) )
{
(*fn) = p_fname;
(*sz) = atol(p_size);
(*tm) = atol(p_time);
if( offs ) *offs = atol(p_offs);
DEB((D_PROT, "binkp_parsemsg: file = \"%s\", size = %d, time = %d",
*fn, *sz, *tm));
return 0;
}
}
return 1;
}
/*****************************************************************************
* Put message to a buffer
*
* Arguments:
* bpi binkp state structure
* msg message
*
* Return value:
* Zero on success, and non-zero value if no more free space left
* in the buffer
*/
int binkp_buffer_message(s_bpinfo *bpi, s_bpmsg *msg)
{
DEB((D_PROT, "binkp_buffer_message: buffer message #%d, %ld byte(s)",
(int)msg->type, (long)msg->size));
/* Check for possible internal error */
if( msg->size > BINKP_MAX_BLKSIZE )
{
log("size of msg we want to send is too big (%db)", msg->size);
return 1;
}
/* Is there space for the new msg? */
if( bpi->opos + msg->size > BINKP_MAX_BLKSIZE ) return 1;
if( msg->data )
{
memcpy(bpi->obuf + bpi->opos, msg->data, msg->size + BINKP_BLK_HDRSIZE);
bpi->opos += msg->size + BINKP_BLK_HDRSIZE;
free(msg->data);
msg->data = NULL;
}
return 0;
}
/*****************************************************************************
* Send as much buffered data as possible (non-blocking)
*
* Arguments:
* bpi binkp state structure
*
* Return value:
* Zero on success, and non-zero value on errors
*/
int binkp_send_buffer(s_bpinfo *bpi)
{
int n;
DEB((D_PROT, "binkp_send_buffer: sending %ld byte(s)", (long)bpi->opos));
n = tty_write(bpi->optr, bpi->opos);
if( n >= bpi->opos )
{ bpi->optr = bpi->obuf; bpi->opos = 0; }
else if( n > 0 )
{ bpi->optr += n; bpi->opos -= n; }
else
return -1;
return 0;
}
/*****************************************************************************
* Send as much buffered data or messages from the queue as possible
*
* Arguments:
* bpi binkp state structure
*
* Return value:
* Zero on success, and non-zero value on errors
*/
int binkp_send(s_bpinfo *bpi)
{
int i;
if( bpi->opos == 0 && bpi->msgqueue )
{
/*
* Buffer is empty and there are unsent msgs
*/
for( i = 0; i < bpi->n_msgs; i++ )
{
if( bpi->msgqueue[i].sent == FALSE )
{
if( binkp_buffer_message(bpi, &bpi->msgqueue[i]) )
break;
else
bpi->msgqueue[i].sent = TRUE;
}
}
/* If the message queue is empty, free it */
if( i >= bpi->n_msgs )
{
if( bpi->msgqueue )
{ free(bpi->msgqueue); bpi->msgqueue = NULL; }
bpi->n_msgs = 0;
}
}
return bpi->opos ? binkp_send_buffer(bpi) : 0;
}
/*****************************************************************************
* Flush all buffers and queues that can contain unsent data
*
* Arguments:
* bpi binkp state structure
* timeout abort flushing if this time will be exceeded
*
* Return value:
* Zero on success, and non-zero value on errors
*/
int binkp_flush_queue(s_bpinfo *bpi, int timeout)
{
bool send_ready = FALSE;
time_t flush_timer;
timer_set(&flush_timer, timeout);
while( bpi->opos > 0 || bpi->n_msgs > 0 )
{
if( timer_expired(flush_timer)
|| tty_select(NULL, &send_ready, 10) < 0 )
return -1;
if( send_ready && binkp_send(bpi) < 0 )
return -1;
}
return 0;
}
/*****************************************************************************
* Try to receive next message or data block in non-blocking mode
*
* Arguments:
* bpi binkp state structure
*
* Return value:
* One of the BPMSG_* values
*/
int binkp_recv(s_bpinfo *bpi)
{
int n = 0;
int size;
if( bpi->inew || bpi->isize == -1 )
{
bpi->inew = FALSE;
bpi->isize = -1;
size = BINKP_BLK_HDRSIZE;
}
else
size = bpi->isize;
if( size > 0 )
{
n = tty_read(bpi->ibuf + bpi->ipos, size - bpi->ipos);
if( n <= 0 ) return BPMSG_EXIT;
}
bpi->ipos += n;
if( bpi->ipos == size )
{
if( bpi->isize == -1 )
{
/* We got block header */
bpi->ipos = 0;
bpi->imsg = ((bpi->ibuf[0] >> 7) & 0377) ? TRUE : FALSE;
bpi->isize = binkp_gethdr(bpi->ibuf);
DEB((D_PROT, "binkp_recv: received header: %ld byte(s) (%s)",
(long)bpi->isize, bpi->imsg ? "msg" : "data"));
if( bpi->isize > BINKP_MAX_BLKSIZE )
{
log("internal error: got %ld bytes block size", bpi->isize);
return BPMSG_EXIT;
}
else if( bpi->isize == 0 )
{
bpi->ipos = 0;
bpi->inew = TRUE;
bpi->isize = -1;
if( bpi->imsg == TRUE )
log("zero length message from remote");
}
}
else /* We got whole data block/message */
{
if( bpi->imsg == TRUE ) /* Is it message? */
{
bpi->ipos = 0;
bpi->inew = TRUE;
bpi->ibuf[size] = '\0';
bpi->imsgtype = binkp_getmsgtype(bpi->ibuf[0]);
DEB((D_PROT, "binkp_recv: got message #%d, %ld byte(s), \"%s\"",
(int)bpi->imsgtype, bpi->isize, bpi->ibuf+1));
if( bpi->imsgtype < 0 )
{
bpi->isize = -1;
log("got incorrect message type");
if( ++bpi->junkcount >= 5 )
{
log("junk count exceeded");
return BPMSG_EXIT;
}
return BPMSG_NONE;
}
return bpi->imsgtype;
}
else /* It is data */
{
bpi->ipos = 0;
bpi->inew = TRUE;
bpi->ibuf[size] = '\0';
DEB((D_PROT, "binkp_recv: got data block, %ld byte(s)",
(long)bpi->isize));
return BPMSG_DATA;
}
}
}
return BPMSG_NONE;
}
/*****************************************************************************
* Send (queue) system information to the remote
*
* Arguments:
* bpi binkp state structure
* binkp structure with the system information
*
* Return value:
* None
*/
void binkp_queue_sysinfo(s_bpinfo *bpi, s_binkp_sysinfo *binkp)
{
int i;
char *astr = NULL;
char abuf[BF_MAXADDRSTR+1];
if( !state.caller && binkp->challenge_length > 0 )
{
char challenge[128];
string_bin_to_hex(challenge, binkp->challenge, binkp->challenge_length);
binkp_queuemsgf(bpi, BPMSG_NUL, "OPT CRAM-MD5-%s", challenge);
}
binkp_queuemsg(bpi, BPMSG_NUL, "SYS ", binkp->systname);
binkp_queuemsg(bpi, BPMSG_NUL, "ZYZ ", binkp->sysop);
binkp_queuemsg(bpi, BPMSG_NUL, "LOC ", binkp->location);
binkp_queuemsg(bpi, BPMSG_NUL, "PHN ", binkp->phone);
binkp_queuemsg(bpi, BPMSG_NUL, "NDL ", binkp->flags);
binkp_queuemsg(bpi, BPMSG_NUL, "TIME ", binkp->timestr);
binkp_queuemsgf(bpi, BPMSG_NUL, "VER %s %s/%d.%d",
binkp->progname, binkp->protname,
binkp->majorver, binkp->minorver);
for( i = 0; i < binkp->anum; i++ )
{
if( i ) astr = xstrcat(astr, " ");
astr = xstrcat(astr, ftn_addrstr(abuf, binkp->addrs[i].addr));
}
if( astr )
{
binkp_queuemsg(bpi, BPMSG_ADR, NULL, astr);
free(astr);
}
}
/*****************************************************************************
* Write system information to the log
*
* Arguments:
* binkp structure with the system information
*
* Return value:
* None
*/
void binkp_log_sysinfo(s_binkp_sysinfo *binkp)
{
int i;
char abuf[BF_MAXADDRSTR+1];
if( binkp->anum )
for( i = 0; i < binkp->anum; i++ )
{
log(" Address : %s", ftn_addrstr(abuf, binkp->addrs[i].addr));
}
if( *binkp->systname && *binkp->phone )
log(" System : %s (%s)",
string_printable(binkp->systname),
string_printable(binkp->phone));
else if( *binkp->systname )
log(" System : %s",
string_printable(binkp->systname));
else if( *binkp->phone )
log(" Phone : %s",
string_printable(binkp->phone));
#ifdef BFORCE_LOG_PASSWD
if( *binkp->passwd )
log(" Password : %s", string_printable(binkp->passwd));
#endif
if( *binkp->opt )
log(" Options : %s", string_printable(binkp->opt));
if( *binkp->sysop && *binkp->location )
log(" SysOp : %s from %s",
string_printable(binkp->sysop),
string_printable(binkp->location));
else if( *binkp->sysop )
log(" SysOp : %s",
string_printable(binkp->sysop));
else if( *binkp->location )
log(" Location : %s",
string_printable(binkp->location));
if( *binkp->progname )
{
log(" Mailer : %s (%s/%d.%d)",
*binkp->progname ? string_printable(binkp->progname) : "?",
*binkp->protname ? string_printable(binkp->protname) : "?",
binkp->majorver, binkp->minorver);
}
if( *binkp->flags )
log(" Flags : %s", string_printable(binkp->flags));
if( *binkp->timestr )
log(" Time : %s", string_printable(binkp->timestr));
}
/*****************************************************************************
* Set our local system information
*
* Arguments:
* binkp structure where to store system information
* remote_addr remote main address (for setting best AKA)
* caller are we calling system?
*
* Return value:
* None
*/
void binkp_set_sysinfo(s_binkp_sysinfo *binkp, s_faddr *remote_addr, bool caller)
{
s_cval_entry *addr_ptr;
s_cval_entry *hide_ptr;
s_faddr *primary = NULL;
const char *p_systname = conf_string(cf_system_name);
const char *p_location = conf_string(cf_location);
const char *p_sysop = conf_string(cf_sysop_name);
const char *p_phone = conf_string(cf_phone);
const char *p_flags = conf_string(cf_flags);
/* free previously allocated memory */
if( binkp->addrs )
free(binkp->addrs);
memset(binkp, '\0', sizeof(s_binkp_sysinfo));
/* Set best primary address */
if( remote_addr )
{
primary = session_get_bestaka(*remote_addr);
/* Add primary address */
if( primary )
session_addrs_add(&binkp->addrs, &binkp->anum, *primary);
}
/* Add other AKAs */
for( addr_ptr = conf_first(cf_address); addr_ptr;
addr_ptr = conf_next(addr_ptr) )
{
for( hide_ptr = conf_first(cf_hide_our_aka); hide_ptr;
hide_ptr = conf_next(hide_ptr) )
{
if( !ftn_addrcomp(hide_ptr->d.falist.addr, addr_ptr->d.falist.addr) )
break;
}
if( !hide_ptr && primary != &addr_ptr->d.falist.addr )
session_addrs_add(&binkp->addrs, &binkp->anum,
addr_ptr->d.falist.addr);
}
if( binkp->anum == 0 )
log("warning: no addresses will be presented to remote");
/* session password */
if( caller )
session_get_password(state.node.addr, binkp->passwd, sizeof(binkp->passwd));
binkp->majorver = BINKP_MAJOR;
binkp->minorver = BINKP_MINOR;
strnxcpy(binkp->progname, BF_NAME"/"BF_VERSION"/"BF_OS, sizeof(binkp->progname));
strnxcpy(binkp->protname, BINKP_NAME, sizeof(binkp->protname));
strnxcpy(binkp->sysop, p_sysop ? p_sysop : "Unknown", sizeof(binkp->sysop));
strnxcpy(binkp->systname, p_systname ? p_systname : "Unknown", sizeof(binkp->systname));
strnxcpy(binkp->location, p_location ? p_location : "Unknown", sizeof(binkp->location));
strnxcpy(binkp->phone, p_phone ? p_phone : "Unknown", sizeof(binkp->phone));
strnxcpy(binkp->flags, p_flags ? p_flags : "BINKP", sizeof(binkp->flags));
time_string_format(binkp->timestr, sizeof(binkp->timestr), "%Y/%m/%d %H:%M:%S", 0);
/* Set session challenge string */
if( !caller )
{
long rnd = (long)random();
int pid = ((int)getpid()) ^ ((int)random());
long utm = (long)time(0);
binkp->options |= BINKP_OPT_MD5;
binkp->challenge[0] = (unsigned char)(rnd );
binkp->challenge[1] = (unsigned char)(rnd >> 8 );
binkp->challenge[2] = (unsigned char)(rnd >> 16);
binkp->challenge[3] = (unsigned char)(rnd >> 24);
binkp->challenge[4] = (unsigned char)(pid );
binkp->challenge[5] = (unsigned char)(pid >> 8 );
binkp->challenge[6] = (unsigned char)(utm );
binkp->challenge[7] = (unsigned char)(utm >> 8 );
binkp->challenge[8] = (unsigned char)(utm >> 16);
binkp->challenge[9] = (unsigned char)(utm >> 24);
binkp->challenge_length = 10;
}
}
void binkp_parse_options(s_binkp_sysinfo *binkp, char *options)
{
char *p, *n;
for( p = string_token(options, &n, NULL, 0); p;
p = string_token(NULL, &n, NULL, 0) )
{
if( !strcmp(p, "NR") )
binkp->options |= BINKP_OPT_NR;
else if( !strcmp(p, "MB") )
binkp->options |= BINKP_OPT_MB;
else if( !strcmp(p, "MPWD") )
binkp->options |= BINKP_OPT_MPWD;
else if( !strncmp(p, "CRAM-", 5) )
{
char *hash_types = p + 5;
char *challenge = strchr(hash_types, '-');
if( challenge )
{
char *pp, *nn;
*challenge++ = '\0';
for( pp = string_token(hash_types, &nn, "/", 0); pp;
pp = string_token(NULL, &nn, "/", 0) )
{
if( !strcmp(pp, "SHA1") )
binkp->options |= BINKP_OPT_SHA1;
else if( !strcmp(pp, "MD5") )
binkp->options |= BINKP_OPT_MD5;
else if( !strcmp(pp, "DES") )
binkp->options |= BINKP_OPT_DES;
}
if( strlen(challenge) > (2*sizeof(binkp->challenge)) )
log("binkp got too long challenge string");
else
binkp->challenge_length = string_hex_to_bin(
binkp->challenge, challenge);
}
else
log("binkp got invalid option: \"%s\"", string_printable(p));
}
}
}
File diff suppressed because it is too large Load Diff
+842
View File
@@ -0,0 +1,842 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*
* BUG: When we resend EMSIDAT packet, it's TRX# field is most probable
* out of date.
*/
#include "includes.h"
#include "confread.h"
#include "version.h"
#include "logger.h"
#include "util.h"
#include "io.h"
#include "nodelist.h"
#include "session.h"
#include "prot_common.h"
#include "prot_emsi.h"
/*
* #define EMSI_INQ "**EMSI_INQC816"
* #define EMSI_REQ "**EMSI_REQA77E"
* #define EMSI_ACK "**EMSI_ACKA490"
* #define EMSI_NAK "**EMSI_NAKEEC3"
* #define EMSI_CLI "**EMSI_CLIFA8C"
* #define EMSI_ICI "**EMSI_ICI2D73"
* #define EMSI_HBT "**EMSI_HBTEAEE"
* #define EMSI_IRQ "**EMSI_IRQ8E08"
*/
typedef struct tx_emsidat {
int caller;
int tries;
time_t mast_timer;
time_t sync_timer;
char buf[13];
int emsi_seq;
int nakcount; /* count received EMSI_NAK */
s_emsi *local_emsi;
} s_tx_emsidat;
typedef struct rx_emsidat {
int caller;
int rx_ack; /* strip second EMSI_ACK */
int tries;
int tries_recv;
time_t mast_timer;
time_t sync_timer;
char buf[13];
int emsi_seq;
s_emsi *remote_emsi;
} s_rx_emsidat;
/*
* State machine (TODO: REMOVE!) Now it is used only by EMSI protocol.
*/
static int state_machine(s_states *sm, void *data)
{
signed int cur_state = 0;
do
{
DEB((D_STATEM, "state_machine: entering with state \"%s\" (%d)",
sm[cur_state].st_name, cur_state));
cur_state = (*(sm[cur_state].proc))(data);
DEB((D_STATEM, "state_machine: return \"%s\" (%d)",
(cur_state>0)?sm[cur_state].st_name:"finish", cur_state));
}
while( cur_state > 0 );
return(cur_state);
}
/* ------------------------------------------------------------------------- */
/* Transmite EMSI_DAT packet state machine routines */
/* ------------------------------------------------------------------------- */
/* SM0 */
static int sm_tx_init(s_tx_emsidat *d)
{
timer_set(&d->mast_timer, 60);
return(SM1);
}
/* SM1 */
static int sm_tx_senddat(s_tx_emsidat *d)
{
char *emsi_dat = NULL;
char buf[8];
if( ++d->tries > 6 )
{
log("too many tries sending emsi data");
return(SME);
}
if( d->tries > 1 )
log("emsi data send - retry %d", d->tries - 1);
DEB((D_HSHAKE, "sm_tx_senddat: try number %d", d->tries));
if( (emsi_dat = emsi_createdat(d->local_emsi)) == NULL )
{
log("cannot create emsi data packet");
return(SME);
}
DEB((D_HSHAKE, "sm_tx_senddat: emsi: \"%s\"", emsi_dat));
if( tty_puts(emsi_dat, 60) < 0 )
{
free(emsi_dat);
return SME;
}
/*
* Calculate and send CRC-16 of our emsi packet
*/
sprintf(buf, "%04hX\r",
(short unsigned)getcrc16xmodem(emsi_dat+2, strlen(emsi_dat+2)));
free(emsi_dat); emsi_dat = NULL;
if( PUTSTR(buf) < 0 || FLUSHOUT() < 0 )
return SME;
return SM2;
}
/* SM2 */
static int sm_tx_waitseq(s_tx_emsidat *d)
{
int rc, pos = 0;
timer_set(&d->sync_timer, (d->tries > 1) ? 20 : 10);
while(1)
{
if( timer_expired(d->mast_timer) )
{
DEB((D_HSHAKE, "sm_tx_waitseq: master timer expired"));
log("master timer expired");
return(SME);
}
if( timer_expired(d->sync_timer) )
{
DEB((D_HSHAKE, "sm_tx_waitseq: sync timer expired"));
return(SM1);
}
if( (rc = GETCHAR(1)) < 0 )
{
if( rc != TTY_TIMEOUT )
{
DEB((D_HSHAKE, "sm_rx_waitseq: got ERROR/HANGUP"));
return SME;
}
}
else if( rc == XON || rc == XOFF )
{
/* Do nothing. Drop them down */
}
else if( rc == '*' )
{
memset(d->buf, '\0', sizeof(d->buf));
pos = 0;
d->emsi_seq = 1;
}
else if( d->emsi_seq && rc > ' ' && rc < '~' )
{
if( pos < sizeof(d->buf)-1 )
{
d->buf[pos++] = rc;
d->buf[pos ] = '\0';
}
if( pos == (sizeof(d->buf) - 1) )
{
DEB((D_HSHAKE, "sm_tx_waitseq: emsi buffer full \"%s\"", d->buf));
d->emsi_seq = 0;
if( !strncasecmp(d->buf, "EMSI_REQA77E", 12) )
{
/* Do nothing. Drop it down */
}
else if( !strncasecmp(d->buf, "EMSI_ACKA490", 12) )
{
/*
* Remote acknowleged our
* emsi data packet. exit.
*/
return SM0;
}
else if( !strncasecmp(d->buf, "EMSI_NAKEEC3", 12) )
{
/*
* Remote failed on our emsi data
* packet. Resend EMSI_DAT only after
* first EMSI_NAK
*/
DEB((D_HSHAKE, "sm_tx_waitseq: got NAK"));
if( !d->nakcount++ )
return SM1;
}
else if( !strncasecmp(d->buf, "EMSI_INQC816", 12) )
{
/*
* Do nothing. Just update sync timer
*/
return SM2;
}
else if( !strncasecmp(d->buf, "EMSI_DAT", 8) )
{
/*
* 1) We are calling system
* We got an echo of our sequence,
* possible they don't know about
* FIDO. yet :) Resend EMSI_INQ
* again.
* 2) We are asnwering system
* Think where is a stupid mailer
* that didn't seen our EMSI_ACK,
* so send it again in hope to the
* best
*/
DEB((D_HSHAKE, "sm_tx_waitseq: got echo \"%s\"",
string_printable(d->buf)));
if( d->caller )
{
/* Wait for a login prompt */
sleep(2);
if( PUTSTR("**EMSI_INQC816\r") < 0
|| FLUSHOUT() < 0 )
return SME;
/* Wait for a password prompt */
sleep(2);
if( PUTSTR("**EMSI_INQC816\r") < 0
|| FLUSHOUT() < 0 )
return SME;
return SM1;
}
else
{
/* Send acknowlegment */
if( PUTSTR("**EMSI_ACKA490\r**EMSI_ACKA490\r") < 0 )
return SME;
if( FLUSHOUT() < 0 )
return SME;
}
}
else
{
DEB((D_HSHAKE, "got unexpected emsi sequence: \"%s\"",
string_printable(d->buf)));
log("got unexpected emsi sequence \"%s\"",
string_printable(d->buf));
}
}
}
else if( d->emsi_seq )
{
d->emsi_seq = 0;
DEB((D_HSHAKE, "sm_tx_waitseq: bad character 0x%02x in \"%s\"",
rc, string_printable(d->buf)));
}
}
return SME;
}
static s_states st_tx_emsidat[] =
{
{ "sm_tx_init", sm_tx_init },
{ "sm_tx_senddat", sm_tx_senddat },
{ "sm_tx_waitseq", sm_tx_waitseq }
};
int emsi_send_emsidat(s_emsi *local_emsi)
{
s_tx_emsidat d;
memset(&d, '\0', sizeof(s_tx_emsidat));
d.caller = state.caller;
d.local_emsi = local_emsi;
return state_machine(st_tx_emsidat, &d) ? 1 : 0;
}
/* ------------------------------------------------------------------------- */
/* Receive EMSI_DAT packet state machine routines */
/* ------------------------------------------------------------------------- */
/* SM0 */
static int sm_rx_init(s_rx_emsidat *d)
{
timer_set(&d->mast_timer, 60);
timer_set(&d->sync_timer, 20);
return SM1;
}
/* SM1 */
static int sm_rx_sendnak(s_rx_emsidat *d)
{
if( ++d->tries > 6 )
{
log("too many tries resyncing with remote");
return(SME);
}
DEB((D_HSHAKE, "sm_rx_sendnak: try number %d", d->tries));
if( !d->caller )
{
if( conf_boolean(cf_emsi_slave_sends_nak)
&& PUTSTR("**EMSI_NAKEEC3\r") < 0 )
return SME;
if( PUTSTR("**EMSI_REQA77E\r") < 0 )
return SME;
}
else if( d->tries > 1 )
{
if( PUTSTR("**EMSI_NAKEEC3\r") < 0 )
return SME;
}
if( FLUSHOUT() < 0 )
return SME;
return SM2;
}
/* SM2 */
static int sm_rx_waitseq(s_rx_emsidat *d)
{
int rc, pos = 0;
timer_set(&d->sync_timer, 20);
while(1)
{
if( timer_expired(d->mast_timer) )
{
DEB((D_HSHAKE, "sm_rx_waitseq: master timer expired"));
log("master timer expired");
return SME;
}
if( timer_expired(d->sync_timer) )
{
DEB((D_HSHAKE, "sm_rx_waitseq: sync timer expired"));
return SM1;
}
if( (rc = GETCHAR(1)) < 0 )
{
if( rc != TTY_TIMEOUT )
{
DEB((D_HSHAKE, "sm_rx_waitseq: got ERROR/HANGUP"));
return SME;
}
}
else if( rc == XON || rc == XOFF )
{
/* Do nothing. Drop them down */
}
else if( rc == '*' )
{
memset(d->buf, '\0', sizeof(d->buf));
pos = 0;
d->emsi_seq = 1;
}
else if( d->emsi_seq && rc > ' ' && rc < '~' )
{
if( pos < sizeof(d->buf)-1 )
{
d->buf[pos++] = rc;
d->buf[pos ] = '\0';
}
if( pos == sizeof(d->buf)-1 )
{
DEB((D_HSHAKE, "sm_rx_waitseq: emsi buffer full \"%s\"", d->buf));
d->emsi_seq = 0;
if( d->caller && !strncasecmp(d->buf, "EMSI_ACKA490", 12) )
{
/* Do nothing. Drop it down. */
}
else if( !strncasecmp(d->buf, "EMSI_HBTEAEE", 12) )
{
/*
* Remote wants some time to think
*/
return SM2;
}
else if( !strncasecmp(d->buf, "EMSI_DAT", 8) )
{
/*
* Start receiving emsi data packet
*/
return SM3;
}
else
{
DEB((D_HSHAKE, "got unexpected emsi sequence: \"%s\"",
string_printable(d->buf)));
log("got unexpected emsi sequence \"%s\"",
string_printable(d->buf));
}
}
}
else if( d->emsi_seq )
{
d->emsi_seq = 0;
DEB((D_HSHAKE, "sm_rx_waitseq: bad character 0x%02x in \"%s\"",
rc, string_printable(d->buf)));
}
}
return SME;
}
/* SM3 */
static int sm_rx_getdat(s_rx_emsidat *d)
{
int rc = 0;
int pos = 0;
int emsi_len = 0;
short unsigned ourcrc;
short unsigned remcrc;
char *emsi_dat = NULL;
if( d->tries_recv++ )
log("emsi data receive - retry %d", d->tries_recv);
/*
* At this point, there is a EMSI_DATXXXX packet in
* the buffer, there XXXX is the hex length of emsi
* data packet
*/
if( strspn(d->buf+8, "0123456789abcdefABCDEF") != 4 )
return SM1;
if( sscanf(d->buf+8, "%04x", &emsi_len) != 1 )
return SM1;
/*
* Don't receive emsi packet's longer our "limit"
*/
if( emsi_len > EMSI_MAXDAT )
{
CLEARIN();
log("emsi data packet too long %db (maximum %db allowed)",
emsi_len, EMSI_MAXDAT);
return SM1;
}
/* Increase packet's length on CRC length */
emsi_len += 16;
emsi_dat = (char*)xmalloc(emsi_len + 1);
strncpy(emsi_dat, d->buf, 12);
pos = 12;
while( pos < emsi_len )
{
if( timer_expired(d->mast_timer) )
break;
if( (rc = GETCHAR(1)) < 0 )
{
if( rc != TTY_TIMEOUT )
break;
}
else
{
emsi_dat[pos++] = (unsigned char)rc;
emsi_dat[pos ] = '\0';
}
}
if( pos != emsi_len )
{
/* Fatal error occured */
DEB((D_HSHAKE, "sm_rx_getdat: can't get emsi_dat packet"));
DEB((D_HSHAKE, "sm_rx_getdat: buffer: \"%s\"",
string_printable(emsi_dat)));
free(emsi_dat);
return SME;
}
DEB((D_HSHAKE, "sm_rx_getdat: got \"%s\"",
string_printable(emsi_dat)));
/*
* Get CRC given by remote
*/
if( sscanf(emsi_dat + emsi_len - 4 , "%04hX", &remcrc) != 1 )
{
log("bad emsi data packet (can't get CRC16)");
free(emsi_dat);
return(SM1);
}
/*
* Calculate our own crc of the data packet
*/
ourcrc = getcrc16xmodem(emsi_dat, emsi_len-4);
/*
* Compare our and remote CRCs
*/
if( ourcrc != remcrc )
{
DEB((D_HSHAKE, "sm_rx_getdat: our = %hX, remote = %hX", ourcrc, remcrc));
log("got emsi data packet with bad CRC");
free(emsi_dat);
return SM1;
}
/*
* Parse received emsi data packet. All obtained
* information will be stored in d->remote_emsi
*/
rc = emsi_parsedat(emsi_dat+12, d->remote_emsi);
free(emsi_dat);
if( rc )
{
log("received invalid emsi data packet");
return SM1;
}
/* Send acknowlegment */
if( PUTSTR("**EMSI_ACKA490\r**EMSI_ACKA490\r") < 0 )
return SME;
if( FLUSHOUT() < 0 )
return SME;
return SM0;
}
static s_states st_rx_emsidat[] =
{
{ "sm_rx_init", sm_rx_init },
{ "sm_rx_sendnak", sm_rx_sendnak },
{ "sm_rx_waitseq", sm_rx_waitseq },
{ "sm_rx_getdat", sm_rx_getdat }
};
int emsi_recv_emsidat(s_emsi *remote_emsi)
{
s_rx_emsidat d;
memset(&d, '\0', sizeof(s_rx_emsidat));
d.caller = state.caller;
d.remote_emsi = remote_emsi;
return state_machine(st_rx_emsidat, &d) ? 1 : 0;
}
/* ------------------------------------------------------------------------- */
/* Fill/update our outgoing emsi oriented structure */
/* ------------------------------------------------------------------------- */
void emsi_set_sysinfo(s_emsi *emsi, s_emsi *remote_emsi, int hrc,
e_protocol protocol)
{
char buf[64];
s_cval_entry *addr_ptr;
s_cval_entry *hide_ptr;
s_faddr *primary = NULL;
const long options = conf_options(cf_options);
const long speed = conf_number(cf_max_speed);
const char *p_systname = conf_string(cf_system_name);
const char *p_location = conf_string(cf_location);
const char *p_sysopname = conf_string(cf_sysop_name);
const char *p_phone = conf_string(cf_phone);
const char *p_flags = conf_string(cf_flags);
const char *p_emsioh = conf_string(cf_emsi_OH_time);
const char *p_emsifr = conf_string(cf_emsi_FR_time);
/* free previously allocated memory */
if( emsi->addrs ) free(emsi->addrs);
memset(emsi, '\0', sizeof(s_emsi));
/* ----------------------------------------------------------------- */
/* Data for {EMSI} field */
/* ----------------------------------------------------------------- */
emsi->have_emsi = 1;
/* Set best primary address */
primary = session_get_bestaka(state.node.addr);
/* Add primary address */
if( primary )
session_addrs_add(&emsi->addrs, &emsi->anum, *primary);
/* Add other AKAs */
for( addr_ptr = conf_first(cf_address); addr_ptr;
addr_ptr = conf_next(addr_ptr) )
{
for( hide_ptr = conf_first(cf_hide_our_aka); hide_ptr;
hide_ptr = conf_next(hide_ptr) )
{
if( !ftn_addrcomp(hide_ptr->d.falist.addr, addr_ptr->d.falist.addr) )
break;
}
if( !hide_ptr && primary != &addr_ptr->d.falist.addr )
session_addrs_add(&emsi->addrs, &emsi->anum,
addr_ptr->d.falist.addr);
}
if( emsi->anum == 0 )
log("warning: no addresses will be presented to remote");
/* session password */
if( state.caller )
{
session_get_password(state.node.addr, emsi->passwd, sizeof(emsi->passwd));
}
else if( hrc == HRC_OK )
{
/* Satisfy remote with their password */
const char *p = state.handshake->remote_password(state.handshake);
if( p )
strnxcpy(emsi->passwd, p, sizeof(emsi->passwd));
}
/* link codes */
if( state.caller ) /* CALLER */
{
if( (options & OPTIONS_NO_RH1) != OPTIONS_NO_RH1
&& (options & OPTIONS_NO_HYDRA) != OPTIONS_NO_HYDRA)
{ emsi->linkcodes.RH1 = 1; }
if( (options & OPTIONS_NO_PICKUP) == OPTIONS_NO_PICKUP )
{ emsi->linkcodes.NPU = 1; }
else
{ emsi->linkcodes.PUA = 1; }
if( (options & OPTIONS_MAILONLY) == OPTIONS_MAILONLY )
{ emsi->linkcodes.HXT = 1; }
if( (options & OPTIONS_NO_EMSI_II) != OPTIONS_NO_EMSI_II )
{
/* EMSI-II */
if( (options & OPTIONS_HOLDREQ) != OPTIONS_HOLDREQ )
{ emsi->linkcodes.RMA = 1; }
}
else
{
/* EMSI-I */
emsi->linkcodes.N81 = 1;
}
}
else if( (remote_emsi->compcodes.EII == 1)
&& (options & OPTIONS_NO_EMSI_II) != OPTIONS_NO_EMSI_II )
{
/* ANSWER/EMSI-II */
if( remote_emsi->linkcodes.RH1 && protocol == PROT_HYDRA )
{ emsi->linkcodes.RH1 = 1; }
if( state.reqstat == REQS_ALLOW && remote_emsi->linkcodes.RMA )
{ emsi->linkcodes.RMA = 1; }
else if( state.reqstat == REQS_NOTALLOW )
{ emsi->linkcodes.HRQ = 1; }
if( (options & OPTIONS_MAILONLY) == OPTIONS_MAILONLY )
{ emsi->linkcodes.HXT = 1; }
}
else
{
/* ANSWER/EMSI-I */
if( remote_emsi->linkcodes.RH1 && protocol == PROT_HYDRA )
{ emsi->linkcodes.RH1 = 1; }
if( state.reqstat == REQS_NOTALLOW )
{ emsi->linkcodes.HRQ = 1; }
if( (options & OPTIONS_MAILONLY) == OPTIONS_MAILONLY )
{ emsi->linkcodes.HXT = 1; }
}
/* compatibility codes */
if( state.caller )
{
if( (options & OPTIONS_NO_EMSI_II) != OPTIONS_NO_EMSI_II )
{
/* EMSI-II */
emsi->compcodes.EII = 1;
}
else
{
/* EMSI-I */
emsi->compcodes.ARC = 1;
emsi->compcodes.XMA = 1;
}
if( (options & OPTIONS_NO_ZMODEM) != OPTIONS_NO_ZMODEM )
{ emsi->compcodes.ZMO = 1; }
if( (options & OPTIONS_NO_ZEDZAP) != OPTIONS_NO_ZEDZAP )
{ emsi->compcodes.ZAP = 1; }
if( (options & OPTIONS_NO_DIRZAP) != OPTIONS_NO_DIRZAP )
{ emsi->compcodes.DZA = 1; }
if( (options & OPTIONS_NO_JANUS) != OPTIONS_NO_JANUS )
{ emsi->compcodes.JAN = 1; }
if( (options & OPTIONS_NO_HYDRA) != OPTIONS_NO_HYDRA )
{ emsi->compcodes.HYD = 1; }
}
else
{
if( (remote_emsi->compcodes.EII == 1)
&& (options & OPTIONS_NO_EMSI_II) != OPTIONS_NO_EMSI_II )
{
/* EMSI-II */
emsi->compcodes.EII = 1;
}
else
{
/* EMSI-I */
emsi->compcodes.ARC = 1;
emsi->compcodes.XMA = 1;
}
if( state.reqstat == REQS_DISABLED )
{ emsi->compcodes.NRQ = 1; }
switch(protocol) {
case PROT_NOPROT: emsi->compcodes.NCP = 1; break;
case PROT_ZMODEM: emsi->compcodes.ZMO = 1; break;
case PROT_ZEDZAP: emsi->compcodes.ZAP = 1; break;
case PROT_DIRZAP: emsi->compcodes.DZA = 1; break;
case PROT_JANUS: emsi->compcodes.JAN = 1; break;
case PROT_HYDRA: emsi->compcodes.HYD = 1; break;
default: ASSERT(FALSE); break;
}
}
strnxcpy(emsi->m_pid, BF_EMSI_NUM, sizeof(emsi->m_pid));
strnxcpy(emsi->m_name, BF_EMSI_NAME, sizeof(emsi->m_name));
if( hrc != HRC_BAD_PASSWD )
{
strnxcpy(emsi->m_ver, BF_EMSI_VER, sizeof(emsi->m_ver));
strnxcpy(emsi->m_reg, BF_EMSI_REG, sizeof(emsi->m_reg));
}
else
{
strnxcpy(emsi->m_ver, "?", sizeof(emsi->m_ver));
strnxcpy(emsi->m_reg, "?", sizeof(emsi->m_reg));
}
/* ----------------------------------------------------------------- */
/* Data for {IDENT} field */
/* ----------------------------------------------------------------- */
emsi->have_ident = 1;
emsi->speed = (speed > 0) ? speed : 300;
strnxcpy(emsi->sysop, p_sysopname ? p_sysopname : "Unknown", sizeof(emsi->sysop));
strnxcpy(emsi->phone, p_phone ? p_phone : "Unknown", sizeof(emsi->phone));
switch(hrc) {
case HRC_BAD_PASSWD:
strnxcpy(emsi->sname, "Bad password", sizeof(emsi->sname));
strnxcpy(emsi->location, "Check security table", sizeof(emsi->location));
strnxcpy(emsi->flags, "Password Error", sizeof(emsi->flags));
break;
case HRC_LOW_SPEED:
strnxcpy(emsi->sname, "Connect speed too low", sizeof(emsi->sname));
strnxcpy(emsi->location, "Buy new modem and call again", sizeof(emsi->location));
sprintf(buf, "Minimal speed: %ldbps", (long)state.minspeed);
strnxcpy(emsi->flags, buf, sizeof(emsi->flags));
break;
case HRC_BUSY:
strnxcpy(emsi->sname, "All AKAs are busy", sizeof(emsi->sname));
strnxcpy(emsi->location, "Possible another session is running", sizeof(emsi->location));
strnxcpy(emsi->flags, "Please, call later", sizeof(emsi->flags));
break;
default:
strnxcpy(emsi->sname, p_systname ? p_systname : "Unknown", sizeof(emsi->sname));
strnxcpy(emsi->location, p_location ? p_location : "Unknown", sizeof(emsi->location));
strnxcpy(emsi->flags, p_flags ? p_flags : "MO", sizeof(emsi->flags));
}
/* ----------------------------------------------------------------- */
/* Data for {OHFR} field */
/* ----------------------------------------------------------------- */
if( p_emsioh && *p_emsioh && hrc != HRC_BAD_PASSWD )
{
emsi->have_ohfr = 1;
strnxcpy(emsi->oh_time, p_emsioh, sizeof(emsi->oh_time));
if( p_emsifr && *p_emsifr )
strnxcpy(emsi->fr_time, p_emsifr, sizeof(emsi->fr_time));
}
/* ----------------------------------------------------------------- */
/* Data for {TRX#} field */
/* ----------------------------------------------------------------- */
emsi->have_trx = 1;
emsi->time = localtogmt(time(NULL));
/* ----------------------------------------------------------------- */
/* Data for {TRAF} and {MOH#} fields */
/* ----------------------------------------------------------------- */
if( state.caller == 0 && hrc != HRC_BAD_PASSWD )
{
emsi->have_traf = 1;
emsi->netmail_size = state.traff_send.netmail_size;
emsi->arcmail_size = state.traff_send.arcmail_size;
if ( state.traff_send.files_size )
{
emsi->have_moh = 1;
emsi->files_size = state.traff_send.files_size;
}
}
}
+480
View File
@@ -0,0 +1,480 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "version.h"
#include "logger.h"
#include "util.h"
#include "nodelist.h"
#include "session.h"
#include "prot_emsi.h"
void emsi_init(s_handshake_protocol *THIS);
void emsi_deinit(s_handshake_protocol *THIS);
int emsi_incoming(s_handshake_protocol *THIS);
int emsi_outgoing(s_handshake_protocol *THIS);
s_faddr *emsi_remote_address(s_handshake_protocol *THIS);
char *emsi_remote_password(s_handshake_protocol *THIS);
char *emsi_remote_sysop_name(s_handshake_protocol *THIS);
char *emsi_remote_system_name(s_handshake_protocol *THIS);
char *emsi_remote_location(s_handshake_protocol *THIS);
char *emsi_remote_phone(s_handshake_protocol *THIS);
char *emsi_remote_flags(s_handshake_protocol *THIS);
char *emsi_remote_mailer(s_handshake_protocol *THIS);
int emsi_remote_traffic(s_handshake_protocol *THIS, s_traffic *dest);
s_faddr *emsi_local_address(s_handshake_protocol *THIS);
char *emsi_local_password(s_handshake_protocol *THIS);
s_handshake_protocol handshake_protocol_emsi = {
/* Section 1 */
"EMSI",
"Joaquim H. Homrighausen",
"FSC-0056,0088",
NULL,
NULL,
0,
emsi_init,
emsi_deinit,
emsi_incoming,
emsi_outgoing,
/* Section 2 */
emsi_remote_address,
emsi_remote_password,
emsi_remote_sysop_name,
emsi_remote_system_name,
emsi_remote_location,
emsi_remote_phone,
emsi_remote_flags,
emsi_remote_mailer,
emsi_remote_traffic,
/* Section 3 */
emsi_local_address,
emsi_local_password
};
static void emsi_set_send_options(s_emsi *remote_emsi)
{
session_set_send_options();
if( remote_emsi->linkcodes.FNC )
state.sopts.fnc = 1;
if( remote_emsi->linkcodes.RH1 )
state.sopts.hydraRH1 = 1;
if( state.caller )
{
if( remote_emsi->linkcodes.HRQ
|| remote_emsi->compcodes.NRQ )
state.sopts.holdreq = 1;
if( remote_emsi->linkcodes.HAT )
state.sopts.holdall = 1;
if( remote_emsi->linkcodes.HXT )
state.sopts.holdxt = 1;
}
else
{
if( remote_emsi->linkcodes.NPU )
state.sopts.holdall = 1;
if( remote_emsi->linkcodes.PMO )
state.sopts.holdfiles = 1;
if( remote_emsi->linkcodes.NRQ )
state.sopts.holdreq = 1;
}
}
void emsi_init(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data == NULL);
ASSERT(THIS->local_data == NULL);
THIS->remote_data = (char *)xmalloc(sizeof(s_emsi));
THIS->local_data = (char *)xmalloc(sizeof(s_emsi));
memset(THIS->remote_data, '\0', sizeof(s_emsi));
memset(THIS->local_data, '\0', sizeof(s_emsi));
}
void emsi_deinit(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
ASSERT(THIS->local_data);
if( THIS->remote_data )
{
memset(THIS->remote_data, '\0', sizeof(s_emsi));
free(THIS->remote_data);
}
if( THIS->local_data )
{
memset(THIS->local_data, '\0', sizeof(s_emsi));
free(THIS->local_data);
}
}
/*
* Do incoming emsi session
*/
int emsi_incoming(s_handshake_protocol *THIS)
{
int rc = HRC_OK;
s_emsi *remote_emsi = NULL;
s_emsi *local_emsi = NULL;
ASSERT(THIS);
ASSERT(THIS->remote_data);
ASSERT(THIS->local_data);
remote_emsi = (s_emsi *)THIS->remote_data;
local_emsi = (s_emsi *)THIS->local_data;
/*
* Receive EMSI_DAT packet
*/
if( emsi_recv_emsidat(remote_emsi) )
return HRC_OTHER_ERR;
/*
* Check password(s)
*/
if( session_addrs_check(remote_emsi->addrs, remote_emsi->anum,
remote_emsi->passwd, NULL, 0) )
{
rc = HRC_BAD_PASSWD;
/* Don't return. Send EMSI_DAT with
* invalid password messages */
}
else
{
/* Lock (create BSY) remote addresses */
if( session_addrs_lock(remote_emsi->addrs, remote_emsi->anum) )
{
log("all remote addresses are busy");
rc = HRC_BUSY;
}
else
{
/*
* We know caller's address so we can process
* more expressions and fill state.node structure..
*/
session_remote_lookup(remote_emsi->addrs, remote_emsi->anum);
if( session_check_speed() )
rc = HRC_LOW_SPEED;
}
}
/*
* Put EMSI information to log
*/
(void)emsi_logdat(remote_emsi);
session_remote_log_status();
if( rc == HRC_OK )
{
const long options = conf_options(cf_options);
/*
* Set inbound directories, ignore errors,
* because we want send mail in any case.
*/
(void)session_set_inbound();
/*
* Set protocol that we will use
*/
if( remote_emsi->compcodes.HYD && !(options & OPTIONS_NO_HYDRA) )
THIS->protocol = PROT_HYDRA;
else if( remote_emsi->compcodes.ZAP && !(options & OPTIONS_NO_ZEDZAP) )
THIS->protocol = PROT_ZEDZAP;
else if( remote_emsi->compcodes.ZMO && !(options & OPTIONS_NO_ZMODEM) )
THIS->protocol = PROT_ZMODEM;
else /* NCP */
{
THIS->protocol = PROT_NOPROT;
rc = HRC_NO_PROTOS;
}
/*
* Check EMSI flags and set corresponding local HOLD flags
*/
(void)emsi_set_send_options(remote_emsi);
/*
* Create mail/files queue
*/
session_create_files_queue(remote_emsi->addrs,
remote_emsi->anum);
/*
* Set FREQ processor status
*/
if( rc == HRC_OK && THIS->protocol != PROT_NOPROT )
session_set_freqs_status();
else
state.reqstat = REQS_DISABLED;
}
/*
* Prepare ``local_emsi'' structure
*/
(void)emsi_set_sysinfo(local_emsi, remote_emsi, rc, THIS->protocol);
/*
* Send EMSI_DAT packet
*/
if( emsi_send_emsidat(local_emsi) )
return HRC_OTHER_ERR;
return rc;
}
/*
* Do outgoing emsi session
*/
int emsi_outgoing(s_handshake_protocol *THIS)
{
s_emsi *remote_emsi = NULL;
s_emsi *local_emsi = NULL;
ASSERT(THIS);
ASSERT(THIS->remote_data);
ASSERT(THIS->local_data);
remote_emsi = (s_emsi *)THIS->remote_data;
local_emsi = (s_emsi *)THIS->local_data;
/*
* Set FREQ processor status
*/
session_set_freqs_status();
/*
* Prepare ``local_emsi'' structure
*/
(void)emsi_set_sysinfo(local_emsi, NULL, HRC_OK, THIS->protocol);
/*
* Send EMSI_DAT packet
*/
if( emsi_send_emsidat(local_emsi) )
return HRC_OTHER_ERR;
/*
* Receive EMSI_DAT packet
*/
if( emsi_recv_emsidat(remote_emsi) )
return HRC_OTHER_ERR;
/*
* Put EMSI information to the log
*/
(void)emsi_logdat(remote_emsi);
/*
* Make sure expected address was presented
*/
if( session_addrs_check_genuine(remote_emsi->addrs,
remote_emsi->anum, state.node.addr) )
return HRC_NO_ADDRESS;
/*
* Check password(s)
*/
if( session_addrs_check(remote_emsi->addrs, remote_emsi->anum,
remote_emsi->passwd, NULL, 0) )
return HRC_BAD_PASSWD;
/*
* Lock (create BSY) remote addresses
*/
(void)session_addrs_lock(remote_emsi->addrs, remote_emsi->anum);
/*
* Set protocol we will use ("options" ignored)
*/
if( remote_emsi->compcodes.HYD && local_emsi->compcodes.HYD )
THIS->protocol = PROT_HYDRA;
else if( remote_emsi->compcodes.JAN && local_emsi->compcodes.JAN )
THIS->protocol = PROT_JANUS;
else if( remote_emsi->compcodes.DZA && local_emsi->compcodes.DZA )
THIS->protocol = PROT_DIRZAP;
else if( remote_emsi->compcodes.ZAP && local_emsi->compcodes.ZAP )
THIS->protocol = PROT_ZEDZAP;
else if( remote_emsi->compcodes.ZMO && local_emsi->compcodes.ZMO )
THIS->protocol = PROT_ZMODEM;
else
return HRC_NO_PROTOS;
/*
* Show remote status (prot/unprot, listed/unlisted)
*/
session_remote_log_status();
/*
* Set inbound directories
*/
if( session_set_inbound() )
return HRC_OTHER_ERR;
/*
* Check EMSI flags and set corresponding local HOLD flags
*/
(void)emsi_set_send_options(remote_emsi);
/*
* Create mail/files queue
*/
session_create_files_queue(remote_emsi->addrs,
remote_emsi->anum);
return HRC_OK;
}
s_faddr *emsi_remote_address(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_emsi *)THIS->remote_data)->anum > 0 )
return &((s_emsi *)THIS->remote_data)->addrs[0].addr;
return NULL;
}
char *emsi_remote_password(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_emsi *)THIS->remote_data)->passwd[0] )
return ((s_emsi *)THIS->remote_data)->passwd;
return NULL;
}
char *emsi_remote_sysop_name(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_emsi *)THIS->remote_data)->sysop[0] )
return ((s_emsi *)THIS->remote_data)->sysop;
return NULL;
}
char *emsi_remote_system_name(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_emsi *)THIS->remote_data)->sname[0] )
return ((s_emsi *)THIS->remote_data)->sname;
return NULL;
}
char *emsi_remote_location(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_emsi *)THIS->remote_data)->location[0] )
return ((s_emsi *)THIS->remote_data)->location;
return NULL;
}
char *emsi_remote_phone(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_emsi *)THIS->remote_data)->phone[0] )
return ((s_emsi *)THIS->remote_data)->phone;
return NULL;
}
char *emsi_remote_flags(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_emsi *)THIS->remote_data)->flags[0] )
return ((s_emsi *)THIS->remote_data)->flags;
return NULL;
}
char *emsi_remote_mailer(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_emsi *)THIS->remote_data)->m_name[0] )
return ((s_emsi *)THIS->remote_data)->m_name;
return NULL;
}
int emsi_remote_traffic(s_handshake_protocol *THIS, s_traffic *dest)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
ASSERT(dest);
memset(dest, '\0', sizeof(s_traffic));
if( ((s_emsi *)THIS->remote_data)->have_traf
|| ((s_emsi *)THIS->remote_data)->have_moh )
{
dest->netmail_size = ((s_emsi *)THIS->remote_data)->netmail_size;
dest->arcmail_size = ((s_emsi *)THIS->remote_data)->arcmail_size;
dest->files_size = ((s_emsi *)THIS->remote_data)->files_size;
return 0;
}
return -1;
}
s_faddr *emsi_local_address(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->local_data);
if( ((s_emsi *)THIS->local_data)->anum > 0 )
return &((s_emsi *)THIS->local_data)->addrs[0].addr;
return NULL;
}
char *emsi_local_password(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->local_data);
if( ((s_emsi *)THIS->local_data)->passwd[0] )
return ((s_emsi *)THIS->local_data)->passwd;
return NULL;
}
+817
View File
@@ -0,0 +1,817 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "version.h"
#include "logger.h"
#include "util.h"
#include "session.h"
#include "prot_emsi.h"
/* ------------------------------------------------------------------------- */
/* Add one char $ch to string $src. */
/* Return pointer to reallocated string */
/* ------------------------------------------------------------------------- */
static char *add_char(char *src, char ch)
{
char *dest;
int len;
len = src ? strlen(src) : 0;
dest = len ? xrealloc(src, len + 2) : xmalloc(2);
*(dest + len ) = ch;
*(dest + len + 1) = '\0';
return(dest);
}
/* ------------------------------------------------------------------------- */
/* Add string $add to string $source. Use escaping sequences for */
/* ']' and '}' characters. Return pointer to reallocated string */
/* ------------------------------------------------------------------------- */
static char *add_str(char *source, const char *add)
{
char *dest;
int len, pos;
pos = strlen(source);
len = pos + strlen(add) + 1;
dest = (char *)xrealloc(source, len);
while( *add )
{
if( (*add == ']') || (*add == '}') )
{
dest = (char *)xrealloc(dest, ++len);
dest[pos++] = *add;
}
#ifdef USE_EMSI7BIT
if( !isprint((unsigned char)*add) || (unsigned char)*add > '~' )
#else
if( !isprint((unsigned char)*add) )
#endif
{
len += 2;
dest = (char *)xrealloc(dest, len);
sprintf(&dest[pos], "\\%02hd", *(unsigned char*)add);
add += 1;
pos += 3;
}
else
dest[pos++] = *add++;
}
dest[pos] = '\0';
return(dest);
}
/* ------------------------------------------------------------------------- */
/* Add EMSI-II flag to string $source. Return pointer to reallocated string */
/* ------------------------------------------------------------------------- */
static char *add_nflag(char *source, const char *flag, int AKAn)
{
unsigned char *dest;
unsigned char buf[EMSI_MAXNFLAG+1];
int len;
sprintf(buf, "%s%d,", flag, AKAn);
len = strlen(source) + strlen(buf) + 1;
dest = (char *)xrealloc(source, len);
strcat(dest, buf);
return(dest);
}
/* ------------------------------------------------------------------------- */
/* Create emsi subpacket and return pointer to it */
/* ------------------------------------------------------------------------- */
char *emsi_createdat(s_emsi *emsi)
{
int i;
char *tmp = NULL;
char buf[100];
char abuf[BF_MAXADDRSTR+1];
tmp = (char *)xstrcpy("**EMSI_DAT0000");
/* {EMSI} indentifier
*/
if( emsi->have_emsi )
{
tmp = add_char(tmp, '{');
tmp = add_str(tmp, "EMSI");
tmp = add_char(tmp, '}');
/* our addresses, akas, etc :) */
tmp = add_char(tmp, '{');
for( i = 0; i < emsi->anum; i++ )
{
if( i ) tmp = add_char(tmp, ' ');
tmp = add_str(tmp, ftn_addrstr(abuf, emsi->addrs[i].addr));
}
tmp = add_char(tmp, '}');
/* password if avilable */
tmp = add_char(tmp, '{');
if( emsi->passwd[0] ) tmp = add_str(tmp, emsi->passwd);
tmp = add_char(tmp, '}');
/* link codes */
tmp = add_char(tmp, '{');
if( emsi->linkcodes.N81 ) tmp = add_str(tmp, "8N1,");
if( emsi->linkcodes.PUP ) tmp = add_str(tmp, "PUP,");
if( emsi->linkcodes.PUA ) tmp = add_str(tmp, "PUA,");
if( emsi->linkcodes.NPU ) tmp = add_str(tmp, "NPU,");
if( emsi->linkcodes.HAT ) tmp = add_str(tmp, "HAT,");
if( emsi->linkcodes.PMO ) tmp = add_str(tmp, "PMO,");
if( emsi->linkcodes.NFE ) tmp = add_str(tmp, "NFE,");
if( emsi->linkcodes.NXP ) tmp = add_str(tmp, "NXP,");
if( emsi->linkcodes.NRQ ) tmp = add_str(tmp, "NRQ,");
if( emsi->linkcodes.HNM ) tmp = add_str(tmp, "HNM,");
if( emsi->linkcodes.HXT ) tmp = add_str(tmp, "HXT,");
if( emsi->linkcodes.HFE ) tmp = add_str(tmp, "HFE,");
if( emsi->linkcodes.HRQ ) tmp = add_str(tmp, "HRQ,");
if( emsi->linkcodes.FNC ) tmp = add_str(tmp, "FNC,");
if( emsi->linkcodes.RMA ) tmp = add_str(tmp, "RMA,");
if( emsi->linkcodes.RH1 ) tmp = add_str(tmp, "RH1,");
for( i = 0; i < emsi->anum; i++ )
{
if( emsi->addrs[i].flags & EMSI_FLAG_PU )
tmp = add_nflag(tmp, "PU", i);
if( emsi->addrs[i].flags & EMSI_FLAG_HA )
tmp = add_nflag(tmp, "HA", i);
if( emsi->addrs[i].flags & EMSI_FLAG_PM )
tmp = add_nflag(tmp, "PM", i);
if( emsi->addrs[i].flags & EMSI_FLAG_NF )
tmp = add_nflag(tmp, "NF", i);
if( emsi->addrs[i].flags & EMSI_FLAG_NX )
tmp = add_nflag(tmp, "NX", i);
if( emsi->addrs[i].flags & EMSI_FLAG_NR )
tmp = add_nflag(tmp, "NR", i);
if( emsi->addrs[i].flags & EMSI_FLAG_HN )
tmp = add_nflag(tmp, "HN", i);
if( emsi->addrs[i].flags & EMSI_FLAG_HX )
tmp = add_nflag(tmp, "HX", i);
if( emsi->addrs[i].flags & EMSI_FLAG_HF )
tmp = add_nflag(tmp, "HF", i);
if( emsi->addrs[i].flags & EMSI_FLAG_HR )
tmp = add_nflag(tmp, "HR", i);
}
if( tmp[strlen(tmp+1)] == ',' )
{
/* replace last ',' character */
tmp[strlen(tmp+1)] = '}';
}
else
{
tmp = add_char(tmp, '}');
}
/* compatibility_codes */
tmp = add_char(tmp, '{');
if( emsi->compcodes.NCP ) tmp = add_str(tmp, "NCP,");
if( emsi->compcodes.ZMO ) tmp = add_str(tmp, "ZMO,");
if( emsi->compcodes.ZAP ) tmp = add_str(tmp, "ZAP,");
if( emsi->compcodes.DZA ) tmp = add_str(tmp, "DZA,");
if( emsi->compcodes.JAN ) tmp = add_str(tmp, "JAN,");
if( emsi->compcodes.HYD ) tmp = add_str(tmp, "HYD,");
if( emsi->compcodes.FRQ ) tmp = add_str(tmp, "FRQ,");
if( emsi->compcodes.NRQ ) tmp = add_str(tmp, "NRQ,");
if( emsi->compcodes.ARC ) tmp = add_str(tmp, "ARC,");
if( emsi->compcodes.XMA ) tmp = add_str(tmp, "XMA,");
if( emsi->compcodes.FNC ) tmp = add_str(tmp, "FNC,");
if( emsi->compcodes.EII ) tmp = add_str(tmp, "EII,");
if( emsi->compcodes.DFB ) tmp = add_str(tmp, "DFB,");
if( emsi->compcodes.CHT ) tmp = add_str(tmp, "CHT,");
if( emsi->compcodes.BBS ) tmp = add_str(tmp, "BBS,");
if( emsi->compcodes.HFR ) tmp = add_str(tmp, "HFR,");
if( tmp[strlen(tmp+1)] == ',' )
{
/* replace last ',' character */
tmp[strlen(tmp+1)] = '}';
}
else
{
tmp = add_char(tmp, '}');
}
/* mailer product code */
tmp = add_char(tmp, '{');
tmp = add_str(tmp, emsi->m_pid[0]?emsi->m_pid:"fe");
tmp = add_char(tmp, '}');
/* mailer name */
tmp = add_char(tmp, '{');
tmp = add_str(tmp, emsi->m_name[0]?emsi->m_name:"BinkleyForce");
tmp = add_char(tmp, '}');
/* mailer version */
tmp = add_char(tmp, '{');
tmp = add_str(tmp, emsi->m_ver[0]?emsi->m_ver:"X.XXX");
tmp = add_char(tmp, '}');
/* mailer serial number */
tmp = add_char(tmp, '{');
tmp = add_str(tmp, emsi->m_reg[0]?emsi->m_reg:"Freeware");
tmp = add_char(tmp, '}');
}
/* {IDENT} indentifier
*/
if( emsi->have_ident )
{
tmp = add_char(tmp, '{');
tmp = add_str(tmp, "IDENT");
tmp = add_char(tmp, '}');
tmp = add_char(tmp, '{');
tmp = add_char(tmp, '[');
if( emsi->sname[0] ) tmp = add_str(tmp, emsi->sname);
tmp = add_char(tmp, ']');
tmp = add_char(tmp, '[');
if( emsi->location[0] ) tmp = add_str(tmp, emsi->location);
tmp = add_char(tmp, ']');
tmp = add_char(tmp, '[');
if( emsi->sysop[0] ) tmp = add_str(tmp, emsi->sysop);
tmp = add_char(tmp, ']');
tmp = add_char(tmp, '[');
if( emsi->phone[0] ) tmp = add_str(tmp, emsi->phone);
tmp = add_char(tmp, ']');
tmp = add_char(tmp, '[');
if( emsi->speed )
{
sprintf(buf, "%d", emsi->speed);
tmp = add_str(tmp, buf);
}
tmp = add_char(tmp, ']');
tmp = add_char(tmp, '[');
if( emsi->flags[0] ) tmp = add_str(tmp, emsi->flags);
tmp = add_char(tmp, ']');
tmp = add_char(tmp, '}');
}
/* {TRAF} indentifier
*/
if( emsi->have_traf )
{
tmp = add_char(tmp, '{');
tmp = add_str(tmp, "TRAF");
tmp = add_char(tmp, '}');
tmp = add_char(tmp, '{');
sprintf(buf, "%08lX %08lX",
(long)emsi->netmail_size, (long)emsi->arcmail_size);
tmp = add_str(tmp, buf);
tmp = add_char(tmp, '}');
}
/* {MOH#} indentifier
*/
if( emsi->have_moh )
{
tmp = add_char(tmp, '{');
tmp = add_str(tmp, "MOH#");
tmp = add_char(tmp, '}');
tmp = add_char(tmp, '{');
tmp = add_char(tmp, '[');
sprintf(buf, "%08lX", (long)emsi->files_size);
tmp = add_str(tmp, buf);
tmp = add_char(tmp, ']');
tmp = add_char(tmp, '}');
}
/* {OHFR} indentifier
*/
if( emsi->have_ohfr )
{
tmp = add_char(tmp, '{');
tmp = add_str(tmp, "OHFR");
tmp = add_char(tmp, '}');
tmp = add_char(tmp, '{');
if( emsi->oh_time[0] )
{
tmp = add_str(tmp, emsi->oh_time);
if( emsi->fr_time[0] )
{
/* send FR time only after OH time */
tmp = add_char(tmp, ' ');
tmp = add_str(tmp, emsi->fr_time);
}
}
tmp = add_char(tmp, '}');
}
/* {TZUTC} indentifier
*/
if( emsi->have_tzutc )
{
tmp = add_char(tmp, '{');
tmp = add_str(tmp, "TZUTC");
tmp = add_char(tmp, '}');
tmp = add_char(tmp, '{');
tmp = add_char(tmp, '[');
sprintf(buf, "+%04d", emsi->tzutc);
tmp = add_str(tmp, buf);
tmp = add_char(tmp, ']');
tmp = add_char(tmp, '}');
}
/* {XDATE} indentifier.. What's the fucking invention :-/
*/
if( emsi->have_xdatetime )
{
tmp = add_char(tmp, '{');
tmp = add_str(tmp, "XDATETIME");
tmp = add_char(tmp, '}');
tmp = add_char(tmp, '{');
tmp = add_char(tmp, '[');
tmp = add_str(tmp, emsi->xdatetime);
tmp = add_char(tmp, ']');
tmp = add_char(tmp, '}');
}
/* {TRX#} indentifier
*/
if( emsi->have_trx )
{
tmp = add_char(tmp, '{');
tmp = add_str(tmp, "TRX#");
tmp = add_char(tmp, '}');
tmp = add_char(tmp, '{');
tmp = add_char(tmp, '[');
sprintf(buf, "%08lX", (long)emsi->time);
tmp = add_str(tmp, buf);
tmp = add_char(tmp, ']');
tmp = add_char(tmp, '}');
}
/*
* Write total length of <data_pkt>
*/
sprintf(buf, "%04hX", (short unsigned)strlen(tmp+14));
memcpy(tmp+10, buf, 4);
return(tmp);
}
/* ------------------------------------------------------------------------- */
/* Return substring between first pair of $from and $to characters */
/* Warning: $str destructive */
/* ------------------------------------------------------------------------- */
static char *get_field(char **str, char from, char to)
{
char *dst, *src, *dest = NULL;
int ch;
src = *str;
if( *src++ != from )
return NULL;
dst = dest = src;
while( *src )
{
if( *src == to )
{
if( *(src+1) == to )
src++;
else
break;
}
else if( *src == '\\' )
{
if( *(src+1) == '\\' )
src++;
else
{
if( strspn(src+1, "0123456789abcdefABCDEF") == 2 )
{
sscanf(src+1, "%02x", &ch);
*dst++ = (ch & 0xff);
if( ch == ']' )
*dst++ = ']';
src += 3;
continue;
}
}
}
*dst++ = *src++;
}
if( *src == '\0' )
return NULL;
*dst = '\0';
*str = src + 1;
return dest;
}
/* ------------------------------------------------------------------------- */
/* Check $p for EMSI-II link flag $name.. Such flags looks like XXn, */
/* there n is an AKA number, on success return AKA number else (-1) */
/* ------------------------------------------------------------------------- */
static int nflgcmp(const char *p, const char *name)
{
int AKAn = -1;
if( (strncmp(p, name, 2) == 0) &&
(strspn(p+2, "0123456789") == strlen(p+2)) )
{
AKAn = atoi(p+2);
}
return AKAn;
}
/* ------------------------------------------------------------------------- */
/* Parse emsi subpacket bracket by bracket. Return zero on success. */
/* All obtained information put into $emsi structure */
/* ------------------------------------------------------------------------- */
int emsi_parsedat(char *emsi_dat, s_emsi *emsi)
{
int i;
char *tmp, *p, *q, *n;
while( (tmp=get_field(&emsi_dat, '{', '}')) != NULL )
{
p = q = n = NULL;
if( strcmp(tmp, "EMSI") == 0 )
{
emsi->have_emsi = 1;
/* addresses */
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
for( p = string_token(p, &n, NULL, 0); p;
p = string_token(NULL, &n, NULL, 0) )
{
s_faddr addr;
if( ftn_addrparse(&addr, p, FALSE) )
log("unparsable address \"%s\" skipped", p);
else
session_addrs_add(&emsi->addrs, &emsi->anum, addr);
}
if( emsi->anum == 0 )
{
log("parsable addresses not found");
return(1);
}
/* password */
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
if( p && *p ) strnxcpy(emsi->passwd, p, sizeof(emsi->passwd));
/* link codes */
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
DEB((D_HSHAKE, "parse_emsidat: link codes: %s", p));
for( p = strtok(p, ","); p; p=strtok(NULL, ",") )
{
if( !strcmp(p, "PUP") ) emsi->linkcodes.PUP = 1;
else if( !strcmp(p, "PUA") ) emsi->linkcodes.PUA = 1;
else if( !strcmp(p, "NPU") ) emsi->linkcodes.NPU = 1;
else if( !strcmp(p, "HAT") ) emsi->linkcodes.HAT = 1;
else if( !strcmp(p, "PMO") ) emsi->linkcodes.PMO = 1;
else if( !strcmp(p, "NFE") ) emsi->linkcodes.NFE = 1;
else if( !strcmp(p, "NXP") ) emsi->linkcodes.NXP = 1;
else if( !strcmp(p, "NRQ") ) emsi->linkcodes.NRQ = 1;
else if( !strcmp(p, "HNM") ) emsi->linkcodes.HNM = 1;
else if( !strcmp(p, "HXT") ) emsi->linkcodes.HXT = 1;
else if( !strcmp(p, "HFE") ) emsi->linkcodes.HFE = 1;
else if( !strcmp(p, "HRQ") ) emsi->linkcodes.HRQ = 1;
else if( !strcmp(p, "FNC") ) emsi->linkcodes.FNC = 1;
else if( !strcmp(p, "RMA") ) emsi->linkcodes.RMA = 1;
else if( !strcmp(p, "RH1") ) emsi->linkcodes.RH1 = 1;
/* check EMSI-II address dependend flags */
else if( ((i=nflgcmp(p, "HA")) >= 0) && (i < emsi->anum) )
emsi->addrs[i].flags |= EMSI_FLAG_HA;
else if( ((i=nflgcmp(p, "PM")) >= 0) && (i < emsi->anum) )
emsi->addrs[i].flags |= EMSI_FLAG_PM;
else if( ((i=nflgcmp(p, "NF")) >= 0) && (i < emsi->anum) )
emsi->addrs[i].flags |= EMSI_FLAG_NF;
else if( ((i=nflgcmp(p, "NX")) >= 0) && (i < emsi->anum) )
emsi->addrs[i].flags |= EMSI_FLAG_NX;
else if( ((i=nflgcmp(p, "NR")) >= 0) && (i < emsi->anum) )
emsi->addrs[i].flags |= EMSI_FLAG_NR;
else if( ((i=nflgcmp(p, "HN")) >= 0) && (i < emsi->anum) )
emsi->addrs[i].flags |= EMSI_FLAG_HN;
else if( ((i=nflgcmp(p, "HX")) >= 0) && (i < emsi->anum) )
emsi->addrs[i].flags |= EMSI_FLAG_HX;
else if( ((i=nflgcmp(p, "HF")) >= 0) && (i < emsi->anum) )
emsi->addrs[i].flags |= EMSI_FLAG_HF;
else if( ((i=nflgcmp(p, "HR")) >= 0) && (i < emsi->anum) )
emsi->addrs[i].flags |= EMSI_FLAG_HR;
}
/* compatibility codes */
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
DEB((D_HSHAKE, "parse_emsidat: compatibility codes: %s", p));
for( p = strtok(p, ","); p; p=strtok(NULL, ",") )
{
if( !strcmp(p, "ZMO") ) emsi->compcodes.ZMO = 1;
else if( !strcmp(p, "ZAP") ) emsi->compcodes.ZAP = 1;
else if( !strcmp(p, "DZA") ) emsi->compcodes.DZA = 1;
else if( !strcmp(p, "JAN") ) emsi->compcodes.JAN = 1;
else if( !strcmp(p, "HYD") ) emsi->compcodes.HYD = 1;
else if( !strcmp(p, "NCP") ) emsi->compcodes.NCP = 1;
else if( !strcmp(p, "NRQ") ) emsi->compcodes.NRQ = 1;
else if( !strcmp(p, "ARC") ) emsi->compcodes.ARC = 1;
else if( !strcmp(p, "XMA") ) emsi->compcodes.XMA = 1;
else if( !strcmp(p, "FNC") ) emsi->compcodes.FNC = 1;
else if( !strcmp(p, "EII") ) emsi->compcodes.EII = 1;
else if( !strcmp(p, "CHT") ) emsi->compcodes.CHT = 1;
else if( !strcmp(p, "BBS") ) emsi->compcodes.BBS = 1;
else if( !strcmp(p, "HFR") ) emsi->compcodes.HFR = 1;
}
/* mailer information */
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
if( p && *p ) strnxcpy(emsi->m_pid, p, sizeof(emsi->m_pid));
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
if( p && *p ) strnxcpy(emsi->m_name, p, sizeof(emsi->m_name));
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
if( p && *p ) strnxcpy(emsi->m_ver, p, sizeof(emsi->m_ver));
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
if( p && *p ) strnxcpy(emsi->m_reg, p, sizeof(emsi->m_reg));;
}
else if( strcmp(tmp, "IDENT") == 0 )
{
emsi->have_ident = 1;
if( (tmp=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
if( (p=get_field(&tmp, '[', ']')) == NULL ) return(1);
if( p && *p ) strnxcpy(emsi->sname, p, sizeof(emsi->sname));
if( (p=get_field(&tmp, '[', ']')) == NULL ) return(1);
if( p && *p ) strnxcpy(emsi->location, p, sizeof(emsi->location));
if( (p=get_field(&tmp, '[', ']')) == NULL ) return(1);
if( p && *p ) strnxcpy(emsi->sysop, p, sizeof(emsi->sysop));
if( (p=get_field(&tmp, '[', ']')) == NULL ) return(1);
if( p && *p ) strnxcpy(emsi->phone, p, sizeof(emsi->phone));;
if( (p=get_field(&tmp, '[', ']')) == NULL ) return(1);
if( p && *p ) sscanf(p, "%d", &emsi->speed);
if( (p=get_field(&tmp, '[', ']')) == NULL ) return(1);
if( p && *p ) strnxcpy(emsi->flags, p, sizeof(emsi->flags));
}
else if( strcmp(tmp, "TRX#") == 0 )
{
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
if( (p=get_field(&p, '[', ']')) == NULL ) return(1);
if( sscanf(p, "%08lx", &emsi->time) == 1 )
{
emsi->have_trx = 1;
}
else
{
log("Bad TRX# entry \"%s\"", p);
}
}
else if( strcmp(tmp, "TRAF") == 0 )
{
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
if( p && *p )
{
if( sscanf(p, "%08X %08X", &emsi->netmail_size, &emsi->arcmail_size) == 2 )
{
emsi->have_traf = 1;
}
else
{
log("Bad TRAF entry \"%s\"", p);
}
}
}
else if( strcmp(tmp, "MOH#") == 0 )
{
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
if( (p=get_field(&p, '[', ']')) == NULL ) return(1);
if( p && *p )
{
if( sscanf(p, "%08X", &emsi->files_size) == 1 )
{
emsi->have_moh = 1;
}
else
{
log("Bad MOH# entry \"%s\"", p);
}
}
else
{
log("Bad MOH# entry \"%s\"", p);
}
}
else if( strcmp(tmp, "OHFR") == 0 )
{
emsi->have_ohfr = 1;
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
q = p;
while( *q && !isspace(*q) ) q++;
if( *q ) *q++ = '\0';
if( *p ) strnxcpy(emsi->oh_time, p, sizeof(emsi->oh_time));
while( *q && isspace(*q) ) q++;
if( *q ) strnxcpy(emsi->fr_time, q, sizeof(emsi->fr_time));
}
else if( strcmp(tmp, "XDATETIME") == 0 )
{
emsi->have_xdatetime = 1;
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
if( (p=get_field(&p, '[', ']')) == NULL ) return(1);
if( *p ) strnxcpy(emsi->xdatetime, p, sizeof(emsi->xdatetime));
}
else if( strcmp(tmp, "TZUTC") == 0 )
{
emsi->have_tzutc = 1;
if( (p=get_field(&emsi_dat, '{', '}')) == NULL ) return(1);
if( (p=get_field(&p, '[', ']')) == NULL ) return(1);
}
else
{
strnxcat(emsi->addons, "{", sizeof(emsi->addons));
strnxcat(emsi->addons, tmp, sizeof(emsi->addons));
strnxcat(emsi->addons, "}", sizeof(emsi->addons));
}
} /* end of while */
return(0);
}
void emsi_logdat(s_emsi *emsi)
{
int i;
char abuf[BF_MAXADDRSTR+1];
char buf[64];
if( emsi->have_emsi )
{
if( emsi->anum )
{
for( i = 0; i < emsi->anum; i++ )
{
if( emsi->addrs[i].busy )
log(" Address : %s (Busy)", ftn_addrstr(abuf, emsi->addrs[i].addr));
else
log(" Address : %s", ftn_addrstr(abuf, emsi->addrs[i].addr));
}
}
else
{
log(" Address : <none>");
}
}
if( emsi->have_ident )
{
if( emsi->sname[0] && emsi->phone[0] )
log(" System : %s (%s)",
string_printable(emsi->sname),
string_printable(emsi->phone));
else if( emsi->sname[0] )
log(" System : %s",
string_printable(emsi->sname));
else if( emsi->phone[0] )
log(" Phone : %s",
string_printable(emsi->phone));
}
if( emsi->have_emsi )
{
char flags[128];
*flags = '\0';
if( emsi->linkcodes.PUP )
strcat(flags, "PUP,");
if( emsi->linkcodes.NPU )
strcat(flags, "NPU,");
if( emsi->linkcodes.HAT )
strcat(flags, "HAT,");
if( emsi->linkcodes.NRQ || emsi->compcodes.NRQ )
strcat(flags, "NRQ,");
if( emsi->linkcodes.HXT )
strcat(flags, "HXT,");
if( emsi->linkcodes.HRQ )
strcat(flags, "HRQ,");
if( emsi->linkcodes.FNC || emsi->compcodes.FNC )
strcat(flags, "FNC,");
if( emsi->compcodes.FRQ )
strcat(flags, "FRQ,");
if( emsi->compcodes.EII )
strcat(flags, "EII,");
if( emsi->compcodes.CHT )
strcat(flags, "CHT,");
if( emsi->compcodes.BBS )
strcat(flags, "BBS,");
if( emsi->compcodes.HFR )
strcat(flags, "HFR,");
if( *flags )
{
flags[strlen(flags)-1] = '\0';
log(" Options : %s", flags);
}
}
#ifdef BFORCE_LOG_PASSWD
if( emsi->have_emsi )
{
if( emsi->passwd[0] )
log(" Password : %s", string_printable(emsi->passwd));
}
#endif
if( emsi->have_ident )
{
if( emsi->sysop[0] && emsi->location[0] )
log(" SysOp : %s from %s",
string_printable(emsi->sysop),
string_printable(emsi->location));
else if( emsi->sysop[0] )
log(" SysOp : %s",
string_printable(emsi->sysop));
else if( emsi->location[0] )
log(" Location : %s",
string_printable(emsi->location));
if( emsi->flags[0] && emsi->speed )
log(" Flags : %d,%s",
emsi->speed, string_printable(emsi->flags));
else if( emsi->flags[0] )
log(" Flags : %s",
string_printable(emsi->flags));
else if( emsi->speed )
log(" Speed : %d", emsi->speed);
}
if( emsi->have_emsi )
{
if( emsi->m_name[0] || emsi->m_pid[0]
|| emsi->m_ver[0] || emsi->m_reg )
{
log(" Mailer : %s [%s] %s/%s",
emsi->m_name[0] ? string_printable(emsi->m_name) : "?",
emsi->m_pid[0] ? string_printable(emsi->m_pid) : "?",
emsi->m_ver[0] ? string_printable(emsi->m_ver) : "?",
emsi->m_reg[0] ? string_printable(emsi->m_reg) : "?");
}
}
if( emsi->have_trx )
{
log(" Time : %s", time_string_long(buf, sizeof(buf), gmttolocal(emsi->time)));
}
if( emsi->have_xdatetime )
{
log(" XDATETIME : %s", string_printable(emsi->xdatetime));
}
if( emsi->have_ohfr )
{
log(" OHFR : \"%s\" and \"%s\"",
string_printable(emsi->oh_time),
string_printable(emsi->fr_time));
}
if( emsi->have_traf )
{
log(" TRAF : netmail %ldb, arcmail %ldb",
emsi->netmail_size, emsi->arcmail_size);
}
if( emsi->have_moh )
{
log(" #MOH : files %ldb", emsi->files_size);
}
if( emsi->addons[0] )
{
log("EMSI addon : %s",
string_printable(emsi->addons));
}
}
File diff suppressed because it is too large Load Diff
+15
View File
@@ -0,0 +1,15 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
+15
View File
@@ -0,0 +1,15 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
+591
View File
@@ -0,0 +1,591 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "session.h"
#include "prot_yoohoo.h"
typedef enum {
YS_Init,
YS_SendHello,
YS_WaitResp,
YS_Done,
YS_Error
} YooHoo_SendState;
typedef enum {
YR_Init,
YR_SendENQ,
YR_WaitHeader,
YR_TossJunk,
YR_RecvHello,
YR_SendNAK,
YR_SendACK,
YR_Done,
YR_Error
} YooHoo_RecvState;
static char *yoohoo_putword(char *buf, int val)
{
buf[0] = ( ((unsigned int) val) ) & 0xff;
buf[1] = ( ((unsigned int) val) >> 8 ) & 0xff;
return buf + 2;
}
static int yoohoo_getword(const char *buf)
{
return ( (unsigned int) ((unsigned char) buf[0]) )
| ( (unsigned int) ((unsigned char) buf[1]) << 8 );
}
/*****************************************************************************
* Make ``hello'' packet from the yoohoo sysinfo structure and put
* it to the buffer
*
* Arguments:
* buffer pointer to the destination buffer (must be at least
* 128 bytes)
* hello structure with the YooHoo system information
*
* Return value:
* None
*/
static void yoohoo_put_hello(char *buffer, s_yoohoo_sysinfo *hello)
{
char *p, *q;
ASSERT(buffer && hello);
memset(buffer, '\0', YOOHOO_HELLOLEN);
p = buffer;
p = yoohoo_putword(p, 0x6f);
p = yoohoo_putword(p, 0x01); /* Hello version */
p = yoohoo_putword(p, hello->product_code); /* Product code */
p = yoohoo_putword(p, hello->version_maj); /* Major version */
p = yoohoo_putword(p, hello->version_min); /* Minor version */
strnxcpy(p, hello->system, 60); /* Node name */
/*
* Add domain after the end of 'Node name'
* TODO: check it for buffer overflows %-I
*/
if( hello->anum > 0 && hello->addrs[0].addr.domain
&& *hello->addrs[0].addr.domain )
{
char *q;
if( strlen(hello->system) + strlen(hello->addrs[0].addr.domain) > 57 )
{
if( strlen(hello->addrs[0].addr.domain) < 60 )
q = p + (60 - strlen(hello->addrs[0].addr.domain));
else
q = p;
*q++ = '\0';
}
else
{
q = p + strlen(hello->system) + 1;
}
strnxcpy(q, hello->addrs[0].addr.domain, 60-(q-p));
}
p += 60;
strnxcpy(p, hello->sysop, 20); /* SysOp name */
p += 20;
if( hello->anum > 0 )
{
p = yoohoo_putword(p, hello->addrs[0].addr.zone);
p = yoohoo_putword(p, hello->addrs[0].addr.net);
p = yoohoo_putword(p, hello->addrs[0].addr.node);
p = yoohoo_putword(p, hello->addrs[0].addr.point);
}
else
p += 8;
strncpy(p, hello->passwd, 8); /* Session password */
p += 8;
p += 8; /* Reserved 8 bytes */
p = yoohoo_putword(p, hello->capabilities); /* Capabilities */
p += 12; /* Reserved 12 bytes */
#ifdef DEBUG
DEB((D_HSHAKE, "yoohoo_put_hello: HELLO dump: \"%s\"",
q = string_printable_buffer(buffer, 128)));
if( q ) free(q);
#endif
ASSERT((p - buffer) == YOOHOO_HELLOLEN);
}
/*****************************************************************************
* Extract session information from the ``hello'' packet
*
* Arguments:
* hello pointer to the destination structure with the session
* information
* buffer source buffer with ``hello'' packet
*
* Return value:
* None
*/
static int yoohoo_get_hello(s_yoohoo_sysinfo *hello, const char *buffer)
{
s_faddr addr;
ASSERT(buffer && hello);
#ifdef DEBUG
{
char *q = string_printable_buffer(buffer, YOOHOO_HELLOLEN);
DEB((D_HSHAKE, "yoohoo_get_hello: HELLO dump: \"%s\"", q));
if( q ) free(q);
}
#endif
memset(hello, '\0', sizeof(s_yoohoo_sysinfo));
if( yoohoo_getword(buffer+2) != 0x01 )
log("YooHoo hello version is %d!", yoohoo_getword(buffer+2));
hello->product_code = yoohoo_getword(buffer+4);
hello->version_maj = yoohoo_getword(buffer+6);
hello->version_min = yoohoo_getword(buffer+8);
strnxcpy(hello->system, buffer+10, MIN(sizeof(hello->system),60+1));
strnxcpy(hello->sysop, buffer+70, MIN(sizeof(hello->sysop),20+1));
/*
* Extract address
*/
memset(&addr, '\0', sizeof(s_faddr));
addr.zone = yoohoo_getword(buffer+90);
addr.net = yoohoo_getword(buffer+92);
addr.node = yoohoo_getword(buffer+94);
addr.point = yoohoo_getword(buffer+96);
session_addrs_add(&hello->addrs, &hello->anum, addr);
strnxcpy(hello->passwd, buffer+98, MIN(sizeof(hello->passwd),8+1));
/* Reserved 8 bytes */
hello->capabilities = yoohoo_getword(buffer+114);
/* Reserved 12 bytes */
return 0;
}
int yoohoo_send_hello(s_yoohoo_sysinfo *local_data)
{
char hello_buffer[YOOHOO_HELLOLEN];
unsigned short hello_crc = 0;
YooHoo_SendState state = YS_Init;
time_t wait_timer;
int tries = 0;
int rc;
ASSERT(local_data);
while(1)
{
switch(state) {
case YS_Init:
tries = 0;
yoohoo_put_hello(hello_buffer, local_data);
hello_crc = getcrc16xmodem(hello_buffer, YOOHOO_HELLOLEN);
state = YS_SendHello;
break;
case YS_SendHello:
if( ++tries > 10 )
{
log("too many tries sending hello");
state = YS_Error;
break;
}
else if( tries > 1 )
log("yoohoo hello send - retry %d", tries);
if( PUTCHAR(0x1f) < 0
|| WRITE_TIMEOUT(hello_buffer, sizeof(hello_buffer)) < 0
|| PUTCHAR(((unsigned int) hello_crc >> 8) & 0xff) < 0
|| PUTCHAR(((unsigned int) hello_crc ) & 0xff) < 0 )
{
state = YS_Error;
break;
}
timer_set(&wait_timer, 40);
state = YS_WaitResp;
break;
case YS_WaitResp:
if( timer_expired(wait_timer) )
{
log("time out waiting for response");
state = YS_Error;
break;
}
if( (rc = GETCHAR(1)) < 0 )
{
if( rc != TTY_TIMEOUT )
{
state = YS_Error;
break;
}
}
else if( rc == XON || rc == XOFF )
{
/* Do nothing. Drop them down */
}
else if( rc == '?' || rc == ENQ )
{
if( rc == '?' )
log("remote failed to receive our HELLO packet");
state = YS_SendHello;
}
else if( rc == ACK )
{
state = YS_Done;
}
break;
case YS_Done:
return 0;
case YS_Error:
return -1;
}
}
return -1; /* UNREACHABLE */
}
int yoohoo_recv_hello(s_yoohoo_sysinfo *remote_data)
{
char hello_buffer[YOOHOO_HELLOLEN];
int crc_local = 0;
int crc_remote = 0;
YooHoo_RecvState state = YR_Init;
time_t wait_timer;
time_t junk_timer;
int hello_pos;
int tries = 0;
int rc;
ASSERT(remote_data);
while(1)
{
switch(state) {
case YR_Init:
tries = 0;
memset(hello_buffer, '\0', sizeof(hello_buffer));
state = YR_SendENQ;
break;
case YR_SendENQ:
if( ++tries > 3 )
{
log("too many tries receiving hello");
state = YR_Error;
break;
}
else if( tries > 1 )
log("yoohoo hello recv - retry %d", tries);
if( PUTCHAR(ENQ) < 0 )
{
state = YR_Error;
break;
}
timer_set(&wait_timer, 120);
state = YR_WaitHeader;
break;
case YR_WaitHeader:
if( timer_expired(wait_timer) )
{
log("time out waiting for response");
state = YR_Error;
break;
}
if( (rc = GETCHAR(1)) < 0 )
{
if( rc != TTY_TIMEOUT )
{
state = YR_Error;
break;
}
}
else if( rc == XON || rc == XOFF )
{
/* Do nothing. Drop them down */
}
else if( rc == 0x1f )
{
state = YR_RecvHello;
}
else
{
timer_set(&junk_timer, 10);
state = YR_TossJunk;
}
break;
case YR_TossJunk:
if( timer_expired(junk_timer) )
{
state = YR_SendENQ;
break;
}
if( (rc = GETCHAR(1)) < 0 )
{
if( rc != TTY_TIMEOUT )
{
state = YR_Error;
break;
}
}
else if( rc == XON || rc == XOFF )
{
/* Do nothing. Drop them down */
}
else if( rc == 0x1f )
{
state = YR_RecvHello;
}
break;
case YR_RecvHello:
hello_pos = 0;
while( (rc = GETCHAR(30)) >= 0 )
{
if( hello_pos < 128 )
{
hello_buffer[hello_pos++] = rc;
}
else if( hello_pos == 128 )
{
crc_remote = ((unsigned int) ((unsigned char) rc) << 8);
++hello_pos;
}
else if( hello_pos == 129 )
{
crc_remote |= (unsigned int) ((unsigned char) rc);
break;
}
else
break;
}
if( hello_pos != 129 )
{
state = YR_Error;
break;
}
/*
* Check CRC-16
*/
crc_local = getcrc16xmodem(hello_buffer, sizeof(hello_buffer));
if( crc_local != crc_remote )
{
log("got hello packet with incorrect checksum");
state = YR_SendNAK;
break;
}
if( yoohoo_get_hello(remote_data, hello_buffer) )
{
log("got invalid hello packet");
state = YR_SendNAK;
}
else
state = YR_SendACK;
break;
case YR_SendNAK:
if( PUTCHAR('?') < 0 )
state = YR_Error;
else
state = YR_WaitHeader;
break;
case YR_SendACK:
if( PUTCHAR(ACK) < 0 )
state = YR_Error;
else
state = YR_Done;
break;
case YR_Done:
return 0;
case YR_Error:
return -1;
}
}
return -1; /* UNREACHABLE */
}
void yoohoo_set_sysinfo(s_yoohoo_sysinfo *local_data, int hrc,
e_protocol protocol)
{
s_cval_entry *addr_ptr;
s_faddr *primary = NULL;
const long options = conf_options(cf_options);
const char *p_system = conf_string(cf_system_name);
const char *p_sysop = conf_string(cf_sysop_name);
memset(local_data, '\0', sizeof(s_yoohoo_sysinfo));
/* Set best primary address */
primary = session_get_bestaka(state.node.addr);
/*
* Set our local address
*/
if( primary )
session_addrs_add(&local_data->addrs, &local_data->anum, *primary);
else if( (addr_ptr = conf_first(cf_address)) )
session_addrs_add(&local_data->addrs, &local_data->anum, addr_ptr->d.falist.addr);
if( !local_data->anum )
log("warning: no addresses will be presented to remote");
/*
* Set session password
*/
if( state.caller )
{
session_get_password(state.node.addr,
local_data->passwd, sizeof(local_data->passwd));
}
else if( hrc == HRC_OK )
{
/* Satisfy remote with their password */
const char *p = state.handshake->remote_password(state.handshake);
if( p )
strnxcpy(local_data->passwd, p, sizeof(local_data->passwd));
}
if( !state.caller )
{
if( state.reqstat != REQS_ALLOW )
local_data->capabilities |= YOOHOO_WZ_FREQ;
}
/* compatibility codes */
if( state.caller )
{
if( (options & OPTIONS_NO_ZMODEM) != OPTIONS_NO_ZMODEM )
local_data->capabilities |= YOOHOO_ZMODEM;
if( (options & OPTIONS_NO_ZEDZAP) != OPTIONS_NO_ZEDZAP )
local_data->capabilities |= YOOHOO_ZEDZAP;
if( (options & OPTIONS_NO_JANUS) != OPTIONS_NO_JANUS )
local_data->capabilities |= YOOHOO_JANUS;
if( (options & OPTIONS_NO_HYDRA) != OPTIONS_NO_HYDRA )
local_data->capabilities |= YOOHOO_HYDRA;
}
else
{
switch(protocol) {
case PROT_ZMODEM: local_data->capabilities |= YOOHOO_ZMODEM; break;
case PROT_ZEDZAP: local_data->capabilities |= YOOHOO_ZEDZAP; break;
case PROT_JANUS: local_data->capabilities |= YOOHOO_JANUS; break;
case PROT_HYDRA: local_data->capabilities |= YOOHOO_HYDRA; break;
default: break;
}
}
local_data->product_code = BF_PRODCODE;
if( hrc == HRC_BAD_PASSWD )
{
local_data->version_maj = 99;
local_data->version_min = 99; /* TODO */
}
else
{
local_data->version_maj = 0;
local_data->version_min = 1;
}
strnxcpy(local_data->sysop, p_sysop ? p_sysop : "Unknown", sizeof(local_data->sysop));
switch(hrc) {
case HRC_BAD_PASSWD:
strnxcpy(local_data->system, "Bad password", sizeof(local_data->system));
break;
case HRC_LOW_SPEED:
strnxcpy(local_data->system, "Connect speed too low", sizeof(local_data->system));
break;
case HRC_BUSY:
strnxcpy(local_data->system, "All AKAs are busy", sizeof(local_data->system));
break;
default:
strnxcpy(local_data->system, p_system ? p_system : "Unknown", sizeof(local_data->system));
}
}
/*****************************************************************************
* Write system information to the log
*
* Arguments:
* yoohoo structure with the system information
*
* Return value:
* None
*/
void yoohoo_log_sysinfo(s_yoohoo_sysinfo *yoohoo)
{
int i;
char abuf[BF_MAXADDRSTR+1];
if( yoohoo->anum )
for( i = 0; i < yoohoo->anum; i++ )
{
log(" Address : %s", ftn_addrstr(abuf, yoohoo->addrs[i].addr));
}
else
log(" Address : <none>");
if( yoohoo->system[0] )
log(" System : %s", string_printable(yoohoo->system));
#ifdef BFORCE_LOG_PASSWD
if( yoohoo->passwd[0] )
log(" Password : %s", string_printable(yoohoo->passwd));
#endif
if( yoohoo->sysop[0] )
log(" SysOp : %s", string_printable(yoohoo->sysop));
if( yoohoo->product_code || yoohoo->version_maj || yoohoo->version_min )
{
log(" Mailer : %s [%02x] %d.%d",
"?", yoohoo->product_code,
yoohoo->version_maj, yoohoo->version_min);
}
}
+363
View File
@@ -0,0 +1,363 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "version.h"
#include "logger.h"
#include "util.h"
#include "nodelist.h"
#include "session.h"
#include "prot_yoohoo.h"
void yoohoo_init(s_handshake_protocol *THIS);
void yoohoo_deinit(s_handshake_protocol *THIS);
int yoohoo_incoming(s_handshake_protocol *THIS);
int yoohoo_outgoing(s_handshake_protocol *THIS);
s_faddr *yoohoo_remote_address(s_handshake_protocol *THIS);
char *yoohoo_remote_password(s_handshake_protocol *THIS);
char *yoohoo_remote_sysop_name(s_handshake_protocol *THIS);
char *yoohoo_remote_system_name(s_handshake_protocol *THIS);
char *yoohoo_remote_location(s_handshake_protocol *THIS);
char *yoohoo_remote_phone(s_handshake_protocol *THIS);
char *yoohoo_remote_flags(s_handshake_protocol *THIS);
char *yoohoo_remote_mailer(s_handshake_protocol *THIS);
s_faddr *yoohoo_local_address(s_handshake_protocol *THIS);
char *yoohoo_local_password(s_handshake_protocol *THIS);
s_handshake_protocol handshake_protocol_yoohoo = {
/* Section 1 */
"YooHoo",
"",
"",
NULL,
NULL,
0,
yoohoo_init,
yoohoo_deinit,
yoohoo_incoming,
yoohoo_outgoing,
/* Section 2 */
yoohoo_remote_address,
yoohoo_remote_password,
yoohoo_remote_sysop_name,
yoohoo_remote_system_name,
NULL,
NULL,
NULL,
NULL,
NULL,
/* Section 3 */
yoohoo_local_address,
yoohoo_local_password
};
void yoohoo_init(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data == NULL);
ASSERT(THIS->local_data == NULL);
THIS->remote_data = (char *)xmalloc(sizeof(s_yoohoo_sysinfo));
THIS->local_data = (char *)xmalloc(sizeof(s_yoohoo_sysinfo));
memset(THIS->remote_data, '\0', sizeof(s_yoohoo_sysinfo));
memset(THIS->local_data, '\0', sizeof(s_yoohoo_sysinfo));
}
void yoohoo_deinit(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
ASSERT(THIS->local_data);
if( THIS->remote_data )
{
memset(THIS->remote_data, '\0', sizeof(s_yoohoo_sysinfo));
free(THIS->remote_data);
}
if( THIS->local_data )
{
memset(THIS->local_data, '\0', sizeof(s_yoohoo_sysinfo));
free(THIS->local_data);
}
}
int yoohoo_incoming(s_handshake_protocol *THIS)
{
int rc = HRC_OK;
s_yoohoo_sysinfo *remote_data = NULL;
s_yoohoo_sysinfo *local_data = NULL;
ASSERT(THIS);
ASSERT(THIS->remote_data);
ASSERT(THIS->local_data);
remote_data = (s_yoohoo_sysinfo *)THIS->remote_data;
local_data = (s_yoohoo_sysinfo *)THIS->local_data;
if( yoohoo_recv_hello(remote_data) )
return HRC_OTHER_ERR;
/*
* Check password(s)
*/
if( session_addrs_check(remote_data->addrs, remote_data->anum,
remote_data->passwd, NULL, 0) )
{
rc = HRC_BAD_PASSWD;
/* Don't return. Send HELLO with
* invalid password messages */
}
else
{
/* Lock (create BSY) remote addresses */
if( session_addrs_lock(remote_data->addrs,
remote_data->anum) )
{
log("all remote addresses are busy");
rc = HRC_BUSY;
}
else
{
/*
* Fill state.node with a first valid
* address, try to lookup it in nodelist
*/
session_remote_lookup(remote_data->addrs, remote_data->anum);
if( session_check_speed() )
rc = HRC_LOW_SPEED;
}
}
/*
* Put HELLO information to the log
*/
(void)yoohoo_log_sysinfo(remote_data);
session_remote_log_status();
if( rc == HRC_OK )
{
const long options = conf_options(cf_options);
/*
* Set inbound directories, ignore errors,
* because we want send mail in any case.
*/
(void)session_set_inbound();
/*
* Set protocol that we will use
*/
if( (remote_data->capabilities & YOOHOO_HYDRA)
&& !(options & OPTIONS_NO_HYDRA) )
THIS->protocol = PROT_HYDRA;
else if( (remote_data->capabilities & YOOHOO_ZEDZAP)
&& !(options & OPTIONS_NO_ZEDZAP) )
THIS->protocol = PROT_ZEDZAP;
else if( (remote_data->capabilities & YOOHOO_ZMODEM)
&& !(options & OPTIONS_NO_ZMODEM) )
THIS->protocol = PROT_ZMODEM;
else /* NCP */
{
THIS->protocol = PROT_NOPROT;
rc = HRC_NO_PROTOS;
}
/*
* Create mail/files queue
*/
session_create_files_queue(remote_data->addrs, remote_data->anum);
/*
* Set FREQ processor status
*/
if( rc == HRC_OK && THIS->protocol != PROT_NOPROT )
session_set_freqs_status();
else
state.reqstat = REQS_DISABLED;
}
/*
* Prepare ``local_data'' structure
*/
(void)yoohoo_set_sysinfo(local_data, rc, THIS->protocol);
if( yoohoo_send_hello(local_data) && rc == HRC_OK )
rc = HRC_OTHER_ERR;
return rc;
}
int yoohoo_outgoing(s_handshake_protocol *THIS)
{
s_yoohoo_sysinfo *remote_data = NULL;
s_yoohoo_sysinfo *local_data = NULL;
ASSERT(THIS);
ASSERT(THIS->remote_data);
ASSERT(THIS->local_data);
remote_data = (s_yoohoo_sysinfo *)THIS->remote_data;
local_data = (s_yoohoo_sysinfo *)THIS->local_data;
/*
* Set FREQ processor status
*/
session_set_freqs_status();
/*
* Prepare ``local_data'' structure
*/
(void)yoohoo_set_sysinfo(local_data, HRC_OK, THIS->protocol);
if( yoohoo_send_hello(local_data) )
return HRC_OTHER_ERR;
if( yoohoo_recv_hello(remote_data) )
return HRC_OTHER_ERR;
/*
* Put EMSI information to the log
*/
(void)yoohoo_log_sysinfo(remote_data);
/*
* Make sure expected address was presented
*/
if( session_addrs_check_genuine(remote_data->addrs,
remote_data->anum,
state.node.addr) )
return HRC_NO_ADDRESS;
/*
* Check password(s)
*/
if( session_addrs_check(remote_data->addrs, remote_data->anum,
remote_data->passwd, NULL, 0) )
return HRC_BAD_PASSWD;
/*
* Lock (create BSY) remote addresses
*/
(void)session_addrs_lock(remote_data->addrs,
remote_data->anum);
/*
* Set protocol we will use ("options" ignored)
*/
if( remote_data->capabilities & YOOHOO_HYDRA )
THIS->protocol = PROT_HYDRA;
else if( remote_data->capabilities & YOOHOO_JANUS )
THIS->protocol = PROT_JANUS;
else if( remote_data->capabilities & YOOHOO_ZEDZAP )
THIS->protocol = PROT_ZEDZAP;
else if( remote_data->capabilities & YOOHOO_ZMODEM )
THIS->protocol = PROT_ZMODEM;
else
return HRC_NO_PROTOS;
/*
* Show remote status (prot/unprot, listed/unlisted)
*/
session_remote_log_status();
/*
* Set inbound directories
*/
if( session_set_inbound() )
return HRC_OTHER_ERR;
/*
* Check EMSI flags and set corresponding local HOLD flags
*/
(void)session_set_send_options();
/*
* Create mail/files queue
*/
session_create_files_queue(remote_data->addrs,
remote_data->anum);
return HRC_OK;
}
s_faddr *yoohoo_remote_address(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_yoohoo_sysinfo *)THIS->remote_data)->anum > 0 )
return &((s_yoohoo_sysinfo *)THIS->remote_data)->addrs[0].addr;
return NULL;
}
char *yoohoo_remote_password(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_yoohoo_sysinfo *)THIS->remote_data)->passwd[0] )
return ((s_yoohoo_sysinfo *)THIS->remote_data)->passwd;
return NULL;
}
char *yoohoo_remote_sysop_name(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_yoohoo_sysinfo *)THIS->remote_data)->sysop[0] )
return ((s_yoohoo_sysinfo *)THIS->remote_data)->sysop;
return NULL;
}
char *yoohoo_remote_system_name(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->remote_data);
if( ((s_yoohoo_sysinfo *)THIS->remote_data)->system[0] )
return ((s_yoohoo_sysinfo *)THIS->remote_data)->system;
return NULL;
}
s_faddr *yoohoo_local_address(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->local_data);
if( ((s_yoohoo_sysinfo *)THIS->local_data)->anum > 0 )
return &((s_yoohoo_sysinfo *)THIS->local_data)->addrs[0].addr;
return NULL;
}
char *yoohoo_local_password(s_handshake_protocol *THIS)
{
ASSERT(THIS);
ASSERT(THIS->local_data);
if( ((s_yoohoo_sysinfo *)THIS->local_data)->passwd[0] )
return ((s_yoohoo_sysinfo *)THIS->local_data)->passwd;
return NULL;
}
File diff suppressed because it is too large Load Diff
+561
View File
@@ -0,0 +1,561 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "session.h"
#include "outbound.h"
#include "io.h"
#include "prot_common.h"
#include "prot_zmodem.h"
typedef enum zrxstates {
ZRX_INIT, /* Send ZRINIT frame -> goto ZRX_INITACK */
ZRX_INITACK, /* Wait for answer on ZRINIT (for ZRQINIT?) */
ZRX_GOTFILE, /* We got ZFINFO -> check it, open, etc.. */
ZRX_SENDRPOS, /* Send position we want receive file from */
ZRX_RPOSACK, /* Wait for answer on (ZRPOS) our postion */
ZRX_WAITDATA, /* And wait for data block with file's data */
ZRX_REFUSE, /* Feee... Refuse this file */
ZRX_SKIP /* Burn baby.. burn.. skip it! */
} e_zrxstates;
static void zmodem_puts(const char *s);
static int zmodem_proc_ZFILE(s_protinfo *pi, char *blkptr, size_t blklen);
/* ------------------------------------------------------------------------- */
/* Receive files with Z-Modem protocol */
/* Return: */
/* PRC_SUCCESSFUL: All files received or transfer was finished cleanly */
/* PRC_ERROR: Error at sending something(include carrier lost) */
/* PRC_ERROR: Error at receiving something(include carrier lost) */
/* PRC_MERROR: Misc. errors (i.e. incompatibilies, failures, etc) */
/* PRC_TRIESOUT: Very many tries doing something without result */
/* PRC_REMOTEDEAD: For a long time no real information transfered */
/* PRC_REMOTEABORT: Transfer was aborted by remote (i.e. five CAN, etc..) */
/* PRC_LOCALBORT: Transfer was aborted by local (i.e. CPS too low, etc..) */
/* ------------------------------------------------------------------------- */
int rx_zmodem(s_protinfo *pi, bool caller)
{
char zconv; /* ZMODEM file conversion request */
char zmanag; /* ZMODEM file management request */
char ztrans; /* ZMODEM file transport request */
char zexten; /* ZMODEM file extended options */
char *rxbuf; /* Buffer with ZMAXBLOCKLEN size */
int zrqinitcnt; /* Count received ZRQINITs */
int zfincnt; /* Count received ZFINs (in state ZTX_INITACK) */
int inithdrtype; /* Send this header at ZRX_INIT state */
int txtries = 0;
int skipbypos = 0;
int ftype = 0;
enum zrxstates rxstate;
time_t deadtimer;
int rc = PRC_NOERROR;
int n, c;
log("start %s receive", Protocols[state.handshake->protocol]);
DEB((D_PROT, "start %s receive", Protocols[state.handshake->protocol]));
if( pi->start_time == 0 )
pi->start_time = time(NULL);
skipbypos = conf_boolean(cf_zmodem_skip_by_pos);
rxbuf = (char *)xmalloc(ZMAXBLOCKLEN+1);
zrqinitcnt = 0;
zfincnt = 0;
inithdrtype = ZRINIT;
Z_Rxwait = ZWAITTIME;
Z_Rxtout = ZRXTIMEOUT;
rxstate = ZRX_INIT;
setalarm(Z_Rxtout);
timer_set(&deadtimer, ZDEADTIMER);
while(1)
{
if( timer_expired(deadtimer) )
{
DEB((D_PROT, "rx_zmodem: deadtimer = %ld", (long)deadtimer));
DEB((D_PROT, "rx_zmodem: rxstate = %d", (int)rxstate));
DEB((D_PROT, "rx_zmodem: rc = %d", rc));
DEB((D_PROT, "rx_zmodem: txtries = %d", txtries));
log("brain dead! (abort)");
gotoexit(PRC_LOCALABORTED);
}
if( rxstate == ZRX_INIT || rxstate == ZRX_SENDRPOS )
{
if( ++txtries > ZMAXTRIES )
{
log("tries reached miximal count");
gotoexit(PRC_LOCALABORTED);
}
}
switch(rxstate) {
case ZRX_INIT:
DEB((D_PROT, "rx_zmodem: entering state ZRX_INIT"));
stohdr(Z_Txhdr, 0L);
Z_Txhdr[ZF0] = CANFC32|CANFDX|CANOVIO|CANBRK;
if( Z_Ctlesc )
Z_Txhdr[ZF0] |= TESCCTL;
if( zshhdr(inithdrtype, Z_Txhdr) < 0 )
gotoexit(PRC_ERROR);
if( inithdrtype == ZSKIP )
inithdrtype = ZRINIT;
setalarm(Z_Rxtout);
rxstate = ZRX_INITACK;
break;
case ZRX_GOTFILE:
DEB((D_PROT, "rx_zmodem: entering state ZRX_GOTFILE"));
if( pi->recv && pi->recv->fp )
p_rx_fclose(pi);
switch(zmodem_proc_ZFILE(pi, rxbuf, Z_Rxcount)) {
case 0:
txtries = 0;
rxstate = ZRX_SENDRPOS;
break;
case 2:
rxstate = ZRX_SKIP;
break;
default:
rxstate = ZRX_REFUSE;
break;
}
break;
case ZRX_SENDRPOS:
DEB((D_PROT, "rx_zmodem: entering state ZRX_SENDRPOS"));
stohdr(Z_Txhdr, pi->recv->bytes_received);
if( zshhdr(ZRPOS, Z_Txhdr) < 0 )
gotoexit(PRC_ERROR);
setalarm(Z_Rxtout);
rxstate = ZRX_RPOSACK;
break;
case ZRX_WAITDATA:
DEB((D_PROT, "rx_zmodem: entering state ZRX_WAITDATA"));
if( (rc = p_info(pi, 0)) )
gotoexit(rc);
setalarm(Z_Rxtout);
switch(c = zrdata(rxbuf, ZMAXBLOCKLEN, pi->recv->bytes_received)) {
case ZHANGUP:
case ZEXIT:
gotoexit(PRC_ERROR);
break;
case ZCAN:
gotoexit(PRC_REMOTEABORTED);
break;
case ZTIMER:
log("time out waiting for data");
txtries = 0;
rxstate = ZRX_SENDRPOS;
break;
case ZERROR:
case ZCRCERR: /* CRC error */
zmodem_puts(Z_Attn);
txtries = 0;
rxstate = ZRX_SENDRPOS;
break;
case GOTCRCW:
case GOTCRCQ:
case GOTCRCG:
case GOTCRCE:
timer_set(&deadtimer, ZDEADTIMER);
if( (n = p_rx_writefile(rxbuf, Z_Rxcount, pi)) < 0 )
{
rxstate = ( n == -2 ) ? ZRX_SKIP : ZRX_REFUSE;
break;
}
pi->recv->bytes_received += Z_Rxcount;
switch(c) {
case GOTCRCW:
stohdr(Z_Txhdr, pi->recv->bytes_received);
if( zshhdr(ZACK, Z_Txhdr) < 0 ) gotoexit(PRC_ERROR);
rxstate = ZRX_RPOSACK;
break;
case GOTCRCQ:
stohdr(Z_Txhdr, pi->recv->bytes_received);
if( zshhdr(ZACK, Z_Txhdr) < 0 ) gotoexit(PRC_ERROR);
break;
case GOTCRCG:
break;
case GOTCRCE:
txtries = 0;
rxstate = ZRX_RPOSACK;
break;
}
break;
}
break;
case ZRX_REFUSE:
DEB((D_PROT, "rx_zmodem: entering state ZRX_REFUSE"));
txtries = 0;
inithdrtype = ZFERR;
rxstate = ZRX_INIT;
break;
case ZRX_SKIP:
DEB((D_PROT, "rx_zmodem: entering state ZRX_SKIP"));
txtries = 0;
if( skipbypos )
{
pi->recv->bytes_received = pi->recv->bytes_total;
rxstate = ZRX_SENDRPOS;
}
else
{
inithdrtype = ZSKIP;
rxstate = ZRX_INIT;
}
break;
default:
break;
} /* end of switch(rxstate) */
if( rxstate != ZRX_INIT && rxstate != ZRX_GOTFILE
&& rxstate != ZRX_SENDRPOS && rxstate != ZRX_WAITDATA
&& rxstate != ZRX_SKIP && rxstate != ZRX_REFUSE )
{
switch( ftype = zgethdr(Z_Rxhdr) ) {
case ZCAN:
gotoexit(PRC_REMOTEABORTED);
break;
case ZHANGUP:
case ZEXIT:
gotoexit(PRC_ERROR);
break;
case ZTIMER:
log("time out");
switch(rxstate) {
case ZRX_INITACK: rxstate = ZRX_INIT; break;
case ZRX_RPOSACK: rxstate = ZRX_SENDRPOS; break;
default: break;
}
break;
case ZERROR:
case ZCRCERR:
/* NAK them all! (TODO: think a little) */
stohdr(Z_Txhdr, 0L);
if( zshhdr(ZNAK, Z_Txhdr) < 0 )
gotoexit(PRC_ERROR);
break;
case ZRQINIT:
if( rxstate == ZRX_INITACK )
{
zrqinitcnt++;
rxstate = ZRX_INIT;
}
break;
case ZFILE:
if( rxstate == ZRX_INITACK
|| rxstate == ZRX_RPOSACK )
{
zconv = Z_Rxhdr[ZF0];
zmanag = Z_Rxhdr[ZF1];
ztrans = Z_Rxhdr[ZF2];
zexten = Z_Rxhdr[ZF3];
/* default to "binary" mode */
if( !zconv )
zconv = ZCBIN;
inithdrtype = ZRINIT;
setalarm(Z_Rxtout);
switch(zrdata(rxbuf, ZMAXBLOCKLEN, 0)) {
case ZHANGUP:
case ZEXIT:
gotoexit(PRC_ERROR);
break;
case ZTIMER:
txtries = 0;
rxstate = ZRX_INIT;
break;
case GOTCRCW:
rxstate = ZRX_GOTFILE;
break;
default:
stohdr(Z_Txhdr, 0L);
if( zshhdr(ZNAK, Z_Txhdr) < 0 ) gotoexit(PRC_ERROR);
rxstate = ZRX_INITACK;
break;
}
}
break;
case ZSINIT:
if( rxstate == ZRX_INITACK )
{
Z_Ctlesc = TESCCTL & Z_Rxhdr[ZF0];
setalarm(Z_Rxtout);
switch( zrdata(Z_Attn, ZATTNLEN, 0) ) {
case ZHANGUP:
case ZEXIT:
gotoexit(PRC_ERROR);
break;
case ZTIMER:
txtries = 0;
rxstate = ZRX_INIT;
break;
case GOTCRCW:
stohdr(Z_Txhdr, 1L);
if( zshhdr(ZACK, Z_Txhdr) < 0 ) gotoexit(PRC_ERROR);
rxstate = ZRX_INIT;
break;
default:
stohdr(Z_Txhdr, 0L);
if( zshhdr(ZNAK, Z_Txhdr) < 0 ) gotoexit(PRC_ERROR);
break;
}
}
break;
case ZNAK:
switch(rxstate) {
case ZRX_INITACK: rxstate = ZRX_INIT; break;
case ZRX_RPOSACK: rxstate = ZRX_SENDRPOS; break;
default: break;
}
break;
case ZEOF:
if( rxstate == ZRX_RPOSACK )
{
if( rclhdr(Z_Rxhdr) == pi->recv->bytes_received )
{
pi->recv->status = FSTAT_SUCCESS;
if( !p_rx_fclose(pi) )
{
rxstate = ZRX_INIT;
inithdrtype = ZRINIT;
} else
rxstate = ZRX_REFUSE;
txtries = 0;
} else
log("out of sync");
}
break;
case ZSKIP:
if( rxstate == ZRX_RPOSACK )
{
log("remote side skipped file");
rxstate = ZRX_INIT;
}
break;
case ZDATA:
if( rxstate == ZRX_RPOSACK )
{
if( rclhdr(Z_Rxhdr) == pi->recv->bytes_received )
{
rxstate = ZRX_WAITDATA;
}
else
{
log("out of sync");
zmodem_puts(Z_Attn);
txtries = 0;
rxstate = ZRX_SENDRPOS;
}
}
break;
case ZFREECNT:
if( rxstate == ZRX_INITACK )
{
stohdr(Z_Txhdr, ~0L);
if( zshhdr(ZACK, Z_Txhdr) < 0 ) gotoexit(PRC_ERROR);
}
break;
case ZCOMMAND:
if( rxstate == ZRX_INITACK )
{
inithdrtype = ZRINIT;
setalarm(Z_Rxtout);
switch( zrdata(rxbuf, ZMAXBLOCKLEN, 0) ) {
case ZHANGUP:
case ZEXIT:
gotoexit(PRC_ERROR);
break;
case ZTIMER:
txtries = 0;
rxstate = ZRX_INIT;
break;
case GOTCRCW:
log("remote command execution requested (n/a)");
log("command: \"%s\"", rxbuf);
stohdr(Z_Txhdr, 0L);
if( zshhdr(ZCOMPL, Z_Txhdr) < 0 ) gotoexit(PRC_ERROR);
gotoexit(PRC_LOCALABORTED);
break;
default:
stohdr(Z_Txhdr, 0L);
if( zshhdr(ZNAK, Z_Txhdr) < 0 ) gotoexit(PRC_ERROR);
txtries = 0;
rxstate = ZRX_INIT;
break;
}
}
break;
case ZFIN:
if( zrqinitcnt )
{
stohdr(Z_Txhdr, 0L);
if( zshhdr(ZFIN, Z_Txhdr) < 0 ) gotoexit(PRC_ERROR);
gotoexit(PRC_NOERROR);
}
else if( rxstate == ZRX_INITACK )
{
/*
* Don't believe first ZFIN on outgoing calls
*/
if( ++zfincnt > ZRXSKIPFIN || !caller )
{
stohdr(Z_Txhdr, 0L);
if( zshhdr(ZFIN, Z_Txhdr) < 0 ) gotoexit(PRC_ERROR);
gotoexit(PRC_NOERROR);
}
rxstate = ZRX_INIT;
}
break;
default:
log("got unexpected frame %d", ftype);
break;
}
}
} /* end of while(1) */
exit:
DEB((D_PROT, "rx_zmodem: RECV exit = %d", rc));
setalarm(0);
if( pi->recv && pi->recv->fp )
p_rx_fclose(pi);
if( rxbuf )
free(rxbuf);
return(rc);
}
/* ------------------------------------------------------------------------- */
/* Send a string to the modem, processing for \336 (sleep 1 sec) */
/* and \335 (break signal) */
/* ------------------------------------------------------------------------- */
static void zmodem_puts(const char *s)
{
DEB((D_PROT, "zmodem_puts: \"%s\"", string_printable(s)));
while( s && *s )
{
char *p = strpbrk(s, "\335\336");
if( !p )
{
WRITE_TIMEOUT(s, strlen(s));
return;
}
if( p != s )
{
WRITE_TIMEOUT(s, p-s);
s = p;
}
if( *p == '\336' )
sleep(1);
else
tio_send_break();
p++;
}
}
/* ------------------------------------------------------------------------- */
/* Process incoming file information header */
/* ------------------------------------------------------------------------- */
static int zmodem_proc_ZFILE(s_protinfo *pi, char *blkptr, size_t blklen)
{
char *fileiptr = NULL;
size_t filesize = 0L;
time_t filetime = 0L;
#ifdef DEBUG
char *tmp = string_printable_buffer(blkptr, blklen);
DEB((D_PROT, "zmodem_proc_ZFILE: process \"%s\" (%ld bytes)",
tmp, blklen));
if( tmp )
{
free(tmp); tmp = NULL;
}
#endif
blkptr[blklen] = '\0';
fileiptr = blkptr + strlen(blkptr) + 1;
if( fileiptr >= (blkptr + blklen) ||
sscanf(fileiptr, "%d%lo", &filesize, &filetime) < 1 )
{
log("zmodem: got invalid ZFILE packet");
return 1;
}
DEB((D_PROT, "zmodem_proc_ZFILE: filesize=%ld, filetime=%lo",
(long)filesize, (long)filetime));
return p_rx_fopen(pi, blkptr, filesize, filetime, 0);
}
+728
View File
@@ -0,0 +1,728 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "io.h"
#include "session.h"
#include "prot_common.h"
#include "prot_zmodem.h"
/* ------------------------------------------------------------------------- */
/* States of our Zmodem sending protocol */
/* ------------------------------------------------------------------------- */
typedef enum ztxstates {
ZTX_START, /* Start sending (init, send "rz\r") */
ZTX_RQINIT, /* Send ZRQINIT frame */
ZTX_RQINITACK, /* Wait for answer on ZRQINIT frame */
ZTX_NEXTFILE, /* Prepare next file for sending */
ZTX_FINFO, /* Send file's ZFINFO frame with data */
ZTX_FINFOACK, /* Wait for answer on our ZFINFO + .. */
ZTX_STARTDATA, /* Start sending of data (send ZDATA?) */
ZTX_DATA, /* Send new portion of data blocks */
ZTX_READCHECK, /* Check - we got some chars */
ZTX_CRCWACK, /* Wait for CRCW ack */
ZTX_CRCQACK, /* Wait for CRCQ ack */
ZTX_EOF, /* Send ZEOF frame with our file length */
ZTX_EOFACK, /* Wait for answer on our ZEOF */
ZTX_FIN, /* Send ZFIN to finish sending */
ZTX_FINACK /* Wait for answer on sent ZFIN */
} e_ztxstates;
static void zmodem_add_empty_packet(s_protinfo *pi)
{
struct stat st;
s_filelist **ptrl;
s_packet pkt;
char tmpname[] = "/tmp/bfXXXXXX";
char *p_tmpname;
if( (p_tmpname = mktemp(tmpname)) == NULL )
{
logerr("cannot generate temp. file name for packet from \"%s\"", tmpname);
return;
}
memset(&pkt, '\0', sizeof(s_packet));
pkt.dest = state.node.addr;
pkt.orig = *state.handshake->remote_address(state.handshake);
if( pkt_createpacket(p_tmpname, &pkt) )
{
char abuf[BF_MAXADDRSTR+1];
logerr("cannot create packet for address %s",
ftn_addrstr(abuf, pkt.dest));
return;
}
if( stat(p_tmpname, &st) )
{
logerr("cannot stat created packet \"%s\"", p_tmpname);
unlink(p_tmpname);
return;
}
for( ptrl = &pi->filelist; *ptrl; ptrl = &((*ptrl)->next) )
{ /* EMPTY LOOP */ }
(*ptrl) = (s_filelist *)xmalloc(sizeof(s_filelist));
memset(*ptrl, '\0', sizeof(s_filelist));
(*ptrl)->fname = xstrcpy(p_tmpname);
(*ptrl)->type = TYPE_NETMAIL;
(*ptrl)->action = ACTION_FORCEUNLINK;
(*ptrl)->size = st.st_size;
}
/* ------------------------------------------------------------------------- */
/* Send files with Z-Modem protocol */
/* Files to transfer stored in pi->syslist structure */
/* Return: */
/* PRC_SUCCESSFUL: All files received or transfer was finished cleanly */
/* PRC_ERROR: Error at sending something(include carrier lost) */
/* PRC_ERROR: Error at receiving something(include carrier lost) */
/* PRC_MERROR: Misc. errors (i.e. incompatibilies, failures, etc) */
/* PRC_TRIESOUT: Very many tries doing something without result */
/* PRC_REMOTEDEAD: For a long time no real information transfered */
/* PRC_REMOTEABORT: Transfer was aborted by remote (i.e. five CAN, etc..) */
/* PRC_LOCALBORT: Transfer was aborted by local (i.e. CPS too low, etc..) */
/* ------------------------------------------------------------------------- */
int tx_zmodem(s_protinfo *pi, bool caller)
{
int startblk = 64; /* Initial Zmodem block size */
int minblk = 64; /* Minimal Z-protocol block size */
int maxblk = 1024;/* Maximal Z-protocol block size */
int blocklen = 0; /* Length of transmitted blocks */
int goodblk = 0; /* How many blocks we sent w/o ZRPOS'tion :) */
int txwindow = 0; /* Tranmitter window size (0 means streaming) */
int newcnt = 0; /* Count free bytes in receiver's buffer */
int rxbuflen = 0; /* Receiver's max buffer length */
int rxlastpos = 0; /* Receiver's last reported offset */
int beenhere = 0; /* How many times we've been ZRPOS'd same place */
long bytescnt = 0; /* Received bytes(current offset) */
long lastsync = 0; /* Last offset to which we got a ZRPOS */
char zconv = 0; /* Local ZMODEM file conversion request */
char zmanag = 0; /* Local ZMODEM file management request */
char ztrans = 0; /* Local ZMODEM file translation request */
char zexten = 0; /* Local ZMODEM file extended options */
char *txbuf = NULL;/* Buffer with ZMAXBLOCKLEN size */
int zrinitcnt = 0; /* Count received ZRINITs */
int rxflags1 = 0;
int rxflags2 = 0;
int txtries = 0;
int junkcnt = 0;
int initacked = 0; /* TRUE when at least one ZRQINIT was sent */
/* after first ZRINIT was received */
int rc = 0; /* Our return code */
int dtype, n;
int ftype;
char c, *p;
long unsigned crc32;
enum ztxstates txstate;
time_t deadtimer;
log("start %s send", Protocols[state.handshake->protocol]);
DEB((D_PROT, "start %s send", Protocols[state.handshake->protocol]));
/* Set time transfer started at */
if( pi->start_time == 0 )
pi->start_time = time(NULL);
txbuf = (char *)xmalloc(ZMAXBLOCKLEN+1);
zconv = ZCBIN;
maxblk = (state.handshake->protocol == PROT_ZMODEM) ? 1024 : 8192;
/* Set initial block size (default is 128b) */
if( (startblk = conf_number(cf_zmodem_start_block_size)) > 0 )
{
if( startblk%64 || startblk > maxblk || startblk < 64 )
startblk = 256;
} else
startblk = 256;
blocklen = startblk;
txwindow = conf_number(cf_zmodem_tx_window);
Z_Rxwait = ZWAITTIME;
Z_Rxtout = ZRXTIMEOUT;
txstate = ZTX_START;
timer_set(&deadtimer, ZDEADTIMER);
setalarm(Z_Rxtout);
/*
* At zmodem batches send empty netmail packet
* if no real outgoing traffic available
*/
if( !pi->send_left_size && conf_boolean(cf_zmodem_send_dummy_pkt) )
zmodem_add_empty_packet(pi);
while(1)
{
if( timer_expired(deadtimer) )
{
log("brain dead! (abort)");
gotoexit(PRC_LOCALABORTED);
}
if( txstate == ZTX_RQINIT || txstate == ZTX_FINFO
|| txstate == ZTX_EOF || txstate == ZTX_FIN )
{
#ifdef DEBUG
if( txtries ) DEB((D_PROT, "tx_zmodem: try #%d", txtries));
#endif
if( ++txtries > ZMAXTRIES )
{
log("out of tries");
gotoexit(PRC_LOCALABORTED);
}
}
switch(txstate) {
case ZTX_START:
DEB((D_PROT, "tx_zmodem: entering state ZTX_START"));
if( PUTSTR("rz\r") < 0 )
gotoexit(PRC_ERROR);
txtries = 0;
txstate = ZTX_RQINIT;
break;
case ZTX_RQINIT:
DEB((D_PROT, "tx_zmodem: entering state ZTX_RQINIT"));
stohdr(Z_Txhdr, 0L);
if( zshhdr(ZRQINIT, Z_Txhdr) < 0 )
gotoexit(PRC_ERROR);
setalarm(Z_Rxtout);
txstate = ZTX_RQINITACK;
break;
case ZTX_NEXTFILE:
DEB((D_PROT, "tx_zmodem: entering state ZTX_NEXTFILE"));
if( pi->send && pi->send->fp )
p_tx_fclose(pi);
txtries = 0;
txstate = p_tx_fopen(pi) ? ZTX_FIN : ZTX_FINFO;
break;
case ZTX_FINFO:
DEB((D_PROT, "tx_zmodem: entering state ZTX_FINFO"));
zrinitcnt = 0;
strnxcpy(txbuf, pi->send->net_name, ZMAXFNAME);
p = txbuf + strlen(txbuf) + 1;
sprintf(p, "%ld %lo %lo 0 %ld %ld",
(long)pi->send->bytes_total, (long)pi->send->mod_time,
(long)pi->send->mode, (long)pi->send_left_num,
(long)pi->send_left_size);
DEB((D_PROT, "tx_zmodem: send \"%s\\000%s\"", txbuf, p));
Z_Txhdr[ZF0] = zconv; /* file conversion request */
Z_Txhdr[ZF1] = zmanag; /* file management request */
Z_Txhdr[ZF2] = ztrans; /* file transport request */
Z_Txhdr[ZF3] = zexten;
if( zsbhdr(ZFILE, Z_Txhdr) < 0 )
gotoexit(PRC_ERROR);
if( zsdata(txbuf, (p - txbuf) + strlen(p), ZCRCW, 0) < 0 )
gotoexit(PRC_ERROR);
setalarm(Z_Rxtout);
txstate = ZTX_FINFOACK;
break;
case ZTX_STARTDATA:
DEB((D_PROT, "tx_zmodem: entering state ZTX_STARTDATA"));
newcnt = rxbuflen;
junkcnt = 0;
stohdr(Z_Txhdr, pi->send->bytes_sent);
if( zsbhdr(ZDATA, Z_Txhdr) < 0 )
gotoexit(PRC_ERROR);
txstate = ZTX_DATA;
break;
case ZTX_DATA:
DEB((D_PROT, "tx_zmodem: entering state ZTX_DATA"));
timer_set(&deadtimer, ZDEADTIMER);
setalarm(Z_Rxtout); /* Remove annoing timeouts! */
if( (n = p_tx_readfile(txbuf, blocklen, pi)) < 0 )
{
/* error occured, remote wait for DATA */
/* so send null ZCRCE data subpacket */
if( zsdata(txbuf, 0, ZCRCE, 0) < 0 )
gotoexit(PRC_ERROR);
txstate = ZTX_NEXTFILE;
break;
}
if( pi->send->eofseen )
dtype = ZCRCE;
else if( junkcnt > 6 )
dtype = ZCRCW;
else if( bytescnt == lastsync )
dtype = ZCRCW;
else if( rxbuflen && (newcnt -= n) <= 0 )
dtype = ZCRCW;
else if( txwindow && (bytescnt - rxlastpos + n) >= txwindow )
dtype = ZCRCQ;
else
dtype = ZCRCG;
if( (rc = p_info(pi, 0)) )
gotoexit(rc);
if( zsdata(txbuf, n, dtype, pi->send->bytes_sent) < 0 )
gotoexit(PRC_ERROR);
if( ++goodblk > 5 && blocklen*2 <= maxblk )
{
goodblk = 0;
blocklen *= 2;
DEB((D_PROT, "tx_zmodem: new blocklen = %ld byte(s)", blocklen));
}
bytescnt = pi->send->bytes_sent += n;
if( dtype == ZCRCW )
{
junkcnt = 0;
setalarm(Z_Rxtout);
txstate = ZTX_CRCWACK;
break;
}
else if( dtype == ZCRCQ )
{
junkcnt = 0;
setalarm(Z_Rxtout);
txstate = ZTX_CRCQACK;
break;
}
else if( dtype == ZCRCE )
{
txtries = 0;
txstate = ZTX_EOF;
break;
}
if( CHARWAIT(0) )
{
while( (rc = GETCHAR(1)) != ZTIMER )
{
if( rc < 0 )
{
gotoexit(PRC_ERROR);
}
else if( rc == CAN || rc == ZPAD )
{
DEB((D_PROT, "tx_zmodem: got ZPAD or CAN!"));
setalarm(Z_Rxtout);
txstate = ZTX_READCHECK;
break;
}
else if( rc == XOFF || rc == (XOFF|0200) )
{
DEB((D_PROT, "tx_zmodem: got XOFF"));
if( GETCHAR(5) < 0 )
gotoexit(PRC_ERROR);
break;
}
else if( rc == XON || rc == (XON|0200) )
{
DEB((D_PROT, "tx_zmodem: got XON"));
}
else
{
junkcnt++;
DEB((D_PROT, "tx_zmodem: got JUNK = 0x%x (junkcnt = %d)",
rc, junkcnt));
}
} /* end of while( rc != ZTIMER ) */
} /* end of if( CHARWAIT(0) ) */
break;
case ZTX_EOF:
DEB((D_PROT, "tx_zmodem: entering state ZTX_EOF"));
stohdr(Z_Txhdr, pi->send->bytes_sent);
if( zsbhdr(ZEOF, Z_Txhdr) < 0 )
gotoexit(PRC_ERROR);
setalarm(Z_Rxtout);
txstate = ZTX_EOFACK;
break;
case ZTX_FIN:
DEB((D_PROT, "tx_zmodem: entering state ZTX_FIN"));
stohdr(Z_Txhdr, 0L);
if( zshhdr(ZFIN, Z_Txhdr) < 0 )
gotoexit(PRC_ERROR);
setalarm(Z_Rxtout);
txstate = ZTX_FINACK;
break;
default:
/* Ignore them all */
break;
} /* end of switch(txstate) */
if( txstate != ZTX_START && txstate != ZTX_RQINIT
&& txstate != ZTX_FINFO && txstate != ZTX_DATA
&& txstate != ZTX_EOF && txstate != ZTX_FIN )
{
switch( ftype = zgethdr(Z_Rxhdr) ) {
case ZCAN:
gotoexit(PRC_REMOTEABORTED);
break;
case ZHANGUP:
case ZEXIT:
gotoexit(PRC_ERROR);
break;
case ZTIMER:
log("time out");
if( txstate == ZTX_READCHECK )
zsdata(txbuf, 0, ZCRCE, 0);
switch(txstate) {
case ZTX_RQINITACK: txstate = ZTX_RQINIT; break;
case ZTX_FINFOACK: txstate = ZTX_FINFO; break;
case ZTX_READCHECK: txstate = ZTX_STARTDATA; break;
case ZTX_CRCWACK: txstate = ZTX_STARTDATA; break;
case ZTX_CRCQACK: txstate = ZTX_STARTDATA; break;
case ZTX_EOFACK: txstate = ZTX_EOF; break;
case ZTX_FINACK: txstate = ZTX_FIN; break;
default: break;
}
break;
case ZERROR:
case ZCRCERR:
/* NAK them all! */
stohdr(Z_Txhdr, 0L);
if( zshhdr(ZNAK, Z_Txhdr) < 0 )
gotoexit(PRC_ERROR);
break;
case ZRQINIT:
if( txstate == ZTX_RQINITACK )
{
if( Z_Rxhdr[0] == ZCOMMAND )
break;
stohdr(Z_Txhdr, 0L);
if( zshhdr(ZNAK, Z_Txhdr) < 0 )
gotoexit(PRC_ERROR);
txstate = ZTX_RQINIT;
}
else if( txstate == ZTX_FINFOACK )
{
/* remote is sender - abort */
log("zmodem: remote is sender");
gotoexit(PRC_LOCALABORTED);
}
break;
case ZRINIT:
if( txstate == ZTX_RQINITACK )
{
if( initacked == 0 )
{
/* Be sure ack first ZRINIT */
stohdr(Z_Txhdr, 0L);
if( zshhdr(ZRQINIT, Z_Txhdr) < 0 )
gotoexit(PRC_ERROR);
initacked = 1;
}
/* Get receiver's options */
rxflags1 = (0377 & Z_Rxhdr[ZF0]);
rxflags2 = (0377 & Z_Rxhdr[ZF1]);
Z_Txfcs32 = (rxflags1 & CANFC32);
Z_Ctlesc |= (rxflags1 & TESCCTL);
rxbuflen = (0377 & Z_Rxhdr[ZP0]);
rxbuflen += ((0377 & Z_Rxhdr[ZP1])<<8);
/* No ZCRCQ if remote doesn't indicate */
/* FDX ability */
if( !(rxflags1 & CANFDX) )
txwindow = 0;
DEB((D_PROT, "tx_zmodem: Z_Txfcs32 = %d Z_Ctlesc = %d",
Z_Txfcs32, Z_Ctlesc));
DEB((D_PROT, "tx_zmodem: rxbuflen = %d blocklen = %d",
rxbuflen, blocklen));
DEB((D_PROT, "tx_zmodem: txwindow = %u",
txwindow));
txstate = ZTX_NEXTFILE;
}
else if( txstate == ZTX_FINFOACK )
{
/* Possible they didn't see */
/* our file information */
if( ++zrinitcnt > 2 )
txstate = ZTX_FINFO;
}
else if( txstate == ZTX_READCHECK
|| txstate == ZTX_CRCQACK
|| txstate == ZTX_CRCWACK )
{
if( txstate == ZTX_READCHECK
|| txstate == ZTX_CRCQACK )
zsdata(txbuf, 0, ZCRCE, 0);
/* Assume file normaly sent ? */
log("assume file normaly sent");
pi->send->status = FSTAT_SUCCESS;
txstate = ZTX_NEXTFILE;
}
else if( txstate == ZTX_EOFACK )
{
/* ok, send next */
pi->send->status = FSTAT_SUCCESS;
txstate = ZTX_NEXTFILE;
}
else if( txstate == ZTX_FINACK )
{
/* Possible we should ignore */
/* first ZRINIT. Because they */
/* didn't see our first ZFIN */
/* But I'm soo lazy .. :)) */
txstate = ZTX_FIN;
}
break;
case ZACK:
if( txstate == ZTX_CRCWACK )
{
rxlastpos = Z_Rxpos;
if( pi->send->bytes_sent == Z_Rxpos )
txstate = ZTX_STARTDATA;
}
else if( txstate == ZTX_READCHECK
|| txstate == ZTX_CRCQACK )
{
rxlastpos = Z_Rxpos;
txstate = ZTX_DATA;
}
break;
case ZSKIP:
if( txstate == ZTX_FINFOACK
|| txstate == ZTX_READCHECK
|| txstate == ZTX_CRCQACK
|| txstate == ZTX_CRCWACK
|| txstate == ZTX_EOFACK )
{
if( txstate == ZTX_READCHECK
|| txstate == ZTX_CRCQACK )
zsdata(txbuf, 0, ZCRCE, 0);
if( txstate == ZTX_READCHECK )
CLEAROUT();
pi->send->status = FSTAT_SKIPPED;
log("remote side skipped file");
txstate = ZTX_NEXTFILE;
}
break;
case ZFIN:
/* BUG!BUG!BUG!BUG!BUG!BUG!BUG!BUG!BUG! */
/* BUG!BUG!BUG!BUG!BUG!BUG!BUG!BUG!BUG! */
/* BUG!BUG!BUG!BUG!BUG!BUG!BUG!BUG!BUG! */
if( txstate == ZTX_FINACK )
{
if( PUTSTR("OO") == 0 )
FLUSHOUT();
gotoexit(PRC_NOERROR);
}
break;
case ZRPOS:
if( txstate == ZTX_FINFOACK
|| txstate == ZTX_READCHECK
|| txstate == ZTX_CRCQACK
|| txstate == ZTX_CRCWACK
|| txstate == ZTX_EOFACK )
{
rxlastpos = Z_Rxpos;
/* Clear modem buffers */
/* if( txstate != FINFOACK ) SENDBREAK(); */
if( txstate == ZTX_READCHECK ) CLEAROUT();
if( txstate == ZTX_READCHECK
|| txstate == ZTX_CRCQACK )
{
if( zsdata(txbuf, 0, ZCRCE, 0) < 0 )
gotoexit(PRC_ERROR);
}
/* Reset EOF flag! */
pi->send->eofseen = FALSE;
/* Check pos */
if( (Z_Rxpos || txstate != ZTX_FINFOACK)
&& fseek(pi->send->fp, Z_Rxpos, 0) )
{
logerr("can't send file from requested position");
/* Open next file for send */
txstate = ZTX_NEXTFILE;
break;
}
if( txstate == ZTX_FINFOACK )
{
if( Z_Rxpos )
{
log("resyncing at offset %d", Z_Rxpos);
pi->send->bytes_skipped = Z_Rxpos;
}
}
else if( txstate == ZTX_READCHECK
|| txstate == ZTX_CRCWACK
|| txstate == ZTX_CRCQACK )
{
goodblk = 0;
if( lastsync >= Z_Rxpos && ++beenhere > 4 )
if( blocklen > minblk )
{
blocklen /= 2;
DEB((D_PROT, "tx_zmodem: falldown to %ld BlockLen", blocklen));
}
}
lastsync = bytescnt = pi->send->bytes_sent = Z_Rxpos;
if( txstate == ZTX_FINFOACK )
--lastsync;
txstate = ZTX_STARTDATA;
}
break;
case ZNAK:
switch(txstate) {
case ZTX_RQINITACK: txstate = ZTX_RQINIT; break;
case ZTX_FINFOACK: txstate = ZTX_FINFO; break;
case ZTX_EOFACK: txstate = ZTX_EOF; break;
case ZTX_FINACK: txstate = ZTX_FIN; break;
default: break;
}
break;
case ZCRC:
if( txstate == ZTX_FINFOACK )
{
/* Send file's CRC-32 */
crc32 = 0xFFFFFFFFL;
while( ((c = getc(pi->send->fp)) != EOF) && --Z_Rxpos )
crc32 = updcrc32(c, crc32);
crc32 = ~crc32;
clearerr(pi->send->fp); /* Clear EOF */
fseek(pi->send->fp, 0L, 0);
stohdr(Z_Txhdr, crc32);
if( zsbhdr(ZCRC, Z_Txhdr) < 0 )
gotoexit(PRC_ERROR);
}
break;
case ZCHALLENGE:
if( txstate == ZTX_RQINITACK )
{
/* Echo receiver's challenge number */
stohdr(Z_Txhdr, Z_Rxpos);
if( zshhdr(ZACK, Z_Txhdr) < 0 )
gotoexit(PRC_ERROR);
txstate = ZTX_RQINIT;
}
break;
case ZCOMMAND:
if( txstate == ZTX_RQINITACK )
{
txstate = ZTX_RQINIT;
}
break;
case ZABORT:
log("remote requested for session abort");
stohdr(Z_Txhdr, 0L);
if( zshhdr(ZFIN, Z_Txhdr) < 0 )
gotoexit(PRC_ERROR);
gotoexit(PRC_REMOTEABORTED);
break;
case ZFERR:
if( txstate == ZTX_FINFOACK
|| txstate == ZTX_READCHECK
|| txstate == ZTX_CRCWACK
|| txstate == ZTX_CRCQACK
|| txstate == ZTX_EOFACK )
{
if( txstate == ZTX_READCHECK
|| txstate == ZTX_CRCQACK )
{
if( zsdata(txbuf, 0, ZCRCE, 0) < 0 )
gotoexit(PRC_ERROR);
}
pi->send->status = FSTAT_REFUSED;
log("remote side refused file");
txstate = ZTX_NEXTFILE;
}
break;
default:
log("got unexpected frame %d", ftype);
break;
} /* end of switch(hdr) */
} /* end of if */
} /* end of while */
exit:
DEB((D_PROT, "tx_zmodem: SEND exit = %d", rc));
setalarm(0);
if( pi->send && pi->send->fp )
p_tx_fclose(pi);
if( txbuf )
free(txbuf);
return(rc);
}
+138
View File
@@ -0,0 +1,138 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "nodelist.h"
#include "io.h"
#include "session.h"
int answ_system(e_session type, char *connstr, int inetd)
{
TIO oldtio;
struct sockaddr_in client;
int clientlen = sizeof(client);
int rc = 0;
char *p;
init_state(&state);
state.session = type;
state.caller = FALSE;
state.valid = TRUE;
/*
* Set verbal line name
*/
if( inetd )
{
state.linename = xstrcpy("tcpip");
state.inet = TRUE;
}
else
state.linename = isatty(0) ? port_get_name(ttyname(0)) : NULL;
if( !inetd )
{
if( tio_get_dcd(0) == 0 )
log("warning: DCD line is not active");
if( (p = getenv("CALLER_ID")) && *p && strcmp(p, "none") )
state.cidstr = (char*)xstrcpy(p);
if( connstr && *connstr )
state.connstr = (char*)xstrcpy(connstr);
else if( (p = getenv("CONNECT")) && *p )
state.connstr = (char*)xstrcpy(p);
if( state.connstr )
state.connspeed = modem_getconnspeed(state.connstr);
}
/*
* Open new log file with current line name as extension
*/
if( log_reopen(log_getfilename(LOG_FILE_SESSION), state.linename, NULL) )
{
log("can't continue without logging");
gotoexit(BFERR_FATALERROR);
}
#ifdef DEBUG
(void)debug_setfilename(log_getfilename(LOG_FILE_DEBUG));
#endif
if( inetd )
{
if( connstr && *connstr )
state.connstr = (char*)xstrcpy(connstr);
else if( getpeername(0, (struct sockaddr*)&client, &clientlen) == -1 )
logerr("can't get client address");
else
{
state.peername = (char*)xstrcpy(inet_ntoa(client.sin_addr));
state.peerport = (long)ntohs(client.sin_port);
}
}
if( inetd == 0 && state.cidstr )
{
setproctitle("bforce answering, CID: %.32s",
string_printable(state.cidstr));
log("Caller-ID: \"%s\"",
string_printable(state.cidstr));
}
else if( inetd && state.peername )
{
setproctitle("bforce answering, host %.32s:%ld",
string_printable(state.peername), state.peerport);
log("TCP/IP connect from %s on port %ld",
string_printable(state.peername), state.peerport);
}
else
{
setproctitle("bforce answering");
}
if( state.connstr )
log("connect \"%s\" (%ld)", state.connstr, state.connspeed);
if( (inetd == 0 && (rc = port_init(0, 0, &oldtio, FALSE)) == 0)
|| (inetd == 1 && (rc = tcpip_init()) == 0) )
{
port_carrier(0, TRUE);
rc = session();
if( !inetd )
{
port_deinit(0, &oldtio);
port_close();
}
}
else
rc = BFERR_FATALERROR;
exit:
out_bsy_unlockall();
log("session rc = %d (\"%s\")", rc, BFERR_NAME(rc));
if( state.node.addr.zone > 0 )
(void)session_stat_update(&state.node.addr,
&state.sess_stat, FALSE, rc);
deinit_state(&state);
return(rc);
}
+716
View File
@@ -0,0 +1,716 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "nodelist.h"
#include "io.h"
#include "session.h"
#ifdef XXXX
/* Unused */
int call_system_modem_init(TIO *old_tio_settings)
{
int rc = BFERR_NOERROR;
char abuf[BF_MAXADDRSTR+1];
int c;
TIO oldtio; /* Original terminal settings */
long minspeed = 0L; /* Min connect speed */
long waittime = 0L; /* Abort dialing after.. */
char dialstring[256] = ""; /* Modem dial string with phone number */
char phone[BFORCE_MAX_PHONE+1];
const char *p_resetstr = NULL; /* Modem reset string */
const char *p_prefstr = NULL; /* Modem dial prefix string */
const char *p_suffstr = NULL; /* Modem dial suffix string */
/*
* Set verbal line name to the modem device name
*/
state.linename = port_get_name(state.modemport->name);
/*
* Open new log file with current line name as extension
*/
if( log_reopen(log_getfilename(LOG_FILE_SESSION),
state.linename, NULL) )
{
log("can't continue without logging");
return BFERR_FATALERROR;
}
#ifdef DEBUG
(void)debug_setfilename(log_getfilename(LOG_FILE_DEBUG));
#endif
if( (rc = port_open(state.modemport, 1, old_tio_setting)) )
{
log("cannot open modem port \"%s\"",
state.modemport->name);
return BFERR_PORTBUSY;
}
/* Load dialing options */
p_resetstr = conf_string(cf_modem_reset_command);
p_prefstr = conf_string(cf_modem_dial_prefix);
p_suffstr = conf_string(cf_modem_dial_suffix);
waittime = conf_number(cf_wait_carrier_out);
/* Set default wait for carrier time */
if( !waittime )
waittime = 120;
/* Prepare dial string */
*dialstring = '\0';
if( p_prefstr )
strnxcpy(dialstring, p_prefstr, sizeof(dialstring));
else
log("warning: no modem dial prefix defined");
modem_transphone(phone, state.node.phone, sizeof(phone));
strnxcat(dialstring, phone, sizeof(phone));
if( p_suffstr )
strnxcat(dialstring, p_suffstr, sizeof(dialstring));
else
log("warning: no modem dial suffix defined");
log("calling %s (%s, %s)",
ftn_addrstr(abuf, state.node.addr),
(state.node.name && *state.node.name) ? state.node.name : "<none>",
string_printable(dialstring));
/* Clear modem buffer from possible "NO CARRIER"s */
CLEARIN();
/* Reset modem */
if( p_resetstr && *p_resetstr )
{
if( (c = modem_command(p_resetstr, 5, TRUE)) )
{
log("can't reset modem: %s", modem_errlist[c]);
port_deinit(0, &oldtio);
port_close();
return BFERR_NOMODEM; /* XXX close port? */
}
/* Try to remove some needless
* modem responses from buffer */
CLEARIN();
}
rc = modem_dial(dialstring, waittime, &state.connstr);
if( rc )
{
/* Error must be allready reported */
port_deinit(0, &oldtio);
port_close();
return BFERR_CANT_CONNECT10;
}
if( state.connstr )
{
state.connspeed = modem_getconnspeed(state.connstr);
log("connect \"%s\" (%ld)",
state.connstr, state.connspeed);
}
minspeed = conf_number(cf_min_speed_out);
if( state.connspeed && state.connspeed < minspeed )
{
TTYRESET();
log("connect speed too low, at least %ld required",
minspeed);
port_deinit(0, &oldtio);
port_close();
return BFERR_CONNECT_TOOLOW;
}
/* Give modem some time for raising DCD line */
usleep(100000); /* 0.1 sec */
if( tio_get_dcd(0) == 0 )
log("warning: DCD line is not active after connect!");
port_carrier(0, TRUE);
return BFERR_NOERROR;
}
/* Unused */
int call_system_modem_deinit(TIO *old_tio_settings)
{
const char *p_hangstr; /* Modem hangup string */
const char *p_statstr; /* Modem statistic string */
p_hangstr = conf_string(cf_modem_hangup_command);
p_statstr = conf_string(cf_modem_stat_command);
signal(SIGHUP, SIG_IGN);
signal(SIGINT, SIG_IGN);
signal(SIGTERM, SIG_IGN);
CLEARIN(); CLEAROUT();
/* Hangup if we think modem is still online! */
if( !tty_hangup && p_hangstr && *p_hangstr )
{
TTYRESET(); /* Reset error flags */
if( (c = modem_hangup(p_hangstr, 5)) )
log("can't hangup modem: %s", modem_errlist[c]);
}
/* Write modem statistic to log file */
if( p_statstr && *p_statstr )
{
TTYRESET(); /* Reset error flags */
if( (c = modem_command(p_statstr, 10, TRUE)) )
log("can't get modem statistic: %s", modem_errlist[c]);
}
port_deinit(0, old_tio_settings);
port_close();
return BFERR_NOERROR;
}
#endif /* XXXX */
int call_system_quiet(const char *connstr, bool inet)
{
TIO oldtio;
struct sockaddr_in client;
int clientlen = sizeof(client);
int rc = 0;
char *p;
/*
* Set verbal line name
*/
if( inet ) {
state.linename = xstrcpy("tcpip");
state.inet = TRUE;
}
else
state.linename = isatty(0) ? port_get_name(ttyname(0)) : NULL;
if( !inet )
{
if( tio_get_dcd(0) == 0 )
log("warning: DCD line is not active");
if( connstr && *connstr )
state.connstr = (char*)xstrcpy(connstr);
else if( (p = getenv("CONNECT")) && *p )
state.connstr = (char*)xstrcpy(p);
if( state.connstr )
state.connspeed = modem_getconnspeed(state.connstr);
}
/*
* Open new log file with current line name as extension
*/
if( log_reopen(log_getfilename(LOG_FILE_SESSION), state.linename, NULL) )
{
log("can't continue without logging");
return BFERR_FATALERROR;
}
#ifdef DEBUG
(void)debug_setfilename(log_getfilename(LOG_FILE_DEBUG));
#endif
if( inet )
{
if( connstr && *connstr )
state.connstr = (char*)xstrcpy(connstr);
else if( getpeername(0, (struct sockaddr*)&client, &clientlen) == -1 )
logerr("can't get client address");
else
{
state.peername = (char*)xstrcpy(inet_ntoa(client.sin_addr));
state.peerport = (long)ntohs(client.sin_port);
}
}
if( !inet && state.cidstr )
{
setproctitle("bforce outgoing, CID: %.32s",
string_printable(state.cidstr));
log("Caller-ID: \"%s\"",
string_printable(state.cidstr));
}
else if( inet && state.peername )
{
setproctitle("bforce outgoing, host %.32s:%ld",
string_printable(state.peername), state.peerport);
log("TCP/IP connect from %s on port %ld",
string_printable(state.peername), state.peerport);
}
else
{
setproctitle("bforce outgoing");
}
if( state.connstr )
log("connect \"%s\" (%ld)", state.connstr, state.connspeed);
if( (!inet && (rc = port_init(0, 0, &oldtio, FALSE)) == 0)
|| ( inet && (rc = tcpip_init()) == 0) )
{
port_carrier(0, TRUE);
rc = session();
if( !inet )
{
port_deinit(0, &oldtio);
port_close();
}
}
else
rc = BFERR_FATALERROR;
return rc;
}
/* ------------------------------------------------------------------------- */
/* Before using we must lock tty and set: */
/* state.node - node information */
/* state.modemport - to modem device we are going to use */
/* ------------------------------------------------------------------------- */
int call_system_modem(void)
{
char abuf[BF_MAXADDRSTR+1];
int c, rc = BFERR_NOERROR;
TIO oldtio; /* Original terminal settings */
long minspeed = 0L; /* Min connect speed */
long waittime = 0L; /* Abort dialing after.. */
char dialstring[256] = ""; /* Modem dial string with phone number */
char phone[BFORCE_MAX_PHONE+1];
const char *p_resetstr = NULL; /* Modem reset string */
const char *p_prefstr = NULL; /* Modem dial prefix string */
const char *p_suffstr = NULL; /* Modem dial suffix string */
const char *p_hangstr = NULL; /* Modem hangup string */
const char *p_statstr = NULL; /* Modem statistic string */
/*
* Set verbal line name to the modem device name
*/
state.linename = port_get_name(state.modemport->name);
/*
* Open new log file with current line name as extension
*/
if( log_reopen(log_getfilename(LOG_FILE_SESSION),
state.linename, NULL) )
{
log("can't continue without logging");
return BFERR_FATALERROR;
}
#ifdef DEBUG
(void)debug_setfilename(log_getfilename(LOG_FILE_DEBUG));
#endif
if( (rc = port_open(state.modemport, 1, &oldtio)) == 0 )
{
/* Load dialing options */
p_resetstr = conf_string(cf_modem_reset_command);
p_prefstr = conf_string(cf_modem_dial_prefix);
p_suffstr = conf_string(cf_modem_dial_suffix);
p_hangstr = conf_string(cf_modem_hangup_command);
p_statstr = conf_string(cf_modem_stat_command);
waittime = conf_number(cf_wait_carrier_out);
/* Set default wait for carrier time */
if( !waittime )
waittime = 120;
*dialstring = '\0';
if( p_prefstr )
strnxcpy(dialstring, p_prefstr, sizeof(dialstring));
else
log("warning: no modem dial prefix defined");
modem_transphone(phone, state.node.phone, sizeof(phone));
strnxcat(dialstring, phone, sizeof(phone));
if( p_suffstr )
strnxcat(dialstring, p_suffstr, sizeof(dialstring));
else
log("warning: no modem dial suffix defined");
log("calling %s (%s, %s)",
ftn_addrstr(abuf, state.node.addr),
(state.node.name && *state.node.name) ? state.node.name : "<none>",
string_printable(dialstring));
/*
* Clear modem buffer from possible "NO CARRIER"s
*/
CLEARIN();
/*
* Reset modem
*/
if( p_resetstr && *p_resetstr )
{
if( (c = modem_command(p_resetstr, 5, TRUE)) )
{
log("can't reset modem: %s", modem_errlist[c]);
return BFERR_NOMODEM; /* XXX close port */
}
/*
* Try to remove some needless
* modem responses from buffer
*/
CLEARIN();
}
rc = modem_dial(dialstring, waittime, &state.connstr);
if( rc < 0 )
{
rc = BFERR_CANT_CONNECT10;
}
else if( rc == 0 )
{
if( state.connstr )
{
state.connspeed = modem_getconnspeed(state.connstr);
log("connect \"%s\" (%ld)", state.connstr, state.connspeed);
}
minspeed = conf_number(cf_min_speed_out);
if( state.connspeed && state.connspeed < minspeed )
{
TTYRESET();
log("connect speed too low, at least %ld required", minspeed);
rc = BFERR_CONNECT_TOOLOW;
}
else
{
/* Give modem some time for rising DCD line */
usleep(100000); /* 0.1 sec */
if( tio_get_dcd(0) == 0 )
log("warning: DCD line is not active after connect!");
port_carrier(0, TRUE);
rc = session();
port_carrier(0, FALSE);
}
signal(SIGHUP, SIG_IGN);
signal(SIGINT, SIG_IGN);
signal(SIGTERM, SIG_IGN);
CLEARIN(); CLEAROUT();
/* Hangup if we think modem is still online! */
if( !tty_hangup && p_hangstr && *p_hangstr )
{
TTYRESET(); /* Reset error flags */
if( (c = modem_hangup(p_hangstr, 5)) )
log("can't hangup modem: %s", modem_errlist[c]);
}
/* Write modem statistic to log file */
if( p_statstr && *p_statstr )
{
TTYRESET(); /* Reset error flags */
if( (c = modem_command(p_statstr, 10, TRUE)) )
log("can't get modem statistic: %s", modem_errlist[c]);
}
}
port_deinit(0, &oldtio);
port_close();
}
else
{
log("cannot open modem port \"%s\"", state.modemport->name);
rc = BFERR_PORTBUSY;
}
return rc;
}
int call_system_tcpip(void)
{
char abuf[BF_MAXADDRSTR+1];
int rc = BFERR_NOERROR;
/*
* Set verbal line name to "tcpip" value
*/
state.linename = xstrcpy("tcpip");
state.inet = TRUE;
/*
* Open new log file with current line name as extension
*/
if( log_reopen(log_getfilename(LOG_FILE_SESSION),
state.linename, NULL) )
{
log("can't continue without logging");
return BFERR_FATALERROR;
}
#ifdef DEBUG
(void)debug_setfilename(log_getfilename(LOG_FILE_DEBUG));
#endif
if( nodelist_checkflag(state.node.flags, "BINKP") == 0
|| nodelist_checkflag(state.node.flags, "IBN") == 0 )
{
state.tcpmode = TCPMODE_BINKP;
state.session = SESSION_BINKP;
}
else if( nodelist_checkflag(state.node.flags, "TELN") == 0 )
{
state.tcpmode = TCPMODE_TELNET;
state.session = SESSION_UNKNOWN;
}
else if( nodelist_checkflag(state.node.flags, "IFC") == 0 )
{
state.tcpmode = TCPMODE_RAW;
state.session = SESSION_UNKNOWN;
}
else /* Default is "raw" mode */
{
state.tcpmode = TCPMODE_RAW;
state.session = SESSION_UNKNOWN;
}
log("calling %s (%s, %s)",
ftn_addrstr(abuf, state.node.addr),
(state.node.name && *state.node.name ) ? state.node.name : "<none>",
(state.node.phone && *state.node.phone) ? state.node.phone : "<none>");
if( (rc = tcpip_connect(state.node.phone, state.tcpmode)) == 0
&& (rc = tcpip_init() == 0) )
{
TTYSTATUS(1);
rc = session();
tcpip_shutdown();
}
else
{
rc = BFERR_CANT_CONNECT10;
}
return rc;
}
int call_system(s_faddr addr, const s_bforce_opts *opts)
{
int rc = 0;
char abuf[BF_MAXADDRSTR+1];
char *p_lockdir = NULL;
char *errmsg = NULL;
bool inet = FALSE;
init_state(&state);
state.caller = TRUE;
state.valid = TRUE;
state.node.addr = addr;
nodelist_lookup(&state.node, addr);
state.listed = state.node.listed;
state.node.addr.domain[0] = '\0'; /* Discard domain for node address */
if( opts->dontcall )
goto do_session;
/*
* Get node overrides
*/
if( override_get(&state.override, state.node.addr, opts->hiddline) )
{
errmsg = "incorrect hidden line number";
gotoexit(BFERR_PHONE_UNKNOWN);
}
/*
* Apply overrides to the node information
*/
if( state.override.sFlags )
{
strnxcat(state.node.flags, ",", sizeof(state.node.flags));
strnxcat(state.node.flags, state.override.sFlags, sizeof(state.node.flags));
}
if( opts->iaddr && *opts->iaddr )
{
inet = TRUE;
(void)strnxcpy(state.node.phone,
opts->iaddr, sizeof(state.node.phone));
}
else if( opts->phone && *opts->phone )
{
(void)strnxcpy(state.node.phone,
opts->phone, sizeof(state.node.phone));
}
else if( state.override.sIpaddr )
{
inet = TRUE;
(void)strnxcpy(state.node.phone,
state.override.sIpaddr, sizeof(state.node.phone));
}
else if( state.override.sPhone )
{
(void)strnxcpy(state.node.phone,
state.override.sPhone, sizeof(state.node.phone));
}
if( !inet )
{
if( !modem_isgood_phone(state.node.phone) )
errmsg = "don't know phone number";
}
else
{
if( !tcpip_isgood_host(state.node.phone) )
errmsg = "don't know host name";
}
if( errmsg )
gotoexit(BFERR_PHONE_UNKNOWN);
/*
* Is now a working time for that node/line
*/
if( !inet && !opts->force)
{
time_t unixtime = time(NULL);
struct tm *now = localtime(&unixtime);
bool goodtime;
if( !opts->hiddline )
{
if( state.override.sFlags && !nodelist_checkflag(state.override.sFlags, "CM") )
goodtime = TRUE;
else
{
if( timevec_isdefined(&state.override.worktime) )
goodtime = timevec_isnow(&state.override.worktime, now);
else
{
if( !nodelist_checkflag(state.node.flags, "CM") )
goodtime = TRUE;
else
goodtime = timevec_isnow(&state.node.worktime, now);
}
}
}
else
goodtime = timevec_isnow(&state.override.worktime, now);
if( !goodtime )
{
errmsg = "not works now, try later";
gotoexit(BFERR_NOTWORKING);
}
}
do_session:
/*
* It's easier to ignore than handle! After connect
* new handlers must be installed, don't worry.
*/
signal(SIGHUP, SIG_IGN);
signal(SIGINT, SIG_IGN);
signal(SIGTERM, SIG_IGN);
/*
* Try to lock address of system we are going to call
*/
#ifdef BFORCE_USE_CSY
if( out_bsy_lock(state.node.addr, TRUE) )
#else
if( out_bsy_lock(state.node.addr) )
#endif
{
errmsg = "cannot lock address";
gotoexit(BFERR_SYSTEM_LOCKED);
}
setproctitle("bforce calling %.32s, %.32s",
ftn_addrstr(abuf, state.node.addr), state.node.phone);
if( opts->dontcall )
{
rc = call_system_quiet(opts->connect, opts->inetd);
}
else if( !inet )
{
if( (p_lockdir = conf_string(cf_uucp_lock_directory)) == NULL )
p_lockdir = BFORCE_LOCK_DIR;
if( opts->device && *opts->device )
{
if( (state.modemport =
modem_getmatch_port(opts->device)) == NULL )
{
errmsg = "unknown port name";
gotoexit(BFERR_PORTBUSY);
}
}
else if( (state.modemport =
modem_getfree_port(p_lockdir)) == NULL )
{
errmsg = "no free matching ports";
gotoexit(BFERR_PORTBUSY);
}
if( port_lock(p_lockdir, state.modemport) )
{
errmsg = "cannot lock modem port";
gotoexit(BFERR_PORTBUSY);
}
else /* Successfuly locked port */
{
rc = call_system_modem();
port_unlock(p_lockdir, state.modemport);
}
}
else
{
rc = call_system_tcpip();
}
exit:
out_bsy_unlockall();
if( errmsg )
log("call to %s failed: %s", ftn_addrstr(abuf, addr), errmsg);
log("session rc = %d (\"%s\")", rc, BFERR_NAME(rc));
(void)session_stat_update(&state.node.addr,
&state.sess_stat, TRUE, rc);
deinit_state(&state);
return(rc);
}
+187
View File
@@ -0,0 +1,187 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "nodelist.h"
#include "session.h"
/*
* Environment variables:
* $REM_ADDR_FTN,
* $REM_ADDR_INET,
* $LOC_ADDR_FTN,
* $LOC_ADDR_INET,
* $PASSWORD,
* $MAILER,
* $LOCATION,
* $SYSOP,
* $SYSTEM_NAME
* $PHONE,
* $FLAGS
* $PROTECTED,
* $LISTED,
* $INBOUND
* $CONNECT,
* $CALLERID,
* $RC
*/
int session_run_command(const char *execstr)
{
int rc = 0;
s_faddr *addr;
char abuf[BF_MAXADDRSTR+1];
char sbuf[32];
s_exec_options eopts;
char *p;
exec_options_init(&eopts);
if( state.handshake )
{
if( state.handshake->remote_address
&& (addr = state.handshake->remote_address(state.handshake)) )
{
exec_env_add(&eopts, "REM_ADDR_FTN",
ftn_addrstr_fido(abuf, *addr));
exec_env_add(&eopts, "REM_ADDR_INET",
ftn_addrstr_inet(abuf, *addr));
}
if( state.handshake->local_address
&& (addr = state.handshake->local_address(state.handshake)) )
{
exec_env_add(&eopts, "LOC_ADDR_FTN",
ftn_addrstr_fido(abuf, *addr));
exec_env_add(&eopts, "LOC_ADDR_INET",
ftn_addrstr_inet(abuf, *addr));
}
if( state.handshake->remote_password
&& (p = state.handshake->remote_password(state.handshake)) )
exec_env_add(&eopts, "PASSWORD", p);
if( state.handshake->remote_mailer
&& (p = state.handshake->remote_mailer(state.handshake)) )
exec_env_add(&eopts, "MAILER", p);
if( state.handshake->remote_location
&& (p = state.handshake->remote_location(state.handshake)) )
exec_env_add(&eopts, "LOCATION", p);
if( state.handshake->remote_sysop_name
&& (p = state.handshake->remote_sysop_name(state.handshake)) )
exec_env_add(&eopts, "SYSOP", p);
if( state.handshake->remote_system_name
&& (p = state.handshake->remote_system_name(state.handshake)) )
exec_env_add(&eopts, "SYSTEM_NAME", p);
if( state.handshake->remote_phone
&& (p = state.handshake->remote_phone(state.handshake)) )
exec_env_add(&eopts, "PHONE", p);
if( state.handshake->remote_flags
&& (p = state.handshake->remote_flags(state.handshake)) )
exec_env_add(&eopts, "FLAGS", p);
}
if( state.valid )
{
exec_env_add(&eopts, "PROTECTED", state.protected ? "1" : "0");
exec_env_add(&eopts, "LISTED", state.listed ? "1" : "0");
if( state.inbound && *state.inbound )
exec_env_add(&eopts, "INBOUND", state.inbound);
if( state.connstr && *state.connstr )
exec_env_add(&eopts, "CONNECT", state.connstr);
if( state.cidstr && *state.cidstr )
exec_env_add(&eopts, "CALLERID", state.cidstr);
if( state.session_rc >= 0 )
{
sprintf(sbuf, "%d", state.session_rc);
exec_env_add(&eopts, "RC", sbuf);
}
}
exec_options_set_command(&eopts, execstr);
rc = exec_command(&eopts);
exec_options_deinit(&eopts);
return rc;
}
int override_get(s_override *dest, s_faddr addr, int line)
{
s_override *p;
int curline = 0;
p = conf_override(cf_override, addr);
curline = 0;
while( p && curline < line )
{
p = p->hidden;
++curline;
}
if( p && curline == line )
{
*dest = *p;
return 0;
}
else if( line == 0 )
return 0;
else
return 1;
}
void init_state(s_state *pstate)
{
memset(pstate, '\0', sizeof(s_state));
pstate->session_rc = -1;
}
void deinit_state(s_state *pstate)
{
if( pstate->linename )
free(pstate->linename);
if( pstate->cidstr )
free(pstate->cidstr);
if( pstate->peername )
free(pstate->peername);
if( pstate->connstr )
free(pstate->connstr);
if( pstate->inbound )
free(pstate->inbound);
if( pstate->tinbound )
free(pstate->tinbound);
if( pstate->mailfor )
deinit_falist(pstate->mailfor);
deinit_fsqueue(&pstate->queue);
if( state.handshake && state.handshake->deinit )
state.handshake->deinit(state.handshake);
memset(pstate, '\0', sizeof(s_state));
pstate->session_rc = -1;
}
+507
View File
@@ -0,0 +1,507 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "version.h"
#include "logger.h"
#include "util.h"
#include "io.h"
#include "session.h"
#define INTRO_MAX_SIZE 512
#define INTRO_MAX_LINES 10
#define OUTGOING_MAST_TIMER 60
#define OUTGOING_SYNC_TIMER 5
#define INCOMING_MAST_TIMER 60
#define INCOMING_SYNC_TIMER 2
/* ------------------------------------------------------------------------- */
/* Initiate outbound session and define handshake protocol */
/* On success: zero (state.session is handshake type) */
/* On error: non-zero (state.session set to UNKNOWN) */
/* ------------------------------------------------------------------------- */
int session_init_outgoing(void)
{
int c = 0;
int tries = 0;
int pos_emsi = 0;
int pos_intro = 0;
bool canemsi = FALSE;
bool canyoohoo = FALSE;
bool canftsc = FALSE;
bool canintro = FALSE;
char buf_emsi[13];
char buf_intro[256];
int emsi_seq = 0; /* start reading emsi sequence */
int enqcount = 0; /* number of ENQ received */
int nakcount = 0; /* number of NAK or 'C' received */
int enq_need = 1;
int nak_need = 1;
time_t mast_timer = 0; /* master timer, seems to be 60sec */
time_t sync_timer = 0; /* resync every .. seconds */
long options = conf_options(cf_options);
int intro_lines = 0;
int intro_count = 0;
int unexp_count = 0;
state.session = SESSION_UNKNOWN;
if( (options & OPTIONS_NO_EMSI) != OPTIONS_NO_EMSI )
canemsi = TRUE;
if( (options & OPTIONS_NO_YOOHOO) != OPTIONS_NO_YOOHOO )
canyoohoo = TRUE;
if( (options & OPTIONS_NO_FTS1) != OPTIONS_NO_FTS1 )
canftsc = TRUE;
if( (options & OPTIONS_NO_INTRO) != OPTIONS_NO_INTRO )
canintro = TRUE;
enq_need = canemsi ? 2 : 1;
nak_need = (canemsi || canyoohoo) ? 2 : 1;
/*
* Put CR until any character received
*/
if( PUTCHAR('\r') < 0 || FLUSHOUT() < 0 )
return 1;
while( !CHARWAIT(1) )
{
if( ++tries > 15 )
{
log("too much tries waking remote");
return 1;
}
if( PUTCHAR('\r') < 0 || FLUSHOUT() < 0 )
return 1;
}
#ifdef DEBUG
if( tries > 0 )
DEB((D_HSHAKE, "tx_init: remote waked on %d try", tries));
#endif
/*
* Safety is the 1st law
*/
*buf_emsi = '\0';
*buf_intro = '\0';
/*
* Start timers
*/
timer_set(&mast_timer, OUTGOING_MAST_TIMER);
timer_set(&sync_timer, OUTGOING_SYNC_TIMER*2);
/*
* Determine supported handshakes on called system
* (support for FTS-1, YooHoo, EMSI)
*/
while(1)
{
if( timer_expired(mast_timer) )
{
log("session initialisation timed out");
DEB((D_HSHAKE, "handshake initialisation timed out"));
return 1;
}
if( timer_expired(sync_timer) )
{
DEB((D_HSHAKE, "tx_sendsync: resyncing"));
if( canemsi && PUTSTR("**EMSI_INQC816**EMSI_INQC816") < 0 )
return 1;
if( canyoohoo && PUTCHAR(YOOHOO) < 0 )
return 1;
if( canftsc && PUTCHAR(TSYNC) < 0 )
return 1;
if( canemsi && PUTCHAR('\r') < 0 )
return 1;
if( FLUSHOUT() < 0 )
return 1;
timer_set(&sync_timer, OUTGOING_SYNC_TIMER);
}
/*
* Pickup next char
*/
c = GETCHAR(1);
if( canintro && c > 0 )
{
if( c == XON || c == XOFF )
{
/* Do nothing. Drop them down */
}
else if( c == '\r' || c == '\n' )
{
if( pos_intro > 0 )
{
intro_lines += 1;
intro_count += pos_intro;
recode_intro_in(buf_intro);
log("intro: \"%s\"",
string_printable(buf_intro));
pos_intro = 0;
buf_intro[0] = '\0';
}
}
else if( pos_intro < sizeof(buf_intro) - 1 )
{
buf_intro[pos_intro++] = (char)c;
buf_intro[pos_intro ] = '\0';
}
if( pos_intro >= sizeof(buf_intro) - 1 )
{
intro_lines += 1;
intro_count += pos_intro;
recode_intro_in(buf_intro);
log("intro buffer is full");
log("intro: \"%s\"",
string_printable(buf_intro));
pos_intro = 0;
buf_intro[0] = '\0';
}
if( intro_lines >= INTRO_MAX_LINES )
{
log("stop logging intro: %d lines limit", intro_lines);
canintro = FALSE;
}
else if( intro_count >= INTRO_MAX_SIZE )
{
log("stop logging intro: %d bytes limit", intro_count);
canintro = FALSE;
}
}
if( c < 0 )
{
if( c != TTY_TIMEOUT )
{
DEB((D_HSHAKE, "tx_init: got TTY_ERROR/TTY_HANGUP"));
return 1;
}
}
else if( c == XON || c == XOFF )
{
/* Do nothing. Drop them down */
}
else if( c == ENQ )
{
if( enq_need && ++enqcount >= enq_need && canyoohoo )
{
DEB((D_HSHAKE, "tx_init: exit with YooHoo"));
state.session = SESSION_YOOHOO;
return 0;
}
}
else if( c == TSYNC )
{
if( nak_need && ++nakcount > nak_need && canftsc )
{
DEB((D_HSHAKE, "tx_init: exit with FTS-1"));
state.session = SESSION_FTSC;
return 0;
}
}
else if( canemsi && c > ' ' && c < '~' )
{
if( c != 'C' )
nakcount = 0;
enqcount = 0;
if( c == '*' )
{
memset(buf_emsi, '\0', sizeof(buf_emsi));
pos_emsi = 0;
emsi_seq = 1;
}
else if( emsi_seq )
{
if( pos_emsi < sizeof(buf_emsi)-1 )
{
buf_emsi[pos_emsi++] = (char)c;
buf_emsi[pos_emsi ] = '\0';
}
if( pos_emsi >= sizeof(buf_emsi)-1 )
{
emsi_seq = 0;
DEB((D_HSHAKE, "tx_init: emsi buffer full \"%s\"",
string_printable(buf_emsi)));
if( !strncasecmp(buf_emsi, "EMSI_REQA77E", 12)
|| !strncasecmp(buf_emsi, "EMSI_NAKEEC3", 12) )
{
DEB((D_HSHAKE, "tx_init: exit with EMSI"));
state.session = SESSION_EMSI;
if( PUTSTR("**EMSI_INQC816\r") < 0
|| PUTSTR("**EMSI_INQC816\r") < 0 )
return 1;
if( FLUSHOUT() < 0 )
return 1;
return 0;
}
else if( !strncasecmp(buf_emsi, "EMSI_INQC816", 12) )
{
/*
* Most probable it is echo of
* our own EMSI_INQ, try to send
* separated EMSI_INQ as user
* name and password to be sure
* that they understand us.
*/
/* Wait for a login prompt */
sleep(3);
if( PUTSTR("**EMSI_INQC816\r") < 0
|| FLUSHOUT() < 0 )
return 1;
/* Wait for a password prompt */
sleep(2);
if( PUTSTR("**EMSI_INQC816\r") < 0
|| FLUSHOUT() < 0 )
return 1;
timer_set(&sync_timer, OUTGOING_SYNC_TIMER);
}
else if( !strncasecmp(buf_emsi, "EMSI", 4) )
{
log("unexpected emsi sequence \"%s\"",
string_printable(buf_emsi));
if( ++unexp_count > 10 )
{
log("too many unexpected emsi sequences");
return 1;
}
}
}
}
}
else if( emsi_seq )
{
emsi_seq = 0;
DEB((D_HSHAKE, "sm_rx_waitseq: bad character 0x%02x in \"%s\"",
c, string_printable(buf_emsi)));
}
}
return 1;
}
/* ------------------------------------------------------------------------- */
/* Initiate inbound session and define handshake protocol */
/* On success: return zero (state.session defines handshake type) */
/* On error: return non-zero (state.session set to HSHAKE_UNKNOWN) */
/* */
/* TODO: It is not working yet, it only reports about EMSI requests.. (1) */
/* ------------------------------------------------------------------------- */
int session_init_incoming(void)
{
int c = 0;
int pos = 0;
bool canemsi = FALSE;
bool canyoohoo = FALSE;
bool canftsc = FALSE;
char buf[13];
int emsi_seq = 0; /* start reading emsi sequence */
int yoohoo_count = 0; /* number of ENQ received */
int tsync_count = 0; /* number of NAK or 'C' received */
int yoohoo_need = 1;
int tsync_need = 1;
time_t mast_timer = 0; /* master timer, seems to be 60sec */
time_t sync_timer = 0;
long options = conf_options(cf_options);
int unexp_count = 0;
state.session = SESSION_UNKNOWN;
if( (options & OPTIONS_NO_EMSI) != OPTIONS_NO_EMSI )
canemsi = TRUE;
if( (options & OPTIONS_NO_YOOHOO) != OPTIONS_NO_YOOHOO )
canyoohoo = TRUE;
if( (options & OPTIONS_NO_FTS1) != OPTIONS_NO_FTS1 )
canftsc = TRUE;
yoohoo_need = canemsi ? 2 : 1;
tsync_need = (canemsi || canyoohoo) ? 2 : 1;
if( PUTCHAR('\r') < 0 )
return 1;
/*
* Output banner
*/
if( canemsi && PUTSTR("**EMSI_REQA77E\r") < 0 )
return 1;
if( state.connstr )
{
/* Show connect string */
if( PUTCHAR('[') < 0 )
return 1;
if( PUTSTR(state.connstr) < 0 )
return 1;
if( PUTSTR("]\n") < 0 )
return 1;
}
if( PUTSTR(BF_BANNERVER) < 0 || PUTCHAR(' ') < 0
|| PUTSTR(BF_COPYRIGHT) < 0 || PUTCHAR('\n') < 0 )
return 1;
if( FLUSHOUT() < 0 )
return 1;
/* Start timers */
timer_set(&mast_timer, INCOMING_MAST_TIMER);
timer_set(&sync_timer, INCOMING_SYNC_TIMER/2);
/*
* Determine supported handshakes on called system
* (support for FTS-1, YooHoo, EMSI)
*/
while(1)
{
if( timer_expired(mast_timer) )
{
log("session initialisation timed out");
DEB((D_HSHAKE, "handshake initialisation timed out"));
return 1;
}
if( timer_expired(sync_timer) )
{
DEB((D_HSHAKE, "rx_init: resyncing"));
if( canemsi && PUTSTR("**EMSI_REQA77E\r") < 0 )
return 1;
if( FLUSHOUT() < 0 )
return 1;
timer_set(&sync_timer, INCOMING_SYNC_TIMER);
}
/*
* Pickup next char
*/
if( (c = GETCHAR(1)) < 0 )
{
if( c != TTY_TIMEOUT )
{
DEB((D_HSHAKE, "rx_init: got TTY_ERROR/TTY_HANGUP"));
return 1;
}
}
else if( c == XON || c == XOFF )
{
/* Do nothing. Drop them down */
}
else if( c == YOOHOO )
{
if( ++yoohoo_count >= yoohoo_need && canyoohoo )
{
DEB((D_HSHAKE, "rx_init: exit with YooHoo"));
state.session = SESSION_YOOHOO;
return 0;
}
}
else if( c == TSYNC )
{
if( ++tsync_count > tsync_need && canftsc )
{
DEB((D_HSHAKE, "rx_init: exit with FTS-1"));
state.session = SESSION_FTSC;
return 0;
}
}
else if( canemsi && c > ' ' && c < '~' )
{
tsync_count = 0;
yoohoo_count = 0;
if( c == '*' )
{
memset(buf, '\0', sizeof(buf));
pos = 0;
emsi_seq = 1;
}
else if( emsi_seq )
{
if( pos < sizeof(buf)-1 )
{
buf[pos++] = (char)(c & 0xff);
buf[pos ] = '\0';
}
if( pos >= sizeof(buf)-1 )
{
emsi_seq = 0;
DEB((D_HSHAKE, "rx_init: emsi buffer full \"%s\"",
string_printable(buf)));
if( !strncasecmp(buf, "EMSI_INQC816", 12) )
{
DEB((D_HSHAKE, "rx_init: exit with EMSI"));
state.session = SESSION_EMSI;
return 0;
}
else if( !strncasecmp(buf, "EMSI", 4) )
{
log("unexpected emsi sequence \"%s\"",
string_printable(buf));
if( ++unexp_count > 10 )
{
log("too many unexpected emsi sequences");
return 1;
}
}
}
}
}
else if( emsi_seq )
{
emsi_seq = 0;
DEB((D_HSHAKE, "rx_init: bad character 0x%02x in \"%s\"",
c, string_printable(buf)));
}
}
return 1;
}
+872
View File
@@ -0,0 +1,872 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "bforce.h"
#include "util.h"
#include "nodelist.h"
#include "session.h"
#include "prot_zmodem.h"
#include "prot_yoohoo.h"
#include "prot_emsi.h"
#include "prot_binkp.h"
/* All session information stores here */
s_state state;
int hydra(s_protinfo *pi, bool flag_RH1);
s_faddr *session_get_bestaka(s_faddr addr)
{
s_cval_entry *addr_ptr;
s_cval_entry *hide_ptr;
s_faddr *best = NULL;
int bestl = 0;
int curl = 0;
for( addr_ptr = conf_first(cf_address); addr_ptr;
addr_ptr = conf_next(addr_ptr) )
{
for( hide_ptr = conf_first(cf_hide_our_aka); hide_ptr;
hide_ptr = conf_next(hide_ptr) )
{
if( !ftn_addrcomp(hide_ptr->d.falist.addr, addr_ptr->d.falist.addr) )
break;
}
if( !hide_ptr )
{
curl = ftn_addrsmetric(addr_ptr->d.falist.addr, addr);
if( curl > bestl || best == NULL )
{
bestl = curl;
best = &addr_ptr->d.falist.addr;
}
}
}
return best;
}
int session_addrs_lock(s_sysaddr *addrs, int anum)
{
int i;
char abuf[BF_MAXADDRSTR+1];
bool one_lock = FALSE;
for( i = 0; i < anum; i++ )
{
if( addrs[i].good )
{
#ifdef BFORCE_USE_CSY
if( out_bsy_lock(addrs[i].addr, FALSE) )
#else
if( out_bsy_lock(addrs[i].addr) )
#endif
{
log("exclude address %s: allready locked",
ftn_addrstr(abuf, addrs[i].addr));
addrs[i].busy = TRUE;
}
else
one_lock = TRUE;
}
}
return one_lock ? 0 : -1;
}
int session_addrs_add(s_sysaddr **addrs, int *anum, s_faddr addr)
{
int i;
char abuf[BF_MAXADDRSTR+1];
if( *anum && *addrs )
{
/* Check for addresses duplication */
for( i = 0; i < *anum; i++ )
{
if( !ftn_addrcomp((*addrs)[i].addr, addr) )
{
log("exclude address %s: duplicated address",
ftn_addrstr(abuf, addr));
return -1;
}
}
}
if( *addrs && *anum )
*addrs = xrealloc(*addrs, sizeof(s_sysaddr)*(*anum+1));
else
*addrs = xmalloc(sizeof(s_sysaddr));
memset(&(*addrs)[*anum], '\0', sizeof(s_sysaddr));
(*addrs)[*anum].addr = addr;
(*addrs)[*anum].busy = FALSE;
(*addrs)[*anum].good = FALSE;
++(*anum);
return 0;
}
int session_addrs_check(s_sysaddr *addrs, int anum, const char *passwd,
const char *challenge, int challenge_length)
{
int i;
char abuf[BF_MAXADDRSTR+1];
char pbuf[32];
bool failure = FALSE;
bool success = FALSE;
bool cram = (challenge && *challenge);
if( !anum )
return -1;
for( i = 0; i < anum; i++ )
{
if( session_check_addr(addrs[i].addr) )
{
log("exclude address %s: not acceptable",
ftn_addrstr(abuf, addrs[i].addr));
continue;
}
if( !session_get_password(addrs[i].addr, pbuf, sizeof(pbuf)) )
{
bool good_passwd = FALSE;
if( passwd && *passwd )
{
if( cram )
{
char digest_bin[16];
char digest_hex[33];
md5_cram_get(pbuf, challenge, challenge_length, digest_bin);
/* Encode digest to the hex string */
string_bin_to_hex(digest_hex, digest_bin, 16);
if( strcasecmp(passwd, digest_hex) == 0 )
good_passwd = TRUE;
}
else if( strcasecmp(passwd, pbuf) == 0 )
good_passwd = TRUE;
}
if( good_passwd )
{
/* correct password */
addrs[i].good = TRUE;
state.protected = TRUE;
success = TRUE;
}
else
{
log("exclude address %s: bad password",
ftn_addrstr(abuf, addrs[i].addr));
addrs[i].good = FALSE;
failure = TRUE;
}
}
else
/* not password protected address */
addrs[i].good = TRUE;
}
/*
* Return error, if received password is incorrect for all AKAs
*/
if( failure && !success )
return -1;
return 0;
}
int session_addrs_to_falist(s_sysaddr *addrs, int anum, s_falist **dest)
{
int i;
for( i = 0; i < anum; i++ )
{
if( !addrs[i].busy && addrs[i].good )
{
(*dest) = (s_falist *)xmalloc(sizeof(s_falist));
memset(*dest, '\0', sizeof(s_falist));
(*dest)->addr = addrs[i].addr;
dest = (s_falist**)&((*dest)->next);
}
}
return 0;
}
int session_addrs_check_genuine(s_sysaddr *addrs, int anum, s_faddr expected)
{
int i;
for( i = 0; i < anum; i++ )
{
if( !ftn_addrcomp(addrs[i].addr, expected) )
return 0;
}
return 1;
}
/* ------------------------------------------------------------------------- */
/* Return non-zero value if current speed too low */
/* ------------------------------------------------------------------------- */
int session_check_speed(void)
{
state.minspeed = conf_number(cf_min_speed_in);
if( state.connspeed > 0 && state.minspeed > state.connspeed )
return 1;
return 0;
}
int session_check_addr(s_faddr addr)
{
s_cval_entry *addr_ptr;
for( addr_ptr = conf_first(cf_address); addr_ptr;
addr_ptr = conf_next(addr_ptr) )
{
if( !ftn_addrcomp(addr, addr_ptr->d.falist.addr) )
return 1;
}
return 0;
}
/* ------------------------------------------------------------------------- */
/* Get session password for address $addr, put it in $buf */
/* If no password found - return non-zero value */
/* ------------------------------------------------------------------------- */
int session_get_password(s_faddr addr, char *buffer, size_t buflen)
{
s_cval_entry *pwd_ptr;
for( pwd_ptr = conf_first(cf_password); pwd_ptr;
pwd_ptr = conf_next(pwd_ptr) )
{
if( !ftn_addrcomp(addr, pwd_ptr->d.falist.addr) )
{
strnxcpy(buffer, pwd_ptr->d.falist.what, buflen);
return 0;
}
}
return 1;
}
int session_remote_lookup(s_sysaddr *addrs, int anum)
{
int i;
for( i = 0; i < anum; i++ )
{
if( addrs[i].good )
{
nodelist_lookup(&state.node, addrs[i].addr);
state.node.addr.domain[0] = '\0';
state.listed = state.node.listed;
break;
}
}
return (i < anum) ? 0 : -1;
}
void session_remote_log_status(void)
{
log("remote is %s,%s",
(state.listed) ? "listed" : "unlisted",
(state.protected) ? "protected" : "unprotected");
}
/* ------------------------------------------------------------------------- */
/* Set inbound directory, create temporary inbound in it, check permissions */
/* If something wrong - return non-zero value */
/* ------------------------------------------------------------------------- */
int session_set_inbound(void)
{
struct stat st;
char *p_inb;
if( (p_inb = conf_string(cf_inbound_directory)) )
{
state.inbound = (char*)xstrcpy(p_inb);
}
else
{
log("no inbound specified, assume \"./\"");
state.inbound = (char*)xstrcpy("./");
}
state.tinbound = (char*)xstrcpy(state.inbound);
state.tinbound = (char*)xstrcat(state.tinbound, "tmp/");
/*
* Warning, access() make checks using real uid and gid
* (not effective), so we can fail, but..
*/
if( stat(state.tinbound, &st) == 0 )
{
if( (st.st_mode & S_IFDIR) != S_IFDIR )
{
log("temporary inbound \"%s\" is not directory", state.tinbound);
return(1);
}
else if( access(state.tinbound, R_OK|W_OK|X_OK) )
{
log("have no r/w permission to temporary inbound \"%s\"", state.tinbound);
return(1);
}
}
else if( errno == ENOENT )
{
/* "tmp" inbound doesn't exist */
if( mkdir(state.tinbound, 0700) < 0 )
{
logerr("can't create temporary inbound \"%s\"", state.tinbound);
return(1);
}
chmod(state.tinbound, 0700);
}
else
{
/* Different stat() errors */
logerr("can't stat temporary inbound \"%s\"", state.tinbound);
return 1;
}
return(0);
}
/* ------------------------------------------------------------------------- */
/* Set status of _OUR_ FREQ processor */
/* ------------------------------------------------------------------------- */
void session_set_freqs_status(void)
{
int root_ok = 0;
int magc_ok = 0;
char *p;
long options;
state.reqstat = REQS_DISABLED;
options = conf_options(cf_options);
if( (options & OPTIONS_MAILONLY) == OPTIONS_MAILONLY
|| (options & OPTIONS_NO_FREQS) == OPTIONS_NO_FREQS )
{ state.reqstat = REQS_NOTALLOW; return; }
if( state.connspeed > 0
&& state.connspeed < conf_number(cf_freq_min_speed) )
{ state.reqstat = REQS_NOTALLOW; return; }
if( (p = conf_string(cf_freq_srif_command)) && *p )
{
/*
* Can we execute this processor? Disable freqs if we can't!
*/
if( !exec_file_exist(p) )
state.reqstat = REQS_ALLOW;
else
logerr("can't stat SRIF processor \"%s\"", p);
}
else
{
/* Check root dir */
if( (p = conf_string(cf_freq_dir_list)) && *p )
{
if( access(p, R_OK) == 0 )
root_ok = 1;
else
logerr("can't stat FREQ dir list \"%s\"", p);
}
/* Check magic dir */
if( (p = conf_string(cf_freq_alias_list)) && *p )
{
if( access(p, R_OK) == 0 )
magc_ok = 1;
else
logerr("can't stat FREQ alias list \"%s\"", p);
}
/* Set FREQ processor status */
if( root_ok || magc_ok )
state.reqstat = REQS_ALLOW;
}
}
/* ------------------------------------------------------------------------- */
/* Set our "send options" (common part, based on our local settings) */
/* ------------------------------------------------------------------------- */
void session_set_send_options(void)
{
const long options = conf_options(cf_options);
if( state.caller == FALSE )
state.sopts.holdreq = 1;
if( (options & OPTIONS_MAILONLY) == OPTIONS_MAILONLY )
state.sopts.holdxt = 1;
if( (options & OPTIONS_HOLDXT) == OPTIONS_HOLDXT )
state.sopts.holdxt = 1;
if( (options & OPTIONS_HOLDREQ) == OPTIONS_HOLDREQ )
state.sopts.holdreq = 1;
if( (options & OPTIONS_HOLDALL) == OPTIONS_HOLDALL )
state.sopts.holdall = 1;
if( (options & OPTIONS_HOLDHOLD) == OPTIONS_HOLDHOLD )
state.sopts.holdhold = 1;
}
/* ------------------------------------------------------------------------- */
/* Return (non-zero) if we _CAN'T_ send this file NOW! */
/* ------------------------------------------------------------------------- */
static int holdfile(s_filelist *fi, const char *delayout)
{
if( state.sopts.holdall ) return(1);
if( state.sopts.holdxt && !(fi->type & TYPE_NETMAIL) ) return(1);
if( state.sopts.holdreq && (fi->type & TYPE_REQUEST) ) return(1);
if( state.sopts.holdhold && fi->flavor == FLAVOR_HOLD ) return(1);
if( fi->status != STATUS_WILLSEND ) return(1);
if( delayout && !checkmasks(delayout, fi->fname) ) return(2);
return 0;
}
/* ------------------------------------------------------------------------- */
/* Set SKIP flag for files we can't send NOW */
/* ------------------------------------------------------------------------- */
void session_set_send_files(void)
{
int holdmsg = 0, rc = 0;
s_filelist *ptrl = NULL;
const char *delayout = conf_string(cf_delay_files_send);
for( ptrl = state.queue.fslist; ptrl; ptrl = ptrl->next )
if( (rc = holdfile(ptrl, delayout)) )
{
if( rc == 2 && !holdmsg )
{
log("delaying files \"%s\"", delayout);
++holdmsg;
}
ptrl->status = STATUS_SKIP;
}
}
int session_create_files_queue(s_sysaddr *addrs, int anum)
{
s_falist *mailfor = NULL;
s_outbound_callback_data ocb;
/* Set addresses for which we will send files */
(void)session_addrs_to_falist(addrs, anum, &mailfor);
/* Scan outbound directory */
if( mailfor )
{
memset(&ocb, '\0', sizeof(s_outbound_callback_data));
ocb.callback = out_handle_fsqueue;
ocb.dest = (void *)&state.queue;
(void)out_scan(&ocb, mailfor);
(void)session_set_send_files();
(void)session_traffic_set_outgoing(&state.traff_send);
}
return 0;
}
int session_traffic_set_incoming(s_traffic *dest)
{
memset(dest, '\0', sizeof(s_traffic));
if( state.handshake && state.handshake->remote_traffic )
return state.handshake->remote_traffic(state.handshake, dest);
return -1;
}
int session_traffic_set_outgoing(s_traffic *dest)
{
s_filelist *ptrl;
memset(dest, '\0', sizeof(s_traffic));
for( ptrl = state.queue.fslist; ptrl; ptrl = ptrl->next )
{
if( ptrl->type & TYPE_NETMAIL )
{
dest->netmail_size += ptrl->size;
dest->netmail_num++;
}
else if( ptrl->type & TYPE_ARCMAIL )
{
dest->arcmail_size += ptrl->size;
dest->arcmail_num++;
}
else
{
dest->files_size += ptrl->size;
dest->files_num++;
}
}
return 0;
}
void session_traffic_log(bool incoming, s_traffic *traff)
{
char buf[32];
char msg[128] = "";
if( traff == NULL )
strcpy(msg, "unknown");
else if( traff->netmail_size == 0
&& traff->arcmail_size == 0 && traff->files_size == 0 )
strcpy(msg, "none");
else
{
if( traff->netmail_size > 0 )
{
string_humansize(buf, traff->netmail_size);
strcat(msg, buf);
strcat(msg, " netmail, ");
}
if( traff->arcmail_size > 0 )
{
string_humansize(buf, traff->arcmail_size);
strcat(msg, buf);
strcat(msg, " arcmail, ");
}
if( traff->files_size > 0 )
{
string_humansize(buf, traff->files_size);
strcat(msg, buf);
strcat(msg, " files, ");
}
if( *msg )
msg[strlen(msg)-2] = '\0';
}
log("%s traffic: %s", incoming ? "incoming" : "outgoing", msg);
}
void session_traffic(void)
{
int rc;
rc = session_traffic_set_incoming(&state.traff_recv);
session_traffic_log(TRUE, rc ? NULL : &state.traff_recv);
/* Outgoing traffic must be allread calculated */
session_traffic_log(FALSE, &state.traff_send);
}
/*
* History file line format:
* line verbal name,
* remote address,
* session start time (Unix),
* session_length (seconds),
* session status flags (L - listed, P - protected),
* session result code (one of mailer return codes),
* size of sent netmail,
* size of sent arcmail,
* size of sent files,
* size of received netmail,
* size of received arcmail,
* size of received files
*/
void session_update_history(s_traffic *send, s_traffic *recv, int rc)
{
FILE *hist_fp;
char *hist_file = conf_string(cf_history_file);
char abuf[BFORCE_MAX_ADDRSTR+1];
char session_status[32] = "";
if( !hist_file )
return;
hist_fp = file_open(hist_file, "a");
if( !hist_fp )
{
logerr("cannot open history file \"%s\"", hist_file);
return;
}
if( state.listed )
strcat(session_status, "L");
if( state.protected )
strcat(session_status, "P");
if( state.caller )
strcat(session_status, "O");
else
strcat(session_status, "I");
fprintf(hist_fp, "%s,%s,%lu,%u,%s,%d,%lu,%lu,%lu,%lu,%lu,%lu\n",
state.linename ? state.linename : "",
state.node.addr.zone ? ftn_addrstr(abuf, state.node.addr) : "",
(unsigned long) state.start_time,
(unsigned int) time_elapsed(state.start_time),
session_status,
rc,
(unsigned long) send->netmail_size,
(unsigned long) send->arcmail_size,
(unsigned long) (send->files_size + send->freqed_size),
(unsigned long) recv->netmail_size,
(unsigned long) recv->arcmail_size,
(unsigned long) (recv->files_size + recv->freqed_size));
(void)file_close(hist_fp);
}
/* ------------------------------------------------------------------------- */
/* Start session with another FTN mailer */
/* ------------------------------------------------------------------------- */
int session(void)
{
s_protinfo pi;
int rc = BFERR_NOERROR;
s_traffic traff_send;
s_traffic traff_recv;
char *p;
memset(&traff_send, '\0', sizeof(s_traffic));
memset(&traff_recv, '\0', sizeof(s_traffic));
/* Store session start time */
state.start_time = time(NULL);
if( state.session == SESSION_UNKNOWN )
{
rc = state.caller ? session_init_outgoing()
: session_init_incoming();
if( rc )
gotoexit(BFERR_HANDSHAKE_ERROR);
}
/* -------------------------------------------------------------- */
/* Handshake part */
/* -------------------------------------------------------------- */
switch( state.session ) {
case SESSION_EMSI:
state.handshake = &handshake_protocol_emsi;
break;
case SESSION_BINKP:
state.handshake = &handshake_protocol_binkp;
break;
case SESSION_YOOHOO:
state.handshake = &handshake_protocol_yoohoo;
break;
case SESSION_FTSC:
log("%sbound FTS-1 session", state.caller?"out":"in");
log("FTS-1 session not availabe");
gotoexit(BFERR_HANDSHAKE_ERROR);
case SESSION_UNKNOWN:
ASSERT_MSG();
gotoexit(BFERR_HANDSHAKE_ERROR);
default:
ASSERT_MSG();
gotoexit(BFERR_HANDSHAKE_ERROR);
}
state.handshake->init(state.handshake);
log("%sbound %s session",
state.caller ? "out" : "in", state.handshake->verbal_name);
rc = state.caller ? state.handshake->outgoing_session(state.handshake)
: state.handshake->incoming_session(state.handshake);
DEB((D_PROT, "session: handshake rc = %d", rc));
if( rc != HRC_OK )
{
const char *errmsg = NULL;
switch(rc) {
case HRC_LOW_SPEED:
errmsg = "connect speed too low";
rc = BFERR_CONNECT_TOOLOW;
break;
case HRC_BAD_PASSWD:
errmsg = "security violation";
rc = BFERR_HANDSHAKE_ERROR;
break;
case HRC_NO_ADDRESS:
errmsg = "no expected address was presented";
rc = BFERR_HANDSHAKE_ERROR;
break;
case HRC_NO_PROTOS:
errmsg = "no common protocols";
rc = BFERR_HANDSHAKE_ERROR;
break;
case HRC_BUSY:
errmsg = "all remote addresses are busy";
rc = BFERR_HANDSHAKE_ERROR;
break;
case HRC_FATAL_ERR:
case HRC_TEMP_ERR:
case HRC_OTHER_ERR:
errmsg = NULL;
rc = BFERR_HANDSHAKE_ERROR;
break;
default:
errmsg = "unexpected error number";
rc = BFERR_HANDSHAKE_ERROR;
break;
}
if( errmsg )
log("abort session due to: %s", errmsg);
}
else
{
/*
* Execute 'run_after_handshake' command
*/
if( (p = conf_string(cf_run_after_handshake)) )
session_run_command(p);
/*
* Files transfer part
*/
DEB((D_FREQ, "setreqstat: Our FREQ processor status: \"%s\"",
( state.reqstat == REQS_ALLOW ) ? "Allowed":
( state.reqstat == REQS_NOTALLOW ) ? "Not allowed now":
( state.reqstat == REQS_DISABLED ) ? "No FREQs available":"Error"));
DEB((D_HSHAKE, "session: decided to use %s protocol",
Protocols[state.handshake->protocol]));
/*
* Log expected traffic
*/
session_traffic();
init_protinfo(&pi, state.caller);
switch(state.handshake->protocol) {
case PROT_BINKP:
rc = binkp_transfer(&pi);
break;
case PROT_ZMODEM:
case PROT_ZEDZAP:
case PROT_DIRZAP:
rc = state.caller ? tx_zmodem(&pi, state.caller)
: rx_zmodem(&pi, state.caller);
if( rc == PRC_NOERROR )
{
rc = state.caller ? rx_zmodem(&pi, state.caller)
: tx_zmodem(&pi, state.caller);
}
break;
case PROT_JANUS:
log("Janus is not available in current version");
break;
case PROT_HYDRA:
rc = hydra(&pi, state.sopts.hydraRH1);
break;
case PROT_NOPROT:
log("no common protocols available");
break;
default:
ASSERT_MSG();
break;
}
/*
* Convert value returned by protocol to the BForce return code
*/
switch(rc) {
case PRC_NOERROR: rc = BFERR_NOERROR; break;
case PRC_ERROR:
case PRC_REMOTEABORTED:
case PRC_LOCALABORTED: rc = BFERR_XMITERROR; break;
case PRC_CPSTOOLOW: rc = BFERR_CPSTOOLOW; break;
case PRC_STOPTIME: rc = BFERR_STOPTIME; break;
default: ASSERT_MSG();
}
state.session_rc = rc;
/*
* Do session clenup (remove temp. files, etc.)
*/
(void)p_session_cleanup(&pi, (rc == BFERR_NOERROR));
if( rc == BFERR_NOERROR )
{
/*
* Flush our 'stdout' buffer
*/
FLUSHOUT();
/*
* Remove empty .?lo files
*/
(void)out_flo_unlinkempty(state.queue.flotab, state.queue.flonum);
/*
* Wait a little if we are answering on incoming call
* (to be sure that all data will be sent) (?)
*/
if( !state.caller ) sleep(1);
}
/*
* Remove all .bsy locks
*/
out_bsy_unlockall();
/*
* Write total amount of received/sent bytes, files, etc.
*/
p_log_txrxstat(&pi);
/*
* Save session traffic before deiniting
*/
traff_send = pi.traffic_sent;
traff_recv = pi.traffic_rcvd;
deinit_protinfo(&pi);
/*
* Execute 'run_after_session' command
*/
if( (p = conf_string(cf_run_after_session)) )
session_run_command(p);
}
exit:
state.session_rc = rc;
session_update_history(&traff_send, &traff_recv, rc);
return rc;
}
+304
View File
@@ -0,0 +1,304 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "bforce.h"
#include "util.h"
#include "nodelist.h"
#include "session.h"
/*
* Format of 'sts' files (project only..)
*
* Header:
* 0 byte - version (current is 1)
* 1 byte - global undialable flag (for all lines)
* 2 word - tries
* 4 word - handshake tries
* 6 dword - hold all calls until
* 8 dword - node will not accept our file requests till this time
* 10 dword - last successfull outgoing session
* 12 dword - last successfull incoming session
*
* Each entry (per-line statistics)
*/
void session_stat_reset_counters(s_sess_stat *stat)
{
stat->tries = TRIES_RESET;
stat->tries_noansw = TRIES_RESET;
stat->tries_noconn = TRIES_RESET;
stat->tries_nodial = TRIES_RESET;
stat->tries_hshake = TRIES_RESET;
stat->tries_sessns = TRIES_RESET;
}
static char *session_stat_get_stsfile(s_faddr *addr, int linenum)
{
char buf[32];
char *yield = NULL;
char *p_stsdir = conf_string(cf_status_directory);
if( p_stsdir && *p_stsdir )
{
if( linenum == -1 )
sprintf(buf, "%u.%u.%u.%u.sts",
addr->zone, addr->net,
addr->node, addr->point);
else
sprintf(buf, "%u.%u.%u.%u-%u.sts",
addr->zone, addr->net,
addr->node, addr->point, linenum);
yield = string_concat(p_stsdir, buf, NULL);
}
return yield;
}
static int session_stat_read_stsfile(FILE *fp, s_sess_stat *stat)
{
if( fseek(fp, 0, SEEK_SET) == -1 )
return -1;
memset(stat, '\0', sizeof(s_sess_stat));
fscanf(fp, "%u %u %u %u %u %u %lu %lu %lu %lu",
(unsigned int *) &stat->tries,
(unsigned int *) &stat->tries_noconn,
(unsigned int *) &stat->tries_noansw,
(unsigned int *) &stat->tries_nodial,
(unsigned int *) &stat->tries_hshake,
(unsigned int *) &stat->tries_sessns,
(unsigned long *) &stat->hold_until,
(unsigned long *) &stat->hold_freqs,
(unsigned long *) &stat->last_success_out,
(unsigned long *) &stat->last_success_in);
/* Set last successfull session time */
stat->last_success = MAX(stat->last_success_out, stat->last_success_in);
return 0;
}
static int session_stat_write_stsfile(FILE *fp, s_sess_stat *stat)
{
if( fseek(fp, 0, SEEK_SET) == -1 )
return -1;
fprintf(fp, "%u %u %u %u %u %u %lu %lu %lu %lu",
(unsigned int) stat->tries,
(unsigned int) stat->tries_noconn,
(unsigned int) stat->tries_noansw,
(unsigned int) stat->tries_nodial,
(unsigned int) stat->tries_hshake,
(unsigned int) stat->tries_sessns,
(unsigned long) stat->hold_until,
(unsigned long) stat->hold_freqs,
(unsigned long) stat->last_success_out,
(unsigned long) stat->last_success_in);
return 0;
}
static int session_stat_update_stsfile(const char *stsname, s_sess_stat *stat)
{
int rc = 0;
FILE *sts_fp = NULL;
s_sess_stat tmpstat;
bool stsexist = FALSE;
memset(&tmpstat, '\0', sizeof(s_sess_stat));
stsexist = (access(stsname, R_OK) == 0);
if( (sts_fp = file_open(stsname, stsexist ? "r+" : "w")) == NULL )
{
logerr("cannot open status file \"%s\"", stsname);
gotoexit(-1);
}
if( stsexist )
{
/* Ignore read errors */
(void)session_stat_read_stsfile(sts_fp, &tmpstat);
if( ftruncate(fileno(sts_fp), 0) == -1 )
{
logerr("cannot truncate status file \"%s\"", stsname);
gotoexit(-1);
}
}
/*
* Update statistic
*/
if( stat->tries == TRIES_RESET )
tmpstat.tries = 0;
else
tmpstat.tries += stat->tries;
if( stat->tries_noconn == TRIES_RESET )
tmpstat.tries_noconn = 0;
else
tmpstat.tries_noconn += stat->tries_noconn;
if( stat->tries_nodial == TRIES_RESET )
tmpstat.tries_nodial = 0;
else
tmpstat.tries_nodial += stat->tries_nodial;
if( stat->tries_noansw == TRIES_RESET )
tmpstat.tries_noansw = 0;
else
tmpstat.tries_noansw += stat->tries_noansw;
if( stat->tries_hshake == TRIES_RESET )
tmpstat.tries_hshake = 0;
else
tmpstat.tries_hshake += stat->tries_hshake;
if( stat->tries_sessns == TRIES_RESET )
tmpstat.tries_sessns = 0;
else
tmpstat.tries_sessns += stat->tries_sessns;
if( stat->hold_until == HOLD_RESET )
tmpstat.hold_until = 0;
else if( stat->hold_until > tmpstat.hold_until )
tmpstat.hold_until = stat->hold_until;
if( stat->hold_freqs == HOLD_RESET )
tmpstat.hold_freqs = 0;
else if( stat->hold_freqs > tmpstat.hold_freqs )
tmpstat.hold_freqs = stat->hold_freqs;
if( stat->last_success_out > tmpstat.last_success_out )
tmpstat.last_success_out = stat->last_success_out;
if( stat->last_success_in > tmpstat.last_success_in )
tmpstat.last_success_in = stat->last_success_in;
/*
* Write new statistic to the 'sts' file
*/
if( session_stat_write_stsfile(sts_fp, &tmpstat) == -1 )
{
logerr("error writing status file \"%s\"", stsname);
gotoexit(-1);
}
exit:
if( sts_fp )
file_close(sts_fp);
return rc;
}
int session_stat_get(s_sess_stat *stat, s_faddr *addr)
{
FILE *fp;
char *stsname = session_stat_get_stsfile(addr, -1);
memset(stat, '\0', sizeof(s_sess_stat));
if( stsname )
{
fp = file_open(stsname, "r");
if( !fp )
{
free(stsname);
return -1;
}
(void)session_stat_read_stsfile(fp, stat);
(void)file_close(fp);
free(stsname);
}
return 0;
}
int session_stat_apply_diff(s_faddr addr, s_sess_stat stat)
{
int rc;
char *stsname = session_stat_get_stsfile(&addr, -1);
if( !stsname )
return -1;
rc = session_stat_update_stsfile(stsname, &stat);
free(stsname);
return rc;
}
int session_stat_update(s_faddr *addr, s_sess_stat *stat, bool caller, int rc)
{
char *stsname;
/*
* Update sessions statistic depending on session
* return code. The latter must be one of BFERR
* values. Warning, stat structure might allready
* contain desired settings!
*/
if( rc == BFERR_NOERROR )
{
if( caller )
stat->last_success_out = time(NULL);
else
stat->last_success_in = time(NULL);
session_stat_reset_counters(stat);
}
else
{
if( caller )
{
stat->tries++;
if( rc == BFERR_HANDSHAKE_ERROR )
stat->tries_hshake++;
if( rc == BFERR_CANT_CONNECT14 )
stat->tries_noansw++;
if( rc == BFERR_CANT_CONNECT13 )
stat->tries_nodial++;
if( BFERR_CANT_CONNECT10 <= rc && rc <= BFERR_CANT_CONNECT19 )
stat->tries_noconn++;
if( rc >= BFERR_CONNECT_TOOLOW )
stat->tries_sessns++;
/* Reset some counters */
if( rc >= BFERR_CONNECT_TOOLOW )
{
stat->tries_noansw = TRIES_RESET;
stat->tries_noconn = TRIES_RESET;
}
if( rc > BFERR_HANDSHAKE_ERROR )
stat->tries_hshake = TRIES_RESET;
}
}
stsname = session_stat_get_stsfile(addr, -1);
if( !stsname )
return -1;
rc = session_stat_update_stsfile(stsname, stat);
free(stsname);
return rc;
}
+206
View File
@@ -0,0 +1,206 @@
/* First, the polynomial itself and its table of feedback terms. The */
/* polynomial is */
/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */
/* Note that we take it "backwards" and put the highest-order term in */
/* the lowest-order bit. The X^32 term is "implied"; the LSB is the */
/* X^31 term, etc. The X^0 term (usually shown as "+1") results in */
/* the MSB being 1. */
/* */
/* Note that the usual hardware shift register implementation, which */
/* is what we're using (we're merely optimizing it by doing eight-bit */
/* chunks at a time) shifts bits into the lowest-order term. In our */
/* implementation, that means shifting towards the right. Why do we */
/* do it this way? Because the calculated CRC must be transmitted in */
/* order from highest-order term to lowest-order term. UARTs transmit */
/* characters in order from LSB to MSB. By storing the CRC this way, */
/* we hand it to the UART in the order low-byte to high-byte; the UART */
/* sends each low-bit to hight-bit; and the result is transmission bit */
/* by bit from highest- to lowest-order term without requiring any bit */
/* shuffling on our part. Reception works similarly. */
/* */
/* The feedback terms table consists of 256, 32-bit entries. Notes: */
/* */
/* The table can be generated at runtime if desired; code to do so */
/* is shown later. It might not be obvious, but the feedback */
/* terms simply represent the results of eight shift/xor opera- */
/* tions for all combinations of data and CRC register values. */
/* */
/* The values must be right-shifted by eight bits by the "updcrc" */
/* logic; the shift must be unsigned (bring in zeroes). On some */
/* hardware you could probably optimize the shift in assembler by */
/* using byte-swap instructions. */
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
unsigned long TableCRC32CCITT[256] = /* CRC polynomial 0xedb88320 */
{
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
/* Used by Xmodem and Zmodem */
unsigned short TableCRC16Xmodem[256] =
{
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
};
/* Used by Hydra */
unsigned short TableCRC16CCITT[256] = /* CRC polynomial 0x8408 */
{
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
};
/*****************************************************************************
* Calculate CCITT CRC-32 of the data block. Used in Zmodem, Hydra protocols.
*
* Arguments:
* buffer pointer to the staring of data block
* buflen data block size
*
* Return value:
* CRC-32
*/
unsigned long getcrc32ccitt(const unsigned char *buffer, size_t buflen)
{
unsigned long crc = 0xffffffffL;
for( ; buflen-- > 0; buffer++ )
crc = TableCRC32CCITT[((int) crc ^ (*buffer)) & 0xff] ^ ((crc >> 8) & 0x00ffffff);
return crc;
}
/*****************************************************************************
* Calculate CRC-16 of the data block. Used in Xmodem, Zmodem protocols.
*
* Arguments:
* buffer pointer to the staring of data block
* buflen data block size
*
* Return value:
* CRC-16
*/
unsigned short getcrc16xmodem(const unsigned char *buffer, size_t buflen)
{
unsigned short crc = 0;
for( ; buflen-- > 0; buffer++ )
crc = TableCRC16Xmodem[(((crc >> 8) & 0xff) ^ (*buffer)) & 0xff] ^ (crc << 8);
return crc;
}
/*****************************************************************************
* Calculate CCITT CRC-16 of the data block. Used in Hydra protocol.
*
* Arguments:
* buffer pointer to the staring of data block
* buflen data block size
*
* Return value:
* CRC-16
*/
unsigned short getcrc16ccitt(const unsigned char *buffer, size_t buflen)
{
unsigned short crc = 0xffff;
for( ; buflen-- > 0; buffer++ )
crc = TableCRC16CCITT[(crc ^ (*buffer)) & 0xff] ^ ((crc >> 8) & 0x00ff);
return crc;
}
+312
View File
@@ -0,0 +1,312 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
struct fnctab {
const char *find;
const char *repl;
} fnctab[] = {
{ ".tar.gz", ".tgz" },
{ ".tar.bz2", ".tbz" },
{ ".html", ".htm" },
{ ".desc", ".dsc" },
{ NULL, NULL }
};
/*****************************************************************************
* Lock whole file for reading or writing
*
* Arguments:
* fp pointer to the opened file FILE structure
* exclusive lock file for exclusive or shared access
*
* Return value:
* zero value on success and -1 on errors
*/
int file_lock(FILE *fp, bool exclusive)
{
#ifdef USE_FLOCK
if( flock(fileno(fp), (exclusive ? LOCK_EX : LOCK_SH) | LOCK_NB) == -1 )
return -1;
#else
struct flock flck;
memset(&flck, '\0', sizeof(struct flock));
flck.l_whence = SEEK_SET;
flck.l_start = 0;
flck.l_len = 0;
flck.l_type = exclusive ? F_WRLCK : F_RDLCK;
if( fcntl(fileno(fp), F_SETLK, &flck) == -1 )
return -1;
#endif
return 0;
}
/*****************************************************************************
* Unlock file
*
* Arguments:
* fp pointer to the opened file FILE structure
*
* Return value:
* None
*/
void file_unlock(FILE *fp)
{
#ifdef USE_FLOCK
(void)flock(fileno(fp), LOCK_UN | LOCK_NB)
#else
struct flock flck;
memset(&flck, '\0', sizeof(struct flock));
flck.l_whence = SEEK_SET;
flck.l_start = 0;
flck.l_len = 0;
flck.l_type = F_UNLCK;
(void)fcntl(fileno(fp), F_SETLK, &flck);
#endif
}
/*****************************************************************************
* Lock whole file for reading or writing, do some number of tries before
* giving up
*
* Arguments:
* fp pointer to the opened file FILE structure
* exclusive lock file for exclusive or shared access
*
* Return value:
* zero value on success and -1 on errors
*/
int file_lock_wait(FILE *fp, bool exclusive)
{
int tries;
for( tries = 0; tries < 50; tries++ )
{
if( file_lock(fp, exclusive) == 0 )
return 0;
usleep(200);
}
return -1;
}
bool file_name_issafe(int ch)
{
if( ch == '!' ) return TRUE;
if( ch == '"' ) return TRUE;
if( ch == '#' ) return TRUE;
if( ch == '$' ) return TRUE;
if( ch == '&' ) return TRUE;
if( ch == '+' ) return TRUE;
if( ch == ',' ) return TRUE;
if( ch == '-' ) return TRUE;
if( ch == '.' ) return TRUE;
if( ch == '@' ) return TRUE;
if( ch == '_' ) return TRUE;
if( ch == '^' ) return TRUE;
if( ch == '~' ) return TRUE;
if( ch > 47 && ch < 58 ) return TRUE; /* '0'-'9' */
if( ch > 64 && ch < 91 ) return TRUE; /* 'A'-'Z' */
if( ch > 96 && ch < 123 ) return TRUE; /* 'a'-'z' */
if( ch > 127 && ch < 256 ) return TRUE; /* Hmm. :) */
return FALSE;
}
char *file_name_makesafe(char *filename)
{
char *p;
for( p = filename; *p; p++ )
if( !file_name_issafe((unsigned char)(*p)) ) *p = '_';
return filename;
}
char *file_getname(char *filename)
{
char *p = strrchr(filename, '/');
return p ? p + 1 : filename;
}
char *file_gettmp(void)
{
char *tmp = xstrcpy("/tmp/bforce-XXXXXX");
char *res = mktemp(tmp);
if( !res )
free(tmp);
return res;
}
char *file_get_dos_name(char *buffer, const char *filename)
{
char *copy = xstrcpy(filename);
char *p;
int i;
int extension_length = 0;
for( i = 0; fnctab[i].find; i++ )
{
if( (p = strstr(copy, fnctab[i].find)) )
{
*p = '\0';
strcat(copy, fnctab[i].repl);
strcat(copy, p + strlen(fnctab[i].find));
break;
}
}
/*
* Make sure, there is no '.' characters
* except extension separator point
*/
for( p = copy + strlen(copy) - 1; p >= copy; p-- )
{
if( (unsigned char)(*p) <= ' ' || *p == '*' || *p == '?' )
*p = '_';
else if( *p == '.' )
{
if( 4 >= strlen(p) && strlen(p) > 1 && !extension_length )
extension_length = strlen(p + 1);
else
*p = '_';
}
}
if( (extension_length > 0 && strlen(copy) <= 9 + extension_length)
|| (extension_length == 0 && strlen(copy) <= 8) )
strcpy(buffer, copy);
else
{
strncpy(buffer, copy, 5);
if( extension_length > 0 )
strncpy(buffer + 6, copy + strlen(copy) - 3 - extension_length, 6);
else
strncpy(buffer + 6, copy + strlen(copy) - 2, 2);
buffer[5] = '~';
buffer[12] = '\0';
}
free(copy); copy = NULL;
/*
* Make it lower case
*/
string_tolower(buffer);
if( !extension_length )
buffer[8] = '\0';
return buffer;
}
bool is_directory(const char *dirname)
{
struct stat st;
if( stat(dirname, &st) == -1 )
return FALSE;
return S_ISDIR(st.st_mode) ? TRUE : FALSE;
}
bool is_regfile(const char *filename)
{
struct stat st;
if( stat(filename, &st) == -1 )
return FALSE;
return S_ISREG(st.st_mode) ? TRUE : FALSE;
}
int directory_create(const char *dirname, mode_t access_mode)
{
char tmpname[BFORCE_MAX_PATH+1];
char *p = tmpname;
bool eol = FALSE;
strnxcpy(tmpname, dirname, sizeof(tmpname));
while( *p && !eol )
{
while( *p && *p != '/' ) ++p;
if( *p )
*p = '\0';
else
eol = TRUE;
if( !is_directory(tmpname) )
{
if( mkdir(tmpname, access_mode) == -1 && errno != EEXIST )
return -1;
(void)chmod(tmpname, access_mode);
}
if( !eol )
*p++ = '/';
}
return 0;
}
FILE *file_open(const char *path, const char *mode)
{
FILE *stream;
bool is_write;
ASSERT(path);
ASSERT(mode && (*mode == 'r' || *mode == 'w' || *mode == 'a'));
stream = fopen(path, mode);
if( !stream )
return NULL;
is_write = (*mode != 'r') ? TRUE : FALSE;
/* Try to lock it */
if( file_lock(stream, is_write) == 0 )
return stream;
/* If we can't physically lock file, just send it as is */
if ( errno == EOPNOTSUPP || errno == EINVAL )
return stream;
/* Do second try */
if( file_lock_wait(stream, is_write) == 0 )
return stream;
fclose(stream);
return NULL;
}
int file_close(FILE *stream)
{
ASSERT(stream);
file_unlock(stream);
return fclose(stream);
}
+525
View File
@@ -0,0 +1,525 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#define ADDRNUM_MIN 0x0000
#define ADDRNUM_MAX 0x7fff
static int addrstr2int(const char *s)
{
int val = atoi(s);
if( val < ADDRNUM_MIN )
val = ADDRNUM_MIN;
else if( val > ADDRNUM_MAX )
val = ADDRNUM_MAX;
return val;
}
char *addrint2str(char *buffer, int val)
{
if( val == -1 )
strcpy(buffer, "*");
else if( val < ADDRNUM_MIN )
strcpy(buffer, "MIN");
else if( val > ADDRNUM_MAX )
strcpy(buffer, "MAX");
else
sprintf(buffer, "%d", val);
return buffer;
}
static int ftn_addrparse_fido(s_faddr *addr, const char *s, bool wildcard)
{
bool badaddr = 0;
bool stop = 0;
bool gotzone = 0;
bool gotnet = 0;
bool gotnode = 0;
bool gotpoint = 0;
const char *p = s;
ASSERT(s != NULL);
while( !stop && !badaddr )
{
switch(*p) {
case ':':
if( !gotzone && isdigit(*s) )
{
gotzone = 1;
addr->zone = addrstr2int(s);
s = ++p;
}
else if( !gotzone && wildcard && *s == '*' )
{
gotzone = 1;
addr->zone = -1;
s = ++p;
}
else badaddr = 1;
break;
case '/':
if( !gotnet && isdigit(*s) )
{
gotnet = 1;
addr->net = addrstr2int(s);
s = ++p;
}
else if( !gotnet && wildcard && *s == '*' )
{
gotnet = 1;
addr->net = -1;
s = ++p;
}
else if( *s != '/' ) badaddr = 1;
else ++p;
break;
case '.':
if( *s == '/' ) ++s;
if( !gotnode && isdigit(*s) )
{
gotnode = 1;
addr->node = addrstr2int(s);
s = ++p;
}
else if( !gotnode && wildcard && *s == '*' )
{
gotnode = 1;
addr->node = -1;
s = ++p;
}
else if( *s != '.' ) badaddr = 1;
else ++p;
break;
case '@':
case '\0':
if( gotzone && !gotnet ) { badaddr = 1; break; }
if( *s == '/' )
{
++s;
if( !gotnode && isdigit(*s) )
{
gotnode = 1;
addr->node = addrstr2int(s);
}
else if( !gotnode && wildcard && *s == '*' )
{
gotnode = 1;
addr->node = -1;
}
else badaddr = 1;
}
else if( *s == '.' )
{
++s;
if( !gotpoint && isdigit(*s) )
{
gotpoint = 1;
addr->point = addrstr2int(s);
}
else if( !gotpoint && wildcard && *s == '*' )
{
gotpoint = 1;
addr->point = -1;
}
else badaddr = 1;
}
else if( isdigit(*s) )
{
if( !gotnode )
{
gotnode = 1;
addr->node = addrstr2int(s);
}
else if( !gotpoint )
{
gotpoint = 1;
addr->point = addrstr2int(s);
}
else badaddr = 1;
}
else if( wildcard && *s == '*' )
{
if( !gotnode )
{
gotnode = 1;
addr->node = -1;
}
else if( !gotpoint )
{
gotpoint = 1;
addr->point = -1;
}
else badaddr = 1;
}
else badaddr = 1;
stop = 1;
break;
default:
if( isdigit(*p) || (wildcard && *p == '*') )
{ ++p; }
else
{ badaddr = 1; }
}
}
if( !badaddr && *p++ == '@' && *p )
{
strnxcpy(addr->domain, string_printable(p), sizeof(addr->domain));
}
return badaddr;
}
static int ftn_addrparse_inet(s_faddr *addr, const char *s, bool wildcard)
{
bool badaddr = 0;
bool stop = 0;
bool gotzone = 0;
bool gotnet = 0;
bool gotnode = 0;
bool gotpoint = 0;
const char *p = s;
ASSERT(s != NULL);
while( !stop && !badaddr )
{
if( *p == '.' || *p == '\0' )
{
if( *p == '\0' ) stop = 1;
switch(*s++) {
case 'p':
case 'P':
if( !gotpoint && isdigit(*s) )
{
gotpoint = 1;
addr->point = addrstr2int(s);
s = ++p;
}
else badaddr = 1;
break;
case 'f':
case 'F':
if( !gotnet && !gotzone && !gotnode && isdigit(*s) )
{
gotnode = 1;
addr->node = addrstr2int(s);
s = ++p;
}
else badaddr = 1;
break;
case 'n':
case 'N':
if( gotnode && !gotzone && !gotnet && isdigit(*s) )
{
gotnet = 1;
addr->net = addrstr2int(s);
s = ++p;
}
else badaddr = 1;
break;
case 'z':
case 'Z':
if( gotnode && gotnet && !gotzone && isdigit(*s) )
{
gotzone = 1;
addr->zone = addrstr2int(s);
if( *p++ == '.' && *p )
{
strnxcpy(addr->domain, string_printable(p), sizeof(addr->domain));
}
stop = 1;
}
else badaddr = 1;
break;
default:
badaddr = 1;
break;
}
}
else
{
++p;
}
}
return badaddr;
}
/*****************************************************************************
* Parse FTN address (can be specified in traditional form (X:X/X.X) as
* well as in domain form (pX.fX.nX.zX.domain))
*
* Arguments:
* addr we will put parsed address here
* s pointer to the null-terminated string with address
* wildcard set FALSE if you want forbid wildcards processing
*
* Return value:
* zero value if addres was parsed successfuly, and non-zero if wasn't
*/
int ftn_addrparse(s_faddr *addr, const char *s, bool wildcard)
{
const char *p;
bool stop = 0;
bool badaddr = 0;
ASSERT(s != NULL);
memset(addr, '\0', sizeof(s_faddr));
/*
* Detect the address form (domain or traditional)
*/
for( p = s; *p && !stop && !badaddr; p++ )
{
switch( *p ) {
case '*':
if( wildcard == FALSE ) badaddr = 1;
case '@':
stop = 1;
case ':':
case '/':
case '.':
addr->inetform = 0;
break;
case 'p':
case 'P':
case 'f':
case 'F':
addr->inetform = 1;
stop = 1;
break;
default:
if( !isdigit(*p) ) badaddr = 1;
}
}
if( !badaddr )
{
addr->zone = DEFAULT_ZONE;
addr->net = DEFAULT_NET;
addr->node = DEFAULT_NODE;
addr->point = 0;
if( addr->inetform )
badaddr = ftn_addrparse_inet(addr, s, wildcard);
else
badaddr = ftn_addrparse_fido(addr, s, wildcard);
}
return badaddr;
}
char *ftn_addrstr_fido(char *buf, s_faddr addr)
{
char str1[10];
char str2[10];
char str3[10];
char str4[10];
if( addr.point )
{
sprintf(buf, "%s:%s/%s.%s",
addrint2str(str1, addr.zone), addrint2str(str2, addr.net),
addrint2str(str3, addr.node), addrint2str(str4, addr.point));
}
else
{
sprintf(buf, "%s:%s/%s",
addrint2str(str1, addr.zone), addrint2str(str2, addr.net),
addrint2str(str3, addr.node));
}
if( *addr.domain )
{
strnxcat(buf, "@", BF_MAXADDRSTR);
strnxcat(buf, addr.domain, BF_MAXADDRSTR);
}
return buf;
}
char *ftn_addrstr_inet(char *buf, s_faddr addr)
{
char str1[10];
char str2[10];
char str3[10];
char str4[10];
if( addr.point )
{
sprintf(buf, "p%s.f%s.n%s.z%s",
addrint2str(str1, addr.point), addrint2str(str2, addr.node),
addrint2str(str3, addr.net), addrint2str(str4, addr.zone));
}
else
{
sprintf(buf, "f%s.n%s.z%s",
addrint2str(str1, addr.node), addrint2str(str2, addr.net),
addrint2str(str3, addr.zone));
}
if( *addr.domain )
{
strnxcat(buf, ".", BF_MAXADDRSTR);
strnxcat(buf, addr.domain, BF_MAXADDRSTR);
}
return buf;
}
/*****************************************************************************
* Put FTN address as the null-terminated string to the buffer
*
* Arguments:
* buf pointer to the destination buffer (must be at least
* BF_MAXADDRSTR bytes length)
* addr FTN address
*
* Return value:
* pointer to the buffer start
*/
char *ftn_addrstr(char *buf, s_faddr addr)
{
ASSERT(buf != NULL);
return addr.inetform ? ftn_addrstr_inet(buf, addr)
: ftn_addrstr_fido(buf, addr);
}
/*****************************************************************************
* Compare two FTN addresses
*
* Arguments:
* addr1 first FTN address
* addr2 second FTN address
*
* Return value:
* zero value if addresses are equal, and non-zero if not
*/
int ftn_addrcomp(s_faddr addr1, s_faddr addr2)
{
return !( addr1.zone == addr2.zone && addr1.net == addr2.net
&& addr1.node == addr2.node && addr1.point == addr2.point );
}
/*****************************************************************************
* Compare two FTN addresses
*
* Arguments:
* addr1 first FTN address
* operator logical operator (EQ|GT|LT)
* addr2 second FTN address
*
* Return value:
* zero value if expression is true, and non-zero if not
*/
int ftn_addrcomp_logic(s_faddr addr1, int operator, s_faddr addr2)
{
int i;
int matr1[4] = { addr1.zone, addr1.net, addr1.node, addr1.point };
int matr2[4] = { addr2.zone, addr2.net, addr2.node, addr2.point };
for( i = 0; i < 4; i++ )
{
switch(operator) {
case ADDR_EQ:
if( matr1[i] != matr2[i] )
return 1;
break;
case ADDR_GT:
if( matr1[i] > matr2[i] )
return 0;
else if( matr1[i] < matr2[i] )
return 1;
break;
case ADDR_LT:
if( matr1[i] < matr2[i] )
return 0;
else if( matr1[i] > matr2[i] )
return 1;
break;
default:
ASSERT(0);
}
}
return 0;
}
/*****************************************************************************
* Compare two FTN addresses (second address can contain wildcards)
*
* Arguments:
* addr first FTN address
* mask second FTN address (with wildcards)
*
* Return value:
* zero value if addresses are equal, and non-zero if not
*/
int ftn_addrcomp_mask(s_faddr addr, s_faddr mask)
{
return !( (addr.zone == mask.zone || mask.zone == -1)
&& (addr.net == mask.net || mask.net == -1)
&& (addr.node == mask.node || mask.node == -1)
&& (addr.point == mask.point || mask.point == -1) );
}
/*****************************************************************************
* Get the metric of matching two addresses
*
* Arguments:
* addr1 first FTN address
* addr2 second FTN address
*
* Return value:
* from 0 to 4 (0 - no matching, 4 - equal addresses)
*/
int ftn_addrsmetric(s_faddr addr1, s_faddr addr2)
{
int metric = 0;
if( addr1.zone == addr2.zone )
{
++metric;
if( addr1.net == addr2.net )
{
++metric;
if( addr1.node == addr2.node )
{
++metric;
if( addr1.point == addr2.point )
{
++metric;
}
}
}
}
return metric;
}
+336
View File
@@ -0,0 +1,336 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
/* Data structure for MD5 (Message-Digest) computation */
typedef struct {
int chunks; /* Number of 64 byte chunks */
unsigned int buf[4];
} s_md5;
/* F, G, H and I are basic MD5 functions */
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
/* ROTATE_LEFT rotates x left n bits */
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
/* Rotation is separate from addition to prevent recomputation */
#define FF(a, b, c, d, x, s, ac) \
{(a) += F ((b), (c), (d)) + (x) + (unsigned int)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define GG(a, b, c, d, x, s, ac) \
{(a) += G ((b), (c), (d)) + (x) + (unsigned int)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) \
{(a) += H ((b), (c), (d)) + (x) + (unsigned int)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) \
{(a) += I ((b), (c), (d)) + (x) + (unsigned int)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#ifdef __STDC__
#define UL(x) x##U
#else
#define UL(x) x
#endif
/*****************************************************************************
* Initialise MD5 structure
*
* Arguments:
* md pointer to the MD5 structure
*
* Return value:
* None
*/
static void md5_init(s_md5 *md)
{
md->chunks = 0;
md->buf[0] = (unsigned int)0x67452301;
md->buf[1] = (unsigned int)0xefcdab89;
md->buf[2] = (unsigned int)0x98badcfe;
md->buf[3] = (unsigned int)0x10325476;
}
/*****************************************************************************
* Process next data chunk
*
* Arguments:
* md pointer to the MD5 structure
* buffer pointer to the data chunk (must be 64 bytes)
*
* Return value:
* None
*/
static void md5_update(s_md5 *md, const unsigned char *buffer)
{
int i;
unsigned int in[16];
unsigned int a = md->buf[0];
unsigned int b = md->buf[1];
unsigned int c = md->buf[2];
unsigned int d = md->buf[3];
++md->chunks;
/* Unpack buffer */
for( i = 0; i < 16; i++ )
{
in[i] = ((unsigned int)(buffer[0]) )
| ((unsigned int)(buffer[1]) << 8 )
| ((unsigned int)(buffer[2]) << 16)
| ((unsigned int)(buffer[3]) << 24);
buffer += 4;
}
/* Round 1 */
#define S11 7
#define S12 12
#define S13 17
#define S14 22
FF( a, b, c, d, in[ 0], S11, UL(3614090360)); /* 1 */
FF( d, a, b, c, in[ 1], S12, UL(3905402710)); /* 2 */
FF( c, d, a, b, in[ 2], S13, UL( 606105819)); /* 3 */
FF( b, c, d, a, in[ 3], S14, UL(3250441966)); /* 4 */
FF( a, b, c, d, in[ 4], S11, UL(4118548399)); /* 5 */
FF( d, a, b, c, in[ 5], S12, UL(1200080426)); /* 6 */
FF( c, d, a, b, in[ 6], S13, UL(2821735955)); /* 7 */
FF( b, c, d, a, in[ 7], S14, UL(4249261313)); /* 8 */
FF( a, b, c, d, in[ 8], S11, UL(1770035416)); /* 9 */
FF( d, a, b, c, in[ 9], S12, UL(2336552879)); /* 10 */
FF( c, d, a, b, in[10], S13, UL(4294925233)); /* 11 */
FF( b, c, d, a, in[11], S14, UL(2304563134)); /* 12 */
FF( a, b, c, d, in[12], S11, UL(1804603682)); /* 13 */
FF( d, a, b, c, in[13], S12, UL(4254626195)); /* 14 */
FF( c, d, a, b, in[14], S13, UL(2792965006)); /* 15 */
FF( b, c, d, a, in[15], S14, UL(1236535329)); /* 16 */
/* Round 2 */
#define S21 5
#define S22 9
#define S23 14
#define S24 20
GG( a, b, c, d, in[ 1], S21, UL(4129170786)); /* 17 */
GG( d, a, b, c, in[ 6], S22, UL(3225465664)); /* 18 */
GG( c, d, a, b, in[11], S23, UL( 643717713)); /* 19 */
GG( b, c, d, a, in[ 0], S24, UL(3921069994)); /* 20 */
GG( a, b, c, d, in[ 5], S21, UL(3593408605)); /* 21 */
GG( d, a, b, c, in[10], S22, UL( 38016083)); /* 22 */
GG( c, d, a, b, in[15], S23, UL(3634488961)); /* 23 */
GG( b, c, d, a, in[ 4], S24, UL(3889429448)); /* 24 */
GG( a, b, c, d, in[ 9], S21, UL( 568446438)); /* 25 */
GG( d, a, b, c, in[14], S22, UL(3275163606)); /* 26 */
GG( c, d, a, b, in[ 3], S23, UL(4107603335)); /* 27 */
GG( b, c, d, a, in[ 8], S24, UL(1163531501)); /* 28 */
GG( a, b, c, d, in[13], S21, UL(2850285829)); /* 29 */
GG( d, a, b, c, in[ 2], S22, UL(4243563512)); /* 30 */
GG( c, d, a, b, in[ 7], S23, UL(1735328473)); /* 31 */
GG( b, c, d, a, in[12], S24, UL(2368359562)); /* 32 */
/* Round 3 */
#define S31 4
#define S32 11
#define S33 16
#define S34 23
HH( a, b, c, d, in[ 5], S31, UL(4294588738)); /* 33 */
HH( d, a, b, c, in[ 8], S32, UL(2272392833)); /* 34 */
HH( c, d, a, b, in[11], S33, UL(1839030562)); /* 35 */
HH( b, c, d, a, in[14], S34, UL(4259657740)); /* 36 */
HH( a, b, c, d, in[ 1], S31, UL(2763975236)); /* 37 */
HH( d, a, b, c, in[ 4], S32, UL(1272893353)); /* 38 */
HH( c, d, a, b, in[ 7], S33, UL(4139469664)); /* 39 */
HH( b, c, d, a, in[10], S34, UL(3200236656)); /* 40 */
HH( a, b, c, d, in[13], S31, UL( 681279174)); /* 41 */
HH( d, a, b, c, in[ 0], S32, UL(3936430074)); /* 42 */
HH( c, d, a, b, in[ 3], S33, UL(3572445317)); /* 43 */
HH( b, c, d, a, in[ 6], S34, UL( 76029189)); /* 44 */
HH( a, b, c, d, in[ 9], S31, UL(3654602809)); /* 45 */
HH( d, a, b, c, in[12], S32, UL(3873151461)); /* 46 */
HH( c, d, a, b, in[15], S33, UL( 530742520)); /* 47 */
HH( b, c, d, a, in[ 2], S34, UL(3299628645)); /* 48 */
/* Round 4 */
#define S41 6
#define S42 10
#define S43 15
#define S44 21
II( a, b, c, d, in[ 0], S41, UL(4096336452)); /* 49 */
II( d, a, b, c, in[ 7], S42, UL(1126891415)); /* 50 */
II( c, d, a, b, in[14], S43, UL(2878612391)); /* 51 */
II( b, c, d, a, in[ 5], S44, UL(4237533241)); /* 52 */
II( a, b, c, d, in[12], S41, UL(1700485571)); /* 53 */
II( d, a, b, c, in[ 3], S42, UL(2399980690)); /* 54 */
II( c, d, a, b, in[10], S43, UL(4293915773)); /* 55 */
II( b, c, d, a, in[ 1], S44, UL(2240044497)); /* 56 */
II( a, b, c, d, in[ 8], S41, UL(1873313359)); /* 57 */
II( d, a, b, c, in[15], S42, UL(4264355552)); /* 58 */
II( c, d, a, b, in[ 6], S43, UL(2734768916)); /* 59 */
II( b, c, d, a, in[13], S44, UL(1309151649)); /* 60 */
II( a, b, c, d, in[ 4], S41, UL(4149444226)); /* 61 */
II( d, a, b, c, in[11], S42, UL(3174756917)); /* 62 */
II( c, d, a, b, in[ 2], S43, UL( 718787259)); /* 63 */
II( b, c, d, a, in[ 9], S44, UL(3951481745)); /* 64 */
md->buf[0] += a;
md->buf[1] += b;
md->buf[2] += c;
md->buf[3] += d;
}
/*****************************************************************************
* Compute MD5 digest (RFC-1321)
*
* Arguments:
* md pointer to the MD5 structure
* digest pointer to the resulting digest buffer (must be 16 bytes)
* data pointer to the source data
* length source data length
*
* Return value:
* None
*/
static void md5_compute(s_md5 *md, const unsigned char *data, size_t length,
unsigned char *digest)
{
unsigned char buffer[64];
int i;
while( length >= 64 )
{
md5_update(md, data);
data += 64;
length -= 64;
}
memcpy(buffer, data, length);
buffer[length] = 0x80;
memset(buffer + length + 1, '\0', 63 - length);
if( length > 55 )
{
md5_update(md, buffer);
memset(buffer, '\0', 64);
--md->chunks;
}
length += (md->chunks * 64);
length <<= 3;
buffer[56] = (unsigned char)((length ) & 0xff);
buffer[57] = (unsigned char)((length >> 8 ) & 0xff);
buffer[58] = (unsigned char)((length >> 16) & 0xff);
buffer[59] = (unsigned char)((length >> 24) & 0xff);
md5_update(md, buffer);
for( i = 0; i < 4; i++ )
{
unsigned int x = md->buf[i];
*digest++ = (unsigned char)((x ) & 0xff);
*digest++ = (unsigned char)((x >> 8 ) & 0xff);
*digest++ = (unsigned char)((x >> 16) & 0xff);
*digest++ = (unsigned char)((x >> 24) & 0xff);
}
}
void md5_get(const unsigned char *data, size_t length, unsigned char *digest)
{
s_md5 md;
md5_init(&md);
md5_compute(&md, data, length, digest);
}
/*****************************************************************************
* Compute CRAM-MD5 digest (RFC-2195). It is produced by calculating
*
* MD5((secret XOR opad), MD5((secret XOR ipad), challengedata))
*
* where MD5 is chosen hash function, ipad and opad are 36 hex and 5C hex
* and secret is null-padded to a length of 64 bytes. If the secret is
* longer than 64 bytes, the hash-function digest of the secret is used as
* an input
*
* Arguments:
* secret pointer to the null-terminated secret string (e.g. password)
* challenge pointer to the challenge data
* challenge_length length of the challenge data
* digest pointer to the resulting digest buffer (must be 16 bytes)
*
* Return value:
* None
*/
void md5_cram_get(const unsigned char *secret, const unsigned char *challenge,
int challenge_length, unsigned char *digest)
{
int i;
unsigned char secret_md5[16];
int secret_length = strlen(secret);
unsigned char osecret[64];
unsigned char isecret[64];
s_md5 md;
/*
* If the secret length is longer 64 bytes
* use MD5 digest of the secret as input
*/
if( secret_length > 64 )
{
md5_get(secret, secret_length, secret_md5);
secret = secret_md5;
secret_length = 16;
}
memcpy(osecret, secret, secret_length);
memcpy(isecret, secret, secret_length);
memset(osecret + secret_length, '\0', 64 - secret_length);
memset(isecret + secret_length, '\0', 64 - secret_length);
for( i = 0; i < 64; i++ )
{
osecret[i] ^= 0x5c;
isecret[i] ^= 0x36;
}
/*
* Compute HASH((secret XOR ipad), challenge)
*/
md5_init(&md);
md5_update(&md, isecret);
md5_compute(&md, challenge, challenge_length, secret_md5);
/*
* Compute HASH((secret XOR opad), secret_md5)
*/
md5_init(&md);
md5_update(&md, osecret);
md5_compute(&md, secret_md5, 16, digest);
}
+336
View File
@@ -0,0 +1,336 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
/*
* Array of mask aliases, you may add new values if you need
*/
struct magfname {
const char *alias;
const char *masks;
} magfname[] = {
{ "netmail", "*.pkt *.out *.cut *.hut *.dut *.iut" },
{ "arcmail", "*.su? *.mo? *.tu? *.we? *.th? *.fr? *.sa?" },
{ "ticfile", "*.tic" },
{ "archive", "*.tgz *.bz2 *.zip *.rar *.arj *.lha *.ha" },
{ NULL, NULL }
};
/*****************************************************************************
* Allocate memory, check for errors
*
* Arguments:
* size number of bytes to allocate
*
* Return value:
* Pointer to the allocated memory
*/
void *xmalloc(size_t size)
{
char *tmp;
if( size <= 0 )
{
log("requested to allocate %ld bytes", (long)size);
size = 1;
}
if( (tmp = (char *)malloc(size)) == NULL )
{
log("failed to allocate %ld bytes -> abort", (long)size);
abort();
}
return tmp;
}
/*****************************************************************************
* Change the size of allready allocated memory
*
* Arguments:
* buf pointer to the memory block which size we want change
* size new block size
*
* Return value:
* Pointer to the reallocated memory
*/
void *xrealloc(void *buf, size_t size)
{
char *tmp;
if( size <= 0 )
{
tmp = NULL;
log("requested to reallocate %ld bytes", (long)size);
if( buf ) free(buf);
}
else if( (tmp = (char*)(buf ? realloc(buf, size) : malloc(size))) == NULL )
{
log("failed to reallocate %ld bytes -> abort", size);
abort();
}
return tmp;
}
/*****************************************************************************
* Make copy of memory block
*
* Arguments:
* buffer pointer to the memory block which we want to duplicate
* size memory block size
*
* Return value:
* Pointer to the memory block copy (must be freed)
*/
void *xmemcpy(const void *buffer, size_t buflen)
{
void *ptr = xmalloc(buflen);
memcpy(ptr, buffer, buflen);
return ptr;
}
/*****************************************************************************
* Compare string for matching to the mask. Special characters for the mask:
* '?' - any one chracter (except '\0');
* '*' - any group of chracters (including '\0');
* '\' - next chracter will be compared directly (including '?' and '*')
*
* Arguments:
* str pointer to the null-terminated string
* mask pointer to the null-terminated mask
*
* Return value:
* zero value if string matchs pattern, and non-zero if not
*/
int strcasemask(const char *str, const char *mask)
{
const char *s, *m;
char c;
ASSERT(str != NULL && mask != NULL);
s = str;
m = mask;
while( *s )
{
switch( c = *m++ ) {
case '\0':
return 1;
case '\\':
if( *m )
{
if( toupper(*m++) != toupper(*s++) )
return 1;
}
else if( *s++ == '\\' && *s == '\0' )
return 0;
else
return 1;
break;
case '?':
++s;
break;
case '*':
if( *m )
{
do {
/* anti stack overflow */
while( *m == '*' ) m++;
if( *m != '\\' && *m != '?' )
while( *s && toupper(*s) != toupper(*m) ) ++s;
if( *s && !strcasemask(s, m) )
return 0;
} while( *s++ );
return 1;
}
return 0;
default:
if( toupper(c) != toupper(*s++) )
return 1;
}
}
return( *s != '\0' || *m != '\0' );
}
/*****************************************************************************
* Check whether masks list (e.g. "*.zip *.rar *.tic") conforms to the file
* name. For the masks description look string_pattern() info.
*
* Arguments:
* masks pointer to the null-terminated masks list
* str pointer to the null-terminated file name
*
* Return value:
* non-zero value if file name match masks, and zero if not
*/
int checkmasks(const char *masks, const char *str)
{
int i = 0, not = 0;
char *p = NULL;
char *n = NULL;
char *strs;
int yield = 1;
ASSERT(masks != NULL && str != NULL);
strs = xstrcpy(masks);
for( p = string_token(strs, &n, NULL, 1); p;
p = string_token(NULL, &n, NULL, 1) )
{
DEB((D_INFO, "checkmasks: checking \"%s\" in \"%s\"", str, p));
not = ( p[0] == '!' );
if( not )
++p;
if( p[0] == '%' )
{
for( i = 0; magfname[i].alias; i++ )
if( strcasecmp(p+1, magfname[i].alias) == 0 )
{
if( !checkmasks(magfname[i].masks, str) )
{
free(strs);
return not;
}
else if( not )
yield = 0;
break;
}
}
else if( !strcasemask(str, p) )
{
free(strs);
return not;
}
else if( not )
yield = 0;
}
free(strs);
return yield;
}
/*****************************************************************************
* Put long integer (4 bytes) to the buffer
*
* Arguments:
* buffer pointer to the destination buffer
* val value that we want put to the buffer
*
* Return value:
* Pointer to the specified buffer
*/
char *buffer_putlong(char *buffer, long val)
{
buffer[0] = ( ((unsigned long) val) ) & 0xff;
buffer[1] = ( ((unsigned long) val) >> 8 ) & 0xff;
buffer[2] = ( ((unsigned long) val) >> 16 ) & 0xff;
buffer[3] = ( ((unsigned long) val) >> 24 ) & 0xff;
return buffer;
}
/*****************************************************************************
* Put integer (2 bytes) to the buffer
*
* Arguments:
* buffer pointer to the destination buffer
* val value that we want put to the buffer
*
* Return value:
* Pointer to the specified buffer
*/
char *buffer_putint(char *buffer, int val)
{
buffer[0] = ( ((unsigned int) val) ) & 0xff;
buffer[1] = ( ((unsigned int) val) >> 8 ) & 0xff;
return buffer;
}
/*****************************************************************************
* Get long integer (4 bytes) from the buffer
*
* Arguments:
* buffer pointer to the buffer
*
* Return value:
* Extracted value
*/
long buffer_getlong(const char *buffer)
{
return ( (unsigned long) ((unsigned char) buffer[0]) )
| ( (unsigned long) ((unsigned char) buffer[1]) << 8 )
| ( (unsigned long) ((unsigned char) buffer[2]) << 16 )
| ( (unsigned long) ((unsigned char) buffer[3]) << 24 );
}
/*****************************************************************************
* Get integer (2 bytes) from the buffer
*
* Arguments:
* buffer pointer to the buffer
*
* Return value:
* Extracted value
*/
int buffer_getint(const char *buffer)
{
return ( (unsigned int) ((unsigned char) buffer[0]) )
| ( (unsigned int) ((unsigned char) buffer[1]) << 8 );
}
void printf_usage(const char *ident, const char *fmt, ...)
{
va_list args;
if( ident )
printf("%s %s %s\n\n", BF_BANNERVER, ident, BF_COPYRIGHT);
else
printf("%s %s\n\n", BF_BANNERVER, BF_COPYRIGHT);
if( fmt )
{
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
}
else
printf("Sorry, no usage information available\n\n");
printf("Mail bug reports to <adb@newmail.ru>\n");
fflush(stdout);
}
/* end of u_misc.c */
+220
View File
@@ -0,0 +1,220 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
/*
* Packet header offsets
*/
#define PKTHDR_ORIGNODE 0
#define PKTHDR_DESTNODE 2
#define PKTHDR_YEAR 4
#define PKTHDR_MONTH 6
#define PKTHDR_DAY 8
#define PKTHDR_HOUR 10
#define PKTHDR_MINUTE 12
#define PKTHDR_SECOND 14
#define PKTHDR_BAUD 16
#define PKTHDR_PKTTYPE 18
#define PKTHDR_ORIGNET 20
#define PKTHDR_DESTNET 22
#define PKTHDR_PRODCODELOW 24
#define PKTHDR_REVMAJOR 25
#define PKTHDR_PASSWORD 26
#define PKTHDR_QORIGZONE 34
#define PKTHDR_QDESTZONE 36
#define PKTHDR_AUXNET 38
#define PKTHDR_CWVALIDCOPY 40
#define PKTHDR_PRODCODEHIGH 42
#define PKTHDR_REVMINOR 43
#define PKTHDR_CAPABILWORD 44
#define PKTHDR_ORIGZONE 46
#define PKTHDR_DESTZONE 48
#define PKTHDR_ORIGPOINT 50
#define PKTHDR_DESTPOINT 52
#define PKTHDR_PRODDATA 54
#define PKTHDR_SIZE 58
/*
* Packed message header offsets
*/
#define PKTMSGHDR_PKTTYPE 0
#define PKTMSGHDR_ORIGNODE 2
#define PKTMSGHDR_DESTNODE 4
#define PKTMSGHDR_ORIGNET 6
#define PKTMSGHDR_DESTNET 8
#define PKTMSGHDR_ATTR 10
#define PKTMSGHDR_COST 12
#define PKTMSGHDR_DATE 14 /* 20 bytes */
#define PKTMSGHDR_TOUSER 24 /* 36 bytes */
#define PKTMSGHDR_FROMUSER 60 /* 36 bytes */
#define PKTMSGHDR_SUBJECT 96 /* 72 bytes */
#define PKTMSGHDR_SIZE 168
/*
* Message attributes
*/
#define MSGATTR_PVT 0x0001
#define MSGATTR_CRASH 0x0002
#define MSGATTR_RECD 0x0004
#define MSGATTR_SENT 0x0008
#define MSGATTR_FILEATTACH 0x0010
#define MSGATTR_INTRANSIT 0x0020
#define MSGATTR_ORPHAN 0x0040
#define MSGATTR_KILLSENT 0x0080
#define MSGATTR_LOCAL 0x0100
#define MSGATTR_HOLD 0x0200
#define MSGATTR_RESERVED 0x0400
#define MSGATTR_FILEREQ 0x0800
#define MSGATTR_RREQ 0x1000
#define MSGATTR_IRRR 0x2000
#define MSGATTR_AUDIT 0x4000
#define MSGATTR_UPDATEREQ 0x8000
#define MSGATTR_NOTZEROED ( MSGATTR_PVT | MSGATTR_CRASH \
| MSGATTR_FILEATTACH | MSGATTR_RESERVED \
| MSGATTR_RREQ | MSGATTR_IRRR | MSGATTR_AUDIT )
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
static char *pkt_putword(char *buf, int val)
{
buf[0] = ( ((unsigned int) val) ) & 0xff;
buf[1] = ( ((unsigned int) val) >> 8 ) & 0xff;
return buf;
}
static char *pkt_putbyte(char *buf, int val)
{
buf[0] = ( ((unsigned int) val) ) & 0xff;
return buf;
}
static int pkt_getword(const char *buf)
{
return ( (unsigned int) ((unsigned char) buf[0]) )
| ( (unsigned int) ((unsigned char) buf[1]) << 8 );
}
static char *pkt_putpktheader(char *pkthdr_buffer, const s_packet *pkt)
{
time_t now = localtogmt(time(NULL));
struct tm *ptm = localtime(&now);
memset(pkthdr_buffer, '\0', PKTHDR_SIZE);
pkt_putword(pkthdr_buffer + PKTHDR_ORIGNODE, pkt->orig.node);
pkt_putword(pkthdr_buffer + PKTHDR_DESTNODE, pkt->dest.node);
pkt_putword(pkthdr_buffer + PKTHDR_YEAR, ptm->tm_year);
pkt_putword(pkthdr_buffer + PKTHDR_MONTH, ptm->tm_mon);
pkt_putword(pkthdr_buffer + PKTHDR_DAY, ptm->tm_mday);
pkt_putword(pkthdr_buffer + PKTHDR_HOUR, ptm->tm_hour);
pkt_putword(pkthdr_buffer + PKTHDR_MINUTE, ptm->tm_min);
pkt_putword(pkthdr_buffer + PKTHDR_SECOND, ptm->tm_sec);
pkt_putword(pkthdr_buffer + PKTHDR_BAUD, pkt->baud);
pkt_putword(pkthdr_buffer + PKTHDR_PKTTYPE, 0x0002);
pkt_putword(pkthdr_buffer + PKTHDR_ORIGNET, pkt->orig.net);
pkt_putword(pkthdr_buffer + PKTHDR_DESTNET, pkt->dest.net);
pkt_putbyte(pkthdr_buffer + PKTHDR_PRODCODELOW, 0xfe);
pkt_putword(pkthdr_buffer + PKTHDR_REVMAJOR, 0);
memcpy(pkthdr_buffer + PKTHDR_PASSWORD, pkt->password, MIN(8, strlen(pkt->password)));
pkt_putword(pkthdr_buffer + PKTHDR_QORIGZONE, pkt->orig.zone);
pkt_putword(pkthdr_buffer + PKTHDR_QDESTZONE, pkt->dest.zone);
/* .. skipped .. */
pkt_putword(pkthdr_buffer + PKTHDR_ORIGZONE, pkt->orig.zone);
pkt_putword(pkthdr_buffer + PKTHDR_DESTZONE, pkt->dest.zone);
pkt_putword(pkthdr_buffer + PKTHDR_ORIGPOINT, pkt->orig.point);
pkt_putword(pkthdr_buffer + PKTHDR_DESTPOINT, pkt->dest.point);
return pkthdr_buffer;
}
static char *pkt_putmsgheader(char *msghdr_buffer, const s_message *msg)
{
char buf[30];
memset(msghdr_buffer, '\0', PKTMSGHDR_SIZE);
pkt_putword(msghdr_buffer + PKTMSGHDR_PKTTYPE, 0x0002);
pkt_putword(msghdr_buffer + PKTMSGHDR_ORIGNODE, msg->orig.node);
pkt_putword(msghdr_buffer + PKTMSGHDR_DESTNODE, msg->dest.node);
pkt_putword(msghdr_buffer + PKTMSGHDR_ORIGNET, msg->orig.net);
pkt_putword(msghdr_buffer + PKTMSGHDR_DESTNET, msg->dest.net);
pkt_putword(msghdr_buffer + PKTMSGHDR_ATTR, msg->attr & MSGATTR_NOTZEROED);
pkt_putword(msghdr_buffer + PKTMSGHDR_COST, msg->cost);
strnxcpy(msghdr_buffer + PKTMSGHDR_DATE, time_string_msghdr(buf, msg->time), 20);
strnxcpy(msghdr_buffer + PKTMSGHDR_TOUSER, msg->nameto, 36);
strnxcpy(msghdr_buffer + PKTMSGHDR_FROMUSER, msg->namefrom, 36);
strnxcpy(msghdr_buffer + PKTMSGHDR_SUBJECT, msg->subject, 72);
return msghdr_buffer;
}
static int pkt_writepacket(FILE *fp, const s_packet *pkt)
{
int i;
char pkthdr[PKTHDR_SIZE];
char msghdr[PKTMSGHDR_SIZE];
pkt_putpktheader(pkthdr, pkt);
if( fwrite(pkthdr, sizeof(pkthdr), 1, fp) != 1 )
return 1;
for( i = 0; i < pkt->n_msgs; i++ )
{
pkt_putmsgheader(msghdr, &pkt->msgs[i]);
if( fwrite(msghdr, sizeof(msghdr), 1, fp) != 1 )
return 1;
if( pkt->msgs[i].text )
fprintf(fp, "%s\r", pkt->msgs[i].text);
if( pkt->msgs[i].tagline )
fprintf(fp, "... %s\r", pkt->msgs[i].tagline);
fprintf(fp, "--- %s\r",
pkt->msgs[i].tearline ? pkt->msgs[i].tearline : BF_BANNERVER);
if( pkt->msgs[i].origin )
fprintf(fp, "* Origin: %s\r", pkt->msgs[i].origin);
fputc('\0', fp); /* end of message */
}
fputc('\0', fp); /* end of packet */
fputc('\0', fp); /* end of packet */
return 0;
}
int pkt_createpacket(const char *pktname, const s_packet *pkt)
{
int rc;
FILE *fp;
if( (fp = file_open(pktname, "w")) == NULL )
return -1;
rc = pkt_writepacket(fp, pkt);
if( file_close(fp) )
return -1;
return rc;
}
+203
View File
@@ -0,0 +1,203 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "outbound.h"
pid_t plock_read(const char *lockname)
{
FILE *fp = NULL;
pid_t pid = 0;
ASSERT(lockname != NULL);
if( (fp = file_open(lockname, "rt")) )
{
if( fscanf(fp, "%d", &pid) != 1 )
pid = 0;
file_close(fp);
}
DEB((D_OUTBOUND, "plock_read: file \"%s\", PID = %d", lockname, pid));
return pid;
}
pid_t plock_write(const char *lockname)
{
int fd, rc = PLOCK_OK;
char buf[32];
ASSERT(lockname != NULL);
if( (fd = open(lockname, O_CREAT | O_RDWR, 0644)) < 0 )
/* Don't log any errors, really we can have
* no outbound directory for this address */
return PLOCK_ERROR;
chmod(lockname, 0644);
sprintf(buf, "%10d\n", (int)getpid());
if( write(fd, (char *)buf, strlen(buf)) != strlen(buf) )
{
logerr("can't write PID to the lock file \"%s\"", lockname);
rc = PLOCK_ERROR;
}
close(fd);
if( rc != PLOCK_OK )
unlink(lockname);
return rc;
}
/*
* Return codes:
* PLOCK_OK
* PLOCK_EXIST
* PLOCK_ERROR
* PLOCK_OURBSY
*/
int plock_check(const char *lockname)
{
pid_t pid = 0;
struct stat st;
ASSERT(lockname != NULL);
if( stat(lockname, &st) && errno == ENOENT )
return PLOCK_OK;
if( (pid = plock_read(lockname)) == 0 )
return (errno == ENOENT) ? PLOCK_OK : PLOCK_ERROR;
if( pid == getpid() )
return PLOCK_OURLOCK; /* Should we unlink it? */
if( kill(pid, 0) == -1 && errno == ESRCH )
{
/*
* That process no longer exists,
* try to remove lock file
*/
log("remove stale lock file \"%s\", PID %d",
lockname, (int)pid);
if( !unlink(lockname) )
return PLOCK_OK;
else
{
logerr("cannot remove lock file");
return PLOCK_ERROR;
}
}
return PLOCK_EXIST; /* locking process still lives */
}
int plock_link(const char *lockname, const char *tmpname)
{
int rc;
ASSERT(lockname != NULL && tmpname != NULL);
if( !link(tmpname, lockname) )
{
unlink(tmpname);
return PLOCK_OK;
}
/* Can't create link */
if( errno == EEXIST )
{
if( (rc = plock_check(lockname)) != PLOCK_OK )
{
if( rc == PLOCK_OURLOCK )
rc = PLOCK_OK;
}
else if( link(tmpname, lockname) )
{
logerr("cannot link lock \"%s\" to \"%s\"", tmpname, lockname);
rc = PLOCK_ERROR;
} else
rc = PLOCK_OK;
}
else
{
logerr("cannot link lock \"%s\" to \"%s\"", tmpname, lockname);
rc = PLOCK_ERROR;
}
if( unlink(tmpname) == -1 && errno != ENOENT )
logerr("cannot remove lock file \"%s\"", tmpname);
return rc;
}
int plock_create(const char *lockname)
{
int rc;
char *tmpname, *p;
ASSERT(lockname != NULL);
tmpname = xstrcpy(lockname);
if( (p = strrchr(tmpname, DIRSEPCHR)) && p != tmpname )
*++p = '\0';
else
{
free(tmpname);
return PLOCK_ERROR;
}
tmpname = xstrcat(tmpname, "bforce-XXXXXX");
if( (p = mktemp(tmpname)) == NULL )
{
logerr("can't generate unique file name from \"%s\"", tmpname);
free(tmpname);
return PLOCK_ERROR;
}
if( (rc = plock_write(p)) == PLOCK_OK )
rc = plock_link(lockname, p);
DEB((D_OUTBOUND, "out_bsy_createfile: createlink(\"%s\", \"%s\"), rc = %d",
lockname, p, rc));
free(tmpname);
return rc;
}
int plock_remove(const char *lockname)
{
pid_t pid = 0;
ASSERT(lockname != NULL);
DEB((D_OUTBOUND, "out_bsy_unlinkfile: want unlink \"%s\"", lockname));
if( (pid = plock_read(lockname)) == 0 )
return 1;
if( pid == getpid() && unlink(lockname) == -1 )
return 1;
return 0;
}
+141
View File
@@ -0,0 +1,141 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
char default_table[RECODE_MAX_CHAR+1] =
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
"\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f"
"\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f"
"\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f"
"\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f"
"\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f"
"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
"\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf"
"\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
"\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf"
"\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff";
s_recode_table recode_table_in;
s_recode_table recode_table_out;
bool initialised = FALSE;
static void recode_init(void)
{
memset(&recode_table_in, '\0', sizeof(s_recode_table));
memset(&recode_table_out, '\0', sizeof(s_recode_table));
memcpy(recode_table_in.table, default_table, sizeof(default_table));
memcpy(recode_table_out.table, default_table, sizeof(default_table));
}
static int recode_load_table(char *dest, const char *filename)
{
FILE *fp;
char buf[80];
int find = 0;
int repl = 0;
int line = 0;
/* Restore default recode table */
memcpy(dest, default_table, sizeof(default_table));
fp = file_open(filename, "r");
if( !fp )
{
logerr("cannot open recode table \"%s\"", filename);
return -1;
}
while( fgets(buf, sizeof(buf), fp) )
{
++line;
string_chomp(buf);
string_trimboth(buf);
if( *buf == '#' )
continue;
if( sscanf(buf, "%i %i", &find, &repl) == 2 )
{
if( 0 > find || find > RECODE_MAX_CHAR )
log("recode character out of range 0..%d in \"%s\" line %d",
RECODE_MAX_CHAR, filename, line);
else
dest[find] = (unsigned char)repl;
}
}
file_close(fp);
return 0;
}
static int recode_update_table(s_recode_table *tab, const char *filename)
{
bool newtab = FALSE;
/*
* Check/update current recode table
*/
if( filename && *filename )
{
if( !tab->filename || strcmp(filename, tab->filename) )
newtab = TRUE;
}
else if( tab->filename && *tab->filename )
newtab = TRUE;
if( newtab )
{
if( filename && *filename )
{
tab->filename = filename;
recode_load_table(tab->table, filename);
}
else
{
tab->filename = NULL;
memcpy(tab->table, default_table, sizeof(default_table));
}
}
return 0;
}
char *recode(char *str, s_recode_table *tab, const char *filename)
{
char *p;
if( !initialised )
{
recode_init();
initialised = TRUE;
}
recode_update_table(tab, filename);
for( p = str; *p; p++ )
*p = tab->table[(unsigned char)*p];
return str;
}
+932
View File
@@ -0,0 +1,932 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef TEST
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#else
#include <stdio.h>
#include <stdarg.h>
#define TRUE 1
#define FALSE 0
#define bool int
#define xmalloc malloc
#define xrealloc realloc
#define ASSERT
#endif
/*
* Maximum number of quoted-printable strings we will store together
*/
#define PRINTABLE_MAXITEMS 5
/*
* Cyclic buffer for quoted-printable strings
*/
static char *printable_storage[PRINTABLE_MAXITEMS];
/*
* Position of next entry to use in printable_storage[]
*/
static int printable_pos = -1;
/*****************************************************************************
* Allocate memory for the copy of a string pointed by src
*
* Arguments:
* src pointer to the null-terminated string
*
* Return value:
* Pointer to the resulting string (must be freed)
*/
char *xstrcpy(const char *src)
{
char *tmp;
if( !src )
return NULL;
tmp = xmalloc(strlen(src)+1);
strcpy(tmp, src);
return tmp;
}
/*****************************************************************************
* Append string pointed by add to the string src, allocate memory for result
*
* Arguments:
* src pointer to the null-terminated string (will be freed)
* add this one will be appended to the src
*
* Return value:
* Pointer to the resulting string (must be freed)
*/
char *xstrcat(char *src, const char *add)
{
char *tmp;
size_t size;
if( !add || *add == '\0' )
return src;
size = (src ? strlen(src) : 0) + strlen(add);
tmp = (char*)xmalloc(size+1);
if( src )
{
strcpy(tmp, src);
free(src);
} else
*tmp = '\0';
strcat(tmp, add);
return tmp;
}
/*****************************************************************************
* Copy a string to the buffer. Checks for the destination buffer overflow and
* terminating '\0' character.
*
* Arguments:
* dst pointer to the destination buffer
* src string to copy from
* len destination buffer size
*
* Return value:
* Pointer to the resulting string
*/
char *strnxcpy(char *dst, const char *src, size_t len)
{
ASSERT(src != NULL && dst != NULL && len >= 0);
dst[len - 1] = 0;
return strncpy(dst, src, len - 1);
}
/*****************************************************************************
* Add one string to the end of another. Checks for destination buffer
* overflow and terminating '\0' character.
*
* Arguments:
* dst pointer to the destination buffer (append to the string
* stored in it)
* src append this string
* len destination buffer size
*
* Return value:
* Pointer to the resulting string
*/
char *strnxcat(char *dst, const char *src, size_t len)
{
int pos;
ASSERT(src != NULL && dst != NULL && len >= 0);
pos = strlen(dst);
return strnxcpy(dst + pos, src, len - pos);
}
/*****************************************************************************
* Get next substring from the string.
*
* Arguments:
* str pointer to a null-terminated string
* next points to the pointer where you want store address of
* the next substring for next calls
* delim delimiter characters, if NULL than the isspace() call used
* to check for the delimiter characters
* quoted ignore spaces in the quoted substrings
*
* Return value:
* Pointer to the new substring or NULL if no more available
*/
char *string_token(char *str, char **next, const char *delim, int quoted)
{
char *yield;
char *p;
ASSERT(next != NULL);
yield = str ? str : *next;
if( yield )
{
if( delim && *delim )
while( *yield && strchr(delim, *yield) ) yield++;
else
while( isspace(*yield) ) yield++;
if( *yield )
{
if( quoted && *yield == '"' )
{
p = ++yield;
while( *p && *p != '"' ) p++;
}
else
{
p = yield;
if( delim && *delim )
while( *p && !strchr(delim, *p) ) p++;
else
while( *p && !isspace(*p) ) p++;
}
if( *p )
{
*p = '\0';
*next = p+1;
} else
*next = NULL;
} else
yield = *next = NULL;
}
return yield;
}
/*****************************************************************************
* Remove trailing CR and LF characters
*
* Arguments:
* str pointer to the null-terminated string
*
* Return value:
* Pointer to the string
*/
char *string_chomp(char *str)
{
char *p;
ASSERT(str != NULL);
if( str && *str )
{
p = str + strlen(str + 1);
if( *p == '\n' )
*p-- = '\0';
if( *p == '\r' && p >= str )
*p = '\0';
}
return str;
}
/*****************************************************************************
* Find the firtst occurance of substring into the string
*
* Arguments:
* substr pointer to the null-terminated substring
* string pointer to the null-terminated string
*
* Return value:
* Pointer to the first occurrence of the substring in the string,
* and NULL if substring is not found
*/
const char *string_casestr(const char *string, const char *substr)
{
size_t subln = strlen(substr);
size_t strln = strlen(string);
while( *string && strln >= subln )
{
if( !strncasecmp(substr, string, subln) )
return string;
++string;
--strln;
}
return NULL;
}
/*****************************************************************************
* Find character in the string (It is like strchr(), but case insensitive)
*
* Arguments:
* str pointer to the null-terminated string
* ch character you want to find
*
* Return value:
* Pointer to the first occurrence of the character in the string,
* and NULL if character is not found
*/
const char *string_casechr(const char *str, int ch)
{
ch = tolower(ch);
while( *str )
{
if( tolower(*str) == ch )
return str;
++str;
}
return NULL;
}
/*****************************************************************************
* Convert string to the upper case
*
* Arguments:
* str pointer to the null-terminated string
*
* Return value:
* Pointer to the string
*/
char *string_toupper(char *str)
{
char *p;
ASSERT(str != NULL);
for( p = str; *p; p++ ) *p = toupper(*p);
return(str);
}
/*****************************************************************************
* Convert string to the lower case
*
* Arguments:
* str pointer to the null-terminated string
*
* Return value:
* Pointer to the string
*/
char *string_tolower(char *str)
{
char *p;
ASSERT(str != NULL);
for( p = str; *p; p++ ) *p = tolower(*p);
return(str);
}
/*****************************************************************************
* Check wheather string doesn't contain lower case characters
*
* Arguments:
* str pointer to the null-terminated string
*
* Return value:
* Return TRUE if string conforms our requirements, and FALSE if not
*/
bool string_isupper(const char *str)
{
const char *p;
ASSERT(str != NULL);
for( p = str; *p; p++ )
{
if( isalpha(*p) && islower(*p) ) break;
}
return (*p == '\0') ? TRUE : FALSE;
}
/*****************************************************************************
* Check wheather string doesn't contain upper case characters
*
* Arguments:
* str pointer to the null-terminated string
*
* Return value:
* Return TRUE if string conforms our requirements, and FALSE if not
*/
bool string_islower(const char *str)
{
const char *p;
ASSERT(str != NULL);
for( p = str; *p; p++ )
{
if( isalpha(*p) && isupper(*p) ) break;
}
return (*p == '\0') ? TRUE : FALSE;
}
/*****************************************************************************
* Remove spaces at the end of string
*
* Arguments:
* str pointer to the null-terminated string
*
* Return value:
* Pointer to the string
*/
char *string_trimright(char *str)
{
char *p;
ASSERT(str != NULL);
if( str && *str )
{
p = str + strlen(str+1);
while( p >= str && isspace(*p) ) *p-- = '\0';
}
return str;
}
/*****************************************************************************
* Remove spaces at the begining of string
*
* Arguments:
* str pointer to the null-terminated string
*
* Return value:
* pointer to the string
*/
char *string_trimleft(char *str)
{
char *p;
ASSERT(str != NULL);
if( str && *str )
{
p = str;
while( isspace(*p) ) p++;
if( p > str )
memmove(str, p, strlen(p)+1);
}
return str;
}
/*****************************************************************************
* Remove white spaces at the begining and at the end of string
*
* Arguments:
* str pointer to the null-terminated string
*
* Return value:
* pointer to the string
*/
char *string_trimboth(char *str)
{
char *p;
ASSERT(str != NULL);
if( str && *str )
{
/* Remove leading spaces */
p = str;
while( isspace(*p) ) p++;
if( p > str )
memmove(str, p, strlen(p)+1);
/* Remove trailing spaces */
p = str + strlen(str+1);
while( p >= str && isspace(*p) ) *p-- = '\0';
}
return str;
}
/*****************************************************************************
* Quote all unprintable characters in the buffer (e.g. "\xff\xfe")
*
* Arguments:
* buffer pointer to the buffer to process
* buflen buffer size
*
* Return value:
* Pointer to the quoted-printable string (must be freed)
*/
char *string_printable_buffer(const char *buffer, size_t buflen)
{
char *dest, *p;
const char *bp;
int nonprintcount = 0;
size_t pos = 0;
for( bp = buffer, pos = 0; pos < buflen; bp++, pos++ )
{
if( !isprint((unsigned char)*bp) )
nonprintcount++;
}
dest = xmalloc(buflen + nonprintcount * 4 + 1);
if( nonprintcount == 0 )
{
memcpy(dest, buffer, buflen);
dest[buflen] = '\0';
}
else
{
p = dest;
for( pos = 0; pos < buflen; buffer++, pos++ )
{
if( !isprint((unsigned char)*buffer) )
{
sprintf(p, "\\x%02x", (unsigned char)*buffer);
p += 4;
} else
*p++ = *buffer;
}
*p = '\0';
}
return dest;
}
/*****************************************************************************
* Quote all unprintable characters in the string (e.g. "\xff\xfe")
*
* Arguments:
* str pointer to the null-terminated string
*
* Return value:
* Pointer to the quoted-printable string. Memory allocated for the
* resulting string will be freed automatically. So don't use more
* than last PRINTABLE_MAXITEMS pointers returned by this function.
*/
const char *string_printable(const char *str)
{
char *p;
const char *q;
int nonprintcount = 0;
size_t pos = 0;
size_t len = 0;
if( printable_pos == -1 )
{
memset(printable_storage, '\0', sizeof(printable_storage));
printable_pos = 0;
}
if( str == NULL ) return "(null)";
len = strlen(str);
for( q = str, pos = 0; pos < len; q++, pos++ )
{
if( iscntrl((unsigned char)*q) || !isprint((unsigned char)*q) )
nonprintcount++;
}
if( !nonprintcount )
return str;
if( printable_pos >= PRINTABLE_MAXITEMS )
printable_pos = 0;
if( printable_storage[printable_pos] )
free(printable_storage[printable_pos]);
p = printable_storage[printable_pos] = xmalloc(len + nonprintcount * 4 + 1);
for( pos = 0; pos < len; str++, pos++ )
{
if( iscntrl((unsigned char)*str) || !isprint((unsigned char)*str) )
{
sprintf(p, "\\x%02x", (unsigned char)*str);
p += 4;
} else
*p++ = *str;
}
*p = '\0';
return printable_storage[printable_pos++];
}
/*****************************************************************************
* Replace all chracters 'oldchar' by the 'newchar'
*
* Arguments:
* str pointer to the null-terminated string
* oldchar old chracter
* newchar character to put istead of 'oldchar'
*
* Return value:
* Pointer to the string
*/
char *string_replchar(char *str, char oldchar, char newchar)
{
char *p = str;
while( *p )
{
if( *p == oldchar ) *p = newchar;
++p;
}
return str;
}
/*****************************************************************************
* Devide string on substrings and put pointers to them into the
* dest[] array.
*
* Arguments:
* dest destination array where we should put substrings
* items number of entries in dest[]
* str string to parse (will be destroyed)
* separator separator character
*
* Return value:
* Number of substrings in the dest[]
*/
int string_parse(char **dest, int items, char *str, int separator)
{
int count = 0;
char *p = str;
dest[count++] = str;
while( *p && count < items )
{
if( *((unsigned char *)p) == separator )
{
*p++ = '\0';
dest[count++] = p;
} else
++p;
}
return count;
}
/*****************************************************************************
* Devide string on substrings separated by white-space characters and put
* pointers to them into the dest[] array. Also it will ignore spaces in
* quoted strings (quote characters will be removed)
*
* Arguments:
* dest destination array where we should put substrings
* items number of entries in dest[]
* str string to parse (will be destroyed)
*
* Return value:
* Number of substrings in the dest[]
*/
int string_parse_regular(char **dest, int items, char *str)
{
int count = 0;
char *p = str;
while( *p )
{
while( *p && isspace(*p) )
++p;
if( *((unsigned char *)p) == '"' && *++p )
{
dest[count++] = p;
while( *p && *((unsigned char *)p) != '"' ) p++;
}
else if( *p )
{
dest[count++] = p;
while( *p && !isspace(*p) ) p++;
}
if( *p && count < items )
*p++ = '\0';
else
break;
}
return count;
}
/*****************************************************************************
* Replace all substrings 'find' by the 'repl' in the string 'str'
*
* Arguments:
* str null-terminated string to process (will be unchanged)
* find substring to find
* repl replace substring
*
* Return value:
* Pointer to the new string (must be freed)
*/
char *string_translate(const char *str, const char *find, const char *repl)
{
size_t sz_find = strlen(find);
size_t sz_repl = strlen(repl);
size_t sz_dest = strlen(str);
char *dest, *p;
p = dest = xstrcpy(str);
if( !sz_find ) return dest;
while( *p )
{
if( memcmp(p, find, sz_find) == 0 )
{
size_t offset = p - dest;
size_t newsize = sz_dest + (sz_repl - sz_find);
if( newsize > sz_dest )
dest = xrealloc(dest, newsize+1);
if( sz_repl > sz_find )
memmove(dest + offset + (sz_repl - sz_find), dest + offset, sz_dest - offset + 1);
else if( sz_repl < sz_find )
memmove(dest + offset, dest + offset + (sz_find - sz_repl), sz_dest - offset + 1);
memcpy(dest + offset, repl, sz_repl);
sz_dest = newsize;
p = dest + offset + sz_repl;
} else
++p;
}
return dest;
}
/*****************************************************************************
* Convert size into human readable format (e.g. 100,256Kb or 20.7Mb)
*
* Arguments:
* buffer pointer to the buffer for resulting string
* size size in bytes that you want to print
*
* Return value:
* Pointer to the string
*/
char *string_humansize(char *buffer, size_t size)
{
if( size < 1024 )
sprintf(buffer, "%ldb", (long)size);
else if( size < 100*1024 )
sprintf(buffer, "%.1fK", ((double)size)/1024.0);
else if( size < 1000*1024 )
sprintf(buffer, "%ldK", (long)(size/1024));
else if( size < 100*1024*1024 )
sprintf(buffer, "%.1fM", ((double)size)/(1024.0*1024.0));
else if( size < 1000*1024*1024 )
sprintf(buffer, "%ldM", (long)(size/(1024*1024)));
else
sprintf(buffer, "%.1fG", ((double)size)/(1024.0*1024.0*1024.0));
return string_replchar(buffer, ',', '.');
}
/*****************************************************************************
* Interpret escape sequence (\xNN, \NNN, \r, \n, etc.)
*
* Arguments:
* pptr points a pointer to the first character after '\'
*
* Return value:
* Value of the escaped character
*/
int string_get_escape(char **pptr)
{
int ch = 0;
static const char *hexdigits = "0123456789abcdef";
char *p = *pptr;
if( *p == 'x' )
{
const char *q;
if( (q = string_casechr(hexdigits, *(++p))) )
{
ch = q - hexdigits;
if( (q = string_casechr(hexdigits, *(++p))) )
{
ch = ch * 16 + (q - hexdigits);
}
}
}
else if( *p == '0' || *p == '1' || *p == '2' || *p == '3' )
{
ch = *(p++) - '0';
if( isdigit(*p) && *p != '8' && *p != '9' )
{
ch = ch * 8 + (*(p++) - '0');
if( isdigit(*p) && *p != '8' && *p != '9' )
{
ch = ch * 8 + (*p - '0');
}
}
}
else switch(*p) {
case 'a':
ch = '\a'; break;
case 'b':
ch = '\b'; break;
case 'f':
ch = '\f'; break;
case 'n':
ch = '\n'; break;
case 'r':
ch = '\r'; break;
case 't':
ch = '\t'; break;
case '\\':
ch = '\\'; break;
default:
ch = *p;
}
*pptr = p + 1;
return (ch > 0) ? (ch & 0xff) : -1;
}
int string_dequote(char *dst, char *src)
{
char *d = dst;
char *s = src;
int ch;
while( *s )
{
if( s[0] == '\\' && s[1] )
{
++s;
ch = string_get_escape(&s);
if( ch != -1 )
*d++ = ch;
}
else
*d++ = *s++;
}
*d = '\0';
return 0;
}
char *string_concat(const char *str, ...)
{
va_list args;
size_t yield_len;
char *yield_ptr;
char *yield;
char *p;
/*
* Calculate total length of yielding string
*/
yield_len = strlen(str);
va_start(args, str);
while( (p = va_arg(args, char *)) )
yield_len += strlen(p);
va_end(args);
yield = xmalloc(yield_len + 1);
strncpy(yield, str, yield_len);
yield[yield_len] = '\0';
yield_ptr = yield + strlen(yield);
va_start(args, str);
while( (p = va_arg(args, char *)) )
{
strcpy(yield_ptr, p);
yield_ptr += strlen(p);
}
va_end(args);
return yield;
}
void string_bin_to_hex(char *string, const char *binptr, int binlen)
{
static const char *hexdigits = "0123456789abcdef";
int i;
for( i = 0; i < binlen; i++ )
{
*string++ = hexdigits[(*binptr >> 4) & 0x0f];
*string++ = hexdigits[(*binptr ) & 0x0f];
++binptr;
}
*string = '\0';
}
int string_hex_to_bin(char *binptr, const char *string)
{
static const char *hexdigits = "0123456789abcdef";
int len = (int)strlen(string);
int i, val;
const char *p;
char *dest = binptr;
for( i = 0; 2*i < len; i++ )
{
if( (p = string_casechr(hexdigits, *(string++))) )
{
val = (int)(p - hexdigits);
if( (p = string_casechr(hexdigits, *(string++))) )
{
val = val * 16 + (int)(p - hexdigits);
*dest++ = (unsigned char)(val & 0xff);
}
else
return 0;
}
else
return 0;
}
return (int)(dest - binptr);
}
bool string_is_empty(const char *string)
{
const char *p;
for( p = string; *p; p++ )
if( !isspace((int)(unsigned char)*p) )
return FALSE;
return TRUE;
}
#ifdef TEST
int main(void)
{
char *hexstr = "0406ff2354124e6a9b2f6ed6ff00411287";
char binbuf[64];
int binlen;
char newhex[64];
/*
* string_hex_to_bin() and string_bin_to_hex()
*/
printf("*** Checking string_hex_to_bin() and string_bin_to_hex()\n");
printf("Original string : \"%s\"\n", hexstr);
binlen = string_hex_to_bin(binbuf, hexstr);
string_bin_to_hex(newhex, binbuf, binlen);
printf("Resulting string : \"%s\"\n", newhex);
if( strcmp(hexstr, newhex) )
printf("<<< ERROR!!! >>>\n");
return 0;
}
#endif /* TEST */
+621
View File
@@ -0,0 +1,621 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
static const char *months[] =
{
"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
};
int time_settimer(time_t *timer, int value)
{
*timer = time(NULL) + value;
return 0;
}
int time_timerout(time_t timer)
{
if( timer > 0 && time(NULL) >= timer )
return 1;
return 0;
}
int time_timeleft(time_t timer)
{
if( timer > 0 )
return MAX(time(NULL) - timer, 0);
return 0;
}
int time_elapsed(time_t since_time)
{
if( since_time > 0 )
{
int yield = time(NULL) - since_time;
return ( yield > 0 ) ? yield : 0;
}
return 0;
}
/*****************************************************************************
* Put time string into buffer, according to the format
*
* Arguments:
* buffer pointer to the destination buffer
* buflen buffer size
* fmt format string (`man strftime' for more information)
* t seconds since 1970.. you know..
*
* Return value:
* Pointer to the resulting string
*/
char *time_string_format(char *buffer, size_t buflen, const char *fmt, time_t t)
{
struct tm *tm;
if( !t ) t = time(&t);
tm = localtime(&t);
if( strftime(buffer, buflen, fmt, tm) == 0 )
{
strnxcpy(buffer, "invalid format", buflen);
}
return buffer;
}
/*****************************************************************************
* Put time string into buffer (time format depends on the locale settings).
*
* Arguments:
* buffer pointer to the destination buffer
* buflen buffer size
* t seconds since 1970.. you know..
*
* Return value:
* Pointer to the resulting string
*/
char *time_string_long(char *buffer, size_t buflen, time_t t)
{
char *sptr;
if( !t ) time(&t);
sptr = ctime(&t);
strnxcpy(buffer, sptr, buflen);
return string_chomp(buffer);
}
/*****************************************************************************
* Put time string into buffer (e.g. My birth day is "Aug 11 07:20:00").
*
* Arguments:
* buffer pointer to the destination buffer
* buflen buffer size
* t seconds since 1970.. you know..
*
* Return value:
* Pointer to the resulting string
*/
char *time_string_log(char *buffer, size_t buflen, time_t t)
{
struct tm *ptm;
ASSERT(buflen > 16);
if( !t ) time(&t);
ptm = localtime(&t);
sprintf(buffer, "%3s %02d %02d:%02d:%02d",
months[ptm->tm_mon], ptm->tm_mday,
ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
return buffer;
}
/*****************************************************************************
* Put date+time string into buffer. Special format for netmail message
* headers.
*
* Arguments:
* buffer pointer to the destination buffer
* buflen buffer size
* t seconds since 1970.. you know..
*
* Return value:
* Pointer to the resulting string
*/
char *time_string_msghdr(char *buffer, time_t t)
{
struct tm *ptm;
if( !t ) time(&t);
ptm = localtime(&t);
sprintf(buffer, "%02d %3s %02d %02d:%02d:%02d",
ptm->tm_mday, months[ptm->tm_mon],
(ptm->tm_year < 100) ? ptm->tm_year : ptm->tm_year % 100,
ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
return buffer;
}
/*****************************************************************************
* Get TimeZone for our location
*
* Arguments:
*
* Return value:
* Offset in minutes
*/
long time_gmtoffset(void)
{
time_t tt = time(NULL);
struct tm local = *localtime(&tt);
struct tm gmt = *gmtime(&tt);
long tz = gmt.tm_yday - local.tm_yday;
if( tz > 1 )
tz = -24;
else if( tz < -1 )
tz = 24;
else
tz *= 24;
tz += gmt.tm_hour - local.tm_hour;
tz *= 60;
tz += gmt.tm_min - local.tm_min;
return tz;
}
/*****************************************************************************
* Get TimeZone for our location as pointer to the null terminated string
*
* Arguments:
* buffer pointer to the destination buffer (must be at least 6 bytes)
*
* Return value:
* Pointer to the resulting string (e.g. "+0400")
*/
char *time_string_gmtoffset(char *buffer)
{
long tz = time_gmtoffset();
char sign = (tz > 0)?'+':'-';
int hour = tz/60;
int mint = tz%60;
sprintf(buffer, "%c%02d%02d", sign, hour, mint);
return buffer;
}
/*****************************************************************************
* Get time in native format from seconds counter (e.g. "1:30:10")
*
* Arguments:
* buffer pointer to the destination buffer (must be at least 9 bytes)
* timer number of seconds
*
* Return value:
* Pointer to the resulting string
*/
char *time_string_timer(char *buffer, int timer)
{
int hour, min, sec;
hour = (timer/3600);
min = (timer%3600)/60;
sec = (timer%60);
if( hour )
sprintf(buffer, "%02d:%02d:%02d", (hour < 100) ? hour : 99, min, sec);
else
sprintf(buffer, "%02d:%02d", min, sec);
return buffer;
}
/*****************************************************************************
* Get approximate interval in native format (e.g. "1 day", "3 hours")
*
* Arguments:
* buffer pointer to the destination buffer (must be large enough)
* seconds time interval in seconds
*
* Return value:
* Pointer to the resulting string
*/
char *time_string_approx_interval(char *buffer, int seconds)
{
if( seconds < 0 )
strcpy(buffer, "error");
else if( seconds == 0 )
strcpy(buffer, "up-to-date");
else if( seconds == 1 )
strcpy(buffer, "1 second");
else if( seconds < 60 )
sprintf(buffer, "%d seconds", seconds);
else if( seconds < 120 )
strcpy(buffer, "1 minute");
else if( seconds < 3600 )
sprintf(buffer, "%d minutes", seconds/60);
else if( seconds < 7200 )
strcpy(buffer, "1 hour");
else if( seconds < 86400 )
sprintf(buffer, "%d hours", seconds/3600);
else if( seconds < 172800 )
strcpy(buffer, "1 day");
else if( seconds < 999*86400 )
sprintf(buffer, "%d days", seconds/86400);
else
sprintf(buffer, "%d years", seconds/(366*86400));
return buffer;
}
/*****************************************************************************
* Check time for conforming to the time interval specified by string
*
* Arguments:
* str pointer to the time interval string
* now time to check (most often it is current time)
*
* Return value:
* Zero value if time conforms, 1 if not, and -1 if specified time interval
* string is incorrect
*/
int time_check(const char *str, struct tm *now)
{
int h1, h2, m1, m2, beg, end, cur, day;
bool dayok = FALSE;
bool timeok = FALSE;
ASSERT(str != NULL && now != NULL);
if( *str == '\0' ) return 1;
if( strncasecmp(str, "Sun", 3) == 0 ) day = 0;
else if( strncasecmp(str, "Mon", 3) == 0 ) day = 1;
else if( strncasecmp(str, "Tue", 3) == 0 ) day = 2;
else if( strncasecmp(str, "Wed", 3) == 0 ) day = 3;
else if( strncasecmp(str, "Thu", 3) == 0 ) day = 4;
else if( strncasecmp(str, "Fri", 3) == 0 ) day = 5;
else if( strncasecmp(str, "Sat", 3) == 0 ) day = 6;
else if( strncasecmp(str, "Any", 3) == 0 ) day = -1;
else if( strncasecmp(str, "Wk", 2) == 0 ) day = -2;
else if( strncasecmp(str, "We", 2) == 0 ) day = -3;
else day = -4;
if( day >= 0 )
{
dayok = (now->tm_wday == day);
str += 3;
}
else
{
switch(day) {
case -3:
dayok = ( (now->tm_wday == 0) || (now->tm_wday == 6) );
str += 2;
break;
case -2:
dayok = ( (now->tm_wday != 0) && (now->tm_wday != 6) );
str += 2;
break;
case -1:
str += 3;
default:
dayok = TRUE;
}
}
if( !dayok ) return 1;
if( *str == '\0' )
return (day == -4) ? -1 : 0;
if( sscanf(str, "%02d:%02d-%02d:%02d", &h1, &m1, &h2, &m2) != 4 )
return -1;
cur = now->tm_hour*60 + now->tm_min;
beg = h1*60 + m1;
end = h2*60 + m2;
if( end > beg )
timeok = ( (cur >= beg) && (cur <= end) );
else
timeok = ( (cur >= beg) || (cur <= end) );
DEB((D_INFO, "checktime: is %02d:%02d between %02d:%02d and %02d:%02d? %s!",
now->tm_hour,now->tm_min, h1, m1, h2, m2, timeok ? "Yes" : "No"));
return !timeok;
}
/*****************************************************************************
* Check time for conforming to the time intervals
*
* Arguments:
* timestr pointer to the time intervals string
* tim time to check (most often it is current time)
*
* Return value:
* Zero value if time conforms, 1 if not, and -1 if specified time interval
* string is incorrect
*/
int time_checkintervals(const char *timestr, struct tm *now)
{
char *str, *p;
ASSERT(timestr != NULL);
str = xstrcpy(timestr);
for( p = strtok(str, ","); p; p = strtok(NULL, ",") )
{
if( *p )
{
switch(time_check(p, now)) {
case 0:
return 0;
case -1:
return -1;
case 1:
break;
default:
ASSERT(0);
}
}
}
return 1;
}
int timevec_add(s_timevec *dest, int day_beg, int day_end, long beg, long end)
{
int i;
/*
* Check for dupes. TODO: more complex checks
*/
for( i = 0; i < dest->num; i++ )
{
if( dest->tvec[i].day_beg <= day_beg
&& dest->tvec[i].day_end >= day_end
&& dest->tvec[i].beg == beg
&& dest->tvec[i].end == end )
return 0;
}
if( dest->num >= TIMEVEC_MAX_ELEMENTS )
return -1;
dest->tvec[dest->num].day_beg = day_beg;
dest->tvec[dest->num].day_end = day_end;
dest->tvec[dest->num].beg = beg;
dest->tvec[dest->num].end = end;
dest->num++;
return 0;
}
/*****************************************************************************
* Parse one time interval. Only uucico like time format is supported yet.
*
* Arguments:
* dest pointer to the destination time storage structure
* str time string to parse
*
* Return value:
* Zero value on success, and -1 for incorrect time strings
*/
int timevec_parse(s_timevec *dest, const char *str)
{
int beg_hour = 0;
int end_hour = 0;
int beg_min = 0;
int end_min = 0;
enum day beg_day;
enum day end_day;
int beg = 0;
int end = 0;
if( strncasecmp(str, "Sun", 3) == 0 )
beg_day = DAY_SUNDAY;
else if( strncasecmp(str, "Mon", 3) == 0 )
beg_day = DAY_MONDAY;
else if( strncasecmp(str, "Tue", 3) == 0 )
beg_day = DAY_TUESDAY;
else if( strncasecmp(str, "Wed", 3) == 0 )
beg_day = DAY_WEDNESDAY;
else if( strncasecmp(str, "Thu", 3) == 0 )
beg_day = DAY_THURSDAY;
else if( strncasecmp(str, "Fri", 3) == 0 )
beg_day = DAY_FRIDAY;
else if( strncasecmp(str, "Sat", 3) == 0 )
beg_day = DAY_SATURDAY;
else if( strncasecmp(str, "Any", 3) == 0 )
beg_day = DAY_ANY;
else if( strncasecmp(str, "Wk", 2) == 0 )
beg_day = DAY_WORKDAY;
else if( strncasecmp(str, "We", 2) == 0 )
beg_day = DAY_WEEKEND;
else
beg_day = DAY_UNDEF;
end_day = beg_day;
if( beg_day >= DAY_MONDAY && beg_day <= DAY_SUNDAY )
str += 3;
else if( beg_day == DAY_ANY )
str += 3;
else if( beg_day == DAY_WORKDAY || beg_day == DAY_WEEKEND )
str += 2;
if( sscanf(str, "%02d:%02d-%02d:%02d", &beg_hour, &beg_min, &end_hour, &end_min) != 4 )
return -1;
beg = beg_hour * 60 + beg_min;
end = end_hour * 60 + end_min;
if( beg == end )
return -1;
switch(beg_day) {
case DAY_MONDAY:
case DAY_TUESDAY:
case DAY_WEDNESDAY:
case DAY_THURSDAY:
case DAY_FRIDAY:
case DAY_SATURDAY:
case DAY_SUNDAY:
timevec_add(dest, beg_day, end_day, beg, end);
break;
case DAY_WORKDAY:
timevec_add(dest, DAY_MONDAY, DAY_FRIDAY, beg, end);
break;
case DAY_WEEKEND:
timevec_add(dest, DAY_SATURDAY, DAY_SUNDAY, beg, end);
break;
default:
timevec_add(dest, DAY_MONDAY, DAY_SUNDAY, beg, end);
break;
}
return 0;
}
int timevec_parse_list(s_timevec *dest, const char *str)
{
char *p = NULL;
char *tmp = xstrcpy(str);
int rc = 0;
for( p = strtok(tmp, ","); p; p = strtok(NULL, ",") )
{
if( *p && timevec_parse(dest, p) == -1 )
rc = -1;
}
free(tmp);
return rc;
}
int timevec_check(const s_timevec *tv, const struct tm *now)
{
int i;
bool ok = FALSE;
int cur = now->tm_hour * 60 + now->tm_min;
int cur_day = DAY_UNDEF;
if( now->tm_wday == 0 )
cur_day = DAY_SUNDAY;
else if( now->tm_wday == 1 )
cur_day = DAY_MONDAY;
else if( now->tm_wday == 2 )
cur_day = DAY_TUESDAY;
else if( now->tm_wday == 3 )
cur_day = DAY_WEDNESDAY;
else if( now->tm_wday == 4 )
cur_day = DAY_THURSDAY;
else if( now->tm_wday == 5 )
cur_day = DAY_FRIDAY;
else if( now->tm_wday == 6 )
cur_day = DAY_SATURDAY;
else
{
log("timevec_check: error 'tm->tm_wday' is out of range");
return -1;
}
for( i = 0; i < tv->num; i++ )
{
if( (cur_day >= tv->tvec[i].day_beg)
&& (cur_day <= tv->tvec[i].day_end) )
{
int beg = tv->tvec[i].beg;
int end = tv->tvec[i].end;
if( end > beg )
ok = ( (cur >= beg) && (cur <= end) );
else
ok = ( (cur >= beg) || (cur <= end) );
if( ok ) break;
}
}
return ok ? 0 : 1;
}
char *timevec_string(char *buffer, const s_timevec *tv, size_t buflen)
{
int i;
char *ptr = buffer;
*ptr = '\0';
for( i = 0; i < tv->num; i++ )
{
if( tv->tvec[i].day_beg == DAY_MONDAY
&& tv->tvec[i].day_end == DAY_SUNDAY )
{
sprintf(ptr, "%02ld:%02ld-%02ld:%02ld,",
tv->tvec[i].beg / 60, tv->tvec[i].beg % 60,
tv->tvec[i].end / 60, tv->tvec[i].end % 60);
}
else if( tv->tvec[i].day_beg == tv->tvec[i].day_end )
{
sprintf(ptr, "%d.%02ld:%02ld-%02ld:%02ld,", tv->tvec[i].day_beg,
tv->tvec[i].beg / 60, tv->tvec[i].beg % 60,
tv->tvec[i].end / 60, tv->tvec[i].end % 60);
}
else
{
sprintf(ptr, "%d.%02ld:%02ld-%d.%02ld:%02ld,",
tv->tvec[i].day_beg, tv->tvec[i].beg / 60, tv->tvec[i].beg % 60,
tv->tvec[i].day_end, tv->tvec[i].end / 60, tv->tvec[i].end % 60);
}
ptr += strlen(ptr);
}
if( ptr > buffer )
*(ptr - 1) = '\0';
return buffer;
}
bool timevec_isdefined(const s_timevec *tv)
{
return tv->num ? TRUE : FALSE;
}
bool timevec_isnow(const s_timevec *tv, const struct tm *now)
{
return ( timevec_check(tv, now) == 0 ) ? TRUE : FALSE;
}
/* end of u_time.c */
+286
View File
@@ -0,0 +1,286 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "version.h"
#include "logger.h"
#include "util.h"
#include "nodelist.h"
/*
* Our fake expressions checker. Allways return FALSE (?)
*/
bool eventexpr(s_expr *expr)
{
return FALSE;
}
static void usage(void)
{
printf_usage("nodelist compiler",
"usage: bfindex [-fh]\n"
"\n"
"options:\n"
" -f force nodelist compiling\n"
" -h show this help message\n"
"\n"
);
}
static int nodelist_makeindex(s_nodelist *nlp, s_faddr addr)
{
s_bni bni;
char buf[1024];
long countnodes = 0L;
long countlines = 0L;
enum nodelist_keyword keyword;
memset(&bni, 0, sizeof(s_bni));
bni.zone = addr.zone;
bni.net = addr.net;
bni.node = addr.node;
bni.point = addr.point;
if( nodelist_createheader(nlp) == -1 )
{
log("cannot create nodelist index header");
return -1;
}
while(1)
{
char *p, *q;
if( (bni.offset = ftell(nlp->fp_nodelist)) == -1 )
{
logerr("ftell() return -1 for nodelist");
return -1;
}
if( fgets(buf, sizeof(buf), nlp->fp_nodelist) == NULL )
{
return countnodes;
}
string_chomp(buf);
++countlines;
if( buf[0] == ';' || buf[0] == '\0' ) continue;
if( (p = strchr(buf, ',')) )
{
*p++ = '\0';
if( (q = strchr(p, ',')) ) *q = '\0';
}
if( p == NULL || *p == '\0' )
{
log("incorrect nodelist line %ld: Short line", countlines);
continue;
}
if( (keyword = nodelist_keywordval(buf)) == -1 )
{
log("incorrect nodelist line %d: Bad keyword \"%s\"",
countlines, buf);
continue;
}
if( keyword == KEYWORD_BOSS )
{
s_faddr tmpaddr;
if( ftn_addrparse(&tmpaddr, p, FALSE) )
{
log("incorrect nodelist line %ld: Bad boss address \"%s\"",
countlines, p);
}
else
{
bni.zone = tmpaddr.zone;
bni.net = tmpaddr.net;
bni.node = tmpaddr.node;
bni.point = 0;
bni.hub = 0;
}
}
else if( ISDEC(p) )
{
int value = atoi(p);
if( value > 0x7fff )
value = 0x7fff;
else if( value < 0 )
value = 0;
switch(keyword) {
case KEYWORD_ZONE:
bni.zone = value;
bni.net = 0;
bni.node = 0;
bni.point = 0;
bni.hub = 0;
break;
case KEYWORD_REGION:
bni.net = value;
bni.node = 0;
bni.point = 0;
bni.hub = 0;
break;
case KEYWORD_HOST:
bni.net = value;
bni.node = 0;
bni.point = 0;
bni.hub = 0;
break;
case KEYWORD_HUB:
bni.node = value;
bni.point = 0;
bni.hub = value;
break;
case KEYWORD_EMPTY:
case KEYWORD_PVT:
case KEYWORD_HOLD:
case KEYWORD_DOWN:
bni.node = value;
bni.point = 0;
break;
case KEYWORD_POINT:
bni.point = value;
break;
default:
ASSERT_MSG();
}
if( nodelist_putindex(nlp, &bni) == -1 )
return -1;
++countnodes;
}
else
{
log("incorrect nodelist line %ld: Bad number \"%s\"",
countlines, p);
}
}
return -1;
}
int main(int argc, char *argv[])
{
s_cval_entry *cfptr;
char *nodelistdir = NULL;
time_t starttime = 0L;
bool forcecompile = FALSE;
long countnodes = 0L;
char c;
/* Initialise random number generation */
(void)srand((unsigned)time(0));
/* Initialise current locale */
(void)setlocale(LC_ALL, "");
/* Set our name (for logging only) */
while( (c = getopt(argc, argv, "hf")) != EOF )
{
switch( c ) {
case 'f':
forcecompile = TRUE;
break;
case 'h':
usage();
exit(0);
default:
usage();
exit(1);
}
}
if( conf_readconf(conf_getconfname(), 0) )
{
exit(1);
}
if( log_open(log_getfilename(LOG_FILE_SESSION), NULL, NULL) )
{
log("can't continue without logging");
exit(1);
}
/* Ignore some terminating signals */
signal(SIGHUP, SIG_IGN);
signal(SIGINT, SIG_IGN);
signal(SIGTERM, SIG_IGN);
time(&starttime);
nodelistdir = conf_string(cf_nodelist_directory);
for( cfptr = conf_first(cf_nodelist); cfptr; cfptr = conf_next(cfptr) )
{
s_nodelist *nlp = NULL;
bool willcompile = FALSE;
if( forcecompile )
{
willcompile = TRUE;
}
else if( (nlp = nodelist_open(nodelistdir,
cfptr->d.falist.what,
NODELIST_READ)) == NULL )
{
willcompile = TRUE;
}
else
{
nodelist_close(nlp); nlp = NULL;
willcompile = FALSE;
}
if( willcompile )
{
log("rebuilding index for nodelist \"%s\"", cfptr->d.falist.what);
if( (nlp = nodelist_open(nodelistdir, cfptr->d.falist.what,
NODELIST_WRITE)) )
{
long rc = nodelist_makeindex(nlp, cfptr->d.falist.addr);
nodelist_close(nlp); nlp = NULL;
if( rc > 0 ) countnodes += rc;
}
}
else
log("nodelist \"%s\" is up to date", cfptr->d.falist.what);
}
if( countnodes > 0 )
{
long ptime = (long)time(NULL) - (long)starttime;
long nps = (ptime > 0) ? countnodes / ptime : countnodes;
log("processed %ld nodes in %ld second(s) (%ld node/sec)",
countnodes, ptime, nps);
}
deinit_conf();
/*
* Shutdown logging services
*/
if( log_isopened() ) log_close();
#ifdef DEBUG
if( debug_isopened() ) debug_close();
#endif
exit(0);
}
+338
View File
@@ -0,0 +1,338 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "version.h"
#include "logger.h"
#include "util.h"
#include "outbound.h"
#include "session.h"
/*
* Command line options storage structure
*/
typedef struct {
bool calls_stat;
bool sort_bysize;
bool sort_byaddr;
bool sort_reverse;
bool disable_total_sizes;
bool humansizes;
int nodeslimit;
} s_opts;
/*
* Our fake expressions checker. Allways return FALSE (?)
*/
bool eventexpr(s_expr *expr)
{
return FALSE;
}
static void usage(void)
{
printf_usage("outbound viewer",
"usage: bfstat [-afhprst] [-n<number>]\n"
"\n"
"options:\n"
" -a sort by FTN address (default)\n"
" -c print incoming/outgoing calls statistic\n"
" -f disable queue sorting\n"
" -h print this help message\n"
" -n <number> don't print more than <number> systems\n"
" -p print sizes in human readable format\n"
" -r reverse order while sorting\n"
" -s sort by total files size\n"
" -t disable total sizes printing\n"
"\n"
);
}
static void bfstat_opts_default(s_opts *opts)
{
memset(opts, '\0', sizeof(s_opts));
opts->sort_bysize = FALSE;
opts->sort_byaddr = TRUE;
opts->sort_reverse = FALSE;
opts->disable_total_sizes = FALSE;
opts->humansizes = FALSE;
opts->nodeslimit = 0;
}
static void bfstat_print_outbound(s_sysqueue *queue, s_opts *opts)
{
int i;
char sbuf[4][10];
char age_buffer[20];
char abuf[BF_MAXADDRSTR+1];
size_t size_netmail = 0;
size_t size_arcmail = 0;
size_t size_other = 0;
time_t now = time(0);
int printnum = opts->nodeslimit ? MIN(opts->nodeslimit, queue->sysnum)
: queue->sysnum;
printf("Address Netmail Arcmail Other Flavors Age\n");
printf("=========================================================================\n");
for( i = 0; i < printnum; i++ )
{
/* Update total size counters */
if( !opts->disable_total_sizes )
{
size_netmail += queue->systab[i].netmail_size;
size_arcmail += queue->systab[i].arcmail_size;
size_other += queue->systab[i].request_size
+ queue->systab[i].files_size;
}
/* Get mail age string */
if( queue->systab[i].mailage > 0 )
time_string_approx_interval(age_buffer,
(now - queue->systab[i].mailage));
else
*age_buffer = '\0';
if( opts->humansizes )
{
printf("%-25s %-9s %-9s %-9s %c%c%c%c%c %s\n",
ftn_addrstr(abuf, queue->systab[i].node.addr),
string_humansize(sbuf[0], queue->systab[i].netmail_size),
string_humansize(sbuf[1], queue->systab[i].arcmail_size),
string_humansize(sbuf[2], queue->systab[i].request_size + queue->systab[i].files_size),
(queue->systab[i].flavors & FLAVOR_HOLD ) ? 'H' : '.',
(queue->systab[i].flavors & FLAVOR_NORMAL) ? 'N' : '.',
(queue->systab[i].flavors & FLAVOR_DIRECT) ? 'D' : '.',
(queue->systab[i].flavors & FLAVOR_CRASH ) ? 'C' : '.',
(queue->systab[i].flavors & FLAVOR_IMMED ) ? 'I' : '.',
age_buffer);
}
else
{
printf("%-25s %-9ld %-9ld %-9ld %c%c%c%c%c %s\n",
ftn_addrstr(abuf, queue->systab[i].node.addr),
(long)(queue->systab[i].netmail_size),
(long)(queue->systab[i].arcmail_size),
(long)(queue->systab[i].request_size + queue->systab[i].files_size),
(queue->systab[i].flavors & FLAVOR_HOLD ) ? 'H' : '.',
(queue->systab[i].flavors & FLAVOR_NORMAL) ? 'N' : '.',
(queue->systab[i].flavors & FLAVOR_DIRECT) ? 'D' : '.',
(queue->systab[i].flavors & FLAVOR_CRASH ) ? 'C' : '.',
(queue->systab[i].flavors & FLAVOR_IMMED ) ? 'I' : '.',
age_buffer);
}
}
if( !opts->disable_total_sizes )
{
printf("=========================================================================\n");
if( opts->humansizes )
{
printf("TOTAL %3d systems %-9s %-9s %-9s %-9s\n",
printnum,
string_humansize(sbuf[0], size_netmail),
string_humansize(sbuf[1], size_arcmail),
string_humansize(sbuf[2], size_other),
string_humansize(sbuf[3], size_netmail+size_arcmail+size_other));
}
else
{
printf("TOTAL %3d systems %-9ld %-9ld %-9ld %-9ld\n",
printnum,
(long)size_netmail, (long)size_arcmail, (long)size_other,
(long)(size_netmail + size_arcmail + size_other));
}
}
}
static void bfstat_print_stat(s_sysqueue *queue, s_opts *opts)
{
int i;
s_sess_stat stat;
char abuf[BF_MAXADDRSTR+1];
time_t now = time(0);
int printnum = opts->nodeslimit ? MIN(opts->nodeslimit, queue->sysnum)
: queue->sysnum;
printf("Address Last incoming Last outgoing Status\n");
printf("=========================================================================\n");
for( i = 0; i < printnum; i++ )
{
if( session_stat_get(&stat, &queue->systab[i].node.addr) )
{
printf("%-25s No statistic available\n",
ftn_addrstr(abuf, queue->systab[i].node.addr));
}
else
{
char last_in[30];
char last_out[30];
char status[60];
char buffer[30];
/*
* Format date of the last successful incoming session
*/
if( stat.last_success_in > 0 )
{
time_string_format(last_in, sizeof(last_in),
"%H:%M %d/%m/%y", stat.last_success_in);
}
else
strcpy(last_in, "--------------");
/*
* Format date of the last successful outgoing session
*/
if( stat.last_success_out > 0 )
{
time_string_format(last_out, sizeof(last_out),
"%H:%M %d/%m/%y", stat.last_success_out);
}
else
strcpy(last_out, "--------------");
/*
* Generate calls status message
*/
if( stat.undialable )
{
strcpy(status, "Undialable");
}
else if( stat.hold_until > now )
{
sprintf(status, "Holded for %s",
time_string_approx_interval(buffer, stat.hold_until - now));
}
else if( stat.hold_freqs > now )
{
sprintf(status, "Holded for %s",
time_string_approx_interval(buffer, stat.hold_freqs - now));
}
else
strcpy(status, "Normal");
if( *status )
{
printf("%-25s %-15s %-15s %s\n",
ftn_addrstr(abuf, queue->systab[i].node.addr),
last_in, last_out, status);
}
else
{
printf("%-25s %-15s %-15s\n",
ftn_addrstr(abuf, queue->systab[i].node.addr),
last_in, last_out);
}
}
}
}
int main(int argc, char *argv[])
{
s_opts opts;
s_sysqueue queue;
s_outbound_callback_data ocb;
char c;
int i;
bfstat_opts_default(&opts);
while( (c = getopt(argc, argv, "acfhn:prst")) != EOF )
{
switch( c ) {
case 'h':
usage();
exit(0);
case 'c':
opts.calls_stat = TRUE;
break;
case 'f':
opts.sort_bysize = FALSE;
opts.sort_byaddr = FALSE;
opts.sort_reverse = FALSE;
break;
case 'p':
opts.humansizes = TRUE;
break;
case 't':
opts.disable_total_sizes = TRUE;
break;
case 'r':
opts.sort_reverse = TRUE;
break;
case 's':
opts.sort_byaddr = FALSE;
opts.sort_bysize = TRUE;
break;
case 'a':
opts.sort_byaddr = TRUE;
opts.sort_bysize = FALSE;
break;
case 'n':
if( ISDEC(optarg) )
opts.nodeslimit = atoi(optarg);
break;
default:
usage();
exit(1);
}
}
memset(&queue, '\0', sizeof(s_sysqueue));
/* Initialise random number generation */
(void)srand((unsigned)time(0));
/* Initialise current locale */
(void)setlocale(LC_ALL, "");
if( conf_readconf(conf_getconfname(), 0) )
exit(1);
memset(&ocb, '\0', sizeof(s_outbound_callback_data));
ocb.callback = out_handle_sysqueue;
ocb.dest = (void *)&queue;
out_scan(&ocb, NULL);
if( queue.sysnum > 1 && (opts.sort_byaddr || opts.sort_bysize) )
{
int sort_opts = opts.sort_byaddr ? QUEUE_SORT_ADDRESS
: opts.sort_bysize ? QUEUE_SORT_SIZE : 0;
if( opts.sort_reverse )
sort_opts |= QUEUE_SORT_REVERSE;
out_sysqueue_sort(&queue, sort_opts);
}
if( queue.sysnum > 0 )
{
if( opts.calls_stat )
bfstat_print_stat(&queue, &opts);
else
bfstat_print_outbound(&queue, &opts);
}
else
printf("Outbound queue is empty\n");
fflush(stdout);
deinit_sysqueue(&queue);
deinit_conf();
exit(0);
}
+155
View File
@@ -0,0 +1,155 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#include "includes.h"
#include "confread.h"
#include "logger.h"
#include "util.h"
#include "nodelist.h"
#define DEF_DOMAIN "fidonet.org"
/*
* Our fake expressions checker. Allways return FALSE (?)
*/
bool eventexpr(s_expr *expr)
{
return FALSE;
}
static void usage(void)
{
printf_usage("nodelist lookup utility",
"usage: nlookup [-rmh] <address>\n"
"\n"
"options:\n"
" -r show nodelist string\n"
" -m show email address\n"
" -h show this help message\n"
"\n"
);
}
void print_nodemail(const s_node *node)
{
char abuf[BF_MAXADDRSTR+1];
if( node->sysop && *node->sysop && strcmp(node->sysop, "<none>") )
{
char username[BNI_MAXSYSOP+1];
strnxcpy(username, node->sysop, sizeof(node->sysop));
string_replchar(username, ' ', '_');
printf("%s@%s.fidonet.org\n", username,
ftn_addrstr_inet(abuf, node->addr));
}
fflush(stdout);
}
void print_nodeinfo(const s_node *node)
{
char abuf[BF_MAXADDRSTR+1];
printf("Address : %s\n", ftn_addrstr(abuf, node->addr));
printf("System : %s\n", node->name);
printf("Phone : %s\n", node->phone);
printf("Sysop : %s\n", node->sysop);
printf("Location : %s\n", node->location);
printf("Speed : %lu\n", node->speed);
printf("Flags : %s\n", node->flags);
if( node->worktime.num )
{
char timebuf[80];
time_t unixtime = time(NULL);
struct tm *now = localtime(&unixtime);
timevec_string(timebuf, &node->worktime, sizeof(timebuf));
printf("Work time : %s (%s)\n", timebuf,
timevec_check(&node->worktime, now) ? "false" : "true");
}
if( node->sysop && *node->sysop && strcmp(node->sysop, "<none>") )
{
char username[BNI_MAXSYSOP+1];
strnxcpy(username, node->sysop, sizeof(node->sysop));
string_replchar(username, ' ', '_');
printf("e-mail : %s@%s\n", username,
ftn_addrstr_inet(abuf, node->addr));
}
fflush(stdout);
}
int main(int argc, char *argv[])
{
s_node node;
s_faddr addr;
char ch;
bool rawstring = FALSE;
bool emailaddr = FALSE;
/* Initialise random number generation */
(void)srand((unsigned)time(0));
/* Initialise current locale */
(void)setlocale(LC_ALL, "");
while( (ch=getopt(argc, argv, "hrm")) != EOF )
{
switch( ch ) {
case 'h':
usage();
exit(BFERR_NOERROR);
case 'r':
rawstring = TRUE;
break;
case 'm':
emailaddr = TRUE;
break;
default:
usage();
exit(BFERR_FATALERROR);
}
}
if( optind >= argc || ftn_addrparse(&addr, argv[optind], FALSE) )
{
usage();
exit(BFERR_FATALERROR);
}
if( conf_readconf(conf_getconfname(), 0) )
exit(BFERR_FATALERROR);
if( rawstring )
{
char buf[512];
if( nodelist_lookup_string(buf, sizeof(buf), addr) == 0 )
printf("%s\n", buf);
}
else if( nodelist_lookup(&node, addr) == 0 )
{
if( emailaddr )
print_nodemail(&node);
else
print_nodeinfo(&node);
}
deinit_conf();
exit(0);
}
Vendored Executable
+951
View File
@@ -0,0 +1,951 @@
#! /bin/sh
# Attempt to guess a canonical system name.
# Copyright (C) 1992, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
#
# This file 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 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Written by Per Bothner <bothner@cygnus.com>.
# The master version of this file is at the FSF in /home/gd/gnu/lib.
#
# This script attempts to guess a canonical system name similar to
# config.sub. If it succeeds, it prints the system name on stdout, and
# exits with 0. Otherwise, it exits with 1.
#
# The plan is that this can be called by configure scripts if you
# don't specify an explicit system type (host/target name).
#
# Only a few systems have been added to this list; please add others
# (but try to keep the structure clean).
#
# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
# (ghazi@noc.rutgers.edu 8/24/94.)
if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
PATH=$PATH:/.attbin ; export PATH
fi
UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
trap 'rm -f dummy.c dummy.o dummy; exit 1' 1 2 15
# Note: order is significant - the case branches are not exclusive.
case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
alpha:OSF1:*:*)
if test $UNAME_RELEASE = "V4.0"; then
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
fi
# A Vn.n version is a released version.
# A Tn.n version is a released field test version.
# A Xn.n version is an unreleased experimental baselevel.
# 1.2 uses "1.2" for uname -r.
cat <<EOF >dummy.s
.globl main
.ent main
main:
.frame \$30,0,\$26,0
.prologue 0
.long 0x47e03d80 # implver $0
lda \$2,259
.long 0x47e20c21 # amask $2,$1
srl \$1,8,\$2
sll \$2,2,\$2
sll \$0,3,\$0
addl \$1,\$0,\$0
addl \$2,\$0,\$0
ret \$31,(\$26),1
.end main
EOF
${CC-cc} dummy.s -o dummy 2>/dev/null
if test "$?" = 0 ; then
./dummy
case "$?" in
7)
UNAME_MACHINE="alpha"
;;
15)
UNAME_MACHINE="alphaev5"
;;
14)
UNAME_MACHINE="alphaev56"
;;
10)
UNAME_MACHINE="alphapca56"
;;
16)
UNAME_MACHINE="alphaev6"
;;
esac
fi
rm -f dummy.s dummy
echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr [[A-Z]] [[a-z]]`
exit 0 ;;
21064:Windows_NT:50:3)
echo alpha-dec-winnt3.5
exit 0 ;;
Amiga*:UNIX_System_V:4.0:*)
echo m68k-cbm-sysv4
exit 0;;
amiga:NetBSD:*:*)
echo m68k-cbm-netbsd${UNAME_RELEASE}
exit 0 ;;
amiga:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
*:[Aa]miga[Oo][Ss]:*:*)
echo ${UNAME_MACHINE}-unknown-amigaos
exit 0 ;;
arc64:OpenBSD:*:*)
echo mips64el-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
arc:OpenBSD:*:*)
echo mipsel-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
hkmips:OpenBSD:*:*)
echo mips-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
pmax:OpenBSD:*:*)
echo mipsel-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
sgi:OpenBSD:*:*)
echo mips-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
wgrisc:OpenBSD:*:*)
echo mipsel-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
echo arm-acorn-riscix${UNAME_RELEASE}
exit 0;;
arm32:NetBSD:*:*)
echo arm-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
exit 0 ;;
SR2?01:HI-UX/MPP:*:*)
echo hppa1.1-hitachi-hiuxmpp
exit 0;;
Pyramid*:OSx*:*:*|MIS*:OSx*:*:*|MIS*:SMP_DC-OSx*:*:*)
# akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
if test "`(/bin/universe) 2>/dev/null`" = att ; then
echo pyramid-pyramid-sysv3
else
echo pyramid-pyramid-bsd
fi
exit 0 ;;
NILE:*:*:dcosx)
echo pyramid-pyramid-svr4
exit 0 ;;
sun4H:SunOS:5.*:*)
echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
i86pc:SunOS:5.*:*)
echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
sun4*:SunOS:6*:*)
# According to config.sub, this is the proper way to canonicalize
# SunOS6. Hard to guess exactly what SunOS6 will be like, but
# it's likely to be more like Solaris than SunOS4.
echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
sun4*:SunOS:*:*)
case "`/usr/bin/arch -k`" in
Series*|S4*)
UNAME_RELEASE=`uname -v`
;;
esac
# Japanese Language versions have a version number like `4.1.3-JL'.
echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
exit 0 ;;
sun3*:SunOS:*:*)
echo m68k-sun-sunos${UNAME_RELEASE}
exit 0 ;;
sun*:*:4.2BSD:*)
UNAME_RELEASE=`(head -1 /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
case "`/bin/arch`" in
sun3)
echo m68k-sun-sunos${UNAME_RELEASE}
;;
sun4)
echo sparc-sun-sunos${UNAME_RELEASE}
;;
esac
exit 0 ;;
aushp:SunOS:*:*)
echo sparc-auspex-sunos${UNAME_RELEASE}
exit 0 ;;
atari*:NetBSD:*:*)
echo m68k-atari-netbsd${UNAME_RELEASE}
exit 0 ;;
atari*:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
sun3*:NetBSD:*:*)
echo m68k-sun-netbsd${UNAME_RELEASE}
exit 0 ;;
sun3*:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
mac68k:NetBSD:*:*)
echo m68k-apple-netbsd${UNAME_RELEASE}
exit 0 ;;
mac68k:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
mvme68k:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
mvme88k:OpenBSD:*:*)
echo m88k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
powerpc:machten:*:*)
echo powerpc-apple-machten${UNAME_RELEASE}
exit 0 ;;
macppc:NetBSD:*:*)
echo powerpc-apple-netbsd${UNAME_RELEASE}
exit 0 ;;
RISC*:Mach:*:*)
echo mips-dec-mach_bsd4.3
exit 0 ;;
RISC*:ULTRIX:*:*)
echo mips-dec-ultrix${UNAME_RELEASE}
exit 0 ;;
VAX*:ULTRIX*:*:*)
echo vax-dec-ultrix${UNAME_RELEASE}
exit 0 ;;
2020:CLIX:*:*)
echo clipper-intergraph-clix${UNAME_RELEASE}
exit 0 ;;
mips:*:*:UMIPS | mips:*:*:RISCos)
sed 's/^ //' << EOF >dummy.c
int main (argc, argv) int argc; char **argv; {
#if defined (host_mips) && defined (MIPSEB)
#if defined (SYSTYPE_SYSV)
printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
#endif
#if defined (SYSTYPE_SVR4)
printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
#endif
#if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
#endif
#endif
exit (-1);
}
EOF
${CC-cc} dummy.c -o dummy \
&& ./dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
&& rm dummy.c dummy && exit 0
rm -f dummy.c dummy
echo mips-mips-riscos${UNAME_RELEASE}
exit 0 ;;
Night_Hawk:Power_UNIX:*:*)
echo powerpc-harris-powerunix
exit 0 ;;
m88k:CX/UX:7*:*)
echo m88k-harris-cxux7
exit 0 ;;
m88k:*:4*:R4*)
echo m88k-motorola-sysv4
exit 0 ;;
m88k:*:3*:R3*)
echo m88k-motorola-sysv3
exit 0 ;;
AViiON:dgux:*:*)
# DG/UX returns AViiON for all architectures
UNAME_PROCESSOR=`/usr/bin/uname -p`
if [ $UNAME_PROCESSOR = mc88100 -o $UNAME_PROCESSOR = mc88110 ] ; then
if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx \
-o ${TARGET_BINARY_INTERFACE}x = x ] ; then
echo m88k-dg-dgux${UNAME_RELEASE}
else
echo m88k-dg-dguxbcs${UNAME_RELEASE}
fi
else echo i586-dg-dgux${UNAME_RELEASE}
fi
exit 0 ;;
M88*:DolphinOS:*:*) # DolphinOS (SVR3)
echo m88k-dolphin-sysv3
exit 0 ;;
M88*:*:R3*:*)
# Delta 88k system running SVR3
echo m88k-motorola-sysv3
exit 0 ;;
XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
echo m88k-tektronix-sysv3
exit 0 ;;
Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
echo m68k-tektronix-bsd
exit 0 ;;
*:IRIX*:*:*)
echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
exit 0 ;;
????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id
exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX '
i?86:AIX:*:*)
echo i386-ibm-aix
exit 0 ;;
*:AIX:2:3)
if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
sed 's/^ //' << EOF >dummy.c
#include <sys/systemcfg.h>
main()
{
if (!__power_pc())
exit(1);
puts("powerpc-ibm-aix3.2.5");
exit(0);
}
EOF
${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
echo rs6000-ibm-aix3.2.5
elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
echo rs6000-ibm-aix3.2.4
else
echo rs6000-ibm-aix3.2
fi
exit 0 ;;
*:AIX:*:4)
IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | head -1 | awk '{ print $1 }'`
if /usr/sbin/lsattr -EHl ${IBM_CPU_ID} | grep POWER >/dev/null 2>&1; then
IBM_ARCH=rs6000
else
IBM_ARCH=powerpc
fi
if [ -x /usr/bin/oslevel ] ; then
IBM_REV=`/usr/bin/oslevel`
else
IBM_REV=4.${UNAME_RELEASE}
fi
echo ${IBM_ARCH}-ibm-aix${IBM_REV}
exit 0 ;;
*:AIX:*:*)
echo rs6000-ibm-aix
exit 0 ;;
ibmrt:4.4BSD:*|romp-ibm:BSD:*)
echo romp-ibm-bsd4.4
exit 0 ;;
ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC NetBSD and
echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to
exit 0 ;; # report: romp-ibm BSD 4.3
*:BOSX:*:*)
echo rs6000-bull-bosx
exit 0 ;;
DPX/2?00:B.O.S.:*:*)
echo m68k-bull-sysv3
exit 0 ;;
9000/[34]??:4.3bsd:1.*:*)
echo m68k-hp-bsd
exit 0 ;;
hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
echo m68k-hp-bsd4.4
exit 0 ;;
9000/[34678]??:HP-UX:*:*)
case "${UNAME_MACHINE}" in
9000/31? ) HP_ARCH=m68000 ;;
9000/[34]?? ) HP_ARCH=m68k ;;
9000/6?? | 9000/7?? | 9000/80[24] | 9000/8?[13679] | 9000/892 )
sed 's/^ //' << EOF >dummy.c
#include <stdlib.h>
#include <unistd.h>
int main ()
{
#if defined(_SC_KERNEL_BITS)
long bits = sysconf(_SC_KERNEL_BITS);
#endif
long cpu = sysconf (_SC_CPU_VERSION);
switch (cpu)
{
case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
case CPU_PA_RISC2_0:
#if defined(_SC_KERNEL_BITS)
switch (bits)
{
case 64: puts ("hppa2.0w"); break;
case 32: puts ("hppa2.0n"); break;
default: puts ("hppa2.0"); break;
} break;
#else /* !defined(_SC_KERNEL_BITS) */
puts ("hppa2.0"); break;
#endif
default: puts ("hppa1.0"); break;
}
exit (0);
}
EOF
(${CC-cc} dummy.c -o dummy 2>/dev/null ) && HP_ARCH=`./dummy`
rm -f dummy.c dummy
esac
HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
echo ${HP_ARCH}-hp-hpux${HPUX_REV}
exit 0 ;;
3050*:HI-UX:*:*)
sed 's/^ //' << EOF >dummy.c
#include <unistd.h>
int
main ()
{
long cpu = sysconf (_SC_CPU_VERSION);
/* The order matters, because CPU_IS_HP_MC68K erroneously returns
true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct
results, however. */
if (CPU_IS_PA_RISC (cpu))
{
switch (cpu)
{
case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
default: puts ("hppa-hitachi-hiuxwe2"); break;
}
}
else if (CPU_IS_HP_MC68K (cpu))
puts ("m68k-hitachi-hiuxwe2");
else puts ("unknown-hitachi-hiuxwe2");
exit (0);
}
EOF
${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
echo unknown-hitachi-hiuxwe2
exit 0 ;;
9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
echo hppa1.1-hp-bsd
exit 0 ;;
9000/8??:4.3bsd:*:*)
echo hppa1.0-hp-bsd
exit 0 ;;
hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
echo hppa1.1-hp-osf
exit 0 ;;
hp8??:OSF1:*:*)
echo hppa1.0-hp-osf
exit 0 ;;
i?86:OSF1:*:*)
if [ -x /usr/sbin/sysversion ] ; then
echo ${UNAME_MACHINE}-unknown-osf1mk
else
echo ${UNAME_MACHINE}-unknown-osf1
fi
exit 0 ;;
parisc*:Lites*:*:*)
echo hppa1.1-hp-lites
exit 0 ;;
C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
echo c1-convex-bsd
exit 0 ;;
C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
if getsysinfo -f scalar_acc
then echo c32-convex-bsd
else echo c2-convex-bsd
fi
exit 0 ;;
C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
echo c34-convex-bsd
exit 0 ;;
C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
echo c38-convex-bsd
exit 0 ;;
C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
echo c4-convex-bsd
exit 0 ;;
CRAY*X-MP:*:*:*)
echo xmp-cray-unicos
exit 0 ;;
CRAY*Y-MP:*:*:*)
echo ymp-cray-unicos${UNAME_RELEASE}
exit 0 ;;
CRAY*[A-Z]90:*:*:*)
echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
-e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
exit 0 ;;
CRAY*TS:*:*:*)
echo t90-cray-unicos${UNAME_RELEASE}
exit 0 ;;
CRAY-2:*:*:*)
echo cray2-cray-unicos
exit 0 ;;
F300:UNIX_System_V:*:*)
FUJITSU_SYS=`uname -p | tr [A-Z] [a-z] | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
echo "f300-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit 0 ;;
F301:UNIX_System_V:*:*)
echo f301-fujitsu-uxpv`echo $UNAME_RELEASE | sed 's/ .*//'`
exit 0 ;;
hp3[0-9][05]:NetBSD:*:*)
echo m68k-hp-netbsd${UNAME_RELEASE}
exit 0 ;;
hp300:OpenBSD:*:*)
echo m68k-unknown-openbsd${UNAME_RELEASE}
exit 0 ;;
sparc*:BSD/OS:*:*)
echo sparc-unknown-bsdi${UNAME_RELEASE}
exit 0 ;;
i?86:BSD/386:*:* | *:BSD/OS:*:*)
echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
exit 0 ;;
*:FreeBSD:*:*)
echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
exit 0 ;;
*:NetBSD:*:*)
echo ${UNAME_MACHINE}-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
exit 0 ;;
*:OpenBSD:*:*)
echo ${UNAME_MACHINE}-unknown-openbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
exit 0 ;;
i*:CYGWIN*:*)
echo ${UNAME_MACHINE}-pc-cygwin
exit 0 ;;
i*:MINGW*:*)
echo ${UNAME_MACHINE}-pc-mingw32
exit 0 ;;
p*:CYGWIN*:*)
echo powerpcle-unknown-cygwin
exit 0 ;;
prep*:SunOS:5.*:*)
echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
*:GNU:*:*)
echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
exit 0 ;;
*:Linux:*:*)
# uname on the ARM produces all sorts of strangeness, and we need to
# filter it out.
case "$UNAME_MACHINE" in
arm* | sa110*) UNAME_MACHINE="arm" ;;
esac
# The BFD linker knows what the default object file format is, so
# first see if it will tell us.
ld_help_string=`ld --help 2>&1`
ld_supported_emulations=`echo $ld_help_string \
| sed -ne '/supported emulations:/!d
s/[ ][ ]*/ /g
s/.*supported emulations: *//
s/ .*//
p'`
case "$ld_supported_emulations" in
i?86linux) echo "${UNAME_MACHINE}-pc-linux-gnuaout" ; exit 0 ;;
i?86coff) echo "${UNAME_MACHINE}-pc-linux-gnucoff" ; exit 0 ;;
sparclinux) echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 ;;
armlinux) echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 ;;
m68klinux) echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 ;;
elf32ppc) echo "powerpc-unknown-linux-gnu" ; exit 0 ;;
esac
if test "${UNAME_MACHINE}" = "alpha" ; then
sed 's/^ //' <<EOF >dummy.s
.globl main
.ent main
main:
.frame \$30,0,\$26,0
.prologue 0
.long 0x47e03d80 # implver $0
lda \$2,259
.long 0x47e20c21 # amask $2,$1
srl \$1,8,\$2
sll \$2,2,\$2
sll \$0,3,\$0
addl \$1,\$0,\$0
addl \$2,\$0,\$0
ret \$31,(\$26),1
.end main
EOF
LIBC=""
${CC-cc} dummy.s -o dummy 2>/dev/null
if test "$?" = 0 ; then
./dummy
case "$?" in
7)
UNAME_MACHINE="alpha"
;;
15)
UNAME_MACHINE="alphaev5"
;;
14)
UNAME_MACHINE="alphaev56"
;;
10)
UNAME_MACHINE="alphapca56"
;;
16)
UNAME_MACHINE="alphaev6"
;;
esac
objdump --private-headers dummy | \
grep ld.so.1 > /dev/null
if test "$?" = 0 ; then
LIBC="libc1"
fi
fi
rm -f dummy.s dummy
echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} ; exit 0
elif test "${UNAME_MACHINE}" = "mips" ; then
cat >dummy.c <<EOF
main(argc, argv)
int argc;
char *argv[];
{
#ifdef __MIPSEB__
printf ("%s-unknown-linux-gnu\n", argv[1]);
#endif
#ifdef __MIPSEL__
printf ("%sel-unknown-linux-gnu\n", argv[1]);
#endif
return 0;
}
EOF
${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy "${UNAME_MACHINE}" && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
else
# Either a pre-BFD a.out linker (linux-gnuoldld)
# or one that does not give us useful --help.
# GCC wants to distinguish between linux-gnuoldld and linux-gnuaout.
# If ld does not provide *any* "supported emulations:"
# that means it is gnuoldld.
echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations:"
test $? != 0 && echo "${UNAME_MACHINE}-pc-linux-gnuoldld" && exit 0
case "${UNAME_MACHINE}" in
i?86)
VENDOR=pc;
;;
*)
VENDOR=unknown;
;;
esac
# Determine whether the default compiler is a.out or elf
cat >dummy.c <<EOF
#include <features.h>
main(argc, argv)
int argc;
char *argv[];
{
#ifdef __ELF__
# ifdef __GLIBC__
# if __GLIBC__ >= 2
printf ("%s-${VENDOR}-linux-gnu\n", argv[1]);
# else
printf ("%s-${VENDOR}-linux-gnulibc1\n", argv[1]);
# endif
# else
printf ("%s-${VENDOR}-linux-gnulibc1\n", argv[1]);
# endif
#else
printf ("%s-${VENDOR}-linux-gnuaout\n", argv[1]);
#endif
return 0;
}
EOF
${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy "${UNAME_MACHINE}" && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
fi ;;
# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. earlier versions
# are messed up and put the nodename in both sysname and nodename.
i?86:DYNIX/ptx:4*:*)
echo i386-sequent-sysv4
exit 0 ;;
i?86:UNIX_SV:4.2MP:2.*)
# Unixware is an offshoot of SVR4, but it has its own version
# number series starting with 2...
# I am not positive that other SVR4 systems won't match this,
# I just have to hope. -- rms.
# Use sysv4.2uw... so that sysv4* matches it.
echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
exit 0 ;;
i?86:*:4.*:* | i?86:SYSTEM_V:4.*:*)
if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
echo ${UNAME_MACHINE}-univel-sysv${UNAME_RELEASE}
else
echo ${UNAME_MACHINE}-pc-sysv${UNAME_RELEASE}
fi
exit 0 ;;
i?86:*:3.2:*)
if test -f /usr/options/cb.name; then
UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
elif /bin/uname -X 2>/dev/null >/dev/null ; then
UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')`
(/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486
(/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \
&& UNAME_MACHINE=i586
echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
else
echo ${UNAME_MACHINE}-pc-sysv32
fi
exit 0 ;;
i?86:UnixWare:*:*)
if /bin/uname -X 2>/dev/null >/dev/null ; then
(/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \
&& UNAME_MACHINE=i586
fi
echo ${UNAME_MACHINE}-unixware-${UNAME_RELEASE}-${UNAME_VERSION}
exit 0 ;;
pc:*:*:*)
# uname -m prints for DJGPP always 'pc', but it prints nothing about
# the processor, so we play safe by assuming i386.
echo i386-pc-msdosdjgpp
exit 0 ;;
Intel:Mach:3*:*)
echo i386-pc-mach3
exit 0 ;;
paragon:*:*:*)
echo i860-intel-osf1
exit 0 ;;
i860:*:4.*:*) # i860-SVR4
if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
else # Add other i860-SVR4 vendors below as they are discovered.
echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4
fi
exit 0 ;;
mini*:CTIX:SYS*5:*)
# "miniframe"
echo m68010-convergent-sysv
exit 0 ;;
M68*:*:R3V[567]*:*)
test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
3[34]??:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 4850:*:4.0:3.0)
OS_REL=''
test -r /etc/.relid \
&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& echo i486-ncr-sysv4.3${OS_REL} && exit 0
/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
&& echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;;
3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& echo i486-ncr-sysv4 && exit 0 ;;
m68*:LynxOS:2.*:*)
echo m68k-unknown-lynxos${UNAME_RELEASE}
exit 0 ;;
mc68030:UNIX_System_V:4.*:*)
echo m68k-atari-sysv4
exit 0 ;;
i?86:LynxOS:2.*:*)
echo i386-unknown-lynxos${UNAME_RELEASE}
exit 0 ;;
TSUNAMI:LynxOS:2.*:*)
echo sparc-unknown-lynxos${UNAME_RELEASE}
exit 0 ;;
rs6000:LynxOS:2.*:* | PowerPC:LynxOS:2.*:*)
echo rs6000-unknown-lynxos${UNAME_RELEASE}
exit 0 ;;
SM[BE]S:UNIX_SV:*:*)
echo mips-dde-sysv${UNAME_RELEASE}
exit 0 ;;
RM*:SINIX-*:*:*)
echo mips-sni-sysv4
exit 0 ;;
*:SINIX-*:*:*)
if uname -p 2>/dev/null >/dev/null ; then
UNAME_MACHINE=`(uname -p) 2>/dev/null`
echo ${UNAME_MACHINE}-sni-sysv4
else
echo ns32k-sni-sysv
fi
exit 0 ;;
PENTIUM:CPunix:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
# says <Richard.M.Bartel@ccMail.Census.GOV>
echo i586-unisys-sysv4
exit 0 ;;
*:UNIX_System_V:4*:FTX*)
# From Gerald Hewes <hewes@openmarket.com>.
# How about differentiating between stratus architectures? -djm
echo hppa1.1-stratus-sysv4
exit 0 ;;
*:*:*:FTX*)
# From seanf@swdc.stratus.com.
echo i860-stratus-sysv4
exit 0 ;;
mc68*:A/UX:*:*)
echo m68k-apple-aux${UNAME_RELEASE}
exit 0 ;;
news*:NEWS-OS:*:6*)
echo mips-sony-newsos6
exit 0 ;;
R3000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R4000:UNIX_SV:*:*)
if [ -d /usr/nec ]; then
echo mips-nec-sysv${UNAME_RELEASE}
else
echo mips-unknown-sysv${UNAME_RELEASE}
fi
exit 0 ;;
BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only.
echo powerpc-be-beos
exit 0 ;;
BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only.
echo powerpc-apple-beos
exit 0 ;;
BePC:BeOS:*:*) # BeOS running on Intel PC compatible.
echo i586-pc-beos
exit 0 ;;
esac
#echo '(No uname command or uname output not recognized.)' 1>&2
#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
cat >dummy.c <<EOF
#ifdef _SEQUENT_
# include <sys/types.h>
# include <sys/utsname.h>
#endif
main ()
{
#if defined (sony)
#if defined (MIPSEB)
/* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed,
I don't know.... */
printf ("mips-sony-bsd\n"); exit (0);
#else
#include <sys/param.h>
printf ("m68k-sony-newsos%s\n",
#ifdef NEWSOS4
"4"
#else
""
#endif
); exit (0);
#endif
#endif
#if defined (__arm) && defined (__acorn) && defined (__unix)
printf ("arm-acorn-riscix"); exit (0);
#endif
#if defined (hp300) && !defined (hpux)
printf ("m68k-hp-bsd\n"); exit (0);
#endif
#if defined (NeXT)
#if !defined (__ARCHITECTURE__)
#define __ARCHITECTURE__ "m68k"
#endif
int version;
version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
exit (0);
#endif
#if defined (MULTIMAX) || defined (n16)
#if defined (UMAXV)
printf ("ns32k-encore-sysv\n"); exit (0);
#else
#if defined (CMU)
printf ("ns32k-encore-mach\n"); exit (0);
#else
printf ("ns32k-encore-bsd\n"); exit (0);
#endif
#endif
#endif
#if defined (__386BSD__)
printf ("i386-pc-bsd\n"); exit (0);
#endif
#if defined (sequent)
#if defined (i386)
printf ("i386-sequent-dynix\n"); exit (0);
#endif
#if defined (ns32000)
printf ("ns32k-sequent-dynix\n"); exit (0);
#endif
#endif
#if defined (_SEQUENT_)
struct utsname un;
uname(&un);
if (strncmp(un.version, "V2", 2) == 0) {
printf ("i386-sequent-ptx2\n"); exit (0);
}
if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
printf ("i386-sequent-ptx1\n"); exit (0);
}
printf ("i386-sequent-ptx\n"); exit (0);
#endif
#if defined (vax)
#if !defined (ultrix)
printf ("vax-dec-bsd\n"); exit (0);
#else
printf ("vax-dec-ultrix\n"); exit (0);
#endif
#endif
#if defined (alliant) && defined (i860)
printf ("i860-alliant-bsd\n"); exit (0);
#endif
exit (1);
}
EOF
${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
# Apollos put the system type in the environment.
test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; }
# Convex versions that predate uname can use getsysinfo(1)
if [ -x /usr/convex/getsysinfo ]
then
case `getsysinfo -f cpu_type` in
c1*)
echo c1-convex-bsd
exit 0 ;;
c2*)
if getsysinfo -f scalar_acc
then echo c32-convex-bsd
else echo c2-convex-bsd
fi
exit 0 ;;
c34*)
echo c34-convex-bsd
exit 0 ;;
c38*)
echo c38-convex-bsd
exit 0 ;;
c4*)
echo c4-convex-bsd
exit 0 ;;
esac
fi
#echo '(Unable to guess system type)' 1>&2
exit 1
+1011
View File
File diff suppressed because it is too large Load Diff
Vendored Executable
+955
View File
@@ -0,0 +1,955 @@
#! /bin/sh
# Configuration validation subroutine script, version 1.1.
# Copyright (C) 1991, 92-97, 1998 Free Software Foundation, Inc.
# This file is (in principle) common to ALL GNU software.
# The presence of a machine in this file suggests that SOME GNU software
# can handle that machine. It does not imply ALL GNU software can.
#
# This file 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 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Configuration subroutine to validate and canonicalize a configuration type.
# Supply the specified configuration type as an argument.
# If it is invalid, we print an error message on stderr and exit with code 1.
# Otherwise, we print the canonical config type on stdout and succeed.
# This file is supposed to be the same for all GNU packages
# and recognize all the CPU types, system types and aliases
# that are meaningful with *any* GNU software.
# Each package is responsible for reporting which valid configurations
# it does not support. The user should be able to distinguish
# a failure to support a valid configuration from a meaningless
# configuration.
# The goal of this file is to map all the various variations of a given
# machine specification into a single specification in the form:
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
# or in some cases, the newer four-part form:
# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
# It is wrong to echo any other type of specification.
if [ x$1 = x ]
then
echo Configuration name missing. 1>&2
echo "Usage: $0 CPU-MFR-OPSYS" 1>&2
echo "or $0 ALIAS" 1>&2
echo where ALIAS is a recognized configuration type. 1>&2
exit 1
fi
# First pass through any local machine types.
case $1 in
*local*)
echo $1
exit 0
;;
*)
;;
esac
# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
# Here we must recognize all the valid KERNEL-OS combinations.
maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
case $maybe_os in
linux-gnu*)
os=-$maybe_os
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
;;
*)
basic_machine=`echo $1 | sed 's/-[^-]*$//'`
if [ $basic_machine != $1 ]
then os=`echo $1 | sed 's/.*-/-/'`
else os=; fi
;;
esac
### Let's recognize common machines as not being operating systems so
### that things like config.sub decstation-3100 work. We also
### recognize some manufacturers as not being operating systems, so we
### can provide default operating systems below.
case $os in
-sun*os*)
# Prevent following clause from handling this invalid input.
;;
-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
-apple)
os=
basic_machine=$1
;;
-hiux*)
os=-hiuxwe2
;;
-sco5)
os=sco3.2v5
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco4)
os=-sco3.2v4
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco3.2.[4-9]*)
os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco3.2v[4-9]*)
# Don't forget version if it is 3.2v4 or newer.
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco*)
os=-sco3.2v2
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-isc)
os=-isc2.2
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-clix*)
basic_machine=clipper-intergraph
;;
-isc*)
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-lynx*)
os=-lynxos
;;
-ptx*)
basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
;;
-windowsnt*)
os=`echo $os | sed -e 's/windowsnt/winnt/'`
;;
-psos*)
os=-psos
;;
esac
# Decode aliases for certain CPU-COMPANY combinations.
case $basic_machine in
# Recognize the basic CPU types without company name.
# Some are omitted here because they have special meanings below.
tahoe | i860 | m32r | m68k | m68000 | m88k | ns32k | arc | arm \
| arme[lb] | pyramid | mn10200 | mn10300 | tron | a29k \
| 580 | i960 | h8300 | hppa | hppa1.0 | hppa1.1 | hppa2.0 \
| alpha | alphaev5 | alphaev56 | we32k | ns16k | clipper \
| i370 | sh | powerpc | powerpcle | 1750a | dsp16xx | pdp11 \
| mips64 | mipsel | mips64el | mips64orion | mips64orionel \
| mipstx39 | mipstx39el \
| sparc | sparclet | sparclite | sparc64 | v850)
basic_machine=$basic_machine-unknown
;;
# We use `pc' rather than `unknown'
# because (1) that's what they normally are, and
# (2) the word "unknown" tends to confuse beginning users.
i[34567]86)
basic_machine=$basic_machine-pc
;;
# Object if more than one company name word.
*-*-*)
echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
exit 1
;;
# Recognize the basic CPU types with company name.
vax-* | tahoe-* | i[34567]86-* | i860-* | m32r-* | m68k-* | m68000-* \
| m88k-* | sparc-* | ns32k-* | fx80-* | arc-* | arm-* | c[123]* \
| mips-* | pyramid-* | tron-* | a29k-* | romp-* | rs6000-* \
| power-* | none-* | 580-* | cray2-* | h8300-* | i960-* \
| xmp-* | ymp-* | hppa-* | hppa1.0-* | hppa1.1-* | hppa2.0-* \
| alpha-* | alphaev5-* | alphaev56-* | we32k-* | cydra-* \
| ns16k-* | pn-* | np1-* | xps100-* | clipper-* | orion-* \
| sparclite-* | pdp11-* | sh-* | powerpc-* | powerpcle-* \
| sparc64-* | mips64-* | mipsel-* \
| mips64el-* | mips64orion-* | mips64orionel-* \
| mipstx39-* | mipstx39el-* \
| f301-*)
;;
# Recognize the various machine names and aliases which stand
# for a CPU type and a company and sometimes even an OS.
3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
basic_machine=m68000-att
;;
3b*)
basic_machine=we32k-att
;;
alliant | fx80)
basic_machine=fx80-alliant
;;
altos | altos3068)
basic_machine=m68k-altos
;;
am29k)
basic_machine=a29k-none
os=-bsd
;;
amdahl)
basic_machine=580-amdahl
os=-sysv
;;
amiga | amiga-*)
basic_machine=m68k-cbm
;;
amigaos | amigados)
basic_machine=m68k-cbm
os=-amigaos
;;
amigaunix | amix)
basic_machine=m68k-cbm
os=-sysv4
;;
apollo68)
basic_machine=m68k-apollo
os=-sysv
;;
aux)
basic_machine=m68k-apple
os=-aux
;;
balance)
basic_machine=ns32k-sequent
os=-dynix
;;
convex-c1)
basic_machine=c1-convex
os=-bsd
;;
convex-c2)
basic_machine=c2-convex
os=-bsd
;;
convex-c32)
basic_machine=c32-convex
os=-bsd
;;
convex-c34)
basic_machine=c34-convex
os=-bsd
;;
convex-c38)
basic_machine=c38-convex
os=-bsd
;;
cray | ymp)
basic_machine=ymp-cray
os=-unicos
;;
cray2)
basic_machine=cray2-cray
os=-unicos
;;
[ctj]90-cray)
basic_machine=c90-cray
os=-unicos
;;
crds | unos)
basic_machine=m68k-crds
;;
da30 | da30-*)
basic_machine=m68k-da30
;;
decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
basic_machine=mips-dec
;;
delta | 3300 | motorola-3300 | motorola-delta \
| 3300-motorola | delta-motorola)
basic_machine=m68k-motorola
;;
delta88)
basic_machine=m88k-motorola
os=-sysv3
;;
dpx20 | dpx20-*)
basic_machine=rs6000-bull
os=-bosx
;;
dpx2* | dpx2*-bull)
basic_machine=m68k-bull
os=-sysv3
;;
ebmon29k)
basic_machine=a29k-amd
os=-ebmon
;;
elxsi)
basic_machine=elxsi-elxsi
os=-bsd
;;
encore | umax | mmax)
basic_machine=ns32k-encore
;;
fx2800)
basic_machine=i860-alliant
;;
genix)
basic_machine=ns32k-ns
;;
gmicro)
basic_machine=tron-gmicro
os=-sysv
;;
h3050r* | hiux*)
basic_machine=hppa1.1-hitachi
os=-hiuxwe2
;;
h8300hms)
basic_machine=h8300-hitachi
os=-hms
;;
harris)
basic_machine=m88k-harris
os=-sysv3
;;
hp300-*)
basic_machine=m68k-hp
;;
hp300bsd)
basic_machine=m68k-hp
os=-bsd
;;
hp300hpux)
basic_machine=m68k-hp
os=-hpux
;;
hp9k2[0-9][0-9] | hp9k31[0-9])
basic_machine=m68000-hp
;;
hp9k3[2-9][0-9])
basic_machine=m68k-hp
;;
hp9k7[0-9][0-9] | hp7[0-9][0-9] | hp9k8[0-9]7 | hp8[0-9]7)
basic_machine=hppa1.1-hp
;;
hp9k8[0-9][0-9] | hp8[0-9][0-9])
basic_machine=hppa1.0-hp
;;
hppa-next)
os=-nextstep3
;;
i370-ibm* | ibm*)
basic_machine=i370-ibm
os=-mvs
;;
# I'm not sure what "Sysv32" means. Should this be sysv3.2?
i[34567]86v32)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-sysv32
;;
i[34567]86v4*)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-sysv4
;;
i[34567]86v)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-sysv
;;
i[34567]86sol2)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-solaris2
;;
iris | iris4d)
basic_machine=mips-sgi
case $os in
-irix*)
;;
*)
os=-irix4
;;
esac
;;
isi68 | isi)
basic_machine=m68k-isi
os=-sysv
;;
m88k-omron*)
basic_machine=m88k-omron
;;
magnum | m3230)
basic_machine=mips-mips
os=-sysv
;;
merlin)
basic_machine=ns32k-utek
os=-sysv
;;
miniframe)
basic_machine=m68000-convergent
;;
mipsel*-linux*)
basic_machine=mipsel-unknown
os=-linux-gnu
;;
mips*-linux*)
basic_machine=mips-unknown
os=-linux-gnu
;;
mips3*-*)
basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
;;
mips3*)
basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
;;
ncr3000)
basic_machine=i486-ncr
os=-sysv4
;;
news | news700 | news800 | news900)
basic_machine=m68k-sony
os=-newsos
;;
news1000)
basic_machine=m68030-sony
os=-newsos
;;
news-3600 | risc-news)
basic_machine=mips-sony
os=-newsos
;;
next | m*-next )
basic_machine=m68k-next
case $os in
-nextstep* )
;;
-ns2*)
os=-nextstep2
;;
*)
os=-nextstep3
;;
esac
;;
nh3000)
basic_machine=m68k-harris
os=-cxux
;;
nh[45]000)
basic_machine=m88k-harris
os=-cxux
;;
nindy960)
basic_machine=i960-intel
os=-nindy
;;
np1)
basic_machine=np1-gould
;;
pa-hitachi)
basic_machine=hppa1.1-hitachi
os=-hiuxwe2
;;
paragon)
basic_machine=i860-intel
os=-osf
;;
pbd)
basic_machine=sparc-tti
;;
pbb)
basic_machine=m68k-tti
;;
pc532 | pc532-*)
basic_machine=ns32k-pc532
;;
pentium | p5 | k5 | nexen)
basic_machine=i586-pc
;;
pentiumpro | p6 | k6 | 6x86)
basic_machine=i686-pc
;;
pentiumii | pentium2)
basic_machine=i786-pc
;;
pentium-* | p5-* | k5-* | nexen-*)
basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentiumpro-* | p6-* | k6-* | 6x86-*)
basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentiumii-* | pentium2-*)
basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pn)
basic_machine=pn-gould
;;
power) basic_machine=rs6000-ibm
;;
ppc) basic_machine=powerpc-unknown
;;
ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ppcle | powerpclittle | ppc-le | powerpc-little)
basic_machine=powerpcle-unknown
;;
ppcle-* | powerpclittle-*)
basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ps2)
basic_machine=i386-ibm
;;
rm[46]00)
basic_machine=mips-siemens
;;
rtpc | rtpc-*)
basic_machine=romp-ibm
;;
sequent)
basic_machine=i386-sequent
;;
sh)
basic_machine=sh-hitachi
os=-hms
;;
sps7)
basic_machine=m68k-bull
os=-sysv2
;;
spur)
basic_machine=spur-unknown
;;
sun2)
basic_machine=m68000-sun
;;
sun2os3)
basic_machine=m68000-sun
os=-sunos3
;;
sun2os4)
basic_machine=m68000-sun
os=-sunos4
;;
sun3os3)
basic_machine=m68k-sun
os=-sunos3
;;
sun3os4)
basic_machine=m68k-sun
os=-sunos4
;;
sun4os3)
basic_machine=sparc-sun
os=-sunos3
;;
sun4os4)
basic_machine=sparc-sun
os=-sunos4
;;
sun4sol2)
basic_machine=sparc-sun
os=-solaris2
;;
sun3 | sun3-*)
basic_machine=m68k-sun
;;
sun4)
basic_machine=sparc-sun
;;
sun386 | sun386i | roadrunner)
basic_machine=i386-sun
;;
symmetry)
basic_machine=i386-sequent
os=-dynix
;;
tx39)
basic_machine=mipstx39-unknown
;;
tx39el)
basic_machine=mipstx39el-unknown
;;
tower | tower-32)
basic_machine=m68k-ncr
;;
udi29k)
basic_machine=a29k-amd
os=-udi
;;
ultra3)
basic_machine=a29k-nyu
os=-sym1
;;
vaxv)
basic_machine=vax-dec
os=-sysv
;;
vms)
basic_machine=vax-dec
os=-vms
;;
vpp*|vx|vx-*)
basic_machine=f301-fujitsu
;;
vxworks960)
basic_machine=i960-wrs
os=-vxworks
;;
vxworks68)
basic_machine=m68k-wrs
os=-vxworks
;;
vxworks29k)
basic_machine=a29k-wrs
os=-vxworks
;;
xmp)
basic_machine=xmp-cray
os=-unicos
;;
xps | xps100)
basic_machine=xps100-honeywell
;;
none)
basic_machine=none-none
os=-none
;;
# Here we handle the default manufacturer of certain CPU types. It is in
# some cases the only manufacturer, in others, it is the most popular.
mips)
if [ x$os = x-linux-gnu ]; then
basic_machine=mips-unknown
else
basic_machine=mips-mips
fi
;;
romp)
basic_machine=romp-ibm
;;
rs6000)
basic_machine=rs6000-ibm
;;
vax)
basic_machine=vax-dec
;;
pdp11)
basic_machine=pdp11-dec
;;
we32k)
basic_machine=we32k-att
;;
sparc)
basic_machine=sparc-sun
;;
cydra)
basic_machine=cydra-cydrome
;;
orion)
basic_machine=orion-highlevel
;;
orion105)
basic_machine=clipper-highlevel
;;
*)
echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
exit 1
;;
esac
# Here we canonicalize certain aliases for manufacturers.
case $basic_machine in
*-digital*)
basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
;;
*-commodore*)
basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
;;
*)
;;
esac
# Decode manufacturer-specific aliases for certain operating systems.
if [ x"$os" != x"" ]
then
case $os in
# First match some system type aliases
# that might get confused with valid system types.
# -solaris* is a basic system type, with this one exception.
-solaris1 | -solaris1.*)
os=`echo $os | sed -e 's|solaris1|sunos4|'`
;;
-solaris)
os=-solaris2
;;
-svr4*)
os=-sysv4
;;
-unixware*)
os=-sysv4.2uw
;;
-gnu/linux*)
os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
;;
# First accept the basic system types.
# The portable systems comes first.
# Each alternative MUST END IN A *, to match a version number.
# -sysv* is not here because it comes later, after sysvr4.
-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
| -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\
| -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
| -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
| -aos* \
| -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
| -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
| -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \
| -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* \
| -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
| -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
| -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
| -mingw32* | -linux-gnu* | -uxpv* | -beos*)
# Remember, each alternative MUST END IN *, to match a version number.
;;
-linux*)
os=`echo $os | sed -e 's|linux|linux-gnu|'`
;;
-sunos5*)
os=`echo $os | sed -e 's|sunos5|solaris2|'`
;;
-sunos6*)
os=`echo $os | sed -e 's|sunos6|solaris3|'`
;;
-osfrose*)
os=-osfrose
;;
-osf*)
os=-osf
;;
-utek*)
os=-bsd
;;
-dynix*)
os=-bsd
;;
-acis*)
os=-aos
;;
-ctix* | -uts*)
os=-sysv
;;
-ns2 )
os=-nextstep2
;;
# Preserve the version number of sinix5.
-sinix5.*)
os=`echo $os | sed -e 's|sinix|sysv|'`
;;
-sinix*)
os=-sysv4
;;
-triton*)
os=-sysv3
;;
-oss*)
os=-sysv3
;;
-svr4)
os=-sysv4
;;
-svr3)
os=-sysv3
;;
-sysvr4)
os=-sysv4
;;
# This must come after -sysvr4.
-sysv*)
;;
-xenix)
os=-xenix
;;
-none)
;;
*)
# Get rid of the `-' at the beginning of $os.
os=`echo $os | sed 's/[^-]*-//'`
echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
exit 1
;;
esac
else
# Here we handle the default operating systems that come with various machines.
# The value should be what the vendor currently ships out the door with their
# machine or put another way, the most popular os provided with the machine.
# Note that if you're going to try to match "-MANUFACTURER" here (say,
# "-sun"), then you have to tell the case statement up towards the top
# that MANUFACTURER isn't an operating system. Otherwise, code above
# will signal an error saying that MANUFACTURER isn't an operating
# system, and we'll never get to this point.
case $basic_machine in
*-acorn)
os=-riscix1.2
;;
arm*-semi)
os=-aout
;;
pdp11-*)
os=-none
;;
*-dec | vax-*)
os=-ultrix4.2
;;
m68*-apollo)
os=-domain
;;
i386-sun)
os=-sunos4.0.2
;;
m68000-sun)
os=-sunos3
# This also exists in the configure program, but was not the
# default.
# os=-sunos4
;;
*-tti) # must be before sparc entry or we get the wrong os.
os=-sysv3
;;
sparc-* | *-sun)
os=-sunos4.1.1
;;
*-be)
os=-beos
;;
*-ibm)
os=-aix
;;
*-hp)
os=-hpux
;;
*-hitachi)
os=-hiux
;;
i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
os=-sysv
;;
*-cbm)
os=-amigaos
;;
*-dg)
os=-dgux
;;
*-dolphin)
os=-sysv3
;;
m68k-ccur)
os=-rtu
;;
m88k-omron*)
os=-luna
;;
*-next )
os=-nextstep
;;
*-sequent)
os=-ptx
;;
*-crds)
os=-unos
;;
*-ns)
os=-genix
;;
i370-*)
os=-mvs
;;
*-next)
os=-nextstep3
;;
*-gould)
os=-sysv
;;
*-highlevel)
os=-bsd
;;
*-encore)
os=-bsd
;;
*-sgi)
os=-irix
;;
*-siemens)
os=-sysv4
;;
*-masscomp)
os=-rtu
;;
f301-fujitsu)
os=-uxpv
;;
*)
os=-none
;;
esac
fi
# Here we handle the case where we know the os, and the CPU type, but not the
# manufacturer. We pick the logical manufacturer.
vendor=unknown
case $basic_machine in
*-unknown)
case $os in
-riscix*)
vendor=acorn
;;
-sunos*)
vendor=sun
;;
-aix*)
vendor=ibm
;;
-hpux*)
vendor=hp
;;
-hiux*)
vendor=hitachi
;;
-unos*)
vendor=crds
;;
-dgux*)
vendor=dg
;;
-luna*)
vendor=omron
;;
-genix*)
vendor=ns
;;
-mvs*)
vendor=ibm
;;
-ptx*)
vendor=sequent
;;
-vxsim* | -vxworks*)
vendor=wrs
;;
-aux*)
vendor=apple
;;
esac
basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
;;
esac
echo $basic_machine$os
Vendored Executable
+7427
View File
File diff suppressed because it is too large Load Diff
+109
View File
@@ -0,0 +1,109 @@
dnl Process this file with autoconf to produce a configure script.
dnl
dnl $Id$
dnl
#AC_INIT(bforce/bforce.c)
AC_INIT([bforce],[0.22.8.ugenk2],[ugenk@tut.by])
AC_CONFIG_HEADER(include/config.h)
AC_CANONICAL_SYSTEM
dnl # Minimum Autoconf version required.
AC_PREREQ(2.50)
###############
# Setup version
###############
if [ test -f $srcdir/.version ]; then
AC_DEFINE_UNQUOTED(RELEASE_VERSION, "`cat $srcdir/.version`")
else
AC_DEFINE(RELEASE_VERSION, "?.?")
fi
###################
# Optional features
#
OWNER='uucp'
GROUP='news'
AC_ARG_WITH(owner, dnl
--with-owner=USER set possibility to run bforce from a USER (uucp),
)
AC_SUBST(OWNER)
AC_ARG_WITH(group, dnl
--with-group=GROUP set possibility to run bforce from a GROUP (news),
)
AC_SUBST(GROUP)
AC_ARG_ENABLE(debug, [ --enable-debug enable debugging support (default)],
[if test $enableval = yes; then
AC_DEFINE(DEBUG)
fi], [AC_DEFINE(DEBUG)])
AC_ARG_ENABLE(dcd-control, [ --enable-watch-cd enable DCD line control (default)],
[if test $enableval = yes; then
AC_DEFINE(MODEM_WATCH_CARRIER)
fi], [AC_DEFINE(MODEM_WATCH_CARRIER)])
AC_ARG_ENABLE(hangup-watch-cd, [ --enable-hangup-watch-cd hangup watchs for DCD line (default)],
[if test $enableval = yes; then
AC_DEFINE(MODEM_HANGUP_WATCH_CARRIER)
fi], [AC_DEFINE(MODEM_HANGUP_WATCH_CARRIER)])
AC_ARG_ENABLE(log-passwd, [ --enable-log-passwd write session password to log (default)],
[if test $enableval = yes; then
AC_DEFINE(BFORCE_LOG_PASSWD)
fi], [AC_DEFINE(BFORCE_LOG_PASSWD)])
AC_ARG_ENABLE(csy-locks, [ --enable-csy-locks use '.csy' locks while dialing (default)],
[if test $enableval = yes; then
AC_DEFINE(BFORCE_USE_CSY)
fi], [AC_DEFINE(BFORCE_USE_CSY)])
AC_ARG_WITH(uucp-lockdir, [ --with-uucp-lockdir specify directory for UUCP style locks],
[AC_DEFINE_UNQUOTED(BFORCE_LOCK_DIR, "$withval")],
[AC_MSG_CHECKING("UUCP lock files directory")
if test -d /var/lock/serial ; then
lockdir=/var/lock/serial/
elif test -d /var/spool/lock ; then
lockdir=/var/spool/lock/
else
lockdir=/var/lock/
fi
AC_DEFINE_UNQUOTED(BFORCE_LOCK_DIR, "$lockdir")
AC_MSG_RESULT("$lockdir")
])
dnl Checks for programs.
AC_PROG_YACC
AC_PROG_CC
AC_PROG_INSTALL
dnl Checks for libraries.
dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(fcntl.h sys/file.h sys/ioctl.h sys/time.h unistd.h)
AC_CHECK_HEADERS(termios.h sys/termiox.h sys/vfs.h sys/statfs.h sys/statvfs.h)
AC_CHECK_HEADERS(sys/select.h sys/param.h sys/mount.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_MODE_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
dnl Checks for library functions.
AC_FUNC_GETPGRP
AC_PROG_GCC_TRADITIONAL
AC_FUNC_SETVBUF_REVERSED
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(mkdir mktime select socket strspn strcasecmp)
AC_CHECK_FUNCS(rename statfs statvfs setproctitle)
AC_OUTPUT(Makefile)
AC_OUTPUT(../debian/Makefile)
+22
View File
@@ -0,0 +1,22 @@
/* Do you want debug code to be compiled? */
#undef DEBUG
/* Do you want use DCD line control? */
#undef MODEM_WATCH_CARRIER
/* Do you want hangup to watch for modem DCD line? */
#undef MODEM_HANGUP_WATCH_CARRIER
/* Version string */
#undef RELEASE_VERSION
/* Disable passwords logging? */
#undef BFORCE_LOG_PASSWD
/* Path to the UUCP lock files directory */
#undef BFORCE_LOCK_DIR
/* Do you want use .csy locks? */
#undef BFORCE_USE_CSY
+191
View File
@@ -0,0 +1,191 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _BFORCE_H_
#define _BFORCE_H_
#ifndef DAEMON_LOGFILE
#define DAEMON_LOGFILE "/var/log/bforce/bf-daemon"
#endif
#ifndef BFORCE_LOGFILE
#define BFORCE_LOGFILE "/var/log/bforce/bf-log"
#endif
#ifndef BFORCE_DEBFILE
#define BFORCE_DEBFILE "/var/log/bforce/bf-debug"
#endif
#ifndef BFORCE_CFGFILE
#define BFORCE_CFGFILE "/etc/bforce/bforce.conf"
#endif
/*
* BinkleyForce limits
*/
#define BF_MAXCFGLINE 512
#define BF_MAXREQLINE 256
#define BF_MAXPATH 256
#define BF_MAXDOMAIN 40
#define BF_MAXADDRSTR 80
/*
* Maximum length of file name (without path)
*/
#define BFORCE_MAX_NAME 128
/*
* Maximum path length, including file name length
*/
#define BFORCE_MAX_PATH 256
/*
* Maximum length of address string
*/
#define BFORCE_MAX_ADDRSTR 80
/*
* Lock files type:
* 1 - Ascii lock files
* 2 - Binary lock files
* 3 - SVR4 lock files (not implemented)
*/
#define BFORCE_LOCK_TYPE 1
/*
* Maximum length of phone number string
*/
#define BFORCE_MAX_PHONE 80
/*
* Maximum length of modem command string. Most modems
* cannot handle strings longer 40 characters.
*/
#define MODEM_MAX_COMMAND 120
/*
* Maximum length of modem response string
*/
#define MODEM_MAX_RESP 120
/*
* Maximum number of characters that modem can response
* on something command. Responses larger this will be
* considered invalid, and mailer will return "modem not
* response" without further waiting for "OK" or "ERROR"
*/
#define MODEM_MAX_RESP_SIZE 8128
/*
* BinkleyForce return codes
*/
#define BFERR_NOERROR 0
#define BFERR_FATALERROR 1
#define BFERR_PHONE_UNKNOWN 2
#define BFERR_PORTBUSY 3
#define BFERR_SYSTEM_LOCKED 4
#define BFERR_TRY_LATER 5
#define BFERR_NOMODEM 6
#define BFERR_NOTWORKING 7
#define BFERR_CANT_CONNECT10 10
#define BFERR_CANT_CONNECT11 11
#define BFERR_CANT_CONNECT12 12
#define BFERR_CANT_CONNECT13 13
#define BFERR_CANT_CONNECT14 14
#define BFERR_CANT_CONNECT15 15
#define BFERR_CANT_CONNECT16 16
#define BFERR_CANT_CONNECT17 17
#define BFERR_CANT_CONNECT18 18
#define BFERR_CANT_CONNECT19 19
#define BFERR_CONNECT_TOOLOW 20
#define BFERR_HANDSHAKE_ERROR 21
#define BFERR_XMITERROR 22
#define BFERR_CPSTOOLOW 23
#define BFERR_STOPTIME 24
#define BFERR_MAXERRNO 24 /* Maximal error number */
#define BFERR_NAME(rc) ((rc >= 0) && (rc <= BFERR_MAXERRNO) ? BFERR[rc] : "Out of range")
/*
* Some most popular defines
*/
#define gotoexit(a) { rc = a; goto exit; }
#ifdef __GNUC__
#define ASSERT_MSG() log("assertion failed: file: %s, line: %d, function: %s", \
__FILE__, __LINE__, __FUNCTION__);
#else
#define ASSERT_MSG() log("assertion failed: file: %s, line: %d", \
__FILE__, __LINE__);
#endif
#define ASSERT(expr) \
if( !(expr) ) \
{ \
ASSERT_MSG(); \
abort(); \
}
#define ISHEX(s) (strspn(s, "0123456790abcdefABCDEF") == strlen(s))
#define ISDEC(s) (strspn(s, "0123456789" ) == strlen(s))
#define ISOCT(s) (strspn(s, "01234567" ) == strlen(s))
/*
* Some usable defines
*/
#define FALSE 0
#define TRUE 1
#define UNDEF -1
/*
* Definition of new pretty types
*/
typedef char bool;
typedef unsigned long UINT32;
typedef unsigned short UINT16;
typedef unsigned char UINT8;
typedef signed long SINT32;
typedef signed short SINT16;
typedef signed char SINT8;
#include "confread.h"
/*
* Command line options
*/
typedef struct {
bool daemon; /* Run as daemon? */
bool quit; /* Quit from daemon */
bool dontcall; /* -m key */
int inetd; /* Called from inetd? */
int force; /* Force call? */
int hiddline; /* Hidden line number (0,1..) */
char *confname; /* Use this config instead def. */
char *incname; /* Include this config */
char *phone; /* Forced phone number */
char *iaddr; /* Forced IP address */
char *connect; /* Connect string */
char *device; /* Forced device name */
int stype; /* Handshake type in slave mode */
s_falist *addrlist;
} s_bforce_opts;
/*
* Global variables
*/
extern const char *BFERR[];
int daemon_run(const char *confname, const char *incname, bool quit);
#endif
+145
View File
@@ -0,0 +1,145 @@
/* include/config.h. Generated by configure. */
/* include/config.h.in. Generated automatically from configure.in by autoheader. */
/* Define to empty if the keyword does not work. */
/* #undef const */
/* Define if the `getpgrp' function takes no argument. */
#define GETPGRP_VOID 1
/* Define if you don't have vprintf but do have _doprnt. */
/* #undef HAVE_DOPRNT */
/* Define if you have <sys/wait.h> that is POSIX.1 compatible. */
#define HAVE_SYS_WAIT_H 1
/* Define if you have the vprintf function. */
#define HAVE_VPRINTF 1
/* Define to `int' if <sys/types.h> doesn't define. */
/* #undef mode_t */
/* Define to `int' if <sys/types.h> doesn't define. */
/* #undef pid_t */
/* Define as the return type of signal handlers (int or void). */
#define RETSIGTYPE void
/* Define if the setvbuf function takes the buffering type as its second
argument and the buffer pointer as the third, as on System V
before release 3. */
/* #undef SETVBUF_REVERSED */
/* Define to `unsigned' if <sys/types.h> doesn't define. */
/* #undef size_t */
/* Define if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1
/* Define if your <sys/time.h> declares struct tm. */
/* #undef TM_IN_SYS_TIME */
/* Do you want debug code to be compiled? */
#define DEBUG 1
/* Do you want use DCD line control? */
#define MODEM_WATCH_CARRIER 1
/* Do you want hangup to watch for modem DCD line? */
#define MODEM_HANGUP_WATCH_CARRIER 1
/* Version string */
#define RELEASE_VERSION "0.22.8.ugenk4"
/* Disable passwords logging? */
#define BFORCE_LOG_PASSWD 1
/* Path to the UUCP lock files directory */
#define BFORCE_LOCK_DIR "/var/lock/"
/* Do you want use .csy locks? */
#define BFORCE_USE_CSY 1
/* Define if you have the mkdir function. */
#define HAVE_MKDIR 1
/* Define if you have the mktime function. */
#define HAVE_MKTIME 1
/* Define if you have the rename function. */
#define HAVE_RENAME 1
/* Define if you have the select function. */
#define HAVE_SELECT 1
/* Define if you have the setproctitle function. */
/* #undef HAVE_SETPROCTITLE */
/* Define if you have the socket function. */
#define HAVE_SOCKET 1
/* Define if you have the statfs function. */
#define HAVE_STATFS 1
/* Define if you have the statvfs function. */
#define HAVE_STATVFS 1
/* Define if you have the strcasecmp function. */
#define HAVE_STRCASECMP 1
/* Define if you have the strspn function. */
#define HAVE_STRSPN 1
/* Define if you have the <dirent.h> header file. */
#define HAVE_DIRENT_H 1
/* Define if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define if you have the <ndir.h> header file. */
/* #undef HAVE_NDIR_H */
/* Define if you have the <sys/dir.h> header file. */
/* #undef HAVE_SYS_DIR_H */
/* Define if you have the <sys/file.h> header file. */
#define HAVE_SYS_FILE_H 1
/* Define if you have the <sys/ioctl.h> header file. */
#define HAVE_SYS_IOCTL_H 1
/* Define if you have the <sys/mount.h> header file. */
#define HAVE_SYS_MOUNT_H 1
/* Define if you have the <sys/ndir.h> header file. */
/* #undef HAVE_SYS_NDIR_H */
/* Define if you have the <sys/param.h> header file. */
#define HAVE_SYS_PARAM_H 1
/* Define if you have the <sys/select.h> header file. */
#define HAVE_SYS_SELECT_H 1
/* Define if you have the <sys/statfs.h> header file. */
#define HAVE_SYS_STATFS_H 1
/* Define if you have the <sys/statvfs.h> header file. */
#define HAVE_SYS_STATVFS_H 1
/* Define if you have the <sys/termiox.h> header file. */
/* #undef HAVE_SYS_TERMIOX_H */
/* Define if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define if you have the <sys/vfs.h> header file. */
#define HAVE_SYS_VFS_H 1
/* Define if you have the <termios.h> header file. */
#define HAVE_TERMIOS_H 1
/* Define if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
+144
View File
@@ -0,0 +1,144 @@
/* include/config.h.in. Generated automatically from configure.in by autoheader. */
/* Define to empty if the keyword does not work. */
#undef const
/* Define if the `getpgrp' function takes no argument. */
#undef GETPGRP_VOID
/* Define if you don't have vprintf but do have _doprnt. */
#undef HAVE_DOPRNT
/* Define if you have <sys/wait.h> that is POSIX.1 compatible. */
#undef HAVE_SYS_WAIT_H
/* Define if you have the vprintf function. */
#undef HAVE_VPRINTF
/* Define to `int' if <sys/types.h> doesn't define. */
#undef mode_t
/* Define to `int' if <sys/types.h> doesn't define. */
#undef pid_t
/* Define as the return type of signal handlers (int or void). */
#undef RETSIGTYPE
/* Define if the setvbuf function takes the buffering type as its second
argument and the buffer pointer as the third, as on System V
before release 3. */
#undef SETVBUF_REVERSED
/* Define to `unsigned' if <sys/types.h> doesn't define. */
#undef size_t
/* Define if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME
/* Define if your <sys/time.h> declares struct tm. */
#undef TM_IN_SYS_TIME
/* Do you want debug code to be compiled? */
#undef DEBUG
/* Do you want use DCD line control? */
#undef MODEM_WATCH_CARRIER
/* Do you want hangup to watch for modem DCD line? */
#undef MODEM_HANGUP_WATCH_CARRIER
/* Version string */
#undef RELEASE_VERSION
/* Disable passwords logging? */
#undef BFORCE_LOG_PASSWD
/* Path to the UUCP lock files directory */
#undef BFORCE_LOCK_DIR
/* Do you want use .csy locks? */
#undef BFORCE_USE_CSY
/* Define if you have the mkdir function. */
#undef HAVE_MKDIR
/* Define if you have the mktime function. */
#undef HAVE_MKTIME
/* Define if you have the rename function. */
#undef HAVE_RENAME
/* Define if you have the select function. */
#undef HAVE_SELECT
/* Define if you have the setproctitle function. */
#undef HAVE_SETPROCTITLE
/* Define if you have the socket function. */
#undef HAVE_SOCKET
/* Define if you have the statfs function. */
#undef HAVE_STATFS
/* Define if you have the statvfs function. */
#undef HAVE_STATVFS
/* Define if you have the strcasecmp function. */
#undef HAVE_STRCASECMP
/* Define if you have the strspn function. */
#undef HAVE_STRSPN
/* Define if you have the <dirent.h> header file. */
#undef HAVE_DIRENT_H
/* Define if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define if you have the <ndir.h> header file. */
#undef HAVE_NDIR_H
/* Define if you have the <sys/dir.h> header file. */
#undef HAVE_SYS_DIR_H
/* Define if you have the <sys/file.h> header file. */
#undef HAVE_SYS_FILE_H
/* Define if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H
/* Define if you have the <sys/mount.h> header file. */
#undef HAVE_SYS_MOUNT_H
/* Define if you have the <sys/ndir.h> header file. */
#undef HAVE_SYS_NDIR_H
/* Define if you have the <sys/param.h> header file. */
#undef HAVE_SYS_PARAM_H
/* Define if you have the <sys/select.h> header file. */
#undef HAVE_SYS_SELECT_H
/* Define if you have the <sys/statfs.h> header file. */
#undef HAVE_SYS_STATFS_H
/* Define if you have the <sys/statvfs.h> header file. */
#undef HAVE_SYS_STATVFS_H
/* Define if you have the <sys/termiox.h> header file. */
#undef HAVE_SYS_TERMIOX_H
/* Define if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define if you have the <sys/vfs.h> header file. */
#undef HAVE_SYS_VFS_H
/* Define if you have the <termios.h> header file. */
#undef HAVE_TERMIOS_H
/* Define if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
+363
View File
@@ -0,0 +1,363 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _CONFREAD_H_
#define _CONFREAD_H_
#include "util.h"
/* Constatnts for gotfile switches */
#define GOTFILE_SW_SRIF 0x01
#define GOTFILE_SW_IMMED 0x01
#define GOTFILE_SW_ONLINE 0x01
#define MAXINCLUDELEVEL 10
#define PROC_RC_OK 0 /* Successfully processed string */
#define PROC_RC_WARN 1 /* Successfully, but not all so good */
#define PROC_RC_IGNORE 2 /* Line was ignored, but we can continue */
#define PROC_RC_ABORT 3 /* Incorrect line and we can not continue */
/*
* Options (from/for "options" keyword)
*/
#define OPTIONS_NO_ZMODEM 0x00000001L
#define OPTIONS_NO_ZEDZAP 0x00000002L
#define OPTIONS_NO_DIRZAP 0x00000004L
#define OPTIONS_NO_JANUS 0x00000008L
#define OPTIONS_NO_HYDRA 0x00000010L
#define OPTIONS_NO_BINKP 0x00000020L
#define OPTIONS_NO_TCP 0x00000040L
#define OPTIONS_NO_CHAT 0x00000080L
#define OPTIONS_NO_FTS1 0x00000100L
#define OPTIONS_NO_YOOHOO 0x00000200L
#define OPTIONS_NO_EMSI 0x00000400L
#define OPTIONS_NO_EMSI_II 0x00000800L
#define OPTIONS_NO_FREQS 0x00001000L
#define OPTIONS_MAILONLY 0x00002000L
#define OPTIONS_HOLDXT 0x00004000L
#define OPTIONS_HOLDREQ 0x00008000L
#define OPTIONS_HOLDALL 0x00010000L
#define OPTIONS_HOLDHOLD 0x00020000L
#define OPTIONS_NO_PICKUP 0x00040000L
#define OPTIONS_NO_RH1 0x00080000L
#define OPTIONS_NO_INTRO 0x00100000L
#define RESPTYPE_CONNECT 0x0000L
#define RESPTYPE_BUSY 0x0001L
#define RESPTYPE_NOCARRIER 0x0002L
#define RESPTYPE_NODIALTONE 0x0004L
#define RESPTYPE_NOANSWER 0x0008L
#define RESPTYPE_ERROR 0x0010L
#define TRIES_ACTION_UNDIALABLE 0x01
#define TRIES_ACTION_HOLDSYSTEM 0x02
#define TRIES_ACTION_HOLDALL 0x04
/*
* Add new entry to the end of list
*/
#define LIST_NEWENT(newp,list,type) \
for( newp = list; *newp; newp = &((*newp)->next) ); \
*newp = (type*)xmalloc(sizeof(type)); \
memset(*newp, '\0', sizeof(type));
typedef struct expr {
bool error; /* Incorrect expression. Don't try twice! */
char *expr; /* Pointer to the expression string */
} s_expr;
/*
* Storage structures for base config components
*/
typedef struct string {
char *str;
} s_string;
typedef struct number {
long num;
} s_number;
typedef struct boolean {
bool istrue;
} s_boolean;
typedef struct falist {
s_faddr addr;
char *what;
struct falist *next;
} s_falist;
typedef struct domain {
char *domain;
char *path;
int zone;
} s_domain;
typedef struct translate {
char *find;
char *repl;
} s_translate;
typedef struct connlist {
long speed;
long value;
} s_connlist;
typedef struct dialresp {
char *mstr; /* Modem string/substring */
int type; /* Response meaning (for mailer) */
int retv; /* Force this return code */
} s_dialresp;
typedef struct filemode {
mode_t mode;
} s_filemode;
typedef struct modemport {
long speed;
char *name;
} s_modemport;
typedef struct tries {
int tries;
int action;
int arg;
} s_tries;
typedef struct override {
s_faddr addr; /* Overrides for this address */
char *sIpaddr;
char *sPhone;
char *sFlags;
s_timevec worktime;
s_timevec freqtime;
struct override *hidden; /* Hidden lines list */
} s_override;
typedef struct options {
unsigned long value;
unsigned long mask; /* bit[k] == 1 if bit[k] defined in value */
} s_options;
typedef struct filebox {
s_faddr addr;
char *path;
int flavor;
struct falist *next;
} s_filebox;
typedef enum {
cf_address,
cf_amiga_outbound_directory,
cf_binkp_timeout,
cf_daemon_circle,
cf_daemon_circle_crash,
cf_daemon_circle_direct,
cf_daemon_circle_immed,
cf_daemon_circle_modem,
cf_daemon_circle_normal,
cf_daemon_circle_rescan,
cf_daemon_maxclients_modem,
cf_daemon_maxclients_tcpip,
cf_daemon_pid_file,
cf_delay_files_recv,
cf_delay_files_send,
cf_disable_aka_matching,
cf_domain,
cf_emsi_FR_time,
cf_emsi_OH_time,
cf_emsi_slave_sends_nak,
cf_filebox,
cf_filebox_directory,
cf_flags,
cf_flo_translate,
cf_freq_alias_list,
cf_freq_dir_list,
cf_freq_ignore_masks,
cf_freq_limit_number,
cf_freq_limit_size,
cf_freq_limit_time,
cf_freq_min_speed,
cf_freq_srif_command,
cf_hide_our_aka,
cf_history_file,
cf_hydra_options,
cf_hydra_mincps_recv,
cf_hydra_mincps_send,
cf_hydra_tx_window,
cf_hydra_rx_window,
cf_inbound_directory,
cf_location,
cf_log_file,
cf_log_file_daemon,
cf_max_speed,
cf_maxtries,
cf_maxtries_nodial,
cf_maxtries_noansw,
cf_maxtries_noconn,
cf_maxtries_hshake,
cf_maxtries_sessions,
cf_min_cps_recv,
cf_min_cps_send,
cf_min_cps_time,
cf_min_free_space,
cf_min_speed_in,
cf_min_speed_out,
cf_mode_netmail,
cf_mode_arcmail,
cf_mode_request,
cf_mode_ticfile,
cf_mode_default,
cf_modem_can_send_break,
cf_modem_dial_prefix,
cf_modem_dial_suffix,
cf_modem_dial_response,
cf_modem_hangup_command,
cf_modem_port,
cf_modem_reset_command,
cf_modem_stat_command,
cf_nodelist,
cf_nodelist_directory,
cf_nodial_flag,
cf_override,
cf_options,
cf_outbound_directory,
cf_password,
cf_phone,
cf_phone_translate,
cf_recode_file_in,
cf_recode_file_out,
cf_recode_intro_in,
cf_recv_buffer_size,
cf_rescan_delay,
cf_run_after_handshake,
cf_run_after_session,
cf_session_limit_in,
cf_session_limit_out,
cf_skip_files_recv,
cf_status_directory,
cf_system_name,
cf_sysop_name,
cf_uucp_lock_directory,
cf_wait_carrier_in,
cf_wait_carrier_out,
cf_zmodem_mincps_recv,
cf_zmodem_mincps_send,
cf_zmodem_send_dummy_pkt,
cf_zmodem_skip_by_pos,
cf_zmodem_start_block_size,
cf_zmodem_tx_window,
cf_nomail_flag,
cf_bind_ip,
/* #ifdef USE_SYSLOG */
cf_syslog_facility,
/* #endif */
#ifdef DEBUG
cf_debug_file,
cf_debug_level,
#endif
BFORCE_NUMBER_OF_KEYWORDS
} bforce_config_keyword;
typedef struct cval_entry {
s_expr expr;
union {
s_falist falist;
s_domain domain;
s_override override;
s_options options;
s_translate translate;
s_connlist connlist;
s_number number;
s_boolean boolean;
s_string string;
s_modemport modemport;
s_dialresp dialresp;
s_tries tries;
s_filemode filemode;
s_filebox filebox;
} d;
struct cval_entry *next;
} s_cval_entry;
typedef struct conf_entry {
char *name;
enum {
CT_ADDRESS,
CT_BOOLEAN,
CT_CONNLIST,
CT_DIALRESP,
CT_DOMAIN,
CT_FILEMODE,
CT_MODEMPORT,
CT_NODELIST,
CT_NUMBER,
CT_OPTIONS,
CT_OVERRIDE,
CT_PATH,
CT_PASSWORD,
CT_STRING,
CT_TRANSLATE,
CT_TRIES,
CT_DEBLEVEL,
CT_FILEBOX
} type;
s_cval_entry *data;
bforce_config_keyword real_key;
} s_conf_entry;
extern s_conf_entry bforce_config[];
/* conf_proc.c */
int proc_configline(const char *k, const char *e, const char *v);
/* conf_deinit.c */
void deinit_conf(void);
void deinit_cval_entry(s_cval_entry *dest, bforce_config_keyword type);
void deinit_dialresp(s_dialresp *dest);
void deinit_domain(s_domain *dest);
void deinit_expr(s_expr *dest);
void deinit_falist(s_falist *dest);
void deinit_modemport(s_modemport *dest);
void deinit_override(s_override *dest);
void deinit_string(s_string *dest);
void deinit_translate(s_translate *dest);
/* conf_read.c */
const char *conf_getconfname(void);
int conf_postreadcheck(void);
int conf_readpasswdlist(s_falist **pwdlist, char *fname);
int conf_readconf(const char *confname, int inclevel);
#ifdef DEBUG
void log_overridelist(s_override *subst);
void log_options(s_options *opt);
#endif
/* conf_get.c */
s_cval_entry *conf_first(bforce_config_keyword keyword);
s_cval_entry *conf_next(s_cval_entry *ptrl);
bool conf_boolean(bforce_config_keyword keyword);
mode_t conf_filemode(bforce_config_keyword keyword);
long conf_options(bforce_config_keyword keyword);
long conf_connlist(bforce_config_keyword keyword, long speed);
char *conf_string(bforce_config_keyword keyword);
long conf_number(bforce_config_keyword keyword);
s_override *conf_override(bforce_config_keyword keyword, s_faddr addr);
s_tries *conf_tries(bforce_config_keyword keyword);
/* expression.y */
bool eventexpr(s_expr *expr);
#endif /* _CONFREAD_H_ */
+93
View File
@@ -0,0 +1,93 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _DAEMON_H_
#define _DAEMON_H_
#include "outbound.h"
/*
* Branch information
*/
typedef struct {
s_faddr addr;
bool tcpip;
char *portname;
bool wait; /* It is like a zombie! */
pid_t pid; /* Branch PID, returned by fork() call */
time_t start;
time_t stop; /* We should stop (kill) branch at this time */
int rc; /* Process return code (one of BFERR values) */
} s_daemon_branch;
/*
* Daemon queue sates
*/
typedef enum {
DQ_CallSystem,
DQ_GetNextSystem,
DQ_Idle
} DQ_State;
/*
* Daemon states
*/
typedef enum {
DM_Start,
DM_Restart,
DM_ProcessQueues,
DM_Usr1,
DM_Usr2,
DM_Shutdown
} DM_State;
/*
* Daemon queue
*/
typedef struct {
s_sysqueue *q; /* Pointer to the systems queue (shared) */
int current;
int circle;
bool tcpip; /* Queue for TCP/IP systems? */
DQ_State state;
} s_daemon_queue;
extern int max_tcpip;
extern int max_modem;
extern int tcpip_clients;
extern int modem_clients;
/* daemon.c */
int daemon_run(const char *confname, const char *incname, bool quit);
/* daemon_branch.c */
bool daemon_branch_exist(s_faddr addr);
void daemon_branch_check_stop_timers(void);
int daemon_branch_exit(pid_t pid, int rc);
int daemon_branch_get_first_waiting(void);
s_daemon_branch *daemon_branch_get_pointer(int pos);
void daemon_branch_add(s_faddr addr, pid_t pid, bool tcpip, const char *pname);
void daemon_branch_remove(int pos);
int daemon_branch_number(void);
void daemon_branch_deinit(void);
/* daemon_call.c */
int daemon_call(s_sysentry *syst);
/* daemon_lines.c */
int daemon_line_add(const char *name, int type);
void daemon_line_hold(const char *name, int holdtime);
bool daemon_line_isready(const char *name);
void daemon_lines_deinit(void);
#endif /* _DAEMON_H_ */
+70
View File
@@ -0,0 +1,70 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _FREQ_H_
#define _FREQ_H_
#include "session.h"
#include "outbound.h"
/*
* List of our available for FREQing resources
*/
typedef struct frlist {
struct frlist *next;
char *magic;
char *path;
char *passwd;
char *expr; /* process only if expression is true */
} s_frlist;
/*
* List of requested files (from requester)
*/
typedef struct reqlist {
struct reqlist *next;
char *fmask;
char *passwd;
time_t newer;
time_t older;
int skip;
} s_reqlist;
/*
* Keep all FREQ processor-important information here
*/
typedef struct freq {
char *srifproc; /* Name of external (SRIF) FREQ processor */
s_frlist *frlist; /* File areas list for int. FREQ processor */
s_reqlist *reqlist; /* List of requested file masks, etc.. */
s_filelist **filelist; /* Put here files we found and want to send */
s_filelist **flast; /* Pointer to the last entry in filelist */
int fnumber; /* Total number of files, we found */
int fileslimit; /* Maxmum number of files to send as answer */
size_t fsize; /* Total size of files, we found */
size_t sizelimit; /* Maxmum size of files to send as answer */
} s_freq;
/* req_bark.c */
/* req_proc.c */
void req_proc(char *reqname, s_filelist **filelist);
/* req_srif.c */
int req_createsrif(char *sname, char *req, char *rsp);
void req_addfilelist(char *listname, s_freq *freq);
/* req_wazo.c */
int req_readwazooreq(char *reqname, s_reqlist **reqlist);
#endif
+143
View File
@@ -0,0 +1,143 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _INCLUDES_H_
#define _INCLUDES_H_
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <errno.h>
#include <utime.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <ctype.h>
#include <locale.h>
#include <signal.h>
/*
* Has ANSI C headers?
*/
#ifdef STDC_HEADERS
# include <string.h>
# include <stdarg.h>
#else
# include <varargs.h>
#endif
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#ifndef WEXITSTATUS
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
#endif
#ifndef WIFEXITED
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_DIRENT_H
# include <dirent.h>
# define NAMLEN(dirent) strlen((dirent)->d_name)
#else
# define dirent direct
# define NAMLEN(dirent) (dirent)->d_namlen
# ifdef HAVE_NDIR_H
# include <ndir.h>
# endif
# ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif
# ifdef HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif
#endif
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h>
#endif
#ifdef HAVE_SYS_STATFS_H
#include <sys/statfs.h>
#endif
#ifdef HAVE_SYS_STATVFS_H
#include <sys/statvfs.h>
#endif
#ifdef HAVE_SYS_VFS_H
#include <sys/vfs.h>
#endif
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#elif HAVE_SYS_TIME
# include <sys/time.h>
#else
# include <time.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
#ifdef HAVE_SYS_TERMIOX_H
#include <sys/termiox.h>
#endif
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
/*
* Include OS dependent information
*/
#include "os.h"
/*
* Include version information
*/
#include "version.h"
/*
* Include main defines, constants
*/
#include "bforce.h"
#endif
+230
View File
@@ -0,0 +1,230 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _IO_H_
#define _IO_H_
typedef enum {
TCPMODE_RAW,
TCPMODE_TELNET,
TCPMODE_BINKP
} e_tcpmode;
extern int tty_online;
extern int tty_hangup;
extern int tty_abort;
extern int tty_modem;
extern int tty_status;
#define XON ('Q' & 037)
#define XOFF ('S' & 037)
#define CPMEOF ('Z' & 037)
#define NUL 0x00
#define SOH 0x01
#define STX 0x02
#define ETX 0x03
#define EOT 0x04
#define ENQ 0x05
#define ACK 0x06
#define BEL 0x07
#define BS 0x08
#define HT 0x09
#define LF 0x0a
#define VT 0x0b
#define FF 0x0c
#define CR 0x0d
#define SO 0x0e
#define SI 0x0f
#define DLE 0x10
#define DC1 0x11
#define DC2 0x12
#define DC3 0x13
#define DC4 0x14
#define NAK 0x15
#define SYN 0x16
#define ETB 0x17
#define CAN 0x18
#define EM 0x19
#define SUB 0x1a
#define ESC 0x1b
#define FS 0x1c
#define GS 0x1d
#define RS 0x1e
#define US 0x1f
#define TSYNC 0xae
#define YOOHOO 0xf1
/* DON'T CHANGE THIS VALUES! */
/* SOME DON'T USE MACROS */
#define TTY_SUCCESS 0
#define TTY_TIMEOUT -1
#define TTY_HANGUP -2
#define TTY_ERROR -3
#define XSELECT(a,b,c) tty_xselect(a, b, c)
#define WRITE(a,b) tty_write(a, b)
#define READ(a,b) tty_read(a, b)
#define WRITE_TIMEOUT(a,b) tty_write_timeout(a, b, 30)
#define READ_TIMEOUT(a,b,c) tty_read_timeout(a, b, c)
#define GETCHAR(a) tty_getc(a)
#define CHARWAIT(a) tty_charwait(a)
#define PUTCHAR(a) tty_putc(a, 30)
#define BUFCHAR(a) tty_bufc(a, 30)
#define PUTSTR(a) tty_puts(a, 30)
#define CLEARIN() tty_clearin()
#define CLEAROUT() tty_clearout()
#define FLUSHOUT() tty_flushout()
#define FLUSHBUF() tty_flushbuf(30)
#define DTRHIGH() tio_setdtr(0, TRUE)
#define DTRLOW() tio_setdtr(0, FALSE)
#define SENDBREAK() tio_sendbreak()
#define TTYRESET() \
{ \
tty_abort = 0; \
tty_status = TTY_SUCCESS; \
}
#define TTYSTATUS(a) \
{ \
tty_online = a; \
tty_hangup = 0; \
tty_abort = 0; \
tty_status = TTY_SUCCESS; \
}
/*
* io_unix_tty.c
*/
int tty_select(bool *rd, bool *wr, int timeout);
int tty_xselect(bool *rd, bool *wr, int timeout);
int tty_charwait(int timeout);
int tty_read(unsigned char *buf, size_t size);
int tty_read_timeout(unsigned char *buf, size_t size, int timeout);
int tty_write(const unsigned char *buf, size_t size);
int tty_write_timeout(const unsigned char *buf, size_t size, int timeout);
int tty_putc(unsigned char ch, int timeout);
int tty_puts(const unsigned char *s, int timeout);
int tty_getc(int timeout);
int tty_bufc(unsigned char ch, int timeout);
int tty_flushout(void);
int tty_flushbuf(int timeout);
int tty_clearin(void);
int tty_clearout(void);
const char *tty_errstr(int status);
/*
* io_unix_lock.c
*/
#define LOCKCHECK_NOLOCK 0
#define LOCKCHECK_LOCKED 1
#define LOCKCHECK_ERROR 2
#define LOCKCHECK_OURLOCK 3
int port_checklock(const char *lockdir, const s_modemport *modemport);
int port_lock(const char *lockdir, const s_modemport *modemport);
int port_unlock(const char *lockdir, const s_modemport *modemport);
/*
* io_unix_tio.c
*/
#ifdef HAVE_TERMIOS_H
typedef struct termios TIO;
#endif
/*
* Flow control flags
*/
#define FLOW_HARD 0x01
#define FLOW_SOFT 0x02
/*
* Define our own RS232 line flags
*/
#ifdef TIOCM_DTR
# define TIO_RS232_DTR TIOCM_DTR
# define TIO_RS232_DSR TIOCM_DSR
# define TIO_RS232_RTS TIOCM_RTS
# define TIO_RS232_CTS TIOCM_CTS
# ifdef TIOCM_CAR
# define TIO_RS232_DCD TIOCM_CAR
# else
# define TIO_RS232_DCD TIOCM_CD
# endif
# ifdef TIOCM_RNG
# define TIO_RS232_RNG TIOCM_RNG
# else
# define TIO_RS232_RNG TIOCM_RI
# endif
#else /* TIOCM_DTR */
# define TIO_RS232_DTR 0x01
# define TIO_RS232_DSR 0x02
# define TIO_RS232_RTS 0x04
# define TIO_RS232_CTS 0x08
# define TIO_RS232_DCD 0x10
# define TIO_RS232_RNG 0x20
#endif /* TIOCM_DTR */
int tio_get(int fd, TIO *tio);
int tio_set(int fd, TIO *tio);
int tio_set_speed(TIO *tio, unsigned int speed);
int tio_get_speed(TIO *tio);
int tio_set_flow_control(int fd, TIO *tio, int flow);
void tio_set_raw_mode(TIO *tio);
void tio_set_local(TIO *tio, bool local);
int tio_set_dtr(int fd, bool on);
int tio_ctty(int fd);
int tio_send_break(void);
int tio_get_dcd(int fd);
int tio_get_rs232_state(void);
/*
* io_tcpip.c
*/
int tcpip_connect(const char *hostname, e_tcpmode tcpmode);
int tcpip_init(void);
int tcpip_shutdown(void);
bool tcpip_isgood_host(const char *str);
/*
* io_unix_modem.c
*/
char *port_get_name(const char *devname);
int port_open(const s_modemport *port, int detach, TIO *oldtio);
int port_init(int fd, int portspeed, TIO *oldtio, bool local);
int port_carrier(int fd, bool online);
int port_deinit(int fd, TIO *oldtio);
void port_close(void);
/*
* io_modem.c
*/
#define MODEM_OK 0
#define MODEM_ERROR 1
#define MODEM_CANTSEND 2
#define MODEM_NORESP 3
extern const char *modem_errlist[];
long modem_getconnspeed(const char *connstr);
bool modem_isgood_phone(const char *str);
char *modem_transphone(char *buffer, const char *phone, size_t buflen);
void modem_clearin(int timeout);
int modem_putstr(const char *str);
int modem_getline(char *buf, int bufsize, time_t timer);
int modem_dial(const char *dialstr, int timeout, char **connstr);
int modem_command(const char *command, int timeout, bool logit);
int modem_hangup(const char *command, int timeout);
bool modem_candialout(const char *modemdev);
s_modemport *modem_getfree_port(const char *lockdir);
s_modemport *modem_getmatch_port(const char *ttysubname);
#endif /* _IO_H_ */
+85
View File
@@ -0,0 +1,85 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _LOGGER_H_
#define _LOGGER_H_
#include "confread.h"
/* enable this to use syslog facility */
#define USE_SYSLOG
enum { LOG_MODE_FILE, LOG_MODE_SYSLOG, LOG_MODE_MIXED };
enum { LOG_FILE_DAEMON, LOG_FILE_SESSION, LOG_FILE_DEBUG, LOG_FILE_HISTORY };
enum {
LOG_EMERG = 0, /* system is unusable */
LOG_ALERT = 1, /* action must be taken immediately */
LOG_CRIT = 2, /* critical conditions */
LOG_ERR = 3, /* error conditions */
LOG_WARNING = 4, /* warning conditions */
LOG_NOTICE = 5, /* normal but significant condition */
LOG_INFO = 6, /* informational */
LOG_DEBUG = 7 /* debug-level messages */
};
#ifdef DEBUG
# define D_CONFIG 0x0000001L
# define D_OVERRIDE 0x0000002L
# define D_EVENT 0x0000004L
# define D_NODELIST 0x0000008L
# define D_OUTBOUND 0x0000010L
# define D_INFO 0x0000020L
# define D_HSHAKE 0x0000040L
# define D_TTYIO 0x0000080L
# define D_MODEM 0x0000100L
# define D_PROT 0x0000200L
# define D_FREQ 0x0000400L
# define D_STATEM 0x0000800L
# define D_DAEMON 0x0001000L
# define D_FULL 0xfffffffL
#endif
#ifdef DEBUG
# define DEB(what) debug what
#else
# define DEB(what)
#endif
const char *log_getfilename(int whatfor);
bool log_isopened(void);
/* #ifndef USE_SYSLOG
void log_setident(const char *ident);
#endif */ /* ifndef USE_SYSLOG */
int log_open(const char *logname, const char *ext, const char *tty);
int log_close(void);
int log_reopen(const char *logname, const char *ext, const char *tty);
int log(const char *s, ...);
int logerr(const char *s, ...);
#ifdef DEBUG
void debug_setlevel(long newlevel, bool logit);
bool debug_isopened(void);
void debug_setfilename(const char *debugname);
int debug_parsestring(char *str, unsigned long *deblevel);
int debug_open(const char *debugname);
int debug_close(void);
int debug(unsigned long what, const char *str, ...);
#endif
#endif
+168
View File
@@ -0,0 +1,168 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _NODELIST_H_
#define _NODELIST_H_
/*
* Each nodelist has corresponding index file. Index file name is the
* same as nodelist, but extension is changed to the ".bni", so index
* file to the nodelist "net5020.ndl" will be called "net5020.bni"
*
* Nodelist index header:
*
* Offset Size Description
* -------------------------------
* 0x0000 4 bytes Nodelist file date
* 0x0004 4 bytes Nodelist file size
* 0x0008 4 bytes Total number of entries in index file
* 0x000c 4 bytes Unused
*
* Nodelist index is an array of next entries:
*
* Offset Size Description
* -------------------------------
* 0x0010 2 bytes Zone number
* 0x0012 2 bytes Net number
* 0x0014 2 bytes Node number
* 0x0016 2 bytes Point number
* 0x0018 2 bytes HUB number (I hope HUB is in the same zone:net)
* 0x001a 4 bytes Offset of string in nodelist file
*
*/
enum
{
NODELIST_HDRSIZE = 16, /* Don't change! */
NODELIST_ENTRYSIZE = 14, /* Don't change! */
NODELIST_READAHEAD = 50
};
/*
* Modes for nodelist_opendindex()
*/
enum nodelist_iomode
{
NODELIST_READ,
NODELIST_WRITE
};
/*
* Positions of <...> in nodelist strings
*/
enum nodelist_positon
{
NODELIST_POSKEYWORD = 0,
NODELIST_POSNUMBER = 1,
NODELIST_POSNAME = 2,
NODELIST_POSLOCATION = 3,
NODELIST_POSSYSOP = 4,
NODELIST_POSPHONE = 5,
NODELIST_POSSPEED = 6,
NODELIST_POSFLAGS = 7
};
/*
* Storage sizes for node structure
*/
enum nodelist_limit
{
BNI_MAXNAME = 48,
BNI_MAXLOCATION = 48,
BNI_MAXSYSOP = 48,
BNI_MAXPHONE = 48,
BNI_MAXFLAGS = 120
};
/*
* node->keyword values
*/
enum nodelist_keyword
{
KEYWORD_EMPTY,
KEYWORD_ZONE,
KEYWORD_REGION,
KEYWORD_HOST,
KEYWORD_HUB,
KEYWORD_PVT,
KEYWORD_HOLD,
KEYWORD_DOWN,
KEYWORD_BOSS,
KEYWORD_POINT
};
/*
* Nodelist procedures error codes
*/
enum nodelist_error
{
BNIERR_NOERROR = 0,
BNIERR_NODENOTFOUND = 1,
BNIERR_IDXIOERR = 2,
BNIERR_NDLIOERR = 3,
BNIERR_BADINDEX = 4,
BNIERR_NONODELIST = 5
};
typedef struct nodelist
{
FILE *fp_index;
FILE *fp_nodelist;
char name_index[BF_MAXPATH+1];
char name_nodelist[BF_MAXPATH+1];
long entries;
}
s_nodelist;
typedef struct bni
{
int zone;
int net;
int node;
int point;
int hub;
long offset;
}
s_bni;
typedef struct node
{
s_faddr addr;
s_faddr addr_hub;
enum nodelist_keyword keyword;
bool listed;
char name[BNI_MAXNAME+1];
char location[BNI_MAXLOCATION+1];
char sysop[BNI_MAXSYSOP+1];
char phone[BNI_MAXPHONE+1];
long speed;
char flags[BNI_MAXFLAGS+1];
s_timevec worktime;
}
s_node;
int nodelist_checkflag(const char *nodeflags, const char *flag);
int nodelist_keywordval(const char *keyword);
int nodelist_parsestring(s_node *node, char *str);
s_nodelist *nodelist_open(const char *dir, const char *name, int mode);
int nodelist_checkheader(s_nodelist *nlp);
int nodelist_createheader(s_nodelist *nlp);
int nodelist_close(s_nodelist *nlp);
int nodelist_putindex(s_nodelist *nlp, const s_bni *bni);
int nodelist_findindex(s_nodelist *nlp, s_bni *bni, s_faddr addr);
int nodelist_getstr(s_nodelist *nlp, size_t offset, char *buffer, size_t buflen);
int nodelist_lookup_string(char *buffer, size_t buflen, s_faddr addr);
int nodelist_lookup(s_node *node, s_faddr addr);
void nodelist_initnode(s_node *node, s_faddr addr);
#endif /* _NODELIST_H_ */
+72
View File
@@ -0,0 +1,72 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _OS_H_
#define _OS_H_
#define EXEC_OPT_NOWAIT 0x01
#define EXEC_OPT_SETSID 0x02
#define EXEC_OPT_LOGOUT 0x04
#define EXEC_OPT_USESHELL 0x08
#define EXEC_MAX_NUM_ENVS 40
#define EXEC_MAX_NUM_ARGS 20
#define EXEC_DEFAULT_UMASK ~(S_IRUSR|S_IWUSR);
struct exec_options
{
/*
* This variables must be set before running
*/
char *command;
char *envp[EXEC_MAX_NUM_ENVS+1];
int umask;
int timeout;
int options;
/*
* This variables will store command execution status
*/
int retc;
int runtime;
};
typedef struct exec_options s_exec_options;
int exec_file_exist(const char *command);
void exec_options_init(s_exec_options *eopt);
void exec_options_deinit(s_exec_options *eopt);
void exec_env_add(s_exec_options *eopt, const char *name, const char *value);
void exec_options_set_command(s_exec_options *eopt, const char *command);
int exec_command(s_exec_options *eopt);
#if defined(OS2) || defined(W32)
#define DIRSEPCHR '\\'
#define DIRSEPSTR "\\"
#else /* Unices */
#define DIRSEPCHR '/'
#define DIRSEPSTR "/"
#endif
size_t getfreespace(const char *path);
int xsystem(const char *command, const char *p_input, const char *p_output);
#ifndef HAVE_SETPROCTITLE
void setargspace(char *argv[], char *envp[]);
void setproctitle(const char *fmt, ...);
#endif
#ifndef HAVE_RENAME
int rename(const char *old_name, const char *new_name);
#endif
#endif /* _OS_H_ */
+209
View File
@@ -0,0 +1,209 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _OUTBOUND_H_
#define _OUTBOUND_H_
#include "nodelist.h"
#define FLAVOR_NONE 0x000
#define FLAVOR_HOLD 0x001
#define FLAVOR_NORMAL 0x002
#define FLAVOR_DIRECT 0x004
#define FLAVOR_IMMED 0x008
#define FLAVOR_CRASH 0x010
#define ACTION_NOTHING 0x000 /* Do nothing with file after ses. */
#define ACTION_UNLINK 0x001 /* Unlink file if send successful */
#define ACTION_TRUNCATE 0x002 /* Truncate file if send successful */
#define ACTION_FORCEUNLINK 0x004 /* Unlink file in any case after ses.*/
#define TYPE_UNKNOWN 0x000
#define TYPE_NETMAIL 0x001
#define TYPE_ARCMAIL 0x002
#define TYPE_TICFILE 0x004
#define TYPE_FILEECHO 0x008
#define TYPE_FILEBOX 0x010
#define TYPE_FROMFLO 0x020
#define TYPE_REQUEST 0x040
#define TYPE_REQANSW 0x080 /* Our answer on incoming file req. */
#define TYPE_FLOFILE 0x100
#define TYPE_ASONAME 0x200 /* File with AmigaDOS Style Outbound */
/* name (e.g. 2.5020.1398.11.out) */
#define STATUS_WILLSEND 0
#define STATUS_SKIP 1
#define STATUS_SENDING 2
#define STATUS_SENT 3
#define QUEUE_SORT_ADDRESS 0x01
#define QUEUE_SORT_SIZE 0x02
#define QUEUE_SORT_REVERSE 0x04
typedef struct {
FILE *fp;
char att_path[BFORCE_MAX_PATH+1];
int att_action;
int att_offs; /* offset of the curent line */
} s_FLO;
enum { OUTB_TYPE_BSO,
OUTB_TYPE_DOMAIN,
OUTB_TYPE_ASO,
OUTB_TYPE_FBOX };
typedef struct outbound_callback_data {
int (*callback)(struct outbound_callback_data *);
void *dest;
s_faddr addr;
char *path;
int flavor; /* Force this flavor for file */
unsigned short type;
} s_outbound_callback_data;
typedef struct filelist {
struct filelist *next;
char *fname;
size_t size;
unsigned short type;
unsigned short status;
unsigned short action;
unsigned short flavor;
short flodsc;
} s_filelist;
typedef struct flofile {
char *fname;
short flavor;
time_t mtime;
} s_flofile;
typedef struct fsqueue {
s_flofile *flotab;
s_filelist *fslist;
int flonum; /* Number of items in .?LO files table */
} s_fsqueue;
#define TRIES_RESET -1 /* Use this macro to reset tries counter */
#define HOLD_RESET 1 /* Use this macro to reset hold timer */
typedef struct sess_stat {
bool undialable;
int tries;
int tries_noconn;
int tries_nodial;
int tries_noansw;
int tries_hshake;
int tries_sessns;
unsigned long hold_until;
unsigned long hold_freqs;
unsigned long last_success;
unsigned long last_success_in;
unsigned long last_success_out;
} s_sess_stat;
typedef struct sysentry {
s_node node;
bool lookedup;
const s_override *overrides; /* List of all overrides */
const s_override *lineptr; /* List of all overrides */
s_sess_stat stat;
int line; /* Current line number */
bool tcpip; /* Call to the current line via TCP/IP? */
bool busy; /* Address is busy [in an another queue, etc.] */
time_t lastcall; /* Last call _finish_ time */
time_t mailage; /* The oldest file modification time */
size_t netmail_size;
size_t arcmail_size;
size_t request_size;
size_t files_size;
int flavors;
int types;
} s_sysentry;
typedef struct sysqueue {
s_sysentry *systab;
int sysnum;
time_t holduntil;
int current_modem;
int current_tcpip;
int next_modem;
int next_tcpip;
} s_sysqueue;
typedef struct exttab {
const char *ext;
int type;
int flavor;
int action;
} s_exttab;
extern s_exttab outtab[];
extern s_exttab exttab[];
extern int (*sysqueue_add_callback)(s_sysentry *);
extern int (*sysqueue_rem_callback)(s_sysentry *);
extern bool sysqueue_dont_count_sizes;
/* outb_bsy.c */
int out_bsy_check(s_faddr addr);
#ifdef BFORCE_USE_CSY
int out_bsy_lock(s_faddr addr, bool csy_locks);
#else
int out_bsy_lock(s_faddr addr);
#endif
int out_bsy_unlock(s_faddr addr);
int out_bsy_unlockall(void);
/* outb_flo.h */
s_FLO *flo_open(const char *path, const char *mode);
int flo_next(s_FLO *FLO);
int flo_mark_sent(s_FLO *FLO);
int flo_eof(s_FLO *FLO);
int flo_close(s_FLO *FLO);
bool out_flo_isempty(const char *path);
int out_flo_marksent(const char *fname, const char *floname);
int out_flo_getsizes(const char *floname, size_t *arcmail, size_t *files);
int out_flo_unlinkempty(const s_flofile *flotab, int flonum);
/* outb_getname.c */
char *out_getname_4d(s_faddr addr);
char *out_getname_domain(s_faddr addr);
char *out_getname_amiga(s_faddr addr);
/* outb_queue.c */
int out_filetype(const char *fname);
int out_handle_fsqueue(s_outbound_callback_data *callback);
void deinit_filelist(s_filelist *filelist);
void deinit_fsqueue(s_fsqueue *q);
#ifdef DEBUG
void log_filelist(const s_filelist *filelist);
void log_fsqueue(const s_fsqueue *q);
#endif
/* outb_main.c */
int out_get_root(const char *outbound, char **out_root, char **out_main);
int out_parse_name_aso(s_faddr *addr, const char *name);
int out_scan(s_outbound_callback_data *callback, const s_falist *fa_list);
/* outb_sysqueue.c */
void out_reset_trycounters(s_sysentry *syst);
void out_reset_sysqueue(s_sysqueue *q);
void out_sysqueue_sort(s_sysqueue *q, int opts);
void out_remove_from_sysqueue(s_sysqueue *q, int pos);
int out_handle_sysqueue(s_outbound_callback_data *callback);
void deinit_sysqueue(s_sysqueue *q);
#ifdef DEBUG
void log_sysqueue(const s_sysqueue *q);
#endif
#endif
+160
View File
@@ -0,0 +1,160 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*
* binkp's frames:
*
* +---------------------- 0=data block, 1=message(command)
* | +---- data block size / msg's argument size
* | |
* 7 6543210 76543210
* +-+-------+--------+--- ... ---+
* | | HI LO | | -- data block / msg's argument
* +-+-------+--------+--- ... ---+
*/
#ifndef _P_BINKP_H_
#define _P_BINKP_H_
#define BINKP_NAME "binkp"
#define BINKP_MAJOR 1
#define BINKP_MINOR 0
#define BINKP_PORT 24554
#define BINKP_TIMEOUT (5*60)
#define BINKP_MIN_BLKSIZE 128
#define BINKP_MAX_BLKSIZE 0x7fff
#define BINKP_DEF_BLKSIZE (4*1024u)
#define BINKP_BLK_HDRSIZE 2
#define BINKP_MAXPASSWD 64
#define BINKP_MAXSYSTNAME 120
#define BINKP_MAXLOCATION 120
#define BINKP_MAXSYSOP 120
#define BINKP_MAXPHONE 120
#define BINKP_MAXFLAGS 120
#define BINKP_MAXLOCATION 120
#define BINKP_MAXPROGNAME 40
#define BINKP_MAXPROTNAME 40
#define BINKP_MAXTIMESTR 40
#define BINKP_MAXCHALLENGE 128
#define BINKP_MAXOPT 196
#define BINKP_OPT_NR 0x01 /* Non-reliable mode */
#define BINKP_OPT_MB 0x02 /* Multiple batch mode */
#define BINKP_OPT_MPWD 0x04 /* Multiple passwods mode */
#define BINKP_OPT_MD5 0x08 /* CRAM-MD5 authentication */
#define BINKP_OPT_SHA1 0x10 /* CRAM-SHA1 authentication */
#define BINKP_OPT_DES 0x20 /* CRAM-DES authentication */
typedef struct {
s_sysaddr *addrs;
int anum;
char passwd[BINKP_MAXPASSWD+1];
char systname[BINKP_MAXSYSTNAME+1];
char location[BINKP_MAXLOCATION+1];
char sysop[BINKP_MAXSYSOP+1];
char phone[BINKP_MAXPHONE+1];
char flags[BINKP_MAXFLAGS+1];
char progname[BINKP_MAXPROGNAME+1];
char protname[BINKP_MAXPROTNAME+1];
char timestr[BINKP_MAXTIMESTR+1];
char opt[BINKP_MAXOPT+1];
int majorver;
int minorver;
int options;
char challenge[BINKP_MAXCHALLENGE+1];
int challenge_length;
} s_binkp_sysinfo;
typedef enum {
/*
* Pseudo message types, returned by binkp_recv()
*/
BPMSG_EXIT = -3, /* Terminate session */
BPMSG_NONE = -2, /* Got nothing intresting */
BPMSG_DATA = -1, /* Got data block */
/*
* Real BinkP message types
*/
BPMSG_NUL = 0, /* Site information */
BPMSG_ADR, /* List of addresses */
BPMSG_PWD, /* Session password */
BPMSG_FILE, /* File information */
BPMSG_OK, /* Password was acknowleged (data ignored) */
BPMSG_EOB, /* End Of Batch (data ignored) */
BPMSG_GOT, /* File received */
BPMSG_ERR, /* Misc errors */
BPMSG_BSY, /* All AKAs are busy */
BPMSG_GET, /* Get a file from offset */
BPMSG_SKIP, /* Skip a file (RECEIVE LATER) */
BPMSG_MIN = BPMSG_NUL, /* Minimal message type value */
BPMSG_MAX = BPMSG_SKIP /* Maximal message type value */
} e_bpmsg;
typedef struct {
bool sent; /* Sent message (queued) */
e_bpmsg type; /* Message type */
int size; /* Message size (length of text) */
char *data; /* Message text */
} s_bpmsg;
typedef struct {
char *obuf; /* Output buffer */
int opos; /* Unsent bytes left in buffer */
char *optr; /* Send data from this position */
char *ibuf; /* Our input buffer */
int ipos;
int isize;
bool imsg; /* Is it message? */
bool inew;
e_bpmsg imsgtype; /* Message type */
int junkcount;
s_bpmsg *msgqueue; /* Outgoing messages queue */
int n_msgs; /* Number of messages in queue */
int timeout;
} s_bpinfo;
/* prot_binkp.c */
int binkp_outgoing(s_binkp_sysinfo *local_data, s_binkp_sysinfo *remote_data);
int binkp_incoming(s_binkp_sysinfo *local_data, s_binkp_sysinfo *remote_data);
int binkp_transfer(s_protinfo *pi);
/* prot_binkp_misc.c */
void binkp_init_bpinfo(s_bpinfo *bpi);
void binkp_deinit_bpinfo(s_bpinfo *bpi);
int binkp_gethdr(const char *s);
int binkp_getmsgtype(char ch);
void binkp_puthdr(char *s, unsigned int u);
void binkp_putmsgtype(char *s, e_bpmsg msg);
void binkp_queuemsg(s_bpinfo *bpi, e_bpmsg msg, const char *s1, const char *s2);
void binkp_queuemsgf(s_bpinfo *bpi, e_bpmsg msg, const char *fmt, ...);
int binkp_parsfinfo(char *s, char **fn, size_t *sz, time_t *tm, size_t *offs);
int binkp_buffer_message(s_bpinfo *bpi, s_bpmsg *msg);
int binkp_send_buffer(s_bpinfo *bpi);
int binkp_send(s_bpinfo *bpi);
int binkp_flush_queue(s_bpinfo *bpi, int timeout);
int binkp_recv(s_bpinfo *bpi);
void binkp_update_sysinfo(s_binkp_sysinfo *binkp);
void binkp_log_sysinfo(s_binkp_sysinfo *binkp);
void binkp_queue_sysinfo(s_bpinfo *bpi, s_binkp_sysinfo *binkp);
void binkp_set_sysinfo(s_binkp_sysinfo *binkp, s_faddr *remote_addr, bool caller);
void binkp_parse_options(s_binkp_sysinfo *binkp, char *options);
/* prot_binkp_api.c */
extern s_handshake_protocol handshake_protocol_binkp;
#endif /* _P_BINKP_H_ */
+136
View File
@@ -0,0 +1,136 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _P_COMMON_H_
#define _P_COMMON_H_
#include "outbound.h"
/* File transfer protocols return codes */
#define PRC_NOERROR 0 /* No comments :) */
#define PRC_ERROR 1 /* I/O error occured while snd./rcv. */
#define PRC_REMOTEABORTED 2 /* "ABORT" initiated by remote */
#define PRC_LOCALABORTED 3 /* We got SIGINT/SIGTERM? */
#define PRC_CPSTOOLOW 4 /* Cps was so low.. :( */
#define PRC_STOPTIME 5 /* Aborted due to the time limits */
/* Send/Recv file status values */
#define FSTAT_PROCESS 1
#define FSTAT_WAITACK 2
#define FSTAT_SUCCESS 3
#define FSTAT_SKIPPED 4
#define FSTAT_REFUSED 5
typedef struct traffic {
int netmail_num; /* Number of netmail packets */
int netmail_time; /* Netmail packets sending/receiving time */
size_t netmail_size; /* Size of netmail packtes */
int arcmail_num; /* Dito.. */
int arcmail_time;
size_t arcmail_size;
int files_num;
int files_time;
size_t files_size;
int freqed_num;
int freqed_time;
size_t freqed_size;
} s_traffic;
/*
* Information on currently receiveing/transmitting file
*/
typedef struct finfo {
FILE *fp; /* File descriptor of current file */
char *local_name; /* Local file name that is used at our side */
char *net_name; /* File name as it known to the remote side */
char *fname; /* Local file name with full path */
time_t start_time; /* Start of current file rx/tx transactions */
time_t mod_time; /* File last modification time */
mode_t mode;
size_t bytes_total; /* File size */
size_t bytes_sent;
size_t bytes_received;
size_t bytes_skipped; /* crash recovery */
int eofseen; /* end of file seen */
int status;
int action;
int type;
int flodsc; /* Index number in flo files table */
} s_finfo;
/*
* Transfer protocol related structure
*/
typedef struct protinfo {
/* ----------------------------------------------------------------- */
/* Variables defined before protocol starting */
/* ----------------------------------------------------------------- */
bool reqs_only; /* Send only .REQ files (for Hydra RH1 mode) */
time_t stop_time; /* Stop transfer at this time */
int freq_timelimit; /* Abort transfer if send freqs longer this */
int min_tx_cps; /* Minimal transmite speed */
int min_rx_cps; /* Minimal receive speed */
int min_cps_time; /* Abort transfer if minimal bps stay during
this time period */
char *buffer; /* Ptr. to buffer for buffered file saving */
size_t buflen; /* Buffer size */
/* ----------------------------------------------------------------- */
/* All variables below used by misc protocol routines */
/* ----------------------------------------------------------------- */
s_filelist *filelist; /* List of files.. It is our answer on .req! */
int tx_cps; /* Current transmite CPS */
int rx_cps; /* Current receive CPS */
int send_freqtime; /* Time we spend at sending REQed files */
time_t tx_low_cps_time; /* If CPS lower min_tx_cps it is time how
long it lasts */
time_t rx_low_cps_time; /* Same, but for transmite CPS */
time_t start_time; /* Time transfer started at */
s_traffic traffic_sent;
s_traffic traffic_rcvd;
size_t send_left_size;
size_t recv_left_size;
int send_left_num;
int recv_left_num;
s_finfo *send;
s_finfo *recv;
s_finfo *sentfiles;
s_finfo *rcvdfiles;
int n_sentfiles;
int n_rcvdfiles;
} s_protinfo;
extern const char *Protocols[]; /* Protocol names */
int p_tx_fopen(s_protinfo *pi);
int p_tx_fclose(s_protinfo *pi);
int p_tx_readfile(char *buf, size_t sz, s_protinfo *pi);
int p_rx_writefile(const char *buf, size_t sz, s_protinfo *pi);
int p_compfinfo(s_finfo *finf, const char *fn, size_t sz, time_t tm);
int p_rx_fopen(s_protinfo *pi, char *f_name, size_t f_size, time_t f_modtime, mode_t f_mode);
int p_rx_fclose(s_protinfo *pi);
int p_info(s_protinfo *pi, int bidir);
void prot_update_traffic(s_protinfo *pi, const s_fsqueue *q);
void p_log_txrxstat(const s_protinfo *pi);
void p_session_cleanup(s_protinfo *pi, bool success);
void p_shortname(char *name);
char *prot_unique_name(char *dirname, char *fname, int type);
void p_checkname(char *name);
void deinit_finfo(s_finfo *fi);
void init_protinfo(s_protinfo *pi, bool caller);
void deinit_protinfo(s_protinfo *pi);
char *p_convfilename(const char *origname, int type);
char *p_gettmpname(const char *inbound, char *fname, s_faddr addr, size_t sz, time_t tm);
#endif
+221
View File
@@ -0,0 +1,221 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _S_EMSI_H_
#define _S_EMSI_H_
/*
* EMSI limits
*/
#define EMSI_MAXDAT 16384
#define EMSI_MAXNFLAG 20
#define EMSI_MAXPASSWD 30
#define EMSI_MAXMPID 30
#define EMSI_MAXMNAME 120
#define EMSI_MAXMVER 120
#define EMSI_MAXMREG 120
#define EMSI_MAXSYSNAME 120
#define EMSI_MAXLOCATION 120
#define EMSI_MAXSYSOP 120
#define EMSI_MAXPHONE 120
#define EMSI_MAXFLAGS 120
#define EMSI_MAXOHTIME 120
#define EMSI_MAXFRTIME 120
#define EMSI_MAXXDATETIME 60
#define EMSI_MAXADDONS 120
/*
* EMSI XXn flags that affect only address number n in AKA list
*/
#define EMSI_FLAG_PU 0x0001 /* Pickup FILES for this address */
#define EMSI_FLAG_HA 0x0002 /* Hold all FILES for this address */
#define EMSI_FLAG_PM 0x0004 /* PickUp Mail ONLY for this address */
#define EMSI_FLAG_NF 0x0008 /* No TIC'S, associated files or file attaches */
/* for this address */
#define EMSI_FLAG_NX 0x0010 /* No compressed mail pickup desired, */
/* for this address */
#define EMSI_FLAG_NR 0x0020 /* File requests not accepted by caller */
/* for this address */
#define EMSI_FLAG_HN 0x0040 /* Hold all traffic EXCEPT Mail (ARCmail and */
/* Packets) for this address */
#define EMSI_FLAG_HX 0x0080 /* Hold compressed mail for this address */
#define EMSI_FLAG_HF 0x0100 /* Hold tic's and associated files and file */
/* attaches other than mail for this address */
#define EMSI_FLAG_HR 0x0200 /* Hold file requests (not processed at this */
/* time)for this address */
/*
* Defines for state machine
*/
#define SME -1
#define SM0 0
#define SM1 1
#define SM2 2
#define SM3 3
#define SM4 4
#define SM5 5
#define SM6 6
#define SM7 7
#define SM8 8
#define SM9 9
struct states
{
const char *st_name;
int (*proc)();
};
typedef struct states s_states;
struct linkcodes
{
/*
* EMSI-I (FSC-0056) and EMSI-II (FSC-0088) flags
* for XXn flags see s_emsiaddr structure
*/
UINT32 N81:1, /* Communication parameter emulation :) (EMSI-I) */
PUP:1, /* Pickup FILES for primary address only */
PUA:1, /* Pickup FILES for all presented addresses */
NPU:1, /* No FILE pickup desired. (calling system) */
HAT:1, /* Hold all FILES (answering system) */
PMO:1, /* PickUp Mail (ARCmail and Packets) ONLY */
NFE:1, /* No TIC'S, associated files or files attaches */
/* desired */
NXP:1, /* No compressed mail pickup desired */
NRQ:1, /* File requests not accepted by caller */
/* This flag is presented if file request processing */
/* is disabled TEMPORARILY for any reason */
HNM:1, /* Hold all traffic EXCEPT Mail(ARCmail and Packets) */
HXT:1, /* Hold compressed mail traffic. */
HFE:1, /* Hold tic's and associated files */
/* and file attaches other than mail */
HRQ:1, /* Hold file requests (not processed at this time) */
/* this flag is presented if file request processing */
/* is disabled TEMPORARILY for any reason */
FNC:1, /* Convert file names to "msdos" format */
RMA:1, /* System is able to process multiple file requests */
RH1:1; /* Under Hydra batch 1 contain file requests only, */
/* while batch 2 is reserved for all other files */
};
typedef struct linkcodes s_linkcodes;
struct compcodes
{
UINT16 NCP:1, /* No compatible protocols (failure) */
ZMO:1, /* Zmodem w/1,024 byte data packets */
ZAP:1, /* ZedZap (Zmodem variant) */
DZA:1, /* DirectZAP (Zmodem variant) */
JAN:1, /* Janus */
HYD:1; /* Hydra */
UINT16 FRQ:1, /* The system will accept and process FREQs */
NRQ:1, /* No file requests accepted by this system */
ARC:1, /* ARCmail 0.60-capable */
XMA:1, /* Supports other forms of compressed mail */
FNC:1, /* Filename conversion into 8.3 format */
EII:1, /* EMSI-II flags are supported */
DFB:1, /* Can fall-back to FTS1/WAZOO negotiation */
CHT:1, /* Chat during transmittion available */
BBS:1, /* Site has public BBS available */
HFR:1; /* Remote will automaticaly hold requested */
/* files for us */
};
typedef struct compcodes s_compcodes;
struct emsi
{
/*
* Keep here all unknown EMSI_DAT addons
*/
char addons[EMSI_MAXADDONS+1];
/*
* {EMSI_DAT} (main handshake information)
*/
bool have_emsi;
s_sysaddr *addrs; /* dynamicaly allocated array */
int anum; /* number of used entries in it */
char passwd[EMSI_MAXPASSWD+1];
s_linkcodes linkcodes; /* XXn linkcodes contained in eaddr */
s_compcodes compcodes;
char m_pid[EMSI_MAXMPID+1];
char m_name[EMSI_MAXMNAME+1];
char m_ver[EMSI_MAXMVER+1];
char m_reg[EMSI_MAXMREG+1];
/*
* {IDENT} (system information)
*/
bool have_ident;
char sname[EMSI_MAXSYSNAME+1];
char location[EMSI_MAXLOCATION+1];
char sysop[EMSI_MAXSYSOP+1];
char phone[EMSI_MAXPHONE+1];
int speed;
char flags[EMSI_MAXFLAGS+1];
/*
* {TRAF} (size of netmail and arcmail files on hold)
*/
bool have_traf;
size_t netmail_size;
size_t arcmail_size;
/*
* {MOH#} (size of files on hold? :))
*/
bool have_moh;
size_t files_size;
/*
* {OHFR} (site's work and freq time intervals)
*/
bool have_ohfr;
char oh_time[EMSI_MAXOHTIME+1];
char fr_time[EMSI_MAXFRTIME+1];
/*
* {TZUTC} (site's time zone)
*/
bool have_tzutc;
int tzutc;
/*
* {XDATETIME} (site's date and time in extended format)
*/
bool have_xdatetime;
char xdatetime[EMSI_MAXXDATETIME+1];
/*
* {TRX#} (site's current time)
*/
bool have_trx;
time_t time;
};
typedef struct emsi s_emsi;
/* prot_emsi.c */
int emsi_send_emsidat(s_emsi *local_emsi);
int emsi_recv_emsidat(s_emsi *remote_emsi);
void emsi_set_sysinfo(s_emsi *emsi, s_emsi *remote_emsi, int hrc,
e_protocol protocol);
/* prot_emsi_api.c */
extern s_handshake_protocol handshake_protocol_emsi;
/* prot_emsi_misc.c */
char *emsi_createdat(s_emsi *emsi);
int emsi_parsedat(char *emsi_dat, s_emsi *emsi);
void emsi_logdat(s_emsi *emsi);
#endif
+64
View File
@@ -0,0 +1,64 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _S_YOOHOO_H_
#define _S_YOOHOO_H_
#define YOOHOO_HELLOLEN 128 /* Size of the 'HELLO' frame */
#define YOOHOO_MAXFIELD 40
/*
* Information for/from yoohoo handshake (real packet size is 128 bytes)
*/
typedef struct
{
s_sysaddr *addrs; /* FTN address */
int anum;
int product_code; /* product code */
int version_maj; /* major revision of the product */
int version_min; /* minor revision of the product */
char system[YOOHOO_MAXFIELD+1];
char sysop[YOOHOO_MAXFIELD+1];
char passwd[YOOHOO_MAXFIELD+1];
int capabilities;
}
s_yoohoo_sysinfo;
#define YOOHOO_DIETIFNA 0x0001 /* Can do fast "FTS-0001" */
#define YOOHOO_FTB_USER 0x0002 /* Reserved by Opus-CBCS */
#define YOOHOO_ZMODEM 0x0004 /* Does ZModem, 1K blocks */
#define YOOHOO_ZEDZAP 0x0008 /* Can do ZModem variant */
#define YOOHOO_JANUS 0x0010 /* Can do Janus */
#define YOOHOO_HYDRA 0x0020 /* Can do Hydra */
#define YOOHOO_Bit_6 0x0040 /* reserved by FTSC */
#define YOOHOO_Bit_7 0x0080 /* reserved by FTSC */
#define YOOHOO_Bit_8 0x0100 /* reserved by FTSC */
#define YOOHOO_Bit_9 0x0200 /* reserved by FTSC */
#define YOOHOO_Bit_a 0x0400 /* reserved by FTSC */
#define YOOHOO_Bit_b 0x0800 /* reserved by FTSC */
#define YOOHOO_Bit_c 0x1000 /* reserved by FTSC */
#define YOOHOO_Bit_d 0x2000 /* reserved by FTSC */
#define YOOHOO_DO_DOMAIN 0x4000 /* Packet contains domain */
#define YOOHOO_WZ_FREQ 0x8000 /* WZ file req. ok */
/* prot_yoohoo.c */
int yoohoo_send_hello(s_yoohoo_sysinfo *local_data);
int yoohoo_recv_hello(s_yoohoo_sysinfo *remote_data);
void yoohoo_set_sysinfo(s_yoohoo_sysinfo *local_data, int hrc,
e_protocol protocol);
void yoohoo_log_sysinfo(s_yoohoo_sysinfo *yoohoo);
/* prot_yoohoo_api.c */
extern s_handshake_protocol handshake_protocol_yoohoo;
#endif
+222
View File
@@ -0,0 +1,222 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*
* Z M O D E M . H Manifest constants for ZMODEM
* application to application file transfer protocol
* 05-23-87 Chuck Forsberg Omen Technology Inc
*/
#ifndef _P_ZMODEM_H_
#define _P_ZMODEM_H_
#include "prot_common.h"
/* ------------------------------------------------------------------------- */
/* Z-Modem chracteristics definitions */
/* ------------------------------------------------------------------------- */
#define ZDEADTIMER 180 /* If expired think remote side is dead */
#define ZRXTIMEOUT 120 /* Time to wait for receiving whole block */
#define ZWAITTIME 30 /* Time to wait for character */
#define ZMAXBLOCKLEN 8192 /* Maximal zmodem RX/TX block size */
#define ZMAXTRIES 10 /* Maximal number of tries to do somthing */
#define ZRXSKIPFIN 2 /* Number of ZFINs to ignore at start up */
#define ZMAXFNAME 4096 /* Max. file name, to avoid txbuf overflow */
/* ------------------------------------------------------------------------- */
/* Z-Modem constants definition */
/* ------------------------------------------------------------------------- */
#define ZPAD '*' /* 052 Padding character begins frames */
#define ZDLE 030 /* Ctrl-X Zmodem escape - `ala BISYNC DLE */
#define ZBIN 'A' /* Binary frame indicator */
#define ZHEX 'B' /* HEX frame indicator */
#define ZBIN32 'C' /* Binary frame with 32 bit FCS */
/* ------------------------------------------------------------------------- */
/* Frame types (see array "Frametypes" in zm.c) */
/* ------------------------------------------------------------------------- */
#define ZCRCERR -5 /* CRC error */
#define ZERROR -4 /* Miscelaneouse errors */
#define ZEXIT -3 /* Critical errors */
#define ZHANGUP -2 /* No Carrier */
#define ZTIMER -1 /* Time out waiting for smth. */
#define ZOK 0 /* All right */
/*
* TTY_TIMEOUT -1 \
* TTY_HANGUP -2 > defined in ttyio.h
* TTY_ERROR -3 /
*/
#define ZRQINIT 0 /* Request receive init */
#define ZRINIT 1 /* Receive init */
#define ZSINIT 2 /* Send init sequence (optional) */
#define ZACK 3 /* ACK to above */
#define ZFILE 4 /* File name from sender */
#define ZSKIP 5 /* To sender: skip this file */
#define ZNAK 6 /* Last packet was garbled */
#define ZABORT 7 /* Abort batch transfers */
#define ZFIN 8 /* Finish session */
#define ZRPOS 9 /* Resume data trans at this position */
#define ZDATA 10 /* Data packet(s) follow */
#define ZEOF 11 /* End of file */
#define ZFERR 12 /* Fatal Read or Write error Detected */
#define ZCRC 13 /* Request for file CRC and response */
#define ZCHALLENGE 14 /* Receiver's Challenge */
#define ZCOMPL 15 /* Request is complete */
#define ZCAN 16 /* Other end canned session with CAN*5 */
#define ZFREECNT 17 /* Request for free bytes on filesystem */
#define ZCOMMAND 18 /* Command from sending program */
#define ZSTDERR 19 /* Output to standard error, data follows */
/* ------------------------------------------------------------------------- */
/* ZDLE sequences */
/* ------------------------------------------------------------------------- */
#define ZCRCE 'h' /* CRC next, frame ends, header packet follows */
#define ZCRCG 'i' /* CRC next, frame continues nonstop */
#define ZCRCQ 'j' /* CRC next, frame continues, ZACK expected */
#define ZCRCW 'k' /* CRC next, ZACK expected, end of frame */
#define ZRUB0 'l' /* Translate to rubout 0177 */
#define ZRUB1 'm' /* Translate to rubout 0377 */
/* ------------------------------------------------------------------------- */
/* $zdlread return values (internal) */
/* -1 is general error, -2 is timeout */
/* ------------------------------------------------------------------------- */
#define GOTOR 0400
#define GOTCRCE (ZCRCE|GOTOR) /* ZDLE-ZCRCE received */
#define GOTCRCG (ZCRCG|GOTOR) /* ZDLE-ZCRCG received */
#define GOTCRCQ (ZCRCQ|GOTOR) /* ZDLE-ZCRCQ received */
#define GOTCRCW (ZCRCW|GOTOR) /* ZDLE-ZCRCW received */
#define GOTCAN (GOTOR|030) /* CAN*5 seen */
/* ------------------------------------------------------------------------- */
/* Byte positions within header array */
/* ------------------------------------------------------------------------- */
#define ZF0 3 /* First flags byte */
#define ZF1 2
#define ZF2 1
#define ZF3 0
#define ZP0 0 /* Low order 8 bits of position */
#define ZP1 1
#define ZP2 2
#define ZP3 3 /* High order 8 bits of file position */
/* ------------------------------------------------------------------------- */
/* Bit Masks for ZRINIT flags byte ZF0 */
/* ------------------------------------------------------------------------- */
#define CANFDX 0x01 /* Rx can send and receive true FDX */
#define CANOVIO 0x02 /* Rx can receive data during disk I/O */
#define CANBRK 0x04 /* Rx can send a break signal */
#define CANCRY 0x08 /* Receiver can decrypt */
#define CANLZW 0x10 /* Receiver can uncompress */
#define CANFC32 0x20 /* Receiver can use 32 bit Frame Check */
#define ESCCTL 0x40 /* Receiver expects ctl chars to be escaped */
#define ESC8 0x80 /* Receiver expects 8th bit to be escaped */
/* ------------------------------------------------------------------------- */
/* Bit Masks for ZRINIT flags byze ZF1 */
/* ------------------------------------------------------------------------- */
#define ZF1_CANVHDR 0x01 /* Variable headers OK */
#define ZF1_TIMESYNC 0x02 /* nonstandard, Receiver request timesync */
/* ------------------------------------------------------------------------- */
/* Parameters for ZSINIT frame */
/* ------------------------------------------------------------------------- */
#define ZATTNLEN 32 /* Max length of attention string */
/* ------------------------------------------------------------------------- */
/* Bit Masks for ZSINIT flags byte ZF0 */
/* ------------------------------------------------------------------------- */
#define TESCCTL 0100 /* Transmitter expects ctl chars to be escaped */
#define TESC8 0200 /* Transmitter expects 8th bit to be escaped */
/* ------------------------------------------------------------------------- */
/* Parameters for ZFILE frame */
/* Conversion options one of these in ZF0 */
/* ------------------------------------------------------------------------- */
#define ZCBIN 1 /* Binary transfer - inhibit conversion */
#define ZCNL 2 /* Convert NL to local end of line convention */
#define ZCRESUM 3 /* Resume interrupted file transfer */
/* ------------------------------------------------------------------------- */
/* Management include options, one of these ored in ZF1 */
/* ------------------------------------------------------------------------- */
#define ZF1_ZMSKNOLOC 0x80 /* Skip file if not present at rx */
/* ------------------------------------------------------------------------- */
/* Management options, one of these ored in ZF1 */
/* ------------------------------------------------------------------------- */
#define ZF1_ZMMASK 0x1f /* Mask for the choices below */
#define ZF1_ZMNEWL 1 /* Transfer if source newer or longer */
#define ZF1_ZMCRC 2 /* Transfer if different file CRC or length */
#define ZF1_ZMAPND 3 /* Append contents to existing file (if any) */
#define ZF1_ZMCLOB 4 /* Replace existing file */
#define ZF1_ZMNEW 5 /* Transfer if source newer */
/* Number 5 is alive ... */
#define ZF1_ZMDIFF 6 /* Transfer if dates or lengths different */
#define ZF1_ZMPROT 7 /* Protect destination file */
#define ZF1_ZMCHNG 8 /* Change filename if destination exists */
/* ------------------------------------------------------------------------- */
/* Transport options, one of these in ZF2 */
/* ------------------------------------------------------------------------- */
#define ZTLZW 1 /* Lempel-Ziv compression */
#define ZTCRYPT 2 /* Encryption */
#define ZTRLE 3 /* Run Length encoding */
/* ------------------------------------------------------------------------- */
/* Extended options for ZF3, bit encoded */
/* ------------------------------------------------------------------------- */
#define ZXSPARS 64 /* Encoding for sparse file operations */
/* ------------------------------------------------------------------------- */
/* Parameters for ZCOMMAND frame ZF0 (otherwise 0) */
/* ------------------------------------------------------------------------- */
#define ZCACK1 1 /* Acknowledge, then do command */
/* ------------------------------------------------------------------------- */
/* Z-Modem globals */
/* ------------------------------------------------------------------------- */
extern int Z_Rxexp; /* True means timer expired */
extern int Z_Rxtout; /* Seconds to wait for receiving whole block */
extern int Z_Rxwait; /* Seconds to wait for character available */
extern int Z_Rxframeind; /* ZBIN ZBIN32, or ZHEX type of frame r-ed */
extern int Z_Rxtype; /* Type of header received */
extern int Z_Rxcount; /* Count of data bytes received */
extern int Z_Txnulls; /* Number of nulls to send at beg. of ZDATA */
extern char Z_Rxhdr[4]; /* Received header */
extern char Z_Txhdr[4]; /* Transmitted header */
extern long Z_Rxpos; /* Received file position */
extern int Z_Txfcs32; /* TRUE means send binary frames with 32 bit FCS */
extern int Z_Txcrc32; /* Display flag ind. 32 bit CRC being sent */
extern int Z_Rxcrc32; /* Display flag ind. 32 bit CRC being r-ed */
extern char Z_Attn[ZATTNLEN+1]; /* Attention string rx sends to tx on err */
extern int Z_Ctlesc; /* Encode control characters */
extern int Z_Lastsent; /* Character we sent last */
//extern int Z_Dirzap; /* Direct ZedZap (don't escape XON/XOFF) */
/* ------------------------------------------------------------------------- */
/* Z-Modem primitives (look p_zmmisc.c for them) */
/* ------------------------------------------------------------------------- */
void setalarm(int sec);
int zsendline(char c);
int zsbhdr(int type, char *hdr);
int zshhdr(int type, char *hdr);
int zsdata(const char *buf, int length, int frameend, long pos);
int zrdata(char *buf, int length, long pos);
int zgethdr(char *hdr);
void stohdr(char *hdr, long pos);
long rclhdr(char *hdr);
int tx_zmodem(s_protinfo *pi, bool caller);
int rx_zmodem(s_protinfo *pi, bool caller);
#endif
+223
View File
@@ -0,0 +1,223 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _S_MAIN_H_
#define _S_MAIN_H_
#define CALLOPT_FORCE 0x01
#define CALLOPT_INET 0x02
#include "io.h"
#include "nodelist.h"
#include "outbound.h"
#include "prot_common.h"
typedef enum session {
SESSION_UNKNOWN,
SESSION_FTSC,
SESSION_YOOHOO,
SESSION_EMSI,
SESSION_BINKP
} e_session;
typedef enum protocol {
PROT_NOPROT,
PROT_XMODEM,
PROT_ZMODEM,
PROT_ZEDZAP,
PROT_DIRZAP,
PROT_JANUS,
PROT_HYDRA,
PROT_TCP,
PROT_BINKP
} e_protocol;
typedef enum reqstat {
REQS_DISABLED, /* Freqs not supported by the system */
REQS_ALLOW, /* We will process file requests */
REQS_NOTALLOW /* Freqs TEMPORARY disabled for any reason */
} e_reqstat;
#define HRC_OK 0 /* No errors */
#define HRC_LOW_SPEED 1 /* Connect speed too low (shown it in EMSI) */
#define HRC_BAD_PASSWD 2 /* Pasword failure (shown it in EMSI) */
#define HRC_NO_ADDRESS 3 /* Expected address was not presented */
#define HRC_NO_PROTOS 4 /* No common protocols :( */
#define HRC_BUSY 5 /* All remote AKAs are busy */
#define HRC_FATAL_ERR 6 /* Any other fatal handshake error */
#define HRC_TEMP_ERR 7 /* Any other temporary handshake error */
#define HRC_OTHER_ERR 8 /* Any other error (e.g. timeout, NO CARRIER) */
typedef struct sysaddr {
s_faddr addr;
bool busy;
bool good;
int flags;
} s_sysaddr;
typedef struct {
char passwd[128];
char challenge[128];
int challenge_length;
bool cram_auth;
} s_session_passwd;
typedef struct sendopts {
int fnc:1, /* Convert outgoing file names to 8+3 format */
holdreq:1, /* Hold .REQ files? (file requests) */
holdhold:1, /* Hold files with HOLD flavor? */
holdfiles:1, /* Hold all files except netmail + arcmail */
holdxt:1, /* Hold all except netmail? */
holdall:1, /* Hold ALL trafic!? */
hydraRH1; /* Hydra RH1 mode (EMSI only) */
} s_sendopts;
/*
* Handhake protocols API
*/
typedef struct handshake_protocol
{
/*
* 1. Main pointers
*/
char *verbal_name;
char *author;
char *standard;
char *remote_data;
char *local_data;
e_protocol protocol;
void (*init)(struct handshake_protocol *THIS);
void (*deinit)(struct handshake_protocol *THIS);
int (*incoming_session)(struct handshake_protocol *THIS);
int (*outgoing_session)(struct handshake_protocol *THIS);
/*
* 2. Remote system information extract methods
*/
s_faddr* (*remote_address)(struct handshake_protocol *THIS);
char* (*remote_password)(struct handshake_protocol *THIS);
char* (*remote_sysop_name)(struct handshake_protocol *THIS);
char* (*remote_system_name)(struct handshake_protocol *THIS);
char* (*remote_location)(struct handshake_protocol *THIS);
char* (*remote_phone)(struct handshake_protocol *THIS);
char* (*remote_flags)(struct handshake_protocol *THIS);
char* (*remote_mailer)(struct handshake_protocol *THIS);
int (*remote_traffic)(struct handshake_protocol *THIS, s_traffic *dest);
/*
* 3. Local system information extract methods
*/
s_faddr* (*local_address)(struct handshake_protocol *THIS);
char* (*local_password)(struct handshake_protocol *THIS);
} s_handshake_protocol;
struct state
{
s_node node;
const s_modemport *modemport;
char *linename; /* Verbal line name (i.e. ttyS1, tcpip, etc.) */
time_t start_time; /* Session start time (e.g. connect time) */
e_tcpmode tcpmode; /* Current mode to work via TCP/IP */
e_session session; /* handshake type (EMSI, YooHoo, etc.) */
bool valid; /* This structure contain real information */
bool caller; /* Outgoing session */
bool protected; /* Password protected session? */
bool listed; /* Session with listed system? */
bool inet; /* We are working via TCP/IP now */
int session_rc; /* Session return code */
s_sendopts sopts; /* Our send options (hold arcmail, etc.) */
e_reqstat reqstat; /* Our file request processor status */
s_override override;
s_sess_stat sess_stat; /* Try counters, hold timers, etc. */
long connspeed;
long minspeed;
char *cidstr; /* Caller Phone/ID when we are answering */
char *peername; /* Remote peer name than using TCP/IP */
long peerport; /* Remote port number, we are connected to */
char *connstr;
char *inbound; /* Inbound directory for this session */
char *tinbound; /* Temporary inbound for this session */
s_traffic traff_send; /* Expected outgoing traffic */
s_traffic traff_recv; /* Expected incoming traffic */
s_handshake_protocol *handshake;
s_falist *mailfor; /* Remote valid addresses */
s_fsqueue queue; /* Send files queue */
};
typedef struct state s_state;
/* s_common.c */
int session_get_local_address(s_faddr *addr);
int session_get_remote_address(s_faddr *addr);
int session_get_remote_sysop(char **dest);
int session_get_remote_systname(char **const dest);
int session_get_remote_mailer(char **const dest);
int session_get_remote_phone(char **const dest);
int session_get_remote_location(char **const dest);
int session_is_remote_protected(void);
int session_is_remote_listed(void);
int session_get_callerid(char **const dest);
int session_get_connect(char **const dest);
int session_run_command(const char *execstr);
int override_get(s_override *dest, s_faddr addr, int line);
void init_state(s_state *pstate);
void deinit_state(s_state *pstate);
/* s_init.c */
int session_init_outgoing(void);
int session_init_incoming(void);
/* s_main.c */
extern s_state state;
s_faddr *session_get_bestaka(s_faddr addr);
int session_addrs_lock(s_sysaddr *addrs, int anum);
int session_addrs_add(s_sysaddr **addrs, int *anum, s_faddr addr);
int session_addrs_check(s_sysaddr *addrs, int anum, const char *passwd,
const char *challenge, int challenge_length);
int session_addrs_to_falist(s_sysaddr *addrs, int anum, s_falist **dest);
int session_addrs_check_genuine(s_sysaddr *addrs, int anum, s_faddr expected);
int session_check_speed(void);
int session_check_addr(s_faddr addr);
int session_get_password(s_faddr addr, char *buffer, size_t buflen);
int session_remote_lookup(s_sysaddr *addrs, int anum);
void session_remote_log_status(void);
int session_check_password(s_faddr addr, const char *passwd);
int session_set_inbound(void);
void session_set_freqs_status(void);
void session_set_send_options(void);
void session_set_send_files(void);
int session_create_files_queue(s_sysaddr *addrs, int anum);
int session_traffic_set_incoming(s_traffic *dest);
int session_traffic_set_outgoing(s_traffic *dest);
void session_traffic(void);
void session_update_history(s_traffic *send, s_traffic *recv, int rc);
int session(void);
/* sess_call.c */
int call_system(s_faddr addr, const s_bforce_opts *opts);
int call_system_modem(void);
int call_system_tcpip(void);
/* sess_answ.c */
int answ_system(e_session type, char *connstr, int inetd);
/* sess_stat.c */
void session_stat_reset_counters(s_sess_stat *stat);
int session_stat_get(s_sess_stat *stat, s_faddr *addr);
int session_stat_apply_diff(s_faddr addr, s_sess_stat stat);
int session_stat_update(s_faddr *addr, s_sess_stat *stat, bool caller, int rc);
#endif
+258
View File
@@ -0,0 +1,258 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _UTIL_H_
#define _UTIL_H_
#define DEFAULT_ZONE 2
#define DEFAULT_NET 5020
#define DEFAULT_NODE 0
#define TIMEVEC_MAX_ELEMENTS 10
enum { ADDR_EQ, ADDR_GT, ADDR_LT };
enum {
PLOCK_OK,
PLOCK_EXIST,
PLOCK_ERROR,
PLOCK_OURLOCK
};
enum day
{
DAY_MONDAY,
DAY_TUESDAY,
DAY_WEDNESDAY,
DAY_THURSDAY,
DAY_FRIDAY,
DAY_SATURDAY,
DAY_SUNDAY,
DAY_ANY,
DAY_WORKDAY,
DAY_WEEKEND,
DAY_UNDEF
};
typedef struct faddr {
bool inetform; /* Is address in domain form? */
int zone; /* -1 value means any?! */
int net;
int node;
int point;
char domain[BF_MAXDOMAIN+1];
} s_faddr;
typedef struct timeint {
enum day day_beg;
enum day day_end;
long beg;
long end;
} s_timeint;
typedef struct timevec {
int num;
s_timeint tvec[TIMEVEC_MAX_ELEMENTS];
} s_timevec;
typedef struct message {
int attr;
int cost;
time_t time;
s_faddr orig;
s_faddr dest;
char namefrom[36];
char nameto[36];
char subject[72];
char *text;
char *tagline;
char *tearline;
char *origin;
} s_message;
typedef struct packet {
s_faddr orig;
s_faddr dest;
int baud;
char password[8+1];
s_message *msgs;
int n_msgs;
} s_packet;
enum
{
FILELOCK_CLEAR,
FILELOCK_READ,
FILELOCK_WRITE
};
#define RECODE_MAX_CHAR 255
typedef struct recode_table {
const char *filename;
char table[RECODE_MAX_CHAR+1];
} s_recode_table;
#undef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#undef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#undef ABS
#define ABS(a) (((a) < 0) ? -(a) : (a))
#define SET_LAT_A_Z "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define SET_LAT_a_z "abcdefghijklmnopqrstuvwxyz"
#define SET_DEC "0123456789"
#define SET_HEX "0123456789ABCDEFabcdef"
#define SET_OCT "01234567"
#define CRC16TEST(crc) ((crc) == 0xf0b8)
#define CRC32TEST(crc) ((crc) == 0xdebb20e3L)
#define updcrc16(cp, crc) (TableCRC16Xmodem[(((int)(crc) >> 8) & 0xff)] ^ ((crc) << 8) ^ (cp))
#define updcrc32(cp, crc) (TableCRC32CCITT[((int)(crc) ^ cp) & 0xff] ^ (((crc) >> 8) & 0x00FFFFFF))
#define localtogmt(t) ((t) - time_gmtoffset()*60)
#define gmttolocal(t) ((t) + time_gmtoffset()*60)
#define timer_set(ptr, v) (time_settimer(ptr, v))
#define timer_expired(tm) (time(NULL) > (tm))
#define timer_running(tm) ((tm) > 0)
#define timer_timeleft(tm) (time_timeleft(tm))
#define recode_file_out(str) recode(str, &recode_table_out, conf_string(cf_recode_file_out));
#define recode_file_in(str) recode(str, &recode_table_in, conf_string(cf_recode_file_in));
#define recode_intro_in(str) recode(str, &recode_table_in, conf_string(cf_recode_intro_in));
extern s_recode_table recode_table_in;
extern s_recode_table recode_table_out;
extern unsigned long TableCRC32CCITT[];
extern unsigned short TableCRC16Xmodem[];
extern unsigned short TableCRC16CCITT[];
/* u_crc.c */
unsigned long getcrc32ccitt(const unsigned char *buffer, size_t buflen);
unsigned short getcrc16xmodem(const unsigned char *buffer, size_t buflen);
unsigned short getcrc16ccitt(const unsigned char *buffer, size_t buflen);
/* u_file.c */
int file_lock(FILE *fp, bool exclusive);
void file_unlock(FILE *fp);
int file_lock_wait(FILE *fp, bool exclusive);
bool file_name_issafe(int ch);
char *file_name_makesafe(char *filename);
char *file_getname(char *filename);
char *file_gettmp(void);
char *file_get_dos_name(char *buffer, const char *filename);
bool is_directory(const char *dirname);
bool is_regfile(const char *filename);
int directory_create(const char *dirname, mode_t access_mode);
FILE *file_open(const char *path, const char *mode);
int file_close(FILE *stream);
/* u_ftn.c */
int ftn_addrparse(s_faddr *addr, const char *s, bool wildcard);
char *ftn_addrstr_fido(char *buf, s_faddr addr);
char *ftn_addrstr_inet(char *buf, s_faddr addr);
char *ftn_addrstr(char *buf, s_faddr addr);
int ftn_addrcomp(s_faddr addr1, s_faddr addr2);
int ftn_addrcomp_logic(s_faddr addr1, int operator, s_faddr addr2);
int ftn_addrcomp_mask(s_faddr addr, s_faddr mask);
int ftn_addrsmetric(s_faddr addr1, s_faddr addr2);
/* u_md5.c */
void md5_get(const unsigned char *data, size_t length, unsigned char *digest);
void md5_cram_get(const unsigned char *secret, const unsigned char *challenge,
int challenge_length, unsigned char *digest);
/* u_misc.c */
void *xmalloc(size_t size);
void *xrealloc(void *buf, size_t size);
void *xmemcpy(const void *buffer, size_t buflen);
char *strparse(char *str, char **next, int quoted);
int strcasemask(const char *str, const char *mask);
int checkmasks(const char *masks, const char *str);
char *buffer_putlong(char *buffer, long val);
char *buffer_putint(char *buf, int val);
long buffer_getlong(const char *buf);
int buffer_getint(const char *buf);
void printf_usage(const char *ident, const char *fmt, ...);
/* u_pkt.c */
int pkt_createpacket(const char *pktname, const s_packet *pkt);
/* u_plock.c */
int plock_check(const char *lockname);
int plock_create(const char *lockname);
int plock_remove(const char *lockname);
int plock_link(const char *lockname, const char *tmpname);
/* u_recode.c */
char *recode(char *src, s_recode_table *tab, const char *filename);
/* u_string.c */
char *xstrcpy(const char *src);
char *xstrcat(char *src, const char *add);
char *strnxcpy(char *dst, const char *src, size_t len);
char *strnxcat(char *dst, const char *src, size_t len);
char *string_token(char *str, char **next, const char *delim, int quoted);
char *string_chomp(char *str);
const char *string_casestr(const char *string, const char *substr);
const char *string_casechr(const char *str, int ch);
char *string_toupper(char *str);
char *string_tolower(char *str);
bool string_isupper(const char *str);
bool string_islower(const char *str);
char *string_trimright(char *str);
char *string_trimleft(char *str);
char *string_trimboth(char *str);
char *string_printable_buffer(const char *buffer, size_t buflen);
const char *string_printable(const char *str);
char *string_replchar(char *str, char oldchar, char newchar);
int string_parse(char **dest, int items, char *str, int separator);
int string_parse_regular(char **dest, int items, char *str);
char *string_translate(const char *str, const char *find, const char *repl);
char *string_humansize(char *buffer, size_t size);
int string_get_escape(char **pptr);
int string_dequote(char *dst, char *src);
char *string_concat(const char *str, ...);
void string_bin_to_hex(char *string, const char *binptr, int binlen);
int string_hex_to_bin(char *binptr, const char *string);
bool string_is_empty(const char *string);
/* u_time.c */
int time_settimer(time_t *timer, int value);
int time_timerout(time_t timer);
int time_timeleft(time_t timer);
int time_elapsed(time_t since_time);
char *time_string_format(char *buffer, size_t buflen, const char *fmt, time_t t);
char *time_string_long(char *buffer, size_t buflen, time_t t);
char *time_string_log(char *buffer, size_t buflen, time_t t);
char *time_string_msghdr(char *buffer, time_t t);
long time_gmtoffset(void);
char *time_string_gmtoffset(char *buffer);
char *time_string_timer(char *buffer, int timer);
char *time_string_approx_interval(char *buffer, int seconds);
int time_check(const char *str, struct tm *now);
int time_checkintervals(const char *timestr, struct tm *now);
int timevec_add(s_timevec *dest, int day_beg, int day_end, long beg, long end);
int timevec_parse(s_timevec *dest, const char *str);
int timevec_parse_list(s_timevec *dest, const char *str);
int timevec_check(const s_timevec *tv, const struct tm *now);
char *timevec_string(char *buffer, const s_timevec *tv, size_t buflen);
bool timevec_isdefined(const s_timevec *tv);
bool timevec_isnow(const s_timevec *tv, const struct tm *now);
#endif /* _UTIL_H_ */
+33
View File
@@ -0,0 +1,33 @@
/*
* binkleyforce -- unix FTN mailer project
*
* Copyright (c) 1998-2000 Alexander Belkin, 2:5020/1398.11
*
* This program 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 of the License, or
* (at your option) any later version.
*
* $Id$
*/
#ifndef _VERSION_H_
#define _VERSION_H_
#define BF_PRODCODE 0xfe
#define BF_NAME "binkleyforce"
#define BF_RDATE "n/a"
#define BF_VERSION RELEASE_VERSION
#define BF_CDATE __DATE__ __TIME__
#define BF_REG "free software"
#define BF_COPYRIGHT "(c) 1997-2000 by Alexander Belkin"
#define BF_BANNERVER BF_NAME" "BF_VERSION"/"BF_OS
#define BF_EMSI_NUM "fe"
#define BF_EMSI_NAME BF_NAME
#define BF_EMSI_VER BF_VERSION"/"BF_OS
#define BF_EMSI_REG BF_REG
#endif
+251
View File
@@ -0,0 +1,251 @@
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5 (mit/util/scripts/install.sh).
#
# Copyright 1991 by the Massachusetts Institute of Technology
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of M.I.T. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. M.I.T. makes no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
chmodcmd=""
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0