home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / glibc-1.06 / hurd / hurdauth.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-25  |  2.7 KB  |  101 lines

  1. /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <hurd.h>
  20.  
  21. struct _hurd_port _hurd_auth;
  22.  
  23. error_t
  24. __add_auth (sigthread_t me,
  25.         auth_t addauth)
  26. {
  27.   error_t err;
  28.   auth_t newauth;
  29.  
  30.   if (err = _HURD_PORT_USE (&_hurd_auth,
  31.                 __auth_combine (port, addauth, &newauth)))
  32.     return err;
  33.  
  34.   /* XXX clobbers errno. Need per-thread errno. */
  35.   err = __setauth (newauth);
  36.   __mach_port_deallocate (__mach_task_self (), newauth);
  37.   if (err)
  38.     return errno;
  39.  
  40.   __mach_port_deallocate (__mach_task_self (), addauth);
  41.   return POSIX_SUCCESS;
  42. }
  43.  
  44. error_t
  45. __del_auth (sigthread_t me, task_t task,
  46.         uid_t *uids, size_t nuids,
  47.         gid_t *gids, size_t ngids)
  48. {
  49.   error_t err;
  50.   auth_t newauth;
  51.   size_t i, j;
  52.  
  53.   if (task != __mach_task_self ())
  54.     return EPERM;
  55.  
  56.   __mutex_lock (&_hurd_idlock);
  57.   if (!_hurd_id_valid)
  58.     {
  59.       error_t err = _HURD_PORT_USE (&_hurd_auth,
  60.                     __auth_getids (port, &_hurd_id));
  61.       if (err)
  62.     {
  63.       __mutex_unlock (&_hurd_idlock);
  64.       return err;
  65.     }
  66.       _hurd_id_valid = 1;
  67.     }
  68.  
  69.   while (nuids-- > 0)
  70.     {
  71.       const uid_t uid = *uids++;
  72.       for (i = 0; i < _hurd_id.nuids; ++i)
  73.     if (_hurd_id.uidset[i] == uid)
  74.       /* Move the last uid into this slot, and decrease the
  75.          number of uids so the last slot is no longer used.  */
  76.       _hurd_id.uidset[i] = _hurd_id.uidset[--_hurd_id.nuids];
  77.     }
  78.   while (ngids-- > 0)
  79.     {
  80.       const gid_t gid = *gids++;
  81.       for (i = 0; i < _hurd_id.ngroups; ++i)
  82.     if (_hurd_id.gidset[i] == gid)
  83.       /* Move the last gid into this slot, and decrease the
  84.          number of gids so the last slot is no longer used.  */
  85.       _hurd_id.gidset[i] = _hurd_id.gidset[--_hurd_id.ngroups];
  86.     }
  87.  
  88.   err = _HURD_PORT_USE (&_hurd_auth,
  89.             __auth_makeauth (port, &_hurd_id, &newauth));
  90.   _hurd_id_valid = !err;
  91.   __mutex_unlock (&_hurd_idlock);
  92.  
  93.   if (err)
  94.     return err;
  95.   err = __setauth (newauth);    /* XXX clobbers errno */
  96.   __mach_port_deallocate (__mach_task_self (), newauth);
  97.   if (err)
  98.     return errno;
  99.   return POSIX_SUCCESS;
  100. }
  101.