Return the GSS error status messages back with every invocation of the GSSImportName...
authorMark Donnelly <mark@painless-security.com>
Fri, 3 Oct 2014 20:14:43 +0000 (16:14 -0400)
committerMark Donnelly <mark@painless-security.com>
Fri, 3 Oct 2014 20:14:43 +0000 (16:14 -0400)
json_gssapi/CMakeLists.txt
json_gssapi/json_protocol.txt
json_gssapi/src/commands/GSSImportName.cpp
json_gssapi/src/commands/GSSImportName.h
json_gssapi/src/datamodel/GSSDisplayStatus.cpp [new file with mode: 0644]
json_gssapi/src/datamodel/GSSDisplayStatus.h [new file with mode: 0644]
json_gssapi/test/CMakeLists.txt

index 3a9eb1c..170b231 100644 (file)
@@ -5,6 +5,7 @@ project(json_gssapi)
 include_directories(src/)
 
 add_library(jsongssapi SHARED 
+                       src/datamodel/GSSDisplayStatus.cpp 
                        src/datamodel/GSSName.cpp
                        src/datamodel/GSSOID.cpp
                        src/datamodel/GSSOIDSet.cpp
index 9305594..d1d8f42 100644 (file)
Binary files a/json_gssapi/json_protocol.txt and b/json_gssapi/json_protocol.txt differ
index 2e6d5c7..1aeba1f 100644 (file)
@@ -8,6 +8,7 @@
 #include "GSSImportName.h"
 #include "GSSException.h"
 #include <cache/GSSNameCache.h>
+#include <datamodel/GSSDisplayStatus.h>
 
 
 typedef OM_uint32 (*gss_imp_name_type)(
@@ -29,13 +30,17 @@ void GSSImportName::execute()
 
   /* Main */
   retVal = function(&minor_status, inputName.toGss(), inputNameType.toGss(), &name);
-  if ( GSS_ERROR(this->retVal) )
-  {
-    std::string errMsg;
-    errMsg += "Cannot import name: ";
-    errMsg += inputName.toString();
-    throw GSSException(errMsg.c_str(), this->retVal, this->minor_status, inputNameType.toGss());
-  }
+//   if ( GSS_ERROR(this->retVal) )
+//   {
+    JSONObject errors;
+    GSSDisplayStatus ds(retVal, minor_status, inputNameType.toGss());
+    errors.set("major_status_message", ds.getMajorMessage().c_str());
+    errors.set("minor_status_message", ds.getMinorMessage().c_str());
+    values->set("errors", errors);
+//   }
+  
+  
+  
   this->outputName.setValue(name);
   key = GSSNameCache::instance()->store(this->outputName);
 //   std::cout << "Storing key: " << key << std::endl;
@@ -57,8 +62,6 @@ void GSSImportName::execute()
 JSONObject *GSSImportName::toJSON()
 {
   /* Variables */
-  JSONObject *values = new JSONObject();
-  
   /* Error checking */
   
   /* Setup */
@@ -78,8 +81,9 @@ GSSImportName::GSSImportName ( gss_imp_name_type fn )
 {
   // defaults
   function = fn;
-  inputName = "";
-  inputNameType.setValue(GSSBuffer("{ 1 2 840 113554 1 2 1 4 }"));
+  inputName = string("");
+  inputNameType.setValue(GSSBuffer( string("{ 1 2 840 113554 1 2 1 4 }") ));
+  values = new JSONObject();
 }
 
 GSSImportName::GSSImportName(JSONObject *params, gss_imp_name_type fn) : GSSCommand(params)
@@ -88,6 +92,7 @@ GSSImportName::GSSImportName(JSONObject *params, gss_imp_name_type fn) : GSSComm
   /* Error checking */
   /* Setup */
   /* Main */
+  values = new JSONObject();
   loadParameters(params);
   function = fn;
   /* Cleanup */
index 534604f..7ebb713 100644 (file)
@@ -39,6 +39,8 @@ private:
   GSSBuffer inputName;
   GSSOID    inputNameType;
   GSSName   outputName;
+  
+  JSONObject *values;
 };
 
 #endif // GSSIMPORTNAME_H
diff --git a/json_gssapi/src/datamodel/GSSDisplayStatus.cpp b/json_gssapi/src/datamodel/GSSDisplayStatus.cpp
new file mode 100644 (file)
index 0000000..04c8d62
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#include "GSSDisplayStatus.h"
+
+#include <sstream>
+
+static void disp_status(OM_uint32 status, int status_type, gss_OID mech, std::ostream &output_stream)
+{
+  OM_uint32 disp_major, disp_minor, disp_context;
+  gss_buffer_desc disp_buf;
+
+  disp_context = 0;
+  do
+  {
+    disp_major = gss_display_status(&disp_minor, 
+                                   status, 
+                                   status_type,
+                                   mech, 
+                                   &disp_context, 
+                                   &disp_buf);
+    if (GSS_ERROR(disp_major))
+    {
+      output_stream << "Internal, unknown GSS error";
+      break; // Get out of this loop.
+    } else
+      output_stream << (char *)disp_buf.value;
+  } while (disp_context != 0);
+}
+
+
+GSSDisplayStatus::GSSDisplayStatus(OM_uint32 major, 
+                     OM_uint32 minor,
+                    gss_OID   mech  )
+{
+  std::stringstream major_stream;
+  std::stringstream minor_stream;
+  /* Setup */
+  
+  /* Main */
+  disp_status(major, GSS_C_GSS_CODE, mech, major_stream);
+  majorMessage = major_stream.str();
+  
+  disp_status(minor, GSS_C_MECH_CODE, mech, minor_stream);
+  minorMessage = minor_stream.str();
+}
+
+GSSDisplayStatus::~GSSDisplayStatus()
+{
+
+}
+
diff --git a/json_gssapi/src/datamodel/GSSDisplayStatus.h b/json_gssapi/src/datamodel/GSSDisplayStatus.h
new file mode 100644 (file)
index 0000000..c1f2e76
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#ifndef GSSDISPLAYSTATUS_H
+#define GSSDISPLAYSTATUS_H
+
+#include <gssapi.h>
+#include <string>
+#include <ostream>
+
+using std::string;
+
+class GSSDisplayStatus
+{
+public:
+    GSSDisplayStatus(OM_uint32 major, 
+                     OM_uint32 minor,
+                    gss_OID   mech  );
+    ~GSSDisplayStatus();
+    
+    string getMajorMessage() const { return majorMessage; }
+    string getMinorMessage() const { return minorMessage; }
+    
+private:
+    string minorMessage;
+    string majorMessage;
+        
+    GSSDisplayStatus& operator= ( const GSSDisplayStatus& other ) {};
+};
+
+#endif // GSSDISPLAYSTATUS_H
index 61b1f62..7f160c9 100644 (file)
@@ -36,6 +36,7 @@ add_executable(test GSSExceptionTest.cpp
                     ../src/commands/GSSWrap.cpp
                     ../src/datamodel/GSSBuffer.cpp
                     ../src/datamodel/GSSCredential.cpp
+                    ../src/datamodel/GSSDisplayStatus.cpp
                     ../src/datamodel/GSSName.cpp
                     ../src/datamodel/GSSOID.cpp
                     ../src/datamodel/GSSOIDSet.cpp