Exemplo n.º 1
0
Arquivo: group.py Projeto: net9/ftp9
 def get_node_by_path(self, path):
     """return the corresponding Node for filesystem path ``path``, or None
     on error"""
     path = fs_enc(path)
     while path[-1] == u'/':
         path = path[:-1]
     return self._path2grp.get(path)
Exemplo n.º 2
0
Arquivo: auth.py Projeto: net9/ftp9
    def has_perm(self, username, perm, path=None):
        username = fs_enc(username)
        path = fs_enc(path)
        parts = path.split(u"/")
        if len(parts) > self._root_path_len and parts[self._root_path_len] == config.ROOT_PUB_NAME:
            if username == config.FTP_ADMIN_USERNAME:
                return True
            return self._perm_map[perm] != "modify"

        for i in range(self._root_path_len, len(parts)):
            base = parts[i]
            if base == config.PUBLIC_NAME or base == config.PRIVATE_NAME:
                if username == config.FTP_ADMIN_USERNAME:
                    return True
                base = "public" if base == config.PUBLIC_NAME else "private"
                g = self._group_info.get_node_by_path(u"/".join(parts[:i]))
                if not g:
                    return False
                return username in getattr(g, base + "_" + self._perm_map[perm])

        return perm in ["e", "l"]
Exemplo n.º 3
0
Arquivo: group.py Projeto: net9/ftp9
    def _update_fs(self):
        pjoin = os.path.join
        path2grp = dict()

        def get_grpname(fname):
            t = fname.split('-', 1)
            if len(t) == 1:
                return None
            return t[1]

        def walk(node, rootdir):
            path2grp[rootdir] = node

            create_list = set([i.name for i in node.children])
            if node is self._root:
                create_list.add(config.ROOT_PUB_NAME)
            else:
                create_list.add(config.PUBLIC_NAME)
                create_list.add(config.PRIVATE_NAME)

            remove_list = set()
            if os.path.isdir(rootdir):
                for i in os.listdir(rootdir):
                    if os.path.isdir(pjoin(rootdir, i)):
                        remove_list.add(fs_enc(i))

            intersect = create_list & remove_list
            create_list -= intersect
            remove_list -= intersect

            for i in create_list:
                os.makedirs(pjoin(rootdir, i))

            for i in remove_list:
                p0 = pjoin(rootdir, i)
                if config.FTP_DISCARDEDGRP_SAVEDIR:
                    tgt_dir = pjoin(
                            config.FTP_DISCARDEDGRP_SAVEDIR,
                            self._timestamp,
                            relpath(rootdir))
                    if not os.path.isdir(tgt_dir):
                        os.makedirs(tgt_dir)
                    shutil.move(p0, tgt_dir)
                else:
                    shutil.rmtree(p0)

            for i in node.children:
                walk(i, pjoin(rootdir, i.name))
        
        walk(self._root, config.FTP_ROOT)

        self._path2grp = {fs_enc(k): v for k, v in path2grp.iteritems()}
Exemplo n.º 4
0
Arquivo: group.py Projeto: net9/ftp9
        def walk(node, rootdir):
            path2grp[rootdir] = node

            create_list = set([i.name for i in node.children])
            if node is self._root:
                create_list.add(config.ROOT_PUB_NAME)
            else:
                create_list.add(config.PUBLIC_NAME)
                create_list.add(config.PRIVATE_NAME)

            remove_list = set()
            if os.path.isdir(rootdir):
                for i in os.listdir(rootdir):
                    if os.path.isdir(pjoin(rootdir, i)):
                        remove_list.add(fs_enc(i))

            intersect = create_list & remove_list
            create_list -= intersect
            remove_list -= intersect

            for i in create_list:
                os.makedirs(pjoin(rootdir, i))

            for i in remove_list:
                p0 = pjoin(rootdir, i)
                if config.FTP_DISCARDEDGRP_SAVEDIR:
                    tgt_dir = pjoin(
                            config.FTP_DISCARDEDGRP_SAVEDIR,
                            self._timestamp,
                            relpath(rootdir))
                    if not os.path.isdir(tgt_dir):
                        os.makedirs(tgt_dir)
                    shutil.move(p0, tgt_dir)
                else:
                    shutil.rmtree(p0)

            for i in node.children:
                walk(i, pjoin(rootdir, i.name))