1 /* Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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. */
20 #include <hurd/msg_server.h>
25 _hurd_refport_secure_p (mach_port_t ref
)
27 if (ref
== __mach_task_self ())
29 if (__USEPORT (AUTH
, ref
== port
))
35 _S_msg_add_auth (mach_port_t me
,
41 if (err
= __USEPORT (AUTH
,
42 __auth_makeauth (port
,
43 &addauth
, 1, MACH_MSG_TYPE_MOVE_SEND
,
51 err
= __setauth (newauth
);
52 __mach_port_deallocate (__mach_task_self (), newauth
);
60 _S_msg_del_auth (mach_port_t me
,
62 intarray_t uids
, mach_msg_type_number_t nuids
,
63 intarray_t gids
, mach_msg_type_number_t ngids
)
68 if (!_hurd_refport_secure_p (task
))
72 __mutex_lock (&_hurd_id
.lock
);
73 err
= _hurd_check_ids ();
78 size_t nu
= _hurd_id
.gen
.nuids
, ng
= _hurd_id
.gen
.ngids
;
82 memcpy (newu
, _hurd_id
.gen
.uids
, nu
* sizeof (uid_t
));
83 memcpy (newg
, _hurd_id
.gen
.gids
, ng
* sizeof (gid_t
));
85 for (j
= 0; j
< nuids
; ++j
)
87 const uid_t uid
= uids
[j
];
88 for (i
= 0; i
< nu
; ++i
)
90 /* Move the last uid into this slot, and decrease the
91 number of uids so the last slot is no longer used. */
94 __vm_deallocate (__mach_task_self (),
95 (vm_address_t
) uids
, nuids
* sizeof (uid_t
));
97 for (j
= 0; j
< ngids
; ++j
)
99 const gid_t gid
= gids
[j
];
100 for (i
= 0; i
< nu
; ++i
)
102 /* Move the last gid into this slot, and decrease the
103 number of gids so the last slot is no longer used. */
104 newu
[i
] = newu
[--nu
];
106 __vm_deallocate (__mach_task_self (),
107 (vm_address_t
) gids
, ngids
* sizeof (gid_t
));
109 err
= __USEPORT (AUTH
, __auth_makeauth
111 NULL
, 0, MACH_MSG_TYPE_COPY_SEND
,
113 _hurd_id
.aux
.uids
, _hurd_id
.aux
.nuids
,
115 _hurd_id
.aux
.uids
, _hurd_id
.aux
.ngids
,
118 __mutex_unlock (&_hurd_id
.lock
);
124 err
= __setauth (newauth
);
125 __mach_port_deallocate (__mach_task_self (), newauth
);