[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: porting nethack-3.4.0 to the Hurd: partial results



PUYDT Julien <julien.puydt@club-internet.fr> wrote:
> As a beginner, I would be happy to have some advice/comment...

To make the getresuid () function behave like the according Linux system
call (and make it slightly more robost), it should be done like that
(same for getresgid ()).  Oh, and I also made a small mistake when I
told you to use 0, as the size is also a pointer.  But as you forgot to
pass the second argument to munmap (), your code shouldn't even have
compiled...

Of course, this is untested.

static int
real_getresuid (ruid, euid, suid)
  uid_t *ruid, *euid, *suid;
{
  error_t err;
  idarray_t euids = NULL, auids = NULL, egids = NULL, agids = NULL;
  mach_msg_type_number_t eu_cnt = 0, au_cnt = 0, eg_cnt = 0, ag_cnt = 0;

  err = auth_getids (getauth (),
                     &euids, &eu_cnt, &auids, &au_cnt,
                     &egids, &eg_cnt, &agids, &ag_cnt);

  if(! err)
    {
      if (eu_cnt == 0)
        *euid = -1;
      else
        *euid = euids[0];

      switch (au_cnt)
        {
        case 0:
          *ruid = -1;
          *suid = -1;
          break;

        case 1:
          *ruid = auids[0];
          *suid = -1;
          break;

        default:
          *ruid = auids[0];
          *suid = auids[1];
        }

#define UNMAP(kind) if (kind ## _cnt) munmap (kind ## ids, kind ## _cnt);

      UNMAP (eu);
      UNMAP (au);
      UNMAP (eg);
      UNMAP (ag);

#undef UNMAP
      return 0;
    }
  errno = err;
  return -1;
}

Cheers,
GNU/Wolfgang

-- 
Wolfgang Jährling  <wolfgang@pro-linux.de>  \\  http://stdio.cjb.net/
Debian GNU/Hurd user && Debian GNU/Linux user \\  http://www.gnu.org/
The Hurd Hacking Guide: http://www.gnu.org/software/hurd/hacking-guide/
["We're way ahead of you here. The Hurd has always been on the    ]
[ cutting edge of not being good for anything." -- Roland McGrath ]


--
To UNSUBSCRIBE, email to debian-hurd-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org



Reply to: