From 5b504caadf8bb4ad4a4b163bb10ff8444d88fad7 Mon Sep 17 00:00:00 2001 From: janw Date: Mon, 4 Feb 2008 13:48:11 +0000 Subject: [PATCH] Some fixes when operating on loopback device. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8738 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/new-gosa-si-client | 75 ++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/gosa-si/new-gosa-si-client b/gosa-si/new-gosa-si-client index c26b48350..d24ced9d6 100755 --- a/gosa-si/new-gosa-si-client +++ b/gosa-si/new-gosa-si-client @@ -43,7 +43,7 @@ use lib "/usr/lib/gosa-si/client/events"; my ($cfg_file, %cfg_defaults, $foreground, $verbose, $pid_file, $procid, $pid, $log_file); my ($server_ip, $server_port, $server_key, $server_timeout, $server_domain); -my ($client_ip, $client_port, $ldap_enabled, $ldap_config, $pam_config, $nss_config); +my ($client_ip, $client_port, $client_mac_address, $ldap_enabled, $ldap_config, $pam_config, $nss_config); my $xml; my $default_server_key; my $event_hash; @@ -53,7 +53,6 @@ my @servers; our $cfg_file; our $server_address; our $client_address; -our $client_mac_address; our $server_key; # default variables @@ -67,6 +66,7 @@ our $REGISTERED_FLAG = 1; "client" => {"client_port" => [\$client_port, "20083"], "client_ip" => [\$client_ip, "0.0.0.0"], + "client_mac_address" => [\$client_mac_address, "00:00:00:00:00:00:00"], "ldap" => [\$ldap_enabled, 1], "ldap_config" => [\$ldap_config, "/etc/ldap/ldap.conf"], "pam_config" => [\$pam_config, "/etc/pam_ldap.conf"], @@ -276,42 +276,43 @@ 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") { - if(defined($server_ip)) { - $result = &get_local_mac_for_remote_ip($server_ip); + my $ifreq= shift; + my $result; + if ($ifreq && length($ifreq) > 0) { + if($ifreq eq "all") { + if(defined($server_ip)) { + $result = &get_local_mac_for_remote_ip($server_ip); } - elsif ($client_mac_address && length($client_mac_address) > 0){ + elsif ($client_mac_address && length($client_mac_address) > 0){ $result = &client_mac_address; - } - else { - $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 ($client_mac_address and length($client_mac_address) > 0) { - $result= $client_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; + } + else { + $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 ($client_mac_address and length($client_mac_address) > 0) { + $result= $client_mac_address; + } + else { + 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; } @@ -1070,6 +1071,8 @@ $client_address = $client_ip.":".$client_port; # detect own ip and mac address my $network_interface= &get_interface_for_ip($client_ip); +daemon_log("Mac address at this point: $client_mac_address", 1); +daemon_log("Interface at this point: $network_interface", 1); $client_mac_address= &get_mac($network_interface); daemon_log("gosa-si-client ip address detected: $client_ip", 1); daemon_log("gosa-si-client mac address detected: $client_mac_address", 1); -- 2.30.2