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: //usr/lib/python3.6/site-packages/ipaplatform/redhat/__pycache__/tasks.cpython-36.opt-1.pyc
3

�d[e�m�@s@dZddlmZmZddlZddlZddlZddlmZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZddlmZddl
mZddlmZdd	lmZdd
lmZddlZddlmZddlmZdd
lm Z ddl!m"Z"ej#e$�Z%dej&dgfgZ'ej(d�Z)eGdd�d��Z*Gdd�de"�Z+e+�Z,dS)zZ
This module contains default Red Hat OS family-specific implementations of
system tasks.
�)�print_function�absolute_importN)�Path)�find_library)�total_ordering)�CalledProcessError)�PyAsn1Error)�directivesetter)�ipautil)�	constants)�paths)�
get_auth_tool)�BaseTaskNamespaceZsofthsm2z
p11-kit-proxyz�
    # auto-generated by IPA installer
    [main]
    dns={dnsprocessing}

    [global-dns]
    searches={searches}

    [global-dns-domain-*]
    servers={servers}
c@sHeZdZdZedd��Zdd�Zedd��Zdd	�Z	d
d�Z
dd
�ZdS)�
IPAVersionNcCsH|j}|dkr>tjtd��}|j}tjtjg|_tj|_||_|||�S)z.Lazy load and call librpm's rpmvercmp
        NZrpm)	�_rpmvercmp_func�ctypesZCDLLrZ	rpmvercmpZc_char_pZargtypesZc_intZrestype)�cls�a�bZrpmvercmp_funcZlibrpm�r�/usr/lib/python3.6/tasks.py�
_rpmvercmpSszIPAVersion._rpmvercmpcCs||_|jd�|_dS)Nzutf-8)�_version�encode�_bytes)�self�versionrrr�__init__aszIPAVersion.__init__cCs|jS)N)r)rrrrreszIPAVersion.versioncCs"t|t�stS|j|j|j�dkS)Nr)�
isinstancer�NotImplementedrr)r�otherrrr�__eq__is
zIPAVersion.__eq__cCs"t|t�stS|j|j|j�dkS)Nr)rrrrr)rr rrr�__lt__ns
zIPAVersion.__lt__cCs
t|j�S)N)�hashr)rrrr�__hash__sszIPAVersion.__hash__)�__name__�
__module__�__qualname__r�classmethodrr�propertyrr!r"r$rrrrrOsrcsZeZdZdOdd�Zdd�Zejfdd�Zdd	�Zd
d�Z	dd
�Z
dd�ZdPdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�ZdQd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"dd)d@��fdAdB�
Z#dR�fdCdD�	Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(�fdMdN�Z)�Z*S)S�RedHatTaskNamespaceFcCsRtj}|j�stjj|�r"dS|g}|r6|jd�|j|�tj|dd�dS)aRestore SELinux security context on the given filepath.

        SELinux equivalent is /path/to/restorecon <filepath>
        restorecon's return values are not reliable so we have to
        ignore them (BZ #739604).

        ipautil.run() will do the logging.
        Nz-FF)Z
raiseonerr)	rZSBIN_RESTORECON�is_selinux_enabled�os�path�exists�appendr
�run)r�filepath�force�
restorecon�argsrrr�restore_contextys	

z#RedHatTaskNamespace.restore_contextcCsDytjtjg�Wn(tjk
r(dStk
r:dSXdSdS)z2Check if SELinux is available and enabled
        FTN)r
r0rZSELINUXENABLEDr�OSError)rrrrr+�sz&RedHatTaskNamespace.is_selinux_enabledcCs(|j�sdStjj|�s$td|��dS)a�
        We don't have a specific package requirement for policycoreutils
        which provides restorecon. This is because we don't require
        SELinux on client installs. However if SELinux is enabled then
        this package is required.

        This function returns nothing but may raise a Runtime exception
        if SELinux is enabled but restorecon is not available.
        FzoSELinux is enabled but %s does not exist.
Install the policycoreutils package and start the installation again.T)r+r,r-r.�RuntimeError)rr3rrr�check_selinux_status�s
z(RedHatTaskNamespace.check_selinux_statuscCs^tjjtj�std��y&tjddd�}|j�dkr:t	d��Wnt	k
rXtd��YnXdS)aChecks whether IPv6 kernel module is loaded.

        Function checks if /proc/net/if_inet6 is present. If IPv6 stack is
        enabled, it exists and contains the interfaces configuration.

        :raises: RuntimeError when IPv6 stack is disabled
        z�IPv6 stack has to be enabled in the kernel and some interface has to have ::1 address assigned. Typically this is 'lo' interface. If you do not wish to use IPv6 globally, disable it on the specific interfaces in sysctl.conf except 'lo' interface.z::1T)Zallow_loopbackNz"no interface for ::1 address foundz�IPv6 stack is enabled in the kernel but there is no interface that has ::1 address assigned. Add ::1 address resolution to 'lo' interface. You might need to enable IPv6 on the interface 'lo' in sysctl.conf.)
r,r-r.rZIF_INET6r7r
ZCheckedIPAddressZget_matching_interface�
ValueError)rZ
localhost6rrr�check_ipv6_stack_enabled�sz,RedHatTaskNamespace.check_ipv6_stack_enabledcCsbytjtjdgtjd�}Wn4tjk
rN}z|jdkr<dS�WYdd}~XnX|jd�j�SdS)zsCheck if running inside a container

        :returns: container runtime or None
        :rtype: str, None
        z--container)�stderr�Nzutf-8)	�
subprocessZcheck_outputrZSYSTEMD_DETECT_VIRTZSTDOUTr�
returncode�decode�strip)r�output�errr�detect_container�s
z$RedHatTaskNamespace.detect_containercCst�}|j||||�dS)N)r
Zunconfigure)r�fstore�
statestoreZwas_sssd_installedZwas_sssd_configured�auth_configrrr�$restore_pre_ipa_client_configuration�sz8RedHatTaskNamespace.restore_pre_ipa_client_configurationcCszy*ttjd��}dd�|D�}WdQRXWntk
rBg}YnX|jdj|��ttjd��}|j|�WdQRXdS)N�rcSs"g|]}|j�j�jd�s|�qS)Z	NISDOMAIN)r@�upper�
startswith)�.0�linerrr�
<listcomp>�sz5RedHatTaskNamespace.set_nisdomain.<locals>.<listcomp>z
NISDOMAIN={}
�w)�openrZSYSCONF_NETWORK�IOErrorr/�format�
writelines)rZ	nisdomain�f�contentrrr�
set_nisdomain�s
z!RedHatTaskNamespace.set_nisdomainTcCst�}|j|||||�dS)N)r
Z	configure)r�sssd�	mkhomedirrEZsudoZsubidrFrrr�modify_nsswitch_pam_stack�sz-RedHatTaskNamespace.modify_nsswitch_pam_stackcCsdS)NFr)rrrr�is_nosssd_supported�sz'RedHatTaskNamespace.is_nosssd_supportedcCst�}|j|�dS)N)r
Zbackup)rr-rFrrr�backup_auth_configurationsz-RedHatTaskNamespace.backup_auth_configurationcCst�}|j|�dS)N)r
Zrestore)rr-rFrrr�restore_auth_configurationsz.RedHatTaskNamespace.restore_auth_configurationcCs�|jdd�}tjdddg}|r(|jd�|jd�tj|�xdD]}|jd|�qBW|jddd�|jdd
d�|jddt|��dS)zg
        Migrate the pam stack configuration from authconfig to an authselect
        profile.
        Z
authconfigrWZselectrVz	with-sudozwith-mkhomedirz--force�ldap�krb5�sssdauthZ
authselectZprofileZ
features_list�N)r\r]rVr^rW)	Z	get_stater�
AUTHSELECTr/r
r0�
restore_state�backup_state�bool)rrErW�authselect_cmd�confrrr�migrate_auth_configurations




z.RedHatTaskNamespace.migrate_auth_configurationcCsRytjtjg�Wn,tk
r>}ztjd|�dSd}~XnXtjd�dSdS)Nz1Could not update systemwide CA trust database: %sFzSystemwide CA database updated.T)r
r0rZUPDATE_CA_TRUSTr�logger�error�info)rrBrrr�reload_systemwide_ca_store!s
z.RedHatTaskNamespace.reload_systemwide_ca_storecCst|jtj|�|jtj�g�S)N)�any�write_p11kit_certsr�IPA_P11_KIT�remove_ca_certificates_bundle�SYSTEMWIDE_IPA_CA_CRT)r�ca_certsrrr�platform_insert_ca_certs,sz,RedHatTaskNamespace.platform_insert_ca_certsc.Cs&ddlm}ddlm}t|�}yt|d�}Wn"tk
rPtjd|��YnX|���|j	d�yt
j|j�d�Wn"tk
r�tjd|��YnXt
�}�xr|D�]h\}}	}
}y|j}|j}
|j}|j}Wn(tt|fk
r�tjd	|	��YnXtjj|	�}tjj|�}tjj|
�}
tjj|�}tjj|�}d
t|||
||d�}|
dk�rd|d
7}n|
dk�rv|d7}|dj|j|jj�jd�d�7}|j	|�|jdk	r�||kr�y
|j}Wn$tk
�r�tjd|	��YnXtjj|�}dt|||d�}|j	|�|j|�q�WWdQRXdS)Nr)�x509)�CertificateErrorrNzFailed to open %sz.# This file was created by IPA. Do not edit.

i�zFailed to set mode of %sz!Failed to decode certificate "%s"z�[p11-kit-object-v1]
class: certificate
certificate-type: x-509
certificate-category: authority
label: "%(label)s"
subject: "%(subject)s"
issuer: "%(issuer)s"
serial-number: "%(serial_number)s"
x-public-key-info: "%(public_key_info)s"
)�label�subject�issuer�
serial_number�public_key_infoTztrusted: true
Fzx-distrusted: true
z{pem}

�ascii)Zpemz,Failed to encode extended key usage for "%s"z�[p11-kit-object-v1]
class: x-certificate-extension
label: "ExtendedKeyUsage for %(label)s"
x-public-key-info: "%(public_key_info)s"
object-id: 2.5.29.37
value: "%(value)s"

)rtrx�value) ZipalibrrZ
ipalib.errorsrsrrOrPrgrh�writer,�fchmod�fileno�setZ
subject_bytesZissuer_bytesZserial_number_bytesZpublic_key_info_bytesrr9�urllib�parseZquote�dictrQZpublic_bytesZEncodingZPEMr?Zextended_key_usageZextended_key_usage_bytes�add)r�filenamerprrrsr-rSZhas_ekuZcertZnicknameZtrustedZ_ext_key_usagerurvrwrxrt�objZ
ext_key_usagerzrrrrl4sz

	








z&RedHatTaskNamespace.write_p11kit_certscCst|jtj�|jtj�g�S)N)rkrnrrmro)rrrr�platform_remove_ca_certs�s
z,RedHatTaskNamespace.platform_remove_ca_certscCsHt|�}|j�sdSy|j�Wn"tk
rBtjd|��YnXdS)NFzCould not remove %sT)r�is_file�unlink�	Exceptionrgrh)rr�r-rrrrn�sz1RedHatTaskNamespace.remove_ca_certificates_bundlecCs6tj}tjj|�r|j|�tj�}|jdd|�dS)N�network�hostname)	r�ETC_HOSTNAMEr,r-r.�backup_file�socketZgethostnamerb)rrDrEr1�old_hostnamerrr�backup_hostname�s

z#RedHatTaskNamespace.backup_hostnamecCs�|jdd�}|dk	rfy|j|�WnBtjk
rd}z$tjdtj��tjd||�WYdd}~XnXt	j
}|j|�r�|j|�dS)Nr�r�z%sz3Failed to restore this machine hostname to %s (%s).)
ra�set_hostnamer
rrg�debug�	traceback�
format_excrhrr��has_file�restore_file)rrDrEr�rBr1rrr�restore_hostname�s
z$RedHatTaskNamespace.restore_hostnameNcCs dd�}|j�sdSi}i}x�|j�D]�\}}|dkr8q&yHtjtj|gdd�}|jj�d}	|dk	rn|||	�|	|kr~|||<Wq&tjk
r�}
zt	j
d||
�|||<WYdd}
~
Xq&Xq&W|r�||�}ytj|�Wn tjk
r�|j|�YnX|�rtj
j|dj||��d	��dS)
NcSs&tjdg}|jdd�|j�D��|S)Nz-PcSsg|]}d|�qS)z%s=%sr)rK�updaterrrrM�szXRedHatTaskNamespace.set_selinux_booleans.<locals>.get_setsebool_args.<locals>.<listcomp>)rZ	SETSEBOOL�extend�items)Zchangesr4rrr�get_setsebool_args�s
zDRedHatTaskNamespace.set_selinux_booleans.<locals>.get_setsebool_argsFT)Zcapture_output�z#Cannot get SELinux boolean '%s': %s� )ZfailedZcommand)r+r�r
r0rZ	GETSEBOOLrA�splitrrgrhr��	ipapython�errorsZSetseboolError�join)rZrequired_settingsZbackup_funcr�Zupdated_varsZfailed_varsZsetting�state�resultZoriginal_staterBr4rrr�set_selinux_booleans�s>
z(RedHatTaskNamespace.set_selinux_booleanscCst|�S)z�
        :param version: textual version
        :return: object implementing proper __cmp__ method for version compare
        )r)rrrrr�parse_ipa_version�sz%RedHatTaskNamespace.parse_ipa_versioncCsntjjtj�stjtjd�tjtjjtj	d�tj
ttjtj
tjd��tjtj
d�|jtj
�|j�dS)zACreate systemd config for httpd service to work with IPA
        i�zipa-httpd.conf.template)�KDCPROXY_CONFIG�IPA_HTTPD_KDCPROXY�KRB5CC_HTTPDi�N)r,r-r.rZSYSTEMD_SYSTEM_HTTPD_D_DIR�mkdirr
�copy_template_filer��USR_SHARE_IPA_DIR�SYSTEMD_SYSTEM_HTTPD_IPA_CONFr�r�r�r��chmodr5�systemd_daemon_reload)rrrr� configure_httpd_service_ipa_conf�sz4RedHatTaskNamespace.configure_httpd_service_ipa_confcCstjtjddg�dS)z#Tell systemd to reload config filesz--systemz
daemon-reloadN)r
r0rZ	SYSTEMCTL)rrrrr�sz)RedHatTaskNamespace.systemd_daemon_reloadc	CsLtjtjjtjd�tjttj	t
j|tjd��tj
tjd�|jtj�dS)Nzgssproxy.conf.template)�HTTP_KEYTAB�
HTTPD_USERZIPAAPI_USERZSWEEPER_SOCKETi�)r
r�r,r-r�rr�Z
GSSPROXY_CONFr�r�rr�Z IPA_CCACHE_SWEEPER_GSSPROXY_SOCKr�r5)rZipauserrrr�configure_http_gssproxy_confsz0RedHatTaskNamespace.configure_http_gssproxy_confcCs�tj}tjjdkrtj}ntj}|dks0|dkr>tj	d�dSt
jj|�}t
jj
|�s`t
j|�tjt
jjtjd�|t|d��t
j|d�|j|�dS)zmConfigure WSGI for correct Python version (Fedora)

        See https://pagure.io/freeipa/issue/7394
        r�Nz+Nothing to do for configure_httpd_wsgi_confzipa-httpd-wsgi.conf.template)ZWSGI_MODULEi�)rZHTTPD_IPA_WSGI_MODULES_CONF�sys�version_info�majorrZMOD_WSGI_PYTHON2ZMOD_WSGI_PYTHON3rgrir,r-�dirname�isdir�makedirsr
r�r�r�r�r�r5)rreZwsgi_moduleZconfdirrrr�configure_httpd_wsgi_confs"

z-RedHatTaskNamespace.configure_httpd_wsgi_confcCsjytjtj�WnLtk
r\}z0|jtjkr>tjdtj�ntj	dtj|�dSd}~XnX|j
�dS)z.Remove systemd config for httpd service of IPAz+Trying to remove %s but file does not existzError removing %s: %sN)r,r�rr�r6�errno�ENOENTrgr�rhr�)rrBrrr�remove_httpd_service_ipa_conf1s

z1RedHatTaskNamespace.remove_httpd_service_ipa_confcCstjtjddd�dS)NZSSLProtocolF)r	�
set_directiver�HTTPD_SSL_CONF)rrrr�configure_httpd_protocolDsz,RedHatTaskNamespace.configure_httpd_protocolcCstjtjd|g�dS)Nzset-hostname)r
r0rZBIN_HOSTNAMECTL)rr�rrrr�Jsz RedHatTaskNamespace.set_hostnamecCsJy0ttjd��}|j�j�dkr$dSWdQRXWntk
rDYnXdS)aA
        Checks whether this host is FIPS-enabled.

        Returns a boolean indicating if the host is FIPS-enabled, i.e. if the
        file /proc/sys/crypto/fips_enabled contains a non-0 value. Otherwise,
        or if the file /proc/sys/crypto/fips_enabled does not exist,
        the function returns False.
        rH�0TNF)rOrZPROC_FIPS_ENABLED�readr@rP)rrSrrr�is_fips_enabledMs	z#RedHatTaskNamespace.is_fips_enabledcCs(tjtjddd�tjtjddd�dS)NZErrorLogzlogs/error_logFZTransferLogzlogs/access_log)r	r�rr�)rrrr�setup_httpd_logging`sz'RedHatTaskNamespace.setup_httpd_logging)�resolve1_enabledrDcsBt�j||||d�ddlm}|dk	rB|jtj�rB|jtj�|d}|j�}|r�t	j
dtj�|rnd}nd}tj
|d	j|�d	j|�d
�}	ttjd�� }
tj|
j�d�|
j|	�WdQRX|j�|o�|�r>t	j
d
tj�ddj
dj|��g}	x|D]}|	jdj
|��q�Wttjd��}
|
jdj|	��WdQRXdS)z�Configure global DNS resolver (e.g. /etc/resolv.conf)

        :param nameservers: list of IP addresses
        :param searchdomains: list of search domaons
        :param fstore: optional file store for backup
        )�nameservers�
searchdomainsr�rDr)�
knownservicesN�NetworkManagerz$Network Manager is enabled, write %szsystemd-resolved�default�,)�
dnsprocessingZserversZsearchesrNi�zLNeither Network Manager nor systemd-resolved are enabled, write %s directly.z!# auto-generated by IPA installerz	search {}r�z
nameserver {}�
)�super�configure_dns_resolver�ipaplatform.servicesr�r�rZRESOLV_CONFr��
is_enabledrgr��NETWORK_MANAGER_IPA_CONF�NM_IPA_CONFrQr�rOr,r|r}r{�reload_or_restartr/)rr�r�r�rDr��nmZ
nm_enabledr�ZcfgrSZ
nameserver)�	__class__rrr�hsF
z*RedHatTaskNamespace.configure_dns_resolvercsPt�j|d�ddlm}|d}tjjtj�rLtj	tj�|j
�rL|j�dS)zxUnconfigure global DNS resolver (e.g. /etc/resolv.conf)

        :param fstore: optional file store for restore
        )rDr)r�r�N)r��unconfigure_dns_resolverr�r�r,r-�isfilerr�r�r�r�)rrDr�r�)r�rrr��sz,RedHatTaskNamespace.unconfigure_dns_resolverc
Csg}x�tD]�\}}}tjjtjdj|��}tjj|�r�t|��}|j	�}WdQRXd|k}	|	r�|j
|�r�tjd|�|j
|�t|d��F}|jd�|jdj|��|jdjd	j|���tj|j�d
�WdQRX|j|�tjd|�|j|�q
W|S)z5Disable global p11-kit configuration for NSS
        z	{}.moduleNZIPAzBacking up existing '%s'.rNz# created by IPA installer
zmodule: {}
zdisable-in: {}
z, i�z#Created PKCS#11 module config '%s'.)�PKCS11_MODULESr,r-r�r�ETC_PKCS11_MODULES_DIRrQr�rOr�r�rgr�r�r{r|r}r5r/)
rrD�	filenames�name�moduleZdisabled_inr�rSrTZis_ipa_filerrr�configure_pkcs11_modules�s*



z,RedHatTaskNamespace.configure_pkcs11_modulescCstg}xjtD]b\}}}tjjtjdj|��}ytj|�Wntk
rLYnX|j	|�|j
|�r
|j|�q
W|S)z5Restore global p11-kit configuration for NSS
        z	{}.module)r�r,r-r�rr�rQr�r6r/r�r�)rrDr�r��_moduleZ_disabled_inr�rrr�restore_pkcs11_modules�s

z*RedHatTaskNamespace.restore_pkcs11_modulescCstdd�tD��S)z<Return the list of module config files setup by IPA
        css*|]"\}}}tjjtjdj|��VqdS)z	{}.moduleN)r,r-r�rr�rQ)rKr�r�Z	_disabledrrr�	<genexpr>�sz9RedHatTaskNamespace.get_pkcs11_modules.<locals>.<genexpr>)�tupler�)rrrr�get_pkcs11_modules�sz&RedHatTaskNamespace.get_pkcs11_modulescCsdS)z(sudo enablement is handled by authselectNr)rZ_fstorerrr�enable_sssd_sudo�sz$RedHatTaskNamespace.enable_sssd_sudocsZtt|�j|�tjddg}ytj|�Wn*tjk
rTtj	d�tj	d�YnXdS)zDisable ldap-based automountzdisable-featurezwith-custom-automountz/Unable to disable with-custom-automount featurezRIt may happen if the configuration was done using authconfig instead of authselectN)
r�r*�disable_ldap_automountrr`r
r0rrgri)rrErd)r�rrr��s
z*RedHatTaskNamespace.disable_ldap_automount)F)TF)N)N)+r%r&r'r5r+rZ
RESTORECONr8r:rCrGrUrXrYrZr[rfrjrqrlr�rnr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��
__classcell__rr)r�rr*wsJ
	
X
	
,	Dr*)-�__doc__Z
__future__rrrZloggingr,Zpathlibrr�r�r�rr=r��textwrapZctypes.utilr�	functoolsrrZpyasn1.errorrr�r	r
Zipapython.errorsZipaplatform.constantsrZipaplatform.pathsrZipaplatform.redhat.authconfigr
Zipaplatform.base.tasksrZ	getLoggerr%rgZLIBSOFTHSM2_SOr��dedentr�rr*Ztasksrrrr�<module>sF

(