Many more fixes.. Trying to get all this work now..
[licom.git] / lib / LiCoM / Connection.pm
1 package LiCoM::Connection;
2
3 use strict;
4 use warnings;
5
6 use Exporter;
7 use Net::LDAP;
8 use Net::LDAP::Filter;
9
10 =head1 NAME
11
12 LiCoM::Connection - Represents the connection to an LDAP-server.
13
14 =cut
15
16 our $Ldap;
17
18 @LiCoM::Connection::EXPORT_OK = (qw($Ldap));
19 @LiCoM::Connection::ISA = ('Exporter');
20
21 return (1);
22
23 =head1 METHODS
24
25 =over 4
26
27 =item LiCoM::Connection-E<gt>B<connect> (I<$server>, I<$bind_dn>, I<$password>, I<$base_dn>, [I<$port>])
28
29 Connects to the LDAP-Server given.
30
31 =cut
32
33 sub connect
34 {
35         my $pkg = shift;
36         my %opts = @_;
37
38         my $bind_dn = $opts{'bind_dn'};
39         my $uri     = $opts{'uri'};
40         my $passwd  = $opts{'password'};
41
42         my $msg;
43
44         die unless ($bind_dn and $uri and defined ($passwd));
45
46         $Ldap = Net::LDAP->new ($uri);
47
48         $msg = $Ldap->bind ($bind_dn, password => $passwd);
49         if ($msg->is_error ())
50         {
51                 warn ('LDAP bind failed: ' . $msg->error_text ());
52                 return (0);
53         }
54
55         return (1);
56 }
57
58 =item LiCoM::Connection-E<gt>B<disconnect> ()
59
60 Disconnect from the LDAP-Server.
61
62 =cut
63
64 sub disconnect
65 {
66         $Ldap->unbind ();
67         $Ldap = undef;
68 }
69
70 =back
71
72 =head1 AUTHOR
73
74 Florian octo Forster E<lt>octo at verplant.orgE<gt>
75
76 =cut