Blob Blame History Raw
From 1f82a2588ac4c8975de0ebe52ad84393b8420e5b Mon Sep 17 00:00:00 2001
From: Germano Percossi <germano.percossi@citrix.com>
Date: Fri, 18 Nov 2016 18:54:51 +0000
Subject: [PATCH 10/12] mount.cifs: Fixed command line parsing and aligned with
 kernel

The way token matching was done was consuming the parameters namespace
quickly.  For example, anything starting with "dom" was interpreted with
domain, while it could have been a completely different word.  The same
is true even for "ro".

Moreover, many perfectly valid options like "addr" where not accepted.

The cifs  kernel module is very strict when it comes to names: 'dom' and
'domain' are valid while 'domai' is not, so the userspace tool needs to
comply otherwise it becomes very difficult to come up with new names for
options.

Now, checking is strict and as close as possible to kernel.  When it is
not, it is just to avoid breaking compatibility with some users.
However, workg has been removed because it is too lazy and undocumented.

The only variable left without strict checking is 'x-' because the
intent is to ignore anything starting in that way

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
(cherry picked from commit a1f3acd40b265f134a97a739a6898b3958d206b9)

Resolves bz: 1427337

Signed-off-by: Sachin Prabhu <sprabhu@redhat.com>
---
 mount.cifs.c | 82 ++++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 47 insertions(+), 35 deletions(-)

diff --git a/mount.cifs.c b/mount.cifs.c
index 88a3618..6eb0e6b 100644
--- a/mount.cifs.c
+++ b/mount.cifs.c
@@ -689,73 +689,85 @@ static int parse_opt_token(const char *token)
 	if (token == NULL)
 		return OPT_ERROR;
 
-	if (strncmp(token, "users", 5) == 0)
+	/*
+	 * token is NULL terminated and contains exactly the
+	 * keyword so we can match exactly
+	 */
+	if (strcmp(token, "users") == 0)
 		return OPT_USERS;
-	if (strncmp(token, "user_xattr", 10) == 0)
+	if (strcmp(token, "user_xattr") == 0)
 		return OPT_USER_XATTR;
-	if (strncmp(token, "user", 4) == 0)
+	if (strcmp(token, "user") == 0 ||
+		strcmp(token, "username") == 0)
 		return OPT_USER;
-	if (strncmp(token, "pass", 4) == 0)
+	if (strcmp(token, "pass") == 0 ||
+		strcmp(token, "password") == 0)
 		return OPT_PASS;
-	if (strncmp(token, "sec", 3) == 0)
+	if (strcmp(token, "sec") == 0)
 		return OPT_SEC;
-	if (strncmp(token, "ip", 2) == 0)
+	if (strcmp(token, "ip") == 0 ||
+		strcmp(token, "addr") == 0)
 		return OPT_IP;
-	if (strncmp(token, "unc", 3) == 0 ||
-		strncmp(token, "target", 6) == 0 ||
-		strncmp(token, "path", 4) == 0)
+	if (strcmp(token, "unc") == 0 ||
+		strcmp(token, "target") == 0 ||
+		strcmp(token, "path") == 0)
 		return OPT_UNC;
-	if (strncmp(token, "dom", 3) == 0 || strncmp(token, "workg", 5) == 0)
+	if (strcmp(token, "dom") == 0 ||
+		strcmp(token, "domain") == 0 ||
+		strcmp(token, "workgroup") == 0)
 		return OPT_DOM;
-	if (strncmp(token, "cred", 4) == 0)
+	if (strcmp(token, "cred") == 0 || /* undocumented */
+		strcmp(token, "credentials") == 0)
 		return OPT_CRED;
-	if (strncmp(token, "uid", 3) == 0)
+	if (strcmp(token, "uid") == 0)
 		return OPT_UID;
-	if (strncmp(token, "cruid", 5) == 0)
+	if (strcmp(token, "cruid") == 0)
 		return OPT_CRUID;
-	if (strncmp(token, "gid", 3) == 0)
+	if (strcmp(token, "gid") == 0)
 		return OPT_GID;
-	if (strncmp(token, "fmask", 5) == 0)
+	if (strcmp(token, "fmask") == 0)
 		return OPT_FMASK;
-	if (strncmp(token, "file_mode", 9) == 0)
+	if (strcmp(token, "file_mode") == 0)
 		return OPT_FILE_MODE;
-	if (strncmp(token, "dmask", 5) == 0)
+	if (strcmp(token, "dmask") == 0)
 		return OPT_DMASK;
-	if (strncmp(token, "dir_mode", 4) == 0 || strncmp(token, "dirm", 4) == 0)
+	if (strcmp(token, "dir_mode") == 0 ||
+		strcmp(token, "dirm") == 0)
 		return OPT_DIR_MODE;
-	if (strncmp(token, "nosuid", 6) == 0)
+	if (strcmp(token, "nosuid") == 0)
 		return OPT_NO_SUID;
-	if (strncmp(token, "suid", 4) == 0)
+	if (strcmp(token, "suid") == 0)
 		return OPT_SUID;
-	if (strncmp(token, "nodev", 5) == 0)
+	if (strcmp(token, "nodev") == 0)
 		return OPT_NO_DEV;
-	if (strncmp(token, "nobrl", 5) == 0 || strncmp(token, "nolock", 6) == 0)
+	if (strcmp(token, "nobrl") == 0 ||
+		strcmp(token, "nolock") == 0)
 		return OPT_NO_LOCK;
-	if (strncmp(token, "mand", 4) == 0)
+	if (strcmp(token, "mand") == 0)
 		return OPT_MAND;
-	if (strncmp(token, "nomand", 6) == 0)
+	if (strcmp(token, "nomand") == 0)
 		return OPT_NOMAND;
-	if (strncmp(token, "dev", 3) == 0)
+	if (strcmp(token, "dev") == 0)
 		return OPT_DEV;
-	if (strncmp(token, "noexec", 6) == 0)
+	if (strcmp(token, "noexec") == 0)
 		return OPT_NO_EXEC;
-	if (strncmp(token, "exec", 4) == 0)
+	if (strcmp(token, "exec") == 0)
 		return OPT_EXEC;
-	if (strncmp(token, "guest", 5) == 0)
+	if (strcmp(token, "guest") == 0)
 		return OPT_GUEST;
-	if (strncmp(token, "ro", 2) == 0)
+	if (strcmp(token, "ro") == 0)
 		return OPT_RO;
-	if (strncmp(token, "rw", 2) == 0 && strlen(token) == 2)
+	if (strcmp(token, "rw") == 0)
 		return OPT_RW;
-	if (strncmp(token, "remount", 7) == 0)
+	if (strcmp(token, "remount") == 0)
 		return OPT_REMOUNT;
-	if (strncmp(token, "_netdev", 7) == 0)
+	if (strcmp(token, "_netdev") == 0)
 		return OPT_IGNORE;
-	if (strncmp(token, "backupuid", 9) == 0)
+	if (strcmp(token, "backupuid") == 0)
 		return OPT_BKUPUID;
-	if (strncmp(token, "backupgid", 9) == 0)
+	if (strcmp(token, "backupgid") == 0)
 		return OPT_BKUPGID;
-	if (strncmp(token, "nofail", 6) == 0)
+	if (strcmp(token, "nofail") == 0)
 		return OPT_NOFAIL;
 	if (strncmp(token, "x-", 2) == 0)
 		return OPT_IGNORE;
-- 
2.9.3