numerous Kerberos, syslog changes; signal() is now type sig_t
[unix-history] / usr / src / usr.bin / login / login.c
index 4f8110f..625a3aa 100644 (file)
@@ -22,7 +22,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)login.c    5.40 (Berkeley) %G%";
+static char sccsid[] = "@(#)login.c    5.44 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -98,6 +98,7 @@ main(argc, argv)
        int quietlog, passwd_req, ioctlval, timedout();
        char *domain, *salt, *envinit[1], *ttyn, *pp;
        char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10];
        int quietlog, passwd_req, ioctlval, timedout();
        char *domain, *salt, *envinit[1], *ttyn, *pp;
        char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10];
+       char localhost[MAXHOSTNAMELEN];
        char *ctime(), *ttyname(), *stypeof(), *crypt(), *getpass();
        time_t time();
        off_t lseek();
        char *ctime(), *ttyname(), *stypeof(), *crypt(), *getpass();
        time_t time();
        off_t lseek();
@@ -116,8 +117,11 @@ main(argc, argv)
         * -h is used by other servers to pass the name of the remote
         *    host to login so that it may be placed in utmp and wtmp
         */
         * -h is used by other servers to pass the name of the remote
         *    host to login so that it may be placed in utmp and wtmp
         */
-       (void)gethostname(tbuf, sizeof(tbuf));
-       domain = index(tbuf, '.');
+       domain = NULL;
+       if (gethostname(localhost, sizeof(localhost)) < 0)
+               syslog(LOG_ERR, "couldn't get local hostname: %m");
+       else
+               domain = index(localhost, '.');
 
        fflag = hflag = pflag = rflag = 0;
        passwd_req = 1;
 
        fflag = hflag = pflag = rflag = 0;
        passwd_req = 1;
@@ -176,6 +180,7 @@ main(argc, argv)
                        break;
                case '?':
                default:
                        break;
                case '?':
                default:
+                       syslog(LOG_ERR, "invalid flag");
                        (void)fprintf(stderr,
                            "usage: login [-fp] [username]\n");
                        exit(1);
                        (void)fprintf(stderr,
                            "usage: login [-fp] [username]\n");
                        exit(1);
@@ -224,7 +229,7 @@ main(argc, argv)
        openlog("login", LOG_ODELAY, LOG_AUTH);
 
        for (cnt = 0;; ask = 1) {
        openlog("login", LOG_ODELAY, LOG_AUTH);
 
        for (cnt = 0;; ask = 1) {
-               ioctlval = 0;
+               ioctlval = TTYDISC;
                (void)ioctl(0, TIOCSETD, &ioctlval);
 
                if (ask) {
                (void)ioctl(0, TIOCSETD, &ioctlval);
 
                if (ask) {
@@ -259,7 +264,10 @@ main(argc, argv)
                if (fflag && pwd) {
                        int uid = getuid();
 
                if (fflag && pwd) {
                        int uid = getuid();
 
-                       passwd_req = pwd->pw_uid == 0 ||
+                       passwd_req =
+#ifndef        KERBEROS
+                            pwd->pw_uid == 0 ||
+#endif
                            (uid && uid != pwd->pw_uid);
                }
 
                            (uid && uid != pwd->pw_uid);
                }
 
@@ -336,6 +344,7 @@ main(argc, argv)
                (void)printf("Logging in with home = \"/\".\n");
        }
 
                (void)printf("Logging in with home = \"/\".\n");
        }
 
+#if BSD > 43
 #define        TWOWEEKS        (14*24*60*60)
        if (pwd->pw_change || pwd->pw_expire)
                (void)gettimeofday(&tp, (struct timezone *)NULL);
 #define        TWOWEEKS        (14*24*60*60)
        if (pwd->pw_change || pwd->pw_expire)
                (void)gettimeofday(&tp, (struct timezone *)NULL);
@@ -360,7 +369,6 @@ main(argc, argv)
                            months[ttp->tm_mon], ttp->tm_mday, ttp->tm_year);
                }
 
                            months[ttp->tm_mon], ttp->tm_mday, ttp->tm_year);
                }
 
-#define        TWOWEEKS        (14*24*60*60)
        if (pwd->pw_change || pwd->pw_expire)
                (void)gettimeofday(&tp, (struct timezone *)NULL);
        if (pwd->pw_change)
        if (pwd->pw_change || pwd->pw_expire)
                (void)gettimeofday(&tp, (struct timezone *)NULL);
        if (pwd->pw_change)
@@ -368,21 +376,26 @@ main(argc, argv)
                        (void)printf("Sorry -- your password has expired.\n");
                        sleepexit(1);
                }
                        (void)printf("Sorry -- your password has expired.\n");
                        sleepexit(1);
                }
-               else if (tp.tv_sec - pwd->pw_change < TWOWEEKS && !quietlog) {
+               else if (pwd->pw_change - tp.tv_sec <
+                   2 * DAYSPERWEEK * SECSPERDAY && !quietlog) {
                        ttp = localtime(&pwd->pw_change);
                        (void)printf("Warning: your password expires on %s %d, %d\n",
                        ttp = localtime(&pwd->pw_change);
                        (void)printf("Warning: your password expires on %s %d, %d\n",
-                           months[ttp->tm_mon], ttp->tm_mday, TM_YEAR_BASE + ttp->tm_year);
+                           months[ttp->tm_mon], ttp->tm_mday,
+                           TM_YEAR_BASE + ttp->tm_year);
                }
        if (pwd->pw_expire)
                if (tp.tv_sec >= pwd->pw_expire) {
                        (void)printf("Sorry -- your account has expired.\n");
                        sleepexit(1);
                }
                }
        if (pwd->pw_expire)
                if (tp.tv_sec >= pwd->pw_expire) {
                        (void)printf("Sorry -- your account has expired.\n");
                        sleepexit(1);
                }
-               else if (tp.tv_sec - pwd->pw_expire < TWOWEEKS && !quietlog) {
+               else if (pwd->pw_expire - tp.tv_sec <
+                   2 * DAYSPERWEEK * SECSPERDAY && !quietlog) {
                        ttp = localtime(&pwd->pw_expire);
                        (void)printf("Warning: your account expires on %s %d, %d\n",
                        ttp = localtime(&pwd->pw_expire);
                        (void)printf("Warning: your account expires on %s %d, %d\n",
-                           months[ttp->tm_mon], ttp->tm_mday, TM_YEAR_BASE + ttp->tm_year);
+                           months[ttp->tm_mon], ttp->tm_mday,
+                           TM_YEAR_BASE + ttp->tm_year);
                }
                }
+#endif
 
        /* nothing else left to fail -- really log in */
        {
 
        /* nothing else left to fail -- really log in */
        {
@@ -416,11 +429,6 @@ main(argc, argv)
 
        if (*pwd->pw_shell == '\0')
                pwd->pw_shell = _PATH_BSHELL;
 
        if (*pwd->pw_shell == '\0')
                pwd->pw_shell = _PATH_BSHELL;
-       /* turn on new line discipline for the csh */
-       else if (!strcmp(pwd->pw_shell, _PATH_CSHELL)) {
-               ioctlval = NTTYDISC;
-               (void)ioctl(0, TIOCSETD, &ioctlval);
-       }
 
        /* destroy environment unless user has requested preservation */
        if (!pflag)
 
        /* destroy environment unless user has requested preservation */
        if (!pflag)
@@ -461,8 +469,10 @@ main(argc, argv)
        strcpy(tbuf + 1, (p = rindex(pwd->pw_shell, '/')) ?
            p + 1 : pwd->pw_shell);
 
        strcpy(tbuf + 1, (p = rindex(pwd->pw_shell, '/')) ?
            p + 1 : pwd->pw_shell);
 
+#if    BSD > 43
        if (setlogname(pwd->pw_name, strlen(pwd->pw_name)) < 0)
                syslog(LOG_ERR, "setlogname() failure: %m");
        if (setlogname(pwd->pw_name, strlen(pwd->pw_name)) < 0)
                syslog(LOG_ERR, "setlogname() failure: %m");
+#endif
 
        /* discard permissions last so can't get killed and drop core */
        (void)setuid(pwd->pw_uid);
 
        /* discard permissions last so can't get killed and drop core */
        (void)setuid(pwd->pw_uid);
@@ -519,7 +529,8 @@ jmp_buf motdinterrupt;
 motd()
 {
        register int fd, nchars;
 motd()
 {
        register int fd, nchars;
-       int (*oldint)(), sigint();
+       sig_t oldint;
+       int sigint();
        char tbuf[8192];
 
        if ((fd = open(_PATH_MOTDFILE, O_RDONLY, 0)) < 0)
        char tbuf[8192];
 
        if ((fd = open(_PATH_MOTDFILE, O_RDONLY, 0)) < 0)