From c3816dc1f990d7baca0823187fe9177e5d640fe1 Mon Sep 17 00:00:00 2001 From: Kevin Wasserman Date: Thu, 15 Jan 2015 13:19:46 -0500 Subject: [PATCH] Add KRB5_CALLCONV decorator Also improve type safety --- json_gssapi/src/commands/GSSInitSecContext.cpp | 23 +++-------------------- json_gssapi/src/commands/GSSInitSecContext.h | 24 ++++++++++++++++++++---- json_gssapi/test/GSSCreateSecContextTest.cpp | 12 ++++++------ 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/json_gssapi/src/commands/GSSInitSecContext.cpp b/json_gssapi/src/commands/GSSInitSecContext.cpp index 0df10ed..58803fd 100644 --- a/json_gssapi/src/commands/GSSInitSecContext.cpp +++ b/json_gssapi/src/commands/GSSInitSecContext.cpp @@ -45,27 +45,10 @@ #include "util_base64.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 */ -); - void GSSInitSecContext::execute() { /* Variables */ - init_sec_context fn = (init_sec_context)function; gss_OID actual_mech_type; /* Error checking */ @@ -76,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, @@ -308,14 +291,14 @@ JSONObject *GSSInitSecContext::toJSON() GSSInitSecContext::GSSInitSecContext( JSONObject *params, - void *fn) + 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; diff --git a/json_gssapi/src/commands/GSSInitSecContext.h b/json_gssapi/src/commands/GSSInitSecContext.h index 71f9bf8..a3454e3 100644 --- a/json_gssapi/src/commands/GSSInitSecContext.h +++ b/json_gssapi/src/commands/GSSInitSecContext.h @@ -41,6 +41,22 @@ #include #include +typedef OM_uint32 (KRB5_CALLCONV *init_sec_context_type)( + 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 */ +); + class GSSInitSecContext : public GSSCommand { public: @@ -59,8 +75,8 @@ public: void execute(); JSONObject *toJSON(); - GSSInitSecContext(void *fn = (void *)&gss_init_sec_context); - GSSInitSecContext(JSONObject *params, void *fn = (void *)&gss_init_sec_context); + GSSInitSecContext(init_sec_context_type fn = &gss_init_sec_context); + GSSInitSecContext(JSONObject *params, init_sec_context_type fn = &gss_init_sec_context); bool loadParameters(JSONObject *params); bool zeroOut(bool initialized = true); @@ -70,7 +86,7 @@ public: OM_uint32 getReqFlags() { return req_flags; } OM_uint32 getTimeReq() { return time_req; } gss_ctx_id_t getContextHandle() { return context_handle; } - void *getGSSFunction() { return function; } + init_sec_context_type getGSSFunction() { return function; } GSSOID getMechType() { return mechType; }; GSSOID getActualMechType() { return actualMechType; }; @@ -78,7 +94,7 @@ public: const char * getTargetDisplayName(); private: - void *function; + init_sec_context_type function; GSSContext context; GSSOID mechType; GSSOID actualMechType; diff --git a/json_gssapi/test/GSSCreateSecContextTest.cpp b/json_gssapi/test/GSSCreateSecContextTest.cpp index 843c581..a0752b4 100644 --- a/json_gssapi/test/GSSCreateSecContextTest.cpp +++ b/json_gssapi/test/GSSCreateSecContextTest.cpp @@ -86,11 +86,11 @@ void GSSCreateSecContextTest::testConstructor() { GSSInitSecContext cmd = GSSInitSecContext(); - void *cmdFn; - void *GSSFn; + init_sec_context_type cmdFn; + init_sec_context_type GSSFn; cmdFn = cmd.getGSSFunction(); - GSSFn = (void *)&gss_init_sec_context; + GSSFn = &gss_init_sec_context; CPPUNIT_ASSERT_MESSAGE( "The default constructor for GSSCreateSecContextCommand should assign the function gss_init_sec_context", cmdFn == GSSFn); @@ -152,7 +152,7 @@ void GSSCreateSecContextTest::testConstructorWithJSONObject() GSSInitSecContext cmd = GSSInitSecContext( &json, - (void *)&mock_init_sec + &mock_init_sec ); const char *from_cmd = cmd.getTargetDisplayName(); @@ -193,7 +193,7 @@ GSSCreateSecContextTest::testEmptyCall() { gss_ctx_id_t expectedResult, expectedArgument; - GSSInitSecContext cmd ((void *)&mock_init_sec); + GSSInitSecContext cmd (&mock_init_sec); /* Set expectations on what the GSS function will be called with */ cmd.time_req = rand() % 1024; @@ -309,7 +309,7 @@ GSSCreateSecContextTest::testEmptyCall() void GSSCreateSecContextTest::testJSONMarshal() { /* Variables */ - GSSInitSecContext cmd ((void *)&mock_init_sec); + GSSInitSecContext cmd (&mock_init_sec); JSONObject *result; GSSContextCache *cache = GSSContextCache::instance(); GSSContext context; -- 2.1.4