From f653527d15e50b26f2265f4bc974226f5204ef98 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Wed, 5 Dec 2007 15:19:09 +0000 Subject: [PATCH] modification of function decrypt git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8023 594d385d-05f5-0310-b6e9-bd551577e9d8 --- contrib/daemon/gosa-sc | 43 +++++++++++++++++++++++++++++++++----- contrib/daemon/gosa-sd-bus | 43 +++++++++++++++++++++++++++++++++----- 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/contrib/daemon/gosa-sc b/contrib/daemon/gosa-sc index 767d0c80f..4f917dff9 100755 --- a/contrib/daemon/gosa-sc +++ b/contrib/daemon/gosa-sc @@ -38,7 +38,7 @@ use Cwd; my ($cfg_file, %cfg_defaults, $foreground, $verbose, $pid_file, $procid, $pid, $log_file); my ($server_address, $server_ip, $server_port, $server_domain, $server_passwd, $server_cipher, $server_timeout); -my ($client_address, $client_ip, $client_port, $mac_address); +my ($client_address, $client_ip, $client_port, $client_mac_address); my ($input_socket, $rbits, $wbits, $ebits, $xml, $known_hosts); # default variables @@ -50,9 +50,7 @@ $foreground = 0 ; "pid_file" => [\$pid_file, "/var/run/".$0.".pid"], }, "client" => - {"client_ip" => [\$client_ip, "10.89.1.155"], - "client_port" => [\$client_port, "10010"], - "mac_address" => [\$mac_address, ""], + {"client_port" => [\$client_port, "10010"], }, "server" => {"server_ip" => [\$server_ip, "10.89.1.155"], @@ -200,6 +198,32 @@ sub check_pid { } +#=== FUNCTION ================================================================ +# NAME: get_ip_and_mac +# PARAMETERS: nothing +# RETURNS: (ip, mac) +# DESCRIPTION: executes /sbin/ifconfig and parses the output, the first occurence +# of a inet address is returned as well as the mac address in the line +# above the inet address +#=============================================================================== +sub get_ip_and_mac { + my $ip = "0.0.0.0.0"; # Defualt-IP + my $mac = "00:00:00:00:00:00"; # Default-MAC + my @ifconfig = qx(/sbin/ifconfig); + foreach(@ifconfig) { + if (/Hardware Adresse (\S{2}):(\S{2}):(\S{2}):(\S{2}):(\S{2}):(\S{2})/) { + $mac = "$1:$2:$3:$4:$5:$6"; + next; + } + if (/inet Adresse:(\d+).(\d+).(\d+).(\d+)/) { + $ip = "$1.$2.$3.$4"; + last; + } + } + return ($ip, $mac); +} + + #=== FUNCTION ================================================================ # NAME: usage # PARAMETERS: @@ -309,7 +333,7 @@ sub register_at_server { # create msg hash my $register_hash = &create_xml_hash("here_i_am", $client_address, $server); &add_content2xml_hash($register_hash, "new_passwd", $new_server_passwd); - &add_content2xml_hash($register_hash, "mac_address", $mac_address); + &add_content2xml_hash($register_hash, "client_mac_address", $client_mac_address); &add_content2xml_hash($register_hash, "events", $events); # send xml hash to server with general server passwd @@ -504,6 +528,7 @@ sub decrypt_msg { my $msg = $my_cipher->decrypt($crypted_msg); #my $msg = $crypted_msg; #$msg =~ s/^a*//gi; + $msg =~ s/\0$//gi; return $msg; } @@ -956,6 +981,14 @@ if( 0 != $pid ) { if( !$foreground ) { exit( 0 ) }; } +# detect own ip and mac address +($client_ip, $client_mac_address) = &get_ip_and_mac(); +if (not defined $client_ip) { + die "EXIT: ip address of $0 could not be detected"; +} +daemon_log("client ip address detected: $client_ip", 1); +daemon_log("client mac address detected: $client_mac_address", 1); + # prepare variables if (defined $server_ip && defined $server_port) { $server_address = $server_ip.":".$server_port; diff --git a/contrib/daemon/gosa-sd-bus b/contrib/daemon/gosa-sd-bus index 6035fb4a3..d92800238 100755 --- a/contrib/daemon/gosa-sd-bus +++ b/contrib/daemon/gosa-sd-bus @@ -36,7 +36,7 @@ use IPC::Shareable qw( :lock); IPC::Shareable->clean_up_all; my ($cfg_file, $default_cfg_file, %cfg_defaults, $foreground, $verbose); -my ($bus_activ, $bus_passwd, $bus_ip, $bus_port, $bus_address, $bus); +my ($bus_activ, $bus_passwd, $bus_ip, $bus_port, $bus_address, $bus, $bus_mac_address); my ($pid_file, $procid, $pid, $log_file, $my_own_address); my (%free_child, %busy_child, $child_max, $child_min, %child_alive_time, $child_timeout); my ($xml, $bus_cipher, $known_daemons, $shmkh); @@ -57,7 +57,7 @@ $shmkh = tie($known_daemons, 'IPC::Shareable', undef, {create => 1, "bus" => {"bus_activ" => [\$bus_activ, "on"], "bus_passwd" => [\$bus_passwd, "tester"], - "bus_ip" => [\$bus_ip, "10.89.1.155"], +# "bus_ip" => [\$bus_ip, "10.89.1.155"], "bus_port" => [\$bus_port, "10001"], "child_max" => [\$child_max, 10], "child_min" => [\$child_min, 3], @@ -234,6 +234,33 @@ sub sig_int_handler { $SIG{INT} = \&sig_int_handler; +#=== FUNCTION ================================================================ +# NAME: get_ip_and_mac +# PARAMETERS: nothing +# RETURNS: (ip, mac) +# DESCRIPTION: executes /sbin/ifconfig and parses the output, the first occurence +# of a inet address is returned as well as the mac address in the line +# above the inet address +#=============================================================================== +sub get_ip_and_mac { + my $ip = "0.0.0.0.0"; # Defualt-IP + my $mac_address = "00:00:00:00:00:00"; # Default-MAC + my @ifconfig = qx(/sbin/ifconfig); + foreach(@ifconfig) { + if (/Hardware Adresse (\S{2}):(\S{2}):(\S{2}):(\S{2}):(\S{2}):(\S{2})/) { + $mac_address = "$1:$2:$3:$4:$5:$6"; + next; + } + if (/inet Adresse:(\d+).(\d+).(\d+).(\d+)/) { + $ip = "$1.$2.$3.$4"; + last; + } + } + return ($ip, $mac_address); +} + + + #=== FUNCTION ================================================================ # NAME: activating_child # PARAMETERS: msg - string - incoming message @@ -561,6 +588,7 @@ sub decrypt_msg { my $msg = $my_cipher->decrypt($crypted_msg); #my $msg = $crypted_msg; #$msg =~ s/^a*//gi; + $msg =~ s/\0$//gi; return $msg; } @@ -1067,7 +1095,7 @@ $SIG{CHLD} = 'IGNORE'; # restart daemon log file if(-e $log_file ) { unlink $log_file } -daemon_log("started!"); +daemon_log("$0 started!"); # Just fork, if we"re not in foreground mode if( ! $foreground ) { $pid = fork(); } @@ -1081,8 +1109,13 @@ if( 0 != $pid ) { if( !$foreground ) { exit( 0 ) }; } -# detect own ip, port and address(= ip:port) - +# detect own ip and mac address +($bus_ip, $bus_mac_address) = &get_ip_and_mac(); +if (not defined $bus_ip) { + die "EXIT: ip address of $0 could not be detected"; +} +daemon_log("bus ip address detected: $bus_ip", 1); +daemon_log("bus mac address detected: $bus_mac_address", 1); # setup xml parser -- 2.30.2