403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /lib/python3.11/site-packages/ansible/modules/__pycache__/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /lib/python3.11/site-packages/ansible/modules/__pycache__/user.cpython-311.pyc
�

���c�����ddlmZmZmZeZdZdZdZddl	Z	ddl
Z	ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZmZmZddlmZdd	l m!Z!dd
l"m#Z#ddl$m%cm&cm'Z(Gd�de	j)��Z*	e	j+�,e(j-e.e	j/�0d
������Z1e	j2fe1j3_4e	j5e*��e1j3_6dZ7n
#e8$rdZ7YnwxYwej9d��Z:d�Z3Gd�de;��Z<Gd�de<��Z=Gd�de=��Z>Gd�de<��Z?Gd�de<��Z@Gd�de<��ZAGd�de<��ZBGd �d!e<��ZCGd"�d#e<��ZDGd$�d%e<��ZEGd&�d'eE��ZFd(�ZGeHd)kreG��dSdS)*�)�absolute_import�division�print_functiona�/
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.
        type: str
    hidden:
        description:
            - macOS only, optionally hide the user from the login window and system preferences.
            - The default will be C(true) if the I(system) option is used.
        type: bool
        version_added: "2.6"
    non_unique:
        description:
            - Optionally when used with the -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 seuser type (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).
        type: str
    groups:
        description:
            - List of groups user will be added to.
            - By default, the user is removed from all other groups. Configure C(append) to modify this.
            - When set to an empty string C(''),
              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 C(true), add the user to the groups specified in C(groups).
            - If C(false), user will only be added to the groups specified in C(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 C(/usr/bin/false).
              Since Ansible 2.5, the default shell for non-system users on macOS is C(/bin/bash).
            - See notes for details on how other operating systems determine the default shell by
              the underlying tool.
        type: str
    home:
        description:
            - Optionally set the user's home directory.
        type: path
    skeleton:
        description:
            - Optionally set a home skeleton directory.
            - Requires C(create_home) option!
        type: str
        version_added: "2.0"
    password:
        description:
            - Optionally set the user's password to this crypted value.
            - On macOS systems, this value has to be cleartext. Beware of security issues.
            - To create a an account with a locked/disabled password on Linux systems, set this to C('!') or C('*').
            - To create a an account with a locked/disabled password on OpenBSD, set this to C('*************').
            - 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 these password values.
        type: str
    state:
        description:
            - Whether the account should exist or not, taking action if the state is different from what is stated.
        type: str
        choices: [ absent, present ]
        default: present
    create_home:
        description:
            - Unless set to C(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 C(createhome) to C(create_home) in Ansible 2.5.
        type: bool
        default: yes
        aliases: [ createhome ]
    move_home:
        description:
            - "If set to C(true) when used with C(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 C(state=present), setting this to C(true) makes the user a system account.
            - This setting cannot be changed on existing users.
        type: bool
        default: no
    force:
        description:
            - This only affects C(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 C(generate_ssh_key=yes) this forces an existing key to be overwritten.
        type: bool
        default: no
    remove:
        description:
            - This only affects C(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 C(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 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 I(.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:
            - C(always) will update passwords if they differ.
            - C(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 C(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.
            - Does nothing when used with other platforms.
            - Can set multiple profiles using comma separation.
            - To delete all the profiles, use C(profile='').
            - Currently supported on Illumos/Solaris.
        type: str
        version_added: "2.8"
    authorization:
        description:
            - Sets the authorization of the user.
            - Does nothing when used with other platforms.
            - Can set multiple authorizations using comma separation.
            - To delete all authorizations, use C(authorization='').
            - Currently supported on Illumos/Solaris.
        type: str
        version_added: "2.8"
    role:
        description:
            - Sets the role of the user.
            - Does nothing when used with other platforms.
            - Can set multiple roles using comma separation.
            - To delete all roles, use C(role='').
            - Currently supported on Illumos/Solaris.
        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"
    umask:
        description:
            - Sets the umask of the user.
            - Does nothing when used with other platforms.
            - Currently supported on Linux.
            - Requires C(local) is omitted or False.
        type: str
        version_added: "2.12"
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)
a�
- 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: 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
a�

append:
  description: Whether or not to append the user to groups.
  returned: When state is C(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 I(state) is C(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 I(groups) is not empty and I(state) is C(present)
  type: str
  sample: 'chrony,apache'
home:
  description: "Path to user's home directory."
  returned: When I(state) is C(present)
  type: str
  sample: '/home/asmith'
move_home:
  description: Whether or not to move an existing home directory.
  returned: When I(state) is C(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 I(state) is C(present) and I(password) is not empty
  type: str
  sample: 'NOT_LOGGING_PASSWORD'
remove:
  description: Whether or not to remove the user account.
  returned: When I(state) is C(absent) and user exists
  type: bool
  sample: True
shell:
  description: User login shell.
  returned: When I(state) is C(present)
  type: str
  sample: '/bin/bash'
ssh_fingerprint:
  description: Fingerprint of generated SSH key.
  returned: When I(generate_ssh_key) is C(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 I(generate_ssh_key) is C(True)
  type: str
  sample: /home/asmith/.ssh/id_rsa
ssh_public_key:
  description: Generated SSH public key file.
  returned: When I(generate_ssh_key) is C(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 I(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 I(uid) is passed to the module
  type: int
  sample: 1044
password_expire_max:
  description: Maximum number of days during which a password is valid.
  returned: When user exists
  type: int
  sample: 20
password_expire_min:
  description: Minimum number of days between password change
  returned: When user exists
  type: int
  sample: 20
N)�distro)�to_bytes�	to_native�to_text)�
AnsibleModule)�get_best_parsable_locale)�get_platform_subclassc
��eZdZdejfdejfdejfdejfdejfdejfdejfdejfd	ejfg	Zd
S)�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_���9/usr/lib/python3.11/site-packages/ansible/modules/user.pyrr�so������	�F�O�$�	�F�O�$�	�f�m�$�	�6�=�!�	�6�=�!�	�F�M�"�	�V�]�#�	�f�m�$�	�F�N�#�
�H�H�Hr!r�cTFz[^a-zA-Z0-9./=]c�@�t�|��jS�N)�_LIBC�getspnam�contents)�b_names r"r'r'�s���>�>�&�!�!�*�*r!c����eZdZdZdZdZdZdZdZdZ	dZ
�fd	�Zd
�Zd�Z
d'd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd(d�Zd(d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd �Z d!�Z!d"�Z"d#�Z#d$�Z$d%�Z%d&�Z&�xZ'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�r��tt��}t||���|��Sr%)rr+�super�__new__)�cls�args�kwargs�new_cls�	__class__s    �r"r1zUser.__new__s.���'��-�-���S�'�"�"�*�*�7�3�3�3r!c	�X�||_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_	|jd	|_
|jd
|_|jd|_|jd|_
|jd
|_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_|jd|_d|_|jd|_d|_|jd|_|jd|_|jd|_ |jd|_!|jd|_"|jd |_#|jd!|_$|j$�|jr|�%d"�#��|jd$�%d%�&|jd$��|_|jd&�k	tOj(|jd&��|_nE#tR$r8}|�%d'|j�d(tU|�����#��Yd}~nd}~wwxYw|jd)�|jd)|_+n-tXj-�&d*d+|jz��|_+|j�|jr|�.d,��dSdSdS)-N�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�umaskz$'umask' can not be used with 'local'��msg�groups�,�expireszInvalid value for 'expires' �: �ssh_key_filez.sshzid_%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.)/�module�paramsr8r9r:r;r<r=r>r?r@rArBrCrDrErFrGrHrI�	sshkeygen�ssh_bits�ssh_type�ssh_comment�ssh_passphraserOrPr]rQr[rRrSrTrUrVrWrX�	fail_json�join�time�gmtime�	Exceptionr�ssh_file�os�path�warn)�selfr`�es   r"�__init__z
User.__init__sZ������]�7�+��
��M�&�)��	��=��'����m�H�-��� �-��5����m�H�-����]�7�+��
��}�Y�/����]�7�+��
��
�j�1��
��]�7�+��
��m�H�-���!�=��7�����{�3����
�j�1��
��m�H�-���!�=��7����m�H�-�����'9�:����
�n�5��
��
�n�5��
�!�=�):�;���$�m�,@�A���%�}�->�?����M�&�)��	����#�]�?�;�������]�7�+��
��}�Y�/���#�]�?�;����M�&�)��	�#)�=�1F�#G�� �#)�=�1F�#G�� ��]�7�+��
��:�!�d�j�!����!G��H�H�H��=��"�.��(�(�6�=��#:�;�;�D�K��=��#�/�
j�#�{�6�=��+C�D�D������
j�
j�
j�� � � �T�\�\�\�[d�ef�[g�[g�[g�%h� �i�i�i�i�i�i�i�i�����
j�����=��(�4�"�M�.�9�D�M�M��G�L�L���4�=�1H�I�I�D�M��;��4�;��
�K�K�H�
I�
I�
I�
I�
I����s�$K1�1
L3�;.L.�.L3c����jjd�rf�jdk�r\d}�jjdtgd���vrd}�nt	�fd�dD����rd}d�jjdvrd}n߉jjd�d��}t
|��d	kr�tt�	|d
����rd}|ddkrt
|d
��d
krd}|ddkrt
|d
��dkrd}|ddkrt
|d
��dkrd}nd}|r �j�
d��dSdSdSdS)NrA�DarwinF)�*�!z
*************c3�@�K�|]}|�jjdvV��dS)rAN)r`ra)�.0�charrps  �r"�	<genexpr>z0User.check_password_encrypted.<locals>.<genexpr>ds2�����P�P�$�t�t�{�1�*�=�=�P�P�P�P�P�Pr!z:*!T�$������1��5�+�6�VzThe input password appears not to have been hashed. The 'password' argument must be encrypted for this module to work properly.)r`ra�platform�set�any�split�len�bool�_HASH_RE�searchro)rp�
maybe_invalid�fieldss`  r"�check_password_encryptedzUser.check_password_encryptedYs�����;��j�)� 	p�d�m�x�.G�.G�!�M��{�!�*�-��5P�5P�5P�1Q�1Q�Q�Q� %�
�
��P�P�P�P�%�P�P�P�P�P�)�$(�M��d�k�0��<�<�<�$(�M�M�!�[�/�
�;�A�A�#�F�F�F��6�{�{�a�'�'������r�
� ;� ;�<�<�1�,0�M�!�!�9��+�+��F�2�J���2�0E�0E�,0�M�!�!�9��+�+��F�2�J���2�0E�0E�,0�M�!�!�9��+�+��F�2�J���2�0E�0E�,0�M��(,�
��
p��� � �"o�p�p�p�p�p�? 	p� 	p�.G�.G�<
p�
pr!FTc��|jjr!|r|j�d|z��dSd�|D��}|j�|||���S)N�#In check mode, would have run: "%s"�r�r�c�,�g|]}t|����Sr )�str�rx�xs  r"�
<listcomp>z(User.execute_command.<locals>.<listcomp>�s��'�'�'�a�3�q�6�6�'�'�'r!)�use_unsafe_shell�data)r`�
check_mode�debug�run_command)rp�cmdr�r��obey_checkmodes     r"�execute_commandzUser.execute_command}sm���;�!�	^�n�	^��K���C�c�I�J�J�J��;�(�'�3�'�'�'�C��;�*�*�3�AQ�X\�*�]�]�]r!c�n�|jjs&|jr!|j�|j��SdSdSr%)r`r��
SHADOWFILE�backup_local�rps r"�
backup_shadowzUser.backup_shadow�sD���{�%�	=�$�/�	=��;�+�+�D�O�<�<�<�	=�	=�	=�	=r!c�.�|jrd}nd}|j�|d��g}|jr|js|�d��|jr|�d��|�|j��|�|��S)N�luserdel�userdelT�-f�-r)rRr`�get_bin_pathrBrIrCr9r�)rp�command_namer�s   r"�remove_user_userdelzUser.remove_user_userdel�s����:�	%�%�L�L�$�L��{�'�'��d�;�;�<���:�	�d�j�	��J�J�t�����;�	��J�J�t�����
�
�4�9�����#�#�C�(�(�(r!c�.�|jr9d}|j�dd��}|j�dd��}nd}|j�|d��g}|j�K|�d��|�|j��|jr|�d��|j�/|�d��|�|j��|j�n|�|j��s#|j�	d	|jz�
��|�d��|�|j���nP|�|j
���r5|jr|�d���ntj�
d
��rmtj��}t!|�d��d��}|dkr|�d��n�|�d��n�tj�
d��rWtj��}t!|�d��d��}|dkr|�d��n|�d��|j�lt'|j��rX|���}|js=|�d��|�d�|����|j�/|�d��|�|j��|j��|jr]tj�|j��}tj�|��s|�|j��|�d��|�|j��|j�/|�d��|�|j��|j��|jsz|�d��|jt=jd��kr|�d��n2|�t=j |j!|j����|j"�T|�d��|j#r|�d|j"z��n|�|j"��|jr�|js|�d��|j$�/|�d��|�|j$��|j%�2|�d��|�d |j%z��n|�d!��|j&r|�d"��|�|j
��|�'|��\}	}
}|jr|	dkr|	|
|fS|j��|jt=jd��krd#}n4t!tQj)|jj*d$����d%z}|�'|d&tW|��|j
g��\}	}
}|
|
z
}
||z
}|	dkr|	|
|fS|j�t'|j��dkr|	|
|fS|D];}|�'|d!|j
|g��\}	}
}|
|
z
}
||z
}|	dkr|	|
|fcS�<|	|
|fS)'N�luseradd�	lgroupmodT�lchage�useradd�-u�-o�-Z�Group %s does not existrY�-g�-nz/etc/redhat-release�.r��-Nz/etc/SuSE-release��-Gr\�-c�-d�-s�-er��-p�!%s�-m�-k�-K�UMASK=�-Mr�r}r]�Q�-E),rRr`r�r:rIr<r=r>�group_existsrgr9rmrn�existsr�version�intr�r[r��get_groups_setrhr?rPrD�dirname�isdir�create_homedirr@r]rirj�strftime�DATE_FORMATrArQrFrXrGr��math�floorrar)rpr��
lgroupmod_cmd�
lchage_cmdr��dist�
major_releaser[�parent�rc�out�err�lexpires�_out�_err�	add_groups                r"�create_user_useraddzUser.create_user_useradd�s����:�	%�%�L� �K�4�4�[�$�G�G�M���1�1�(�D�A�A�J�J�$�L��{�'�'��d�;�;�<���8���J�J�t�����J�J�t�x� � � ���
!��
�
�4� � � ��;�"��J�J�t�����J�J�t�{�#�#�#��:�!��$�$�T�Z�0�0�
R���%�%�*C�d�j�*P�%�Q�Q�Q��J�J�t�����J�J�t�z�"�"�"�"�
�
�
�t�y�
)�
)�	%�
�z�
%��
�
�4� � � � ��7�>�>�"7�8�8�%�!�>�+�+�D�$'��
�
�3����(:�$;�$;�M�$��)�)��
�
�4�(�(�(�(��
�
�4�(�(�(�(��W�^�^�$7�8�8�%�"�>�+�+�D�$'��
�
�3����(:�$;�$;�M�$��*�*��
�
�4�(�(�(���J�J�t�$�$�$��;�"�s�4�;�'7�'7�"��(�(�*�*�F��:�
-��
�
�4� � � ��
�
�3�8�8�F�+�+�,�,�,��<�#��J�J�t�����J�J�t�|�$�$�$��9� ���
3�������3�3���w�}�}�V�,�,�3��'�'��	�2�2�2��J�J�t�����J�J�t�y�!�!�!��:�!��J�J�t�����J�J�t�z�"�"�"��<�#�D�J�#��J�J�t�����|�d�k�!�n�n�,�,��
�
�2������
�
�4�=��)9�4�<�H�H�I�I�I��=�$��J�J�t�����!�
*��
�
�5�4�=�0�1�1�1�1��
�
�4�=�)�)�)���	��:�
!��
�
�4� � � ��}�(��
�
�4� � � ��
�
�4�=�)�)�)��z�%��
�
�4� � � ��
�
�8�d�j�0�1�1�1���J�J�t�����;�	��J�J�t�����
�
�4�9�����-�-�c�2�2���S�#��z�	"�R�1�W�W���S�>�!��<�#��|�d�k�!�n�n�,�,�����t�z�$�+�*<�Y�*G�H�H�I�I�U�R��#�3�3�Z��y�QY�GZ�GZ�\`�\e�4f�g�g��R��t��4�K�C��4�K�C��Q�w�w��C��~�%��;��#�d�k�"2�"2�a�"7�"7���S�>�!��	&�	&�I�#�3�3�]�D�$�)�U^�4_�`�`��R��t��4�K�C��4�K�C��Q�w�w��C��~�%�%�%���C��~�r!c��|jrd}nd}|j�|d��}tj|tj��sdS|dg}|�|d���\}}}||z}t|���d��}|D],}	|	�	���
d��rdS�-dS)	N�lusermod�usermodTFz--help�r��
z-a, --append)rRr`r�rm�access�X_OKr�rr��strip�
startswith)
rpr��usermod_pathr�r��data1�data2�helpout�lines�lines
          r"�_check_usermod_appendzUser._check_usermod_append!s����:�	%�%�L�L�$�L��{�/�/��d�C�C���y��r�w�/�/�	��5��X�&��!�1�1�#�e�1�L�L���U�E��%�-���'�"�"�(�(��.�.���	�	�D��z�z�|�|�&�&�~�6�6�
��t�t�
��ur!c��|jrWd}|j�dd��}t��}t��}|j�dd��}d}nd}|j�|d��g}|���}|���}	|j�i|dt|j��krK|�d��|�|j��|j	r|�d��|j
��|�|j
��s#|j�d	|j
z�
��|�
|j
��}
|d|
dkr0|�d��|�|
d��|j���|�d
���}d
}g}
|jdkr|r	|jsd}nh|�d
���}
t|���|
��}|r.|jr%|
D]!}||vr|	r|�d��d}n�"nd}|�r|jr}|jr1t|
���|��}t��}n�t|
���|��}t|���|
��}n�|jr@|	s>|�d��|�d�|����n=|�d��|�d�|
����|j�@|d|jkr/|�d��|�|j��|j�\|d|jkrK|�d��|�|j��|jr|�d��|j�@|d|jkr/|�d��|�|j��|j��:t|���d��}|jt5jd��kr;|dkr4|jrd}n�|�d��|�d��n�t5j|d z��}|dks|dd�|jdd�kr�|jr5tt9j|jjd!����d z}nG|�d��|�t5j|j |j����|j!r1|d�"d"��s|�d#��n9|j!d
ur0|d�"d"��r|�d$��|j#d%kr�|j$��|d�%d"��|j$�%d"��kr`d&�|D��}|�d'��|j!r|�d(|j$z��n|�|j$��d)\}}}tM|��dkr3|�|j'��|�(|��\}}}|jr|�|dks|||fS|�D|�(|d*tS|��|j'g��\}}}||z
}||z
}|dkr|||fStM|��dkrtM|��dkr|||fS|D];}|�(|d+|j'|g��\}}}||z
}||z
}|dkr|||fcS�<|D];}|�(|d|j'|g��\}}}||z
}||z
}|dkr|||fcS�<|||fS),Nr�r�Tr�r��r�r�r�rYr|r�F)�exclude_primaryr���remove_existing�-a�-Ar\r��r�r�r�r��r�r~rr}r�r�r]rv�-L�-U�alwaysc��g|]}|dv�|��	S))r�r�r �rxr#s  r"r�z,User.modify_user_usermod.<locals>.<listcomp>�s"��;�;�;��Q�l�%:�%:�1�%:�%:�%:r!r�r��Nr�r�r�r�)*rRr`r�r��	user_infor�r:r�rIr<r>r�rg�
group_infor[�user_group_membershipr��symmetric_difference�
differencerhr?rPrEr@r]�
user_passwordrirjr�r�rar�r�rQr�rOrA�lstripr�r9r�r)rpr�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��	del_groups                         r"�modify_user_usermodzUser.modify_user_usermod<s3���:�	%�%�L� �K�4�4�[�$�G�G�M��E�E�M��E�E�M���1�1�(�D�A�A�J��H�H�$�L��{�'�'��d�;�;�<���~�~�����/�/�1�1�
��8��D��G�s�4�8�}�}�$<�$<��J�J�t�����J�J�t�x� � � ���
!��
�
�4� � � ��:�!��$�$�T�Z�0�0�
R���%�%�*C�d�j�*P�%�Q�Q�Q��O�O�D�J�/�/�E��A�w�%��(�"�"��
�
�4� � � ��
�
�5��8�$�$�$��;�"�!�7�7��7�N�N�N�#�O��F��{�b� � �!�+�$�+�+�&*�O���,�,�U�,�C�C�� ��0�0�E�E�f�M�M�
��	/��{�/�!'�&�&�A� �J���#-�!5�$'�J�J�t�$4�$4�$4�26�� %��	 /��+/���
5��:�
5��{�O�(+�F���(>�(>�~�(N�(N�
�(+���
�
�(+�F���(>�(>�~�(N�(N�
�(+�N�(;�(;�(F�(F�v�(N�(N�
�
��{�5�:�5��
�
�4�(�(�(��
�
�3�8�8�J�#7�#7�8�8�8�8��
�
�4�(�(�(��
�
�3�8�8�F�#3�#3�4�4�4��<�#��Q��4�<�(?�(?��J�J�t�����J�J�t�|�$�$�$��9� �T�!�W��	�%9�%9��J�J�t�����J�J�t�y�!�!�!��~�
!��
�
�4� � � ��:�!�d�1�g���&;�&;��J�J�t�����J�J�t�z�"�"�"��<�#�!�$�"4�"4�"6�"6�q�"9�:�:�O��|�d�k�!�n�n�,�,�"�a�'�'��z�'�#%����
�
�4�(�(�(��
�
�2�����'+�k�/�E�2I�&J�&J�#�#�Q�&�&�*=�b�q�b�*A�T�\�RT�ST�RT�EU�*U�*U��z�R�#&�t�z�$�+�2D�Y�2O�'P�'P�#Q�#Q�UZ�#Z����
�
�4�(�(�(��
�
�4�=��1A�4�<�#P�#P�Q�Q�Q���	�d�1�g�&8�&8��&=�&=�	��J�J�t�����
�
�5�
(�
(�T�!�W�-?�-?��-D�-D�
(��J�J�t������8�+�+��
�0I�d�ST�g�n�n�]`�Na�Na�ei�er�ey�ey�z}�e~�e~�N~�N~�;�;�c�;�;�;�C��J�J�t�����!�
*��
�
�5�4�=�0�1�1�1�1��
�
�4�=�)�)�)�'���S�#��s�8�8�a�<�<��J�J�t�y�!�!�!�!�1�1�#�6�6�N�R��c��z�	"�"�*��a�����S�>�!���#�3�3�Z��y�QY�GZ�GZ�\`�\e�4f�g�g��R��t��4�K�C��4�K�C��Q�w�w��C��~�%��}����"�"�s�=�'9�'9�Q�'>�'>���S�>�!�&�	&�	&�I�#�3�3�]�D�$�)�U^�4_�`�`��R��t��4�K�C��4�K�C��Q�w�w��C��~�%�%�%��'�	&�	&�I�#�3�3�]�D�$�)�U^�4_�`�`��R��t��4�K�C��4�K�C��Q�w�w��C��~�%�%�%���C��~�r!c���	tjt|����dS#ttf$r+	tj|��YdS#t$rYYdSwxYwwxYw)NTF)�grp�getgrgidr��
ValueError�KeyError�getgrnam�rpr>s  r"r�zUser.group_exists�s���		��L��U���$�$�$��4���H�%�	�	�	�
���U�#�#�#��t�t���
�
�
��u�u�u�
����		���s&�!%�A!�A�
A�A!�A�A!c��|�|��sdS	ttjt	|������S#t
tf$r$ttj|����cYSwxYw�NF)r��listrrr�rrrrs  r"rzUser.group_info�s~��� � ��'�'�	��5�	-����S��Z�Z�0�0�1�1�1���H�%�	-�	-�	-����U�+�+�,�,�,�,�,�	-���s�-A�2A<�;A<c��|j�dS|���}td�|j�d��D����}|���D]s}|�|��s|j�d|z���|r<|r:|�|��d|dkr|�	|���t|S)Nc3�BK�|]}|�|���V��dSr%)r�r�s  r"rzz&User.get_groups_set.<locals>.<genexpr>�s/����D�D�1�!�D�Q�W�W�Y�Y�D�D�D�D�D�Dr!r\r�rYr�r|)
r[rr�r��copyr�r`rgrrC)rpr�rr[rs     r"r�zUser.get_groups_set�s����;���4��~�~�����D�D���(9�(9�#�(>�(>�D�D�D�D�D�������	!�	!�A��$�$�Q�'�'�
K���%�%�*C�q�*I�%�J�J�J��
!��
!�D�O�O�A�,>�,>�q�,A�T�!�W�,L�,L��
�
�a� � � ���
r!c��g}|���}tj��D]Z}|j|jvrJ|s|�|d���.|d|jkr|�|d���[|S)z- Return a list of groups the user belongs to rr|)�get_pwd_infor�getgrallr9�gr_memrI�gr_gid)rpr�r[rr>s     r"rzUser.user_group_membership�s������ � �"�"���\�^�^�	0�	0�E��y�E�L�(�(�&�0��M�M�%��(�+�+�+�+��A�w�%�,�.�.��
�
�e�A�h�/�/�/���
r!c��|j�r%tj�|j��s3|j�d�|j�����d}d�|j��}t|jd��5}|�
��ddd�}|D](}|�t|����rd}n�)ddd��n#1swxYwY|s9|j�
d�|j|j�	����|S	tj|j��rdSdS#t $rYdSwxYw)
NzK'local: true' specified but unable to find local account file {0} to parse.rYFz{0}:�rbr}Tz�'local: true' specified and user '{name}' was not found in {file}. The local user account may already exist if the local account database exists somewhere other than {file}.)�filer9)rRrmrnr��PASSWORDFILEr`rg�formatr9�open�	readlinesr�rro�pwd�getpwnamr)rpr��	name_test�f�reversed_linesr�s      r"�user_existszUser.user_exists
s���
�:�	��7�>�>�$�"3�4�4�
S���%�%�*w�*~�*~�@D�@Q�+R�+R�%�S�S�S��F��
�
�d�i�0�0�I��d�'��.�.�
�!�!"�����t�t��t�!4��*���D����x�	�':�':�;�;��!%�����
�
�
�
�
�
�
�
�
�
�
����
�
�
�
��
c��� � �3�39�6�t�?P�W[�W`�6�3a�3a�c�c�c�
�M�
��<��	�*�*� ��4� � ���
�
�
��u�u�
���s%�A	C&�&C*�-C*�/E�
E�Ec�z�|���sdSttj|j����Sr)r5r r0r1r9r�s r"r%zUser.get_pwd_info.s5�����!�!�	��5��C�L���+�+�,�,�,r!c��|���sdS|���}t|d��dkst|d��dkr|���d|d<|S)NFr~r)r5r%r�r)rprs  r"rzUser.user_info3st�����!�!�	��5�� � �"�"���t�A�w�<�<�1����D��G���� 1� 1��(�(�*�*�1�-�D��G��r!c��|jdu}|jdu}trZ	tt	|j����}n#t$rYdSwxYw||j|jkz}||j|jkz}|s|sdSd}|j	�
|d��g}|r|�d|jg��|r|�d|jg��|�|j��|�
|��S)Nr�chageTr�r�)rWrV�	HAVE_SPWDr'rr9rrrr`r��extendrIr�)rp�min_needs_change�max_needs_change�shadow_infor�r�s      r"�set_password_expirezUser.set_password_expire;s5���3�4�?���3�4�?���	O�
$�&�x��	�':�':�;�;�����
$�
$�
$�#�|�|�
$����
�� 8�K�<N� N�N���� 8�K�<N� N�N�� �	"�$4�	"�!�>����{�'�'��d�;�;�<���	9��J�J��d�6�7�8�8�8��	9��J�J��d�6�7�8�8�8��
�
�4�9�����#�#�C�(�(�(s�!=�
A�
Ac�6�d}d}trU	tt|j����}t	|j��}|j}||fS#t$r||fcYSwxYw|���s||fS|j	r|�
��\}}||fS)Nr�)r:r'rr9rrrrr5r��parse_shadow_file)rp�passwdr]r>s    r"rzUser.user_passwordUs��������	'�
'�&�x��	�':�':�;�;��"�;�#6�7�7��%�/���w��&���
'�
'�
'��w��&�&�&�
'�������!�!�	7��7�?�"�
�_�	7�"�4�4�6�6�O�F�G��w��s�?A
�
A�Ac��d}d}tj�|j��r�tj|jtj��r�t
|jd��5}|D]\}|�d|jz��r=|�	d��d}|�	d��|j
pd}�]	ddd��n#1swxYwY||fS)Nr��r�%s:�:r~r})rmrnr�r�r��R_OKr.r�r9r��SHADOWFILE_EXPIRE_INDEX)rprBr]r3r�s     r"rAzUser.parse_shadow_filehs"������
�7�>�>�$�/�*�*�	V�r�y���"�'�/R�/R�	V��d�o�s�+�+�
V�q��V�V�D����u�t�y�'8�9�9�V�!%���C����!3��"&�*�*�S�/�/�$�2N�"O�"U�SU���V�
V�
V�
V�
V�
V�
V�
V�
V�
V�
V�
V����
V�
V�
V�
V�
�w��s�"A C�C�Cc�l�|���}tj�|j��r|j}nstj�|d��s#|jjstd|j	z���tj�
|d|j��}|S)Nr�z%User %s home directory does not exist)rrmrn�isabsrlr�r`r�rkr9rh)rprr_s   r"�get_ssh_key_pathzUser.get_ssh_key_pathss����~�~����
�7�=�=���'�'�	@��=�L�L��7�>�>�$�q�'�*�*�
U�4�;�3I�
U�� G�$�)� S�T�T�T��7�<�<��Q����?�?�L��r!c	��	�|���}d}	|���}n)#t$r}ddt|��fcYd}~Sd}~wwxYwtj�|��}tj�|��s�|jj	rdS	t	j
|tdd����t	j||d|d��n/#t$r"}ddd|�d	t|����fcYd}~Sd}~wwxYwtj�|��r|jrd
}ndS|j�dd
��g}|�d��|�|j��|jdkr/|�d��|�|j��|�d��|�|j��|�d��|�|��|j�� |jj	r|j�d|z��dSt-j��\}}t-j��\}	}
t-j��\}}tj���}
t5|j��|
d<	t7jd�|D��||
|tj|
���}d}d}|�����t?j|	|gggd��d}d}d}|}|D]�}||	krMt	j |	d��}||z
}||vr.t	j!|tE|jd���dz��|}nLt	j |d��}||z
}||vr.t	j!|tE|jd���dz��|}d|vsd|vrdS��|�����|j#}t|��}t|��}nn#t$r}ddt|��fcYd}~Sd}~wwxYw|�d ��|�d��|�$||�!��\}}}|dkrS|jj	sGt	j||d|d��t	jd"|z|d|d��|||fS)#Nr~r�r��0700�r�r|zFailed to create r^�y)Nz1Key already exists, use "force: yes" to overwriter��
ssh-keygenT�-trz-bz-Cr�r��LC_ALLc�,�g|]}t|����Sr )rrs  r"r�z$User.ssh_key_gen.<locals>.<listcomp>�s��%?�%?�%?�a�h�q�k�k�%?�%?�%?r!)�stdin�stdout�stderr�
preexec_fn�envr!s+Enter passphrase (empty for no passphrase):sEnter same passphrase againi(�strict��errors�
sOverwrite (y/n)?)NzKey already existsr�r��r��%s.pub)%rrKrkrrmrnr�r�r`r��mkdirr��chown�OSErrorrBr�rIrdrcrerfr��pty�openpty�environr#r�
subprocess�Popen�setsid�poll�select�read�writer�
returncoder�)rpr�	overwriter_rq�ssh_dirr��master_in_fd�slave_in_fd�
master_out_fd�slave_out_fd�
master_err_fd�slave_err_fdrX�p�
out_buffer�
err_buffer�r_list�first_prompt�
second_prompt�prompt�fd�chunkr�r�r�s                          r"�ssh_key_genzUser.ssh_key_gen}s<���~�~�����	�	)��0�0�2�2�L�L���	)�	)�	)��r�9�Q�<�<�(�(�(�(�(�(�(�����	)�����'�/�/�,�/�/���w�~�~�g�&�&�	T��{�%�
#�"�{�
T����#�f�a�.�.�1�1�1����$�q�'�4��7�3�3�3�3���
T�
T�
T��2�2�G�G�G�Y�q�\�\�\�R�S�S�S�S�S�S�S�����
T����
�7�>�>�,�'�'�	W��z�
W��	�	�V�V��{�'�'��d�;�;�<���
�
�4�����
�
�4�=�!�!�!��=�1����J�J�t�����J�J�t�}�%�%�%��
�
�4�����
�
�4�#�$�$�$��
�
�4�����
�
�<� � � ���*��{�%�
#���!�!�"G�#�"M�N�N�N�"�{�(+��
�
�%�L�+�*-�+�-�-�'�M�<�*-�+�-�-�'�M�<��*�/�/�#�#�C�4�T�[�A�A�C��M�#
-��$�%?�%?�3�%?�%?�%?�+6�,8�,8�02�	�),�.�.�.��!�
� �
��f�f�h�h�&�#�]�M�=�+I�2�r�ST�U�U�VW�X�F�#Q�L�$B�M�)�F�$�D�D����.�.�$&�G�M�5�$A�$A�E�&�%�/�J�%��3�3� "���x��@S�\d�7e�7e�7e�hm�7m� n� n� n�)6���$&�G�M�5�$A�$A�E�&�%�/�J�%��3�3� "���x��@S�\d�7e�7e�7e�hm�7m� n� n� n�)6��.�*�<�<�@S�Wa�@a�@a�#C�#C�#C�Ab�%�f�f�h�h�&�,�\���
�+�+���
�+�+�����
-�
-�
-��2�y��|�|�,�,�,�,�,�,�,�����
-����
�J�J�t�����J�J�r�N�N�N�!�1�1�#�I�1�F�F�N�R��c�
��7�7�4�;�1�7�
�H�\�4��7�D��G�4�4�4��H�X��,�d�1�g�t�A�w�?�?�?��C��~�s^�-�
A�A�A�A�#AC)�)
D�3D�
D�D�DP �%:P � 
Q�*Q�;Q�Qc�\�|���}tj�|��sdd|zdfS|j�dd��g}|�d��|�d��|�|��|�|d�	��S)
Nr~zSSH Key file %s does not existr�rPTz-lr�Fr�)rKrmrnr�r`r�rIr�)rpr_r�s   r"�ssh_key_fingerprintzUser.ssh_key_fingerprint�s����,�,�.�.���w�~�~�l�+�+�	L��7�,�F��K�K��{�'�'��d�;�;�<���
�
�4�����
�
�4�����
�
�<� � � ��#�#�C��#�>�>�>r!c��d|���z}	t|d��5}|������}ddd��n#1swxYwYn#t$rYdSwxYw|S)Nr^rD)rKr.rjr��IOError)rp�ssh_public_key_filer3�ssh_public_keys    r"�get_ssh_public_keyzUser.get_ssh_public_key�s���&��)>�)>�)@�)@�@��	��)�3�/�/�
2�1�!"�������!1�!1��
2�
2�
2�
2�
2�
2�
2�
2�
2�
2�
2����
2�
2�
2�
2����	�	�	��4�4�	�����s4�A(�'A�A(�A � A(�#A �$A(�(
A6�5A6c�*�|���Sr%)r�r�s r"�create_userzUser.create_user�����'�'�)�)�)r!c�*�|���Sr%)r�r�s r"�remove_userzUser.remove_user�r�r!c�*�|���Sr%)rr�s r"�modify_userzUser.modify_user�r�r!c
��tj�|���s�|j�|j}nd}tj�|��r\	t	j||d���n�#t$r6}|j�ddt|��z���Yd}~nad}~wwxYw	tj
|��nC#t$r6}|j�ddt|��z���Yd}~nd}~wwxYwtj�|j��r�t|jd��5}|D]�}tjd|��}|r�t|�d��d	��}d
|z}	tj||���Y#t$r6}|j�ddt|��z���Yd}~��d}~wwxYw��	ddd��dS#1swxYwYdSdSdS)Nz	/etc/skelT)�symlinks�%s��failedrZrDz^UMASK\s+(\d+)$r~rNi�)rmrnr�rF�shutil�copytreerar`�	exit_jsonr�makedirs�
LOGIN_DEFSr.�re�matchr�r>�chmod)	rprnrFrqr3r��mrX�modes	         r"r�zUser.create_homedir�s����w�~�~�d�#�#�	\��}�(��=���&���w�~�~�h�'�'�	
P�P��O�H�d�T�B�B�B�B�B���P�P�P��K�)�)��4�)�A�,�,�;N�)�O�O�O�O�O�O�O�O�����P����P��K��%�%�%�%���P�P�P��K�)�)��4�)�A�,�,�;N�)�O�O�O�O�O�O�O�O�����P�����w�~�~�d�o�.�.�

\��$�/�3�/�/�	\�1� !�\�\���H�%7��>�>���\�$'�����
�
�A�$6�$6�E�#(�E�6�>�D�\� "���t� 4� 4� 4� 4��#*�\�\�\� $�� 5� 5�T�t�i�XY�l�l�GZ� 5� [� [� [� [� [� [� [� [�����\����\�\�	\�	\�	\�	\�	\�	\�	\�	\�	\�	\�	\�	\����	\�	\�	\�	\�	\�	\�%	\�	\�"

\�

\sm�A*�*
B*�4,B%�%B*�.C�
D�
,C>�>D�?AG-�F�G-�
G�%,G�G-�G�G-�-G1�4G1c���	tj|||��tj|��D]x\}}}|D]6}tjtj�||��||���7|D]6}tjtj�||��||���7�ydS#t
$r7}	|j�ddt|	��z���Yd}	~	dSd}	~	wwxYw)NTr�r�)	rmr`�walkrnrhrar`r�r)
rpr:�gidrn�root�dirs�files�dr3rqs
          r"�
chown_homedirzUser.chown_homedirs��	H��H�T�3��$�$�$�%'�W�T�]�]�
>�
>�!��d�E��>�>�A��H�R�W�\�\�$��2�2�C��=�=�=�=��>�>�A��H�R�W�\�\�$��2�2�C��=�=�=�=�>�
>�
>��
�	H�	H�	H��K�!�!��4�)�A�,�,�3F�!�G�G�G�G�G�G�G�G�G�����	H���s�B#B'�'
C(�1,C#�#C()FNT)T)(rrr�__doc__r��distributionr,r�rHr�r�r1rrr�r�r�r�r�r�rr�rr�rr5r%rr?rrArKr~r�r�r�r�r�r�r��
__classcell__�r6s@r"r+r+s/�������
�
��H��L� �L��J���"�J��K�4�4�4�4�4�;I�;I�;I�z"p�"p�"p�H^�^�^�^�=�=�=�
)�
)�
)�F�F�F�P���6_�_�_�B
�
�
�-�-�-�
�
�
�
�
�
�
�
����B-�-�-�
���)�)�)�4���&	�	�	����Y�Y�Y�v	?�	?�	?����*�*�*�*�*�*�*�*�*�\�\�\�<	H�	H�	H�	H�	H�	H�	Hr!r+c�>�eZdZdZdZdZdZdZdZd�Z	d�Z
d	�Zd
�ZdS)�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���|���}|jr�|d�d��s�|j�dd��d|jg}|j�M|dt|j��kr/|�d��|�|j��|�	|��S|jdur�|d�d��r�|j�dd��d	|jg}|j�M|dt|j��kr/|�d��|�|j��|�	|��Sd
S)Nr~�*LOCKED*�pwT�lockr�r�F�unlockr)
rrQr�r`r�r9r:r�rIr�)rprr�s   r"�_handle_lockzFreeBsdUser._handle_lock6s[���~�~������	-�d�1�g�&8�&8��&D�&D�	-���(�(��t�4�4���	��C�
�x�#��Q��3�t�x�=�=�(@�(@��
�
�4� � � ��
�
�4�8�$�$�$��'�'��,�,�,�
�
�5�
(�
(�T�!�W�-?�-?�
�-K�-K�
(���(�(��t�4�4���	��C�
�x�#��Q��3�t�x�=�=�(@�(@��
�
�4� � � ��
�
�4�8�$�$�$��'�'��,�,�,��~r!c��|j�dd��dd|jg}|jr|�d��|�|��S)Nr�Tr�r�r��r`r�r9rCrIr��rpr�s  r"r�zFreeBsdUser.remove_userOs[���K�$�$�T�4�0�0����I�	
���;�	��J�J�t�����#�#�C�(�(�(r!c���|j�dd��dd|jg}|j�K|�d��|�|j��|jr|�d��|j�/|�d��|�|j��|j�/|�d��|�|j��|j�l|�	|j��s#|j�
d	|jz�
��|�d��|�|j��|j�Q|���}|�d��|�d
�
|����|jr�|�d��|j�/|�d��|�|j��|j�2|�d��|�d|jz��|j�/|�d��|�|j��|j�/|�d��|�|j��|j��|�d��|jt)jd��kr|�d��n9|�t-t/j|j������|�|��\}}}|�(|dkr"|j�
|j||���|j�P|j�dd��d|j|jg}|�|��\}}}|�|}||z
}||z
}|���\}}}|�|}||z
}||z
}|||fS)Nr�Tr�r�r�r�r�r�r�rYr�r�r\r�r�r�r�r�r�r�r�0�r9rZr��chpassr�)r`r�r9r:rIr<r?rPr>r�rgr[r�rhrDrFrXr@rHr]rirjr��calendar�timegmr�rAr�)	rpr�r[r�r�r��_rcr�r�s	         r"r�zFreeBsdUser.create_user[s����K�$�$�T�4�0�0����I�	
���8���J�J�t�����J�J�t�x� � � ���
!��
�
�4� � � ��<�#��J�J�t�����J�J�t�|�$�$�$��9� ��J�J�t�����J�J�t�y�!�!�!��:�!��$�$�T�Z�0�0�
R���%�%�*C�d�j�*P�%�Q�Q�Q��J�J�t�����J�J�t�z�"�"�"��;�"��(�(�*�*�F��J�J�t�����J�J�s�x�x��'�'�(�(�(���		2��J�J�t�����}�(��
�
�4� � � ��
�
�4�=�)�)�)��z�%��
�
�4� � � ��
�
�8�d�j�0�1�1�1��:�!��J�J�t�����J�J�t�z�"�"�"���'��J�J�t�����J�J�t�'�(�(�(��<�#��J�J�t�����|�d�k�!�n�n�,�,��
�
�3������
�
�3�x��t�|�<�<�=�=�>�>�>��-�-�c�2�2���S�#�
�>�b�A�g�g��K�!�!�t�y�c�b�!�A�A�A��=�$���(�(��4�8�8���
��	�	�C�#�2�2�3�7�7�O�C��t��z����4�K�C��4�K�C��+�+�-�-���T�4�
�:��B��t����t����C��~�r!c�
�|j�dd��dd|jg}t|��}|���}|j�i|dt
|j��krK|�d��|�|j��|jr|�d��|j	�@|d|j	kr/|�d	��|�|j	��|j
��|d
|j
kr|js+tj
�|j
��s|jr|�d��|d
|j
kr/|�d��|�|j
��|j�/|�d
��|�|j��|j�2|�d��|�d|jz��|j��|�|j��s#|j�d|jz���|�|j��}|d|dkr/|�d��|�|j��|j�@|d|jkr/|�d��|�|j��|j��d}tj
�|j��r�tj|jtj��rkt7|jd��5}|D]:}|�d|jz��r|�d��d}�;	ddd��n#1swxYwY|j|kr/|�d��|�|j��|j��|���}|� ��}	tC|���"|	��}
d}|
r|jr|	D]
}||
vrd}n�nd}|rX|�d��|	}
|jr|	tC|��z}
|�d�#|
����|j$��t
|�%��d��}|j$tMj'd��kr1|dkr*|�d��|�d ��n�tMj'|��}|dks|dd�|j$dd�krN|�d��|�tQtSj*|j$������d!\}}}|t|��krM|�+|��\}}}||z
}||z
}|�(|dkr"|j�|j||�"��|j,d#kr�|j-��|d�.d$��|j-�.d$��krP|j�d%d��d&|j-|jg}|�+|��\}}}|�|}||z
}||z
}|�/��\}}}|�|}||z
}||z
}|||fS)'Nr�Tr�r�r�r�r�r�r�r�r�r�r�r�r�r�rYr|r�r�r�rDrErFr�Fr�r\r~rr�r�rr�r�r�r�r�)0r`r�r9r�rr:r�rIr<r?rPrErmrnr�rDrFrXr>r�rgrr@rHr�r�rGr.r�r�r[rr�r�rrhr]rrirjr�r�r�r�rOrAr	r�)rpr��cmd_lenrr�user_login_classr3r�rr[rrr�
new_groupsrrr�r�r�r�r�r�s                      r"r�zFreeBsdUser.modify_user�s���K�$�$�T�4�0�0����I�	
���c�(�(���~�~�����8��D��G�s�4�8�}�}�$<�$<��J�J�t�����J�J�t�x� � � ���
!��
�
�4� � � ��<�#��Q��4�<�(?�(?��J�J�t�����J�J�t�|�$�$�$��9� ��Q��4�9�$�$���$�����PT�PY�AZ�AZ�$�_c�_o�$��
�
�4� � � ��A�w�$�)�#�#��
�
�4� � � ��
�
�4�9�%�%�%��}�(��
�
�4� � � ��
�
�4�=�)�)�)��z�%��
�
�4� � � ��
�
�8�d�j�0�1�1�1��:�!��$�$�T�Z�0�0�
R���%�%�*C�d�j�*P�%�Q�Q�Q��O�O�D�J�/�/�E��A�w�%��(�"�"��
�
�4� � � ��
�
�4�:�&�&�&��:�!�d�1�g���&;�&;��J�J�t�����J�J�t�z�"�"�"���'�#���w�~�~�d�o�.�.�
B�2�9�T�_�b�g�3V�3V�
B��$�/�3�/�/�B�1� !�B�B���?�?�5�4�9�+<�=�=�B�/3�z�z�#���q�/A�,��B�B�B�B�B�B�B�B�B�B�B�B����B�B�B�B���#3�3�3��
�
�4� � � ��
�
�4�+�,�,�,��;�"�!�7�7�9�9�N��(�(�*�*�F��^�,�,�A�A�&�I�I�J�#�O��
+��;�+�#�"�"���
�?�?�.2�O�!�E�+��'+�O��
1��
�
�4� � � �#�
��;�>�!'�#�n�*=�*=�!=�J��
�
�3�8�8�J�/�/�0�0�0��<�#�!�$�"4�"4�"6�"6�q�"9�:�:�O��|�t�{�1�~�~�-�-�"�Q�&�&��J�J�t�$�$�$��J�J�s�O�O�O��'+�k�/�&B�&B�#�#�a�'�'�+>�r��r�+B�d�l�SU�TU�SU�FV�+V�+V��J�J�t�$�$�$��J�J�s�8�?�4�<�#@�#@�A�A�B�B�B�'���S�#��c�#�h�h���#�3�3�C�8�8��R��t��4�K�C��4�K�C��~�"��'�'���%�%�4�9�#�"�%�E�E�E���8�+�+��
�0I�d�ST�g�n�n�]g�Nh�Nh�lp�ly�mA�mA�BL�mM�mM�OM�OM���(�(��4�8�8���
��	�	�C�#�2�2�3�7�7�O�C��t��z����4�K�C��4�K�C��+�+�-�-���T�4�
�:��B��t����t����C��~�s�>N%�%N)�,N))
rrrr�r�r�r�rHr�r�r�r�r�r r!r"r�r�$s������	�	��H��L�%�J����K����2
)�
)�
)�X�X�X�tH�H�H�H�Hr!r�c��eZdZdZdZdS)�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)rrrr�r�r r!r"r�r�@s���������H�H�Hr!r�c�0�eZdZdZdZdZdZd�Zd�Zd�Z	dS)�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�dd��g}|j�K|�d��|�|j��|jr|�d��|j�l|�|j��s#|j�d|jz���|�d��|�|j��|j�Q|�	��}|�d��|�d	�
|����|j�/|�d
��|�|j��|j�/|�d��|�|j��|j
�/|�d��|�|j
��|j�/|�d
��|�|j��|j�:|jdkr/|�d��|�|j��|jr�|�d��|j�/|�d��|�|j��|j�2|�d��|�d|jz��|�|j��|�|��S)Nr�Tr�r�r�rYr�r�r\r�r�r�r�rur�r�r�r�r�)r`r�r:rIr<r>r�rgr[r�rhr?rPr@rHrArDrFrXr9r��rpr�r[s   r"r�zOpenBSDUser.create_user\s����{�'�'�	�4�8�8�9���8���J�J�t�����J�J�t�x� � � ���
!��
�
�4� � � ��:�!��$�$�T�Z�0�0�
R���%�%�*C�d�j�*P�%�Q�Q�Q��J�J�t�����J�J�t�z�"�"�"��;�"��(�(�*�*�F��J�J�t�����J�J�s�x�x��'�'�(�(�(��<�#��J�J�t�����J�J�t�|�$�$�$��9� ��J�J�t�����J�J�t�y�!�!�!��:�!��J�J�t�����J�J�t�z�"�"�"���'��J�J�t�����J�J�t�'�(�(�(��=�$���#�)=�)=��J�J�t�����J�J�t�}�%�%�%���		2��J�J�t�����}�(��
�
�4� � � ��
�
�4�=�)�)�)��z�%��
�
�4� � � ��
�
�8�d�j�0�1�1�1��
�
�4�9�����#�#�C�(�(�(r!c���|j�dd��g}|jr|�d��|�|j��|�|��S�Nr�Tr��r`r�rCrIr9r�r�s  r"r�zOpenBSDUser.remove_user_userdel��`���{�'�'�	�4�8�8�9���;�	��J�J�t�����
�
�4�9�����#�#�C�(�(�(r!c�	�|j�dd��g}|���}|j�i|dt	|j��krK|�d��|�|j��|jr|�d��|j��|�|j��s#|j�	d|jz���|�
|j��}|d|dkr/|�d	��|�|j��|j��|���}d
}d}g}|jdkr|r	|jsd}nQ|�
��}t|���|��}|r|jr|D]}	|	|vrd
}d}n�
nd}|r=|�|��|�d�|����|j�@|d|jkr/|�d��|�|j��|j�\|d|jkrK|jr|�d��|�d��|�|j��|j�@|d|jkr/|�d��|�|j��|j��d}
|j�dd��|jg}|�|d
���\}}
}|
���D]=}|���}|ddkrt5|��dkr|d}
�>|j|
kr/|�d��|�|j��|jr1|d�d��s|�d��n9|jd
ur0|d�d��r|�d��|jdkrR|j�K|jdkr@|d|jkr/|�d ��|�|j��t5|��dkrd!S|�|j��|�|��S)"Nr�Tr�r�r�r�rYr|r�F�-Sr�r�r\r�r�r�r�r�r�r��userinfor�r�classr~r�rur�r�r�r�r)r`r�rr:r�rIr<r>r�rgrr[rr�r�rrhr?rPrEr@rHr9r��
splitlinesr�r�rQr�rOrA)rpr�rrrr�
groups_optionr[rrr��userinfo_cmdr�r�r�r��tokenss                 r"r�zOpenBSDUser.modify_user�s����{�'�'�	�4�8�8�9���~�~�����8��D��G�s�4�8�}�}�$<�$<��J�J�t�����J�J�t�x� � � ���
!��
�
�4� � � ��:�!��$�$�T�Z�0�0�
R���%�%�*C�d�j�*P�%�Q�Q�Q��O�O�D�J�/�/�E��A�w�%��(�"�"��
�
�4� � � ��
�
�4�:�&�&�&��;�"�!�7�7�9�9�N�#�O� �M��F��{�b� � �!�+�$�+�+�&*�O���,�,�.�.�� ��0�0�E�E�f�M�M�
��/��{�/�!'�&�&�A� �J���04�
�26�� %�� /��
+/���
-��
�
�=�)�)�)��
�
�3�8�8�F�+�+�,�,�,��<�#��Q��4�<�(?�(?��J�J�t�����J�J�t�|�$�$�$��9� �T�!�W��	�%9�%9��~�
!��
�
�4� � � ��J�J�t�����J�J�t�y�!�!�!��:�!�d�1�g���&;�&;��J�J�t�����J�J�t�z�"�"�"���'�#�� �K�4�4�Z��F�F��	�R�L�!�1�1�,�u�1�U�U�N�R��c����(�(�
1�
1���������!�9��'�'�C��K�K�1�,<�,<�'-�a�y�$����#3�3�3��
�
�4� � � ��
�
�4�+�,�,�,���	�d�1�g�&8�&8��&=�&=�	��J�J�t�����
�
�5�
(�
(�T�!�W�-?�-?��-D�-D�
(��J�J�t������8�+�+��
�0I��M�S�(�(�T�!�W��
�-E�-E��J�J�t�����J�J�t�}�%�%�%��s�8�8�q�=�=�!�>��
�
�4�9�����#�#�C�(�(�(r!�
rrrr�r�r�r�r�r�r�r r!r"r�r�Ksb������
�
��H��L�%�J�5)�5)�5)�n)�)�)�\)�\)�\)�\)�\)r!r�c�0�eZdZdZdZdZdZd�Zd�Zd�Z	dS)�
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�dd��g}|j�K|�d��|�|j��|jr|�d��|j�l|�|j��s#|j�d|jz���|�d��|�|j��|j��|�	��}t|��dkr+|j�d	t|��z���|�d
��|�d�|����|j�/|�d��|�|j��|j
�/|�d
��|�|j
��|j�/|�d��|�|j��|j�/|�d��|�|j��|j�/|�d��|�|j��|jr�|�d��|j�/|�d��|�|j��|j�2|�d��|�d|jz��|�|j��|�|��S)Nr�Tr�r�r�rYr���.Too many groups (%d) NetBSD allows for 16 max.r�r\r�r�r�r�r�r�r�r�r�)r`r�r:rIr<r>r�rgr[r�r�rhr?rPr@rHrArDrFrXr9r�r�s   r"r�zNetBSDUser.create_users����{�'�'�	�4�8�8�9���8���J�J�t�����J�J�t�x� � � ���
!��
�
�4� � � ��:�!��$�$�T�Z�0�0�
R���%�%�*C�d�j�*P�%�Q�Q�Q��J�J�t�����J�J�t�z�"�"�"��;�"��(�(�*�*�F��6�{�{�R�����%�%�*Z�]`�ag�]h�]h�*h�%�i�i�i��J�J�t�����J�J�s�x�x��'�'�(�(�(��<�#��J�J�t�����J�J�t�|�$�$�$��9� ��J�J�t�����J�J�t�y�!�!�!��:�!��J�J�t�����J�J�t�z�"�"�"���'��J�J�t�����J�J�t�'�(�(�(��=�$��J�J�t�����J�J�t�}�%�%�%���		2��J�J�t�����}�(��
�
�4� � � ��
�
�4�=�)�)�)��z�%��
�
�4� � � ��
�
�8�d�j�0�1�1�1��
�
�4�9�����#�#�C�(�(�(r!c���|j�dd��g}|jr|�d��|�|j��|�|��Sr�r�r�s  r"r�zNetBSDUser.remove_user_userdelDr�r!c�&	�|j�dd��g}|���}|j�i|dt	|j��krK|�d��|�|j��|jr|�d��|j��|�|j��s#|j�	d|jz���|�
|j��}|d|dkr/|�d	��|�|j��|j��|���}d
}g}|jdkr|r	|jsd}nq|�
��}t|���|��}|r9|jr0|D],}||vr&t|���|��}d}n�-nd}|r{t#|��dkr+|j�	d
t#|��z���|�d��|�d�|����|j�@|d|jkr/|�d��|�|j��|j�\|d|jkrK|jr|�d��|�d��|�|j��|j�@|d|jkr/|�d��|�|j��|j�/|�d��|�|j��|jdkrG|j�@|d|jkr/|�d��|�|j��|jr1|d�d��s|�d��n9|jd
ur0|d�d��r|�d��t#|��dkrdS|�|j��|�|��S)Nr�Tr�r�r�r�rYr|r�Fr�r�r�r�r\r�r�r�r�r�r�r�r�r�r~r�r�z-C yesz-C nor)r`r�rr:r�rIr<r>r�rgrr[rr�r�r�unionr�rhr?rPrEr@rHrOrArQr�r9r�)	rpr�rrrrr[rrs	         r"r�zNetBSDUser.modify_userKs\���{�'�'�	�4�8�8�9���~�~�����8��D��G�s�4�8�}�}�$<�$<��J�J�t�����J�J�t�x� � � ���
!��
�
�4� � � ��:�!��$�$�T�Z�0�0�
R���%�%�*C�d�j�*P�%�Q�Q�Q��O�O�D�J�/�/�E��A�w�%��(�"�"��
�
�4� � � ��
�
�4�:�&�&�&��;�"�!�7�7�9�9�N�#�O��F��{�b� � �!�+�$�+�+�&*�O���,�,�.�.�� ��0�0�E�E�f�M�M�
��/��{�/�!'�&�&�A� �J���),�^�)<�)<�)B�)B�6�)J�)J��26�� %�� /��
+/���
-��v�;�;��#�#��K�)�)�.^�ad�ek�al�al�.l�)�m�m�m��
�
�4� � � ��
�
�3�8�8�F�+�+�,�,�,��<�#��Q��4�<�(?�(?��J�J�t�����J�J�t�|�$�$�$��9� �T�!�W��	�%9�%9��~�
!��
�
�4� � � ��J�J�t�����J�J�t�y�!�!�!��:�!�d�1�g���&;�&;��J�J�t�����J�J�t�z�"�"�"���'��J�J�t�����J�J�t�'�(�(�(���8�+�+��
�0I�d�ST�g�Y]�Yf�Nf�Nf��J�J�t�����J�J�t�}�%�%�%���	 �d�1�g�&8�&8��&D�&D�	 ��J�J�x� � � � �
�
�5�
(�
(�T�!�W�-?�-?�
�-K�-K�
(��J�J�w�����s�8�8�q�=�=�!�>��
�
�4�9�����#�#�C�(�(�(r!r�r r!r"r�r��sb���������H��L�%�J�7)�7)�7)�r)�)�)�O)�O)�O)�O)�O)r!r�c�P��eZdZdZdZdZdZdZd�Zd�Z	d�Z
d�Z�fd	�Zd
�Z
�xZS)�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}tdd��5}|D]�}|���}|�d��s|dkr�2tjd|��}|r|�d��}|�d��\}}|dkr|�d	��}��|d
kr|�d	��}��|dkr|�d	��}��	ddd��n#1swxYwYnB#t$r5}	|j	�
dt|	��z�
��Yd}	~	nd}	~	wwxYw|||fS)Nr�z/etc/default/passwdrD�#z^([^#]*)#(.*)$r~�=�MINWEEKSr��MAXWEEKS�	WARNWEEKSz&failed to read /etc/default/passwd: %srY)r.r�r�r�r�r>r��rstriprkr`rgr)
rp�minweeks�maxweeks�	warnweeksr3r�r��key�valuer�s
          r"�get_password_defaultszSunOS.get_password_defaults�s���	a��H��H��I��+�S�1�1�
7�Q��
7�
7�D��:�:�<�<�D�����,�,�!���
�
� ���!2�D�9�9�A��*� �w�w�q�z�z��!%���C���J�C���j�(�(�#(�<�<��#5�#5����
�*�*�#(�<�<��#5�#5�����+�+�$)�L�L��$6�$6�	��
7�
7�
7�
7�
7�
7�
7�
7�
7�
7�
7�
7����
7�
7�
7�
7����	a�	a�	a��K�!�!�&N�QZ�[^�Q_�Q_�&_�!�`�`�`�`�`�`�`�`�����	a�����(�I�.�.s;�C>�C
C2�&C>�2C6�6C>�9C6�:C>�>
D=�+D8�8D=c���|j�dd��g}|jr|�d��|�|j��|�|��Sr�r�r�s  r"r�zSunOS.remove_user��`���{�'�'�	�4�8�8�9���;�	��J�J�t�����
�
�4�9�����#�#�C�(�(�(r!c��|j�dd��g}|j�K|�d��|�|j��|jr|�d��|j�l|�|j��s#|j�d|jz���|�d��|�|j��|j�Q|�	��}|�d��|�d	�
|����|j�/|�d
��|�|j��|j�/|�d��|�|j��|j
�/|�d��|�|j
��|jr�|�d
��|j�/|�d��|�|j��|j�2|�d��|�d|jz��|j�/|�d��|�|j��|j�/|�d��|�|j��|j�/|�d��|�|j��|�|j��|�|��\}}}|�(|dkr"|j�|j||���|jj�s\|j��T|���|���\}}}	g}	t5|jd��5}
|
D�]n}t9|d���}|����d��}|d|jks|	�|���b|j|d<t?tAtCj!��dz����|d<|r4	t?tA|��dz��|d<n#tD$rYnwxYw|r4	t?tA|��dz��|d<n#tD$rYnwxYw|r4	t?tA|��dz��|d <n#tD$rYnwxYwd�
|��}|	�d!|z����p	ddd��n#1swxYwYt5|jd"��5}
|
�#|	��ddd��n#1swxYwYnB#tH$r5}|j�d#t9|��z���Yd}~nd}~wwxYw|||fS)$Nr�Tr�r�r�rYr�r�r\r�r�r�r�r�r�r��-Pr��-Rrr�r*�surrogate_or_strictrZrFr~r�r�r.r|r�r��%s
�w+�#failed to update users password: %s)%r`r�r:rIr<r>r�rgr[r�rhr?rPr@rDrFrXrSrTrUr9r�r�rAr�r�r.r�rr�r�r�r�rir�
writelinesrk)
rpr�r[r�r�r�r�r�r�r�r3r�r�s
             r"r�zSunOS.create_user�s=���{�'�'�	�4�8�8�9���8���J�J�t�����J�J�t�x� � � ���
!��
�
�4� � � ��:�!��$�$�T�Z�0�0�
R���%�%�*C�d�j�*P�%�Q�Q�Q��J�J�t�����J�J�t�z�"�"�"��;�"��(�(�*�*�F��J�J�t�����J�J�s�x�x��'�'�(�(�(��<�#��J�J�t�����J�J�t�|�$�$�$��9� ��J�J�t�����J�J�t�y�!�!�!��:�!��J�J�t�����J�J�t�z�"�"�"���		2��J�J�t�����}�(��
�
�4� � � ��
�
�4�=�)�)�)��z�%��
�
�4� � � ��
�
�8�d�j�0�1�1�1��<�#��J�J�t�����J�J�t�|�$�$�$���)��J�J�t�����J�J�t�)�*�*�*��9� ��J�J�t�����J�J�t�y�!�!�!��
�
�4�9�����-�-�c�2�2���S�#�
�>�b�A�g�g��K�!�!�t�y�c�b�!�A�A�A��{�%�'	f��}�(��"�"�$�$�$�04�0J�0J�0L�0L�-��(�I�"f��E��d�o�t�4�4�8��$%�8�8�D�#,�T�:O�#P�#P�#P�D�%)�Z�Z�\�\�%7�%7��%<�%<�F�#)�!�9��	�#9�#9� %���T� 2� 2� 2� (�(,�
�F�1�I�(+�C��	���u�0D�,E�,E�(F�(F�F�1�I�'�)�!)�03�C��M�M�A�4E�0F�0F�F�1�I�I��'1�!)�!)�!)�$(�D�!)���� (�)�!)�03�C��M�M�A�4E�0F�0F�F�1�I�I��'1�!)�!)�!)�$(�D�!)���� )�)�!)�03�C�	�N�N�Q�4F�0G�0G�F�1�I�I��'1�!)�!)�!)�$(�D�!)����$'�8�8�F�#3�#3�D�!�L�L��$��7�7�7�7�78�8�8�8�8�8�8�8�8�8�8�8����8�8�8�8�:�d�o�t�4�4�,�����U�+�+�+�,�,�,�,�,�,�,�,�,�,�,����,�,�,�,��� �f�f�f��K�)�)�.S�V_�`c�Vd�Vd�.d�)�e�e�e�e�e�e�e�e�����f�����C��~�s��(V
�?B$T?�$"R�T?�
R�T?�R�T?�"R=�<T?�=
S
�T?�	S
�
T?�"S3�2T?�3
T�=T?�?T�2T?�3V
�?U�V
�U�V
�V�5V
�V�V
�V�	V
�
W�+W�Wc�f
�|j�dd��g}t|��}|���}|j�i|dt|j��krK|�d��|�|j��|jr|�d��|j��|�	|j��s#|j�
d|jz���|�|j��}|d|dkr/|�d	��|�|j��|j��|�
��}|���}t|���|��}d
}|r|jr|D]
}	|	|vrd}n�nd}|r[|�d��|}
|jr|
�|��|�d�|
����|j�@|d
|jkr/|�d��|�|j��|j�\|d|jkrK|jr|�d��|�d��|�|j��|j�@|d|jkr/|�d��|�|j��|j�@|d|jkr/|�d��|�|j��|j�@|d|jkr/|�d��|�|j��|j�@|d|jkr/|�d��|�|j��|t|��kr^|�|j��|�|��\}}}
|�(|dkr"|j�
|j|
|���nd\}}}
|jdk�rM|j��E|d|jk�r3|���d\}}}
|jj�s|� ��\}}}	g}tC|j"d ��5}|D�]8}tG|d!�"��}|�$���%d#��}|d|jks|�|���b|j|d<tMttOj'��d$z����|d<|r"tMt|��dz��|d<|r"tMt|��dz��|d
<|r"tMt|��dz��|d<d#�|��}|�d%|z����:	ddd��n#1swxYwYtC|j"d&��5}|�(|��ddd��n#1swxYwYd}nB#tR$r5}
|j�
d'tG|
��z���Yd}
~
nd}
~
wwxYw|||
fS)(Nr�Tr�r�r�r�rYr|r�Fr�r\r�r�r�r�r�r�r�r.r�rNr��	r�rr�rr�r~r�r*r�rZrFr�r�r�r�)*r`r�r�rr:r�rIr<r>r�rgrr[rr�r�r�updaterhr?rPrEr@rSrTrUr9r�rOrAr�r�r�r.r�rr�r�r�rir�rk)rpr�r�rrrr[rrrr�r�r�r�r�r�r�r�r3r�r�s                     r"rzSunOS.modify_user_usermod;s	���{�'�'�	�4�8�8�9���c�(�(���~�~�����8��D��G�s�4�8�}�}�$<�$<��J�J�t�����J�J�t�x� � � ���
!��
�
�4� � � ��:�!��$�$�T�Z�0�0�
R���%�%�*C�d�j�*P�%�Q�Q�Q��O�O�D�J�/�/�E��A�w�%��(�"�"��
�
�4� � � ��
�
�4�:�&�&�&��;�"�!�7�7�9�9�N��(�(�*�*�F��^�,�,�A�A�&�I�I�J�#�O��
+��;�+�#�"�"���
�?�?�.2�O�!�E�+��'+�O��
1��
�
�4� � � �#�
��;�6��%�%�n�5�5�5��
�
�3�8�8�J�/�/�0�0�0��<�#��Q��4�<�(?�(?��J�J�t�����J�J�t�|�$�$�$��9� �T�!�W��	�%9�%9��~�
!��
�
�4� � � ��J�J�t�����J�J�t�y�!�!�!��:�!�d�1�g���&;�&;��J�J�t�����J�J�t�z�"�"�"��<�#��Q��4�<�(?�(?��J�J�t�����J�J�t�|�$�$�$���)�d�1�g��9K�.K�.K��J�J�t�����J�J�t�)�*�*�*��9� �T�!�W��	�%9�%9��J�J�t�����J�J�t�y�!�!�!��c�#�h�h����J�J�t�y�!�!�!�!�1�1�#�6�6�N�R��c��~�"��'�'���%�%�4�9�#�"�%�E�E�E��+�N�R��c���8�+�+��
�0I�d�ST�g�Y]�Yf�Nf�Nf���� � � �(�N�R��c��;�)�
f�04�0J�0J�0L�0L�-��(�I�f��E��d�o�t�4�4�8��$%�8�8�D�#,�T�:O�#P�#P�#P�D�%)�Z�Z�\�\�%7�%7��%<�%<�F�#)�!�9��	�#9�#9� %���T� 2� 2� 2� (�(,�
�F�1�I�(+�C��	���u�0D�,E�,E�(F�(F�F�1�I�'�C�,/��H�
�
��0A�,B�,B��q�	�'�C�,/��H�
�
��0A�,B�,B��q�	�(�D�,/��I����0B�,C�,C��q�	�#&�8�8�F�#3�#3�D�!�L�L��$��7�7�7�7�8�8�8�8�8�8�8�8�8�8�8�8����8�8�8�8�"�d�o�t�4�4�,�����U�+�+�+�,�,�,�,�,�,�,�,�,�,�,����,�,�,�,��B�B�� �f�f�f��K�)�)�.S�V_�`c�Vd�Vd�.d�)�e�e�e�e�e�e�e�e�����f�����C��~�sa�;Y,�D=X�Y,�X � Y,�#X �$Y,�<Y�Y,�Y"�"Y,�%Y"�&Y,�,
Z+�6+Z&�&Z+c���tt|�����}|r||���z
}|Sr%)r0r�r�_user_attr_info)rprr6s  �r"rzSunOS.user_info�sA����U�D�!�!�+�+�-�-���	+��D�(�(�*�*�*�D��r!c���dgdz}t|jd��5}|D]�}|����d��}|d|jkr}td�|d�d��D����}|�d	d��|d<|�d
d��|d<|�dd��|d<��	ddd��n#1swxYwY|S)
Nr�r|rDz::::rc3�@K�|]}|�d��V��dS)r�N)r�r�s  r"rzz(SunOS._user_attr_info.<locals>.<genexpr>�s,����I�I��q�w�w�s�|�|�I�I�I�I�I�Ir!r~�;�profiles�auths�rolesr�)r.�	USER_ATTRr�r�r9�dict�get)rpr�file_handlerr�r��tmps      r"r�zSunOS._user_attr_info�s*���t�a�x��
�$�.�#�
&�
&�	3�,�$�
3�
3���
�
���*�*�6�2�2����8�t�y�(�(��I�I�U�1�X�^�^�C�5H�5H�I�I�I�I�I�C�!�g�g�j�"�5�5�D��G�!�g�g�g�r�2�2�D��G�!�g�g�g�r�2�2�D��G��

3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3����	3�	3�	3�	3��s�B;C$�$C(�+C()rrrr�r�r�r�rr�r�r�rrr�r�r�s@r"r�r��s�����������H��L��J� �I�/�/�/�4)�)�)�g�g�g�Rl�l�l�\�����
�
�
�
�
�
�
r!r�c���eZdZdZdZdZdZdZgd�Z�fd�Z	d�Z
d�Zd	�Zdd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Zd�Zdd�Zd�Z�xZS)�
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()
    rtNr�))r?�RealName)rP�NFSHomeDirectory)r@�	UserShell)r:�UniqueID)r>�PrimaryGroupID�r;�IsHiddenc���tt|���|��|j�|jrd|_n|jrd|_nd|_|j�|j�d��dSdS)Nr~rr)r0rrrr;rGr�rI)rpr`r6s  �r"rrzDarwinUser.__init__�s����
�j�$���(�(��0�0�0��;���{�
 �����
�[�	��D�K�K��D�K��;�"��K���5�6�6�6�6�6�#�"r!c�F�|j�dd��|jgS)N�dsclT)r`r��dscl_directoryr�s r"�	_get_dsclzDarwinUser._get_dscl�s"����(�(���6�6��8K�L�Lr!c�b�|���}|ddd|jgz
}|�|d���\}}}g}|���D]Z}|�d��s|�d��r�-|�|���d���[|S)	Nz-searchz/Groups�GroupMembershipFr�� �)r)rr9r�r�r�rIr�)rpr�r�r�r�r[r�s       r"�_list_user_groupszDarwinUser._list_user_groups�s����n�n�����	�9�&7���C�C���-�-�c�%�-�H�H���S�#����N�N�$�$�	+�	+�D����s�#�#�
�t���s�';�';�
���M�M�$�*�*�,�,�q�/�*�*�*�*��
r!c��|���}|dd|jz|gz
}|�|d���\}}}|dkrdS|���}t	|��dkr!|d�d��dSt	|��d	kr9d
�|d���g|d	d�z��St	|��d	kr|d���SdS)zCReturn user PROPERTY as given my dscl(1) read or None if not found.�-read�	/Users/%sFr�rNr~r^r�r�)rr9r�r�r�r�rhr�)rp�propertyr�r�r�r�r�s       r"�_get_user_propertyzDarwinUser._get_user_property�s����n�n�������t�y�0�(�;�;���-�-�c�%�-�H�H���S�#�
��7�7��4���� � ���u�:�:��?�?���8�>�>�$�'�'��*�*��u�:�:��>�>��9�9�e�A�h�n�n�.�.�/�%����)�;�<�<�<��u�:�:��?�?���8�>�>�#�#�#��tr!c��|���}|gd�z
}|�|d���\}}}|dkr|j�d|||���d}d}|���D]@}t|�d��d��}	||	kr|	}||	kr|	d	kr|	}�A|rd|cxkrd
krnn|dzS|dzS)zv
        Return the next available uid. If system=True, then
        uid should be below of 500, if possible.
        )z-listz/UsersrFr�rz$Unable to get the next available uid)rZr�r�r�rr}i�i�r~)rr�r`rgr�r�r�)
rprGr�r�r�r��max_uid�max_system_uidr��current_uids
          r"�
_get_next_uidzDarwinUser._get_next_uid	s ��
�n�n�����.�.�.�.���-�-�c�%�-�H�H���S�#�
��7�7��K�!�!�:����	
"�
�
�
������N�N�$�$�	-�	-�D��d�j�j��o�o�b�1�2�2�K���$�$�%����+�+��c�0A�0A�!,����	&�q�>�/�/�/�/�C�/�/�/�/�/�!�A�%�%���{�r!c�
�|���}|jr|dd|jz|jgz
}n|dd|jzddgz
}|�|��\}}}|dkr|j�d|||���|||fS)	zsChange password for SELF.NAME against SELF.PASSWORD.

        Please note that password must be cleartext.
        z-passwdr�-create�PasswordrurzError when changing password�rZr�r�r�)rrAr9r�r`rg�rpr�r�r�r�s     r"�_change_user_passwordz DarwinUser._change_user_password,	s����n�n�����=�	I��I�{�T�Y�6��
�F�F�C�C��I�{�T�Y�6�
�C�H�H�C��-�-�c�2�2���S�#�
��7�7��K�!�!�&D�#�SV�[]�!�^�^�^��C��~�r!c��|j�d|_	tj|j��j|_n3#t$r&|j�d|jz���YnwxYwt|j��|_dS)zDConvert SELF.GROUP to is stringed numerical value suitable for dscl.N�nogroupzBGroup "%s" not found. Try to create it first using "group" module.rY)r>rrr(rr`rgr�r�s r"�_make_group_numericalz DarwinUser._make_group_numericalB	s����:��"�D�J�	y���d�j�1�1�8�D�J�J���	y�	y�	y��K�!�!�&j�mq�mw�&w�!�x�x�x�x�x�	y�������_�_��
�
�
s�#4�-A$�#A$c	���|dkrd}nd}ddd||jdd|g}|�|��\}}}|d	kr-|j�d
|�d|j�d|�d
�|||���|||fS)��Add or remove SELF.NAME to or from GROUP depending on ACTION.
        ACTION can be 'add' or 'remove' otherwise 'remove' is assumed. �addr�r��dseditgroupr��editrQ�userrzCannot z user "z" to group "�".r')r9r�r`rg)rpr>�action�optionr�r�r�r�s        r"�__modify_groupzDarwinUser.__modify_groupM	s����U�?�?��F�F��F��d�F�F�D�I�t�V�U�S���-�-�c�2�2���S�#�
��7�7��K�!�!�!�)/�������E�E�E�'C�HK�QT�Y[�
"�
]�
]�
]��C��~�r!c��d}d}d}d}t|�����}|j�(t|j�d����}ntg��}|jdur3||z
D]-}|�|d��\}}	}
||z
}||	z
}||
z
}d}�.||z
D]-}|�|d��\}}	}
||z
}||	z
}||
z
}d}�.||||fS)	r.rr�FNr\�deleteTr/)r�rr[r�rI�_DarwinUser__modify_group)rpr�r�r��changed�current�targetrCr�r�r�r/s            r"�
_modify_groupzDarwinUser._modify_group[	s#�����������d�,�,�.�.�/�/���;�"����*�*�3�/�/�0�0�F�F���W�W�F��;�%���!�F�*�
�
��$(�$7�$7���$I�$I�!��d�D��b����t����t�������G�#�	�	�C� $� 3� 3�C�� ?� ?��S�$���#�I�B��4�K�C��4�K�C��G�G��C��g�&�&r!c���d}dd|dg}|�|d���\}}}g}|���dd�D]X}	|�d	��d}n$#t$r|���}YnwxYw|�|���Y|jr_|j|vrTdd
|dd|jg}|�|��\}}}|dkr&|j�	d
|jz|||���dSdS|j|vrl||�
|j��=dd
|ddg|z}|�|��\}}}|dkr&|j�	d|jz|||���dSdS)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�defaultsrj�HiddenUsersListFr�r~r}�"rkz
-array-addrz%Cannot user "%s" to hidden user list.r'z-arrayz.Cannot remove user "%s" from hidden user list.N)r�r�r��
IndexErrorr�rIrGr9r`rg�index)rp�
plist_filer�r�r�r��hidden_usersr�s        r"�_update_system_userzDarwinUser._update_system_user{	s���
H�
��6�:�/@�A���-�-�c�%�-�H�H���S�#������!�!�!�B�$�'�	#�	#�A�
��G�G�C�L�L��O�����
�
�
��G�G�I�I����
��������"�"�"�"��;�	��y��,�,�!�7�J�8I�<�Y]�Yb�c��!%�!5�!5�c�!:�!:���S�#���7�7��K�)�)�.U�X\�Xa�.a�gj�ps�xz�)�{�{�{��q�-�,��y�L�(�(�!�,�"4�"4�T�Y�"?�"?�@�!�7�J�8I�8�T�Wc�c��!%�!5�!5�c�!:�!:���S�#���7�7��K�)�)�.^�ae�aj�.j�ps�y|�BD�)�E�E�E��q�)�(s�A!�!B�Bc��|���}|dd|jzdgz
}|�|d���\}}}|dkS)z1Check is SELF.NAME is a known user on the system.rrrFr�r)rr9r�r(s     r"r5zDarwinUser.user_exists�	sP���n�n�������t�y�0�*�=�=���-�-�c�%�-�H�H���S�#��Q�w�r!c��|���}|���}|dd|jzgz
}|�|��\}}}|dkr&|j�d|jz|||���|jrMtj�	|d��r(tj|d��|d|dzz
}|||fS)zCDelete SELF.NAME. If SELF.FORCE is true, remove its home directory.z-deleterrzCannot delete user "%s".r'r�z
Removed %s)rrr9r�r`rgrBrmrnr�r��rmtree)rprr�r�r�r�s      r"r�zDarwinUser.remove_user�	s����~�~�����n�n�����	�;���2�3�3���-�-�c�2�2���S�#�
��7�7��K�!�!�&@�4�9�&L�RU�[^�ce�!�f�f�f��:�	.��w�~�~�d�1�g�&�&�
.��
�d�1�g�&�&�&��|�d�1�g�-�-���C��~�r!rc�<�|���}|dd|jzgz
}|�|��\}}}|dkr&|j�d|jz|||���|���|j�,t|�|j	����|_|j
r�|j�d|jz|_|jjs}tj�|j��stj|j��|�t%|j��t%|j��|j��|j	s|j�d|_|jD]�}|d|jvr�|j|dr�|���}|dd|jz|d|j|dgz
}|�|��\}}}|dkr0|j�d|d�d	|j�d
�|||���||z
}||z
}|dkr|||fcS��|���\}}}||z
}||z
}|���|jr#|���\}}}}	||z
}||z
}|||fS)Nr%rrzCannot create user "%s".r'z	/bin/bashr~zCannot add property "z" to user "r3)rr9r�r`rgr,r:r�r#rGrDrPr�rmrnr�r�r�r�r>r@r��__dict__r)rFr[r=)
rpr�r�r�r�r��fieldr�r�r:s
          r"r�zDarwinUser.create_user�	s����n�n�����	�;���2�3�3���-�-�c�2�2���S�#�
��7�7��K�!�!�&@�4�9�&L�RU�[^�ce�!�f�f�f��"�"�$�$�$��8���4�-�-�d�k�:�:�;�;�D�H���	N��y� �'�$�)�3��	��;�)�
N��w�~�~�d�i�0�0�+��K��	�*�*�*��"�"�3�t�x�=�=�#�d�j�/�/�4�9�M�M�M��{�	%�t�z�1�$�D�J��[�	,�	,�E��Q�x�4�=�(�(�T�]�5��8�-D�(��n�n�&�&���	�;���#:�E�!�H�d�m�TY�Z[�T\�F]�^�^��#'�#7�#7��#<�#<� ��T�4���7�7��K�)�)�)�Z_�`a�Zb�Zb�Zb�dh�dm�dm�dm�.n�tw�~A�FH�)�I�I�I��t����t�����7�7���d�+�+�+�+���5�5�7�7���T�4��t����t���� � �"�"�"��;�	�(,�(:�(:�(<�(<�%�R��t�W��4�K�C��4�K�C��C��~�r!c�Z�d}d}d}|jr|���|jD]�}|d|jvr�|j|dr�|�|d��}|�$|t|j|d��kr�|���}|dd|jz|d|j|dgz
}|�|��\}}}	|dkr0|j	�
d|d�d|j�d�|||�	��|}||z
}||	z
}��|jd
kr+|j�$|�
��\}}}	||z
}||	z
}|}|jr)|���\}}}	}
||z
}||	z
}|
dur|}|���}|dkr|}|||fS)Nr�rr~r%rzCannot update property "z" for user "r3r'r�T)r>r,r�rKrr	rr9r�r`rgrOrAr)r[r=rF)rpr:r�r�rLr;r�r�r�r��_changeds           r"r�zDarwinUser.modify_user�	s
���������:�	)��&�&�(�(�(��[�
	 �
	 �E��Q�x�4�=�(�(�T�]�5��8�-D�(��1�1�%��(�;�;���?�g����u�Q�x�9P�1Q�1Q�&Q�&Q��.�.�*�*�C��I�{�T�Y�'>��a��$�-�X]�^_�X`�Ja�b�b�C�'+�';�';�C�'@�'@�$�R��t��Q�w�w���-�-�-�#(��8�8�8�T�Y�Y�Y�!8�=@�c�b�.�R�R�R�!�G��4�K�C��4�K�C����8�+�+��
�0I�#�9�9�;�;��R��t��4�K�C��4�K�C��G��;�	�)-�);�);�)=�)=�&�R��t�X��4�K�C��4�K�C��4�����
�
%�
%�
'�
'��
��7�7��G���c�"�"r!r%)r)rrrr�r�r�r�rr�rrrrrr#r)r,r9r=rFr5r�r�r�r�r�s@r"rr�s<��������� �H��L��J��N����F�7�7�7�7�7�"M�M�M�	�	�	����(����:���,	%�	%�	%����'�'�'�@'�'�'�R������$2�2�2�2�h(#�(#�(#�(#�(#�(#�(#r!rc�8�eZdZdZdZdZdZd�Zd	d�Zd�Z	d�Z
dS)
�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�dd��g}|jr|�d��|�|j��|�|��Sr�r�r�s  r"r�zAIX.remove_user+
r�r!r�c�<�|j�|d��g}|j�/|�d��|�|j��|j�l|�|j��s#|j�d|jz���|�d��|�|j��|j�et|j��rQ|�	��}|�d��|�d�
|����|j�/|�d��|�|j��|j�/|�d	��|�|j��|j
�/|�d
��|�|j
��|jr�|�d��|j�/|�d��|�|j��|j�2|�d
��|�d|jz��|�|j��|�|��\}}}|j��g}|�|j�dd����|�d��|�d��|�||j�d|j�����|||fS)NTr�r�rYr�r�r\r�r�r�r�r�r�r��chpasswdr�rFr])r`r�r:rIr>r�rgr[r�r�rhr?rPr@rDrFrXr9r�rA)rpr�r�r[r�r�r�s       r"r�zAIX.create_user_useradd3
s����{�'�'��d�;�;�<���8���J�J�t�����J�J�t�x� � � ��:�!��$�$�T�Z�0�0�
R���%�%�*C�d�j�*P�%�Q�Q�Q��J�J�t�����J�J�t�z�"�"�"��;�"�s�4�;�'7�'7�"��(�(�*�*�F��J�J�t�����J�J�s�x�x��'�'�(�(�(��<�#��J�J�t�����J�J�t�|�$�$�$��9� ��J�J�t�����J�J�t�y�!�!�!��:�!��J�J�t�����J�J�t�z�"�"�"���		2��J�J�t�����}�(��
�
�4� � � ��
�
�4�=�)�)�)��z�%��
�
�4� � � ��
�
�8�d�j�0�1�1�1��
�
�4�9�����-�-�c�2�2���S�#��=�$��C��J�J�t�{�/�/�
�D�A�A�B�B�B��J�J�t�����J�J�t����� � ��d�i�i�i����+O� �P�P�P��C��~�r!c���|j�dd��g}|���}|j�M|dt	|j��kr/|�d��|�|j��|j��|�|j��s#|j�d|jz���|�	|j��}|d|dkr/|�d��|�|j��|j
��|���}d	}g}|j
d
kr|r	|jsd}nO|���}t|���|��}|r|jr|D]
}||vrd}n�nd}|r=|�d��|�d�|����|j�@|d
|jkr/|�d��|�|j��|j�\|d|jkrK|jr|�d��|�d��|�|j��|j�@|d|jkr/|�d��|�|j��t)|��dkrd\}	}
}n3|�|j��|�|��\}	}
}|jdkr�|j��|d|jkr�g}|�|j�dd����|�d��|�d��|�||j�d|j�����\}}
}nd\}}
}|	�|	|
|
z||zfS||
|
z||zfS)Nr�Tr�r�r�rYr|r�Fr�r�r\r�r�r�r�r�r�r�r~rr�rSr�rFr])r`r�rr:r�rIr>r�rgrr[rr�r�rrhr?rPrEr@r�r9r�rOrA)rpr�rrrrr[rrr�r�r��rc2�out2�err2s               r"rzAIX.modify_user_usermodi
s����{�'�'�	�4�8�8�9���~�~�����8��D��G�s�4�8�}�}�$<�$<��J�J�t�����J�J�t�x� � � ��:�!��$�$�T�Z�0�0�
R���%�%�*C�d�j�*P�%�Q�Q�Q��O�O�D�J�/�/�E��A�w�%��(�"�"��
�
�4� � � ��
�
�4�:�&�&�&��;�"�!�7�7�9�9�N�#�O��F��{�b� � �!�+�$�+�+�&*�O���,�,�.�.�� ��0�0�E�E�f�M�M�
��/��{�/�!'�&�&�A� �J���26�� %�� /��+/���
-��
�
�4� � � ��
�
�3�8�8�F�+�+�,�,�,��<�#��Q��4�<�(?�(?��J�J�t�����J�J�t�|�$�$�$��9� �T�!�W��	�%9�%9��~�
!��
�
�4� � � ��J�J�t�����J�J�t�y�!�!�!��:�!�d�1�g���&;�&;��J�J�t�����J�J�t�z�"�"�"��s�8�8�q�=�=�+�N�R��c�c��J�J�t�y�!�!�!�!�1�1�#�6�6�N�R��c���8�+�+��
�0I�d�ST�g�Y]�Yf�Nf�Nf��C��J�J�t�{�/�/�
�D�A�A�B�B�B��J�J�t�����J�J�t���� $� 4� 4�S�$�)�)�)�UY�Ub�Ub�?c� 4� d� d��S�$��� .��S�$��
�>���d�
�C�$�J�/�/���t��S�4�Z�0�0r!c�T�t|j��}d}d}tj�|j���rHtj|jtj���r#t|jd��5}|�	��}ddd��n#1swxYwYd}d}	t|��D]5\}}	|	�d|z��r||dz}||dz}n�6d|vr.|�dd��d�
��}d|vr.|�dd��d�
��}n3#t$r&|j�d	|jz�
��YnwxYwt#|��}
t#|��pd}|
|fS)aExample AIX shadowfile data:
        nobody:
                password = *

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

        test1:
                password = *
                lastupdate = 1553695126

        r!r*Ns%s:r~r�s = r}zFailed to parse shadow file %srY)rr9rmrnr�r�r�rGr.r/�	enumerater�r�r�rBr`rgr)rpr)�b_passwd�	b_expires�bf�b_lines�
b_passwd_line�b_expires_linerC�b_linerBr]s            r"rAzAIX.parse_shadow_file�
s���$�)�$�$�����	�
�7�>�>�$�/�*�*�	^�r�y���"�'�/R�/R�	^��d�o�t�,�,�
)���,�,�.�.��
)�
)�
)�
)�
)�
)�
)�
)�
)�
)�
)����
)�
)�
)�
)� �M� �N�
^�%.�w�%7�%7���M�E�6��(�(��&��9�9��(/���	�(:�
�)0����);������]�*�*�,�2�2�6�1�=�=�b�A�G�G�I�I�H��^�+�+� .� 4� 4�V�Q� ?� ?�� C� I� I� K� K�I����
^�
^�
^���%�%�*J�T�_�*\�%�]�]�]�]�]�
^�����8�$�$���I�&�&�,�"���w��s%�8B�B� B�)B)E�-F�F)r�)rrrr�r�r�r�r�r�rrAr r!r"rPrP
su���������H��L�'�J�)�)�)�4�4�4�4�lK1�K1�K1�Z,�,�,�,�,r!rPc�0�eZdZdZdZdZdZd�Zd�Zd�Z	dS)�HPUXz�
    This is a HP-UX User manipulation class.

    This overrides the following methods from the generic class:-
      - create_user()
      - remove_user()
      - modify_user()
    zHP-UXNr-c��dg}|j�K|�d��|�|j��|jr|�d��|j�l|�|j��s#|j�d|jz���|�d��|�|j��|j�et|j��rQ|�	��}|�d��|�d�
|����|j�/|�d	��|�|j��|j�/|�d
��|�|j��|j
�/|�d��|�|j
��|j�/|�d��|�|j��|jr|�d
��n|�d��|jr|�d��|�|j��|�|��S)Nz/usr/sam/lbin/useradd.samr�r�r�rYr�r�r\r�r�r�r�r�r�r�)r:rIr<r>r�r`rgr[r�r�rhr?rPr@rArDrGr9r�r�s   r"r�zHPUX.create_user�
sB��*�+���8���J�J�t�����J�J�t�x� � � ���
!��
�
�4� � � ��:�!��$�$�T�Z�0�0�
R���%�%�*C�d�j�*P�%�Q�Q�Q��J�J�t�����J�J�t�z�"�"�"��;�"�s�4�;�'7�'7�"��(�(�*�*�F��J�J�t�����J�J�s�x�x��'�'�(�(�(��<�#��J�J�t�����J�J�t�|�$�$�$��9� ��J�J�t�����J�J�t�y�!�!�!��:�!��J�J�t�����J�J�t�z�"�"�"��=�$��J�J�t�����J�J�t�}�%�%�%���	��J�J�t������J�J�t�����;�	��J�J�t�����
�
�4�9�����#�#�C�(�(�(r!c���dg}|jr|�d��|jr|�d��|�|j��|�|��S)Nz/usr/sam/lbin/userdel.sam�-Fr�)rBrIrCr9r�r�s  r"r�zHPUX.remove_user#sj��*�+���:�	��J�J�t�����;�	��J�J�t�����
�
�4�9�����#�#�C�(�(�(r!c�H�dg}|���}|j�i|dt|j��krK|�d��|�|j��|jr|�d��|j��|�|j��s#|j�d|jz���|�	|j��}|d|dkr/|�d��|�|j��|j
��|���}d	}g}|j
d
kr|r	|jsd}nQ|�d	���}t|���|��}|r|jr|D]
}||vrd}n�nd}|rX|�d
��|}	|jr|t|��z}	|�d�|	����|j�@|d|jkr/|�d��|�|j��|j�\|d|jkrK|�d��|�|j��|jr|�d��|j�@|d|jkr/|�d��|�|j��|jdkr\|j�U|d|jkrD|�d��|�d��|�|j��t-|��dkrdS|�|j��|�|��S)Nz/usr/sam/lbin/usermod.samr�r�r�r�rYr|r�Fr�Tr�r�r\r�r�r�r�r�r�r�r�r~rer�r)rr:r�rIr<r>r�r`rgrr[rr�r�rrhr?rPrEr@rOrAr�r9r�)
rpr�rrrrr[rrr�s
          r"r�zHPUX.modify_user,s���*�+���~�~�����8��D��G�s�4�8�}�}�$<�$<��J�J�t�����J�J�t�x� � � ���
!��
�
�4� � � ��:�!��$�$�T�Z�0�0�
R���%�%�*C�d�j�*P�%�Q�Q�Q��O�O�D�J�/�/�E��A�w�%��(�"�"��
�
�4� � � ��
�
�4�:�&�&�&��;�"�!�7�7�9�9�N�#�O��F��{�b� � �!�+�$�+�+�&*�O���,�,�U�,�C�C�� ��0�0�E�E�f�M�M�
��/��{�/�!'�&�&�A� �J���26�� %�� /��+/���
1��
�
�4� � � �#�
��;�>�!'�#�n�*=�*=�!=�J��
�
�3�8�8�J�/�/�0�0�0��<�#��Q��4�<�(?�(?��J�J�t�����J�J�t�|�$�$�$��9� �T�!�W��	�%9�%9��J�J�t�����J�J�t�y�!�!�!��~�
!��
�
�4� � � ��:�!�d�1�g���&;�&;��J�J�t�����J�J�t�z�"�"�"���8�+�+��
�0I�d�ST�g�Y]�Yf�Nf�Nf��J�J�t�����J�J�t�����J�J�t�}�%�%�%��s�8�8�q�=�=�!�>��
�
�4�9�����#�#�C�(�(�(r!)
rrrr�r�r�r�r�r�r�r r!r"rbrb�
sb���������H��L��J�.)�.)�.)�`)�)�)�G)�G)�G)�G)�G)r!rbc�$�eZdZdZd�Zd�Zd�ZdS)�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�dd��g}|�d��|j�/|�d��|�|j��|j�||�|j��s3|j�d�|j�����|�d��|�|j��|j�/|�d��|�|j��|j	�/|�d	��|�|j	��|j
�/|�d
��|�|j
��|js|�d��|j�/|�d��|�|j��|j
�2|�d
��|�d|j
z��|jr|�d��|�|j��|�|��\}}}|�(|dkr"|j�|j||���|j��|j�dd��g}|�d��d�|j|j���}|�||���\}}}|�(|dkr"|j�|j||���|j��t'|j��r�|���}|j�dd��}|D]O}||j|g}|�|��\}}}|�(|dkr"|j�|j||����P|||fS)N�adduserTz-Dr�zGroup {0} does not existrYr�r�z-hr�z-Hr�r�r�r�rr�rS�--encrypted�{name}:{password}�r9rAr])r`r�rIr:r>r�rgr-r?rPr@rDrFrXrGr9r�rAr[r�r�)	rpr�r�r�r�r�r[�add_cmd_binr>s	         r"r�zBusyBox.create_users����{�'�'�	�4�8�8�9���
�
�4�����8���J�J�t�����J�J�t�x� � � ��:�!��$�$�T�Z�0�0�
Y���%�%�*D�*K�*K�D�J�*W�*W�%�X�X�X��J�J�t�����J�J�t�z�"�"�"��<�#��J�J�t�����J�J�t�|�$�$�$��9� ��J�J�t�����J�J�t�y�!�!�!��:�!��J�J�t�����J�J�t�z�"�"�"���	��J�J�t�����=�$��J�J�t�����J�J�t�}�%�%�%��:�!��J�J�t�����J�J�x�$�*�,�-�-�-��;�	��J�J�t�����
�
�4�9�����+�+�C�0�0���C��
�>�b�A�g�g��K�!�!�t�y�c�b�!�A�A�A��=�$��;�+�+�J��=�=�>�C��J�J�}�%�%�%�&�-�-�4�9�t�}�-�U�U�D��/�/��$�/�?�?�L�B��S��~�"��'�'���%�%�4�9�#�"�%�E�E�E��;�"�s�4�;�'7�'7�"��(�(�*�*�F��+�2�2�9�d�C�C�K��
J�
J��"�D�I�u�5��#�3�3�C�8�8���C���>�b�A�g�g��K�)�)�t�y�c�b�)�I�I�I���3��|�r!c��|j�dd��|jg}|jr|�d��|�|��S)N�deluserTz
--remove-homer�r�s  r"r�zBusyBox.remove_user�sW��
�K�$�$�Y��5�5��I�
��
�;�	(��J�J��'�'�'��#�#�C�(�(�(r!c�X�|���}g}d}d}d}|���}|j�dd��}|j�dd��}|j��t|j��r�|���}t|���|��}	|	r�|D]S}
|
|	vrM||j	|
g}|�
|��\}}}|�(|dkr"|j�|j	||����T|	D]Z}
|
|vrT|jsM||j	|
g}|�
|��\}}}|�(|dkr"|j�|j	||����[|j
dkr�|j��|d|jkr�|j�d	d��g}
|
�d
��d�|j	|j���}|�
|
|�
��\}}}|�(|dkr"|j�|j	||���|||fS)Nr�rjT�delgrouprr�r�r~rSrkrlrmr])rrr`r�r[r�r�r�rr9r�rgrIrOrAr-)rprr[r�r�r�rrn�remove_cmd_binrr�add_cmd�
remove_cmdr�r�s               r"r�zBusyBox.modify_user�s\���3�3�5�5����
�������~�~�����k�.�.�y�$�?�?����1�1�*�d�C�C���;�"�s�4�;�'7�'7�"��(�(�*�*�F��^�,�,�A�A�&�I�I�J��

R��R�R�A��J���#.��	�1�"=��'+�';�';�G�'D�'D���C���>�b�A�g�g� �K�1�1�t�y�c�b�1�Q�Q�Q��#�R�R�A�����t�{��&4�d�i��%C�
�'+�';�';�J�'G�'G���C���>�b�A�g�g� �K�1�1�t�y�c�b�1�Q�Q�Q����8�+�+��
�0I�d�ST�g�Y]�Yf�Nf�Nf��;�+�+�J��=�=�>�C��J�J�}�%�%�%�&�-�-�4�9�t�}�-�U�U�D��/�/��$�/�?�?�L�B��S��~�"��'�'���%�%�4�9�#�"�%�E�E�E��3��|�r!N)rrrr�r�r�r�r r!r"rhrhvsO��������C�C�C�J
)�
)�
)�(�(�(�(�(r!rhc��eZdZdZdZdZdS)�Alpinez�
    This is the Alpine User manipulation class. It inherits the BusyBox class
    behaviors such as using adduser and deluser commands.
    �LinuxN)rrrr�r�r�r r!r"rwrw�s$���������H��L�L�Lr!rwc
�|�tddddtj��z���}ttdUidtddddg�	���d
tdddg�
���dtd����dtdd����dtd����dtdd����dtd����dtd����dtd����dtdd����dtd����d tdd����d!tdd����d"td����d#td����d$tdd����d%tdd����d&tddd'g�(���d)td����d*tdd����d+tdd����d,tdd����d-td����d.td|d/����d0td|d1����d2td����d3td|d����d4tdd����d5tdd6d6d7gd�8���d9td:����d;tdd����d<td����d=td����d>td����d?td����d@td�����d�A��}t	|��}|���|�dB|jz��|jr|�dC|jz��d}dD}dD}i}|j	|d
<|j
|d<|j
dkr�|���rl|jr|�
d�E��|���\}}}|dkr|�|j	||�F��|j|d$<|j|d%<�np|j
dk�rd|���s�|jr|�
d�E��d}|jrL|jrEt(j�|j��}t(j�|��sd}|���\}}}|r@|���}	|	dur(|�|	dG|	dH|j��|jr|j	|d*<nA|j|d*<|j|d&<n,|���\}}}|j|d,<|j|d+<|�#|dkr|�|j	||�F��|j�dI|d<|�d|dJ<nd|dJ<|r||dK<|r||dL<|����r-|j
dk�r!|���}	|	durdM|j	z|dN<d|dO<|	dG|d<|	dH|d<|	dP|d<|	dQ|d<|	dR|d<|j �
|j |d<|���}	|j�
|	dQ|_t(j�!|j��sU|jrN|jsB|�"|j��|�|	dG|	dH|j��d|dJ<|j#r�|�$��\}}}|�#|dkr|�|j	||�F��|dkrd|dJ<|�%��\}}}|dkr|�&��|dS<n|�&��|dS<|�'��|d2<|�(��|dT<|�)��\}}}|�n)|dkr|�|j	||�F��nd|dJ<|j
dUi|��dS)VNr�rsazansible-generated on %s)�bits�type�
passphraser?r8r��present�absent)r|�default�choicesr9Tr2)r|�required�aliasesr:r�)r|r<r�F)r|r�r>r[r )r|�elementsr?rPrnr@rA)r|�no_logrHrVrWr;r=rBrCrD�
createhome)r|r�r�rFrGrErIrJrKr{rLr|r_rMrNrOr��	on_create)r|r�r�r�r]�floatrQrRrSrTrUrX)�
argument_spec�supports_check_modezUser instantiated - platform %sz#User instantiated - distribution %sr�)r:r�r�r|�NOT_LOGGING_PASSWORDr:rUrVzfailed to look up user name: %srZr�r�r�r��ssh_fingerprintr�r )*r�socket�gethostnamer
r+r�r�r�r�r9r8r5r�r�r�rgrBrCrPrDrmrnr�r�r�rr�rGr�rIrErAr[r�r�rbr~r�r�rKr�r?)
�ssh_defaultsr`r2r�r�r��result�path_needs_parentsr�rs
          r"�mainr�s�	���
�
��)�F�,>�,@�,@�@�	���L���+
�+
�+
��E�9�x��>S�T�T�T�T�+
��5�4�&��B�B�B�B�+
��%� � � � �+
����7�7�7�7�	+
�
�E�"�"�"�"�+
��V�e�4�4�4�4�
+
��e�$�$�$�$�+
��6�"�"�"�"�+
��E�"�"�"�"�+
��u�T�2�2�2�2�+
��%�(�(�(�(�+
�!%�%�� >� >� >� >�+
�!%�%�� >� >� >� >�+
��V�$�$�$�$�+
�"�U�#�#�#�#�#+
�&�F�E�2�2�2�2�'+
�(�V�U�3�3�3�3�)+
�,�&�$���O�O�O�O�-+
�.�u�%�%�%�%�/+
�0�V�U�3�3�3�3�1+
�4���6�6�6�6�5+
�6�V�U�3�3�3�3�7+
�:"�v�.�.�.�.�;+
�<�5�,�v�2F�G�G�G�G�=+
�>�5�,�v�2F�G�G�G�G�?+
�@�6�*�*�*�*�A+
�B!�e�\�)�5L�M�M�M�M�C+
�D $��t�<�<�<�<�E+
�F!�e�X��R]�G^�gl�m�m�m�m�G+
�H�g�&�&�&�&�I+
�J�F�5�9�9�9�9�K+
�L�F�#�#�#�#�M+
�N�e�$�$�$�$�O+
�P�E�*�*�*�*�Q+
�R�5�!�!�!�!�S+
�T�E�"�"�"�"�U+
�X!�[.�.�.�F�`��<�<�D��!�!�#�#�#�
�L�L�2�T�]�B�C�C�C���P����:�T�=N�N�O�O�O�	
�B�
�C�
�C�
�F��Y�F�6�N��j�F�7�O��z�X��������	+�� �
/�� � �� �.�.�.�!�-�-�/�/�N�R��c��Q�w�w�� � �d�i�S�R� �@�@�@�"�j�F�7�O�#�{�F�8���	
��y�	 �	 ����!�!�	1�� �
/�� � �� �.�.�.�"'���y�
.�T�-�
.�������3�3���w�}�}�V�,�,�.�)-�&�!�-�-�/�/�N�R��c�"�
D��~�~�'�'���u�$�$��&�&�t�A�w��Q����C�C�C�� �
9�#'�9��x� � �#'�;��x� �(,�(8��}�%�%�"�-�-�/�/�N�R��c�#�{�F�8��"&�.�F�;��
�>�b�A�g�g����$�)����<�<�<��=�$�!7�F�:��	�z�!��y��� ��y��
����x��
����x�������.)�d�j�I�5�5��~�~�����5�=�=�=��	�I�F�5�M�#�F�8���Q���u�
��q�'��w�� ��G��y���a���v���q�'��w���;�"�#�{�F�8���~�~�����9���Q��D�I��w�~�~�d�i�(�(�	%�T�-=�	%��$�
@��#�#�D�I�.�.�.��"�"�4��7�D��G�T�Y�?�?�?� $�F�9���>�
	A�!�-�-�/�/�N�R��c��~�"��'�'�� � �d�i�S�R� �@�@�@��Q�w�w�$(��y�!�!�5�5�7�7�N�R��c��Q�w�w�,/�I�I�K�K��(�)�)�,/�I�I�K�K��(�)�%)�%:�%:�%<�%<�F�>�"�'+�'>�'>�'@�'@�F�#�$��1�1�3�3���S�#�
�:���Q�w�w�� � �d�i�S�R� �@�@�@�@�$(��y�!��F����v�����r!�__main__)I�
__future__rrrr|�
__metaclass__�
DOCUMENTATION�EXAMPLES�RETURNr�ctypes.util�errnorr�rmr�rbr0rir�r�rerir��ansible.module_utilsr�ansible.module_utils._textrrr	�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&rr'�argtypes�POINTER�restyper:�AttributeError�compiler��objectr+r�r�r�r�r�rrPrbrhrwr�rr r!r"�<module>r�s���A�@�@�@�@�@�@�@�@�@��
�W�
�r1��fm
��`�
�
�
���������
�
�
�
�����	�	�	�	�	�	�	�	�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�������������'�'�'�'�'�'�C�C�C�C�C�C�C�C�C�C�4�4�4�4�4�4�G�G�G�G�G�G�F�F�F�F�F�F�.�.�.�.�.�.�.�.�.�.�.�.������V�%������K�#�#������K�$�$�S�)�)�	
�	
�
�
�E� &��0�E�N��+�V�^�N�;�;�E�N���I�I�������I�I�I������2�:�(�)�)��+�+�+�^H�^H�^H�^H�^H�6�^H�^H�^H�FY�Y�Y�Y�Y�$�Y�Y�Y�x�����{����k)�k)�k)�k)�k)�$�k)�k)�k)�\a)�a)�a)�a)�a)��a)�a)�a)�H\�\�\�\�\�D�\�\�\�~]#�]#�]#�]#�]#��]#�]#�]#�@F�F�F�F�F�$�F�F�F�RN)�N)�N)�N)�N)�4�N)�N)�N)�bB�B�B�B�B�d�B�B�B�J�����W����k�k�k�^�z����D�F�F�F�F�F��s�A/D�D�
D

Youez - 2016 - github.com/yon3zu
LinuXploit