
    Vh                   j   d dl mZ dZdZdZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dlmZmZmZ d dlmZ d d	lmZ d d
lmZ d dlm c m!c m"Z#  G d dejH                        Z%	 ejL                  jO                   e#jP                  e)ejT                  jW                  d                  Z,ejZ                  fe,j\                  _/         ej`                  e%      e,j\                  _1        dZ2 e
jh                  d      Z5d Z. G d de6      Z7 G d de7      Z8 G d de8      Z9 G d de7      Z: G d de7      Z; G d de7      Z< G d de7      Z= G d  d!e7      Z> G d" d#e7      Z? G d$ d%e7      Z@ G d& d'e@      ZAd( ZBeCd)k(  r eB        yy# e3$ r dZ2Y w xY w)*    )annotationsa7  
module: user
version_added: "0.2"
short_description: Manage user accounts
description:
    - Manage user accounts and user attributes.
    - For Windows targets, use the M(ansible.windows.win_user) module instead.
options:
    name:
        description:
            - Name of the user to create, remove or modify.
        type: str
        required: true
        aliases: [ user ]
    uid:
        description:
            - Optionally sets the I(UID) of the user.
        type: int
    comment:
        description:
            - Optionally sets the description (aka I(GECOS)) of user account.
            - On macOS, this defaults to the O(name) option.
        type: str
    hidden:
        description:
            - macOS only, optionally hide the user from the login window and system preferences.
            - The default will be V(true) if the O(system) option is used.
        type: bool
        version_added: "2.6"
    non_unique:
        description:
            - Optionally when used with the C(-u) option, this option allows to change the user ID to a non-unique value.
        type: bool
        default: no
        version_added: "1.1"
    seuser:
        description:
            - Optionally sets the C(seuser) type C(user_u) on SELinux enabled systems.
        type: str
        version_added: "2.1"
    group:
        description:
            - Optionally sets the user's primary group (takes a group name).
            - On macOS, this defaults to V(staff).
        type: str
    groups:
        description:
            - A list of supplementary groups which the user is also a member of.
            - By default, the user is removed from all other groups. Configure O(append) to modify this.
            - When set to an empty string V(''),
              the user is removed from all groups except the primary group.
            - Before Ansible 2.3, the only input format allowed was a comma separated string.
        type: list
        elements: str
    append:
        description:
            - If V(true), add the user to the groups specified in O(groups).
            - If V(false), user will only be added to the groups specified in O(groups),
              removing them from all other groups.
        type: bool
        default: no
    shell:
        description:
            - Optionally set the user's shell.
            - On macOS, before Ansible 2.5, the default shell for non-system users was V(/usr/bin/false).
              Since Ansible 2.5, the default shell for non-system users on macOS is V(/bin/bash).
            - On other operating systems, the default shell is determined by the underlying tool
              invoked by this module. See Notes for a per platform list of invoked tools.
            - From Ansible 2.18, the type is changed to I(path) from I(str).
        type: path
    home:
        description:
            - Optionally set the user's home directory.
        type: path
    skeleton:
        description:
            - Optionally set a home skeleton directory.
            - Requires O(create_home) option!
        type: str
        version_added: "2.0"
    password:
        description:
            - If provided, set the user's password to the provided encrypted hash (Linux) or plain text password (macOS).
            - B(Linux/Unix/POSIX:) Enter the hashed password as the value.
            - See L(FAQ entry,https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-generate-encrypted-passwords-for-the-user-module)
              for details on various ways to generate the hash of a password.
            - To create an account with a locked/disabled password on Linux systems, set this to V('!') or V('*').
            - To create an account with a locked/disabled password on OpenBSD, set this to V('*************').
            - B(OS X/macOS:) Enter the cleartext password as the value. Be sure to take relevant security precautions.
            - On macOS, the password specified in the C(password) option will always be set, regardless of whether the user account already exists or not.
            - When the password is passed as an argument, the M(ansible.builtin.user) module will always return changed to C(true) for macOS systems.
              Since macOS no longer provides access to the hashed passwords directly.
        type: str
    state:
        description:
            - Whether the account should exist or not, taking action if the state is different from what is stated.
            - See this L(FAQ entry,https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#running-on-macos-as-a-target)
              for additional requirements when removing users on macOS systems.
        type: str
        choices: [ absent, present ]
        default: present
    create_home:
        description:
            - Unless set to V(false), a home directory will be made for the user
              when the account is created or if the home directory does not exist.
            - Changed from O(createhome) to O(create_home) in Ansible 2.5.
        type: bool
        default: yes
        aliases: [ createhome ]
    move_home:
        description:
            - "If set to V(true) when used with O(home), attempt to move the user's old home
              directory to the specified directory if it isn't there already and the old home exists."
        type: bool
        default: no
    system:
        description:
            - When creating an account O(state=present), setting this to V(true) makes the user a system account.
            - This setting cannot be changed on existing users.
        type: bool
        default: no
    force:
        description:
            - This only affects O(state=absent), it forces removal of the user and associated directories on supported platforms.
            - The behavior is the same as C(userdel --force), check the man page for C(userdel) on your system for details and support.
            - When used with O(generate_ssh_key=yes) this forces an existing key to be overwritten.
        type: bool
        default: no
    remove:
        description:
            - This only affects O(state=absent), it attempts to remove directories associated with the user.
            - The behavior is the same as C(userdel --remove), check the man page for details and support.
        type: bool
        default: no
    login_class:
        description:
            - Optionally sets the user's login class, a feature of most BSD OSs.
        type: str
    generate_ssh_key:
        description:
            - Whether to generate a SSH key for the user in question.
            - This will B(not) overwrite an existing SSH key unless used with O(force=yes).
        type: bool
        default: no
        version_added: "0.9"
    ssh_key_bits:
        description:
            - Optionally specify number of bits in SSH key to create.
            - The default value depends on C(ssh-keygen).
        type: int
        version_added: "0.9"
    ssh_key_type:
        description:
            - Optionally specify the type of SSH key to generate.
            - Available SSH key types will depend on implementation
              present on target host.
        type: str
        default: rsa
        version_added: "0.9"
    ssh_key_file:
        description:
            - Optionally specify the SSH key filename.
            - If this is a relative filename then it will be relative to the user's home directory.
            - This parameter defaults to V(.ssh/id_rsa).
        type: path
        version_added: "0.9"
    ssh_key_comment:
        description:
            - Optionally define the comment for the SSH key.
        type: str
        default: ansible-generated on $HOSTNAME
        version_added: "0.9"
    ssh_key_passphrase:
        description:
            - Set a passphrase for the SSH key.
            - If no passphrase is provided, the SSH key will default to having no passphrase.
        type: str
        version_added: "0.9"
    update_password:
        description:
            - V(always) will update passwords if they differ.
            - V(on_create) will only set the password for newly created users.
        type: str
        choices: [ always, on_create ]
        default: always
        version_added: "1.3"
    expires:
        description:
            - An expiry time for the user in epoch, it will be ignored on platforms that do not support this.
            - Currently supported on GNU/Linux, FreeBSD, and DragonFlyBSD.
            - Since Ansible 2.6 you can remove the expiry time by specifying a negative value.
              Currently supported on GNU/Linux and FreeBSD.
        type: float
        version_added: "1.9"
    password_lock:
        description:
            - Lock the password (C(usermod -L), C(usermod -U), C(pw lock)).
            - Implementation differs by platform. This option does not always mean the user cannot login using other methods.
            - This option does not disable the user, only lock the password.
            - This must be set to V(false) in order to unlock a currently locked password. The absence of this parameter will not unlock a password.
            - Currently supported on Linux, FreeBSD, DragonFlyBSD, NetBSD, OpenBSD.
        type: bool
        version_added: "2.6"
    local:
        description:
            - Forces the use of "local" command alternatives on platforms that implement it.
            - This is useful in environments that use centralized authentication when you want to manipulate the local users
              (in other words, it uses C(luseradd) instead of C(useradd)).
            - This will check C(/etc/passwd) for an existing account before invoking commands. If the local account database
              exists somewhere other than C(/etc/passwd), this setting will not work properly.
            - This requires that the above commands as well as C(/etc/passwd) must exist on the target host, otherwise it will be a fatal error.
        type: bool
        default: no
        version_added: "2.4"
    profile:
        description:
            - Sets the profile of the user.
            - Can set multiple profiles using comma separation.
            - To delete all the profiles, use O(profile='').
            - Currently supported on Illumos/Solaris. Does nothing when used with other platforms.
        type: str
        version_added: "2.8"
    authorization:
        description:
            - Sets the authorization of the user.
            - Can set multiple authorizations using comma separation.
            - To delete all authorizations, use O(authorization='').
            - Currently supported on Illumos/Solaris. Does nothing when used with other platforms.
        type: str
        version_added: "2.8"
    role:
        description:
            - Sets the role of the user.
            - Can set multiple roles using comma separation.
            - To delete all roles, use O(role='').
            - Currently supported on Illumos/Solaris. Does nothing when used with other platforms.
        type: str
        version_added: "2.8"
    password_expire_max:
        description:
            - Maximum number of days between password change.
            - Supported on Linux only.
        type: int
        version_added: "2.11"
    password_expire_min:
        description:
            - Minimum number of days between password change.
            - Supported on Linux only.
        type: int
        version_added: "2.11"
    password_expire_warn:
        description:
            - Number of days of warning before password expires.
            - Supported on Linux only.
        type: int
        version_added: "2.16"
    umask:
        description:
            - Sets the umask of the user.
            - Currently supported on Linux. Does nothing when used with other platforms.
            - Requires O(local) is omitted or V(false).
        type: str
        version_added: "2.12"
    password_expire_account_disable:
        description:
            - Number of days after a password expires until the account is disabled.
            - Currently supported on AIX, Linux, NetBSD, OpenBSD.
        type: int
        version_added: "2.18"
    uid_min:
        description:
            - Sets the UID_MIN value for user creation.
            - Overwrites /etc/login.defs default value.
            - Currently supported on Linux. Does nothing when used with other platforms.
            - Requires O(local) is omitted or V(False).
        type: int
        version_added: "2.18"
    uid_max:
        description:
            - Sets the UID_MAX value for user creation.
            - Overwrites /etc/login.defs default value.
            - Currently supported on Linux. Does nothing when used with other platforms.
            - Requires O(local) is omitted or V(False).
        type: int
        version_added: "2.18"

extends_documentation_fragment: action_common_attributes
attributes:
    check_mode:
        support: full
    diff_mode:
        support: none
    platform:
        platforms: posix
notes:
  - There are specific requirements per platform on user management utilities. However
    they generally come pre-installed with the system and Ansible will require they
    are present at runtime. If they are not, a descriptive error message will be shown.
  - On SunOS platforms, the shadow file is backed up automatically since this module edits it directly.
    On other platforms, the shadow file is backed up by the underlying tools used by this module.
  - On macOS, this module uses C(dscl) to create, modify, and delete accounts. C(dseditgroup) is used to
    modify group membership. Accounts are hidden from the login window by modifying
    C(/Library/Preferences/com.apple.loginwindow.plist).
  - On FreeBSD, this module uses C(pw useradd) and C(chpass) to create, C(pw usermod) and C(chpass) to modify,
    C(pw userdel) remove, C(pw lock) to lock, and C(pw unlock) to unlock accounts.
  - On all other platforms, this module uses C(useradd) to create, C(usermod) to modify, and
    C(userdel) to remove accounts.
seealso:
- module: ansible.posix.authorized_key
- module: ansible.builtin.group
- module: ansible.windows.win_user
author:
- Stephen Fromm (@sfromm)
ai  
- name: Add the user 'johnd' with a specific uid and a primary group of 'admin'
  ansible.builtin.user:
    name: johnd
    comment: John Doe
    uid: 1040
    group: admin

- name: Create a user 'johnd' with a home directory
  ansible.builtin.user:
    name: johnd
    create_home: yes

- name: Add the user 'james' with a bash shell, appending the group 'admins' and 'developers' to the user's groups
  ansible.builtin.user:
    name: james
    shell: /bin/bash
    groups: admins,developers
    append: yes

- name: Remove the user 'johnd'
  ansible.builtin.user:
    name: johnd
    state: absent
    remove: yes

- name: Create a 2048-bit SSH key for user jsmith in ~jsmith/.ssh/id_rsa
  ansible.builtin.user:
    name: jsmith
    generate_ssh_key: yes
    ssh_key_bits: 2048
    ssh_key_file: .ssh/id_rsa

- name: Added a consultant whose account you want to expire
  ansible.builtin.user:
    name: james18
    shell: /bin/zsh
    groups: developers
    expires: 1422403387

- name: Starting at Ansible 2.6, modify user, remove expiry time
  ansible.builtin.user:
    name: james18
    expires: -1

- name: Set maximum expiration date for password
  ansible.builtin.user:
    name: ram19
    password_expire_max: 10

- name: Set minimum expiration date for password
  ansible.builtin.user:
    name: pushkar15
    password_expire_min: 5

- name: Set number of warning days for password expiration
  ansible.builtin.user:
    name: jane157
    password_expire_warn: 30

- name: Set number of days after password expires until account is disabled
  ansible.builtin.user:
    name: jimholden2016
    password_expire_account_disable: 15
a  
append:
  description: Whether or not to append the user to groups.
  returned: When O(state) is V(present) and the user exists
  type: bool
  sample: True
comment:
  description: Comment section from passwd file, usually the user name.
  returned: When user exists
  type: str
  sample: Agent Smith
create_home:
  description: Whether or not to create the home directory.
  returned: When user does not exist and not check mode
  type: bool
  sample: True
force:
  description: Whether or not a user account was forcibly deleted.
  returned: When O(state) is V(absent) and user exists
  type: bool
  sample: False
group:
  description: Primary user group ID
  returned: When user exists
  type: int
  sample: 1001
groups:
  description: List of groups of which the user is a member.
  returned: When O(groups) is not empty and O(state) is V(present)
  type: str
  sample: 'chrony,apache'
home:
  description: "Path to user's home directory."
  returned: When O(state) is V(present)
  type: str
  sample: '/home/asmith'
move_home:
  description: Whether or not to move an existing home directory.
  returned: When O(state) is V(present) and user exists
  type: bool
  sample: False
name:
  description: User account name.
  returned: always
  type: str
  sample: asmith
password:
  description: Masked value of the password.
  returned: When O(state) is V(present) and O(password) is not empty
  type: str
  sample: 'NOT_LOGGING_PASSWORD'
remove:
  description: Whether or not to remove the user account.
  returned: When O(state) is V(absent) and user exists
  type: bool
  sample: True
shell:
  description: User login shell.
  returned: When O(state) is V(present)
  type: str
  sample: '/bin/bash'
ssh_fingerprint:
  description: Fingerprint of generated SSH key.
  returned: When O(generate_ssh_key) is V(True)
  type: str
  sample: '2048 SHA256:aYNHYcyVm87Igh0IMEDMbvW0QDlRQfE0aJugp684ko8 ansible-generated on host (RSA)'
ssh_key_file:
  description: Path to generated SSH private key file.
  returned: When O(generate_ssh_key) is V(True)
  type: str
  sample: /home/asmith/.ssh/id_rsa
ssh_public_key:
  description: Generated SSH public key file.
  returned: When O(generate_ssh_key) is V(True)
  type: str
  sample: >
    'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC95opt4SPEC06tOYsJQJIuN23BbLMGmYo8ysVZQc4h2DZE9ugbjWWGS1/pweUGjVstgzMkBEeBCByaEf/RJKNecKRPeGd2Bw9DCj/bn5Z6rGfNENKBmo
    618mUJBvdlEgea96QGjOwSB7/gmonduC7gsWDMNcOdSE3wJMTim4lddiBx4RgC9yXsJ6Tkz9BHD73MXPpT5ETnse+A3fw3IGVSjaueVnlUyUmOBf7fzmZbhlFVXf2Zi2rFTXqvbdGHKkzpw1U8eB8xFPP7y
    d5u1u0e6Acju/8aZ/l17IDFiLke5IzlqIMRTEbDwLNeO84YQKWTm9fODHzhYe0yvxqLiK07 ansible-generated on host'
stderr:
  description: Standard error from running commands.
  returned: When stderr is returned by a command that is run
  type: str
  sample: Group wheels does not exist
stdout:
  description: Standard output from running commands.
  returned: When standard output is returned by the command that is run
  type: str
  sample:
system:
  description: Whether or not the account is a system account.
  returned: When O(system) is passed to the module and the account does not exist
  type: bool
  sample: True
uid:
  description: User ID of the user account.
  returned: When O(uid) is passed to the module
  type: int
  sample: 1044
N)distro)to_bytes	to_nativeto_text)AnsibleModule)get_best_parsable_locale)get_platform_subclassc            
          e Zd Zdej                  fdej                  fdej
                  fdej
                  fdej
                  fdej
                  fdej
                  fdej
                  fd	ej                  fg	Zy
)StructSpwdTypesp_nampsp_pwdp	sp_lstchgsp_minsp_maxsp_warnsp_inact	sp_expiresp_flagN)__name__
__module____qualname__ctypesc_char_pc_longc_ulong_fields_     D/home/dcms/DCMS/lib/python3.12/site-packages/ansible/modules/user.pyr   r     su    	FOO$	FOO$	fmm$	6==!	6==!	FMM"	V]]#	fmm$	FNN#
Hr   r   cTFz[^a-zA-Z0-9./=]c                @    t         j                  |       j                  S N)_LIBCgetspnamcontents)b_names    r    r%   r%   !  s    >>&!***r   c                       e Zd ZdZdZdZdZdZdZdZ	dZ
 fd	Zd
 Zd Zd%dZd Zd Zd Zd Zd Zd Zd Zd&dZd'dZd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z& xZ'S )(Usera|  
    This is a generic User manipulation class that is subclassed
    based on platform.

    A subclass may wish to override the following action methods:-
      - create_user()
      - remove_user()
      - modify_user()
      - ssh_key_gen()
      - ssh_key_fingerprint()
      - user_exists()

    All subclasses MUST define platform and distribution (which may be None).
    GenericNz/etc/passwd/etc/shadow   z/etc/login.defsz%Y-%m-%dc                @    t        t              }t        | |  |      S r#   )r
   r)   super__new__)clsargskwargsnew_cls	__class__s       r    r/   zUser.__new__<  s    '-S'*733r   c           	     	   || _         |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _	        |j                  d	   | _
        |j                  d
   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        d | _        |j                  d   | _        d | _        |j                  d   | _        |j                  d   | _        |j                  d   | _         |j                  d   | _!        |j                  d   | _"        |j                  d    | _#        |j                  d!   | _$        |j                  d"   | _%        |j                  d#   | _&        |j                  d$   | _'        |j                  d%   | _(        | j<                  rZ| jJ                  |jS                  d&'       | jN                  |jS                  d('       | jP                  |jS                  d)'       |j                  d*   #d+jU                  |j                  d*         | _        |j                  d,   (	 tW        jX                  |j                  d,         | _        |j                  d/   |j                  d/   | _/        n2t`        jb                  jU                  d0d1| j,                  z        | _/        | j:                  | j&                  r|je                  d2       y y y # tZ        $ r5}|jS                  d-| j6                  d.t]        |      '       Y d }~d }~ww xY w)3Nstatenameuidhidden
non_uniqueseusergroupcommentshellpasswordforceremovecreate_home	move_homeskeletonsystemlogin_classappendgenerate_ssh_keyssh_key_bitsssh_key_typessh_key_commentssh_key_passphraseupdate_passwordhomepassword_locklocalprofileauthorizationrolepassword_expire_maxpassword_expire_minpassword_expire_warnumaskpassword_expire_account_disableuid_minuid_maxz$'umask' can not be used with 'local'msgz&'uid_min' can not be used with 'local'z&'uid_max' can not be used with 'local'groups,expireszInvalid value for 'expires' : ssh_key_filez.sshzid_%sz'append' is set, but no 'groups' are specified. Use 'groups' for appending new groups.This will change to an error in Ansible 2.14.)3moduleparamsr6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   	sshkeygenssh_bitsssh_typessh_commentssh_passphraserM   rN   r_   rO   r]   rP   rQ   rR   rS   rT   rU   rV   rW   inactiverY   rZ   	fail_jsonjointimegmtime	Exceptionr   ssh_fileospathwarn)selfrb   es      r    __init__zUser.__init__@  s   ]]7+
MM&)	=='mmH- --5mmH-]]7+
}}Y/]]7+
j1]]7+
mmH-!==7{3j1mmH-!==7mmH-'9:n5n5!==):;$mm,@A%}}->?MM&)	#]]?;]]7+
}}Y/#]]?;MM&)	#)==1F#G #)==1F#G $*MM2H$I!]]7+
&GH}}Y/}}Y/::zz%  %K L||'  %M N||'  %M N==".((6==#:;DK==#/j#{{6==+CD ==(4"MM.9DMGGLL4==1HIDM;;4;; KK H I $/  j  T\\[def[g%h iijs   "'Q 	R	+RR	c                     j                   j                  d   rW j                  dk7  rFd} j                   j                  d   t        g d      v rd}nt	         fddD              rd}d j                   j                  d   vrd}nȉ j                   j                  d   j                  d      }t        |      d	k\  rt        t        j                  |d
               rd}|d   dk(  rt        |d
         dk7  rd}|d   dk(  rt        |d
         dk7  rd}|d   dk(  rt        |d
         dk7  rd}|d   dk(  rt        |d
         dk7  rd}nd}|r j                   j                  d       y y y y )Nr?   DarwinF)*!z*************c              3  T   K   | ]  }|j                   j                  d    v  ! yw)r?   N)rb   rc   ).0charrs   s     r    	<genexpr>z0User.check_password_encrypted.<locals>.<genexpr>  s%     P$tt{{11*==Ps   %(z:*!T$      1   5+   6V   yzThe input password appears not to have been hashed. The 'password' argument must be encrypted for this module to work properly.)rb   rc   platformsetanysplitlenbool_HASH_REsearchrr   )rs   maybe_invalidfieldss   `  r    check_password_encryptedzUser.check_password_encrypted  so   ;;j)dmmx.G!M {{!!*-5P1QQ % P%PP$(Mdkk00<<$(M![[//
;AA#FF6{a'r
 ;<,0M!!9+F2J20E,0M!!9+F2J20E,0M!!9+F2J20E,0M!!9+F2J20E,0M(,   "o p C /H)r   c                    | j                   j                  r!|r| j                   j                  d|z         y|D cg c]  }t        |       }}| j                   j	                  |||      S c c}w )N#In check mode, would have run: "%s"r    r   )use_unsafe_shelldata)rb   
check_modedebugstrrun_command)rs   cmdr   r   obey_checkmodexs         r    execute_commandzUser.execute_command  sh    ;;!!nKKCcIJ $''a3q6'C';;**3AQX\*]] (s   A.c                    | j                   j                  s2| j                  r%| j                   j                  | j                        S y y r#   )rb   r   
SHADOWFILEbackup_localrs   s    r    backup_shadowzUser.backup_shadow  s6    {{%%$//;;++DOO<< +:%r   c                B   | j                   rd}nd}| j                  j                  |d      g}| j                  r| j                   s|j	                  d       | j
                  r|j	                  d       |j	                  | j                         | j                  |      S )NluserdeluserdelT-f-r)rP   rb   get_bin_pathr@   rG   rA   r7   r   )rs   command_namer   s      r    remove_user_userdelzUser.remove_user_userdel  sy    ::%L$L{{''d;<::djjJJt;;JJt

499##C((r   c                   | j                   r;d}| j                  j                  dd      }| j                  j                  dd      }nd}| j                  j                  |d      g}| j                  I|j	                  d       |j	                  | j                         | j
                  r|j	                  d       | j                  ,|j	                  d       |j	                  | j                         | j                  r| j                  | j                        s)| j                  j                  d	| j                  z  
       |j	                  d       |j	                  | j                         n+| j                  | j                        r| j                   r|j	                  d       nt        j                  j                  d      rZt        j                         }t!        |j#                  d      d         }|dk  r|j	                  d       n|j	                  d       nxt        j                  j                  d      rHt        j                         }t!        |j#                  d      d         }|dk\  r#|j	                  d       n|j	                  d       | j$                  bt'        | j$                        rM| j)                         }| j                   s1|j	                  d       |j	                  dj+                  |             | j,                  ,|j	                  d       |j	                  | j,                         | j.                  | j0                  rct        j                  j3                  | j.                        }t        j                  j5                  |      s| j7                  | j.                         |j	                  d       |j	                  | j.                         | j8                  ,|j	                  d       |j	                  | j8                         | j:                  | j                   s~|j	                  d       | j:                  t=        j>                  d      k  r|j	                  d       n9|j	                  t=        j@                  | jB                  | j:                               | jD                  5|j	                  d       |j	                  t!        | jD                               | jF                  W|j	                  d       | jH                  r|j	                  d| jF                  z         n|j	                  | jF                         | j0                  r| j                   s|j	                  d       | jJ                  ,|j	                  d       |j	                  | jJ                         | jL                  A|j	                  d        |j	                  d!| jL                  z          n|j	                  d"       | jN                  r|j	                  d#       | jP                  8|j	                  d        |j	                  d$tS        | jP                        z          | jT                  8|j	                  d        |j	                  d%tS        | jT                        z          |j	                  | j                         | jW                  |      \  }	}
}| j                   r|	dk7  r|	|
|fS | j:                  | j:                  t=        j>                  d      k  rd&}n8t!        tY        jZ                  | j                  j\                  d'               d(z  }| jW                  d)t_        |      | j                  g      \  }	}}|
|z  }
||z  }|	dk7  r|	|
|fS | j$                  t'        | j$                        dk(  r|	|
|fS D ];  }| jW                  d"| j                  |g      \  }	}}|
|z  }
||z  }|	dk7  s6|	|
|fc S  |	|
|fS )*Nluseradd	lgroupmodTlchageuseradd-u-o-ZGroup %s does not existr[   -g-nz/etc/redhat-release.r      -Nz/etc/SuSE-release   -Gr^   -c-d-s-er   r   -p!%s-m-k-KUMASK=-Mr   UID_MIN=UID_MAX=r   r_   Q -E)0rP   rb   r   r8   rG   r:   r;   r<   group_existsrj   r7   rp   rq   existsr   versionintr   r]   r   get_groups_setrk   r=   rN   rB   dirnameisdircreate_homedirr>   r_   rl   rm   strftimeDATE_FORMATri   r?   rO   rD   rW   rE   rY   r   rZ   r   mathfloorrc   r   )rs   r   lgroupmod_cmd
lchage_cmdr   distmajor_releaser]   parentrcouterrlexpires_out_err	add_groups                   r    create_user_useraddzUser.create_user_useradd  s    ::%L KK44[$GM11(DAJ$L{{''d;<88JJtJJtxx 

4 ;;"JJtJJt{{#::!$$TZZ0%%*Cdjj*P%QJJtJJtzz"tyy)
 zz

4 77>>"78!>>+D$'

3(:$;M$)

4(

4(WW^^$78 ">>+D$'

3(:$;M$*

4(JJt$;;"s4;;'7((*F::

4 

388F+,<<#JJtJJt||$99  3ww}}V,''		2JJtJJtyy!::!JJtJJtzz"<<#DJJJJt||dkk!n,

2

4==)9)94<<HI==$JJtJJs4==)*==$JJt!!

54==01

4==)::

4 }}(

4 

4==)zz%

4 

8djj01JJt;;JJt<<#JJtJJzC$556<<#JJtJJzC$556

499--c2S#zzR1WS>!<<#||dkk!n, tzz$++*<*<Y*GHIUR#33ZyQYGZ\`\e\e4fgRt4KC4KCQwC~%;;#dkk"2a"7S>! 	&I#33]D$))U^4_`Rt4KC4KCQwC~%	& C~r   c                l   | j                   rd}nd}| j                  j                  |d      }t        j                  |t        j
                        sy|dg}| j                  |d      \  }}}||z   }t        |      j                  d      }|D ]#  }	|	j                         j                  d      s# y y)	NlusermodusermodTFz--helpr   
z-a, --append)rP   rb   r   rp   accessX_OKr   r   r   strip
startswith)
rs   r   usermod_pathr   r   data1data2helpoutlineslines
             r    _check_usermod_appendzUser._check_usermod_append]  s     ::%L$L{{//dC yyrww/X&!11#e1LUE%- '"((. 	Dzz|&&~6	 r   c                    | j                   rQd}| j                  j                  dd      }t               }t               }| j                  j                  dd      }d }nd}| j                  j                  |d      g}| j	                         }| j                         }	| j                  d|d   t        | j                        k7  rI|j                  d       |j                  | j                         | j                  r|j                  d       | j                  | j                  | j                        s)| j                  j                  d	| j                  z  
       | j                  | j                        }
|d   |
d   k7  r%|j                  d       |j                  |
d          | j                  {| j                  d      }d}g }| j                  dk(  r|ro| j                  scd}n`| j!                  dd      }t        |      j#                  |      }|r1| j                  r#|D ]  }||v s|	r|j                  d       d} n nd}|r| j                   rf| j                  r%t        |      j%                  |      }t               }nt        |      j%                  |      }t        |      j%                  |      }nq| j                  r4|	s2|j                  d       |j                  dj'                               n1|j                  d       |j                  dj'                  |             | j(                  >|d   | j(                  k7  r,|j                  d       |j                  | j(                         | j*                  [|d   | j*                  k7  rI|j                  d       |j                  | j*                         | j,                  r|j                  d       | j.                  >|d   | j.                  k7  r,|j                  d       |j                  | j.                         | j0                  <| j3                         d   xs d}t        |      }| j0                  t5        j6                  d      k  r7|dk\  r| j                   rd}n|j                  d        |j                  d       nt5        j6                  |d!z        }|dk  s|d d | j0                  d d k7  r| j                   r9t        t9        j:                  | j                  j<                  d"               d!z  }nJ|j                  d        |j                  t5        j>                  | j@                  | j0                               | jB                  ,|j                  d#       |j                  | jB                         | jD                  r&|d   jG                  d$      s|j                  d%       n3| jD                  du r%|d   jG                  d$      r|j                  d&       | jH                  d'k(  r| jJ                  |d   jM                  d$      | jJ                  jM                  d$      k7  rk|D cg c]	  }|d(vs| }}|j                  d)       | jD                  r|j                  d*| jJ                  z         n|j                  | jJ                         d+\  }}}tO        |      dkD  r0|j                  | jP                         | jS                  |      \  }}}| j                   r|
|dk(  s|||fS @| jS                  d,tU        |      | jP                  g      \  }}}||z  }||z  }|dk7  r|||fS tO              dk(  rtO              dk(  r|||fS |D ];  }| jS                  d-| jP                  |g      \  }}}||z  }||z  }|dk7  s6|||fc S  D ];  }| jS                  d| jP                  |g      \  }}}||z  }||z  }|dk7  s6|||fc S  |||fS c c}w ).Nr   r   Tr   r      r   r   r   r[   r   r   F)exclude_primaryr   remove_existing
names_only-a-Ar^   r      r   r   r   r      r   r   0r   r   r   r   r_   r   ry   -L-Ualways)r  r  r   r   Nr   r   r   r   )+rP   rb   r   r   	user_infor   r8   r   rG   r:   r<   r   rj   
group_infor]   user_group_membershipr   symmetric_difference
differencerk   r=   rN   rC   r>   r_   user_passwordrl   rm   r   r   rc   r   r   ri   rO   r   rM   r?   lstripr   r7   r   r   )rs   r   r   lgroupmod_addlgroupmod_delr   r   r   info
has_appendginfocurrent_groupsgroups_need_modr]   
group_diffgcurrent_expirescurrent_expire_dater!   r   r   r   r   r   r   	del_groups                             r    modify_user_usermodzUser.modify_user_usermodx  s   ::%L KK44[$GMEMEM11(DAJH$L{{''d;<~~//1
88DGs488}$<JJtJJtxx 

4 ::!$$TZZ0%%*Cdjj*P%QOODJJ/EAw%("

4 

58$;;"!777NN#OF{{b !$++&*O,,Ut,T 0EEfM
{{!' &A J#-$'JJt$426 %& +/::{{(+F(>(>~(N(+(+F(>(>~(N(+N(;(F(Fv(N{{:

4(

388J#78

4(

388F#34<<#Q4<<(?JJtJJt||$99 T!W		%9JJtJJtyy!~~

4 ::!d1g&;JJtJJtzz"<<#"00215<O!/2O||dkk!n,"a'zz#%

4(

2 '+kk/E2I&J# #Q&*=bq*AT\\RTSTEU*Uzz#&tzz$++2D2DY2O'P#QUZ#Z

4(

4==1A1A4<<#PQ==$JJtJJt}}% d1g&8&8&=JJt5(T!W-?-?-DJJt8+0IdSTgnn]`Naeierereyeyz}e~N~!;Ql%:1;C;JJt!!

54==01

4==)'S# s8a<JJtyy!!11#6NRczz"*aS>!#33ZyQYGZ\`\e\e4fgRt4KC4KCQwC~%}"s='9Q'>S>!& 	&I#33]D$))U^4_`Rt4KC4KCQwC~%	& ' 	&I#33]D$))U^4_`Rt4KC4KCQwC~%	& C~S <s    	`*`c                    	 t        j                  t        |             y# t        t        f$ r) 	 t        j
                  |       Y y# t        $ r Y Y yw xY ww xY w)NTF)grpgetgrgidr   
ValueErrorKeyErrorgetgrnamrs   r<   s     r    r   zUser.group_exists  sT    		LLU$H% 	U# 		s&   ! AA	AAAAc                    | j                  |      sy	 t        t        j                  t	        |                  S # t
        t        f$ r! t        t        j                  |            cY S w xY wNF)r   listr  r  r   r  r  r  r   s     r    r  zUser.group_info*  sX      '	-SZ011H% 	-U+,,	-s   &; -A+*A+c                   | j                   y | j                         }t        d | j                   j                  d      D              }t               }|j	                         D ]{  }| j                  |      s| j                  j                  d|z         | j                  |      }|r|r|d   |d   k(  r|j                  |       e|sh|j                  |d          } |r|S |S )Nc              3  B   K   | ]  }|s|j                           y wr#   )r   r{   r   s     r    r}   z&User.get_groups_set.<locals>.<genexpr>7  s     D1!QWWYDs   r^   r   r[   r   r   r   )r]   r  r   r   copyr   rb   rj   r  rA   add)rs   r   r   r  r]   group_namesr  r  s           r    r   zUser.get_groups_set3  s    ;;~~D(9(9#(>DDe 	/A$$Q'%%*Cq*I%J+JJqMT!W,Da 
1.	/ r   c                
   g }| j                         }t        j                         D ]Y  }| j                  |j                  v s|s|j                  |d          3|d   |j                  k7  sF|j                  |d          [ |S )z- Return a list of groups the user belongs to r   r   )get_pwd_infor  getgrallr7   gr_memrG   gr_gid)rs   r   r]   r  r<   s        r    r  zUser.user_group_membershipE  st      "\\^ 	0EyyELL(&MM%(+Aw%,,.eAh/	0 r   c                D   | j                   rt        j                  j                  | j                        s5| j
                  j                  dj                  | j                               d}dj                  | j                        }t        | j                  d      5 }|j                         d d d   }|D ]   }|j                  t        |            sd} n d d d        |S 	 t        j                  | j                        ryy # 1 sw Y   |S xY w# t        $ r Y yw xY w)NzK'local: true' specified but unable to find local account file {0} to parse.r[   Fz{0}:rbr   T)rP   rp   rq   r   PASSWORDFILErb   rj   formatr7   open	readlinesr   r   pwdgetpwnamr  )rs   r   	name_testfreversed_linesr   s         r    user_existszUser.user_existsT  s   
 ::77>>$"3"34%%*w*~*~  @D  @Q  @Q  +R%  SFdii0Id''. !!"tt!4* Dx	':;!% M<<		* + M  s$   6DD%D D	DDc                t    | j                         syt        t        j                  | j                              S r"  )r:  r#  r5  r6  r7   r   s    r    r+  zUser.get_pwd_infoo  s)    !CLL+,,r   c                    | j                         sy| j                         }t        |d         dk(  st        |d         dk(  r| j                         d   |d<   |S )NFr   r   )r:  r+  r   r  )rs   r  s     r    r  zUser.user_infot  sZ    !  "tAw<1DG 1((*1-DGr   c                   | j                   d u}| j                  d u}| j                  d u}t        rs	 t	        t        | j                              }|| j                   |j                  k7  z  }|| j                  |j                  k7  z  }|| j                  |j                  k7  z  }|s|s|syd}| j                  j                  |d      g}|r|j                  d| j                   g       |r|j                  d| j                  g       |r|j                  d| j                  g       |j                  | j                         | j                  |      S # t        $ r Y yw xY w)Nr  chageTr   r   z-W)rU   rT   rV   	HAVE_SPWDr%   r   r7   r  r   r   r   rb   r   extendrG   r   )rs   min_needs_changemax_needs_changewarn_needs_changeshadow_infor   r   s          r    set_password_expirezUser.set_password_expire|  sS   334?334? 55TA$&x		':;  8 8K<N<N NN 8 8K<N<N NN!:!:k>Q>Q!QQ $48I!{{''d;<JJd6678JJd6678JJd7789

499##C(()  $#$s   E 	EEc                2   d}d}t         rD	 t        t        | j                              }t	        |j
                        }|j                  }||fS | j                         s||fS | j                  r| j                         \  }}||fS # t        $ r ||fcY S w xY w)Nr   )r?  r%   r   r7   r   r   r   r  r:  r   parse_shadow_file)rs   passwdr_   rD  s       r    r  zUser.user_password  s    '&x		':;";#6#67%//w& !7?"__"446OFGw  'w&'s   AB BBc                   d}d}t         j                  j                  | j                        rt        j                  | j                  t         j
                        rt        | j                  d      5 }|D ]W  }|j                  d| j                  z        s"|j                  d      d   }|j                  d      | j                     xs d}Y 	 d d d        ||fS ||fS # 1 sw Y   ||fS xY w)Nr   r%s::r   r   )rp   rq   r   r   r   R_OKr3  r   r7   r   SHADOWFILE_EXPIRE_INDEX)rs   rH  r_   r8  r   s        r    rG  zUser.parse_shadow_file  s    77>>$//*ryy"''/Rdoos+ Vq VDutyy'89!%C!3"&**S/$2N2N"O"USUVV
 wvwV
 ws   2$C 8C  C,c                   | j                         }t        j                  j                  | j                        r| j                  }|S t        j                  j                  |d         s.| j                  j                  st        d| j                  z        t        j                  j                  |d   | j                        }|S )Nr   z%User %s home directory does not exist)r  rp   rq   isabsro   r   rb   r   rn   r7   rk   )rs   r  ra   s      r    get_ssh_key_pathzUser.get_ssh_key_path  s    ~~77=='==L
  77>>$q'*4;;3I3I G$)) STT77<<Q?Lr   c           	     F   | j                         }d }	 | j                         }| d}t        j
                  j                  |      }t        j
                  j                  |      sU| j                  j                  ry	 t	        j                  |t        dd             t	        j                  ||d   |d          t        j
                  j                  |      rN| j                  r"| j                  j                  d| d       d}n | j                  j                  d| d       yt        j
                  j                  |      ra| j                  r5| j                  j                  d| d       t	        j                   |       n | j                  j                  d| d       y| j                  j#                  dd      g}|j%                  d       |j%                  | j&                         | j(                  dkD  r,|j%                  d       |j%                  | j(                         |j%                  d       |j%                  | j*                         |j%                  d       |j%                  |       | j,                  | j                  j                  r| j                  j/                  d|z         yt1        j2                         \  }}	t1        j2                         \  }
}t1        j2                         \  }}t        j4                  j7                         }t9        | j                        |d<   	 t;        j<                  |D cg c]  }t?        |       c}|	||t        j@                  |      }d}d}|jC                         tE        jD                  |
|gg g d      d   }d}d }|}|D ]  }||
k(  rPt	        jF                  |
d!      }||z  }||v rt	        jH                  |t?        | j,                  d"#      d$z          |}nOt	        jF                  |d!      }||z  }||v r0t	        jH                  |t?        | j,                  d"#      d$z          |}d%|v sd%|v s y& |jC                         |jJ                  }t        |      }t        |      }n9|j%                  d'       |j%                  d       | jM                  ||(      \  }}}|dk(  rP| j                  j                  s:t	        j                  ||d   |d          t	        j                  ||d   |d          |||fS # t        $ r}ddt        |      fcY d }~S d }~ww xY w# t        $ r}ddd	|d
t        |      fcY d }~S d }~ww xY wc c}w # t        $ r}ddt        |      fcY d }~S d }~ww xY w))Nz.pubr   r   r   0700   r   r   zFailed to create r`   z+Overwriting existing ssh key private file ""r   z%Found existing ssh key private file "z.", no force, so skipping ssh-keygen generation)Nz1Key already exists, use "force: yes" to overwriter   z*Overwriting existing ssh key public file "z$Found existing ssh key public file ")Nz8Public key already exists, use "force: yes" to overwriter   
ssh-keygenT-tr   z-bz-Cr   r   LC_ALL)stdinstdoutstderr
preexec_fnenvr   s+   Enter passphrase (empty for no passphrase):s   Enter same passphrase againi (  stricterrors   s   Overwrite (y/n)?)NzKey already existsr   r   r   )'r  rQ  rn   r   rp   rq   r   r   rb   r   mkdirr   chownOSErrorr@   rr   unlinkr   rG   rf   re   rg   rh   r   ptyopenptyenvironr'  r	   
subprocessPopenr   setsidpollselectreadwrite
returncoder   )rs   r  	overwritera   pub_filert   ssh_dirr   master_in_fdslave_in_fdmaster_out_fdslave_out_fdmaster_err_fdslave_err_fdr]  r!   p
out_buffer
err_bufferr_listfirst_promptsecond_promptpromptfdchunkr   r   r   s                               r    ssh_key_genzUser.ssh_key_gen  s   ~~		)002L&t,H ''//,/ww~~g&{{%%"T#fa.1$q'473 77>>,'zz  #N|n\]!^_	  #H  WE  "F  GV77>>(#zz  #MhZWX!YZ		(#  #GzQ  "A  B]{{''d;<

4

4==!==1JJtJJt}}%

4

4##$

4

< *{{%%!!"G#"MN"(+%L+*-++-'M<*-++-'M<**//#C4T[[ACM#-$$3%?ahqk%?+6,8,802		),. !
 
ffh&#]]M=+I2rSTUVWXF#QL$BM)F$ D.$&GGM5$AE&%/J%3 "x@S@S\d7ehm7m n)6$&GGM5$AE&%/J%3 "x@S@S\d7ehm7m n)6.*<@SWa@a#CD ffh&, \\
+
+ JJtJJrN!11#I1FNRc74;;11 HH\47DG4HHXtAwQ0C~A  	)r9Q<((	)  T2GYq\RSSTP &@B  -2y|,,-s~   T, ?=U 9U? U:DU? "U? $U? 6"U? ,	U5UUU	U7U2,U72U7:U? ?	V VV V c                6   | j                         }t        j                  j                  |      sdd|z  dfS | j                  j                  dd      g}|j                  d       |j                  d       |j                  |       | j                  |d	      S )
Nr   zSSH Key file %s does not existr   rV  Tz-lr   Fr   )rQ  rp   rq   r   rb   r   rG   r   )rs   ra   r   s      r    ssh_key_fingerprintzUser.ssh_key_fingerprint*  s    ,,.ww~~l+7,FKK{{''d;<

4

4

< ##C#>>r   c                    d| j                         z  }	 t        |d      5 }|j                         j                         }d d d        |S # 1 sw Y   S xY w# t        $ r Y y w xY w)Nz%s.pubrJ  )rQ  r3  ro  r   IOError)rs   ssh_public_key_filer8  ssh_public_keys       r    get_ssh_public_keyzUser.get_ssh_public_key5  sm    &)>)>)@@	)3/ 21!"!12 	2   		s.   A A
 A 
AA A 	A#"A#c                "    | j                         S r#   )r   r   s    r    create_userzUser.create_user>      ''))r   c                "    | j                         S r#   )r   r   s    r    remove_userzUser.remove_userB  r  r   c                "    | j                         S r#   )r  r   s    r    modify_userzUser.modify_userF  r  r   c           
        t         j                  j                  |      s | j                  | j                  }nd}t         j                  j                  |      r-|t         j                  k7  r	 t        j                  ||d       n	 t        j                  |       t         j                  j                  | j                        ryt        | j                  d      5 }|D ]S  }t        j                  d|      }|st!        |j#                  d      d	      }d
| z  }	 t        j$                  ||       U 	 d d d        y y y # t        $ r3}| j                  j                  ddt        |      z         Y d }~d }~ww xY w# t        $ r4}| j                  j                  ddt        |      z         Y d }~d }~ww xY w# t        $ r4}| j                  j                  ddt        |      z         Y d }~d }~ww xY w# 1 sw Y   y xY w)Nz	/etc/skelT)symlinks%sfailedr\   rJ  z^UMASK\s+(\d+)$r   rT  i  )rp   rq   r   rD   devnullshutilcopytreere  rb   	exit_jsonr   makedirs
LOGIN_DEFSr3  rematchr   r<   chmod)	rs   rq   rD   rt   r8  r   mrW   modes	            r    r   zUser.create_homedirJ  s   ww~~d#}}(==&ww~~h'H

,BPOOHdTBPKK% ww~~doo.$//3/ 	\1 ! \HH%7>$'
A$6E#(E6>D\ "t 4\	\ 	\ /# $  PKK))4)A,;N)OOP
  PKK))4)A,;N)OOP $+ \ $ 5 5TtiXYlGZ 5 [ [\	\ 	\sl   /E 	F H<!HG4H	E>)E99E>	F>
)F99F>	G>
)G93H9G>>HH
c                "   	 t        j                  |||       t        j                  |      D ]  \  }}}|D ]7  }t        j                  t         j                  j	                  ||      ||       9 |D ]Y  }t         j                  j	                  ||      }	t         j                  j                  |	      rCt        j                  |	||       [  y # t        $ r3}
| j                  j                  ddt        |
      z         Y d }
~
y d }
~
ww xY w)NTr  r  )
rp   rd  walkrq   rk   islinkre  rb   r  r   )rs   r8   gidrq   rootdirsfilesdr8  	full_pathrt   s              r    chown_homedirzUser.chown_homedirh  s    
	HHHT3$%'WWT] 6!dE >AHHRWW\\$2C=> 6A "T1 5I77>>)4C566  	HKK!!4)A,3F!GG	Hs   B3C 6C 	D)D		D)FNT)TF)T)(r   r   r   __doc__r   distributionr1  r   rN  r  r   r/   ru   r   r   r   r   r   r   r  r   r  r   r  r:  r+  r  rE  r  rG  rQ  r  r  r  r  r  r  r   r  __classcell__r4   s   @r    r)   r)   %  s     HL LJ"JK4DIL%pN^=)Rh6dL
-$6-
)<&	fP	?***\<Hr   r)   c                  <    e Zd ZdZdZdZdZdZdZd Z	d Z
d	 Zd
 Zy)FreeBsdUsera1  
    This is a FreeBSD User manipulation class - it uses the pw command
    to manipulate the user database, followed by the chpass command
    to change the password.

    This overrides the following methods from the generic class:-
      - create_user()
      - remove_user()
      - modify_user()
    FreeBSDN/etc/master.passwdr   z%d-%b-%Yc                   | j                         }| j                  r|d   j                  d      s| j                  j	                  dd      d| j
                  g}| j                  G|d   t        | j                        k7  r,|j                  d       |j                  | j                         | j                  |      S | j                  du r|d   j                  d      r| j                  j	                  dd      d	| j
                  g}| j                  G|d   t        | j                        k7  r,|j                  d       |j                  | j                         | j                  |      S y
)Nr   *LOCKED*pwTlockr   r   Funlockr  )
r  rO   r   rb   r   r7   r8   r   rG   r   )rs   r  r   s      r    _handle_lockzFreeBsdUser._handle_lock  s,   ~~d1g&8&8&D((t4		C
 xx#Q3txx=(@

4 

488$'',,5(T!W-?-?
-K((t4		C
 xx#Q3txx=(@

4 

488$'',,r   c                    | j                   j                  dd      dd| j                  g}| j                  r|j	                  d       | j                  |      S )Nr  Tr   r   r   rb   r   r7   rA   rG   r   rs   r   s     r    r  zFreeBsdUser.remove_user  sP    KK$$T40II	
 ;;JJt##C((r   c                .	   | j                   j                  dd      dd| j                  g}| j                  I|j	                  d       |j	                  | j                         | j
                  r|j	                  d       | j                  ,|j	                  d       |j	                  | j                         | j                  ,|j	                  d       |j	                  | j                         | j                  p| j                  | j                        s)| j                   j                  d	| j                  z  
       |j	                  d       |j	                  | j                         | j                  A| j                         }|j	                  d       |j	                  dj                  |             | j                  r|j	                  d       | j                  ,|j	                  d       |j	                  | j                         | j                   /|j	                  d       |j	                  d| j                   z          | j"                  ,|j	                  d       |j	                  | j"                         | j$                  ,|j	                  d       |j	                  | j$                         | j&                  ||j	                  d       | j&                  t)        j*                  d      k  r|j	                  d       n7|j	                  t-        t/        j0                  | j&                                     | j2                  8|j	                  d       |j	                  dt-        | j2                        z          | j4                  8|j	                  d       |j	                  dt-        | j4                        z          | j7                  |      \  }}}|-|dk7  r(| j                   j                  | j                  ||       | j8                  W| j                   j                  dd      d| j8                  | j                  g}| j7                  |      \  }}}||}||z  }||z  }| j;                         \  }}}||}||z  }||z  }|||fS )Nr  Tr   r   r   r   r   r   r   r[   r   r   r^   r   r   r   r   r   r  r   r   r  r   r   r7   r\   r   chpassr   )rb   r   r7   r8   rG   r:   r=   rN   r<   r   rj   r]   r   rk   rB   rD   rW   r>   rF   r_   rl   rm   r   calendartimegmrY   rZ   r   r?   r  )	rs   r   r]   r   r   r   _rcr   r   s	            r    r  zFreeBsdUser.create_user  s   KK$$T40II	
 88JJtJJtxx 

4 <<#JJtJJt||$99 JJtJJtyy!::!$$TZZ0%%*Cdjj*P%QJJtJJtzz";;"((*FJJtJJsxx'(JJt}}(

4 

4==)zz%

4 

8djj01::!JJtJJtzz"'JJtJJt''(<<#JJt||dkk!n,

3

3xt||<=><<#JJtJJzC$556<<#JJtJJzC$556 --c2S#>bAgKK!!tyycb!A ==$((48			C #2237OCtz4KC4KC ++-T4:BttC~r   c                   | j                   j                  dd      dd| j                  g}t        |      }| j	                         }| j
                  d|d   t        | j
                        k7  rI|j                  d       |j                  | j
                         | j                  r|j                  d       | j                  >|d   | j                  k7  r,|j                  d	       |j                  | j                         | j                  |d
   | j                  k7  r| j                  s5t        j                  j                  | j                        s| j                  r|j                  d       |d
   | j                  k7  r,|j                  d       |j                  | j                         | j                   ,|j                  d       |j                  | j                          | j"                  /|j                  d       |j                  d| j"                  z          | j$                  | j'                  | j$                        s)| j                   j)                  d| j$                  z         | j+                  | j$                        }|d   |d   k7  r,|j                  d       |j                  | j$                         | j,                  >|d   | j,                  k7  r,|j                  d       |j                  | j,                         | j.                  d }t        j                  j                  | j0                        rt        j2                  | j0                  t        j4                        rZt7        | j0                  d      5 }|D ]5  }|j9                  d| j                  z        s"|j;                  d      d   }7 	 d d d        | j.                  |k7  r,|j                  d       |j                  | j.                         | j<                  | j?                         }| jA                  d      }	tC        |      jE                  |	      }
d}|
r| j                  r|	D ]
  }||
v sd} n nd}|rM|j                  d       |	}| j                  r|	tC        |      z  }|j                  djG                  |             | jH                  | jK                         d   xs d}t        |      }| jH                  tM        jN                  d       k  r(|d kD  r|j                  d!       |j                  d       nwtM        jN                  |      }|d k  s|d d | jH                  d d k7  rH|j                  d!       |j                  tQ        tS        jT                  | jH                                     d"\  }}}|t        |      k7  rN| jW                  |      \  }}}||z  }||z  }|-|d k7  r(| j                   j)                  | j                  ||#       | jX                  d$k(  r| jZ                  |d   j]                  d%      | jZ                  j]                  d%      k7  rW| j                   j                  d&d      d'| jZ                  | j                  g}| jW                  |      \  }}}||}||z  }||z  }| j_                         \  }}}||}||z  }||z  }|||fS # 1 sw Y   xY w)(Nr  Tr   r   r   r   r   r   r   r   r   r   r   r   r   r   r[   r   r   r   r   rJ  rK  rL  r  r   Fr   r^   r   r  r   r   r  r  r  r  r  r   )0rb   r   r7   r   r  r8   r   rG   r:   r=   rN   rC   rp   rq   r   rB   rD   rW   r<   r   rj   r  r>   rF   r   r   rM  r3  r   r   r]   r  r   r   r	  rk   r_   r  rl   rm   r   r  r  r   rM   r?   r  r  )rs   r   cmd_lenr  r  user_login_classr8  r   r  r]   r  r  r  
new_groupsr  r  r   r   r   r   r   r  s                         r    r  zFreeBsdUser.modify_user  s   KK$$T40II	
 c(~~88DGs488}$<JJtJJtxx 

4 <<#Q4<<(?JJtJJt||$99 Q499$PTPYPYAZ_c_o_o

4 Aw$))#

4 

499%}}(

4 

4==)zz%

4 

8djj01::!$$TZZ0%%*Cdjj*P%QOODJJ/EAw%("

4 

4::&::!d1g&;JJtJJtzz"'#ww~~doo.299T__bgg3V$//3/ B1 ! B??5499+<=/3zz#q/A,BB #33

4 

4++,;;"!779N((D(9F^,AA&IJ#O;;# "
?.2O!"
 '+O

4 #
;;!'#n*=!=J

388J/0<<#"00215<O!/2O ||t{{1~-"Q&JJt$JJsO '+kk/&B# #a'+>r+BdllSUTUFV+VJJt$JJs8??4<<#@AB'S# c#h#33C8Rt4KC4KC~"'%%499#"%E 8+0IdSTgnn]gNhlplyly  mA  mA  BL  mM  OM((48			C #2237OCtz4KC4KC ++-T4:BttC~kB Bs   	$[.[[%)r   r   r   r  r   r  r   rN  r   r  r  r  r  r   r   r    r  r  x  s:    	 HL%JK2
)`DIr   r  c                      e Zd ZdZdZy)DragonFlyBsdUserz
    This is a DragonFlyBSD User manipulation class - it inherits the
    FreeBsdUser class behaviors, such as using the pw command to
    manipulate the user database, followed by the chpass command
    to change the password.
    	DragonFlyN)r   r   r   r  r   r   r   r    r  r    s     Hr   r  c                  .    e Zd ZdZdZdZdZd Zd Zd Z	y)OpenBSDUsera,  
    This is a OpenBSD User manipulation class.
    Main differences are that OpenBSD:-
     - has no concept of "system" account.
     - has no force delete user

    This overrides the following methods from the generic class:-
      - create_user()
      - remove_user()
      - modify_user()
    OpenBSDNr  c                   | j                   j                  dd      g}| j                  I|j                  d       |j                  | j                         | j                  r|j                  d       | j
                  p| j                  | j
                        s)| j                   j                  d| j
                  z         |j                  d       |j                  | j
                         | j                  A| j                         }|j                  d       |j                  d	j                  |             | j                  ,|j                  d
       |j                  | j                         | j                  ,|j                  d       |j                  | j                         | j                  ,|j                  d       |j                  | j                         | j                  ,|j                  d       |j                  | j                         | j                  ;| j                  dk7  r,|j                  d       |j                  | j                         | j                   r|j                  d       | j"                  ,|j                  d       |j                  | j"                         | j$                  /|j                  d       |j                  d| j$                  z          | j&                  ,|j                  d       |j                  | j&                         | j(                  8|j                  d       |j                  dt+        | j(                        z          | j,                  8|j                  d       |j                  dt+        | j,                        z          |j                  | j.                         | j1                  |      S )Nr   Tr   r   r   r[   r   r   r^   r   r   r   r  rx   r   r   r   r   r   r   r   r   )rb   r   r8   rG   r:   r<   r   rj   r]   r   rk   r=   rN   r>   rF   r?   rB   rD   rW   ri   rY   r   rZ   r7   r   rs   r   r]   s      r    r  zOpenBSDUser.create_user  s   {{''	48988JJtJJtxx 

4 ::!$$TZZ0%%*Cdjj*P%QJJtJJtzz";;"((*FJJtJJsxx'(<<#JJtJJt||$99 JJtJJtyy!::!JJtJJtzz"'JJtJJt''(==$#)=JJtJJt}}%JJt}}(

4 

4==)zz%

4 

8djj01==$JJtJJt}}%<<#JJtJJzC$556<<#JJtJJzC$556

499##C((r   c                    | j                   j                  dd      g}| j                  r|j                  d       |j                  | j                         | j                  |      S Nr   Tr   rb   r   rA   rG   r7   r   r  s     r    r   zOpenBSDUser.remove_user_userdel  O    {{''	489;;JJt

499##C((r   c                
   | j                   j                  dd      g}| j                         }| j                  d|d   t	        | j                        k7  rI|j                  d       |j                  | j                         | j                  r|j                  d       | j                  | j                  | j                        s)| j                   j                  d| j                  z         | j                  | j                        }|d   |d   k7  r,|j                  d	       |j                  | j                         | j                  | j                         }d
}d}g }| j                  dk(  r|r]| j
                  sQd}nN| j                  d      }t        |      j                  |      }|r | j
                  r|D ]  }	|	|v sd}d} n nd}|r1|j                  |       |j                  dj!                  |             | j"                  >|d   | j"                  k7  r,|j                  d       |j                  | j"                         | j$                  [|d   | j$                  k7  rI| j&                  r|j                  d       |j                  d       |j                  | j$                         | j(                  >|d   | j(                  k7  r,|j                  d       |j                  | j(                         | j*                  ,|j                  d       |j                  | j*                         | j,                  d }
| j                   j                  dd      | j.                  g}| j1                  |d
      \  }}}|j3                         D ]/  }|j5                         }|d   dk(  st7        |      dk(  s+|d   }
1 | j,                  |
k7  r,|j                  d       |j                  | j,                         | j8                  r&|d   j;                  d      s|j                  d       n3| j8                  d
u r%|d   j;                  d      r|j                  d        | j<                  d!k(  rY| j>                  M| j>                  dk7  r>|d   | j>                  k7  r,|j                  d"       |j                  | j>                         t7        |      dk(  ry#|j                  | j.                         | j1                  |      S )$Nr   Tr   r   r   r   r[   r   r   F-Sr   r  r   r^   r   r   r   r   r   r   r   r   userinfor   r   classr   r  rx   r   r  r  r   r  ) rb   r   r  r8   r   rG   r:   r<   r   rj   r  r]   r  r   r   r	  rk   r=   rN   rC   r>   ri   rF   r7   r   
splitlinesr   r   rO   r   rM   r?   )rs   r   r  r  r  r  groups_optionr]   r  r  r  userinfo_cmdr   r   r   r   tokenss                    r    r  zOpenBSDUser.modify_user  s   {{''	489~~88DGs488}$<JJtJJtxx 

4 ::!$$TZZ0%%*Cdjj*P%QOODJJ/EAw%("

4 

4::&;;"!779N#O MF{{b !$++&*O,,,= 0EEfM
{{!' &A J0426 %	& +/

=)

388F+,<<#Q4<<(?JJtJJt||$99 T!W		%9~~

4 JJtJJtyy!::!d1g&;JJtJJtzz"==$JJtJJt}}%'# KK44ZF		RL!11,u1UNRc( 1!9'CK1,<'-ay$	1 #33

4 

4++,d1g&8&8&=JJt5(T!W-?-?-DJJt8+0IMMS(T!W-EJJtJJt}}% s8q=!

499##C((r   
r   r   r   r  r   r  r   r  r   r  r   r   r    r  r    s*    
 HL%J@)D)`)r   r  c                  .    e Zd ZdZdZdZdZd Zd Zd Z	y)
NetBSDUsera+  
    This is a NetBSD User manipulation class.
    Main differences are that NetBSD:-
     - has no concept of "system" account.
     - has no force delete user


    This overrides the following methods from the generic class:-
      - create_user()
      - remove_user()
      - modify_user()
    NetBSDNr  c                   | j                   j                  dd      g}| j                  I|j                  d       |j                  | j                         | j                  r|j                  d       | j
                  p| j                  | j
                        s)| j                   j                  d| j
                  z         |j                  d       |j                  | j
                         | j                  w| j                         }t        |      dkD  r(| j                   j                  d	t        |      z         |j                  d
       |j                  dj                  |             | j                  ,|j                  d       |j                  | j                         | j                  ,|j                  d       |j                  | j                         | j                  ,|j                  d       |j                  | j                         | j                  ,|j                  d       |j                  | j                         | j                   ,|j                  d       |j                  | j                          | j"                  ,|j                  d       |j                  | j"                         | j$                  r|j                  d       | j&                  ,|j                  d       |j                  | j&                         | j(                  /|j                  d       |j                  d| j(                  z          | j*                  8|j                  d       |j                  dt-        | j*                        z          | j.                  8|j                  d       |j                  dt-        | j.                        z          |j                  | j0                         | j3                  |      S )Nr   Tr   r   r   r[   r      .Too many groups (%d) NetBSD allows for 16 max.r   r^   r   r   r   r  r   r   r   r   r   r   r   r   )rb   r   r8   rG   r:   r<   r   rj   r]   r   r   rk   r=   rN   r>   rF   r?   ri   rB   rD   rW   rY   r   rZ   r7   r   r  s      r    r  zNetBSDUser.create_userw  s   {{''	48988JJtJJtxx 

4 ::!$$TZZ0%%*Cdjj*P%QJJtJJtzz";;"((*F6{R%%*Z]`ag]h*h%iJJtJJsxx'(<<#JJtJJt||$99 JJtJJtyy!::!JJtJJtzz"'JJtJJt''(==$JJtJJt}}%==$JJtJJt}}%JJt}}(

4 

4==)zz%

4 

8djj01<<#JJtJJzC$556<<#JJtJJzC$556

499##C((r   c                    | j                   j                  dd      g}| j                  r|j                  d       |j                  | j                         | j                  |      S r  r  r  s     r    r   zNetBSDUser.remove_user_userdel  r  r   c                h	   | j                   j                  dd      g}| j                         }| j                  d|d   t	        | j                        k7  rI|j                  d       |j                  | j                         | j                  r|j                  d       | j                  | j                  | j                        s)| j                   j                  d| j                  z         | j                  | j                        }|d   |d   k7  r,|j                  d	       |j                  | j                         | j                  | j                         }d
}g }| j                  dk(  r|ru| j
                  sid}nf| j                  d      }t        |      j                  |      }|r8| j
                  r*|D ]$  }||v st        |      j!                  |      }d} n nd}|rgt#        |      dkD  r(| j                   j                  dt#        |      z         |j                  d       |j                  dj%                  |             | j&                  >|d   | j&                  k7  r,|j                  d       |j                  | j&                         | j(                  [|d   | j(                  k7  rI| j*                  r|j                  d       |j                  d       |j                  | j(                         | j,                  >|d   | j,                  k7  r,|j                  d       |j                  | j,                         | j.                  ,|j                  d       |j                  | j.                         | j0                  ,|j                  d       |j                  | j0                         | j2                  dk(  rJ| j4                  >|d   | j4                  k7  r,|j                  d       |j                  | j4                         | j6                  r&|d   j9                  d      s|j                  d       n3| j6                  d
u r%|d   j9                  d      r|j                  d       t#        |      dk(  ry |j                  | j:                         | j=                  |      S )!Nr   Tr   r   r   r   r[   r   r   Fr   r  r  r  r   r^   r   r   r   r   r   r   r   r  r   r  r   r   r  z-C yesz-C nor  )rb   r   r  r8   r   rG   r:   r<   r   rj   r  r]   r  r   r   r	  unionr   rk   r=   rN   rC   r>   rF   ri   rM   r?   rO   r   r7   r   )	rs   r   r  r  r  r  r]   r  r  s	            r    r  zNetBSDUser.modify_user  s   {{''	489~~88DGs488}$<JJtJJtxx 

4 ::!$$TZZ0%%*Cdjj*P%QOODJJ/EAw%("

4 

4::&;;"!779N#OF{{b !$++&*O,,,= 0EEfM
{{!' &A J),^)<)B)B6)J26 %	& +/v;#KK)).^adekal.l)m

4 

388F+,<<#Q4<<(?JJtJJt||$99 T!W		%9~~

4 JJtJJtyy!::!d1g&;JJtJJtzz"'JJtJJt''(==$JJtJJt}}%8+0IdSTgY]YfYfNfJJtJJt}}%d1g&8&8&DJJx 5(T!W-?-?
-KJJw s8q=!

499##C((r   r  r   r   r    r  r  e  s*     HL%JC)J)S)r   r  c                  P     e Zd ZdZd ZdZdZdZd Zd Z	d Z
d Z fd	Zd
 Z xZS )SunOSa  
    This is a SunOS User manipulation class - The main difference between
    this class and the generic user class is that Solaris-type distros
    don't support the concept of a "system" account and we need to
    edit the /etc/shadow file manually to set a password. (Ugh)

    This overrides the following methods from the generic class:-
      - create_user()
      - remove_user()
      - modify_user()
      - user_info()
    Nr+   z/etc/user_attrc                :   	 d}d}d}t        dd      5 }|D ]  }|j                         }|j                  d      s|dk(  r*t        j                  d|      }|r|j                  d      }|j                  d      \  }}|dk(  r|j                  d	      }~|d
k(  r|j                  d	      }|dk(  s|j                  d	      } 	 d d d        fS # 1 sw Y   xY w# t        $ r2}	| j                  j                  dt        |	      z         Y d }	~	Gd }	~	ww xY w)Nr   z/etc/default/passwdrJ  #z^([^#]*)#(.*)$r   =MINWEEKSr   MAXWEEKS	WARNWEEKSz&failed to read /etc/default/passwd: %sr[   )r3  r   r   r  r  r<   r   rstriprn   rb   rj   r   )
rs   minweeksmaxweeks	warnweeksr8  r   r  keyvaluer   s
             r    get_password_defaultszSunOS.get_password_defaults,  s#   	aHHI+S1 7Q 7D::<D,
 !2D9A wwqz!%CJCj(#(<<#5
*#(<<#5+$)LL$6	77$ (I..%7 7  	aKK!!&NQZ[^Q_&_!``	as5   C BC2CC CC 	D((DDc                    | j                   j                  dd      g}| j                  r|j                  d       |j                  | j                         | j                  |      S r  r  r  s     r    r  zSunOS.remove_userF  O    {{''	489;;JJt

499##C((r   c                   | j                   j                  dd      g}| j                  I|j                  d       |j                  | j                         | j                  r|j                  d       | j
                  p| j                  | j
                        s)| j                   j                  d| j
                  z         |j                  d       |j                  | j
                         | j                  A| j                         }|j                  d       |j                  d	j                  |             | j                  ,|j                  d
       |j                  | j                         | j                  ,|j                  d       |j                  | j                         | j                  ,|j                  d       |j                  | j                         | j                  r|j                  d       | j                  ,|j                  d       |j                  | j                         | j                   /|j                  d       |j                  d| j                   z          | j"                  ,|j                  d       |j                  | j"                         | j$                  ,|j                  d       |j                  | j$                         | j&                  ,|j                  d       |j                  | j&                         | j(                  ,|j                  d       |j                  | j(                         | j*                  8|j                  d       |j                  dt-        | j*                        z          | j.                  8|j                  d       |j                  dt-        | j.                        z          |j                  | j0                         | j3                  |      \  }}}|-|dk7  r(| j                   j                  | j0                  ||       | j                   j4                  s| j6                  | j9                          | j;                         \  }}}	 g }	t=        | j>                  d      5 }
|
D ]
  }tA        |d      }|jC                         jE                  d      }|d   | j0                  k(  s|	j                  |       T| j6                  |d<   t-        tG        tI        jH                         dz              |d<   |r	 t-        tG        |      d z        |d!<   |r	 t-        tG        |      d z        |d"<   |r	 t-        tG        |      d z        |d#<   dj                  |      }|	j                  d$|z          	 d d d        t=        | j>                  d%      5 }
|
jM                  |	       d d d        ||fS # tJ        $ r Y w xY w# tJ        $ r Y w xY w# tJ        $ r Y w xY w# 1 sw Y   kxY w# 1 sw Y   GxY w# tN        $ r2}| j                   j                  d&tA        |      z         Y d }~d }~ww xY w)'Nr   Tr   r   r   r[   r   r   r^   r   r   r   r   r   r   r   -Pr   -Rr   r   r   r   r  r0  surrogate_or_strictr_  rL  r   r   r   r,   r   r   r   %s
w+#failed to update users password: %s)(rb   r   r8   rG   r:   r<   r   rj   r]   r   rk   r=   rN   r>   rB   rD   rW   rQ   rR   rS   ri   rY   r   rZ   r7   r   r   r?   r   r  r3  r   r   r   r   r   rl   r  
writelinesrn   )rs   r   r]   r   r   r   r  r  r  r   r8  r   r   s                r    r  zSunOS.create_userN  s   {{''	48988JJtJJtxx 

4 ::!$$TZZ0%%*Cdjj*P%QJJtJJtzz";;"((*FJJtJJsxx'(<<#JJtJJt||$99 JJtJJtyy!::!JJtJJtzz"JJt}}(

4 

4==)zz%

4 

8djj01<<#JJtJJt||$)JJtJJt))*99 JJtJJtyy!==$JJtJJt}}%<<#JJtJJzC$556<<#JJtJJzC$556

499--c2S#>bAgKK!!tyycb!A{{%%}}(""$040J0J0L-(I"fEdoot4 8$% 8D#,T:O#PD%)ZZ\%7%7%<F#)!9		#9 %T 2 ((,F1I(+C		u0D,E(FF1I'!)03CMA4E0FF1I  (!)03CMA4E0FF1I  )!)03C	NQ4F0GF1I $'88F#3D!LL$7788: doot4 ,U+,
 C~- (2 !)$(!) (2 !)$(!) (2 !)$(!)18 8:, ,  fKK)).SV_`cVd.d)eefs   X0 BX1W+XW:(X+X	(X.X0 X$X0 +	W74X6W77X:	XXXX		XXXXX!X0 $X-)X0 0	Y+9(Y&&Y+c                t   | j                   j                  dd      g}t        |      }| j                         }| j                  d|d   t        | j                        k7  rI|j                  d       |j                  | j                         | j                  r|j                  d       | j                  | j                  | j                        s)| j                   j                  d| j                  z         | j                  | j                        }|d   |d   k7  r,|j                  d	       |j                  | j                         | j                  | j                         }| j                  d
      }t        |      j!                  |      }d}|r| j                  r|D ]
  }	|	|v sd} n nd}|rP|j                  d       |}
| j                  r|
j#                  |       |j                  dj%                  |
             | j&                  >|d   | j&                  k7  r,|j                  d       |j                  | j&                         | j(                  [|d   | j(                  k7  rI| j*                  r|j                  d       |j                  d       |j                  | j(                         | j,                  >|d   | j,                  k7  r,|j                  d       |j                  | j,                         | j.                  >|d   | j.                  k7  r,|j                  d       |j                  | j.                         | j0                  >|d   | j0                  k7  r,|j                  d       |j                  | j0                         | j2                  >|d   | j2                  k7  r,|j                  d       |j                  | j2                         | j4                  ,|j                  d       |j                  | j4                         |t        |      k7  r`|j                  | j6                         | j9                  |      \  }}}|4|dk7  r/| j                   j                  | j6                  ||       nd\  }}}| j:                  dk(  r| j<                  |d    | j<                  k7  r| j?                          d!\  }}}| j                   j@                  sv| jC                         \  }}}	 g }tE        | jF                  d"      5 }|D ]  }tI        |d#$      }|jK                         jM                  d%      }|d   | j6                  k(  s|j                  |       T| j<                  |d <   tO        t        tQ        jP                         d&z              |d<   |rtO        t        |      dz        |d<   |rtO        t        |      dz        |d<   |rtO        t        |      dz        |d<   d%j%                  |      }|j                  d'|z         
 	 d d d        tE        | jF                  d(      5 }|jS                  |       d d d        d}||fS # 1 sw Y   @xY w# 1 sw Y   xY w# tT        $ r2}| j                   j                  d)tI        |      z         Y d }~Sd }~ww xY w)*Nr   Tr   r   r   r   r[   r   r   r  Fr   r^   r   r   r   r   r   r   r   r,   r  rT  r   	   r  r   r   r  r  r  r   r   r0  r  r_  rL  r   r  r  r  )+rb   r   r   r  r8   r   rG   r:   r<   r   rj   r  r]   r  r   r   r	  updaterk   r=   rN   rC   r>   rQ   rR   rS   ri   r7   r   rM   r?   r   r   r  r3  r   r   r   r   r   rl   r  rn   )rs   r   r  r  r  r  r]   r  r  r  r  r   r   r   r  r  r  r   r8  r   r   s                        r    r  zSunOS.modify_user_usermod  s   {{''	489c(~~88DGs488}$<JJtJJtxx 

4 ::!$$TZZ0%%*Cdjj*P%QOODJJ/EAw%("

4 

4::&;;"!779N((D(9F^,AA&IJ#O;;# "
?.2O!"
 '+O

4 #
;;%%n5

388J/0<<#Q4<<(?JJtJJt||$99 T!W		%9~~

4 JJtJJtyy!::!d1g&;JJtJJtzz"<<#Q4<<(?JJtJJt||$)d1g9K9K.KJJtJJt))*99 T!W		%9JJtJJtyy!==$JJtJJt}}% c#hJJtyy!!11#6NRc~"'%%499#"%E+NRc 8+0IdSTgY]YfYfNf (NRc;;))040J0J0L-(IfEdoot4 8$% 8D#,T:O#PD%)ZZ\%7%7%<F#)!9		#9 %T 2 ((,F1I(+C		u0D,E(FF1I',/H0A,Bq	',/H0A,Bq	(,/I0B,Cq	#&88F#3D!LL$788" doot4 ,U+,B C~/8 8", , ! fKK)).SV_`cVd.d)eefsI   >Y< DY$%Y< Y0
Y< $Y-)Y< 0Y95Y< <	Z7(Z22Z7c                V    t         t        |          }|r|| j                         z  }|S r#   )r.   r  r  _user_attr_info)rs   r  r4   s     r    r  zSunOS.user_info4	  s-    UD+-D((**Dr   c                   dgdz  }t        | j                  d      5 }|D ]  }|j                         j                  d      }|d   | j                  k(  s5t        d |d   j                  d      D              }|j                  d	d      |d<   |j                  d
d      |d<   |j                  dd      |d<    	 d d d        |S # 1 sw Y   |S xY w)Nr   r   rJ  z::::r   c              3  >   K   | ]  }|j                  d         yw)r  N)r   r&  s     r    r}   z(SunOS._user_attr_info.<locals>.<genexpr>@	  s     Iqwws|Is   r   ;profilesauthsrolesr   )r3  	USER_ATTRr   r   r7   dictget)rs   r  file_handlerr   r   tmps         r    r  zSunOS._user_attr_info:	  s    tax$..#& 	3,$ 3

**628tyy(IU1X^^C5HIIC!ggj"5DG!gggr2DG!gggr2DG3	3 	3 s   7CA%CC)r   r   r   r  r   r  r   r  r  r  r  r  r  r  r  r  s   @r    r  r    s@     HLJ I/4)rhpd
r   r  c                       e Zd ZdZdZdZdZdZg dZ fdZ	d Z
d Zd	 Zdd
Zd Zd Zd Zd Zd Zd Zd ZddZd Z xZS )
DarwinUsera  
    This is a Darwin macOS User manipulation class.
    Main differences are that Darwin:-
      - Handles accounts in a database managed by dscl(1)
      - Has no useradd/groupadd
      - Does not create home directories
      - User password must be cleartext
      - UID must be given
      - System users must ben under 500

    This overrides the following methods from the generic class:-
      - user_exists()
      - create_user()
      - remove_user()
      - modify_user()
    rw   Nr   ))r=   RealName)rN   NFSHomeDirectory)r>   	UserShell)r8   UniqueID)r<   PrimaryGroupIDr9   IsHiddenc                    t         t        |   |       | j                  | j                  r#d| _        n| j                  rd| _        nd| _        | j                  | j
                  j                  d       y y )Nr   r   r  )r.   r  ru   r9   rE   r   rG   )rs   rb   r4   s     r    ru   zDarwinUser.__init__g	  se    j$(0 ;;{{[[DKDK ;;"KK56 #r   c                R    | j                   j                  dd      | j                  gS )NdsclT)rb   r   dscl_directoryr   s    r    	_get_dsclzDarwinUser._get_dsclx	  s$    ((68K8KLLr   c                2   | j                         }|ddd| j                  gz  }| j                  |d      \  }}}g }|j                         D ]G  }|j	                  d      s|j	                  d      r&|j                  |j                         d          I |S )	Nz-searchz/GroupsGroupMembershipFr    )r   )r  r7   r   r  r   rG   r   )rs   r   r   r   r   r]   r   s          r    _list_user_groupszDarwinUser._list_user_groups{	  s    nn	9&7CC--c%-HS#NN$ 	+Ds#ts';MM$**,q/*	+ r   c                   | j                         }|dd| j                  z  |gz  }| j                  |d      \  }}}|dk7  ry|j                         }t	        |      dk(  r|d   j                  d      d   S t	        |      d	kD  r)d
j                  |d   j                         g|d	d z         S t	        |      d	k(  r|d   j                         S y)zCReturn user PROPERTY as given my dscl(1) read or None if not found.-read	/Users/%sFr   r   Nr   r`   r   r   )r  r7   r   r  r   r   rk   r   )rs   propertyr   r   r   r   r   s          r    _get_user_propertyzDarwinUser._get_user_property	  s    nntyy0(;;--c%-HS#7  u:?8>>$'**u:>99eAhnn./%);<<u:?8>>##r   c                v   | j                         }|g dz  }| j                  |d      \  }}}|dk7  r| j                  j                  d|||       d}d}|j	                         D ]4  }t        |j                  d      d         }	||	k  r|	}||	k  s-|	d	k  s3|	}6 |rd|cxk  r	d
k  r|dz   S  |dz   S |dz   S )zv
        Return the next available uid. If system=True, then
        uid should be below of 500, if possible.
        )z-listz/Usersr  Fr   r   z$Unable to get the next available uid)r\   r   r   r   r   r   i  i  r   )r  r   rb   rj   r  r   r   )
rs   rE   r   r   r   r   max_uidmax_system_uidr   current_uids
             r    _get_next_uidzDarwinUser._get_next_uid	  s    
 nn..--c%-HS#7KK!!:	 "  NN$ 	-Ddjjob12K$%+c0A!,	- q>/C/!A%% 0{w{r   c                "   | j                         }| j                  r |dd| j                  z  | j                  gz  }n|dd| j                  z  ddgz  }| j                  |      \  }}}|dk7  r| j                  j                  d|||       |||fS )	zsChange password for SELF.NAME against SELF.PASSWORD.

        Please note that password must be cleartext.
        z-passwdr%  -createPasswordrx   r   zError when changing passwordr\   r   r   r   )r  r?   r7   r   rb   rj   rs   r   r   r   r   s        r    _change_user_passwordz DarwinUser._change_user_password	  s     nn==I{TYY6FFCI{TYY6
CHHC--c2S#7KK!!&D#SV[]!^C~r   c                ,   | j                   d| _         	 t        j                  | j                         j                  | _         t        | j                         | _         y# t        $ r, | j
                  j                  d| j                   z         Y Ow xY w)zDConvert SELF.GROUP to is stringed numerical value suitable for dscl.NnogroupzBGroup "%s" not found. Try to create it first using "group" module.r[   )r<   r  r  r.  r  rb   rj   r   r   s    r    _make_group_numericalz DarwinUser._make_group_numerical	  sy    ::"DJ	ydjj188DJ _
  	yKK!!&jmqmwmw&w!x	ys   .A 2BBc           	         |dk(  rd}nd}ddd|| j                   dd|g}| j                  |      \  }}}|d	k7  r3| j                  j                  d
|d| j                   d|d|||       |||fS )Add or remove SELF.NAME to or from GROUP depending on ACTION.
        ACTION can be 'add' or 'remove' otherwise 'remove' is assumed. r(  r   r   dseditgroupr   editrW  userr   zCannot z user "z" to group "".r0  )r7   r   rb   rj   )rs   r<   actionoptionr   r   r   r   s           r    __modify_groupzDarwinUser.__modify_group	  s     U?FFdFFDIItVUS--c2S#7KK!!)/E'CHKQTY[ " ]C~r   c                   d}d}d}d}t        | j                               }| j                  | j                  d      }nt        g       }| j                  du r1||z
  D ])  }| j                  |d      \  }}	}
||z  }||	z  }||
z  }d}+ ||z
  D ])  }| j                  |d      \  }}	}
||z  }||	z  }||
z  }d}+ ||||fS )r7  r   r   FTr  deleter(  )r   r"  r]   r   rG   _DarwinUser__modify_group)rs   r   r   r   changedcurrenttargetrA   r  r   r   r(  s               r    _modify_groupzDarwinUser._modify_group	  s
    d,,./;;"((D(9FWF;;%!F* $($7$7$I!dDbtt G# 	C $ 3 3C ?S$#IB4KC4KCG	 Cg&&r   c                   d}dd|dg}| j                  |d      \  }}}g }|j                         dd D ](  }	 |j                  d	      d   }|j                  |       * | j                  rh| j                  |vrYdd
|dd| j                  g}| j                  |      \  }}}|dk7  r,| j                  j                  d| j                  z  |||       yy| j                  |v rm||j                  | j                        = dd
|ddg|z   }| j                  |      \  }}}|dk7  r,| j                  j                  d| j                  z  |||       yy# t        $ r |j	                         }Y w xY w)zvHide or show user on login window according SELF.SYSTEM.

        Returns 0 if a change has been made, None otherwise.z0/Library/Preferences/com.apple.loginwindow.plistdefaultsro  HiddenUsersListFr   r   r   rU  rp  z
-array-addr   z%Cannot user "%s" to hidden user list.r0  z-arrayz.Cannot remove user "%s" from hidden user list.N)r   r  r   
IndexErrorr   rG   rE   r7   rb   rj   index)rs   
plist_filer   r   r   r   hidden_usersr   s           r    _update_system_userzDarwinUser._update_system_user
  s   
 H
 6:/@A--c%-HS# !!B' 	#AGGCLO "	# ;;yy,!7J8I<Y]YbYbc!%!5!5c!:S#7KK)).UX\XaXa.agjpsxz){ - yyL(!,"4"4TYY"?@!7J8I8TWcc!%!5!5c!:S#7KK)).^aeajaj.jpsy|  BD)  E )  GGIs   EE-,E-c                    | j                         }|dd| j                  z  dgz  }| j                  |d      \  }}}|dk(  S )z1Check is SELF.NAME is a known user on the system.r$  r%  r  Fr   r   )r  r7   r   r1  s        r    r:  zDarwinUser.user_exists/
  sL    nntyy0*==--c%-HS#Qwr   c                   | j                         }| j                         }|dd| j                  z  gz  }| j                  |      \  }}}|dk7  r,| j                  j                  d| j                  z  |||       | j                  rEt        j                  j                  |d         r#t        j                  |d          |d|d   z  z  }|||fS )zCDelete SELF.NAME. If SELF.FORCE is true, remove its home directory.z-deleter%  r   zCannot delete user "%s".r0  r   z
Removed %s)r  r  r7   r   rb   rj   r@   rp   rq   r   r  rmtree)rs   r  r   r   r   r   s         r    r  zDarwinUser.remove_user6
  s    ~~nn	;233--c2S#7KK!!&@499&LRU[^ce!f::ww~~d1g&d1g&|d1g--C~r   c                   | j                         }|dd| j                  z  gz  }| j                  |      \  }}}|dk7  r,| j                  j	                  d| j                  z  |||       | j
                  | j                  | _        | j                  d| _        | j                          | j                  )t        | j                  | j                              | _        | j                  r| j                  d| j                  z  | _        | j                  j                  st        j                   j#                  | j                        st        j$                  | j                         | j'                  t)        | j                        t)        | j                        | j                         | j                  s| j*                  d| _        | j,                  D ]  }|d   | j.                  v s| j.                  |d      s(| j                         }|dd| j                  z  |d   | j.                  |d      gz  }| j                  |      \  }}}|dk7  r3| j                  j	                  d	|d   d
| j                  d|||       ||z  }||z  }|dk7  s|||fc S  | j1                         \  }}}||z  }||z  }| j3                          | j4                  r| j7                         \  }}}}	||z  }||z  }|||fS )Nr.  r%  r   zCannot create user "%s".r0  staffz	/bin/bashr   zCannot add property "z" to user "r;  )r  r7   r   rb   rj   r=   r<   r5  r8   r   r,  rE   rB   rN   r   rp   rq   r   r  r  r   r>   r   __dict__r2  rM  r]   rE  )
rs   r   r   r   r   r   fieldr   r   rB  s
             r    r  zDarwinUser.create_userH
  s   nn	;233--c2S#7KK!!&@499&LRU[^ce!f <<99DL :: DJ""$884--dkk:;DH yy '$))3	;;))ww~~dii0KK		*""3txx=#djj/499M {{tzz1$DJ[[ 	,EQx4==(T]]58-Dnn&	;#:E!HdmmTYZ[T\F]^^#'#7#7#< T47KK))Z_`aZbdhdmdm.ntw  ~A  FH)  Itt7d++	,  557T4tt  " ;;(,(:(:(<%RtW4KC4KCC~r   c                P   d }d}d}| j                   r| j                          | j                  D ]  }|d   | j                  v s| j                  |d      s(| j	                  |d         }||t        | j                  |d            k7  s]| j                         }|dd| j                  z  |d   | j                  |d      gz  }| j                  |      \  }}}	|dk7  r3| j                  j                  d|d   d| j                  d|||	       |}||z  }||	z  } | j                  d
k(  r,| j                   | j                         \  }}}	||z  }||	z  }|}| j                  r%| j                         \  }}}	}
||z  }||	z  }|
du r|}| j!                         }|dk(  r|}|||fS )Nr   r   r   r.  r%  zCannot update property "z" for user "r;  r0  r  T)r<   r5  r   rS  r'  r   r  r7   r   rb   rj   rM   r?   r2  r]   rE  rM  )rs   rB  r   r   rT  rC  r   r   r   r   _changeds              r    r  zDarwinUser.modify_user
  s   ::&&([[ 	 EQx4==(T]]58-D11%(;?guQx9P1Q&Q..*CI{TYY'>a$--X]^_X`JabbC'+';';C'@$RtQw--#(8TYY!8=@cb . R !G4KC4KC	  8+0I#99;Rt4KC4KCG;;)-););)=&RtX4KC4KC4%%'7Gc""r   r#   )r  )r   r   r   r  r   r  r   r  r   ru   r  r"  r'  r,  r2  r5  rA  rE  rM  r:  r  r  r  r  r  s   @r    r  r  G	  so      HLJNF7"M	(:,	%'@'R$:x(#r   r  c                  6    e Zd ZdZd ZdZdZd ZddZd Z	d Z
y)	AIXz
    This is a AIX User manipulation class.

    This overrides the following methods from the generic class:-
      - create_user()
      - remove_user()
      - modify_user()
      - parse_shadow_file()
    Nz/etc/security/passwdc                    | j                   j                  dd      g}| j                  r|j                  d       |j                  | j                         | j                  |      S r  r  r  s     r    r  zAIX.remove_user
  r  r   c                   | j                   j                  |d      g}| j                  ,|j                  d       |j                  | j                         | j                  p| j                  | j                        s)| j                   j                  d| j                  z         |j                  d       |j                  | j                         | j                  Vt        | j                        rA| j                         }|j                  d       |j                  dj                  |             | j                  ,|j                  d       |j                  | j                         | j                  ,|j                  d	       |j                  | j                         | j                  ,|j                  d
       |j                  | j                         | j                  r|j                  d       | j                  ,|j                  d       |j                  | j                         | j                   /|j                  d       |j                  d| j                   z          | j"                  ,|j                  d       |j                  | j"                         | j$                  8|j                  d       |j                  dt'        | j$                        z          | j(                  8|j                  d       |j                  dt'        | j(                        z          |j                  | j*                         | j-                  |      \  }}}| j.                  {g }|j                  | j                   j                  dd             |j                  d       |j                  d       | j-                  || j*                  d| j.                         |||fS )NTr   r   r[   r   r   r^   r   r   r   r   r   r   r   r   r   r   chpasswdr   rL  rb  )rb   r   r8   rG   r<   r   rj   r]   r   r   rk   r=   rN   r>   rB   rD   rW   ri   rY   r   rZ   r7   r   r?   )rs   r   r   r]   r   r   r   s          r    r   zAIX.create_user_useradd
  s   {{''d;<88JJtJJtxx ::!$$TZZ0%%*Cdjj*P%QJJtJJtzz";;"s4;;'7((*FJJtJJsxx'(<<#JJtJJt||$99 JJtJJtyy!::!JJtJJtzz"JJt}}(

4 

4==)zz%

4 

8djj01==$JJtJJt}}%<<#JJtJJzC$556<<#JJtJJzC$556

499--c2S# ==$CJJt{{//
DABJJtJJt  dii+O PC~r   c                J   | j                   j                  dd      g}| j                         }| j                  G|d   t	        | j                        k7  r,|j                  d       |j                  | j                         | j                  | j                  | j                        s)| j                   j                  d| j                  z         | j                  | j                        }|d   |d   k7  r,|j                  d       |j                  | j                         | j                  | j                         }d	}g }| j                  d
k(  r|r[| j
                  sOd}nL| j                  d      }t        |      j                  |      }|r| j
                  r|D ]
  }||v sd} n nd}|r1|j                  d       |j                  dj                  |             | j                   >|d   | j                   k7  r,|j                  d       |j                  | j                          | j"                  [|d   | j"                  k7  rI| j$                  r|j                  d       |j                  d       |j                  | j"                         | j&                  >|d   | j&                  k7  r,|j                  d       |j                  | j&                         | j(                  ,|j                  d       |j                  | j(                         t+        |      dk(  rd\  }	}
}n0|j                  | j,                         | j/                  |      \  }	}
}| j0                  dk(  r| j2                  |d   | j2                  k7  rg }|j                  | j                   j                  dd             |j                  d       |j                  d       | j/                  || j,                  d| j2                        \  }}}nd\  }}}|	|	|
|z   ||z   fS ||
|z   ||z   fS )Nr   Tr   r   r   r[   r   r   Fr   r  r   r^   r   r   r   r   r   r   r   r   r   r  r  r[  r   rL  rb  )rb   r   r  r8   r   rG   r<   r   rj   r  r]   r  r   r   r	  rk   r=   rN   rC   r>   ri   r   r7   r   rM   r?   )rs   r   r  r  r  r  r]   r  r  r   r   r   rc2out2err2s                  r    r  zAIX.modify_user_usermod  ss   {{''	489~~88DGs488}$<JJtJJtxx ::!$$TZZ0%%*Cdjj*P%QOODJJ/EAw%("

4 

4::&;;"!779N#OF{{b !$++&*O,,,= 0EEfM
{{!' &A J26 %&
 +/

4 

388F+,<<#Q4<<(?JJtJJt||$99 T!W		%9~~

4 JJtJJtyy!::!d1g&;JJtJJtzz"==$JJtJJt}}% s8q=+NRcJJtyy!!11#6NRc 8+0IdSTgY]YfYfNfCJJt{{//
DABJJtJJt $ 4 4S$))UYUbUb?c 4 dS$ .S$>d
C$J//tS4Z00r   c                   t        | j                        }d}d}t        j                  j	                  | j
                        rt        j                  | j
                  t        j                        rt        | j
                  d      5 }|j                         }ddd       d}d}	 t              D ]+  \  }}	|	j                  d|z        s||dz      }||dz      } n d|v r#|j                  dd      d   j                         }d|v r#|j                  dd      d   j                         }t#        |      }
t#        |      xs d}|
|fS # 1 sw Y   xY w# t        $ r, | j                  j!                  d	| j
                  z  
       Y ^w xY w)a  Example AIX shadowfile data:
        nobody:
                password = *

        operator1:
                password = {ssha512}06$xxxxxxxxxxxx....
                lastupdate = 1549558094

        test1:
                password = *
                lastupdate = 1553695126

        r   r0  Ns   %s:r   r   s    = r   zFailed to parse shadow file %sr[   )r   r7   rp   rq   r   r   r   rM  r3  r4  	enumerater   r   r   rI  rb   rj   r   )rs   r'   b_passwd	b_expiresbfb_linesb_passwd_lineb_expires_linerJ  b_linerH  r_   s               r    rG  zAIX.parse_shadow_fileX  sx    $))$	77>>$//*ryy"''/Rdoot, ),,.)  M N^%.w%7 ME6((&9(/	(:)0); ]*,2261=bAGGIH^+ . 4 4VQ ? C I I KI
 8$I&,"w3) )(  ^%%*JT__*\%]^s%   E
%%E A!E 
E2F
F)r   )r   r   r   r  r   r  r   r  r   r  rG  r   r   r    rX  rX  
  s/     HL'J)?BO1b,r   rX  c                  .    e Zd ZdZdZdZdZd Zd Zd Z	y)HPUXz
    This is a HP-UX User manipulation class.

    This overrides the following methods from the generic class:-
      - create_user()
      - remove_user()
      - modify_user()
    zHP-UXNr+   c                   dg}| j                   I|j                  d       |j                  | j                          | j                  r|j                  d       | j                  p| j	                  | j                        s)| j
                  j                  d| j                  z         |j                  d       |j                  | j                         | j                  Vt        | j                        rA| j                         }|j                  d       |j                  dj                  |             | j                  ,|j                  d	       |j                  | j                         | j                  ,|j                  d
       |j                  | j                         | j                  ,|j                  d       |j                  | j                         | j                  ,|j                  d       |j                  | j                         | j                  r|j                  d       n|j                  d       | j                   r|j                  d       |j                  | j"                         | j%                  |      S )Nz/usr/sam/lbin/useradd.samr   r   r   r[   r   r   r^   r   r   r   r   r   r   r   )r8   rG   r:   r<   r   rb   rj   r]   r   r   rk   r=   rN   r>   r?   rB   rE   r7   r   r  s      r    r  zHPUX.create_user  s   *+88JJtJJtxx 

4 ::!$$TZZ0%%*Cdjj*P%QJJtJJtzz";;"s4;;'7((*FJJtJJsxx'(<<#JJtJJt||$99 JJtJJtyy!::!JJtJJtzz"==$JJtJJt}}%JJtJJt;;JJt

499##C((r   c                    dg}| j                   r|j                  d       | j                  r|j                  d       |j                  | j                         | j	                  |      S )Nz/usr/sam/lbin/userdel.sam-Fr   )r@   rG   rA   r7   r   r  s     r    r  zHPUX.remove_user  sQ    *+::JJt;;JJt

499##C((r   c                D   dg}| j                         }| j                  d|d   t        | j                        k7  rI|j                  d       |j                  | j                         | j                  r|j                  d       | j
                  | j                  | j
                        s)| j                  j                  d| j
                  z         | j                  | j
                        }|d   |d   k7  r,|j                  d       |j                  | j
                         | j                  | j                         }d	}g }| j                  d
k(  r|r\| j                  sPd}nM| j                  d	d      }t        |      j                  |      }|r| j                  r|D ]
  }||v sd} n nd}|rM|j                  d       |}	| j                  r|t        |      z  }	|j                  dj                  |	             | j                   >|d   | j                   k7  r,|j                  d       |j                  | j                          | j"                  [|d   | j"                  k7  rI|j                  d       |j                  | j"                         | j$                  r|j                  d       | j&                  >|d   | j&                  k7  r,|j                  d       |j                  | j&                         | j(                  dk(  r[| j*                  O|d   | j*                  k7  r=|j                  d       |j                  d       |j                  | j*                         t-        |      dk(  ry|j                  | j.                         | j1                  |      S )Nz/usr/sam/lbin/usermod.samr   r   r   r   r[   r   r   Fr   Tr   r   r^   r   r   r   r   r   r   r   r  r   rm  r   r  )r  r8   r   rG   r:   r<   r   rb   rj   r  r]   r  r   r   r	  rk   r=   rN   rC   r>   rM   r?   r   r7   r   )
rs   r   r  r  r  r  r]   r  r  r  s
             r    r  zHPUX.modify_user  s   *+~~88DGs488}$<JJtJJtxx 

4 ::!$$TZZ0%%*Cdjj*P%QOODJJ/EAw%("

4 

4::&;;"!779N#OF{{b !$++&*O,,Ut,T 0EEfM
{{!' &A J26 %&
 +/

4 #
;;!'#n*=!=J

388J/0<<#Q4<<(?JJtJJt||$99 T!W		%9JJtJJtyy!~~

4 ::!d1g&;JJtJJtzz"8+0IdSTgY]YfYfNfJJtJJtJJt}}% s8q=!

499##C((r   )
r   r   r   r  r   r  r   r  r  r  r   r   r    rj  rj    s)     HLJ.)`)G)r   rj  c                  "    e Zd ZdZd Zd Zd Zy)BusyBoxz
    This is the BusyBox class for use on systems that have adduser, deluser,
    and delgroup commands. It overrides the following methods:
        - create_user()
        - remove_user()
        - modify_user()
    c                 	   | j                   j                  dd      g}|j                  d       | j                  ,|j                  d       |j                  | j                         | j                  || j                  | j                        s5| j                   j                  dj                  | j                               |j                  d       |j                  | j                         | j                  ,|j                  d       |j                  | j                         | j                  ,|j                  d	       |j                  | j                         | j                  ,|j                  d
       |j                  | j                         | j                  s|j                  d       | j                  ,|j                  d       |j                  | j                         | j                  /|j                  d       |j                  d| j                  z          | j                  r|j                  d       | j                  8|j                  d       |j                  dt!        | j                        z          | j"                  8|j                  d       |j                  dt!        | j"                        z          |j                  | j$                         | j'                  |      \  }}}|-|dk7  r(| j                   j                  | j$                  ||       | j(                  | j                   j                  dd      g}|j                  d       dj                  | j$                  | j(                        }| j'                  ||      \  }}}|-|dk7  r(| j                   j                  | j$                  ||       | j*                  t-        | j*                        r| j/                         }| j                   j                  dd      }|D ]W  }|| j$                  |g}| j'                  |      \  }}}|*|dk7  s0| j                   j                  | j$                  ||       Y |||fS )NadduserTz-Dr   zGroup {0} does not existr[   r   r   z-hr   z-Hr   r   r   r  r   r   r   r  r[  --encrypted{name}:{password}r7   r?   rb  )rb   r   rG   r8   r<   r   rj   r2  r=   rN   r>   rB   rD   rW   rE   rY   r   rZ   r7   r   r?   r]   r   r   )	rs   r   r   r   r   r   r]   add_cmd_binr<   s	            r    r  zBusyBox.create_user!  sz   {{''	489

488JJtJJtxx ::!$$TZZ0%%*D*K*KDJJ*W%XJJtJJtzz"<<#JJtJJt||$99 JJtJJtyy!::!JJtJJtzz"JJt==$JJtJJt}}%::!JJtJJx$**,-;;JJt<<#JJtJJzC$556<<#JJtJJzC$556

499++C0C>bAgKK!!tyycb!A==$;;++J=>CJJ}%&--499t}}-UD//$/?LBS~"'%%499#"%E ;;"s4;;'7((*F++229dCK J"DIIu5#33C8C>bAgKK))tyycb)I	J 3|r   c                    | j                   j                  dd      | j                  g}| j                  r|j	                  d       | j                  |      S )NdeluserTz--remove-homer  r  s     r    r  zBusyBox.remove_usern  sL     KK$$Y5II

 ;;JJ'##C((r   c                   | j                         }g }d }d}d}| j                         }| j                  j                  dd      }| j                  j                  dd      }| j                  t        | j                        r| j                         }t        |      j                  |      }	|	r|D ]\  }
|
|	v s|| j                  |
g}| j                  |      \  }}}|/|dk7  s5| j                  j                  | j                  ||       ^ |	D ]i  }
|
|vs| j                  r|| j                  |
g}| j                  |      \  }}}|<|dk7  sB| j                  j                  | j                  ||       k | j                  dk(  r| j                  |d   | j                  k7  r| j                  j                  d	d      g}|j                  d
       dj                  | j                  | j                        }| j                  ||      \  }}}|-|dk7  r(| j                  j                  | j                  ||       |||fS )Nr   rr  Tdelgroupr   r  r  r   r[  rs  rt  ru  rb  )r  r  rb   r   r]   r   r   r   r	  r7   r   rj   rG   rM   r?   r2  )rs   r  r]   r   r   r   r  rv  remove_cmd_binr  r  add_cmd
remove_cmdr   r   s                  r    r  zBusyBox.modify_userz  s*   335~~kk..y$?11*dC ;;"s4;;'7((*F^,AA&IJ RAJ#.		1"='+';';G'DC>bAg KK11tyycb1QR $ RAt{{&4dii%C
'+';';J'GC>bAg KK11tyycb1QR 8+0IdSTgY]YfYfNf;;++J=>CJJ}%&--499t}}-UD//$/?LBS~"'%%499#"%E3|r   N)r   r   r   r  r  r  r  r   r   r    rp  rp    s    KZ
)(r   rp  c                      e Zd ZdZdZd Zy)Alpinez
    This is the Alpine User manipulation class. It inherits the BusyBox class
    behaviors such as using adduser and deluser commands.
    LinuxN)r   r   r   r  r   r  r   r   r    r  r    s     HLr   r  c                    t        ddd dt        j                         z        } t        t        dYi dt        ddddg	      d
t        dddg      dt        d      dt        dd      dt        d      dt        dd      dt        d      dt        d      dt        d      dt        dd      dt        d      d t        dd      d!t        dd      d"t        dd      d#t        d      d$t        d      d%t        dd      d&t        dd      d't        ddd(g)      d*t        d      d+t        dd      d,t        dd      d-t        dd      d.t        d      d/t        d| d0         d1t        d| d2         d3t        d      d4t        d| d         d5t        dd      d6t        dd7d7d8gd9      d:t        d;      d<t        dd      d=t        d      d>t        d      d?t        d      d@t        d      dAt        d      dBt        dd      dCt        d      dDt        d      dE      }t	        |      }|j                          |j                  dF|j                  z         |j                  r|j                  dG|j                  z         d }dH}dH}i }|j                  |d
<   |j                  |d<   |j                  dk(  r|j                         r|j                  r|j                  dI       |j                         \  }}}|dk7  r|j                  |j                  ||J       |j                   |d%<   |j"                  |d&<   n|j                  dk(  r|j                         s
|j                  r|j                  dI       d}|j$                  rV|j&                  rJt(        j*                  j-                  |j$                        }t(        j*                  j/                  |      sd}|j1                         \  }}}|r7|j3                         }	|	dur#|j5                  |	dK   |	dL   |j$                         |j                  r|j                  |d+<   nQ|j6                  |d+<   |j&                  |d'<   n2|j9                         \  }}}|j:                  |d-<   |j<                  |d,<   |#|dk7  r|j                  |j                  ||J       |j>                  dM|d<   |d|dN<   nd|dN<   |r||dO<   |r||dP<   |j                         r|j                  dk(  r|j3                         }	|	du rdQ|j                  z  |dR<   d|dS<   |	dK   |d<   |	dL   |d<   |	dT   |d<   |	dU   |d<   |	dV   |d<   |j@                  |j@                  |d<   |j3                         }	|j$                  
|	dU   |_        t(        j*                  jC                  |j$                        s[|j&                  rO|j                  s>|jE                  |j$                         |j5                  |	dK   |	dL   |j$                         d|dN<   |jF                  r|jI                         \  }}}|#|dk7  r|j                  |j                  ||J       |dk(  rd|dN<   |jK                         \  }}}|dk(  r|jM                         |dW<   n|jM                         |dW<   |jO                         |d3<   |jQ                         |dX<   |jS                         \  }}}|n)|dk7  r|j                  |j                  ||J       nd|dN<    |j                  dYi | y )ZNr   rsazansible-generated on %s)bitstype
passphraser=   r6   r   presentabsent)r  defaultchoicesr7   Tr:  )r  requiredaliasesr8   r   )r  r:   r   F)r  r  r<   r]   r#  )r  elementsr=   rN   rq   r>   r?   )r  no_logrF   rT   rU   rV   r9   r;   r@   rA   rB   
createhome)r  r  r  rD   rE   rC   rG   rH   rI   r  rJ   r  ra   rK   rL   rM   r  	on_create)r  r  r  r  r_   floatrO   rP   rQ   rR   rS   rW   rX   rY   rZ   )argument_specsupports_check_modezUser instantiated - platform %sz#User instantiated - distribution %sr   )rB  r  r   r   NOT_LOGGING_PASSWORDrB  rZ  r[  zfailed to look up user name: %sr\   r  r   r   r   ssh_fingerprintr  r   )*r  socketgethostnamer   r)   r   r   r   r  r7   r6   r:  r   r  r  rj   r@   rA   rN   rB   rp   rq   r   r   r  r  r  rE   r  rG   rC   r?   r]   r   r   rd   r  r  r   rQ  r  rE  )
ssh_defaultsrb   r:  r   r   r   resultpath_needs_parentsr   r  s
             r    mainr    s   )F,>,>,@@	L  /
E9x>ST/
54&B/
 % /
 7	/

 E"/
 Ve4/
 e$/
 6"/
 F#/
 uT2/
 %(/
 !%% >/
 !%% >/
 "&5!?/
  V$!/
$ U#%/
( FE2)/
* VU3+/
. &$O//
0 u%1/
2 VU33/
6 67/
8 VU39/
< "v.=/
> 5,v2FG?/
@ 5,v2FGA/
B 6*C/
D !e\)5LME/
F  $t<G/
H !eXR]G^glmI/
J g&K/
L F59M/
N F#O/
P e$Q/
R E*S/
T 5!U/
V E"W/
X -1eE,JY/
Z e$[/
\ e$]/
` !c2Fh <D!!#
LL2T]]BC:T=N=NNO	B
C
CFYYF6NjjF7OzzX     .!--/NRcQw  diiSR @"jjF7O#{{F8	y	 !     . "'yyT--3ww}}V,)-&!--/NRc "~~'u$&&tAwQC  #'99x #';;x (,(8(8}% "--/NRc#{{F8"&..F;>bAg$))<==$!7F:	z!y y
x
xdjjI5~~5==		IF5M#F8Quq'w Gyavq'w;;"#{{F8 ~~99QDIww~~dii(T-=-=$$##DII.""47DGTYY? $F9 >>!--/NRc~"'  diiSR @Qw$(y!!557NRcQw,/IIK(),/IIK()%)%:%:%<F>"'+'>'>'@F#$113S#:Qw  diiSR @$(y!Fvr   __main__)D
__future__r   DOCUMENTATIONEXAMPLESRETURNctypes.utilr   r  r  rp   r  rg  r5  rn  r  r  rj  rl   r   ansible.module_utilsr   +ansible.module_utils.common.text.convertersr   r   r   ansible.module_utils.basicr   "ansible.module_utils.common.localer	   $ansible.module_utils.common.sys_infor
   "ansible.module_utils.compat.typingmodule_utilscompattypingt	Structurer   cdllLoadLibrarycastr   utilfind_libraryr$   r   r%   argtypesPOINTERrestyper?  AttributeErrorcompiler   objectr)   r  r  r  r  r  r  rX  rj  rp  r  r  r   r   r   r    <module>r     s   #yv	@Dc
L  
  	 	 
 
       ' T T 4 G F . .V%% KK##KK$$S)	
E  &0ENN+V^^N;ENNI
 2::()+NH6 NHfb$ bJ	{ z)$ z)zq) q)hkD k\	e# e#PU$ UpN)4 N)bJd JZW of zF OZ  Is   BF( (F21F2