I'm currently trying to set the effective uid and gid to match the owner of a particular file as indicated by stat(), unfortunately it isn't working properly.

When I set the two values separately (gid first) it works as desired (setting the uid first doesn't allow the gid to change), but setting the variables at the same time doesn't set the egid properly.

Initial settings:

$uid = 99; # $> = 0 $gid = "99 2 99"; # $) = "0 1 0"

1) Separately - uid first

$> = $uid; $) = $gid; # Current values are now: # $> = 99 # $) = "0 1 0"

2) Separately - gid first

$) = $gid; $> = $uid; # Current values are now: # $> = 99 # $) = "99 2 99" # Which is the desired outcome

3) Single assignment

($>, $)) = ($uid, $gid;) # Current values are now: # $> = 99 # $) = "0 99 2" # The other groups section has been successfully changed, # but the actual effective gid has not.

Attempt 3) has the same outcome if both lists are reversed at the assignment stage.

Is it somehow possible to assign to the effective gid and uid at the same time? Obviously I can split it into two steps, but I would prefer to assign both at once if possible (and this seems a strange way to behave).

EDIT
This is Perl 5.8.0 running on Redhat 9

Prowler
 - Spelling is a demanding task that requies you full attention.


In reply to Setting EUID & EGID in one step by prowler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.