Code

Added workaround for some ipv6 setups.
[gosa.git] / gosa-si / modules / ArpHandler.pm
1 package ArpHandler;
3 use Exporter;
4 @ISA = ("Exporter");
6 use strict;
7 use warnings;
8 use GOSA::GosaSupportDaemon;
9 use Getopt::Long;
10 use Config::IniFiles;
11 use POSIX;
12 use Fcntl;
13 use Net::LDAP;
14 use Net::LDAP::LDIF;
15 use Net::LDAP::Entry;
16 use Net::DNS;
17 use Switch;
18 use Data::Dumper;
19 use Socket qw/PF_INET SOCK_DGRAM inet_ntoa sockaddr_in/;
20 use POE qw(Component::Pcap Component::ArpWatch);
22 BEGIN{}
23 END{}
25 my ($timeout, $mailto, $mailfrom, $user, $group);
26 my %daemon_children;
27 my ($ldap, $bind_phrase, $password, $ldap_base, $interface) ;
28 my $hosts_database={};
29 my $resolver=Net::DNS::Resolver->new;
31 $ldap_base = "dc=gonicus,dc=de" ;
32 $interface = "all";
34 sub get_module_info {
35         my @info = (undef,
36                 undef,
37                 undef,
38                 undef,
39                 "socket",
40         );
42         $ldap = Net::LDAP->new("ldap.intranet.gonicus.de") or die "$@";
44         # When interface is not configured (or 'all'), start arpwatch on all possible interfaces
45         if ((!defined($interface)) || $interface eq 'all') {
46                 foreach my $device(&get_interfaces) {
47                         # TODO: Need a better workaround for IPv4-to-IPv6 bridges
48                         if($device =~ m/^sit.$/) {
49                                 next;
50                         }
52                         # If device has a valid mac address
53                         if(not(&get_mac($device) eq "00:00:00:00:00:00")) {
54                                 &main::daemon_log("Starting ArpWatch on $device", 1);
55                                 POE::Session->create( 
56                                         inline_states => {
57                                                 _start => sub {
58                                                         &start(@_,$device);
59                                                 },
60                                                 _stop => sub {
61                                                         $_[KERNEL]->post( sprintf("arp_watch_$device") => 'shutdown' )
62                                                 },
63                                                 got_packet => \&got_packet,
64                                         },
65                                 );
66                         }
67                 }
68         } else {
69                 &main::daemon_log("Starting ArpWatch on $interface", 1);
70                 POE::Session->create( 
71                         inline_states => {
72                                 _start => \&start,
73                                 _stop => sub {
74                                         $_[KERNEL]->post( sprintf("arp_watch_$interface") => 'shutdown' )
75                                 },
76                                 got_packet => \&got_packet,
77                         },
78                 );
79         }
81         return \@info;
82 }
84 sub process_incoming_msg {
85         return 1;
86 }
88 sub start {
89         my $device = (exists($_[ARG0])?$_[ARG0]:'eth0');
90         POE::Component::ArpWatch->spawn( 
91                 Alias => sprintf("arp_watch_$device"),
92                 Device => $device, 
93                 Dispatch => 'got_packet',
94                 Session => $_[SESSION],
95         );
97         $_[KERNEL]->post( sprintf("arp_watch_$device") => 'run' );
98 }
100 sub got_packet {
101         my $packet = $_[ARG0];
103         if(     $packet->{source_haddr} eq "00:00:00:00:00:00" || 
104                 $packet->{source_haddr} eq "ff:ff:ff:ff:ff:ff" || 
105                 $packet->{source_ipaddr} eq "0.0.0.0") {
106                 return;
107         }
109         if(!exists($hosts_database->{$packet->{source_haddr}})) {
110                 my $dnsresult= $resolver->search($packet->{source_ipaddr});
111                 my $dnsname= (defined($dnsresult))?$dnsresult->{answer}[0]->{ptrdname}:$packet->{source_ipaddr};
112                 my $ldap_result=&get_host_from_ldap($packet->{source_haddr});
113                 if(exists($ldap_result->{dn})) {
114                         $hosts_database->{$packet->{source_haddr}}=$ldap_result;
115                         if(!exists($ldap_result->{ipHostNumber})) {
116                                 $hosts_database->{$packet->{source_haddr}}->{ipHostNumber}=$packet->{source_ipaddr};
117                         } else {
118                                 if(!($ldap_result->{ipHostNumber} eq $packet->{source_ipaddr})) {
119                                         &main::daemon_log(
120                                                 "Current IP Address ".$packet->{source_ipaddr}.
121                                                 " of host ".$ldap_result->{dnsname}.
122                                                 " differs from LDAP (".$ldap_result->{ipHostNumber}.")", 4);
123                                 }
124                         }
125                         $hosts_database->{$packet->{source_haddr}}->{dnsname}=$dnsname;
126                         &main::daemon_log("Host was found in LDAP as ".$ldap_result->{dn}, 6);
127                 } else {
128                         $hosts_database->{$packet->{source_haddr}}={
129                                 macAddress => $packet->{source_haddr},
130                                 ipHostNumber => $packet->{source_ipaddr},
131                                 dnsname => $dnsname,
132                         };
133                         &main::daemon_log("Host was not found in LDAP (".($hosts_database->{$packet->{source_haddr}}->{dnsname}).")",6);
134                         &main::daemon_log(
135                                 "New Host ".($hosts_database->{$packet->{source_haddr}}->{dnsname}).
136                                 ": ".$hosts_database->{$packet->{source_haddr}}->{ipHostNumber}.
137                                 "/".$hosts_database->{$packet->{source_haddr}}->{macAddress},4);
138                 }
139         } else {
140                 if(!($hosts_database->{$packet->{source_haddr}}->{ipHostNumber} eq $packet->{source_ipaddr})) {
141                         &main::daemon_log(
142                                 "IP Address change of MAC ".$packet->{source_haddr}.
143                                 ": ".$hosts_database->{$packet->{source_haddr}}->{ipHostNumber}.
144                                 "->".$packet->{source_ipaddr}, 4);
145                         $hosts_database->{$packet->{source_haddr}}->{ipHostNumber}= $packet->{source_ipaddr};
146                 }
147                 &main::daemon_log("Host already in cache (".($hosts_database->{$packet->{source_haddr}}->{dnsname}).")",6);
148         }
149
151 sub get_host_from_ldap {
152         my $mac=shift;
153         my $result={};
154                 
155         my $ldap_result= search_ldap_entry(
156                 $ldap,
157                 $ldap_base,
158                 "(|(macAddress=$mac)(dhcpHWAddress=ethernet $mac))"
159         );
161         if($ldap_result->count==1) {
162                 if(exists($ldap_result->{entries}[0]) && 
163                         exists($ldap_result->{entries}[0]->{asn}->{objectName}) && 
164                         exists($ldap_result->{entries}[0]->{asn}->{attributes})) {
166                         for my $attribute(@{$ldap_result->{entries}[0]->{asn}->{attributes}}) {
167                                 if($attribute->{type} eq 'cn') {
168                                         $result->{cn} = $attribute->{vals}[0];
169                                 }
170                                 if($attribute->{type} eq 'macAddress') {
171                                         $result->{macAddress} = $attribute->{vals}[0];
172                                 }
173                                 if($attribute->{type} eq 'dhcpHWAddress') {
174                                         $result->{dhcpHWAddress} = $attribute->{vals}[0];
175                                 }
176                                 if($attribute->{type} eq 'ipHostNumber') {
177                                         $result->{ipHostNumber} = $attribute->{vals}[0];
178                                 }
179                         }
180                 }
181                 $result->{dn} = $ldap_result->{entries}[0]->{asn}->{objectName};
182         }
184         return $result;
187 #===  FUNCTION  ================================================================
188 #         NAME:  get_interfaces 
189 #   PARAMETERS:  none
190 #      RETURNS:  (list of interfaces) 
191 #  DESCRIPTION:  Uses proc fs (/proc/net/dev) to get list of interfaces.
192 #===============================================================================
193 sub get_interfaces {
194         my @result;
195         my $PROC_NET_DEV= ('/proc/net/dev');
197         open(PROC_NET_DEV, "<$PROC_NET_DEV")
198                 or die "Could not open $PROC_NET_DEV";
200         my @ifs = <PROC_NET_DEV>;
202         close(PROC_NET_DEV);
204         # Eat first two line
205         shift @ifs;
206         shift @ifs;
208         chomp @ifs;
209         foreach my $line(@ifs) {
210                 my $if= (split /:/, $line)[0];
211                 $if =~ s/^\s+//;
212                 push @result, $if;
213         }
215         return @result;
218 #===  FUNCTION  ================================================================
219 #         NAME:  get_mac 
220 #   PARAMETERS:  interface name (i.e. eth0)
221 #      RETURNS:  (mac address) 
222 #  DESCRIPTION:  Uses ioctl to get mac address directly from system.
223 #===============================================================================
224 sub get_mac {
225         my $ifreq= shift;
226         my $result;
227         if ($ifreq && length($ifreq) > 0) { 
228                 if($ifreq eq "all") {
229                         $result = "00:00:00:00:00:00";
230                 } else {
231                         my $SIOCGIFHWADDR= 0x8927;     # man 2 ioctl_list
233                         socket SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('ip')
234                                 or die "socket: $!";
236                         if(ioctl SOCKET, $SIOCGIFHWADDR, $ifreq) {
237                                 my ($if, $mac)= unpack 'h36 H12', $ifreq;
239                                 if (length($mac) > 0) {
240                                         $mac=~ m/^([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/;
241                                         $mac= sprintf("%s:%s:%s:%s:%s:%s", $1, $2, $3, $4, $5, $6);
242                                         $result = $mac;
243                                 }
244                         }
245                 }
246         }
247         return $result;
250 #===  FUNCTION  ================================================================
251 #         NAME:  add_ldap_entry
252 #      PURPOSE:  adds an element to ldap-tree
253 #   PARAMETERS:  
254 #      RETURNS:  none
255 #  DESCRIPTION:  ????
256 #       THROWS:  no exceptions
257 #     COMMENTS:  none
258 #     SEE ALSO:  n/a
259 #===============================================================================
260 #sub add_ldap_entry {
261 #    my ($ldap_tree, $ldap_base, $mac, $gotoSysStatus, $ip, $interface, $desc) = @_;
262 #    my $dn = "cn=$mac,ou=incoming,$ldap_base";
263 #    my $s_res = &search_ldap_entry($ldap_tree, $ldap_base, "(|(macAddress=$mac)(dhcpHWAddress=ethernet $mac))");
264 #    my $c_res = $s_res->count;
265 #    if($c_res == 1) {
266 #        daemon_log("WARNING: macAddress $mac already in LDAP", 1);
267 #        return;
268 #    } elsif($c_res > 0) {
269 #        daemon_log("ERROR: macAddress $mac exists $c_res times in LDAP", 1);
270 #        return;
271 #    }
273 #    # create LDAP entry 
274 #    my $entry = Net::LDAP::Entry->new( $dn );
275 #    $entry->dn($dn);
276 #    $entry->add("objectClass" => "goHard");
277 #    $entry->add("cn" => $mac);
278 #    $entry->add("macAddress" => $mac);
279 #    if(defined $gotoSysStatus) {$entry->add("gotoSysStatus" => $gotoSysStatus)}
280 #    if(defined $ip) {$entry->add("ipHostNumber" => $ip) }
281 #    #if(defined $interface) { }
282 #    if(defined $desc) {$entry->add("description" => $desc) }
283 #    
284 #    # submit entry to LDAP
285 #    my $result = $entry->update ($ldap_tree); 
286 #        
287 #    # for $result->code constants please look at Net::LDAP::Constant
288 #    my $log_time = localtime( time );
289 #    if($result->code == 68) {   # entry already exists 
290 #        daemon_log("WARNING: $log_time: $dn ".$result->error, 3);
291 #    } elsif($result->code == 0) {   # everything went fine
292 #        daemon_log("$log_time: add entry $dn to ldap", 1);
293 #    } else {  # if any other error occur
294 #        daemon_log("ERROR: $log_time: $dn, ".$result->code.", ".$result->error, 1);
295 #    }
296 #    return;
297 #}
300 #===  FUNCTION  ================================================================
301 #         NAME:  change_ldap_entry
302 #      PURPOSE:  ????
303 #   PARAMETERS:  ????
304 #      RETURNS:  ????
305 #  DESCRIPTION:  ????
306 #       THROWS:  no exceptions
307 #     COMMENTS:  none
308 #     SEE ALSO:  n/a
309 #===============================================================================
310 #sub change_ldap_entry {
311 #    my ($ldap_tree, $ldap_base, $mac, $gotoSysStatus ) = @_;
312 #    
313 #    # check if ldap_entry exists or not
314 #    my $s_res = &search_ldap_entry($ldap_tree, $ldap_base, "(|(macAddress=$mac)(dhcpHWAddress=ethernet $mac))");
315 #    my $c_res = $s_res->count;
316 #    if($c_res == 0) {
317 #        daemon_log("WARNING: macAddress $mac not in LDAP", 1);
318 #        return;
319 #    } elsif($c_res > 1) {
320 #        daemon_log("ERROR: macAddress $mac exists $c_res times in LDAP", 1);
321 #        return;
322 #    }
324 #    my $s_res_entry = $s_res->pop_entry();
325 #    my $dn = $s_res_entry->dn();
326 #    my $result = $ldap->modify( $dn, replace => {'gotoSysStatus' => $gotoSysStatus } );
328 #    # for $result->code constants please look at Net::LDAP::Constant
329 #    my $log_time = localtime( time );
330 #    if($result->code == 32) {   # entry doesnt exists 
331 #        &add_ldap_entry($mac, $gotoSysStatus);
332 #    } elsif($result->code == 0) {   # everything went fine
333 #        daemon_log("$log_time: entry $dn changed successful", 1);
334 #    } else {  # if any other error occur
335 #        daemon_log("ERROR: $log_time: $dn, ".$result->code.", ".$result->error, 1);
336 #    }
338 #    return;
339 #}
341 #===  FUNCTION  ================================================================
342 #         NAME:  search_ldap_entry
343 #      PURPOSE:  ????
344 #   PARAMETERS:  [Net::LDAP] $ldap_tree - object of an ldap-tree
345 #                string $sub_tree - dn of the subtree the search is performed
346 #                string $search_string - either a string or a Net::LDAP::Filter object
347 #      RETURNS:  [Net::LDAP::Search] $msg - result object of the performed search
348 #  DESCRIPTION:  ????
349 #       THROWS:  no exceptions
350 #     COMMENTS:  none
351 #     SEE ALSO:  n/a
352 #===============================================================================
353 sub search_ldap_entry {
354     my ($ldap_tree, $sub_tree, $search_string) = @_;
355     my $msg = $ldap_tree->search( # perform a search
356                         base   => $sub_tree,
357                         filter => $search_string,
358                       ) or daemon_log("cannot perform search at ldap: $@", 1);
359 #    if(defined $msg) {
360 #        print $sub_tree."\t".$search_string."\t";
361 #        print $msg->count."\n";
362 #        foreach my $entry ($msg->entries) { $entry->dump; };
363 #    }
365     return $msg;
370 #========= MAIN = main ========================================================
371 #daemon_log( "####### START DAEMON ######\n", 1 );
372 #&check_cmdline_param ;
373 #&check_pid;
374 #&open_fifo($fifo_path);
376 ## Just fork, if we"re not in foreground mode
377 #if( ! $foreground ) { $pid = fork(); }
378 #else { $pid = $$; }
380 ## Do something useful - put our PID into the pid_file
381 #if( 0 != $pid ) {
382 #    open( LOCK_FILE, ">$pid_file" );
383 #    print LOCK_FILE "$pid\n";
384 #    close( LOCK_FILE );
385 #    if( !$foreground ) { exit( 0 ) };
386 #}
389 #if( not -p $fifo_path ) { die "fifo file disappeared\n" }
390 #if($c_res == 1) {
391 #        daemon_log("WARNING: macAddress $mac already in LDAP", 1);
392 #        return;
393 #    } elsif($c_res > 0) {
394 #        daemon_log("ERROR: macAddress $mac exists $c_res times in LDAP", 1);
395 #        return;
396 #    }
398 #    # create LDAP entry 
399 #    my $entry = Net::LDAP::Entry->new( $dn );
400 #    $entry->dn($dn);
401 #    $entry->add("objectClass" => "goHard");
402 #    $entry->add("cn" => $mac);
403 #    $entry->add("macAddress" => $mac);
404 #    if(defined $gotoSysStatus) {$entry->add("gotoSysStatus" => $gotoSysStatus)}
405 #    if(defined $ip) {$entry->add("ipHostNumber" => $ip) }
406 #    #if(defined $interface) { }
407 #    if(defined $desc) {$entry->add("description" => $desc) }
408 #    
409 #    # submit entry to LDAP
410 #    my $result = $entry->update ($ldap_tree); 
411 #        
412 #    # for $result->code constants please look at Net::LDAP::Constant
413 #    my $log_time = localtime( time );
414 #    if($result->code == 68) {   # entry already exists 
415 #        daemon_log("WARNING: $log_time: $dn ".$result->error, 3);
416 #    } elsif($result->code == 0) {   # everything went fine
417 #        daemon_log("$log_time: add entry $dn to ldap", 1);
418 #    } else {  # if any other error occur
419 #        daemon_log("ERROR: $log_time: $dn, ".$result->code.", ".$result->error, 1);
420 #    }
421 #    return;
422 #}
425 #===  FUNCTION  ================================================================
426 #         NAME:  change_ldap_entry
427 #      PURPOSE:  ????
428 #   PARAMETERS:  ????
429 #      RETURNS:  ????
430 #  DESCRIPTION:  ????
431 #       THROWS:  no exceptions
432 #     COMMENTS:  none
433 #     SEE ALSO:  n/a
434 #===============================================================================
435 #sub change_ldap_entry {
436 #    my ($ldap_tree, $ldap_base, $mac, $gotoSysStatus ) = @_;
437 #    
438 #    # check if ldap_entry exists or not
439 #    my $s_res = &search_ldap_entry($ldap_tree, $ldap_base, "(|(macAddress=$mac)(dhcpHWAddress=ethernet $mac))");
440 #    my $c_res = $s_res->count;
441 #    if($c_res == 0) {
442 #        daemon_log("WARNING: macAddress $mac not in LDAP", 1);
443 #        return;
444 #    } elsif($c_res > 1) {
445 #        daemon_log("ERROR: macAddress $mac exists $c_res times in LDAP", 1);
446 #        return;
447 #    }
449 #    my $s_res_entry = $s_res->pop_entry();
450 #    my $dn = $s_res_entry->dn();
451 #    my $result = $ldap->modify( $dn, replace => {'gotoSysStatus' => $gotoSysStatus } );
453 #    # for $result->code constants please look at Net::LDAP::Constant
454 #    my $log_time = localtime( time );
455 #    if($result->code == 32) {   # entry doesnt exists 
456 #        &add_ldap_entry($mac, $gotoSysStatus);
457 #    } elsif($result->code == 0) {   # everything went fine
458 #        daemon_log("$log_time: entry $dn changed successful", 1);
459 #    } else {  # if any other error occur
460 #        daemon_log("ERROR: $log_time: $dn, ".$result->code.", ".$result->error, 1);
461 #    }
463 #    return;
464 #}
466 #===  FUNCTION  ================================================================
467 #         NAME:  search_ldap_entry
468 #      PURPOSE:  ????
469 #   PARAMETERS:  [Net::LDAP] $ldap_tree - object of an ldap-tree
470 #                string $sub_tree - dn of the subtree the search is performed
471 #                string $search_string - either a string or a Net::LDAP::Filter object
472 #      RETURNS:  [Net::LDAP::Search] $msg - result object of the performed search
473 #  DESCRIPTION:  ????
474 #       THROWS:  no exceptions
475 #     COMMENTS:  none
476 #     SEE ALSO:  n/a
477 #===============================================================================
478 #sub search_ldap_entry {
479 #    my ($ldap_tree, $sub_tree, $search_string) = @_;
480 #    my $msg = $ldap_tree->search( # perform a search
481 #                        base   => $sub_tree,
482 #                        filter => $search_string,
483 #                      ) or daemon_log("cannot perform search at ldap: $@", 1);
484 ##    if(defined $msg) {
485 ##        print $sub_tree."\t".$search_string."\t";
486 ##        print $msg->count."\n";
487 ##        foreach my $entry ($msg->entries) { $entry->dump; };
488 ##    }
490 #    return $msg;
491 #}
495 #========= MAIN = main ========================================================
496 #daemon_log( "####### START DAEMON ######\n", 1 );
497 #&check_cmdline_param ;
498 #&check_pid;
499 #&open_fifo($fifo_path);
501 ## Just fork, if we"re not in foreground mode
502 #if( ! $foreground ) { $pid = fork(); }
503 #else { $pid = $$; }
505 ## Do something useful - put our PID into the pid_file
506 #if( 0 != $pid ) {
507 #    open( LOCK_FILE, ">$pid_file" );
508 #    print LOCK_FILE "$pid\n";
509 #    close( LOCK_FILE );
510 #    if( !$foreground ) { exit( 0 ) };
511 #}
514 #if( not -p $fifo_path ) { die "fifo file disappeared\n" }
515 #sysopen(FIFO, $fifo_path, O_RDONLY) or die "can't read from $fifo_path: $!" ;
517 #while( 1 ) {
518 #    # checke alle prozesse im hash daemon_children ob sie noch aktiv sind, wenn
519 #    # nicht, dann entferne prozess aus hash
520 #    while( (my $key, my $val) = each( %daemon_children) ) {
521 #        my $status = waitpid( $key, &WNOHANG) ;
522 #        if( $status == -1 ) { 
523 #            delete $daemon_children{$key} ; 
524 #            daemon_log("childprocess finished: $key", 3) ;
525 #        }
526 #    }
528 #    # ist die max_process anzahl von prozesskindern erreicht, dann warte und 
529 #    # prüfe erneut, ob in der zwischenzeit prozesse fertig geworden sind
530 #    if( keys( %daemon_children ) >= $max_process ) { 
531 #        sleep($max_process_timeout) ;
532 #        next ;
533 #    }
535 #    my $msg = <FIFO>;
536 #    if( not defined( $msg )) { next ; }
537 #    
538 #    chomp( $msg );
539 #    if( length( $msg ) == 0 ) { next ; }
541 #    my $forked_pid = fork();
542 ##=== PARENT = parent ==========================================================
543 #    if ( $forked_pid != 0 ) { 
544 #        daemon_log("childprocess forked: $forked_pid", 3) ;
545 #        $daemon_children{$forked_pid} = 0 ;
546 #    }
547 ##=== CHILD = child ============================================================
548 #    else {
549 #        # parse the incoming message from arp, split the message and return 
550 #        # the values in an array. not defined values are set to "none" 
551 #        #my ($mac, $ip, $interface, $arp_sig, $desc) = &parse_input( $msg ) ;
552 #        daemon_log( "childprocess read from arp: $fifo_path\nline: $msg", 3);
553 #        my ($mac, $ip, $interface, $arp_sig, $desc) = split('\s', $msg, 5);
555 #        # create connection to LDAP
556 #        $#sysopen(FIFO, $fifo_path, O_RDONLY) or die "can't read from $fifo_path: $!" ;
558 #while( 1 ) {
559 #    # checke alle prozesse im hash daemon_children ob sie noch aktiv sind, wenn
560 #    # nicht, dann entferne prozess aus hash
561 #    while( (my $key, my $val) = each( %daemon_children) ) {
562 #        my $status = waitpid( $key, &WNOHANG) ;
563 #        if( $status == -1 ) { 
564 #            delete $daemon_children{$key} ; 
565 #            daemon_log("childprocess finished: $key", 3) ;
566 #        }
567 #    }
569 #    # ist die max_process anzahl von prozesskindern erreicht, dann warte und 
570 #    # prüfe erneut, ob in der zwischenzeit prozesse fertig geworden sind
571 #    if( keys( %daemon_children ) >= $max_process ) { 
572 #        sleep($max_process_timeout) ;
573 #        next ;
574 #    }
576 #    my $msg = <FIFO>;
577 #    if( not defined( $msg )) { next ; }
578 #    
579 #    chomp( $msg );
580 #    if( length( $msg ) == 0 ) { next ; }
582 #    my $forked_pid = fork();
583 ##=== PARENT = parent ==========================================================
584 #    if ( $forked_pid != 0 ) { 
585 #        daemon_log("childprocess forked: $forked_pid", 3) ;
586 #        $daemon_children{$forked_pid} = 0 ;
587 #    }
588 ##=== CHILD = child ============================================================
589 #    else {
590 #        # parse the incoming message from arp, split the message and return 
591 #        # the values in an array. not defined values are set to "none" 
592 #        #my ($mac, $ip, $interface, $arp_sig, $desc) = &parse_input( $msg ) ;
593 #        daemon_log( "childprocess read from arp: $fifo_path\nline: $msg", 3);
594 #        my ($mac, $ip, $interface, $arp_sig, $desc) = split('\s', $msg, 5);
596 #        # create connection to LDAP
597 #        $ldap = Net::LDAP->new( "localhost" ) or die "$@";
598 #        $ldap->bind($bind_phrase,
599 #                    password => $password,
600 #                    ) ;
601 #        
602 #        switch($arp_sig) {
603 #            case 0 {&change_ldap_entry($ldap, $ldap_base, 
604 #                                      $mac, "ip-changed",
605 #                                      )} 
606 #            case 1 {&change_ldap_entry($ldap, $ldap_base, 
607 #                                      $mac, "mac-not-whitelisted",
608 #                                      )}
609 #            case 2 {&change_ldap_entry($ldap, $ldap_base, 
610 #                                      $mac, "mac-in-blacklist",
611 #                                      )}
612 #            case 3 {&add_ldap_entry($ldap, $ldap_base, 
613 #                                   $mac, "new-mac-address", $ip, 
614 #                                   $interface, $desc, 
615 #                                   )}
616 #            case 4 {&change_ldap_entry($ldap, $ldap_base, 
617 #                                      $mac, "unauthorized-arp-request",
618 #                                      )}
619 #            case 5 {&change_ldap_entry($ldap, $ldap_base, 
620 #                                      $mac, "abusive-number-of-arp-requests",
621 #                                      )}
622 #            case 6 {&change_ldap_entry($ldap, $ldap_base, 
623 #                                      $mac, "ether-and-arp-mac-differs",
624 #                                      )}
625 #            case 7 {&change_ldap_entry($ldap, $ldap_base, 
626 #                                      $mac, "flood-detected",
627 #                                      )}
628 #            case 8 {&add_ldap_entry($ldap, $ldap_base, 
629 #                                   $mac, $ip, "new-system",
630 #                                   )}
631 #            case 9 {&change_ldap_entry($ldap, $ldap_base, 
632 #                                      $mac, "mac-changed",
633 #                                      )}
634 #        }
637         # ldap search
638 #        my $base_phrase = "dc=gonicus,dc=de";
639 #        my $filter_phrase = "cn=keinesorge";
640 #        my $attrs_phrase = "cn macAdress";
641 #        my $msg_search = $ldap->search( base   => $base_phrase,
642 #                                        filter => $filter_phrase,
643 #                                        attrs => $attrs_phrase,
644 #                                        );
645 #        $msg_search->code && die $msg_search->error;
646 #        
647 #        my @entries = $msg_search->entries;
648 #        my $max = $msg_search->count;
649 #        print "anzahl der entries: $max\n";
650 #        my $i;
651 #        for ( $i = 0 ; $i < $max ; $i++ ) {
652 #            my $entry = $msg_search->entry ( $i );
653 #            foreach my $attr ( $entry->attributes ) {
654 #                if( not $attr eq "cn") {
655 #                    next;
656 #                }
657 #                print join( "\n ", $attr, $entry->get_value( $attr ) ), "\n\n";
658 #            }
659 #        }
660                 #
661                 #        # ldap add
662                 #       
663                 #        
664                 #        $ldap->unbind;
665                 #        exit;
666                 #    }
667                 #
668                 #}
670 1;