[comp.unix.wizards] setuid?

arras@icase.edu (Michael Arras) (05/07/90)

	I have a shell script I would like other users to run as myself. I
tried:

% chmod +s myfile

but it did not work. I tried this under System V/386 unix. Does anyone know
how to set the effective or real uid under this unix. I also tried the C
function seteuid() and got:

undefined			first referenced
 symbol				in file
seteuid				trysetuid.o
ld fatal: Symbol referencing errors. No output written to trysetuid

Mike Arras
arras@icase.edu			Eschew Obfuscation
ICASE/NASA Langley

egnu02@castle.ed.ac.uk (M Rae) (05/07/90)

In article <1990May7.020504.26757@icase.edu> arras@icase.edu (Michael Arras) writes:
>
>	I have a shell script I would like other users to run as myself. I
>tried:
>
>% chmod +s myfile
>

Use chmod giving the octal permission values

% chmod 4711 myfile 

which gives -rws--x--x permissions.
REAL wizards always do it this way :)

	-Mark

merlyn@iwarp.intel.com (Randal Schwartz) (05/08/90)

In article <3830@castle.ed.ac.uk>, egnu02@castle (M Rae) writes:
| In article <1990May7.020504.26757@icase.edu> arras@icase.edu (Michael Arras) writes:
| >
| >	I have a shell script I would like other users to run as myself. I
| >tried:
| >
| >% chmod +s myfile
| >
| 
| Use chmod giving the octal permission values
| 
| % chmod 4711 myfile 
| 
| which gives -rws--x--x permissions.
| REAL wizards always do it this way :)

But REAL wizards wouldn't have asked this question in c.u.w, because
it is *inappropriate*.  And, a real wizard would also tell you that
(1) setuid shell scripts are pretty durn dangerous (and anybody that
can't even handle turning on the setuid bit almost certainly shouldn't
be turning it on in a SHELL script), and (2) setuid shell scripts
don't work on most earlier UNIXes, because the shell is interpreting
the script.  (You need a '#!'-convention, or that other hack that S5
threw in to get setuid shells to work.)

Besides, fledgling wizards should be taught to type:

	chmod u+s myfile

until they get their octal down pat.

Just another UNIX wizard,
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/

ag@cbmvax.commodore.com (Keith Gabryelski) (05/08/90)

In article <3830@castle.ed.ac.uk> egnu02@castle.ed.ac.uk (Mark Rae) writes:
>In article <1990May7.020504.26757@icase.edu> arras@icase.edu (Michael Arras)
writes:
>>	I have a shell script I would like other users to run as myself. I
>>tried:
>>
>>% chmod +s myfile
>
>Use chmod giving the octal permission values
>
>% chmod 4711 myfile 
>
>which gives -rws--x--x permissions.  REAL wizards always do it this way :)

This didn't answer Mr. Rae's question nor was it in the least
constructive since on System V [*1] a shell script can not be setuid;
on Berkeley setuid shell scripts have been shown to be security holes.

What Mr. Ray wants is C program wrapper that is setuid to himself that
exec(2)s his shell script.

Pax, Keith

*1: at least as distributed from AT&T; your vendor may have made some
mistake and stuck it in.
--
Support code for SVVS:
{int fd=open("/dev/zero",0);mmap(0,0x800,1,0x11,fd,0);close(fd);}
Keith Gabryelski				ag@amix.commodore.com

guy@auspex.auspex.com (Guy Harris) (05/09/90)

>(You need a '#!'-convention, or that other hack that S5
>threw in to get setuid shells to work.)

Uhh, what other hack is that?

(Of course, since I have rarely, if ever, used octal modes in "chmod"
since I first used V7, I'm not a wizard....)

guy@auspex.auspex.com (Guy Harris) (05/09/90)

>This didn't answer Mr. Rae's question nor was it in the least
>constructive since on System V [*1] a shell script can not be setuid;

Eh?  When last I saw S5R4 it *did* support set-uid shell scripts, and
used the "/dev/fd/N" hack to get around at least one of the known
security holes.

ag@cbmvax.commodore.com (Keith Gabryelski) (05/09/90)

In article <3320@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes:
>In article <11410@cbmvax.commodore.com> I wrote:
>>This didn't answer Mr. Rae's question nor was it in the least
>>constructive since on System V [*1] a shell script can not be setuid;
>
>Eh?  When last I saw S5R4 it *did* support set-uid shell scripts, and
>used the "/dev/fd/N" hack to get around at least one of the known
>security holes.

My mistake--a correction: System V Release 4.0 does support set-uid
shell scripts if the !# notion is used.  I've tried this with the
bourne and korn shells.

Pax, Keith
-- 
Support code for SVVS:
{int fd=open("/dev/zero",0);mmap(0,0x800,1,0x11,fd,0);close(fd);}
Keith Gabryelski				ag@amix.commodore.com

guy@auspex.auspex.com (Guy Harris) (05/10/90)

>My mistake--a correction: System V Release 4.0 does support set-uid
>shell scripts if the !# notion is used.  I've tried this with the
>bourne and korn shells.

It should work with the C shell as well, although since the C shell is
derived from the 4.3BSD one, you have to put the "-b" flag in the "#!"
line.

You should, of course, put the "-" flag in the "#!" line for the Bourne
or Korn shells (unless you *like* security holes).  Of course, you
should also make sure you set IFS and PATH very early on in the script
(or "path" if the C shell).  There are probably various other things you
should do in order to make a less-insecure set-UID shell script.  I
don't know whether it's possible to make a secure set-UID shell script
or not; people have probably thought so in the past, and been rudely
surprised....

>Support code for SVVS:
>{int fd=open("/dev/zero",0);mmap(0,0x800,1,0x11,fd,0);close(fd);}

Oh, dear.  Won't people - people writing the SVVS, in particular -
*EVER* learn to stop dereferencing null pointers?  Sigh....

(For the benefit of those not familiar with "mmap()" or "/dev/zero", the
above sequence of code amounts to "stuff a 2K zero-fill-on-demand
read-only page at location zero", for the benefit of stupid code that
doesn't check for NULL pointers.)