404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.145.12.185: ~ $
3

\�me9T�@slddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZmZm
Z
ddlZddlmZmZmZddlmZmZmZmZmZeje�ZdZdZGdd	�d	e�ZGd
d�de�Z Gdd
�d
e�Z!Gdd�de�Z"Gdd�de�Z#dd�Z$d$dd�Z%dd�Z&d%dd�Z'd&dd�Z(Gdd�dej)�Z*Gdd�de*�Z+Gd d!�d!�Z,Gd"d#�d#e*�Z-dS)'�N)�StringIO)�Any�Dict�List)�subp�
temp_utils�util)�find_fallback_nic�get_devicelist�get_ib_interface_hwaddr�get_interface_mac�is_ib_interfacez/run/systemd/netif/leasesaN#!/bin/sh
log() {
    echo "udhcpc[$PPID]" "$interface: $2"
}
[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
case $1 in
    bound|renew)
    cat <<JSON > "$LEASE_FILE"
{
    "interface": "$interface",
    "fixed-address": "$ip",
    "subnet-mask": "$subnet",
    "routers": "${router%% *}",
    "static_routes" : "${staticroutes}"
}
JSON
    ;;
    deconfig)
    log err "Not supported"
    exit 1
    ;;
    leasefail | nak)
    log err "configuration failed: $1: $message"
    exit 1
    ;;
    *)
    echo "$0: Unknown udhcpc command: $1" >&2
    exit 1
    ;;
esac
c@seZdZdZdS)�NoDHCPLeaseErrorz'Raised when unable to get a DHCP lease.N)�__name__�
__module__�__qualname__�__doc__�rr�/usr/lib/python3.6/dhcp.pyrAsrc@seZdZdZdS)�InvalidDHCPLeaseFileErrorz�Raised when parsing an empty or invalid dhclient.lease file.

    Current uses are DataSourceAzure and DataSourceEc2 during ephemeral
    boot to scrape metadata.
    N)rrrrrrrrrEsrc@seZdZdZdS)�NoDHCPLeaseInterfaceErrorz7Raised when unable to find a viable interface for DHCP.N)rrrrrrrrrMsrc@seZdZdZdS)�NoDHCPLeaseMissingDhclientErrorz$Raised when unable to find dhclient.N)rrrrrrrrrQsrc@seZdZdZdS)�NoDHCPLeaseMissingUdhcpcErrorz)Raised when unable to find udhcpc client.N)rrrrrrrrrUsrc
CsZxN|jD]D}y|�}tjd|j�|Sttfk
rJtjd|j�YqXqWt��dS)z�distros set priority list, select based on this order which to use

    If the priority dhcp client isn't found, fall back to lower in list.
    zDHCP client selected: %szDHCP client not found: %sN)Zdhcp_client_priority�LOG�debug�client_namerr�warning)�distro�clientZdhcp_clientrrr�select_dhcp_clientYsrcCsZ|dkr(t�}|dkrDtjd�t��n|t�krDtjd|�t��t|�}|j|||�S)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.)r	rrrr
r�dhcp_discovery)rZnic�
dhcp_log_funcrrrr�maybe_perform_dhcp_discoveryks


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)�dict�	configobjZ	ConfigObjr)Zcontentrrr�networkd_parse_lease�sr%cCsT|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_DIR�os�path�isdir�listdirr%r�	load_file�join)�leases_d�retZlfilerrr�networkd_load_leases�sr/cCsF|dkrt}t|d�}x*t|j��D]\}}|j|�r$||Sq$WdS)N)r-)r&r/�sorted�items�get)Zkeynamer-ZleasesZ_ifindex�datarrr�networkd_get_option_from_leases�s

r4c@sLeZdZdZedd��Zedd��Zeed�dd��Zeed�d	d
��Z	dS)�
DhcpClient�cCstjd|jgddgd�dS)NZpkillr�)�rcs)rr)�clsrrr�kill_dhcp_client�szDhcpClient.kill_dhcp_clientcCs.|j�tjd�}x|D]}tj|�qWdS)Nz/var/lib/dhcp/*)r:�globr'�remove)r9�files�filerrr�clear_leases�s

zDhcpClient.clear_leases)�dhcp_interfacecCs|jd|j|ddgd�dS)N�startrr7)r8)�manage_servicer)r9r@rrrr�
start_service�szDhcpClient.start_servicecCs|jd|jddgd�dS)N�stoprr7)r8)rBr)r9r@rrrr�stop_service�szDhcpClient.stop_serviceN)
rrrr�classmethodr:r?�strrCrErrrrr5�sr5c@steZdZdZdd�Zeeeeee	fd�dd��Z
ddd	�Zed
d��Zedd
��Z
eddd��Zedd��ZdS)�IscDhclient�dhclientcCs&tjd�|_|js"tjd�t��dS)NrIz7Skip dhclient configuration: No dhclient command found.)r�which�
dhclient_pathrrr)�selfrrr�__init__�s
zIscDhclient.__init__)�
lease_file�returncCs�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)a7Parse the given dhcp lease file returning all leases as dicts.

        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}�;�"r6zoption � r7z1Cannot parse dhcp lease file {0}. No leases found)�re�compile�DOTALLrr+�lenr�format�findall�split�strip�replace�appendr#)rNZlease_regexZdhcp_leasesZ
lease_contentZleaseZ
lease_options�linerrr�parse_dhcp_lease_file�s&

z!IscDhclient.parse_dhcp_lease_fileNc!Cstjd|�d}d}d}tjt��tj|�tj|�WdQRX|jj|�t	|�r�dt
|�dd�}d||f}tjdd	�}	tj
j|	|d
�}tj||�y"tj|j|j||||��\}
}WnBtjk
�r}z"tjd|j|j|j�t|�WYdd}~XnXtj||gdd
d�}
|
�r@tjddjdd�|
D���gSd}d}x�tdd�D]v}tj|�j�}yt|�}Wntk
�r�Yn6Xtj |�}|dk�r�tjd|�tj!|t"j#�d}Pt$j%d
��qTW|�s�tj&d||d�|dk	�r�||
|�|j'|�S)a�Run dhclient on the interface without scripts/filesystem artifacts.

        @param dhclient_cmd_path: Full path to the dhclient used.
        @param interface: Name of the network interface on which to dhclient.
        @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 dhclient.lease file or empty list.
        z!Performing a dhcp discovery on %sz/run/dhclient.pidz/run/dhclient.leaseNz20:%s�$z0interface "%s" {send dhcp-client-identifier %s;}T)�	needs_exez-dhclient.confz3dhclient exited with code: %s stderr: %r stdout: %r�g{�G�z�?)ZmaxwaitZnaplenz+dhclient did not produce expected files: %sz, css|]}tjj|�VqdS)N)r'r(�basename)�.0�frrr�	<genexpr>Isz-IscDhclient.dhcp_discovery.<locals>.<genexpr>�unknownFri�r7zkilling dhclient with pid=%szCdhclient(pid=%s, parentpid=%s) failed to daemonize after %s secondsg$@)(rr�
contextlib�suppress�FileNotFoundErrorr'r<�net_ops�link_upr
rr�get_tmp_ancestorr(r,r�
write_filerZbuild_dhclient_cmdrK�ProcessExecutionError�	exit_code�stderr�stdoutrZwait_for_filesr�ranger+rZ�int�
ValueErrorZ
get_proc_ppid�kill�signal�SIGKILL�timeZsleep�errorr^)rL�	interfacer!rZpid_filerNZconfig_file�dhcp_client_identifierZinterface_dhclient_content�tmp_dir�out�errryZmissingZppidZ
daemonized�_Zpid_content�pidrrrr �sz

	



zIscDhclient.dhcp_discoverycs�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
        rPcSsg|]}|r|�qSrr)rc�tokrrr�
<listcomp>�sz3IscDhclient.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)rry)ZcidrZrequiredZremain�msg)�rfc3442rr�_trunc_error�sz5IscDhclient.parse_static_routes.<locals>._trunc_errorr��!�	N�.r7ra����0����z0.0.0.0zSParsed invalid net length "%s".  Verify DHCP rfc3442-classless-static-routes value.z%s/%s)�rstriprSrY�	enumeratersrrrVr,rryr\)r��tokens�
static_routesr�Zcurrent_idx�idxr�Z
net_lengthZreq_toksZnet_addressZgatewayr)r�r�parse_static_routesjsr!
	 " 


zIscDhclient.parse_static_routescCsJdddg}x:|D]2}tjj|�rttj|��dkrtjd|�|SqWdS)Nz/var/lib/dhclientz
/var/lib/dhcpz/var/lib/NetworkManagerrzUsing %s lease directory)r'r(�existsrVr*rr)Zsupported_dirs�drrr�get_dhclient_d�s
zIscDhclient.get_dhclient_dcCs~|dkrtj�}|sdStj|�}d}d}xN|D]F}|jd�r@q0|jd�sLq0tjj||�}tjj|�}||kr0|}|}q0W|S)Nr7Z	dhclient6�.lease�.leases���)r�r�)	rHr�r'r*�
startswith�endswithr(r,�getmtime)Zlease_dZlease_filesZlatest_mtimeZlatest_fileZfnameZabs_path�mtimerrr�get_latest_lease�s$




zIscDhclient.get_latest_leasecCsdt|d��P}xH|D]@}d|kr|jd�jd�}t|�dkr|d}tjd|�|}qWWdQRX|S)N�rzdhcp-server-identifierz ;
rRr�zFound DHCP identifier %s)�openrZrYrVrr)rN�fdr]ZwordsZdhcptokZlatest_addressrrr�!parse_dhcp_server_from_lease_files
z-IscDhclient.parse_dhcp_server_from_lease_file)NN)N)rrrrrM�staticmethodrGrrrr^r r�r�r�r�rrrrrH�s$
rk rHc@seZdZdZdd�ZdS)�DhcpcdZdhcpcdcCstd��dS)NzDhcpcd not yet implemented)r)rLrrrrMszDhcpcd.__init__N)rrrrrMrrrrr�sr�c@s"eZdZdZdd�Zddd�ZdS)�Udhcpc�udhcpccCs&tjd�|_|js"tjd�t��dS)Nr�z3Skip udhcpc configuration: No udhcpc command found.)rrJ�udhcpc_pathrrr)rLrrrrMs
zUdhcpc.__init__NcCs�tjd|�tjdd�}tjj||d�}tjt	��tj
|�WdQRX|jj|�tjj|d�}t
j|td�|jdd	d
|d|dd
ddg}t|�r�t|dd�}|jdd|jdd�g�ytj|d|idd�\}	}
WnBtjk
�r}z"tjd|j|j|j�t|�WYdd}~XnX|dk	�r0||	|
�t
jt
j|��}|dj�}
|
�r~dd�t|
ddd�|
ddd��D�|d<|gS)asRun udhcpc on the interface without scripts or filesystem artifacts.

        @param interface: Name of the network interface on which to run udhcpc.
        @param dhcp_log_func: A callable accepting the udhcpc output and
            error streams.

        @return: A list of dicts of representing the dhcp leases parsed from
            the udhcpc lease file.
        z!Performing a dhcp discovery on %sT)r`z.lease.jsonN�
udhcpc_scripti�z-OZstaticroutesz-iz-sz-nz-qz-fz-v)Zethernet_formatz-xz0x3d:%s�:r6Z
LEASE_FILE)Z
update_envZcapturez1udhcpc exited with code: %s stderr: %r stdout: %rr�cSsg|]}|�qSrr)rc�irrrr�ksz)Udhcpc.dhcp_discovery.<locals>.<listcomp>r�r7)rrrrlr'r(r,rgrhrir<rjrkrrm�
UDHCPC_SCRIPTr�r
r�extendr[rrnrorprqrZ	load_jsonr+rY�zip)rLrzr!rr|rNr��cmdr{r}r~ryZ
lease_jsonr�rrrr !sR


,zUdhcpc.dhcp_discovery)NN)rrrrrMr rrrrr�s	r�)NN)N)N).�abcrgr;Zloggingr'rSrvrx�iorZtypingrrrr$Z	cloudinitrrrZ
cloudinit.netr	r
rrr
Z	getLoggerrrr&r��	Exceptionrrrrrrr"r%r/r4�ABCr5rHr�r�rrrr�<module>s>




L

Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 33.43 KB 0644
__init__.cpython-36.pyc File 33.43 KB 0644
activators.cpython-36.opt-1.pyc File 9.52 KB 0644
activators.cpython-36.pyc File 9.52 KB 0644
bsd.cpython-36.opt-1.pyc File 5.74 KB 0644
bsd.cpython-36.pyc File 5.74 KB 0644
cmdline.cpython-36.opt-1.pyc File 7.2 KB 0644
cmdline.cpython-36.pyc File 7.2 KB 0644
dhcp.cpython-36.opt-1.pyc File 15.98 KB 0644
dhcp.cpython-36.pyc File 15.98 KB 0644
eni.cpython-36.opt-1.pyc File 12.89 KB 0644
eni.cpython-36.pyc File 12.89 KB 0644
ephemeral.cpython-36.opt-1.pyc File 10.51 KB 0644
ephemeral.cpython-36.pyc File 10.51 KB 0644
freebsd.cpython-36.opt-1.pyc File 2.54 KB 0644
freebsd.cpython-36.pyc File 2.54 KB 0644
netbsd.cpython-36.opt-1.pyc File 1.69 KB 0644
netbsd.cpython-36.pyc File 1.69 KB 0644
netplan.cpython-36.opt-1.pyc File 11.91 KB 0644
netplan.cpython-36.pyc File 11.91 KB 0644
network_manager.cpython-36.opt-1.pyc File 12.83 KB 0644
network_manager.cpython-36.pyc File 12.83 KB 0644
network_state.cpython-36.opt-1.pyc File 27.57 KB 0644
network_state.cpython-36.pyc File 27.57 KB 0644
networkd.cpython-36.opt-1.pyc File 8.21 KB 0644
networkd.cpython-36.pyc File 8.21 KB 0644
openbsd.cpython-36.opt-1.pyc File 2.18 KB 0644
openbsd.cpython-36.pyc File 2.18 KB 0644
renderer.cpython-36.opt-1.pyc File 1.82 KB 0644
renderer.cpython-36.pyc File 1.82 KB 0644
renderers.cpython-36.opt-1.pyc File 1.53 KB 0644
renderers.cpython-36.pyc File 1.53 KB 0644
sysconfig.cpython-36.opt-1.pyc File 23.07 KB 0644
sysconfig.cpython-36.pyc File 23.07 KB 0644
udev.cpython-36.opt-1.pyc File 1.22 KB 0644
udev.cpython-36.pyc File 1.31 KB 0644