コード例 #1
0
ファイル: accessmap.py プロジェクト: pombr/conary
    def _filterItems(self, cu, sql, permissionId=None):
        """
        Apply regexp permission checks, returning a SQL clause that filters a
        join between instances and permissions.

        The supplied query string should select relevant rows from the
        instances table.
        """
        cu.execute("SELECT DISTINCT itemId, item FROM Items"
                " JOIN Permissions USING ( itemId )"
                + self.getWhereArgs("WHERE", permissionId=permissionId))
        patterns = dict(cu)

        # The supplied query yields items that need to be checked against
        # patterns.
        cu.execute(sql)
        where = set()
        for itemId, item in cu:
            for patternId, pattern in patterns.iteritems():
                if pattern == 'ALL':
                    # This is by far the most common case, so instead of
                    # enumerating every trove with its own filter, just select
                    # on whether the ALL permission is applicable.
                    where.add('p.itemId = %d' % patternId)
                elif items.checkTrove(pattern, item):
                    where.add("(p.itemId = %d AND i.itemId = %d)"
                            % (patternId, itemId))
        if where:
            return "( %s )" % (" OR ".join(where))
        else:
            return None
コード例 #2
0
    def _filterItems(self, cu, sql, permissionId=None):
        """
        Apply regexp permission checks, returning a SQL clause that filters a
        join between instances and permissions.

        The supplied query string should select relevant rows from the
        instances table.
        """
        cu.execute("SELECT DISTINCT itemId, item FROM Items"
                   " JOIN Permissions USING ( itemId )" +
                   self.getWhereArgs("WHERE", permissionId=permissionId))
        patterns = dict(cu)

        # The supplied query yields items that need to be checked against
        # patterns.
        cu.execute(sql)
        where = set()
        for itemId, item in cu:
            for patternId, pattern in patterns.iteritems():
                if pattern == 'ALL':
                    # This is by far the most common case, so instead of
                    # enumerating every trove with its own filter, just select
                    # on whether the ALL permission is applicable.
                    where.add('p.itemId = %d' % patternId)
                elif items.checkTrove(pattern, item):
                    where.add("(p.itemId = %d AND i.itemId = %d)" %
                              (patternId, itemId))
        if where:
            return "( %s )" % (" OR ".join(where))
        else:
            return None
コード例 #3
0
ファイル: checkrepo.py プロジェクト: fedora-conary/conary
 def check(self):
     db = self.getDB()
     log.info("checking the state of the CheckTroveCache table")
     cu = db.cursor()
     cu.execute("select patternId, itemId from CheckTroveCache")
     existing = set([(x[0],x[1]) for x in cu.fetchall()])
     required = []
     cu.execute("select distinct i.itemId, i.item from Permissions as p "
                "join Items as i using(itemId)")
     patterns = set([(x[0], x[1]) for x in cu.fetchall()])
     cu.execute("select itemId, item from Items")
     troveNames = set([(x[0], x[1]) for x in cu.fetchall()])
     for patternId, pattern in patterns:
         for itemId, item in troveNames:
             if items.checkTrove(pattern, item):
                 required.append((patternId, itemId))
     required = set(required)
     self._status = required.difference(existing)
     if len(self._status):
         log.warning("found %d entries that are missing from CheckTroveCache", len(self._status))
         return False
     return True
コード例 #4
0
ファイル: migrate.py プロジェクト: fedora-conary/conary
def createCheckTroveCache(db):
    db.loadSchema()
    assert("CheckTroveCache" in db.tables)
    cu = db.cursor()
    cu.execute("delete from CheckTroveCache")
    # grab all possible patterns
    cu.execute("select distinct i.itemId, i.item "
               "from Permissions join Items as i using(itemId)")
    patterns = set([(x[0],x[1]) for x in cu.fetchall()])
    patterns.add((0, "ALL"))
    # grab all items
    cu.execute("select itemId, item from Items")
    items = cu.fetchall()
    from conary.repository.netrepos.items import checkTrove
    for (patternId, pattern) in patterns:
        for (itemId, troveName) in items:
            if not checkTrove(pattern, troveName):
                continue
            cu.execute("insert into CheckTroveCache (patternId, itemId) values (?,?)",
                    (patternId, itemId))
    db.analyze("CheckTroveCache")
    return True
コード例 #5
0
def createCheckTroveCache(db):
    db.loadSchema()
    assert ("CheckTroveCache" in db.tables)
    cu = db.cursor()
    cu.execute("delete from CheckTroveCache")
    # grab all possible patterns
    cu.execute("select distinct i.itemId, i.item "
               "from Permissions join Items as i using(itemId)")
    patterns = set([(x[0], x[1]) for x in cu.fetchall()])
    patterns.add((0, "ALL"))
    # grab all items
    cu.execute("select itemId, item from Items")
    items = cu.fetchall()
    from conary.repository.netrepos.items import checkTrove
    for (patternId, pattern) in patterns:
        for (itemId, troveName) in items:
            if not checkTrove(pattern, troveName):
                continue
            cu.execute(
                "insert into CheckTroveCache (patternId, itemId) values (?,?)",
                (patternId, itemId))
    db.analyze("CheckTroveCache")
    return True
コード例 #6
0
ファイル: checkrepo.py プロジェクト: pombreda/conary-1
 def check(self):
     db = self.getDB()
     log.info("checking the state of the CheckTroveCache table")
     cu = db.cursor()
     cu.execute("select patternId, itemId from CheckTroveCache")
     existing = set([(x[0], x[1]) for x in cu.fetchall()])
     required = []
     cu.execute("select distinct i.itemId, i.item from Permissions as p "
                "join Items as i using(itemId)")
     patterns = set([(x[0], x[1]) for x in cu.fetchall()])
     cu.execute("select itemId, item from Items")
     troveNames = set([(x[0], x[1]) for x in cu.fetchall()])
     for patternId, pattern in patterns:
         for itemId, item in troveNames:
             if items.checkTrove(pattern, item):
                 required.append((patternId, itemId))
     required = set(required)
     self._status = required.difference(existing)
     if len(self._status):
         log.warning(
             "found %d entries that are missing from CheckTroveCache",
             len(self._status))
         return False
     return True
コード例 #7
0
ファイル: netauth.py プロジェクト: fedora-conary/conary
 def checkTrove(self, pattern, trove):
     return items.checkTrove(pattern, trove)