HEX
Server: LiteSpeed
System: Linux w5304130.sdnsbox.com 4.18.0-425.3.1.lve.el8.x86_64 #1 SMP Tue Nov 22 22:59:23 EST 2022 x86_64
User: makefitmeserver (1001)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/up2date_client/__pycache__/rhnreg.cpython-36.pyc
3

U��Z(X�@s�ddlZddlZddlZddlmZddlmZddlmZddlmZddlmZddlm	Z	ddlm
Z
dd	lmZdd
l
mZddlmZmZddlmZy4ddlZddlZdd
lmZmZmZmZmZmZWnFek
�rddljZddl j!Ze"Ze#Ze$Ze%Ze&Ze&Ze'Z(YnXyddl)m*Z*Wnek
�rFdZ*YnXddl+Z+e+j,ddd�Z-e.e-d��sre-j+e-_/e-j/Z0dZ1de1Z2de1Z3dZ4ddlm5Z5e5j6�Z7ej8�Z9dd�Z:dd�Z;dd�Z<dd�Z=d d!�Z>d"d#�Z?d$d%�Z@d&d'�ZAd(d)�ZBd*d+�ZCd,d-�ZDd.d/�ZEd0d1�ZFd2d3�ZGd4d5�ZHd6d7�ZIGd8d9�d9�ZJd^d:d;�ZKd<d=�ZLd>d?�ZMdddddifd@dA�ZNdBdC�ZOdDdE�ZPdFdG�ZQdHdI�ZRdJdK�ZSdLdM�ZTd_dNdO�ZUGdPdQ�dQ�ZVdRdS�ZWdTdU�ZXd`dVdW�ZYdXdY�ZZe�dZk�r�d[d\�Z[ndd]l\m[Z[dS)a�N)�up2dateUtils)�
up2dateErrors)�	rhnserver)�pkgUtils)�
up2dateLog)�rhnreg_constants)�hardware)�convertPackagesFromHashToList)�getPlatform)�ustr�sstr)�
raise_with_tb)�ListType�	TupleType�
StringType�UnicodeType�DictType�DictionaryType)�supportzrhn-client-toolsT)Zfallback�ugettextz/etc/sysconfig/rhnz%s/rhn_register_remindz%s/hw-activation-codez/etc/pki/consumer/cert.pem)�configcCs�tjdtjtjB�r�tjdtj�rZtjdtjtjB�rLtjd�tjd�q�ttd��n|tjdtjtjB�rztjd�nttd	��d
}tj|tjtjB�s�tjdtjtjB�r�d}tjd|�}|r�tjd
|�dS)Nz/usr/sbin/rhnsdz%/usr/lib/systemd/system/rhnsd.servicez/usr/bin/systemctlz+/usr/bin/systemctl enable rhnsd > /dev/nullz*/usr/bin/systemctl start rhnsd > /dev/nullz,Warning: unable to enable rhnsd with systemdz/sbin/chkconfigz$/sbin/chkconfig rhnsd on > /dev/nullz.Warning: unable to enable rhnsd with chkconfigz
/sbin/servicez/usr/sbin/servicez%s rhnsd status > /dev/nullz%s rhnsd start > /dev/null)�os�access�R_OK�X_OK�system�print�_)Zservice_pathZrc�r�/usr/lib/python3.6/rhnreg.py�
startRhnsdBs 
r cCs�tdp
d}tj|tj�siSt|d�}|j�}i}x`|D]X}|j�}|dkrPq:y|jd�\}}Wn"tk
r�t	t
j|��YnX|j�||<q:W|S)NZoemInfoFilez/etc/sysconfig/rhn/oeminfo�r��:)�cfgrrr�open�	readlines�strip�split�
ValueErrorr
rZOemInfoFileError)Z
configFile�fd�L�info�i�key�valuerrr�
getOemInfo\s 

r0cCs*tjttj�r"tjt�}|jdkSdSdS)z@ Returns true if system is registred using subscription manager rFN)rr�	RHSM_FILEr�stat�st_size)Zstatinforrr�rhsm_registeredss

r4cCstjtdtj�S)N�systemIdPath)rrr$rrrrr�
registered{sr6cCs$tjttj�s ttd�}|j�dS)Nzw+)rr�REMIND_FILErr%�close)r*rrr�createSystemRegisterRemindFile~s
r9cCstjttj�rtjt�dS)N)rrr7r�unlinkrrrr�removeSystemRegisterRemindFile�sr;cCs�tjj|�}tj|tj�sdStj|tj�rLytj||d�Wn
dStj|tjtj	Bt
dd��}tj|d�}z|jt
|��Wd|j�XdS)z; Write a file to disk that is not readable by other users. Fz.saveZ0600��wNT)r�path�dirnamer�W_OK�F_OK�renamer%�O_WRONLY�O_CREAT�int�fdopen�writerr8)Zsecure_fileZ
file_contentsZdir_namer*Zfd_filerrr�_write_secure_file�s
rHcCs"ttd|�}|rt�t�|S)Nr5)rHr$r;�updateRhsmStatus)�systemId�resrrr�
writeSystemId�s
rLcCstt|d�S)z=Returns True if the write is successful or False if it fails.�
)rH�HW_CODE_FILE)�hw_activation_coderrr�writeHWCode�srPcCspy"tjjd�r t�\}}||fSWntk
r6YnXt�\}}|dk	rR||fSt�\}}|dk	rl||fSdS)a�
    This function returns the UUID and virtualization type of this system, if
    it is a guest.  Otherwise, it returns None.  To figure this out, we'll
    use a number of heuristics (list in order of precedence):

       1.  Check /proc/xen/xsd_port.  If exists, we know the system is a
           host; exit.
       2.  Check SMBIOS.  If vendor='Xen' and UUID is non-zero, we know the
           system is a fully-virt guest; exit.
       3.  Check /sys/hypervisor/uuid.  If exists and is non-zero, we know
           the system is a para-virt guest; exit.
       4.  If non of the above checks worked; we know we have a
           non-xen-enabled system; exit.
    z/proc/xen/xsd_portN)NN)rr>�exists�get_fully_virt_info�IOError�get_para_virt_info)�uuid�	virt_typerrr�
get_virt_info�s


rWcCsVy<tdd�}|j�}|j�|j�jdd�jd�}d}||fStk
rPYnXdS)	z�
    This function checks /sys/hypervisor/uuid to see if the system is a
    para-virt guest.  It returns a (uuid, virt_type) tuple.
    z/sys/hypervisor/uuidr!�-r"z
ZparaN)NN)r%�readr8�lower�replace�rstriprS)Z	uuid_filerUrVrrrrT�s
rTcCs@tj�}tj�}|j�dkr8|j�jdd�}d}||fSdSdS)z�
    This function looks in the SMBIOS area to determine if this is a
    fully-virt guest.  It returns a (uuid, virt_type) tuple.
    ZxenrXr"ZfullyN)NN)rZ
dmi_vendorZdmi_system_uuidrZr[)ZvendorrUrVrrrrR�srRcCstd|�}t|�td�kS)Nz0x%sr)�eval�long)rUrrr�
_is_host_uuid�sr_cCstj�}|jj�S)N)r�	RhnServer�registrationZwelcome_message)�srrr�welcomeText�srccCstj�}|jj�dS)N)rr`�capabilitiesZvalidate)rbrrr�getCapssrecCstj�}|jj||�S)N)rr`raZreserve_user)�username�passwordrbrrr�reserveUser
srhc@sfeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�RegistrationResultNcCsB||_||_||_||_||_t|�dkr2||_nd|_||_dS)Nr)�	_systemId�	_channels�_failedChannels�_systemSlots�_failedSystemSlots�len�_universalActivationKey�rawDict)�selfrJ�channelsZfailedChannels�systemSlotsZfailedSystemSlotsZuniversalActivationKeyrqrrr�__init__szRegistrationResult.__init__cCs|jS)N)rj)rrrrr�getSystemIdszRegistrationResult.getSystemIdcCs|jS)N)rk)rrrrr�getChannels!szRegistrationResult.getChannelscCs|jS)N)rl)rrrrr�getFailedChannels$sz$RegistrationResult.getFailedChannelscCs|jS)N)rm)rrrrr�getSystemSlots'sz!RegistrationResult.getSystemSlotscs�fdd��jD�S)Ncsg|]}�j|��qSr)�_getSlotDescription)�.0rb)rrrr�
<listcomp>+sz@RegistrationResult.getSystemSlotDescriptions.<locals>.<listcomp>)rm)rrr)rrr�getSystemSlotDescriptions*sz,RegistrationResult.getSystemSlotDescriptionscs�fdd��jD�S)Ncsg|]}�j|��qSr)�_getFailedSlotDescription)r{rb)rrrrr|.szFRegistrationResult.getFailedSystemSlotDescriptions.<locals>.<listcomp>)rn)rrr)rrr�getFailedSystemSlotDescriptions-sz2RegistrationResult.getFailedSystemSlotDescriptionscCs|jS)z5Returns None if no universal activation key was used.)rp)rrrrr�getUniversalActivationKey0sz,RegistrationResult.getUniversalActivationKeycCst|j�dkot|j�dkS)z�Returns True if the system was subscribed to at least one channel
        and was given any type of system slot so it will get updates. In other
        words, returns True if the system will be getting at least basic
        updates.

        r)rorkrm)rrrrr�hasBaseAndUpdates4s	z$RegistrationResult.hasBaseAndUpdatescCs&|dkrtjdtjS|j|�SdS)N�virtualization_host� )r�VIRTZVIRT_FAILEDrz)rr�slotrrrr~?sz,RegistrationResult._getFailedSlotDescriptioncCs$|dkrtjS|dkrtjS|SdS)NZenterprise_entitledr�)rZ
MANAGEMENTr�)rrr�rrrrzEs
z&RegistrationResult._getSlotDescription)N)�__name__�
__module__�__qualname__rurvrwrxryr}rr�r�r~rzrrrrris

ric
Cs�|tj�tj�tj�d�}|r<x|j�D]\}}|||<q(W|rJ||d<n||d<||d<tdrrttj��|d<t	j
�}|jj|�}	|	S)ziWrapper for the old xmlrpc to register a system. Activates subscriptions
    if a reg num is given.

    )Zprofile_nameZ
os_releaseZrelease_nameZarchitecture�tokenrfrg�supportsSMBIOS�smbios)
r�
getVersion�getOSRelease�getArch�itemsr$�_encode_charactersr�
get_smbiosrr`raZ
new_system)
rfrg�profileNamer��otherZ	auth_dictr.�itemrb�retrrr�registerSystemNs 
r�cCsly,tj�}|j|dddd�}tj|dd�}Wntjk
rBdSXy|j�Wntjk
rfYnXdS)Nzcom.redhat.SubscriptionManagerz/EntitlementStatusF)Z
introspectz0com.redhat.SubscriptionManager.EntitlementStatus)Zdbus_interface)�dbusZ	SystemBusZProxyObjectClassZ	InterfaceZ
DBusExceptionZcheck_status)ZbusZvalidity_objZvalidity_ifacerrrrIks
rIcCs�tj�}tj�}tj�}tj�}d}y|jj|||||�}Wn@tj	k
r|t
j�d}|jdkrvt
tj|j��n�YnX|S)N��c)rr`rr�r�Z
getReleaseraZavailable_eus_channels�	xmlrpclibZFault�sys�exc_infoZ	faultCoder
rZ
DelayErrorZfaultString)rfrgrbZserver_archZserver_versionZserver_releaseZavailableChannels�frrr�getAvailableChannels�s 

r�c
	Cs$|dkri}|r6|dkst�|dks(t�|dk	sZt�n$|dk	sBt�|dk	sNt�|dksZt�x|j�D]}|dksdt�qdWtdr�ttj��|d<tj�}|r�|jj	|t
j�t
j�t
j
�||�}n$|jj|t
j�t
j�t
j
�|||�}tjd	|�t|d
|d|d|d
|d|d|d�}	|	S)a�Uses the new xmlrpcs to register a system. Returns a dict instead of just
    system id.

    The main differences between this and registerSystem and that this doesn't
    do activation and does child channel subscriptions if possible. See the
    documentation for the xmlrpc handlers in backend for more detail.

    If nothing is going to be in other, it can be {} or None.

    New in RHEL 5.

    N�registration_number�org_id�	virt_uuidrV�channelr�r�zReturned:
%sZ	system_idrsZfailed_channelsZsystem_slotsZfailed_system_slotsZuniversal_activation_key)rq)r�r�r�rVr�)�AssertionError�keysr$r�rr�rr`raZnew_system_activation_keyrr�r�r�Znew_system_user_pass�log�	log_debugri)
rfrgr�ZpackagesZ
activationKeyr�r.rbr,�resultrrr�registerSystem2�sNr�cCstdS)NZsupportsEUS)r$rrrr�server_supports_eus�sr�csFdd��tj�}|jjdd�s0�fdd�|D�}|jj|t|��dS)NcSs|ddkrd|kr|d=|S)N�classZNETINFOZip6addrr)�xrrr�remove_ip6addr�sz$sendHardware.<locals>.remove_ip6addrZipv6r�csg|]}�|��qSrr)r{r-)r�rrr|�sz sendHardware.<locals>.<listcomp>)rr`rd�
hasCapabilityraZadd_hw_profiler�)rJZhardwareListrbr)r�r�sendHardware�s
r�cCs0tj�}|jjdd�st|�}|jj||�dS)Nz xmlrpc.packages.extended_profile�)rr`rdr�r	raZadd_packages)rJZpackageListrbrrr�sendPackages�sr�cCstdk	rtj�dS)N)rZrefresh)rJrrr�sendVirtInfo�sr�cCstj�}t|jj|��dS)N)rr`rraZ
list_packages)rJrbrrr�listPackages�sr�cCs�tj|�\}}}}}}|dks&|dkrDd|}tj|�\}}}}}}|d	krVtjd��|dksn|dksn|dkrrd}tj||||||f�}|S)
zzRaises up2dateErrors.InvalidProtocolError if the server url has a
    protocol specified and it's not http or https.

    Nr"zhttps://�https�httpzCYou specified an invalid protocol. Only https and http are allowed.�/z/XMLRPC)r�r�)�urlparserZInvalidProtocolErrorZ
urlunparse)�serverZprotocol�hostr>Z
parametersZqueryZfragmentIdentifierrrr�makeNiceServerUrl�s
r�cCsdS)zdReturns 'hosted' if the url points to a known hosted server. Otherwise
    returns 'satellite'.
    Z	satelliter)Z	serverUrlrrr�
getServerTypesr�c@sBeZdZdZdZiifdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�ActivationResultrr�cCs||_||_||_||_dS)zschannels and systemSlots are dicts where the key/value pairs are
        label (string) / quantity (int).

        N)�_status�_regNumrkrm)rrZstatusZregistrationNumberrsrtrrrruszActivationResult.__init__cCs|jS)N)r�)rrrrr�	getStatusszActivationResult.getStatuscCs|jS)N)r�)rrrrr�getRegistrationNumber!sz&ActivationResult.getRegistrationNumbercCs|jS)z7Returns a dict- the key/value pairs are label/quantity.)rk)rrrrr�getChannelsActivated$sz%ActivationResult.getChannelsActivatedcCs|jS)z7Returns a dict- the key/value pairs are label/quantity.)rm)rrrrr�getSystemSlotsActivated(sz(ActivationResult.getSystemSlotsActivatedN)
r�r�r��
ACTIVATED_NOW�ALREADY_USEDrur�r�r�r�rrrrr�sr�cGs�g}x�|D]�}t|�}|tkr(t|�}nZ|tkrDtdd�|D��}n>|tkr\dd�|D�}n&|tksl|tkr�tdd�|j	�D��}|j
|�q
Wt|�dkr�|dSt|�SdS)	u� All the data we gathered from dmi, bios, gudev are in utf-8,
            we need to convert characters beyond ord(127) - e.g ® to unicode.
        css|]}t|�VqdS)N)r�)r{r-rrr�	<genexpr>6sz%_encode_characters.<locals>.<genexpr>cSsg|]}t|��qSr)r�)r{r-rrrr|8sz&_encode_characters.<locals>.<listcomp>cSsg|]\}}t||��qSr)r�)r{�name�valrrrr|:sr�rN)�typerrr�tuplerrr�dictr��appendro)�argsr�r�Z	item_typerrrr�,s

r�cCs�d}d}d}ytj�}t|�}Wn$tjd�tjtj��YnX|dk	r�y.t|||�}|j	�t
jkrz|j�}t
|�Wn>tjk
r�tjd�Yn tjk
r�tjd�YnX|S)NzMThere was an error while reading the hardware info from the bios. Traceback:
z<There are are no entitlements associated with this hardware.z,The hardware id was not recognized as valid.)rZget_hal_system_and_smbiosr�r��log_meZ
log_exceptionr�r��activateHardwareInfor�r�r�r�rPrZNotEntitlingErrorr�ZInvalidRegistrationNumberError)ZloginrgZactivateHWResult�hardwareInforOrrr�_activate_hardwareBs*

r�c
Cs�i}|rd|i}tj�}|jj||||�}|d}|d}tjd|�|dkr\ttj|�S|dkrpttj|�Sd|}	t	j
|	��dS)	z�Tries to activate an entitlement linked to the hardware info that we
    read from the bios.

    Returns an ActivationResult.
    Can raise:
        Invalid number.
        Hardware info is not entitling.
        Communication errors, etc

    r�Zstatus_coder�zServer returned status code %srr�zNThe server returned unknown status code %s while activating the hardware info.N)rr`raZactivate_hardware_infor�r�r�r�r�rZCommunicationError)
rfrgr�ZorgIdr�r�r�Z
statusCodeZregNum�messagerrrr�^s 
r�cCsdtjdtjtjB�rVddlm}m}|dg|||d�}tdd�|jj	�|j
j	��n
tjd�dS)Nz/usr/sbin/rhn_checkr)�Popen�PIPE)�stdin�stdout�stderrcSs
tj|�S)N)r�r�)r�rrr�<lambda>�sz$spawnRhnCheckForUI.<locals>.<lambda>z Warning: unable to run rhn_check)
rrrr�
subprocessr�r��mapr�r&r�r�r�)r�r��prrr�spawnRhnCheckForUI�s
r�ZdebcCsdS)z.On Debian no extra action for plugin is neededr�r)r�rrrrrr�pluginEnable�sr�)r�)NNNNN)N)N)]rr�r�Zup2date_clientrrrrrrrZup2date_client.rhnPackageInfor	Zup2date_client.pkgplatformr
Zrhn.i18nrrZrhn.tbr
r�r��typesrrrrrr�ImportErrorZurllib.parse�parseZ
xmlrpc.clientZclient�listr��bytes�strr�rEr^Zvirtualizationr�gettextZtranslation�t�hasattrrrZ	SYSID_DIRr7rNr1rZinitUp2dateConfigr$ZinitLogr�r r0r4r6r9r;rHrLrPrWrTrRr_rcrerhrir�rIr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�Zup2date_client.pmPluginrrrr�<module>
s�$



,?
;


"