diff --git a/src/gssapi_client.cpp b/src/gssapi_client.cpp index 4d6ee73b..c1b5c06b 100644 --- a/src/gssapi_client.cpp +++ b/src/gssapi_client.cpp @@ -39,9 +39,22 @@ zmq::gssapi_client_t::gssapi_client_t (const options_t &options_) : security_context_established (false) { const std::string::size_type service_size = options_.gss_service_principle.size(); - service_name = new char[service_size+1]; + service_name = static_cast (malloc(service_size+1)); + assert(service_name); memcpy(service_name, options_.gss_service_principle.c_str(), service_size+1 ); + maj_stat = GSS_S_COMPLETE; + if(!options_.gss_principle.empty()) + { + const std::string::size_type principle_size = options_.gss_principle.size(); + principle_name = static_cast (malloc(principle_size+1)); + assert(principle_name); + memcpy(principle_name, options_.gss_principle.c_str(), principle_size+1 ); + + if (acquire_credentials (principle_name, &cred) != 0) + maj_stat = GSS_S_FAILURE; + } + mechs.elements = NULL; mechs.count = 0; } diff --git a/src/gssapi_mechanism_base.cpp b/src/gssapi_mechanism_base.cpp index c09b302b..81e6cf94 100644 --- a/src/gssapi_mechanism_base.cpp +++ b/src/gssapi_mechanism_base.cpp @@ -38,7 +38,7 @@ zmq::gssapi_mechanism_base_t::gssapi_mechanism_base_t (const options_t & options /// FIXME remove? in_buf (), target_name (GSS_C_NO_NAME), principle_name (NULL), - maj_stat (GSS_S_CONTINUE_NEEDED), + maj_stat (GSS_S_COMPLETE), min_stat (0), init_sec_min_stat (0), ret_flags (0), @@ -46,15 +46,6 @@ zmq::gssapi_mechanism_base_t::gssapi_mechanism_base_t (const options_t & options cred (GSS_C_NO_CREDENTIAL), context (GSS_C_NO_CONTEXT) { - if(!options_.gss_principle.empty()) - { - const std::string::size_type principle_size = options_.gss_principle.size(); - principle_name = new char[principle_size+1]; - memcpy(principle_name, options_.gss_principle.c_str(), principle_size+1 ); - - if (acquire_credentials (principle_name, &cred) != 0) - maj_stat = GSS_S_FAILURE; - } } zmq::gssapi_mechanism_base_t::~gssapi_mechanism_base_t () diff --git a/src/gssapi_server.cpp b/src/gssapi_server.cpp index 02959b7e..68fb59cc 100644 --- a/src/gssapi_server.cpp +++ b/src/gssapi_server.cpp @@ -17,6 +17,7 @@ along with this program. If not, see . */ + #include "platform.hpp" #ifdef ZMQ_HAVE_WINDOWS #include "windows.hpp" @@ -42,12 +43,26 @@ zmq::gssapi_server_t::gssapi_server_t (session_base_t *session_, state (recv_next_token), security_context_established (false) { + maj_stat = GSS_S_CONTINUE_NEEDED; + if(!options_.gss_principle.empty()) + { + const std::string::size_type principle_size = options_.gss_principle.size(); + principle_name = static_cast (malloc(principle_size+1)); + assert(principle_name); + memcpy(principle_name, options_.gss_principle.c_str(), principle_size+1 ); + + if (acquire_credentials (principle_name, &cred) != 0) + maj_stat = GSS_S_FAILURE; + } } zmq::gssapi_server_t::~gssapi_server_t () { if(cred) gss_release_cred(&min_stat, &cred); + + if(target_name) + gss_release_name(&min_stat, &target_name); } int zmq::gssapi_server_t::next_handshake_command (msg_t *msg_) @@ -72,7 +87,6 @@ int zmq::gssapi_server_t::next_handshake_command (msg_t *msg_) return -1; if (maj_stat == GSS_S_COMPLETE) { - gss_release_name(&min_stat, &target_name); security_context_established = true; } diff --git a/src/options.cpp b/src/options.cpp index aa0d4040..8ffdab2f 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -422,7 +422,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, if (optvallen_ > 0 && optvallen_ < 256 && optval_ != NULL) { gss_service_principle.assign ((const char *) optval_, optvallen_); mechanism = ZMQ_GSSAPI; - as_server = 1; + as_server = 0; return 0; } break;