Problem with getuid() -- same as geteuid()?!

David C Lawrence tale at cs.rpi.edu
Sat Feb 3 08:39:55 AEST 1990


In <1836 at clyde.concordia.ca> smw at 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 at cs.rpi.edu" "tale at ai.mit.edu" "tale at rpitsmts.bitnet"))
               "Nice plant.  Looks like a table cloth."



More information about the Comp.unix.questions mailing list