HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/win_file.cpython-310.pyc
o

�N�g��@s�dZddlZddlZddlZddlZddlZddlZddlZddlZ	ddl
Z	ddlZ	ddlZ	ddl
mZmZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>ddlm?Z@ddlmAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTddlUmVZVdZWz"e	jXjY�Z�r�ddl[Z[ddl\Z\ddl]Z]ddl^Z^ddl_Z_ddl`Z	d	ZWWneay�dZWYnwdZbze	jXjY�Z��rddlcZ	d	ZbWnea�ydZbYnwe	jXjY�Z��r�eW�r�eVeJed��ZJeVeMed��ZMeVeed��ZeVeed��ZeVeed��ZeVeed��ZeVeed��ZeVe;ed��Z;eVeKed��ZKeVe.ed��Z.eVe1ed��Z1eVe ed��Z eVe6ed��Z6eVe&ed��Z&eVe'ed��Z'eVe$ed��Z$eVe>ed��Z>eVePed��ZPeVe2ed��Z2eVeed��ZeVe/ed��Z/eVeQed��ZQeVe*ed��Z*eVe,ed��Z,eVe+ed��Z+eVe7ed��Z7eVe3ed��Z3eVeEed��ZEeVe8ed��Z8eVe%ed��Z%eVe5ed��Z5eVe4ed��Z4eVe:ed��Z:eVeed��ZeVe-ed��Z-eVeGed��ZGeVeHed��ZHeVeFed��ZFeVeLed��ZLeVeRed��ZReVe#ed��Z#eVeDed��ZDeVeNed��ZNeVeOed��ZOeVeIed��ZIeVe=ed��Z=eVeCed��ZCeVeTed��ZTeVeAed��ZAeVe9ed��Z9eVe(ed��Z(eVeSed��ZSeVe)ed��Z)eVeed��ZeVeed��ZeVeed��ZeVeed��ZeVeed��ZeVeed��ZeVeed��ZeVe!ed��Z!eVe0ed��Z0eVe"ed��Z"eVe<ed��Z<eVe@ed��Z@eVeed��ZeVeBed��ZBe�eef�Zgd
Zhdd�Zid
d
d�Zjddd�ZkdVdd�Zldd�Zmdd�ZndWdd�ZodWdd�ZpdWdd�ZqdWdd �Zrd!d"�Zsd#d$�ZtdWd%d&�ZudWd'd(�Zvd)d*�ZwdXd+d,�ZxdYd-d.�Zyd/d0�Zzd1d2�Z{dZd4d5�Z|d6d7�Z}d8d9�Z~d[d:d;�Zd<d=�Z�d>d?�Z�d@dA�Z�							d\dBdC�Z�dDdE�Z�d]dFdG�Z�d^dHdI�Z�dJdK�Z�	d_dLdM�Z�	d_dNdO�Z�		d`dPdQ�Z�							dadRdS�Z�dbdTdU�Z�dS)cz�
Manage information about files on the minion, set/read user, group
data, modify the ACL of files/directories

:depends:   - win32api
            - win32file
            - win32con
            - salt.utils.win_dacl
�N)�CommandExecutionError�SaltInvocationError).�__clean_tmp�
_add_flags�_assert_occurrence�_binary_replace�_error�_get_bkroot�_get_eol�
_get_flags�
_mkstemp_copy�_regex_to_static�	_set_line�
_set_line_eol�_set_line_indent�'_splitlines_preserving_trailing_newline�access�append�apply_template_on_contents�basename�blockreplace�check_file_meta�
check_hash�
check_managed�check_managed_changes�comment�comment_line�contains�
contains_glob�contains_regex�copy�
delete_backup�directory_exists�dirname�extract_hash�file_exists�find�get_diff�get_hash�get_managed�get_source_sum�get_sum�join�line�list_backups�list_backups_dir�lstat�manage_file)�normpath)�pardir�patch�path_exists_glob�prepend�psed�read�readdir�readlink�rename�replace�restore_backup�rmdir�search�	seek_read�
seek_write�source_list�touch�truncate�	uncomment�write)�namespaced_functionFT�filecCs tjj��rts
dStsdStS)z'
    Only works on Windows systems
    )Fz&Module win_file: Missing Win32 modules)Fz3Module win_file: Unable to load salt.utils.win_dacl)�salt�utils�platform�
is_windows�HAS_WINDOWS_MODULES�HAS_WIN_DACL�__virtualname__�rPrP�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/win_file.py�__virtual__�s
rR�txt)rCr�makedirsr2)�	makedirs_�	normpath_�@cCsnt��jdkrtd��|h}d}t|�r5t|�}||vr td��|�|�|d7}||kr1td��t|�s|S)z�
    Resolves the given symlink path to its real path, up to a maximum of the
    `max_depth` parameter which defaults to 64.

    If the path is not a symlink path, it is simply returned.
    ��6Symlinks are only supported on Windows Vista or later.rz-The given path is involved in a symlink loop.�z"Too many levels of symbolic links.)�sys�getwindowsversion�majorr�is_linkr:r�add)�pathZ	max_depthZ
paths_seenZ	cur_depthrPrPrQ�_resolve_symlink�s �
�	racCs.t�d�}t�dd�|krt�d|�t|�S)a�
    Convert the group id to the group name on this system

    Under Windows, because groups are just another ACL entity, this function
    behaves the same as uid_to_user.

    For maintaining Windows systems, this function is superfluous and only
    exists for API compatibility with Unix. Use the uid_to_user function
    instead; an info level log entry will be generated if this function is used
    directly.

    Args:
        gid (str): The gid of the group

    Returns:
        str: The name of the group

    CLI Example:

    .. code-block:: bash

        salt '*' file.gid_to_group S-1-5-21-626487655-2533044672-482107328-1010
    z
.gid_to_group�fun��UThe function %s should not be used on Windows systems; see function docs for details.)rO�__opts__�get�log�info�uid_to_user)�gid�	func_namerPrPrQ�gid_to_group�s
�rlcCs@t�d�}t�dd�|krt�d|�|durdStjj�|�S)a�
    Convert the group to the gid on this system

    Under Windows, because groups are just another ACL entity, this function
    behaves the same as user_to_uid, except if None is given, '' is returned.

    For maintaining Windows systems, this function is superfluous and only
    exists for API compatibility with Unix. Use the user_to_uid function
    instead; an info level log entry will be generated if this function is used
    directly.

    Args:
        group (str): The name of the group

    Returns:
        str: The gid of the group

    CLI Example:

    .. code-block:: bash

        salt '*' file.group_to_gid administrators
    z
.group_to_gidrbrcrdN)	rOrerfrgrhrIrJ�win_dacl�get_sid_string)�grouprkrPrPrQ�group_to_gids
�rpcC�Ptj�|�s
td|����|rt��jdkrt|�}tj	j
�|�}tj	j
�|�S)a)
    Return the id of the primary group that owns a given file (Windows only)

    This function will return the rarely used primary group of a file. This
    generally has no bearing on permissions unless intentionally configured
    and is most commonly used to provide Unix compatibility (e.g. Services
    For Unix, NFS services).

    Ensure you know what you are doing before using this function.

    Args:
        path (str): The path to the file or directory

        follow_symlinks (bool):
            If the object specified by ``path`` is a symlink, get attributes of
            the linked file instead of the symlink itself. Default is True

    Returns:
        str: The gid of the primary group

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_pgid c:\temp\test.txt
    �Path not found: rX)
�osr`�existsrr[r\r]rarIrJrmZget_primary_grouprn)r`�follow_symlinksZ
group_namerPrPrQ�get_pgidDsrvcCstt||��S)ac
    Return the name of the primary group that owns a given file (Windows only)

    This function will return the rarely used primary group of a file. This
    generally has no bearing on permissions unless intentionally configured
    and is most commonly used to provide Unix compatibility (e.g. Services
    For Unix, NFS services).

    Ensure you know what you are doing before using this function.

    The return value may be 'None', e.g. if the user is not on a domain. This is
    a valid group - do not confuse this with the Salt/Python value of None which
    means no value was returned. To be certain, use the `get_pgid` function
    which will return the SID, including for the system 'None' group.

    Args:
        path (str): The path to the file or directory

        follow_symlinks (bool):
            If the object specified by ``path`` is a symlink, get attributes of
            the linked file instead of the symlink itself. Default is True

    Returns:
        str: The name of the primary group

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_pgroup c:\temp\test.txt
    )rirv�r`rurPrPrQ�
get_pgroupns rxcC�0t�d�}t�dd�|krt�d|�t||�S)as
    Return the id of the group that owns a given file

    Under Windows, this will return the uid of the file.

    While a file in Windows does have a 'primary group', this rarely used
    attribute generally has no bearing on permissions unless intentionally
    configured and is only used to support Unix compatibility features (e.g.
    Services For Unix, NFS services).

    Salt, therefore, remaps this function to provide functionality that
    somewhat resembles Unix behavior for API compatibility reasons. When
    managing Windows systems, this function is superfluous and will generate
    an info level log entry if used directly.

    If you do actually want to access the 'primary group' of a file, use
    `file.get_pgid`.

    Args:
        path (str): The path to the file or directory

        follow_symlinks (bool):
            If the object specified by ``path`` is a symlink, get attributes of
            the linked file instead of the symlink itself. Default is True

    Returns:
        str: The gid of the owner

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_gid c:\temp\test.txt
    z.get_gidrbrcztThe function %s should not be used on Windows systems; see function docs for details. The value returned is the uid.)rOrerfrgrh�get_uid�r`rurkrPrPrQ�get_gid��
#�
r|cCry)aw
    Return the group that owns a given file

    Under Windows, this will return the user (owner) of the file.

    While a file in Windows does have a 'primary group', this rarely used
    attribute generally has no bearing on permissions unless intentionally
    configured and is only used to support Unix compatibility features (e.g.
    Services For Unix, NFS services).

    Salt, therefore, remaps this function to provide functionality that
    somewhat resembles Unix behavior for API compatibility reasons. When
    managing Windows systems, this function is superfluous and will generate
    an info level log entry if used directly.

    If you do actually want to access the 'primary group' of a file, use
    `file.get_pgroup`.

    Args:
        path (str): The path to the file or directory

        follow_symlinks (bool):
            If the object specified by ``path`` is a symlink, get attributes of
            the linked file instead of the symlink itself. Default is True

    Returns:
        str: The name of the owner

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_group c:\temp\test.txt
    z
.get_grouprbrcz}The function %s should not be used on Windows systems; see function docs for details. The value returned is the user (owner).)rOrerfrgrh�get_userr{rPrPrQ�	get_group�r}rcCs"|dus|dkr
dStjj�|�S)a`
    Convert a User ID (uid) to a username

    Args:
        uid (str): The user id to lookup

    Returns:
        str: The name of the user. The ``uid`` will be returned if there is no
             corresponding username

    CLI Example:

    .. code-block:: bash

        salt '*' file.uid_to_user S-1-5-21-626487655-2533044672-482107328-1010
    Nrc)rIrJrm�get_name)�uidrPrPrQri�sricCs"|dur
tjj��}tjj�|�S)z�
    Convert user name to a uid

    Args:
        user (str): The user to lookup

    Returns:
        str: The user id of the user

    CLI Example:

    .. code-block:: bash

        salt '*' file.user_to_uid myusername
    N)rIrJ�userr~rmrn)r�rPrPrQ�user_to_uidsr�cCrq)a�
    Return the id of the user that owns a given file

    Symlinks are followed by default to mimic Unix behavior. Specify
    `follow_symlinks=False` to turn off this behavior.

    Args:
        path (str): The path to the file or directory

        follow_symlinks (bool):
            If the object specified by ``path`` is a symlink, get attributes of
            the linked file instead of the symlink itself. Default is True

    Returns:
        str: The uid of the owner

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_uid c:\temp\test.txt
        salt '*' file.get_uid c:\temp\test.txt follow_symlinks=False
    rrrX)
rsr`rtrr[r\r]rarIrJrm�	get_ownerrn)r`ruZ	owner_sidrPrPrQrzsrzcCsBtj�|�s
td|����|rt��jdkrt|�}tj	j
�|�S)a~
    Return the user that owns a given file

    Symlinks are followed by default to mimic Unix behavior. Specify
    `follow_symlinks=False` to turn off this behavior.

    Args:
        path (str): The path to the file or directory

        follow_symlinks (bool):
            If the object specified by ``path`` is a symlink, get attributes of
            the linked file instead of the symlink itself. Default is True

    Returns:
        str: The name of the owner

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_user c:\temp\test.txt
        salt '*' file.get_user c:\temp\test.txt follow_symlinks=False
    rrrX)rsr`rtrr[r\r]rarIrJrmr�rwrPrPrQr~Cs
r~cCsDtj�|�s
td|����t�d�}t�dd�|kr t�d|�dS)a4
    Return the mode of a file

    Right now we're just returning None because Windows' doesn't have a mode
    like Linux

    Args:
        path (str): The path to the file or directory

    Returns:
        None

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_mode /etc/passwd
    rrz	.get_moderbrczxThe function %s should not be used on Windows systems; see function docs for details. The value returned is always None.N)	rsr`rtrrOrerfrgrh)r`rkrPrPrQ�get_modeis
�r�cCsN|rt�d�}t�dd�|krt�d|�t�d||�d}t||||dd�S)	a.
    Chown a file, pass the file the desired user and group without following any
    symlinks.

    Under Windows, the group parameter will be ignored.

    This is because while files in Windows do have a 'primary group'
    property, this is rarely used.  It generally has no bearing on
    permissions unless intentionally configured and is most commonly used to
    provide Unix compatibility (e.g. Services For Unix, NFS services).

    If you do want to change the 'primary group' property and understand the
    implications, pass the Windows only parameter, pgroup, instead.

    To set the primary group to 'None', it must be specified in quotes.
    Otherwise Salt will interpret it as the Python value of None and no primary
    group changes will occur. See the example below.

    Args:
        path (str): The path to the file or directory
        user (str): The name of the user to own the file
        group (str): The group (not used)
        pgroup (str): The primary group to assign

    Returns:
        bool: True if successful, otherwise error

    CLI Example:

    .. code-block:: bash

        salt '*' file.lchown c:\temp\test.txt myusername
        salt '*' file.lchown c:\temp\test.txt myusername pgroup=Administrators
        salt '*' file.lchown c:\temp\test.txt myusername "pgroup='None'"
    z.lchownrbrc�bThe group parameter has no effect when using %s on Windows systems; see function docs for details.�2win_file.py %s Ignoring the group parameter for %sNF�ru)rOrerfrgrh�debug�chown)r`r�ro�pgrouprkrPrPrQ�lchown�s$
�r�cCs�|durt�d�}t�dd�|krt�d|�t�d||�|r+t��jdkr+t	|�}t
j�|�s8t
d|����tjj�||�|rJtjj�||�d	S)
a�
    Chown a file, pass the file the desired user and group

    Under Windows, the group parameter will be ignored.

    This is because while files in Windows do have a 'primary group'
    property, this is rarely used.  It generally has no bearing on
    permissions unless intentionally configured and is most commonly used to
    provide Unix compatibility (e.g. Services For Unix, NFS services).

    If you do want to change the 'primary group' property and understand the
    implications, pass the Windows only parameter, pgroup, instead.

    Args:
        path (str): The path to the file or directory
        user (str): The name of the user to own the file
        group (str): The group (not used)
        pgroup (str): The primary group to assign
        follow_symlinks (bool):
            If the object specified by ``path`` is a symlink, get attributes of
            the linked file instead of the symlink itself. Default is True

    Returns:
        bool: True if successful, otherwise error

    CLI Example:

    .. code-block:: bash

        salt '*' file.chown c:\temp\test.txt myusername
        salt '*' file.chown c:\temp\test.txt myusername pgroup=Administrators
        salt '*' file.chown c:\temp\test.txt myusername "pgroup='None'"
    Nz.chownrbrcr�r�rXrrT)rOrerfrgrhr�r[r\r]rarsr`rtrrIrJrm�	set_owner�set_primary_group)r`r�ror�rurkrPrPrQr��s #
�r�cCstjj�||�S)a�
    Change the group of a file

    Under Windows, this will set the rarely used primary group of a file.
    This generally has no bearing on permissions unless intentionally
    configured and is most commonly used to provide Unix compatibility (e.g.
    Services For Unix, NFS services).

    Ensure you know what you are doing before using this function.

    Args:
        path (str): The path to the file or directory
        pgroup (str): The primary group to assign

    Returns:
        bool: True if successful, otherwise error

    CLI Example:

    .. code-block:: bash

        salt '*' file.chpgrp c:\temp\test.txt Administrators
        salt '*' file.chpgrp c:\temp\test.txt "'None'"
    )rIrJrmr�)r`rorPrPrQ�chpgrp�sr�cCs8t�d�}t�dd�|krt�d|�t�d||�dS)a�
    Change the group of a file

    Under Windows, this will do nothing.

    While a file in Windows does have a 'primary group', this rarely used
    attribute generally has no bearing on permissions unless intentionally
    configured and is only used to support Unix compatibility features (e.g.
    Services For Unix, NFS services).

    Salt, therefore, remaps this function to do nothing while still being
    compatible with Unix behavior. When managing Windows systems,
    this function is superfluous and will generate an info level log entry if
    used directly.

    If you do actually want to set the 'primary group' of a file, use ``file
    .chpgrp``.

    To set group permissions use ``file.set_perms``

    Args:
        path (str): The path to the file or directory
        group (str): The group (unused)

    Returns:
        None

    CLI Example:

    .. code-block:: bash

        salt '*' file.chgrp c:\temp\test.txt administrators
    z.chgrprbrcrdz#win_file.py %s Doing nothing for %sN)rOrerfrgrhr�)r`rorkrPrPrQ�chgrps
"�r��sha256cCs�tj�|�s
td|����|rt��jdkrt|�}t�|�}i}|j	|d<t
|dd�|d<|d|d<t|d�|d<|d|d	<t||�|d
<t
|d
�|d<|j|d<|j|d
<|j|d<|j|d<tjj�tt�|j���|d<|r}t||�|d<d|d<t�|j�r�d|d<t�|j�r�d|d<t�|j�r�d|d<t�|j�r�d|d<t�|j�r�d|d<t�|j�r�d|d<t� |j�r�d|d<tj�!|�|d<|S)a#
    Return a dict containing the stats about a given file

    Under Windows, `gid` will equal `uid` and `group` will equal `user`.

    While a file in Windows does have a 'primary group', this rarely used
    attribute generally has no bearing on permissions unless intentionally
    configured and is only used to support Unix compatibility features (e.g.
    Services For Unix, NFS services).

    Salt, therefore, remaps these properties to keep some kind of
    compatibility with Unix behavior. If the 'primary group' is required, it
    can be accessed in the `pgroup` and `pgid` properties.

    Args:
        path (str): The path to the file or directory
        hash_type (str): The type of hash to return
        follow_symlinks (bool):
            If the object specified by ``path`` is a symlink, get attributes of
            the linked file instead of the symlink itself. Default is True

    Returns:
        dict: A dictionary of file/directory stats

    CLI Example:

    .. code-block:: bash

        salt '*' file.stats /etc/passwd
    rrrX�inodeFr�r�rjr�roZpgidr��atime�mtime�ctime�size�mode�sumrH�type�dir�char�block�link�pipe�socket�target)"rsr`rtrr[r\r]ra�stat�st_inorzrirvrl�st_atime�st_mtime�st_ctime�st_sizerIrJ�filesZnormalize_mode�oct�S_IMODE�st_moder+�S_ISDIR�S_ISCHR�S_ISBLK�S_ISREG�S_ISLNK�S_ISFIFO�S_ISSOCK�realpath)r`Z	hash_typeruZpstat�retrPrPrQ�statsAsJ!





r�c	CsBg}ddddddddd	�}|D]}||@|kr|�||�q|S)
z�
    Helper function to parse the OS data

    Args:
        flags: The flags as returned by the GetFileVersionInfo function

    Returns:
        list: A list of Operating system properties found in the flag
    z16-bit Windowsz16-bit Presentation Managerz32-bit Presentation Managerz32-bit WindowszMS-DOSz16-bit OS/2z32-bit OS/2z
Windows NT)rZ���iiii)r)�flagsZfile_osZ
file_os_flags�itemrPrPrQ�_get_version_os�s
�
�r�cCs�d}ddddddd�}dd	d
ddd
dddddd�}dddd�}||vr'||}|dkr6||vr6||�d�}|dkrE||vrE||�d�}|dkrNd|��}|S)NZApplicationZDLLZDriverZFontzVirtual DevicezStatic Link Library)rZr�r�r���ZPrinterZKeyboardZLanguageZDisplayZMouseZNetwork�SystemZInstallableZSoundZCommunicationszVersioned Printer)rZr�r�r�r�rXr���	�
�ZRasterZVectorZTrueType)rZr�r�z Driverz FontzVirtual Device: rP)Z	file_typeZfile_subtypeZret_typeZ
file_typesZdriver_subtypesZ
font_subtypesrPrPrQ�_get_version_type�sF�	��
r�c	Csp|szt�|d�}Wntjyt�d|�YdSwd�t�|d�t�|d�t�|d�t�|d��S)a0
    Get's the version of the file passed in path, or the fixed_info object if
    passed.

    Args:

        path (str): The path to the file

        fixed_info (obj): The fixed info object returned by the
            GetFileVersionInfo function

    Returns:
        str: The version of the file
    �\�No version info found: %srcz{}.{}.{}.{}Z
FileVersionMSZ
FileVersionLS)	�win32api�GetFileVersionInfo�
pywintypes�errorrgr��formatZHIWORDZLOWORD)r`�
fixed_inforPrPrQ�_get_version�s��r�cCs<tj�|�s
td|����tj�|�rtd|����t|�S)a�
    .. versionadded:: 3005

    Get the version of a file.

    .. note::
        Not all files have version information. The following are common file
        types that contain version information:

            - .exe
            - .dll
            - .sys

    Args:
        path (str): The path to the file.

    Returns:
        str: The version of the file if the file contains it. Otherwise, an
            empty string will be returned.

    Raises:
        CommandExecutionError: If the file does not exist
        CommandExecutionError: If the path is not a file

    CLI Example:

    .. code-block:: bash

        salt * file.version C:\Windows\notepad.exe
    �File not found: �Not a file: )rsr`rtr�isdirr�)r`rPrPrQ�version�s
 r�c	Cs(tj�|�s
td|����tj�|�rtd|����i}zt�|d�}Wntjy6t	�
d|�|YSwt||�|d<t|d�|d<t
|d|d	�|d<zt�|d
�d\}}Wntjyot	�
d|�|YSwd
}|D]}d�|||�}z
t�||�||<Wqttjy�Yqtw|S)a
    .. versionadded:: 3005

    Get file details for a file. Similar to what's in the details tab on the
    file properties.

    .. note::
        Not all files have version information. The following are common file
        types that contain version information:

            - .exe
            - .dll
            - .sys

    Args:
        path (str): The path to the file.

    Returns:
        dict: A dictionary containing details about the file related to version.
            An empty dictionary if the file contains no version information.

    Raises:
        CommandExecutionError: If the file does not exist
        CommandExecutionError: If the path is not a file

    CLI Example:

    .. code-block:: bash

        salt * file.version_details C:\Windows\notepad.exe
    r�r�r�r�ZVersionZFileOSZOperatingSystem�FileTypeZFileSubtypez\VarFileInfo\Translationrz"No extended version info found: %s)ZCommentsZCompanyNameZFileDescriptionZFileVersionZInternalNameZLegalCopyrightZLegalTrademarksZOriginalFilenameZPrivateBuildZProductName�ProductVersionZSpecialBuildz\StringFileInfo\{:04X}{:04X}\{})rsr`rtrr�r�r�r�r�rgr�r�r�r�r�)r`r�r��languageZcodepageZproperty_namesZ	prop_nameZ
str_info_pathrPrPrQ�version_detailssJ!�������r�cCsltj�|�s
td|����i}t�|�}|d@dk|d<|d@dk|d<|d@dk|d<|d@dk|d	<|d
@d
k|d<|d@dk|d
<|d@dk|d<|d@dk|d<|d@dk|d<|d@dk|d<|d@dk|d<|d@dk|d<d|d<|ddur�|d	dur�t�|�}t|�}|ddkr�d|d<d|d<|ddur�t�|�}t|�}|dd kr�d|d<|S)!a2
    Return a dictionary object with the Windows
    file attributes for a file.

    Args:
        path (str): The path to the file or directory

    Returns:
        dict: A dictionary of file attributes

    CLI Example:

    .. code-block:: bash

        salt '*' file.get_attributes c:\temp\a.txt
    rr� �archiveiZreparsePointi�
compressed��	directoryi@Z	encryptedr��hidden��normal� �
notIndexediZofflinerZ�readonlyr��system��	temporaryFZ
mountedVolumeTrXl@ZsymbolicLinkl@)rsr`rtr�	win32file�GetFileAttributesZFindFilesIterator�next)r`Z
attributes�
intAttributesZfileIteratorZ
findDataTuplerPrPrQ�get_attributesys:


r�c
Cs4tj�|�s
td|����|r-|s|s|s|s|s|rtd��t�|d�}|dur+dSdSt�|�}	|durA|r=|	dO}	n|	dM}	|durP|rL|	d	O}	n|	d
M}	|dur_|r[|	dO}	n|	dM}	|durn|rj|	d
O}	n|	dM}	|dur}|ry|	dO}	n|	dM}	|dur�|r�|	dO}	n|	dM}	t�||	�}|dur�dSdS)a�
    Set file attributes for a file.  Note that the normal attribute
    means that all others are false.  So setting it will clear all others.

    Args:
        path (str): The path to the file or directory
        archive (bool): Sets the archive attribute. Default is None
        hidden (bool): Sets the hidden attribute. Default is None
        normal (bool):
            Resets the file attributes. Cannot be used in conjunction with any
            other attribute. Default is None
        notIndexed (bool): Sets the indexed attribute. Default is None
        readonly (bool): Sets the readonly attribute. Default is None
        system (bool): Sets the system attribute. Default is None
        temporary (bool): Sets the temporary attribute. Default is None

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' file.set_attributes c:\temp\a.txt normal=True
        salt '*' file.set_attributes c:\temp\a.txt readonly=True hidden=True
    rrz:Normal attribute may not be used with any other attributesr�NTFr�i�r�i��r�i��rZi��r�i��r�i��)rsr`rtrr��SetFileAttributesr�)
r`r�r�r�r�r�r�r�r�r�rPrPrQ�set_attributes�sH$�






r�cCs.t�d�}t�dd�|krt�d|�t|�S)aP
    Set the mode of a file

    This just calls get_mode, which returns None because we don't use mode on
    Windows

    Args:
        path: The path to the file or directory
        mode: The mode (not used)

    Returns:
        None

    CLI Example:

    .. code-block:: bash

        salt '*' file.set_mode /etc/passwd 0644
    z	.set_moderbrcz�The function %s should not be used on Windows systems; see function docs for details. The value returned is always None. Use set_perms instead.)rOrerfrgrhr�)r`r�rkrPrPrQ�set_modes
�r�c
Cs&tj�|�}tj�|�std|����tj�|�s$t|�s$td|����|r2t�	|�}t�
|tj�zBtj�
|�rAt�|�WdSt|�rMt�|�WdStj�|�}tj�|�}t�|�D]}|�d|��}t||�q^t�|�WdSty�}z|r�t�
||�td|�d|����d}~ww)aX
    Remove the named file or directory

    Args:
        path (str): The path to the file or directory to remove.
        force (bool): Remove even if marked Read-Only. Default is False

    Returns:
        bool: True if successful, False if unsuccessful

    CLI Example:

    .. code-block:: bash

        salt '*' file.remove C:\Temp
    zFile path must be absolute: rrr�zCould not remove 'z': NT)rsr`�
expanduser�isabsrrtr^rr�r�r��win32con�FILE_ATTRIBUTE_NORMAL�isfile�remover>r��listdir�OSError)r`�forceZfile_attributes�is_dirrt�namer��excrPrPrQr�.s8
�����r�c
CsDt��jdkrtd��tj�|�std|����tj�|�rRztj�t	j
j�|��tj�|�kr:t�
d||�WdSWn	tyDYnw|sR|sRd|��}t|��tj�|�re|se|sed|��}t|��tj�|�}tj�|�}tj�|�}tjtjB}t�t��|�}t	jj�|�tj�|�s�tj�|�r�|r�|s�t�|�nV|r�tj�|�}d}	|	d	kr�tj|d
�}
zt� |
|t!|��Wntj"y�|	d7}	Ynw|	d	ks�zt�#|
|tj$tj%B�WdStj"y�t�&|
�td|�d
���wzt� ||t!|��WdStj"�y!}ztd|�d|j'�d|j(����d}~ww)a�
    Create a symbolic link to a file

    This is only supported with Windows Vista or later and must be executed by
    a user with the SeCreateSymbolicLink privilege.

    The behavior of this function matches the Unix equivalent, with one
    exception - invalid symlinks cannot be created. The source path must exist.
    If it doesn't, an error will be raised.

    Args:

        src (str): The path to a file or directory

        link (str): The path to the link. Must be an absolute path

        force (bool):
            Overwrite an existing symlink with the same name
            .. versionadded:: 3005

        atomic (bool):
            Use atomic file operations to create the symlink
            .. versionadded:: 3006.0

    Returns:

        bool: ``True`` if successful, otherwise raises ``CommandExecutionError``

    CLI Example:

    .. code-block:: bash

        salt '*' file.symlink /path/to/file /path/to/link
    rXrYzLink path must be absolute: z'link already in correct state: %s -> %sTzFound existing symlink: z Existing path is not a symlink: rr�)r�rZzCould not create '�'z' - [z] N))r[r\r]rrsr`r��islinkr2rIrJr:rgr�r�rrtr��
win32securityZTOKEN_QUERYZTOKEN_ADJUST_PRIVILEGESZOpenProcessTokenr�ZGetCurrentProcessrK�winZ
elevate_token�unlinkr#�tempfileZmktempr�ZCreateSymbolicLink�intr�Z
MoveFileExZMOVEFILE_REPLACE_EXISTINGZMOVEFILE_WRITE_THROUGHr��winerror�strerror)�srcr�r�Zatomic�msgr�Zdesired_access�thZlink_dirZretryZ	temp_linkr�rPrPrQ�symlinkns~%����

 ��
�
����rc
CsHt��jdkrtd��ztjj�|�WSty#}zt	|��d}~ww)a�
    Check if the path is a symlink

    This is only supported on Windows Vista or later.

    Inline with Unix behavior, this function will raise an error if the path
    is not a symlink, however, the error raised will be a SaltInvocationError,
    not an OSError.

    Args:
        path (str): The path to a file or directory

    Returns:
        bool: True if path is a symlink, otherwise False

    CLI Example:

    .. code-block:: bash

       salt '*' file.is_link /path/to/link
    rXrYN)
r[r\r]rrIrJr`r��	Exceptionr)r`r�rPrPrQr^�s���r^c
Cs�tj�|�d}tj�|�std|�d���tj�|�}tj�|�}tj�|�sYz t�|�|r9tj	j
j||d�tj	j
j|d||||d�WdSt
yX}zt|��d}~wwdS)	a�	
    Ensure that the directory is available and permissions are set.

    Args:

        path (str):
            The full path to the directory.

        owner (str):
            The owner of the directory. If not passed, it will be the account
            that created the directory, likely SYSTEM

        grant_perms (dict):
            A dictionary containing the user/group and the basic permissions to
            grant, ie: ``{'user': {'perms': 'basic_permission'}}``. You can also
            set the ``applies_to`` setting here. The default is
            ``this_folder_subfolders_files``. Specify another ``applies_to``
            setting like this:

            .. code-block:: yaml

                {'user': {'perms': 'full_control', 'applies_to': 'this_folder'}}

            To set advanced permissions use a list for the ``perms`` parameter,
            ie:

            .. code-block:: yaml

                {'user': {'perms': ['read_attributes', 'read_ea'], 'applies_to': 'this_folder'}}

        deny_perms (dict):
            A dictionary containing the user/group and permissions to deny along
            with the ``applies_to`` setting. Use the same format used for the
            ``grant_perms`` parameter. Remember, deny permissions supersede
            grant permissions.

        inheritance (bool):
            If True the object will inherit permissions from the parent, if
            ``False``, inheritance will be disabled. Inheritance setting will
            not apply to parent directories if they must be created.

        reset (bool):
            If ``True`` the existing DACL will be cleared and replaced with the
            settings defined in this function. If ``False``, new entries will be
            appended to the existing DACL. Default is ``False``.

            .. versionadded:: 2018.3.0

    Returns:
        bool: True if successful

    Raises:
        CommandExecutionError: If unsuccessful

    CLI Example:

    .. code-block:: bash

        # To grant the 'Users' group 'read & execute' permissions.
        salt '*' file.mkdir C:\Temp\ Administrators "{'Users': {'perms': 'read_execute'}}"

        # Locally using salt call
        salt-call file.mkdir C:\Temp\ Administrators "{'Users': {'perms': 'read_execute', 'applies_to': 'this_folder_only'}}"

        # Specify advanced attributes with a list
        salt '*' file.mkdir C:\Temp\ Administrators "{'jsnuffy': {'perms': ['read_attributes', 'read_ea'], 'applies_to': 'this_folder_only'}}"
    rzDrive z is not mapped)�obj_nameZ	principalrH�r�obj_type�grant_perms�
deny_perms�inheritance�resetNT)rsr`�
splitdriver�rr��
expandvars�mkdirrIrJrmr��	set_permsr�)r`�ownerrrr	r
�driver�rPrPrQr
�s0G
����r
c	Cs�tj�|�}tj�tj�|��}tj�|�r#d|�d�}t�|�|Stj�|�r6d|�d�}t�|�|Sg}	tj�|�r@n|�	|�|}	tj�|�}|	|krXt
d�|���q9|��|D]}
t�d|
�t
|
|||||d�q_dS)	aw
    Ensure that the parent directory containing this path is available.

    Args:

        path (str):
            The full path to the directory.

            .. note::

                The path must end with a trailing slash otherwise the
                directory(s) will be created up to the parent directory. For
                example if path is ``C:\temp\test``, then it would be treated
                as ``C:\temp\`` but if the path ends with a trailing slash
                like ``C:\temp\test\``, then it would be treated as
                ``C:\temp\test\``.

        owner (str):
            The owner of the directory. If not passed, it will be the account
            that created the directory, likely SYSTEM.

        grant_perms (dict):
            A dictionary containing the user/group and the basic permissions to
            grant, ie: ``{'user': {'perms': 'basic_permission'}}``. You can also
            set the ``applies_to`` setting here. The default is
            ``this_folder_subfolders_files``. Specify another ``applies_to``
            setting like this:

            .. code-block:: yaml

                {'user': {'perms': 'full_control', 'applies_to': 'this_folder'}}

            To set advanced permissions use a list for the ``perms`` parameter, ie:

            .. code-block:: yaml

                {'user': {'perms': ['read_attributes', 'read_ea'], 'applies_to': 'this_folder'}}

        deny_perms (dict):
            A dictionary containing the user/group and permissions to deny along
            with the ``applies_to`` setting. Use the same format used for the
            ``grant_perms`` parameter. Remember, deny permissions supersede
            grant permissions.

        inheritance (bool):
            If True the object will inherit permissions from the parent, if
            False, inheritance will be disabled. Inheritance setting will not
            apply to parent directories if they must be created.

        reset (bool):
            If ``True`` the existing DACL will be cleared and replaced with the
            settings defined in this function. If ``False``, new entries will be
            appended to the existing DACL. Default is ``False``.

            .. versionadded:: 2018.3.0

    Returns:
        bool: True if successful

    Raises:
        CommandExecutionError: If unsuccessful

    CLI Example:

    .. code-block:: bash

        # To grant the 'Users' group 'read & execute' permissions.
        salt '*' file.makedirs C:\Temp\ Administrators "{'Users': {'perms': 'read_execute'}}"

        # Locally using salt call
        salt-call file.makedirs C:\Temp\ Administrators "{'Users': {'perms': 'read_execute', 'applies_to': 'this_folder_only'}}"

        # Specify advanced attributes with a list
        salt '*' file.makedirs C:\Temp\ Administrators "{'jsnuffy': {'perms': ['read_attributes', 'read_ea'], 'applies_to': 'this_folder_only'}}"
    zDirectory 'z' already existsz
The path 'z'' already exists and is not a directoryTz_Recursive creation for path '{}' would result in an infinite loop. Please use an absolute path.zCreating directory: %s�r`rrrr	r
)rsr`r�r2r#r�rgr�rtrrr��reverser
)r`rrrr	r
r#rZdirectories_to_createZcurrent_dirnameZdirectory_to_createrPrPrQrUasFN


���	rUc	
Cs�tj�|�}tj�|�}tj�|�\}}|stj�|�\}}|rU|rUtj�|�sUzt||||ddd�WntyM}z
|jtj	krC�WYd}~nd}~ww|tj
krUiSt||||||d�dS)a�	
    Set owner and permissions for each directory created.

    Args:

        path (str):
            The full path to the directory.

        owner (str):
            The owner of the directory. If not passed, it will be the account
            that created the directory, likely SYSTEM.

        grant_perms (dict):
            A dictionary containing the user/group and the basic permissions to
            grant, ie: ``{'user': {'perms': 'basic_permission'}}``. You can also
            set the ``applies_to`` setting here. The default is
            ``this_folder_subfolders_files``. Specify another ``applies_to``
            setting like this:

            .. code-block:: yaml

                {'user': {'perms': 'full_control', 'applies_to': 'this_folder'}}

            To set advanced permissions use a list for the ``perms`` parameter, ie:

            .. code-block:: yaml

                {'user': {'perms': ['read_attributes', 'read_ea'], 'applies_to': 'this_folder'}}

        deny_perms (dict):
            A dictionary containing the user/group and permissions to deny along
            with the ``applies_to`` setting. Use the same format used for the
            ``grant_perms`` parameter. Remember, deny permissions supersede
            grant permissions.

        inheritance (bool):
            If ``True`` the object will inherit permissions from the parent, if
            ``False``, inheritance will be disabled. Inheritance setting will
            not apply to parent directories if they must be created

        reset (bool):
            If ``True`` the existing DACL will be cleared and replaced with the
            settings defined in this function. If ``False``, new entries will be
            appended to the existing DACL. Default is ``False``.

            .. versionadded:: 2018.3.0

    Returns:
        bool: True if successful, otherwise raises an error

    CLI Example:

    .. code-block:: bash

        # To grant the 'Users' group 'read & execute' permissions.
        salt '*' file.makedirs_perms C:\Temp\ Administrators "{'Users': {'perms': 'read_execute'}}"

        # Locally using salt call
        salt-call file.makedirs_perms C:\Temp\ Administrators "{'Users': {'perms': 'read_execute', 'applies_to': 'this_folder_only'}}"

        # Specify advanced attributes with a list
        salt '*' file.makedirs_perms C:\Temp\ Administrators "{'jsnuffy': {'perms': ['read_attributes', 'read_ea'], 'applies_to': 'this_folder_files'}}"
    TFrN)rsr`r�r�splitrt�makedirs_permsr��errnoZEEXIST�curdirr
)	r`rrrr	r
�head�tailr�rPrPrQr�s@C
����
�	rcCsJtj�|�s
td|����tj�|�}tjjj|d||||||t	dd�	S)a}
    Check owner and permissions for the passed directory. This function checks
    the permissions and sets them, returning the changes made. Used by the file
    state to populate the return dict

    Args:

        path (str):
            The full path to the directory.

        ret (dict):
            A dictionary to append changes to and return. If not passed, will
            create a new dictionary to return.

        owner (str):
            The owner to set for the directory.

        grant_perms (dict):
            A dictionary containing the user/group and the basic permissions to
            check/grant, ie: ``{'user': {'perms': 'basic_permission'}}``.
            Default is ``None``.

        deny_perms (dict):
            A dictionary containing the user/group and permissions to
            check/deny. Default is ``None``.

        inheritance (bool):
            ``True will check if inheritance is enabled and enable it. ``False``
            will check if inheritance is disabled and disable it. Default is
            ``True``.

        reset (bool):
            ``True`` will show what permissions will be removed by resetting the
            DACL. ``False`` will do nothing. Default is ``False``.

    Returns:
        dict: A dictionary of changes that have been made

    CLI Example:

    .. code-block:: bash

        # To see changes to ``C:\Temp`` if the 'Users' group is given 'read & execute' permissions.
        salt '*' file.check_perms C:\Temp\ {} Administrators "{'Users': {'perms': 'read_execute'}}"

        # Locally using salt call
        salt-call file.check_perms C:\Temp\ {} Administrators "{'Users': {'perms': 'read_execute', 'applies_to': 'this_folder_only'}}"

        # Specify advanced attributes with a list
        salt '*' file.check_perms C:\Temp\ {} Administrators "{'jsnuffy': {'perms': ['read_attributes', 'read_ea'], 'applies_to': 'files_only'}}"
    rrrH�test)	rrr�rrrr	r
Z	test_mode)
rsr`rtrr�rIrJrm�check_permsre)r`r�rrrr	r
rPrPrQrPs<�rcCstjjj|d||||d�S)a�

    Set permissions for the given path

    Args:

        path (str):
            The full path to the directory.

        grant_perms (dict):
            A dictionary containing the user/group and the basic permissions to
            grant, ie: ``{'user': {'perms': 'basic_permission'}}``. You can also
            set the ``applies_to`` setting here for directories. The default for
            ``applies_to`` is ``this_folder_subfolders_files``. Specify another
            ``applies_to`` setting like this:

            .. code-block:: yaml

                {'user': {'perms': 'full_control', 'applies_to': 'this_folder'}}

            To set advanced permissions use a list for the ``perms`` parameter,
            ie:

            .. code-block:: yaml

                {'user': {'perms': ['read_attributes', 'read_ea'], 'applies_to': 'this_folder'}}

            To see a list of available attributes and applies to settings see
            the documentation for salt.utils.win_dacl.

            A value of ``None`` will make no changes to the ``grant`` portion of
            the DACL. Default is ``None``.

        deny_perms (dict):
            A dictionary containing the user/group and permissions to deny along
            with the ``applies_to`` setting. Use the same format used for the
            ``grant_perms`` parameter. Remember, deny permissions supersede
            grant permissions.

            A value of ``None`` will make no changes to the ``deny`` portion of
            the DACL. Default is ``None``.

        inheritance (bool):
            If ``True`` the object will inherit permissions from the parent, if
            ``False``, inheritance will be disabled. Inheritance setting will
            not apply to parent directories if they must be created. Default is
            ``False``.

        reset (bool):
            If ``True`` the existing DCL will be cleared and replaced with the
            settings defined in this function. If ``False``, new entries will be
            appended to the existing DACL. Default is ``False``.

            .. versionadded:: 2018.3.0

    Returns:
        bool: True if successful

    Raises:
        CommandExecutionError: If unsuccessful

    CLI Example:

    .. code-block:: bash

        # To grant the 'Users' group 'read & execute' permissions.
        salt '*' file.set_perms C:\Temp\ "{'Users': {'perms': 'read_execute'}}"

        # Locally using salt call
        salt-call file.set_perms C:\Temp\ "{'Users': {'perms': 'read_execute', 'applies_to': 'this_folder_only'}}"

        # Specify advanced attributes with a list
        salt '*' file.set_perms C:\Temp\ "{'jsnuffy': {'perms': ['read_attributes', 'read_ea'], 'applies_to': 'this_folder_only'}}"
    rHr)rIrJrmr)r`rrr	r
rPrPrQr�sJ�r)rW)T)NN)NNT)r�T)N)NNNNNNN)F)FF)NNNTF)NNNTT)NNNNTF)NNTF)��__doc__r�loggingrsZos.pathr�r[r�Zsalt.utils.filesrIZsalt.utils.pathZsalt.utils.platformZsalt.utils.userZsalt.exceptionsrrZsalt.modules.filerrrrrr	r
rrr
rrrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2rVr3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrErFZsalt.utils.functoolsrGrMrJrKrLr�r�r�r�r�Zsalt.platform.win�ImportErrorrNZsalt.utils.win_dacl�globals�	getLogger�__name__rgrOrRZ
__outputter__Z__func_alias__rarlrprvrxr|rrir�rzr~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr^r
rUrrrrPrPrPrQ�<module>sX
�0X������
��
#
&
*
#
//

'&
"
2:
.M
+ '^A
�V
 
@j"
�i
�
�r
�N