Hi people,

I'm using some c++ code to connect to a postgresql 6.3.2 database.
I need to use this for a CGI application on a website we maintain.
It runs perfectly from the command line on my linux machine, and also
from the command line on the BSDI machine we use for a virtually-hosted
server.
The problem I'm having is when I attempt to execute it as a CGI app from
the cgi-bin directory on our server.  Here's the code:
----------------------------------------------------------------------------
#include <iostream.h>
#include <libpq++.h>
#include <stdlib.h>

main()
{

  cout << "Content-type: text/plain\n\n";
  cout << "Trying to connect ..." << endl;
  char* dbName = "molinks"; 
  PgEnv Env;
  Env.Host("peculiarweb.com");
  //  Env.Port("");
  // Env.Auth("");
  cout << "Env.Auth = " << Env.Auth() << endl;
  cout << "Env.Host = " << Env.Host() << endl;
  cout << "Env.Port = " << Env.Port() << endl;
  cout << "Env.Option = " << Env.Option() << endl;
  cout << "Env.TTY = " << Env.TTY() << endl;

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

When I try to run it as a CGI app from the web server, I get the
following error:
----------------------------------------------------------------------------
Trying to connect ...
Env.Auth = 
Env.Host = peculiarweb.com
Env.Port = 
Env.Option = 
Env.TTY = 
Connection was unsuccessful...
Error message returned: fe_setauthsvc: invalid name: , ignoring...
----------------------------------------------------------------------------

Anybody have any clue why this happens, or what it means?  Better yet,
anybody know how to fix it?

----------------------------------------------------------------------------
			Belinda & Clint Forgy
Midwest Online					PeculiarWeb Internet Designs
http://www.midwestonline.com			http://www.peculiarweb.com

Fri, 11 Sep 1998 00:11:17 -0500
Midwest Online <mo@midwestonline.com>
getting "fe_setauthsvc: invalid name" error
Midwest Online <mo@midwestonline.com> writes:
> Connection was unsuccessful...
> Error message returned: fe_setauthsvc: invalid name: , ignoring...
> Anybody have any clue why this happens, or what it means?  Better yet,
> anybody know how to fix it?

The error message is pretty much useless --- it looks like the actual
error is being overwritten thanks to a bug in PgConnection::Connect().
You might try diking out the last seven lines of that routine (it's
in src/interfaces/libpq++/pgconnection.cc) and seeing if you get a
more useful message.

My guess is that the execution environment is different for your CGI
program, with respect to either username or lack of one of the
environment variables that libpq pays attention to (PGPORT, etc).

Another possibility is that the database server sees the connection
as being made from a different IP address than what you get from the
command line (I dunno enough about "virtual web servers" to know if that
would happen, but it seems possible), and the IP address is not one of
those listed as permitted to connect in the server's host authentication
file.

BTW, hackers: when I looked into pgconnection.cc, I was astonished
and dismayed by the number of instantly visible bugs.  This code is in
*horrible* shape --- it's amazing it works at all.  Someone is going to
have to adopt libpq++ and give it a close going-over.

			regards, tom lane

Fri, 11 Sep 1998 10:16:37 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: [INTERFACES] getting "fe_setauthsvc: invalid name" error 