d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina Pavel Březina <pbrezina@redhat.com>
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina Copyright (C) 2015 Red Hat
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina This program is free software; you can redistribute it and/or modify
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina it under the terms of the GNU General Public License as published by
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina the Free Software Foundation; either version 3 of the License, or
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina (at your option) any later version.
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina This program is distributed in the hope that it will be useful,
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina GNU General Public License for more details.
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina You should have received a copy of the GNU General Public License
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březinastatic errno_t sdap_search_bases_ex_next_base(struct tevent_req *req);
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březinastatic void sdap_search_bases_ex_done(struct tevent_req *subreq);
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březinastatic struct tevent_req *
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina const char **attrs)
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina req = tevent_req_create(mem_ctx, &state, struct sdap_search_bases_ex_state);
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "No search base specified!\n");
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina state->return_first_reply = return_first_reply;
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina ? dp_opt_get_int(opts->basic, SDAP_SEARCH_TIMEOUT)
15f3e53e7ab9285afbebc8e2ec4d6d4577fef3daPavel Březina state->map[state->map_num_attrs].opt_name != NULL;
53e9a5aef4a688f7c81a4a1e77013e05313e5f9aJakub Hrozek if (state->attrs == NULL && state->map != NULL) {
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina ret = build_attrs_from_map(state, state->map, state->map_num_attrs,
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Unable to build attrs from map "
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina /* asynchronous processing */
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březinastatic errno_t sdap_search_bases_ex_next_base(struct tevent_req *req)
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina state = tevent_req_data(req, struct sdap_search_bases_ex_state);
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina state->cur_base = state->bases[state->base_iter];
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina /* Combine lookup and search base filters. */
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina filter = sdap_combine_filters(state, state->filter,
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina DEBUG(SSSDBG_TRACE_FUNC, "Issuing LDAP lookup with base [%s]\n",
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina subreq = sdap_get_generic_send(state, state->ev, state->opts, state->sh,
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina tevent_req_set_callback(subreq, sdap_search_bases_ex_done, req);
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březinastatic void sdap_search_bases_ex_done(struct tevent_req *subreq)
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina state = tevent_req_data(req, struct sdap_search_bases_ex_state);
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina DEBUG(SSSDBG_TRACE_FUNC, "Receiving data from base [%s]\n",
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina ret = sdap_get_generic_recv(subreq, state, &count, &attrs);
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina /* Add rules to result. */
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina /* Merge with previous reply. */
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina state->reply = talloc_realloc(state, state->reply,
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina for (i = 0; i < count; i++) {
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina state->reply[state->reply_count + i] = talloc_steal(state->reply,
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina /* Return the first successful search result. */
d0599eaa9369fd867953e3c58b8d7bb445525ff5Pavel Březina /* Try next search base. */
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březinastatic int sdap_search_bases_ex_recv(struct tevent_req *req,
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina tevent_req_data(req, struct sdap_search_bases_ex_state);
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina const char **attrs)
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina return sdap_search_bases_ex_send(mem_ctx, ev, opts, sh, bases, map,
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březinaint sdap_search_bases_recv(struct tevent_req *req,
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina return sdap_search_bases_ex_recv(req, mem_ctx, _reply_count, _reply);
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březinasdap_search_bases_return_first_send(TALLOC_CTX *mem_ctx,
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina const char **attrs)
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina return sdap_search_bases_ex_send(mem_ctx, ev, opts, sh, bases, map,
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březinaint sdap_search_bases_return_first_recv(struct tevent_req *req,
f48b1dda750511b57dce360fd18da2402adbcbb0Pavel Březina return sdap_search_bases_ex_recv(req, mem_ctx, _reply_count, _reply);
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březinastatic errno_t sdap_deref_bases_ex_next_base(struct tevent_req *req);
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březinastatic void sdap_deref_bases_ex_done(struct tevent_req *subreq);
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březinastatic struct tevent_req *
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina const char **attrs,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina unsigned int flags,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina req = tevent_req_create(mem_ctx, &state, struct sdap_deref_bases_ex_state);
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "No search base specified!\n");
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina if (maps == NULL || attrs == NULL || deref_attr == NULL) {
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "No attributes or map specified!\n");
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina state->return_first_reply = return_first_reply;
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina ? dp_opt_get_int(opts->basic, SDAP_SEARCH_TIMEOUT)
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina for (state->num_maps = 0; maps[state->num_maps].map != NULL;
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina /* asynchronous processing */
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březinastatic errno_t sdap_deref_bases_ex_next_base(struct tevent_req *req)
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina state = tevent_req_data(req, struct sdap_deref_bases_ex_state);
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina state->cur_base = state->bases[state->base_iter];
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina DEBUG(SSSDBG_TRACE_FUNC, "Issuing LDAP deref lookup with base [%s]\n",
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina subreq = sdap_deref_search_with_filter_send(state, state->ev, state->opts,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina state->sh, state->cur_base->basedn, state->filter,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina state->deref_attr, state->attrs, state->num_maps, state->maps,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina tevent_req_set_callback(subreq, sdap_deref_bases_ex_done, req);
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březinastatic void sdap_deref_bases_ex_done(struct tevent_req *subreq)
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina state = tevent_req_data(req, struct sdap_deref_bases_ex_state);
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina DEBUG(SSSDBG_TRACE_FUNC, "Receiving data from base [%s]\n",
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina ret = sdap_deref_search_with_filter_recv(subreq, state, &count, &attrs);
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina /* Add rules to result. */
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina /* Merge with previous reply. */
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina state->reply = talloc_realloc(state, state->reply,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina for (i = 0; i < count; i++) {
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina state->reply[state->reply_count + i] = talloc_steal(state->reply,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina /* Return the first successful search result. */
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina /* Try next search base. */
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březinastatic int sdap_deref_bases_ex_recv(struct tevent_req *req,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina tevent_req_data(req, struct sdap_deref_bases_ex_state);
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina const char **attrs,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina unsigned int flags,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina return sdap_deref_bases_ex_send(mem_ctx, ev, opts, sh, bases, maps,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březinaint sdap_deref_bases_recv(struct tevent_req *req,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina return sdap_deref_bases_ex_recv(req, mem_ctx, _reply_count, _reply);
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březinasdap_deref_bases_return_first_send(TALLOC_CTX *mem_ctx,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina const char **attrs,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina unsigned int flags,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březina return sdap_deref_bases_ex_send(mem_ctx, ev, opts, sh, bases, maps,
565b9955cc439ade58cc24a98168060a60f33e7aPavel Březinaint sdap_deref_bases_return_first_recv(struct tevent_req *req,