* [PATCH] cifscreds: fix parsing of commands and parameters
@ 2025-11-25 19:55 Paulo Alcantara
2025-11-25 23:59 ` Steve French
0 siblings, 1 reply; 4+ messages in thread
From: Paulo Alcantara @ 2025-11-25 19:55 UTC (permalink / raw)
To: piastryyy
Cc: Xiaoli Feng, Jay Shin, Paulo Alcantara (Red Hat), Steve French,
linux-cifs
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
Reported-by: Xiaoli Feng <xifeng@redhat.com>
Reported-by: Jay Shin <jaeshin@redhat.com>
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>
Cc: Steve French <smfrench@gmail.com>
Cc: linux-cifs@vger.kernel.org
---
cifscreds.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/cifscreds.c b/cifscreds.c
index 295059f9683d..e8713be23d71 100644
--- a/cifscreds.c
+++ b/cifscreds.c
@@ -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
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] cifscreds: fix parsing of commands and parameters
2025-11-25 19:55 [PATCH] cifscreds: fix parsing of commands and parameters Paulo Alcantara
@ 2025-11-25 23:59 ` Steve French
2025-11-26 16:02 ` Paulo Alcantara
0 siblings, 1 reply; 4+ messages in thread
From: Steve French @ 2025-11-25 23:59 UTC (permalink / raw)
To: Paulo Alcantara; +Cc: piastryyy, Xiaoli Feng, Jay Shin, linux-cifs
added to cifs-utils for-next
Do you know if this is a regression of cifs-utils and if so what release/when?
On Tue, Nov 25, 2025 at 1:55 PM Paulo Alcantara <pc@manguebit.org> wrote:
>
> 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
>
> Reported-by: Xiaoli Feng <xifeng@redhat.com>
> Reported-by: Jay Shin <jaeshin@redhat.com>
> Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>
> Cc: Steve French <smfrench@gmail.com>
> Cc: linux-cifs@vger.kernel.org
> ---
> cifscreds.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/cifscreds.c b/cifscreds.c
> index 295059f9683d..e8713be23d71 100644
> --- a/cifscreds.c
> +++ b/cifscreds.c
> @@ -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
>
--
Thanks,
Steve
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-12-01 17:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-25 19:55 [PATCH] cifscreds: fix parsing of commands and parameters Paulo Alcantara
2025-11-25 23:59 ` Steve French
2025-11-26 16:02 ` Paulo Alcantara
[not found] ` <CAKywueTatO7NNZ=020B27vFCLvA1yb0rsWGMgnB8PKV2-Pb=oQ@mail.gmail.com>
2025-12-01 17:35 ` Paulo Alcantara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox