2009-04-22 15:48:07 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
This file is part of the sqlmap project, http://sqlmap.sourceforge.net.
|
|
|
|
|
2010-03-03 18:26:27 +03:00
|
|
|
Copyright (c) 2007-2010 Bernardo Damele A. G. <bernardo.damele@gmail.com>
|
2009-04-22 15:48:07 +04:00
|
|
|
Copyright (c) 2006 Daniele Bellucci <daniele.bellucci@gmail.com>
|
|
|
|
|
|
|
|
sqlmap is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free
|
|
|
|
Software Foundation version 2 of the License.
|
|
|
|
|
|
|
|
sqlmap is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with sqlmap; if not, write to the Free Software Foundation, Inc., 51
|
|
|
|
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
"""
|
|
|
|
|
|
|
|
import errno
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
2009-06-11 19:01:48 +04:00
|
|
|
from lib.core.settings import IS_WIN
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2010-01-02 05:02:12 +03:00
|
|
|
if not IS_WIN:
|
2009-06-11 19:01:48 +04:00
|
|
|
import fcntl
|
|
|
|
|
|
|
|
if (sys.hexversion >> 16) >= 0x202:
|
|
|
|
FCNTL = fcntl
|
|
|
|
else:
|
|
|
|
import FCNTL
|
2009-04-22 15:48:07 +04:00
|
|
|
|
|
|
|
def blockingReadFromFD(fd):
|
|
|
|
# Quick twist around original Twisted function
|
|
|
|
# Blocking read from a non-blocking file descriptor
|
|
|
|
output = ""
|
|
|
|
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
output += os.read(fd, 8192)
|
|
|
|
except (OSError, IOError), ioe:
|
|
|
|
if ioe.args[0] in (errno.EAGAIN, errno.EINTR):
|
|
|
|
# Uncomment the following line if the process seems to
|
|
|
|
# take a huge amount of cpu time
|
|
|
|
# time.sleep(0.01)
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
break
|
|
|
|
|
|
|
|
if not output:
|
|
|
|
raise EOFError, "fd %s has been closed." % fd
|
|
|
|
|
2010-01-02 05:02:12 +03:00
|
|
|
return output
|
2009-04-22 15:48:07 +04:00
|
|
|
|
|
|
|
def blockingWriteToFD(fd, data):
|
|
|
|
# Another quick twist
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
data_length = len(data)
|
|
|
|
wrote_data = os.write(fd, data)
|
|
|
|
except (OSError, IOError), io:
|
|
|
|
if io.errno in (errno.EAGAIN, errno.EINTR):
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
|
|
|
|
if wrote_data < data_length:
|
|
|
|
blockingWriteToFD(fd, data[wrote_data:])
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
def setNonBlocking(fd):
|
|
|
|
"""
|
|
|
|
Make a file descriptor non-blocking
|
|
|
|
"""
|
|
|
|
|
2009-06-11 19:01:48 +04:00
|
|
|
if IS_WIN is not True:
|
|
|
|
flags = fcntl.fcntl(fd, FCNTL.F_GETFL)
|
|
|
|
flags = flags | os.O_NONBLOCK
|
|
|
|
fcntl.fcntl(fd, FCNTL.F_SETFL, flags)
|