Nygeve has asked for the wisdom of the Perl Monks concerning the following question:

Good day, monks.

I'm runnig perl script under UNIX and daemonize it. Is it possible to set root privileges for it(after running)?

Replies are listed 'Best First'.
Re: Setting root privileges for a script
by rob_au (Abbot) on Dec 05, 2002 at 11:50 UTC
    While this can certainly be achieved in Perl, I would suggest that this is not recommended practice (unless there is a pressing need for such privileges) - Typical practice for a daemon is to drop security privileges as soon as possible so that should an exploit in the daemon package be discovered, the risk of harm is minimised.

    For a discussion on securing and locking down daemon processes, this article may be of interest.

    In addition to the POSIX module to which you have been directed above by dbp, I would recommend your having a look at the real and effective user ID variables ($<, $>, $( and $)) listed in perlvar. Note that these variables can only be set, changing the corresponding process user ID variables, on machines supporting the associated set[re][ug]id() routine.

     

    perl -le 'print+unpack("N",pack("B32","00000000000000000000000111110011"))'

Re: Setting root privileges for a script
by dbp (Pilgrim) on Dec 05, 2002 at 10:30 UTC
    Check out the POSIX module. It has setuid, setpgid, and setsid subs. There is also a setpgrp function built into Perl.