81ba992e3e
OBS-URL: https://build.opensuse.org/package/show/systemsmanagement:saltstack/salt?expand=0&rev=205
127 lines
4.6 KiB
Diff
127 lines
4.6 KiB
Diff
From 58329533d8b3239d978c15ecb76934987880897f Mon Sep 17 00:00:00 2001
|
|
From: Victor Zhestkov <35733135+vzhestkov@users.noreply.github.com>
|
|
Date: Tue, 6 Oct 2020 12:36:41 +0300
|
|
Subject: [PATCH] bsc#1176024: Fix file/directory user and group
|
|
ownership containing UTF-8 characters (#275)
|
|
|
|
* Fix check_perm typos of file module
|
|
|
|
* Fix UTF8 support for user/group ownership operations with file module and state
|
|
|
|
* Fix UTF8 support for user/group ownership operations with file module and state
|
|
|
|
Co-authored-by: Victor Zhestkov <vzhestkov@vz-thinkpad.vzhestkov.net>
|
|
---
|
|
salt/modules/file.py | 26 +++++++++++++++++---------
|
|
salt/states/file.py | 12 ++++++++++--
|
|
2 files changed, 27 insertions(+), 11 deletions(-)
|
|
|
|
diff --git a/salt/modules/file.py b/salt/modules/file.py
|
|
index 95bd69a588..d475e3c2e3 100644
|
|
--- a/salt/modules/file.py
|
|
+++ b/salt/modules/file.py
|
|
@@ -247,7 +247,7 @@ def group_to_gid(group):
|
|
try:
|
|
if isinstance(group, int):
|
|
return group
|
|
- return grp.getgrnam(group).gr_gid
|
|
+ return grp.getgrnam(salt.utils.stringutils.to_str(group)).gr_gid
|
|
except KeyError:
|
|
return ""
|
|
|
|
@@ -338,7 +338,7 @@ def user_to_uid(user):
|
|
try:
|
|
if isinstance(user, int):
|
|
return user
|
|
- return pwd.getpwnam(user).pw_uid
|
|
+ return pwd.getpwnam(salt.utils.stringutils.to_str(user)).pw_uid
|
|
except KeyError:
|
|
return ""
|
|
|
|
@@ -5043,7 +5043,10 @@ def check_perms(
|
|
if (
|
|
salt.utils.platform.is_windows()
|
|
and user_to_uid(user) != user_to_uid(perms["luser"])
|
|
- ) or (not salt.utils.platform.is_windows() and user != perms["luser"]):
|
|
+ ) or (
|
|
+ not salt.utils.platform.is_windows()
|
|
+ and salt.utils.stringutils.to_str(user) != perms["luser"]
|
|
+ ):
|
|
perms["cuser"] = user
|
|
|
|
if group:
|
|
@@ -5052,7 +5055,10 @@ def check_perms(
|
|
if (
|
|
salt.utils.platform.is_windows()
|
|
and group_to_gid(group) != group_to_gid(perms["lgroup"])
|
|
- ) or (not salt.utils.platform.is_windows() and group != perms["lgroup"]):
|
|
+ ) or (
|
|
+ not salt.utils.platform.is_windows()
|
|
+ and salt.utils.stringutils.to_str(group) != perms["lgroup"]
|
|
+ ):
|
|
perms["cgroup"] = group
|
|
|
|
if "cuser" in perms or "cgroup" in perms:
|
|
@@ -5083,7 +5089,8 @@ def check_perms(
|
|
and user != ""
|
|
) or (
|
|
not salt.utils.platform.is_windows()
|
|
- and user != get_user(name, follow_symlinks=follow_symlinks)
|
|
+ and salt.utils.stringutils.to_str(user)
|
|
+ != get_user(name, follow_symlinks=follow_symlinks)
|
|
and user != ""
|
|
):
|
|
if __opts__["test"] is True:
|
|
@@ -5101,18 +5108,19 @@ def check_perms(
|
|
salt.utils.platform.is_windows()
|
|
and group_to_gid(group)
|
|
!= group_to_gid(get_group(name, follow_symlinks=follow_symlinks))
|
|
- and user != ""
|
|
+ and group != ""
|
|
) or (
|
|
not salt.utils.platform.is_windows()
|
|
- and group != get_group(name, follow_symlinks=follow_symlinks)
|
|
- and user != ""
|
|
+ and salt.utils.stringutils.to_str(group)
|
|
+ != get_group(name, follow_symlinks=follow_symlinks)
|
|
+ and group != ""
|
|
):
|
|
if __opts__["test"] is True:
|
|
ret["changes"]["group"] = group
|
|
else:
|
|
ret["result"] = False
|
|
ret["comment"].append("Failed to change group to {}".format(group))
|
|
- elif "cgroup" in perms and user != "":
|
|
+ elif "cgroup" in perms and group != "":
|
|
ret["changes"]["group"] = group
|
|
|
|
# Mode changes if needed
|
|
diff --git a/salt/states/file.py b/salt/states/file.py
|
|
index 9f33a8de23..50ceef1158 100644
|
|
--- a/salt/states/file.py
|
|
+++ b/salt/states/file.py
|
|
@@ -863,9 +863,17 @@ def _check_dir_meta(name, user, group, mode, follow_symlinks=False):
|
|
if not stats:
|
|
changes["directory"] = "new"
|
|
return changes
|
|
- if user is not None and user != stats["user"] and user != stats.get("uid"):
|
|
+ if (
|
|
+ user is not None
|
|
+ and salt.utils.stringutils.to_str(user) != stats["user"]
|
|
+ and user != stats.get("uid")
|
|
+ ):
|
|
changes["user"] = user
|
|
- if group is not None and group != stats["group"] and group != stats.get("gid"):
|
|
+ if (
|
|
+ group is not None
|
|
+ and salt.utils.stringutils.to_str(group) != stats["group"]
|
|
+ and group != stats.get("gid")
|
|
+ ):
|
|
changes["group"] = group
|
|
# Normalize the dir mode
|
|
smode = salt.utils.files.normalize_mode(stats["mode"])
|
|
--
|
|
2.37.3
|
|
|
|
|