Created
November 23, 2011 12:14
-
-
Save mschmitt/1388529 to your computer and use it in GitHub Desktop.
Perl wrapper to run process as different user and group
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use diagnostics; | |
my $uid = (getpwnam("saned"))[2]; | |
my $gid = (getgrnam("scanner"))[2]; | |
$( = $) = "$gid $gid"; | |
$< = $> = "$uid"; | |
if ( | |
($< ne "$uid") or | |
($> ne "$uid") or | |
($( ne "$gid $gid") or | |
($) ne "$gid $gid") | |
){ | |
die "Failed to drop privileges to: $uid/$gid. Aborting.\n"; | |
} | |
exec ('/usr/bin/id') or die "Couldn't exec!\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment