in reply to Re: Perl as a daemon... as root?
in thread Perl as a daemon... as root?
If the system supports setreuid() (Linux does), you don't need sudo to switch the userid. Start the script under root (or another privileged id), then drop privileges immediately. When an action needs root privileges again, that can be done with a local change to the effective uid $>:
That works without compromising security in any way.print "real: $<, effective $>\n"; $> = 1000; # drop privileges print "real: $<, effective $>\n"; { # locally regain privileges local $> = 0; $> == 0 or die "Insufficient privileges, run script as root"; print "real: $<, effective $>\n"; } # unprivileged again print "real: $<, effective $>\n";
Anno
|
|---|