Code

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