Skip to contentSkip to conversation

cifscreds: fix parsing of commands and parameters

PATCH In review Paulo Alcantara 2 participants 4 messages Nov 25, 2025 – Dec 1, 2025 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Paulo Alcantara

author maintainer
#0 lore raw

PATCH 1/1 cifscreds: fix parsing of commands and parameters

Fix the parsing of '--username' and '--timeout' options as both require an argument by fixing the value passed in @optstring when calling getopt_long(3).

Also fix the matching of commands by breaking the loop when an exact match is found. Otherwise cifscreds clear ... would return "Ambiguous command" due to "clearall" command.

* Before patch

$ ./cifscreds add -u testuser w22-root2.zelda.test
error: Could not resolve address for testuser
$ ./cifscreds add -u testuser -d ZELDA
Password:
$ grep 'cifs:[ad]' /proc/keys
198de7a1 I--Q---     1 perm 0d0d0000     0     0 logon     cifs:d:testuser: 13
                                                                  ^^ wrong desc
$ ./cifscreds clear -u testuser w22-root2.zelda.test
Ambiguous command
$ ./cifscreds clear -u testuser -d ZELDA
Ambiguous command

* After patch

$ ./cifscreds add -u testuser w22-root2.zelda.test
Password:
$ ./cifscreds add -u testuser -d ZELDA
Password:
$ grep 'cifs:[ad]' /proc/keys
089183a9 I--Q---     1 perm 0d0d0000     0     0 logon     cifs:a:192.168.124.32: 17
0ca5ed80 I--Q---     1 perm 0d0d0000     0     0 logon     cifs:d:ZELDA: 17
$ ./cifscreds clear -u testuser w22-root2.zelda.test
$ ./cifscreds clear -u testuser -d ZELDA
---
 cifscreds.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
cifscreds.c +3 -3
index 295059f9683d..e8713be23d71 100644
@@ -71,7 +71,7 @@ static struct command commands[] = {
 static struct option longopts[] = {
 	{"username", 1, NULL, 'u'},
 	{"domain", 0, NULL, 'd' },
-	{"timeout", 0, NULL, 't' },
+	{"timeout", 1, NULL, 't' },
 	{NULL, 0, NULL, 0}
 };
 
@@ -477,7 +477,7 @@ int main(int argc, char **argv)
 	if (argc == 1)
 		return usage();
 
-	while((n = getopt_long(argc, argv, "dut:", longopts, NULL)) != -1) {
+	while((n = getopt_long(argc, argv, "du:t:", longopts, NULL)) != -1) {
 		switch (n) {
 		case 'd':
 			arg.keytype = (char) n;
@@ -507,7 +507,7 @@ int main(int argc, char **argv)
 		if (cmd->name[n] == 0) {
 			/* exact match */
 			best = cmd;
-			continue;
+			break;
 		}
 
 		/* partial match */
Signature · 1 line
2.51.1
#1 lore raw

added to cifs-utils for-next

Do you know if this is a regression of cifs-utils and if so what release/when?

Quoted 78 lines · Paulo Alcantara

Fix the parsing of '--username' and '--timeout' options as both require an argument by fixing the value passed in @optstring when calling getopt_long(3).

Also fix the matching of commands by breaking the loop when an exact match is found. Otherwise cifscreds clear ... would return "Ambiguous command" due to "clearall" command.

* Before patch

$ ./cifscreds add -u testuser w22-root2.zelda.test
error: Could not resolve address for testuser
$ ./cifscreds add -u testuser -d ZELDA
Password:
$ grep 'cifs:[ad]' /proc/keys
198de7a1 I--Q---     1 perm 0d0d0000     0     0 logon     cifs:d:testuser: 13
                                                                  ^^ wrong desc
$ ./cifscreds clear -u testuser w22-root2.zelda.test
Ambiguous command
$ ./cifscreds clear -u testuser -d ZELDA
Ambiguous command

* After patch

$ ./cifscreds add -u testuser w22-root2.zelda.test
Password:
$ ./cifscreds add -u testuser -d ZELDA
Password:
$ grep 'cifs:[ad]' /proc/keys
089183a9 I--Q---     1 perm 0d0d0000     0     0 logon     cifs:a:192.168.124.32: 17
0ca5ed80 I--Q---     1 perm 0d0d0000     0     0 logon     cifs:d:ZELDA: 17
$ ./cifscreds clear -u testuser w22-root2.zelda.test
$ ./cifscreds clear -u testuser -d ZELDA
---
 cifscreds.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
cifscreds.c +3 -4
index 295059f9683d..e8713be23d71 100644
@@ -71,7 +71,7 @@ static struct command commands[] = {
 static struct option longopts[] = {
        {"username", 1, NULL, 'u'},
        {"domain", 0, NULL, 'd' },
-       {"timeout", 0, NULL, 't' },
+       {"timeout", 1, NULL, 't' },
        {NULL, 0, NULL, 0}
 };
 
@@ -477,7 +477,7 @@ int main(int argc, char **argv)
        if (argc == 1)
                return usage();
 
-       while((n = getopt_long(argc, argv, "dut:", longopts, NULL)) != -1) {
+       while((n = getopt_long(argc, argv, "du:t:", longopts, NULL)) != -1) {
                switch (n) {
                case 'd':
                        arg.keytype = (char) n;
@@ -507,7 +507,7 @@ int main(int argc, char **argv)
                if (cmd->name[n] == 0) {
                        /* exact match */
                        best = cmd;
-                       continue;
+                       break;
                }
 
                /* partial match */
--

2.51.1

Signature · 3 lines
Thanks,

Steve
author maintainer
#2 lore raw
Quoted 3 lines · Steve French

added to cifs-utils for-next

Do you know if this is a regression of cifs-utils and if so what release/when?

It is regression introduced in cifs-utils-7.2.

A message that is not in the archive (sent off-list or not yet received): CAKywueTatO7NNZ=020B27vFCLvA1yb0rsWGMgnB8PKV2-Pb=oQ@mail.gmail.com

author maintainer
#4 lore raw
Quoted 1 line · Pavel Shilovsky

Is the fix urgent enough to make a release?

Yes.