Hello all -

On Fri, 02 Jun 2000, Edgar R Gutierrez wrote:
> Hi Mike..
> 
> The following is a section of a postauthhook that we are currently using.
> This hook creates its own handle to connect to a database...I am not really
> sure what database are you using but this works for MySQL. Well, you will
> not have a problem for as long as the database that you are using is
> supported by PERL's DBI.
> 
> You just have to make sure that you finish all sql statements using the
> $sth->finish statement.. and you close your database
> connection using $dbh->disconnect.
> 
> 
> ----
> sub
> {
> my $p=${$_[0]};
> my $username;
> my $userpassword;
> my
> ($NSD,$DUD,$cycle,$date,$datestamp,$host,$database,$user,$password,$dbh,$sql
> ,$sth,$rv,$table,$i,$j);
> #Connect to MySQL database
> $host="192.168.0.1";
> $database="billing";
> $user="mike";
> $password="gladtohelp";
> $dbh=DBI->connect("DBI:mysql:$database:$host",$user,$password);
> $sql="select * from TABLE";
> $sth=$dbh->prepare($sql);
> $rv=$sth->execute;
> $sth->finish;
> ....
> ....
> mmy $rc;
> $rc=$dbh->disconnect;
> return;
> 
> 
> -----END OF POST AUTH HOOK---
> 
> Hope this gives you an idea on how to go about what you want to do...=)
> 

The above will certainly work, although you can also do something like this:

# configuration to allow a PostAuthHook to access a database
# either define a new AuthBy SQL if different to an existing AuthBy SQL
# or add an Identifier tag to your existing AuthBy SQL

<AuthBy SQL>
        Identifier yourSQL
        DBSource ....
        DBUsername ....
        DBAuth ....
</AuthBy>


Then in your hook use the find function in AuthGeneric to retrieve the reference
to that AuthBy SQL. Once you have the reference, you can use all the standard
routines in AuthSQL.pm and SqlDb.pm, including prepareAndExecute, etc.

# hook to use an SQL database

sub
{
    my $p = ${$_[0]};
    my $rp = ${$_[1]};
    my $result = ${$_[2]};

    my $authby_handle = Radius::AuthGeneric::find('yourSQL');
    my $query = "select ......";
    my $sth = $authby_handle->prepareAndExecute($query);
    .....
}

This way you avoid most of the housekeeping, as it is already taken care of by
the routines in SqlDb.pm. As a relatively simple example of some SQL code that
uses these routines, have a look at Radius/SessSQL.pm.

hth

Hugh    


-- 
Radiator: the most portable, flexible and configurable RADIUS server 
anywhere. SQL, proxy, DBM, files, LDAP, NIS+, password, NT, Emerald, 
Platypus, Freeside, Interbiller, TACACS+, PAM, external, etc, etc.
Available on Unix, Linux, FreeBSD, Windows 95/98/2000, NT, MacOS X.



===
Archive at http://www.starport.net/~radiator/
Announcements on [EMAIL PROTECTED]
To unsubscribe, email '[EMAIL PROTECTED]' with
'unsubscribe radiator' in the body of the message.

Reply via email to