%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@sdZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
ZddlZddl
ZddlmZddlmZddlmZyddlZeZWnek
r�eZnXyddlZeZWnek
reZnXyddlZeZWnek
rAeZnXyddlZeZWnek
rqeZnXeje �Z!d�Z"ed�dd	��Z$d
�Z%d�Z&d�Z'dd
�Z(dd�Z)d�Z*ed�Z+ded�Z,ed�Z-dd�Z.dS(uY
Functions for querying and modifying a user account and the groups to which it
belongs.
i(tabsolute_importtprint_functiontunicode_literalsN(tCommandExecutionError(tjinja_filter(tsixcC@sjtr!tjtj��j}n6trKtjj	j
rKtjj	j�}ntd��tjj
j|�S(u
    Get the current user
    u9Required external library (pwd or win32api) not installed(tHAS_PWDtpwdtgetpwuidtostgeteuidtpw_nametHAS_WIN_FUNCTIONStsalttutilst
win_functionst	HAS_WIN32tget_current_userRtstringutilst
to_unicode(tret((s3/usr/lib/python2.7/site-packages/salt/utils/user.pytget_user6s	uget_uidcC@sits
dS|dkr<ytj�SWqetk
r8dSXn)ytj|�jSWntk
rddSXdS(u�
    Get the uid for a given user name. If no user given, the current euid will
    be returned. If the user does not exist, None will be returned. On systems
    which do not support pwd or os.geteuid, None will be returned.
    N(	RtNoneR	R
tAttributeErrorRtgetpwnamtpw_uidtKeyError(tuser((s3/usr/lib/python2.7/site-packages/salt/utils/user.pytget_uidDs

c
C@sdtjfd��Y}|�}d|_d}d}tj�}tjjjtj|�d||ddddddtj|��dkr�td��nzYtj	j
�}tjjj||tj|��dkr�td	��n|jdkSWd
tjjj
|�Xd
S(u�
    Using the win32 api, determine if the user with token 'user_token' has
    administrator rights.

    See MSDN entry here:
        http://msdn.microsoft.com/en-us/library/aa376389(VS.85).aspx
    tSID_IDENTIFIER_AUTHORITYcB@sVeZdejfdejfdejfdejfdejfdejfgZRS(ubyte0ubyte1ubyte2ubyte3ubyte4ubyte5(t__name__t
__module__tctypestc_bytet_fields_(((s3/usr/lib/python2.7/site-packages/salt/utils/user.pyRasii i iiuAllocateAndInitializeSid faileduCheckTokenMembership failedN(R t	Structuretbyte5tc_void_ptwindlltadvapi32tAllocateAndInitializeSidtbyreft	ExceptiontwintypestBOOLtCheckTokenMembershiptvaluetFreeSid(t
user_tokenRtnt_authoritytSECURITY_BUILTIN_DOMAIN_RIDtDOMAIN_ALIAS_RID_ADMINStadministrators_grouptis_admin((s3/usr/lib/python2.7/site-packages/salt/utils/user.pyt_win_user_token_is_adminYs.			cC@s
td�S(us
    ctypes.windll.shell32.IsUserAnAdmin() is intentionally avoided due to this
    function being deprecated.
    i(R6(((s3/usr/lib/python2.7/site-packages/salt/utils/user.pyt_win_current_user_is_admin�scC@s�t�}tjjj�r4t�r}dj|�SnId}|dkr}x4|D])}|tjkrMdjtj|�SqMWn|S(uh
    Get a user name for publishing. If you find the user is "root" attempt to be
    more specific
    usudo_{0}u	SUDO_USERuroot(u	SUDO_USER(	RR
Rtplatformt
is_windowsR7tformatR	tenviron(Rtenv_varstevar((s3/usr/lib/python2.7/site-packages/salt/utils/user.pytget_specific_user�s		
c
C@s%tj|�}g}t�}|rkytj|�j}Wqttk
rg}tdj||���qtXn	|j	}t
|dt�}tj
dkr�td�tj|�D��}nxD|D]<}||}	|	|kr�|j|	�r�|j|	�q�q�Wtj�|kr[ytj|�Wq[tk
rW}tdjtj�||���q[Xnttj��t|�kr�ytj|�Wq�tk
r�}tdj||���q�Xntj�|jkr!ytj|j�Wq!tk
r}tdjtj�|j|���q!XndS(	um
    Change the current process to belong to the specified user (and the groups
    to which it belongs)
    u+Failed to fetch the GID for {0}. Error: {1}tinclude_defaultudarwincs@s0|]&\}}|jd�s||fVqdS(u_N(t
startswith(t.0tktv((s3/usr/lib/python2.7/site-packages/salt/utils/user.pys	<genexpr>�s	u0Failed to change from gid {0} to {1}. Error: {2}u4Failed to set supplemental groups to {0}. Error: {1}u0Failed to change from uid {0} to {1}. Error: {2}N(RRtsettgrptgetgrnamtgr_gidRRR:tpw_gidtget_group_dicttTruetsysR8tdictRt	iteritemstaddtappendR	tgetgidtsetgidtOSErrortsortedt	getgroupst	setgroupstgetuidRtsetuid(
trunastgrouptuinfot	supgroupstsupgroups_seent
target_pw_gidterrt
group_listt
group_nametgid((s3/usr/lib/python2.7/site-packages/salt/utils/user.pytchugid�sP		"

c	C@s�t}t}tj�}|r9||kr9t}|}n|}tjtjtj��j�j	}|r�||kr�t}|}n|}|s�|r�t
||�n|dk	r�tj
|�ndS(ui
    Helper method for for subprocess.Popen to initialise uid/gid and umask
    for the new process.
    N(tFalsetgetpasstgetuserRJREtgetgrgidRRRHtgr_nameRbRR	tumask(	RXRhRYt	set_runastset_grptcurrent_usert
runas_usertcurrent_grpt	runas_grp((s3/usr/lib/python2.7/site-packages/salt/utils/user.pytchugid_and_umask�s 	$	cC@s,tr(tr(tjtj|�j�jSdS(uo
    Returns the specified user's default group. If the user doesn't exist, a
    KeyError will be raised.
    N(	tHAS_GRPRRERfRRRHRgR(R((s3/usr/lib/python2.7/site-packages/salt/utils/user.pytget_default_groups(cC@s	ttksttkrgSd}t�}ttd�r�tjd|�yAgtj	|t
j|�j�D]}t
j|�j^ql}Wq�tk
r�q�XnFtr�tjd|�yttj	|��}Wq�tk
r�q�Xn|dkrxtjd|�gt
j�D]}||jkr|j^q}y,t|�}||kr`|j|�nWqxtk
rtqxXn|dk	r�|j|�n|tkr�y/t
jt
j|�j�j}|j|�Wq�tk
r�q�Xntjd|t|��t|�S(u\
    Returns a list of all of the system group names of which the user
    is a member.
    ugetgrouplistuTrying os.getgrouplist for '%s'u"Trying pysss.getgrouplist for '%s'u"Trying generic group list for '%s'uGroup list for user '%s': %sN(RpRcRRRDthasattrR	tlogttracetgetgrouplistRRRHRERfRgR*t	HAS_PYSSStlisttpyssstgetgralltgr_memRqRORtupdatetremoveRS(RR?tgroup_namestugroupstgrpidtgt
default_group((s3/usr/lib/python2.7/site-packages/salt/utils/user.pytget_group_listsH	>

1

cC@sittksttkriSi}t|d|�}x.|D]&}|jitj|�j|6�q;W|S(u�
    Returns a dict of all of the system groups as keys, and group ids
    as values, of which the user is a member.
    E.g.: {'staff': 501, 'sudo': 27}
    R?(RpRcRR�R{RERFRG(RR?t
group_dictR}RY((s3/usr/lib/python2.7/site-packages/salt/utils/user.pyRIIs
$cC@sMttksttkrgSttjt|d|���}tt|��S(uZ
    Returns a list of all of the system group IDs of which the user
    is a member.
    R?(	RpRcRRwRt
itervaluesRIRSRD(RR?tgid_list((s3/usr/lib/python2.7/site-packages/salt/utils/user.pytget_gid_listXscC@sits
dS|dkr<ytj�SWqetk
r8dSXn)ytj|�jSWntk
rddSXdS(u�
    Get the gid for a given group name. If no group given, the current egid
    will be returned. If the group does not exist, None will be returned. On
    systems which do not support grp or os.getegid it will return None.
    N(	RpRR	tgetegidRRERFRGR(RY((s3/usr/lib/python2.7/site-packages/salt/utils/user.pytget_gidgs

(/t__doc__t
__future__RRRR RdtloggingR	RKtsalt.utils.pathR
tsalt.utils.platformtsalt.utils.stringutilstsalt.exceptionsRtsalt.utils.decorators.jinjaRtsalt.extRRRJRtImportErrorRcRERpRxRvtsalt.utils.win_functionsRt	getLoggerRRsRRRR6R7R>RbRoRqR�RIR�R�(((s3/usr/lib/python2.7/site-packages/salt/utils/user.pyt<module>s\











			-		H	
;

Zerion Mini Shell 1.0