add in -r flag for shadow password package
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 18 Mar 1989 04:46:00 +0000 (20:46 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sat, 18 Mar 1989 04:46:00 +0000 (20:46 -0800)
SCCS-vsn: usr.bin/login/login.c 5.32.1.3

usr/src/usr.bin/login/login.c

index 80ac767..3b5a1b7 100644 (file)
@@ -22,11 +22,12 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)login.c    5.37 (Berkeley) %G%";
+static char sccsid[] = "@(#)login.c    5.32.1.3 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
  * login [ name ]
 #endif /* not lint */
 
 /*
  * login [ name ]
+ * login -r hostname   (for rlogind)
  * login -h hostname   (for telnetd, etc.)
  * login -f name       (for pre-authenticated login: datakit, xterm, etc.)
  */
  * login -h hostname   (for telnetd, etc.)
  * login -f name       (for pre-authenticated login: datakit, xterm, etc.)
  */
@@ -93,7 +94,7 @@ main(argc, argv)
        struct group *gr;
        register int ch;
        register char *p;
        struct group *gr;
        register int ch;
        register char *p;
-       int ask, fflag, hflag, pflag, cnt;
+       int ask, fflag, hflag, pflag, rflag, cnt;
        int quietlog, passwd_req, ioctlval, timedout();
        char *domain, *salt, *envinit[1], *ttyn, *pp;
        char tbuf[MAXPATHLEN + 2];
        int quietlog, passwd_req, ioctlval, timedout();
        char *domain, *salt, *envinit[1], *ttyn, *pp;
        char tbuf[MAXPATHLEN + 2];
@@ -110,6 +111,7 @@ main(argc, argv)
 
        /*
         * -p is used by getty to tell login not to destroy the environment
 
        /*
         * -p is used by getty to tell login not to destroy the environment
+        * -r is used by rlogind to cause the autologin protocol;
         * -f is used to skip a second login authentication 
         * -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
         * -f is used to skip a second login authentication 
         * -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
@@ -117,11 +119,16 @@ main(argc, argv)
        (void)gethostname(tbuf, sizeof(tbuf));
        domain = index(tbuf, '.');
 
        (void)gethostname(tbuf, sizeof(tbuf));
        domain = index(tbuf, '.');
 
-       fflag = hflag = pflag = 0;
+       fflag = hflag = pflag = rflag = 0;
        passwd_req = 1;
        passwd_req = 1;
-       while ((ch = getopt(argc, argv, "fh:p")) != EOF)
+       while ((ch = getopt(argc, argv, "fh:pr:")) != EOF)
                switch (ch) {
                case 'f':
                switch (ch) {
                case 'f':
+                       if (rflag) {
+                               fprintf(stderr,
+                                   "login: only one of -r and -f allowed.\n");
+                               exit(1);
+                       }
                        fflag = 1;
                        break;
                case 'h':
                        fflag = 1;
                        break;
                case 'h':
@@ -130,6 +137,11 @@ main(argc, argv)
                                    "login: -h for super-user only.\n");
                                exit(1);
                        }
                                    "login: -h for super-user only.\n");
                                exit(1);
                        }
+                       if (rflag) {
+                               fprintf(stderr,
+                                   "login: only one of -r and -h allowed.\n");
+                               exit(1);
+                       }
                        hflag = 1;
                        if (domain && (p = index(optarg, '.')) &&
                            strcasecmp(p, domain) == 0)
                        hflag = 1;
                        if (domain && (p = index(optarg, '.')) &&
                            strcasecmp(p, domain) == 0)
@@ -139,6 +151,29 @@ main(argc, argv)
                case 'p':
                        pflag = 1;
                        break;
                case 'p':
                        pflag = 1;
                        break;
+               case 'r':
+                       if (hflag || fflag) {
+                               fprintf(stderr,
+                                   "login: -f and -h not allowed with -r.\n");
+                               exit(1);
+                       }
+                       if (getuid()) {
+                               fprintf(stderr,
+                                   "login: -r for super-user only.\n");
+                               exit(1);
+                       }
+                       /* "-r hostname" must be last args */
+                       if (optind != argc) {
+                               fprintf(stderr, "Syntax error.\n");
+                               exit(1);
+                       }
+                       rflag = 1;
+                       passwd_req = (doremotelogin(optarg) == -1);
+                       if (domain && (p = index(optarg, '.')) &&
+                           !strcmp(p, domain))
+                               *p = '\0';
+                       hostname = optarg;
+                       break;
                case '?':
                default:
                        fprintf(stderr, "usage: login [-fp] [username]\n");
                case '?':
                default:
                        fprintf(stderr, "usage: login [-fp] [username]\n");
@@ -151,12 +186,21 @@ main(argc, argv)
                ask = 0;
        } else
                ask = 1;
                ask = 0;
        } else
                ask = 1;
+       if (rflag)
+               ask = 0;
 
        ioctlval = 0;
        (void)ioctl(0, TIOCLSET, &ioctlval);
        (void)ioctl(0, TIOCNXCL, 0);
        (void)fcntl(0, F_SETFL, ioctlval);
        (void)ioctl(0, TIOCGETP, &sgttyb);
 
        ioctlval = 0;
        (void)ioctl(0, TIOCLSET, &ioctlval);
        (void)ioctl(0, TIOCNXCL, 0);
        (void)fcntl(0, F_SETFL, ioctlval);
        (void)ioctl(0, TIOCGETP, &sgttyb);
+
+       /*
+        * If talking to an rlogin process, propagate the terminal type and
+        * baud rate across the network.
+        */
+       if (rflag)
+               doremoteterm(&sgttyb);
        sgttyb.sg_erase = CERASE;
        sgttyb.sg_kill = CKILL;
        (void)ioctl(0, TIOCSLTC, &ltc);
        sgttyb.sg_erase = CERASE;
        sgttyb.sg_kill = CKILL;
        (void)ioctl(0, TIOCSLTC, &ltc);
@@ -349,7 +393,7 @@ main(argc, argv)
 
        dolastlog(quietlog);
 
 
        dolastlog(quietlog);
 
-       if (!hflag) {                                   /* XXX */
+       if (!hflag && !rflag) {                                 /* XXX */
                static struct winsize win = { 0, 0, 0, 0 };
 
                (void)ioctl(0, TIOCSWINSZ, &win);
                static struct winsize win = { 0, 0, 0, 0 };
 
                (void)ioctl(0, TIOCSWINSZ, &win);
@@ -576,3 +620,46 @@ sleepexit(eval)
        sleep((u_int)5);
        exit(eval);
 }
        sleep((u_int)5);
        exit(eval);
 }
+
+doremotelogin(host)
+       char *host;
+{
+       static char lusername[UT_NAMESIZE+1];
+       char rusername[UT_NAMESIZE+1];
+
+       getstr(rusername, sizeof(rusername), "remuser");
+       getstr(lusername, sizeof(lusername), "locuser");
+       getstr(term, sizeof(term), "Terminal type");
+       username = lusername;
+       pwd = getpwnam(username);
+       if (pwd == NULL)
+               return(-1);
+       return(ruserok(host, (pwd->pw_uid == 0), rusername, username));
+}
+
+char *speeds[] = {
+       "0", "50", "75", "110", "134", "150", "200", "300", "600",
+       "1200", "1800", "2400", "4800", "9600", "19200", "38400",
+};
+#define        NSPEEDS (sizeof(speeds) / sizeof(speeds[0]))
+
+doremoteterm(tp)
+       struct sgttyb *tp;
+{
+       register char *cp = index(term, '/'), **cpp;
+       char *speed;
+
+       if (cp) {
+               *cp++ = '\0';
+               speed = cp;
+               cp = index(speed, '/');
+               if (cp)
+                       *cp++ = '\0';
+               for (cpp = speeds; cpp < &speeds[NSPEEDS]; cpp++)
+                       if (strcmp(*cpp, speed) == 0) {
+                               tp->sg_ispeed = tp->sg_ospeed = cpp-speeds;
+                               break;
+                       }
+       }
+       tp->sg_flags = ECHO|CRMOD|ANYP|XTABS;
+}