summaryrefslogtreecommitdiff
path: root/lib/Kolab/LDAP/Backend/slurpd.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Kolab/LDAP/Backend/slurpd.pm')
-rw-r--r--lib/Kolab/LDAP/Backend/slurpd.pm148
1 files changed, 75 insertions, 73 deletions
diff --git a/lib/Kolab/LDAP/Backend/slurpd.pm b/lib/Kolab/LDAP/Backend/slurpd.pm
index 8f7cb7a..26b83bb 100644
--- a/lib/Kolab/LDAP/Backend/slurpd.pm
+++ b/lib/Kolab/LDAP/Backend/slurpd.pm
@@ -44,15 +44,15 @@ our @ISA = qw(Exporter);
our %EXPORT_TAGS = (
'all' => [ qw(
- &startup
- &run
- ) ]
+ &startup
+ &run
+ ) ]
);
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw(
-
+
);
our $VERSION = '0.9';
@@ -234,37 +234,39 @@ sub run
my $listenport = $Kolab::config{'slurpd_port'};
my $listenaddr = $Kolab::config{'slurpd_addr'} || "127.0.0.1";
- TRYCONNECT:
+
+TRYCONNECT:
Kolab::log('SD', "Opening listen server on $listenaddr:$listenport");
$server = IO::Socket::INET->new(
- LocalPort => $listenport,
- Proto => "tcp",
- ReuseAddr => 1,
- Type => SOCK_STREAM,
- LocalAddr => $listenaddr,
- Listen => 10
- );
+ LocalPort => $listenport,
+ Proto => "tcp",
+ ReuseAddr => 1,
+ Type => SOCK_STREAM,
+ LocalAddr => $listenaddr,
+ Listen => 10
+ );
+
if (!$server) {
Kolab::log('SD', "Unable to open TCP listen server on $listenaddr:$listenport, Error = $@", KOLAB_ERROR);
- sleep 1;
- goto TRYCONNECT;
+ sleep 1;
+ goto TRYCONNECT;
}
Kolab::log('SD', 'Listen server opened, waiting for incoming connections');
while ($conn = $server->accept()) {
- # PENDING: Only accept connections from localhost and
- # hosts listed in the kolabhost attribute
+ # PENDING: Only accept connections from localhost and
+ # hosts listed in the kolabhost attribute
- my($peerport, $peeraddr) = sockaddr_in($conn->peername);
- $peeraddr = inet_ntoa( $peeraddr );
+ my($peerport, $peeraddr) = sockaddr_in($conn->peername);
+ $peeraddr = inet_ntoa( $peeraddr );
Kolab::log('SD', "Incoming connection accepted, peer=$peeraddr");
- if( $Kolab::config{'slurpd_accept_addr'} && $peeraddr ne $Kolab::config{'slurpd_accept_addr'} ) {
- Kolab::log('SD', "Unauthorized connection from $peeraddr, closing connection", KOLAB_WARN);
- $conn->close;
- undef $conn;
- next;
- }
+ if( $Kolab::config{'slurpd_accept_addr'} && $peeraddr ne $Kolab::config{'slurpd_accept_addr'} ) {
+ Kolab::log('SD', "Unauthorized connection from $peeraddr, closing connection", KOLAB_WARN);
+ $conn->close;
+ undef $conn;
+ next;
+ }
my $select = IO::Select->new($conn);
@@ -274,25 +276,25 @@ sub run
my $offset = 0;
if (!($select->can_read(0)) && $changes) {
- Kolab::log('SD', 'Change detected w/ no pending LDAP messages; waiting a second...');
- if( !($select->can_read(1)) ) {
- $changes = 0;
- Kolab::log('SD', 'Change detected w/ no pending LDAP messages; reloading services if needed');
- my $kidpid = fork();
- unless (defined $kidpid) {
- die("can't fork: $!");
- }
- if ($kidpid == 0 ) {
- # child
- Kolab::LDAP::sync;
- exit(0);
- }
- waitpid($kidpid, 0);
- Kolab::log('SD', "Running $Kolab::config{'kolabconf_script'}");
- system($Kolab::config{'kolabconf_script'}) == 0
- or Kolab::log('SD', "Failed to run $Kolab::config{'kolabconf_script'}: $?", KOLAB_ERROR);
- Kolab::log('SD', "$Kolab::config{'kolabconf_script'} complete");
- }
+ Kolab::log('SD', 'Change detected w/ no pending LDAP messages; waiting a second...');
+ if( !($select->can_read(1)) ) {
+ $changes = 0;
+ Kolab::log('SD', 'Change detected w/ no pending LDAP messages; reloading services if needed');
+ my $kidpid = fork();
+ unless (defined $kidpid) {
+ die("can't fork: $!");
+ }
+ if ($kidpid == 0 ) {
+ # child
+ Kolab::LDAP::sync;
+ exit(0);
+ }
+ waitpid($kidpid, 0);
+ Kolab::log('SD', "Running $Kolab::config{'kolabconf_script'}");
+ system($Kolab::config{'kolabconf_script'}) == 0
+ or Kolab::log('SD', "Failed to run $Kolab::config{'kolabconf_script'}: $?", KOLAB_ERROR);
+ Kolab::log('SD', "$Kolab::config{'kolabconf_script'} complete");
+ }
}
Kolab::log('SD', 'Waiting for LDAP updates');
@@ -300,12 +302,12 @@ sub run
for ($ready = 1; $conn && $ready; $ready = $select->can_read(0)) {
Kolab::log('SD', 'Reading ASN', KOLAB_DEBUG);
my $newoffset = asn_read($conn, $pdu, $offset);
- if( !$conn->connected() or $offset == $newoffset ) {
- Kolab::log('SD', 'Connection closed', KOLAB_DEBUG);
- $conn->close;
- undef $conn;
- }
- $offset = $newoffset;
+ if( !$conn->connected() or $offset == $newoffset ) {
+ Kolab::log('SD', 'Connection closed', KOLAB_DEBUG);
+ $conn->close;
+ undef $conn;
+ }
+ $offset = $newoffset;
defined($offset) or $offset = 0;
}
@@ -313,29 +315,29 @@ sub run
$request = $LDAPRequest->decode($pdu);
if (!$request) {
Kolab::log('SD', "Unable to decode slurpd request, Error = `" . $LDAPRequest->error . "'", KOLAB_ERROR);
- $conn->close if $conn;
- undef $conn;
- undef $pdu;
+ $conn->close if $conn;
+ undef $conn;
+ undef $pdu;
} else {
- $_ = getRequestType($request);
- Kolab::log('SD', "Request $_ received", KOLAB_DEBUG);
- undef $pdu;
-
- SWITCH: {
- if (/^bindRequest/) { $pdu = responseBind($request); last SWITCH; }
- if (/addRequest/) { $pdu = responseAdd($request); $changes = 1; last SWITCH; }
- if (/delRequest/) { $pdu = responseDel($request); $changes = 1; last SWITCH; }
- if (/modifyRequest/) { $pdu = responseMod($request); $changes = 1; last SWITCH; }
- if (/modDNRequest/) { $pdu = responseModDN($request); $changes = 1; last SWITCH; }
-
- if( $conn ) {
- Kolab::log('SD', 'Unknown request, connection closed', KOLAB_DEBUG);
- $conn->close;
- undef $conn;
- }
- }
- }
- }
+ $_ = getRequestType($request);
+ Kolab::log('SD', "Request $_ received", KOLAB_DEBUG);
+ undef $pdu;
+
+ SWITCH: {
+ if (/^bindRequest/) { $pdu = responseBind($request); last SWITCH; }
+ if (/addRequest/) { $pdu = responseAdd($request); $changes = 1; last SWITCH; }
+ if (/delRequest/) { $pdu = responseDel($request); $changes = 1; last SWITCH; }
+ if (/modifyRequest/) { $pdu = responseMod($request); $changes = 1; last SWITCH; }
+ if (/modDNRequest/) { $pdu = responseModDN($request); $changes = 1; last SWITCH; }
+
+ if( $conn ) {
+ Kolab::log('SD', 'Unknown request, connection closed', KOLAB_DEBUG);
+ $conn->close;
+ undef $conn;
+ }
+ }
+ }
+ }
if ($pdu) {
Kolab::log('SD', 'Writing response', KOLAB_DEBUG);
@@ -343,8 +345,8 @@ sub run
$response = $LDAPResponse->decode($pdu);
if (!$response) {
Kolab::log('SD', "Unable to decode slurpd request, Error = `" . $LDAPRequest->error . "'");
- $conn->close;
- undef $conn;
+ $conn->close;
+ undef $conn;
}
}
}