[comp.bugs.4bsd] Login is full of lint

chris@mimsy.UUCP (Chris Torek) (09/03/87)

Index:	bin/login.c 4.3BSD Fix

Description:
	Login has unused variables and other lint fluff.

Repeat-By:
	% lint login.c

Fix:
	lint still complains about endgrent() (see next bug report),
	and about setuid and setgid arguments (not to be fixed here).

RCS file: RCS/login.c,v
retrieving revision 1.1
retrieving revision 1.5.1.1
diff -c2 -r1.1 -r1.5.1.1
*** /tmp/,RCSt1017778	Thu Sep  3 13:40:42 1987
--- /tmp/,RCSt2017778	Thu Sep  3 13:40:44 1987
***************
*** 27,30 ****
--- 27,31 ----
  #include <sys/resource.h>
  #include <sys/file.h>
+ #include <sys/wait.h>
  
  #include <sgtty.h>
***************
*** 43,47 ****
  
  #define	SCMPN(a, b)	strncmp(a, b, sizeof(a))
! #define	SCPYN(a, b)	strncpy(a, b, sizeof(a))
  
  #define NMAX	sizeof(utmp.ut_name)
--- 44,48 ----
  
  #define	SCMPN(a, b)	strncmp(a, b, sizeof(a))
! #define	SCPYN(a, b)	(void) strncpy(a, b, sizeof(a))
  
  #define NMAX	sizeof(utmp.ut_name)
***************
*** 64,68 ****
   * so it can be patched on machines where it's too small.
   */
! int	timeout = 60;
  
  char	term[64];
--- 65,69 ----
   * so it can be patched on machines where it's too small.
   */
! u_int	timeout = 60;
  
  char	term[64];
***************
*** 69,73 ****
  
  struct	passwd *pwd;
! char	*strcat(), *rindex(), *index(), *malloc(), *realloc();
  int	timedout();
  char	*ttyname();
--- 70,75 ----
  
  struct	passwd *pwd;
! char	*strcat(), *strcpy(), *strncpy(), *rindex(), *index();
! char	*malloc(), *realloc();
  int	timedout();
  char	*ttyname();
***************
*** 75,78 ****
--- 77,83 ----
  char	*getpass();
  char	*stypeof();
+ uid_t	getuid();
+ time_t	time();
+ off_t	lseek();
  extern	char **environ;
  extern	int errno;
***************
*** 90,96 ****
  int	usererr = -1;
  char	rusername[NMAX+1], lusername[NMAX+1];
- char	rpassword[NMAX+1];
  char	name[NMAX+1];
- char	*rhost;
  
  main(argc, argv)
--- 95,99 ----
***************
*** 105,114 ****
  	char **envnew;
  
! 	signal(SIGALRM, timedout);
! 	alarm(timeout);
! 	signal(SIGQUIT, SIG_IGN);
! 	signal(SIGINT, SIG_IGN);
! 	setpriority(PRIO_PROCESS, 0, 0);
! 	quota(Q_SETUID, 0, 0, 0);
  	/*
  	 * -p is used by getty to tell login not to destroy the environment
--- 108,117 ----
  	char **envnew;
  
! 	(void) signal(SIGALRM, timedout);
! 	(void) alarm(timeout);
! 	(void) signal(SIGQUIT, SIG_IGN);
! 	(void) signal(SIGINT, SIG_IGN);
! 	(void) setpriority(PRIO_PROCESS, 0, 0);
! 	(void) quota(Q_SETUID, 0, 0, (char *)0);
  	/*
  	 * -p is used by getty to tell login not to destroy the environment
***************
*** 149,157 ****
  		break;
  	}
! 	ioctl(0, TIOCLSET, &zero);
! 	ioctl(0, TIOCNXCL, 0);
! 	ioctl(0, FIONBIO, &zero);
! 	ioctl(0, FIOASYNC, &zero);
! 	ioctl(0, TIOCGETP, &ttyb);
  	/*
  	 * If talking to an rlogin process,
--- 152,160 ----
  		break;
  	}
! 	(void) ioctl(0, TIOCLSET, (char *)&zero);
! 	(void) ioctl(0, TIOCNXCL, (char *)0);
! 	(void) ioctl(0, FIONBIO, (char *)&zero);
! 	(void) ioctl(0, FIOASYNC, (char *)&zero);
! 	(void) ioctl(0, TIOCGETP, (char *)&ttyb);
  	/*
  	 * If talking to an rlogin process,
***************
*** 163,171 ****
  	ttyb.sg_erase = CERASE;
  	ttyb.sg_kill = CKILL;
! 	ioctl(0, TIOCSLTC, &ltc);
! 	ioctl(0, TIOCSETC, &tc);
! 	ioctl(0, TIOCSETP, &ttyb);
  	for (t = getdtablesize(); t > 2; t--)
! 		close(t);
  	ttyn = ttyname(0);
  	if (ttyn == (char *)0 || *ttyn == '\0')
--- 166,174 ----
  	ttyb.sg_erase = CERASE;
  	ttyb.sg_kill = CKILL;
! 	(void) ioctl(0, TIOCSLTC, (char *)&ltc);
! 	(void) ioctl(0, TIOCSETC, (char *)&tc);
! 	(void) ioctl(0, TIOCSETP, (char *)&ttyb);
  	for (t = getdtablesize(); t > 2; t--)
! 		(void) close(t);
  	ttyn = ttyname(0);
  	if (ttyn == (char *)0 || *ttyn == '\0')
***************
*** 181,185 ****
  	do {
  		ldisc = 0;
! 		ioctl(0, TIOCSETD, &ldisc);
  		SCPYN(utmp.ut_name, "");
  		/*
--- 184,188 ----
  	do {
  		ldisc = 0;
! 		(void) ioctl(0, TIOCSETD, (char *)&ldisc);
  		SCPYN(utmp.ut_name, "");
  		/*
***************
*** 201,205 ****
  		if (!strcmp(pwd->pw_shell, "/bin/csh")) {
  			ldisc = NTTYDISC;
! 			ioctl(0, TIOCSETD, &ldisc);
  		}
  		/*
--- 204,208 ----
  		if (!strcmp(pwd->pw_shell, "/bin/csh")) {
  			ldisc = NTTYDISC;
! 			(void) ioctl(0, TIOCSETD, (char *)&ldisc);
  		}
  		/*
***************
*** 211,218 ****
  			char *pp;
  
! 			setpriority(PRIO_PROCESS, 0, -4);
  			pp = getpass("Password:");
  			namep = crypt(pp, pwd->pw_passwd);
! 			setpriority(PRIO_PROCESS, 0, 0);
  			if (strcmp(namep, pwd->pw_passwd))
  				invalid = TRUE;
--- 214,221 ----
  			char *pp;
  
! 			(void) setpriority(PRIO_PROCESS, 0, -4);
  			pp = getpass("Password:");
  			namep = crypt(pp, pwd->pw_passwd);
! 			(void) setpriority(PRIO_PROCESS, 0, 0);
  			if (strcmp(namep, pwd->pw_passwd))
  				invalid = TRUE;
***************
*** 223,228 ****
  		if (pwd->pw_uid != 0 && (nlfd = fopen(nolog, "r")) > 0) {
  			while ((c = getc(nlfd)) != EOF)
! 				putchar(c);
! 			fflush(stdout);
  			sleep(5);
  			exit(0);
--- 226,231 ----
  		if (pwd->pw_uid != 0 && (nlfd = fopen(nolog, "r")) > 0) {
  			while ((c = getc(nlfd)) != EOF)
! 				(void) putchar(c);
! 			(void) fflush(stdout);
  			sleep(5);
  			exit(0);
***************
*** 254,259 ****
  					    "REPEATED LOGIN FAILURES ON %s, %.*s",
  						tty, NMAX, utmp.ut_name);
! 				ioctl(0, TIOCHPCL, (struct sgttyb *) 0);
! 				close(0), close(1), close(2);
  				sleep(10);
  				exit(1);
--- 257,264 ----
  					    "REPEATED LOGIN FAILURES ON %s, %.*s",
  						tty, NMAX, utmp.ut_name);
! 				(void) ioctl(0, TIOCHPCL, (char *)0);
! 				(void) close(0);
! 				(void) close(1);
! 				(void) close(2);
  				sleep(10);
  				exit(1);
***************
*** 280,286 ****
  	} while (invalid);
  /* committed to login turn off timeout */
! 	alarm(0);
  
! 	if (quota(Q_SETUID, pwd->pw_uid, 0, 0) < 0 && errno != EINVAL) {
  		if (errno == EUSERS)
  			printf("%s.\n%s.\n",
--- 285,291 ----
  	} while (invalid);
  /* committed to login turn off timeout */
! 	(void) alarm((unsigned)0);
  
! 	if (quota(Q_SETUID, pwd->pw_uid, 0, (char *)0) < 0 && errno != EINVAL) {
  		if (errno == EUSERS)
  			printf("%s.\n%s.\n",
***************
*** 294,308 ****
  		exit(0);
  	}
! 	time(&utmp.ut_time);
  	t = ttyslot();
  	if (t > 0 && (f = open("/etc/utmp", O_WRONLY)) >= 0) {
! 		lseek(f, (long)(t*sizeof(utmp)), 0);
  		SCPYN(utmp.ut_line, tty);
! 		write(f, (char *)&utmp, sizeof(utmp));
! 		close(f);
  	}
  	if ((f = open("/usr/adm/wtmp", O_WRONLY|O_APPEND)) >= 0) {
! 		write(f, (char *)&utmp, sizeof(utmp));
! 		close(f);
  	}
  	quietlog = access(qlog, F_OK) == 0;
--- 299,313 ----
  		exit(0);
  	}
! 	(void) time(&utmp.ut_time);
  	t = ttyslot();
  	if (t > 0 && (f = open("/etc/utmp", O_WRONLY)) >= 0) {
! 		(void) lseek(f, (long)(t*sizeof(utmp)), 0);
  		SCPYN(utmp.ut_line, tty);
! 		(void) write(f, (char *)&utmp, sizeof(utmp));
! 		(void) close(f);
  	}
  	if ((f = open("/usr/adm/wtmp", O_WRONLY|O_APPEND)) >= 0) {
! 		(void) write(f, (char *)&utmp, sizeof(utmp));
! 		(void) close(f);
  	}
  	quietlog = access(qlog, F_OK) == 0;
***************
*** 310,314 ****
  		struct lastlog ll;
  
! 		lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
  		if (read(f, (char *) &ll, sizeof ll) == sizeof ll &&
  		    ll.ll_time != 0 && !quietlog) {
--- 315,319 ----
  		struct lastlog ll;
  
! 		(void) lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
  		if (read(f, (char *) &ll, sizeof ll) == sizeof ll &&
  		    ll.ll_time != 0 && !quietlog) {
***************
*** 322,342 ****
  				    sizeof (ll.ll_line), ll.ll_line);
  		}
! 		lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
! 		time(&ll.ll_time);
  		SCPYN(ll.ll_line, tty);
  		SCPYN(ll.ll_host, utmp.ut_host);
! 		write(f, (char *) &ll, sizeof ll);
! 		close(f);
  	}
! 	chown(ttyn, pwd->pw_uid, TTYGID(pwd->pw_gid));
  	if (!hflag && !rflag)					/* XXX */
! 		ioctl(0, TIOCSWINSZ, &win);
! 	chmod(ttyn, 0620);
! 	setgid(pwd->pw_gid);
! 	strncpy(name, utmp.ut_name, NMAX);
  	name[NMAX] = '\0';
! 	initgroups(name, pwd->pw_gid);
! 	quota(Q_DOWARN, pwd->pw_uid, (dev_t)-1, 0);
! 	setuid(pwd->pw_uid);
  	/* destroy environment unless user has asked to preserve it */
  	if (!pflag)
--- 327,347 ----
  				    sizeof (ll.ll_line), ll.ll_line);
  		}
! 		(void) lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
! 		(void) time(&ll.ll_time);
  		SCPYN(ll.ll_line, tty);
  		SCPYN(ll.ll_host, utmp.ut_host);
! 		(void) write(f, (char *) &ll, sizeof ll);
! 		(void) close(f);
  	}
! 	(void) chown(ttyn, pwd->pw_uid, TTYGID(pwd->pw_gid));
  	if (!hflag && !rflag)					/* XXX */
! 		(void) ioctl(0, TIOCSWINSZ, (char *)&win);
! 	(void) chmod(ttyn, 0620);
! 	(void) setgid(pwd->pw_gid);
! 	(void) strncpy(name, utmp.ut_name, NMAX);
  	name[NMAX] = '\0';
! 	(void) initgroups(name, pwd->pw_gid);
! 	(void) quota(Q_DOWARN, pwd->pw_uid, (dev_t)-1, (char *)0);
! 	(void) setuid(pwd->pw_uid);
  	/* destroy environment unless user has asked to preserve it */
  	if (!pflag)
***************
*** 348,352 ****
  	while (environ[i] != NULL)
  		i++;
! 	envnew = (char **) malloc(sizeof (char *) * (i + 1));
  	for (; i >= 0; i--)
  		envnew[i] = environ[i];
--- 353,357 ----
  	while (environ[i] != NULL)
  		i++;
! 	envnew = (char **) malloc((unsigned)sizeof (char *) * (i + 1));
  	for (; i >= 0; i--)
  		envnew[i] = environ[i];
***************
*** 356,360 ****
  	setenv("SHELL=", pwd->pw_shell, 1);
  	if (term[0] == '\0')
! 		strncpy(term, stypeof(tty), sizeof(term));
  	setenv("TERM=", term, 0);
  	setenv("USER=", pwd->pw_name, 1);
--- 361,365 ----
  	setenv("SHELL=", pwd->pw_shell, 1);
  	if (term[0] == '\0')
! 		(void) strncpy(term, stypeof(tty), sizeof(term));
  	setenv("TERM=", term, 0);
  	setenv("USER=", pwd->pw_name, 1);
***************
*** 365,369 ****
  	else
  		namep++;
! 	strcat(minusnam, namep);
  	if (tty[sizeof("tty")-1] == 'd')
  		syslog(LOG_INFO, "DIALUP %s, %s", tty, pwd->pw_name);
--- 370,374 ----
  	else
  		namep++;
! 	(void) strcat(minusnam, namep);
  	if (tty[sizeof("tty")-1] == 'd')
  		syslog(LOG_INFO, "DIALUP %s, %s", tty, pwd->pw_name);
***************
*** 378,382 ****
  
  		showmotd();
! 		strcat(maildir, pwd->pw_name);
  		if (stat(maildir, &st) == 0 && st.st_size != 0)
  			printf("You have %smail.\n",
--- 383,387 ----
  
  		showmotd();
! 		(void) strcat(maildir, pwd->pw_name);
  		if (stat(maildir, &st) == 0 && st.st_size != 0)
  			printf("You have %smail.\n",
***************
*** 383,390 ****
  				(st.st_mtime > st.st_atime) ? "new " : "");
  	}
! 	signal(SIGALRM, SIG_DFL);
! 	signal(SIGQUIT, SIG_DFL);
! 	signal(SIGINT, SIG_DFL);
! 	signal(SIGTSTP, SIG_IGN);
  	execlp(pwd->pw_shell, minusnam, 0);
  	perror(pwd->pw_shell);
--- 388,395 ----
  				(st.st_mtime > st.st_atime) ? "new " : "");
  	}
! 	(void) signal(SIGALRM, SIG_DFL);
! 	(void) signal(SIGQUIT, SIG_DFL);
! 	(void) signal(SIGINT, SIG_DFL);
! 	(void) signal(SIGTSTP, SIG_IGN);
  	execlp(pwd->pw_shell, minusnam, 0);
  	perror(pwd->pw_shell);
***************
*** 397,401 ****
  {
  	register char *namep;
! 	char c;
  
  	while (up->ut_name[0] == '\0') {
--- 402,406 ----
  {
  	register char *namep;
! 	int c;
  
  	while (up->ut_name[0] == '\0') {
***************
*** 411,415 ****
  		}
  	}
! 	strncpy(lusername, up->ut_name, NMAX);
  	lusername[NMAX] = 0;
  	if ((pwd = getpwnam(lusername)) == NULL)
--- 416,420 ----
  		}
  	}
! 	(void) strncpy(lusername, up->ut_name, NMAX);
  	lusername[NMAX] = 0;
  	if ((pwd = getpwnam(lusername)) == NULL)
***************
*** 428,432 ****
  {
  
! 	signal(SIGINT, SIG_IGN);
  	stopmotd++;
  }
--- 433,437 ----
  {
  
! 	(void) signal(SIGINT, SIG_IGN);
  	stopmotd++;
  }
***************
*** 449,459 ****
  	register c;
  
! 	signal(SIGINT, catch);
  	if ((mf = fopen("/etc/motd", "r")) != NULL) {
  		while ((c = getc(mf)) != EOF && stopmotd == 0)
! 			putchar(c);
! 		fclose(mf);
  	}
! 	signal(SIGINT, SIG_IGN);
  }
  
--- 454,464 ----
  	register c;
  
! 	(void) signal(SIGINT, catch);
  	if ((mf = fopen("/etc/motd", "r")) != NULL) {
  		while ((c = getc(mf)) != EOF && stopmotd == 0)
! 			(void) putchar(c);
! 		(void) fclose(mf);
  	}
! 	(void) signal(SIGINT, SIG_IGN);
  }
  
***************
*** 513,521 ****
  #define	NSPEEDS	(sizeof (speeds) / sizeof (speeds[0]))
  
! doremoteterm(term, tp)
! 	char *term;
  	struct sgttyb *tp;
  {
! 	register char *cp = index(term, '/'), **cpp;
  	char *speed;
  
--- 518,526 ----
  #define	NSPEEDS	(sizeof (speeds) / sizeof (speeds[0]))
  
! doremoteterm(termstr, tp)
! 	char *termstr;
  	struct sgttyb *tp;
  {
! 	register char *cp = index(termstr, '/'), **cpp;
  	char *speed;
  
***************
*** 544,565 ****
  setenv(var, value, clobber)
  	char *var, *value;
  {
  	extern char **environ;
! 	int index = 0;
  	int varlen = strlen(var);
  	int vallen = strlen(value);
  
! 	for (index = 0; environ[index] != NULL; index++) {
! 		if (strncmp(environ[index], var, varlen) == 0) {
  			/* found it */
  			if (!clobber)
  				return;
! 			environ[index] = malloc(varlen + vallen + 1);
! 			strcpy(environ[index], var);
! 			strcat(environ[index], value);
  			return;
  		}
  	}
! 	environ = (char **) realloc(environ, sizeof (char *) * (index + 2));
  	if (environ == NULL) {
  		fprintf(stderr, "login: malloc out of memory\n");
--- 549,572 ----
  setenv(var, value, clobber)
  	char *var, *value;
+ 	int clobber;
  {
  	extern char **environ;
! 	register int i;
  	int varlen = strlen(var);
  	int vallen = strlen(value);
  
! 	for (i = 0; environ[i] != NULL; i++) {
! 		if (strncmp(environ[i], var, varlen) == 0) {
  			/* found it */
  			if (!clobber)
  				return;
! 			environ[i] = malloc((unsigned)varlen + vallen + 1);
! 			(void) strcpy(environ[i], var);
! 			(void) strcat(environ[i], value);
  			return;
  		}
  	}
! 	environ = (char **) realloc((char *)environ,
! 		(unsigned)sizeof (char *) * (i + 2));
  	if (environ == NULL) {
  		fprintf(stderr, "login: malloc out of memory\n");
***************
*** 566,573 ****
  		exit(1);
  	}
! 	environ[index] = malloc(varlen + vallen + 1);
! 	strcpy(environ[index], var);
! 	strcat(environ[index], value);
! 	environ[++index] = NULL;
  }
  
--- 573,580 ----
  		exit(1);
  	}
! 	environ[i] = malloc((unsigned)varlen + vallen + 1);
! 	(void) strcpy(environ[i], var);
! 	(void) strcat(environ[i], value);
! 	environ[++i] = NULL;
  }
  
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
Domain:	chris@mimsy.umd.edu	Path:	seismo!mimsy!chris