Blame SOURCES/0010-mount.cifs-Fixed-command-line-parsing-and-aligned-wi.patch

25fd3e
From 1f82a2588ac4c8975de0ebe52ad84393b8420e5b Mon Sep 17 00:00:00 2001
25fd3e
From: Germano Percossi <germano.percossi@citrix.com>
25fd3e
Date: Fri, 18 Nov 2016 18:54:51 +0000
25fd3e
Subject: [PATCH 10/12] mount.cifs: Fixed command line parsing and aligned with
25fd3e
 kernel
25fd3e
25fd3e
The way token matching was done was consuming the parameters namespace
25fd3e
quickly.  For example, anything starting with "dom" was interpreted with
25fd3e
domain, while it could have been a completely different word.  The same
25fd3e
is true even for "ro".
25fd3e
25fd3e
Moreover, many perfectly valid options like "addr" where not accepted.
25fd3e
25fd3e
The cifs  kernel module is very strict when it comes to names: 'dom' and
25fd3e
'domain' are valid while 'domai' is not, so the userspace tool needs to
25fd3e
comply otherwise it becomes very difficult to come up with new names for
25fd3e
options.
25fd3e
25fd3e
Now, checking is strict and as close as possible to kernel.  When it is
25fd3e
not, it is just to avoid breaking compatibility with some users.
25fd3e
However, workg has been removed because it is too lazy and undocumented.
25fd3e
25fd3e
The only variable left without strict checking is 'x-' because the
25fd3e
intent is to ignore anything starting in that way
25fd3e
25fd3e
Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
25fd3e
(cherry picked from commit a1f3acd40b265f134a97a739a6898b3958d206b9)
25fd3e
25fd3e
Resolves bz: 1427337
25fd3e
25fd3e
Signed-off-by: Sachin Prabhu <sprabhu@redhat.com>
25fd3e
---
25fd3e
 mount.cifs.c | 82 ++++++++++++++++++++++++++++++++++--------------------------
25fd3e
 1 file changed, 47 insertions(+), 35 deletions(-)
25fd3e
25fd3e
diff --git a/mount.cifs.c b/mount.cifs.c
25fd3e
index 88a3618..6eb0e6b 100644
25fd3e
--- a/mount.cifs.c
25fd3e
+++ b/mount.cifs.c
25fd3e
@@ -689,73 +689,85 @@ static int parse_opt_token(const char *token)
25fd3e
 	if (token == NULL)
25fd3e
 		return OPT_ERROR;
25fd3e
 
25fd3e
-	if (strncmp(token, "users", 5) == 0)
25fd3e
+	/*
25fd3e
+	 * token is NULL terminated and contains exactly the
25fd3e
+	 * keyword so we can match exactly
25fd3e
+	 */
25fd3e
+	if (strcmp(token, "users") == 0)
25fd3e
 		return OPT_USERS;
25fd3e
-	if (strncmp(token, "user_xattr", 10) == 0)
25fd3e
+	if (strcmp(token, "user_xattr") == 0)
25fd3e
 		return OPT_USER_XATTR;
25fd3e
-	if (strncmp(token, "user", 4) == 0)
25fd3e
+	if (strcmp(token, "user") == 0 ||
25fd3e
+		strcmp(token, "username") == 0)
25fd3e
 		return OPT_USER;
25fd3e
-	if (strncmp(token, "pass", 4) == 0)
25fd3e
+	if (strcmp(token, "pass") == 0 ||
25fd3e
+		strcmp(token, "password") == 0)
25fd3e
 		return OPT_PASS;
25fd3e
-	if (strncmp(token, "sec", 3) == 0)
25fd3e
+	if (strcmp(token, "sec") == 0)
25fd3e
 		return OPT_SEC;
25fd3e
-	if (strncmp(token, "ip", 2) == 0)
25fd3e
+	if (strcmp(token, "ip") == 0 ||
25fd3e
+		strcmp(token, "addr") == 0)
25fd3e
 		return OPT_IP;
25fd3e
-	if (strncmp(token, "unc", 3) == 0 ||
25fd3e
-		strncmp(token, "target", 6) == 0 ||
25fd3e
-		strncmp(token, "path", 4) == 0)
25fd3e
+	if (strcmp(token, "unc") == 0 ||
25fd3e
+		strcmp(token, "target") == 0 ||
25fd3e
+		strcmp(token, "path") == 0)
25fd3e
 		return OPT_UNC;
25fd3e
-	if (strncmp(token, "dom", 3) == 0 || strncmp(token, "workg", 5) == 0)
25fd3e
+	if (strcmp(token, "dom") == 0 ||
25fd3e
+		strcmp(token, "domain") == 0 ||
25fd3e
+		strcmp(token, "workgroup") == 0)
25fd3e
 		return OPT_DOM;
25fd3e
-	if (strncmp(token, "cred", 4) == 0)
25fd3e
+	if (strcmp(token, "cred") == 0 || /* undocumented */
25fd3e
+		strcmp(token, "credentials") == 0)
25fd3e
 		return OPT_CRED;
25fd3e
-	if (strncmp(token, "uid", 3) == 0)
25fd3e
+	if (strcmp(token, "uid") == 0)
25fd3e
 		return OPT_UID;
25fd3e
-	if (strncmp(token, "cruid", 5) == 0)
25fd3e
+	if (strcmp(token, "cruid") == 0)
25fd3e
 		return OPT_CRUID;
25fd3e
-	if (strncmp(token, "gid", 3) == 0)
25fd3e
+	if (strcmp(token, "gid") == 0)
25fd3e
 		return OPT_GID;
25fd3e
-	if (strncmp(token, "fmask", 5) == 0)
25fd3e
+	if (strcmp(token, "fmask") == 0)
25fd3e
 		return OPT_FMASK;
25fd3e
-	if (strncmp(token, "file_mode", 9) == 0)
25fd3e
+	if (strcmp(token, "file_mode") == 0)
25fd3e
 		return OPT_FILE_MODE;
25fd3e
-	if (strncmp(token, "dmask", 5) == 0)
25fd3e
+	if (strcmp(token, "dmask") == 0)
25fd3e
 		return OPT_DMASK;
25fd3e
-	if (strncmp(token, "dir_mode", 4) == 0 || strncmp(token, "dirm", 4) == 0)
25fd3e
+	if (strcmp(token, "dir_mode") == 0 ||
25fd3e
+		strcmp(token, "dirm") == 0)
25fd3e
 		return OPT_DIR_MODE;
25fd3e
-	if (strncmp(token, "nosuid", 6) == 0)
25fd3e
+	if (strcmp(token, "nosuid") == 0)
25fd3e
 		return OPT_NO_SUID;
25fd3e
-	if (strncmp(token, "suid", 4) == 0)
25fd3e
+	if (strcmp(token, "suid") == 0)
25fd3e
 		return OPT_SUID;
25fd3e
-	if (strncmp(token, "nodev", 5) == 0)
25fd3e
+	if (strcmp(token, "nodev") == 0)
25fd3e
 		return OPT_NO_DEV;
25fd3e
-	if (strncmp(token, "nobrl", 5) == 0 || strncmp(token, "nolock", 6) == 0)
25fd3e
+	if (strcmp(token, "nobrl") == 0 ||
25fd3e
+		strcmp(token, "nolock") == 0)
25fd3e
 		return OPT_NO_LOCK;
25fd3e
-	if (strncmp(token, "mand", 4) == 0)
25fd3e
+	if (strcmp(token, "mand") == 0)
25fd3e
 		return OPT_MAND;
25fd3e
-	if (strncmp(token, "nomand", 6) == 0)
25fd3e
+	if (strcmp(token, "nomand") == 0)
25fd3e
 		return OPT_NOMAND;
25fd3e
-	if (strncmp(token, "dev", 3) == 0)
25fd3e
+	if (strcmp(token, "dev") == 0)
25fd3e
 		return OPT_DEV;
25fd3e
-	if (strncmp(token, "noexec", 6) == 0)
25fd3e
+	if (strcmp(token, "noexec") == 0)
25fd3e
 		return OPT_NO_EXEC;
25fd3e
-	if (strncmp(token, "exec", 4) == 0)
25fd3e
+	if (strcmp(token, "exec") == 0)
25fd3e
 		return OPT_EXEC;
25fd3e
-	if (strncmp(token, "guest", 5) == 0)
25fd3e
+	if (strcmp(token, "guest") == 0)
25fd3e
 		return OPT_GUEST;
25fd3e
-	if (strncmp(token, "ro", 2) == 0)
25fd3e
+	if (strcmp(token, "ro") == 0)
25fd3e
 		return OPT_RO;
25fd3e
-	if (strncmp(token, "rw", 2) == 0 && strlen(token) == 2)
25fd3e
+	if (strcmp(token, "rw") == 0)
25fd3e
 		return OPT_RW;
25fd3e
-	if (strncmp(token, "remount", 7) == 0)
25fd3e
+	if (strcmp(token, "remount") == 0)
25fd3e
 		return OPT_REMOUNT;
25fd3e
-	if (strncmp(token, "_netdev", 7) == 0)
25fd3e
+	if (strcmp(token, "_netdev") == 0)
25fd3e
 		return OPT_IGNORE;
25fd3e
-	if (strncmp(token, "backupuid", 9) == 0)
25fd3e
+	if (strcmp(token, "backupuid") == 0)
25fd3e
 		return OPT_BKUPUID;
25fd3e
-	if (strncmp(token, "backupgid", 9) == 0)
25fd3e
+	if (strcmp(token, "backupgid") == 0)
25fd3e
 		return OPT_BKUPGID;
25fd3e
-	if (strncmp(token, "nofail", 6) == 0)
25fd3e
+	if (strcmp(token, "nofail") == 0)
25fd3e
 		return OPT_NOFAIL;
25fd3e
 	if (strncmp(token, "x-", 2) == 0)
25fd3e
 		return OPT_IGNORE;
25fd3e
-- 
25fd3e
2.9.3
25fd3e