[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Setting effective UID for a shell script



On  0, Alberto Cabello Sanchez <alberto@unex.es> wrote:
> As far as I know, you can't. I think you have to setuid() and exec() in
> a, say, C compiled program.

No, that's when you want to do it the other way around.

If you are root and want to run it as someone else, then:

su -c <cmd>

will do it without asking for a passwd.

If you are not root and want to run it as root, then:

 * Use one of the setuid script wrappers around.  I don't know of any
   off the top of my head, but they must be around.
 * Write your own setuid script wrapper in C.  It's not hard - it goes
   something like this:

#include <unistd.h>
int main( int argc, char** argv )
{
	execve( argv[0], argv[1] );
	return 0;
}

chown root setuidscriptwrapper
chmod u+sx setuidscriptwrapper

or something of that order.  Control *very* closely who has permission
to run this script.

Tom
-- 
Tom Cook
Information Technology Services, The University of Adelaide

"There are few things more satisfying than seeing your children have teenagers of their own."
	- Doug Larson

Get my GPG public key: https://pinky.its.adelaide.edu.au/~tkcook/tom.cook-at-adelaide.edu.au

Attachment: pgpe9u3G0Wwve.pgp
Description: PGP signature


Reply to: