Bug: ~/.viminfo is unusable if first run was through sudo.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug: ~/.viminfo is unusable if first run was through sudo.

Itay Perl
Hello,

Since by default sudo leaves $HOME unchanged, running 'sudo vim' when
the user does not have a ~/.viminfo file (e.g. first run), will cause
the file to be created in the user's home directory (not in /root),
but owned by root with mode 600 so it is not usable when vim is later
run as a normal user.

A possible fix would be to use getpwuid(3) to retrieve the home
directory, which should be more reliable than $HOME.

Best regards,
Itay

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Bug: ~/.viminfo is unusable if first run was through sudo.

James Vega-3
On Fri, May 21, 2010 at 6:50 AM, ItayP <[hidden email]> wrote:
> Since by default sudo leaves $HOME unchanged, running 'sudo vim' when
> the user does not have a ~/.viminfo file (e.g. first run), will cause
> the file to be created in the user's home directory (not in /root),
> but owned by root with mode 600 so it is not usable when vim is later
> run as a normal user.

This is one reason, among many, that I typically suggest people use
"sudoedit"/"sudo -e".  There are few reasons to run an editor as root if
you're already using sudo.

> A possible fix would be to use getpwuid(3) to retrieve the home
> directory, which should be more reliable than $HOME.

That's a workaround, not a fix.  Any program which is run via sudo,
without passing the -i flag, is going to have $HOME set to the calling
user's homedir instead of that of the user they're sudoing to.  The
proper fix is to educate users to understand this since it affects more
than just Vim.

--
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[hidden email]>

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Bug: ~/.viminfo is unusable if first run was through sudo.

scott-268
On Friday 21 May 2010 10:30:18 am James Vega wrote:

> That's a workaround, not a fix.  Any program which is run via
>  sudo, without passing the -i flag, is going to have $HOME set
>  to the calling user's homedir instead of that of the user
>  they're sudoing to.  The proper fix is to educate users to
>  understand this since it affects more than just Vim.

i took that to mean that i can have

    cd ~/.build/hgvim/vim

as the first line of my install script and i could run it with
sudo

for me, however, i get an error that there is no
/root/.build/hgvim/vim and it can't find my script

i'm using kde 4.3.5 konsole

sc

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Bug: ~/.viminfo is unusable if first run was through sudo.

James Vega-3
On Fri, May 21, 2010 at 12:41 PM, sc <[hidden email]> wrote:

> On Friday 21 May 2010 10:30:18 am James Vega wrote:
>
>> That's a workaround, not a fix.  Any program which is run via
>>  sudo, without passing the -i flag, is going to have $HOME set
>>  to the calling user's homedir instead of that of the user
>>  they're sudoing to.  The proper fix is to educate users to
>>  understand this since it affects more than just Vim.
>
> i took that to mean that i can have
>
>    cd ~/.build/hgvim/vim
>
> as the first line of my install script and i could run it with
> sudo
>
> for me, however, i get an error that there is no
> /root/.build/hgvim/vim and it can't find my script

You're not using the $HOME environment variable.  You're using ~, which
your shell interprets based on the effective user that it is running as,
similar to what the OP suggested.

I was specifically talking about the case of relying on the $HOME
environment variable, which is what Vim uses to decide where to place
the viminfo file.

--
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[hidden email]>

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php