vim-suda
vim-suda copied to clipboard
Cannot retry inputting password
- Create a file owned by root:
sudo touch foo.txt - Open an another terminal (to end the sudo's session)
- Open
vim :Suda foo.txt- Edit something.
:w- Input an incorrect password.
- 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 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?
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/jobstartto read stdin and re-prompt password when stdin got "Sorry, try again." or whatever- It's like re-creating
expectcommand in Vim script. I mean, it's nightmare 💀
- It's like re-creating
- Use
SSH_ASK_PASSWORDenvironment variable to hook the event and tell Vim/Neovim to ask password
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.
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 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.
The retry limit will not be immediately reached if dd is used instead of tee. (#35)
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.