MySQL Auth Problems

Damm, Sebastian s.damm at color-textil.de
Mon May 17 08:22:11 UTC 2004


Hello,

I'm trying to get my MySQL auth perl Script working with inn. I'm already
trying for days and have no clue where the problem is.

I configured my innd with 
./configure --with-perl --enable-largefiles --with-news-master=newsmaster \
  --with-gnu-ld --with-python --with-log-dir=/var/log/inn \
  --with-run-dir=/var/run/news

Now I have a MySQL database and a table with the columns username, password
and news
When news = 1 the User is allowed to use the newsserver.

In my readers.conf there is an auth part
auth "jeder" {
    perl_auth: "authdb_hook.pl"
#    auth: "authdb_standalone.pl"
}

I've tried both versions, running authdb.pl as a standalone program with the
auth: in the readers.conf and using perl_auth and then just using the
authenticate() function in the perl script.

I read the README pages for external authentication programs and perl auth
hooks and I think I did everything right, but when I start the perl hook
program I just get "bad auth", the "standalone version" doesn't print out
any problems, exits with 0 and still tells me a "bad auth".

OK, here's my perl script for using perl_auth:

#!/usr/bin/perl -w
use strict;
use DBI;

sub authenticate
{
  my $backend = 'mysql';
  my $dbname = 'usermnagement';
  my $dbhost = 'localhost';
  my $dbport = '3306';
  my $dbuser = 'news';
  my $dbpass = 'password';

  my $dbh = DBI->connect("dbi:$backend:$dbname;$dbhost;$dbport", "$dbuser",
"$dbpass") || die "Can't connect to MySQL-Server: $DBI::errstr\n";

  my $username='user1';
  my $password='pass1';

  my $getuser="SELECT username FROM users WHERE username='$username' AND
password=PASSWORD('$password') AND news='1'";

  my $sth = $dbh->prepare($getuser) || die "Can't prepare SELECT:
$DBI::errstr\n";
  my $querynum = $sth->execute || die "Can't query: $DBI::errstr\n";
  my @returnarray;
  if ($querynum == 1)
  {
    $returnarray[0]='281';
    $returnarray[1]='';
    return @returnarray;
    exit 0;
  }
  else
  {
    $returnarray[0]='502';
    $returnarray[1]='Get out!';
    return @returnarray;
    exit 1;
  }
  $sth->finish;
  $dbh->disconnect;
}

Can someone tell me what I do wrong? As you can see I haven't even used the
Hash %attributes that it has access to according to hook-perl in the doc
directory of the sources.

The standalone program does not much different:

#!/usr/bin/perl -w
use strict;
use DBI;

authenticate();

sub authenticate
{
  my $backend = 'mysql';
  my $dbname = 'usermanagement';
  my $dbhost = 'localhost';
  my $dbport = '3306';
  my $dbuser = 'news';
  my $dbpass = 'password';

  my $dbh = DBI->connect("dbi:$backend:$dbname;$dbhost;$dbport", "$dbuser",
"$dbpass") || die "Can't connect to MySQL-Server: $DBI::errstr\n";

  my $username='user1';
  my $password='pass1';

  my $getuser="SELECT username FROM users WHERE username='$username' AND
password=PASSWORD('$password') AND news='1'";

  my $sth = $dbh->prepare($getuser) || die "Can't prepare SELECT:
$DBI::errstr\n";
  my $querynum = $sth->execute || die "Can't query: $DBI::errstr\n";
  if ($querynum == 1)
  {
#    print "user:user1\r";
    exit 0;
  }
  else
  {
    print STDERR localtime(time).": Authentication failed for user
".$username."\n";
    exit 1;
  }
  $sth->finish;
  $dbh->disconnect;
}

Unfortunately I don't speak Perl that well but when I run the second version
from the shell it returns with returncode 0 and without any output
news at newsserver:~/bin/auth/passwd> ./authdb_standalone.pl
news at newsserver:~/bin/auth/passwd> echo $?
0
news at newsserver:~/bin/auth/passwd>

I really have no idea what to try anymore, and I haven't found a perl
program for doing MySQL authentication on the net, I only read about one
that Daniel Marsh has written and apparently also posted here, but no
archive has it anymore... :( So if someone has that script still lying
around somewhere, could you send it to me?

Any help would be appreciated.

Sebastian Damm


More information about the inn-workers mailing list