%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@sdZddlmZmZmZyddlZWnek
rEnXddlZddlZddl	m
Z
mZddlm
Z
ddlZddlZddlZddlZddlZddlZddlmZmZddlmZeje�ZdZd	�Zd
�Zdd�Z d
�Z!dddddde#d�Z$e%e%d�Z&e%d�Z'd�Z(d�Z)d�Z*d�Z+d�Z,e%d�Z-d�Z.d�Z/ej0j1j2j3d�d��Z4d�Z5d�Z6d�Z7d�Z8d�Z9d �Z:d!�Z;dS("u
Manage users on Mac OS 10.7+

.. important::
    If you feel that Salt should be using this module to manage users on a
    minion, and it is using a different module (or gives an error similar to
    *'user.info' is not available*), see :ref:`here
    <module-provider-override>`.
i(tabsolute_importtunicode_literalstprint_functionN(trangetmap(tstring_types(tCommandExecutionErrortSaltInvocationError(tsixuusercC@s1tjd�dks%tddkr)tStSdS(NukerneluDarwinuosrelease_infoi
i(i
i(t
__grains__tgettFalset__virtualname__(((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pyt__virtual__)scC@stdddgdt�dS(u
    Flush dscl cache
    ucmd.runudscacheutilu-flushcachetpython_shellN(t__salt__R(((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pyt_flush_dscl_cache1sucreatecC@s�tddkrd\}}nd\}}|rF||d|d<ntd	d
|d|g|d|d
krvdnddt�S(u$
    Run a dscl -create command
    uosrelease_infoi
iu.uu	localhostu/Local/Defaultiucmd.run_alludsclu-toutput_loglevelupasswduquietudebugR(i
i(u.u(u	localhostu/Local/Default(R	RR(tcmdtctypetsourcetnoderoot((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pyt_dscl8scC@sJtd�tj�D��}x'tdd�D]}||kr,|Sq,WdS(Ncs@s|]}|jVqdS(N(tpw_uid(t.0tx((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pys	<genexpr>Ksi�iii(tsettpwdtgetpwallR(tuidstidx((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pyt_first_avail_uidJsc
K@s�t|�r$tdj|���ntjjj|�rHtd��n|dkr`t	�}n|dkrud}n|dkr�dj|�}n|dkr�d}n|dkr�d}nt
|t�s�td��nt
|t�s�td��ndj|�}	t|	d	|g�t|	d
|g�t|	d|g�t|	d|g�t|	d
|g�|r�t
d|d|d|�ntjd�|r�t||�ntS(u�
    Add a user to the minion

    CLI Example:

    .. code-block:: bash

        salt '*' user.add name <uid> <gid> <groups> <home> <shell>
    uUser '{0}' already existsu"Username cannot contain whitespaceiu
/Users/{0}u	/bin/bashuuuid must be an integerugid must be an integeruUniqueIDuPrimaryGroupIDu	UserShelluNFSHomeDirectoryuRealNameu
file.mkdirtusertgroupiN(tinfoRtformattsalttutilststringutilstcontains_whitespaceRtNoneRt
isinstancetintRRttimetsleeptchgroupstTrue(
tnametuidtgidtgroupsthometshelltfullnamet
createhometkwargst	name_path((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pytaddQs<			
cC@s�tjjj|�r$td��nt|�s4tS|rJtjd�n|rkt	dt|�d�nt
|d
�tdj|�gdd�dd	kS(u�
    Remove a user from the minion

    CLI Example:

    .. code-block:: bash

        salt '*' user.delete name remove=True force=True
    u"Username cannot contain whitespaceu.force option is unsupported on MacOS, ignoringufile.removeuhomeu
/Users/{0}Rudeleteuretcodei((
R$R%R&R'RR"R.tlogtwarningRR-RR#(R/tremovetforce((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pytdelete�s

cC@sYdtkr|rtdSg}x'tj�D]}|jt|��q.W|td<|S(u}
    Return the list of all info for all users

    CLI Example:

    .. code-block:: bash

        salt '*' user.getent
    uuser.getent(t__context__RRtappendt_format_info(trefreshtrettdata((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pytgetent�s

cC@s�t|t�std��nt|�}|sHtdj|���n||dkr\tStdj|�d|d|gdd�tj	d�t|�j
d�|kS(	u{
    Change the uid for a named user

    CLI Example:

    .. code-block:: bash

        salt '*' user.chuid foo 4376
    uuid must be an integeruUser '{0}' does not existuuidu
/Users/{0}uUniqueIDRuchangei(R)R*RR"RR#R.RR+R,R
(R/R0tpre_info((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pytchuid�s

cC@s�t|t�std��nt|�}|sHtdj|���n||dkr\tStdj|�d|d|gdd�tj	d�t|�j
d�|kS(	u�
    Change the default group of the user

    CLI Example:

    .. code-block:: bash

        salt '*' user.chgid foo 4376
    ugid must be an integeruUser '{0}' does not existugidu
/Users/{0}uPrimaryGroupIDRuchangei(R)R*RR"RR#R.RR+R,R
(R/R1RF((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pytchgid�s

cC@s�t|�}|s*tdj|���n||dkr>tStdj|�d|d|gdd�tjd�t|�jd�|kS(u�
    Change the default shell of the user

    CLI Example:

    .. code-block:: bash

        salt '*' user.chshell foo /bin/zsh
    uUser '{0}' does not existushellu
/Users/{0}u	UserShellRuchangei(R"RR#R.RR+R,R
(R/R4RF((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pytchshell�s

cK@s�tjjj|�}|jdt�}|rCtjjj|�n|rYtjd�nt|�}|s�t	dj
|���n||dkr�tStdj
|�d|d|gdd�t
jd	�t|�jd�|kS(
u�
    Change the home directory of the user

    CLI Example:

    .. code-block:: bash

        salt '*' user.chhome foo /Users/foo
    upersistu6Ignoring unsupported 'persist' argument to user.chhomeuUser '{0}' does not existuhomeu
/Users/{0}uNFSHomeDirectoryRuchangei(R$R%targstclean_kwargstpopRtinvalid_kwargsR:R"RR#R.RR+R,R
(R/R3R7tpersistRF((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pytchhomes"

cC@s�tjjj|�}t|�}|s?tdj|���ntjjj|d�|d<||dkrptStdj|�d|gdd�t	j
d�tjjjt|�jd��}||kS(u�
    Change the user's Full Name

    CLI Example:

    .. code-block:: bash

        salt '*' user.chfullname foo 'Foo Bar'
    uUser '{0}' does not existufullnameu
/Users/{0}uRealNameRucreatei(R$R%RDtdecodeR"RR#R.RR+R,R
(R/R5RFtcurrent((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pyt
chfullname-s

$c
C@s�t|�}|s*tdj|���nt|t�rK|jd�}ng|D]!}tjjj	|�rR|^qR}|r�t
djdj|����ntt
|��}td�|D��}td|d�}|r�|j|�n||krtSx4||D](}	tdj|	�d	|gd
d�q
W|syx7||D](}	tdj|	�d	|gd
d�qJWntjd
�tt
|��|kS(uW
    Change the groups to which the user belongs. Note that the user's primary
    group does not have to be one of the groups passed, membership in the
    user's primary group is automatically assumed.

    groups
        Groups to which the user should belong, can be passed either as a
        python list or a comma-separated string

    append
        Instead of removing user from groups not included in the ``groups``
        parameter, just add user to any groups for which they are not members

    CLI Example:

    .. code-block:: bash

        salt '*' user.chgroups foo wheel,root
    uUser '{0}' does not existu,uInvalid group name(s): {0}u, cs@s3|])}ttj|��rtj|�VqdS(N(tboolRt	text_type(RR((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pys	<genexpr>osufile.gid_to_groupugidu/Groups/{0}uGroupMembershipRuappendudeletei(R"RR#R)RtsplitR$R%R&R'RtjoinRtlist_groupsRR9R.RR+R,(
R/R2R@tuinfoRt
bad_groupstugrpstdesiredt
primary_groupR!((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pyR-Ms6.
cC@s6ytj|�}Wntk
r'iSXt|�SdS(un
    Return user information

    CLI Example:

    .. code-block:: bash

        salt '*' user.info root
    N(RtgetpwnamtKeyErrorRA(R/RD((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pyR"�s


cC@sPi|jd6t|j�d6|jd6|jd6|jd6|jd6|jd6S(u1
    Return user information in a pretty way
    ugidugroupsuhomeunameushelluuidufullname(tpw_gidRWtpw_nametpw_dirtpw_shellRtpw_gecos(RD((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pyRA�s




uidcC@stdddd|g�S(u�
    Return the primary group of the named user

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' user.primary_group saltadmin
    ucmd.runuidu-gu-n(R(R/((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pyR\�s
cC@s,gtjjj|�D]}|^q}|S(u{
    Return a list of groups the named user belongs to.

    name

        The name of the user for which to list groups. Starting in Salt 2016.11.0,
        all groups for the user, including groups beginning with an underscore
        will be listed.

        .. versionchanged:: 2016.11.0

    CLI Example:

    .. code-block:: bash

        salt '*' user.list_groups foo
    (R$R%R tget_group_list(R/R!R2((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pyRW�s(cC@s tdgd�d}|j�S(ur
    Return a list of all users

    CLI Example:

    .. code-block:: bash

        salt '*' user.list_users
    u/usersulistustdout(RRU(tusers((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pyt
list_users�s
cC@s�t|�}|s*tdj|���nt|�}|rTtdj|���ntdj|�d||gdd�tjd�t|�jd�|kS(u�
    Change the username for a named user

    CLI Example:

    .. code-block:: bash

        salt '*' user.rename name new_name
    uUser '{0}' does not existuUser '{0}' already existsu
/Users/{0}u
RecordNameRuchangei(R"RR#RR+R,R
(R/tnew_nametcurrent_infotnew_info((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pytrename�s

cC@s>ddddg}td|dt�}|dr6tS|dS(	u
    .. versionadded:: 2016.3.0

    Gets the current setting for Auto Login

    :return: If enabled, returns the user name, otherwise returns False
    :rtype: str, bool

    CLI Example:

    .. code-block:: bash

        salt '*' user.get_auto_login
    udefaultsureadu0/Library/Preferences/com.apple.loginwindow.plistu
autoLoginUserucmd.run_alltignore_retcodeuretcodeustdout(RR.R(RRC((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pytget_auto_login�s	cC@s/ddddddddd	d
dg}t|�}ttt|��}t|�|}|dkr||dg||}nxtdt|�t|��D]_}d}xPt|t|t|�t|���D]&}||||A||<|d
7}q�Wq�Wttt|��}djtj	j
j|��S(u�
    Internal function for obfuscating the password used for AutoLogin
    This is later written as the contents of the ``/etc/kcpassword`` file

    .. versionadded:: 2017.7.3

    Adapted from:
    https://github.com/timsutton/osx-vm-templates/blob/master/scripts/support/set_kcpassword.py

    Args:

        password(str):
            The password to obfuscate

    Returns:
        str: The obfuscated password
    i}i�iRi#i�i�i�i�i�i�iiit(tlentlistRtordRtmintchrRVR$R%RDtencode(tpasswordtkeytkey_lent	remaindertchunk_indext	key_indextpassword_index((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pyt_kcpasswords'%	&c
C@s�dddd|g}td|�t�}td|�}tjjjd��Btjjjdtj	rod	nd
��}|j
|�WdQXWdQXt|t�r�|S|j
�|j
�kS(u�
    .. versionadded:: 2016.3.0

    Configures the machine to auto login with the specified user

    Args:

        name (str): The user account use for auto login

        password (str): The password to user for auto login

            .. versionadded:: 2017.7.3

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' user.enable_auto_login stevej
    udefaultsuwriteu0/Library/Preferences/com.apple.loginwindow.plistu
autoLoginUserucmd.runRti?u/etc/kcpassworduwuwbN(RRlR{R$R%tfilest	set_umasktfopenRtPY2twriteR)RStlower(R/RtRRQt
o_passwordtfd((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pytenable_auto_login>s		*cC@sEd}td|�ddddg}td|�t�sAtStS(u�
    .. versionadded:: 2016.3.0

    Disables auto login on the machine

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' user.disable_auto_login
    urm -f /etc/kcpassworducmd.runudefaultsudeleteu0/Library/Preferences/com.apple.loginwindow.plistu
autoLoginUser(RRlR.R(R((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pytdisable_auto_logings	(<t__doc__t
__future__RRRRtImportErrortloggingR+tsalt.ext.six.movesRRtsalt.ext.sixRtsalt.utils.argsR$tsalt.utils.datatsalt.utils.decorators.pathtsalt.utils.filestsalt.utils.stringutilstsalt.utils.usertsalt.exceptionsRRtsalt.extRt	getLoggert__name__R:RR
RRRR(R.R9RR>RERGRHRIRORRR-R"RAR%t
decoratorstpathtwhichR\RWRfRjRlR{R�R�(((s9/usr/lib/python2.7/site-packages/salt/modules/mac_user.pyt<module>
s`
			3				!	 9		
!					2	)

Zerion Mini Shell 1.0