From f3b3da2c6e6718ddc8442847e1752b56f69faed6 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Tue, 3 Jun 2008 08:20:22 +0000 Subject: [PATCH] * gosa-si-server-nobus * under construction git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@11163 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 45 ++++--- gosa-si/modules/ArpHandler.pm | 49 +++---- gosa-si/modules/ClientPackages.pm | 178 +++++++++++++------------- gosa-si/modules/GosaPackages.pm | 183 ++++++++++++++------------- gosa-si/modules/GosaSupportDaemon.pm | 89 +++++++++++++ 5 files changed, 321 insertions(+), 223 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index e7ae82f0e..ae375d7d4 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -819,33 +819,34 @@ sub open_socket { } +# moved to GosaSupportDaemon: 03-06-2008: rettenbe #=== FUNCTION ================================================================ # NAME: get_ip # PARAMETERS: interface name (i.e. eth0) # RETURNS: (ip address) # DESCRIPTION: Uses ioctl to get ip address directly from system. #=============================================================================== -sub get_ip { - my $ifreq= shift; - my $result= ""; - my $SIOCGIFADDR= 0x8915; # man 2 ioctl_list - my $proto= getprotobyname('ip'); - - socket SOCKET, PF_INET, SOCK_DGRAM, $proto - or die "socket: $!"; - - if(ioctl SOCKET, $SIOCGIFADDR, $ifreq) { - my ($if, $sin) = unpack 'a16 a16', $ifreq; - my ($port, $addr) = sockaddr_in $sin; - my $ip = inet_ntoa $addr; - - if ($ip && length($ip) > 0) { - $result = $ip; - } - } - - return $result; -} +#sub get_ip { +# my $ifreq= shift; +# my $result= ""; +# my $SIOCGIFADDR= 0x8915; # man 2 ioctl_list +# my $proto= getprotobyname('ip'); +# +# socket SOCKET, PF_INET, SOCK_DGRAM, $proto +# or die "socket: $!"; +# +# if(ioctl SOCKET, $SIOCGIFADDR, $ifreq) { +# my ($if, $sin) = unpack 'a16 a16', $ifreq; +# my ($port, $addr) = sockaddr_in $sin; +# my $ip = inet_ntoa $addr; +# +# if ($ip && length($ip) > 0) { +# $result = $ip; +# } +# } +# +# return $result; +#} sub get_local_ip_for_remote_ip { @@ -1067,6 +1068,8 @@ sub msg_to_decrypt { $header = @{$msg_hash->{'header'}}[0]; $target = @{$msg_hash->{'target'}}[0]; $source = @{$msg_hash->{'source'}}[0]; + my ($target_ip, $target_port) = split(':', $target); + my $server_address = &get_local_ip_for_remote_ip($target_ip).":$server_port"; # target and source is equal to GOSA -> process here if (not $done) { diff --git a/gosa-si/modules/ArpHandler.pm b/gosa-si/modules/ArpHandler.pm index 1b0997dd2..0e551f43f 100644 --- a/gosa-si/modules/ArpHandler.pm +++ b/gosa-si/modules/ArpHandler.pm @@ -271,36 +271,37 @@ sub get_host_from_ldap { 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 = ; - - 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 = ; +# +# 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 diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index 68056c43c..379420716 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -23,20 +23,20 @@ BEGIN{} 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"], @@ -153,28 +153,28 @@ my $server_address = "$server_ip:$server_port"; $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; - - -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); -} +#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); +#} @@ -252,61 +252,63 @@ sub read_configfile { } +# 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 = ; - - 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 = ; +# +# 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 @@ -352,22 +354,22 @@ sub 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; +#} diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index c744f9b4c..c0fe1ce90 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -105,61 +105,63 @@ sub read_configfile { } } +# 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(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(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 = ; - - 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 = ; +# +# 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 @@ -168,63 +170,64 @@ sub get_interfaces { # DESCRIPTION: Uses ioctl to get mac address directly from system. #=============================================================================== sub get_mac { - my $ifreq= shift; - my $result; - if ($ifreq && length($ifreq) > 0) { - if($ifreq eq "all") { - $result = "00:00:00:00:00:00"; - } else { - my $SIOCGIFHWADDR= 0x8927; # man 2 ioctl_list - - # A configured MAC Address should always override a guessed value - if ($gosa_mac_address and length($gosa_mac_address) > 0) { - $result= $gosa_mac_address; - } - - socket SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('ip') - or die "socket: $!"; - - if(ioctl SOCKET, $SIOCGIFHWADDR, $ifreq) { - my ($if, $mac)= unpack 'h36 H12', $ifreq; - - if (length($mac) > 0) { - $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])$/; - $mac= sprintf("%s:%s:%s:%s:%s:%s", $1, $2, $3, $4, $5, $6); - $result = $mac; - } - } + my $ifreq= shift; + my $result; + if ($ifreq && length($ifreq) > 0) { + if($ifreq eq "all") { + $result = "00:00:00:00:00:00"; + } else { + my $SIOCGIFHWADDR= 0x8927; # man 2 ioctl_list + + # A configured MAC Address should always override a guessed value + if ($gosa_mac_address and length($gosa_mac_address) > 0) { + $result= $gosa_mac_address; + } + + socket SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('ip') + or die "socket: $!"; + + if(ioctl SOCKET, $SIOCGIFHWADDR, $ifreq) { + my ($if, $mac)= unpack 'h36 H12', $ifreq; + + if (length($mac) > 0) { + $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])$/; + $mac= sprintf("%s:%s:%s:%s:%s:%s", $1, $2, $3, $4, $5, $6); + $result = $mac; } + } } - return $result; + } + return $result; } +# moved to GosaSupportDaemon: 03-06-2008: rettenbe #=== FUNCTION ================================================================ # NAME: get_ip # PARAMETERS: interface name (i.e. eth0) # RETURNS: (ip address) # DESCRIPTION: Uses ioctl to get ip address directly from system. #=============================================================================== -sub get_ip { - my $ifreq= shift; - my $result= ""; - my $SIOCGIFADDR= 0x8915; # man 2 ioctl_list - my $proto= getprotobyname('ip'); - - socket SOCKET, PF_INET, SOCK_DGRAM, $proto - or die "socket: $!"; - - if(ioctl SOCKET, $SIOCGIFADDR, $ifreq) { - my ($if, $sin) = unpack 'a16 a16', $ifreq; - my ($port, $addr) = sockaddr_in $sin; - my $ip = inet_ntoa $addr; - - if ($ip && length($ip) > 0) { - $result = $ip; - } - } - - return $result; -} +#sub get_ip { +# my $ifreq= shift; +# my $result= ""; +# my $SIOCGIFADDR= 0x8915; # man 2 ioctl_list +# my $proto= getprotobyname('ip'); +# +# socket SOCKET, PF_INET, SOCK_DGRAM, $proto +# or die "socket: $!"; +# +# if(ioctl SOCKET, $SIOCGIFADDR, $ifreq) { +# my ($if, $sin) = unpack 'a16 a16', $ifreq; +# my ($port, $addr) = sockaddr_in $sin; +# my $ip = inet_ntoa $addr; +# +# if ($ip && length($ip) > 0) { +# $result = $ip; +# } +# } +# +# return $result; +#} #=== FUNCTION ================================================================ diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index d2296f050..769c03b28 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -23,6 +23,9 @@ my @functions = ( "get_logged_in_users", "import_events", "del_doubles", + "get_ip", + "get_interface_for_ip", + "get_interfaces", ); @EXPORT = @functions; use strict; @@ -530,4 +533,90 @@ sub import_events { } +#=== FUNCTION ================================================================ +# NAME: get_ip +# PARAMETERS: interface name (i.e. eth0) +# RETURNS: (ip address) +# DESCRIPTION: Uses ioctl to get ip address directly from system. +#=============================================================================== +sub get_ip { + my $ifreq= shift; + my $result= ""; + my $SIOCGIFADDR= 0x8915; # man 2 ioctl_list + my $proto= getprotobyname('ip'); + + socket SOCKET, PF_INET, SOCK_DGRAM, $proto + or die "socket: $!"; + + if(ioctl SOCKET, $SIOCGIFADDR, $ifreq) { + my ($if, $sin) = unpack 'a16 a16', $ifreq; + my ($port, $addr) = sockaddr_in $sin; + my $ip = inet_ntoa $addr; + + if ($ip && length($ip) > 0) { + $result = $ip; + } + } + + return $result; +} + + +#=== 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(&get_ip($if) eq $ip) { + $result = $if; + } + } + } + } + return $result; +} + +#=== 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 = ; + + 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; +} + + 1; -- 2.30.2