%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyc

�
���^c@@sldZddlmZmZmZddlmZyddlZeZWne	k
rae
ZnXddlZddlZ
ddlZ
ddlmZeje�ZdZd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&d�Z'd�Z(d�Z)dS(u�
Manage macOS local directory passwords and policies

.. versionadded:: 2016.3.0

Note that it is usually better to apply password policies through the creation
of a configuration profile.
i(tabsolute_importtunicode_literalstprint_function(tdatetimeN(tCommandExecutionErrorushadowcC@s4tjjj�stdfStr&tStdfSdS(Nu	Not macOSuThe pwd module failed to load.(tsalttutilstplatformt	is_darwintFalsetHAS_PWDt__virtualname__(((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyt__virtual__"s

c	C@sdj|�}ytjjj|�}Wn[tk
r�}dj|�|jkrjtdj|���ntdj|j���nXyi|jd�djd�}i}x<|D]4}d|kr�|jd�\}}|||<q�q�W|SWntk
riSXd	S(
u2
    Get the entire accountPolicy and return it as a dictionary. For use by this
    module only

    :param str name: The user name

    :return: a dictionary containing all values for the accountPolicy
    :rtype: dict

    :raises: CommandExecutionError on user not found or any other unknown error
    upwpolicy -u {0} -getpolicyuError: user <{0}> not founduUser not found: {0}uUnknown error: {0}u
iu u=N(	tformatRRt	mac_utilstexecute_return_resultRtstrerrortsplitt
IndexError(	tnametcmdtrettexctpolicy_listtpolicy_dicttpolicytkeytvalue((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyt_get_account_policy-s"


cC@s�dj||�}ytjjj|�SWn[tk
r�}dj|�|jkrktdj|���ntdj|j���nXdS(u,
    Set a value in the user accountPolicy. For use by this module only

    :param str name: The user name
    :param str policy: The policy to apply

    :return: True if success, otherwise False
    :rtype: bool

    :raises: CommandExecutionError on user not found or any other unknown error
    u pwpolicy -u {0} -setpolicy "{1}"uError: user <{0}> not founduUser not found: {0}uUnknown error: {0}N(R
RRRtexecute_return_successRR(RRRR((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyt_set_account_policyNscC@s�dj||�}ytjjj|�}WnRtk
r}d|jkrdtdj|���ntdj|j���nX|S(uZ
    Return the value for a key in the accountPolicy section of the user's plist
    file. For use by this module only

    :param str name: The username
    :param str key: The accountPolicy key

    :return: The value contained within the key
    :rtype: str

    :raises: CommandExecutionError on user not found or any other unknown error
    u/dscl . -readpl /Users/{0} accountPolicyData {1}ueDSUnknownNodeNameuUser not found: {0}uUnknown error: {0}(R
RRRRRR(RRRRR((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyt_get_account_policy_data_valueds
cC@sEy&t|�}tj|�jd�SWnttfk
r@dSXdS(u�
    Converts a unix timestamp to a human readable date/time

    :param float unix_timestamp: A unix timestamp

    :return: A date/time in the format YYYY-mm-dd HH:MM:SS
    :rtype: str
    u%Y-%m-%d %H:%M:%SuInvalid TimestampN(tfloatRt
fromtimestamptstrftimet
ValueErrort	TypeError(tunix_timestamp((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyt_convert_to_datetime|s
	cC@sy�tj|�}i|jd6|jd6t|�d6t|�d6t|�d6t|�d6t|�d6t	|�d6t
|�d	6d
d6d
d6d
d
6SWnvtk
rtj
d|�idd6dd6dd6dd6dd6dd6dd6dd6dd	6dd6dd6dd
6SXdS(u�
    Return information for the specified user

    :param str name: The username

    :return: A dictionary containing the user's shadow information
    :rtype: dict

    CLI Example:

    .. code-block:: bash

        salt '*' shadow.info admin
    unameupasswduaccount_createdulogin_failed_countulogin_failed_lastulstchgumaxuexpireuchangeuUnavailableuminuwarnuinactuUser not found: %suN(tpwdtgetpwnamtpw_namet	pw_passwdtget_account_createdtget_login_failed_counttget_login_failed_lasttget_last_changetget_maxdayst
get_expiret
get_changetKeyErrortlogtdebug(Rtdata((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pytinfo�s8










cC@s4t|d�}tjjj|�}t|�}|S(uo
    Get the date/time the account was created

    :param str name: The username of the account

    :return: The date/time the account was created (yyyy-mm-dd hh:mm:ss)
    :rtype: str

    :raises: CommandExecutionError on user not found or any other unknown error

    CLI Example:

    .. code-block:: bash

        salt '*' shadow.get_account_created admin
    ucreationTime(RRRRtparse_returnR&(RRR%t	date_text((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyR+�scC@s4t|d�}tjjj|�}t|�}|S(ul
    Get the date/time the account was changed

    :param str name: The username of the account

    :return: The date/time the account was modified (yyyy-mm-dd hh:mm:ss)
    :rtype: str

    :raises: CommandExecutionError on user not found or any other unknown error

    CLI Example:

    .. code-block:: bash

        salt '*' shadow.get_last_change admin
    upasswordLastSetTime(RRRRR7R&(RRR%R8((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyR.�scC@s"t|d�}tjjj|�S(u\
    Get the the number of failed login attempts

    :param str name: The username of the account

    :return: The number of failed login attempts
    :rtype: int

    :raises: CommandExecutionError on user not found or any other unknown error

    CLI Example:

    .. code-block:: bash

        salt '*' shadow.get_login_failed_count admin
    ufailedLoginCount(RRRRR7(RR((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyR,�scC@s4t|d�}tjjj|�}t|�}|S(u�
    Get the date/time of the last failed login attempt

    :param str name: The username of the account

    :return: The date/time of the last failed login attempt on this account
        (yyyy-mm-dd hh:mm:ss)
    :rtype: str

    :raises: CommandExecutionError on user not found or any other unknown error

    CLI Example:

    .. code-block:: bash

        salt '*' shadow.get_login_failed_last admin
    ufailedLoginTimestamp(RRRRR7R&(RRR%R8((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyR-scC@s4|dd}t|dj|��t|�|kS(u�
    Set the maximum age of the password in days

    :param str name: The username of the account

    :param int days: The maximum age of the account in days

    :return: True if successful, False if not
    :rtype: bool

    :raises: CommandExecutionError on user not found or any other unknown error

    CLI Example:

    .. code-block:: bash

        salt '*' shadow.set_maxdays admin 90
    ii<u!maxMinutesUntilChangePassword={0}(RR
R/(Rtdaystminutes((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pytset_maxdaysscC@s8t|�}d|kr4|d}t|�ddSdS(uP
    Get the maximum age of the password

    :param str name: The username of the account

    :return: The maximum age of the password in days
    :rtype: int

    :raises: CommandExecutionError on user not found or any other unknown error

    CLI Example:

    .. code-block:: bash

        salt '*' shadow.get_maxdays admin 90
    umaxMinutesUntilChangePasswordii<i(Rtint(Rtpoliciestmax_minutes((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyR/:s

cC@stS(uI
    Set the minimum password age in days. Not available in macOS.

    :param str name: The user name

    :param int days: The number of days

    :return: Will always return False until macOS supports this feature.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' shadow.set_mindays admin 90
    (R	(RR9((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pytset_mindaysTscC@stS(uf
    Set the number if inactive days before the account is locked. Not available
    in macOS

    :param str name: The user name

    :param int days: The number of days

    :return: Will always return False until macOS supports this feature.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' shadow.set_inactdays admin 90
    (R	(RR9((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyt
set_inactdayshscC@stS(u�
    Set the number of days before the password expires that the user will start
    to see a warning. Not available in macOS

    :param str name: The user name

    :param int days: The number of days

    :return: Will always return False until macOS supports this feature.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' shadow.set_warndays admin 90
    (R	(RR9((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pytset_warndays}scC@s&t|dj|��t|�|kS(u
    Sets the date on which the password expires. The user will be required to
    change their password. Format is mm/dd/yyyy

    :param str name: The name of the user account

    :param date date: The date the password will expire. Must be in mm/dd/yyyy
        format.

    :return: True if successful, otherwise False
    :rtype: bool

    :raises: CommandExecutionError on user not found or any other unknown error

    CLI Example:

    .. code-block:: bash

        salt '*' shadow.set_change username 09/21/2016
    u+usingExpirationDate=1 expirationDateGMT={0}(RR
R1(Rtdate((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyt
set_change�scC@s$t|�}d|kr |dSdS(uR
    Gets the date on which the password expires

    :param str name: The name of the user account

    :return: The date the password will expire
    :rtype: str

    :raises: CommandExecutionError on user not found or any other unknown error

    CLI Example:

    .. code-block:: bash

        salt '*' shadow.get_change username
    uexpirationDateGMTu
Value not set(R(RR=((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyR1�scC@s&t|dj|��t|�|kS(u
    Sets the date on which the account expires. The user will not be able to
    login after this date. Date format is mm/dd/yyyy

    :param str name: The name of the user account

    :param datetime date: The date the account will expire. Format must be
        mm/dd/yyyy.

    :return: True if successful, False if not
    :rtype: bool

    :raises: CommandExecutionError on user not found or any other unknown error

    CLI Example:

    .. code-block:: bash

        salt '*' shadow.set_expire username 07/23/2015
    u/usingHardExpirationDate=1 hardExpireDateGMT={0}(RR
R0(RRB((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyt
set_expire�scC@s$t|�}d|kr |dSdS(uL
    Gets the date on which the account expires

    :param str name: The name of the user account

    :return: The date the account expires
    :rtype: str

    :raises: CommandExecutionError on user not found or any other unknown error

    CLI Example:

    .. code-block:: bash

        salt '*' shadow.get_expire username
    uhardExpireDateGMTu
Value not set(R(RR=((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyR0�scC@s�dj|�}ytjjj|�WnRtk
rz}d|jkr_tdj|���ntdj|j���nXdj|�}tjjj|�t|�ddkS(uH
    Deletes the account password

    :param str name: The user name of the account

    :return: True if successful, otherwise False
    :rtype: bool

    :raises: CommandExecutionError on user not found or any other unknown error

    CLI Example:

    .. code-block:: bash

        salt '*' shadow.del_password username
    udscl . -passwd /Users/{0} ''ueDSUnknownNodeNameuUser not found: {0}uUnknown error: {0}u&dscl . -create /Users/{0} Password '*'upasswdu*(R
RRRRRRR6(RRR((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pytdel_password�scC@s�dj||�}ytjjj|�WnRtk
r}}d|jkrbtdj|���ntdj|j���nXtS(u'
    Set the password for a named user (insecure, the password will be in the
    process list while the command is running)

    :param str name: The name of the local user, which is assumed to be in the
        local directory service

    :param str password: The plaintext password to set

    :return: True if successful, otherwise False
    :rtype: bool

    :raises: CommandExecutionError on user not found or any other unknown error

    CLI Example:

    .. code-block:: bash

        salt '*' mac_shadow.set_password macuser macpassword
    udscl . -passwd /Users/{0} '{1}'ueDSUnknownNodeNameuUser not found: {0}uUnknown error: {0}(R
RRRRRRtTrue(RtpasswordRR((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pytset_passwords(*t__doc__t
__future__RRRRR'RFR
tImportErrorR	tloggingtsalt.utils.mac_utilsRtsalt.utils.platformtsalt.exceptionsRt	getLoggert__name__R3RRRRRR&R6R+R.R,R-R;R/R?R@RARCR1RDR0RERH(((s;/usr/lib/python2.7/site-packages/salt/modules/mac_shadow.pyt<module>	sD


		!				.														!

Zerion Mini Shell 1.0