fixup init_sec_context function typedef
[gssweb.git] / json_gssapi / src / commands / GSSInitSecContext.cpp
index e79d440..58803fd 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-typedef OM_uint32 (*init_sec_context)(
-    OM_uint32 *,        /* minor_status */
-    gss_cred_id_t,      /* claimant_cred_handle */
-    gss_ctx_id_t *,     /* context_handle */
-    gss_name_t,         /* target_name */
-    gss_OID,            /* mech_type (used to be const) */
-    OM_uint32,          /* req_flags */
-    OM_uint32,          /* time_req */
-    gss_channel_bindings_t,     /* input_chan_bindings */
-    gss_buffer_t,       /* input_token */
-    gss_OID *,          /* actual_mech_type */
-    gss_buffer_t,       /* output_token */
-    OM_uint32 *,        /* ret_flags */
-    OM_uint32 *         /* time_req */
-);
+#include "util_base64.h"
 
 void
 GSSInitSecContext::execute()
 {
   /* Variables */
-  init_sec_context fn = (init_sec_context)function;
   gss_OID actual_mech_type;
   
   /* Error checking */
@@ -74,7 +59,7 @@ GSSInitSecContext::execute()
 
   /* Main */
   // MRW -- fix so that this uses all of the vars from the object 
-  retVal = fn(
+  retVal = function(
     &minor_status,
     GSS_C_NO_CREDENTIAL,
     &context_handle,
@@ -107,7 +92,6 @@ GSSInitSecContext::execute()
   /* Return */
 }
 
-#if 0
 const char* GSSInitSecContext::getTargetDisplayName()
 {
   /* Variables */
@@ -132,12 +116,12 @@ const char* GSSInitSecContext::getTargetDisplayName()
   /* return */
   return( ret );
 }
-#endif
 
 bool GSSInitSecContext::loadParameters(JSONObject *params)
 {
   /* Variables */
   std::string key;
+  std::string token;
   
   /* Error checking */
   if ( params->isNull() )
@@ -150,7 +134,9 @@ bool GSSInitSecContext::loadParameters(JSONObject *params)
   // claimant_cred_handle
 
   // context_handle
-  if ( ! params->get("context_handle").isNull() )
+  if (!(params->get("context_handle").isNull() ||
+       (params->get("context_handle").isString() &&
+        std::string("") == params->get("context_handle").string())))
   {
     this->context_handle = GSS_C_NO_CONTEXT;
     if (params->get("context_handle").isString())
@@ -164,7 +150,11 @@ bool GSSInitSecContext::loadParameters(JSONObject *params)
   }
   
   // target_name
-  if ( ! params->get("target_name").isNull() )
+  if (! (  params->get("target_name").isNull() ||
+          (params->get("target_name").isString() &&
+           std::string("") == params->get("target_name").string())
+       )
+     )
   {
     this->target_name = GSS_C_NO_NAME;
     if (params->get("target_name").isString())
@@ -180,7 +170,13 @@ bool GSSInitSecContext::loadParameters(JSONObject *params)
   }
   
   // mech_type  
-  if ( ! params->get("mech_type").isNull() )
+  if (! ( params->get("mech_type").isNull() ||
+         (
+           params->get("mech_type").isString() &&
+           std::string("") == params->get("mech_type").string()
+         )
+       )
+     )
   {
     key.clear();
     if (params->get("mech_type").isString())
@@ -193,21 +189,20 @@ bool GSSInitSecContext::loadParameters(JSONObject *params)
   }
   
   // req_flags
-  if ( !params->get("req_flags").isNull() )
-    this->req_flags = params->get("req_flags").integer();
+  if (!params->get("req_flags").isNull() )
+    this->req_flags = (OM_uint32 )params->get("req_flags").integer();
 
   // time_req
-  if ( !params->get("time_req").isNull() )
-    this->time_req = params->get("time_req").integer();
-
-  // input_chennel_bindings
+  if (!params->get("time_req").isNull() )
+    this->time_req = (OM_uint32 )params->get("time_req").integer();
 
   // input_token
-  if ( ! params->get("input_token").isNull() )
+  if (! (params->get("input_token").isNull() ||
+        (params->get("input_token").isString() &&
+         std::string("") == params->get("input_token").string())))
   {
-    key = params->get("input_token").string();
-    this->input_token.value = (void *)key.c_str();
-    this->input_token.length = key.length();
+    token = params->get("input_token").string();
+    input_token.value = base64Decode(token.c_str(), &input_token.length);
   }
 
   /* Cleanup */
@@ -238,8 +233,11 @@ bool GSSInitSecContext::zeroOut(bool initialized)
     if (this->output_token.length > 0)
       gss_release_buffer(&minor, &output_token);
     
-    if (this->input_token.length > 0)
-      gss_release_buffer(&minor, &input_token);
+    if (this->input_token.value) {
+      base64Free(input_token.value);
+      input_token.value = NULL;
+      input_token.length = 0;
+    }
   }
 
   // Now set things to reasonable defaults
@@ -267,7 +265,9 @@ JSONObject *GSSInitSecContext::toJSON()
 {
   /* Variables */
   // MRW -- values should be scoped to the class, so execute can set error values?
+  std::string output_str;
   JSONObject *values = new JSONObject();
+  base64EncodeStr(output_token.value, output_token.length, output_str);
   
   /* Error checking */
   
@@ -278,7 +278,7 @@ JSONObject *GSSInitSecContext::toJSON()
   values->set("minor_status", this->minor_status);
   values->set("context_handle", this->contextKey.c_str());
   values->set("actual_mech_type", this->getActualMechType().toString().c_str());
-  values->set("output_token", (const char *)this->output_token.value);
+  values->set("output_token", output_str.c_str());
   values->set("ret_flags", this->ret_flags);
   values->set("time_rec", this->time_rec);
   // MRW -- modify for new error handling
@@ -291,14 +291,14 @@ JSONObject *GSSInitSecContext::toJSON()
 
 GSSInitSecContext::GSSInitSecContext(
   JSONObject *params, 
-  void *fn) : GSSCommand(params)
+  init_sec_context_type fn)
 {
   zeroOut(false);
   loadParameters(params);
   function = fn;
 }
 
-GSSInitSecContext::GSSInitSecContext(void *fn)
+GSSInitSecContext::GSSInitSecContext(init_sec_context_type fn)
 {
   zeroOut(false);
   function = fn;