- chown(ttyn, pwd->pw_uid, pwd->pw_gid);
- setgid(pwd->pw_gid);
- strncpy(name, utmp.ut_name, NMAX);
- name[NMAX] = '\0';
- inigrp(name, pwd->pw_gid);
- setuid(pwd->pw_uid);
- environ = envinit;
- strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
- strncat(shell, pwd->pw_shell, sizeof(shell)-7);
- if (term[strlen("TERM=")] == 0)
- strncat(term, stypeof(ttyn), sizeof(term)-6);
- strncat(user, pwd->pw_name, sizeof(user)-6);
- if ((namep = rindex(pwd->pw_shell, '/')) == NULL)
- namep = pwd->pw_shell;
- else
- namep++;
- strcat(minusnam, namep);
- alarm(0);
- umask(022);
- if (ttyn[sizeof("/dev/tty")-1] == 'd')
- logerr("DIALUP %s %s\n", ttyn+sizeof("/dev/")-1, pwd->pw_name);
+
+ if (chdir(pwd->pw_dir) < 0) {
+ printf("No directory %s!\n", pwd->pw_dir);
+ if (chdir("/"))
+ exit(0);
+ pwd->pw_dir = "/";
+ printf("Logging in with home = \"/\".\n");
+ }
+
+ /* nothing else left to fail -- really log in */
+ {
+ struct utmp utmp;
+
+ (void)time(&utmp.ut_time);
+ strncpy(utmp.ut_name, username, sizeof(utmp.ut_name));
+ strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host));
+ strncpy(utmp.ut_line, tty, sizeof(utmp.ut_line));
+ login(&utmp);
+ }
+
+ quietlog = access(HUSHLOGIN, F_OK) == 0;
+ dolastlog(quietlog);
+
+ if (!hflag) { /* XXX */
+ static struct winsize win = { 0, 0, 0, 0 };
+
+ (void)ioctl(0, TIOCSWINSZ, &win);
+ }
+
+ (void)chown(ttyn, pwd->pw_uid,
+ (gr = getgrnam(TTYGRPNAME)) ? gr->gr_gid : pwd->pw_gid);
+ (void)chmod(ttyn, 0620);
+ (void)setgid(pwd->pw_gid);
+
+ initgroups(username, pwd->pw_gid);
+
+ quota(Q_DOWARN, pwd->pw_uid, (dev_t)-1, 0);
+ (void)setuid(pwd->pw_uid);
+
+ if (*pwd->pw_shell == '\0')
+ pwd->pw_shell = BSHELL;
+ /* turn on new line discipline for the csh */
+ else if (!strcmp(pwd->pw_shell, "/bin/csh")) {
+ ioctlval = NTTYDISC;
+ (void)ioctl(0, TIOCSETD, &ioctlval);
+ }
+
+ /* destroy environment unless user has requested preservation */
+ if (!pflag)
+ environ = envinit;
+ (void)setenv("HOME", pwd->pw_dir, 1);
+ (void)setenv("SHELL", pwd->pw_shell, 1);
+ if (term[0] == '\0')
+ strncpy(term, stypeof(), sizeof(term));
+ (void)setenv("TERM", term, 0);
+ (void)setenv("USER", pwd->pw_name, 1);
+ (void)setenv("PATH", "/usr/ucb:/bin:/usr/bin:", 0);
+
+ if (tty[sizeof("tty")-1] == 'd')
+ syslog(LOG_INFO, "DIALUP %s, %s", tty, pwd->pw_name);
+ if (pwd->pw_uid == 0)
+ if (hostname)
+ syslog(LOG_NOTICE, "ROOT LOGIN %s FROM %s",
+ tty, hostname);
+ else
+ syslog(LOG_NOTICE, "ROOT LOGIN %s", tty);
+