how to execute perl cgi with root rights ?
Added by sasza almost 15 years ago
Hi *
I'm writing small server managing console. It is simple html page with forms which are calling perl script on server side.
My server side perl script will do actions on server and many of such actions are requiring root rights.
Http server is lighttpd 1.4.26 running on ArchLinux. It is running as user:grup=http:http.
When my perl script is trying execute system commands requiring root, I'm receiving:
"access denied". Actions not requiring root are OK.
I believe it is because system command - which needs root rights - is executed as user http.
What is the best method to arrange this ?
thx in advance
Replies (6)
RE: how to execute perl cgi with root rights ? - Added by darix almost 15 years ago
you dont want to do that. have a small daemon running as root and your perl app talking to that.
RE: how to execute perl cgi with root rights ? - Added by sasza almost 15 years ago
Thx for quick replay.
Indeed this is good idea, but is it only possible one ?
You know - for implementing this I have to arrange v.simple perl client-server setup with ipc.
I would prefer solution based on changing perl execution context from http to root as this will require minimal effort in existing perl scripts.
Is it possible ? (beside changing http server group:user from http:http to root:root. Changing it is bad idea from security point of view :-()
br
RE: how to execute perl cgi with root rights ? - Added by darix almost 15 years ago
sudo
sudo allows you to limit the commands that can be run and even restrict the cmdline.
but make sure you properly escape all arguments that an user can enter. ideally there wont be any user supplied arguments in the list.
RE: how to execute perl cgi with root rights ? - Added by sasza almost 15 years ago
Right,
sudo was first thing which I tried.
what I do:
in perl scrip I have:
$cmd = "sudo /sbin/sv restart /var/service/smbd 2&1 2>/dev/null |>";
Well - executing this produces nothing.
If I remove sudo - I get:
Commandline: /sbin/sv restart /var/service/smbd 2>&1 2>/dev/null |
Output: warning: /var/service/smbd: unable to open supervise/ok: access denied
RE: how to execute perl cgi with root rights ? - Added by darix almost 15 years ago
in your cmdline output the sudo is missing :)
double check it is really used.
RE: how to execute perl cgi with root rights ? - Added by sasza almost 15 years ago
Well, my post wasn't enough consistent :-p
last 2 lines are lines showing output without sudo.
For cmd with sudo output is following:
Commandline: sudo /sbin/sv restart /var/service/smbd 2>&1 2>/dev/null |
Output:
Strange.