🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
10 messages
10 total messages Started by Sebastian Damm Thu, 13 May 2004 10:53
Problems with MySQL auth and inn 2.4.1
#69115
Author: Sebastian Damm
Date: Thu, 13 May 2004 10:53
152 lines
5580 bytes
Hello

(I wrote this posting already to the inn-workers list, but since I haven't
received neither a Subscription confirmation nor a copy of my own mail,
I'll try my question here)

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 

#v+
./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
#v-

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
#v+
auth "jeder" {
    perl_auth: "authdb_hook.pl"
#    auth: "authdb_standalone.pl"
}
#v-

I've tried both versions, running authdb_$version.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" twice, 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:

#v+
#!/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;
}
#v-

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. I think the script doesn't even get started,
because when I let the script print something out to STDERR I don't get
anything in the news.notice file (with the standalone version I do get
some messages so I know at least that the script is being run).

The standalone program does not much different:

#v+
#!/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;
}
#v-

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
#v+
news@newsserver:~/bin/auth/passwd> ./authdb_standalone.pl
news@newsserver:~/bin/auth/passwd> echo $?
0
news@newsserver:~/bin/auth/passwd>
#v-

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
-- 
Sebastian Damm ........................................ slim.post@gmx.de
Re: Problems with MySQL auth and inn 2.4.1
#69119
Author: Jeffrey M. Vinocur
Date: Fri, 14 May 2004 21:36
18 lines
1829 bytes
In article <slrnca6kst.la6.slim.post@gibsmir.csn.tu-chemnitz.de>,
Sebastian Damm  <slim.post@gmx.de> wrote:
>
>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" twice, the "standalone version" doesn't
>print out any problems, exits with 0 and still tells me a "bad auth".

I haven't looked at your scripts, but you *may* get some
additional clue from turning on the detailed readers.conf
logging.  Add a line to your syslog.conf for "news.debug" (it
should look just like the lines for news.notice, news.err, and
news.crit), and HUP syslogd.


-- 
Jeffrey M. Vinocur
jeff@litech.org
Re: Problems with MySQL auth and inn 2.4.1
#69128
Author: Sebastian Damm
Date: Mon, 17 May 2004 06:39
38 lines
2410 bytes
Jeffrey M. Vinocur wrote:
> I haven't looked at your scripts, but you *may* get some
> additional clue from turning on the detailed readers.conf
> logging.  Add a line to your syslog.conf for "news.debug" (it
> should look just like the lines for news.notice, news.err, and
> news.crit), and HUP syslogd.

That didn't give me any further help, I only get:

#v+
May 17 08:18:41 col-webneu nnrpd[28369]: 172.20.30.58 (172.20.30.58) connect
May 17 08:18:41 col-webneu nnrpd[28369]: Reading access from /usr/local/news/etc/readers.conf
May 17 08:18:41 col-webneu nnrpd[28369]: Auth strategy 'localhost' does not match client.  Removing.
May 17 08:18:41 col-webneu nnrpd[28369]: 172.20.30.58 no_success_auth 
May 17 08:18:41 col-webneu nnrpd[28369]: 172.20.30.58 auth starting authenticator authdb_standalone.pl 
May 17 08:18:41 col-webneu nnrpd[28369]: 172.20.30.58 auth authenticator failed
May 17 08:18:41 col-webneu nnrpd[28369]: 172.20.30.58 no_success_auth
May 17 08:18:41 col-webneu nnrpd[28369]: 172.20.30.58 bad_auth
#v-

Even with just the lines 

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

exit 0;
#v-

I get the same lines as above. So I think I misunderstand something. But
what?

Any help appreciated

Sebastian
-- 
Sebastian Damm ........................................ slim.post@gmx.de
Re: Problems with MySQL auth and inn 2.4.1
#69129
Author: Russ Allbery
Date: Mon, 17 May 2004 06:53
75 lines
4051 bytes
Sebastian Damm <slim.post@gmx.de> writes:

> 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" twice, 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:

Note that when using perl_auth, you don't ever want to call exit.  I don't
even know what that will do.  It might just kill nnrpd completely.  You
want to just return the array from the authenticate function.

Calling die is fine, though.  If you call die, that error message should
be reported in syslog by nnrpd.

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

You really want to be using placeholder values.  See the DBI
documentation.  This is vulnerable to a SQL injection attack by using a
username or password that contains a single quote and other SQL special
characters.

>   my $sth = $dbh->prepare($getuser) || die "Can't prepare SELECT: $DBI::errstr\n";
>   my $querynum = $sth->execute || die "Can't query: $DBI::errstr\n";

This doesn't do what you want.  $querynum will always be 1 if the
statement executed successfully.  See the DBI documentation:

    For "SELECT" statements, execute simply "starts" the query within
    the database engine. Use one of the fetch methods to retrieve the
    data after calling "execute". The "execute" method does *not* return
    the number of rows that will be returned by the query (because most
    databases can't tell in advance), it simply returns a true value.

>   my @returnarray;
>   if ($querynum == 1)
>   {
>     $returnarray[0]='281';
>     $returnarray[1]='';
>     return @returnarray;
>     exit 0;
>   }

I think this is your problem.  INN is expecting an integer return code,
and you're giving it a string.  INN isn't smart enough to coerce the
string to an integer.

Try:

    $returnarray[0] = 281;
    $returnarray[1] = '';

instead.

>   $sth->finish;
>   $dbh->disconnect;

Neither of these functions are ever being called.  You need to store what
you're going to return, do this, and then return the values.

> 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... :(

There is a MySQL authenticator in INN's contrib directory.  You can get it
as part of a CURRENT snapshot from ftp.isc.org.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>

          Please post questions rather than mailing me directly.
     <http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
Re: Problems with MySQL auth and inn 2.4.1
#69130
Author: Russ Allbery
Date: Mon, 17 May 2004 06:54
24 lines
1935 bytes
Sebastian Damm <slim.post@gmx.de> writes:

> Even with just the lines 

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

> exit 0;
> #v-

> I get the same lines as above. So I think I misunderstand something. But
> what?

Yeah, with just the above, there's no authenticate sub, so the nnrpd Perl
authenticator logic is going to fail.  You have to have an authenticate
sub and it has to return at least two values, even for testing a stub.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>

          Please post questions rather than mailing me directly.
     <http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
Re: Problems with MySQL auth and inn 2.4.1
#69137
Author: Sebastian Damm
Date: Mon, 17 May 2004 09:21
22 lines
1882 bytes
Russ Allbery schrieb:
>> #v+
>> #!/usr/bin/perl -w
>> use strict;
>> use DBI;
>
>> exit 0;
>> #v-
> Yeah, with just the above, there's no authenticate sub, so the nnrpd Perl
> authenticator logic is going to fail.  You have to have an authenticate
> sub and it has to return at least two values, even for testing a stub.

No, I tried these few lines as a standalone auth program, and that should
return nothing, just with exit code 0, right?

But thanks for your lines in your other reply, now I have something to
work with again...

Sebastian
-- 
Sebastian Damm ........................................ slim.post@gmx.de
                                            http://www.hsg-basketball.de
Re: Problems with MySQL auth and inn 2.4.1
#69138
Author: Russ Allbery
Date: Mon, 17 May 2004 09:24
19 lines
2125 bytes
Sebastian Damm <slim.post@gmx.de> writes:
> Russ Allbery schrieb:

>> Yeah, with just the above, there's no authenticate sub, so the nnrpd
>> Perl authenticator logic is going to fail.  You have to have an
>> authenticate sub and it has to return at least two values, even for
>> testing a stub.

> No, I tried these few lines as a standalone auth program, and that
> should return nothing, just with exit code 0, right?

A standalone program has to tell nnrpd what the username is.  If it
doesn't print a username, authentication will fail.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>

          Please post questions rather than mailing me directly.
     <http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
Re: Problems with MySQL auth and inn 2.4.1
#69141
Author: Sebastian Damm
Date: Mon, 17 May 2004 11:30
55 lines
3037 bytes
Russ Allbery schrieb:
> I think this is your problem.  INN is expecting an integer return code,
> and you're giving it a string.  INN isn't smart enough to coerce the
> string to an integer.
>     $returnarray[0] = 281;
>     $returnarray[1] = '';

OK, did that, still didn't work.

> There is a MySQL authenticator in INN's contrib directory.  You can get it
> as part of a CURRENT snapshot from ftp.isc.org.

As I wrote, I read about an authenticator, but couldn't find it. Beause I
just looked into the contrib directory on the ftp server. Now I took the
finally found (;-) authenticator and adapted it to my needs (passwords are
scrambled with the MySQL PASSWORD() function).

But I'm not sure what one line does - or why it shall do what it does: 
This is the whole get_stdin() sub:

#v+
sub get_stdin {
  my %stdin;
  while (<STDIN>) {
    chomp;
    next if $_ =~ /^#.*$/;
    next if $_ =~ /\s+/;  <----- WHY?
    $_ =~ s/#.*$//g;
    $_ =~ s/\s+//g;

    if ( $_ ne "" ) {
      my $key = $_;
      my $value;
      ($key, $value) = split(':', $_, 2);
      $stdin{$key} = $value;
    }
  }
  return(%stdin);
}
#v-

We get values from stdin like "ClientAuthname: user" with a space between
key and value. What is the marked line supposed to do? I know what it
does: It skips the current line if there is a space in it. So we don't get
any usable values. And the auth program fails, of course. Maybe there is
just a ^ missing or a $ to skip lines with leading or trailing spaces.
Trailing spaces would not make sense, though (IMO). When I comment this
line out, the authenticator works.

Thanks for your support and excuse my mail to the inn-workers list, I just
wasn't patient enough. ;)

Sebastian
-- 
Sebastian Damm ........................................ slim.post@gmx.de
Re: Problems with MySQL auth and inn 2.4.1
#69142
Author: Sebastian Damm
Date: Mon, 17 May 2004 12:04
41 lines
2673 bytes
Russ Allbery schrieb:
> A standalone program has to tell nnrpd what the username is.  If it
> doesn't print a username, authentication will fail.

OK, then I misinterpreted the external-auth documentation:

<cite src="doc/external-auth">
Returning information to nnrpd

  Exit status and signals

    The external auth program must exit with a status of 0 to indicate
    success; any other exit status indicates failure.  (The non-zero exit
    value will be logged.)

    If the program dies due to catching a signal (for example, a
    segmentation fault occurs), this will be logged and treated as a
    failure.

  Returning a username and domain

    If the program succeeds, it may return a username string (optionally
    with a domain appended) by writing to standard output.  The line it
    should write is exactly:

        user:username\r

    where *username* is the string that nnrpd should use in matching
    readers.conf access blocks.
</cite>

I thought "may" leaves it up to the authenticator to do it or not.

But I just tested my own standalone program as it was only by substituting
\r with \n in the line where it gives something back to nnrpd. And it
worked. How I love these errors. ;)

Sebastian
-- 
Sebastian Damm ........................................ slim.post@gmx.de
                                            http://www.hsg-basketball.de
Re: Problems with MySQL auth and inn 2.4.1
#69143
Author: Russ Allbery
Date: Mon, 17 May 2004 12:09
24 lines
2237 bytes
Sebastian Damm <slim.post@gmx.de> writes:

> OK, then I misinterpreted the external-auth documentation:

>   Returning a username and domain

>     If the program succeeds, it may return a username string (optionally
>     with a domain appended) by writing to standard output.  The line it
>     should write is exactly:

>         user:username\r

>     where *username* is the string that nnrpd should use in matching
>     readers.conf access blocks.

> I thought "may" leaves it up to the authenticator to do it or not.

Very reasonable on your part.  I'll fix.  :)

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>

          Please post questions rather than mailing me directly.
     <http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads