File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/win_file.cpython-310.pyc
o
�N�g� � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlZ ddl
Z ddlZ ddlZ ddl
mZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm 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@ ddlmAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZT ddlUmVZV dZWz"e jXjY�Z� r�ddl[Z[ddl\Z\ddl]Z]ddl^Z^ddl_Z_ddl`Z d ZWW n eay� dZWY nw dZbze jXjY�Z� �rddlcZ d ZbW n ea�y dZbY nw e 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�filec C s t jj�� rts
dS tsdS tS )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__� rP rP �I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/win_file.py�__virtual__� s
rR �txt)rC r �makedirsr2 )� makedirs_� normpath_�@ c C sn t �� jdk rtd��| h}d}t| �r5t| �} | |v r 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.r z-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_depthrP rP rQ �_resolve_symlink� s �
� ra c C s. 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_namerP rP rQ �gid_to_group� s
�rl c C s@ t � d�}t�dd�|krt�d|� | du rdS tjj�| �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_gidrb rc rd N) rO re rf rg rh rI rJ �win_dacl�get_sid_string)�grouprk rP rP rQ �group_to_gid s
�rp c C �P t j�| �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` �existsr r[ r\ r] ra rI rJ rm Zget_primary_grouprn )r` �follow_symlinksZ
group_namerP rP rQ �get_pgidD s rv c C s t t| |��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
)ri rv �r` ru rP rP rQ �
get_pgroupn s rx c C �0 t � 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_gidrb rc ztThe function %s should not be used on Windows systems; see function docs for details. The value returned is the uid.)rO re rf rg rh �get_uid�r` ru rk rP rP rQ �get_gid� �
#�
r| c C ry )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_grouprb rc z}The function %s should not be used on Windows systems; see function docs for details. The value returned is the user (owner).)rO re rf rg rh �get_userr{ rP rP rQ � get_group� r} r c C s"