Back to index

glibc  2.9
hurdid.c
Go to the documentation of this file.
00001 /* Copyright (C) 1993, 1994, 1995, 1997 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <hurd.h>
00020 #include <hurd/id.h>
00021 
00022 struct hurd_id_data _hurd_id;
00023 
00024 
00025 /* Check that _hurd_id.{gen,aux} are valid and update them if not.
00026    Expects _hurd_id.lock to be held and does not release it.  */
00027 
00028 error_t
00029 _hurd_check_ids (void)
00030 {
00031   if (! _hurd_id.valid)
00032     {
00033       inline void dealloc (__typeof (_hurd_id.gen) *p)
00034        {
00035          if (p->uids)
00036            {
00037              __vm_deallocate (__mach_task_self (),
00038                             (vm_address_t) p->uids,
00039                             p->nuids * sizeof (uid_t));
00040              p->uids = NULL;
00041            }
00042          p->nuids = 0;
00043          if (p->gids)
00044            {
00045              __vm_deallocate (__mach_task_self (),
00046                             (vm_address_t) p->gids,
00047                             p->ngids * sizeof (gid_t));
00048              p->gids = NULL;
00049            }
00050          p->ngids = 0;
00051        }
00052 
00053       error_t err;
00054 
00055       dealloc (&_hurd_id.gen);
00056       dealloc (&_hurd_id.aux);
00057 
00058       if (_hurd_id.rid_auth != MACH_PORT_NULL)
00059        {
00060          __mach_port_deallocate (__mach_task_self (), _hurd_id.rid_auth);
00061          _hurd_id.rid_auth = MACH_PORT_NULL;
00062        }
00063 
00064       if (err = __USEPORT (AUTH, __auth_getids
00065                         (port,
00066                          &_hurd_id.gen.uids, &_hurd_id.gen.nuids,
00067                          &_hurd_id.aux.uids, &_hurd_id.aux.nuids,
00068                          &_hurd_id.gen.gids, &_hurd_id.gen.ngids,
00069                          &_hurd_id.aux.gids, &_hurd_id.aux.ngids)))
00070        return err;
00071 
00072       _hurd_id.valid = 1;
00073     }
00074 
00075   return 0;
00076 }
00077 
00078 static void
00079 init_id (void)
00080 {
00081   __mutex_init (&_hurd_id.lock);
00082   _hurd_id.valid = 0;
00083   _hurd_id.rid_auth = MACH_PORT_NULL;
00084   _hurd_id.gen.uids = _hurd_id.aux.uids = NULL;
00085   _hurd_id.gen.nuids = _hurd_id.aux.nuids = 0;
00086   _hurd_id.gen.gids = _hurd_id.aux.gids = NULL;
00087   _hurd_id.gen.ngids = _hurd_id.aux.ngids = 0;
00088 
00089   (void) &init_id;          /* Avoid "defined but not used" warning.  */
00090 }
00091 text_set_element (_hurd_preinit_hook, init_id);