a )g@sddlmZmZmZeZddlZddlmZddl m Z ddl m Z ddl mZddlmZddlmZdd lmZdd d ZGd ddeZdS))absolute_importdivisionprint_functionN)abstractmethod)choice)ascii_lowercase)dgettext) AnsibleError)to_bytes) AnsiblePlugin cCsdddt|DS)zH return random string used to identify the current privilege escalation css|]}ttVqdSN)rr).0xrC/usr/lib/python3.9/site-packages/ansible/plugins/become/__init__.py z_gen_id..)joinrange)lengthrrr_gen_idsrcseZdZdZeZeZdZdZfddZ dfdd Z dd Z dd d Z e d d ZddZddZddZddZddZZS) BecomeBaseNFr cstt|d|_d|_dS)Nr )superr__init___idsuccessself __class__rrr'szBecomeBase.__init__csLztt|j||dWStyFgd}||vr6t||dYS0dS)z Overrides the base get_option to provide a fallback to playcontext vars in case a 3rd party plugin did not implement the base become options required in Ansible. )hostvars)Z become_user become_passZ become_flagsZ become_exeN)rr get_optionKeyErrorgetattr)roptionr"Z playcontextZ pc_fallbackr rrr$,s zBecomeBase.get_optioncCs|jo|dS)zThis function assists connection plugins in determining if they need to wait for a prompt. Both a prompt and a password are required. r#)promptr$rrrr expect_prompt9szBecomeBase.expect_promptcCst|||jfs|Sz td|j|j|j|f}Wn&tyZtd|j|j fYn0t |dd}|r||s|d||f}|S)Nz %s %s %s %sz=The %s shell family is incompatible with the %s become plugin executablez%s -c %s) allrshlexquoteZECHOZ COMMAND_SEPAttributeErrorr Z SHELL_FAMILYnamer&)rcmdshellZnoexeZexerrr_build_success_command?s    z!BecomeBase._build_success_commandcCst|_d|j|_dS)NzBECOME-SUCCESS-%s)rrr)rr0r1rrrbuild_become_commandMszBecomeBase.build_become_commandcs&t|jtfdd|dDS)Nc3s|]}|vVqdSr)rstriprlZ b_successrrrTrz+BecomeBase.check_success..T)r rany splitlinesrb_outputrr7r check_successRs zBecomeBase.check_successcs2|jr.t|jtfdd|DSdS)z; checks if the expected password prompt exists in b_output c3s|]}|VqdSr)strip startswithr5Zb_promptrrrZrz3BecomeBase.check_password_prompt..F)r(r r=r8r9r:rr?rcheck_password_promptVsz BecomeBase.check_password_promptcCstt|j|}|o||vS)zM returns True/False if domain specific i18n version of msg is found in b_out )r rr/)rZb_outmsgZb_failrrr_check_password_error]sz BecomeBase._check_password_errorcCs"|jD]}|||rdSqdSNTF)failrBrr;Z errstringrrrcheck_incorrect_passwordbs  z#BecomeBase.check_incorrect_passwordcCs"|jD]}|||rdSqdSrC)missingrBrErrrcheck_missing_passwordhs  z!BecomeBase.check_missing_password)NN)F)__name__ __module__ __qualname__r/tuplerDrGZ require_ttyr(rr$r)r2rr3r<r@rBrFrH __classcell__rrr rrs     r)r )Z __future__rrrtypeZ __metaclass__r,abcrZrandomrstringrgettextrZansible.errorsr Zansible.module_utils._textr Zansible.pluginsr rrrrrrs