Restrict access to .ksh scripts

@jlliagre
One place you can find reference to setuid and setgid being ignored is in "man ksh" in the section "Invoking ksh". Sounds like yours must be different.
There's a similar reference in Posix Shell manuals in the section "Shell Invocation".

More research has highlighted Solaris as a notable exception in the modern unix world. I'm pretty sure that suid scripts didn't work in SunOS 4.
It has been a problem to me in the distant past both when suid scripts did work and then when it suddenly stopped working!

Both "ksh" and the Posix Shell have a "-p" parameter. Indirectly the documentation for this switch explains the change of effective UID in your example.

With a bit of trial-and-error I managed to reproduce your test on HP-UX 11.1. The hint came from Sven Mascheck's site (below). On my tests it only works when there is a shebang line in the script.
With the original script owner as root and the permissions 4711 and while running as a non-priviliged user I used such a script to change a binary to permissions 6777 ! Scary.
Thankfully the passwd command doesn't work in a suid script (I already knew that). I've also checked that a non-privileged chown removes the suid bit.

This page from Sven Mascheck's excellent site has some decent lists and tables of O/S which allow suid scripts. The list omits a test result for HP-UX.
The #! magic, details about the shebang/hash-bang mechanism

This thread reinforces the old advice to not allow suid scripts and rubbishes the modern teaching and documentation that suid scripts don't work.

@ ahamed
I used the which sudo and got the below output. No sudo is there.

/usr/bin/which: no sudo in (/usr/kerberos/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/home/s_sabcd/bin

@methyl
Yes. I have the shebang line in my script. Also my scirpt is "Bourne-Again shell script text executable"

which is your OS?

--ahamed

@machomaddy
After re-reading this thread I see that you mention Linux 2.6.18 which I believe is a kernel version.
Other post in this thread says that the suid trick won't work in Linux. I have no way of checking this.
Please post what Linux distribution have (e.g. RedHat , Unbuntu, whatever). Maybe you have one which uses "su" rather than "sudo".

Mine is GNU/Linux

I used the uname -o to get this. Please correct me if I am wrong.

This should show everything:

uname -a

Linux suaoan43 2.6.18-194.3.1.0.2.el5 #1 SMP Wed May 26 10:38:10 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux