1 package SIPackages;
3 use Exporter;
4 @ISA = ("Exporter");
6 # Each module has to have a function 'process_incoming_msg'. This function works as a interface to gosa-sd and receives the msg hash from gosa-sd. 'process_incoming_function checks, wether it has a function to process the incoming msg and forward the msg to it.
9 use strict;
10 use warnings;
11 use GOSA::GosaSupportDaemon;
12 use IO::Socket::INET;
13 use XML::Simple;
14 use Data::Dumper;
15 use Net::LDAP;
16 use Socket qw/PF_INET SOCK_DGRAM inet_ntoa sockaddr_in/;
18 BEGIN{}
19 END {}
21 my ($known_clients_file_name);
22 my ($server_activ, $server_ip, $server_mac_address, $server_port, $server_passwd, $max_clients, $ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password);
23 my ($bus_activ, $bus_passwd, $bus_ip, $bus_port);
24 my $server;
25 my $network_interface;
26 my $no_bus;
27 my (@ldap_cfg, @pam_cfg, @nss_cfg, $goto_admin, $goto_secret);
30 my %cfg_defaults =
31 (
32 "server" =>
33 {"server_activ" => [\$server_activ, "on"],
34 "server_ip" => [\$server_ip, "0.0.0.0"],
35 "server_mac_address" => [\$server_mac_address, ""],
36 "server_port" => [\$server_port, "20081"],
37 "server_passwd" => [\$server_passwd, ""],
38 "max_clients" => [\$max_clients, 100],
39 "ldap_uri" => [\$ldap_uri, ""],
40 "ldap_base" => [\$ldap_base, ""],
41 "ldap_admin_dn" => [\$ldap_admin_dn, ""],
42 "ldap_admin_password" => [\$ldap_admin_password, ""],
43 },
44 "bus" =>
45 {"bus_activ" => [\$bus_activ, "on"],
46 "bus_passwd" => [\$bus_passwd, ""],
47 "bus_ip" => [\$bus_ip, ""],
48 "bus_port" => [\$bus_port, "20080"],
49 },
50 );
52 ### START #####################################################################
54 # read configfile and import variables
55 &read_configfile();
57 # detect interfaces and mac address
58 $network_interface= &get_interface_for_ip($server_ip);
59 $server_mac_address= &get_mac($network_interface);
61 # complete addresses
62 if( $server_ip eq "0.0.0.0" ) {
63 $server_ip = "127.0.0.1";
64 }
65 my $server_address = "$server_ip:$server_port";
66 my $bus_address = "$bus_ip:$bus_port";
68 # create general settings for this module
69 my $xml = new XML::Simple();
71 # register at bus
72 if ($main::no_bus > 0) {
73 $bus_activ = "off"
74 }
75 if($bus_activ eq "on") {
76 ®ister_at_bus();
77 }
79 ### functions #################################################################
82 sub get_module_info {
83 my @info = ($server_address,
84 $server_passwd,
85 $server,
86 $server_activ,
87 "socket",
88 );
89 return \@info;
90 }
93 #=== FUNCTION ================================================================
94 # NAME: read_configfile
95 # PARAMETERS: cfg_file - string -
96 # RETURNS: nothing
97 # DESCRIPTION: read cfg_file and set variables
98 #===============================================================================
99 sub read_configfile {
100 my $cfg;
101 if( defined( $main::cfg_file) && ( length($main::cfg_file) > 0 )) {
102 if( -r $main::cfg_file ) {
103 $cfg = Config::IniFiles->new( -file => $main::cfg_file );
104 } else {
105 print STDERR "Couldn't read config file!";
106 }
107 } else {
108 $cfg = Config::IniFiles->new() ;
109 }
110 foreach my $section (keys %cfg_defaults) {
111 foreach my $param (keys %{$cfg_defaults{ $section }}) {
112 my $pinfo = $cfg_defaults{ $section }{ $param };
113 ${@$pinfo[0]} = $cfg->val( $section, $param, @$pinfo[1] );
114 }
115 }
117 # Read non predefined sections
118 my $param;
119 if ($cfg->SectionExists('ldap')){
120 foreach $param ($cfg->Parameters('ldap')){
121 push (@ldap_cfg, "$param ".$cfg->val('ldap', $param));
122 }
123 }
124 if ($cfg->SectionExists('pam_ldap')){
125 foreach $param ($cfg->Parameters('pam_ldap')){
126 push (@pam_cfg, "$param ".$cfg->val('pam_ldap', $param));
127 }
128 }
129 if ($cfg->SectionExists('nss_ldap')){
130 foreach $param ($cfg->Parameters('nss_ldap')){
131 push (@nss_cfg, "$param ".$cfg->val('nss_ldap', $param));
132 }
133 }
134 if ($cfg->SectionExists('goto')){
135 $goto_admin= $cfg->val('goto', 'terminal_admin');
136 $goto_secret= $cfg->val('goto', 'terminal_secret');
137 } else {
138 $goto_admin= undef;
139 $goto_secret= undef;
140 }
142 }
144 #=== FUNCTION ================================================================
145 # NAME: get_interface_for_ip
146 # PARAMETERS: ip address (i.e. 192.168.0.1)
147 # RETURNS: array: list of interfaces if ip=0.0.0.0, matching interface if found, undef else
148 # DESCRIPTION: Uses proc fs (/proc/net/dev) to get list of interfaces.
149 #===============================================================================
150 sub get_interface_for_ip {
151 my $result;
152 my $ip= shift;
153 if ($ip && length($ip) > 0) {
154 my @ifs= &get_interfaces();
155 if($ip eq "0.0.0.0") {
156 $result = "all";
157 } else {
158 foreach (@ifs) {
159 my $if=$_;
160 if(get_ip($if) eq $ip) {
161 $result = $if;
162 }
163 }
164 }
165 }
166 return $result;
167 }
169 #=== FUNCTION ================================================================
170 # NAME: get_interfaces
171 # PARAMETERS: none
172 # RETURNS: (list of interfaces)
173 # DESCRIPTION: Uses proc fs (/proc/net/dev) to get list of interfaces.
174 #===============================================================================
175 sub get_interfaces {
176 my @result;
177 my $PROC_NET_DEV= ('/proc/net/dev');
179 open(PROC_NET_DEV, "<$PROC_NET_DEV")
180 or die "Could not open $PROC_NET_DEV";
182 my @ifs = <PROC_NET_DEV>;
184 close(PROC_NET_DEV);
186 # Eat first two line
187 shift @ifs;
188 shift @ifs;
190 chomp @ifs;
191 foreach my $line(@ifs) {
192 my $if= (split /:/, $line)[0];
193 $if =~ s/^\s+//;
194 push @result, $if;
195 }
197 return @result;
198 }
200 #=== FUNCTION ================================================================
201 # NAME: get_mac
202 # PARAMETERS: interface name (i.e. eth0)
203 # RETURNS: (mac address)
204 # DESCRIPTION: Uses ioctl to get mac address directly from system.
205 #===============================================================================
206 sub get_mac {
207 my $ifreq= shift;
208 my $result;
209 if ($ifreq && length($ifreq) > 0) {
210 if($ifreq eq "all") {
211 $result = "00:00:00:00:00:00";
212 } else {
213 my $SIOCGIFHWADDR= 0x8927; # man 2 ioctl_list
215 # A configured MAC Address should always override a guessed value
216 if ($server_mac_address and length($server_mac_address) > 0) {
217 $result= $server_mac_address;
218 }
220 socket SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('ip')
221 or die "socket: $!";
223 if(ioctl SOCKET, $SIOCGIFHWADDR, $ifreq) {
224 my ($if, $mac)= unpack 'h36 H12', $ifreq;
226 if (length($mac) > 0) {
227 $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])$/;
228 $mac= sprintf("%s:%s:%s:%s:%s:%s", $1, $2, $3, $4, $5, $6);
229 $result = $mac;
230 }
231 }
232 }
233 }
234 return $result;
235 }
237 #=== FUNCTION ================================================================
238 # NAME: get_ip
239 # PARAMETERS: interface name (i.e. eth0)
240 # RETURNS: (ip address)
241 # DESCRIPTION: Uses ioctl to get ip address directly from system.
242 #===============================================================================
243 sub get_ip {
244 my $ifreq= shift;
245 my $result= "";
246 my $SIOCGIFADDR= 0x8915; # man 2 ioctl_list
247 my $proto= getprotobyname('ip');
249 socket SOCKET, PF_INET, SOCK_DGRAM, $proto
250 or die "socket: $!";
252 if(ioctl SOCKET, $SIOCGIFADDR, $ifreq) {
253 my ($if, $sin) = unpack 'a16 a16', $ifreq;
254 my ($port, $addr) = sockaddr_in $sin;
255 my $ip = inet_ntoa $addr;
257 if ($ip && length($ip) > 0) {
258 $result = $ip;
259 }
260 }
262 return $result;
263 }
266 #=== FUNCTION ================================================================
267 # NAME: register_at_bus
268 # PARAMETERS: nothing
269 # RETURNS: nothing
270 # DESCRIPTION: creates an entry in known_daemons and send a 'here_i_am' msg to bus
271 #===============================================================================
272 sub register_at_bus {
274 # add bus to known_server_db
275 my $res = $main::known_server_db->add_dbentry( {table=>'known_server',
276 primkey=>'hostname',
277 hostname=>$bus_address,
278 status=>'bus',
279 hostkey=>$bus_passwd,
280 timestamp=>&get_time,
281 } );
282 my $msg_hash = &create_xml_hash("here_i_am", $server_address, $bus_address);
283 my $answer = "";
284 $answer = &send_msg_hash2address($msg_hash, $bus_address, $bus_passwd);
285 if ($answer == 0) {
286 &main::daemon_log("register at bus: $bus_address", 1);
287 } else {
288 &main::daemon_log("unable to send 'register'-msg to bus '$bus_address': $answer", 1);
289 }
290 return;
291 }
294 #=== FUNCTION ================================================================
295 # NAME: process_incoming_msg
296 # PARAMETERS: crypted_msg - string - incoming crypted message
297 # RETURNS: nothing
298 # DESCRIPTION: handels the proceeded distribution to the appropriated functions
299 #===============================================================================
300 sub process_incoming_msg {
301 my ($msg, $msg_hash) = @_ ;
302 my $error = 0;
303 my $host_name;
304 my $host_key;
305 my @out_msg_l;
307 # process incoming msg
308 my $header = @{$msg_hash->{header}}[0];
309 my $source = @{$msg_hash->{source}}[0];
310 my @target_l = @{$msg_hash->{target}};
312 &main::daemon_log("SIPackages: msg to process: $header", 3);
313 &main::daemon_log("$msg", 8);
315 if( 0 == length @target_l){
316 &main::daemon_log("ERROR: no target specified for msg $header", 1);
317 $error++;
318 }
320 if( 1 == length @target_l) {
321 my $target = $target_l[0];
322 if( $target eq $server_address ) {
323 if ($header eq 'new_passwd') { @out_msg_l = &new_passwd($msg_hash) }
324 elsif ($header eq 'here_i_am') { @out_msg_l = &here_i_am($msg_hash) }
325 elsif ($header eq 'who_has') { @out_msg_l = &who_has($msg_hash) }
326 elsif ($header eq 'who_has_i_do') { @out_msg_l = &who_has_i_do($msg_hash) }
327 elsif ($header eq 'got_ping') { @out_msg_l = &got_ping($msg_hash)}
328 elsif ($header eq 'get_load') { @out_msg_l = &execute_actions($msg_hash)}
329 else {
330 &main::daemon_log("ERROR: $header is an unknown core funktion", 1);
331 $error++;
332 }
333 }
334 else {
335 &main::daemon_log("msg is not for gosa-si-server '$server_address', deliver it to target '$target'", 5);
336 push(@out_msg_l, $msg);
337 }
338 }
340 if( $error == 0) {
341 if( 0 == @out_msg_l ) {
342 push(@out_msg_l, $msg);
343 }
344 }
346 return \@out_msg_l;
347 }
350 #=== FUNCTION ================================================================
351 # NAME: got_ping
352 # PARAMETERS: msg_hash - hash - hash from function create_xml_hash
353 # RETURNS: nothing
354 # DESCRIPTION: process this incoming message
355 #===============================================================================
356 sub got_ping {
357 my ($msg_hash) = @_;
359 my $source = @{$msg_hash->{source}}[0];
360 my $target = @{$msg_hash->{target}}[0];
361 my $header = @{$msg_hash->{header}}[0];
363 if(exists $main::known_daemons->{$source}) {
364 &main::add_content2known_daemons(hostname=>$source, status=>$header);
365 } else {
366 &main::add_content2known_clients(hostname=>$source, status=>$header);
367 }
369 return;
370 }
373 #=== FUNCTION ================================================================
374 # NAME: new_passwd
375 # PARAMETERS: msg_hash - ref - hash from function create_xml_hash
376 # RETURNS: nothing
377 # DESCRIPTION: process this incoming message
378 #===============================================================================
379 sub new_passwd {
380 my ($msg_hash) = @_;
381 my @out_msg_l;
383 my $header = @{$msg_hash->{header}}[0];
384 my $source_name = @{$msg_hash->{source}}[0];
385 my $source_key = @{$msg_hash->{new_passwd}}[0];
386 my $query_res;
388 # check known_clients_db
389 my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$source_name'";
390 $query_res = $main::known_clients_db->select_dbentry( $sql_statement );
391 if( 1 == keys %{$query_res} ) {
392 my $act_time = &get_time;
393 my $sql_statement= "UPDATE known_clients ".
394 "SET hostkey='$source_key', timestamp='$act_time' ".
395 "WHERE hostname='$source_name'";
396 my $res = $main::known_clients_db->update_dbentry( $sql_statement );
398 my $hash = &create_xml_hash("confirm_new_passwd", $server_address, $source_name);
399 my $out_msg = &create_xml_string($hash);
400 push(@out_msg_l, $out_msg);
401 }
403 # only do if host still not found
404 if( 0 == @out_msg_l ) {
405 # check known_server_db
406 $sql_statement = "SELECT * FROM known_server WHERE hostname='$source_name'";
407 $query_res = $main::known_server_db->select_dbentry( $sql_statement );
408 if( 1 == keys %{$query_res} ) {
409 my $act_time = &get_time;
410 my $sql_statement= "UPDATE known_server ".
411 "SET hostkey='$source_key', timestamp='$act_time' ".
412 "WHERE hostname='$source_name'";
413 my $res = $main::known_server_db->update_dbentry( $sql_statement );
415 my $hash = &create_xml_hash("confirm_new_passwd", $server_address, $source_name);
416 my $out_msg = &create_xml_string($hash);
417 push(@out_msg_l, $out_msg);
418 }
419 }
421 return @out_msg_l;
422 }
425 #=== FUNCTION ================================================================
426 # NAME: here_i_am
427 # PARAMETERS: msg_hash - hash - hash from function create_xml_hash
428 # RETURNS: nothing
429 # DESCRIPTION: process this incoming message
430 #===============================================================================
431 sub here_i_am {
432 my ($msg_hash) = @_;
433 my @out_msg_l;
434 my $out_hash;
436 my $source = @{$msg_hash->{source}}[0];
437 my $mac_address = @{$msg_hash->{mac_address}}[0];
439 # number of known clients
440 my $nu_clients= $main::known_clients_db->count_dbentries('known_clients');
442 # check wether client address or mac address is already known
443 my $sql_statement= "SELECT * FROM known_clients WHERE hostname='$source'";
444 my $db_res= $main::known_clients_db->select_dbentry( $sql_statement );
446 if ( 1 == keys %{$db_res} ) {
447 &main::daemon_log("WARNING: $source is already known as a client", 1);
448 &main::daemon_log("WARNING: values for $source are being overwritten", 1);
449 $nu_clients --;
450 }
452 # number of actual activ clients
453 my $act_nu_clients = $nu_clients;
455 &main::daemon_log("number of actual activ clients: $act_nu_clients", 5);
456 &main::daemon_log("number of maximal allowed clients: $max_clients", 5);
458 if($max_clients <= $act_nu_clients) {
459 my $out_hash = &create_xml_hash("denied", $server_address, $source);
460 &add_content2xml_hash($out_hash, "denied", "I_cannot_take_any_more_clients!");
461 my $passwd = @{$msg_hash->{new_passwd}}[0];
462 &send_msg_hash2address($out_hash, $source, $passwd);
463 return;
464 }
466 # new client accepted
467 my $new_passwd = @{$msg_hash->{new_passwd}}[0];
469 # create entry in known_clients
470 my $events = @{$msg_hash->{events}}[0];
473 # add entry to known_clients_db
474 my $res = $main::known_clients_db->add_dbentry( {table=>'known_clients',
475 primkey=>'hostname',
476 hostname=>$source,
477 events=>$events,
478 macaddress=>$mac_address,
479 status=>'registered',
480 hostkey=>$new_passwd,
481 timestamp=>&get_time,
482 } );
484 if ($res != 0) {
485 &main::daemon_log("ERROR: cannot add entry to known_clients: $res");
486 return;
487 }
489 # return acknowledgement to client
490 $out_hash = &create_xml_hash("registered", $server_address, $source);
491 my $register_out = &create_xml_string($out_hash);
492 push(@out_msg_l, $register_out);
494 # notify registered client to bus
495 if( $bus_activ eq "on") {
496 # fetch actual bus key
497 my $sql_statement= "SELECT * FROM known_server WHERE status='bus'";
498 my $query_res = $main::known_server_db->select_dbentry( $sql_statement );
499 my $hostkey = $query_res->{1}->{'hostkey'};
501 # send update msg to bus
502 $out_hash = &create_xml_hash("new_client", $server_address, $bus_address, $source);
503 my $new_client_out = &create_xml_string($out_hash);
504 push(@out_msg_l, $new_client_out);
505 &main::daemon_log("send bus msg that client '$source' has registerd at server '$server_address'", 3);
506 }
508 # give the new client his ldap config
509 my $new_ldap_config_out = &new_ldap_config($source);
510 if( $new_ldap_config_out ) {
511 push(@out_msg_l, $new_ldap_config_out);
512 }
515 return @out_msg_l;
516 }
519 #=== FUNCTION ================================================================
520 # NAME: who_has
521 # PARAMETERS: msg_hash - hash - hash from function create_xml_hash
522 # RETURNS: nothing
523 # DESCRIPTION: process this incoming message
524 #===============================================================================
525 sub who_has {
526 my ($msg_hash) = @_ ;
528 # what is your search pattern
529 my $search_pattern = @{$msg_hash->{who_has}}[0];
530 my $search_element = @{$msg_hash->{$search_pattern}}[0];
531 &main::daemon_log("who_has-msg looking for $search_pattern $search_element", 7);
533 # scanning known_clients for search_pattern
534 my @host_addresses = keys %$main::known_clients;
535 my $known_clients_entries = length @host_addresses;
536 my $host_address;
537 foreach my $host (@host_addresses) {
538 my $client_element = $main::known_clients->{$host}->{$search_pattern};
539 if ($search_element eq $client_element) {
540 $host_address = $host;
541 last;
542 }
543 }
545 # search was successful
546 if (defined $host_address) {
547 my $source = @{$msg_hash->{source}}[0];
548 my $out_msg = &create_xml_hash("who_has_i_do", $server_address, $source, "mac_address");
549 &add_content2xml_hash($out_msg, "mac_address", $search_element);
550 &send_msg_hash2address($out_msg, $bus_address);
551 }
552 return;
553 }
556 sub who_has_i_do {
557 my ($msg_hash) = @_ ;
558 my $header = @{$msg_hash->{header}}[0];
559 my $source = @{$msg_hash->{source}}[0];
560 my $search_param = @{$msg_hash->{$header}}[0];
561 my $search_value = @{$msg_hash->{$search_param}}[0];
562 print "\ngot msg $header:\nserver $source has client with $search_param $search_value\n";
563 }
566 #=== FUNCTION ================================================================
567 # NAME: new_ldap_config
568 # PARAMETERS: address - string - ip address and port of a host
569 # RETURNS: nothing
570 # DESCRIPTION: send to address the ldap configuration found for dn gotoLdapServer
571 #===============================================================================
572 sub new_ldap_config {
573 my ($address) = @_ ;
575 my $sql_statement= "SELECT * FROM known_clients WHERE hostname='$address'";
576 my $res = $main::known_clients_db->select_dbentry( $sql_statement );
578 # check hit
579 my $hit_counter = keys %{$res};
580 if( not $hit_counter == 1 ) {
581 &main::daemon_log("ERROR: more or no hit found in known_clients_db by query by '$address'", 1);
582 }
584 my $macaddress = $res->{1}->{macaddress};
585 my $hostkey = $res->{1}->{hostkey};
587 if (not defined $macaddress) {
588 &main::daemon_log("ERROR: no mac address found for client $address", 1);
589 return;
590 }
592 # Build LDAP connection
593 my $ldap = Net::LDAP->new($ldap_uri);
594 if( not defined $ldap ) {
595 &main::daemon_log("ERROR: cannot connect to ldap: $ldap_uri", 1);
596 return;
597 }
600 # Bind to a directory with dn and password
601 my $mesg= $ldap->bind($ldap_admin_dn, $ldap_admin_password);
603 # Perform search
604 $mesg = $ldap->search( base => $ldap_base,
605 scope => 'sub',
606 attrs => ['dn', 'gotoLdapServer', 'gosaUnitTag'],
607 filter => "(&(objectClass=GOhard)(macaddress=$macaddress))");
608 $mesg->code && die $mesg->error;
610 # Sanity check
611 if ($mesg->count != 1) {
612 &main::daemon_log("WARNING: client mac address $macaddress not found/not unique in ldap search", 1);
613 &main::daemon_log("\tbase: $ldap_base", 1);
614 &main::daemon_log("\tscope: sub", 1);
615 &main::daemon_log("\tattrs: dn, gotoLdapServer", 1);
616 &main::daemon_log("\tfilter: (&(objectClass=GOhard)(macaddress=$macaddress))", 1);
617 return;
618 }
620 my $entry= $mesg->entry(0);
621 my $dn= $entry->dn;
622 my @servers= $entry->get_value("gotoLdapServer");
623 my $unit_tag= $entry->get_value("gosaUnitTag");
624 my @ldap_uris;
625 my $server;
626 my $base;
628 # Do we need to look at an object class?
629 if (length(@servers) < 1){
630 $mesg = $ldap->search( base => $ldap_base,
631 scope => 'sub',
632 attrs => ['dn', 'gotoLdapServer'],
633 filter => "(&(objectClass=gosaGroupOfNames)(member=$dn))");
634 $mesg->code && die $mesg->error;
636 # Sanity check
637 if ($mesg->count != 1) {
638 &main::daemon_log("WARNING: no LDAP information found for client mac $macaddress", 1);
639 return;
640 }
642 $entry= $mesg->entry(0);
643 $dn= $entry->dn;
644 @servers= $entry->get_value("gotoLdapServer");
645 }
647 @servers= sort (@servers);
649 foreach $server (@servers){
650 $base= $server;
651 $server =~ s%^[^:]+:[^:]+:(ldap.*://[^/]+)/.*$%$1%;
652 $base =~ s%^[^:]+:[^:]+:ldap.*://[^/]+/(.*)$%$1%;
653 push (@ldap_uris, $server);
654 }
656 # Assemble data package
657 my %data = ( 'ldap_uri' => \@ldap_uris, 'ldap_base' => $base,
658 'ldap_cfg' => \@ldap_cfg, 'pam_cfg' => \@pam_cfg,'nss_cfg' => \@nss_cfg );
660 # Need to append GOto settings?
661 if (defined $goto_admin and defined $goto_secret){
662 $data{'goto_admin'}= $goto_admin;
663 $data{'goto_secret'}= $goto_secret;
664 }
666 # Append unit tag if needed
667 if (defined $unit_tag){
669 # Find admin base and department name
670 $mesg = $ldap->search( base => $ldap_base,
671 scope => 'sub',
672 attrs => ['dn', 'ou'],
673 filter => "(&(objectClass=gosaAdministrativeUnit)(gosaUnitTag=$unit_tag))");
674 $mesg->code && die $mesg->error;
676 # Sanity check
677 if ($mesg->count != 1) {
678 &main::daemon_log("WARNING: cannot find administrative unit for client with tag $unit_tag", 1);
679 return;
680 }
682 $entry= $mesg->entry(0);
683 $data{'admin_base'}= $entry->dn;
684 $data{'department'}= $entry->get_value("ou");
686 # Append unit Tag
687 $data{'unit_tag'}= $unit_tag;
688 }
690 # Unbind
691 $mesg = $ldap->unbind;
693 # Send information
694 return send_msg("new_ldap_config", $server_address, $address, \%data, $hostkey);
695 }
698 #=== FUNCTION ================================================================
699 # NAME: execute_actions
700 # PARAMETERS: msg_hash - hash - hash from function create_xml_hash
701 # RETURNS: nothing
702 # DESCRIPTION: invokes the script specified in msg_hash which is located under
703 # /etc/gosad/actions
704 #===============================================================================
705 sub execute_actions {
706 my ($msg_hash) = @_ ;
707 my $configdir= '/etc/gosad/actions/';
708 my $result;
710 my $header = @{$msg_hash->{header}}[0];
711 my $source = @{$msg_hash->{source}}[0];
712 my $target = @{$msg_hash->{target}}[0];
714 if((not defined $source)
715 && (not defined $target)
716 && (not defined $header)) {
717 &main::daemon_log("ERROR: Entries missing in XML msg for gosad actions under /etc/gosad/actions");
718 } else {
719 my $parameters="";
720 my @params = @{$msg_hash->{$header}};
721 my $params = join(", ", @params);
722 &main::daemon_log("execute_actions: got parameters: $params", 5);
724 if (@params) {
725 foreach my $param (@params) {
726 my $param_value = (&get_content_from_xml_hash($msg_hash, $param))[0];
727 &main::daemon_log("execute_actions: parameter -> value: $param -> $param_value", 7);
728 $parameters.= " ".$param_value;
729 }
730 }
732 my $cmd= $configdir.$header."$parameters";
733 &main::daemon_log("execute_actions: executing cmd: $cmd", 7);
734 $result= "";
735 open(PIPE, "$cmd 2>&1 |");
736 while(<PIPE>) {
737 $result.=$_;
738 }
739 close(PIPE);
740 }
742 # process the event result
745 return;
746 }
749 1;