예제 #1
0
 def __init__(self, pattern, rangestr, groups):
     self.pattern = pattern
     self.rangestr = rangestr
     self.groups = groups
     try:
         if pattern is not None:
             self._re = re.compile(pattern)
             self.process = self.process_re
         elif rangestr is not None:
             if '\\' in rangestr:
                 raise PatternInitializationError(
                     "Backslashes are not allowed in NameRanges")
             range_finder = r'\[\[[\d\-,]+\]\]'
             self.process = self.process_range
             self._re = re.compile(r'^' + re.sub(range_finder, r'(\d+)',
                                                 rangestr))
             dmatcher = re.compile(re.sub(range_finder,
                                          r'\[\[([\d\-,]+)\]\]',
                                          rangestr))
             self.dranges = [PackedDigitRange(x)
                             for x in dmatcher.match(rangestr).groups()]
         else:
             raise PatternInitializationError("No pattern or range given")
     except re.error:
         raise PatternInitializationError(
             "Could not compile pattern regex: %s" % sys.exc_info()[1])
예제 #2
0
    def test__in_managed_range(self):
        users = self.get_obj()
        users._whitelist = dict(POSIXGroup=PackedDigitRange("1-10"))
        users._blacklist = dict(POSIXGroup=PackedDigitRange("8-100"))
        self.assertTrue(users._in_managed_range("POSIXGroup", "9"))

        users._whitelist = dict(POSIXGroup=None)
        users._blacklist = dict(POSIXGroup=PackedDigitRange("8-100"))
        self.assertFalse(users._in_managed_range("POSIXGroup", "9"))

        users._whitelist = dict(POSIXGroup=None)
        users._blacklist = dict(POSIXGroup=PackedDigitRange("100-"))
        self.assertTrue(users._in_managed_range("POSIXGroup", "9"))

        users._whitelist = dict(POSIXGroup=PackedDigitRange("1-10"))
        users._blacklist = dict(POSIXGroup=None)
        self.assertFalse(users._in_managed_range("POSIXGroup", "25"))
예제 #3
0
 def __init__(self, config):
     Bcfg2.Client.Tools.Tool.__init__(self, config)
     self.set_defaults = dict(POSIXUser=self.populate_user_entry,
                              POSIXGroup=lambda g: g)
     self._existing = None
     self._whitelist = dict(POSIXUser=None, POSIXGroup=None)
     self._blacklist = dict(POSIXUser=None, POSIXGroup=None)
     if self.setup['posix_uid_whitelist']:
         self._whitelist['POSIXUser'] = \
             PackedDigitRange(*self.setup['posix_uid_whitelist'])
     else:
         self._blacklist['POSIXUser'] = \
             PackedDigitRange(*self.setup['posix_uid_blacklist'])
     if self.setup['posix_gid_whitelist']:
         self._whitelist['POSIXGroup'] = \
             PackedDigitRange(*self.setup['posix_gid_whitelist'])
     else:
         self._blacklist['POSIXGroup'] = \
             PackedDigitRange(*self.setup['posix_gid_blacklist'])
예제 #4
0
 def __init__(self, pattern, rangestr, groups):
     self.pattern = pattern
     self.rangestr = rangestr
     self.groups = groups
     if pattern is not None:
         self.re = re.compile(pattern)
         self.process = self.process_re
     elif rangestr is not None:
         if '\\' in rangestr:
             raise Exception("Backslashes are not allowed in NameRanges")
         range_finder = r'\[\[[\d\-,]+\]\]'
         self.process = self.process_range
         self.re = re.compile(r'^' +
                              re.sub(range_finder, r'(\d+)', rangestr))
         dmatcher = re.compile(
             re.sub(range_finder, r'\[\[([\d\-,]+)\]\]', rangestr))
         self.dranges = [
             PackedDigitRange(x) for x in dmatcher.match(rangestr).groups()
         ]
     else:
         raise Exception("No pattern or range given")
예제 #5
0
파일: POSIXUsers.py 프로젝트: xschlef/bcfg2
def uid_range_type(val):
    """ Option type to unpack a list of numerical ranges """
    return PackedDigitRange(*Bcfg2.Options.Types.comma_list(val))