|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T f
Length: 1475 (0x5c3) Types: TextFile Names: »findem.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Dots/findem.c«
/* findem.c find the login of the person we wanna play */ #include "dots.h" #include <sys/stat.h> #include <sgtty.h> #include <utmp.h> #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]; 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 (!strcmp(utmp_buf.ut_name, login) && (*where && !strcmp(utmp_buf.ut_line, where) || (!*where && strcmp(where, ourtty)))) break; (void) close(fd); if (strcmp(login, utmp_buf.ut_name)) { 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); }