chazhs
asked on
a cgi wrap to do setuid to root - question for jsatterl or anyone else
Can you tell me how to write the cgi wrap that can be setuid to root and then change the process id of the owner of a file?
Please refer to question below; my problem is not resolved yet.
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?qid=20123690
To summarise my request: I want to be able to write to a file from a cgi script. The file does not have world writable permissions.
Setting the owner if the file to be the owner of the script did not work for me.
Thanks for any help.
Please refer to question below; my problem is not resolved yet.
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?qid=20123690
To summarise my request: I want to be able to write to a file from a cgi script. The file does not have world writable permissions.
Setting the owner if the file to be the owner of the script did not work for me.
Thanks for any help.
ASKER
Yes, you are absolutely right, I was confused with "owner of the script" and "owner of the CGI"
I wrote a small pipe to look under which user the cgi is running: But bad luck, $string does not have a value in the below code.
So I am not sure who is the" owner of cgi" on the server. Does this make sense, or am I doing something wrong still?
# Create the pipe to get the output of the shell command
open (PS, "/usr/bin/ps -f |");
while (<PS>) {
$string = <PS>;
print "This process is running as $string";
# the o/p i get for $string is blank
}
Thanks for your time.
I wrote a small pipe to look under which user the cgi is running: But bad luck, $string does not have a value in the below code.
So I am not sure who is the" owner of cgi" on the server. Does this make sense, or am I doing something wrong still?
# Create the pipe to get the output of the shell command
open (PS, "/usr/bin/ps -f |");
while (<PS>) {
$string = <PS>;
print "This process is running as $string";
# the o/p i get for $string is blank
}
Thanks for your time.
What's the OS? Unix?
Try this:
@x = `/usr/bin/ps -f`;
print "PS returned @x\n";
See if it works better.
But There is also a PERL way of finding out the user id.
I believe $> has the "effective UID" and $< has the "real UID". Or if you use "english names", then $EUID and $UID are the token names.
$) and $( have the effective GROUP id and the REAL group id respectively.
So
print "EUID = $>\n";
print "UID = $>\n";
print "EGUID = $)\n";
print "GID = $(\n";
Dave
Try this:
@x = `/usr/bin/ps -f`;
print "PS returned @x\n";
See if it works better.
But There is also a PERL way of finding out the user id.
I believe $> has the "effective UID" and $< has the "real UID". Or if you use "english names", then $EUID and $UID are the token names.
$) and $( have the effective GROUP id and the REAL group id respectively.
So
print "EUID = $>\n";
print "UID = $>\n";
print "EGUID = $)\n";
print "GID = $(\n";
Dave
Oops Typo. SHould be:
print "EUID = $>\n";
print "UID = $<\n"; # this one was wrong.
print "EGUID = $)\n";
print "GID = $(\n";
print "EUID = $>\n";
print "UID = $<\n"; # this one was wrong.
print "EGUID = $)\n";
print "GID = $(\n";
ASKER
Here is the output to your code:
PS returned
EUID = 60001 UID = 60001 EGUID = 60001 60001 GID = 60001 60001
So ps returned with blank value again, and effective UID has some numbers. Does this make sense?
My o.s is solaris5.7
Maybe it means my cgi is running under user " "? Dont know if/how I can change it. And probably, I cannot, since I dont have root permissions on this server?
Thankyou.
PS returned
EUID = 60001 UID = 60001 EGUID = 60001 60001 GID = 60001 60001
So ps returned with blank value again, and effective UID has some numbers. Does this make sense?
My o.s is solaris5.7
Maybe it means my cgi is running under user " "? Dont know if/how I can change it. And probably, I cannot, since I dont have root permissions on this server?
Thankyou.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Im just testing, hey
($n,$p, $u,$g, $q,$c,$gc,$dir,$sh)=getpwu id($<);
print "User Name is $n\n");
printed "nobody"
So I have did
chgrp nobody to my file
chmod 775
and then I WAS ABLE TO WRITE TO IT FRM THE WEB!!!
I will test more and let you know.
thanks!
($n,$p, $u,$g, $q,$c,$gc,$dir,$sh)=getpwu
print "User Name is $n\n");
printed "nobody"
So I have did
chgrp nobody to my file
chmod 775
and then I WAS ABLE TO WRITE TO IT FRM THE WEB!!!
I will test more and let you know.
thanks!
Cool.
ASKER
1) First method above works. Thanks, that is so cool.
I set the group of the file to 60001 and permission 775 and I was able to write.
2) I wonder why it shows the owner of cgi as 60001 but when I printed $n from getpwuid, it printed "nobody" And when I did "ps -ef" it printed blank.
Can you suggest me some good reading material on this one?
Thanks much for your help.
3) Re: method 2 above,
" Perhaps we are going about this the wrong way. if you own the file yourself, and say it's UID/GID are 1234 and 5678 (for example), in PERL you could
$> = 1234; # set the Effective UID for this perl script to 1234
So perl gains access to the file by changing it's user id to YOU..
Maybe that works better? "
My file's uid/gid are "web" and "dba" dont know how this translates into numbers.
I tried the following in my script, so perl has access to the file
$> =' web';
$< =' web';
$) = ' dba';
$( = 'dba' ;
but this did not work. I tried without quotes too.
Thanks for your efforts on this.
I set the group of the file to 60001 and permission 775 and I was able to write.
2) I wonder why it shows the owner of cgi as 60001 but when I printed $n from getpwuid, it printed "nobody" And when I did "ps -ef" it printed blank.
Can you suggest me some good reading material on this one?
Thanks much for your help.
3) Re: method 2 above,
" Perhaps we are going about this the wrong way. if you own the file yourself, and say it's UID/GID are 1234 and 5678 (for example), in PERL you could
$> = 1234; # set the Effective UID for this perl script to 1234
So perl gains access to the file by changing it's user id to YOU..
Maybe that works better? "
My file's uid/gid are "web" and "dba" dont know how this translates into numbers.
I tried the following in my script, so perl has access to the file
$> =' web';
$< =' web';
$) = ' dba';
$( = 'dba' ;
but this did not work. I tried without quotes too.
Thanks for your efforts on this.
You weren't supposed to set the owner of the file to the owner of the script. You were supposed to set the owner of the file to the user that the CGI script is running under.
To check what it is, create a simple perl script that displays the userid.
Does this make a difference? Cause if not, I can suggest a few different ways to get around this, but you really shouldn't have to do that. Setting the file to the right ownership should be sufficient.
Dave