X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-si%2Fgosa-si-client;h=003d30f72e8df25d504a25bae93fb516b4348e46;hb=59ccab6435432d90df6793ea7f8dea06a43b1f50;hp=d1d62dff398c670b322f2f8c859db2338eb917a7;hpb=7ebc84e7ad8cecd5ef9fa336a700bf23b23c7fec;p=gosa.git diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index d1d62dff3..003d30f72 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -75,7 +75,6 @@ use Time::HiRes qw( gettimeofday ); use IO::Socket::INET; use NetAddr::IP; use Crypt::Rijndael; -use GOsaSI::GosaSupportDaemon; use Digest::MD5 qw(md5_hex md5 md5_base64); use MIME::Base64; use XML::Simple; @@ -83,6 +82,7 @@ use File::Basename; use File::Spec; use File::Pid; use Net::ARP; +use GOsaSI::GosaSupportDaemon; use POE qw(Component::Server::TCP Wheel::FollowTail Wheel::Run); use Fcntl; @@ -99,7 +99,7 @@ my $client_status; my $event_dir = "/usr/lib/gosa-si/client/events"; use lib "/usr/lib/gosa-si/client/events"; -my (%cfg_defaults, $foreground, $verbose, $pid_file, $procid, $pid, $log_file, $fai_logpath); +my (%cfg_defaults, $foreground, $pid_file, $procid, $pid, $log_file, $fai_logpath); my ($server_ip, $server_port, $server_timeout, $server_domain, $server_key_lifetime); my ($client_port, $ldap_enabled, $ldap_config, $pam_config, $nss_config); my ($root_uid, $adm_gid); @@ -110,7 +110,8 @@ my @servers; my $gotoHardwareChecksum; my $system_com; my $servers_string; -$verbose= 1; + +my $client_status_hash = { 'developmental'=>'revision', 'stable'=>'release'}; # globalise variables which are used in imported events our $global_kernel; @@ -125,6 +126,7 @@ our $client_force_hostname; our $server_key; our $terminal_server_hash; our $opts_dnslookup; +our $verbose= 0; # where is the config stored by default and his name our $config = '/etc/gosa-si/client.conf'; @@ -294,81 +296,6 @@ sub dump_configuration { } } - -#=== FUNCTION ================================================================ -# NAME: check_cmdline_param -# PARAMETERS: -# RETURNS: -# DESCRIPTION: -#=============================================================================== -sub check_cmdline_param () { - my $err_config; - my $err_counter = 0; - if(not defined($cfg_file)) { - $cfg_file = "/etc/gosa-si/client.conf"; - if(! -r $cfg_file) { - $err_config = "please specify a config file"; - $err_counter += 1; - } - } - if( $err_counter > 0 ) { - &usage( "", 1 ); - if( defined( $err_config)) { print STDERR "$err_config\n"} - print STDERR "\n"; - exit( -1 ); - } -} - - -#=== FUNCTION ================================================================ -# NAME: check_pid -# PARAMETERS: -# RETURNS: -# DESCRIPTION: -#=============================================================================== -sub check_pid { - $pid = -1; - # Check, if we are already running - if( open(my $LOCK_FILE, "<","$pid_file") ) { - $pid = <$LOCK_FILE>; - if( defined $pid ) { - chomp( $pid ); - if( -f "/proc/$pid/stat" ) { - my($stat) = `cat /proc/$pid/stat` =~ m/$pid \((.+)\).*/; - if( $0 eq $stat ) { - close($LOCK_FILE); - exit -1; - } - } - } - close( $LOCK_FILE ); - unlink( $pid_file ); - } - - my $LOCK_FILE2; - # create a syslog msg if it is not to possible to open PID file - if (not sysopen(LOCK_FILE, $pid_file, O_WRONLY|O_CREAT|O_EXCL, 0644)) { - my($msg) = "Couldn't obtain lockfile '$pid_file' "; - if (open($LOCK_FILE2, '<', "$pid_file") - && ($pid = <$LOCK_FILE2>)) - { - chomp($pid); - $msg .= "(PID $pid)\n"; - } else { - $msg .= "(unable to read PID)\n"; - } - if( ! ($foreground) ) { - openlog( $0, "cons,pid", "daemon" ); - syslog( "warning", $msg ); - closelog(); - } - else { - print( STDERR " $msg " ); - } - exit( -1 ); - } -} - ############################# # # @brief When caching an interrupt remove file pid and stopping gosa-si @@ -378,10 +305,16 @@ sub sig_int_handler { daemon_log("shutting down gosa-si-client", 1); -# to be changed crude !! -# system("kill `ps -C gosa-si-server -o pid=`"); + # shtudown the client by telling the poe kernel $global_kernel->yield('shutdown'); - + + #removing the opts file + unlink ('/var/run/gosa-si/gosa-si-client.opts'); + + #removing the fifo for communication + unlink ($fai_com_fifo); + + #removing the pid $pid->remove or warn "Could not remove $pid_file\n"; exit(0); @@ -743,7 +676,7 @@ sub register_at_gosa_si_server { } # Check if our ip is resolvable - if not: don't try to register - my $ip= &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)); + my $ip= defined($client_ip)?$client_ip:&get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)); my $dnsname= gethostbyaddr(inet_aton($ip), AF_INET); if(!defined($dnsname)) { if( defined($client_force_hostname) && $client_force_hostname eq "true") { @@ -756,7 +689,7 @@ sub register_at_gosa_si_server { } # create registration msg - my $local_ip = &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)); + my $local_ip = (defined($client_ip))?$client_ip:&get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)); my $local_mac = &get_local_mac_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)); my $register_hash = &create_xml_hash("here_i_am", $local_ip.":".$client_port, $server); &add_content2xml_hash($register_hash, "new_passwd", $server_key); @@ -785,7 +718,7 @@ sub register_at_gosa_si_server { $try_to_register = 0; # Set fixed client address and mac address - $client_ip= &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)); + $client_ip= (defined($client_ip))?$client_ip:&get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)); $client_address= "$client_ip:$client_port"; $client_mac_address = $local_mac; $client_dnsname = $dnsname; @@ -1292,7 +1225,6 @@ sub post_processing_and_sending sub find_servers { # add gosa-si-server address from config file at first position of server list - #my $server_check_cfg = Config::IniFiles->new( -file => $cfg_file ); my $server_check_cfg = Config::IniFiles->new( -file => $config ); # Parse servers string @@ -1377,6 +1309,57 @@ sub find_servers { } } + +sub start_daemon { + + if( ! $foreground ) { + chdir '/' or die "Can't chdir to /: $!"; + umask 0; + open STDIN, '+>/dev/null' or die "Can't read /dev/null: $!"; + open STDOUT, '+>&STDIN' or die "Can't write to /dev/null: $!"; + open STDERR, '+>&STDIN' or die "Can't write to /dev/null: $!"; + defined($pid = fork) or die "Can't fork: $!"; + exit if $pid; + setsid or die "Can't start a new session: $!"; + } + return; +} + +sub put_version { + + # parse head url and revision from svn + $client_version =~ /^\$HeadURL: (\S+) \$:\$Rev: (\d+) \$$/; + $client_headURL = defined $1 ? $1 : 'unknown' ; + $client_revision = defined $2 ? $2 : 'unknown' ; + if ($client_headURL =~ /\/tag\// || + $client_headURL =~ /\/branches\// ) { + $client_status = "stable"; + } else { + $client_status = "developmental" ; + } + return; +} + +sub get_perms_admin { + # Determine root uid and adm gid, used for creating log files + $root_uid = getpwnam('root'); + $adm_gid = getgrnam('adm'); + if(not defined $adm_gid){ + $adm_gid = getgrnam('root'); + } + return; +} + +sub create_pid { + # Create the PID object + $pid = File::Pid->new({ file => $pid_file }); + + # Write the PID file + $pid->write; + + return; +} + # #==== MAIN = main ============================================================== # @@ -1401,78 +1384,34 @@ if( defined $dump_config ) { # read and set config parameters &read_configfile($config, %cfg_defaults); -#&check_pid; - -# Create the PID object -# Ensure you put a name that won't clobber -# another program's PID file -$pid = File::Pid->new({ - file => $pid_file, -}); - -# Write the PID file -$pid->write; - -# forward error messages to logfile -if ( ! $foreground ) { - open( STDIN, '+>/dev/null' ); - open( STDOUT, '+>&STDIN' ); - open( STDERR, '+>&STDIN' ); -} -# Just fork, if we are not in foreground mode -if( ! $foreground ) { - chdir '/' or die "Can't chdir to /: $!"; - $pid = fork; - setsid or die "Can't start a new session: $!"; - umask 0; -#} else { -# $pid = $$; -} +# daemonize the program +&start_daemon($foreground); -# Do something useful - put our PID into the pid_file -#if( 0 != $pid ) { -# open( my $LOCK_FILE, ">", "$pid_file" ); -# print $LOCK_FILE "$pid\n"; -# close( $LOCK_FILE ); -# if( !$foreground ) { -# exit( 0 ) -# }; -#} - -# parse head url and revision from svn -my $client_status_hash = { 'developmental'=>'revision', 'stable'=>'release'}; -$client_version =~ /^\$HeadURL: (\S+) \$:\$Rev: (\d+) \$$/; -$client_headURL = defined $1 ? $1 : 'unknown' ; -$client_revision = defined $2 ? $2 : 'unknown' ; -if ($client_headURL =~ /\/tag\// || - $client_headURL =~ /\/branches\// ) { - $client_status = "stable"; -} else { - $client_status = "developmental" ; -} +# create pid file +&create_pid($pid, $pid_file); # Determine root uid and adm gid, used for creating log files -$root_uid = getpwnam('root'); -$adm_gid = getgrnam('adm'); -if(not defined $adm_gid){ - $adm_gid = getgrnam('root'); -} +&get_perms_admin($root_uid, $adm_gid); + +# put version +&put_version($client_status_hash, $client_version, $client_version, $client_headURL, $client_status); daemon_log(" ", 1); -daemon_log("gosa-si-client started!", 1); +daemon_log("$0 started!", 1); daemon_log("INFO: status: $client_status", 1); daemon_log("INFO: ".$client_status_hash->{$client_status}.": $client_revision", 1); # to be changed maybe not trace of it when running -system('rm -f /tmp/gosa_si_lock*gosa-si-client*'); +#system('rm -f /tmp/gosa_si_lock*gosa-si-client*'); # detect ip and mac address and complete host address $client_address = $client_ip.":".$client_port; my $network_interface= &get_interface_for_ip($client_ip); $client_mac_address= &get_mac($network_interface); + daemon_log("INFO: ip address detected: $client_ip", 1); -daemon_log("INFO: gosa-si-client mac address detected: $client_mac_address", 1); +daemon_log("INFO: $0 mac address detected: $client_mac_address", 1); # import events