This is the mail archive of the cygwin-developers@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: setregid() and setreuid() implementation proposal


At 06:42 PM 1/22/2003 +0100, Corinna Vinschen wrote:

Back to earth and to the original thread...

>Your code:
>
>    if (rgid != -1)
>      ERROR;
>    return setegid (egid);
>
>My tiny extension:
>
>    if (rgid != -1)
>      if (rgid == egid)
>        return setuid (rgid);
>      ERROR;
>    return setegid (egid);

I think the following is a full implementation. Cygwin doesn't
really care about the real uid, it's just bookkeeping. However
there is a posix requirement that setuid(ruid) must succeed, the
hard part of which would be to change the effective uid.
The only way to know is to do a dry run, that's the first seteuid32
below. The second one is for real. The third is to back out of 
the dry run if needed. Ditto for gid. Neither compiled nor tested.

Pierre

extern "C" int
setreuid32 (__uid32_t ruid, __uid32_t euid)
{
  int ret = 0;
  bool tried;	
  __uid32_t old_euid = myself->uid;

  if ((tried = ruid != ILLEGAL_UID && cygheap->user.real_uid != ruid && euid != ruid))
    ret = seteuid32 (ruid);
  if (!ret && euid != ILLEGAL_UID)
    ret = seteuid32 (euid); 
  if (tried && (ret || euid == ILLEGAL_UID) && seteuid32 (old_euid))
    system_printf ("Cannot restore original euid %u\n", old_euid);
  if (!ret && ruid != ILLEGAL_UID)
    cygheap->user.real_uid = ruid;
  debug_printf ("real: %d, effective: %d", cygheap->user.real_uid, myself->uid);
  return ret;
}





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]