a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina Pavel Březina <pbrezina@redhat.com>
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina Copyright (C) 2015 Red Hat
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina This program is free software; you can redistribute it and/or modify
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina it under the terms of the GNU General Public License as published by
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina the Free Software Foundation; either version 3 of the License, or
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina (at your option) any later version.
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina This program is distributed in the hope that it will be useful,
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina GNU General Public License for more details.
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina You should have received a copy of the GNU General Public License
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březinastatic void ipa_sudo_full_refresh_done(struct tevent_req *subreq);
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březinaipa_sudo_full_refresh_send(TALLOC_CTX *mem_ctx,
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina /* Remove all rules from cache */
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina delete_filter = talloc_asprintf(state, "(%s=%s)", SYSDB_OBJECTCLASS,
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina DEBUG(SSSDBG_TRACE_FUNC, "Issuing a full refresh of sudo rules\n");
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina subreq = ipa_sudo_refresh_send(state, ev, sudo_ctx,
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina tevent_req_set_callback(subreq, ipa_sudo_full_refresh_done, req);
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březinaipa_sudo_full_refresh_done(struct tevent_req *subreq)
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina state = tevent_req_data(req, struct ipa_sudo_full_refresh_state);
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina ret = ipa_sudo_refresh_recv(subreq, &state->dp_error, NULL);
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina if (ret != EOK || state->dp_error != DP_ERR_OK) {
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina ret = sysdb_sudo_set_last_full_refresh(state->domain, time(NULL));
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina DEBUG(SSSDBG_MINOR_FAILURE, "Unable to save time of "
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina "a successful full refresh\n");
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina DEBUG(SSSDBG_TRACE_FUNC, "Successful full refresh of sudo rules\n");
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březinaipa_sudo_full_refresh_recv(struct tevent_req *req,
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina state = tevent_req_data(req, struct ipa_sudo_full_refresh_state);
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březinastatic void ipa_sudo_smart_refresh_done(struct tevent_req *subreq);
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březinastatic struct tevent_req *
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březinaipa_sudo_smart_refresh_send(TALLOC_CTX *mem_ctx,
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina struct sdap_server_opts *srv_opts = sudo_ctx->id_ctx->srv_opts;
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina /* Download all rules from LDAP that are newer than usn */
f58ffb26aeaae0642a149643672fa59ec01a3a36Pavel Březina if (srv_opts == NULL || srv_opts->max_sudo_value == 0) {
f58ffb26aeaae0642a149643672fa59ec01a3a36Pavel Březina DEBUG(SSSDBG_TRACE_FUNC, "USN value is unknown, assuming zero.\n");
ef5e33f7db1e314226b0077596e38ef16305cba5Pavel Březina search_filter = talloc_asprintf(state, "(%s>=%s)",
ef5e33f7db1e314226b0077596e38ef16305cba5Pavel Březina sudo_ctx->sudorule_map[IPA_AT_SUDORULE_ENTRYUSN].name, usn);
ef5e33f7db1e314226b0077596e38ef16305cba5Pavel Březina cmdgroups_filter = talloc_asprintf(state, "(%s>=%s)",
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina sudo_ctx->sudocmdgroup_map[IPA_AT_SUDOCMDGROUP_ENTRYUSN].name, usn);
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina /* Do not remove any rules that are already in the sysdb. */
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina DEBUG(SSSDBG_TRACE_FUNC, "Issuing a smart refresh of sudo rules "
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina subreq = ipa_sudo_refresh_send(state, ev, sudo_ctx, cmdgroups_filter,
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina tevent_req_set_callback(subreq, ipa_sudo_smart_refresh_done, req);
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březinastatic void ipa_sudo_smart_refresh_done(struct tevent_req *subreq)
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina struct ipa_sudo_smart_refresh_state *state = NULL;
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina state = tevent_req_data(req, struct ipa_sudo_smart_refresh_state);
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina ret = ipa_sudo_refresh_recv(subreq, &state->dp_error, NULL);
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina if (ret != EOK || state->dp_error != DP_ERR_OK) {
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina DEBUG(SSSDBG_TRACE_FUNC, "Successful smart refresh of sudo rules\n");
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březinaint ipa_sudo_smart_refresh_recv(struct tevent_req *req,
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina struct ipa_sudo_smart_refresh_state *state = NULL;
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina state = tevent_req_data(req, struct ipa_sudo_smart_refresh_state);
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březinastatic void ipa_sudo_rules_refresh_done(struct tevent_req *subreq);
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březinaipa_sudo_rules_refresh_send(TALLOC_CTX *mem_ctx,
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina req = tevent_req_create(mem_ctx, &state, struct ipa_sudo_rules_refresh_state);
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina search_filter = talloc_zero(tmp_ctx, char); /* assign to tmp_ctx */
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina delete_filter = talloc_zero(tmp_ctx, char); /* assign to tmp_ctx */
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina /* Download only selected rules from LDAP. */
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina /* Remove all selected rules from cache. */
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina ret = sss_filter_sanitize(tmp_ctx, rules[i], &safe_rule);
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina search_filter = talloc_asprintf_append_buffer(search_filter, "(%s=%s)",
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina sudo_ctx->sudorule_map[IPA_AT_SUDORULE_NAME].name,
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina delete_filter = talloc_asprintf_append_buffer(delete_filter, "(%s=%s)",
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina search_filter = talloc_asprintf(tmp_ctx, "(|%s)", search_filter);
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina delete_filter = talloc_asprintf(tmp_ctx, "(&(%s=%s)(|%s))",
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina subreq = ipa_sudo_refresh_send(req, ev, sudo_ctx, NULL, search_filter,
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina tevent_req_set_callback(subreq, ipa_sudo_rules_refresh_done, req);
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březinaipa_sudo_rules_refresh_done(struct tevent_req *subreq)
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina state = tevent_req_data(req, struct ipa_sudo_rules_refresh_state);
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina ret = ipa_sudo_refresh_recv(subreq, &state->dp_error, &downloaded_rules_num);
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina if (ret != EOK || state->dp_error != DP_ERR_OK) {
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina state->deleted = downloaded_rules_num != state->num_rules ? true : false;
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březinaipa_sudo_rules_refresh_recv(struct tevent_req *req,
9630a4614ba4d5f68e967d4e108893550a996f30Pavel Březina state = tevent_req_data(req, struct ipa_sudo_rules_refresh_state);
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březinastatic struct tevent_req *
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březinaipa_sudo_ptask_full_refresh_send(TALLOC_CTX *mem_ctx,
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina sudo_ctx = talloc_get_type(pvt, struct ipa_sudo_ctx);
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina return ipa_sudo_full_refresh_send(mem_ctx, be_ctx->ev, sudo_ctx);
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březinaipa_sudo_ptask_full_refresh_recv(struct tevent_req *req)
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina return ipa_sudo_full_refresh_recv(req, &dp_error);
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březinastatic struct tevent_req *
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březinaipa_sudo_ptask_smart_refresh_send(TALLOC_CTX *mem_ctx,
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březina sudo_ctx = talloc_get_type(pvt, struct ipa_sudo_ctx);
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina return ipa_sudo_smart_refresh_send(mem_ctx, be_ctx->ev, sudo_ctx);
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březinaipa_sudo_ptask_smart_refresh_recv(struct tevent_req *req)
cc7f9b639144183eb4f8bd86e5bed077da7d4e35Pavel Březina return ipa_sudo_smart_refresh_recv(req, &dp_error);
a641a13889d617aca6bd998025e9087e822ff7f0Pavel Březinaipa_sudo_ptask_setup(struct be_ctx *be_ctx, struct ipa_sudo_ctx *sudo_ctx)