Code

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