+package LiCoM::Connection;
+
+use strict;
+use warnings;
+
+use Exporter;
+use Net::LDAP;
+use Net::LDAP::Filter;
+
+=head1 NAME
+
+LiCoM::Connection - Represents the connection to an LDAP-server.
+
+=cut
+
+our %Config = get_config ();
+our $Ldap;
+
+@LiCoM::Connection::EXPORT_OK = (qw($Ldap));
+@LiCoM::Connection::ISA = ('Exporter');
+
+return (1);
+
+=head1 METHODS
+
+=over 4
+
+=item LiCoM::Connection-E<gt>B<connect> (I<$server>, I<$bind_dn>, I<$password>, I<$base_dn>, [I<$port>])
+
+Connects to the LDAP-Server given.
+
+=cut
+
+sub connect
+{
+ my $pkg = shift;
+ my %opts = @_;
+
+ my $bind_dn = $opts{'bind_dn'};
+ my $base_dn = $opts{'base_dn'};
+ my $uri = $opts{'uri'};
+ my $passwd = $opts{'password'};
+
+ my $msg;
+
+ die unless ($bind_dn and $base_dn and $uri and defined ($passwd));
+
+ $Ldap = Net::LDAP->new ($uri);
+
+ $msg = $Ldap->bind ($bind_dn, password => $passwd);
+ if ($msg->is_error ())
+ {
+ warn ('LDAP bind failed: ' . $msg->error_text ());
+ return (0);
+ }
+
+ $Config{'base_dn'} = $base_dn;
+
+ return (1);
+}
+
+=item LiCoM::Connection-E<gt>B<disconnect> ()
+
+Disconnect from the LDAP-Server.
+
+=cut
+
+sub disconnect
+{
+ $Ldap->unbind ();
+ $Ldap = undef;
+}
+
+=back
+
+=head1 AUTHOR
+
+Florian octo Forster E<lt>octo at verplant.orgE<gt>
+
+=cut