No subject

Kai Ng ng at cfd.di.nrc.ca
Wed Feb 13 05:49:20 AEST 1991


Context: AIX 3002 /RS6000 530
According to the man pages of setuid() and setgid(), the behavior of
the respective functions should be the same. Could somebody familiar
with the setuid stuff enlighten me on why they aren't? Or is it a defect?
Thanks.

------------------------------------------------------------------------------

/* FILE tst.c */
#include <stdio.h>
#include <sys/id.h>

#define printID() printf("UID=%4d EUID=%4d GID=%4d EGID=%4d\n",\
  getuid(),geteuid(),getgid(),getegid())

main (int argc, char *argv[])
{
  printID ();

  setuid (getuid ());  setgid (getgid ());
  printf ("setuid (getuid ()); setgid (getgid ());\n");
  printID ();

  setuid (0);  setgid (0);
  printf ("setuid (0); setgid (0);\n");
  printID ();

  setuid (0); setgid (0);
  printf ("setuid (0); setgid (0);\n");
  printID ();
}
 
----------------------------------------------------------------------------

Compiled by root
  cc -o tst tst.c
  chmod 4755 tst / chmod 6755 tst

Executed by a user with uid 2003 and gid 20.

----------------------------------------------------------------------------

Output when mode set to 4755:

UID=2003 EUID=   0 GID=  20 EGID=  20
setuid (getuid ()); setgid (getgid ());
UID=2003 EUID=2003 GID=  20 EGID=  20
setuid (0); setgid (0);
UID=2003 EUID=   0 GID=   0 EGID=   0          <--- GID expected to be 20
setuid (0); setgid (0);
UID=   0 EUID=   0 GID=   0 EGID=   0


Output when mode set to 6755:

UID=2003 EUID=   0 GID=  20 EGID=   0
setuid (getuid ()); setgid (getgid ());
UID=2003 EUID=2003 GID=  20 EGID=  20
setuid (0); setgid (0);
UID=2003 EUID=   0 GID=   0 EGID=   0          <--- GID expected to be 20 
setuid (0); setgid (0);
UID=   0 EUID=   0 GID=   0 EGID=   0

------------------------------------------------------------------------------

-- 
-----------------------------------------------------------------------------
Kai S. Ng                     Informatics, National Research Council Canada
INTERNET ng at cfd.di.nrc.ca     M-60 Montreal Road, Ottawa, Canada    K1A 0R6
BITNET   kain at nrcvm01.bitnet  VOICE (613) 993-0240       FAX (613) 954-2561



More information about the Comp.unix.aix mailing list