hurdid.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Copyright (C) 1993-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #include <hurd.h>
  15. #include <hurd/id.h>
  16. #include "set-hooks.h"
  17. struct hurd_id_data _hurd_id;
  18. /* Check that _hurd_id.{gen,aux} are valid and update them if not.
  19. Expects _hurd_id.lock to be held and does not release it. */
  20. error_t
  21. _hurd_check_ids (void)
  22. {
  23. if (! _hurd_id.valid)
  24. {
  25. inline void dealloc (__typeof (_hurd_id.gen) *p)
  26. {
  27. if (p->uids)
  28. {
  29. __vm_deallocate (__mach_task_self (),
  30. (vm_address_t) p->uids,
  31. p->nuids * sizeof (uid_t));
  32. p->uids = NULL;
  33. }
  34. p->nuids = 0;
  35. if (p->gids)
  36. {
  37. __vm_deallocate (__mach_task_self (),
  38. (vm_address_t) p->gids,
  39. p->ngids * sizeof (gid_t));
  40. p->gids = NULL;
  41. }
  42. p->ngids = 0;
  43. }
  44. error_t err;
  45. dealloc (&_hurd_id.gen);
  46. dealloc (&_hurd_id.aux);
  47. if (_hurd_id.rid_auth != MACH_PORT_NULL)
  48. {
  49. __mach_port_deallocate (__mach_task_self (), _hurd_id.rid_auth);
  50. _hurd_id.rid_auth = MACH_PORT_NULL;
  51. }
  52. if (err = __USEPORT (AUTH, __auth_getids
  53. (port,
  54. &_hurd_id.gen.uids, &_hurd_id.gen.nuids,
  55. &_hurd_id.aux.uids, &_hurd_id.aux.nuids,
  56. &_hurd_id.gen.gids, &_hurd_id.gen.ngids,
  57. &_hurd_id.aux.gids, &_hurd_id.aux.ngids)))
  58. return err;
  59. _hurd_id.valid = 1;
  60. }
  61. return 0;
  62. }
  63. static void attribute_used_retain
  64. init_id (void)
  65. {
  66. __mutex_init (&_hurd_id.lock);
  67. _hurd_id.valid = 0;
  68. _hurd_id.rid_auth = MACH_PORT_NULL;
  69. _hurd_id.gen.uids = _hurd_id.aux.uids = NULL;
  70. _hurd_id.gen.nuids = _hurd_id.aux.nuids = 0;
  71. _hurd_id.gen.gids = _hurd_id.aux.gids = NULL;
  72. _hurd_id.gen.ngids = _hurd_id.aux.ngids = 0;
  73. }
  74. SET_RELHOOK (_hurd_preinit_hook, init_id);