1 /* Copyright (C) 1991, 92, 93, 94, 95, 97 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 Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
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
,
40 uid_t
*genuids
, *gengids
, *auxuids
, *auxgids
;
41 mach_msg_type_number_t ngenuids
, ngengids
, nauxuids
, nauxgids
;
42 uid_t
*newgenuids
, *newgengids
, *newauxuids
, *newauxgids
;
43 mach_msg_type_number_t nnewgenuids
, nnewgengids
, nnewauxuids
, nnewauxgids
;
45 /* Create a list of ids and store it in NEWLISTP, length NEWLISTLEN.
46 Keep all the ids in EXIST (len NEXIST), adding in those from NEW
47 (len NNEW) which are not already there. */
48 error_t
make_list (uid_t
**newlistp
, mach_msg_type_number_t
*newlistlen
,
49 uid_t
*exist
, mach_msg_type_number_t nexist
,
50 uid_t
*new, mach_msg_type_number_t nnew
)
56 urp
= vm_allocate (mach_task_self (), (vm_address_t
*) newlistp
,
57 nexist
+ nnew
* sizeof (uid_t
), 1);
62 for (i
= 0; i
< nexist
; i
++)
63 (*newlistp
)[j
++] = exist
[i
];
65 for (i
= 0; i
< nnew
; i
++)
67 for (k
= 0; k
< nexist
; k
++)
68 if (exist
[k
] == new[i
])
73 (*newlistp
)[j
++] = new[i
];
76 offset
= (round_page (nexist
+ nnew
* sizeof (uid_t
))
77 - round_page (j
* sizeof (uid_t
)));
79 vm_deallocate (mach_task_self (),
80 (vm_address_t
) (*newlistp
81 + (nexist
+ nnew
* sizeof (uid_t
))),
87 /* Find out what ids ADDAUTH refers to */
89 genuids
= gengids
= auxuids
= auxgids
= 0;
90 ngenuids
= ngengids
= nauxuids
= nauxgids
= 0;
91 err
= __auth_getids (addauth
,
99 /* OR in these ids to what we already have, creating a new list. */
102 __mutex_lock (&_hurd_id
.lock
);
105 #define MAKE(genaux,uidgid) \
106 make_list (&new ## genaux ## uidgid ## s, \
107 &nnew ## genaux ## uidgid ## s, \
108 _hurd_id.genaux.uidgid ## s, \
109 _hurd_id.genaux.n ## uidgid ## s, \
110 genaux ## uidgid ## s, \
111 n ## genaux ## uidgid ## s)
113 err
= MAKE (gen
, uid
);
122 __mutex_unlock (&_hurd_id
.lock
);
126 /* Create the new auth port */
129 err
= __USEPORT (AUTH
,
130 __auth_makeauth (port
,
131 &addauth
, MACH_MSG_TYPE_MOVE_SEND
, 1,
132 newgenuids
, nnewgenuids
,
133 newauxuids
, nnewauxuids
,
134 newgengids
, nnewgengids
,
135 newauxgids
, nnewauxgids
,
138 #define freeup(array, len) \
140 vm_deallocate (mach_task_self (), (vm_address_t) array, \
141 len * sizeof (uid_t));
143 freeup (genuids
, ngenuids
);
144 freeup (auxuids
, nauxuids
);
145 freeup (gengids
, ngengids
);
146 freeup (auxgids
, nauxgids
);
147 freeup (newgenuids
, nnewgenuids
);
148 freeup (newauxuids
, nnewauxuids
);
149 freeup (newgengids
, nnewgengids
);
150 freeup (newauxgids
, nnewauxgids
);
156 /* And install it. */
158 err
= __setauth (newauth
);
159 __mach_port_deallocate (__mach_task_self (), newauth
);
167 _S_msg_del_auth (mach_port_t me
,
169 intarray_t uids
, mach_msg_type_number_t nuids
,
170 intarray_t gids
, mach_msg_type_number_t ngids
)
175 if (!_hurd_refport_secure_p (task
))
179 __mutex_lock (&_hurd_id
.lock
);
180 err
= _hurd_check_ids ();
185 size_t nu
= _hurd_id
.gen
.nuids
, ng
= _hurd_id
.gen
.ngids
;
189 memcpy (newu
, _hurd_id
.gen
.uids
, nu
* sizeof (uid_t
));
190 memcpy (newg
, _hurd_id
.gen
.gids
, ng
* sizeof (gid_t
));
192 for (j
= 0; j
< nuids
; ++j
)
194 const uid_t uid
= uids
[j
];
195 for (i
= 0; i
< nu
; ++i
)
197 /* Move the last uid into this slot, and decrease the
198 number of uids so the last slot is no longer used. */
199 newu
[i
] = newu
[--nu
];
201 __vm_deallocate (__mach_task_self (),
202 (vm_address_t
) uids
, nuids
* sizeof (uid_t
));
204 for (j
= 0; j
< ngids
; ++j
)
206 const gid_t gid
= gids
[j
];
207 for (i
= 0; i
< nu
; ++i
)
209 /* Move the last gid into this slot, and decrease the
210 number of gids so the last slot is no longer used. */
211 newu
[i
] = newu
[--nu
];
213 __vm_deallocate (__mach_task_self (),
214 (vm_address_t
) gids
, ngids
* sizeof (gid_t
));
216 err
= __USEPORT (AUTH
, __auth_makeauth
218 NULL
, MACH_MSG_TYPE_COPY_SEND
, 0,
220 _hurd_id
.aux
.uids
, _hurd_id
.aux
.nuids
,
222 _hurd_id
.aux
.uids
, _hurd_id
.aux
.ngids
,
225 __mutex_unlock (&_hurd_id
.lock
);
231 err
= __setauth (newauth
);
232 __mach_port_deallocate (__mach_task_self (), newauth
);