2021-01-08 13:41:50 +01:00
|
|
|
From 60b8f6cdaab10a12973a074678608b86a34e23b7 Mon Sep 17 00:00:00 2001
|
2020-10-14 17:29:00 +02:00
|
|
|
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>
|
|
|
|
---
|
2021-01-08 13:41:50 +01:00
|
|
|
salt/modules/file.py | 26 +++++++++++++++++---------
|
|
|
|
salt/states/file.py | 12 ++++++++++--
|
|
|
|
2 files changed, 27 insertions(+), 11 deletions(-)
|
2020-10-14 17:29:00 +02:00
|
|
|
|
|
|
|
diff --git a/salt/modules/file.py b/salt/modules/file.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index 989a7ad92d..b830b390d3 100644
|
2020-10-14 17:29:00 +02:00
|
|
|
--- a/salt/modules/file.py
|
|
|
|
+++ b/salt/modules/file.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -252,7 +252,7 @@ def group_to_gid(group):
|
2020-10-14 17:29:00 +02:00
|
|
|
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:
|
2021-01-08 13:41:50 +01:00
|
|
|
return ""
|
2020-10-14 17:29:00 +02:00
|
|
|
|
|
|
|
@@ -344,7 +344,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:
|
2021-01-08 13:41:50 +01:00
|
|
|
return ""
|
2020-10-14 17:29:00 +02:00
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -4977,7 +4977,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
|
2020-10-14 17:29:00 +02:00
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
if group:
|
|
|
|
@@ -4986,7 +4989,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
|
2020-10-14 17:29:00 +02:00
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
if "cuser" in perms or "cgroup" in perms:
|
|
|
|
@@ -5017,7 +5023,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 != ""
|
2020-10-14 17:29:00 +02:00
|
|
|
):
|
2021-01-08 13:41:50 +01:00
|
|
|
if __opts__["test"] is True:
|
|
|
|
@@ -5035,18 +5042,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 != ""
|
2020-10-14 17:29:00 +02:00
|
|
|
):
|
2021-01-08 13:41:50 +01:00
|
|
|
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
|
2020-10-14 17:29:00 +02:00
|
|
|
|
|
|
|
# Mode changes if needed
|
|
|
|
diff --git a/salt/states/file.py b/salt/states/file.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index 9e24e389d8..89c70eb454 100644
|
2020-10-14 17:29:00 +02:00
|
|
|
--- a/salt/states/file.py
|
|
|
|
+++ b/salt/states/file.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -989,9 +989,17 @@ def _check_dir_meta(name, user, group, mode, follow_symlinks=False):
|
|
|
|
if not stats:
|
|
|
|
changes["directory"] = "new"
|
2020-10-14 17:29:00 +02:00
|
|
|
return changes
|
2021-01-08 13:41:50 +01:00
|
|
|
- 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
|
2020-10-14 17:29:00 +02:00
|
|
|
# Normalize the dir mode
|
2021-01-08 13:41:50 +01:00
|
|
|
smode = salt.utils.files.normalize_mode(stats["mode"])
|
2020-10-14 17:29:00 +02:00
|
|
|
--
|
2021-01-08 13:41:50 +01:00
|
|
|
2.29.2
|
2020-10-14 17:29:00 +02:00
|
|
|
|
|
|
|
|