Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions Subject: Re: Problem with getuid() -- same as geteuid()?! Message-ID: <5315@star.cs.vu.nl> Date: 6 Feb 90 15:38:41 GMT References: <1836@clyde.concordia.ca> <1837@clyde.concordia.ca> Sender: news@cs.vu.nl Reply-To: maart@cs.vu.nl (Maarten Litmaath) Organization: VU Informatika, Amsterdam, the Netherlands Lines: 53 In article <1837@clyde.concordia.ca>, smw@maxwell.Concordia.CA ( Steven Winikoff ) writes: \In article tale@cs.rpi.edu (David C Lawrence) writes: \ \>@opinionated sidebar \>I personally loathe getlogin() and programmes that are concerned with \>what userid I might have started out as on some pre-su level, [...] \... \My problem is that there are several people at our site who are legitimately \able to su root, working on different projects at the same time (perhaps \that's a bad idea, but it's not under my control). In any case, the idea \is to find some way to identify our printed output, [...] But that's precisely what UCB's lpr does! By means of getlogin()! :-( Anyway, you could always replace lpr by something like this: #include #include char My_lpr[] = "/path/of/my_lpr"; main(argc, argv) int argc; char **argv; { char *getenv(), *lprname = getenv("LPRNAME"); struct passwd *pw; if (lprname) { if (!(pw = getpwnam(lprname))) fprintf(stderr, "You don't exist. Go away.\n"); else if (setuid(pw->pw_uid) != 0) perror("setuid"); } argv[0] = My_lpr; execv(My_lpr, argv); perror(My_lpr); exit(1); } ...where `my_lpr' is: #!/bin/sh exec 3>&1 test -t 0 && exec < /dev/null (/usr/ucb/lpr ${1+"$@"} | cat >&3) 2>&1 | cat >&2 -- The meek get the earth, Henry the moon, the rest of us have other plans. | Maarten Litmaath @ VU Amsterdam: maart@cs.vu.nl, uunet!mcsun!botter!maart