[comp.unix.wizards] getuid

brw@jim.odr.oz (Brian Wallis) (10/27/88)

(I have posted this to comp.unix.ultrix, but the newgroup seems to
have died! I haven't seen any articles for more than a month)

On Ultrix 2.0 on our MicroVax II, the system calls getuid() and
geteuid() both seem to return the same uid no matter what you have
su'd to. ie. If I su to 'local' and run a simple program that prints
both uid's as returned by getuid and geteuid I get the uid of local
from both whereas I thought I should get the uid of me ('brw') from
getuid(). Here is tmp.c and the results...

>
> main()
> {
>   printf("getuid() = %d, geteuid() = %d\n",getuid(),geteuid());
> }
>

51% whoami
brw
52% who am i
jim!brw     tty00   Oct 27 09:11
53% cc tmp.c
54% a.out
getuid() = 272, geteuid() = 272
55% su local
Password:

51% whoami
local
52% who am i
jim!brw     tty00   Oct 27 09:11
53% a.out
getuid() = 290, geteuid() = 290
52% 

This is very annoying! Is this an Ultrix only bug (I have nothing else
to try it on) or am I confused and this is correct behaviour?


-- 
Brian Wallis (brw@jim.odr.oz)		    O'Dowd Research P/L.
	(03) 562-0100 Fax: (03) 562-0616,
	Telex: Jacobs Radio (Bayswater) 152093

guy@auspex.UUCP (Guy Harris) (10/29/88)

>This is very annoying! Is this an Ultrix only bug (I have nothing else
>to try it on) or am I confused and this is correct behaviour?

This is correct behavior.  "su" changes both the real and effective user
ID on every version of UNIX I've ever seen.  *Not* having that behavior
would be *extremely* annoying....

donn@titan.rice.edu (Donn Baumgartner) (11/01/88)

Funny you should ask... in the 4.3 bsd source I have (which is over a year
old admittedly), geteuid() is stubbed out with getuid().
						- Donn

kai@uicsrd.csrd.uiuc.edu (11/01/88)

The "getlogin()" call returns the userid from the entry for the control
terminal in /etc/utmp, usually, the userid used to login on that terminal.
However, inside programs that use pseudo terminals, such as script, window,
etc., this call returns NULL, because those programs don't make utmp entries
for the pseudo terminal.


Patrick Wolfe  (pwolfe@kai.com, uunet!kailand!pwolfe)

brw@jim.odr.oz (Brian Wallis) (11/02/88)

 In article <579@jim.odr.oz> brw@jim.odr.oz (Brian Wallis (me)) writes:
>
>On Ultrix 2.0 on our MicroVax II, the system calls getuid() and
>geteuid() both seem to return the same uid no matter what you have
>su'd to. ie. If I su to 'local' and run a simple program that prints
>both uid's as returned by getuid and geteuid I get the uid of local
>from both whereas I thought I should get the uid of me ('brw') from
>getuid(). Here is tmp.c and the results...
 
   [rest deleted]

Ok, Ok, maybe I didn't look far enough (although our manual entry for
'su' doesn't actually mention that both the uid and euid are set) (and
thanks to all who replied).

  A bit of background. The reason I wanted this was due to running
emacs while su'd to another user (local, our local utility source
container) and wanting to use MY .emacs file. I thought that
(user-uid) or (user-login-name) as opposed to (user-real-uid) and
(user-real-login-name) would tell me who I was logged in as. In fact
the help for the function user-real-login-name is:
> user-real-login-name:
> Return the name of the user's real uid, as a string.
> Differs from user-login-name when running under su.
which misled me. 

  I am currently using a re-definition of user-real-login-name:
> (defun user-real-login-name ()
> "A kludge for the real thing, since getuid() is wrong on Ultrix 2.0"
>   (interactive)
>   (substring (getenv "MAIL")
>	     (string-match "[^/]+$" (getenv "MAIL")) nil))
which is kludgy but works for the people who su to local around here!

What is a better way of doing this?

-- 
Brian Wallis (brw@jim.odr.oz)		    O'Dowd Research P/L.
	(03) 562-0100 Fax: (03) 562-0616,
	Telex: Jacobs Radio (Bayswater) 152093