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