index 1924f5a1e2a32bae9689bb58b97e3b37362abe2a..37942071659adb0d04de2d4c3a7e4f25dcf76c46 100644 (file)
END {}
my ($server_ip, $server_port, $ClientPackages_key, $max_clients, $ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $server_interface);
-my ($bus_activ, $bus_key, $bus_ip, $bus_port);
+#my ($bus_activ, $bus_key, $bus_ip, $bus_port);
my $server;
my $network_interface;
-my $no_bus;
+#my $no_bus;
my (@ldap_cfg, @pam_cfg, @nss_cfg, $goto_admin, $goto_secret);
my $mesg;
my %cfg_defaults = (
-"bus" => {
- "activ" => [\$bus_activ, "on"],
- "key" => [\$bus_key, ""],
- "ip" => [\$bus_ip, ""],
- "port" => [\$bus_port, "20080"],
- },
+#"bus" => {
+# "activ" => [\$bus_activ, "on"],
+# "key" => [\$bus_key, ""],
+# "ip" => [\$bus_ip, ""],
+# "port" => [\$bus_port, "20080"],
+# },
"server" => {
"ip" => [\$server_ip, "0.0.0.0"],
"mac-address" => [\$main::server_mac_address, "00:00:00:00:00"],
filter => "(macaddress=$main::server_mac_address)"
);
- if ($mesg->count == 1) {
+ if ((! $main::server_mac_address eq "00:00:00:00:00:00") and $mesg->count == 1) {
my $entry= $mesg->entry(0);
my $unit_tag= $entry->get_value("gosaUnitTag");
$main::ldap_server_dn= $mesg->entry(0)->dn;
$main::server_address = $server_address;
-if( inet_aton($bus_ip) ){ $bus_ip = inet_ntoa(inet_aton($bus_ip)); }
-######################################################
-# to change
-if( $bus_ip eq "127.0.1.1" ) { $bus_ip = "127.0.0.1" }
-######################################################
-my $bus_address = "$bus_ip:$bus_port";
-$main::bus_address = $bus_address;
-
-# create general settings for this module
-my $xml = new XML::Simple();
+#if( inet_aton($bus_ip) ){ $bus_ip = inet_ntoa(inet_aton($bus_ip)); }
+#######################################################
+## to change
+#if( $bus_ip eq "127.0.1.1" ) { $bus_ip = "127.0.0.1" }
+#######################################################
+#my $bus_address = "$bus_ip:$bus_port";
+#$main::bus_address = $bus_address;
+
+
+#my $hostkey = &create_passwd;
+#my $res = $main::known_server_db->add_dbentry( {table=>$main::known_server_tn,
+# primkey=>['hostname'],
+# hostname=>$main::server_address,
+# status=>'myself',
+# hostkey=>$hostkey,
+# timestamp=>&get_time(),
+# } );
+#if (not $res == 0) {
+# &main::daemon_log("0 ERROR: cannot add server to known_server_db: $res", 1);
+#} else {
+# &main::daemon_log("0 INFO: '$main::server_address' successfully added to known_server_db", 5);
+#}
-# register at bus
-if ($main::no_bus > 0) {
- $bus_activ = "off"
-}
-if($bus_activ eq "on") {
- ®ister_at_bus();
-}
-# add myself to known_server_db
-my $res = $main::known_server_db->add_dbentry( {table=>'known_server',
- primkey=>['hostname'],
- hostname=>$server_address,
- status=>'myself',
- hostkey=>$ClientPackages_key,
- timestamp=>&get_time,
- } );
+## create general settings for this module
+#my $xml = new XML::Simple();
+#
+## register at bus
+#if ($main::no_bus > 0) {
+# $bus_activ = "off"
+#}
+#if($bus_activ eq "on") {
+# ®ister_at_bus();
+#}
### functions #################################################################
}
+# moved to GosaSupportDaemon: 03-06-2008 rettenbe
#=== FUNCTION ================================================================
# NAME: get_interface_for_ip
# PARAMETERS: ip address (i.e. 192.168.0.1)
# RETURNS: array: list of interfaces if ip=0.0.0.0, matching interface if found, undef else
# DESCRIPTION: Uses proc fs (/proc/net/dev) to get list of interfaces.
#===============================================================================
-sub get_interface_for_ip {
- my $result;
- my $ip= shift;
- if ($ip && length($ip) > 0) {
- my @ifs= &get_interfaces();
- if($ip eq "0.0.0.0") {
- $result = "all";
- } else {
- foreach (@ifs) {
- my $if=$_;
- if(&main::get_ip($if) eq $ip) {
- $result = $if;
- }
- }
- }
- }
- return $result;
-}
+#sub get_interface_for_ip {
+# my $result;
+# my $ip= shift;
+# if ($ip && length($ip) > 0) {
+# my @ifs= &get_interfaces();
+# if($ip eq "0.0.0.0") {
+# $result = "all";
+# } else {
+# foreach (@ifs) {
+# my $if=$_;
+# if(&main::get_ip($if) eq $ip) {
+# $result = $if;
+# }
+# }
+# }
+# }
+# return $result;
+#}
+# moved to GosaSupportDaemon: 03-06-2008 rettenbe
#=== FUNCTION ================================================================
# NAME: get_interfaces
# PARAMETERS: none
# RETURNS: (list of interfaces)
# DESCRIPTION: Uses proc fs (/proc/net/dev) to get list of interfaces.
#===============================================================================
-sub get_interfaces {
- my @result;
- my $PROC_NET_DEV= ('/proc/net/dev');
-
- open(PROC_NET_DEV, "<$PROC_NET_DEV")
- or die "Could not open $PROC_NET_DEV";
-
- my @ifs = <PROC_NET_DEV>;
-
- close(PROC_NET_DEV);
-
- # Eat first two line
- shift @ifs;
- shift @ifs;
-
- chomp @ifs;
- foreach my $line(@ifs) {
- my $if= (split /:/, $line)[0];
- $if =~ s/^\s+//;
- push @result, $if;
- }
-
- return @result;
-}
+#sub get_interfaces {
+# my @result;
+# my $PROC_NET_DEV= ('/proc/net/dev');
+#
+# open(PROC_NET_DEV, "<$PROC_NET_DEV")
+# or die "Could not open $PROC_NET_DEV";
+#
+# my @ifs = <PROC_NET_DEV>;
+#
+# close(PROC_NET_DEV);
+#
+# # Eat first two line
+# shift @ifs;
+# shift @ifs;
+#
+# chomp @ifs;
+# foreach my $line(@ifs) {
+# my $if= (split /:/, $line)[0];
+# $if =~ s/^\s+//;
+# push @result, $if;
+# }
+#
+# return @result;
+#}
#=== FUNCTION ================================================================
# NAME: get_mac
# RETURNS: nothing
# DESCRIPTION: creates an entry in known_daemons and send a 'here_i_am' msg to bus
#===============================================================================
-sub register_at_bus {
-
- # add bus to known_server_db
- my $res = $main::known_server_db->add_dbentry( {table=>'known_server',
- primkey=>['hostname'],
- hostname=>$bus_address,
- status=>'bus',
- hostkey=>$bus_key,
- timestamp=>&get_time,
- } );
- my $msg_hash = &create_xml_hash("here_i_am", $server_address, $bus_address);
- my $msg = &create_xml_string($msg_hash);
-
- &main::send_msg_to_target($msg, $bus_address, $bus_key, "here_i_am");
- return $msg;
-}
+#sub register_at_bus {
+#
+# # add bus to known_server_db
+# my $res = $main::known_server_db->add_dbentry( {table=>'known_server',
+# primkey=>['hostname'],
+# hostname=>$bus_address,
+# status=>'bus',
+# hostkey=>$bus_key,
+# timestamp=>&get_time,
+# } );
+# my $msg_hash = &create_xml_hash("here_i_am", $server_address, $bus_address);
+# my $msg = &create_xml_string($msg_hash);
+#
+# &main::send_msg_to_target($msg, $bus_address, $bus_key, "here_i_am");
+# return $msg;
+#}
} elsif ($header eq 'here_i_am') {
@out_msg_l = &here_i_am($msg, $msg_hash, $session_id)
} else {
+ # a event exists with the header as name
if( exists $event_hash->{$header} ) {
- # a event exists with the header as name
&main::daemon_log("$session_id INFO: found event '$header' at event-module '".$event_hash->{$header}."'", 5);
no strict 'refs';
@out_msg_l = &{$event_hash->{$header}."::$header"}($msg, $msg_hash, $session_id);
+
+ # if no event handler is implemented
} else {
$sql_events = "SELECT * FROM $main::known_clients_tn WHERE ( (macaddress LIKE '$source') OR (hostname='$source') )";
my $res = $main::known_clients_db->select_dbentry( $sql_events );
my ($msg, $msg_hash, $session_id) = @_;
my @out_msg_l;
my $out_hash;
-
my $source = @{$msg_hash->{source}}[0];
my $mac_address = @{$msg_hash->{mac_address}}[0];
my $gotoHardwareChecksum = @{$msg_hash->{gotoHardwareChecksum}}[0];
my $client_status = @{$msg_hash->{client_status}}[0];
my $client_revision = @{$msg_hash->{client_revision}}[0];
+ my $key_lifetime = @{$msg_hash->{key_lifetime}}[0];
# number of known clients
my $nu_clients= $main::known_clients_db->count_dbentries('known_clients');
# new client accepted
my $new_passwd = @{$msg_hash->{new_passwd}}[0];
- # create entry in known_clients
- my $events = @{$msg_hash->{events}}[0];
-
-
# add entry to known_clients_db
+ my $events = @{$msg_hash->{events}}[0];
my $act_timestamp = &get_time;
my $res = $main::known_clients_db->add_dbentry( {table=>'known_clients',
primkey=>['hostname'],
status=>'registered',
hostkey=>$new_passwd,
timestamp=>$act_timestamp,
+ keylifetime=>$key_lifetime,
} );
if ($res != 0) {
# return acknowledgement to client
$out_hash = &create_xml_hash("registered", $server_address, $source);
- # notify registered client to bus
- if( $bus_activ eq "on") {
- # fetch actual bus key
- my $sql_statement= "SELECT * FROM known_server WHERE status='bus'";
- my $query_res = $main::known_server_db->select_dbentry( $sql_statement );
- my $hostkey = $query_res->{1}->{'hostkey'};
-
- # send update msg to bus
- $out_hash = &create_xml_hash("new_client", $server_address, $bus_address, $source);
- &add_content2xml_hash($out_hash, "macaddress", $mac_address);
- &add_content2xml_hash($out_hash, "timestamp", $act_timestamp);
- my $new_client_out = &create_xml_string($out_hash);
- push(@out_msg_l, $new_client_out);
- &main::daemon_log("$session_id INFO: send bus msg that client '$source' has registered at server '$server_address'", 5);
- }
# give the new client his ldap config
# Workaround: Send within the registration response, if the client will get an ldap config later
push(@out_msg_l, $hardware_config_out);
}
+ # notify registered client to all other server
+ my %mydata = ( 'client' => $source, 'macaddress' => $mac_address);
+ my $mymsg = &build_msg('new_foreign_client', $main::server_address, "KNOWN_SERVER", \%mydata);
+ push(@out_msg_l, $mymsg);
+
&main::daemon_log("$session_id INFO: register client $source ($mac_address)", 5);
&main::daemon_log("$session_id INFO: client version: $client_status - $client_revision", 5);
-
return @out_msg_l;
}