Subject: Re: non-root user executes root shell?
To: None <netbsd-users@netbsd.org>
From: Sascha Retzki <lantis@iqranet.info>
List: netbsd-users
Date: 10/03/2004 10:55:22
On Sun, Oct 03, 2004 at 03:48:39PM +0900, Joel Rees wrote:
> 
> On 2004.10.3, at 03:33 PM, Water NB wrote:
> 
> >I have a shell-script which be used to mount and umount ISO file to a
> >directory. And I want a non-root user can execute it. How can I?
> >
> >For example:
> >
> >#! /bin/sh
> >vnconfig -c vnd0 /xxx.iso
> >mount cd9660 /dev/vnd0c /mnt
> 
> I'm in the sudo camp on that, myself, but someone here said recently 
> they write a user runnable mount program in C to do that. 

--C code--
#include <stdio.h>

void main(void) {
	system("id");
}
--END C code--
Compile it with "gcc -o executable_name sourcefilename.c".
after that, set the executalbe suid root: "chown root.wheel m00.exe" ;
"chmod +s m00.exe" ... .
you can put the both commands of the script into system() calls, however 
you will not be able to fetch return codes and react via if() calls,
at least not in C. But you get the deal.
Btw, either use "mount_cd9660" or "mount -t cd9660" ;)
If you ever look into writting real C programms and not some sh-script 
imitations, please use "int main(int argc, char *argv[])" and return some
value at the end :))