AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/cloudinit/distros/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /usr/lib/python3/dist-packages/cloudinit/distros/__pycache__/__init__.cpython-310.pyc
o

x[h��
@s�ddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZmZmZmZmZmZmZmZddlmmmZddlmZmZm Z mZm!Z!m"Z"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(m)Z)ddl*m+Z+dd	l,m-Z-dd
l.m/Z/ddl0m1Z1ddl2m3Z3dd
l4m5Z5m6Z6m7Z7ddl8m9Z9ddl:m;Z;ddl<m=Z=dZ>dgdgdgddgddgddgdgdggd�gd�dgd d!gd"�Z?e�@eA�ZBgd#�ZCejDejEd$ZFeeeGeeeeeGeeeGeeGfeeeGeeGeffZHGd%d&�d&eI�ZJGd'd(�d(e!jKejLd)�ZMd*eGd+eNfd,d-�ZOd*eGfd.d/�ZPde&jQfd0d1�ZRd2d3�ZSd4eGd5eeMfd6d7�ZT	9d>d:d;�ZUd<d=�ZVdS)?�N)�defaultdict)�suppress)�StringIO)
�Any�Dict�List�Mapping�MutableMapping�Optional�Set�Tuple�Type�Union)
�helpers�importer�	lifecycle�net�persistence�ssh_util�subp�
temp_utils�
type_utils�util)�LinuxNetworking�
Networking)�PackageManager)�known_package_managers)�hosts)�+ALLOW_EC2_MIRRORS_ON_NON_AWS_INSTANCE_TYPES)�log_with_downgradable_level)�
activators�dhcp�	renderers)�NetOps)�parse_net_config_data)�Renderer�all�alpine�aosc�arch�debian�ubuntu�freebsd�	dragonfly�gentoo�cos�netbsd�openbsd)�	almalinux�amazon�
azurelinux�centos�
cloudlinux�	eurolinux�fedora�mariner�miraclelinux�openmandriva�photon�rhel�rocky�	virtuozzo)�opensusez
opensuse-leapzopensuse-microoszopensuse-tumbleweed�sle_hpcz	sle-micro�sles�suse�	openeuler�OpenCloudOS�	TencentOS)r'r(r)r*r,r.r0r1�redhatrCrDrE)�chronyzsystemd-timesyncd�ntp�ntpdate�-c@seZdZdS)�PackageInstallerErrorN)�__name__�
__module__�__qualname__�rPrP�</usr/lib/python3/dist-packages/cloudinit/distros/__init__.pyrL}srLc
@s�eZdZUdZdZdZdZdZdZdZ	dZ
d	d
gZdZdZ
d
gZeeed<iZeeeeeffed<dZeZeeed<dddd�ZejZeeed<dZ dZ!dZ"eed<dZ#e$eed<dZ%e$eed<dd�Z&de'd dfd!d"�Z(d#d$�Z)d%e*d e+e,ee-e.fe.ffd&d'�Z/d%e*fd(d)�Z0e1d e2j3fd*d+��Z4e1d ee5j6fd,d-��Z7e1d e8fd.d/��Z9d0e8fd1d2�Z:d3d4�Z;d�d5d6�Z<d�d7d8�Z=d�d9d:�Z>e?d;d<��Z@eAjBd�d=d>��ZCdd?�d@dA�ZDdBdC�ZEd�dDdE�ZFd�dFdG�ZGdHdI�ZHd�d eIfdJdK�ZJeAjBd�dLdM��ZKeAjBdNdO��ZLdPdQ�ZMdRdS�ZNeAjBd�dTdU��ZOeAjBdVdW��ZPeAjBdXdY��ZQdZd[�ZRd\d]�ZSe?d^d_��ZTd`da�ZUdbdc�ZVe1ddde��ZWdfdg�ZXd eIfdhdi�ZYdjdk�ZZd eIfdldm�Z[dndo�Z\dpdq�Z]drefdsdt�Z^dudv�Z_d�dwdx�Z`dyeadzeIfd{d|�Zbd}d~�Zcd�dd��Zdd�d�d��Zed�d�d��Zfd�d�d��Zgehd�d���Ziehd�d�d���Zjehdd��d�ed
ed�efd�d���Zkd�ed�ed�ed�efd�d��Zld efd�d��Zmd�d�ead�ed�efd�d��Zne?d�ed�ed�ed�ed�ed eafd�d���Zoe1d�d���Zpepjqd�d���Zpe?d�e'd e$e'fd�d���Zre?d�e'd e$e'fd�d���Zse?d�e'd�e'd e$e'fd�d���Zte?d�ed dfd�d���Zue?d�ed e$efd�d���Zve?d�ed ewfd�d���Zxd�d�d��ZydS)��Distrozpython3-pipz/usr/libz
/etc/hostsz/etc/doas.confz"/etc/sudoers.d/90-cloud-init-usersz
/etc/hostnamez/etc/shadowz/var/lib/extrausers/shadowz
^{username}::z^{username}:!:z/usr/share/zoneinfoz	root:root�service�init_cmd�renderer_configsN�networking_clsz-Hz-Pz-r)�halt�poweroff�reboot�net_ops�Fz/etc/resolv.conf�osfamily�dhclient_lease_directory�dhclient_lease_file_regexcCsT||_||_||_|��|_tj|_tj	|_
t�|�|_
g|_d|_d|_d|_dS)NT)�_paths�_cfg�namerV�
networkingr!�ALL_DHCP_CLIENTS�dhcp_client_priority�iproute2�Iproute2rZr�Runners�_runner�package_managers�_dhcp_client�_fallback_interface�is_linux)�selfra�cfg�pathsrPrPrQ�__init__�s

zDistro.__init__�ci_pkl_version�returncCsTd|jvs	|jjs|��|_t|d�sd|_t|d�sd|_t|d�s(d|_dSdS)z)Perform deserialization fixes for Distro.rbrjNrkrlT)�__dict__rbrV�hasattrrjrkrl)rmrqrPrPrQ�	_unpickle�s




�zDistro._unpicklecCs8t|t�r|St|ttf�rt|�dkrt|�Std��)N�z?Invalid 'packages' yaml specification. Check schema definition.)�
isinstance�str�list�tuple�len�
ValueError)rm�entryrPrPrQ�_validate_entry�s
�zDistro._validate_entry�pkglistcCs�tt�}t�}|D]=}t|t�r>|��D](\}}|D]!}|�|�}z|t|�|�Wqty;t	�
d|�Yqwqq	|�|�|��q	t|�|fS)z�Transform the generic package list to package by package manager.

        Additionally, include list of generic packages
        zLCannot install packages under '%s' as it is not a supported package manager!)r�setrw�dict�itemsr~r�add�KeyError�LOG�error)rmr�packages_by_manager�generic_packagesr}�package_manager�package_list�
definitionrPrPrQ�_extract_package_by_manager�s,

�����z"Distro._extract_package_by_managercCs�d}|�|�\}}t�}|jD]?}|�|jt��}||B}|�|�|��s3t�d|j	�|�
|�q|s6q|�|�}	|�
|	�|	rHt�||	�t|	�|}q|�
�D]\}
}|
j	dd�|jD�vrcqS|�
|
�|j|j�j|d��qS|r{t||��dS)NzcFailed to install the following packages: %s. See associated package manager logs for more details.z"Package manager '%s' not availablecSsg|]}|j�qSrP)ra)�.0�prPrPrQ�
<listcomp>�z+Distro.install_packages.<locals>.<listcomp>)r)r�r�ri�get�	__class__�difference_update�	availabler��debugra�update�install_packages�infor��from_configrhr`rL)rmr�
error_messager�r��total_failed�manager�manager_packages�to_try�failed�manager_type�packagesrPrPrQr��sJ�	�
�



����zDistro.install_packagesc	Cs�|jr|jS|j}t�|jdg�}|r<g}t�d|�|D]}tjD]}||j	kr0|�
|�nq"t�d|�q|r<|}|D]%}z|�|_t�d|j	�|jWStjfyct�d|j	�Yq>wt���)aaccess the distro's preferred dhcp client

        if no client has been selected yet select one - uses
        self.dhcp_client_priority, which may be overridden in each distro's
        object to eliminate checking for clients which will not be provided
        by the distro
        )�networkrdz.Using configured dhcp client priority list: %sz4Configured dhcp client %s is not supported, skippingzDHCP client selected: %szDHCP client not found: %s)
rjrdr�get_cfg_by_pathr`r�r�r!rc�client_name�append�warning�NoDHCPLeaseMissingDhclientError)rmrd�config_priority�
found_clients�client_configured�client_class�clientrPrPrQ�dhcp_client sD	��


���	�zDistro.dhcp_clientcCst�|jdd�}tj|d�S)z�Return the configured network activator for this environment.

        :returns: The network activator class to use
        :raises: NoActivatorException if no activator is found
        )r�r N��priority)rr�r`r �select_activator)rmr�rPrPrQ�network_activator\s�zDistro.network_activatorcCsDt�|jdd�}tj|d�\}}t�d||�||j�|�d�}|S)N)r�r"r�z-Selected renderer '%s' from priority list: %s)�config)	rr�r`r"�selectr�r�rUr�)rmr�ra�
render_cls�rendererrPrPrQ�network_rendererhs��zDistro.network_rendererr�cCs|�|�dS�N)�render_network_state)rm�
network_stater�rPrPrQ�_write_network_stateu�zDistro._write_network_statecCs4tj�|jt|��}tj�|�std||f��|S)Nz(Invalid timezone %s, no file found at %s)�os�path�join�tz_zone_dirrx�isfile�IOError)rm�tz�tz_filerPrPrQ�
_find_tz_filexs
�zDistro._find_tz_filecCs|j�||�Sr�)r`r�)rm�opt_name�defaultrPrPrQ�
get_option�r�zDistro.get_optioncCs||j|<dSr�)r`)rmr��valuerPrPrQ�
set_option�r�zDistro.set_optioncCs(|�||�}|�||j�|�|�dSr�)�_select_hostname�_write_hostname�hostname_conf_fn�_apply_hostname)rm�hostname�fqdn�writeable_hostnamerPrPrQ�set_hostname�szDistro.set_hostnamecCst�S)z?Wrapper to report whether this distro uses systemd or sysvinit.)�uses_systemdrPrPrPrQr��szDistro.uses_systemdcC�t��r���NotImplementedError)rm�command�args�pkgsrPrPrQ�package_command�szDistro.package_command��forcecCsl|jD]0}|��st�d|j�qz|j|d�Wqty3}zt�d|j|�WYd}~qd}~wwdS)Nz8Skipping update for package manager '%s': not available.r�z%Failed to update package using %s: %s)rir�r�r�ra�update_package_sources�	Exceptionr�)rmr�r��erPrPrQr��s 
�����zDistro.update_package_sourcescCst��d}|dvrdS|S)N�)�i386�i486�i586�i686r�)r��uname)rmr)rPrPrQ�get_primary_arch�szDistro.get_primary_archcCs"|�dg�}|s|��}t||�S)N�package_mirrors)r�r��_get_arch_package_mirror_info)rmr)�mirror_inforPrPrQr��s
z$Distro._get_arch_package_mirror_infocCs|�|�}t||d�S)N)�data_sourcer�)r��_get_package_mirror_info)rmr)r��	arch_inforPrPrQ�get_package_mirror_info�s
�zDistro.get_package_mirror_infocCst��Sr�)r�generate_fallback_config�rmrPrPrQr��szDistro.generate_fallback_configcCst|j}t||d�}|�||�|r3t�d�z|j}Wntjy+t�d�YdSw|�	|�dSt�d�dS)aApply the network config.

        If bring_up is True, attempt to bring up the passed in devices. If
        devices is None, attempt to bring up devices returned by
        _write_network_config.

        Returns True if any devices failed to come up, otherwise False.
        )r�z/Bringing up newly configured network interfacesz>No network activator found, not bringing up network interfacesTz3Not bringing up newly configured network interfacesF)
r�r$r�r�r�r�r �NoActivatorExceptionr��bring_up_all_interfaces)rm�	netconfig�bring_upr�r�r�rPrPrQ�apply_network_config�s"	

��

�zDistro.apply_network_configcCr�r�r�)rm�locale�out_fnrPrPrQ�apply_locale��zDistro.apply_localecCr�r�r�)rmr�rPrPrQ�set_timezone�r�zDistro.set_timezonecC�dS)Nz	127.0.0.1rPr�rPrPrQ�_get_localhost_ip�szDistro._get_localhost_ipcCr�r�r�r�rPrPrQ�
get_locale�szDistro.get_localecCr�r�r�)rm�filenamer�rPrPrQ�_read_hostname�r�zDistro._read_hostnamecCr�r�r�)rmr�r�rPrPrQr��r�zDistro._write_hostnamecCr�r�r�r�rPrPrQ�_read_system_hostname�r�zDistro._read_system_hostnamecCsFt�d|�z
t�d|g�WdStjy"t�td|�YdSw)Nz2Non-persistently setting the system hostname to %sr�z;Failed to non-persistently adjust the system hostname to %s)r�r�r�ProcessExecutionErrorr�logexc)rmr�rPrPrQr��s�
��zDistro._apply_hostnamecCs&t�|jd|j�r
|r
|S|s|S|S)N�prefer_fqdn_over_hostname)r�get_cfg_option_boolr`�prefer_fqdn)rmr�r�rPrPrQr�s
���zDistro._select_hostnamecCs6g}|D]}|tvrtd�|���|�t|�q|S)Nz&No distributions found for osfamily {})�
OSFAMILIESr|�format�extend)�family_list�distros�familyrPrPrQ�expand_osfamilys�zDistro.expand_osfamilyc

Cs|}|�||�}|rtj�|�r|�|�}nd}|��\}}g}|r&||kr+|�|�|r5||kr:||kr:|�|�|rK|rK||krKt�d||�dSt	dd�|D��}t�
d|t|��|D]}	z|�||	�Wq_t
yzt�td||	�Yq_w||vr�|�|�dSdS)Nz6%s differs from %s, assuming user maintained hostname.cSsg|]}|r|�qSrPrP)r��frPrPrQr�K�z*Distro.update_hostname.<locals>.<listcomp>z/Attempting to update hostname to %s in %s filesz!Failed to write hostname %s to %s)r�r�r��existsr�r�r�r�r�r�r�r{r�r�rrr�)
rmr�r��prev_hostname_fn�applying_hostname�
prev_hostname�sys_fn�sys_hostname�update_files�fnrPrPrQ�update_hostnamesH

�����zDistro.update_hostnamec
Cszd}tj�|j�rt�t�|j��}nt�d�}tjdd�}|�	�}|�
|�}d}|s5|�|||�d}ndd}|D]*}d}	g}
t|�dkrI|d}	t|�dkrU|dd�}
|	durc|	|krc||
vrcd}q9|r�t
|�}|�||g�|�|�|D] }t|�dkr�|�||d�qxt|�dkr�|j|g|�R�qx|r�t�}|r�|�d	|�|�d	|�tj|j|��d
d�dSdS)N��added��baseFTr[rrvz%s
i���mode)r�r�r
�hosts_fnr�	HostsConfr�load_text_file�make_headerr��	get_entry�	add_entryr{ryr��del_entriesr�write�
write_file�getvalue)
rmr�r��header�eh�local_ip�	prev_info�need_changer}�
entry_fqdn�
entry_aliases�new_entries�contentsrPrPrQ�update_etc_hosts_sP

�
��zDistro.update_etc_hostscCs|jstt�|_|jS)z7Allow distro to determine the preferred ntp client list)�_preferred_ntp_clientsry�PREFERRED_NTP_CLIENTSr�rPrPrQ�preferred_ntp_clients�s
zDistro.preferred_ntp_clientscCs
|�d�S)N�default_user)r�r�rPrPrQ�get_default_user�s
zDistro.get_default_usercKsvt�|�r
t�d|�dSd|vr|�d�}nd}d|g}d|g}t��r/|�d�|�d�ddd	d
ddd
dddd�
}dddd�}dg}|�d�}	|	r�t|	t	�rV|	�
d�}	t|	t�rgtj
d|�d�ddd�dd�|	D�}	d�|	�|d<|�d �}
|
r�|	�|
�|r�|	r�|	D]}t�|�s�|�|�t�d!||�q�d"|��vr�t	|d"�|d"<t|���D]D\}}
||vr�|
r�t|
t	�r�|�|||
g�||vr�|�||d#g�q�|�|||
g�q�||vr�|
r�|�||�|�||�q�|�d$�s�|�d%��r
|�d&�|�d&�n
|�d'�|�d'�t�d(|�z
tj||d)�WdSt�y:}z	t�td*|�|�d+}~ww),z�
        Add a user to the system using standard GNU tools

        This should be overridden on distros where useradd is not desirable or
        not available.

        Returns False if user already exists, otherwise True.
        z!User %s already exists, skipping.F�
create_groupsT�useradd�--extrausersz	--commentz--homez--gidz--uidz--groups�
--passwordz--shellz--expiredatez
--inactivez--selinux-user)
�gecos�homedir�
primary_group�uid�groups�passwd�shell�
expiredate�inactive�selinux_userz--no-user-groupz--systemz
--no-log-init)�
no_user_group�system�no_log_initr>r=�,z	The user z) has a 'groups' config value of type dictz22.3z=Use a comma-delimited string or array instead: group1,group2.��
deprecated�deprecated_version�
extra_messagecSsg|]}|���qSrP��strip)r��grPrPrQr��rz#Distro.add_user.<locals>.<listcomp>r;z created group '%s' for user '%s'r<�REDACTED�no_create_homerDz-Mz-mzAdding user %s)�	logstringzFailed to create user %sN)r�is_userr�r��pop�system_is_snappyr�r�rwrx�splitr�r�	deprecater��is_group�create_groupr��keys�sortedr�rrr�r)rmra�kwargsr5�useradd_cmd�log_useradd_cmd�useradd_opts�
useradd_flags�redact_optsr=r;�group�key�valr�rPrPrQ�add_user�s�


��




�




��


���zDistro.add_userc
Ks�|�d�}|�dd�}gd�}|r|�d�|�|�t�d|�ztj||dd�\}}t�d	||�t�|�}|�d
d�}	W|	StyU}
z	t�td|�|
�d}
~
ww)
zD
        Add a snappy user to the system using snappy tools
        �snapuser�knownF)�snapzcreate-userz--sudoerz--jsonz--knownzAdding snap user %sT)rP�capturez snap create-user returned: %s:%s�usernameNzFailed to create snap user %s)	r�r�r�r�rr�	load_jsonr�r)rmrarZrdre�create_user_cmd�out�err�jobjrhr�rPrPrQ�
add_snap_users(



�
���zDistro.add_snap_usercs�t��r|j|jg}n|jg}d��fdd�|jD��}|D]4}tj�|�s'qt�	|�}t
�d��d�|t
j�s@t
�d�|�qt
�d�|�t
�||t
j�rRdSqd	S)
z�
        Check whether username exists in shadow files with empty password.

        Support reading /var/lib/extrausers/shadow on snappy systems.
        �|csg|]}|j�d��qS)�rh)r)r��patternrprPrQr�4s
��z?Distro._shadow_file_has_empty_user_password.<locals>.<listcomp>�^�:zUser %s not found in %sz0User %s found in %s. Checking for empty passwordTF)rrS�shadow_extrausers_fn�	shadow_fnr��#shadow_empty_locked_passwd_patternsr�r�r
r�re�findall�	MULTILINEr�r�)rmrh�shadow_files�shadow_empty_passwd_re�shadow_file�shadow_contentrPrprQ�$_shadow_file_has_empty_user_password)s4
��
���z+Distro._shadow_file_has_empty_user_passwordcKs�d|vr
|j|fi|��S|j|fi|��}d}d}d}d}d|vr6d}d}|dr4|�||d�nd}d|vrOd}d}|drM|j||ddd�nd}|rk|sjd|vrdd}ttd	tjd
|fd�|�|�}nd|vryd}d}|dsyd}|�dd�r�|�	|�n,|s�|r�|r�t�
d
||�|�|�n|r�ttd	tjd|fd�nttd	tjd|fd�d|vr�|dr�|�||d�d|vr�|dr�|�
||d�n|ddur�tjd|�d�ddd�d|v�r*|d}t|t�r�|g}nt|t��rt|���}|du�r"t|tttf��st�dt|��g}nt|��p!g}t�t|�|�d|v�r`|�dg�}	|	�sCt�d||d�dS|d}
tj}|�d|
�}|�d|�}tjt|	�||d�dS)a�
        Creates or partially updates the ``name`` user in the system.

        This defers the actual user creation to ``self.add_user`` or
        ``self.add_snap_user``, and most of the keys in ``kwargs`` will be
        processed there if and only if the user does not already exist.

        Once the existence of the ``name`` user has been ensured, this method
        then processes these keys (for both just-created and pre-existing
        users):

        * ``plain_text_passwd``
        * ``hashed_passwd``
        * ``lock_passwd``
        * ``doas``
        * ``sudo``
        * ``ssh_authorized_keys``
        * ``ssh_redirect_user``
        rdFN�plain_text_passwdT�
hashed_passwd)�hashedr>z24.3z5'passwd' in user-data is ignored for existing user %s)�logger�version�requested_level�msgr��lock_passwdzIAllowing unlocking empty password for %s based on empty '%s' in user-dataz�Not unlocking blank password for existing user %s. 'lock_passwd: false' present in user-data but no existing password set and no 'plain_text_passwd'/'hashed_passwd' provided in user-dataz�Not unlocking password for user %s. 'lock_passwd: false' present in user-data but no 'passwd'/'plain_text_passwd'/'hashed_passwd' provided in user-data�doas�sudozThe value of 'false' in user z's 'sudo' configz22.2zUse 'null' instead.rG�ssh_authorized_keyszZInvalid type '%s' detected for 'ssh_authorized_keys', expected list, string, dict, or set.�ssh_redirect_user�cloud_public_ssh_keysz^Unable to disable SSH logins for %s given ssh_redirect_user: %s. No cloud public-keys present.z$USERz
$DISABLE_USER)�options)rnrc�
set_passwdrr��logging�WARNINGr~r�r�r��
unlock_passwd�write_doas_rules�write_sudo_rulesrrUrwrxr�ry�valuesrzr�r��typer�setup_user_keys�DISABLE_USER_OPTS�replace)rmrarZ�pre_existing_user�has_existing_password�ud_blank_password_specified�ud_password_specified�password_keyrX�
cloud_keys�
redirect_user�disable_optionrPrPrQ�create_userKs��
�����
�


�
��
�zDistro.create_userc
Cs�dd|gdd|gf}ztdd�|D��}Wnty/}ztd|dd	�|D�f�|�d
}~wwzt�|�Wd
StyM}z	t�td|�|�d
}~ww)zL
        Lock the password of a user, i.e., disable password logins
        r>z-l�usermodz--lockcs�"�|]}t�|d�r|VqdS�rN�r�which�r��toolrPrPrQ�	<genexpr>�� z%Distro.lock_passwd.<locals>.<genexpr>zBUnable to lock user account '%s'. No tools available.   Tried: %s.cS�g|]}|d�qS�rrP�r��crPrPrQr�	rz&Distro.lock_passwd.<locals>.<listcomp>Nz&Failed to disable password for user %s��next�
StopIteration�RuntimeErrorrr�rrr�)rmra�
lock_tools�cmdr�rPrPrQr��s(�������zDistro.lock_passwdrac
CsLdd|gdd|gf}ztdd�|D��}Wnty/}ztd|dd	�|D�f�|�d
}~wwz
tj|ddgd
�\}}WntyR}z	t�td|�|�d
}~ww|r�dd|gddd|gf}ztdd�|D��}Wnty�}ztd|dd	�|D�f�|�d
}~wwzt�|�Wd
Sty�}z	t�td|�|�d
}~wwd
S)zM
        Unlock the password of a user, i.e., enable password logins
        r>z-ur�z--unlockcsr�r�r�r�rPrPrQr�r�z'Distro.unlock_passwd.<locals>.<genexpr>zDUnable to unlock user account '%s'. No tools available.   Tried: %s.cSr�r�rPr�rPrPrQr�rz(Distro.unlock_passwd.<locals>.<listcomp>Nr���rcsz%Failed to enable password for user %sz-dr8z''csr�r�r�r�rPrPrQr�,s��
�zTUnable to set blank password for user account '%s'. No tools available.   Tried: %s.cSr�r�rPr�rPrPrQr�3rz(Failed to set blank password for user %sr�)rmra�unlock_toolsr�r��_rl�passwd_set_toolsrPrPrQr�s`�������
�����������zDistro.unlock_passwdc
CsBzt�dd|g�WdSty }z	t�td|�|�d}~ww)Nr>z--expirezFailed to set 'expire' for %s)rr�rrr�)rm�userr�rPrPrQ�
expire_passwd=s��zDistro.expire_passwdc
Csfd||f}dg}|r|�d�z
tj||d|d�WdSty2}z	t�td|�|�d}~ww)Nz%s:%s�chpasswd�-ezchpasswd for %s)�datarPzFailed to set password for %sT)r�rr�rrr�)rmr�r>r��pass_stringr�r�rPrPrQr�Ds

����zDistro.set_passwd�plist_inr�cCs>d�dd�|D��d}dg|rdgng}tj||d�dS)N�
css"�|]\}}d�||g�VqdS)rsN�r�)r�ra�passwordrPrPrQr�[r�z"Distro.chpasswd.<locals>.<genexpr>r�r�)r�)r�r)rmr�r��payloadr�rPrPrQr�Xs���	zDistro.chpasswdcCstd}t�d||�t�||�}|r3t�d|�d��|�d�|kr(t�d�dSt�d|�d��dSt�d	�dS)
Nz�^(?:permit|deny)(?:\s+(?:nolog|nopass|persist|keepenv|setenv \{[^}]+\})+)*\s+([a-zA-Z0-9_]+)+(?:\s+as\s+[a-zA-Z0-9_]+)*(?:\s+cmd\s+[^\s]+(?:\s+args\s+[^\s]+(?:\s*[^\s]+)*)*)*\s*$z3Checking if user '%s' is referenced in doas rule %rz!User '%s' referenced in doas ruler[z'Correct user is referenced in doas ruleTz.Incorrect user '%s' is referenced in doas ruleFz/doas rule does not appear to reference any user)r�r�rw�searchr`)rmr��rule�rule_pattern�valid_matchrPrPrQ�is_doas_rule_valides(�	�
�
�
zDistro.is_doas_rule_validc

Cs"|s|j}|D]}|�||�sd||f}t�|�dSqdd|g}|D]	}|�d|�q&d�|�}|d7}tj�|�sit	�
�|g}zt	j|d�|�dd�WdStyh}	z	t	�
td|�|	�d}	~	ww|t	�|�vr�z	t	�||�WdSty�}	z	t	�
td	|�|	�d}	~	wwdS)
NzHInvalid doas rule %r for user '%s', not writing any doas rules for user!rz# cloud-init User rules for %s�%sr�� rzFailed to write doas file %sz Failed to append to doas file %s)�doas_fnr�r�r�r�r�r�r�r
rrr$r�rr�append_file)
rmr��rules�	doas_filer�r��lines�contentr.r�rPrPrQr��sH��
�
������zDistro.write_doas_rules�/etc/sudoersc
Csfd}d}d}tj�|�rt�|�}d}ntj�|�rt�|�}d}|��D]'}|��}t�d|�}|s4q%|�	d���}	|	s>q%tj�
|	�}	|	|krLd}nq%|s�zF|svddtjdd	�d
|dg}
|rgt�
d|�|d�|
�7}t�||d
�ndtjdd	�d
|dg}
d�|
�}t�||�t�d||�Wnty�}z	t�td|�|�d}~wwt�|d�dS)NrFz/usr/etc/sudoersTz^[#|@]includedir\s+(.*)$r[z?# See sudoers(5) for more information on "#include" directives:rrz#includedir %szUsing content from '%s'r�r�zAdded '#includedir %s' to %szFailed to write %si�)r�r�r
rr�
splitlinesrLrwr�r`�abspathrr�r�r�r$r�r�r�r�
ensure_dir)rmr��	sudo_base�sudoers_contents�base_exists�system_sudo_base�
found_include�line�
include_match�included_dirr�r�rPrPrQ�ensure_sudo_dir�sb

�
�
�
��zDistro.ensure_sudo_dirc

CsH|s|j}dd|g}t|ttf�r!|D]}|�d||f�qnt|t�r0|�d||f�nd}t|t�|���d�	|�}|d7}|�
tj�
|��tj�|�s|t��|g}z
t�|d�	|�d�WdSty{}	z	t�td|�|	�d}	~	ww|t�|�vr�z	t�||�WdSty�}	z	t�td|�|	�d}	~	wwdS)	Nrz# User rules for %sz%s %sz1Can not create sudoers rule addition with type %rr�r�zFailed to write sudoers file %sz#Failed to append to sudoers file %s)�
ci_sudoers_fnrwryrzr�rx�	TypeErrorr�obj_namer�r�r�r��dirnamer
rrr$r�rr�rr�)
rmr�r��	sudo_filer�r�r�r�r.r�rPrPrQr��sL��

�������zDistro.write_sudo_rulescCs�d|g}t��r
|�d�|sg}t�|�rt�d|�nz
t�|�t�d|�Wnty:t�	td|�Ynwt
|�dkrd|D]"}t�|�sRt�d||�qCt�dd	d
||g�t�d||�qCdSdS)N�groupaddr7z(Skipping creation of existing group '%s'zCreated new group %szFailed to create group %srzCUnable to add group member '%s' to group '%s'; user does not exist.r�z-az-GzAdded user '%s' to group '%s')rrSr�rVr�r�rr�r�rr{rQ)rmra�members�
group_add_cmd�memberrPrPrQrWs4


�
��zDistro.create_groupc
Csld|j|g}z|dkrdt|�}Wnty'}ztd|f�|�d}~ww||g}|r4|�|�|S)N�shutdown�nowz+%dz?power_state[delay] must be 'now' or '+m' (minutes). found '%s'.)�shutdown_options_map�intr|r�r�)�clsr�delay�messager�r�r�rPrPrQ�shutdown_command(s&������

zDistro.shutdown_commandcCs2|j}|��sd|vr|dg}tj|d|d�SdS)zX
        Reload systemd startup daemon.
        May raise ProcessExecutionError
        �	systemctlz
daemon-reloadT�rgr�N)rTr�r)r�r�rTr�rPrPrQ�reload_init9s
�zDistro.reload_initr��action�
extra_argsc	Gs�|j}|��sd|vr*dg}d|gd|gd|gd|gd|gd|gd|gd	|gd
�}n|dg|dg|dg|dg|dg|dg|dg|d	gd
�}|||t|�}tj|d|d�S)
z�
        Perform the requested action on a service. This handles the common
        'systemctl' and 'service' cases and may be overridden in subclasses
        as necessary.
        May raise ProcessExecutionError
        r��stop�start�enable�disable�restartzreload-or-restartzreload-or-try-restart�status)r�r�r�r�r��reloadz
try-reloadr�Tr�)rTr�ryr)r�r�rSr�r�rT�cmdsr�rPrPrQ�manage_serviceDs.
��
zDistro.manage_service�layout�model�variantr�cCs(|��rt�dd||||g�dSt��)N�	localectlzset-x11-keymap)r�rr�)rmr�r�rr�rPrPrQ�
set_keymapis��zDistro.set_keymapcCs.tjdd�}t�|d�s|Stj�|jdd�S)NT)�	needs_exe�noexecz
cloud-init�clouddir)r�get_tmp_ancestorr�
has_mount_optr�r�r��usr_lib_exec)rm�tmp_dirrPrPrQ�get_tmp_exec_pathxszDistro.get_tmp_exec_pathrr�r��cwdc	Ks>|rd|�d�nd}tjdd|d|dd�|�gfi|��S)	a`
        Perform a command as the requested user. Behaves like subp()

        Note: We pass `PATH` to the user env by using `env`. This could be
        probably simplified after bionic EOL by using
        `su --whitelist-environment=PATH ...`, more info on:
        https://lore.kernel.org/all/20180815110445.4qefy5zx5gfgbqly@ws.net.home/T/
        zcd z && r�surKz-czenv PATH=$PATH � )rr�)rmr�r�rrZ�	directoryrPrPrQ�do_as~s	���zDistro.do_asr��
lease_file�pid_file�	interface�config_filec	Cs,|ddd|d|ddg	|rd||gS|gS)Nz-1z-vz-lfz-pfz-sfz	/bin/truez-cfrP)r�rrrrrPrPrQ�build_dhclient_cmd�s	�
�
�zDistro.build_dhclient_cmdcCs.|jdurt��|_|jst�d|j�|jS)zADetermine the network interface used during local network config.Nz0Did not find a fallback interface on distro: %s.)rkr�find_fallback_nicr�r�rar�rPrPrQ�fallback_interface�s

�zDistro.fallback_interfacecCs
||_dSr�)rk)rmr�rPrPrQr�s
�pidcC�Vt�|d�}|dur)tt��t|�Wd�S1swYt�d||�dS)�=Return the parent pid of a process by parsing /proc/$pid/statr�Nz&/proc/%s/stat has an invalid ppid [%s]�rR�_get_proc_stat_by_indexrr|r�r�r��r�matchrPrPrQ�
get_proc_ppid��
 �zDistro.get_proc_ppidcCr)r�Nz&/proc/%s/stat has an invalid pgid [%s]rrrPrPrQ�
get_proc_pgid�rzDistro.get_proc_pgid�fieldc
Cs�z%tjd|dd���}t�d|�}|st�d||�WdSt|�|��WSt	y?}zt�d||�WYd}~dSd}~wt
yQt�d||||�YdSw)	z�
        parse /proc/$pid/stat for a specific field as numbered in man:proc(5)

        param pid: integer to query /proc/$pid/stat for
        param field: field number within /proc/$pid/stat to return
        z
/proc/%s/statT)�quietz,^(\d+) (\(.+\)) ([RSDZTtWXxKPI]) (\d+) (\d+)z*/proc/%s/stat has an invalid contents [%s]Nz Failed to load /proc/%s/stat. %sz4Unable to match field %s of process pid=%s (%s) (%s))rrrLrwr�r�r�r�r`r��
IndexError)rr"r�rr�rPrPrQr�s:����	����zDistro._get_proc_stat_by_index�devicecCsLd}t�d�rd|g}nt�d�rdd|g}ntjdddd��t�|�dS)N�ejectz/lib/udev/cdrom_idz
--eject-media�eject_media_cmdzeject command not foundz.neither eject nor /lib/udev/cdrom_id are found)r��description�reason)rr�r�)r%r�rPrPrQ�eject_media�s


�zDistro.eject_media�blockdevcCs,tj�|�}|�d�rt�d||�|SdS)aReturns underlying block device for a mapped device.

        If it is mapped, blockdev will usually take the form of
        /dev/mapper/some_name

        If blockdev is a symlink pointing to a /dev/dm-* device, return
        the device pointed to. Otherwise, return None.
        z/dev/dm-z$%s is a mapped device pointing to %sN)r�r��realpath�
startswithr�r�)r+r,rPrPrQ�get_mapped_device�s

�zDistro.get_mapped_device�devpathc
Cs�tj�|�}tj�|�}d|}tj�|�std||f��tj�|d�}tj�|�s1td|��t�	|��
�}tj�|�}tj�|�}t�	tj�|d���
�}tj�d|�}	|	|fS)z�convert an entry in /dev/ to parent disk and partition number

        input of /dev/vdb or /dev/disk/by-label/foo
        rpath is hopefully a real-ish path in /dev (vda, sdb..)
        z/sys/class/block/%sz%s had no syspath (%s)�	partitionz%s not a partition�devz
/dev/block/%s)r�r�r,�basenamer
r|r�r�rr�rstripr�)
r/�rpath�bname�syspath�ptpath�ptnum�rsyspath�disksyspath�
diskmajmin�diskdevpathrPrPrQ�device_part_info
s$��zDistro.device_part_infocCr�)a�Ensure that cloud-init has network connectivity.

        For most distros, this is a no-op as cloud-init's network service is
        ordered in boot to start after network connectivity has been achieved.
        As an optimization, distros may opt to order cloud-init's network
        service immediately after cloud-init's local service, and only
        require network connectivity if it has been deemed necessary.
        This method is a hook for distros to implement this optimization.
        It is called during cloud-init's network stage if it was determined
        that network connectivity is necessary in cloud-init's network stage.
        NrPr�rPrPrQ�wait_for_network1szDistro.wait_for_networkr�)NN)F)r�)r)rrN)zrMrNrO�pip_package_namerrr�r�r�rurtrvr��
default_ownerrTrrx�__annotations__rUrr	rr0rrVr
rr�rerfrZr#�_ci_pkl_versionr�resolve_conf_fnr]r
r^rpr�rur~�PackageListrrrrr�r��propertyr!�
DhcpClientr�r �NetworkActivatorr�r%r�r�r�r�r�r��staticmethodr��abc�abstractmethodr�r�r�r�r�r��boolr�r�r�r�r�r�r�r�r�r�r
rr/r2r4rcrnr~r�r�r�r�r�ryr�r�r�r�r�rW�classmethodr�r�r�rr
rrr�setterrr!rr*r.rzr=r>rPrPrPrQrR�s

�
�5;










A+
y"4,

 
$
6
) 

����$������

		 #rR)�	metaclass�url�transformationscCs�ztj�|�}Wn
tyYdSw|j}|durdS|D]}||�}|dur,|Sq|}|jdur;d�||j�}tj�|j|d��S)a�
    Apply transformations to a URL's hostname, return transformed URL.

    This is a separate function because unwrapping and rewrapping only the
    hostname portion of a URL is complex.

    :param url:
        The URL to operate on.
    :param transformations:
        A list of ``(str) -> Optional[str]`` functions, which will be applied
        in order to the hostname portion of the URL.  If any function
        (regardless of ordering) returns None, ``url`` will be returned without
        any modification.

    :return:
        A string whose value is ``url`` with the hostname ``transformations``
        applied, or ``None`` if ``url`` is unparsable.
    Nz{}:{})�netloc)	�urllib�parse�urlsplitr|r��portr�
urlunsplit�_replace)rOrP�parts�new_hostname�transformation�
new_netlocrPrPrQ�&_apply_hostname_transformations_to_url?s"��
r\cs2td�dd�dd��fdd�dd�g}t||�S)aH
    Given a mirror URL, replace or remove any invalid URI characters.

    This performs the following actions on the URL's hostname:
      * Checks if it is an IP address, returning the URL immediately if it is
      * Converts it to its IDN form (see below for details)
      * Replaces any non-Letters/Digits/Hyphen (LDH) characters in it with
        hyphens
      * Removes any leading/trailing hyphens from each domain name label

    Before we replace any invalid domain name characters, we first need to
    ensure that any valid non-ASCII characters in the hostname will not be
    replaced, by ensuring the hostname is in its Internationalized domain name
    (IDN) representation (see RFC 5890).  This conversion has to be applied to
    the whole hostname (rather than just the substitution variables), because
    the Punycode algorithm used by IDNA transcodes each part of the hostname as
    a whole string (rather than encoding individual characters).  It cannot be
    applied to the whole URL, because (a) the Punycode algorithm expects to
    operate on domain names so doesn't output a valid URL, and (b) non-ASCII
    characters in non-hostname parts of the URL aren't encoded via Punycode.

    To put this in RFC 5890's terminology: before we remove or replace any
    characters from our domain name (which we do to ensure that each label is a
    valid LDH Label), we first ensure each label is in its A-label form.

    (Note that Python's builtin idna encoding is actually IDNA2003, not
    IDNA2008.  This changes the specifics of how some characters are encoded to
    ASCII, but doesn't affect the logic here.)

    :param url:
        The URL to operate on.

    :return:
        A sanitized version of the URL, which will have been IDNA encoded if
        necessary, or ``None`` if the generated string is not a parseable URL.
    �.cSst�|�rdS|Sr�)r�
is_ip_address�r�rPrPrQ�<lambda>�r�z&_sanitize_mirror_url.<locals>.<lambda>cSs|�d��d�S)N�idna�ascii)�encode�decoder_rPrPrQr`�scsd��fdd�|D��S)Nrc3s �|]}|�vr
|ndVqdS�rKNrPr���acceptable_charsrPrQr��s�
��9_sanitize_mirror_url.<locals>.<lambda>.<locals>.<genexpr>r�r_rfrPrQr`�s�cSsd�dd�|�d�D��S)Nr]css�|]}|�d�VqdSrerK)r��partrPrPrQr��s�

�rh)r�rTr_rPrPrQr`�s
�)�LDH_ASCII_CHARSr\)rOrPrPrfrQ�_sanitize_mirror_urljs&
�
rkc
Cs$|si}i}|r2|jr2|j|d<t�d|j�r2|jdd�}tr'd||d<n|jdkr2d||d<|r<|jr<|j|d<i}|�d	i���D]\}}|||<qF|�d
i���D]2\}}g}	|D]}
z|
|}Wn	typYq_wt	|�}|dur~|	�
|�q_||	�}|r�|||<qWt�d|�|S)N�availability_zonez#^[a-z][a-z]-(?:[a-z]+-)+[0-9][a-z]$r���r��
ec2_region�ec2�region�failsafer�zfiltered distro mirror info: %s)
rlrwrr�
platform_typerpr�r�r�rkr�r�r�)r�r��
mirror_filter�substrn�resultsra�mirror�
searchlist�mirrors�tmpl�foundrPrPrQr��sJ

�



�
��r�cCs8d}|D]}|�d�}||vr|Sd|vr|}q|S)N�archesr�)r�)r�r)r��itemr{rPrPrQr��s
�r�rarrcCsHt�|dtgdg�\}}|std||f��t�|d�}t|d�}|S)NrrRz1No distribution found for distro %s (searched %s)r)r�find_modulerM�ImportError�
import_module�getattr)ra�locs�looked_locs�modr�rPrPrQ�fetch�s��
r��
/etc/timezone�/etc/localtimecCsjt�|t|���d�|r3|r3tj�|�}|stj�|�s-|r%t�|�t�	||�dSt�
||�dS)Nr�)rr$rxr3r�r��islinkr
�del_file�symlink�copy)r�r��tz_conf�tz_localr�rPrPrQ�set_etc_timezone�s
�r�cCs.zt�d�}t�|j�WStyYdSw)Nz/run/systemd/systemF)r��lstat�stat�S_ISDIR�st_moder�)�resrPrPrQr�s
�r�)Nr�r�)WrIr�r�rwr��string�urllib.parserR�collectionsr�
contextlibr�ior�typingrrrrr	r
rrr
r�cloudinit.net.netops.iproute2r�netopsre�	cloudinitrrrrrrrrr�cloudinit.distros.networkingrr�4cloudinit.distros.package_management.package_managerr�*cloudinit.distros.package_management.utilsr�cloudinit.distros.parsersr�cloudinit.featuresr�cloudinit.lifecycler�
cloudinit.netr r!r"�cloudinit.net.netopsr#�cloudinit.net.network_stater$�cloudinit.net.rendererr%�ALL_DISTROSr�	getLoggerrMr�r1�
ascii_letters�digitsrjrxrDr�rL�CloudInitPickleMixin�ABCMetarRryr\rk�search_for_mirrorr�r�r�r�r�rPrPrPrQ�<module>s�0
0
�
'
��	I+<
�8
�

Anon7 - 2022
AnonSec Team