Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 Jun 1995 10:08:30 +0200 (USAST)
From:      radova@risc6.unisa.ac.za (A. Radovanovic)
To:        hackers@freebsd.org
Subject:   Dynamic SLIP (tty assig.)
Message-ID:  <9506080808.AA44813@risc6.unisa.ac.za>

next in thread | raw e-mail | index | archive | help
For all interested, I am sending the changes of sliplogin (BSD 2.0) which
assigns IPs dynamically. The clent gets his IP when login to the server. The
program works exactly the same as the distribution one, unless you create a
file: /etc/sliphome/slip.ttys . If sliplogin found the file, addresses will
be assigned dynamically. The file is as follows:

---------------------------------------
# etc/sliphome/slip.ttys
#
# tty           remote address
#
/dev/ttyd0      1.2.3.4  # this is just an example - use the real IPs
/dev/ttyd1      2.3.4.5
--------------------------------------

This means that you can have as many users as you wish, but you'll need only
a few IPs - one for each comm port. The client will pick up the address after
login.

I am not on the mailing list, so if you have any suggestions, please mail to
me.

Alex

 ----------------------------+---------------------------------
  Aleksandar Radovanovic     +
 University of South Africa  +  Mail: radova@risc1.unisa.ac.za
 Dept.  of Computer Science  +        radova@osprey.unisa.ac.za
	P.O.Box 392          +  WWW:  http://osprey.unisa.ac.za
       Pretoria 0001         +  Tel.  (27) 12/429-6034
       South Africa          +  Fax.  (27) 12/429-6361
 ----------------------------+---------------------------------

There are only a few simple changes in files: pathnames.h and
sliplogin.c. It could be done better, but I'll improve it :)

a) File pathnames.h: add the following line:

#define _PATH_TTY2IP    "/etc/sliphome/slip.ttys"

b) File: sliplogin.c

1) The global variable dynamic is added:

int     unit;
int     speed;
int     uid;
char    loginargs[BUFSIZ];
char    loginfile[MAXPATHLEN];
char    loginname[BUFSIZ];
int     dynamic = 1;                  /* this is added */

2) The function findid is as follows:

void
findid(name)
	char *name;
{
	FILE *fp;
	char ttydef [16];
	char arguments [80];
	static char slopt[5][16];
	static char laddr[16];
	static char raddr[16];
	static char mask[16];
	char user[16];
	char dummyip [16];
	int i, j, n;

	if ((fp = fopen(_PATH_TTY2IP, "r")) == NULL) {
		(void)fprintf(stderr, "sliplogin: %s: %s\n",
			_PATH_TTY2IP, strerror (errno));
		syslog(LOG_ERR, "%s: %m\n", _PATH_TTY2IP);
		(void) fprintf (stderr, "Static SLIP used.\n");
		dynamic = 0;
	}
	if (dynamic == 1) {
		while (fgets(arguments,sizeof(arguments)-1, fp)) {
			if (ferror(fp)) {
				(void) fclose (fp);
				dynamic = 0;
				break;
			}
			n=sscanf(arguments, "%15s%*[ \t]%15s\n", ttydef, raddr);
			if (ttydef[0] == '#' || isspace (ttydef [0]))
				continue;
			if (strcmp(ttydef, ttyname (0)) == 0) {
				(void) fclose (fp);
				break;
			}
		}
	}

	(void)strcpy(loginname, name);
	if ((fp = fopen(_PATH_ACCESS, "r")) == NULL) {
		(void)fprintf(stderr, "sliplogin: %s: %s\n",
		    _PATH_ACCESS, strerror(errno));
		syslog(LOG_ERR, "%s: %m\n", _PATH_ACCESS);
		exit(1);
	}
	while (fgets(loginargs, sizeof(loginargs) - 1, fp)) {
		if (ferror(fp))
			break;
		n = sscanf(loginargs, "%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s%*[ \t]%15s\n",
			user, laddr, dummyip, mask, slopt[0], slopt[1],
			slopt[2], slopt[3], slopt[4]);
		if (dynamic == 1) sprintf (loginargs,
				"%s %s %s %s %s %s %s %s %s",
				user, laddr, raddr, mask, slopt[0], slopt[1],
				slopt[2], slopt[3], slopt[4]);
		if (user[0] == '#' || isspace(user[0]))
			continue;
		if (strcmp(user, name) != 0)
			continue;

		/*
		 * we've found the guy we're looking for -- see if
		 * there's a login file we can use.  First check for
		 * one specific to this host.  If none found, try for
		 * a generic one.
		 */
		(void)sprintf(loginfile, "%s.%s", _PATH_LOGIN, name);
		if (access(loginfile, R_OK|X_OK) != 0) {
			(void)strcpy(loginfile, _PATH_LOGIN);
			if (access(loginfile, R_OK|X_OK)) {
				fputs("access denied - no login file\n",
				      stderr);
				syslog(LOG_ERR,
				       "access denied for %s - no %s\n",
				       name, _PATH_LOGIN);
				exit(5);
			}
		}

		(void) fclose(fp);
		(void) fprintf (stderr, "Your address is %s\n", raddr);
		return;
	}
	(void)fprintf(stderr, "SLIP access denied for %s\n", name);
	syslog(LOG_ERR, "SLIP access denied for %s\n", name);
	exit(4);
	/* NOTREACHED */
}




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9506080808.AA44813>