Remove arbitrary restrictions on password length.
authorTom Lane <[email protected]>
Fri, 4 Sep 2020 00:09:18 +0000 (20:09 -0400)
committerTom Lane <[email protected]>
Fri, 4 Sep 2020 00:09:18 +0000 (20:09 -0400)
commit67a472d71c98c3d2fa322a1b4013080b20720b98
tree4b7a6254ec7d2da7f8b36b8eaf645c30a452c92c
parentbe4b0c0077e6a1f7be0965f8d93696e0e0eadb52
Remove arbitrary restrictions on password length.

This  started out with the goal of harmonizing various arbitrary
limits on password length, but after awhile a better idea emerged:
let's just get rid of those fixed limits.

recv_password_packet() has an arbitrary limit on the packet size,
which we don't really need, so just drop it.  (Note that this doesn't
really affect anything for MD5 or SCRAM password verification, since
those will hash the user's password to something shorter anyway.
It does matter for auth methods that require a cleartext password.)

Likewise remove the arbitrary error condition in pg_saslprep().

The remaining limits are mostly in client-side code that prompts
for passwords.  To improve those, refactor simple_prompt() so that
it allocates its own result buffer that can be made as big as
necessary.  Actually, it proves best to make a separate routine
pg_get_line() that has essentially the semantics of fgets(), except
that it allocates a suitable result buffer and hence will never
return a truncated line.  (pg_get_line has a lot of potential
applications to replace randomly-sized fgets buffers elsewhere,
but I'll leave that for another .)

I built pg_get_line() atop stringinfo.c, which requires moving
that code to src/common/; but that seems fine since it was a poor
fit for src/port/ anyway.

This  is mostly mine, but it owes a good deal to Nathan Bossart
who pressed for a solution to the password length problem and
created a predecessor .  Also thanks to Peter Eisentraut and
Stephen Frost for ideas and discussion.

Discussion: https://postgr.es/m/09512C4F-8CB9-4021-B455-EF4C4F0D55A0@amazon.com
21 files changed:
contrib/oid2name/oid2name.c
contrib/vacuumlo/vacuumlo.c
src/backend/libpq/auth.c
src/bin/initdb/initdb.c
src/bin/pg_basebackup/streamutil.c
src/bin/pg_dump/pg_backup_db.c
src/bin/pg_dump/pg_dumpall.c
src/bin/pgbench/pgbench.c
src/bin/psql/command.c
src/bin/psql/startup.c
src/bin/scripts/common.c
src/bin/scripts/createuser.c
src/bin/scripts/dropuser.c
src/common/Makefile
src/common/pg_get_line.c[new file with mode: 0644]
src/common/saslprep.c
src/common/sprompt.c[moved from src/port/sprompt.c with 81% similarity]
src/include/common/string.h
src/include/port.h
src/port/Makefile
src/tools/msvc/Mkvcbuild.pm