From 2d6d0728231ad89064267fb0df3090675a4f174b Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sun, 29 Nov 1998 10:10:47 +0000 Subject: 1998-11-28 Roland McGrath * hurd/setuids.c: Renamed to ... * hurd/seteuids.c: this. (setuids): Renamed to seteuids. * hurd/getuids.c: Renamed to ... * hurd/geteuids.c: this. (__getuids): Renamed to geteuids, no aliases. * hurd/hurd.h (geteuids, seteuids): Declare them. * hurd/Versions: Replace getuids; __getuids with geteuids; seteuids. * hurd/Makefile (routines): Updated. --- hurd/Makefile | 2 +- hurd/Versions | 2 +- hurd/geteuids.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hurd/getuids.c | 65 --------------------------------------------------------- hurd/hurd.h | 5 +++++ hurd/seteuids.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ hurd/setuids.c | 59 --------------------------------------------------- 7 files changed, 129 insertions(+), 126 deletions(-) create mode 100644 hurd/geteuids.c delete mode 100644 hurd/getuids.c create mode 100644 hurd/seteuids.c delete mode 100644 hurd/setuids.c (limited to 'hurd') diff --git a/hurd/Makefile b/hurd/Makefile index 85aa30ab88..3eeb445ca7 100644 --- a/hurd/Makefile +++ b/hurd/Makefile @@ -46,7 +46,7 @@ routines = hurdstartup hurdinit \ path-lookup \ setauth \ pid2task task2pid \ - getuids setuids getumask fchroot \ + geteuids seteuids getumask fchroot \ hurdsock hurdauth \ privports \ msgportdemux \ diff --git a/hurd/Versions b/hurd/Versions index 6247858f63..46e92797aa 100644 --- a/hurd/Versions +++ b/hurd/Versions @@ -18,7 +18,7 @@ libc { _hurd_init; _hurd_proc_init; _hurd_exec; _hurd_canonicalize_directory_name_internal; - getuids; __getuids; + geteuids; seteuids; # XXX ought to exist on all platforms getumask; diff --git a/hurd/geteuids.c b/hurd/geteuids.c new file mode 100644 index 0000000000..ed85dfd13d --- /dev/null +++ b/hurd/geteuids.c @@ -0,0 +1,63 @@ +/* Copyright (C) 1993, 94, 96, 97, 98 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include +#include +#include + +int +geteuids (int n, uid_t *uidset) +{ + error_t err; + int nuids; + void *crit; + + crit = _hurd_critical_section_lock (); + __mutex_lock (&_hurd_id.lock); + + if (err = _hurd_check_ids ()) + { + __mutex_unlock (&_hurd_id.lock); + _hurd_critical_section_unlock (crit); + return __hurd_fail (err); + } + + nuids = _hurd_id.gen.nuids; + + if (n != 0) + { + /* Copy the uids onto stack storage and then release the idlock. */ + uid_t uids[nuids]; + memcpy (uids, _hurd_id.gen.uids, sizeof (uids)); + __mutex_unlock (&_hurd_id.lock); + _hurd_critical_section_unlock (crit); + + /* Now that the lock is released, we can safely copy the + uid set into the user's array, which might fault. */ + if (nuids > n) + nuids = n; + memcpy (uidset, uids, nuids * sizeof (uid_t)); + } + else + { + __mutex_unlock (&_hurd_id.lock); + _hurd_critical_section_unlock (crit); + } + + return nuids; +} diff --git a/hurd/getuids.c b/hurd/getuids.c deleted file mode 100644 index f367e0ea9a..0000000000 --- a/hurd/getuids.c +++ /dev/null @@ -1,65 +0,0 @@ -/* Copyright (C) 1993, 1994, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#include -#include -#include - -int -__getuids (int n, uid_t *uidset) -{ - error_t err; - int nuids; - void *crit; - - crit = _hurd_critical_section_lock (); - __mutex_lock (&_hurd_id.lock); - - if (err = _hurd_check_ids ()) - { - __mutex_unlock (&_hurd_id.lock); - _hurd_critical_section_unlock (crit); - return __hurd_fail (err); - } - - nuids = _hurd_id.gen.nuids; - - if (n != 0) - { - /* Copy the uids onto stack storage and then release the idlock. */ - uid_t uids[nuids]; - memcpy (uids, _hurd_id.gen.uids, sizeof (uids)); - __mutex_unlock (&_hurd_id.lock); - _hurd_critical_section_unlock (crit); - - /* Now that the lock is released, we can safely copy the - uid set into the user's array, which might fault. */ - if (nuids > n) - nuids = n; - memcpy (uidset, uids, nuids * sizeof (uid_t)); - } - else - { - __mutex_unlock (&_hurd_id.lock); - _hurd_critical_section_unlock (crit); - } - - return nuids; -} - -weak_alias (__getuids, getuids) diff --git a/hurd/hurd.h b/hurd/hurd.h index 98d726a592..10036a9ecf 100644 --- a/hurd/hurd.h +++ b/hurd/hurd.h @@ -155,6 +155,11 @@ extern int setcttyid (mach_port_t); extern int __setauth (auth_t), setauth (auth_t); +/* Get and set the effective UID set. */ +extern int geteuids (int __n, uid_t *__uidset); +extern int seteuids (int __n, const uid_t *__uidset); + + /* Split FILE into a directory and a name within the directory. The directory lookup uses the current root and working directory. If successful, stores in *NAME a pointer into FILE where the name diff --git a/hurd/seteuids.c b/hurd/seteuids.c new file mode 100644 index 0000000000..231dce5e4b --- /dev/null +++ b/hurd/seteuids.c @@ -0,0 +1,59 @@ +/* Copyright (C) 1993, 94, 97, 98 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include +#include + +/* Set the uid set for the current user to UIDS (N of them). */ +int +seteuids (int n, const uid_t *uids) +{ + error_t err; + auth_t newauth; + int i; + gid_t new[n]; + + /* Fault before taking locks. */ + for (i = 0; i < n; ++i) + new[i] = uids[i]; + + HURD_CRITICAL_BEGIN; + __mutex_lock (&_hurd_id.lock); + err = _hurd_check_ids (); + if (! err) + { + /* Get a new auth port using those IDs. */ + err = __USEPORT (AUTH, + __auth_makeauth (port, NULL, 0, 0, + new, n, + _hurd_id.aux.uids, _hurd_id.aux.nuids, + _hurd_id.gen.gids, _hurd_id.gen.ngids, + _hurd_id.aux.gids, _hurd_id.aux.ngids, + &newauth)); + } + __mutex_unlock (&_hurd_id.lock); + HURD_CRITICAL_END; + + if (err) + return __hurd_fail (err); + + /* Install the new auth port and reauthenticate everything. */ + err = __setauth (newauth); + __mach_port_deallocate (__mach_task_self (), newauth); + return err; +} diff --git a/hurd/setuids.c b/hurd/setuids.c deleted file mode 100644 index 8b202401a4..0000000000 --- a/hurd/setuids.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright (C) 1993, 1994, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#include -#include - -/* Set the uid set for the current user to UIDS (N of them). */ -int -setuids (int n, const uid_t *uids) -{ - error_t err; - auth_t newauth; - int i; - gid_t new[n]; - - /* Fault before taking locks. */ - for (i = 0; i < n; ++i) - new[i] = uids[i]; - - HURD_CRITICAL_BEGIN; - __mutex_lock (&_hurd_id.lock); - err = _hurd_check_ids (); - if (! err) - { - /* Get a new auth port using those IDs. */ - err = __USEPORT (AUTH, - __auth_makeauth (port, NULL, 0, 0, - new, n, - _hurd_id.aux.uids, _hurd_id.aux.nuids, - _hurd_id.gen.gids, _hurd_id.gen.ngids, - _hurd_id.aux.gids, _hurd_id.aux.ngids, - &newauth)); - } - __mutex_unlock (&_hurd_id.lock); - HURD_CRITICAL_END; - - if (err) - return __hurd_fail (err); - - /* Install the new auth port and reauthenticate everything. */ - err = __setauth (newauth); - __mach_port_deallocate (__mach_task_self (), newauth); - return err; -} -- cgit v1.2.3