3 \�me" � @ s� U d dl Z d dlZd dlZd dlZd dlmZ d dlZd dlmZm Z y,d dl Z e jZe j e j e je�d�ZeW nL eefk r� yd dlmZ ejZW n ek r� dd� ZY nX Y nX eje�ZG dd � d ejjj�ZG d d� de�ZdS )� N)�Any)�subp�util)�salt)�bcryptc C s t d��dS )z�Raise when called so that importing this module doesn't throw ImportError when this module is not used. In this case, crypt and passlib are not needed. z/crypt and passlib not found, missing dependencyN)�ImportError)�_� r �/usr/lib/python3.6/netbsd.py� blowfish_hash s r c sn e Zd ZdZdZdgZ� fdd�Zdd� Zdd � Zddd�Z d d� Z dd� Zddd�Zdd� Z dd� Z� ZS )�NetBSDzS Distro subclass for NetBSD. (N.B. OpenBSD inherits from this class.) z*/usr/pkg/etc/sudoers.d/90-cloud-init-usersZgroupaddc sd t � j|||� tjjd�rNdddg| _dddg| _dddg| _dddg| _ndd g| _d g| _d S )Nz/usr/pkg/bin/pkginZpkginz-yZinstall�remove�updatezfull-upgradeZpkg_addz-UZ pkg_delete) �super�__init__�os�path�existsZpkg_cmd_install_prefixZpkg_cmd_remove_prefixZpkg_cmd_update_prefixZpkg_cmd_upgrade_prefix)�self�nameZcfg�paths)� __class__r r r 4 s zNetBSD.__init__c C s dd||gS )N�usermodz-Gr )r �member_nameZ group_namer r r �_get_add_member_to_group_cmd? s z#NetBSD._get_add_member_to_group_cmdc K sR t j|�rtjd|� dS dg}dg}dddddd �}d ddd �}xf|j� D ]Z\}}||kr~|r~t|t�r~|j|| |g� qL||krL|rL|j|| � |j|| � qLW d|ks�d|kr�|dg7 }|dg7 }||g7 }||g7 }tjd|� yt j ||d� W n& t k �r& t jtd|� � Y nX |jdd �} | d k �rN| j || dd� d S )Nz!User %s already exists, skipping.FZuseraddz-dz-cz-gz-Gz-s)ZhomedirZgecosZ primary_group�groups�shellz--no-user-groupz--systemz --no-log-init)Z no_user_group�systemZno_log_initZno_create_homer z-mzAdding user %s)Z logstringzFailed to create user %s�passwdT)�hashed)r Zis_user�LOG�info�items� isinstance�str�extend�appendr � Exception�logexc�get� set_passwd) r r �kwargsZadduser_cmdZlog_adduser_cmdZadduser_optsZ adduser_flags�key�valZ passwd_valr r r �add_userB sB zNetBSD.add_userFc C s\ |r |}nt |�}ytjdd||g� W n$ tk rL tjtd|� � Y nX | j|� d S )Nr z-pzFailed to set password for %s)r r r'