HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/ipaclient/install/__pycache__/ipa_certupdate.cpython-36.pyc
3

�d[eu'�@sddlmZddlZddlZddlmZddlmZmZddl	m
Z
ddlmZm
Z
mZmZddlmZddlmZdd	lmZdd
lmZmZmZddlmZmZmZddlmZej e!�Z"Gd
d�dej#�Z$dd�Z%dd�Z&dd�Z'dd�Z(ddd�Z)dd�Z*dS)�)�absolute_importN)�urlsplit)�
certmonger�	certstore)�is_ipa_configured)�	admintool�certdb�ipaldap�ipautil)�services)�paths)�tasks)�api�errors�x509)�FQDN�IPA_CA_NICKNAME�RENEWAL_CA_NAME)�check_client_configurationcs0eZdZdZdZdZ�fdd�Zdd�Z�ZS)�
CertUpdatezipa-certupdatez%prog [options]zIUpdate local IPA certificate databases with certificates from the server.cstt|�jdd�dS)NT)Z
needs_root)�superr�validate_options)�self)�	__class__��$/usr/lib/python3.6/ipa_certupdate.pyr0szCertUpdate.validate_optionscCs�t�tjjd�}dtjd<dtjd<zfy<tjdtjd�tj�tj	j
j�tt�tj	j
j
�Wn$tjk
r�tjdt��YnXWd|dkr�tjd=n
|tjd<XdS)NZ
KRB5CCNAMEz/etc/krb5.keytabZKRB5_CLIENT_KTNAMEzMEMORY:Z
cli_installer)�contextZconfdirz9Unable to obtain credentials for %s from /etc/krb5.keytab)r�os�environ�getrZ	bootstraprZETC_IPA�finalizeZBackendZ	rpcclientZconnect�
run_with_argsZ
disconnectrZCCacheError�logger�errorr)rZold_krb5ccnamerrr�run3s$


zCertUpdate.run)	�__name__�
__module__�__qualname__Zcommand_nameZusage�descriptionrr$�
__classcell__rr)rrr(s
rcCs�t|jj�j}tjj|�}y|jjdd�}|d}Wn8t	j
t	jfk
rl|jjddd�}|dd}YnX|j�t
j||jj|jj|�}|r�|jj�d}ng}t|�t��r�|jjdd	d
�}dd�|dD�}t|�d
dlm}	m}
|	j�j��r.y|	j|�Wn tk
�r,tjd�YnXyt|	|
|jj |jj!|�Wn tk
�rjtjd�YnXt"j#j$j%��r�t"j#j$j&�t"j#j'j%��r�t"j#j'j&�dS)z�
    Run the certupdate procedure with the given API object.

    :param api: API object with ldap2/rpcclient backend connected
                (such that Commands can be invoked)

    z2.107)�version�resultTz2.0)�serverr*�	enable_raz	CA serverZenabled)Z
role_servroleZstatuscSsg|]}|d�qS)Z
server_serverr)�.0r,rrr�
<listcomp>ssz!run_with_args.<locals>.<listcomp>r)�
cainstance�custodiainstancez.Failed to add lightweight CA tracking requestszFailed to update RA configN)(r�envZjsonrpc_uriZhostnamer	Z
LDAPClientZfrom_hostname_secureZCommandZ
ca_is_enabledrZCommandErrorZNetworkErrorZgssapi_bindrZget_ca_certsZbasedn�realmZca_find�
update_clientrZserver_role_find�
update_serverZipaserver.installr0r1�
CAInstanceZ
is_configuredZ$add_lightweight_ca_tracking_requests�	Exceptionr"Z	exception�update_server_ra_configr-�ca_hostr�
knownservicesZhttpd�
is_running�restartZkrb5kdc)rr,Zldapr+Z
ca_enabled�certsZlwcasZresp�
ca_serversr0r1rrrr!NsLr!cCs�ttj|�ttj|�ttj|�tjtjj	�}xddD]\}xV|j
|�r�y|j|�Wq>tj
k
r�}ztjd||j|�PWYdd}~Xq>Xq>Wq8Wt|j|�tj�tj|�dS)N�IPA CA�External CA certzFailed to remove %s from %s: %s)r?r@)�update_filerZ
IPA_CA_CRTZKDC_CA_BUNDLE_PEMZ
CA_BUNDLE_PEMr�NSSDatabaserr2Znss_dirZhas_nickname�delete_certr
�CalledProcessErrorr"r#Zsecdir�	update_dbr
Z(remove_ca_certs_from_systemwide_ca_storeZ(insert_ca_certs_into_systemwide_ca_store)r=Zipa_db�nickname�errrr4�s 
r4cCsdjtjjjd��}ttj||�tj	j
j�r>tj	j
j|�tj
ttd�}tj|�}|dk	r�tjjd}tjd|�tj|dd�ytj||�}Wn"tk
r�tjd|��YnXtj|d	�}|d
ks�|r�tjd|��tjd|�tj|d
d�ttj|�ttj|�dS)N�-�.)z
cert-databasez
cert-nicknamezca-name�<z$resubmitting certmonger request '%s'zdogtag-ipa-ca-renew-agent-reuse)�cazQResubmitting certmonger request '%s' timed out, please check the request manuallyzca-errorZ
MONITORINGzMError resubmitting certmonger request '%s', please check the request manuallyz!modifying certmonger request '%s'zdogtag-ipa-ca-renew-agent)�joinrr2r3�splitrErZ"ETC_DIRSRV_SLAPD_INSTANCE_TEMPLATErr:Zdirsrvr;r<ZPKI_TOMCAT_ALIAS_DIRrrrZget_request_idZstartup_timeoutr"�debugZresubmit_requestZwait_for_request�RuntimeErrorrZScriptErrorZget_request_valueZmodifyrAZCA_CRTZ
CACERT_PEM)r=�instanceZcriteriaZ
request_idZtimeout�stateZca_errorrrrr5�s8


r5cCsjt|�dkrdS|d}|sT|jj�|jtjjtjj|d�}|j|�|j	|�n||krf|j	|�dS)z�
    After promoting a CA-less deployment to CA-ful, or after removal
    of a CA server from the topology, it may be necessary to update
    the default.conf ca_host setting on non-CA replicas.

    rN)Z	host_namer3Z
custodia_peer)
�lenr6Z$configure_certmonger_renewal_helpersZCustodiaInstancerr2�hostr3Z
import_ra_keyZupdate_ipa_conf)r0r1r-r9r>Znew_ca_hostZcustodiarrrr8�s


r8�cCsXdd�|D�}ytj|||d�Wn0tk
rR}ztjd||�WYdd}~XnXdS)Ncss"|]}|ddk	r|dVqdS)�FrNr)r.�crrr�	<genexpr>szupdate_file.<locals>.<genexpr>)�modezfailed to update %s: %s)rZwrite_certificate_listr7r"r#)�filenamer=rXrGrrrrAs
rAcCs�tj|�}x$|j�D]\}}|jr|j|�qWxj|D]b\}}}}tj|d|�}	y|j|||	�Wq6tj	k
r�}
zt
jd|||
�WYdd}
~
Xq6Xq6WdS)z�Drop all CA certs from db then add certs from list provided

       This may result in some churn as existing certs are dropped
       and re-added but this also provides the ability to change
       the trust flags.
    Tzfailed to update %s in %s: %sN)rrBZ
list_certsrKrCrZkey_policy_to_trust_flagsZadd_certr
rDr"r#)�pathr=Zdb�name�flagsZcertrFZtrustedZekuZtrust_flagsrGrrrrEs
rE)rT)+Z
__future__rZloggingrZurllib.parserZipalib.installrrZipalib.factsrZ	ipapythonrrr	r
ZipaplatformrZipaplatform.pathsrZipaplatform.tasksr
ZipalibrrrZipalib.constantsrrrZipalib.utilrZ	getLoggerr%r"Z	AdminToolrr!r4r5r8rArErrrr�<module>s(
&I0%