Esempio n. 1
0
    def _locToFilePath(self, path):
        """Convert resource path to a unicode absolute file path."""
        assert self.rootFolderPath is not None
        pathInfoParts = path.strip("/").split("/")
        
        r = os.path.abspath(os.path.join(self.rootFolderPath, *pathInfoParts))
        if not r.startswith(self.rootFolderPath):
            raise RuntimeError("Security exception: tried to access file outside root.")
        r = util.toUnicode(r)
#        print "_locToFilePath(%s): %s" % (path, r)
        return r  
Esempio n. 2
0
    def _locToFilePath(self, path):
        """Convert resource path to a unicode absolute file path."""
        assert self.rootFolderPath is not None
        pathInfoParts = path.strip("/").split("/")

        r = os.path.abspath(os.path.join(self.rootFolderPath, *pathInfoParts))
        if not r.startswith(self.rootFolderPath):
            raise RuntimeError("Security exception: tried to access file outside root.")
        r = util.toUnicode(r)
#        print "_locToFilePath(%s): %s" % (path, r)
        return r
Esempio n. 3
0
def quoteEntity(entity_name):
    '''
    This function purposefully double encodes forward slashes '/'.
    This is because many applications that handle http requests assume a %2F 
    encoding of a forward slash actually represents a forward slash. Hence,
    splunkd should always receive double encoded forward slashes when they
    are to appear in entity names.

    e.g. "foo/bar" should be "foo%252Fbar".

    Do not erase this or the unquoteEntity method.
    '''
    return util.safeURLQuote(util.toUnicode(entity_name).replace('/', '%2F'))
def quoteEntity(entity_name):
    '''
    This function purposefully double encodes forward slashes '/'.
    This is because many applications that handle http requests assume a %2F 
    encoding of a forward slash actually represents a forward slash. Hence,
    splunkd should always receive double encoded forward slashes when they
    are to appear in entity names.

    e.g. "foo/bar" should be "foo%252Fbar".

    Do not erase this or the unquoteEntity method.
    '''
    return util.safeURLQuote(util.toUnicode(entity_name).replace('/', '%2F'))
Esempio n. 5
0
    def _locToFilePath(self, path, environ=None):
        """Convert resource path to a unicode absolute file path.
        Optional environ argument may be useful e.g. in relation to per-user
        sub-folder chrooting inside rootFolderPath.
        """
        assert self.rootFolderPath is not None
        pathInfoParts = path.strip("/").split("/")

        r = os.path.abspath(os.path.join(self.rootFolderPath, *pathInfoParts))
        if not r.startswith(self.rootFolderPath):
            raise RuntimeError(
                "Security exception: tried to access file outside root.")
        r = util.toUnicode(r)
        #        print "_locToFilePath(%s, %s): %s" % (path, environ, r)
        return r
Esempio n. 6
0
    def _locToFilePath(self, path):
        """Convert resource path to a unicode absolute file path."""
        assert self.rootFolderPath is not None
        pathInfoParts = path.strip("/").split("/")

        # r = os.path.abspath(os.path.join(self.rootFolderPath, *pathInfoParts))
        try:
            rp = self.rootFolderPath.decode('utf8')
        except:
            try:
                rp = self.rootFolderPath.decode('mbcs')
            except:
                rp = self.rootFolderPath.decode('shiftjis')
        # rpath = os.path.join(self.rootFolderPath, *pathInfoParts)
        try:
            pip = [x.decode('utf8') for x in pathInfoParts]
        except:
            try:
                pip = [x.decode('mbcs') for x in pathInfoParts]
            except:
                pip = [x.decode('shiftjis') for x in pathInfoParts]

        #print(repr(rp), repr(pip))
        # rpath = os.path.join(rp, *pathInfoParts)
        rpath = os.path.join(rp, *pip)

        try:
            r = os.path.abspath(rpath.decode('utf8'))
        except:
            try:
                r = os.path.abspath(rpath.decode('mbcs'))
            except:
                r = os.path.abspath(rpath.decode('shiftjis'))
        # if not r.startswith(self.rootFolderPath):
        if not r.startswith(rp):
            raise RuntimeError(
                "Security exception: tried to access file outside root.")
        r = util.toUnicode(r)
        #        print "_locToFilePath(%s): %s" % (path, r)
        return r