20 Sep 2011 11:14:19 UTC
- Distribution: Privileges-Drop
- Module version: 1.03
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (1)
- Testers (3541 / 204 / 1)
- KwaliteeBus factor: 0
- 24.18% Coverage
- License: perl_5
- Activity24 month
- Download (5.78KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionTLBDK Troels Liebe Bentsenand 1 contributors
- Troels Liebe Bentsen
Privileges::Drop - 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 enviroment variables USER, LOGNAME, HOME and SHELL. drop_privileges('nobody');
- drop_uidgid($uid, $gid, @groups)
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 USER, LOGNAME, HOME and SHELL are also set to the values returned by getpwname.
Returns the $uid and $gid on success and dies on error.
NOTE: If drop_privileges() is called when you don't have root privileges it will just return undef;
As this module only uses Perl's build in function, 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@example.com>
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.
Module Install Instructions
To install Privileges::Drop, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Privileges::Drop
For more information on module installation, please visit the detailed CPAN module installation guide.