Discussion:
Password with libpq
(too old to reply)
Tony Reina
2004-06-27 17:13:54 UTC
Permalink
I'm setting my PostgreSQL server to demand md5 encrypted passwords
from users. In my C programs (using libpq as the interface), it's no
big deal to pass the password through PQconnectdb.

However, what about in the general case where my client program
doesn't know if a password is required or not. Is there any libpq
function to query the server if a password is required? Perhaps,
there's a return value for PQconnectdb which would tell me that the
connection failed because of the password? (In which case, I can ask
for the password and try the connection again.)

Thanks.
-Tony
Tom Lane
2004-06-27 22:12:37 UTC
Permalink
Post by Tony Reina
However, what about in the general case where my client program
doesn't know if a password is required or not. Is there any libpq
function to query the server if a password is required? Perhaps,
there's a return value for PQconnectdb which would tell me that the
connection failed because of the password? (In which case, I can ask
for the password and try the connection again.)
Look into the psql source code; it does essentially this.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ***@postgresql.org so that your
message can get through to the mailing list cleanly
Tony and Bryn Reina
2004-06-28 15:11:02 UTC
Permalink
Thanks Tom. I found the relevant bit of code in the psql files. Looks like
it's just a simple loop that compares the error with the phrase
"fe_sendauth: no password supplied" and then prompts for the password and
tries again. Of course, if someone in the future decides to change the error
message, then the code gets broke. I doubt that's likely however.

-Tony



----- Original Message -----
From: "Tom Lane" <***@sss.pgh.pa.us>
To: "Tony Reina" <***@hotmail.com>
Cc: <pgsql-***@postgresql.org>
Sent: Monday, June 28, 2004 12:12 AM
Subject: Re: [ADMIN] Password with libpq
Post by Tom Lane
Post by Tony Reina
However, what about in the general case where my client program
doesn't know if a password is required or not. Is there any libpq
function to query the server if a password is required? Perhaps,
there's a return value for PQconnectdb which would tell me that the
connection failed because of the password? (In which case, I can ask
for the password and try the connection again.)
Look into the psql source code; it does essentially this.
regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Peter Eisentraut
2004-06-28 17:22:23 UTC
Permalink
Post by Tony and Bryn Reina
Thanks Tom. I found the relevant bit of code in the psql files. Looks
like it's just a simple loop that compares the error with the phrase
"fe_sendauth: no password supplied" and then prompts for the password
and tries again. Of course, if someone in the future decides to
change the error message, then the code gets broke. I doubt that's
likely however.
Eventually, we should introduce error codes for this situation.


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Loading...