예제 #1
0
파일: fd.py 프로젝트: xch89820/owasp-pysec
def clear_all_opened_fds(exclude = None):
    """Close all open file descriptors in current process by violence way

    This function will try to close file descriptors from 0 to maximum value in current process whatever available or not
    """
    maxfd = FD.get_maximum_value()
    for fd in xrange(0, maxfd):
        if exclude is None or fd not in exclude:
            unistd.close(fd)
예제 #2
0
 def open(domain=socket.AF_INET, type=socket.SOCK_STREAM, protocol=0):
     fd = -1
     try:
         fd = socket.socket(domain, type, protocol)
         fd = Socket(fd)
     except:
         if fd > -1:
             unistd.close(fd)
         raise
     return fd
예제 #3
0
 def open(domain=socket.AF_INET, type=socket.SOCK_STREAM, protocol=0):
     fd = -1
     try:
         fd = socket.socket(domain, type, protocol)
         fd = Socket(fd)
     except:
         if fd > -1:
             unistd.close(fd)
         raise
     return fd
예제 #4
0
 def dirat(self, create=0, mode=0755):
     fd = -1
     try:
         fd = fcntl.openat(int(self), fcntl.O_DIRECTORY|fcntl.O_CREAT if create else 0, mode)
         fd = Directory(fd)
     except:
         if fd > -1:
             unistd.close(fd)
         raise
     return fd
예제 #5
0
 def dirat(self, create=0, mode=0755):
     fd = -1
     try:
         fd = fcntl.openat(
             int(self), fcntl.O_DIRECTORY | fcntl.O_CREAT if create else 0,
             mode)
         fd = Directory(fd)
     except:
         if fd > -1:
             unistd.close(fd)
         raise
     return fd
예제 #6
0
 def touch(fpath, mode=0666):
     """Create a new file with passed *mode* in *fpath*.
     If file *fpath* exists, a IOError will be raised."""
     mode = int(mode)
     if not fcheck.mode_check(mode):
         raise ValueError("wrong mode: %r" % oct(mode))
     fd = -1
     try:
         fd = fcntl.open(fpath, fcntl.O_RDONLY | fcntl.O_CREAT, mode)
     finally:
         if fd >= 0:
             unistd.close(fd)
예제 #7
0
 def touch(fpath, mode=0666):
     """Create a new file with passed *mode* in *fpath*.
     If file *fpath* exists, a IOError will be raised."""
     mode = int(mode)
     if not fcheck.mode_check(mode):
         raise ValueError("wrong mode: %r" % oct(mode))
     fd = -1
     try:
         fd = fcntl.open(fpath, fcntl.O_RDONLY | fcntl.O_CREAT, mode)
     finally:
         if fd >= 0:
             unistd.close(fd)
예제 #8
0
 def open(fpath, oflags, mode=0666):
     """Open a file descript for a regular file in fpath using the open mode
     specifie by *oflag* with *mode*"""
     _oflags = FOFLAGS2OFLAGS.get(int(oflags), None)
     if oflags is None:
         raise ValueError("unknown file open mode: %r" % oflags)
     mode = int(mode)
     if not fcheck.mode_check(mode):
         raise ValueError("wrong mode: %r" % oct(mode))
     fd = -1
     try:
         fd = fcntl.open(fpath, _oflags, mode) if oflags in _FO_NEW_FLAGS \
              else fcntl.open(fpath, _oflags)
         if oflags in _FO_NEW_FLAGS and not fcheck.ino_check(int(fd)):
             raise OSError("not enough free inodes")
         fd = File(fd)
     except:
         if fd > -1:
             unistd.close(fd)
         raise
     return fd
예제 #9
0
 def open(fpath, oflags, mode=0666):
     """Open a file descript for a regular file in fpath using the open mode
     specifie by *oflag* with *mode*"""
     _oflags = FOFLAGS2OFLAGS.get(int(oflags), None)
     if oflags is None:
         raise ValueError("unknown file open mode: %r" % oflags)
     mode = int(mode)
     if not fcheck.mode_check(mode):
         raise ValueError("wrong mode: %r" % oct(mode))
     fd = -1
     try:
         fd = fcntl.open(fpath, _oflags, mode) if oflags in _FO_NEW_FLAGS \
              else fcntl.open(fpath, _oflags)
         if oflags in _FO_NEW_FLAGS and not fcheck.ino_check(int(fd)):
             raise OSError("not enough free inodes")
         fd = File(fd)
     except:
         if fd > -1:
             unistd.close(fd)
         raise
     return fd
예제 #10
0
 def close(self):
     """Closes file descriptor"""
     unistd.close(self.fd)
예제 #11
0
 def close(self):
     """Closes file descriptor"""
     unistd.close(self.fd)