4 # Authentication against MySQL Database
6 # Written by Thomas Hochstein <thh@inter.net>
7 # based on a script written by Sven Weise (sven@futzelnet.de).
8 # Covered under the same license as INN in general.
12 # active = User active/inactive? (for temp. suspension)
14 ### database structure
15 # CREATE TABLE IF NOT EXISTS `users` (
16 # `userid` int(11) NOT NULL auto_increment,
17 # `user` varchar(16) collate latin1_bin NOT NULL default '',
18 # `password` varchar(16) collate latin1_bin NOT NULL default '',
19 # `active` tinyint(1) NOT NULL default '1',
20 # `username` varchar(60) collate latin1_bin default NULL,
21 # `usermail` varchar(60) collate latin1_bin default NULL,
22 # `domain` varchar(40) collate latin1_bin default '<EDITME>',
23 # `llo` date default NULL,
24 # PRIMARY KEY (`userid`),
25 # UNIQUE KEY `user` (`user`)
27 ####################################################################################################################################
35 ### DB Vars - EDIT ME!
36 $conf{'dbdriver'} = "mysql";
37 $conf{'dbhost'} = "localhost";
38 $conf{'database'} = "";
41 $conf{'dbtable'} = "";
42 $conf{'actcheck'} = 1;
45 #D open LOG, '>/usr/lib/news/bin/auth/passwd/test.log';
50 # $attributes{hostname} hostname (or the IP address if it doesn't resolve) of the client machine
51 # $attributes{ipaddress} IP address (as a string)
52 # $attributes{port} client port (as an integer)
53 # $attributes{interface} hostname of the interface the client connected on
54 # $attributes{intipaddr} IP address (as a string) of the interface the client connected on
55 # $attributes{intport} port (as an integer) on the interface the client connected on
56 # $attributes{username} username
57 # $attributes{password} password
60 my $dbs = sprintf('DBI:%s:database=%s;host=%s',$conf{'dbdriver'},$conf{'database'},$conf{'dbhost'});
61 my $dbhandle = DBI->connect($dbs, $conf{'dbuser'}, $conf{'dbpw'}, { PrintError => 1 });
63 ### Query database and disconnect.
68 my $sql_user = $dbhandle->quote($attributes{username});
69 my $sql_pass = $dbhandle->quote($attributes{password});
71 my $query = sprintf("SELECT domain FROM %s.%s WHERE user = %s AND password = %s",$conf{'database'},$conf{'dbtable'},$sql_user,$sql_pass);
72 if ($conf{'actcheck'}) {
73 $query .= ' AND active = 1';
75 my $dbquery = $dbhandle->prepare($query);
76 if ($dbquery->execute()) {
77 @result = $dbquery->fetchrow_array;
83 my $today = sprintf('%04d-%02d-%02d', $tm->year+1900, ($tm->mon)+1, $tm->mday);
84 $query = sprintf("UPDATE %s.%s SET llo = '%s' WHERE user = %s",$conf{'database'},$conf{'dbtable'},$today,$sql_user);
85 $dbquery = $dbhandle->prepare($query);
90 $dbhandle->disconnect;
93 ### check password and respond appropriate
95 my $user = $attributes{username} . '@' . $result[0];
96 return (281, 'Authentication successful: '.$user, $user);
98 return (481, 'Authentication failure');
101 # code execution should never reach this point
102 return (481, 'Authentication failure');