MOON
Server: Apache
System: Linux vps.erhabenn.com.br 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User: machen (1008)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyc
�
d�bc@s�ddlZddlZddlZddljjjZddljjjZddl	jjj
Z
ddljjZddl
mZddlmZddlmZdefd��YZdS(i����N(tOSUtilError(t
DefaultOSUtil(tustrt
FreeBSDOSUtilcBs[eZd�Zed��Zd�Zd�Zd"d"d�Zd�Z	ddd�Z
d	�Zd
�Zd�Z
ed��Zed
��Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zed�Zd"d"d�Zd�Zd�Zd�Z d�Z!ed��Z"d �Z#ed!��Z$RS(#cCs)tt|�j�t|_t|_dS(N(tsuperRt__init__tFalset_scsi_disks_timeout_settTruetjit_enabled(tself((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyR!s	cCsdS(Ns/usr/local/sbin((((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytget_agent_bin_path&scCsgd}tj|�jd�}tj|d|�tj|dj|��|jd|gdt�dS(Ns/etc/rc.confs
thostnamet	log_error(	tfileutilt	read_filetsplitttextutiltset_ini_configt
write_filetjoint_run_command_without_raisingR(R
Rtrc_file_patht	conf_file((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytset_hostname*s
cCstjddt�S(Nsservice sshd restarttchk_err(t	shellutiltrunR(R
((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytrestart_ssh_service1scCs�|j|�}|dk	r/tjd|�dS|dk	rVdd|d|dg}ndd|dg}|dk	r�|jd|g�n|j|dd	j|��dS(
s5
        Create user account with 'username'
        s%User {0} already exists, skip useraddNtpwtuseradds-es-ms-cterr_msgs!Failed to create user account:{0}(t
get_userentrytNonetloggertwarntextendt _run_command_raising_OSUtilErrortformat(R
tusernamet
expirationtcommentt	userentrytcmd((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyR4scCsb|j|�r"tjd|�n|jddg�|jdd|g�|j|dt�dS(Ns){0} is a system user. Will not delete it.ttouchs/var/run/utx.activetrmusers-ytremove(tis_sys_userR"terrorRtconf_sudoerR(R
R'((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytdel_accountEs
ii
cCsq|j|�r'tdj|���ntj|||�}|jdd|ddgd|ddj|��dS(	Ns1User {0} is a system user, will not set password.Rtusermods-Ht0t	cmd_inputRsFailed to set password for {0}(R/RR&Rtgen_password_hashR%(R
R'tpasswordtcrypt_idtsalt_lentpasswd_hash((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytchpasswdLs	!cCs(tjd�}|r$td��ndS(Nspw usermod root -h -sCFailed to delete root password: Failed to update password database.(RRR(R
terr((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytdel_root_passwordTscCs:|j�}|d|kr6|djdd�j�SdS(Niit:t(t
_get_net_infotreplacetupperR!(R
tifnametdata((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyt
get_if_macYscCs|j�d S(Ni(R@(R
((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytget_first_if_scs�d�}d��d����fd���fd��d�����fd�}dg}y|�}t|�d	krmg}d
|d	kr�|jd
�nd|d	kr�|jd�nd|d	kr�|jd�nd
|d	kr|jd
�n|r%tdj|���nxE|D]:}y||�}|j|�Wq,tk
req,q,Xq,WnWn)tk
r�}tjdt|��nX|S(sy
        Return a list of strings comprising the route table as in the Linux /proc/net/route format. The input taken is from FreeBSDs
        `netstat -rn -f inet` command. Here is what the function does in detail:

        1. Runs `netstat -rn -f inet` which outputs a column formatted list of ipv4 routes in priority order like so:

            > Routing tables
            > 
            > Internet:
            > Destination        Gateway            Flags    Refs      Use  Netif Expire
            > default            61.221.xx.yy       UGS         0      247    em1
            > 10                 10.10.110.5        UGS         0       50    em0
            > 10.10.110/26       link#1             UC          0        0    em0
            > 10.10.110.5        00:1b:0d:e6:58:40  UHLW        2        0    em0   1145
            > 61.221.xx.yy/29    link#2             UC          0        0    em1
            > 61.221.xx.yy       00:1b:0d:e6:57:c0  UHLW        2        0    em1   1055
            > 61.221.xx/24       link#2             UC          0        0    em1
            > 127.0.0.1          127.0.0.1          UH          0        0    lo0
        
        2. Convert it to an array of lines that resemble an equivalent /proc/net/route content on a Linux system like so:

            > Iface   Destination Gateway     Flags   RefCnt  Use Metric  Mask        MTU Window  IRTT
            > gre828  00000000    00000000    0001    0   0   0   000000F8    0   0   0
            > ens160  00000000    FE04700A    0003    0   0   100 00000000    0   0   0
            > gre828  00000008    00000000    0001    0   0   0   000000FE    0   0   0
            > ens160  0004700A    00000000    0001    0   0   100 00FFFFFF    0   0   0
            > gre828  2504700A    00000000    0005    0   0   0   FFFFFFFF    0   0   0
            > gre828  3704700A    00000000    0005    0   0   0   FFFFFFFF    0   0   0
            > gre828  4104700A    00000000    0005    0   0   0   FFFFFFFF    0   0   0

        :return: Entries in the ipv4 route priority list from `netstat -rn -f inet` in the linux `/proc/net/route` style
        :rtype: list(str)
        cSs;ddddg}tj|dt�}|jd�}t|�dkrWtd��ng|D]}|r^|j�^q^}d	|kr�td
��n|jd	�d}|d}tg||D]}t|�^q��}g||D]}|j	|�^q�}||j�}t|�}	i}
xYt
d|	d�D]D}||j||�||j||d�df|
||<q9W||j||	d�df|
||	d<g}t|�}
xtt
d|
�D]c}i}x9|
D]1}|||
|d|
|d!j�||<q�W|
||d
<|j|�q�W|S(s�
            Runs `netstat -rn -f inet` and parses its output and returns a list of routes where the key is the column name
            and the value is the value in the column, stripped of leading and trailing whitespace.

            :return: List of dictionaries representing routes in the ipv4 route priority list from `netstat -rn -f inet`
            :rtype: list(dict)
            tnetstats-rns-ftinetR
s
is.`netstat -rn -f inet` output seems to be emptys	Internet:s<`netstat -rn -f inet` output seems to contain no ipv4 routesiitMetricN(
Rtrun_commandRRtlenRtstriptindextmaxtljusttrangeR!tappend(R+toutputtoutput_linestlinetroute_header_linetroute_start_linetroute_line_lengthtnetstat_route_listt_route_headerstn_route_headerst
route_columnstitnetstat_routestn_netstat_routest
netstat_routetcolumn((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyt_get_netstat_rn_ipv4_routes�s<%
)&.
(c
SsEdttjtjdtjdtjtj|��d��d�S(s

            Converts an IPv4 32bit address from its ASCII notation (ie. 127.0.0.1) to an 8 digit padded hex notation
            (ie. "0100007F") string.

            :return: 8 character long hex string representation of the IP
            :rtype: string
            s%08Xs!Is=Iii(	tinttbinasciithexlifytstructtpacktunpacktsockett	inet_ptontAF_INET(tipv4_ascii_address((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyt_ipv4_ascii_address_to_hex�s	cSs;djtjdtjddd|>d@��d�j�S(s$
            Converts an subnet mask from its CIDR integer notation (ie. 32) to an 8 digit padded hex notation
            (ie. "FFFFFFFF") string representing its bitmask form.

            :return: 8 character long hex string representation of the IP
            :rtype: string
            s{0:08x}s=Is!II����i i(R&ReRgRfRB(tipv4_cidr_mask((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyt_ipv4_cidr_mask_to_hex�scs�d}d}|dkrn|dkr-d}qn|jd�}t|�dkrat|d�}n|d}n�|�}�|�}||fS(	s�
            Converts an destination address from its CIDR notation (ie. 127.0.0.1/32 or default or localhost) to an 8
            digit padded hex notation (ie. "0100007F" or "00000000" or "0100007F") string and its subnet bitmask
            also in hex (FFFFFFFF).

            :return: tuple of 8 character long hex string representation of the IP and 8 character long hex string representation of the subnet mask
            :rtype: tuple(string, int)
            s0.0.0.0i tdefaultt	localhosts	127.0.0.1t/ii(RRKRb(tdestinationtdestination_iptdestination_subnetmaskthex_destination_ipthex_destination_subnetmask(RlRn(sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyt_ipv4_cidr_destination_to_hex�s		
cs*y�|�SWntjk
r%dSXdS(s�
            If the gateway is an IPv4 address, return its IP in hex, else, return "00000000"

            :return: 8 character long hex string representation of the IP of the gateway
            :rtype: string
            t00000000N(RhR0(tgateway(Rl(sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyt_try_ipv4_gateway_to_hex�scSs�d}d}d}d}d}d|kr7||O}nd|krP||O}nd|kri||O}nd	|kr�||O}n|S(
s�
            Converts route flags to a bitmask of their equivalent linux/route.h values.

            :return: integer representation of a 16 bit mask
            :rtype: int
            iiiiitUtGtHtS((tascii_route_flagst
bitmask_flagstRTF_UPtRTF_GATEWAYtRTF_HOSTtRTF_DYNAMIC((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyt_ascii_route_flags_to_bitmask�s



cs�|d}�|d�\}}�|d�}�|d�}d}d}|d}d}	d}
d}dj|||||||||	|
|�S(s�
            Converts a single FreeBSD `netstat -rn -f inet` route to its equivalent /proc/net/route line. ie:
            > default            0.0.0.0       UGS         0      247    em1
            to
            > em1  00000000    00000000    0003    0   0   0   FFFFFFFF    0   0   0

            :return: string representation of the equivalent /proc/net/route line
            :rtype: string
            tNetiftDestinationtGatewaytFlagsiRIs,{0}	{1}	{2}	{3}	{4}	{5}	{6}	{7}	{8}	{9}	{10}(R&(R_tnetwork_interfaceRuRvthex_gatewayR�tdummy_refcountt	dummy_usetroute_metrict	dummy_mtutdummy_windowt
dummy_irtt(R�RwRz(sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyt1_freebsd_netstat_rn_route_to_linux_proc_net_routes,


sFIface	Destination	Gateway	Flags	RefCnt	Use	Metric	Mask	MTU	Window	IRTTiR�R�R�R�sz`netstat -rn -f inet` output is missing columns required to convert to the Linux /proc/net/route format; columns are [{0}]sCannot read route table [{0}](RKRQtKeyErrorR&t	ExceptionR"R0R(RaR�tlinux_style_route_fileR]tmissing_headersR_tlinux_style_routete((R�RlRwRnRzsI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytread_route_tablebsB$	/			"		

cCs]g}t|�}|dkr.tjd�n+|dkrJtjd�ntj|�}|S(s�
        Construct a list of all network routes known to this system.

        :param list(str) route_table: List of text entries from route table, including headers
        :return: a list of network routes
        :rtype: list(RouteEntry)
        is&netstat -rn -f inet is missing headerss&netstat -rn -f inet contains no routes(RKR"R0Rt_build_route_list(troute_tablet
route_listtcount((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytget_list_of_routesGs	csd�d�d}|js+tjd�n|j�}��fd�}tt||j|���}t|�dkr�d�}t	|d|�}|j
}n|dkr�d}|jstjd	�tjd
�t|_qntjdj
|��t|_|S(
s
        Get the name of the primary interface, which is the one with the
        default route attached to it; if there are multiple default routes,
        the primary has the lowest Metric.
        :return: the interface which has the default route
        iRxs3Examine `netstat -rn -f inet` for primary interfacecs|j�ko�|j@S(N(Rrtflags(troute(tDEFAULT_DESTR�(sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyt
is_defaultlsicSs
t|j�S(N(Rbtmetric(R�((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyt
get_metricrstkeyR?sGCould not determine primary interface, please ensure routes are corrects1Primary interface examination will retry silentlysPrimary interface is [{0}]N(R!tdisable_route_warningR"tinfoR�tlisttfilterR�RKtmint	interfaceR#RR&R(R
tprimary_interfaceR�R�t
candidatesR�t
primary_route((R�R�sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytget_primary_interface[s*			

	cCs|j�|kS(s�
        Indicate whether the specified interface is the primary.
        :param ifname: the name of the interface - eth0, lo, etc.
        :return: True if this interface binds the default route
        (R�(R
RC((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytis_primary_interface�scCs
|jd�S(s=
        Determine if a named interface is loopback.
        tlo(t
startswith(R
RC((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytis_loopback�scCs(dj|||�}tj|dt�S(Nsroute add {0} {1} {2}R(R&RRR(R
tnettmaskRyR+((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyt	route_add�scCs\d}d}|j�}|j|�}x.|D]&}|j|kr.||j@r.tSq.WtS(s�
        For FreeBSD, the default broadcast goes to current default gw, not a all-ones broadcast address, need to
        specify the route manually to get it work in a VNET environment.
        SEE ALSO: man ip(4) IP_ONESBCAST,
        iRx(R�R�RrR�RR(R
R�R�R�troutesR�((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytis_missing_default_route�s
cCstS(N(R(R
((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytis_dhcp_enabled�scCs&tjdj|j��dt�dS(Ns/etc/rc.d/dhclient start {0}R(RRR&tget_if_nameR(R
((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytstart_dhcp_service�scCsdS(N((R
((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytallow_dhcp_broadcast�scCstjdj|�dt�S(Ns$route add 255.255.255.255 -iface {0}R(RRR&R(R
RC((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytset_route_for_dhcp_broadcast�scCs tjdj|�dt�dS(Ns'route delete 255.255.255.255 -iface {0}R(RRR&R(R
RC((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytremove_route_for_dhcp_broadcast�scCs|jdddg�S(Ntpgreps-ntdhclient(t
_get_dhcp_pid(R
((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytget_dhcp_pid�scCsR|j�}tjdj|��}|rN|dkrNtdj|���ndS(Nscdcontrol -f {0} ejectisFailed to eject dvd: ret={0}(tget_dvd_deviceRRR&R(R
Rtdvdtretcode((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyt	eject_dvd�scCs tjdj|�dt�dS(Ns/etc/rc.d/dhclient restart {0}R(RRR&R(R
RCtretriestwait((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyt
restart_if�scCs|d}tj|�\}}|r9tdj|���nyt|�ddSWn&tk
rwtdj|���nXdS(Ns#sysctl hw.physmem |awk '{print $2}'sFailed to get total memory: {0}i(Rtrun_get_outputRR&Rbt
ValueError(R
R+tretRR((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyt
get_total_mem�s
cCsetjd�\}}|r*td��nyt|�SWn&tk
r`tdj|���nXdS(Ns sysctl hw.ncpu |awk '{print $2}'sFailed to get processor cores.sFailed to get total memory: {0}(RR�RRbR�R&(R
R�RR((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytget_processor_cores�s
cCsV|jr
dStjdj|��\}}|rItdj|���nt|_dS(Ns&sysctl kern.cam.da.default_timeout={0}s"Failed set SCSI disks timeout: {0}(RRR�R&RR(R
ttimeoutR�RR((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytset_scsi_disks_timeout�s	cCs"tjdj|�dt�dkS(Ns	ps -p {0}Ri(RRR&R(R
tpid((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytcheck_pid_alive�scCs@d}d}d}tjddt�\}}|rKtdj|���n|j�}|sltd��n|d}tjd|dt�\}}|r�tdj|���nxg|jd	�D]V}|jd
�dkr�|j�d}q�|jd
�dkr�|j�d}q�q�Wtjd|||�|||fS(s�
        There is no SIOCGIFCONF
        on freeBSD - just parse ifconfig.
        Returns strings: iface, inet4_addr, and mac
        or 'None,None,None' if unable to parse.
        We will sleep and retry as the network must be up.
        R?sifconfig -l etherRsCan't find ether interface:{0}sCan't find ether interface.is	ifconfig s Can't get info for interface:{0}s
sinet i����isether sInterface info: ({0},{1},{2})(	RR�RRR&RtfindR"tverbose(tifaceRHtmacR<RRtifacesRT((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyR@�s(	
c
Cs|dkrdSd}|dkr5d}|d}ntjd�\}}|rTdSdt|�}dj||�}d	j|�}tj|�\}}|r�dS|d
}tj|�\}}|j�}dj|�}	tj|	�\}}|dkrt|j�}d
j|�}
tj|
�\}}|dkrtx3|j�jd�D]}|jd�sQ|SqQWqtndj|�}tj|�\}}|dkr|j�}d
j|�}
tj|
�\}}|dkrx3|j�jd�D]}|jd�s�|Sq�WqndS(s>
        Return device name attached to ide port 'n'.
        iRxit00000001is2sysctl dev.storvsc | grep pnpinfo | grep deviceid=t000s{0}-{1}s5sysctl dev.storvsc | grep pnpinfo | grep deviceid={0}s|awk -F . '{print $3}'s;camcontrol devlist -b | grep blkvsc{0} | awk '{{print $1}}'is[camcontrol devlist | grep {0} | awk -F \( '{{print $2}}'|sed -e 's/.*(//'| sed -e 's/).*//'t,tpasss<camcontrol devlist -b | grep storvsc{0} | awk '{{print $1}}'N(R!RR�RR&trstripRR�(
R
tport_idtg0R<RRtg1tg0g1tcmd_search_idetcmd_extract_idtcmd_search_blkvsctcmd_search_devtpossibletcmd_search_storvsc((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytdevice_for_ide_portsN

cCsdS(Ni((((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pytget_total_cpu_ticks_since_boot=sN(%t__name__t
__module__RtstaticmethodRRRR!RR2R;R=RERFR�R�R�R�R�R�R�R�R�R�R�R�R�RR�R�R�R�R�R�R@R�R�(((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyRs@							�	)											
	
			"	9(RhReRct%azurelinuxagent.common.utils.fileutiltcommontutilsRt&azurelinuxagent.common.utils.shellutilRt%azurelinuxagent.common.utils.textutilRtazurelinuxagent.common.loggerR"t azurelinuxagent.common.exceptionRt%azurelinuxagent.common.osutil.defaultRtazurelinuxagent.common.futureRR(((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/osutil/freebsd.pyt<module>s