- 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, WRITEGID);
- 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 */
+ else if (tp.tv_sec - pwd->pw_change < TWOWEEKS) {
+ ttp = localtime(&pwd->pw_change);
+ printf("Warning: your password expires on %s %d, 19%d\n",
+ months[ttp->tm_mon], ttp->tm_mday, ttp->tm_year);
+ }
+ if (pwd->pw_expire)
+ if (tp.tv_sec >= pwd->pw_expire) {
+ printf("Sorry -- your account has expired.\n");
+ sleepexit(1);
+ }
+ else if (tp.tv_sec - pwd->pw_expire < TWOWEEKS) {
+ ttp = localtime(&pwd->pw_expire);
+ printf("Warning: your account expires on %s %d, 19%d\n",
+ months[ttp->tm_mon], ttp->tm_mday, ttp->tm_year);
+ }
+
+ if (pwd->pw_change || pwd->pw_expire)
+ (void)gettimeofday(&tp, (struct timezone *)NULL);
+ if (pwd->pw_change)
+ if (tp.tv_sec >= pwd->pw_change) {
+ (void)printf("Sorry -- your password has expired.\n");
+ sleepexit(1);
+ } else if (pwd->pw_change - tp.tv_sec <
+ 2 * DAYSPERWEEK * SECSPERDAY && !quietlog)
+ (void)printf("Warning: your password expires on %s",
+ ctime(&pwd->pw_change));
+ if (pwd->pw_expire)
+ if (tp.tv_sec >= pwd->pw_expire) {
+ (void)printf("Sorry -- your account has expired.\n");
+ sleepexit(1);
+ } else if (pwd->pw_expire - tp.tv_sec <
+ 2 * DAYSPERWEEK * SECSPERDAY && !quietlog)
+ (void)printf("Warning: your account expires on %s",
+ ctime(&pwd->pw_expire));
+
+ /* Nothing else left to fail -- really log in. */
+ memset((void *)&utmp, 0, sizeof(utmp));
+ (void)time(&utmp.ut_time);
+ (void)strncpy(utmp.ut_name, username, sizeof(utmp.ut_name));
+ if (hostname)
+ (void)strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host));
+ (void)strncpy(utmp.ut_line, tty, sizeof(utmp.ut_line));
+ login(&utmp);
+
+ dolastlog(quietlog);
+
+ (void)chown(ttyn, pwd->pw_uid,
+ (gr = getgrnam(TTYGRPNAME)) ? gr->gr_gid : pwd->pw_gid);
+ (void)setgid(pwd->pw_gid);
+
+ initgroups(username, pwd->pw_gid);
+
+ if (*pwd->pw_shell == '\0')
+ pwd->pw_shell = _PATH_BSHELL;
+
+ /* Destroy environment unless user has requested its preservation. */