Debian Codegraph @

src/modules/app_perl/lib/perl/Kamailio/VDB/Adapter/Auth.pm

raw
1 #
2 # $Id: Auth.pm 757 2007-01-05 10:56:28Z bastian $
3 #
4 # Perl module for Kamailio
5 #
6 # Copyright (C) 2007 Collax GmbH
7 # (Bastian Friedrich <[email protected]>)
8 #
9 # This file is part of Kamailio, a free SIP server.
10 #
11 # Kamailio is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version
15 #
16 # Kamailio is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #
25
26 =head1 Kamailio::VDB::Adapter::Auth
27
28 This adapter is intended for usage with the auth_db module.
29 The VTab should take a username as an argument and return a (plain text!)
30 password.
31
32 =cut
33
34 package Kamailio::VDB::Adapter::Auth;
35
36 use Kamailio::Constants;
37 use Kamailio qw ( log );
38
39 use Kamailio::VDB;
40 use Kamailio::VDB::Column;
41 use Kamailio::VDB::Result;
42 use Kamailio::VDB::Adapter::TableVersions;
43
44 use Data::Dumper;
45
46 our @ISA = qw ( Kamailio::VDB );
47
48 sub query {
49 my $self = shift;
50
51 my $conds = shift;
52 my $retkeys = shift;
53 my $order = shift; # Unused value here.
54
55 my @cols;
56
57 my $username = undef;
58 my $password = undef;
59
60 if ($self->{tablename} eq "version") {
61 return Kamailio::VDB::Adapter::TableVersions::version(@$conds[0]->data());
62 }
63
64 if ((scalar @$conds != 1) || (scalar @$retkeys != 2)) {
65 log(L_ERR, "perlvdb:Auth: Broken column count requested. Unknown behavior. Desperately exiting.\n");
66 return undef;
67 }
68
69 for my $c (@$conds) {
70 $username = $c->data();
71 }
72
73 for my $k (@$retkeys) {
74 push @cols, new Kamailio::VDB::Column(DB_STRING, $k);
75 }
76
77 my $vtab = $self->{vtabs}->{$self->{tablename}};
78 $password = $vtab->call("query", $username);
79
80 my $result;
81
82 if ($password) {
83 my @row;
84 push @row, new Kamailio::VDB::Value(DB_STRING, $password);
85 push @row, undef;
86 $result = new Kamailio::VDB::Result(\@cols, (bless \@row, "Kamailio::Utils::Debug"));
87 } else {
88 $result = new Kamailio::VDB::Result(\@cols);
89 }
90
91 return $result;
92 }
93
94 1;