I want to make a script to shutdown a unixware computer from other user then root. In Sco version i use "as root" but in the unixware i don't know.
Please help me.
10x
You'll either need some sort of daemon that sits around and waits to be told to shut down, or a setuid script owned by root. Be very careful with that, anyone who runs it gets a process running as root.
Ok. Tell me the script.
I don't get it.
The script will be something like:
#!/bin/sh
exec /sbin/poweroff
i.e. whatever way you shut down the server as root.
Call it turnoff.sh and put it in /sbin/ . Then make sure it's owned by the user root and the group wheel(or whatever other group you want that's a group of people you want to be able to turn off the machine).
# cp turnoff.sh /sbin/turnoff.sh
# chown root:wheel /sbin/turnoff.sh
Now give it these permissions:
# chmod 550 /sbin/turnoff.sh
# chmod u+s /sbin/turnoff.sh
As in, only it's owner and it's group can read or execute it, and it has the setuid bit.
That way, people who run the file will run it with root permissions. Yes, it has to be carefully controlled. Setuid is considered dangerous.
Technically, you could do the exact same things to the file itself, but I think it's better to make it a script that won't be replaced every time you upgrade these things.
It doesn't work.
I must be root to work.
"Must be a previlaged user" that say when I try.
I do that:
su root
password
shutdown
How can I do that in a script?
Your OS possibly does not support setuid shell scripts.
#!/sbin/sh
exec /sbin/sh
Create a script as above. Then set the owner to root and the permissions to 4555. Then, run the script as a normal user and run 'whoami'. If the output is root, then you have setuid shell script support on your system. If not, then you will have to 'encapsulate' the script inside a C program that can then be setuid root and not writable by anyone (for security).
When I run whoami the output isn't root it is my user.
So what to do next?
How can I transfer this script into a .c file?
void main()... lol
I don't know
No problem. Try this.
# cat wrapper.c
#include<sys/types.h>
#include<unistd.h>
int main() {
setuid(0);
execl("full_path_to_your_program","filename_of_your_program",0);
}
# cc wrapper.c -o wrapper
# chmod 4555 wrapper
When you run the wrapper, the script will execute as root.
The program doesn't work or I don't know unix. The second one it's true.
My wrapper.c is from line 2 to 7.
Last 2 line I write from root
When I run wrapper nothing happen.
My "full_path_to_your_program" is "/sbin"
My "filename_of_your_program" is "turnoff.sh"
turnoff.sh is :
echo "Program run"
exec /sbin/shutdown -y
If nothing happen when I run wrapper then turnoff.sh isn't running. Why?
turnoff.sh is in /sbin.
Oh, sorry my path_to_program is a bit confusing. Your exec should go like this:
execl("full_path_incl_prog_name","prog_name","any_options","any_more_options",..,0);
In code:
execl("/sbin/turnoff.sh","turnoff.sh",0);
The program work now but:The same thing
"Must be a previlaged user" 
Oh for... can you paste the C code of the program and the current permissions on the executable file?