Обсуждение: Stop pgpass.conf EOL conversion

Поиск
Список
Период
Сортировка

Stop pgpass.conf EOL conversion

От
Daniel Browning
Дата:
Do you agree with modifying pgAdmin so that it stops converting the EOL 
characters in the pgpass.conf file from unix-style (\n) to Windows-style 
(\r\n)?

It works fine with unix-style line endings, and if the file is in that format 
already, I think it should leave well enough alone.

The reason the issue came up is that I would like to be able to use one pgpass 
file for both Windows applications (pgAdmin, psql under powershell, etc.) and 
cygwin applications (/usr/bin/psql). I created a symlink from the pgpass.conf 
file to .pgpass, and it works perfectly. Until, that is, I launch pgAdmin and 
it adds the Windows carriage returns. Then, cygwin's psql stops working; it 
seems to send the carriage return appended to the end of the password, 
resulting in incorrect password errors.

For now, I can work around the problem by setting the pgpass.conf file to be 
read-only at the filesystem level, forcing pgAdmin to stop updating it. 
Apparently, unix-style EOL chars work everywhere (Windows and cygwin), while 
Windows-style EOL chars only work in Windows. If a user wants Windows-style, 
I'd say we should let them do it themselves with their text editor, not do it 
for them behind the scenes.

You might wonder why I don't just work around the problem by only using the 
Windows version of psql from within cygwin. The answer to that is because it 
hangs under cygwin's mintty. I think it's due to the use of native windows 
console functions, which aren't supported under mintty, as reported here:

http://stackoverflow.com/questions/13731384/

Another workaround would be to programatically generate the pgpass.conf from 
the .pgpass file (or vice-versa), but that involves an extra step of work 
every time the file is edited, just like my current workaround (overriding the 
read-only every time I want to make a change).

I could also just not use cygwin, but as a long-term Linux user, I find that 
when I am forced to use Windows, as in this case, it is significantly easier 
for me to use cygwin than to learn all the Windows-equivalent commandline 
tools, which in many cases do not even exist.

What do you think?
--
DB



Re: Stop pgpass.conf EOL conversion

От
Dave Page
Дата:
Hi

On Thu, Sep 4, 2014 at 11:23 PM, Daniel Browning <db@kavod.com> wrote:
> Do you agree with modifying pgAdmin so that it stops converting the EOL
> characters in the pgpass.conf file from unix-style (\n) to Windows-style
> (\r\n)?
>
> It works fine with unix-style line endings, and if the file is in that format
> already, I think it should leave well enough alone.
>
> The reason the issue came up is that I would like to be able to use one pgpass
> file for both Windows applications (pgAdmin, psql under powershell, etc.) and
> cygwin applications (/usr/bin/psql). I created a symlink from the pgpass.conf
> file to .pgpass, and it works perfectly. Until, that is, I launch pgAdmin and
> it adds the Windows carriage returns. Then, cygwin's psql stops working; it
> seems to send the carriage return appended to the end of the password,
> resulting in incorrect password errors.

The primary reason that file (and others) are written with DOS line
endings is because the default editor on Windows (notepad) can't cope
with *nix style line ends. This is obviously a PITA, as it requires
users to install a better editor (which is arguably a very good idea
anyway, but we don't want to force it on users who may just be setting
up an app on a machine for someone else for example).

> I could also just not use cygwin, but as a long-term Linux user, I find that
> when I am forced to use Windows, as in this case, it is significantly easier
> for me to use cygwin than to learn all the Windows-equivalent commandline
> tools, which in many cases do not even exist.

Have you tried Msys? Not suggesting you should switch, but it would be
interesting to know how it behaves.

> What do you think?

At the moment I'm leaning towards leaving it as-is. I see your
problem, but you're the only person to report it in 12+ years that I
can remember. I suspect the notepad issue would inconvenience far more
users. I suppose we could make it a configurable option.

-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



Re: Stop pgpass.conf EOL conversion

От
Daniel Browning
Дата:
On Friday 05 September 2014 12:57:21 am Dave Page wrote:
> On Thu, Sep 4, 2014 at 11:23 PM, Daniel Browning <db@kavod.com> wrote:
> > Do you agree with modifying pgAdmin so that it stops converting the EOL
> > characters in the pgpass.conf file from unix-style (\n) to Windows-style
> > (\r\n)?
> >
> > It works fine with unix-style line endings, and if the file is in that
> > format already, I think it should leave well enough alone.
> >
> > The reason the issue came up is that I would like to be able to use one
> > pgpass file for both Windows applications (pgAdmin, psql under
> > powershell, etc.) and cygwin applications (/usr/bin/psql). I created a
> > symlink from the pgpass.conf file to .pgpass, and it works perfectly.
> > Until, that is, I launch pgAdmin and it adds the Windows carriage
> > returns. Then, cygwin's psql stops working; it seems to send the carriage
> > return appended to the end of the password, resulting in incorrect
> > password errors.
> 
> The primary reason that file (and others) are written with DOS line
> endings is because the default editor on Windows (notepad) can't cope
> with *nix style line ends.

I can understand that, but how would such a user have ever ended up with a 
file that has unix line-endings anyway?

If they were creating it from scratch, it would have windows EOLs already. If 
they copied the file from another windows developer, it would have them too. 
The only case I can think of where this feature would be useful is in a pretty 
specific set of circumstances:
* A novice user copies a .pgpass file with *nix EOLs from a colleague* He knows to rename it to pgpass.conf and put it
inAppData\Roaming\etc.* When he tries to open it in notepad, it's all wonky and he is confused.* He tries running
PgAdminanyway* PgAdmin fixed the file so it can be opened in notepad* The novice user is thankful for PgAdmin doing
that

To me, that seems like a pretty rare circumstance -- and not really PgAdmin's 
place to be doing that. Now if the user was actually *modifying* the 
pgpass.conf in PgAdmin, I could see some reason behind converting to windows 
EOLs; however, when the file is only being read and not written, it seems like 
converting EOLs is trying to be too helpful.

> This is obviously a PITA, as it requires
> users to install a better editor (which is arguably a very good idea
> anyway, but we don't want to force it on users who may just be setting
> up an app on a machine for someone else for example).

Agreed. My inner pedant would like to point out that technically, they don't 
have to install a better editor, they just need to open the file in Wordpad, 
which is distributed with all versions of windows from at least Windows 95 
through 8.1, and reads files with unix-style line endings. But for some novice 
users, opening a file in a non-default program is probably just as hard as 
installing a new text editor, so your point remains.

> > I could also just not use cygwin, but as a long-term Linux user, I find
> > that when I am forced to use Windows, as in this case, it is
> > significantly easier for me to use cygwin than to learn all the
> > Windows-equivalent commandline tools, which in many cases do not even
> > exist.
> 
> Have you tried Msys? Not suggesting you should switch, but it would be
> interesting to know how it behaves.

I haven't tried it. If I get a chance to, I'll report back.

> > What do you think?
> 
> At the moment I'm leaning towards leaving it as-is. I see your
> problem, but you're the only person to report it in 12+ years that I
> can remember. I suspect the notepad issue would inconvenience far more
> users. I suppose we could make it a configurable option.

Personally, I'd be in favor of a configurable option and a dialog box that 
says something like:

"Your pgpass.conf file was in unix format, so we converted it to Windows 
format for you. If you would like to change this behavior, access the such-
and-such option."
--
DB



Re: Stop pgpass.conf EOL conversion

От
Dave Page
Дата:
pgAdmin writes that file whenever a user successfully logs into a server with a new password for the first time, and opts to save it. If the user then edits the file in notepad (maybe to add new details for a server to use from psql), they'll run into problems.

-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK:http://www.enterprisedb.com
The Enterprise PostgreSQL Company

On 5 Sep 2014, at 20:32, Daniel Browning <db@kavod.com> wrote:

On Friday 05 September 2014 12:57:21 am Dave Page wrote:
On Thu, Sep 4, 2014 at 11:23 PM, Daniel Browning <db@kavod.com> wrote:
Do you agree with modifying pgAdmin so that it stops converting the EOL
characters in the pgpass.conf file from unix-style (\n) to Windows-style
(\r\n)?

It works fine with unix-style line endings, and if the file is in that
format already, I think it should leave well enough alone.

The reason the issue came up is that I would like to be able to use one
pgpass file for both Windows applications (pgAdmin, psql under
powershell, etc.) and cygwin applications (/usr/bin/psql). I created a
symlink from the pgpass.conf file to .pgpass, and it works perfectly.
Until, that is, I launch pgAdmin and it adds the Windows carriage
returns. Then, cygwin's psql stops working; it seems to send the carriage
return appended to the end of the password, resulting in incorrect
password errors.

The primary reason that file (and others) are written with DOS line
endings is because the default editor on Windows (notepad) can't cope
with *nix style line ends.

I can understand that, but how would such a user have ever ended up with a
file that has unix line-endings anyway?

If they were creating it from scratch, it would have windows EOLs already. If
they copied the file from another windows developer, it would have them too.
The only case I can think of where this feature would be useful is in a pretty
specific set of circumstances:

* A novice user copies a .pgpass file with *nix EOLs from a colleague
* He knows to rename it to pgpass.conf and put it in AppData\Roaming\etc.
* When he tries to open it in notepad, it's all wonky and he is confused.
* He tries running PgAdmin anyway
* PgAdmin fixed the file so it can be opened in notepad
* The novice user is thankful for PgAdmin doing that

To me, that seems like a pretty rare circumstance -- and not really PgAdmin's
place to be doing that. Now if the user was actually *modifying* the
pgpass.conf in PgAdmin, I could see some reason behind converting to windows
EOLs; however, when the file is only being read and not written, it seems like
converting EOLs is trying to be too helpful.

This is obviously a PITA, as it requires
users to install a better editor (which is arguably a very good idea
anyway, but we don't want to force it on users who may just be setting
up an app on a machine for someone else for example).

Agreed. My inner pedant would like to point out that technically, they don't
have to install a better editor, they just need to open the file in Wordpad,
which is distributed with all versions of windows from at least Windows 95
through 8.1, and reads files with unix-style line endings. But for some novice
users, opening a file in a non-default program is probably just as hard as
installing a new text editor, so your point remains.

I could also just not use cygwin, but as a long-term Linux user, I find
that when I am forced to use Windows, as in this case, it is
significantly easier for me to use cygwin than to learn all the
Windows-equivalent commandline tools, which in many cases do not even
exist.

Have you tried Msys? Not suggesting you should switch, but it would be
interesting to know how it behaves.

I haven't tried it. If I get a chance to, I'll report back.

What do you think?

At the moment I'm leaning towards leaving it as-is. I see your
problem, but you're the only person to report it in 12+ years that I
can remember. I suspect the notepad issue would inconvenience far more
users. I suppose we could make it a configurable option.

Personally, I'd be in favor of a configurable option and a dialog box that
says something like:

"Your pgpass.conf file was in unix format, so we converted it to Windows
format for you. If you would like to change this behavior, access the such-
and-such option."
--
DB

Re: Stop pgpass.conf EOL conversion

От
Daniel Browning
Дата:
On Friday 05 September 2014 12:38:26 pm Dave Page wrote:
> pgAdmin writes that file whenever a user successfully logs into a server
> with a new password for the first time, and opts to save it.

Ah, that probably explains what happened to me. I had all my passwords already 
setup in pgpass, and every time I connected to a new server, pgAdmin would ask 
me for a password, which of course I left blank because it was already in 
pgpass. After a while of repeatedly hitting enter on the same password dialog 
box, I finally clicked the save password checkbox (with a blank password), and 
it stopped asking me.

So maybe the pgAdmin might just stop updating the pgpass file when a user is 
trying to "save" a blank password?

>  If the user then edits the file in notepad (maybe to add new details for a
>  server to use from psql), they'll run into problems.

I'm fine with pgAdmin converting to Windows EOLs if the user changes or saves 
passwords in pgAdmin. But it seems like there's a place for users who just 
want pgAdmin to read the passwords, not change them or rewrite the file for no 
reason except to change the EOL chars.

--
DB



Re: Stop pgpass.conf EOL conversion

От
Dave Page
Дата:
On Fri, Sep 5, 2014 at 9:55 PM, Daniel Browning <db@kavod.com> wrote:
> On Friday 05 September 2014 12:38:26 pm Dave Page wrote:
>> pgAdmin writes that file whenever a user successfully logs into a server
>> with a new password for the first time, and opts to save it.
>
> Ah, that probably explains what happened to me. I had all my passwords already
> setup in pgpass, and every time I connected to a new server, pgAdmin would ask
> me for a password, which of course I left blank because it was already in
> pgpass. After a while of repeatedly hitting enter on the same password dialog
> box, I finally clicked the save password checkbox (with a blank password), and
> it stopped asking me.
>
> So maybe the pgAdmin might just stop updating the pgpass file when a user is
> trying to "save" a blank password?

I'd have to spend some time to remind myself of the logic around how
this works again exactly (which isn't going to be for a while I doubt,
so you may want to look into it), however, I do remember that it only
saves on successful connection to the server, so it should always have
a useful entry in there.

>>  If the user then edits the file in notepad (maybe to add new details for a
>>  server to use from psql), they'll run into problems.
>
> I'm fine with pgAdmin converting to Windows EOLs if the user changes or saves
> passwords in pgAdmin. But it seems like there's a place for users who just
> want pgAdmin to read the passwords, not change them or rewrite the file for no
> reason except to change the EOL chars.

Well one option would be to have a global option to prevent saving of
passwords at all. That would solve the issue - and they would still be
used if present in the file.

-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company