Пример #1
0
 def set_permissions(self, new_permissions, directory=None):
     if directory:
         self.path = directory
         
         if not self.path_is_valid():
             return None
     
     ftp_permissions = FtpPermissions(new_permissions)
     db_permissions = ftp_permissions.permissions
     
     # Getting the account permissions
     # In order to do that we've got to find out the parent directory of the
     # given path
     if self.homedir:
         #print "Home directory: %s" % self.homedir
         account_permissions = ftp_permissions.account_permissions(self.homedir)
         
         # Dissecting the user and group permission part from the bunch
         db_permissions = ftp_permissions.dissect(account_permissions)
         #print "Dissected permissions: %s" % db_permissions
     
     # Translating the humanized permission dictionary into proftpd-friendly
     # representation
     #if self.config_path in ftp_db:
     #    db_permissions.update({"_rev": ftp_db[self.config_path].rev})
     
     FTP_DB[self.config_path] = db_permissions
     FTP_DB.save()
Пример #2
0
 def update(self, groups, users):
     ftp_permissions = FtpPermissions().account_permissions()
     #directories = list(ftp_permissions.keys())
     
     # Fetching DB FTP permissions
     for dir in FTP_DB:
         if dir in ftp_permissions:
             ftp_permissions[dir] = FtpPermissions(ftp_permissions[dir]).merge(db_permissions=FTP_DB[dir])
         else:
             ftp_permissions[dir] = FtpPermissions(FTP_DB[dir]).permissions
             #directories.append(dir)
     
     # Sorting directories. More specific ones go last.
     directories = sorted(ftp_permissions.keys(), self.__order_directory)
     
     logger.debug("User privlileges: %s" % ftp_permissions)
     logger.debug("Account privileges: %s" % account_permissions)
     
     # Applying changes to the config
     for dir in directories:
         ftp_perm = FtpPermissions(ftp_permissions[dir])
         conf_permissions = ftp_perm.to_config()
         dir = dir.replace(" ", "\ ")
         if not dir in self.config["<Directory>"]:
             self.config["<Directory>"][dir] = S()
         
         self.config["<Directory>"][dir]["<Limit>"] = S()
         for type in ("ALL", "DIRS", "READ", "WRITE"):
             if type in conf_permissions:
                 self.config["<Directory>"][dir]["<Limit>"][type] = conf_permissions[type]
Пример #3
0
 def permissions(self, directory=None):
     if directory:
         self.path = directory
         
         if not self.path_is_valid():
             return None
     
     # Initializing FtpPermissions object
     permissions = FtpPermissions()
     
     # Check for "DenyAll", "DenyUser", "DenyGroup", "AllowAll", "AllowUser"
     # and "AllowGroup" statements for the given path
     exact_dir_perm = None
     for ftp_dir in self.ftp_dir_generator(self.path):
         if not "<Limit>" in self.access[ftp_dir]:
             continue
         
         permissions.merge(self.access[ftp_dir]["<Limit>"])
     
     if exact_dir_perm:
         permissions.merge(exact_dir_perm)
     
     # Adding the permissions of the directory's owner (identified by "~")
     owner = self.owner(self.path)
     if owner:
         for home_dir in self.ftp_home_dirs(self.path):
             if not "<Limit>" in self.access[ftp_dir]:
                 continue
             
             permissions.owner_permissions(owner, self.access[ftp_dir]["<Limit>"])
     
     return permissions.permissions
Пример #4
0
 def test_to_db(self):
     input = (
         {'ALL': {'Order': ['Allow,Deny'], 'DenyAll': []}, 'READ': {'AllowUser': ['arnike', 'root'], 'AllowGroup': ['users']}, 'DIRS': {'AllowUser': ['arnike', 'root'], 'AllowGroup': ['users']}, 'WRITE': {'AllowUser': ['root']}},
         {'ALL': {'DenyAll': []}, 'DIRS': {'AllowUser': ['root']}, 'READ': {'AllowUser': ['root']}, 'WRITE': {'AllowUser': ['root']}},
         {'ALL': {'AllowAll': []}},
         {'ALL': {'Order': ['Allow,Deny'], 'DenyUser': ['user_1']}, 'DIRS': {'AllowGroup': ['users'], 'AllowUser': ['arnike', 'root']}, 'READ': {'AllowGroup': ['users'], 'AllowUser': ['arnike', 'root']}, 'WRITE': {'AllowUser': ['root']}}
     )
     
     output = (
         {"all": {"": "none"}, "user": {"arnike": "read", "root": "write"}, "group": {"users": "read"}},
         {'all': {'': 'none'}, 'group': {}, 'user': {'root': 'write'}},
         {"all": {"": "write"}, 'group': {}, 'user': {}},
         {'all': {}, "user": {"arnike": "read", "root": "write", "user_1": "none"}, "group": {"users": "read"}},
     )
     
     for i in xrange(len(input)):
         perm_obj = FtpPermissions()
         db = dict(perm_obj.to_db(input[i]))
         self.assertTrue(db == output[i])
Пример #5
0
 def test_to_config(self):
     input = (
         {"all": {"": "none"}, "user": {"arnike": "read", "root": "write", "user_1": "none"}, "group": {"users": "read"}},
         {"all": {"": "read"}, "user": {"arnike": "read", "root": "write", "user_1": "none"}, "group": {"users": "read"}},
         {"all": {"": "write"}, "user": {"arnike": "read", "root": "write", "user_1": "none"}, "group": {"users": "read"}},
         {"user": {"arnike": "read", "root": "write", "user_1": "none"}, "group": {"users": "read"}},
     )
     
     output = (
         {'DIRS': {'AllowGroup': ['users'], 'AllowUser': ['arnike', 'root'], 'DenyUser': ['user_1']}, 'READ': {'AllowGroup': ['users'], 'AllowUser': ['arnike', 'root'], 'DenyUser': ['user_1']}, 'ALL': {'DenyAll': []}, 'WRITE': {'DenyGroup': ['users'], 'DenyUser': ['arnike', 'user_1'], 'AllowUser': ['root']}},
         {'DIRS': {'Order': ['deny,allow'], 'AllowAll': [], 'AllowUser': ['arnike', 'root'], 'DenyUser': ['user_1']}, 'READ': {'Order': ['deny,allow'], 'AllowAll': [], 'AllowUser': ['arnike', 'root'], 'DenyUser': ['user_1']}, 'WRITE': {'DenyAll': [], 'Order': ['allow,deny'], 'DenyUser': ['arnike', 'user_1'], 'AllowUser': ['root']}},
         {'DIRS': {'Order': ['deny,allow'], 'AllowAll': [], 'AllowGroup': ['users'], 'AllowUser': ['arnike', 'root'], 'DenyUser': ['user_1']}, 'READ': {'Order': ['deny,allow'], 'AllowAll': [], 'AllowGroup': ['users'], 'AllowUser': ['arnike', 'root'], 'DenyUser': ['user_1']}, 'WRITE': {'Order': ['deny,allow'], 'AllowAll': [], 'DenyGroup': ['users'], 'DenyUser': ['arnike', 'user_1'], 'AllowUser': ['root']}},
         {'DIRS': {'AllowGroup': ['users'], 'AllowUser': ['arnike', 'root'], 'DenyUser': ['user_1']}, 'READ': {'AllowGroup': ['users'], 'AllowUser': ['arnike', 'root'], 'DenyUser': ['user_1']}, 'WRITE': {'DenyGroup': ['users'], 'DenyUser': ['arnike', 'user_1'], 'AllowUser': ['root']}}
     )
     
     for i in xrange(len(input)):
         perm_obj = FtpPermissions()
         config = dict(perm_obj.to_config(input[i]))
         self.assertTrue(config == output[i])