473,748 Members | 8,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

os.execve(pth,a rgs,env) and os.chroot(pth) = problems

Hello fellow python users,

I've been working on a basic implementation of a privilege separated
web server, and I've goto the point of running a basic cgi script.
Basically when the execCGI function in my Unpriv.py program is called a
few things should happen, it should fork (which it does), the stdout of
the child should be redirected to a given pipe (which it does), and the
script should execute using execve(which is has problems with). Also
before the execCGI() fucntion is executed, a few important things
happen in __init__: os.chroot('/var/www/webroot/') the path is web
server root and os.setuid(33) where 33 is the uid of a user on my
machine. It seems me that the os.chroot() call is messing up the
os.execve() (which executes the cgi script). os.execve(pth, args,
envVariables) is only executed if os.path.exists( pth) returns True.
But when I run a CGI script that os.path.exists( pth) returns True for,
then os.execve(pth) python throws back the error:

File "/***/***/***/Unpriv.py", line 201, in execCGI
OSError: [Errno 2] No such file or directory

However I don't see how this is possible if os.path.exists( pth) returns
True, why is it os.execve() has problems finding it.

I thought it might be a user permission problem, but I've run it
without the chroot and with the setuid and it works fine. So I'm
pretty sure its something to do with the chroot conflicting with the
os.execve(). Also execution privileges for the script file are also
checked before execution.
Any insight would be greatly appreciated
Here are the relevant functions of Unpriv.py
class Unpriv(object):

def __init__(self):
pipes = sys.argv
self.fromParent , self.toParent = os.pipe()
# this is just how http requested are recieved from a privilege
part and sent back
os.dup2(int(pip es[2]), self. toParent) ##write
os.dup2(int(pip es[1]), self.fromParent ) ##read

os.chroot('/var/www/webroot/') ##chrooting
os.setuid(33) ##setuid
def checkFileExists (self, pth): ## just calls os.path.exists( )
return os.path.exists( pth)
def execCGI(self, pth):
##
x = pth.rfind('?')
if x > -1:
path = pth[:x]
query = pth[x+1:]
query = query.replace(' +', ' ')
else:
path = pth
query = ''

##populate enviroment variables, not yet implemented
envVariables = {}

readEnd, writeEnd = os.pipe()
parentStout = sys.stdout.file no()
args = ['']
args.append(que ry)

pid = os.fork()

if pid == 0:
##child

os.dup2(writeEn d, sys.stdout.file no()) ##this works

## this is the problem!
if self.checkFileE xists(pth):
os.execve(pth , args, envVariables)
else:
## just some debug info for me.
## in fact part of pth is there
##however for some reason execve doesn't see
print 'the directory listing is:',
os.listdir(os.g etcwd())

os._exit(0)

else: #parent
#read the output from the script
scriptOutPut = os.read(readEnd , 100000)
#just some debug info for me
print 'OUTPUT FROM SCRIPT EXECUTION: ' , scriptOutPut
return scriptOutPut

Please excuse any problems with the formatting.
Thanks in advance.

Mar 7 '06 #1
2 5389
In article <11************ *********@j52g2 000cwj.googlegr oups.com>,
"go************ ***@gmail.com" <go************ ***@gmail.com> wrote:
... It seems me that the os.chroot() call is messing up the
os.execve() (which executes the cgi script). os.execve(pth, args,
envVariables) is only executed if os.path.exists( pth) returns True.
But when I run a CGI script that os.path.exists( pth) returns True for,
then os.execve(pth) python throws back the error:

File "/***/***/***/Unpriv.py", line 201, in execCGI
OSError: [Errno 2] No such file or directory

However I don't see how this is possible if os.path.exists( pth) returns
True, why is it os.execve() has problems finding it.


I haven't used chroot enough to know all the pitfalls, but
here's one guess: suppose the CGI script file `pth' might
actually be a script, with a `#!' top line that points to
an interpreter that isn't there, in your chroot space?

Donn Cave, do**@u.washingt on.edu
Mar 7 '06 #2
Thanks for the reply Donn,
It seems logical enough to me that finding #!/usr/bin/env python in the
script file with the chroot I have used, is the problem. Once again
thank you for the help.

Regards,
Gavin

Mar 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2569
by: glmlima | last post by:
I need to implement a prompt of commands (mere academic project). The function presents errors in the call execve, as parameter. It follows the code below. I´m using gcc... thanks. #include "stdio.h" #include "unistd.h" #include "sys/types.h" void type_prompt(); //shows the prompt
1
4192
by: yogamatt1970 | last post by:
I have some code which runs on a number of different machines, however I see problems on one particular Solaris box. When I call Popen.wait(), the following exception is raised: .. . . File "/basis/users/matt/Python-2.4.4/Lib/subprocess.py", line 558, in __init__ errread, errwrite) File "/basis/users/matt/Python-2.4.4/Lib/subprocess.py", line 992, in _execute_child
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.