Patch against sliplogin-2.1.0

Alan L. Wendt (alan@ez0.ezlink.com)
Fri, 8 Nov 1996 10:26:15 -0700 (MST)

This patch allows you to define the string that sliplogin sends
when it fires up a slip session, on a per user basis. I'm using
it to slowly migrate my user base to the same string that PM20's
use because PM20's cannot customize that string :(.

NB 2.1.1 is NOT an official release but I had to call it something.

Alan Wendt

diff -C4 -r sliplogin-2.1.0/Makefile sliplogin-2.1.1/Makefile
*** sliplogin-2.1.0/Makefile Tue Jul 30 00:35:05 1996
--- sliplogin-2.1.1/Makefile Fri Nov 8 00:47:17 1996
***************
*** 31,42 ****
VERSION = 2.1.0

CC = gcc
LINK = $(CC)
! CFLAGS = -O2 -pipe -fomit-frame-pointer -DOLDMESSAGE -m486 #-Wall
EFLAGS = -DESLIPLOGIN -DESLIP_AUTO -DSLIP_MODES
DEFINES = -DSLIPPATH=\"$(SLIP)\" $(EFLAGS)
! LDFLAGS = -s

# if you want to use the access library just uncomment the following lines
# and define -DLINE-ACCESS in EFLAGS above;
# than type 'make all', 'make install_all'
--- 31,42 ----
VERSION = 2.1.0

CC = gcc
LINK = $(CC)
! CFLAGS = -g -pipe -DOLDMESSAGE -m486 #-Wall -fomit-frame-pointer
EFLAGS = -DESLIPLOGIN -DESLIP_AUTO -DSLIP_MODES
DEFINES = -DSLIPPATH=\"$(SLIP)\" $(EFLAGS)
! LDFLAGS = -s -g

# if you want to use the access library just uncomment the following lines
# and define -DLINE-ACCESS in EFLAGS above;
# than type 'make all', 'make install_all'
diff -C4 -r sliplogin-2.1.0/scanfile.c sliplogin-2.1.1/scanfile.c
*** sliplogin-2.1.0/scanfile.c Sat May 11 14:42:49 1996
--- sliplogin-2.1.1/scanfile.c Fri Nov 8 09:52:49 1996
***************
*** 19,33 ****
--- 19,36 ----
"auto", SL_MODE_AUTO
};
#endif

+ static char *get_msg(FILE *, struct slipinfo *, char *);
+
void scan_sliphosts(struct slipinfo *info)
{
FILE *fp;
static char mask[16];
char user[16];
char loginargs[BUFSIZ], timeout[16];
int j;
+ char msgid[16];

if ((fp = fopen(_PATH_ACCESS, "r")) == NULL)
{
fprintf(stderr,"sliplogin: %s: %s\n", _PATH_ACCESS, strerror(errno));
***************
*** 39,46 ****
--- 42,52 ----
while (fgets(loginargs, sizeof(loginargs) - 1, fp))
{
if (ferror(fp)) break;
if (loginargs[0]=='#') continue; /* Comment */
+
+ if (!strcmp(loginargs, "%%\n")) /* Got to message defs with no match */
+ break;

if (loginargs[0]=='+') /* Look at NIS map ? */
{
char *nisdomain, *outval, *c;
***************
*** 63,71 ****
continue; /* Read next line */
}
sscanf(outval, "%15s%15s%15s%15s%15s%15s%15s%15s%15s",
user, info->laddr, info->raddr, info->mask, info->sm_name,
! timeout, info->option[0], info->option[1], info->option[2]);
if(strlen(loginargs+1)>1) /* Local address given */
{
if((c=strchr(loginargs,'\n'))!=NULL) *c='\0';
strncpy(info->laddr,loginargs+1,15);
--- 69,77 ----
continue; /* Read next line */
}
sscanf(outval, "%15s%15s%15s%15s%15s%15s%15s%15s%15s",
user, info->laddr, info->raddr, info->mask, info->sm_name,
! timeout, msgid, info->option[0], info->option[1], info->option[2]);
if(strlen(loginargs+1)>1) /* Local address given */
{
if((c=strchr(loginargs,'\n'))!=NULL) *c='\0';
strncpy(info->laddr,loginargs+1,15);
***************
*** 73,88 ****
} else /* No NIS search */
{
sscanf(loginargs, "%15s%15s%15s%15s%15s%15s%15s%15s%15s",
user, info->laddr, info->raddr, info->mask, info->sm_name,
! timeout, info->option[0], info->option[1], info->option[2]);
}
if ( (strcmp(user, info->loginname) != 0) && strcmp(user, "*") != 0)
continue; /* Read next line */

/* Found user */
info->timeout=atoi(timeout);
if (!info->timeout) info->timeout=-1;
fclose(fp);

/* Now check for dynamic IP assigning */
if (strcmp(info->raddr, "DYNAMIC")==0 || strcmp(info->raddr, "*")==0)
--- 79,96 ----
} else /* No NIS search */
{
sscanf(loginargs, "%15s%15s%15s%15s%15s%15s%15s%15s%15s",
user, info->laddr, info->raddr, info->mask, info->sm_name,
! timeout, msgid, info->option[0], info->option[1], info->option[2]);
}
if ( (strcmp(user, info->loginname) != 0) && strcmp(user, "*") != 0)
continue; /* Read next line */

/* Found user */
info->timeout=atoi(timeout);
if (!info->timeout) info->timeout=-1;
+
+ get_msg(fp, info, msgid);
fclose(fp);

/* Now check for dynamic IP assigning */
if (strcmp(info->raddr, "DYNAMIC")==0 || strcmp(info->raddr, "*")==0)
***************
*** 169,173 ****
--- 177,299 ----
fclose(fp);
(void)fprintf(stderr, "SLIP access denied for %s\n", info->loginname);
syslog(LOG_ERR, "SLIP access denied for %s\n", info->loginname);
FATAL(4);
+ }
+
+
+
+ /* Collect Dynamic IP strings and ID's. Each user line can contain an
+ * optional string that keys a particular dynamic IP message string.
+ * The slip.hosts file can contain an optional '%%' on a line by itself,
+ * followed by zero or more identifer/message string pairs.
+ * Each pair consists of an identifier, white space, a non-whitespace
+ * delimiter, the message string, and the same delimeter repeated.
+ * For example:
+ * std /Slip server is %S , you are %C
+ /
+ * When this message is output to the client, %S is replaced by the
+ * server's IP address and %C by the client's.
+ */
+ static char *get_msg(FILE *fp, struct slipinfo *info, char *desired_id)
+ {
+ char loginargs[BUFSIZ], id[16];
+ int c, delim;
+ int its_our_msg = 0;
+ int len;
+
+ while (fgets(loginargs, sizeof(loginargs) - 1, fp))
+ {
+ if (!strcmp(loginargs, "%%\n"))
+ {
+ goto l1;
+ }
+ }
+ goto badeof;
+
+ /* Scanner is skipping white space looking for the beginning
+ * of an identifier, or the end of file, or the end of a line.
+ */
+ l0:
+ c = getc(fp);
+ if (c == ' ' || c == '\t') goto l0;
+
+ if (c == '\n') {
+
+ /* Just ate a newline, expecting '#' or ' ' or '\t' or '\n'
+ * or EOF or the beginning of an identifier.
+ */
+ l1:
+ c = getc(fp);
+ if (c == '#') {
+ l3:
+ c = getc(fp);
+ /* Scanner is skipping through a comment looking for EOF or NL */
+ if (c == '\n') goto l1;
+ if (c == EOF) goto badeof;
+ goto l3;
+ }
+
+ if (c == ' ' || c == '\t')
+ goto l0;
+
+ if (c == '\n')
+ goto l1;
+
+ len = 0;
+
+ /* Scanner has read one character of a dynamic string's id into c.
+ * Save it and read the next character.
+ * Looking for next character, EOF, or white space.
+ * Next character will continue this loop.
+ * EOF is an error.
+ * Whitespace will end the identifier.
+ */
+ l2:
+ id[len++] = c;
+ c = getc(fp);
+ if (c == EOF) {
+ goto badeof;
+ }
+
+ else if (c == ' ' || c == '\t' || c == '\n') {
+ id[len++] = 0;
+ if (!strcmp(id, desired_id) || !strcmp(id, "*")) {
+ its_our_msg = 1;
+ }
+
+ /* skipping whitespace following identifier */
+ l4:
+ c = getc(fp);
+ if (c == ' ' || c == '\t' || c == '\n') goto l4;
+ if (c == EOF) {
+ badeof:
+ fclose(fp);
+ fputs("unexpected EOF on slip.hosts\n", stderr);
+ syslog(LOG_ERR, "unexpected EOF on slip.hosts\n");
+ FATAL(5);
+ }
+
+ delim = c; /* found delimitor of string */
+ len = 0;
+
+ /* Scanner is expecting either another character of the
+ * message string, or the end-of-string delimiter, or EOF.
+ */
+ l7:
+ c = getc(fp); /* read next character */
+ if (c == delim) {
+ if (its_our_msg) {
+ info->msg[len] = 0;
+ return;
+ }
+ goto l0;
+ }
+ if (c == EOF) goto badeof;
+ if (its_our_msg)
+ info->msg[len++] = c;
+ goto l7;
+ }
+ goto l2;
+ }
+ if (c == EOF) return;
}
diff -C4 -r sliplogin-2.1.0/slip.hosts sliplogin-2.1.1/slip.hosts
*** sliplogin-2.1.0/slip.hosts Sat May 11 15:34:41 1996
--- sliplogin-2.1.1/slip.hosts Thu Nov 7 23:46:52 1996
***************
*** 34,38 ****
--- 34,66 ----
# (WARNING: the specified local IP-Adr. will be overwritten by the
real Serveradress, if the NIS-map contains a DNAMIC local address
entry. See the scanning oder in scanfile.c for explanation.)
+130.149.1.1
+ %%
+ #
+ # Various prompt messages
+ # %L = user name, %C = client IP, %S = server IP, %M = tty
+ # %? = toggle configure_msg test
+ #
+ fun "Captain ! Something is lowering our shields!
+ On screen, Mr. Worf !
+ It's %L at coordinates %C
+ Mr. Data, try %M slip to %S
+ We got him, captain.
+ "

+ old "Starting %M slip for %L
+ %?Slip server is %S , you are %C
+ "
+
+ bsd "%?Your IP address is %C , the server is %S
+ %?starting %M slip login for %L
+ "
+
+ standard "Starting %M slip for %L
+ %?Your IP address is %C , the server is %S
+ "
+
+ #
+ # Emulate a Livingston Portmaster
+ #
+ pm "SL/IP session from (%S) to %C beginning...."

#
# Default
#
* "Starting %M slip for %L
%?Slip server is %S , you are %C
"

diff -C4 -r sliplogin-2.1.0/sliplogin.c sliplogin-2.1.1/sliplogin.c
*** sliplogin-2.1.0/sliplogin.c Sat May 11 15:06:57 1996
--- sliplogin-2.1.1/sliplogin.c Fri Nov 8 00:03:14 1996
***************
*** 194,202 ****
{
int fd, s, ldisc, odisc, pid, unitnumber;
speed_t speed;
struct sigaction sa;
! char *name;
#ifdef POSIX
struct termios tios, otios;
#else
struct sgttyb tty, otty;
--- 194,203 ----
{
int fd, s, ldisc, odisc, pid, unitnumber;
speed_t speed;
struct sigaction sa;
! char *name, *cp;
! int mand;
#ifdef POSIX
struct termios tios, otios;
#else
struct sgttyb tty, otty;
***************
*** 307,342 ****
stats.tx_packets = 0;
#endif

fchmod(0, 0600);
! #ifdef FUNMESSAGE
! fprintf(stderr, "Captain ! Something is lowering our shields!\n");
! fprintf(stderr, "On screen, Mr. Worf !\n");
! fprintf(stderr, "It's %s at coordinates %s\n",info.loginname,info.raddr);
! fprintf(stderr, "Mr. Data, try %s slip to %s\n",info.sm_name,info.laddr);
! fprintf(stderr, "We got him, captain.\n");
! #else
! #ifdef OLDMESSAGE
! fprintf(stderr, "Starting %s slip for %s\n",info.sm_name,info.loginname);
! if (configure_msg)
! fprintf(stderr, "Slip server is %s , you are %s\n",
! info.laddr,info.raddr);
! #elif BSDMESSAGE
! /* IMPORTANT: many scripts are waiting for a special string,
! e.g. 'slip\slogin\sfor', so we first print the IP-adresses
! and then the login message (containing this string) */
! if (configure_msg)
! fprintf(stderr, "Your IP address is %s , the server is %s\n",
! info.raddr,info.laddr);
! fprintf(stderr, "starting %s slip login for %s\n",
! info.sm_name, info.loginname);
! #else
! fprintf(stderr, "Starting %s slip for %s\n",info.sm_name,info.loginname);
! if (configure_msg)
! fprintf(stderr, "Your IP address is %s , the server is %s\n",
! info.raddr,info.laddr);
! #endif
! #endif
fflush(stdout); fflush(stderr);
sleep(2); /* wait to send the output */

#ifdef POSIX
--- 308,350 ----
stats.tx_packets = 0;
#endif

fchmod(0, 0600);
!
! mand = 1; /* %? toggles mandatory; till then it is */
!
! for (cp = info.msg; *cp; cp++) {
! if (cp[0] == '%') {
! switch (cp[1]) {
! case '?': mand = !mand;
! break;
! case 'C': if (mand || configure_msg)
! fputs(info.raddr, stderr);
! break;
! case 'S': if (mand || configure_msg)
! fputs(info.laddr, stderr);
! break;
! case 'L': if (mand || configure_msg)
! fputs(info.loginname, stderr);
! break;
! case 'M': if (mand || configure_msg)
! fputs(info.sm_name, stderr);
! break;
! case '%': if (mand || configure_msg)
! fputs("%", stderr);
! break;
! default: if (mand || configure_msg) {
! putc('%', stderr);
! putc(cp[1], stderr);
! }
! break;
! }
! cp++;
! }
! else if (mand || configure_msg)
! putc(*cp, stderr);
! }
!
fflush(stdout); fflush(stderr);
sleep(2); /* wait to send the output */

#ifdef POSIX
diff -C4 -r sliplogin-2.1.0/sliplogin.h sliplogin-2.1.1/sliplogin.h
*** sliplogin-2.1.0/sliplogin.h Wed May 1 10:26:09 1996
--- sliplogin-2.1.1/sliplogin.h Thu Nov 7 23:48:28 1996
***************
*** 77,82 ****
--- 77,83 ----
char laddr[16];
char unit[32];
char mask[16];
char option[3][16];
+ char msg[BUFSIZ]; /* IP announcement message prototype */
};