Problems with setuid(), SVr2v2 - (nf)

tim at siedap.UUCP tim at siedap.UUCP
Tue Sep 23 06:23:00 AEST 1986


The setuid() system call under SVr2v2 (on a 3B2) doesn't seem to do
one thing which the manual claims it does :

> If the effective user id of the calling process is not super-user,
> but the saved set-user (group) ID from exec(2) is equal to uid (gid),
> the effective user (group) ID is set to uid (gid).

I'm using a process which has set-uid to root; first I want to
change my id's to a project id to read project data, and then
back to those of the caller (to read his files). On BSD this
works fine - you toggle real and eff. via setre(g/u)id. But I
can't for the life of me get any effect on SVr2v2 which would
approximate to what the manual claims is possible.

HELP !!!!!! (I've got a deadline for this stuff ...)

Repeat-by :
Compile this short test program, install it set-uid to root,
and run it. Play around with the calls to reset to the users id's.

------------ 8< -------------------8< ----------------

#include <stdio.h>
main()
{
int c_uid, c_gid;

c_uid = getuid() ;
c_gid = getgid() ;

printf("Real uid = %d\n",getuid()) ;
printf("Eff. uid = %d\n",geteuid()) ;
printf("Real gid = %d\n",getgid()) ;
printf("Eff. gid = %d\n",getegid()) ;

/* Set other id's */
if (setgid(555) != 0)
   {
   printf("setgid proj\n") ;
   exit(0) ;
   }
else ;
if (setuid(555) != 0)
   {
   printf("setuid proj\n") ;
   exit(0) ;
   }
else ;

printf("Real uid = %d\n",getuid()) ;
printf("Eff. uid = %d\n",geteuid()) ;
printf("Real gid = %d\n",getgid()) ;
printf("Eff. gid = %d\n",getegid()) ;

/* Reset caller's id's */
if (setuid(0) != 0)    /* THIS WAS set-user ID from exec ??? */
   {
   printf("setuid 0\n") ;
   exit(0) ;
   }
else ;
if (setgid(c_gid) != 0)
   {
   printf("setgid user\n") ;
   exit(0) ;
   }
else ;
if (setuid(c_uid) != 0)
   {
   printf("setuid user\n") ;
   exit(0) ;
   }
else ;

exit(0) ;
}



More information about the Net.bugs.usg mailing list