Skip to content

Instantly share code, notes, and snippets.

@mschmitt
Created November 23, 2011 12:14
Show Gist options
  • Save mschmitt/1388529 to your computer and use it in GitHub Desktop.
Save mschmitt/1388529 to your computer and use it in GitHub Desktop.
Perl wrapper to run process as different user and group
#!/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