From 1b487ec41896f083e5a5e722d7c78e68fffddd51 Mon Sep 17 00:00:00 2001
From: Jan Soukal <soukal@ics.muni.cz>
Date: Fri, 30 Nov 2012 16:26:14 +0100
Subject: [PATCH] issue 596, pridana podpora varovani pri pouziti obsolete
 atributu ze strany odesilajicich klientu

---
 src/warden-client/doc/CHANGELOG             | 17 +++++++++------
 src/warden-client/doc/README                |  4 ++++
 src/warden-client/lib/WardenClientCommon.pm | 23 ++++++++++++++++++++
 src/warden-client/lib/WardenClientConf.pm   |  9 +++++++-
 src/warden-client/lib/WardenClientSend.pm   | 24 +++++++++++++++++++++
 5 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/src/warden-client/doc/CHANGELOG b/src/warden-client/doc/CHANGELOG
index 79f017b..fd48a8f 100644
--- a/src/warden-client/doc/CHANGELOG
+++ b/src/warden-client/doc/CHANGELOG
@@ -1,5 +1,10 @@
+2012-12-?? v.2.2-beta version
+--------------------------------------------------------------------------------
+- Enhanced handling of errors. Die() functions are removed from         (#599)
+  the code, errors are handled using return values. 
+
 2012-11-05 v.2.1-beta version
--------------------------------
+--------------------------------------------------------------------------------
 - Added WardenClientCommon.pm package containing error-handling and
   connect-to-server functions
 - Installation of Warden client does not require copying of certificates
@@ -17,13 +22,13 @@
 
 
 2012-07-27 v.2.0 stable version and bugfix release of warden-client-2.0.0-beta
-------------------------------------------------------------------------------
+--------------------------------------------------------------------------------
 - Sender client code fixed, so that it will not terminate "parent"
   application when crashed
 
 
 2012-05-10 v.2.0.0-beta beta version of warden-client-2.0.0
------------------------------------------------------------
+--------------------------------------------------------------------------------
 - Changed communication with server: HTTP layer added (compatible with
   Apache mod_perl version of Warden server)
 - Removed Linux version check in install.sh, unistall.sh and update.sh
@@ -31,7 +36,7 @@
     
 
 2012-03-30 v1.2.0 stable version and bugfix release of warden-client-1.1.0
---------------------------------------------------------------------------
+--------------------------------------------------------------------------------
 - Fixed SSL certificate/key access privileges security issue
 - Fixed client crash after multiple events download
 - Fixed install.sh crash when warden client installation dictionary doesn't exist
@@ -41,7 +46,7 @@
 
 
 2012-02-06 v1.1.0 stable version and bugfix release of warden-client-1.0.0
---------------------------------------------------------------------------
+--------------------------------------------------------------------------------
 - Fixed bug when receiving of events
 - Fixed earlier declaration in same scope of variable $data
 - Fixed errMsg function -> finishing by the die function
@@ -54,7 +59,7 @@
 
 
 2011-11-16 v1.0.0 stable version
---------------------------------
+--------------------------------------------------------------------------------
 - Initial package of warden client
 - SSL certificate authentication/authorization supported
 - Automatized installation process
diff --git a/src/warden-client/doc/README b/src/warden-client/doc/README
index 1530723..a4e1dc4 100644
--- a/src/warden-client/doc/README
+++ b/src/warden-client/doc/README
@@ -422,11 +422,15 @@ I. Functions, Arguments and Calls
     $note         = "this threat is dangerous";
     
     # PRIORITY - INT 1
+    # Note: Currently obsolete (although still supported). Will be removed in
+    #       warden-client 3.0! 
     # Subjective definition of incident severity. Values 0-255 are
     # possible where 0 is the lowest priority or 'undef'.
     $priority     = "1";
     
     # TIMEOUT - INT 2
+    # Note: Currently obsolete (although still supported). Will be removed in
+    #       warden-client 3.0!
     # Subjective time (in minutes) or 'undef'. After this time event might be
     # considered timeouted.
     $timeout      = "20";
diff --git a/src/warden-client/lib/WardenClientCommon.pm b/src/warden-client/lib/WardenClientCommon.pm
index 673980d..ef5ba39 100755
--- a/src/warden-client/lib/WardenClientCommon.pm
+++ b/src/warden-client/lib/WardenClientCommon.pm
@@ -16,6 +16,29 @@ use SOAP::Transport::HTTP;
 
 our $VERSION = "2.2";
 
+#-------------------------------------------------------------------------------
+# warnMsg - prints warning (to STDERR and/or Syslog) and returns 1
+#-------------------------------------------------------------------------------
+sub warnMsg
+{
+  my $msg = shift;
+
+  # print warning to STDERR?
+  if ($WardenClientConf::LOG_STDERR) {
+    print STDERR $msg . "\n";  
+  }
+
+  # print warning to Syslog?
+  if ($WardenClientConf::LOG_SYSLOG) {
+    openlog("Warden-client:", "pid", "$WardenClientConf::LOG_SYSLOG_FACILITY");
+    syslog("warn|$WardenClientConf::LOG_SYSLOG_FACILITY", $msg . "\n");
+    closelog();
+  }
+
+  return 1;
+} # end of warnMsg()
+
+
 #-------------------------------------------------------------------------------
 # errMsg - print error message and returns undef
 #-------------------------------------------------------------------------------
diff --git a/src/warden-client/lib/WardenClientConf.pm b/src/warden-client/lib/WardenClientConf.pm
index 034ad9e..1081060 100755
--- a/src/warden-client/lib/WardenClientConf.pm
+++ b/src/warden-client/lib/WardenClientConf.pm
@@ -10,6 +10,13 @@ package WardenClientConf;
 
 use strict;
 
+# (for more information se issue #596) - Should be removed in Warden client 3.0
+# Array containg event attributes that has already been reported to user as obsolete.
+our %report_obsolete = ();
+$report_obsolete{'priority'} = 1;
+$report_obsolete{'timeout'} = 1;
+# end of issue #596
+
 # preset of default variables
 our $URI = undef;
 our $SSL_KEY_FILE = undef;
@@ -22,7 +29,7 @@ our $LOG_SYSLOG_FACILITY = "local7";
 our $LOG_VERBOSE = 0;
 
 
-our $VERSION = "2.1";
+our $VERSION = "2.2";
 
 sub loadConf
 {  
diff --git a/src/warden-client/lib/WardenClientSend.pm b/src/warden-client/lib/WardenClientSend.pm
index 4e05cab..23e57b1 100755
--- a/src/warden-client/lib/WardenClientSend.pm
+++ b/src/warden-client/lib/WardenClientSend.pm
@@ -50,6 +50,30 @@ sub saveNewEvent
     my $priority     = $event[9];
     my $timeout      = $event[10];
 
+    # Issue #596 - Should be removed in Warden client 3.0.
+    # Checking for obsolete attributes priority or timeout. If not default or 'undef' values are found, print out warning.
+
+    # check if obsolete event attribute Priority is used
+    if ($WardenClientConf::report_obsolete{'priority'} && (defined $priority) && ($priority >= 1)) {
+      # print warning
+      WardenClientCommon::warnMsg('Event attribute "Priority" is now obsolete and will be removed in Warden client 3.0');
+      
+      # update WardenClientConf::report_obsolete reference to avoid multiple reports regarding one event attribute
+      $WardenClientConf::report_obsolete{'priority'} = 0;
+    }
+
+    # check if obsolete event attribute Timeout is used
+    if ($WardenClientConf::report_obsolete{'timeout'} && (defined $timeout) && ($timeout >= 0)) {
+      # print warning
+      WardenClientCommon::warnMsg('Event attribute "Timeout" is now obsolete and will be removed in Warden client 3.0');
+
+      # update WardenClientConf::report_obsolete reference to avoid multiple reports regarding one event attribute
+      $WardenClientConf::report_obsolete{'timeout'} = 0;
+    }
+   
+    # end of Issue #596 
+    
+
   my $event;
   eval {
     # create SOAP data object
-- 
GitLab