a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina Pavel Březina <pbrezina@redhat.com>
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina Copyright (C) 2015 Red Hat
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina This program is free software; you can redistribute it and/or modify
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina it under the terms of the GNU General Public License as published by
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina the Free Software Foundation; either version 3 of the License, or
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina (at your option) any later version.
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina This program is distributed in the hope that it will be useful,
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina GNU General Public License for more details.
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina You should have received a copy of the GNU General Public License
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březinastatic void sdap_sudo_full_refresh_done(struct tevent_req *subreq);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březinastruct tevent_req *sdap_sudo_full_refresh_send(TALLOC_CTX *mem_ctx,
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina struct sdap_id_ctx *id_ctx = sudo_ctx->id_ctx;
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina struct sdap_sudo_full_refresh_state *state = NULL;
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina req = tevent_req_create(mem_ctx, &state, struct sdap_sudo_full_refresh_state);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina /* Download all rules from LDAP */
1ab2b07c71da6c19c3855e390d10156d598c06a2Pavel Březina search_filter = talloc_asprintf(state, SDAP_SUDO_FILTER_CLASS,
1ab2b07c71da6c19c3855e390d10156d598c06a2Pavel Březina id_ctx->opts->sudorule_map[SDAP_OC_SUDORULE].name);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina /* Remove all rules from cache */
1ab2b07c71da6c19c3855e390d10156d598c06a2Pavel Březina delete_filter = talloc_asprintf(state, "(%s=%s)",
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina DEBUG(SSSDBG_TRACE_FUNC, "Issuing a full refresh of sudo rules\n");
1ab2b07c71da6c19c3855e390d10156d598c06a2Pavel Březina subreq = sdap_sudo_refresh_send(state, sudo_ctx, search_filter,
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina tevent_req_set_callback(subreq, sdap_sudo_full_refresh_done, req);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březinastatic void sdap_sudo_full_refresh_done(struct tevent_req *subreq)
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina struct sdap_sudo_full_refresh_state *state = NULL;
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina state = tevent_req_data(req, struct sdap_sudo_full_refresh_state);
a00c89f23bd50d4fd9cf24aa09037c997781b8c9Pavel Březina ret = sdap_sudo_refresh_recv(state, subreq, &state->dp_error, NULL);
fc19031212369d69a9693ac8777ce1e61a16fe93Pavel Březina if (ret != EOK || state->dp_error != DP_ERR_OK) {
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina /* save the time in the sysdb */
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina ret = sysdb_sudo_set_last_full_refresh(state->domain, time(NULL));
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina DEBUG(SSSDBG_MINOR_FAILURE, "Unable to save time of "
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina "a successful full refresh\n");
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina /* this is only a minor error that does not affect the functionality,
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina * therefore there is no need to report it with tevent_req_error()
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina * which would cause problems in the consumers */
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina DEBUG(SSSDBG_TRACE_FUNC, "Successful full refresh of sudo rules\n");
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březinaint sdap_sudo_full_refresh_recv(struct tevent_req *req,
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina struct sdap_sudo_full_refresh_state *state = NULL;
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina state = tevent_req_data(req, struct sdap_sudo_full_refresh_state);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březinastatic void sdap_sudo_smart_refresh_done(struct tevent_req *subreq);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březinastruct tevent_req *sdap_sudo_smart_refresh_send(TALLOC_CTX *mem_ctx,
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina struct sdap_id_ctx *id_ctx = sudo_ctx->id_ctx;
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina struct sdap_attr_map *map = id_ctx->opts->sudorule_map;
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina struct sdap_server_opts *srv_opts = id_ctx->srv_opts;
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina struct sdap_sudo_smart_refresh_state *state = NULL;
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina req = tevent_req_create(mem_ctx, &state, struct sdap_sudo_smart_refresh_state);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel 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, "(objectclass=%s)",
ef5e33f7db1e314226b0077596e38ef16305cba5Pavel Březina search_filter = talloc_asprintf(state, "(&(objectclass=%s)(%s>=%s))",
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina /* Do not remove any rules that are already in the sysdb
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina * sysdb_filter = NULL; */
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina DEBUG(SSSDBG_TRACE_FUNC, "Issuing a smart refresh of sudo rules "
1ab2b07c71da6c19c3855e390d10156d598c06a2Pavel Březina subreq = sdap_sudo_refresh_send(state, sudo_ctx, search_filter, NULL);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina tevent_req_set_callback(subreq, sdap_sudo_smart_refresh_done, req);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březinastatic void sdap_sudo_smart_refresh_done(struct tevent_req *subreq)
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina struct sdap_sudo_smart_refresh_state *state = NULL;
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina state = tevent_req_data(req, struct sdap_sudo_smart_refresh_state);
a00c89f23bd50d4fd9cf24aa09037c997781b8c9Pavel Březina ret = sdap_sudo_refresh_recv(state, subreq, &state->dp_error, NULL);
efa19bb588ce1dc6c3f4b94b94464886ad764d09Pavel Březina if (ret != EOK || state->dp_error != DP_ERR_OK) {
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina DEBUG(SSSDBG_TRACE_FUNC, "Successful smart refresh of sudo rules\n");
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březinaint sdap_sudo_smart_refresh_recv(struct tevent_req *req,
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina struct sdap_sudo_smart_refresh_state *state = NULL;
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina state = tevent_req_data(req, struct sdap_sudo_smart_refresh_state);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březinastatic void sdap_sudo_rules_refresh_done(struct tevent_req *subreq);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březinastruct tevent_req *sdap_sudo_rules_refresh_send(TALLOC_CTX *mem_ctx,
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina struct sdap_sudo_rules_refresh_state *state = NULL;
24eac34a8c1f0a284cb697e8d5c09ff049181691Pavel Březina struct sdap_id_ctx *id_ctx = sudo_ctx->id_ctx;
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina req = tevent_req_create(mem_ctx, &state, struct sdap_sudo_rules_refresh_state);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
1ab2b07c71da6c19c3855e390d10156d598c06a2Pavel Březina search_filter = talloc_zero(tmp_ctx, char); /* assign to tmp_ctx */
1ab2b07c71da6c19c3855e390d10156d598c06a2Pavel Březina delete_filter = talloc_zero(tmp_ctx, char); /* assign to tmp_ctx */
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina /* Download only selected rules from LDAP */
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina /* Remove all selected rules from cache */
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina ret = sss_filter_sanitize(tmp_ctx, rules[i], &safe_rule);
1ab2b07c71da6c19c3855e390d10156d598c06a2Pavel Březina search_filter = talloc_asprintf_append_buffer(search_filter, "(%s=%s)",
1ab2b07c71da6c19c3855e390d10156d598c06a2Pavel Březina delete_filter = talloc_asprintf_append_buffer(delete_filter, "(%s=%s)",
1ab2b07c71da6c19c3855e390d10156d598c06a2Pavel Březina search_filter = talloc_asprintf(tmp_ctx, "(&"SDAP_SUDO_FILTER_CLASS"(|%s))",
1ab2b07c71da6c19c3855e390d10156d598c06a2Pavel Březina delete_filter = talloc_asprintf(tmp_ctx, "(&(%s=%s)(|%s))",
1ab2b07c71da6c19c3855e390d10156d598c06a2Pavel Březina subreq = sdap_sudo_refresh_send(req, sudo_ctx, search_filter,
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina tevent_req_set_callback(subreq, sdap_sudo_rules_refresh_done, req);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březinastatic void sdap_sudo_rules_refresh_done(struct tevent_req *subreq)
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina struct sdap_sudo_rules_refresh_state *state = NULL;
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina state = tevent_req_data(req, struct sdap_sudo_rules_refresh_state);
fc19031212369d69a9693ac8777ce1e61a16fe93Pavel Březina ret = sdap_sudo_refresh_recv(state, subreq, &state->dp_error,
fc19031212369d69a9693ac8777ce1e61a16fe93Pavel Březina if (ret != EOK || state->dp_error != DP_ERR_OK) {
fc19031212369d69a9693ac8777ce1e61a16fe93Pavel Březina state->deleted = downloaded_rules_num != state->num_rules ? true : false;
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březinaint sdap_sudo_rules_refresh_recv(struct tevent_req *req,
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina struct sdap_sudo_rules_refresh_state *state = NULL;
00fea5c2aaa0277bea522d2f61de75699ee2ed49Pavel Březina state = tevent_req_data(req, struct sdap_sudo_rules_refresh_state);
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březinastatic struct tevent_req *
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březinasdap_sudo_ptask_full_refresh_send(TALLOC_CTX *mem_ctx,
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina sudo_ctx = talloc_get_type(pvt, struct sdap_sudo_ctx);
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina return sdap_sudo_full_refresh_send(mem_ctx, sudo_ctx);
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březinasdap_sudo_ptask_full_refresh_recv(struct tevent_req *req)
fc19031212369d69a9693ac8777ce1e61a16fe93Pavel Březina return sdap_sudo_full_refresh_recv(req, &dp_error);
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březinastatic struct tevent_req *
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březinasdap_sudo_ptask_smart_refresh_send(TALLOC_CTX *mem_ctx,
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina sudo_ctx = talloc_get_type(pvt, struct sdap_sudo_ctx);
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březina return sdap_sudo_smart_refresh_send(mem_ctx, sudo_ctx);
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březinasdap_sudo_ptask_smart_refresh_recv(struct tevent_req *req)
fc19031212369d69a9693ac8777ce1e61a16fe93Pavel Březina return sdap_sudo_smart_refresh_recv(req, &dp_error);
a13cf3d295a4a6654dfa7e4193c0a2bc8bb78e92Pavel Březinasdap_sudo_ptask_setup(struct be_ctx *be_ctx, struct sdap_sudo_ctx *sudo_ctx)