Code

* bugfix: gosaTriggered.pm: all functions work now
[gosa.git] / gosa-si / gosa-si-bus
index a9ae07261e929c0c4fff58732c3bad79cd5e87fa..37d54002cfa8899372b8036ca35b34742401e97e 100755 (executable)
@@ -28,8 +28,6 @@ use Time::HiRes qw( gettimeofday );
 use POE qw(Component::Server::TCP);
 use Data::Dumper;
 use Crypt::Rijndael;
-use GOSA::DBsqlite;
-use GOSA::GosaSupportDaemon;
 use IO::Socket::INET;
 use NetAddr::IP;
 use XML::Simple;
@@ -37,6 +35,8 @@ use MIME::Base64;
 use File::Basename;
 use Digest::MD5  qw(md5 md5_hex md5_base64);
 
+use GOSA::GosaSupportDaemon;
+use GOSA::DBsqlite;
 
 my ($cfg_file, $default_cfg_file, %cfg_defaults, $foreground, $verbose, $pid_file, $procid, $pid, $log_file,);
 my ($bus_address, $bus_key, $bus_ip, $bus_port, $bus_mac_address);
@@ -466,6 +466,47 @@ sub create_passwd {
 }
 
 
+sub create_ciphering {
+    my ($passwd) = @_;
+       if((!defined($passwd)) || length($passwd)==0) {
+               $passwd = "";
+       }
+    $passwd = substr(md5_hex("$passwd") x 32, 0, 32);
+    my $iv = substr(md5_hex('GONICUS GmbH'),0, 16);
+    my $my_cipher = Crypt::Rijndael->new($passwd , Crypt::Rijndael::MODE_CBC());
+    $my_cipher->set_iv($iv);
+    return $my_cipher;
+}
+
+
+sub encrypt_msg {
+    my ($msg, $key) = @_;
+    my $my_cipher = &create_ciphering($key);
+    my $len;
+    {
+           use bytes;
+           $len= 16-length($msg)%16;
+    }
+    $msg = "\0"x($len).$msg;
+    $msg = $my_cipher->encrypt($msg);
+    chomp($msg = &encode_base64($msg));
+    # there are no newlines allowed inside msg
+    $msg=~ s/\n//g;
+    return $msg;
+}
+
+
+sub decrypt_msg {
+
+    my ($msg, $key) = @_ ;
+    $msg = &decode_base64($msg);
+    my $my_cipher = &create_ciphering($key);
+    $msg = $my_cipher->decrypt($msg); 
+    $msg =~ s/\0*//g;
+    return $msg;
+}
+
+
 sub send_msg_hash2address {
     my ($msg_hash, $address, $encrypt_key) = @_ ;
     my $msg = &create_xml_string($msg_hash);
@@ -771,7 +812,7 @@ sub bus_input {
                 }
                 elsif( $target =~ /([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})/ ) {
                     # target is a mac address
-                    my $sql_statement = "SELECT * FROM bus_known_clients WHERE macaddress='$target'";
+                    my $sql_statement = "SELECT * FROM bus_known_clients WHERE macaddress LIKE '$target'";
                     my $query_res = $bus_known_clients_db->select_dbentry( $sql_statement );
                     if( 1 > keys(%{$query_res})) {
                         daemon_log("ERROR: there are more than one hosts in bus_known_clients_db with mac address '$target'", 1);
@@ -884,9 +925,9 @@ $SIG{CHLD} = 'IGNORE';
 
 # forward error messages to logfile
 if ( ! $foreground ) {
-       open STDIN, '/dev/null' or die "Can’t read /dev/null: $!";
-       open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!";
-       open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!";
+  open( STDIN,  '+>/dev/null' );
+  open( STDOUT, '+>&STDIN'    );
+  open( STDERR, '+>&STDIN'    );
 }
 
 # Just fork, if we are not in foreground mode