hi-

be forewarned, i've tried to specify the relevant environment as completely as 
possible, so this is a lengthy post.

i have what seems to me to be an interesting problem ... i'm converting a series of 
html docs and cgi scripts that i use as a query engine to a couple of cgi scripts, one 
which receives authentication information while the other handles query processing. 
the query page is frame-based, and follows the example included in the cgi.pm readme.

the problem i'm having is that the connect string in the converted script won't work 
using variables for username and password. here's the output from the dbitrace log 
from the connect attempt...


    DBI 1.20-nothread dispatch trace level set to 2
    -> DBI->connect(DBI:Pg:dbname=jrado;host=raider-ralph, , ****)
    -> DBI->install_driver(Pg) for linux perl=5.006001 pid=3030 ruid=1001 euid=1001
       install_driver: DBD::Pg version 1.01 loaded from 
/usr/local/lib/perl/5.6.1/DBD/Pg.pm
    <- install_driver= DBI::dr=HASH(0x82459e4)
    -> default_user in DBD::_::dr for DBD::Pg::dr (DBI::dr=HASH(0x82459e4)~0x82ec3d8 
undef undef HASH(0x8109d38))
    <- default_user= ( undef undef ) [2 items] at DBI.pm line 423
    -> connect for DBD::Pg::dr (DBI::dr=HASH(0x82459e4)~0x82ec3d8 
'dbname=jrado;host=raider-ralph' undef **** HASH(0x8109d38))
pg_db_login
pg_db_login: conn_str = >dbname=jrado host=raider-ralph<br>
No Postgres username specified in startup packet. error 1 recorded: No Postgres 
username specified in startup packet.    !! ERROR: 1 'No Postgres username specified 
in startup packet.' 


the log from a successful connection attempt, which i get when i explicitly pass a 
valid set of credentials in the connect string, is identical to that which i receive 
in the relevant portion of the earlier version when i pass the credentials in scalars. 
that log looks like this:



    DBI 1.20-nothread dispatch trace level set to 2
    -> DBI->connect(DBI:Pg:dbname=jrado;host=raider-ralph, (username deleted for 
post), ****)
    -> DBI->install_driver(Pg) for linux perl=5.006001 pid=32422 ruid=1001 euid=1001
        install_driver: DBD::Pg version 1.01 loaded from 
/usr/local/lib/perl/5.6.1/DBD/Pg.pm
    <- install_driver= DBI::dr=HASH(0x8225fd8)
    -> connect for DBD::Pg::dr (DBI::dr=HASH(0x8225fd8)~0x8100750 
'dbname=jrado;host=raider-ralph' '(username deleted for post)' **** HASH(0x80f6174))
pg_db_login
pg_db_login: conn_str = >dbname=jrado host=raider-ralph user=(username deleted) 
password=(password deleted)
    <- connect= DBI::db=HASH(0x8100714) at DBI.pm line 426


in both scripts the $username and $password scalars are successfully filled from 
parameters, and the connect statement is the standard 

$dbh=DBI->connect($dsn,$username,$password) or die print "error connecting to database 
", $DBI::errstr, "\n";

as i've investigated this further i've discovered that quoting the scalars holding the 
username and password parameters will lead to the submittal of a valid connect string, 
but the connection bombs out with authentication errors.  there is not a great deal of 
difference between the contexts in which the connection is established ... 

here's the one that fails ...

#!/usr/bin/perl -w

sub BEGIN
    {
        $ENV{DISPLAY}= "machine:0.0";
    }

use Carp () ;
use CGI qw( ::standard );;
use CGI::Carp qw( fatalsToBrowser );
use DBI;
use DBD::Pg;
our $counter = 0;
our $full=new CGI;
print $full->header;
our $dbh;
$path_info = $full->path_info;
my ($param1,$param2);
$param1='username';
$param2='password';
my $username;
$username=$full->param($param1);
my $password;
$password=$full->param($param2);
my $database='jrado';
my $driver='Pg';
my $host='raider-ralph';        
my $dsn="DBI:$driver:dbname=$database;host=$host";
$username=~s/^\s+//;
$password=~s/^\s+//;
unlink '/home/www/dbitrace.log6a' if -e '/home/www/dbitrace.log6a';
DBI->trace(2,'/home/www/dbitrace.log6a');
$dbh=DBI->connect($dsn,$username,$password) or die print "error connecting to database 
", $DBI::errstr, "\n";


and here's the one that works ...

#! /usr/bin/perl -Tw
use CGI qw(:all);
##list.cgi

##set up the postgresql interface
use DBI;
use DBD::Pg;

my $match;
my $begdate;
my $enddate;
our $username;
our $password;

$match='';
$begdate='';
$enddate='';

our $list=new CGI;
$begdate=$list->param('begdate');
$enddate=$list->param('enddate');
$match=$list->param('match');
$username=$list->param('username');
$password=$list->param('password');
##declare scalars

##dsn-related
my $host;
my $db;
my $driver;
my $dsn;
my $database;
our $key;


$database='jrado';
$driver='Pg';
$user='';
$host='raider-ralph';
$dsn="DBI:$driver:dbname=$database;host=$host";


##database handle
my $dbh_list;
unlink '/home/www/dbitrace.log4' if -e '/home/www/dbitrace.log4';
DBI->trace(2,'/home/www/dbitrace.log4');
$username=~s/^\s+//;
$password=~s/^\s+//;
$dbh_list=DBI->connect($dsn,$username,$password) or die print "ACCESS DENIED";


can anyone point out to me why the postgresql dbi driver is choking on this?



john cuson
([EMAIL PROTECTED], [EMAIL PROTECTED])

The world is full of obvious things which nobody by any chance ever observes.
                              
                                     Sir Arthur Conan Doyle

Reply via email to