Fw: Re: [Win2k - Version 8.0.2] - StartupMessage Format Question

From: "Tom Pfeifer" <tpfeifer(at)tela(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Cc: oyama(at)module(dot)jp
Subject: Fw: Re: [Win2k - Version 8.0.2] - StartupMessage Format Question
Date: 2005-05-15 15:59:29
Message-ID: 20050515154838.M31208@tela.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Thank you all for the help.  If your interested in the solution I have put it here in the email for
future reference.  This is broken down step by step and could be combined so the code is more
efficient.  This is just the first step.  I need to take this and create the appropriate steps for
Authentication etc...  But the hard part is done.  I can now connect to the postgres backend and I
get an appropriate message back which asks for the password.

use IO::Socket;
$string = 'user' . chr(0) . 'postgres' . chr(0) . 'database' . chr(0) .  'maach' . chr(0) . chr(0);
$strlen = length($string);
$string = pack("a$strlen", $string);
$version = pack('n', 3);
$verlen = length($version);
$revision = pack('n', 0);
$revlen = length($revision);
$total = 4 + $strlen + $verlen + $revlen;
$len = pack('N', $total);
$send = $len . $version . $revision . $string;
while ($send =~ m/(.{1,16})/g) {
  my $chunk = $1;
  print join ' ', map {sprintf '%02X', ord $_} split //, $chunk;
  print '   ' x (16 - length $chunk);
  print '  ';
  print join '', map { sprintf '%s', (/[[:graph:] ]/) ? $_ : '.' } split //, $chunk;
  print "\n";
}
$remote = IO::Socket::INET->new(PeerAddr => '127.0.0.1', PeerPort => '5432', Proto => 'tcp',
Timeout  => '30') or die "error:$!";
$remote->autoflush(1);
print $remote "$send\n";
while ( <$remote> ) { 
  print "\n";
  while ($_ =~ m/(.{1,16})/g) {
    my $chunk = $1;
    print join ' ', map {sprintf '%02X', ord $_} split //, $chunk;
    print '   ' x (16 - length $chunk);
    print '  ';
    print join '', map { sprintf '%s', (/[[:graph:] ]/) ? $_ : '.' } split //, $chunk;
    print "\n";
  }
}
$remote->close;
exit(0);

RESULTS::)
00 00 00 26 00 03 00 00 75 73 65 72 00 70 6F 73  ...&....user.pos
74 67 72 65 73 00 64 61 74 61 62 61 73 65 00 6D  tgres.database.m
61 61 63 68 00 00                                aach..

52 00 00 00 0C 00 00 00 05 80 F4 24 B6           R..........$.

Thanks again to all who clued me in on the correct format for the StartupMessage.
T Pfeifer

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Volkan YAZICI 2005-05-15 17:51:48 Re: Fw: Re: [Win2k - Version 8.0.2] - StartupMessage Format Question
Previous Message Sim Zacks 2005-05-15 06:11:32 Re: Fwd: [NOVICE] Autocommit in Postgresql