Page 1 of 1

User context for init.d scripts

Posted: Mon Jan 10, 2011 3:10 am
by jayrock
Hello,

I'm a little confused with regards to the scripts in init.d. In which context are they executed?

I have a script with some commands. I cannot execute those commands from shell as user, but only as root. The script however seems to work fine once put into init.d.

Googled for it but found contradicting answers here as well. Some claim the context for init.d is root, others say su is needed. It seems the majority thinks that init.d is owned and executed by root, but still I would be glad if someone could clarify this.

Then again, the script used here http://wiki.amahi.org/index.php/Mount_Shares_Locally requires an input file with root credentials - why?


Thanks,

jayrock

Re: User context for init.d scripts

Posted: Mon Jan 10, 2011 3:36 am
by moredruid
I think the /etc/init.d/* should be owned by root. You _can_ however run them in the sudo context if your privileges are sufficient. It might be sufficient to have them owned by a normal user but with the setuid bit set to root, I'm not sure.

could you post your script so we can analyse why it's failing for a normal useraccount?

Re: User context for init.d scripts

Posted: Mon Jan 10, 2011 5:37 am
by jayrock
Thanks for your quick response, it's absolutely fine for me that init.d scripts run as root, I just to want be sure I understand what's going on.

One script is actually posted here, it's "hdparm" that requires the user to be root. As mentioned the script runs fine so no problem. http://forums.amahi.org/viewtopic.php?p=11679#p11679

The other one is a Ruby program that calls an ICMP ping procedure (and others) which requires root. Again, no promblem here, just want be sure about what I'm doing. See here: http://forums.amahi.org/viewtopic.php?p=11632#p11632

So to conclude, for now I assume that when I test the program / script as root, it will behave exactly as when it's started via init.d

Leaves the question open, why does http://wiki.amahi.org/index.php/Mount_Shares_Locally require root credentials to be supplied?

Cheers,

jayrock

Re: User context for init.d scripts

Posted: Mon Jan 10, 2011 9:23 am
by radioz
I haven't looked at the code for the mount_shares_locally script, but since it needs to mount file systems, it would need root permissions to do that.

Re: User context for init.d scripts

Posted: Mon Jan 10, 2011 10:04 am
by jayrock
Well, yes - but that's the whole point, as a script in init.d it has root permission anyway. Maybe it wouldnt need the supplied credentials then. It's just a bit confusing.