In my kiosk system (Read Continue to update my blog for more information), I am going to supply some service such as reboot/shutdown with root permission. The service may be run by HTTPD user apache or another local user.
I realized it with an inetd service, and found it so easy to supply a socket service with shell script.
I will show a simple example (on Slackware 13.0) here.
Edit /etc/services, add the following line:
my_inetd 45678/tcp #My own inetd service
Edit /etc/inetd.conf, add the following line:
my_inetd stream tcp nowait root /usr/local/sbin/my_inetd my_inetd
Create service file /usr/local/sbin/my_inetd (bash script)
#!/bin/sh while true; do echo "Please input your command:" read command echo "Your command is: $command" echo done
Remember to add x permission, and restart inetd service:
chmod a+x /usr/local/sbin/my_inetd /etc/rc.d/rc.inetd restart
Now let's check the service:
telnet localhost 45678
You will see our prompt information "Please input your command:". Great! It works now. You can change the script to run anything you like. NOTICE: if you run the server on internet, please take care of security issue, maybe iptables can deal with it —- disable access from outside, only allow local access to the service port.