|
-
May 11th, 2006, 11:36 PM
#1
Perl, suid, and linux headache
So im trying to do this lab in perl on a solaris machine. Everything works fine until the program is setuid which it needs to be. What im trying to do is get the full path to the script itself and use that path to create files in that dir.
Im using the builtin $0 var to get the full path and file name, then using
$dir = dirname($0); // gets the path name minus the trailing /
I tried using pwd but that doesnt work unless you call the script from its directory.
This works fine, until the script is suid, at which point the $dir variable changes to /dev/fd
instead of /share/longpre/bertka.
Any ideas on how to get around this another way?
<chsh> I've read more interesting technical discussion on the wall of a public bathroom than I have at AO at times
-
May 12th, 2006, 08:12 AM
#2
Solaris != Linux...
Try a small test script
Code:
#!/usr/bin/perl
print "name: $0\n";
To see what happens with $0..
What happens in the dirname sub?
Oliver's Law:
Experience is something you don't get until just after you need it.
-
May 13th, 2006, 03:44 AM
#3
$0 == /share/longpre/bertka/path.pl when not setuid
$0 == /dev/fd/4 when setuid
im not sure what happens in the dirname sub. I should have made it clear about what the issue was, sorry. Its not with the dirname sub but with perls internal variable $0
good job on finding my linux/solaris typo.
<chsh> I've read more interesting technical discussion on the wall of a public bathroom than I have at AO at times
-
May 13th, 2006, 07:37 AM
#4
Seems like a bug. It's probably too late now, but can you just have an argument be the path?
./script `pwd`
Maybe document that there seemed to be some sort of bug and you had to use a workaround.
-
May 14th, 2006, 01:39 PM
#5
A little suprised, I tested myself and confirmed the behaviour, definitely seems like a bug (using the test script):
[504] user@sol (~)% chmod +sx test.pl
[505] user@sol (~)% ls -al test.pl
-rwsr-sr-x 1 user user 33 May 14 07:26 test.pl
[506] user@sol (~)% uname -r
5.9
[507] user@sol (~)% uname -ra
SunOS sol 5.9 Generic_118558-22 sun4u sparc SUNW,Sun-Fire-280R
[508] user@sol (~)% ./test.pl
name: /dev/fd/3
[509] user@sol (~)% chmod -s test.pl
[510] user@sol (~)% ./test.pl
name: ./test.pl
Is there some reason you can't use pwd ?
[527] user@sol (~)% ls -al test.pl
-rwxr-xr-x 1 user sol 193 May 14 07:36 test.pl
[528] user@sol (~)% chmod +s test.pl
[529] user@sol (~)% ./test.pl
name: /dev/fd/3
CWD: /export/home/user
Code:
#!/bin/perl
print "name: $0\n";
$dir = `pwd`;
print "CWD: $dir\n";
There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.
(Merovingian - Matrix Reloaded)
-
May 14th, 2006, 06:28 PM
#6
I didnt want to use pwd as it prints the dir the user is in when they call the script and not the dir the script is in. It was my first choice and i tested it and that was the issue that came up.
<chsh> I've read more interesting technical discussion on the wall of a public bathroom than I have at AO at times
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|