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

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