pileofrogs has asked for the wisdom of the Perl Monks concerning the following question:

Ooh Yay Yay Su Dominay <Whack>, Ye Monks

I'm working on making c saved id functions available in perl. (see Announcing Unix::SavedIDs)

These functions can change the processes UID, EUID, GID and EGID. When I use these functions in perl the IDs do change. I've tested by attempting various file accesses. However, $<,$>,$(,and $) don't reflect the new values.

I think I need to do something in my XSUB to tell perl that those values need to be updated.

Any ideas how to do that?

Thanks!
--Pileofrogs

Replies are listed 'Best First'.
Re: XS Question
by ysth (Canon) on May 09, 2008 at 23:42 UTC
    Set PL_uid, PL_euid, PL_gid, or PL_egid to the new values. In general, to see where built-in magic variables get their value, look at Perl_magic_get in mg.c.

    When any of the variables are changed, perl also sets the low bit of PL_tainting on if the uid is not 0 and either the euid differs from the uid or the egid differs from the gid. You may want to do this in your code too.

Re: XS Question
by chip (Curate) on May 09, 2008 at 23:41 UTC
    I find in mg.c references to global variables PL_gid and PL_uid. Perhaps these are your problem.

        -- Chip Salzenberg, Free-Floating Agent of Chaos

Re: XS Question
by syphilis (Archbishop) on May 09, 2008 at 23:43 UTC
    If you have perl subs/functions that can change the values of those variables, then you could do a callback to those subs/functions from within your XS code.

    See 'perldoc perlcall' - especially the examples that are provided therein.

    Cheers,
    Rob
    Update: Looks like ysth knows a better solution.