A module to make it simple to drop all privileges, even posix groups.
This module tries to simplify the process of dropping privileges. This can be useful when your Perl program needs to bind to privileged ports, etc. This module is much like Proc::UID, except that it's implemented in pure Perl. Special care has been taken to also drop saved uid on platforms that support this, currently only test on on Linux.
use Privileges::Drop; # Do privileged stuff # Drops privileges and sets euid/uid to 1000 and egid/gid to 1000. drop_uidgid(1000, 1000); # Drop privileges to user nobody looking up gid and uid with getpwname # This also set the environment variables USER, LOGNAME, HOME and SHELL. drop_privileges('nobody');
Drops privileges and sets euid/uid to $uid and egid/gid to $gid. Supplementary groups can be set in @groups.
Drops privileges to the $user, looking up gid and uid with getpwname and calling drop_uidgid() with these arguments. The environment variables \s-1USER\s0, \s-1LOGNAME\s0, \s-1HOME\s0 and \s-1SHELL\s0 are also set to the values returned by getpwname. Returns the $uid and $gid on success and dies on error. \s-1NOTE:\s0 If drop_privileges() is called when you don't have root privileges it will just return undef;
As this module only uses Perl's built-in functions, it relies on them to work correctly. That means setting $GID and $EGID should also call setgroups(), something that might not have been the case before Perl 5.004. So if you are running an older version, Proc::UID might be a better choice.
Troels Liebe Bentsen <[email protected]>
Copyright(C) 2007-2009 Troels Liebe Bentsen
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.