Exemplo n.º 1
0
    def get_locked_entities(db,
                            entity_types=None,
                            only_active=True,
                            entity_ids=None,
                            ignore_quarantine_types=None):
        """Utility method that the returns the entity-id of all locked accounts.

        :param db: A database object
        :param entity_types: Entity types to filter on
        :param only_active: Only return locked and active quarantines
        :param entity_ids: Spesific entity-ids to check
        :param ignore_quarantine_types: Quarantines to ignore"""
        cache = defaultdict(list)
        eq = Entity.EntityQuarantine(db)
        for row in eq.list_entity_quarantines(
                entity_types=entity_types,
                only_active=only_active,
                entity_ids=entity_ids,
                ignore_quarantine_types=ignore_quarantine_types):
            cache[row['entity_id']].append(row['quarantine_type'])

        def is_locked(key):
            return QuarantineHandler(db, cache.get(key)).is_locked()

        return set(filter(is_locked, cache.keys()))
Exemplo n.º 2
0
 def check_entity_quarantines(db, entity_id, spreads=None):
     """Utility method that returns an initiated QuarantineHandler
     for a given entity_id"""
     eq = Entity.EntityQuarantine(db)
     eq.find(entity_id)
     return QuarantineHandler(db, [
         int(row['quarantine_type'])
         for row in eq.get_entity_quarantine(only_active=True)
     ], spreads)
Exemplo n.º 3
0
def main():
    global db, co, ac, group, person, qua, logger
    global server, ou, child_ou
    c_data = {}
    ad_data = {}

    db = Factory.get('Database')()
    db.cl_init(change_program="adusync")
    co = Factory.get('Constants')(db)
    ac = Factory.get('Account')(db)
    ou = Factory.get("OU")(db)
    child_ou = Factory.get("OU")(db)
    group = Factory.get('Group')(db)
    person = Factory.get('Person')(db)
    qua = Entity.EntityQuarantine(db)
    logger = Factory.get_logger("cronjob")

    passwd = db._read_password(cereconf.AD_SERVER_HOST,
                               cereconf.AD_SERVER_UNAME)

    # Connect to AD-service at NMH
    #
    server = xmlrpclib.Server(
        "https://%s@%s:%i" %
        (passwd, cereconf.AD_SERVER_HOST, cereconf.AD_SERVER_PORT))
    try:
        opts, args = getopt.getopt(sys.argv[1:], '', ['help', 'dry_run'])
    except getopt.GetoptError:
        usage(1)

    dry_run = False

    for opt, val in opts:
        if opt == '--help':
            usage(1)
        elif opt == '--dry_run':
            dry_run = True

    c_data = get_cerebrum_data()

    # Fetch AD-data. Catch ProtocolError and don't write xpe.url to log
    # since it may contain a password.
    try:
        ad_data = get_ad_data()
    except xmlrpclib.ProtocolError, xpe:
        logger.critical("Error connecting to AD service. Giving up!: %s %s" %
                        (xpe.errcode, xpe.errmsg))
        return
Exemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     super(ADfuSync, self).__init__(*args, **kwargs)
     self.person = Factory.get('Person')(self.db)
     self.qua = Entity.EntityQuarantine(self.db)
     self.ou =  Factory.get('OU')(self.db)