def main(): logger = Factory.get_logger("cronjob") db = Factory.get('Database')() const = Factory.get("Constants")(db) account = Factory.get('Account')(db) auth_prefix, auth_method = "{crypt}", int(const.auth_type_md5_crypt) ldif = LDIFWriter('SERVICES', None) dn = ldif.getconf('dn') ldif.write_container() for username in ldif.getconf('users'): account.clear() try: account.find_by_name(username) except Errors.NotFoundError: logger.error("User '%s' not found" % username) sys.exit(1) passwd = None qh = QuarantineHandler.check_entity_quarantines(db, account.entity_id) if not (qh.should_skip() or qh.is_locked()): try: passwd = account.get_account_authentication(auth_method) except Errors.NotFoundError: logger.warn("Password not found for user %s", username) ldif.write_entry( "cn=%s,%s" % (username, dn), { 'description': "Note: The password is maintained in Cerebrum.", 'objectClass': ('applicationProcess', 'simpleSecurityObject'), 'userPassword': auth_prefix + (passwd or "*locked") }) ldif.close()
def main(): logger = Factory.get_logger("cronjob") db = Factory.get('Database')() const = Factory.get("Constants")(db) account = Factory.get('Account')(db) auth_prefix, auth_method = "{crypt}", int(const.auth_type_md5_crypt) ldif = LDIFWriter('SERVICES', None) dn = ldif.getconf('dn') ldif.write_container() for username in ldif.getconf('users'): account.clear() try: account.find_by_name(username) except Errors.NotFoundError: logger.error("User '%s' not found" % username) sys.exit(1) passwd = None qh = QuarantineHandler.check_entity_quarantines(db, account.entity_id) if not (qh.should_skip() or qh.is_locked()): try: passwd = account.get_account_authentication(auth_method) except Errors.NotFoundError: logger.warn("Password not found for user %s", username) ldif.write_entry("cn=%s,%s" % (username, dn), { 'description': "Note: The password is maintained in Cerebrum.", 'objectClass': ('applicationProcess', 'simpleSecurityObject'), 'userPassword': auth_prefix + (passwd or "*locked")}) ldif.close()
def main(): db = Factory.get('Database')() co = Factory.get('Constants')(db) arecord = ARecord.ARecord(db) dns_owner = DnsOwner.DnsOwner(db) get_id_mac = itemgetter('dns_owner_id', 'mac_adr') get_id_name = itemgetter('dns_owner_id', 'name') get_trait = itemgetter('entity_id', 'code', 'strval') trait2attr = { int(co.trait_dns_comment): 'uioHostComment', int(co.trait_dns_contact): 'uioHostContact', } ldif = LDIFWriter('HOSTS', None) logger.info('Start of hosts export to %s', ldif.f.name) ldif.write_container() base_dn = ldif.getconf('dn') id2attrs = defaultdict(dict) for entity_id, code, strval in imap(get_trait, dns_owner.list_traits( code=trait2attr.keys())): if strval: id2attrs[int(entity_id)][trait2attr[code]] = (strval,) arecords = defaultdict(set) for owner_id, mac in imap(get_id_mac, arecord.list_ext()): if mac: arecords[int(owner_id)].add(mac) done = set() for owner_id, name in sorted(imap(get_id_name, dns_owner.list())): owner_id, name = int(owner_id), name.rstrip('.') # We have both lowercase and uppercase versions of some host # names. Ignore one, hostnames are case-insensitive in LDAP. key = name.lower() if key not in done: done.add(key) entry = { 'host': (name,), 'objectClass': ['uioHostinfo'], 'uioHostMacAddr': arecords.get(owner_id, ()), } entry.update(id2attrs.get(owner_id, ())) ldif.write_entry("host={},{}".format(name, base_dn), entry) ldif.close() logger.info('Done')
def main(): db = Factory.get('Database')() co = Factory.get('Constants')(db) arecord = ARecord.ARecord(db) dns_owner = DnsOwner.DnsOwner(db) get_id_mac = itemgetter('dns_owner_id', 'mac_adr') get_id_name = itemgetter('dns_owner_id', 'name') get_trait = itemgetter('entity_id', 'code', 'strval') trait2attr = {int(co.trait_dns_comment): 'uioHostComment', int(co.trait_dns_contact): 'uioHostContact'} ldif = LDIFWriter('HOSTS', None) ldif.write_container() base_dn = ldif.getconf('dn') id2attrs = defaultdict(dict) for entity_id, code, strval in imap(get_trait, dns_owner.list_traits( code=trait2attr.keys())): if strval: id2attrs[int(entity_id)][trait2attr[code]] = (iso2utf(strval),) arecords = defaultdict(set) for owner_id, mac in imap(get_id_mac, arecord.list_ext()): if mac: arecords[int(owner_id)].add(mac) done = set() for owner_id, name in sorted(imap(get_id_name, dns_owner.list())): owner_id, name = int(owner_id), name.rstrip('.') # We have both lowercase and uppercase versions of some host # names. Ignore one, hostnames are case-insensitive in LDAP. key = name.lower() if key not in done: done.add(key) entry = { 'host': (name,), 'objectClass': ['uioHostinfo'], 'uioHostMacAddr': arecords.get(owner_id, ())} entry.update(id2attrs.get(owner_id, ())) ldif.write_entry("host=%s,%s" % (name, base_dn), entry) ldif.close()
usage(1) for opt, val in opts: if opt in ("-h", "--help"): usage() elif opt in ("-f", "--filename"): filename = val elif opt in ("-s", "--spread"): spread = val elif opt in ("-b", "--base"): base = val logger.info("Configuring export") ldif = LDIFWriter("GUESTS", filename, module=guestconfig) try: base = base or ldif.getconf("dn") spread = spread or ldif.getconf("spread") dn = lambda e: "uid=%s,%s" % (e["uid"], base) exporter = GuestLDIF(ldif, spread=spread) logger.info("Starting guest account ldap export.") count = 0 for entry in exporter.generate_guests(): ldif.write_entry(dn(entry), entry) count += 1 except Exception, e: logger.error("Error: Unable to export: %s" % e, exc_info=1) raise finally: ldif.close()
'-h', '--help', ): usage() elif opt in ('-f', '--filename'): filename = val elif opt in ('-s', '--spread'): spread = val elif opt in ('-b', '--base'): base = val logger.info("Configuring export") ldif = LDIFWriter('GUESTS', filename, module=guestconfig) try: base = base or ldif.getconf('dn') spread = spread or ldif.getconf('spread') dn = lambda e: "uid=%s,%s" % (e['uid'], base) exporter = GuestLDIF(ldif, spread=spread) logger.info("Starting guest account ldap export.") count = 0 for entry in exporter.generate_guests(): ldif.write_entry(dn(entry), entry) count += 1 except Exception, e: logger.error("Error: Unable to export: %s" % e, exc_info=1) raise finally: ldif.close()
usage(1) for opt, val in opts: if opt in ('-h', '--help',): usage() elif opt in ('-f', '--filename'): filename = val elif opt in ('-s', '--spread'): spread = val elif opt in ('-b', '--base'): base = val logger.info("Configuring export") ldif = LDIFWriter('GUESTS', filename, module=guestconfig) try: base = base or ldif.getconf('dn') spread = spread or ldif.getconf('spread') dn = lambda e: "uid=%s,%s" % (e['uid'], base) exporter = GuestLDIF(ldif, spread=spread) logger.info("Starting guest account ldap export.") count = 0 for entry in exporter.generate_guests(): ldif.write_entry(dn(entry), entry) count += 1 except Exception, e: logger.error("Error: Unable to export: %s" % e, exc_info=1) raise finally: ldif.close()