From f8085395f7146c97277ddc51db5e78f414948faf Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Sun, 29 Jan 2012 20:13:35 +0100 Subject: [PATCH 2/2] Move BUILD_SUDO outside the generic LDAP source files Avoid #ifdefs in the general part of the code --- src/providers/ldap/ldap_common.c | 60 --------------------- src/providers/ldap/ldap_common.h | 13 ++--- src/providers/ldap/ldap_init.c | 47 +---------------- src/providers/ldap/sdap_sudo.c | 107 ++++++++++++++++++++++++++++++++++++++ src/providers/ldap/sdap_sudo.h | 4 ++ 5 files changed, 117 insertions(+), 114 deletions(-) diff --git a/src/providers/ldap/ldap_common.c b/src/providers/ldap/ldap_common.c index 786e06b3d936f0cb2c86b0df2a399c14913e03fe..f13ce3f8728eca43de24cdc1e6f9010e5567cb7e 100644 --- a/src/providers/ldap/ldap_common.c +++ b/src/providers/ldap/ldap_common.c @@ -26,7 +26,6 @@ #include "providers/fail_over.h" #include "providers/ldap/sdap_async_private.h" #include "providers/krb5/krb5_common.h" -#include "providers/ldap/sdap_sudo_timer.h" #include "db/sysdb_sudo.h" #include "db/sysdb_services.h" @@ -598,65 +597,6 @@ int ldap_get_sudo_options(TALLOC_CTX *memctx, return EOK; } -#ifdef BUILD_SUDO -int sdap_sudo_setup_tasks(struct sdap_id_ctx *id_ctx) -{ - struct sdap_sudo_refresh_ctx *refresh_ctx = NULL; - struct timeval tv; - int ret = EOK; - bool refreshed = false; - bool refresh_enabled = dp_opt_get_bool(id_ctx->opts->basic, - SDAP_SUDO_REFRESH_ENABLED); - - /* set up periodical update of sudo rules */ - if (refresh_enabled) { - refresh_ctx = sdap_sudo_refresh_ctx_init(id_ctx, id_ctx->be, id_ctx, - id_ctx->opts, - tevent_timeval_zero()); - if (refresh_ctx == NULL) { - DEBUG(SSSDBG_CRIT_FAILURE, - ("sdap_sudo_refresh_ctx_init() failed!\n")); - return ENOMEM; - } - - /* If this is the first startup, we need to kick off - * an refresh immediately, to close a window where - * clients requesting sudo information won't get an - * immediate reply with no entries - */ - ret = sysdb_sudo_get_refreshed(id_ctx->be->sysdb, &refreshed); - if (ret != EOK) { - return ret; - } - if (refreshed) { - /* At least one update has previously run, - * so clients will get cached data. We will delay - * starting to enumerate by 10s so we don't slow - * down the startup process if this is happening - * during system boot. - */ - tv = tevent_timeval_current_ofs(10, 0); - DEBUG(SSSDBG_FUNC_DATA, ("Delaying first refresh of SUDO rules " - "for 10 seconds\n")); - } else { - /* This is our first startup. Schedule the - * update to start immediately once we - * enter the mainloop. - */ - tv = tevent_timeval_current(); - } - - ret = sdap_sudo_refresh_set_timer(refresh_ctx, tv); - if (ret != EOK) { - talloc_free(refresh_ctx); - return ret; - } - } - - return EOK; -} -#endif - errno_t sdap_parse_search_base(TALLOC_CTX *mem_ctx, struct dp_option *opts, int class, struct sdap_search_base ***_search_bases) diff --git a/src/providers/ldap/ldap_common.h b/src/providers/ldap/ldap_common.h index cda21da41248cb693ccfc6a85b74c797b451424f..4f3ccb3ad8084fa8112e2baa7c0a02ecceebea8b 100644 --- a/src/providers/ldap/ldap_common.h +++ b/src/providers/ldap/ldap_common.h @@ -68,6 +68,11 @@ struct sdap_auth_ctx { struct sdap_service *chpass_service; }; +void sdap_shutdown(struct be_req *req); +int sssm_ldap_id_init(struct be_ctx *bectx, + struct bet_ops **ops, + void **pvt_data); + void sdap_check_online(struct be_req *breq); void sdap_do_online_check(struct be_req *be_req, struct sdap_id_ctx *ctx); @@ -85,14 +90,6 @@ void sdap_pam_chpass_handler(struct be_req *breq); /* access */ void sdap_pam_access_handler(struct be_req *breq); -#ifdef BUILD_SUDO -/* sudo */ -void sdap_sudo_handler(struct be_req *breq); -int sdap_sudo_setup_tasks(struct sdap_id_ctx *ctx); -#endif - - - void sdap_handler_done(struct be_req *req, int dp_err, int error, const char *errstr); diff --git a/src/providers/ldap/ldap_init.c b/src/providers/ldap/ldap_init.c index 2721b00027bf6397f8952de1e50507e820a868da..c78ae88e38757b9f11a03f49dda83f77ebf25d13 100644 --- a/src/providers/ldap/ldap_init.c +++ b/src/providers/ldap/ldap_init.c @@ -28,8 +28,6 @@ #include "providers/ldap/sdap_access.h" #include "providers/ldap/sdap_sudo.h" -static void sdap_shutdown(struct be_req *req); - /* Id Handler */ struct bet_ops sdap_id_ops = { .handler = sdap_account_info_handler, @@ -55,14 +53,6 @@ struct bet_ops sdap_access_ops = { .finalize = sdap_shutdown }; -/* SUDO Handler */ -#ifdef BUILD_SUDO -struct bet_ops sdap_sudo_ops = { - .handler = sdap_sudo_handler, - .finalize = sdap_shutdown -}; -#endif - /* Please use this only for short lists */ errno_t check_order_list_for_duplicates(char **list, bool case_sensitive) @@ -395,42 +385,7 @@ done: return ret; } -int sssm_ldap_sudo_init(struct be_ctx *be_ctx, - struct bet_ops **ops, - void **pvt_data) -{ -#ifdef BUILD_SUDO - struct sdap_id_ctx *id_ctx = NULL; - void *data = NULL; - int ret; - - ret = sssm_ldap_id_init(be_ctx, ops, &data); - if (ret != EOK) { - return ret; - } - - id_ctx = talloc_get_type(data, struct sdap_id_ctx); - *ops = &sdap_sudo_ops; - *pvt_data = id_ctx; - - ret = ldap_get_sudo_options(id_ctx, be_ctx->cdb, - be_ctx->conf_path, id_ctx->opts); - if (ret != EOK) { - return ret; - } - - ret = sdap_sudo_setup_tasks(id_ctx); - if (ret != EOK) { - return ret; - } - - return ret; -#else - return EOK; -#endif -} - -static void sdap_shutdown(struct be_req *req) +void sdap_shutdown(struct be_req *req) { /* TODO: Clean up any internal data */ sdap_handler_done(req, DP_ERR_OK, EOK, NULL); diff --git a/src/providers/ldap/sdap_sudo.c b/src/providers/ldap/sdap_sudo.c index aed937f9f3008df7ef30fd624689f685ca9aefbc..3d807d6ba300f8ac81d352162be40ba6c3629677 100644 --- a/src/providers/ldap/sdap_sudo.c +++ b/src/providers/ldap/sdap_sudo.c @@ -28,8 +28,115 @@ #include "providers/ldap/sdap_async.h" #include "providers/ldap/sdap_sudo.h" #include "providers/ldap/sdap_sudo_cache.h" +#include "providers/ldap/sdap_sudo_timer.h" #include "db/sysdb_sudo.h" +struct bet_ops sdap_sudo_ops = { + .handler = sdap_sudo_handler, + .finalize = sdap_shutdown +}; + +int sdap_sudo_setup_tasks(struct sdap_id_ctx *id_ctx); + +int sssm_ldap_sudo_init(struct be_ctx *be_ctx, + struct bet_ops **ops, + void **pvt_data) +{ + struct sdap_id_ctx *id_ctx; + void *data; + int ret; + + ret = sssm_ldap_id_init(be_ctx, ops, &data); + if (ret != EOK) { + DEBUG(SSSDBG_CRIT_FAILURE, ("Cannot init LDAP ID provider [%d]: %s\n", + ret, strerror(ret))); + return ret; + } + + id_ctx = talloc_get_type(data, struct sdap_id_ctx); + if (!id_ctx) { + DEBUG(SSSDBG_CRIT_FAILURE, ("No ID provider?\n")); + return EIO; + } + + *ops = &sdap_sudo_ops; + *pvt_data = id_ctx; + + ret = ldap_get_sudo_options(id_ctx, be_ctx->cdb, + be_ctx->conf_path, id_ctx->opts); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, ("Cannot get SUDO options [%d]: %s\n", + ret, strerror(ret))); + return ret; + } + + ret = sdap_sudo_setup_tasks(id_ctx); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, ("SUDO setup failed [%d]: %s\n", + ret, strerror(ret))); + return ret; + } + + return EOK; +} + +int sdap_sudo_setup_tasks(struct sdap_id_ctx *id_ctx) +{ + struct sdap_sudo_refresh_ctx *refresh_ctx = NULL; + struct timeval tv; + int ret = EOK; + bool refreshed = false; + bool refresh_enabled = dp_opt_get_bool(id_ctx->opts->basic, + SDAP_SUDO_REFRESH_ENABLED); + + /* set up periodical update of sudo rules */ + if (refresh_enabled) { + refresh_ctx = sdap_sudo_refresh_ctx_init(id_ctx, id_ctx->be, id_ctx, + id_ctx->opts, + tevent_timeval_zero()); + if (refresh_ctx == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, + ("sdap_sudo_refresh_ctx_init() failed!\n")); + return ENOMEM; + } + + /* If this is the first startup, we need to kick off + * an refresh immediately, to close a window where + * clients requesting sudo information won't get an + * immediate reply with no entries + */ + ret = sysdb_sudo_get_refreshed(id_ctx->be->sysdb, &refreshed); + if (ret != EOK) { + return ret; + } + if (refreshed) { + /* At least one update has previously run, + * so clients will get cached data. We will delay + * starting to enumerate by 10s so we don't slow + * down the startup process if this is happening + * during system boot. + */ + tv = tevent_timeval_current_ofs(10, 0); + DEBUG(SSSDBG_FUNC_DATA, ("Delaying first refresh of SUDO rules " + "for 10 seconds\n")); + } else { + /* This is our first startup. Schedule the + * update to start immediately once we + * enter the mainloop. + */ + tv = tevent_timeval_current(); + } + + ret = sdap_sudo_refresh_set_timer(refresh_ctx, tv); + if (ret != EOK) { + talloc_free(refresh_ctx); + return ret; + } + } + + return EOK; +} + struct sdap_sudo_load_sudoers_state { struct tevent_context *ev; struct sdap_sudo_ctx *sudo_ctx; diff --git a/src/providers/ldap/sdap_sudo.h b/src/providers/ldap/sdap_sudo.h index b0e66089ae3bf3ac15fe6b9ea04b796b475f4b49..beabf90e83aef00c59877efe47b2dafe6e559231 100644 --- a/src/providers/ldap/sdap_sudo.h +++ b/src/providers/ldap/sdap_sudo.h @@ -21,6 +21,10 @@ #ifndef _SDAP_SUDO_H_ #define _SDAP_SUDO_H_ +/* Common functions from ldap_sudo.c */ +void sdap_sudo_handler(struct be_req *breq); + +/* sdap async interface */ struct tevent_req *sdap_sudo_refresh_send(TALLOC_CTX *mem_ctx, struct be_ctx *be_ctx, struct be_sudo_req *sudo_req, -- 1.7.7.6