Article View: news.software.nntp
Article #69129Re: Problems with MySQL auth and inn 2.4.1
From: Russ Allbery
Date: Mon, 17 May 2004 06:53
Date: Mon, 17 May 2004 06:53
75 lines
4051 bytes
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.
Technical Details
Message-ID:
<87ad07lf2w.fsf@windlord.stanford.edu>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20140818.mbox.gz!number1.nntp.dca.giganews.com!internal1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.maxwell.syr.edu!newsfeed.stanford.edu!shelby.stanford.edu!not-for-mailReferences:
<slrnca6kst.la6.slim.post@gibsmir.csn.tu-chemnitz.de>Show Full Headers
Complete Article Headers
Message-ID: <87ad07lf2w.fsf@windlord.stanford.edu> Subject: Re: Problems with MySQL auth and inn 2.4.1 Date: Sun, 16 May 2004 23:53:27 -0700 From: Russ Allbery <rra@stanford.edu> References: <slrnca6kst.la6.slim.post@gibsmir.csn.tu-chemnitz.de> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20140818.mbox.gz!number1.nntp.dca.giganews.com!internal1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.maxwell.syr.edu!newsfeed.stanford.edu!shelby.stanford.edu!not-for-mail Newsgroups: news.software.nntp Organization: The Eyrie Lines: 75 NNTP-Posting-Host: windlord.stanford.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.Stanford.EDU 1084776807 9544 171.64.19.147 (17 May 2004 06:53:27 GMT) X-Complaints-To: news@news.stanford.edu User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Security Through Obscurity, linux) Cancel-Lock: sha1:6HtbTU1I/0kFy3sElyGfKMmITCA=