I am writing a perl cgi application. At some point of time this cgi application needs to run as root to access and write into a specific file. I would like to know how exactly I should go about doing this and the security precautions that I should take while doing it.
相关问题
- $ENV{$variable} in perl
- Is it possible to pass command-line arguments to @
- Redirecting STDOUT and STDERR to a file, except fo
- Change first key of multi-dimensional Hash in perl
- How do I get a filehandle from the command line?
相关文章
- Running a perl script on windows without extension
- Comparing speed of non-matching regexp
- Can NOT List directory including space using Perl
- Extracting columns from text file using Perl one-l
- Lazy (ungreedy) matching multiple groups using reg
- How do I tell DBD::mysql where mysql.sock is?
- What is a good way to deploy a Perl application?
- Speeding up Selenium Webdriver
You must avoid doing that if you can at all times by all means.
If your program needs to write to the privileged file instantly, then go with Mat's reply. However, you can write the content somewhere else and run a cron job (say) every five minutes to copy the data.
You pretty much shouldn't.
If you can't avoid it, create a small and simple piece of code that runs with setuid root that does exactly that task and nothing more, or use
sudo
or similar to run a script that does just that.Giving that file the appropriate permissions so that your web user can write to it (not necessarily read from it if that's not necessary) would be a better option.