I'm user user1 need to execute a shell script (script.sh) which is owned by user2.
-rwsrwxrwx 1 user2 aduser 3518 Aug 21 05:33 script.sh
Only user2 has write privileges to write/copy a file in directory /dir1/subdir. Hence SUID bit permissions are set to that script.sh. But still not able to run the script from user1 account. It says permissions denied to /dir1/subdir.
But the same script (script.sh) runs successfully from user2 account and able to copy/write a file in /dir1/subdir.
The file-system will be the right-most column from the df command. I've asked it to search in various places (some of which won't exist) to try to cover all operating systems.
As has been said before, it is always a good idea to tell us what operating system you're using (in addition to the shell you're using) when you ask a question here. We can give you much more responsive suggestions if we know the environment you're using...
Even on systems that allow set-UID and/or set-GID scripts, most of them won't allow it when users other than the file's owner (especially for set-UID scripts) and/or groups other than the file's group (especially for set-GID scripts) can write to the file containing the script.
If you can get user2 to change the mode of script.sh from mode 4777 to mode 4755 , you might get it to work on some systems.
Note: /home/user1/script_test/test_script_v1 --> script to copy a file in /dir1/subdir where user1 (me) don't have access to write/copy a file
The program is compiled and I had set the SUID permissions. After setting SUID for that executable I tried to execute it from my home dir, It executed successfully and copied the file in the directory /dir1/subdir.
But I need to pass 5 input parameters to shell script, The scenario just tested is just executing the shell script from c program.. But I need to pass input parameters to shell script. Can anyone please tell me how to change the above c program to pass inputs to shell script.
Thanks in advance.
That would be for constant parameters. You might want to copy the program's parameters to the script parameters using a for loop up to argc, and strcat the respective argv array elements to follow the script name.