
    x[hF)              
       J   % S r SSKrSSKrSSKrSSKrSSKJr  SSKJrJ	r	J
r
Jr  SSKJr  SSKJr  SSKJr  SSKJrJrJr  SS	KJr  SS
KJr  SSKJr  S\/\/ S.r\\S'   \R<                  " \5      r S\!S\"S\!4S jr#S\S\"S\"4S jr$S\4S jr%S\"S\S\S\!SS4
S jr&SS jr'g)zFSet Passwords: Set user passwords and enable/disable SSH password auth    N)List)features	lifecyclesubputil)Cloud)Config)
MetaSchema)ALL_DISTROSDistroug_util)log_util)PER_INSTANCE)update_ssh_configcc_set_passwords)iddistros	frequencyactivate_by_schema_keysmeta
users_listpw_typereturnc                     U (       d  / $ U  Vs/ s H2  nUR                  SS5      U:X  d  M  US   UR                  SS5      4PM4     sn$ s  snf )zDeither password or type: RANDOM is required, user is always requiredtypehashnamepasswordRANDOM)get)r   r   items      C/usr/lib/python3/dist-packages/cloudinit/config/cc_set_passwords.pyget_users_by_typer#   #   sa      	
 #
"xx'72 ;T&\488J9:"

s
   A
A
distroservice
extra_argsc                      U R                   " SU/UQ76   [        R                  S5        g ! [        R                   a   n[        R                  SU5         S nAg S nAff = f)NrestartzRestarted the SSH daemon.zm'ssh_pwauth' configuration may not be applied. Cloud-init was unable to restart SSH daemon due to error: '%s')manage_serviceLOGdebugr   ProcessExecutionErrorwarning)r$   r%   r&   es       r"   _restart_ssh_daemonr/   0   sX    
i>:>		-.%% 
>	
 	

s   ), A  AA c                    UR                  SS5      nSn[        U [        5      (       a  [        R                  " SSSS9  [
        R                  " U 5      (       a  SnOi[
        R                  " U 5      (       a  S	nOKS
U S3nU b  U R                  5       S:X  a  [        R                  SXP5        g[        R                  SXP5        g[        X405      nU(       d  [        R                  SU5        gUR                  5       (       aV  [        R                  " SSSSSU/5      R                  R!                  5       nUR                  5       S;   a  [#        XS5        gg[#        X5        g)zApply sshd PasswordAuthentication changes.

@param pw_auth: config setting from 'pw_auth'.
                Best given as True, False, or "unchanged".
@param distro: an instance of the distro class for the target distribution

@return: Nonessh_svcnamesshPasswordAuthenticationz-Using a string value for the 'ssh_pwauth' key22.2z&Use a boolean value with 'ssh_pwauth'.
deprecateddeprecated_versionextra_messageyesnozLeaving SSH config 'z' unchanged.N	unchangedz%s ssh_pwauth=%sz$%s Unrecognized value: ssh_pwauth=%sz/No need to restart SSH service, %s not updated.	systemctlshowz
--propertyActiveStatez--value)active
activating	reloadingz--job-mode=ignore-dependencies)
get_option
isinstancestrr   	deprecater   is_trueis_falselowerr*   r+   r-   r   uses_systemdr   stdoutstripr/   )pw_authr$   r%   cfg_namecfg_valbmsgupdatedstates           r"   handle_ssh_pwauthrR   <   sH    u5G'H'3F%B	

 ||G	w		%hZ|<?gmmo<II($8 	 KK>N 34G		CXN			
 & 	 ;;=AA  !A B" 	F,    r   cfgcloudargsc                 
   UR                   nU(       a  US   nSU;   a  SUS   ;   a  US   S	 O[        R                  " USS 5      nSn/ n/ nSU;   a  US   n	[        R                  " U	S/ S9nSU	;   a  U	S   (       a  [        R
                  " SS	S
S9  [        U	S   [        5      (       a.  [        R                  S5        [        R                  " U	SU5      nOY[        R
                  " SSSS9  [        R                  S5        [        R                  " U	S5      n
U
(       a  U
R                  5       n[        R                  " U	SU5      nU(       de  U(       d^  U(       aW  [        R                  " X5      u  p[        R                  " U5      u  pU(       a  U< SU< 3/nO[        R                  S5        / nU(       d  U(       Gak  [!        US5      nU VVs/ s H  u  nnUPM
     nnn[!        US5      nU VVs/ s H  u  nnUPM
     nnn/ n[!        US5       HI  u  nn[#        5       nUR%                  U5        UR%                  X45        UR%                  U SU 35        MK     [&        R(                  " S5      nU H  nUR+                  SS5      u  nnUR-                  U5      b,  SU;  a&  UR%                  UU45        UR%                  U5        MV  US:X  d  US:X  a"  [#        5       nUR%                  U< SU< 35        UR%                  UU45        UR%                  U5        M     U(       a'   [        R                  SU5        UR/                  USS9  U(       a'   [        R                  SU5        UR/                  USS9  [5        U5      (       a,  S S!R7                  U5      4n[8        R:                  " S"U-  SSS#9  U(       ag  Un[<        R>                  (       a  UU-  n/ nU H&  n URA                  U5        UR%                  U5        M(     U(       a  [        R                  S%U5        [C        URE                  S&5      U5        [5        U5      (       a$  [        R                  S'[5        U5      5        US(   eg s  snnf s  snnf ! [0         a8  nUR%                  U5        [        R2                  " [        SU5         S nAGNqS nAff = f! [0         a8  nUR%                  U5        [        R2                  " [        SU5         S nAGNS nAff = f! [0         a9  nUR%                  U5        [        R2                  " [        S$U5         S nAGMk  S nAff = f))Nr   chpasswdlistr   Tusers)defaultzConfig key 'lists'z22.3zUse 'users' instead.r5   z$Handling input for chpasswd as list.zThe chpasswd multiline stringr4   zUse string type instead.z0Handling input for chpasswd as multiline string.expire:z2No default or defined user to change password for.textr   r   z\$(1|2a|2y|5|6)(\$.+){2}   RzChanging password for %s:F)hashedz,Failed to set passwords with chpasswd for %szSetting hashed password for %s:z3Failed to set hashed passwords with chpasswd for %sz%Set the following 'random' passwords

z%s
%s
)stderrfallback_to_stdoutzFailed to set 'expire' for %szExpired passwords for: %s users
ssh_pwauthz+%s errors occurred, re-raising the last one)#r$   r   get_cfg_option_strget_cfg_option_listr   rE   rC   rY   r*   r+   
splitlinesget_cfg_option_boolr   normalize_users_groupsextract_defaultr-   r#   rand_user_passwordappendrecompilesplitmatchrX   	Exceptionlogexclenjoinr   	multi_logr   EXPIRE_APPLIES_TO_HASHED_USERSexpire_passwdrR   r    )r   rT   rU   rV   r$   r   r\   plistr   chfg	multilinerZ   _groupsuser_user_configerrorsplist_in_hashed_plist_inhashed_usersrandlistproglineupr.   blurbusers_to_expireexpired_userss                                r"   handler   ~   s   \\F73z?!:J'**3
DAFEJS:--dGRH
T>d6l/#)4
 $v,--		@A00vuE##>'-"<
 		LM 33D&A	%002E))$&A%X"99#F&66u= $h/0EKKLMF
 %Z8%-.X'$X.+J?,;<OqO<(X>GD!)+HLLOOT,-OOtfAhZ01	 ? zz56D::c1%DAqzz!}(S\&&1v.##A& 8qH}*,AOOq!$45A'Q  		5u=7 			;\J= x==8		(#E U"5U #O66</M$I((+!((+ % 		;]Kcggl+V4
6{{		?VMRj ] /<@  a G   a I  4 ! IMM!$KK%DaHHIsT   R<R	5&R #&S 0"T
S-SS
T-TT
U#-UUc           
         U S:  a  [        S5      e[        R                  " [        R                  5      [        R                  " [        R
                  5      [        R                  " [        R                  5      [        R                  " [        R                  5      /nUR                  [        [        R                  " U [        U5      -
  [        R                  [        R
                  -   [        R                  -   [        R                  -   S95      5        [        R                  " U5        SR                  U5      $ )N   z.Password length must be at least 4 characters.)select_from )
ValueErrorrandomchoicestringdigitsascii_lowercaseascii_uppercasepunctuationextendrY   r   rand_strru   shufflerv   )pwlenres_rand_lists     r"   rm   rm     s    qyIJJ 	fmm$f,,-f,,-f(()	M MMM**"MM(()(() $$%	

 NN=!77=!!rS   )   )(__doc__loggingr   ro   r   typingr   	cloudinitr   r   r   r   cloudinit.cloudr   cloudinit.configr	   cloudinit.config.schemar
   cloudinit.distrosr   r   r   cloudinit.logr   cloudinit.settingsr   cloudinit.ssh_utilr   r   __annotations__	getLogger__name__r*   rY   rD   r#   r/   rR   r   rm    rS   r"   <module>r      s    M   	   5 5 ! # . : : " + 0 }!	j  !
$ 
 
 
	
 	
 	
3 	
?-v ?-DE E6 E% Et E EP"rS   