Search code examples
perlopencvlive555

exec() in perl as root


I am trying to execute a command through exec() in perl. It runs but not with the same results as running it outside the script as a sudoer. I would like to know how can I run the same command as sudo inside the script first to do some tests. I wouldnt like to leave a program opened running as sudo for security reasons. The program Im running is called openRTSP and it makes RTSP connection over TCP. Im guessing that my perl user is not allowed to access the files that openRTSP needs, but i didnt have any success in finding the files.

Thanks in advance.


Solution

  • There are actually two possible explanations:

    • Your script is not running with the same environment variables as the sudo execution. Maybe in the shell profile you have a specific PATH or other variable set, which is not set when running it from the script.

    • You actually do not have permissions. In that case it's tough. You do NOT want to set the setuid permission to your perl script or (even worse) your perl interpreter. What you can try to do is have a new user group (or maybe a new user) that has complete access and control over the files you need, and I mean ONLY the files you need and run the script as that user. Other than that, you can try and have a small C or C++ wrapper, but that would take longer to write, I guess.

    Also, see this question for some more info.