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

�
���^c@@sgdZddlmZmZmZddlZddlZddlZddlm	Z	ddl
mZybddlZddl
Z
ddlZddlZddlZddlmZmZmZeZWnek
r�eZnXd�Zd�Zd	�Zed
�Zd�Zed�Zd
�Zd�Z ed�Z!d�Z"dd�Z#d�Z$d�Z%dS(up
Various functions to be used by windows during start up and to monkey patch
missing functions in other modules
i(tabsolute_importtprint_functiontunicode_literalsN(tCommandExecutionError(trange(tHWND_BROADCASTtWM_SETTINGCHANGEtSMTO_ABORTIFHUNGcC@ststdfSdS(u4
    Only load if Win32 Libraries are installed
    uThis utility requires pywin32u
win_functions(t	HAS_WIN32tFalse(((s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pyt__virtual__s
cC@stj�j�S(u�
    This is a monkey patch for os.getppid. Used in:
    - salt.utils.parsers

    Returns:
        int: The parent process id
    (tpsutiltProcesstppid(((s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pytget_parent_pid(scC@s4t|t�}x|D]}|dkrtSqWtS(u�
    Is the passed user a member of the Administrators group

    Args:
        name (str): The name to check

    Returns:
        bool: True if user is a member of the Administrators group, False
        otherwise
    uS-1-5-32-544uS-1-5-18(uS-1-5-32-544uS-1-5-18(tget_user_groupstTrueR	(tnametgroupstgroup((s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pytis_admin3s

cC@se|dkr|g}ntjd|�}|s4|St�}x!|D]}|jt|��qDW|S(u
    Get the groups to which a user belongs

    Args:
        name (str): The user name to query
        sid (bool): True will return a list of SIDs, False will return a list of
        group names

    Returns:
        list: A list of group names or sids
    uSYSTEMN(twin32nettNetUserGetLocalGroupstNonetsettaddtget_sid_from_name(RtsidRt
ret_groupsR((s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pyRGs	
cC@sm|dkrd}nytjd|�d}Wn.tjk
r_}tdj||���nXtj|�S(u�
    This is a tool for getting a sid from a name. The name can be any object.
    Usually a user or a group

    Args:
        name (str): The name of the user or group for which to get the sid

    Returns:
        str: The corresponding SID
    uNULL SIDiuUser {0} not found: {1}N(Rt
win32securitytLookupAccountNamet
pywintypesterrorRtformattConvertSidToStringSid(RRtexc((s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pyRcs	cC@s�yztjtj�}|ddkrdtj�}|dkrFd}qyt|�dkryd}qyn|sytj�}nWn+tjk
r�}tdj|���nX|s�t	S|S(u�
    Gets the user executing the process

    Args:

        with_domain (bool):
            ``True`` will prepend the user name with the machine name or domain
            separated by a backslash

    Returns:
        str: The user name
    i����u$uSYSTEMuS-1-5-18uFailed to get current user: {0}(
twin32apit
GetUserNameExtNameSamCompatibletGetUserNameRRR RR!R	(twith_domaint	user_namet	test_userR#((s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pytget_current_user{s 
	cC@sytjd|�d}Wn4tjk
rPdjtj�d j�|g�SXtj	d|�\}}}dj||g�S(u�
    Gets the SAM name for a user. It basically prefixes a username without a
    backslash with the computer name. If the user does not exist, a SAM
    compatible name will be returned using the local hostname as the domain.

    i.e. salt.utils.get_same_name('Administrator') would return 'DOMAIN.COM\Administrator'

    .. note:: Long computer names are truncated to 15 characters
    iu\iN(
RRRRR tjointplatformtnodetuppertLookupAccountSid(tusernametsid_objtdomaint_((s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pytget_sam_name�s
$c@s,tr(d�tj�fd�d�ndS(Nic@s|�krtStS(N(RR	(tevent(tctrl_logoff_event(s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pyt<lambda>�si(RR$tSetConsoleCtrlHandler(((R7s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pytenable_ctrl_logoff_handler�s
cC@sJ|stjd|�r6d|jdd�d}n|s@|St|�S(u�
    Escape the argument for the cmd.exe shell.
    See http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx

    First we escape the quote chars to produce a argument suitable for
    CommandLineToArgvW. We don't need to do this for simple arguments.

    Args:
        arg (str): a single command line argument to escape for the cmd.exe shell

    Kwargs:
        escape (bool): True will call the escape_for_cmd_exe() function
                       which escapes the characters '()%!^"<>&|'. False
                       will not call the function and only quotes the cmd

    Returns:
        str: an escaped string suitable to be passed as a program argument to the cmd.exe shell
    u(["\s])u"u\"(tretsearchtreplacetescape_for_cmd_exe(targtescape((s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pytescape_argument�s
c@sed}tjddjd�t|�D��d�}d�|D���fd�}|j||�S(ug
    Escape an argument string to be suitable to be passed to
    cmd.exe on Windows

    This method takes an argument that is expected to already be properly
    escaped for the receiving program to be properly parsed. This argument
    will be further escaped to pass the interpolation performed by cmd.exe
    unchanged.

    Any meta-characters will be escaped, removing the ability to e.g. use
    redirects or variables.

    Args:
        arg (str): a single command line argument to escape for cmd.exe

    Returns:
        str: an escaped string suitable to be passed as a program argument to cmd.exe
    u
()%!^"<>&|u(u|cs@s|]}tj|�VqdS(N(R;R@(t.0tchar((s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pys	<genexpr>�su)cS@s"i|]}dj|�|�qS(u^{0}(R!(RBRC((s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pys
<dictcomp>�s	c@s|jd�}�|S(Ni(R(tmRC(tmeta_map(s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pytescape_meta_chars�s(R;tcompileR,tlisttsub(R?t
meta_charstmeta_reRF((REs</usr/lib/python2.7/site-packages/salt/utils/win_functions.pyR>�s
0uEnvironmentcC@sOtj|�}tjddt�}|jttd|tdd�}|dkS(u
    Send a WM_SETTINGCHANGE Broadcast to all Windows

    Args:

        message (str):
            A string value representing the portion of the system that has been
            updated and needs to be refreshed. Default is ``Environment``. These
            are some common values:

            - "Environment" : to effect a change in the environment variables
            - "intl" : to effect a change in locale settings
            - "Policy" : to effect a change in Group Policy Settings
            - a leaf node in the registry
            - the name of a section in the ``Win.ini`` file

            See lParam within msdn docs for
            `WM_SETTINGCHANGE <https://msdn.microsoft.com/en-us/library/ms725497%28VS.85%29.aspx>`_
            for more information on Broadcasting Messages.

            See GWL_WNDPROC within msdn docs for
            `SetWindowLong <https://msdn.microsoft.com/en-us/library/windows/desktop/ms633591(v=vs.85).aspx>`_
            for information on how to retrieve those messages.

    .. note::
        This will only affect new processes that aren't launched by services. To
        apply changes to the path or registry to services, the host must be
        restarted. The ``salt-minion``, if running as a service, will not see
        changes to the environment until the system is restarted. Services
        inherit their environment from ``services.exe`` which does not respond
        to messaging events. See
        `MSDN Documentation <https://support.microsoft.com/en-us/help/821761/changes-that-you-make-to-environment-variables-do-not-affect-services>`_
        for more information.

    CLI Example:

    ... code-block:: python

        import salt.utils.win_functions
        salt.utils.win_functions.broadcast_setting_change('Environment')
    uuser32tuse_last_errorii�i(tctypestcreate_unicode_buffertWinDLLRtSendMessageTimeoutWRRR(tmessagetbroadcast_messagetuser32tresult((s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pytbroadcast_setting_change�s=cC@sqtjd�}|j|�}d}|dk	rmx:tdd�D]&}||j|�ddd�7}q@Wn|S(u�
    Converts a GUID   to a compressed guid (SQUID)

    Each Guid has 5 parts separated by '-'. For the first three each one will be
    totally reversed, and for the remaining two each one will be reversed by
    every other character. Then the final compressed Guid will be constructed by
    concatenating all the reversed parts without '-'.

    .. Example::

        Input:                  2BE0FA87-5B36-43CF-95C8-C68D6673FB94
        Reversed:               78AF0EB2-63B5-FC34-598C-6CD86637BF49
        Final Compressed Guid:  78AF0EB263B5FC34598C6CD86637BF49

    Args:

        guid (str): A valid GUID

    Returns:
        str: A valid compressed GUID (SQUID)
    uO^\{(\w{8})-(\w{4})-(\w{4})-(\w\w)(\w\w)-(\w\w)(\w\w)(\w\w)(\w\w)(\w\w)(\w\w)\}$uiiNi����(R;RGtmatchRRR(tguidtguid_patternt
guid_matchtsquidtindex((s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pyt
guid_to_squid7s'cC@stjd�}|j|�}d}|dk	rd|jd�ddd�d|jd�ddd�d|jd	�ddd�d|jd
�ddd�|jd�ddd�d}x7tdd
�D]&}||j|�ddd�7}q�W|d7}n|S(u�
    Converts a compressed GUID (SQUID) back into a GUID

    Args:

        squid (str): A valid compressed GUID

    Returns:
        str: A valid GUID
    uG^(\w{8})(\w{4})(\w{4})(\w\w)(\w\w)(\w\w)(\w\w)(\w\w)(\w\w)(\w\w)(\w\w)$uu{iNi����u-iiiiiiu}(R;RGRVRRR(RZt
squid_patterntsquid_matchRWR[((s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pyt
squid_to_guidVs�$
(&t__doc__t
__future__RRRR-R;RMtsalt.exceptionsRtsalt.ext.six.movesRRRR$RRtwin32conRRRRRtImportErrorR	R
RRRRR+R5R:RAR>RUR\R_(((s</usr/lib/python2.7/site-packages/salt/utils/win_functions.pyt<module>s:


	
			#				E	

Zerion Mini Shell 1.0