Date: Thu, 26 Oct 1995 13:19:25 +0000 () From: Sergio Lenzi <lenzi@cwbone.bsi.com.br> To: Jason Hodges <jason@eon.webnet.com.au> Cc: questions@freebsd.org Subject: Re: A few questions.. Message-ID: <Pine.BSF.3.91.951026130905.194A-101000@cwbone.bsi.com.br> In-Reply-To: <199510260653.XAA15724@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Hello jason,
I use this kind of thing (ppp and slip) here.
I put "options GATEWAY" in the conf file
run routed with options -s
Make a table in the form:
tty ip
ttyd1 200.123.14.14
ttyd2 200.123.14.15
ttyd3 200.123.14.16
....
When a user logs_in it starts an awk program
that given a tty it returns an ip.
ip=awk "\$1 == \"$1\"{print \$2}' < tbl
after that, the ppp program is run....
pppd passive :$ip
in the /etc/ppp options -> Bmodem
crtscts
For the slip question I coded an slip program...
that runs un ifconfig + route command at start
and route delete + ifconfig at carrier lost....
[-- Attachment #2 --]
slip.c 100664 1773 1763 10365 6041171744 12140 0 ustar cadastro cadastro #include <sys/param.h>
#include <sys/socket.h>
#include <sys/signal.h>
#include <sys/file.h>
#include <sys/syslog.h>
#include <netdb.h>
#include <sys/termios.h>
#include <sys/ioctl.h>
#include <ttyent.h>
#include <net/slip.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
static int unit;
static int speed;
static int uid;
static char loginname[BUFSIZ];
static char *logoutfile;
static char *ip1,*ip2;
char *
sigstr(s)
int s;
{
static char buf[32];
switch (s) {
case SIGHUP: return("HUP");
case SIGINT: return("INT");
case SIGQUIT: return("QUIT");
case SIGILL: return("ILL");
case SIGTRAP: return("TRAP");
case SIGIOT: return("IOT");
case SIGEMT: return("EMT");
case SIGFPE: return("FPE");
case SIGKILL: return("KILL");
case SIGBUS: return("BUS");
case SIGSEGV: return("SEGV");
case SIGSYS: return("SYS");
case SIGPIPE: return("PIPE");
case SIGALRM: return("ALRM");
case SIGTERM: return("TERM");
case SIGURG: return("URG");
case SIGSTOP: return("STOP");
case SIGTSTP: return("TSTP");
case SIGCONT: return("CONT");
case SIGCHLD: return("CHLD");
case SIGTTIN: return("TTIN");
case SIGTTOU: return("TTOU");
case SIGIO: return("IO");
case SIGXCPU: return("XCPU");
case SIGXFSZ: return("XFSZ");
case SIGVTALRM: return("VTALRM");
case SIGPROF: return("PROF");
case SIGWINCH: return("WINCH");
#ifdef SIGLOST
case SIGLOST: return("LOST");
#endif
case SIGUSR1: return("USR1");
case SIGUSR2: return("USR2");
}
(void)sprintf(buf, "sig %d", s);
return(buf);
}
void hup_handler(s)
int s;
{
char cmd[2*MAXPATHLEN+32];
seteuid(0);
if (access(logoutfile, R_OK|X_OK) == 0) {
sprintf(cmd, "%s %d %s %s", logoutfile, unit,ip1,ip2);
system(cmd);
}
close(0);
syslog(LOG_INFO, "closed %s slip unit %d (%s)\n",
loginname,
unit,
sigstr(s));
exit(0);
/* NOTREACHED */
}
main(int ac,char **av) {
int fd, s, ldisc, odisc;
char *name,*loginfile;
struct termios tios, otios;
char logincmd[2*BUFSIZ+32];
extern uid_t getuid();
extern char *getlogin();
if (ac < 5) {
fprintf(stderr,"use %s icmd outcmd ipfrom ipto\n",
av[0]);
exit (1);
}
s = getdtablesize();
for (fd = 3 ; fd < s ; fd++)
(void) close(fd);
loginfile=av[1];
logoutfile=av[2];
ip1=av[3];
ip2=av[4];
openlog(name, LOG_PID, LOG_DAEMON);
uid = getuid();
if ((name = getlogin()) == NULL) {
fprintf(stderr, "access denied - no username\n");
exit(1);
}
strcpy(loginname,name);
(void) fchmod(0, 0600);
fprintf(stderr, "starting slip login for %s\n", loginname);
/* set up the line parameters */
if (tcgetattr(0, &tios) < 0) {
syslog(LOG_ERR, "tcgetattr: %m");
exit(1);
}
otios = tios;
cfmakeraw(&tios);
tios.c_iflag &= ~IMAXBEL;
if (tcsetattr(0, TCSAFLUSH, &tios) < 0) {
syslog(LOG_ERR, "tcsetattr: %m");
exit(1);
}
speed = cfgetispeed(&tios);
/* find out what ldisc we started with */
if (ioctl(0, TIOCGETD, (caddr_t)&odisc) < 0) {
syslog(LOG_ERR, "ioctl(TIOCGETD) (1): %m");
exit(1);
}
ldisc = SLIPDISC;
if (ioctl(0, TIOCSETD, (caddr_t)&ldisc) < 0) {
syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
exit(1);
}
/* find out what unit number we were assigned */
if (ioctl(0, SLIOCGUNIT, (caddr_t)&unit) < 0) {
syslog(LOG_ERR, "ioctl (SLIOCGUNIT): %m");
exit(1);
}
(void) signal(SIGHUP, hup_handler);
(void) signal(SIGTERM, hup_handler);
syslog(LOG_INFO,
"attaching slip unit %d for %s\n",
unit,
loginname);
(void)sprintf(logincmd, "%s %d %s %s",
loginfile,
unit,
ip1,
ip2);
/*
* aim stdout and errout at /dev/null so logincmd output won't
* babble into the slip tty line.
*/
(void) close(1);
if ((fd = open("/dev/null", O_WRONLY)) != 1) {
if (fd < 0) {
syslog(LOG_ERR, "open /dev/null: %m");
exit(1);
}
(void) dup2(fd, 1);
(void) close(fd);
}
(void) dup2(1, 2);
/*
* Run login and logout scripts as root (real and effective);
* current route(8) is setuid root, and checks the real uid
* to see whether changes are allowed (or just "route get").
*/
(void) setuid(0);
if (s = system(logincmd)) {
syslog(LOG_ERR,
"%s login failed: exit status %d from %s",
loginname,
s,
loginfile);
ioctl(0, TIOCSETD, (caddr_t)&odisc);
exit(6);
}
/* reset uid to users' to allow the user to give a signal. */
seteuid(uid);
/* twiddle thumbs until we get a signal */
pause();
}
sliplogin.sh 100666 1773 1763 120 6037267276 13322 0 ustar cadastro cadastro #!/bin/sh
iface=$1
ip1=$2
ip2=$3
ifconfig sl$iface $ip1 $ip2 netmask 0xffffffff
sliplogout.sh 100666 1773 1763 133 6041171302 13502 0 ustar cadastro cadastro #!/bin/sh
iface=$1
ip1=$2
ip2=$3
/sbin/ifconfig sl$iface down
/sbin/route delete $ip1 $ip2
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.91.951026130905.194A-101000>
