%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/useradd.pyo

�
���^c@@s8dZddlmZmZmZyddlZeZWnek
rQe	ZnXddl
Z
ddlZddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlmZddlmZe
je�ZdZd�Zd�Zd	�Zd
�Zdd�Zdddddee	dddddedde	d
�Z e	e	dd�Z!e	d�Z"d�Z#dd�Z$dd�Z%e	dd�Z&e	dd�Z'd�Z(d�Z)d�Z*d�Z+d�Z,dd�Z-d�Z.d�Z/d�Z0e
j1j2j3j4d�d��Z5d �Z6d!�Z7dd"�Z8dS(#u$
Manage users with the useradd command

.. 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_importtprint_functiontunicode_literalsN(tCommandExecutionError(tsixuusercC@s$trtddkrtStdfS(uL
    Set the user module if the kernel is Linux, OpenBSD, NetBSD or AIX
    ukerneluLinuxuOpenBSDuNetBSDuAIXuuseradd execution module not loaded: either pwd python library not available or system not one of Linux, OpenBSD, NetBSD or AIX(uLinuxuOpenBSDuNetBSDuAIX(tHAS_PWDt
__grains__t__virtualname__tFalse(((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyt__virtual__&scC@s3t|tj�st|�Stjjj|�SdS(uS
    Usernames can only contain ascii chars, so make sure we return a str type
    N(t
isinstanceRtstring_typeststrtsalttutilststringutilstto_str(tname((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyt_quote_username0s
cC@s�tjjjtjt|��j�jdd�}|s=iSx#t	|�dkrb|j
d�q@Witjjj|d�d6tjjj|d�d6tjjj|d	�d
6tjjj|d�d6tjjj|d�d
6SdS(uD
    Retrieve GECOS field info and return it in dictionary form
    u,iiuiufullnameiu
roomnumberiu	workphoneiu	homephoneuotherN(
R
RRt
to_unicodetpwdtgetpwnamRtpw_gecostsplittlentappendtdatatdecode(Rtgecos_field((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyt
_get_gecos:s'cC@s^dj|jdd�|jdd�|jdd�|jdd�|jdd��jd�S(	u�
    Accepts a dictionary entry containing GECOS field names and their values,
    and returns a full GECOS comment string, to be used with usermod.
    u{0},{1},{2},{3},{4}ufullnameuu
roomnumberu	workphoneu	homephoneuotheru,(tformattgettrstrip(t
gecos_dict((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyt_build_gecosMs
cC@s|d	krd}n9t|tj�s9tj|�}ntjjj|�}t	|�}|sdt
S|||krxtStj
|�}|||<ddt|�|g}|d	k	r�tddkr�|jd|f�ntd|dt
�t|�}t	|�j|�|kS(
u:
    Common code to change a user's GECOS information
    uuusermodu-cukerneluAIXu-Rucmd.runtpython_shellN(tNoneR
RRt	text_typeR
RRRRRtTruetcopytdeepcopyR"Rtextendt__salt__tinfoR(Rtkeytvaluetroottpre_infot
gecos_datatcmdt	post_info((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyt
_update_gecosYs$	
ucC@s�dg}|r%|jd|g�n|d"krG|jd|g�n|d#kri|jd|g�n�|d
k	r�||kr�d}tddkrSy�tjjj|��p}xf|D]^}tjjj|�}d	|d
 kr�q�nd|kr|jdt	d|�g�nPq�WWd
QXWq�t
k
rOtjd|dt
j�q�Xq�d}y|tjjj|��a}xW|D]O}tjjj|�}d|d kr�q{n|jd|j�dg�Pq{WWd
QXWq�t
k
r�q�Xn|
r|jd�n0tddkr2tddkr2|jd�n|rH|jd�n|d
k	rj|jd|g�n|r�tddkr�|jd�n|r�tddkr�tddkr�|jd�ntddkr�|d
k	r�|jd|g�q�n|j|�|d
k	r;tddkr;|jd|f�nt	d|dt�}|d d!kretS|r{t||�n|r�t||�n|	r�t||	�n|
r�t||
�n|r�t||�n|r�t||�ntS($u�
    Add a user to the minion

    CLI Example:

    .. code-block:: bash

        salt '*' user.add name <uid> <gid> <groups> <home> <shell>
    uuseraddu-suu-uu-gu/etc/login.defsukerneluOpenBSDuUSERGROUPS_ENABiuyesufile.group_to_gidNuError reading texc_info_on_loglevelu/etc/usermgmt.confugroupii����u-muNetBSDu-Mu-lu-duAIXu-ou-ru-Lu-Rucmd.run_allR#uretcodei(Nu(Nu(R)R$RR
RtfilestfopenRRR*tOSErrortlogtdebugtloggingtDEBUGRRRtchgroupst
chfullnametchroomnumbertchworkphonetchhomephonetchotherR&(Rtuidtgidtgroupsthometshelltuniquetsystemtfullnamet
roomnumbert	workphonet	homephonetothert
createhomet
loginclassR.t	nologinitR1t	defs_filetfp_tlinet
usermgmt_filetret((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pytaddus�	






cC@sdg}|r|jd�n|rUtddkrUtddkrU|jd�n|j|�|dk	r�tddkr�|jd|f�ntd|d	t�}|d
dkr�tS|d
dkrtd
dkr�tSd|dksd|dkrtjd�tSntS(u�
    Remove a user from the minion

    CLI Example:

    .. code-block:: bash

        salt '*' user.delete name remove=True force=True
    uuserdelu-rukerneluOpenBSDuAIXu-fu-Rucmd.run_allR#uretcodeiiu	os_familyuDebianuvar/mailustderruvar/spool/mailurWhile the userdel exited with code 12, this is a known bug on debian based distributions. See http://goo.gl/HH3FzTN(uDebian(	RRR$R)R*RR&R8R9(RtremovetforceR.R1RU((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.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__RtgetpwallRt_format_info(trefreshRUR((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pytgetent's

cC@s_t|�}||dkr tSdd||g}td|dt�t|�jd�|kS(u{
    Change the uid for a named user

    CLI Example:

    .. code-block:: bash

        salt '*' user.chuid foo 4376
    uuiduusermodu-uucmd.runR#(R+R&R*RR(RRBR/R1((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pytchuid;s
cC@s�t|�}||dkr tSdd||g}|d	k	rdtddkrd|jd|f�ntd|dt�t|�jd�|kS(
u�
    Change the default group of the user

    CLI Example:

    .. code-block:: bash

        salt '*' user.chgid foo 4376
    ugiduusermodu-gukerneluAIXu-Rucmd.runR#N(R+R&R$RR)R*RR(RRCR.R/R1((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pytchgidMs
cC@s�t|�}||dkr tSdd||g}|d	k	rdtddkrd|jd|f�ntd|dt�t|�jd�|kS(
u�
    Change the default shell of the user

    CLI Example:

    .. code-block:: bash

        salt '*' user.chshell foo /bin/zsh
    ushelluusermodu-sukerneluAIXu-Rucmd.runR#N(R+R&R$RR)R*RR(RRFR.R/R1((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pytchshellcs
cC@s�t|�}||dkr tSdd|g}|dk	ratddkra|jd|f�n|r�tddkr�|jd�n|j|�td	|d
t�t|�jd�|kS(u�
    Change the home directory of the user, pass True for persist to move files
    to the new home directory if the old home directory exist.

    CLI Example:

    .. code-block:: bash

        salt '*' user.chhome foo /home/users/foo True
    uhomeuusermodu-dukerneluAIXu-RuOpenBSDu-mucmd.runR#N(	R+R&R$RR)RR*RR(RREtpersistR.R/R1((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pytchhomeys
c	
C@st|tj�r$|jd�}ntt|��}|t|�krLtSdg}tddkr�|r�tddkr�|jd�n|jd�n#|r�|jd�n
|jd�|rtddkr|j	dj
|�ddj
|�|g�n|j	dj
|�|g�|dk	rRtddkrR|j	d	|f�ntd
|dt
�}tddkr�tddkr�|dd
kr�d|dkr�t}xE|D]=}dd||g}td|dt
�d
kr�t
}q�q�W|Sn|dd
kS(u�
    Change the groups to which this user belongs

    name
        User to modify

    groups
        Groups to set for the user

    append : False
        If ``True``, append the specified group(s). Otherwise, this function
        will replace the user's groups with the specified group(s).

    CLI Examples:

    .. code-block:: bash

        salt '*' user.chgroups foo wheel,root
        salt '*' user.chgroups foo wheel,root append=True
    u,uusermodukerneluOpenBSDuAIXu-au-Gu-Su-Rucmd.run_allR#uretcodeiunot found inustderrugpasswducmd.retcodeN(R
RRRtsettlist_groupsR&RRR)tjoinR$R*R(	RRDRR.tugrpsR1tresultRUtgroup((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyR<�s8	
0  

cC@st|d|�S(u�
    Change the user's Full Name

    CLI Example:

    .. code-block:: bash

        salt '*' user.chfullname foo "Foo Bar"
    ufullname(R3(RRI((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyR=�s
cC@st|d|�S(u
    Change the user's Room Number

    CLI Example:

    .. code-block:: bash

        salt '*' user.chroomnumber foo 123
    u
roomnumber(R3(RRJ((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyR>�s
cC@st|d|�S(u�
    Change the user's Work Phone

    CLI Example:

    .. code-block:: bash

        salt '*' user.chworkphone foo 7735550123
    u	workphone(R3(RRK((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyR?�s
cC@st|d|�S(u�
    Change the user's Home Phone

    CLI Example:

    .. code-block:: bash

        salt '*' user.chhomephone foo 7735551234
    u	homephone(R3(RRL((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyR@�s
cC@st|d|�S(u�
    Change the user's other GECOS attribute

    CLI Example:

    .. code-block:: bash

        salt '*' user.chother foobar
    uother(R3(RRM((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyRAs
cC@s�tddkrtS|t|�kr*tSdd||g}|dk	r^|jd|f�ntd|dt�t|�|kS(	u�
    Change the default login class of the user

    .. note::
        This function only applies to OpenBSD systems.

    CLI Example:

    .. code-block:: bash

        salt '*' user.chloginclass foo staff
    ukerneluOpenBSDuusermodu-Lu-Rucmd.runR#N(RRtget_loginclassR&R$R)R*(RROR.R1((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pytchloginclasss
cC@s<ytjt|��}Wntk
r-iSXt|�SdS(un
    Return user information

    CLI Example:

    .. code-block:: bash

        salt '*' user.info root
    N(RRRtKeyErrorR\(RR((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyR+,s


cC@s�tddkrtStdd|gdt�}xd|j�D]P}|jd�r=y|jd	d�d}PWq�ttfk
r�q=q�Xq=q=Wd}|S(
u�
    Get the login class of the user

    .. note::
        This function only applies to OpenBSD systems.

    CLI Example:

    .. code-block:: bash

        salt '*' user.get_loginclass foo
    ukerneluOpenBSDucmd.run_stdoutuuserinfoR#uclassiuN(	RRR*t
splitlinest
startswithRR$t
ValueErrort
IndexError(RtuserinfoRSRU((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyRj>s
	cC@s�tjjj|j�jdd�}x#t|�dkrI|jd�q'Wi|jd6t	|j
�d6|jd6|j
d6|jd	6|j
d
6|jd6|dd
6|dd6|dd6|dd6|dd6S(u1
    Return user information in a pretty way
    u,iiuugidugroupsuhomeunameupasswdushelluuidiufullnameiu
roomnumberiu	workphoneiu	homephoneuother(R
RRRRRRRtpw_gidRetpw_nametpw_dirt	pw_passwdtpw_shelltpw_uid(RR((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyR\\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((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyt
primary_groupts
cC@stjjj|�S(u�
    Return a list of groups the named user belongs to

    CLI Example:

    .. code-block:: bash

        salt '*' user.list_groups foo
    (R
Rtusertget_group_list(R((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyRe�s
cC@s&tgtj�D]}|j^q�S(ur
    Return a list of all users

    CLI Example:

    .. code-block:: bash

        salt '*' user.list_users
    (tsortedRR[Rs(Ry((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyt
list_users�s
cC@s�t|�}|s*tdj|���nt|�}|rTtdj|���ndd||g}|dk	r�tddkr�|jd|f�ntd|d	t�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 existsuusermodu-lukerneluAIXu-Rucmd.runR#unameN(	R+RRR$RR)R*RR(Rtnew_nameR.tcurrent_infotnew_infoR1((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pytrename�s
(9t__doc__t
__future__RRRRR&RtImportErrorRR:R'tsalt.utils.dataR
tsalt.utils.filestsalt.utils.decorators.pathtsalt.utils.stringutilstsalt.utils.usertsalt.exceptionsRtsalt.extRt	getLoggert__name__R8RR	RRR"R$R3RVRYR^R_R`RaRcR<R=R>R?R@RARkR+RjR\Rt
decoratorstpathtwhichRxReR|R�(((s8/usr/lib/python2.7/site-packages/salt/modules/useradd.pyt<module>
st


	
	
		s/	<	
	
	
	
	
			!	
	

Zerion Mini Shell 1.0