Mark writes:
> After the fork() you can do this to change the userid:
>
> GETPRIVMODE();
> setuid(new_uid);
> GETUSERMODE();
>
> You should only do this after careful validation of the new_uid to make sure
> the PC isn't trying to gain access to unauthorized users.
I recommend encapsulating the above as follows:
int my_setuid (uid_t new_uid)
{
GETPRIVMODE ();
return setuid (new_uid);
}
Note the lack of call to GETUSERMODE(). This means that if my_setuid is
called from an already privileged routine, my_setuid will not
incorrectly return in user mode.
Of course, you could also do:
GETPRIVMODE (); /* returns CCE if was in user mode */
need_getusermode_call = (CCODE() == CCE);
if (setuid (new_uid))
...oops, setuid failed...
if (need_getusermode_call)
GETUSERMODE ();
--
Stan Sieler [log in to unmask]http://www.allegro.com/sieler.html