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) | 		      krb5_context context) | ||||||
| { | { | ||||||
|     kadm5_ret_t ret = 0; |     kadm5_ret_t ret = 0; | ||||||
|     *ctx = malloc(sizeof(**ctx)); |  | ||||||
|     if(*ctx == NULL) |     *ctx = calloc(1, sizeof(**ctx)); | ||||||
|  |     if (*ctx == NULL) | ||||||
| 	return ENOMEM; | 	return ENOMEM; | ||||||
|     memset(*ctx, 0, sizeof(**ctx)); |     (*ctx)->log_context.socket_fd = rk_INVALID_SOCKET; | ||||||
|  |  | ||||||
|     set_funcs(*ctx); |     set_funcs(*ctx); | ||||||
|     (*ctx)->context = context; |     (*ctx)->context = context; | ||||||
|     krb5_add_et_list (context, initialize_kadm5_error_table_r); |     krb5_add_et_list (context, initialize_kadm5_error_table_r); | ||||||
|  |  | ||||||
| #define is_set(M) (params && params->mask & KADM5_CONFIG_ ## M) | #define is_set(M) (params && params->mask & KADM5_CONFIG_ ## M) | ||||||
|     if (is_set(REALM)) { |     if (is_set(REALM)) { | ||||||
| 	(*ctx)->config.realm = strdup(params->realm); | 	(*ctx)->config.realm = strdup(params->realm); | ||||||
|   | |||||||
| @@ -55,8 +55,9 @@ destroy_config (kadm5_config_params *c) | |||||||
| static void | static void | ||||||
| destroy_kadm5_log_context (kadm5_log_context *c) | destroy_kadm5_log_context (kadm5_log_context *c) | ||||||
| { | { | ||||||
|     free (c->log_file); |     free(c->log_file); | ||||||
|     rk_closesocket (c->socket_fd); |     if (c->socket_fd != rk_INVALID_SOCKET) | ||||||
|  |         rk_closesocket(c->socket_fd); | ||||||
| #ifdef NO_UNIX_SOCKETS | #ifdef NO_UNIX_SOCKETS | ||||||
|     if (c->socket_info) { |     if (c->socket_info) { | ||||||
| 	freeaddrinfo(c->socket_info); | 	freeaddrinfo(c->socket_info); | ||||||
| @@ -72,16 +73,18 @@ destroy_kadm5_log_context (kadm5_log_context *c) | |||||||
| kadm5_ret_t | kadm5_ret_t | ||||||
| kadm5_s_destroy(void *server_handle) | kadm5_s_destroy(void *server_handle) | ||||||
| { | { | ||||||
|     kadm5_ret_t ret; |     kadm5_ret_t ret = 0; | ||||||
|     kadm5_server_context *context = server_handle; |     kadm5_server_context *context = server_handle; | ||||||
|     krb5_context kcontext = context->context; |     krb5_context kcontext = context->context; | ||||||
|  |  | ||||||
|     ret = context->db->hdb_destroy(kcontext, context->db); |     if (context->db != NULL) | ||||||
|     destroy_kadm5_log_context (&context->log_context); |         ret = context->db->hdb_destroy(kcontext, context->db); | ||||||
|     destroy_config (&context->config); |     destroy_kadm5_log_context(&context->log_context); | ||||||
|     krb5_free_principal (kcontext, context->caller); |     destroy_config(&context->config); | ||||||
|     if(context->my_context) |     krb5_free_principal(kcontext, context->caller); | ||||||
|  |     if (context->my_context) | ||||||
| 	krb5_free_context(kcontext); | 	krb5_free_context(kcontext); | ||||||
|     free (context); |     free(context); | ||||||
|  |  | ||||||
|     return ret; |     return ret; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -51,7 +51,7 @@ kadm5_s_init_with_context(krb5_context context, | |||||||
|  |  | ||||||
|     *server_handle = NULL; |     *server_handle = NULL; | ||||||
|     ret = _kadm5_s_init_context(&ctx, realm_params, context); |     ret = _kadm5_s_init_context(&ctx, realm_params, context); | ||||||
|     if(ret) |     if (ret) | ||||||
| 	return ret; | 	return ret; | ||||||
|  |  | ||||||
|     if (realm_params->mask & KADM5_CONFIG_DBNAME) |     if (realm_params->mask & KADM5_CONFIG_DBNAME) | ||||||
| @@ -83,17 +83,18 @@ kadm5_s_init_with_context(krb5_context context, | |||||||
| 	return ret; | 	return ret; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     ctx->log_context.log_fd   = -1; |     ctx->log_context.log_fd = -1; | ||||||
|  |  | ||||||
| #ifndef NO_UNIX_SOCKETS | #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 | #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_socktype, | ||||||
| 					 ctx->log_context.socket_info->ai_protocol); | 					ctx->log_context.socket_info->ai_protocol); | ||||||
| #endif | #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); |     ret = krb5_parse_name(ctx->context, client_name, &ctx->caller); | ||||||
|     if (ret == 0) |     if (ret == 0) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Viktor Dukhovni
					Viktor Dukhovni