More robust kadm5 server handle init and cleanup

This commit is contained in:
Viktor Dukhovni
2016-12-03 01:36:53 -05:00
parent 7209b72869
commit f0a772e3e6
3 changed files with 26 additions and 19 deletions

View File

@@ -230,13 +230,16 @@ _kadm5_s_init_context(kadm5_server_context **ctx,
krb5_context context)
{
kadm5_ret_t ret = 0;
*ctx = malloc(sizeof(**ctx));
if(*ctx == NULL)
*ctx = calloc(1, sizeof(**ctx));
if (*ctx == NULL)
return ENOMEM;
memset(*ctx, 0, sizeof(**ctx));
(*ctx)->log_context.socket_fd = rk_INVALID_SOCKET;
set_funcs(*ctx);
(*ctx)->context = context;
krb5_add_et_list (context, initialize_kadm5_error_table_r);
#define is_set(M) (params && params->mask & KADM5_CONFIG_ ## M)
if (is_set(REALM)) {
(*ctx)->config.realm = strdup(params->realm);

View File

@@ -55,8 +55,9 @@ destroy_config (kadm5_config_params *c)
static void
destroy_kadm5_log_context (kadm5_log_context *c)
{
free (c->log_file);
rk_closesocket (c->socket_fd);
free(c->log_file);
if (c->socket_fd != rk_INVALID_SOCKET)
rk_closesocket(c->socket_fd);
#ifdef NO_UNIX_SOCKETS
if (c->socket_info) {
freeaddrinfo(c->socket_info);
@@ -72,16 +73,18 @@ destroy_kadm5_log_context (kadm5_log_context *c)
kadm5_ret_t
kadm5_s_destroy(void *server_handle)
{
kadm5_ret_t ret;
kadm5_ret_t ret = 0;
kadm5_server_context *context = server_handle;
krb5_context kcontext = context->context;
ret = context->db->hdb_destroy(kcontext, context->db);
destroy_kadm5_log_context (&context->log_context);
destroy_config (&context->config);
krb5_free_principal (kcontext, context->caller);
if(context->my_context)
if (context->db != NULL)
ret = context->db->hdb_destroy(kcontext, context->db);
destroy_kadm5_log_context(&context->log_context);
destroy_config(&context->config);
krb5_free_principal(kcontext, context->caller);
if (context->my_context)
krb5_free_context(kcontext);
free (context);
free(context);
return ret;
}

View File

@@ -51,7 +51,7 @@ kadm5_s_init_with_context(krb5_context context,
*server_handle = NULL;
ret = _kadm5_s_init_context(&ctx, realm_params, context);
if(ret)
if (ret)
return ret;
if (realm_params->mask & KADM5_CONFIG_DBNAME)
@@ -83,17 +83,18 @@ kadm5_s_init_with_context(krb5_context context,
return ret;
}
ctx->log_context.log_fd = -1;
ctx->log_context.log_fd = -1;
#ifndef NO_UNIX_SOCKETS
ctx->log_context.socket_fd = socket (AF_UNIX, SOCK_DGRAM, 0);
ctx->log_context.socket_fd = socket(AF_UNIX, SOCK_DGRAM, 0);
#else
ctx->log_context.socket_fd = socket (ctx->log_context.socket_info->ai_family,
ctx->log_context.socket_info->ai_socktype,
ctx->log_context.socket_info->ai_protocol);
ctx->log_context.socket_fd = socket(ctx->log_context.socket_info->ai_family,
ctx->log_context.socket_info->ai_socktype,
ctx->log_context.socket_info->ai_protocol);
#endif
socket_set_nonblocking(ctx->log_context.socket_fd, 1);
if (ctx->log_context.socket_fd != rk_INVALID_SOCKET)
socket_set_nonblocking(ctx->log_context.socket_fd, 1);
ret = krb5_parse_name(ctx->context, client_name, &ctx->caller);
if (ret == 0)