[2770] in Release_Engineering
/bin/login changes from dialup
daemon@ATHENA.MIT.EDU (Mark Rosenstein)
Wed Apr 15 00:32:28 1992
Date: Wed, 15 Apr 92 00:32:04 -0400
From: Mark Rosenstein <mar@MIT.EDU>
To: rel-eng@MIT.EDU
These changes:
1) If a user has been deactivated (i.e. kerberos but no hesiod) do not
let them login.
2) Properly lock /etc/passwd when editing it
3) If we notice that /etc/passwd got stepped on, then create one with
just a root entry and complain loudly.
-Mark
*** /source/athena/bin/login/login.c Sun Apr 5 17:41:50 1992
--- ./login.c Wed Nov 6 15:51:44 1991
***************
*** 1,9 ****
/*
! * $Id: login.c,v 1.42 1991/08/24 17:41:35 probe Exp $
*/
#ifndef lint
! static char *rcsid = "$Id: login.c,v 1.42 1991/08/24 17:41:35 probe Exp $";
#endif
/*
--- 1,9 ----
/*
! * $Id: login.c,v 1.1 91/11/01 16:00:32 mar Exp Locker: mar $
*/
#ifndef lint
! static char *rcsid = "$Id: login.c,v 1.1 91/11/01 16:00:32 mar Exp Locker: mar $";
#endif
/*
***************
*** 463,469 ****
if (inhibitflag)
invalid = TRUE;
else /* we are allowed to create an entry */
! pwd = &newuser;
/* Modifications for Kerberos authentication -- asp */
SCPYN(pp2, pp);
--- 463,469 ----
if (inhibitflag)
invalid = TRUE;
else /* we are allowed to create an entry */
! pwd = &nouser;
/* Modifications for Kerberos authentication -- asp */
SCPYN(pp2, pp);
***************
*** 519,532 ****
pwd->pw_gid = nspwd->pw_gid;
pwd->pw_gecos = nspwd->pw_gecos;
pwd->pw_shell = nspwd->pw_shell;
} else {
! pwd->pw_uid = 200;
! pwd->pw_gid = MIT_GID;
! pwd->pw_gecos = "";
! pwd->pw_shell = "/bin/csh";
}
strncpy(pwd->pw_name, utmp.ut_name, NMAX);
- strncat(pwd->pw_dir, utmp.ut_name, NMAX);
(void) insert_pwent(pwd);
tmppwflag = TRUE;
}
--- 519,530 ----
pwd->pw_gid = nspwd->pw_gid;
pwd->pw_gecos = nspwd->pw_gecos;
pwd->pw_shell = nspwd->pw_shell;
+ pwd->pw_dir = nspwd->pw_dir;
} else {
! invalid = TRUE;
! goto leavethis;
}
strncpy(pwd->pw_name, utmp.ut_name, NMAX);
(void) insert_pwent(pwd);
tmppwflag = TRUE;
}
***************
*** 1566,1580 ****
struct passwd *pwd;
{
FILE *pfile;
! int cnt;
while (getpwuid(pwd->pw_uid))
(pwd->pw_uid)++;
cnt = 10;
! while (!access("/etc/ptmp",0) && --cnt)
! sleep(1);
! unlink("/etc/ptmp");
if((pfile=fopen("/etc/passwd", "a")) != NULL) {
fprintf(pfile, "%s:%s:%d:%d:%s:%s:%s\n",
--- 1564,1583 ----
struct passwd *pwd;
{
FILE *pfile;
! int cnt, fd;
while (getpwuid(pwd->pw_uid))
(pwd->pw_uid)++;
cnt = 10;
! while (cnt-- > 0 &&
! (fd = open("/etc/ptmp", O_WRONLY|O_CREAT|O_EXCL, 0644)) < 0)
! sleep(1);
! if (fd < 0) {
! syslog(LOG_CRIT, "failed to lock /etc/passwd for insert");
! printf("Failed to add you to /etc/passwd\n");
! }
!
if((pfile=fopen("/etc/passwd", "a")) != NULL) {
fprintf(pfile, "%s:%s:%d:%d:%s:%s:%s\n",
***************
*** 1587,1592 ****
--- 1590,1598 ----
pwd->pw_shell);
fclose(pfile);
}
+
+ close(fd);
+ unlink("/etc/ptmp");
}
remove_pwent(pwd)
***************
*** 1594,1607 ****
{
FILE *newfile;
struct passwd *copypw;
! int cnt;
cnt = 10;
! while (!access("/etc/ptmp",0) && --cnt)
! sleep(1);
! unlink("/etc/ptmp");
!
! if ((newfile = fopen("/etc/ptmp", "w")) != NULL) {
setpwent();
while ((copypw = getpwent()) != 0)
if (copypw->pw_uid != pwd->pw_uid)
--- 1600,1618 ----
{
FILE *newfile;
struct passwd *copypw;
! struct stat statb;
! int cnt, fd;
cnt = 10;
! while (cnt-- > 0 &&
! (fd = open("/etc/ptmp", O_WRONLY|O_CREAT|O_EXCL, 0644)) < 0)
! sleep(1);
! if (fd < 0) {
! syslog(LOG_CRIT, "failed to lock /etc/passwd for remove");
! printf("Failed to remove you from /etc/passwd\n");
! }
!
! if ((newfile = fdopen(fd, "w")) != NULL) {
setpwent();
while ((copypw = getpwent()) != 0)
if (copypw->pw_uid != pwd->pw_uid)
***************
*** 1615,1621 ****
copypw->pw_shell);
endpwent();
fclose(newfile);
! rename("/etc/ptmp", "/etc/passwd");
return(0);
} else return(1);
}
--- 1626,1647 ----
copypw->pw_shell);
endpwent();
fclose(newfile);
! if (stat("/etc/ptmp", &statb) != 0 || statb.st_size < 80) {
! syslog(LOG_CRIT, "something stepped on /etc/ptmp");
! printf("Failed to cleanup login\n");
! } else
! rename("/etc/ptmp", "/etc/passwd");
! if (stat("/etc/passwd", &statb) != 0 || statb.st_size < 80) {
! syslog(LOG_CRIT, "something stepped on /etc/passwd");
! printf("Failed to cleanup login\n");
! sleep(12);
! if (stat("/etc/passwd", &statb) != 0 || statb.st_size < 80) {
! syslog(LOG_CRIT, "/etc/passwd still empty, adding root");
! newfile = fopen("/etc/passwd", "w");
! fprintf(newfile, "root:*:0:1:System PRIVILEGED Account:/:/bin/csh\n");
! fclose(newfile);
! }
! }
return(0);
} else return(1);
}