Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!rpi!tale From: tale@cs.rpi.edu (David C Lawrence) Newsgroups: comp.unix.questions Subject: Re: Problem with getuid() -- same as geteuid()?! Message-ID: Date: 2 Feb 90 21:39:55 GMT References: <1836@clyde.concordia.ca> Organization: Rensselaer Polytechnic Institute, Troy NY Lines: 45 In <1836@clyde.concordia.ca> smw@maxwell.concordia.ca ( Steven Winikoff ): > When I log in as user "smw" (user index = 1000), the program does indeed > return "uid = 1000". > However, when I then execute the su command, I receive "uid = 0" instead > of the expected "uid = 1000". > Am I missing something? Yes. > I thought that this was the expected behaviour for geteuid() instead > of getuid(), No. > and that's why I used getuid() in the first place! You could use getlogin(), but be wary of it. It can fail under a lot of situations. @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, so I won't describe how to do it. One thing you might want to reconsider is why you are concerned with the userid of the login. When I su to someone else I want my userid to be that one, not the one that I was. (On very rare occasion I might want it to be the original, but I can deal with that in another way.) @end opinionated sidebar > Can anyone tell me if I'm just confused, or if I'm simply not doing it > right, or if there's actually a bug in the Sun and MIPS implementation > of these calls? If there was a bug in it then things would have been upchucking all over the place and people would be up in arms about it. geteuid() is used to get the userid of a setuid executable. getuid() is meant to return the userid that invoked the programme. For non-setuid executables they will always return the same number. Dave -- (setq mail '("tale@cs.rpi.edu" "tale@ai.mit.edu" "tale@rpitsmts.bitnet")) "Nice plant. Looks like a table cloth."