More robust kadm5 server handle init and cleanup
This commit is contained in:
		| @@ -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); | ||||
|   | ||||
| @@ -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; | ||||
|  | ||||
|     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) | ||||
|     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; | ||||
| } | ||||
|   | ||||
| @@ -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) | ||||
| @@ -86,13 +86,14 @@ kadm5_s_init_with_context(krb5_context context, | ||||
|     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_fd = socket(ctx->log_context.socket_info->ai_family, | ||||
| 					ctx->log_context.socket_info->ai_socktype, | ||||
| 					ctx->log_context.socket_info->ai_protocol); | ||||
| #endif | ||||
|  | ||||
|     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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Viktor Dukhovni
					Viktor Dukhovni