def check_version(): """ :raise UpgradePlatformError: if platform is not the same :raise UpgradeDataOlderVersionError: if data needs to be upgraded :raise UpgradeDataNewerVersionError: older version of IPA was detected than data :raise UpgradeMissingVersionError: if platform or version is missing """ platform = sysupgrade.get_upgrade_state('ipa', 'platform') if platform is not None: if platform != ipaplatform.NAME: raise UpgradePlatformError( "platform mismatch (expected '%s', current '%s')" % ( platform, ipaplatform.NAME) ) else: raise UpgradeMissingVersionError("no platform stored") data_version = sysupgrade.get_upgrade_state('ipa', 'data_version') if data_version is not None: parsed_data_ver = tasks.parse_ipa_version(data_version) parsed_ipa_ver = tasks.parse_ipa_version(version.VENDOR_VERSION) if parsed_data_ver < parsed_ipa_ver: raise UpgradeDataOlderVersionError( "data needs to be upgraded (expected version '%s', current " "version '%s')" % (version.VENDOR_VERSION, data_version) ) elif parsed_data_ver > parsed_ipa_ver: raise UpgradeDataNewerVersionError( "data are in newer version than IPA (data version '%s', IPA " "version '%s')" % (data_version, version.VENDOR_VERSION) ) else: raise UpgradeMissingVersionError("no data_version stored")
def upgrade_instance(self): installed = sysupgrade.get_upgrade_state("custodia", "installed") if installed: if (not os.path.isfile(self.server_keys) or not os.path.isfile(self.config_file)): logger.warning( "Custodia server keys or config are missing, forcing " "reinstallation of ipa-custodia." ) installed = False if not installed: logger.info("Custodia service is being configured") self.create_instance() else: old_config = open(self.config_file).read() self.__config_file() new_config = open(self.config_file).read() if new_config != old_config: logger.info("Restarting Custodia") self.restart() mode = os.stat(self.server_keys).st_mode if stat.S_IMODE(mode) != 0o600: logger.info("Secure server.keys mode") os.chmod(self.server_keys, 0o600)
def execute(self, **options): ldap = self.api.Backend.ldap2 if sysupgrade.get_upgrade_state('dns', 'server_config_to_ldap'): self.log.debug('upgrade is not needed') return False, [] dns_container_dn = DN(self.api.env.container_dns, self.api.env.basedn) try: ldap.get_entry(dns_container_dn) except errors.NotFound: self.log.debug('DNS container not found, nothing to upgrade') sysupgrade.set_upgrade_state('dns', 'server_config_to_ldap', True) return False, [] result = self.api.Command.server_show(self.api.env.host)['result'] if not 'DNS server' in result.get('enabled_role_servrole', []): self.log.debug('This server is not DNS server, nothing to upgrade') sysupgrade.set_upgrade_state('dns', 'server_config_to_ldap', True) return False, [] # create container first, if doesn't exist ensure_dnsserver_container_exists(ldap, self.api, logger=self.log) try: self.api.Command.dnsserver_add(self.api.env.host) except errors.DuplicateEntry: self.log.debug("DNS server configuration already exists " "in LDAP database") else: self.log.debug("DNS server configuration has been sucessfully " "created in LDAP database") sysupgrade.set_upgrade_state('dns', 'server_config_to_ldap', True) return False, []
def execute(self, **options): update_done = sysupgrade.get_upgrade_state( 'winsync', 'passsync_privilege_updated') if update_done: root_logger.debug("PassSync privilege update pre-check not needed") return False, [] root_logger.debug("Check if there is existing PassSync privilege") passsync_privilege_dn = DN(('cn', 'PassSync Service'), self.api.env.container_privilege, self.api.env.basedn) ldap = self.api.Backend.ldap2 try: ldap.get_entry(passsync_privilege_dn, ['']) except errors.NotFound: root_logger.debug( "PassSync privilege not found, this is a new update") sysupgrade.set_upgrade_state('winsync', 'passsync_privilege_updated', False) else: root_logger.debug( "PassSync privilege found, skip updating PassSync") sysupgrade.set_upgrade_state('winsync', 'passsync_privilege_updated', True) return False, []
def execute(self, **options): update_done = sysupgrade.get_upgrade_state( 'winsync', 'passsync_privilege_updated') if update_done: root_logger.debug("PassSync privilege update not needed") return False, [] root_logger.debug( "Add PassSync user as a member of PassSync privilege") ldap = self.api.Backend.ldap2 passsync_dn = DN(('uid', 'passsync'), ('cn', 'sysaccounts'), ('cn', 'etc'), self.api.env.basedn) passsync_privilege_dn = DN(('cn', 'PassSync Service'), self.api.env.container_privilege, self.api.env.basedn) try: entry = ldap.get_entry(passsync_dn, ['']) except errors.NotFound: root_logger.debug("PassSync user not found, no update needed") sysupgrade.set_upgrade_state('winsync', 'passsync_privilege_updated', True) return False, [] else: root_logger.debug("PassSync user found, do update") update = { 'dn': passsync_privilege_dn, 'updates': ["add:member:'%s'" % passsync_dn] } sysupgrade.set_upgrade_state('winsync', 'passsync_privilege_updated', True) return False, [update]
def execute(self, **options): update_done = sysupgrade.get_upgrade_state('winsync', 'passsync_privilege_updated') if update_done: root_logger.debug("PassSync privilege update not needed") return False, [] root_logger.debug("Add PassSync user as a member of PassSync privilege") ldap = self.api.Backend.ldap2 passsync_dn = DN(('uid','passsync'), ('cn', 'sysaccounts'), ('cn', 'etc'), self.api.env.basedn) passsync_privilege_dn = DN(('cn','PassSync Service'), self.api.env.container_privilege, self.api.env.basedn) try: entry = ldap.get_entry(passsync_dn, ['']) except errors.NotFound: root_logger.debug("PassSync user not found, no update needed") sysupgrade.set_upgrade_state('winsync', 'passsync_privilege_updated', True) return False, [] else: root_logger.debug("PassSync user found, do update") update = {'dn': passsync_privilege_dn, 'updates': ["add:member:'%s'" % passsync_dn]} sysupgrade.set_upgrade_state('winsync', 'passsync_privilege_updated', True) return False, [update]
def upgrade_instance(self): if not sysupgrade.get_upgrade_state("custodia", "installed"): root_logger.info("Custodia service is being configured") self.create_instance() mode = os.stat(self.server_keys).st_mode if stat.S_IMODE(mode) != 0o600: root_logger.info("Secure server.keys mode") os.chmod(self.server_keys, 0o600)
def find_subject_base(self): """ Try to find the current value of certificate subject base. 1) Look in sysupgrade first 2) If no value is found there, look in DS (start DS if necessary) 3) Last resort, look in the certmap.conf itself 4) If all fails, log loudly and return None Note that this method can only be executed AFTER the ipa server is configured, the api is initialized elsewhere and that a ticket already have been acquired. """ root_logger.debug("Trying to find certificate subject base in sysupgrade") subject_base = sysupgrade.get_upgrade_state("certmap.conf", "subject_base") if subject_base: root_logger.debug("Found certificate subject base in sysupgrade: %s", subject_base) return subject_base root_logger.debug("Unable to find certificate subject base in sysupgrade") root_logger.debug("Trying to find certificate subject base in DS") ds_is_running = is_ds_running() if not ds_is_running: try: self.start() ds_is_running = True except ipautil.CalledProcessError as e: root_logger.error("Cannot start DS to find certificate " "subject base: %s", e) if ds_is_running: try: ret = api.Command["config_show"]() subject_base = str(ret["result"]["ipacertificatesubjectbase"][0]) root_logger.debug("Found certificate subject base in DS: %s", subject_base) except errors.PublicError as e: root_logger.error("Cannot connect to DS to find certificate " "subject base: %s", e) if not subject_base: root_logger.debug("Unable to find certificate subject base in DS") root_logger.debug("Trying to find certificate subject base in " "certmap.conf") certmap_dir = config_dirname(installutils.realm_to_serverid(api.env.realm)) try: with open(os.path.join(certmap_dir, "certmap.conf")) as f: for line in f: if line.startswith("certmap ipaca"): subject_base = line.strip().split(",")[-1] root_logger.debug("Found certificate subject base in certmap.conf: " "%s", subject_base) except IOError as e: root_logger.error("Cannot open certmap.conf to find certificate " "subject base: %s", e.strerror) if subject_base: return subject_base root_logger.debug("Unable to find certificate subject base in " "certmap.conf") return None
def reindex_task(self, force=False): """Reindex ipaca entries pkispawn sometimes does not run its indextasks. This leads to slow unindexed filters on attributes such as description, which is used to log in with a certificate. Explicitly reindex attribute that should have been reindexed by CA's indextasks.ldif. See https://pagure.io/dogtagpki/issue/3083 """ state_name = 'reindex_task' if not force and sysupgrade.get_upgrade_state('dogtag', state_name): return cn = "indextask_ipaca_{}".format(int(time.time())) dn = DN(('cn', cn), ('cn', 'index'), ('cn', 'tasks'), ('cn', 'config')) entry = api.Backend.ldap2.make_entry( dn, objectClass=['top', 'extensibleObject'], cn=[cn], nsInstance=['ipaca'], # Dogtag PKI database nsIndexAttribute=[ # from pki/base/ca/shared/conf/indextasks.ldif 'archivedBy', 'certstatus', 'clientId', 'dataType', 'dateOfCreate', 'description', 'duration', 'extension', 'issuedby', 'issuername', 'metaInfo', 'notafter', 'notbefore', 'ownername', 'publicKeyData', 'requestid', 'requestowner', 'requestsourceid', 'requeststate', 'requesttype', 'revInfo', 'revokedOn', 'revokedby', 'serialno', 'status', 'subjectname', ], ttl=[10], ) logger.debug('Creating ipaca reindex task %s', dn) api.Backend.ldap2.add_entry(entry) logger.debug('Waiting for task...') exitcode = replication.wait_for_task(api.Backend.ldap2, dn) logger.debug('Task %s has finished with exit code %i', dn, exitcode) sysupgrade.set_upgrade_state('dogtag', state_name, True)
def find_subject_base(self): """ Try to find the current value of certificate subject base. 1) Look in sysupgrade first 2) If no value is found there, look in DS (start DS if necessary) 3) If all fails, log loudly and return None Note that this method can only be executed AFTER the ipa server is configured, the api is initialized elsewhere and that a ticket already have been acquired. """ root_logger.debug( 'Trying to find certificate subject base in sysupgrade') subject_base = sysupgrade.get_upgrade_state('certmap.conf', 'subject_base') if subject_base: root_logger.debug( 'Found certificate subject base in sysupgrade: %s', subject_base) return subject_base root_logger.debug( 'Unable to find certificate subject base in sysupgrade') root_logger.debug('Trying to find certificate subject base in DS') ds_is_running = is_ds_running() if not ds_is_running: try: self.start() ds_is_running = True except ipautil.CalledProcessError as e: root_logger.error( 'Cannot start DS to find certificate ' 'subject base: %s', e) if ds_is_running: try: ret = api.Command['config_show']() subject_base = str( ret['result']['ipacertificatesubjectbase'][0]) root_logger.debug('Found certificate subject base in DS: %s', subject_base) except errors.PublicError as e: root_logger.error( 'Cannot connect to DS to find certificate ' 'subject base: %s', e) if subject_base: return subject_base root_logger.debug('Unable to find certificate subject base in ' 'certmap.conf') return None
def execute(self, **options): if sysupgrade.get_upgrade_state('sidgen', 'config_basedn_updated'): self.log.debug("Already done, skipping") return False, () restart = False if self._fix_config(): sysupgrade.set_upgrade_state('sidgen', 'update_sids', True) restart = True # DS has to be restarted to apply changes sysupgrade.set_upgrade_state('sidgen', 'config_basedn_updated', True) return restart, ()
def execute(self, **options): if sysupgrade.get_upgrade_state('sidgen', 'config_basedn_updated'): logger.debug("Already done, skipping") return False, () restart = False if self._fix_config(): sysupgrade.set_upgrade_state('sidgen', 'update_sids', True) restart = True # DS has to be restarted to apply changes sysupgrade.set_upgrade_state('sidgen', 'config_basedn_updated', True) return restart, ()
def find_subject_base(self): """ Try to find the current value of certificate subject base. 1) Look in sysupgrade first 2) If no value is found there, look in DS (start DS if necessary) 3) If all fails, log loudly and return None Note that this method can only be executed AFTER the ipa server is configured, the api is initialized elsewhere and that a ticket already have been acquired. """ logger.debug( 'Trying to find certificate subject base in sysupgrade') subject_base = sysupgrade.get_upgrade_state( 'certmap.conf', 'subject_base') if subject_base: logger.debug( 'Found certificate subject base in sysupgrade: %s', subject_base) return subject_base logger.debug( 'Unable to find certificate subject base in sysupgrade') logger.debug( 'Trying to find certificate subject base in DS') ds_is_running = is_ds_running() if not ds_is_running: try: self.start() ds_is_running = True except ipautil.CalledProcessError as e: logger.error('Cannot start DS to find certificate ' 'subject base: %s', e) if ds_is_running: try: ret = api.Command['config_show']() subject_base = str( ret['result']['ipacertificatesubjectbase'][0]) logger.debug( 'Found certificate subject base in DS: %s', subject_base) except errors.PublicError as e: logger.error('Cannot connect to DS to find certificate ' 'subject base: %s', e) if subject_base: return subject_base logger.debug('Unable to find certificate subject base in certmap.conf') return None
def ntp_ldap_enable(fqdn, base_dn, realm): ntp = NTPInstance(realm=realm) is_exposed_in_ldap = sysupgrade.get_upgrade_state('ntp', NTP_EXPOSED_IN_LDAP) was_running = ntp.is_running() if ntp.is_configured() and not is_exposed_in_ldap: ntp.ldap_enable('NTP', fqdn, None, base_dn) sysupgrade.set_upgrade_state('ntp', NTP_EXPOSED_IN_LDAP, True) if was_running: ntp.start()
def change_mod_nss_port_from_http(self): # mod_ssl enforces SSLEngine on for vhost on 443 even though # the listener is mod_nss. This then crashes the httpd as mod_nss # listened port obviously does not match mod_ssl requirements. # # The workaround for this was to change port to http. It is no longer # necessary, as mod_nss now ships with default configuration which # sets SSLEngine off when mod_ssl is installed. # # Remove the workaround. if sysupgrade.get_upgrade_state('nss.conf', 'listen_port_updated'): installutils.set_directive(paths.HTTPD_NSS_CONF, 'Listen', '443', quotes=False) sysupgrade.set_upgrade_state('nss.conf', 'listen_port_updated', False)
def ntp_ldap_enable(fqdn, base_dn, realm): ntp = NTPInstance(realm=realm) is_exposed_in_ldap = sysupgrade.get_upgrade_state( 'ntp', NTP_EXPOSED_IN_LDAP) was_running = ntp.is_running() if ntp.is_configured() and not is_exposed_in_ldap: ntp.ldap_enable('NTP', fqdn, None, base_dn) sysupgrade.set_upgrade_state('ntp', NTP_EXPOSED_IN_LDAP, True) if was_running: ntp.start()
def upgrade_instance(self): if not sysupgrade.get_upgrade_state("custodia", "installed"): logger.info("Custodia service is being configured") self.create_instance() else: old_config = open(self.config_file).read() self.__config_file() new_config = open(self.config_file).read() if new_config != old_config: logger.info("Restarting Custodia") self.restart() mode = os.stat(self.server_keys).st_mode if stat.S_IMODE(mode) != 0o600: logger.info("Secure server.keys mode") os.chmod(self.server_keys, 0o600)
def reindex_task(self, force=False): """Reindex ipaca entries pkispawn sometimes does not run its indextasks. This leads to slow unindexed filters on attributes such as description, which is used to log in with a certificate. Explicitly reindex attribute that should have been reindexed by CA's indextasks.ldif. See https://pagure.io/dogtagpki/issue/3083 """ state_name = 'reindex_task' if not force and sysupgrade.get_upgrade_state('dogtag', state_name): return cn = "indextask_ipaca_{}".format(int(time.time())) dn = DN( ('cn', cn), ('cn', 'index'), ('cn', 'tasks'), ('cn', 'config') ) entry = api.Backend.ldap2.make_entry( dn, objectClass=['top', 'extensibleObject'], cn=[cn], nsInstance=['ipaca'], # Dogtag PKI database nsIndexAttribute=[ # from pki/base/ca/shared/conf/indextasks.ldif 'archivedBy', 'certstatus', 'clientId', 'dataType', 'dateOfCreate', 'description', 'duration', 'extension', 'issuedby', 'issuername', 'metaInfo', 'notafter', 'notbefore', 'ownername', 'publicKeyData', 'requestid', 'requestowner', 'requestsourceid', 'requeststate', 'requesttype', 'revInfo', 'revokedOn', 'revokedby', 'serialno', 'status', 'subjectname', ], ttl=[10], ) logger.debug('Creating ipaca reindex task %s', dn) api.Backend.ldap2.add_entry(entry) logger.debug('Waiting for task...') exitcode = replication.wait_for_task(api.Backend.ldap2, dn) logger.debug( 'Task %s has finished with exit code %i', dn, exitcode ) sysupgrade.set_upgrade_state('dogtag', state_name, True)
def __recover_from_missing_maps(self, ldap): # https://fedorahosted.org/freeipa/ticket/5507 # if all following DNs are missing, but 'NIS Server' container exists # we are experiencig bug and maps should be fixed if sysupgrade.get_upgrade_state('nis', 'done_recover_from_missing_maps'): # this recover must be done only once, a user may deleted some # maps, we do not want to restore them again return logger.debug("Recovering from missing NIS maps bug") suffix = "cn=NIS Server,cn=plugins,cn=config" domain = self.api.env.domain missing_dn_list = [ DN(nis_map.format(domain=domain, suffix=suffix)) for nis_map in [ "nis-domain={domain}+nis-map=passwd.byname,{suffix}", "nis-domain={domain}+nis-map=passwd.byuid,{suffix}", "nis-domain={domain}+nis-map=group.byname,{suffix}", "nis-domain={domain}+nis-map=group.bygid,{suffix}", "nis-domain={domain}+nis-map=netid.byname,{suffix}", "nis-domain={domain}+nis-map=netgroup,{suffix}", ] ] for dn in missing_dn_list: try: ldap.get_entry(dn, attrs_list=['cn']) except errors.NotFound: pass else: # bug is not effective, at least one of 'possible missing' # maps was detected return sysupgrade.set_upgrade_state('nis', 'done_recover_from_missing_maps', True) # bug is effective run update to recreate missing maps ld = LDAPUpdate(sub_dict={}, ldapi=True) ld.update([paths.NIS_ULDIF])
def execute(self, **options): update_done = sysupgrade.get_upgrade_state('winsync', 'passsync_privilege_updated') if update_done: root_logger.debug("PassSync privilege update pre-check not needed") return False, [] root_logger.debug("Check if there is existing PassSync privilege") passsync_privilege_dn = DN(('cn','PassSync Service'), self.api.env.container_privilege, self.api.env.basedn) ldap = self.api.Backend.ldap2 try: ldap.get_entry(passsync_privilege_dn, ['']) except errors.NotFound: root_logger.debug("PassSync privilege not found, this is a new update") sysupgrade.set_upgrade_state('winsync', 'passsync_privilege_updated', False) else: root_logger.debug("PassSync privilege found, skip updating PassSync") sysupgrade.set_upgrade_state('winsync', 'passsync_privilege_updated', True) return False, []
def find_subject_base(self): """ Try to find the current value of certificate subject base. 1) Look in sysupgrade first 2) If no value is found there, look in DS (start DS if necessary) 3) Last resort, look in the certmap.conf itself 4) If all fails, log loudly and return None Note that this method can only be executed AFTER the ipa server is configured, the api is initialized elsewhere and that a ticket already have been acquired. """ root_logger.debug( 'Trying to find certificate subject base in sysupgrade') subject_base = sysupgrade.get_upgrade_state( 'certmap.conf', 'subject_base') if subject_base: root_logger.debug( 'Found certificate subject base in sysupgrade: %s', subject_base) return subject_base root_logger.debug( 'Unable to find certificate subject base in sysupgrade') root_logger.debug( 'Trying to find certificate subject base in DS') ds_is_running = is_ds_running() if not ds_is_running: try: self.start() ds_is_running = True except ipautil.CalledProcessError as e: root_logger.error('Cannot start DS to find certificate ' 'subject base: %s', e) if ds_is_running: try: api.Backend.ldap2.connect(autobind=True) ret = api.Command['config_show']() subject_base = str( ret['result']['ipacertificatesubjectbase'][0]) root_logger.debug( 'Found certificate subject base in DS: %s', subject_base) except errors.PublicError as e: root_logger.error('Cannot connect to DS to find certificate ' 'subject base: %s', e) finally: try: api.Backend.ldap2.disconnect() except Exception: pass if not subject_base: root_logger.debug('Unable to find certificate subject base in DS') root_logger.debug('Trying to find certificate subject base in ' 'certmap.conf') certmap_dir = config_dirname( installutils.realm_to_serverid(api.env.realm) ) try: with open(os.path.join(certmap_dir, 'certmap.conf')) as f: for line in f: if line.startswith('certmap ipaca'): subject_base = line.strip().split(',')[-1] root_logger.debug( 'Found certificate subject base in certmap.conf: ' '%s', subject_base) except IOError as e: root_logger.error('Cannot open certmap.conf to find certificate ' 'subject base: %s', e.strerror) if subject_base: return subject_base root_logger.debug('Unable to find certificate subject base in ' 'certmap.conf') return None
def disable_mod_ssl_ocsp(self): if sysupgrade.get_upgrade_state('http', OCSP_ENABLED) is None: self.__disable_mod_ssl_ocsp() sysupgrade.set_upgrade_state('http', OCSP_ENABLED, False)
def upgrade_instance(self): if not sysupgrade.get_upgrade_state("custodia", "installed"): root_logger.info("Custodia service is being configured") self.create_instance()
def find_subject_base(self): """ Try to find the current value of certificate subject base. 1) Look in sysupgrade first 2) If no value is found there, look in DS (start DS if necessary) 3) Last resort, look in the certmap.conf itself 4) If all fails, log loudly and return None Note that this method can only be executed AFTER the ipa server is configured, the api is initialized elsewhere and that a ticket already have been acquired. """ root_logger.debug( 'Trying to find certificate subject base in sysupgrade') subject_base = sysupgrade.get_upgrade_state( 'certmap.conf', 'subject_base') if subject_base: root_logger.debug( 'Found certificate subject base in sysupgrade: %s', subject_base) return subject_base root_logger.debug( 'Unable to find certificate subject base in sysupgrade') root_logger.debug( 'Trying to find certificate subject base in DS') ds_is_running = is_ds_running() if not ds_is_running: try: self.start() ds_is_running = True except ipautil.CalledProcessError as e: root_logger.error('Cannot start DS to find certificate ' 'subject base: %s', e) if ds_is_running: try: ret = api.Command['config_show']() subject_base = str( ret['result']['ipacertificatesubjectbase'][0]) root_logger.debug( 'Found certificate subject base in DS: %s', subject_base) except errors.PublicError as e: root_logger.error('Cannot connect to DS to find certificate ' 'subject base: %s', e) if not subject_base: root_logger.debug('Unable to find certificate subject base in DS') root_logger.debug('Trying to find certificate subject base in ' 'certmap.conf') certmap_dir = config_dirname( installutils.realm_to_serverid(api.env.realm) ) try: with open(os.path.join(certmap_dir, 'certmap.conf')) as f: for line in f: if line.startswith('certmap ipaca'): subject_base = line.strip().split(',')[-1] root_logger.debug( 'Found certificate subject base in certmap.conf: ' '%s', subject_base) except IOError as e: root_logger.error('Cannot open certmap.conf to find certificate ' 'subject base: %s', e.strerror) if subject_base: return subject_base root_logger.debug('Unable to find certificate subject base in ' 'certmap.conf') return None
def execute(self, **options): ldap = self.api.Backend.ldap2 if sysupgrade.get_upgrade_state('sidgen', 'update_sids') is not True: self.log.debug("SIDs do not need to be generated") return False, () # check if IPA domain for AD trust has been created, and if we need to # regenerate missing SIDs if attribute 'ipaNTSecurityIdentifier' domain_IPA_AD_dn = DN( ('cn', self.api.env.domain), self.api.env.container_cifsdomains, self.api.env.basedn) attr_name = 'ipaNTSecurityIdentifier' try: entry = ldap.get_entry(domain_IPA_AD_dn, attrs_list=[attr_name]) except errors.NotFound: self.log.debug("IPA domain object %s is not configured", domain_IPA_AD_dn) sysupgrade.set_upgrade_state('sidgen', 'update_sids', False) return False, () else: if not entry.single_value.get(attr_name): # we need to run sidgen task sidgen_task_dn = DN( "cn=generate domain sid,cn=ipa-sidgen-task,cn=tasks," "cn=config") sidgen_tasks_attr = { "objectclass": ["top", "extensibleObject"], "cn": ["sidgen"], "delay": [0], "nsslapd-basedn": [self.api.env.basedn], } task_entry = ldap.make_entry(sidgen_task_dn, **sidgen_tasks_attr) try: ldap.add_entry(task_entry) except errors.DuplicateEntry: self.log.debug("sidgen task already created") else: self.log.debug("sidgen task has been created") # we have to check all trusts domains which may been affected by the # bug. Symptom is missing 'ipaNTSecurityIdentifier' attribute base_dn = DN(self.api.env.container_adtrusts, self.api.env.basedn) try: trust_domain_entries, truncated = ldap.find_entries( base_dn=base_dn, scope=ldap.SCOPE_ONELEVEL, attrs_list=["cn"], # more types of trusts can be stored under cn=trusts, we need # the type with ipaNTTrustPartner attribute filter="(&(ipaNTTrustPartner=*)(!(%s=*)))" % attr_name ) except errors.NotFound: pass else: if truncated: self.log.warning("update_sids: Search results were truncated") for entry in trust_domain_entries: domain = entry.single_value["cn"] self.log.error( "Your trust to %s is broken. Please re-create it by " "running 'ipa trust-add' again.", domain) sysupgrade.set_upgrade_state('sidgen', 'update_sids', False) return False, ()
def execute(self, **options): ldap = self.api.Backend.ldap2 if sysupgrade.get_upgrade_state('sidgen', 'update_sids') is not True: logger.debug("SIDs do not need to be generated") return False, () # check if IPA domain for AD trust has been created, and if we need to # regenerate missing SIDs if attribute 'ipaNTSecurityIdentifier' domain_IPA_AD_dn = DN( ('cn', self.api.env.domain), self.api.env.container_cifsdomains, self.api.env.basedn) attr_name = 'ipaNTSecurityIdentifier' try: entry = ldap.get_entry(domain_IPA_AD_dn, attrs_list=[attr_name]) except errors.NotFound: logger.debug("IPA domain object %s is not configured", domain_IPA_AD_dn) sysupgrade.set_upgrade_state('sidgen', 'update_sids', False) return False, () else: if not entry.single_value.get(attr_name): # we need to run sidgen task sidgen_task_dn = DN( "cn=generate domain sid,cn=ipa-sidgen-task,cn=tasks," "cn=config") sidgen_tasks_attr = { "objectclass": ["top", "extensibleObject"], "cn": ["sidgen"], "delay": [0], "nsslapd-basedn": [self.api.env.basedn], } task_entry = ldap.make_entry(sidgen_task_dn, **sidgen_tasks_attr) try: ldap.add_entry(task_entry) except errors.DuplicateEntry: logger.debug("sidgen task already created") else: logger.debug("sidgen task has been created") # we have to check all trusts domains which may been affected by the # bug. Symptom is missing 'ipaNTSecurityIdentifier' attribute base_dn = DN(self.api.env.container_adtrusts, self.api.env.basedn) try: trust_domain_entries, truncated = ldap.find_entries( base_dn=base_dn, scope=ldap.SCOPE_ONELEVEL, attrs_list=["cn"], # more types of trusts can be stored under cn=trusts, we need # the type with ipaNTTrustPartner attribute filter="(&(ipaNTTrustPartner=*)(!(%s=*)))" % attr_name ) except errors.NotFound: pass else: if truncated: logger.warning("update_sids: Search results were truncated") for entry in trust_domain_entries: domain = entry.single_value["cn"] logger.error( "Your trust to %s is broken. Please re-create it by " "running 'ipa trust-add' again.", domain) sysupgrade.set_upgrade_state('sidgen', 'update_sids', False) return False, ()