From: cajus Date: Tue, 15 Jul 2008 06:24:24 +0000 (+0000) Subject: Cleanup and force-hostname functionality X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d47928d43540800ff10f9918243db1e0648d1875;p=gosa.git Cleanup and force-hostname functionality git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@11637 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/client/events/corefunctions.pm b/gosa-si/client/events/corefunctions.pm index b4b992156..5ccf16119 100644 --- a/gosa-si/client/events/corefunctions.pm +++ b/gosa-si/client/events/corefunctions.pm @@ -237,7 +237,6 @@ sub new_ldap_config { my $file1; my $file2; open(file1, "> $ldap_config"); -#print STDERR Dumper(PerlIO::get_layers(file1, output => 1)); print file1 "# This file was automatically generated by gosa-si-client. Do not change.\n"; print file1 "URI"; foreach $element (@ldap_uris) { diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index 145a82cf8..120be0734 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -99,13 +99,13 @@ my $fai_log_dir = "/tmp/fai"; {"port" => [\$client_port, "20083"], "ip" => [\$client_ip, "0.0.0.0"], "mac-address" => [\$client_mac_address, "00:00:00:00:00:00"], - "server-domain" => [\$server_domain, ""], + "server-domain" => [\$server_domain, ""], "ldap" => [\$ldap_enabled, 1], "ldap-config" => [\$ldap_config, "/etc/ldap/ldap.conf"], "pam-config" => [\$pam_config, "/etc/pam_ldap.conf"], "nss-config" => [\$nss_config, "/etc/libnss-ldap.conf"], - "fai-logpath" => [\$fai_logpath, "/var/log/fai/fai.log"], - "force-hostname" => [\$client_force_hostname, "false"], + "fai-logpath" => [\$fai_logpath, "/var/log/fai/fai.log"], + "force-hostname" => [\$client_force_hostname, "false"], }, "server" => { "ip" => [\$server_ip, "127.0.0.1"], @@ -416,17 +416,6 @@ sub generate_hw_digest { } -# moved to GosaSupportDaemon: rettenbe, 19.05.2008 -#sub create_passwd { -# my $new_passwd = ""; -# for(my $i=0; $i<31; $i++) { -# $new_passwd .= ("a".."z","A".."Z",0..9)[int(rand(62))] -# } -# -# return $new_passwd; -#} - - sub create_ciphering { my ($passwd) = @_; if((!defined($passwd)) || length($passwd)==0) { @@ -468,45 +457,6 @@ sub decrypt_msg { } -# moved to GosaSupportDaemon: rettenbe: 16.05.2008 -#sub get_server_addresses { -# my $domain= shift; -# my @result; -# -# my $error = 0; -# my $res = Net::DNS::Resolver->new; -# my $query = $res->send("_gosa-si._tcp.".$domain, "SRV"); -# my @hits; -# -# if ($query) { -# foreach my $rr ($query->answer) { -# push(@hits, $rr->target.":".$rr->port); -# } -# } -# else { -# #warn "query failed: ", $res->errorstring, "\n"; -# $error++; -# } -# -# if( $error == 0 ) { -# foreach my $hit (@hits) { -# my ($hit_name, $hit_port) = split(/:/, $hit); -# chomp($hit_name); -# chomp($hit_port); -# -# my $address_query = $res->send($hit_name); -# if( 1 == length($address_query->answer) ) { -# foreach my $rr ($address_query->answer) { -# push(@result, $rr->address.":".$hit_port); -# } -# } -# } -# } -# -# return @result; -#} - - #=== FUNCTION ================================================================ # NAME: send_msg_hash_to_target # PARAMETERS: msg_hash - hash - xml_hash created with function create_xml_hash @@ -658,8 +608,12 @@ sub register_at_gosa_si_server { my $ip= &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)); my $dnsname= gethostbyaddr(inet_aton($ip), AF_INET); if(!defined($dnsname)) { - &write_to_file("goto-error-dns:$ip", $fai_logpath); - exit(1); + if( defined($client_force_hostname) && $client_force_hostname eq "true") { + $dnsname = `hostname`; + } else { + &write_to_file("goto-error-dns:$ip", $fai_logpath); + exit(1); + } } # create registration msg @@ -843,38 +797,6 @@ sub check_outgoing_xml_validity { } -#sub import_events { -# -# if (not -e $event_dir) { -# daemon_log("ERROR: cannot find directory or directory is not readable: $event_dir", 1); -# } -# opendir (DIR, $event_dir) or die "ERROR while loading gosa-si-events from directory $event_dir : $!\n"; -# -# while (defined (my $event = readdir (DIR))) { -# if( $event eq "." || $event eq ".." ) { next; } -# daemon_log("INFO: found event module: $event", 5); -# eval{ require $event; }; -# if( $@ ) { -# daemon_log("ERROR: import of event module '$event' failed", 1); -# daemon_log("$@", 1); -# next; -# } -# -# $event =~ /(\S*?).pm$/; -# my $event_module = $1; -# my $events_l = eval( $1."::get_events()") ; -# foreach my $event_name (@{$events_l}) { -# $event_hash->{$event_name} = $event_module; -# } -# -# } -# -# my @all_events = keys %$event_hash; -# my $all_events_string = join(", ", @all_events); -# -# daemon_log("INFO: imported events: $all_events_string", 5); -#} - sub trigger_new_key { my ($kernel) = $_[KERNEL] ; diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index d73b3c763..250e0080b 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -825,36 +825,6 @@ 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_local_ip_for_remote_ip { my $remote_ip= shift; my $result="0.0.0.0"; @@ -1306,6 +1276,7 @@ sub handle_task_done { sub process_task { no strict "refs"; + #CHECK: Not @_[...]? my ($session, $heap, $task) = @_; my $error = 0; my $answer_l; @@ -1481,6 +1452,7 @@ sub session_start { sub watch_for_done_jobs { + #CHECK: $heap for what? my ($kernel,$heap) = @_[KERNEL, HEAP]; my $sql_statement = "SELECT * FROM ".$job_queue_tn." WHERE ((status='done') AND (modified='0'))"; diff --git a/gosa-si/modules/ArpHandler.pm b/gosa-si/modules/ArpHandler.pm index 0e551f43f..8d9f6f556 100644 --- a/gosa-si/modules/ArpHandler.pm +++ b/gosa-si/modules/ArpHandler.pm @@ -271,37 +271,6 @@ 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; -#} #=== FUNCTION ================================================================ # NAME: get_mac @@ -477,4 +446,5 @@ sub search_ldap_entry { return $msg; } +# vim:ts=4:shiftwidth:expandtab 1; diff --git a/gosa-si/modules/ArpWatch.pm b/gosa-si/modules/ArpWatch.pm index 6487ef101..e03bed4d0 100644 --- a/gosa-si/modules/ArpWatch.pm +++ b/gosa-si/modules/ArpWatch.pm @@ -171,6 +171,7 @@ sub _process_packet { sub _ipaddr { join( ".", unpack( "C4", pack( "N", oct( "0x". shift ) ) ) ) } sub _phys { join( ":", grep {length} split( /(..)/, shift ) ) } +# vim:ts=4:shiftwidth:expandtab 1; __END__ diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index 06b041023..f89362a97 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -31,12 +31,6 @@ 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"], -# }, "server" => { "ip" => [\$server_ip, "0.0.0.0"], "mac-address" => [\$main::server_mac_address, "00:00:00:00:00"], @@ -153,43 +147,6 @@ 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); -#} - - - -## 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 ################################################################# @@ -252,63 +209,6 @@ 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; -#} - -# 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; -#} #=== FUNCTION ================================================================ # NAME: get_mac @@ -348,61 +248,6 @@ sub get_mac { } -#=== FUNCTION ================================================================ -# NAME: register_at_bus -# PARAMETERS: nothing -# 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; -#} - - - -# outcommented from rettenbe: moved to GosaSupportDaemon.pm -#sub import_events { -# if (not -e $event_dir) { -# &main::daemon_log("S ERROR: cannot find directory or directory is not readable: $event_dir", 1); -# } -# opendir (DIR, $event_dir) or die "ERROR while loading gosa-si-events from directory $event_dir : $!\n"; -# -# while (defined (my $event = readdir (DIR))) { -# if( $event eq "." || $event eq ".." ) { next; } -# if( $event eq "gosaTriggered.pm" ) { next; } # only GOsa specific events -# -# eval{ require $event; }; -# if( $@ ) { -# &main::daemon_log("S ERROR: import of event module '$event' failed", 1); -# &main::daemon_log("$@", 8); -# next; -# } -# -# $event =~ /(\S*?).pm$/; -# my $event_module = $1; -# my $events_l = eval( $1."::get_events()") ; -# foreach my $event_name (@{$events_l}) { -# $event_hash->{$event_name} = $event_module; -# } -# my $events_string = join( ", ", @{$events_l}); -# &main::daemon_log("S DEBUG: ClientPackages imported events $events_string", 8); -# } -#} - - #=== FUNCTION ================================================================ # NAME: process_incoming_msg # PARAMETERS: crypted_msg - string - incoming crypted message @@ -565,7 +410,7 @@ sub new_key { # DESCRIPTION: process this incoming message #=============================================================================== sub here_i_am { - my ($msg, $msg_hash, $session_id) = @_; + my ($heap, $msg, $msg_hash, $session_id) = @_[HEAP, ARG0, ARG1, ARG2]; my @out_msg_l; my $out_hash; my $source = @{$msg_hash->{source}}[0]; @@ -575,6 +420,14 @@ sub here_i_am { my $client_revision = @{$msg_hash->{client_revision}}[0]; my $key_lifetime = @{$msg_hash->{key_lifetime}}[0]; + # Move forced hostname to heap - if used + if ( defined($msg_hash->{'force-hostname'}[0]) && + length($msg_hash->{'force-hostname'}[0]) > 0){ + $heap->{force-hostname}->{$mac_address}= $msg_hash->{'force-hostname'}[0]; + } else { + $heap->{force-hostname}->{$mac_address}= undef; + } + # number of known clients my $nu_clients= $main::known_clients_db->count_dbentries('known_clients'); @@ -1030,4 +883,5 @@ sub server_matches { return $result; } +# vim:ts=4:shiftwidth:expandtab 1; diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index 88b2c60ea..ae9422552 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -430,9 +430,6 @@ sub get_dns_domains() { } -############################################# -# moved from gosa-si-client: rettenbe, 16.05.2008 -# outcommented at gosa-si-client sub get_server_addresses { my $domain= shift; my @result; diff --git a/gosa-si/modules/ServerPackages.pm b/gosa-si/modules/ServerPackages.pm index 8d165d923..b33a49879 100644 --- a/gosa-si/modules/ServerPackages.pm +++ b/gosa-si/modules/ServerPackages.pm @@ -10,14 +10,6 @@ use warnings; use GOSA::GosaSupportDaemon; use Data::Dumper; -#use IO::Socket::INET; -#use XML::Simple; -#use Data::Dumper; -#use NetAddr::IP; -#use Net::LDAP; -#use Socket; -#use Net::hostent; - my $event_dir = "/usr/lib/gosa-si/server/ServerPackages"; use lib "/usr/lib/gosa-si/server/ServerPackages"; diff --git a/gosa-si/server/events/siTriggered.pm b/gosa-si/server/events/siTriggered.pm index 7694b1910..4cab90788 100644 --- a/gosa-si/server/events/siTriggered.pm +++ b/gosa-si/server/events/siTriggered.pm @@ -123,7 +123,7 @@ sub got_ping { sub detected_hardware { - my ($msg, $msg_hash, $session_id) = @_ ; + my ($heap, $msg, $msg_hash, $session_id) = @_[HEAP, ARG0, ARG1, ARG2]; my $address = $msg_hash->{source}[0]; my $header = $msg_hash->{header}[0]; my $gotoHardwareChecksum= $msg_hash->{detected_hardware}[0]->{gotoHardwareChecksum}; @@ -164,10 +164,8 @@ sub detected_hardware { &main::daemon_log("INFO: Need to create a new LDAP Entry for client $address", 4); my $ipaddress= $1 if $address =~ /^([0-9\.]*?):.*$/; my $dnsname; - if (defined($msg_hash->{'force-hostname'}) && - defined($msg_hash->{'force-hostname'}[0]) && - length($msg_hash->{'force-hostname'}[0]) > 0){ - $dnsname= $msg_hash->{'force-hostname'}[0]; + if ( defined($heap->{force-hostname}->{$macaddress}) ){ + $dnsname= $heap->{force-hostname}->{$macaddress}; &main::daemon_log("INFO: Using forced hostname $dnsname for client $address", 4); } else { $dnsname= gethostbyaddr(inet_aton($ipaddress), AF_INET) || $ipaddress; @@ -248,48 +246,4 @@ sub detected_hardware { return ; } - -# moved to server_server_com.pm: rettenbe 30.06.2008 -#sub trigger_wake { -# my ($msg, $msg_hash, $session_id) = @_ ; -# -# foreach (@{$msg_hash->{macAddress}}){ -# &main::daemon_log("$session_id INFO: trigger wake for $_", 5); -# my $host = $_; -# my $ipaddr = '255.255.255.255'; -# my $port = getservbyname('discard', 'udp'); -# -# my ($raddr, $them, $proto); -# my ($hwaddr, $hwaddr_re, $pkt); -# -# # get the hardware address (ethernet address) -# $hwaddr_re = join(':', ('[0-9A-Fa-f]{1,2}') x 6); -# if ($host =~ m/^$hwaddr_re$/) { -# $hwaddr = $host; -# } else { -# &main::daemon_log("$session_id ERROR: trigger_wake called with non mac address", 1); -# } -# -# # Generate magic sequence -# foreach (split /:/, $hwaddr) { -# $pkt .= chr(hex($_)); -# } -# $pkt = chr(0xFF) x 6 . $pkt x 16; -# -# # Allocate socket and send packet -# -# $raddr = gethostbyname($ipaddr); -# $them = pack_sockaddr_in($port, $raddr); -# $proto = getprotobyname('udp'); -# -# socket(S, AF_INET, SOCK_DGRAM, $proto) or die "socket : $!"; -# setsockopt(S, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt : $!"; -# -# send(S, $pkt, 0, $them) or die "send : $!"; -# close S; -# } -# -# return; -#} - 1;