6b9308
From 791381a715bac0f2910101bf0d6cceac9e569452 Mon Sep 17 00:00:00 2001
6b9308
From: Karel Zak <kzak@redhat.com>
6b9308
Date: Mon, 12 Oct 2015 11:42:13 +0200
6b9308
Subject: [PATCH 196/197] libmount: fix uid= and gid= translation
6b9308
6b9308
The current libmount version returns error when no able to convert
6b9308
username/groupname to uid/git.
6b9308
6b9308
 # mount mount /dev/sda1 /mnt/test -o uid=ignore
6b9308
 # mount: failed to parse mount options
6b9308
6b9308
This is regression, the original mount(8) has ignored possible unknown
6b9308
user/group names and the option has been used unconverted (with the
6b9308
original value). For example UDF kernel driver depends on this behavior
6b9308
and "uid=ignore" (or "forgot") is a valid mount option.
6b9308
6b9308
Fixed version (unit test):
6b9308
6b9308
./test_mount_optstr  --fix uid=kzak,gid=forgot,aaa,bbb
6b9308
optstr: uid=kzak,gid=forgot,aaa,bbb
6b9308
fixed:  uid=1000,gid=forgot,aaa,bbb
6b9308
6b9308
Reported-By: Anthony DeRobertis <anthony@derobert.net>
6b9308
Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=801527
6b9308
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1747710
6b9308
Upstream: http://github.com/karelzak/util-linux/commit/440a355a3d3934d99f7ef82adf02342e6f2f7983
6b9308
Signed-off-by: Karel Zak <kzak@redhat.com>
6b9308
---
6b9308
 libmount/src/optstr.c | 25 ++++++++++++++-----------
6b9308
 1 file changed, 14 insertions(+), 11 deletions(-)
6b9308
6b9308
diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c
6b9308
index 7bd9bbdb5..63b98c754 100644
6b9308
--- a/libmount/src/optstr.c
6b9308
+++ b/libmount/src/optstr.c
6b9308
@@ -962,7 +962,6 @@ static int set_uint_value(char **optstr, unsigned int num,
6b9308
  */
6b9308
 int mnt_optstr_fix_uid(char **optstr, char *value, size_t valsz, char **next)
6b9308
 {
6b9308
-	int rc = 0;
6b9308
 	char *end;
6b9308
 
6b9308
 	if (!optstr || !*optstr || !value || !valsz)
6b9308
@@ -974,10 +973,11 @@ int mnt_optstr_fix_uid(char **optstr, char *value, size_t valsz, char **next)
6b9308
 
6b9308
 	if (valsz == 7 && !strncmp(value, "useruid", 7) &&
6b9308
 	    (*(value + 7) == ',' || !*(value + 7)))
6b9308
-		rc = set_uint_value(optstr, getuid(), value, end, next);
6b9308
+		return set_uint_value(optstr, getuid(), value, end, next);
6b9308
 
6b9308
 	else if (!isdigit(*value)) {
6b9308
 		uid_t id;
6b9308
+		int rc;
6b9308
 		char *p = strndup(value, valsz);
6b9308
 		if (!p)
6b9308
 			return -ENOMEM;
6b9308
@@ -985,16 +985,17 @@ int mnt_optstr_fix_uid(char **optstr, char *value, size_t valsz, char **next)
6b9308
 		free(p);
6b9308
 
6b9308
 		if (!rc)
6b9308
-			rc = set_uint_value(optstr, id, value, end, next);
6b9308
+			return set_uint_value(optstr, id, value, end, next);
6b9308
+	}
6b9308
 
6b9308
-	} else if (next) {
6b9308
-		/* nothing */
6b9308
+	if (next) {
6b9308
+		/* no change, let's keep the original value */
6b9308
 		*next = value + valsz;
6b9308
 		if (**next == ',')
6b9308
 			(*next)++;
6b9308
 	}
6b9308
 
6b9308
-	return rc;
6b9308
+	return 0;
6b9308
 }
6b9308
 
6b9308
 /*
6b9308
@@ -1009,7 +1010,6 @@ int mnt_optstr_fix_uid(char **optstr, char *value, size_t valsz, char **next)
6b9308
  */
6b9308
 int mnt_optstr_fix_gid(char **optstr, char *value, size_t valsz, char **next)
6b9308
 {
6b9308
-	int rc = 0;
6b9308
 	char *end;
6b9308
 
6b9308
 	if (!optstr || !*optstr || !value || !valsz)
6b9308
@@ -1021,9 +1021,10 @@ int mnt_optstr_fix_gid(char **optstr, char *value, size_t valsz, char **next)
6b9308
 
6b9308
 	if (valsz == 7 && !strncmp(value, "usergid", 7) &&
6b9308
 	    (*(value + 7) == ',' || !*(value + 7)))
6b9308
-		rc = set_uint_value(optstr, getgid(), value, end, next);
6b9308
+		return set_uint_value(optstr, getgid(), value, end, next);
6b9308
 
6b9308
 	else if (!isdigit(*value)) {
6b9308
+		int rc;
6b9308
 		gid_t id;
6b9308
 		char *p = strndup(value, valsz);
6b9308
 		if (!p)
6b9308
@@ -1032,15 +1033,17 @@ int mnt_optstr_fix_gid(char **optstr, char *value, size_t valsz, char **next)
6b9308
 		free(p);
6b9308
 
6b9308
 		if (!rc)
6b9308
-			rc = set_uint_value(optstr, id, value, end, next);
6b9308
+			return set_uint_value(optstr, id, value, end, next);
6b9308
+
6b9308
+	}
6b9308
 
6b9308
-	} else if (next) {
6b9308
+	if (next) {
6b9308
 		/* nothing */
6b9308
 		*next = value + valsz;
6b9308
 		if (**next == ',')
6b9308
 			(*next)++;
6b9308
 	}
6b9308
-	return rc;
6b9308
+	return 0;
6b9308
 }
6b9308
 
6b9308
 /*
6b9308
-- 
6b9308
2.25.2
6b9308