o nnh@sddlmZddlZddlmZddlmZddlmZddl m Z ddl m Z ddl mZdd lmZdd d ZGd ddeZdS)) annotationsN)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).0xrJ/usr/local/lib/python3.10/dist-packages/ansible/plugins/become/__init__.py sz_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&s zBecomeBase.__init__csHz tt|j||dWSty#gd}||vrt||dYSw)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) become_user become_pass become_flags become_exeN)rr get_optionKeyErrorgetattr)roptionr playcontext pc_fallbackrrrr$+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_prompt8szBecomeBase.expect_promptcCs|t|||jfs |Sztd|j|j|j|f}Wnty+td|j|j fwt |dd}|r<|ss    z!BecomeBase._build_success_commandcCst|_d|j|_dS)NzBECOME-SUCCESS-%s)rrr)rr5r6rrrbuild_become_commandLszBecomeBase.build_become_commandcs&t|jtfdd|dDS)Nc3s|] }|vVqdSr )rstripr l b_successrrrSsz+BecomeBase.check_success..T)rrany splitlinesrb_outputrr>r check_successQs zBecomeBase.check_successcs2|jrt|jtfdd|DSdS)z; checks if the expected password prompt exists in b_output c3s|] }|VqdSr )strip startswithr<b_promptrrrYsz3BecomeBase.check_password_prompt..F)r*rrEr@rArBrrGrcheck_password_promptUsz BecomeBase.check_password_promptcCstt|j|}|o ||vS)zM returns True/False if domain specific i18n version of msg is found in b_out )rrr4)rb_outmsgb_failrrr_check_password_error\s z BecomeBase._check_password_errorcC"|jD] }|||rdSqdSNTF)failrMrrC errstringrrrcheck_incorrect_passworda  z#BecomeBase.check_incorrect_passwordcCrNrO)missingrMrQrrrcheck_missing_passwordgrTz!BecomeBase.check_missing_password)NN)F)__name__ __module__ __qualname__r4tuplerPrU require_ttyr*rr$r+r9rr:rDrIrMrSrV __classcell__rrrrrs"   r)r ) __future__rr.abcrrandomrstringrgettextransible.errorsr+ansible.module_utils.common.text.convertersransible.pluginsr rrrrrrs