+ if (argc > 1 && !strcmp(argv[1], "-r")) {
+ rflag++;
+ rhost = argv[2];
+ argc = 1;
+ getstr(rusername, sizeof (rusername), "remuser");
+ getstr(lusername, sizeof (lusername), "locuser");
+ getstr(term+5, sizeof(term)-5, "Terminal type");
+ if (getuid())
+ goto abnormal;
+ setpwent();
+ pwd = getpwnam(lusername);
+ endpwent();
+ if (pwd == NULL)
+ goto abnormal;
+ hostf = pwd->pw_uid ? fopen("/etc/hosts.equiv", "r") : 0;
+ again:
+ if (hostf) {
+ char ahost[32];
+
+ while (fgets(ahost, sizeof (ahost), hostf)) {
+ char *user;
+
+ if ((user = index(ahost, '\n')) != 0)
+ *user++ = '\0';
+ if ((user = index(ahost, ' ')) != 0)
+ *user++ = '\0';
+ if (!strcmp(rhost, ahost) &&
+ !strcmp(rusername, user ?
+ user : lusername)) {
+ fclose(hostf);
+ goto normal;
+ }
+ }
+ fclose(hostf);
+ }
+ if (first == 1) {
+ char *rhosts = ".rhosts";
+ struct stat sbuf;
+
+ first = 0;
+ if (chdir(pwd->pw_dir) < 0)
+ goto again;
+ if (lstat(rhosts, &sbuf) < 0)
+ goto again;
+ if ((sbuf.st_mode & S_IFMT) == S_IFLNK) {
+ printf("login: .rhosts is a soft link.\r\n");
+ goto abnormal;
+ }
+ hostf = fopen(rhosts, "r");
+ fstat(fileno(hostf), &sbuf);
+ if ((int) sbuf.st_uid != pwd->pw_uid &&
+ (int) sbuf.st_uid != 0) {
+ printf("login: Bad .rhosts ownership.\r\n");
+ fclose(hostf);
+ goto abnormal;
+ }
+ goto again;
+ }
+abnormal:
+ rhost = 0;
+ rflag = -1;
+ }
+normal:
+ ioctl(0, TIOCLSET, &zero); /* XXX */
+ ioctl(0, TIOCNXCL, 0);
+ ioctl(0, FIONBIO, &zero);
+ ioctl(0, FIOASYNC, &zero);
+ ioctl(0, TIOCGETP, &ttyb); /* XXX */
+ if (rflag) {
+ char *cp = index(term, '/');
+ if (cp) {
+ int i;
+ *cp++ = 0;
+ for (i = 0; i < NSPEEDS; i++)
+ if (!strcmp(speeds[i], cp)) {
+ ttyb.sg_ispeed = ttyb.sg_ospeed = i;
+ break;
+ }
+ }
+ ttyb.sg_flags = ECHO|CRMOD|ANYP|XTABS;
+ }
+ ioctl(0, TIOCSETP, &ttyb); /* XXX */
+ ioctl(0, TIOCCSET, &tc);