Changes for eftp supervisor based call control

This commit is contained in:
he 1999-07-25 21:55:25 +00:00
parent b55ea60dd1
commit ba28ec7ad9
14 changed files with 413 additions and 321 deletions

View File

@ -1,4 +1,4 @@
/* $Id: CHANGES,v 1.3 1999/06/30 22:00:27 he Exp $
/* $Id: CHANGES,v 1.4 1999/07/25 21:55:25 he Exp $
# Change log for eftp4Linux
#
# [new] means 'new feature added'
@ -18,7 +18,23 @@
#
$Log: CHANGES,v $
Revision 1.4 1999/07/25 21:55:25 he
Changes for eftp supervisor based call control
- [chg] eft_i4l.c: Replaced calls to external programmes (isdnctrl,x25_route,
ifconfig, scripts) by directly calling ioctl()'s.
- [new] eft_i4l.c: Support for supervisor based isdn call control.
- [chg] eftp.c: Supporting above supervisor based isdn call control.
(prepares eftp for use by non-root users).
- [chg] eftp_setup: Removed, no longer needed with above changes.
- [fix] eftd.sh: Moved isdnloop setup before iface setup such that script
will also work if no other HL drivers are present.
- [chg] Makefile: Dummy "install" target to keep isdn4k-utils root makefile
happy.
Revision 1.3 1999/06/30 22:00:27 he
Version 0.0.11
===============

View File

@ -1,10 +1,10 @@
# $Id: Makefile,v 1.8 1999/07/12 10:35:29 keil Exp $
# $Id: Makefile,v 1.9 1999/07/25 21:55:27 he Exp $
SHELL = /bin/sh
CVS = cvs -z 4
SCRIPTS = scripts/eftd.sh scripts/eftp.sh scripts/eftp_setup
SCRIPTS = scripts/eftd.sh scripts/eftp.sh
#
#additions to the CHANGES file shall automatically increase the compiled-in
@ -13,9 +13,9 @@ SCRIPTS = scripts/eftd.sh scripts/eftp.sh scripts/eftp_setup
E4L_EXTRA_VERSION_DEP := $(shell pwd)/CHANGES
export E4L_EXTRA_VERSION_DEP
CONF_DEPS = ./configure scripts/eftd.sh scripts/eftp.sh scripts/eftp_setup src/config.h Rules.make
CONF_DEPS = ./configure scripts/eftd.sh scripts/eftp.sh src/config.h Rules.make
#this target is requested from isdn4k-utils default target
#this target is required by the isdn4k-utils root makefile's default target
all: $(CONF_DEPS)
make -C src
@ -24,14 +24,12 @@ really_all: $(CONF_DEPS)
config src/config.h Rules.make $(SCRIPTS): configure
./configure
chmod a+x scripts/eftd.sh scripts/eftp.sh scripts/eftp_setup
chmod a+x scripts/eftd.sh scripts/eftp.sh
configure: configure.in
autoconf
permissions: scripts/eftd.sh scripts/eftp.sh scripts/eftp_setup
chown root scripts/eftp_setup
chmod u+s scripts/eftp_setup
permissions: scripts/eftd.sh scripts/eftp.sh
chmod a+x $(SCRIPTS)
clean:
@ -48,9 +46,12 @@ distclean: clean
configureclean: distclean
rm -f configure
#
# This (dummy) target is required by the isdn4k-utils
# root makefile but not implemented yet.
#
install:
echo "dummy install"
@echo "NOTE: eurofile install not yet implemented. Install by hand for now!"
commit: distclean
$(CVS) commit .

View File

@ -1,4 +1,4 @@
$Id: TODO,v 1.2 1999/06/29 18:37:14 he Exp $
$Id: TODO,v 1.3 1999/07/25 21:55:28 he Exp $
Important:
@ -11,20 +11,21 @@ Important:
X.25 routes are needed to be set up before the isdn connection
can be set up, which is currently done by the eftp.sh shell script
which needs to be run from root. The latter is not acceptable for a
general purpose release.
general purpose release. (in progress)
Not showstoppers, but should be done before a possible stable release:
- remove old execve()/script rleated stuff from setup/autoconf
- more casefix testing with new mangeling method
- selectivly and automatically (for filesystems not supporting
symlinks) disallow symlink-based transfer name database
lookup
- certain disconnect scenarios result in error/warning
messages which are harmless, but might confuse novice users.
(in particualar, release/wait for release seems to be buggy)
- improve autoconf readline support (support non-default
locations of libreadline and lib[n]curses).
- integrate source tree to isdn4k-utils CVS repository.
- 'make install', with reasonable default config files.
- make eftp command input working when stdin is a pipe.
- autoconf is somewhat ugly as several configuration variable

4
eurofile/configure vendored
View File

@ -1552,7 +1552,7 @@ done
ac_given_srcdir=$srcdir
ac_given_INSTALL="$INSTALL"
trap 'rm -fr `echo "scripts/eftp_setup scripts/eftp.sh scripts/eftd.sh
trap 'rm -fr `echo "scripts/eftp.sh scripts/eftd.sh
src/config.h Rules.make" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
EOF
cat >> $CONFIG_STATUS <<EOF
@ -1650,7 +1650,7 @@ EOF
cat >> $CONFIG_STATUS <<EOF
CONFIG_FILES=\${CONFIG_FILES-"scripts/eftp_setup scripts/eftp.sh scripts/eftd.sh
CONFIG_FILES=\${CONFIG_FILES-"scripts/eftp.sh scripts/eftd.sh
src/config.h Rules.make"}
EOF
cat >> $CONFIG_STATUS <<\EOF

View File

@ -1,5 +1,5 @@
dnl Process this file with autoconf to produce a configure script.
dnl $Id: configure.in,v 1.4 1999/06/30 22:56:20 he Exp $
dnl $Id: configure.in,v 1.5 1999/07/25 21:55:30 he Exp $
AC_INIT(COPYING.authlib)
@ -86,5 +86,5 @@ AC_SUBST(CONFIG_EFTD)
AC_SUBST(CONFIG_EFTP_READLINE)
AC_SUBST(CONFIG_EFTD_WUAUTH)
AC_SUBST(HAVE_GETDELIM)
AC_OUTPUT(scripts/eftp_setup scripts/eftp.sh scripts/eftd.sh
AC_OUTPUT(scripts/eftp.sh scripts/eftd.sh
src/config.h Rules.make)

View File

@ -1,7 +1,7 @@
#!/bin/sh
@EFT_AUTOCONF_WARNING@
#
# generated from $Id: eftd.sh.in,v 1.1 1999/06/30 17:02:14 he Exp $
# generated from $Id: eftd.sh.in,v 1.2 1999/07/25 21:55:35 he Exp $
#
# Henner Eisen 1998
#
@ -162,6 +162,31 @@ case "$1" in
set -- $EFT_SERVER_MSN
if [ x$EFTD_WITH_LOOP != x ]; then
# for local testing of x.25 connections we load the isdnloop driver
$INSMOD -m isdnloop isdnloop_id=eft_loop -o eft_loop> /var/modules/isdnloop.map
$LOOPCTRL -d eft_loop start dss1 00000 $EFT_CLIENT_MSN $EFT_SERVER_MSN
sleep 1
# A local outgoing interface operating on top of (bound to) the
# isdnloop driver. X.25 call requests the X.25 address "1"
# will be routed through the outgoing interface eft_lout. That call
# request will be looped back to our own machine (and received at the
# incoming interface created for the eft daemon).
$ISDNCTRL addif eft_lout
$ISDNCTRL eaz eft_lout $EFT_CLIENT_MSN
$ISDNCTRL addphone eft_lout out $1
$ISDNCTRL l2_prot eft_lout x75i
$ISDNCTRL encap eft_lout x25iface
$ISDNCTRL huptimeout eft_lout 200
# $ISDNCTRL huptimeout eft_lout 30
$ISDNCTRL dialmode eft_lout auto
$ISDNCTRL bind eft_lout eft_loop,0
ifconfig eft_lout up
$X25ROUTE add 1/1 eft_lout
fi
for i in $ISDNIF_IN; do
# interface alreay defined?
if { cat /proc/net/dev | grep $i > /dev/null; } ; then
@ -227,31 +252,6 @@ case "$1" in
EFTD_OPTIONS="$EFTD_OPTIONS -b $EFTD_LOG_FILENAME"
fi
if [ x$EFTD_WITH_LOOP != x ]; then
# for local testing of x.25 connections we load the isdnloop driver
$INSMOD -m isdnloop isdnloop_id=eft_loop -o eft_loop> /var/modules/isdnloop.map
$LOOPCTRL -d eft_loop start dss1 00000 $EFT_CLIENT_MSN $EFT_SERVER_MSN
sleep 1
# A local outgoing interface operating on top of (bound to) the
# isdnloop driver. X.25 call requests the X.25 address "1"
# will be routed through the outgoing interface eft_lout. That call
# request will be looped back to our own machine (and received at the
# incoming interface created for the eft daemon).
$ISDNCTRL addif eft_lout
$ISDNCTRL eaz eft_lout $EFT_CLIENT_MSN
$ISDNCTRL addphone eft_lout out $EFT_SERVER_MSN
$ISDNCTRL l2_prot eft_lout x75i
$ISDNCTRL encap eft_lout x25iface
$ISDNCTRL huptimeout eft_lout 200
# $ISDNCTRL huptimeout eft_lout 30
$ISDNCTRL dialmode eft_lout auto
$ISDNCTRL bind eft_lout eft_loop,0
ifconfig eft_lout up
$X25ROUTE add 1/1 eft_lout
fi
if [ x"$EFTD_DEBUG" = "x1" ] ; then
echo "Starting EUROFile daemon under gdb."
# remove a possibly present '-m' option

View File

@ -1,7 +1,7 @@
#!/bin/sh
@EFT_AUTOCONF_WARNING@
#
# generated from $Id: eftp.sh.in,v 1.1 1999/06/30 17:02:15 he Exp $
# generated from $Id: eftp.sh.in,v 1.2 1999/07/25 21:55:37 he Exp $
#
# This opens an eurofile session to a remote eurofile server
#
@ -153,7 +153,7 @@ $X25ROUTE add 0/0 isdnxout
cd /tmp
eftpbin=@EFT_TOPDIR@/src/eftp/eftp
su $EFT_CLIENT_USERID -c "$eftpbin -u $2"
su $EFT_CLIENT_USERID -c "$eftpbin -x '' -u $2"
$ISDNCTRL hangup isdnxout
$X25ROUTE del 0/0 isdnxout
@ -166,3 +166,6 @@ if [ $DIALOUT = localhost ]; then
@RMMOD@ isdnloop
fi

View File

@ -1,161 +0,0 @@
#! @PERL@
#
@EFT_AUTOCONF_WARNING@
#
# generated from $Id: eftp_setup.in,v 1.1 1999/06/30 17:02:16 he Exp $
#
# Helper script for eftp that sets up x.25 network interfaces connectable
# to a dedicated remote isdn number.
#
# (derived fron eftp.sh. Not yet finished and therefor neither usable
# nor used yet)
#
# This must run suid root, thus it is written in perl for security reasons.
# You might want to restrict usage of this script to a selected group
# of people by setting appropriate group execute permissions when installing
# this file.
#
# External programmes are referenced by absolute pathnames for
# security reasons.
#
# Usage: eftp_setup PHONE_NUMBER FILE_DESCRIPTOR
#
# PHONE_NUMBER can also be "localhost" in which case a local loopback
# connection on top of the isdnloop driver will be used.
#
# FILE_DESCRIPTOR should be associated with a bidirectional pipe which
# will be used to syncronize this script with its parent process.
#
#
# There must be no x25 route set up before this script is called.
#
# For this script to work, the basic setup for the isdn and x25
# drivers must be done. The following three modules must be loaded
# (or compiled into the kernel) before calling this script:
#
# "x25" (insmod x25)
# "isdn" (insmod isdn)
# An isdn HL driver which supports l2_prot x75i (i.e. insmod hisax ...)
#
#******************************
#
# Security Consideration:
# perl does its best to detect any hidden gotchas that might compromise
# security. However, as perl does not know about the security of external
# programmes, it cannot protect from security traps hidden inside external
# programmes. We kill the whole environment (killing MODPATH is essential).
#
foreach $key (keys %ENV) {
delete $ENV{$key};
}
#system "printenv";
#
#Scan configuration file for own msn (used for outgoing eft
# connection and MSN of local server (used as destination when the
# symolic remote address "localhost" is specified).
sub my_system {
# print @_,"\n";
system @_;
}
setpgrp 0, 0;
open MSN, "@I4LCONFDIR@/eft.conf"
or die "Can't open: $!\n";
while(<MSN>){
SWITCH: {
if (/^EFT_CLIENT_MSN=([0-9]*)/) { $EFT_CLIENT_MSN = $1;
last SWITCH; }
if (/^EFT_SERVER_MSN=([0-9]*)/) { $EFT_SERVER_MSN = $1;
last SWITCH; }
};
};
$DIALOUT=$ARGV[0];
$sfd=$ARGV[1];
$sfdw=$ARGV[2];
print "client=", $EFT_CLIENT_MSN, "\n";
print "server=", $EFT_SERVER_MSN, "\n";
print "dial=", $DIALOUT, "\n";
print "pipe=", $sfd, "\n";
print "wpipe=", $sfdw, "\n";
#
# pipe used to syncronize this helper script with the calling process
#
open syncpipe, "<&=$sfd";
open wsyncpipe, ">&=$sfdw";
$_=$DIALOUT;
if(/^localhost$/){
# for local testing of x.25 connections we load the isdnloop driver
# beware: User settable MODPATH compromises security
my_system "@INSMOD@ isdnloop isdnloop_id=isdnfake";
# my_system "@INSMOD@ -m isdnloop isdnloop_id=isdnfake > /var/modules/isdnloop.map";
my_system "@LOOPCTRL@ -d isdnfake start dss1 00000 $EFT_CLIENT_MSN $EFT_SERVER_MSN";
sleep 1;
# A local outgoing interface operating on top of (and bound to) the
# isdnloop driver. X.25 call requests to arbitray X.25 addresses will be
# routet to the outgoing interface isdnxlo1. That call request will be
# looped back to our own machine (and received at the incoming
# interface created for the eft daemon).
my_system "@ISDNCTRL@ addif isdnxout";
my_system "@ISDNCTRL@", "eaz", "isdnxout", $EFT_CLIENT_MSN;
my_system "@ISDNCTRL@", "addphone", "isdnxout", "out", $EFT_SERVER_MSN;
my_system "@ISDNCTRL@ l2_prot isdnxout x75i";
my_system "@ISDNCTRL@ encap isdnxout x25iface";
my_system "@ISDNCTRL@ huptimeout isdnxout 1800";
my_system "@ISDNCTRL@ status isdnxout on";
my_system "@ISDNCTRL@ bind isdnxout isdnfake,0";
} elsif(/[0-9]/) {
# outgoing interface operating on top of real HL driver (i.e. HiSax).
# A HL driver must already be loaded and support l2_prot x75i.
# This will set up a real isdn connection and therefore might leave
# traces on your phone bill.
# Outgoing Interface on top of HiSax to remote server
my_system "@ISDNCTRL@ addif isdnxout";
my_system "@ISDNCTRL@ eaz isdnxout", $EFT_CLIENT_MSN;
my_system "@ISDNCTRL@ addphone isdnxout out ", $DIALOUT;
my_system "@ISDNCTRL@ l2_prot isdnxout x75i";
my_system "@ISDNCTRL@ encap isdnxout x25iface";
my_system "@ISDNCTRL@ huptimeout isdnxout 110";
my_system "@ISDNCTRL@ secure isdnxout on";
my_system "@ISDNCTRL@ status isdnxout on";
} else {
print "incorrect remote number: \"$DIALOUT\"\n";
exit 1;
}
#~kernel/eftp4linux-work/scripts/oops.sh
my_system "@IFCONFIG@ isdnxout up";
my_system "@X25ROUTE@ add 0/0 isdnxout";
#tell parent process that we are ready by writing an x25_addr
# (currently the empty address/empty string) to the pipe
syswrite wsyncpipe, "\0", 1;
close wsyncpipe;
#wait for parent process to finish or to close the connection
#(block by reading from the pipe until parent process closes it).
sysread syncpipe, $dummy, 1;
print "parent sent ", $dummy, "\n";
my_system "@ISDNCTRL@ hangup isdnxout";
my_system "@X25ROUTE@ del 0/0 isdnxout";
my_system "@IFCONFIG@ isdnxout down";
my_system "@ISDNCTRL@ delif isdnxout";
$_=$DIALOUT;
if(/^localhost$/){
sleep 2;
my_system "@RMMOD@ isdnloop";
}

View File

@ -1,4 +1,4 @@
/* $Id: access.c,v 1.1 1999/06/30 17:18:08 he Exp $ */
/* $Id: access.c,v 1.2 1999/07/25 21:55:43 he Exp $ */
/* Copyright 1997 by Henner Eisen
This code is free software; you can redistribute it and/or
@ -424,7 +424,9 @@ int tdu_wait_for_end_access(struct tdu_fsm * fsm, struct timeval * timeout)
int tdu_end_access_received(struct tdu_fsm *fsm)
{
tdu_printf(TDU_LOG_TRC, "tdu_end_access_received()\n");
#if 0
tdu_printf(TDU_LOG_AP3, "tdu_end_access_received()\n");
#endif
if( fsm->assoc.slave_handler ){
tdu_send_response_pos(fsm,TDU_CI_T_END_ACCESS);
fsm->assoc.handler = fsm->assoc.slave_handler;

View File

@ -1,4 +1,4 @@
/* $Id: assoc.c,v 1.1 1999/06/30 17:18:09 he Exp $ */
/* $Id: assoc.c,v 1.2 1999/07/25 21:55:47 he Exp $ */
/*
Copyright 1997 by Henner Eisen
@ -345,7 +345,9 @@ void tdu_assoc_set_idle(struct tdu_fsm * fsm)
static void tdu_release_received(struct tdu_fsm * fsm)
{
tdu_printf(TDU_LOG_TRC, "tdu_release_received()\n");
#if 0
tdu_printf(TDU_LOG_AP3, "tdu_release_received()\n");
#endif
if( fsm->regime_handler == & fsm->assoc.handler ){
tdu_send_response_pos(fsm, TDU_CI_T_RELEASE);
fsm->idle.handler = tdu_released;

View File

@ -1,6 +1,6 @@
/* $Id: eft_i4l.c,v 1.1 1999/06/30 17:18:16 he Exp $ */
/* $Id: eft_i4l.c,v 1.2 1999/07/25 21:55:48 he Exp $ */
/*
* isdn4linux implementation specific functions
* isdn4linux implementation dependent functions
*/
#include <string.h>
@ -12,14 +12,16 @@
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <net/if.h>
#include <linux/x25.h>
#include <linux/isdn.h>
#include <linux/isdnif.h>
#include <errno.h>
#include "../config.h"
#include <eft.h>
/*
* get the remote phone number corresponding to the connected socket.
* Get the remote phone number corresponding to the connected socket.
* isdn_no must be an array of at least 21 chacters
*/
int eft_get_peer_phone(unsigned char * isdn_no, int sk)
@ -32,17 +34,17 @@ int eft_get_peer_phone(unsigned char * isdn_no, int sk)
isdn_no[0] = 0;
#ifdef IIOCNETGPN
/*
* If this experimental IOCTL is supported, the peer number is really
* determined
* from the network interface
*/
fd = open("/dev/isdninfo",O_RDONLY);
if ( fd < 0 ){
perror("eft_get_peer_phone:open(/dev/isdninfo)");
return -1;
}
#ifdef IIOCNETGPN
/*
* This IOCTL is supported in recent i4l-cvs version and in kernel 2.3.6.
* The peer number is really determined from the network interface
*/
d = eft_get_device(dev, EFT_DEV_NAME_LEN, sk);
if ( ! d ){
fprintf(stderr,"eft_get_peer_phone: unable to figure out "
@ -111,119 +113,254 @@ if( ! try_first_channel ) return 0;
}
/*
* configure isdn network devices for outgoing eft connection
* Configure isdn network devices for outgoing eft connection
*/
static int sync_pipe_r=-1;
static int sync_pipe_w=-1;
int eft_get_x25route(struct sockaddr_x25 * x25addr, char * isdn_no)
int eft_get_x25route(struct sockaddr_x25 * x25addr,
struct x25_route_struct *x25_route, char * isdn_no)
{
int filedes_r[2], filedes_w[2], err;
#define FD_STR_SIZE 25
char *args[5], fd_str_r[FD_STR_SIZE],
fd_str_w[FD_STR_SIZE], *env[1];
pid_t pid;
int s=-1, ifd=-1, filedes[2], err;
char * addr = "", if_name[255]="eftpout0";
isdn_net_ioctl_phone phone;
isdn_net_ioctl_cfg cfg;
struct ifreq ifr;
/*
* By convention, the symbolic isdn address "localhost" is
* mapped to x25 address "1" and the eftd.sh setup script
* may already have configured a corresponding interface and an
* mapped to x25 address "1" and we assume that an external setup
* script has already configured a corresponding interface and an
* x25 route.
*/
if( strcmp(isdn_no, "localhost") == 0 ) {
strcpy(x25addr->sx25_addr.x25_addr, "1");
/* don't set proper device name such that this magic route is
not accessible from caller */
x25_route->device[0] = 0;
return 0;
}
/* pipe for later telling the waiting parent to release the route */
if(pipe(filedes)){
perror("eft_get_x25route():pipe()");
return -1;
}
sync_pipe_r=filedes[0];
sync_pipe_w=filedes[1];
if(pipe(filedes_r)){
perror("eft_setup_route():pipe()");
return -1;
}
sync_pipe_r=filedes_r[0];
if(pipe(filedes_w)){
perror("eft_setup_route():pipe()");
return -1;
}
sync_pipe_w=filedes_w[1];
pid = fork();
if( pid<0 ){
perror("eft_setup_route():fork()");
return -1;
} else if( pid > 0 ) {
/* parent process */
printf("waiting for set up\n");
close(filedes_w[0]);
close(filedes_r[1]);
err=read(sync_pipe_r,x25addr->sx25_addr.x25_addr,
sizeof(x25_address));
if( err < 1 ){
perror("eft_setup_route():parent read sync_pipe");
return -1;
} else {
x25addr->sx25_addr.x25_addr[err-1]=0;
printf("set up successful, address \"%s\", len=%d\n",
x25addr->sx25_addr.x25_addr, err-1);
/*FIXME: we should read the x25address from the pipe*/
strcpy(x25addr->sx25_addr.x25_addr, "");
return 0;
}
if ((s = socket(PF_X25, SOCK_SEQPACKET, 0)) < 0 ) {
perror("eft_get_x25route: socket");
return 1;
}
memset(&cfg,0,sizeof(cfg));
strcpy(cfg.name, if_name);
if( (ifd=open("/dev/isdnctrl",O_RDWR)) < 0){
perror("open isdnctrl");
err = -1;
goto error;
};
if( ioctl(ifd, IIOCNETAIF, if_name) ){
perror("addif");
err = -1;
} else {
/* child process */
/* FIXME: locate this script outside of eftp4linux source tree */
args[0] = CONFIG_EFT_TOPDIR "/scripts/eftp_setup";
args[1] = isdn_no;
err = snprintf(fd_str_w,FD_STR_SIZE,"%d",filedes_w[0]);
args[2] = fd_str_w;
err = snprintf(fd_str_r,FD_STR_SIZE,"%d",filedes_r[1]);
args[3] = fd_str_r;
args[4] = NULL;
env[0] = NULL;
close(filedes_w[1]);
close(filedes_r[0]);
execve(args[0],args,env);
perror("execve");
exit(1);
if ( ioctl(ifd, IIOCNETGCF, &cfg) ){
perror("get_cfg");
err = -1;
goto error_delif;
}
/* FIXME: hard coded MSN, should be read from config file */
strncpy(cfg.eaz, "3904300", sizeof(cfg.eaz));
cfg.eaz[sizeof(cfg.eaz)-1] = 0;
cfg.l2_proto = ISDN_PROTO_L2_X75I;
cfg.dialmax = 1;
cfg.secure = 1;
cfg.onhtime = 200;
cfg.p_encap = ISDN_NET_ENCAP_X25IFACE;
#ifdef ISDN_NET_DM_AUTO
cfg.dialmode = ISDN_NET_DM_AUTO;
#endif
if ( ioctl(ifd, IIOCNETSCF, &cfg) ){
perror("set_cfg");
err = -1;
ioctl(ifd, IIOCNETDIF, if_name);
goto error_delif;
}
strcpy(phone.name, if_name);
phone.outgoing = 1;
strncpy(phone.phone, isdn_no, ISDN_MSNLEN);
phone.phone[ISDN_MSNLEN-1] = 0;
if( ioctl(ifd, IIOCNETANM, &phone) ){
perror("add_phone");
err = -1;
goto error_delif;
}
/* ifconfig up */
strcpy(ifr.ifr_name, if_name);
if (ioctl(s, SIOCGIFFLAGS, &ifr) ) {
perror("SIOCAGIFFLAGS");
err = -1;
goto error_delif;
}
ifr.ifr_flags |= IFF_UP;
if (ioctl(s, SIOCGIFFLAGS, &ifr) ) {
perror("SIOCAGIFFLAGS");
err = -1;
goto error_delif;
} else {
ifr.ifr_flags |= IFF_UP;
if (ioctl(s, SIOCSIFFLAGS, &ifr) ) {
perror("SIOCASIFFLAGS");
err = -1;
goto error_ifdown;
}
strcpy(x25_route->address.x25_addr, addr);
x25_route->sigdigits = strlen(addr);
strcpy(x25_route->device, if_name);
printf( "adding route %s, sig=%d\n",addr,x25_route->sigdigits);
if (ioctl(s, SIOCADDRT, x25_route) ) {
perror("SIOCADDRT");
err = -1;
goto error_ifdown;
}
strcpy(x25addr->sx25_addr.x25_addr, addr);
err = 0;
error_ifdown:
if( err ) {
ifr.ifr_flags &= ~IFF_UP;
ioctl(s, SIOCSIFFLAGS, &ifr);
}
}
error_delif:
if(err) ioctl(ifd, IIOCNETDIF, if_name);
}
return -1;
error:
close(ifd);
close(s);
return err;
}
/*
* wait for request from child to release x25 route
*/
int eft_wait_release_route()
{
char dummy[1];
close(sync_pipe_w);
sync_pipe_w = -1;
/* printf("waiting for release route\n"); */
read(sync_pipe_r,dummy,1);
/* printf("end waiting\n"); */
return 0;
}
/*
* release isdn network devices
*/
int eft_release_route(struct sockaddr_x25 * x25addr, char * isdn_no)
int eft_signal_release_route()
{
/* signal release route request to possible parent process */
/* printf("signalling release route\n"); */
close(sync_pipe_r);
sync_pipe_r = -1;
close(sync_pipe_w);
sync_pipe_w = -1;
return 0;
}
int eft_release_route(struct x25_route_struct * x25_route)
{
int s;
/* try closing the route ourselves */
if ((s = socket(PF_X25, SOCK_SEQPACKET, 0)) < 0) {
perror("eft_release_route: socket");
return 1;
}
/* printf("releasing route\n"); */
if (ioctl(s, SIOCDELRT, x25_route) == -1) {
perror("SIOCDELRT");
close(s);
return -1;
}
/* printf("route released\n"); */
close(s);
return 0;
}
/*
* hangup physical connection of isdn network interface.
* hang up physical connection of isdn network interface.
*/
void eft_dl_disconnect(unsigned char * iif)
void eft_dl_disconnect(unsigned char * if_name)
{
pid_t pid;
char buf[80];
sprintf(buf,EFT_ISDNCTRL_PATH " hangup %s",iif);
/* printf(buf);printf("\n"); */
/* system(buf) */
pid=fork();
if(pid==0){
/* FIXME: isdnctrl path should not be hardcoded here */
printf("%s %s %s %s\n",EFT_ISDNCTRL_PATH,"isdnctrl", "hangup", iif);
execl(EFT_ISDNCTRL_PATH,"isdnctrl", "hangup", iif, NULL);
perror("execl()");
} else if(pid>0) {
int status;
if( wait(&status) != pid ){
perror("eft_dl_disconnect: wait failed");
}
wait(&status);
int ifd;
if( (ifd=open("/dev/isdnctrl",O_RDWR)) < 0){
perror("open isdnctrl");
goto error;
};
if( ioctl(ifd, IIOCNETHUP, if_name) < 0 ){
perror("hangup");
goto error;
}
error:
close(ifd);
}
/*
* release (possibly remove) isdn network interface.
*/
int eft_release_device(unsigned char * if_name)
{
int err=0, s=-1, ifd=-1;
struct ifreq ifr;
if ((s = socket(PF_X25, SOCK_SEQPACKET, 0)) < 0) {
perror("eft_release_device: socket");
goto error_delif;
}
/* ifconfig down */
ifr.ifr_flags = 0;
strcpy(ifr.ifr_name, if_name);
if (ioctl(s, SIOCGIFFLAGS, &ifr) ) {
perror("SIOCGIFFLAGS");
err = -1;
goto error_delif;
}
ifr.ifr_flags &= ~IFF_UP;
if (ioctl(s, SIOCSIFFLAGS, &ifr) ) {
perror("SIOCSIFFLAGS");
err = -1;
goto error_delif;
}
error_delif:
if( (ifd=open("/dev/isdnctrl",O_RDWR)) < 0){
perror("open isdnctrl");
err = -1;
goto error;
};
if( ioctl(ifd, IIOCNETDIF, if_name) ){
perror("delif");
err = -1;
}
ioctl(ifd, IIOCNETDIF, if_name);
error:
close(ifd);
close(s);
return err;
}
/*
* return the name of the network interface which is used by
* Return the name of the network interface which is used by
* a connected X.25 socket.
*
* This is a hack as it uses /proc file system contents like kernel internal
@ -239,7 +376,7 @@ char * eft_get_device(char * dev, int len, int sock_fd)
static char dummy[]="dummy";
int i, inod_col, dev_col;
/* first, the socket's inode number is exctracted from the
/* first, the socket's inode number is extracted from the
* socket file descriptors /proc/self/fd/# symbolic link contents
*/
snprintf(path_buf,MAXPATHLEN+1,"/proc/self/fd/%d",sock_fd);

View File

@ -1,4 +1,4 @@
/* $Id: eft.h,v 1.1 1999/06/30 17:28:39 he Exp $ */
/* $Id: eft.h,v 1.2 1999/07/25 21:55:53 he Exp $ */
/*
* Interface for accessing eurofile service primitives.
* Eurofile for Linux is implemented as a library. Programmers
@ -73,9 +73,13 @@ extern void eft_fix_cases(unsigned char *);
/* extern void eft_set_slash_fix(struct eft *, int);
extern int eft_need_slash_fix(struct eft *); */
struct sockaddr_x25;
extern int eft_get_x25route(struct sockaddr_x25 *, char *isdn_no);
extern int eft_release_route(struct sockaddr_x25 *, char * isdn_no);
struct x25_route_struct;
extern int eft_get_x25route(struct sockaddr_x25 *, struct x25_route_struct *, char *isdn_no);
extern int eft_release_route(struct x25_route_struct *);
extern int eft_signal_release_route();
extern int eft_wait_release_route();
extern void eft_dl_disconnect(unsigned char *);
extern int eft_release_device(unsigned char *);
extern long eft_get_flags(struct eft *);
extern void eft_set_flags(struct eft *, long);

View File

@ -1,4 +1,4 @@
/* $Id: eftd.c,v 1.1 1999/06/30 17:19:02 he Exp $ */
/* $Id: eftd.c,v 1.2 1999/07/25 21:55:58 he Exp $ */
/*
Copyright 1998 by Henner Eisen
@ -737,8 +737,9 @@ int main(int argc, char** argv)
*/
if( sigprocmask(SIG_BLOCK, &sig_pipe, NULL) )
perror("sigprocmask()");
#if 1
setsockopt(ns,SOL_SOCKET,SO_LINGER,&ling,sizeof(ling));
#endif
/*
* attach authentication methods to the protocol state machine
*/

View File

@ -1,4 +1,4 @@
/* $Id: eftp.c,v 1.1 1999/06/30 17:19:08 he Exp $ */
/* $Id: eftp.c,v 1.2 1999/07/25 21:56:04 he Exp $ */
/*
Copyright 1997 by Henner Eisen
@ -117,6 +117,7 @@
#include <signal.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <linux/x25.h>
/* for error mask setting */
#include <tdu_user.h>
@ -469,6 +470,7 @@ static void show_help(char *cmd)
int main(int argc, char **argv)
{
struct sockaddr_x25 x25bind, x25connect;
struct x25_route_struct x25_route;
int s, count, on=1, selval, prompt_for_pw = 1;
unsigned char called[TDU_PLEN_ADDR+1], udata[TDU_PLEN_UDATA+1];
@ -523,6 +525,83 @@ int main(int argc, char **argv)
}
}
if( isdn_no ){
/*
* If the destinatioin is given by means of an isdn number,
* we will try to dynamically create an isdn X.25 network
* interface and an x.25 route through it. In order to
* reliably hang up the connection later -- even if this
* programm crashes -- we will fork a child process in charge
* of the real work and ourselves will only wait for that
* child to exit such that we can clean up the low layer
* connection afterwards.
*
* In order to dynamically create isdn network interfaces
* and to set them up, we need certain priviliges (write
* access to /dev/isdnctrl and netadmin capability). However,
* we don't want to grant those priviliges to the executing
* eftp program. Forking also allows us to run the child
* process with fewer priviliges than ourselves.
*/
pid_t pid;
fprintf(stderr, "Setting up isdn x25 network interface\n");
if( eft_get_x25route(&x25connect,&x25_route,isdn_no) ){
perror("eftp: unable to get an X.25 route for isdn number");
exit(1);
}
pid = fork();
if( pid<0 ){
perror("eftp: fork()");
exit(1);
} else if( pid > 0 ) {
/*
* parent process
*
* We first wait until the child no longer needs the
* x25 route and clear the route (needs netadmin
* capability)
*/
int status, err=0;
close(s);
eft_wait_release_route();
eft_release_route(&x25_route);
/*
* Finally, wait for the child to exit and clear
* the low layer isdn connection and remove
* dynamically created interfaces (needs netadmin
* capability and write access to /dev/isdnctrl)
*/
if( wait(&status) != pid ){
perror("eftp supervisor: wait failed");
err = 1;
} else {
if(WIFSIGNALED(status)){
tdu_printf(TDU_LOG_ERR,
"internal error in eftp[%d]: %s\n\tyou might try to debug eftp using gdb\n",
pid, strsignal(WTERMSIG(status)));
err = 2;
}
}
eft_dl_disconnect( x25_route.device );
eft_release_device( x25_route.device );
exit(err);
} else {
/* Child process
*
* Just contiunue processing the protocol
*/
;
}
} else if( x25_no ){
strncpy(x25connect.sx25_addr.x25_addr, x25_no, 15);
} else {
fprintf(stderr, "Neither isdn nor X.25 address specified.\n"
" Assuming route to empty X.25 address\n");
strcpy(x25connect.sx25_addr.x25_addr, "");
}
/* build ident string [uid/password] from various input sources */
ident = NULL;
if( user ) {
@ -565,7 +644,6 @@ int main(int argc, char **argv)
strcpy(x25bind.sx25_addr.x25_addr, "" );
x25connect.sx25_family = AF_X25;
strcpy(x25connect.sx25_addr.x25_addr, "");
s = socket(AF_X25, SOCK_SEQPACKET, 0);
if (s < 0) {
@ -648,16 +726,6 @@ int main(int argc, char **argv)
exit(1);
}
if( isdn_no ){
fprintf(stderr, "Setting up isdn x25 network interface\n");
if( eft_get_x25route(&x25connect,isdn_no) ){
perror("eftp: unable get an x25route for isdn number");
exit(1);
}
} else if( x25_no ){
strncpy(x25connect.sx25_addr.x25_addr, x25_no, 15);
}
fprintf(stderr, "Trying to establish X.25 DTE-DTE connection to "
"x25 address \"%s\" ...\n", x25connect.sx25_addr.x25_addr);
if (connect(s, (struct sockaddr *)&x25connect, sizeof (x25connect)) < 0) {
@ -665,6 +733,18 @@ int main(int argc, char **argv)
return 1;
}
fprintf(stderr,"eftp: X.25 connection established.\n");
if(isdn_no){
/* Now we are connected and don't need the X.25 route
* any longer. We tell our parent to release it. Thus,
* the route is free for re-use by other eftp clients.
* Relasing it also disables other users to play dirty
* tricks on us by piggybacking other X.25 connection
* throug our isdn connection.
*/
eft_signal_release_route(&x25_route);
}
if( ioctl( s, SIOCX25GFACILITIES, &facilities ) != 0 ){
perror("eftp: SIOCX25GFACILITIES failed");
return 1;
@ -686,8 +766,8 @@ int main(int argc, char **argv)
/* This specifies the amount of (debugging) output printed to stderr*/
/* tdu_stderr_mask = TDU_LOG_FH | TDU_LOG_REW | TDU_LOG_ERR; */
tdu_stderr_mask = TDU_LOG_ERR | TDU_LOG_IER | TDU_LOG_OER /*| TDU_LOG_DBG
| TDU_LOG_HASH | TDU_LOG_TMP */ ;
tdu_stderr_mask = TDU_LOG_ERR | TDU_LOG_IER | TDU_LOG_OER /* | TDU_LOG_DBG
| TDU_LOG_HASH | TDU_LOG_TMP */ ;
#if 0
/* for maximum amount of debugging output use */
tdu_stderr_mask = -1 /* ^ TDU_LOG_TMP ^ TDU_LOG_TRC */;
@ -702,8 +782,9 @@ int main(int argc, char **argv)
*/
if( sigprocmask(SIG_BLOCK, &sig_pipe, NULL) )
perror("sigprocmask()");
#if 1
setsockopt(s,SOL_SOCKET,SO_LINGER,&ling,sizeof(ling));
#endif
/* and finally establish logical eft connection */
if( eft_connect( eft, ident) < 0 ) {
fprintf(stderr, "eftp: connection failed\n");
@ -777,8 +858,13 @@ int main(int argc, char **argv)
disconnect:
printf("eftp: requesting eft_disconnect()\n");
eft_disconnect( eft );
/* XXX why this? Without sleep, disconnect processing does not
* complete properly on the server side.
* this is probably caused by unclean termination of association regime
* (wait criteron for end of association falsly claimed to early)
*/
sleep(1);
close(s);
if( isdn_no ) eft_release_route( &x25connect, isdn_no );
Ende: pid = getpid();