Libpq++ autenthication problem II - Mailing list pgsql-general

From Dario Fumagalli
Subject Libpq++ autenthication problem II
Date
Msg-id 358946ED.59DA2EC7@art-media.it
Whole thread Raw
List pgsql-general
Original message:

Hi all,

I'm having some problems trying to use the "password" and "crypt"
authentication protocols in my libpq++ apps.

Until now my programs were always on the same machine and were CGIs. So
I used "trust" authentication in my pg_hba.conf file.
Since I'm spreading the PostgreSQL fame as much as I can some customers
are asking my company for some PostgreSQL-based apps.
For one of those customers I must provide a degree of security better
than "trust", possibly "crypt".

I'm searching documentation or examples about "password" and "crypt"
connections using libpq++. I searched on the WEB site (libpq IS
documented, but perhaps I'm too a newbie to translate the given
explainations to working code (= code that compiles AND succeeds in the
connections)).
I also tried searching the interfaces mailing list archives, but with no
luck.

Following there is an example (it is
src/interfaces/libpq++/examples/testlibpq0.cc with some lines added) of
my first efforts. I know that everything else is OK. My v. 6.3.1
installation works OK since the last year; people can view my data using
libpq++ based CGIs (those that use the "trust" authentication); JDBC
both on server (listening on a port) and on client (JDBC drivers
downloaded with applets) work even with "password" authentication; ODBC
connections are OK (thanks Byron :) ) with "trust" and "password"
authentication (not for "crypt" but it seems it is not implemented yet
on the driver's side...); PHP 3 connections work both with "password"
and "crypt" protocols. All the listed means of connection work with
other databases AND with this specific database.

I'm really sure I'm making a little mistake somewhere in the code. If
someone could help, I'll be grateful...


Listing of src/interfaces/libpq++/examples/testlibpq0.cc with temptative
(first 5 lines changed) authentication support (those username and
password work in psql):

/*-------------------------------------------------------------------------
 *
 * testlibpq0.c--
 *    small test program for libpq++,
 * small interactive loop where queries can be entered interactively
 * and sent to the backend
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *    $Header:
/usr/local/cvsroot/pgsql/src/interfaces/libpq++/examples/testlibpq0.cc,v
1.3 1997/02/13 10:00:42 scrappy Exp $
 *

*-------------------------------------------------------------------------
 */

#include <iostream.h>
#include <libpq++.h>

int main()
{
  PgEnv Env; // Costruisce l'ambiente per PostgreSQL. Necessario se si
usa
             // l'autenticazione (come nel caso di Jia)
  Env.Auth("password"); // Sostituire con "crypt" se necessario
  Env.Option("user=jiaguest password=c3e0scx");

  // Open the connection to the database and make sure it's OK
  PgDatabase data(Env, "template1");
  if ( data.ConnectionBad() ) {
      cout << "Connection was unsuccessful..." << endl
           << "Error message returned: " << data.ErrorMessage() << endl;
      return 1;
  }
  else
      cout << "Connection successful...  Enter queries below:" << endl;

  // Interactively obtain and execute queries
  ExecStatusType status;
  string buf;
  int done = 0;
  while (!done)
    {
      cout << "> ";
      cout.flush();
      getline(cin, buf);
      if ( buf != "" )
               if ( (status = data.Exec( buf.c_str() )) ==
PGRES_TUPLES_OK )
                  data.DisplayTuples();
               else
                  cout << "No tuples returned..." << endl
                       << "status = " << status << endl
                       << "Error returned: " << data.ErrorMessage() <<
endl;
      else
               done = 1;
      }
  return 0;
} // End main()


One possible answer (since I received none :( ):

I looked at the sources under interfaces/libpq++ and they seem rather
obsolete. The following are my findings (hope to be correct):

In fact they use an old method (valid before password and crypt
authentication appeared) of connecting to the backend.

This older method is unable to connect via those new authentication
protocols. I also found some old bits here and there (related to the
connection) that perhaps could be removed.

Since I want to use a C++ interface to PostgreSQL (and I'm bragging sooo
much with my colleagues and friends about its "mighty powers") I could
rewrite some pieces here and there.

Given that:
- I found a workaround (using environment variables), but it's not
elegant.

- due to the new connection method (a string) I have collisions with
overloaded constructors' parameters. I can write code that can cope with
the new authentication methods, but the current C++ interface will be
broken.

- I'm not the only one on this planet who wants to use libpq++.

- I have proofs (other mails) of people who need / like to connect to
PostgreSQL using libpq++ AND password or crypt authentication methods.
In those days a library that does not permit password protected
connections is virtually useless.


I would like to ask the authors if I can rewrite some parts of libpq++
and post them.
It will NOT be only a patch and will NOT be backwardly compatible.

Moreover, if The Authors agree with it (and I modify the library), I
would like to be put on the developers' list. This will help me spread
the PostgreSQL fame even more in others Italian programmers' mailing
lists where I know there are a lot of people interested in DBMS.

Cheers,

Dario Fumagalli

Art & Media
Via Villa Giusti, 11 - 10142 Torino (Italy)
Tel. +39-11-7707412 PBX - Fax +39-11-704283
email swdevel@art-media.it
      dfumagalli@art-media.it (personal mail slot)
http://www.art-media.it

pgsql-general by date:

Previous
From: eric@gateway.ctlno.com
Date:
Subject: Help with auto increment
Next
From: eric@gateway.ctlno.com
Date:
Subject: Help with auto-increment