namjaejeon / ksmbd-tools

ksmbd kernel server userspace utilities
GNU General Public License v2.0
55 stars 43 forks source link

ksmbd.adduser shows password prompts after the pass has been entered twice #201

Closed 0sma closed 4 months ago

0sma commented 4 months ago

This issue is present in ksmbd-tools version : 3.5.1

If adding a new user with: ksmbd.adduser -a user1

following is presented on CLI: [ksmbd.adduser/12789]: INFO: Prompting for password

No prompts for new/retype password are presented. These are shown after the enter/return has been pressed twice, together with additional information:

New password: Retype password: [ksmbd.adduser/12789]: INFO: Wrote '/etc/ksmbd/ksmbdpwd.db' [ksmbd.adduser/12789]: INFO: Added user 'user1' [ksmbd.adduser/12789]: ERROR: Invalid lock entry '12561' [ksmbd.adduser/12789]: INFO: Ignored lock file

In previous version (3.4.8) prompts for password have been presented correctly.

namjaejeon commented 4 months ago

@0sma @atheik

Hm.. I am trying to reproduce it, What is meaning "the enter/return has been pressed twice" ? You don't insert password and give enter twice ?

0sma commented 4 months ago

The issue is that no prompt to enter New password/Retype password is presented on CLI, after the ksmd.adduser is started. Those prompts are displayed after the passwords have been typed in and confirmed. I.e. the enter/return has been pressed twice.

Here's a screenshot to understand it better: ksmbd1

Password prompts are displayed after the pass have been entered: ksmbd2

The expected behaviour would be to show prompts for: New password immediately after the ksmbd.adduser starts Retype password after enter/return has been pressed

atheik commented 4 months ago

@0sma,

What terminal emulator are you using? What is TERM and the output of stty -a?

0sma commented 4 months ago
root@<redacted>:~# echo $TERM
xterm
root@<redacted>:~# stty -a
speed 38400 baud; rows 24; columns 126; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S;
susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc
atheik commented 4 months ago

@0sma,

Thanks. And what terminal emulator are you using? TERM alone does not reveal it.

atheik commented 4 months ago

Reproduced this on Alpine Linux 3.20.1. The ksmbd.addshare prompting does not work there either. Since I can't reproduce this on Arch Linux or Debian GNU/Linux, I'm guessing this is probably a musl libc thing. If so, then the prompting is probably broken on OpenWrt as well.

0sma commented 4 months ago

@atheik,

The system is an OpenWrt based router. As I'm connecting to it over SSH, the terminal emulator would be Putty/ssh client.

atheik commented 4 months ago

@0sma,

Thank you for opening this issue.

@namjaejeon,

This fixes the issue:

[PATCH] ksmbd-tools: fix prompting when built against musl libc (click the arrow to expand) ````diff From 204b88969c10708645b2e091c0dd95baad1ba742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atte=20Heikkil=C3=A4?= Date: Thu, 27 Jun 2024 23:36:04 +0300 Subject: [PATCH] ksmbd-tools: fix prompting when built against musl libc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The output stream flushing schemes of GNU libc and musl libc differ, resulting in addshare and adduser prompting incorrectly when built against the latter. Fix this by flushing explicitly with fflush(3). Signed-off-by: Atte Heikkilä --- addshare/share_admin.c | 1 + adduser/user_admin.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/addshare/share_admin.c b/addshare/share_admin.c index 575f5fa..fd2c593 100644 --- a/addshare/share_admin.c +++ b/addshare/share_admin.c @@ -122,6 +122,7 @@ static void __load_conf(enum KSMBD_SHARE_CONF conf, } printf("\r" "\e[2K" "%s%s" "\e[6n", option, buf); + fflush(stdout); if (option != options[conf]) g_free(option); diff --git a/adduser/user_admin.c b/adduser/user_admin.c index 1abfb8a..59c1336 100644 --- a/adduser/user_admin.c +++ b/adduser/user_admin.c @@ -42,9 +42,11 @@ static void __prompt_password_stdin(char *password, size_t *sz) buflen = 0, password[buflen] = buf[buflen] = 0x00;;) { int c; - if (!buflen) + if (!buflen) { printf("\r" "\e[2K" "%s password: ", *password == 0x00 ? "New" : "Retype"); + fflush(stdout); + } c = getchar(); if (c == EOF || c == 0x04) -- 2.45.2 ````
namjaejeon commented 4 months ago

@atheik Thanks for your patch!, Applied it to #master now. I will release it.

@0sma It would be grateful if you could confirm that this patch fix your issue.

0sma commented 4 months ago

Thanks for a quick resolution. The patch fixes the issue.