I have some bash scripts that I use with the user 'root' to manage iptable rules.
The problem is that I want these things at the same time:
- The script must be owned by root
- Permissions must be 700
- I want to have an executable binary that certain user can execute. This executable will run the mentioned script as root.
This used to work, and is still what I use in older distributions:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
setuid(0);
system("/root/iptables/my-iptables-script.sh");
return 0;
}
So I compile this and then use sudo chown root
and sudo chmod 4777
. This way the user can now execute the binary and run the script owned by root.
But now I installed Ubuntu 13.10 and when I run that binary I get "permission denied" for the script.
Is it possible that something changed in this respect since 12.04?
What can I do?
strace -f -e trace=process /path/to/binary
What is the shebang line of the script? – Hauke Laging Feb 26 '14 at 22:11#!/bin/sh
– ChocoDeveloper Feb 26 '14 at 22:19system("strace -f -o /root/iptables/script.strace /root/iptables/my-iptables-script.sh");
and give us the content ofscript.strace
. – Hauke Laging Feb 26 '14 at 22:35strace: Can't stat '/root/iptables/my-iptables-script.sh': Permission denied
– ChocoDeveloper Feb 26 '14 at 22:50mount | grep nosuid
? – slm Feb 26 '14 at 23:10strace
cannot stat the script file then the binary does obviously not run as root. Either yoursudo chmod 4777
did not work or the SUID bit was reset by a non-root user writing to the file or (as slm indicates) the binary resides on anosuid
filesystem. You may add a message to the binary which tells the user the RUID and EUID (aftersetuid(0)
). – Hauke Laging Feb 26 '14 at 23:15df -h /path/to/file
. – slm Feb 26 '14 at 23:17/home/myuser/Encryptor [...] (rw,nosuid,nodev
is not mountednosuid
, really? – Hauke Laging Feb 26 '14 at 23:17df
says the binary is in filesystem/home/myuser/.Private
mounted on/home/myuser
, and the script is in filesystem/dev/mapper/ubuntu--vg-root
mounted on/
– ChocoDeveloper Feb 26 '14 at 23:22