o
    O6ufø  ã                   @   s>   d dl Z d dlmZ d dlmZmZmZ G dd„ deeƒZdS )é    N©Úglob)ÚPluginÚIndependentPluginÚ	PluginOptc                   @   sB   e Zd ZdZdZdZeddedd�gZdd	„ Z	d
d„ Z
dd„ ZdS )ÚSshzSecure shell serviceÚssh)ÚservicesÚsecurityÚsystemÚidentityÚ	userconfsTz5Changes whether module will collect user .ssh configs)ÚdefaultÚval_typeÚdescc                 C   sF   |   dddœ¡ g d¢}|  |¡ |  |¡ |  d¡r!|  ¡  d S d S )NÚsshd_configÚ
ssh_config)z/etc/ssh/sshd_config$z/etc/ssh/ssh_config$)z/etc/ssh/ssh_configz/etc/ssh/sshd_configz/etc/ssh/sshd_config.d/*r   )Úadd_file_tagsÚadd_copy_specÚincluded_configsÚ
get_optionÚuser_ssh_files_permissions)ÚselfÚsshcfgs© r   ú8/usr/lib/python3/dist-packages/sos/report/plugins/ssh.pyÚsetup   s   þ


ÿz	Ssh.setupc              	   C   sÎ   z\dd„ dd„ |D ƒD ƒ}|D ]J}|  d¡d }t|  |¡ddd��/}|D ]$}t|  ¡ ƒd	ks4| d
¡r5q%| ¡  d¡rI|  ¡ }| j|d |d� q%W d  ƒ n1 sTw   Y  qW dS  tyf   Y dS w )z Include subconfig files c                 S   s   g | ]	}|D ]}|‘qqS r   r   )Ú.0ÚfilesÚfr   r   r   Ú
<listcomp>7   s    ýþÿz(Ssh.included_configs.<locals>.<listcomp>c                 S   s   g | ]}t |d d�‘qS )T)Ú	recursiver   )r   Úcopyspecr   r   r   r    8   s    ÿú/éÿÿÿÿÚrzUTF-8)Úencodingr   ú#Úincludeé   )ÚtagsN)ÚsplitÚopenÚ	path_joinÚlenÚ
startswithÚlowerr   Ú	Exception)r   r   ÚcfgfilesÚsshcfgÚtagÚcfgfileÚlineÚconfargr   r   r   r   3   s4   ÿÿÿ€ùþ€þÿzSsh.included_configsc                 C   s>   t  ¡ }|D ]}|  |jd¡}|  |¡r|  d|› �¡ qdS )z 
        Iterate over .ssh folders in user homes to see their permissions.

        Bad permissions can prevent SSH from allowing access to given user.
        z.sshzls -laZ N)ÚpwdÚgetpwallr-   Úpw_dirÚ
path_isdirÚadd_cmd_output)r   Ú
users_dataÚuserÚhome_dirr   r   r   r   K   s   
€ýzSsh.user_ssh_files_permissionsN)Ú__name__Ú
__module__Ú__qualname__Ú
short_descÚplugin_nameÚprofilesr   ÚstrÚoption_listr   r   r   r   r   r   r   r      s    ÿÿr   )r8   r   Úsos.report.pluginsr   r   r   r   r   r   r   r   Ú<module>   s   
