LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Fedora (https://www.linuxquestions.org/questions/fedora-35/)
-   -   Unable to execute "reboot" in cgi script (https://www.linuxquestions.org/questions/fedora-35/unable-to-execute-reboot-in-cgi-script-595739/)

jcaga 10-30-2007 05:42 AM

Unable to execute "reboot" in cgi script
 
Hi,

I am trying to execute "reboot" command inside a cgi script but nothing happens. I am using 2.6.18-1.2798.fc6. My script /var/www/cgi-bin/reboot.cgi contains:
---------------
reboot
---------------

Executing the script from a remote client:
http://192.168.15.43/cgi-bin/reboot.cgi

/var/log/httpd/error_log gives me the error:

[Tue Oct 30 18:36:58 2007] [error] [client 192.168.15.91] reboot: must be superuser.
[Tue Oct 30 18:36:58 2007] [error] [client 192.168.15.91] Premature end of script headers: reboot.cgi

How do I fix this?

Thanks

shafty023 10-30-2007 09:37 AM

That would be because your apache user which is running apache does not have access privs to execute a system reboot. That would be a huge gaping security hole if any standard user could execute a system reboot remotely like that. Especially through apache.

If you want to add that support you'll need to add this to the sudoers file, assuming your apache user is "apache" ---> apache ALL=NOPASSWD: /sbin/reboot .

How do you add this to the sudoers file you ask?

1) su - root
2) visudo
3) add this line in there -> apache ALL=NOPASSWD: /sbin/reboot
4) save the changes
5) now change your script to say "sudo reboot"

jcaga 10-30-2007 09:02 PM

This line is already there:

apache ALL=(ALL) NOPASSWD:ALL

do I have to modify it to:

apache ALL=NOPASSWD: /sbin/reboot

jcaga 10-30-2007 09:50 PM

gotcha!

1.) changed apache ALL=(ALL) NOPASSWD:ALL to apache ALL=(root) NOPASSWD:ALL
2.) added sudo before the reboot command in cgi scripts
3.) commented out "Defaults requiretty" in /etc/sudoers, else you will see, "sorry, you must have a tty to run sudo"

amit_1 05-10-2012 08:45 AM

Followed the steps given by jcaga. But still not able to implement it.

When i try to open localhost/cgi-bin/reboot.cgi following error comes:-
Error 500 Internal Server Error

/var/log/httpd/error_log gives me the error:

Exec Format Error : Exec of ..cgi-bin/reboot.cgi failed

reboot.cgi has 700 permission

Any help please??

---------- Post added 05-10-12 at 07:46 AM ----------

I forgot to mention i am using RHEL 5.6


All times are GMT -5. The time now is 04:36 PM.