jfh@rpp386.Dallas.TX.US (John F. Haugh II) (02/22/89)
[ This is being reposted. A very serious bug showed up quite rapidly after the original posting. You should only be seeing this once. ] OK. This isn't exactly a patch-patch. This is more like some features and some bug fixes. Some of you may be unable to tell the difference. Others of you may believe there really is no distinction ... This is what this patch is supposed to accomplish - - Login time setting of TERM environmental variable. - Add close of lastlog if lseek() fails. - Changed int's in shadow.h to long's. - Changed gets() in password.c to fgets(). The suggestion to add the first feature is credited to Chip Rosenthal. The last three may be credited to Jonathan Bayer, who has been involved with this project since its inception. Read the README file for details concerning the TERM variable option. Features in the pipeline include - - Support for updating the dialup password files - Longer passwords Good luck - - John. -- *** Makefile --- new/Makefile ************** *** 1,5 # ! # @(#)Makefile 1.3 - System V shadow password system # # @(#)Makefile 1.3 18:58:25 2/18/89 # --- 1,5 ----- # ! # @(#)Makefile 1.4 - System V shadow password system # # @(#)Makefile 1.4 18:06:16 2/20/89 # ************** *** 1,7 # # @(#)Makefile 1.3 - System V shadow password system # ! # @(#)Makefile 1.3 18:58:25 2/18/89 # SHELL = /bin/sh --- 1,7 ----- # # @(#)Makefile 1.4 - System V shadow password system # ! # @(#)Makefile 1.4 18:06:16 2/20/89 # SHELL = /bin/sh ************** *** 17,23 # LDFLAGS = -g LOBJS = lmain.o login.o env.o password.o entry.o valid.o setup.o shell.o age.o \ ! pwent.o utmp.o sub.o mail.o motd.o log.o shadow.o dialup.o dialchk.o LSRCS = lmain.c login.c env.c password.c entry.c valid.c setup.c shell.c age.c \ pwent.c utmp.c sub.c mail.c motd.c log.c shadow.c dialup.c dialchk.c --- 17,24 ----- # LDFLAGS = -g LOBJS = lmain.o login.o env.o password.o entry.o valid.o setup.o shell.o age.o \ ! pwent.o utmp.o sub.o mail.o motd.o log.o shadow.o dialup.o dialchk.o \ ! ttytype.o LSRCS = lmain.c login.c env.c password.c entry.c valid.c setup.c shell.c age.c \ pwent.c utmp.c sub.c mail.c motd.c log.c shadow.c dialup.c dialchk.c \ ************** *** 20,26 pwent.o utmp.o sub.o mail.o motd.o log.o shadow.o dialup.o dialchk.o LSRCS = lmain.c login.c env.c password.c entry.c valid.c setup.c shell.c age.c \ ! pwent.c utmp.c sub.c mail.c motd.c log.c shadow.c dialup.c dialchk.c SOBJS = smain.o env.o password.o entry.o valid.o susetup.o sushell.o \ pwent.o susub.o mail.o motd.o sulog.o shadow.o age.o --- 21,28 ----- ttytype.o LSRCS = lmain.c login.c env.c password.c entry.c valid.c setup.c shell.c age.c \ ! pwent.c utmp.c sub.c mail.c motd.c log.c shadow.c dialup.c dialchk.c \ ! ttytype.c SOBJS = smain.o env.o password.o entry.o valid.o susetup.o sushell.o \ pwent.o susub.o mail.o motd.o sulog.o shadow.o age.o ************** *** 47,53 shadow.c shell.c valid.c FILES1 = README log.c mail.c shadow.h sulog.c Makefile entry.c obscure.c \ ! setup.c sub.c config.h pmain.c sulogin.c dialup.h FILES2 = lastlog.h login.c motd.c password.c shell.c utmp.c age.c env.c \ pwent.c shadow.c valid.c lmain.c smain.c pwconv.c dialup.c dialchk.c \ --- 49,55 ----- shadow.c shell.c valid.c FILES1 = README log.c mail.c shadow.h sulog.c Makefile entry.c obscure.c \ ! setup.c sub.c config.h pmain.c sulogin.c dialup.h ttytype.c FILES2 = lastlog.h login.c motd.c password.c shell.c utmp.c age.c env.c \ pwent.c shadow.c valid.c lmain.c smain.c pwconv.c dialup.c dialchk.c \ *** README --- new/README ************** *** 128,133 Select this option by defining the TTYPERM macro as having the desired mode. File Size Setting - This option includes code to set the user's ulimit at login time. Additional code to set the umask and --- 128,143 ----- Select this option by defining the TTYPERM macro as having the desired mode. + Terminal Type Setup - + This option allows the terminal type to be set at + login time. The environmental variable TERM will be + set from the specified terminal to port mapping + file. + + Select this option by defining the TTYTYPE macro as + having the value of the name of the type to port + mapping file. + File Size Setting - This option includes code to set the user's ulimit at login time. Additional code to set the umask and *** config.h --- new/config.h ************** *** 1,5 /* * Configuration file for login. */ /* --- 1,7 ----- /* * Configuration file for login. + * + * @(#)config.h 1.2 18:06:19 2/20/89 */ /* ************** *** 112,117 */ #define TTYPERM 0600 /* * Define QUOTAS if you want the code added in setup.c to support --- 114,127 ----- */ #define TTYPERM 0600 + + /* + * Define TTYTYPE to the be name of the port to terminal type + * mapping file. This is used to set the environmental variable + * "TERM" to the correct terminal type. + */ + + #define TTYTYPE "/etc/ttytype" /* * Define QUOTAS if you want the code added in setup.c to support *** lmain.c --- new/lmain.c ************** *** 9,15 #include "lastlog.h" #ifndef lint ! static char _sccsid[] = "@(#)lmain.c 1.2 19:00:57 2/18/89"; #endif char name[BUFSIZ]; --- 9,15 ----- #include "lastlog.h" #ifndef lint ! static char _sccsid[] = "@(#)lmain.c 1.3 18:06:20 2/20/89"; #endif char name[BUFSIZ]; ************** *** 157,162 #endif #ifdef MAILCHECK mailcheck (); /* report on the status of mail */ #endif signal (SIGINT, SIG_DFL); /* default interrupt signal */ signal (SIGQUIT, SIG_DFL); /* default quit signal */ --- 157,165 ----- #endif #ifdef MAILCHECK mailcheck (); /* report on the status of mail */ + #endif + #ifdef TTYTYPE + ttytype (utent.ut_line); #endif signal (SIGINT, SIG_DFL); /* default interrupt signal */ signal (SIGQUIT, SIG_DFL); /* default quit signal */ *** ttytype.c --- new/ttytype.c ************** *** 0 --- 1,50 ----- + #include <stdio.h> + #include <string.h> + #include "config.h" + + #ifdef TTYTYPE + #ifndef lint + static char _sccsid[] = "@(#)ttytype.c 1.1 15:31:54 2/19/89"; + #endif + + /* + * ttytype - set ttytype from port to terminal type mapping database + */ + + void ttytype (line) + char *line; + { + FILE *fp; + char buf[BUFSIZ]; + char termvar[BUFSIZ]; + char *cp; + char *type; + char *port; + char *getenv (); + + if (getenv ("TERM")) + return; + + if (! (fp = fopen (TTYTYPE, "r"))) + return; + + while (fgets (buf, BUFSIZ, fp)) { + if (buf[0] == '#') + continue; + + if (cp = strchr (buf, '\n')) + *cp = '\0'; + + if ((type = strtok (buf, " \t")) + && (port = strtok ((char *) 0, " \t"))) { + if (strcmp (line, port) == 0) + break; + } + } + if (! feof (fp) && ! ferror (fp)) { + strcat (strcpy (termvar, "TERM="), type); + addenv (termvar); + } + fclose (fp); + } + #endif *** log.c --- new/log.c ************** *** 7,13 #include "config.h" #ifndef lint ! static char _sccsid[] = "@(#)log.c 1.2 13:59:29 2/5/89"; #endif #ifdef LASTLOG --- 7,13 ----- #include "config.h" #ifndef lint ! static char _sccsid[] = "@(#)log.c 1.3 19:00:07 2/21/89"; #endif #ifdef LASTLOG ************** *** 33,39 offset = pwent.pw_uid * sizeof lastlog; ! if (lseek (fd, offset, 0) != offset) return; if (read (fd, (char *) &lastlog, sizeof lastlog) != sizeof lastlog) --- 33,40 ----- offset = pwent.pw_uid * sizeof lastlog; ! if (lseek (fd, offset, 0) != offset) { ! (void) close (fd); return; } if (read (fd, (char *) &lastlog, sizeof lastlog) != sizeof lastlog) ************** *** 35,41 if (lseek (fd, offset, 0) != offset) return; ! if (read (fd, (char *) &lastlog, sizeof lastlog) != sizeof lastlog) memset ((char *) &lastlog, sizeof lastlog, 0); --- 36,42 ----- if (lseek (fd, offset, 0) != offset) { (void) close (fd); return; ! } if (read (fd, (char *) &lastlog, sizeof lastlog) != sizeof lastlog) memset ((char *) &lastlog, sizeof lastlog, 0); *** password.c --- new/password.c ************** *** 12,17 * on failure. */ int password (prompt, pass) char *prompt; char *pass; --- 12,21 ----- * on failure. */ + #ifndef lint + static char _sccsid[] = "@(#)password.c 1.2 19:00:10 2/21/89"; + #endif + int password (prompt, pass) char *prompt; char *pass; ************** *** 17,22 char *pass; { char buf[BUFSIZ]; int eof; int ttyopened = 0; struct termio termio; --- 21,27 ----- char *pass; { char buf[BUFSIZ]; + char *cp; int eof; int ttyopened = 0; struct termio termio; ************** *** 36,42 ioctl (fileno (fp), TCSETAF, &termio); fputs (prompt, stdout); ! eof = gets (buf) == (char *) 0 || feof (fp) || ferror (fp); putchar ('\n'); ioctl (fileno (fp), TCSETAF, &save); --- 41,47 ----- ioctl (fileno (fp), TCSETAF, &termio); fputs (prompt, stdout); ! eof = fgets (buf, s, BUFSIZ) == (char *) 0 || feof (fp) || ferror (fp); putchar ('\n'); ioctl (fileno (fp), TCSETAF, &save); ************** *** 43,48 if (! eof) { buf[8] = '\0'; (void) strcpy (pass, buf); } if (ttyopened) --- 48,56 ----- if (! eof) { buf[8] = '\0'; + if ((cp = strchr (buf, '\n')) || (cp = strchr (buf, '\r'))) + *cp = '\0'; + (void) strcpy (pass, buf); } if (ttyopened) *** shadow.h --- new/shadow.h ************** *** 1,6 /* * This information is not derived from AT&T licensed sources. Posted * to the USENET 11/88. */ /* --- 1,8 ----- /* * This information is not derived from AT&T licensed sources. Posted * to the USENET 11/88. + * + * @(#)shadow.h 1.2 19:00:11 2/21/89 */ /* ************** *** 11,18 char *sp_namp; /* login name */ char *sp_pwdp; /* encrypted password */ long sp_lstchg; /* date of last change */ ! int sp_max; /* maximum number of days between changes */ ! int sp_min; /* minimum number of days between changes */ }; /* --- 13,20 ----- char *sp_namp; /* login name */ char *sp_pwdp; /* encrypted password */ long sp_lstchg; /* date of last change */ ! long sp_max; /* maximum number of days between changes */ ! long sp_min; /* minimum number of days between changes */ }; /* -- John F. Haugh II +--Quote of the Week:------------------ VoiceNet: (214) 250-3311 Data: -6272 | "If I do not want others to quote me, InterNet: jfh@rpp386.Dallas.TX.US | I do not speak." -- Phil Wayne UucpNet : <backbone>!killer!rpp386!jfh +--------------------------------------