Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!ll-xn!mit-eddie!oberon.lcs.mit.edu!billw From: billw@oberon.lcs.mit.edu (Bill Wisner) Newsgroups: comp.sources.bugs Subject: Problem in Dan Heller's "dots" game Message-ID: <7765@eddie.MIT.EDU> Date: 30 Dec 87 04:49:17 GMT Sender: uucp@eddie.MIT.EDU Reply-To: billw@oberon.lcs.mit.edu (Bill Wisner) Organization: MIT Laboratory for Computer Science Lines: 63 Due to a problem with the format of /etc/utmp, dots can't handle 2-player games against someone with an eight-letter username. The following replacement for findem.c alleviates the problem. -- (cut here) /* findem.c find the login of the person we wanna play */ #include "dots.h" #include #include #include #define UTMP "/etc/utmp" struct utmp utmp_buf; struct stat stat_buf; struct sgttyb sgtty_buf; int fd; findem(argc, argv) char **argv; { char *ttyname(), to_tty[13], *tmp_name; register char *login = argv[2], *where = "", *ourtty = ttyname(0) + 5; register FILE *recipient; if (argc > 3) where = argv[3]; if (!strcmp(where, ourtty)) { fprintf(stderr, "You can't play yourself.\n"); return 0; } if ((fd = open(UTMP, 0)) == -1) { perror(UTMP); return 0; } while (read(fd, (char *) &utmp_buf, sizeof(utmp_buf))) if (!strncmp(utmp_buf.ut_name, login, 8) && (*where && !strcmp(utmp_buf.ut_line, where) || (!*where && strcmp(where, ourtty)))) break; (void) close(fd); if (strncmp(login, utmp_buf.ut_name, 8)) { fprintf(stderr, "%s is not logged in.", login); return 0; } if (*where && strcmp(where, utmp_buf.ut_line)) { fprintf(stderr, "%s is not logged in on %s.\n", login, where); return 0; } (void) sprintf(to_tty, "/dev/%s", utmp_buf.ut_line); if (!(recipient = fopen(to_tty, "w"))) { perror(to_tty); fprintf(stderr, "%s: Can't ask %s to play.\n", argv[0], argv[2]); return 0; } setuid(getuid()); /* turns off set-uid attribute once tty is opened */ setgid(getgid()); /* probably isn't necessary most of the time */ return invite(recipient); }