vim-suda icon indicating copy to clipboard operation
vim-suda copied to clipboard

Cannot retry inputting password

Open thinca opened this issue 5 years ago • 6 comments

  1. Create a file owned by root: sudo touch foo.txt
  2. Open an another terminal (to end the sudo's session)
  3. Open vim
  4. :Suda foo.txt
  5. Edit something.
  6. :w
  7. Input an incorrect password.
  8. Error occurs without retry.
Password: ***Error detected while processing BufWriteCmd Autocommands for "suda://*"..function suda#BufWriteCmd[14]..BufWriteCmd Autocommands for "suda://*"..function suda#BufWriteCmd[3]..suda#write:
line   33:
E605: Exception not caught: Sorry, try again.^@Sorry, try again.^@^@sudo: no password was provided^@sudo: 2 incorrect password attempts^@

At this time, suda.vim inputs incorrect password severary. (See the error message.)

thinca avatar Sep 10 '20 02:09 thinca

@thinca I have encountered the same problem, even if I reopen the file and input the correct password it won't work. I have to reboot to be able to use suda again. Is there a fix yet?

BrachyKnight avatar Sep 16 '20 16:09 BrachyKnight

OK. This is quite difficult 💀

This is caused by that sudo asking password several times when users continue inputting wrong passwords (and then may lock.) While suda.vim provides password through stdin by system function, suda.vim cannot stop sudo asking password several times. It could be fixed if there is any options to stop asking passwords when the first one is wrong but I could not find any options for that. Thus, the issue will never be solved if suda.vim use the current implementation.

So what we need to do is one of the below:

  • Use job_start/jobstart to read stdin and re-prompt password when stdin got "Sorry, try again." or whatever
    • It's like re-creating expect command in Vim script. I mean, it's nightmare 💀
  • Use SSH_ASK_PASSWORD environment variable to hook the event and tell Vim/Neovim to ask password
    • Similar to what edita.vim does but use prompt instead of buffer
    • Neovim provides RPC thus it's possible 👍
    • Vim does NOT provide a way to listen to external events thus we need to make it. I mean, it's nightmare 💀
      • The PR for ch_listen would solve this problem

So I could not find any way without a nightmare 💀 Probably we should help the https://github.com/vim/vim/pull/3639 so that we can use ch_listen to make a listener for external events in Vim script.

lambdalisue avatar Sep 19 '20 08:09 lambdalisue

Not sure if it's related, but it seems to somehow break sudo.

Follow the initial steps to reproduce, but then open a new shell and then try sudo su, enter the correct password, but you'll be given an error that the password is incorrect.

aarobc avatar Oct 07 '20 15:10 aarobc

@aarobc It's related, please read https://github.com/lambdalisue/suda.vim/issues/34#issuecomment-695187058. The problem is, if I'm understanding it correctly, that sudo continously asks suda.vim for a password via stdin. Once you've entered a wrong password you will hit your retry limit for sudo, and be locked out of sudo for a couple of minutes.

sQVe avatar Oct 08 '20 06:10 sQVe

The retry limit will not be immediately reached if dd is used instead of tee. (#35)

zeertzjq avatar Feb 17 '21 05:02 zeertzjq

Use SSH_ASK_PASSWORD environment variable to hook the event and tell Vim/Neovim to ask password

Finally, I've got that work like https://github.com/lambdalisue/askpass.vim

But above require extra dependency which user might not want so maybe I'll create a new suda.vim which relies on denops.vim to handle this kind of issue.

lambdalisue avatar Sep 01 '21 00:09 lambdalisue