diff options
Diffstat (limited to 'sysdeps/mach')
-rw-r--r-- | sysdeps/mach/hurd/setegid.c | 15 | ||||
-rw-r--r-- | sysdeps/mach/hurd/seteuid.c | 15 | ||||
-rw-r--r-- | sysdeps/mach/hurd/setgid.c | 49 | ||||
-rw-r--r-- | sysdeps/mach/hurd/setregid.c | 48 | ||||
-rw-r--r-- | sysdeps/mach/hurd/setreuid.c | 44 | ||||
-rw-r--r-- | sysdeps/mach/hurd/setuid.c | 45 |
6 files changed, 158 insertions, 58 deletions
diff --git a/sysdeps/mach/hurd/setegid.c b/sysdeps/mach/hurd/setegid.c index 8ca4abee06..6710462125 100644 --- a/sysdeps/mach/hurd/setegid.c +++ b/sysdeps/mach/hurd/setegid.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1994 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1994, 1995 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 @@ -40,17 +40,18 @@ DEFUN(setegid, (gid), gid_t gid) /* Make a new auth handle which has EGID as the first element in the list of effective gids. */ - size_t ngen = _hurd_id.gen.ngids < 1 ? 1 : _hurd_id.gen.ngids; - gid_t newgen[ngen]; - - newgen[0] = gid; - memcpy (&newgen[1], _hurd_id.gen.gids, (ngen - 1) * sizeof (gid_t)); + if (_hurd_id.gen.ngids > 0) + { + _hurd_id.gen.gids[0] = gid; + _hurd_id.valid = 0; + } err = __USEPORT (AUTH, __auth_makeauth (port, NULL, MACH_MSG_TYPE_COPY_SEND, 0, _hurd_id.gen.uids, _hurd_id.gen.nuids, _hurd_id.aux.uids, _hurd_id.aux.nuids, - newgen, ngen, + _hurd_id.gen.ngids ? _hurd_id.gen.gids : &gid, + _hurd_id.gen.ngids ?: 1, _hurd_id.aux.gids, _hurd_id.aux.ngids, &newauth)); } diff --git a/sysdeps/mach/hurd/seteuid.c b/sysdeps/mach/hurd/seteuid.c index 9c44c4d275..62f4488624 100644 --- a/sysdeps/mach/hurd/seteuid.c +++ b/sysdeps/mach/hurd/seteuid.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1994 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1994, 1995 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 @@ -40,15 +40,16 @@ DEFUN(seteuid, (uid), uid_t uid) /* Make a new auth handle which has EUID as the first element in the list of effective uids. */ - size_t ngen = _hurd_id.gen.nuids < 1 ? 1 : _hurd_id.gen.nuids; - uid_t newgen[ngen]; - - newgen[0] = uid; - memcpy (&newgen[1], _hurd_id.gen.uids, (ngen - 1) * sizeof (uid_t)); + if (_hurd_id.gen.nuids > 0) + { + _hurd_id.gen.uids[0] = uid; + _hurd_id.valid = 0; + } err = __USEPORT (AUTH, __auth_makeauth (port, NULL, MACH_MSG_TYPE_COPY_SEND, 0, - newgen, ngen, + _hurd_id.gen.nuids ? _hurd_id.gen.uids : &uid, + _hurd_id.gen.nuids ?: 1, _hurd_id.aux.uids, _hurd_id.aux.nuids, _hurd_id.gen.gids, _hurd_id.gen.ngids, _hurd_id.aux.gids, _hurd_id.aux.ngids, diff --git a/sysdeps/mach/hurd/setgid.c b/sysdeps/mach/hurd/setgid.c index 933792b86b..660a3fe5d0 100644 --- a/sysdeps/mach/hurd/setgid.c +++ b/sysdeps/mach/hurd/setgid.c @@ -43,22 +43,45 @@ DEFUN(__setgid, (gid), gid_t gid) /* Make a new auth handle which has GID as the real gid, and as the first element in the list of effective gids. */ - gid_t newgen[_hurd_id.gen.ngids + 1]; - gid_t newaux[_hurd_id.aux.ngids]; - - newgen[0] = gid; - memcpy (&newgen[1], _hurd_id.gen.gids, - _hurd_id.gen.ngids * sizeof (gid_t)); - newaux[0] = gid; - memcpy (&newaux[1], _hurd_id.aux.gids, - (_hurd_id.aux.ngids - 1) * sizeof (gid_t)); + gid_t *newgen, *newaux, auxbuf[2]; + size_t ngen, naux; + + newaux = _hurd_id.aux.gids; + naux = _hurd_id.aux.ngids; + if (_hurd_id.gen.ngids == 0) + { + /* No effective gids now. The new set will be just GID. */ + newgen = &gid; + ngen = 1; + } + else if (_hurd_id.gen.gids[0] == 0) + { + /* We are root; set the effective, real, and saved to GID. */ + _hurd_id.gen.gids[0] = gid; + _hurd_id.valid = 0; + newgen = _hurd_id.gen.gids; + ngen = _hurd_id.gen.ngids; + if (_hurd_id.aux.ngids < 2) + { + newaux = auxbuf; + naux = 2; + } + _hurd_id.aux.gids[0] = _hurd_id.aux.gids[1] = gid; + } + else + { + /* We are not root; just change the effective GID. */ + _hurd_id.gen.gids[0] = gid; + _hurd_id.valid = 0; + newgen = _hurd_id.gen.gids; + ngen = _hurd_id.gen.ngids; + } err = __USEPORT (AUTH, __auth_makeauth (port, NULL, MACH_MSG_TYPE_COPY_SEND, 0, - _hurd_id.gen.uids, _hurd_id.gen.nuids, - _hurd_id.aux.uids, _hurd_id.aux.nuids, - newgen, 1 + _hurd_id.gen.ngids, - newaux, _hurd_id.aux.ngids, + newgen, ngen, newaux, naux, + _hurd_id.gen.gids, _hurd_id.gen.ngids, + _hurd_id.aux.gids, _hurd_id.aux.ngids, &newauth)); } __mutex_unlock (&_hurd_id.lock); diff --git a/sysdeps/mach/hurd/setregid.c b/sysdeps/mach/hurd/setregid.c index 8b76f7008a..ea7e38bc74 100644 --- a/sysdeps/mach/hurd/setregid.c +++ b/sysdeps/mach/hurd/setregid.c @@ -39,21 +39,47 @@ __setregid (gid_t rgid, gid_t egid) /* Make a new auth handle which has RGID as the real gid, and EGID as the first element in the list of effective gids. */ - size_t ngen = _hurd_id.gen.ngids < 1 ? 1 : _hurd_id.gen.ngids; - size_t naux = _hurd_id.aux.ngids < 1 ? 1 : _hurd_id.aux.ngids; - gid_t newaux[naux], newgen[ngen]; + gid_t *newgen, *newaux; + size_t ngen, naux; - newgen[0] = egid; - memcpy (&newgen[1], _hurd_id.gen.gids, (ngen - 1) * sizeof (gid_t)); - newaux[0] = rgid; - memcpy (&newaux[1], _hurd_id.aux.gids, (naux - 1) * sizeof (gid_t)); + newgen = _hurd_id.gen.gids; + ngen = _hurd_id.gen.ngids; + if (egid != -1) + { + if (_hurd_id.gen.ngids == 0) + { + /* No effective gids now. The new set will be just GID. */ + newgen = &egid; + ngen = 1; + } + else + { + _hurd_id.gen.gids[0] = egid; + _hurd_id.valid = 0; + } + } + + newaux = _hurd_id.aux.gids; + naux = _hurd_id.aux.ngids; + if (rgid != -1) + { + if (_hurd_id.aux.ngids == 0) + { + newaux = &rgid; + naux = 1; + } + else + { + _hurd_id.aux.gids[0] = rgid; + _hurd_id.valid = 0; + } + } err = __USEPORT (AUTH, __auth_makeauth (port, NULL, MACH_MSG_TYPE_COPY_SEND, 0, - _hurd_id.gen.gids, _hurd_id.gen.ngids, - _hurd_id.aux.gids, _hurd_id.aux.ngids, - newgen, ngen, - newaux, naux, + _hurd_id.gen.uids, _hurd_id.gen.nuids, + _hurd_id.aux.uids, _hurd_id.aux.nuids, + newgen, ngen, newaux, naux, &newauth)); } __mutex_unlock (&_hurd_id.lock); diff --git a/sysdeps/mach/hurd/setreuid.c b/sysdeps/mach/hurd/setreuid.c index 1dcbf0ee82..530e4a20c7 100644 --- a/sysdeps/mach/hurd/setreuid.c +++ b/sysdeps/mach/hurd/setreuid.c @@ -39,19 +39,45 @@ __setreuid (uid_t ruid, uid_t euid) /* Make a new auth handle which has RUID as the real uid, and EUID as the first element in the list of effective uids. */ - size_t ngen = _hurd_id.gen.nuids < 1 ? 1 : _hurd_id.gen.nuids; - size_t naux = _hurd_id.aux.nuids < 1 ? 1 : _hurd_id.aux.nuids; - uid_t newaux[naux], newgen[ngen]; + uid_t *newgen, *newaux; + size_t ngen, naux; - newgen[0] = euid; - memcpy (&newgen[1], _hurd_id.gen.uids, (ngen - 1) * sizeof (uid_t)); - newaux[0] = ruid; - memcpy (&newaux[1], _hurd_id.aux.uids, (naux - 1) * sizeof (uid_t)); + newgen = _hurd_id.gen.uids; + ngen = _hurd_id.gen.nuids; + if (euid != -1) + { + if (_hurd_id.gen.nuids == 0) + { + /* No effective uids now. The new set will be just UID. */ + newgen = &euid; + ngen = 1; + } + else + { + _hurd_id.gen.uids[0] = euid; + _hurd_id.valid = 0; + } + } + + newaux = _hurd_id.aux.uids; + naux = _hurd_id.aux.nuids; + if (ruid != -1) + { + if (_hurd_id.aux.nuids == 0) + { + newaux = &ruid; + naux = 1; + } + else + { + _hurd_id.aux.uids[0] = ruid; + _hurd_id.valid = 0; + } + } err = __USEPORT (AUTH, __auth_makeauth (port, NULL, MACH_MSG_TYPE_COPY_SEND, 0, - newgen, ngen, - newaux, naux, + newgen, ngen, newaux, naux, _hurd_id.gen.gids, _hurd_id.gen.ngids, _hurd_id.aux.gids, _hurd_id.aux.ngids, &newauth)); diff --git a/sysdeps/mach/hurd/setuid.c b/sysdeps/mach/hurd/setuid.c index 70d5ba4456..586ad2154f 100644 --- a/sysdeps/mach/hurd/setuid.c +++ b/sysdeps/mach/hurd/setuid.c @@ -43,20 +43,43 @@ DEFUN(__setuid, (uid), uid_t uid) /* Make a new auth handle which has UID as the real uid, and as the first element in the list of effective uids. */ - uid_t newgen[_hurd_id.gen.nuids + 1]; - uid_t newaux[_hurd_id.aux.nuids]; - - newgen[0] = uid; - memcpy (&newgen[1], _hurd_id.gen.uids, - _hurd_id.gen.nuids * sizeof (uid_t)); - newaux[0] = uid; - memcpy (&newaux[1], _hurd_id.aux.uids + 1, - (_hurd_id.aux.nuids - 1) * sizeof (uid_t)); + uid_t *newgen, *newaux, auxbuf[2]; + size_t ngen, naux; + + newaux = _hurd_id.aux.uids; + naux = _hurd_id.aux.nuids; + if (_hurd_id.gen.nuids == 0) + { + /* No effective uids now. The new set will be just UID. */ + newgen = &uid; + ngen = 1; + } + else if (_hurd_id.gen.uids[0] == 0) + { + /* We are root; set the effective, real, and saved to UID. */ + _hurd_id.gen.uids[0] = uid; + _hurd_id.valid = 0; + newgen = _hurd_id.gen.uids; + ngen = _hurd_id.gen.nuids; + if (_hurd_id.aux.nuids < 2) + { + newaux = auxbuf; + naux = 2; + } + _hurd_id.aux.uids[0] = _hurd_id.aux.uids[1] = uid; + } + else + { + /* We are not root; just change the effective UID. */ + _hurd_id.gen.uids[0] = uid; + _hurd_id.valid = 0; + newgen = _hurd_id.gen.uids; + ngen = _hurd_id.gen.nuids; + } err = __USEPORT (AUTH, __auth_makeauth (port, NULL, MACH_MSG_TYPE_COPY_SEND, 0, - newgen, 1 + _hurd_id.gen.nuids, - newaux, _hurd_id.aux.nuids, + newgen, ngen, newaux, naux, _hurd_id.gen.gids, _hurd_id.gen.ngids, _hurd_id.aux.gids, _hurd_id.aux.ngids, &newauth)); |