Ali Azimi
Ali Azimi

Reputation: 331

Reload linux services in c

I want to restart linux services such as apache, bind, proftpd and other in c and cgi code.

i use system() to do this, for example :

system ("service httpd reload");

also i set suid on compiled program and run it. but don't work and return error on permissions.

what should i do ?

edit: my apache logs error :

[Wed Dec 21 21:07:13 2011] [error] [client *] cannot remove `/var/run/httpd.pid'
[Wed Dec 21 21:07:13 2011] [error] [client *] : Permission denied
[Wed Dec 21 21:07:13 2011] [error] [client *]
[Wed Dec 21 21:07:13 2011] [error] [client *] touch:
[Wed Dec 21 21:07:13 2011] [error] [client *] cannot touch `/var/lock/subsys/httpd'
[Wed Dec 21 21:07:13 2011] [error] [client *] : Permission denied

and same logs for named, proftpd, etc.

Upvotes: 4

Views: 1758

Answers (2)

You need to be root to run successfully the /usr/sbin/service command.

So your question is how can your application gain root privileges.

If your application is a CGI to which you (legitimately) don't want to give root access, you could code a wrapper program which is setuid root and which can only be run from you CGI (or at least, from the uid under which it is running).

But are you sure that you really want to run such things from CGI? (You could study how webmin works).

Upvotes: 0

dimir
dimir

Reputation: 793

Here is a couple of things to check:

  1. Make sure the compiled program has suid root (that is, the owner of the program is root).
  2. Make sure the partition you are executing the program from is mounted without "noexec" option.

Upvotes: 1

Related Questions