Basically, what I'm trying to do, is write a script where people log in with their username/password, and the script changes it's level of priveleges to match those of the user logging in (same uid, gid, and groups). The script starts out suid root, and then drops priveleges.
I'm having problems understanding how the $UID, $GID, $EUID, and $EGID variables work. Here are some examples:
If I assign the variables like this:
$UID = $new_uid;
$GID = $new_gid;
$EUID = $new_uid;
$EGID = "$new_gid $new_gid";
Then it appears as if my script is still in one of root's groups. My debugging output shows:
UID: '1001'
GID: '100 33'
EUID: '1001'
EGID: '100 33'
1001 and 100 are the user's uid and gid, so those are correct, but 33 is a group that root is in, but the user is not in. The script shouldn't be in that group anymore.
However, if I assign the variables in a different order, the results are not the same. Assigning like this:
($UID, $GID) = ($new_uid, $new_gid);
($EUID, $EGID) = ($new_uid, "$new_gid $new_gid");
results in what appears to be what I want:
UID: '1001'
GID: '100 100'
EUID: '1001'
EGID: '100 100'
I know that list variables inside a list assignment are assigned in parallel.... but why does the order affect the result? And should I be changing $UID and $GID, or just $EUID and $EGID?