File: //lib/python3.6/site-packages/up2date_client/__pycache__/rhnreg.cpython-36.pyc
3
/V)j�. � @ s� d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm Z d dl
mZ d d lm
Z
mZ y4d dlZd dlZd d
lmZmZmZmZmZmZ W nD ek
r� d dljZd dljZeZeZeZe Ze!Ze!Ze"Z#Y nX d dl$Z$e$j%ddd
�Z&e'e&d��s e&j$e&_(e&j(Z)dZ*dZ+ddddd�Z,dd� e,j-� D �Z.d dlm/Z/ e/j0� Z1ej2� Z3dd� Z4dd� Z5dd� Z6e e7d�d d!�Z8e7d"�d#d$�Z9d6d&d'�Z:d7e7d(�d)d*�Z;d+d,� Z<e d-�d.d/�Z=d8d0d1�Z>d2d3� Z?d4d5� Z@dS )9� N)�up2dateUtils)�
up2dateErrors)�up2dateAuth)� rhnserver)�
up2dateLog)�
statistics)�getPlatform)�ustr�sstr)�ListType� TupleType�
StringType�UnicodeType�DictType�DictionaryTypezrhn-client-toolsT)Zfallback�ugettextz/etc/sysconfig/rhnz/etc/sysconfig/rhn/jwt.tokenZ
shared_pro�shared�solo�admin)zCloudLinux OS Shared ProzCloudLinux OS SharedzCloudLinux OS SolozCloudLinux OS Adminc C s i | ]\}}||�qS � r )�.0�k�vr r �/usr/lib/python3.6/rhnreg.py�
<dictcomp>5 s r )�configc C s t jtd t j�S )N�systemIdPath)�os�access�cfg�R_OKr r r r �
registered= s r! c C s� t jj| �}t j|t j�sdS t jj| �rJyt j| | d � W n
dS t j| t jt j B t j
B t jB t jB d�}yt j
|d�}W n tk
r� t j|� � Y nX z|jt|�� W d|j� X dS )z; Write a file to disk that is not readable by other users. Fz.savei� �wNT)r �path�dirnamer �W_OK�lexists�rename�open�O_WRONLY�O_CREAT�
O_NOFOLLOW�O_EXCL� O_CLOEXEC�fdopen� Exception�close�writer
)Zsecure_fileZ
file_contentsZdir_name�fdZfd_filer r r �_write_secure_file@ s*
r3 c C s t td | �}|S )Nr )r3 r )�systemId�resr r r �
writeSystemIdd s r6 )�token�allowTransitionc C sz ddl }ddl}|jjd�s dS ddg}|r6|jd� |j||jd�}|j| j� d�\}}|j dkrvt
jd ||f � dS )
zH
Execute binary file which we use as hook for jwt token updates
r Nz /opt/cloudlinux/venv/bin/python3z/usr/sbin/cl-pre-jwt-updatez--new-token-stdinz--allow-transition)�stdin)�inputz7Pre jwt update hook failed with stdout=%s and stderr=%s)�
subprocessr r# �exists�append�Popen�PIPE�communicate�encode�
returncode�log�log_me)r7 r8 r; r �cmd�p�stdout�stderrr r r �_execute_pre_jwt_update_hooki s
rI )r8 c C sj ddl }ddl}|jjd�s dS dg}| r4|jd� |j|�}|j� \}}|jdkrftj d||f � dS )zH
Execute binary file which we use as hook for jwt token updates
r Nz /opt/cloudlinux/venv/bin/python3z/usr/sbin/cl-post-jwt-updatez--allow-transitionz8Post jwt update hook failed with stdout=%s and stderr=%s)
r; r r# r<