Path: utzoo!attcan!uunet!clyde.concordia.ca!maxwell!smw From: smw@maxwell.Concordia.CA ( Steven Winikoff ) Newsgroups: comp.unix.questions Subject: Re: Problem with getuid() -- same as geteuid()?! Message-ID: <1844@clyde.concordia.ca> Date: 7 Feb 90 19:15:29 GMT References: <1836@clyde.concordia.ca> <1837@clyde.concordia.ca> <5315@star.cs.vu.nl> Sender: usenet@clyde.concordia.ca Reply-To: smw@maxwell.Concordia.CA ( Steven Winikoff ) Organization: Concordia University, Montreal, Quebec Lines: 94 First, my apologies if this gets posted twice. The first one apparently vanished into the bit bucket. In article <5315@star.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: >In article <1837@clyde.concordia.ca>, > smw@maxwell.Concordia.CA ( Steven Winikoff ) writes: >\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()! :-( True. But if I could use lpr in the first place, none of this would have arisen... :-) Fact is that the printer I'm trying to reach is connected to a CDC Cyber under NOS (CDC's proprietary OS, for those unfamiliar with Control Data). The Cyber is connected to a VMS VAX 8550 via JNET, and my Unix system is connected to the VAX via a MicroVAX running Ultrix! Are you now as confused as I am? If not, all you have to do is reread the above paragraph a couple of dozen times, and then your head will be spinning just like mine! :-) No, there's no way I can get a printer closer than that. :-( And no, there's no way (at least none that our Powers That Be will agree to finance!) to bridge the gap between Unix and the Cyber directly. :-( So I'm stuck with writing an application that wants to send a file to the VAX via ftp, along with instructions re what to do with it when it gets there. A client process on the VAX takes the file and automagically routes it over the JNET link. (The VAX/Cyber link is maintained by our local VMS guru. My personal VMS knowledge ranges between poor and non-existent.) That's why I need some reliable way of determining who *really* sent a given file, simply because I'd like to be able to recognize my own output when I get it! When I began all this, I naively thought that getuid would do it for me. Now I know that it won't. Based on the suggestions of all the kind people who have so far responded to me, it seems that the best I can do in the case where getuid returns 0 is a tiered approach which begins with getlogin and falls back on logname (== value of $USER) when getlogin fails. >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 I'm not quite sure I understand your code. Who sets LPRNAME? In "my_lpr", what gets exec'd in line 2? Please excuse my ignorance, I'm only a wizard wanna-be! >-- > 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 Love your .sig! ------------------------------------------------------------------------ Steven Winikoff smw@maxwell.concordia.ca Software Analyst Concordia University Computer Centre voice: (514) 848-7619 Montreal, Quebec, Canada (10:00-18:00 EST)