Example #1
0
    def mod_dir_owner(self, relative_path, user = None, group = None, operator="unknown"):
        if not self.is_available():
            raise StorLeverError("File system is unavailable", 500)
        if "." in relative_path or ".." in relative_path:
            raise StorLeverError("name cannot include . or ..", 400)
        if relative_path.startswith("/"):
            raise StorLeverError("name must be a relative path name", 400)

        path = os.path.join(self.fs_conf["mount_point"], relative_path)
        if not os.path.exists(path):
            raise StorLeverError("Share directory not found", 404)
        umgr = user_mgr()
        if user is None:
            uid = -1
        else:
            uid = umgr.get_user_info_by_name(user)["uid"]
        if group is None:
            gid = -1
        else:
            gid = umgr.get_group_by_name(group)["gid"]
        os.chown(path, uid, gid)

        logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
                   "Share directory (%s) owner is changed to (%s:%s)"
                   " by user(%s)" %
                   (path, user, group, operator))
Example #2
0
    def _get_uid_map(self):
        umgr = user_mgr();
        ulist = umgr.user_list()
        uid_map = {}
        for user in ulist:
            uid_map[user["uid"]] = user

        return uid_map
Example #3
0
    def _get_gid_map(self):
        umgr = user_mgr()
        glist = umgr.group_list()
        gid_map = {}
        for group in glist:
            gid_map[group["gid"]] = group

        return gid_map
Example #4
0
    def test_group_list(self):
        manager = user_mgr()
        group_list = manager.group_list()
        self.assertEquals("root", group_list[0]["name"])
        self.assertEquals(0, group_list[0]["gid"])

        root_group = manager.get_group_by_name("root")
        self.assertEquals("root", root_group["name"])
        self.assertEquals(0, root_group["gid"])
Example #5
0
 def test_user_add_del(self):
     manager = user_mgr()
     manager.user_add("storlever_test", groups="root", home_dir="/home")
     user = manager.get_user_info_by_name("storlever_test")
     self.assertEquals("storlever_test", user["name"])
     self.assertEquals("root", user["groups"])
     manager.user_mod("storlever_test", groups="")
     user = manager.get_user_info_by_name("storlever_test")
     self.assertEquals("", user["groups"])
     manager.user_del_by_name("storlever_test")
Example #6
0
def add_group(request):
    group_info = get_params_from_request(request, group_info_schema)
    user_mgr = usermgr.user_mgr()
    user_mgr.group_add(group_info["name"], group_info.get("gid"),
                       user=request.client_addr)

    # generate 201 response
    resp = Response(status=201)
    resp.location = request.route_url('group_info', group_name=group_info["name"])
    return resp
Example #7
0
def mod_user_info(request):
    user_name = request.matchdict["user_name"]
    user_info = get_params_from_request(request)
    user_info["name"] = user_name
    user_info = user_info_schema.validate(user_info)
    user_mgr = usermgr.user_mgr()
    user_mgr.user_mod(user_info["name"], user_info.get("password"), user_info.get("uid"),
                      user_info.get("primary_group"), user_info.get("groups"),
                      user_info.get("home_dir"), user_info.get("login"),
                      user_info.get("comment"), user=request.client_addr)
    return Response(status=200)
Example #8
0
    def test_user_list(self):
        manager = user_mgr()
        user_list = manager.user_list()
        self.assertEquals("root", user_list[0]["name"])
        self.assertEquals("root", user_list[0]["primary_group"])
        self.assertEquals(0, user_list[0]["uid"])

        root_user = manager.get_user_info_by_name("root")
        self.assertEquals("root", root_user["name"])
        self.assertEquals("root", root_user["primary_group"])
        self.assertEquals(0, root_user["uid"])
Example #9
0
    def set_ftp_conf(self, config={}, operator="unkown", **kwargs):
        if not isinstance(config, dict):
            raise StorLeverError("Parameter type error", 500)
        if len(config) == 0 and len(kwargs) == 0:
            return
        config.update(kwargs)
        not_allowed_keys = (
            "user_list",
        )
        config = filter_dict(config, not_allowed_keys, True)


        with self.lock:
            ftp_conf = self._load_conf()
            for name, value in config.items():
                if name in ftp_conf and value is not None:
                    ftp_conf[name] = value

            # check config conflict
            ftp_conf = self.ftp_conf_schema.validate(ftp_conf)

            if ftp_conf["listen"] and ftp_conf["listen6"]:
                raise StorLeverError("listen and listen6 cannot both be true", 400)
            if ftp_conf["local_root"] != "" and \
                    (not os.path.exists(ftp_conf["local_root"])):
                 raise StorLeverError("local_root does not exist", 400)
            if ftp_conf["anon_root"] != "" and \
                    (not os.path.exists(ftp_conf["anon_root"])):
                 raise StorLeverError("anon_root does not exist", 400)
            try:
                user_mgr().get_user_info_by_name(ftp_conf["anon_username"])
            except Exception as e:
                raise StorLeverError("anon_username does not exist", 400)

            # save new conf
            self._save_conf(ftp_conf)
            self._sync_to_system_conf(ftp_conf)

        logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
                   "FTP config is updated by user(%s)" %
                   (operator))
Example #10
0
def add_user(request):
    user_info = get_params_from_request(request, user_info_schema)
    user_mgr = usermgr.user_mgr()
    user_mgr.user_add(user_info["name"], user_info.get("password"), user_info.get("uid"),
                      user_info.get("primary_group"), user_info.get("groups"),
                      user_info.get("home_dir"), user_info.get("login"),
                      user_info.get("comment"), user=request.client_addr)

    # generate 201 response
    resp = Response(status=201)
    resp.location = request.route_url('user_info', user_name=user_info["name"])
    return resp
Example #11
0
    def add_user_conf(self, user_name, login_enable=False, chroot_enable=False, operator="unkown"):
        with self.lock:
            ftp_conf = self._load_conf()
            if user_name in ftp_conf["user_list"]:
                 raise StorLeverError("user_name(%s) already exists" % (user_name), 400)
            try:
                user_mgr().get_user_info_by_name(user_name)
            except Exception as e:
                raise StorLeverError("user (%s) not found in system" % (user_name), 400)

            user_conf ={
                "user_name": user_name,
                "login_enable": login_enable,
                "chroot_enable": chroot_enable
            }
            ftp_conf["user_list"][user_name] = user_conf

            # save new conf
            self._save_conf(ftp_conf)
            self._sync_to_system_conf(ftp_conf)

        logger.log(logging.INFO, logger.LOG_TYPE_CONFIG,
                   "ftp user (%s) config is added by operator(%s)" %
                   (user_name, operator))
Example #12
0
 def test_group_add_del(self):
     manager = user_mgr()
     manager.group_add("storlever_test")
     group = manager.get_group_by_name("storlever_test")
     self.assertEquals("storlever_test", group["name"])
     manager.group_del_by_name("storlever_test")
Example #13
0
def get_user_info(request):
    user_name = request.matchdict["user_name"]
    user_mgr = usermgr.user_mgr()      # get user manager
    return user_mgr.get_user_info_by_name(user_name)
Example #14
0
    def grow_size(self):
        pass

    #
    # share related
    #

    def create_dir(self, relative_path, user=None, group=None, mode=0777, operator="unknown"):
        # make sure fs is available
        if not self.is_available():
            raise StorLeverError("File system is unavailable", 500)
        if "." in relative_path or ".." in relative_path:
            raise StorLeverError("name cannot include . or ..", 400)
        if relative_path.startswith("/"):
            raise StorLeverError("name must be a relative path name", 400)
        umgr = user_mgr()
        if user is None:
            uid = -1
        else:
            uid = umgr.get_user_info_by_name(user)["uid"]
        if group is None:
            gid = -1
        else:
            gid = umgr.get_group_by_name(group)["gid"]

        mount_point = self.fs_conf["mount_point"]
        path = os.path.join(mount_point, relative_path)
        os.umask(0)
        os.makedirs(path, mode)
        os.chown(path, uid, gid)
Example #15
0
def del_group(request):
    group_name = request.matchdict["group_name"]
    user_mgr = usermgr.user_mgr()      # get user manager
    user_mgr.group_del_by_name(group_name, user=request.client_addr)
    return Response(status=200)
Example #16
0
def get_group_info(request):
    group_name = request.matchdict["group_name"]
    user_mgr = usermgr.user_mgr()      # get user manager
    return user_mgr.get_group_by_name(group_name)
Example #17
0
def del_user(request):
    user_name = request.matchdict["user_name"]
    user_mgr = usermgr.user_mgr()      # get user manager
    user_mgr.user_del_by_name(user_name, user=request.client_addr)
    return Response(status=200)
Example #18
0
def get_group_list(request):
    user_mgr = usermgr.user_mgr()      # get user manager
    return user_mgr.group_list()