HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //lib/python3.9/site-packages/ipaplatform/redhat/__pycache__/tasks.cpython-39.pyc
a

�N(i�m�@s@dZddlmZmZddlZddlZddlZddlmZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZddlmZddl
mZddlmZdd	lmZdd
lmZddlZddlmZddlmZdd
lm Z ddl!m"Z"e�#e$�Z%dej&dgfgZ'e�(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}|dur>t�td��}|j}tjtjg|_tj|_||_|||�S)z.Lazy load and call librpm's rpmvercmp
        NZrpm)	�_rpmvercmp_func�ctypesZCDLLrZ	rpmvercmpZc_char_p�argtypesZc_intZrestype)�cls�a�bZrpmvercmp_funcZlibrpm�r�</usr/lib/python3.9/site-packages/ipaplatform/redhat/tasks.py�
_rpmvercmpSszIPAVersion._rpmvercmpcCs||_|�d�|_dS)N�utf-8)�_version�encode�_bytes��self�versionrrr�__init__aszIPAVersion.__init__cCs|jS�N)r�rrrrreszIPAVersion.versioncCs"t|t�stS|�|j|j�dkS�Nr��
isinstancer�NotImplementedrr�r�otherrrr�__eq__is
zIPAVersion.__eq__cCs"t|t�stS|�|j|j�dkSr#r$r'rrr�__lt__ns
zIPAVersion.__lt__cCs
t|j�Sr!)�hashrr"rrr�__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�RedHatTaskNamespaceFcCsNtj}|��rtj�|�sdS|g}|r2|�d�|�|�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_contextcCsDzt�tjg�Wn(tjy(YdSty:YdS0dSdS)z2Check if SELinux is available and enabled
        FTN)r
r8rZSELINUXENABLEDr�OSErrorr"rrrr3�sz&RedHatTaskNamespace.is_selinux_enabledcCs(|��sdStj�|�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)r3r4r5r6�RuntimeError)rr;rrr�check_selinux_status�s
�z(RedHatTaskNamespace.check_selinux_statuscCs\tj�tj�std��z&tjddd�}|��dur:t	d��Wnt	yVtd��Yn0dS)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.)
r4r5r6rZIF_INET6r?r
ZCheckedIPAddressZget_matching_interface�
ValueError)rZ
localhost6rrr�check_ipv6_stack_enabled�s��z,RedHatTaskNamespace.check_ipv6_stack_enabledc
Csnztjtjdgtjd�}Wn@tjyZ}z&|jdkrDWYd}~dS�WYd}~nd}~00|�d���SdS)zsCheck if running inside a container

        :returns: container runtime or None
        :rtype: str, None
        z--container)�stderr�Nr)	�
subprocessZcheck_outputrZSYSTEMD_DETECT_VIRTZSTDOUTr�
returncode�decode�strip)r�output�errr�detect_container�s�

z$RedHatTaskNamespace.detect_containercCst�}|�||||�dSr!)r
Zunconfigure)r�fstore�
statestoreZwas_sssd_installedZwas_sssd_configured�auth_configrrr�$restore_pre_ipa_client_configuration�s�z8RedHatTaskNamespace.restore_pre_ipa_client_configurationcCs�z>ttjd��}dd�|D�}Wd�n1s20YWntyTg}Yn0|�d�|��ttjd��}|�|�Wd�n1s�0YdS)N�rcSs"g|]}|�����d�s|�qS)Z	NISDOMAIN)rH�upper�
startswith)�.0�linerrr�
<listcomp>�s�z5RedHatTaskNamespace.set_nisdomain.<locals>.<listcomp>z
NISDOMAIN={}
�w)�openrZSYSCONF_NETWORK�IOErrorr7�format�
writelines)rZ	nisdomain�f�contentrrr�
set_nisdomain�s�(
z!RedHatTaskNamespace.set_nisdomainTcCst�}|�|||||�dSr!)r
Z	configure)r�sssd�	mkhomedirrMZsudoZsubidrNrrr�modify_nsswitch_pam_stack�sz-RedHatTaskNamespace.modify_nsswitch_pam_stackcCsdS)NFrr"rrr�is_nosssd_supported�sz'RedHatTaskNamespace.is_nosssd_supportedcCst�}|�|�dSr!)r
Zbackup�rr5rNrrr�backup_auth_configurationsz-RedHatTaskNamespace.backup_auth_configurationcCst�}|�|�dSr!)r
Zrestorerbrrr�restore_auth_configurationsz.RedHatTaskNamespace.restore_auth_configurationcCs�|�dd�}tjdddg}|r(|�d�|�d�t�|�dD]}|�d|�q@|�d	d
d�|�d	dd�|�d	dt|��d
S)zg
        Migrate the pam stack configuration from authconfig to an authselect
        profile.
        Z
authconfigr_Zselectr^z	with-sudozwith-mkhomedirz--force)ZldapZkrb5r^Zsssdauthr_Z
authselectZprofileZ
features_list�N)	Z	get_stater�
AUTHSELECTr7r
r8�
restore_state�backup_state�bool)rrMr_�authselect_cmd�confrrr�migrate_auth_configurations


�z.RedHatTaskNamespace.migrate_auth_configurationc
CsXzt�tjg�Wn2tyD}zt�d|�WYd}~dSd}~00t�d�dSdS)Nz1Could not update systemwide CA trust database: %sFzSystemwide CA database updated.T)r
r8rZUPDATE_CA_TRUSTr�logger�error�info�rrJrrr�reload_systemwide_ca_store!s�
z.RedHatTaskNamespace.reload_systemwide_ca_storecCst|�tj|�|�tj�g�Sr!)�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Cs0ddlm}ddlm}t|�}zt|d�}Wn tyNt�d|��Yn0|���|�	d�zt
�|��d�Wn ty�t�d|��Yn0t
�}|D�]f\}}	}
}}z|j}
|j}|j}|j}Wn&tt|fy�t�d	|	��Yn0tj�|	�}tj�|
�}
tj�|�}tj�|�}tj�|�}d
t||
|||d�}|
du�r\|d
7}n|
du�rn|d7}|dj|�|jj��d�d�7}|�	|�|jdur�||vr�z
|j}Wn"t�y�t�d|	��Yn0tj�|�}dt|||d�}|�	|�|�|�q�Wd�n1�s"0YdS)Nr)�x509)�CertificateErrorrVzFailed to open %sz.# This file was created by IPA. Do not edit.

�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"

)r|r��value) ZipalibryZ
ipalib.errorsrzrrWrXrmrn�writer4�fchmod�fileno�setZ
subject_bytesZissuer_bytesZserial_number_bytesZpublic_key_info_bytesrrA�urllib�parse�quote�dictrYZpublic_bytesZEncodingZPEMrGZextended_key_usageZextended_key_usage_bytes�add)r�filenamerwryrzr5r[Zhas_ekuZcertZnicknameZtrustedZ_ext_key_usageZ_serialr}r~rr�r|�objZ
ext_key_usager�rrrrs4s�

�	��


�

�
���	
,z&RedHatTaskNamespace.write_p11kit_certscCst|�tj�|�tj�g�Sr!)rrrurrtrvr"rrr�platform_remove_ca_certs�s

�z,RedHatTaskNamespace.platform_remove_ca_certscCsFt|�}|��sdSz|��Wn ty@t�d|��Yn0dS)NFzCould not remove %sT)r�is_file�unlink�	Exceptionrmrn)rr�r5rrrru�sz1RedHatTaskNamespace.remove_ca_certificates_bundlecCs6tj}tj�|�r|�|�t��}|�dd|�dS)N�network�hostname)	r�ETC_HOSTNAMEr4r5r6�backup_file�socketZgethostnamerh)rrLrMr9�old_hostnamerrr�backup_hostname�s

z#RedHatTaskNamespace.backup_hostnamec
Cs�|�dd�}|durhz|�|�WnDtjyf}z*t�dt���t�d||�WYd}~n
d}~00t	j
}|�|�r�|�|�dS)Nr�r�z%sz3Failed to restore this machine hostname to %s (%s).)
rg�set_hostnamer
rrm�debug�	traceback�
format_excrnrr��has_file�restore_file)rrLrMr�rJr9rrr�restore_hostname�s�
z$RedHatTaskNamespace.restore_hostnameNcCsdd�}|��sdSi}i}|��D]�\}}|dur6q$zHtjtj|gdd�}|j��d}	|durl|||	�|	|kr||||<Wq$tjy�}
z"t	�
d||
�|||<WYd}
~
q$d}
~
00q$|r�||�}zt�|�Wntjy�|�|�Yn0|�rtj
j|d�||��d	��dS)
NcSs&tjdg}|�dd�|��D��|S)Nz-PcSsg|]}d|�qS)z%s=%sr)rS�updaterrrrU��zXRedHatTaskNamespace.set_selinux_booleans.<locals>.get_setsebool_args.<locals>.<listcomp>)rZ	SETSEBOOL�extend�items)Zchangesr<rrr�get_setsebool_args�s
zDRedHatTaskNamespace.set_selinux_booleans.<locals>.get_setsebool_argsFT)Zcapture_output�z#Cannot get SELinux boolean '%s': %s� )ZfailedZcommand)r3r�r
r8rZ	GETSEBOOLrI�splitrrmrnr��	ipapython�errorsZSetseboolError�join)rZrequired_settingsZbackup_funcr�Zupdated_varsZfailed_varsZsetting�state�resultZoriginal_staterJr<rrr�set_selinux_booleans�sB�
 �z(RedHatTaskNamespace.set_selinux_booleanscCst|�S)z�
        :param version: textual version
        :return: object implementing proper __cmp__ method for version compare
        )rrrrr�parse_ipa_version�sz%RedHatTaskNamespace.parse_ipa_versionc	Csntj�tj�st�tjd�t�tj�tj	d�tj
ttjtj
tjd��t�tj
d�|�tj
�|��dS)zACreate systemd config for httpd service to work with IPA
        i�zipa-httpd.conf.template)�KDCPROXY_CONFIG�IPA_HTTPD_KDCPROXY�KRB5CC_HTTPDr{N)r4r5r6rZSYSTEMD_SYSTEM_HTTPD_D_DIR�mkdirr
�copy_template_filer��USR_SHARE_IPA_DIR�SYSTEMD_SYSTEM_HTTPD_IPA_CONFr�r�r�r��chmodr=�systemd_daemon_reloadr"rrr� configure_httpd_service_ipa_conf�s��
z4RedHatTaskNamespace.configure_httpd_service_ipa_confcCst�tjddg�dS)z#Tell systemd to reload config filesz--systemz
daemon-reloadN)r
r8rZ	SYSTEMCTLr"rrrr�sz)RedHatTaskNamespace.systemd_daemon_reloadc
CsLt�tj�tjd�tjttj	t
j|tjd��t�
tjd�|�tj�dS)Nzgssproxy.conf.template)�HTTP_KEYTAB�
HTTPD_USERZIPAAPI_USERZSWEEPER_SOCKETi�)r
r�r4r5r�rr�Z
GSSPROXY_CONFr�r�rr�Z IPA_CCACHE_SWEEPER_GSSPROXY_SOCKr�r=)rZipauserrrr�configure_http_gssproxy_confs��z0RedHatTaskNamespace.configure_http_gssproxy_confcCs�tj}tjjdkrtj}ntj}|dus0|dur>t�	d�dSt
j�|�}t
j�
|�s`t
�|�t�t
j�tjd�|t|d��t
�|d�|�|�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_MODULEr{)rZHTTPD_IPA_WSGI_MODULES_CONF�sys�version_info�majorrZMOD_WSGI_PYTHON2ZMOD_WSGI_PYTHON3rmror4r5�dirname�isdir�makedirsr
r�r�r�r�r�r=)rrkZwsgi_moduleZconfdirrrr�configure_httpd_wsgi_confs&

��z-RedHatTaskNamespace.configure_httpd_wsgi_confc
Cspzt�tj�WnRtyb}z:|jtjkr<t�dtj�nt�	dtj|�WYd}~dSd}~00|�
�dS)z.Remove systemd config for httpd service of IPAz+Trying to remove %s but file does not existzError removing %s: %sN)r4r�rr�r>�errno�ENOENTrmr�rnr�rprrr�remove_httpd_service_ipa_conf1s��z1RedHatTaskNamespace.remove_httpd_service_ipa_confcCst�tjddd�dS)NZSSLProtocolF�r	Z
set_directiverZHTTPD_SSL_CONFr"rrr�configure_httpd_protocolDs
�z,RedHatTaskNamespace.configure_httpd_protocolcCst�tjd|g�dS)Nzset-hostname)r
r8rZBIN_HOSTNAMECTL)rr�rrrr�Jsz RedHatTaskNamespace.set_hostnamecCsjzRttjd��2}|����dkr2Wd�WdSWd�n1sF0YWntydYn0dS)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.
        rP�0NTF)rWrZPROC_FIPS_ENABLED�readrHrX)rr[rrr�is_fips_enabledMs	4z#RedHatTaskNamespace.is_fips_enabledcCs(t�tjddd�t�tjddd�dS)NZErrorLogzlogs/error_logFZTransferLogzlogs/access_logr�r"rrr�setup_httpd_logging`s��z'RedHatTaskNamespace.setup_httpd_logging)�resolve1_enabledrLcs�|rt|t�sJ�|r t|t�s$J�t�j||||d�ddlm}|durd|�tj�sd|�	tj�|d}|�
�}|r�t�dtj
�|r�d}nd}tj|d	�|�d	�|�d
�}	ttj
d��*}
t�|
��d�|
�|	�Wd�n1s�0Y|��|�s�|�s�t�d
tj�dd�d�|��g}	|D]}|	�d�|���q0ttjd�� }
|
�d�|	��Wd�n1�s|0YdS)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�rLr��
knownservicesN�NetworkManagerz$Network Manager is enabled, write %szsystemd-resolved�default�,)�
dnsprocessingZserversZsearchesrVr{zLNeither Network Manager nor systemd-resolved are enabled, write %s directly.z!# auto-generated by IPA installerz	search {}r�z
nameserver {}�
)r%�list�super�configure_dns_resolver�ipaplatform.servicesr�r�rZRESOLV_CONFr��
is_enabledrmr��NETWORK_MANAGER_IPA_CONF�NM_IPA_CONFrYr�rWr4r�r�r��reload_or_restartr7)rr�r�r�rLr��nmZ
nm_enabledr�Zcfgr[Z
nameserver��	__class__rrr�hsT���(��z*RedHatTaskNamespace.configure_dns_resolvercsPt�j|d�ddlm}|d}tj�tj�rLt�	tj�|�
�rL|��dS)zxUnconfigure global DNS resolver (e.g. /etc/resolv.conf)

        :param fstore: optional file store for restore
        )rLrr�r�N)r��unconfigure_dns_resolverr�r�r4r5�isfilerr�r�r�r�)rrLr�r�r�rrr��sz,RedHatTaskNamespace.unconfigure_dns_resolverc
	Cs"g}tD�]\}}}tj�tjd�|��}tj�|�r�t|��}|�	�}Wd�n1s\0Yd|v}	|	s�|�
|�s�t�d|�|�
|�t|d��P}|�d�|�d�|��|�d�d	�|���t�|��d
�Wd�n1s�0Y|�|�t�d|�|�|�q|S)z5Disable global p11-kit configuration for NSS
        �	{}.moduleNZIPAzBacking up existing '%s'.rVz# created by IPA installer
zmodule: {}
zdisable-in: {}
z, r{z#Created PKCS#11 module config '%s'.)�PKCS11_MODULESr4r5r�r�ETC_PKCS11_MODULES_DIRrYr�rWr�r�rmr�r�r�r�r�r=r7)
rrL�	filenames�name�moduleZdisabled_inr�r[r\Zis_ipa_filerrr�configure_pkcs11_modules�s,�
&

.
z,RedHatTaskNamespace.configure_pkcs11_modulesc	Csng}tD]`\}}}tj�tjd�|��}zt�|�WntyHYn0|�	|�|�
|�r|�|�q|S)z5Restore global p11-kit configuration for NSS
        r�)r�r4r5r�rr�rYr�r>r7r�r�)rrLr�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*|]"\}}}tj�tjd�|��VqdS)r�N)r4r5r�rr�rY)rSr�r�Z	_disabledrrr�	<genexpr>�s�
�z9RedHatTaskNamespace.get_pkcs11_modules.<locals>.<genexpr>)�tupler�r"rrr�get_pkcs11_modules�s�z&RedHatTaskNamespace.get_pkcs11_modulescCsdS)z(sudo enablement is handled by authselectNr)rZ_fstorerrr�enable_sssd_sudo�sz$RedHatTaskNamespace.enable_sssd_sudocsXtt|��|�tjddg}zt�|�Wn(tjyRt�	d�t�	d�Yn0dS)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�r2�disable_ldap_automountrrfr
r8rrmro)rrMrjr�rrr��s�
z*RedHatTaskNamespace.disable_ldap_automount)F)TF)N)N)+r-r.r/r=r3rZ
RESTORECONr@rBrKrOr]r`rarcrdrlrqrxrsr�rur�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��
__classcell__rrr�rr2wsN
	�
X
	
,	�Er2)-�__doc__Z
__future__rrrZloggingr4�pathlibrr�r�r�r�rEr��textwrapZctypes.utilr�	functoolsrrZpyasn1.errorrr�r	r
Zipapython.errorsZipaplatform.constantsrZipaplatform.pathsrZipaplatform.redhat.authconfigr
Zipaplatform.base.tasksrZ	getLoggerr-rmZLIBSOFTHSM2_SOr��dedentr�rr2Ztasksrrrr�<module>sH
�

'