o
    id                     @   s*   d dl mZmZmZ G dd deeZdS )    )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 ddg}| | | | | 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_configr   )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   zN|D ]H}| dd }t| |d/}|D ]$}t|  dks&|dr'q| dr;|  }| j|d |d qW d    n1 sFw   Y  qW d S  tyX   Y d S w )	N/rr   #include   )tags)splitopen	path_joinlen
startswithlowerr   	Exception)r   r   sshcfgtagcfgfilelineconfargr   r   r   r   0   s$   zSsh.included_configsc              	   C   s   |  d}|d r6zt| d}| }W d   n1 s w   Y  W n ty5   | d Y dS w |d  }|D ]%}z| |dd d	}| |rY| 	d

| W q> tyc   Y q>w 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getent passwdstatusz/etc/passwdNzCouldn't read /etc/passwdoutput:   z.sshz
ls -laZ {})exec_cmdr#   r$   	readlinesr(   
_log_error
splitlinesr"   
path_isdiradd_cmd_outputformat
IndexError)r   
users_datapasswd_fileusers_data_linesusr_linehome_dirr   r   r   r   A   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   N)sos.report.pluginsr   r   r   r   r   r   r   r   <module>   s   
