From ccb67baa3ebb1a6da02fdb082de09ee6a0f25b55 Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Fri, 14 May 2010 12:04:36 +0200 Subject: [PATCH 5/6] Add callback to remove krb5 info files when going offline --- src/Makefile.am | 1 + src/providers/ipa/ipa_common.c | 8 ++++++++ src/providers/krb5/krb5_common.c | 29 +++++++++++++++++++++++++++++ src/providers/krb5/krb5_common.h | 2 ++ 4 files changed, 40 insertions(+), 0 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index e403a77..afe74c8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -509,6 +509,7 @@ krb5_utils_tests_SOURCES = \ providers/krb5/krb5_common.c \ providers/data_provider_fo.c \ providers/data_provider_opts.c \ + providers/data_provider_callbacks.c \ $(SSSD_FAILOVER_OBJ) \ $(SSSD_UTIL_OBJ) krb5_utils_tests_CFLAGS = \ diff --git a/src/providers/ipa/ipa_common.c b/src/providers/ipa/ipa_common.c index 304df8e..6738e3e 100644 --- a/src/providers/ipa/ipa_common.c +++ b/src/providers/ipa/ipa_common.c @@ -581,6 +581,14 @@ int ipa_service_init(TALLOC_CTX *memctx, struct be_ctx *ctx, goto done; } + ret = be_add_offline_cb(memctx, ctx, remove_krb5_info_files_callback, + service->krb5_service, NULL); + if (ret != EOK) { + /* Not a fatal error. */ + DEBUG(1, ("Failed to add offline callback, " + "krb5 info file will not be removed when going offline.\n")); + } + ret = EOK; done: diff --git a/src/providers/krb5/krb5_common.c b/src/providers/krb5/krb5_common.c index dfcb502..4afa3dc 100644 --- a/src/providers/krb5/krb5_common.c +++ b/src/providers/krb5/krb5_common.c @@ -425,6 +425,14 @@ int krb5_service_init(TALLOC_CTX *memctx, struct be_ctx *ctx, goto done; } + ret = be_add_offline_cb(memctx, ctx, remove_krb5_info_files_callback, + service, NULL); + if (ret != EOK) { + /* Not a fatal error. */ + DEBUG(1, ("Failed to add offline callback, " + "krb5 info file will not be removed when going offline.\n")); + } + ret = EOK; done: @@ -473,6 +481,27 @@ static errno_t remove_krb5_info_files(TALLOC_CTX *mem_ctx, const char *realm) return EOK; } +void remove_krb5_info_files_callback(void *pvt) +{ + int ret; + TALLOC_CTX *tmp_ctx = NULL; + struct krb5_service *krb5_service = talloc_get_type(pvt, + struct krb5_service); + + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + DEBUG(1, ("talloc_new failed, cannot remove krb5 info files.\n")); + return; + } + + ret = remove_krb5_info_files(tmp_ctx, krb5_service->realm); + if (ret != EOK) { + DEBUG(1, ("remove_krb5_info_files failed.\n")); + } + + talloc_zfree(tmp_ctx); +} + void krb5_finalize(struct tevent_context *ev, struct tevent_signal *se, int signum, diff --git a/src/providers/krb5/krb5_common.h b/src/providers/krb5/krb5_common.h index 87d6168..fbbd41d 100644 --- a/src/providers/krb5/krb5_common.h +++ b/src/providers/krb5/krb5_common.h @@ -77,6 +77,8 @@ int krb5_service_init(TALLOC_CTX *memctx, struct be_ctx *ctx, const char *service_name, const char *servers, const char *realm, struct krb5_service **_service); +void remove_krb5_info_files_callback(void *pvt); + void krb5_finalize(struct tevent_context *ev, struct tevent_signal *se, int signum, -- 1.6.6.1