Newsgroups: comp.unix.aix Path: utzoo!utgpu!cunews!nrcnet0!cfd.di.nrc.ca!ng From: ng@cfd.di.nrc.ca (Kai Ng) Message-ID: <1991Feb12.184920.5967@nrcnet0.nrc.ca> Sender: root@nrcnet0.nrc.ca (Operator) Nntp-Posting-Host: cfd.di.nrc.ca Reply-To: ng@cfd.di.nrc.ca Organization: Informatics, National Research Council Canada Date: Tue, 12 Feb 91 18:49:20 GMT 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 #include #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@cfd.di.nrc.ca M-60 Montreal Road, Ottawa, Canada K1A 0R6 BITNET kain@nrcvm01.bitnet VOICE (613) 993-0240 FAX (613) 954-2561