foreach $serv ( @serv ) { $command="/bin/ldapsearch -h $serv -b '' -s base 'objectclass=*' |"; DEBUG_msg("Forking child to run $command"); $pid=fork(); if ( ! defined $pid ) { ERROR_exit("Unable to fork process for $serv in $dmn"); } elsif ( $pid == 0 ) { # We are the child - run the LDAP command, find ldapServiceName and # compare the domain with the one we're checking and then exit # with the appropriate status ... open(INP,$command) or ERROR_exit("Unable to run LDAP search $!"); while( $data= ) { chomp($data); (@words)=split(/:/,$data); if ( $words[0] eq "ldapServiceName" ) { # Now have the info - extract domain ... $words[2]=~ s/.*\@//; $words[2]= lc($words[2]); DEBUG_msg(" Found $words[2] for $serv"); if ( $words[2] eq $dmn ) { DEBUG_msg(" matches expected domain - exit OK"); exit 5; } else { DEBUG_msg(" domain mismatch - exit FAIL"); exit 2; } } } close(INP); # Didnt find the data - exit from child with error exit 3; } else { # Still in parent $pid the PID of the child DEBUG_msg(" Child process $pid"); $pid_list{$pid}=$serv.":".$dmn; } } foreach $pid ( keys %pid_list ) { DEBUG_msg("Checking state of $pid"); $res=waitpid($pid,WNOHANG); $rc=$res >> 8; my $tst=$res/256; print STDERR "PID $pid res $res rc $rc test $tst ";