- (bal) Whitespace resync w/ OpenBSD for uidswap.c
This commit is contained in:
parent
3035860f24
commit
768f975b13
|
@ -6,6 +6,7 @@
|
||||||
- markus@cvs.openbsd.org 2001/04/23 22:14:13
|
- markus@cvs.openbsd.org 2001/04/23 22:14:13
|
||||||
[ssh-keygen.c]
|
[ssh-keygen.c]
|
||||||
remove debug
|
remove debug
|
||||||
|
- (bal) Whitespace resync w/ OpenBSD for uidswap.c
|
||||||
|
|
||||||
20010424
|
20010424
|
||||||
- OpenBSD CVS Sync
|
- OpenBSD CVS Sync
|
||||||
|
@ -5245,4 +5246,4 @@
|
||||||
- Wrote replacements for strlcpy and mkdtemp
|
- Wrote replacements for strlcpy and mkdtemp
|
||||||
- Released 1.0pre1
|
- Released 1.0pre1
|
||||||
|
|
||||||
$Id: ChangeLog,v 1.1167 2001/04/24 16:59:28 mouring Exp $
|
$Id: ChangeLog,v 1.1168 2001/04/25 06:27:59 mouring Exp $
|
||||||
|
|
66
uidswap.c
66
uidswap.c
|
@ -28,7 +28,7 @@ RCSID("$OpenBSD: uidswap.c,v 1.16 2001/04/20 16:32:22 markus Exp $");
|
||||||
|
|
||||||
/* Lets assume that posix saved ids also work with seteuid, even though that
|
/* Lets assume that posix saved ids also work with seteuid, even though that
|
||||||
is not part of the posix specification. */
|
is not part of the posix specification. */
|
||||||
|
|
||||||
/* Saved effective uid. */
|
/* Saved effective uid. */
|
||||||
static int privileged = 0;
|
static int privileged = 0;
|
||||||
static int temporarily_use_uid_effective = 0;
|
static int temporarily_use_uid_effective = 0;
|
||||||
|
@ -36,7 +36,7 @@ static uid_t saved_euid = 0;
|
||||||
static gid_t saved_egid;
|
static gid_t saved_egid;
|
||||||
static gid_t saved_egroups[NGROUPS_MAX], user_groups[NGROUPS_MAX];
|
static gid_t saved_egroups[NGROUPS_MAX], user_groups[NGROUPS_MAX];
|
||||||
static int saved_egroupslen = -1, user_groupslen = -1;
|
static int saved_egroupslen = -1, user_groupslen = -1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Temporarily changes to the given uid. If the effective user
|
* Temporarily changes to the given uid. If the effective user
|
||||||
* id is not root, this does nothing. This call cannot be nested.
|
* id is not root, this does nothing. This call cannot be nested.
|
||||||
|
@ -44,42 +44,42 @@ static int saved_egroupslen = -1, user_groupslen = -1;
|
||||||
void
|
void
|
||||||
temporarily_use_uid(struct passwd *pw)
|
temporarily_use_uid(struct passwd *pw)
|
||||||
{
|
{
|
||||||
/* Save the current euid, and egroups. */
|
/* Save the current euid, and egroups. */
|
||||||
saved_euid = geteuid();
|
saved_euid = geteuid();
|
||||||
debug("temporarily_use_uid: %d/%d (e=%d)",
|
debug("temporarily_use_uid: %d/%d (e=%d)",
|
||||||
pw->pw_uid, pw->pw_gid, saved_euid);
|
pw->pw_uid, pw->pw_gid, saved_euid);
|
||||||
if (saved_euid != 0) {
|
if (saved_euid != 0) {
|
||||||
privileged = 0;
|
privileged = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
privileged = 1;
|
privileged = 1;
|
||||||
temporarily_use_uid_effective = 1;
|
temporarily_use_uid_effective = 1;
|
||||||
saved_egid = getegid();
|
saved_egid = getegid();
|
||||||
saved_egroupslen = getgroups(NGROUPS_MAX, saved_egroups);
|
saved_egroupslen = getgroups(NGROUPS_MAX, saved_egroups);
|
||||||
if (saved_egroupslen < 0)
|
if (saved_egroupslen < 0)
|
||||||
fatal("getgroups: %.100s", strerror(errno));
|
fatal("getgroups: %.100s", strerror(errno));
|
||||||
|
|
||||||
/* set and save the user's groups */
|
/* set and save the user's groups */
|
||||||
if (user_groupslen == -1) {
|
if (user_groupslen == -1) {
|
||||||
if (initgroups(pw->pw_name, pw->pw_gid) < 0)
|
if (initgroups(pw->pw_name, pw->pw_gid) < 0)
|
||||||
fatal("initgroups: %s: %.100s", pw->pw_name,
|
fatal("initgroups: %s: %.100s", pw->pw_name,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
user_groupslen = getgroups(NGROUPS_MAX, user_groups);
|
user_groupslen = getgroups(NGROUPS_MAX, user_groups);
|
||||||
if (user_groupslen < 0)
|
if (user_groupslen < 0)
|
||||||
fatal("getgroups: %.100s", strerror(errno));
|
fatal("getgroups: %.100s", strerror(errno));
|
||||||
}
|
}
|
||||||
/* Set the effective uid to the given (unprivileged) uid. */
|
/* Set the effective uid to the given (unprivileged) uid. */
|
||||||
if (setgroups(user_groupslen, user_groups) < 0)
|
if (setgroups(user_groupslen, user_groups) < 0)
|
||||||
fatal("setgroups: %.100s", strerror(errno));
|
fatal("setgroups: %.100s", strerror(errno));
|
||||||
pw->pw_gid = pw->pw_gid;
|
pw->pw_gid = pw->pw_gid;
|
||||||
if (setegid(pw->pw_gid) < 0)
|
if (setegid(pw->pw_gid) < 0)
|
||||||
fatal("setegid %u: %.100s", (u_int) pw->pw_gid,
|
fatal("setegid %u: %.100s", (u_int) pw->pw_gid,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
if (seteuid(pw->pw_uid) == -1)
|
if (seteuid(pw->pw_uid) == -1)
|
||||||
fatal("seteuid %u: %.100s", (u_int) pw->pw_uid,
|
fatal("seteuid %u: %.100s", (u_int) pw->pw_uid,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Restores to the original (privileged) uid.
|
* Restores to the original (privileged) uid.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue