postgres/libpqxx: Refuses authentication via password

642 views Asked by At

I'm using two tools here in university, wich both work with the same postgres database. The one written in Java uses the jdbc-driver and that works just fine.

The second one written in C++ has some difficulties. It gives me following error

Ident authentication failed for user "xyz"

The connection string looks like this

dbname=myDB user=xyz hostaddr=127.0.0.1 port=5432 connect_timeout=10 password=myPW

I checked the values like 10 times and the are exactly the same in both applications. I thought it might be the pg_hba.cfg. So I tried a lot and finally got all doors open:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all             trust
local   all             postgres        ident
local   all             all             password
# IPv4 local connections:
host    all             all             192.168.185.0/24        trust
host    all             postgres        127.0.0.1/32            ident
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 ident

How can it be, that the C++ tool always tries to go with the indent authentification method despite a password is given. (Or is it the db..?) Are there any special cases in libpqxx I have to lookout for?

1

There are 1 answers

1
Craig Ringer On

I think you mean peer when you wrote ident. ident on a local connection makes little sense. However, that's not the line being matched.

How can it be, that the C++ tool always tries to go with the indent authentication method despite a password is given. (Or is it the db..?) Are there any special cases in libpqxx I have to lookout for?

The database server chooses the auth method and demands that the client authenticate with the desired method.

The password is unused and never even sent to the server if it doesn't ask for it, as in ident authentication. If you want password authentication, set the server to request the md5 authentication method.

I've recently suggested on the mailing list that libpq should issue a WARNING when a password is supplied but ignored due to server configuration. I haven't convinced anyone it's a good idea yet.