Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!topaz.rutgers.edu!ron From: ron@topaz.rutgers.edu (Ron Natalie) Newsgroups: comp.unix.wizards Subject: Re: Pseudo-tty ownership problem Message-ID: <15300@topaz.rutgers.edu> Date: Sun, 4-Oct-87 14:38:54 EDT Article-I.D.: topaz.15300 Posted: Sun Oct 4 14:38:54 1987 Date-Received: Wed, 7-Oct-87 06:23:31 EDT References: <730@quacky.UUCP> <6503@brl-smoke.ARPA> Organization: Rutgers Univ., New Brunswick, N.J. Lines: 87 Enclosed... A program that when made setuid root allows a user who is so authorized to chown a pty to himself and free it up later. I needed this for when I added user mode attach/detach to UNIX. This program must be called with the open control side of the PTY as file descriptor 0 (to prove that the user has passed the kernel restrictions on who can use the pty) and the name of the PTY. There was code to create a UTMP entry for the pty (-u) and delete the utmp entry when done, but I've removed that as it was shamelessly stolen from some other program which is probably under license (I think it was login). --- Cut Here --- #include #include #include #include char *filename = "/dev/ptyxx"; main(argc, argv) int argc; char **argv; { int i; int foo = 0; int aflag = 0; int dflag = 0; int uflag = 0; char *ptyname = 0; struct stat statf, statd; while(--argc) { ++argv; if(*argv[0] == '-') { if(argv[0][1] == 'a') aflag++; if(argv[0][1] == 'd') dflag++; if(argv[0][1] == 'u') uflag++; } else ptyname = *argv; } if( (aflag + dflag) != 1 || (ptyname == 0)) { fprintf(stderr, "Usage: pty {-a or -d} ptycontrol\n"); exit(1); } filename[8] = ptyname[0]; filename[9] = ptyname[1]; if(stat(filename, &statd) == -1) { perror(filename); exit(2); } if(fstat(0, &statf) == -1) { perror("std in"); exit(3); } if(( statd.st_mode&S_IFMT) != S_IFCHR) { fprintf(stderr, "%s: not a pty\n", filename); exit(4); } if(( statf.st_mode&S_IFMT) != S_IFCHR) { fprintf(stderr, "std in: not a pty\n"); exit(5); } if(statf.st_rdev != statd.st_rdev) { fprintf(stderr, "std in does not match pty controller\n"); exit(6); } filename[5] = 't'; if(aflag) { chmod(filename, 0611); i = chown(filename, getuid(), getgid()); } if(dflag) { rmut(); } if(i == -1) { perror(filename); exit(7); } exit(0); }