[comp.unix.ultrix] getuid, geteuid broke?

local@jim.odr.oz.au (local src Local etc.) (11/04/88)

Reply-to: local@jim.odr.oz.au (local src Local etc.)



getuid() seems to always return the effective user id, and getgid()
always returns the effective group id. I compiled and ran the following...

/* tmp.c */
main()
{
  printf("getuid = %d, geteuid = %d\n",getuid(),geteuid());
  printf("getgid = %d, getegid = %d\n",getgid(),getegid());
}

57% cc tmp.c
58% a.out
getuid = 290, geteuid = 290
getgid = 6, getegid = 6
59% whoami
local
60% su
Password:

# 51% a.out
getuid = 0, geteuid = 0
getgid = 0, getegid = 0
# 52% whoami
root
# 53% 

  This is wrong, isn't it. I thought that getuid() should return the
same thing after I did the su.
  I discovered this in emacs (18.52) using the functions (user-uid)
and (user-real-uid) which call geteuid() and getuid() respectivly. Am
I doing something wrong here, how do I fix it.

  We are running Ultrix 2.0 on a MicroVax II.

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

dls@mace.cc.purdue.edu (David L Stevens) (11/22/88)

Reply-to: dls@mace.cc.purdue.edu (David L Stevens)


	Nope, not an error. The effective uid of the "su" shell differs from
the real id, but forked children are real and effective "root".
	The right way to test it would be to compile your program, change
the owner to "root", change the mode to "4751" (setuid) and then it should
print different real and effective uids.
-- 
					+-DLS  (dls@mace.cc.purdue.edu)