Commit Graph

491 Commits

Author SHA1 Message Date
Robert Haas 3b5548a3d5 When using libpq URI syntax, error out on invalid parameter names.
Dan Farina
2012-06-08 08:47:24 -04:00
Peter Eisentraut 2d612abd4d libpq: URI parsing fixes
Drop special handling of host component with slashes to mean
Unix-domain socket.  Specify it as separate parameter or using
percent-encoding now.

Allow omitting username, password, and port even if the corresponding
designators are present in URI.

Handle percent-encoding in query parameter keywords.

Alex Shulgin

some documentation improvements by myself
2012-05-28 22:44:34 +03:00
Alvaro Herrera b035cb9db7 Accept postgres:// URIs in libpq connection functions
postgres:// URIs are an attempt to "stop the bleeding" in this general
area that has been said to occur due to external projects adopting their
own syntaxes.  The syntaxes supported by this patch:

 postgres://[user[:pwd]@][unix-socket][:port[/dbname]][?param1=value1&...]
 postgres://[user[:pwd]@][net-location][:port][/dbname][?param1=value1&...]

should be enough to cover most interesting cases without having to
resort to "param=value" pairs, but those are provided for the cases that
need them regardless.

libpq documentation has been shuffled around a bit, to avoid stuffing
all the format details into the PQconnectdbParams description, which was
already a bit overwhelming.  The list of keywords has moved to its own
subsection, and the details on the URI format live in another subsection.

This includes a simple test program, as requested in discussion, to
ensure that interesting corner cases continue to work appropriately in
the future.

Author: Alexander Shulgin
Some tweaking by Álvaro Herrera, Greg Smith, Daniel Farina, Peter Eisentraut
Reviewed by Robert Haas, Alexey Klyukin (offlist), Heikki Linnakangas,
Marko Kreen, and others

Oh, it also supports postgresql:// but that's probably just an accident.
2012-04-11 04:33:51 -03:00
Tom Lane 92785dac2e Add a "row processor" API to libpq for better handling of large results.
Traditionally libpq has collected an entire query result before passing
it back to the application.  That provides a simple and transactional API,
but it's pretty inefficient for large result sets.  This patch allows the
application to process each row on-the-fly instead of accumulating the
rows into the PGresult.  Error recovery becomes a bit more complex, but
often that tradeoff is well worth making.

Kyotaro Horiguchi, reviewed by Marko Kreen and Tom Lane
2012-04-04 18:27:56 -04:00
Tom Lane e9ce658b62 Refactor to eliminate duplicate copies of conninfo default-finding code.
Alex Shulgin, lightly edited by me
2012-03-22 12:08:34 -04:00
Peter Eisentraut d4318483e1 libpq: Fix minor memory leaks
When using connection info arrays with a conninfo string in the dbname
slot, some memory would be leaked if an error occurred while
processing the following array slots.

found by Coverity
2012-03-16 20:35:00 +02:00
Peter Eisentraut f9325df0fc libpq: Fix memory leak
If a client encoding is specified as a connection parameter (or
environment variable), internal storage allocated for it would never
be freed.
2012-03-07 23:35:03 +02:00
Magnus Hagander 21238deea5 Properly free the sslcompression field in PGconn
Marko Kreen
2012-02-01 16:51:35 +01:00
Bruce Momjian e126958c2e Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
Robert Haas 8d15e3ec4f Don't forget to de-escape the password field in .pgpass.
This has been broken just about forever (or more specifically, commit
7f4981f4af) and nobody noticed until
Richard Huxton reported it recently.  Analysis and fix by Ross
Reedstrom, although I didn't use his patch.  This doesn't seem
important enough to back-patch and is mildly backward incompatible, so
I'm just doing this in master.
2011-12-22 13:02:57 -05:00
Magnus Hagander 64aea1ebc7 Add libpq connection option to disable SSL compression
This can be used to remove the overhead of SSL compression on
fast networks.

Laurenz Albe
2011-11-28 13:13:42 +01:00
Tom Lane e331c60ea7 Suppress remaining -Waddress warnings from recent gcc versions.
Still an exercise in satisfying pedants.
2011-10-18 21:44:23 -04:00
Tom Lane 2a571bc233 Fully const-ify PQconnectdbParams, PQconnectStartParams, and PQpingParams.
The keywords and values arguments of these functions are more properly
declared "const char * const *" than just "const char **".

Lionel Elie Mamane, reviewed by Craig Ringer
2011-09-25 18:52:48 -04:00
Tom Lane a49fbaaf8d Don't assume that "E" response to NEGOTIATE_SSL_CODE means pre-7.0 server.
These days, such a response is far more likely to signify a server-side
problem, such as fork failure.  Reporting "server does not support SSL"
(in sslmode=require) could be quite misleading.  But the results could
be even worse in sslmode=prefer: if the problem was transient and the
next connection attempt succeeds, we'll have silently fallen back to
protocol version 2.0, possibly disabling features the user needs.

Hence, it seems best to just eliminate the assumption that backing off
to non-SSL/2.0 protocol is the way to recover from an "E" response, and
instead treat the server error the same as we would in non-SSL cases.

I tested this change against a pre-7.0 server, and found that there
was a second logic bug in the "prefer" path: the test to decide whether
to make a fallback connection attempt assumed that we must have opened
conn->ssl, which in fact does not happen given an "E" response.  After
fixing that, the code does indeed connect successfully to pre-7.0,
as long as you didn't set sslmode=require.  (If you did, you get
"Unsupported frontend protocol", which isn't completely off base
given the server certainly doesn't support SSL.)

Since there seems no reason to believe that pre-7.0 servers exist anymore
in the wild, back-patch to all supported branches.
2011-08-27 16:37:58 -04:00
Tom Lane 724e30c9f8 Ensure we discard unread/unsent data when abandoning a connection attempt.
There are assorted situations wherein PQconnectPoll() will abandon a
connection attempt and try again with different parameters (eg, SSL versus
not SSL).  However, the code forgot to discard any pending data in libpq's
I/O buffers when doing this.  In at least one case (server returns E
message during SSL negotiation), there is unread input data which bollixes
the next connection attempt.  I have not checked to see whether this is
possible in the other cases where we close the socket and retry, but it
seems like a matter of good defensive programming to add explicit
buffer-flushing code to all of them.

This is one of several issues exposed by Daniel Farina's report of
misbehavior after a server-side fork failure.

This has been wrong since forever, so back-patch to all supported branches.
2011-08-27 14:16:14 -04:00
Peter Eisentraut ce8d7bb644 Replace printf format %i by %d
They are identical, but the overwhelming majority of the code uses %d,
so standardize on that.
2011-07-26 22:54:29 +03:00
Bruce Momjian 6560407c7d Pgindent run before 9.1 beta2. 2011-06-09 14:32:50 -04:00
Tom Lane 3980f7fc6e Implement getpeereid() as a src/port compatibility function.
This unifies a bunch of ugly #ifdef's in one place.  Per discussion,
we only need this where HAVE_UNIX_SOCKETS, so no need to cover Windows.

Marko Kreen, some adjustment by Tom Lane
2011-06-02 13:05:01 -04:00
Tom Lane be4585b1c2 Replace use of credential control messages with getsockopt(LOCAL_PEERCRED).
It turns out the reason we hadn't found out about the portability issues
with our credential-control-message code is that almost no modern platforms
use that code at all; the ones that used to need it now offer getpeereid(),
which we choose first.  The last holdout was NetBSD, and they added
getpeereid() as of 5.0.  So far as I can tell, the only live platform on
which that code was being exercised was Debian/kFreeBSD, ie, FreeBSD kernel
with Linux userland --- since glibc doesn't provide getpeereid(), we fell
back to the control message code.  However, the FreeBSD kernel provides a
LOCAL_PEERCRED socket parameter that's functionally equivalent to Linux's
SO_PEERCRED.  That is both much simpler to use than control messages, and
superior because it doesn't require receiving a message from the other end
at just the right time.

Therefore, add code to use LOCAL_PEERCRED when necessary, and rip out all
the credential-control-message code in the backend.  (libpq still has such
code so that it can still talk to pre-9.1 servers ... but eventually we can
get rid of it there too.)  Clean up related autoconf probes, too.

This means that libpq's requirepeer parameter now works on exactly the same
platforms where the backend supports peer authentication, so adjust the
documentation accordingly.
2011-05-31 16:10:46 -04:00
Peter Eisentraut fcd4575905 Fix untranslatable assembly of libpq connection failure message
Even though this only affects the insertion of a parenthesized word,
it's unwise to assume that parentheses can pass through untranslated.
And in any case, the new version is clearer in the code and for
translators.
2011-05-19 22:56:53 +03:00
Tom Lane 8d0df2048f Fix write-past-buffer-end in ldapServiceLookup().
The code to assemble ldap_get_values_len's output into a single string
wrote the terminating null one byte past where it should.  Fix that,
and make some other cosmetic adjustments to make the code a trifle more
readable and more in line with usual Postgres coding style.

Also, free the "result" string when done with it, to avoid a permanent
memory leak.

Bug report and patch by Albe Laurenz, cosmetic adjustments by me.
2011-05-12 11:56:38 -04:00
Heikki Linnakangas a7cb69a5a3 Silence compiler warning about unused variable on Windows. 2011-04-19 14:55:26 +03:00
Bruce Momjian bf50caf105 pgindent run before PG 9.1 beta 1. 2011-04-10 11:42:00 -04:00
Tom Lane d518d6a168 Fix typo in PQconnectStartParams().
This would lead to leaking the PGconn structure after an error detected by
conninfo_array_parse(), as well as failing to return a useful error message
in such cases.  Backpatch to 9.0 where the error was introduced.

Joseph Adams
2011-04-02 18:05:42 -04:00
Tom Lane 775464e845 Add missing "static" marker to internal_ping().
Per testing with a compiler that doesn't like that.
2011-03-06 20:04:29 -05:00
Peter Eisentraut 02e14562a8 Set psql client encoding from locale by default
Add a new libpq connection option client_encoding (which includes the
existing PGCLIENTENCODING environment variable), which besides an
encoding name accepts a special value "auto" that tries to determine
the encoding from the locale in the client's environment, using the
mechanisms that have been in use in initdb.

psql sets this new connection option to "auto" when running from a
terminal and not overridden by setting PGCLIENTENCODING.

original code by Heikki Linnakangas, with subsequent contributions by
Jaime Casanova, Peter Eisentraut, Stephen Frost, Ibrar Ahmed
2011-02-19 08:54:58 +02:00
Bruce Momjian 5d950e3b0c Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
Bruce Momjian 7e95337d58 Properly print the IP number and "localhost" for failed localhost
connections when the server is down, on Win32.
2010-12-18 11:26:17 -05:00
Bruce Momjian 48da2b87e3 Fix crash caused by NULL lookup when reporting IP address of failed
libpq connection, per report from Magnus.  This happens only on GIT
master and only on Win32 because that is the platform where "" maps to
an IP address (localhost).
2010-12-16 10:13:43 -05:00
Tom Lane 49cd8a3f81 On further testing, PQping also needs an explicit check for AUTH_REQ.
The pg_fe_sendauth code might fail if it can't handle the authentication
request message type --- if so, ping should still say the server is up.
2010-11-27 02:11:45 -05:00
Tom Lane db96e1ccfc Rewrite PQping to be more like what we agreed to last week.
Basically, we want to distinguish all cases where the connection was
not made from those where it was.  A convenient proxy for this is to
see if we got a message with a SQLSTATE code back from the postmaster.
This presumes that the postmaster will always send us a SQLSTATE in
a failure message, which is true for 7.4 and later postmasters in
every case except fork failure.  (We could possibly complicate the
postmaster code to do something about that, but it seems not worth
the trouble, especially since pg_ctl's response for that case should
be to keep waiting anyway.)

If we did get a SQLSTATE from the postmaster, there are basically only
two cases, as per last week's discussion: ERRCODE_CANNOT_CONNECT_NOW
and everything else.  Any other error code implies that the postmaster
is in principle willing to accept connections, it just didn't like or
couldn't handle this particular request.  We want to make a special
case for ERRCODE_CANNOT_CONNECT_NOW so that "pg_ctl start -w" knows
it should keep waiting.

In passing, pick names for the enum constants that are a tad less
likely to present collision hazards in future.
2010-11-27 01:30:34 -05:00
Tom Lane be3b666eb8 Clean up IPv4 vs IPv6 bogosity in connectFailureMessage().
Newly added code was supposing that "struct sockaddr_in" applies to IPv6.
2010-11-26 19:16:39 -05:00
Bruce Momjian f2eba413db Use conn->raddr consistently for non-connect libpq error reporting. 2010-11-26 13:26:13 -05:00
Bruce Momjian bad8277f13 Update comment that says we only report last libpq connection failure,
per Peter.
2010-11-26 11:52:03 -05:00
Bruce Momjian ed51bd4968 Use only addr_cur when reporting connection failures in libpq. 2010-11-26 11:49:35 -05:00
Bruce Momjian afd7d9adca Add PQping and PQpingParams to libpq to allow detection of the server's
status, including a status where the server is running but refuses a
postgres connection.

Have pg_ctl use this new function.  This fixes the case where pg_ctl
reports that the server is not running (cannot connect) but in fact it
is running.
2010-11-25 13:09:38 -05:00
Bruce Momjian ba11258ccb When reporting the server as not responding, if the hostname was
supplied, also print the IP address.  This allows IPv4 and IPv6 failures
to be distinguished.  Also useful when a hostname resolves to multiple
IP addresses.

Also, remove use of inet_ntoa() and use our own inet_net_ntop() in all
places, including in libpq, because it is thread-safe.
2010-11-24 17:04:19 -05:00
Magnus Hagander 9f2e211386 Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
Peter Eisentraut 0b4a0868f9 Portability fixes for Solaris for requirepeer feature patch
per report from Dave Page
2010-07-19 18:53:25 +00:00
Tom Lane 1b51018afc Fix up poor handling of unsupported-platform case in requirepeer patch. 2010-07-18 17:08:11 +00:00
Tom Lane 25241aee60 Fix thinko in recent patch: 'sock' should be 'conn->sock'. 2010-07-18 16:42:20 +00:00
Bruce Momjian 9c5ea833a0 Add SO_PEERCRED check in new unix domain socket permission checking code. 2010-07-18 15:51:00 +00:00
Peter Eisentraut 040aee295e Add server authentication over Unix-domain sockets
This adds a libpq connection parameter requirepeer that specifies the user
name that the server process is expected to run under.

reviewed by KaiGai Kohei
2010-07-18 11:37:26 +00:00
Magnus Hagander a64bf0afb7 Make the Windows tcp keepalive support depend on the existance of the
SIO_KEEPALIVE_VALS define instead of just WIN32, since MingW doesn't
support this API (yet?).
2010-07-08 16:19:50 +00:00
Magnus Hagander 44b0d1671a Add support for TCP keepalives on Windows, both for backend and the new
libpq support.
2010-07-08 10:20:14 +00:00
Robert Haas 5acd417c8f Support setting the keepalive idle time on MacOS X.
MacOS X uses TCP_KEEPALIVE rather than TCP_KEEPIDLE for this purpose.

Thanks to Fujii Masao for the review.
2010-07-06 21:14:25 +00:00
Bruce Momjian 239d769e7e pgindent run for 9.0, second run 2010-07-06 19:19:02 +00:00
Robert Haas d8cd283a08 Add TCP keepalive support to libpq.
This adds four additional connection parameters to libpq: keepalives,
keepalives_idle, keepalives_count, and keepalives_interval.
keepalives default to on, per discussion, but can be turned off by
specifying keepalives=0.  The remaining parameters, where supported,
can be used to adjust how often keepalives are sent and how many
can be lost before the connection is broken.

The immediate motivation for this patch is to make sure that
walreceiver will eventually notice if the master reboots without
closing the connection cleanly, but it should be helpful in other
cases as well.

Tollef Fog Heen, Fujii Masao, and me.
2010-06-23 21:54:13 +00:00
Tom Lane 4ed4b6c54e Rearrange libpq's SSL initialization to simplify it and make it handle some
additional cases correctly.  The original coding failed to load additional
(chain) certificates from the client cert file, meaning that indirectly signed
client certificates didn't work unless one hacked the server's root.crt file
to include intermediate CAs (not the desired approach).  Another problem was
that everything got loaded into the shared SSL_context object, which meant
that concurrent connections trying to use different sslcert settings could
well fail due to conflicting over the single available slot for a keyed
certificate.

To fix, get rid of the use of SSL_CTX_set_client_cert_cb(), which is
deprecated anyway in the OpenSSL documentation, and instead just
unconditionally load the client cert and private key during connection
initialization.  This lets us use SSL_CTX_use_certificate_chain_file(),
which does the right thing with additional certs, and is lots simpler than
the previous hacking about with BIO-level access.  A small disadvantage is
that we have to load the primary client cert a second time with
SSL_use_certificate_file, so that that one ends up in the correct slot
within the connection's SSL object where it can get paired with the key.
Given the other overhead of making an SSL connection, that doesn't seem
worth worrying about.

Per discussion ensuing from bug #5468.
2010-05-26 21:39:27 +00:00
Tom Lane 0954358047 Fix a couple of places where the result of fgets() wasn't checked.
This is mostly to suppress compiler warnings, although in principle
the cases could result in undesirable behavior.

Martin Pitt
2010-04-30 17:09:13 +00:00
Peter Eisentraut 2fb605ec76 Fix peculiar, untranslatable message concatenation attempt 2010-03-17 20:58:38 +00:00
Bruce Momjian a6c1cea2b7 Add libpq warning message if the .pgpass-retrieved password fails.
Add ERRCODE_INVALID_PASSWORD sqlstate error code.
2010-03-13 14:55:57 +00:00
Tom Lane 61d75116a7 Fix a couple of places that would loop forever if attempts to read a stdio file
set ferror() but never set feof().  This is known to be the case for recent
glibc when trying to read a directory as a file, and might be true for other
platforms/cases too.  Per report from Ed L.  (There is more that we ought to
do about his report, but this is one easily identifiable issue.)
2010-03-03 20:31:09 +00:00
Bruce Momjian 65e806cba1 pgindent run for 9.0 2010-02-26 02:01:40 +00:00
Tom Lane 50a90fac40 Stamp HEAD as 9.0devel, and update various places that were referring to 8.5
(hope I got 'em all).  Per discussion, this release will be 9.0 not 8.5.
2010-02-17 04:19:41 +00:00
Joe Conway f419a82c70 Modify recently added PQconnectdbParams() with new argument, expand_dbname.
If expand_dbname is non-zero and dbname contains an = sign, it is taken as
a conninfo string in exactly the same way as if it had been passed to
PQconnectdb. This is equivalent to the way PQsetdbLogin() works, allowing
PQconnectdbParams() to be a complete alternative.

Also improve the way the new function is called from psql and replace a
previously missed call to PQsetdbLogin() in psql. Additionally use
PQconnectdbParams() for pg_dump and friends, and the bin/scripts
command line utilities such as vacuumdb, createdb, etc.

Finally, update the documentation for the new parameter, as well as the
nuances of precedence in cases where key words are repeated or duplicated
in the conninfo string.
2010-02-05 03:09:05 +00:00
Joe Conway e3f36838e5 Introduce two new libpq connection functions, PQconnectdbParams and
PQconnectStartParams. These are analogous to PQconnectdb and PQconnectStart
respectively. They differ from the legacy functions in that they accept
two NULL-terminated arrays, keywords and values, rather than conninfo
strings. This avoids the need to build the conninfo string in cases
where it might be inconvenient to do so. Includes documentation.

Also modify psql to utilize PQconnectdbParams rather than PQsetdbLogin.
This allows the new config parameter application_name to be set, which
in turn is displayed in the pg_stat_activity view and included in CSV
log entries. This will also ensure both new functions get regularly
exercised.

Patch by Guillaume Lelarge with review and minor adjustments by
Joe Conway.
2010-01-28 06:28:26 +00:00
Peter Eisentraut 41a4e45957 Add user-specific .pg_service.conf file
This extends the existing pg_service.conf facility to first look for a
service definition file in the user's home directory.
2010-01-20 21:15:21 +00:00
Heikki Linnakangas 40f908bdcd Introduce Streaming Replication.
This includes two new kinds of postmaster processes, walsenders and
walreceiver. Walreceiver is responsible for connecting to the primary server
and streaming WAL to disk, while walsender runs in the primary server and
streams WAL from disk to the client.

Documentation still needs work, but the basics are there. We will probably
pull the replication section to a new chapter later on, as well as the
sections describing file-based replication. But let's do that as a separate
patch, so that it's easier to see what has been added/changed. This patch
also adds a new section to the chapter about FE/BE protocol, documenting the
protocol used by walsender/walreceivxer.

Bump catalog version because of two new functions,
pg_last_xlog_receive_location() and pg_last_xlog_replay_location(), for
monitoring the progress of replication.

Fujii Masao, with additional hacking by me
2010-01-15 09:19:10 +00:00
Bruce Momjian 0239800893 Update copyright for the year 2010. 2010-01-02 16:58:17 +00:00
Tom Lane 3dfcf8cc15 Instead of sending application_name as a SET command after the connection
is made, include it in the startup-packet options.  This makes it work more
like every other libpq connection option, in particular it now has the same
response to RESET ALL as the rest.  This also saves one network round trip
for new applications using application_name.  The cost is that if the server
is pre-8.5, it'll reject the startup packet altogether, forcing us to retry
the entire connection cycle.  But on balance we shouldn't be optimizing that
case in preference to the behavior with a new server, especially when doing
so creates visible behavioral oddities.  Per discussion.
2009-12-02 04:38:35 +00:00
Peter Eisentraut 22032820f9 Error when a specified connection service is not found, instead of ignoring it 2009-11-29 20:14:53 +00:00
Peter Eisentraut e527d5010b Remove prefix "ERROR:" from some messages, to make everything consistent 2009-11-29 18:53:44 +00:00
Tom Lane 8217cfbd99 Add support for an application_name parameter, which is displayed in
pg_stat_activity and recorded in log entries.

Dave Page, reviewed by Andres Freund
2009-11-28 23:38:08 +00:00
Tom Lane 61be11ff08 Make libpq reject non-numeric and out-of-range port numbers with a suitable
error message, rather than blundering on and failing with something opaque.

Sam Mason
2009-09-27 03:43:10 +00:00
Tom Lane cea80e726e Avoid extra system calls to block SIGPIPE if the platform provides either
sockopt(SO_NOSIGPIPE) or the MSG_NOSIGNAL flag to send().

We assume these features are available if (1) the symbol is defined at
compile time and (2) the kernel doesn't reject the call at runtime.
It might turn out that there are some platforms where (1) and (2) are
true and yet the signal isn't really blocked, in which case applications
would die on server crash.  If that sort of thing gets reported, then
we'll have to add additional defenses of some kind.

Jeremy Kerr
2009-07-24 17:58:31 +00:00
Bruce Momjian d747140279 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list
provided by Andrew.
2009-06-11 14:49:15 +00:00
Tom Lane 2c39ab12f3 Make pwdfMatchesString() a little more careful about matching * fields. 2009-05-18 16:15:22 +00:00
Magnus Hagander e883d0b551 Remove sslverify parameter again, replacing it with two new sslmode values:
"verify-ca" and "verify-full".

Since "prefer" remains the default, this will make certificate validation
off by default, which should lead to less upgrade issues.
2009-04-24 09:43:10 +00:00
Bruce Momjian 511db38ace Update copyright for 2009. 2009-01-01 17:24:05 +00:00
Magnus Hagander 5f3724dd7c Support specifying filename for SSL certificate, key, root certificate store
and certificate revokation list by using connection parameters or environment
variables.

Original patch by Mark Woodward, heavily reworked by Alvaro Herrera and
Magnus Hagander.
2008-12-15 10:28:22 +00:00
Tom Lane 739259d62e Adjust the behavior of the PQExpBuffer code to make it have well-defined
results (ie, an empty "broken" buffer) if memory overrun occurs anywhere
along the way to filling the buffer.  The previous coding would just silently
discard portions of the intended buffer contents, as exhibited in trouble
report from Sam Mason.  Also, tweak psql's main loop to correctly detect
and report such overruns.  There's probably much more that should be done
in this line, but this is a start.
2008-11-26 00:26:23 +00:00
Tom Lane 1304f297a4 Remove PGINTERVALSTYLE from the set of special environment variables for
libpq.  As noted by Peter, adding this variable created a risk of unexpected
connection failures when talking to older server versions, and since it
doesn't do anything you can't do with PGOPTIONS, it doesn't seem really
necessary.  Removing it does occasion a few extra lines in pg_regress.c,
but saving a getenv() call per libpq connection attempt is perhaps worth
that anyway.
2008-11-25 19:30:42 +00:00
Magnus Hagander c89404edf3 Fix libpq certificate validation for SSL connections.
Add config parameter "sslverify" to control the verification. Default
is to do full verification.

Clean up some old SSL code that never really worked.
2008-11-13 09:45:25 +00:00
Tom Lane df7641e25a Add a new GUC variable called "IntervalStyle" that decouples interval output
from DateStyle, and create a new interval style that produces output matching
the SQL standard (at least for interval values that fall within the standard's
restrictions).  IntervalStyle is also used to resolve the conflict between the
standard and traditional Postgres rules for interpreting negative interval
input.

Ron Mayer
2008-11-09 00:28:35 +00:00
Magnus Hagander 5e75a5dca9 Fix incorrect comment in SSL code 2008-11-03 14:18:57 +00:00
Magnus Hagander 53a5026b5c Remove support for (insecure) crypt authentication.
This breaks compatibility with pre-7.2 versions.
2008-10-28 12:10:44 +00:00
Magnus Hagander f3a0688ace Add support for multiple error messages from libpq, by simply appending them
after each other (since we already add a newline on each, this makes them
multiline).

Previously a new error would just overwrite the old one, so for example any
error caused when trying to connect with SSL enabled would be overwritten
by the error message form the non-SSL connection when using sslmode=prefer.
2008-10-27 09:42:31 +00:00
Magnus Hagander 501e58ba4e Fix memory leak when using gsslib parameter in libpq connections 2008-10-23 16:17:19 +00:00
Tom Lane c52aab5525 Get rid of pgpass_from_client tracking inside libpq --- given the conclusion
that presence of the password in the conninfo string must be checked *before*
risking a connection attempt, there is no point in checking it afterwards.
This makes the specification of PQconnectionUsedPassword() a bit simpler
and perhaps more generally useful, too.
2008-09-22 14:21:44 +00:00
Tom Lane cae7ad906a Fix dblink_connect() so that it verifies that a password is supplied in the
conninfo string *before* trying to connect to the remote server, not after.
As pointed out by Marko Kreen, in certain not-very-plausible situations
this could result in sending a password from the postgres user's .pgpass file,
or other places that non-superusers shouldn't have access to, to an
untrustworthy remote server.  The cleanest fix seems to be to expose libpq's
conninfo-string-parsing code so that dblink can check for a password option
without duplicating the parsing logic.

Joe Conway, with a little cleanup by Tom Lane
2008-09-22 13:55:14 +00:00
Tom Lane 32f159cc55 Add an "events" system to libpq, whereby applications can get callbacks that
enable them to manage private data associated with PGconns and PGresults.

Andrew Chernow and Merlin Moncure
2008-09-17 04:31:08 +00:00
Tom Lane 02ac305405 Tweak libpq to avoid crashing due to incorrect buffer size calculation when
we are on a 64-bit machine (ie, size_t is wider than int) and someone passes
in a query string that approaches or exceeds INT_MAX bytes.  Also, just for
paranoia's sake, guard against similar overflows in sizing the input buffer.

The backend will not in the foreseeable future be prepared to send or receive
strings exceeding 1GB, so I didn't take the more invasive step of switching
all the buffer index variables from int to size_t; though someday we might
want to do that.

I have a suspicion that this is not the only such bug in libpq, but this
fix is enough to take care of the crash reported by Francisco Reyes.
2008-05-29 22:02:44 +00:00
Magnus Hagander 1d89026788 Implement error checking for pthreads calls in thread-safe mode. They really
should always succeed, but in the likely event of a failure we would
previously fall through *without locking* - the new code will exit(1).

Printing the error message on stderr will not work for all applications, but
it's better than nothing at all - and our API doesn't provide a way to return
the error to the caller.
2008-05-16 18:30:53 +00:00
Tom Lane 3405f2b925 Use error message wordings for permissions checks on .pgpass and SSL private
key files that are similar to the one for the postmaster's data directory
permissions check.  (I chose to standardize on that one since it's the most
heavily used and presumably best-wordsmithed by now.)  Also eliminate explicit
tests on file ownership in these places, since the ensuing read attempt must
fail anyway if it's wrong, and there seems no value in issuing the same error
message for distinct problems.  (But I left in the explicit ownership test in
postmaster.c, since it had its own error message anyway.)  Also be more
specific in the documentation's descriptions of these checks.  Per a gripe
from Kevin Hunter.
2008-03-31 02:43:14 +00:00
Tom Lane 5037ed834d Fix up closePGconn() so that PQreset() will work on GSSAPI/SSPI connections;
the patch for those features put its cleanup code into freePGconn() which is
really the wrong place.  Remove redundant code from freePGconn() and add
comments in hopes of preventing similar mistakes in future.
Noticed while trying (futilely) to reproduce bug #3902.
2008-01-29 02:06:30 +00:00
Bruce Momjian 9098ab9e32 Update copyrights in source tree to 2008. 2008-01-01 19:46:01 +00:00
Tom Lane 4f9bf7fc5a Fix up the PQconnectionUsedPassword mess: create a separate
PQconnectionNeedsPassword function that tells the right thing for whether to
prompt for a password, and improve PQconnectionUsedPassword so that it checks
whether the password used by the connection was actually supplied as a
connection argument, instead of coming from environment or a password file.
Per bug report from Mark Cave-Ayland and subsequent discussion.
2007-12-09 19:01:40 +00:00
Bruce Momjian fdf5a5efb7 pgindent run for 8.3. 2007-11-15 21:14:46 +00:00
Magnus Hagander 20c38514b4 Don't try to free pgpassfile since it's a stack variable.
Martin Pitt
2007-10-09 15:03:27 +00:00
Magnus Hagander 29ac718f47 Use PQExpBuffer for error message in fe-auth.c.
In passing, change functions that passedin both PGconn and
parts of it to just pass in the PGconn.
2007-07-23 17:52:06 +00:00
Magnus Hagander f70866fb23 SSPI authentication on Windows. GSSAPI compatible client when doing Kerberos
against a Unix server, and Windows-specific server-side authentication
using SSPI "negotiate" method (Kerberos or NTLM).

Only builds properly with MSVC for now.
2007-07-23 10:16:54 +00:00
Magnus Hagander 31013db0a1 A bunch of GSSAPI fixes per comments from Tom:
* use elog not ereport for debug
* fix debug levels for some output
* properly check for memory allocation errors in a couple of missed places
2007-07-11 08:27:33 +00:00
Magnus Hagander 6160106c74 Add support for GSSAPI authentication.
Documentation still being written, will be committed later.

Henry B. Hotz and Magnus Hagander
2007-07-10 13:14:22 +00:00
Tom Lane 5f7b1f8d9d Closer code review for PQconnectionUsedPassword() patch: in particular,
not OK to include postgres_fe.h into libpq-fe.h, hence declare it as
returning int not bool.
2007-07-08 18:28:56 +00:00
Joe Conway 51bc3dfe4b Arrange for the authentication request type to be preserved in
PGconn. Invent a new libpq connection-status function,
PQconnectionUsedPassword() that returns true if the server
demanded a password during authentication, false otherwise.
This may be useful to clients in general, but is immediately
useful to help plug a privilege escalation path in dblink.
Per list discussion and design proposed by Tom Lane.
2007-07-08 17:11:51 +00:00
Magnus Hagander c0aa50630b Remove unsafe calling of WSAStartup and WSACleanup from DllMain. Move the
inline cleanup call around so it will be called in the right order, and
be called on errors.

Per report from Tokuharu Yuzawa.
2007-03-08 19:27:28 +00:00
Bruce Momjian 2d848857ee Add comment that on Win32, we don't need to check the .pgpass file
permission, per Magnus.
2007-02-20 15:20:51 +00:00
Peter Eisentraut 4ab8fcba8a StrNCpy -> strlcpy (not complete) 2007-02-10 14:58:55 +00:00
Peter Eisentraut 086c189456 Normalize fgets() calls to use sizeof() for calculating the buffer size
where possible, and fix some sites that apparently thought that fgets()
will overwrite the buffer by one byte.

Also add some strlcpy() to eliminate some weird memory handling.
2007-02-08 11:10:27 +00:00