effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher/*
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher SSSD
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher Authors:
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher Stephen Gallagher <sgallagh@redhat.com>
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher Copyright (C) 2012 Red Hat
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher This program is free software; you can redistribute it and/or modify
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher it under the terms of the GNU General Public License as published by
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher the Free Software Foundation; either version 3 of the License, or
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher (at your option) any later version.
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher This program is distributed in the hope that it will be useful,
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher but WITHOUT ANY WARRANTY; without even the implied warranty of
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher GNU General Public License for more details.
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher You should have received a copy of the GNU General Public License
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher along with this program. If not, see <http://www.gnu.org/licenses/>.
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher*/
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher#include "util/util.h"
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina#include "util/strtonum.h"
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher#include "providers/ad/ad_common.h"
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher#include "providers/ad/ad_id.h"
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek#include "providers/ad/ad_domain_info.h"
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose#include "providers/ad/ad_pac.h"
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek#include "providers/ldap/sdap_async_enum.h"
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina#include "providers/ldap/sdap_idmap.h"
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozekstatic void
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozekdisable_gc(struct ad_options *ad_options)
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek{
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek errno_t ret;
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek if (dp_opt_get_bool(ad_options->basic, AD_ENABLE_GC) == false) {
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek return;
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek }
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_IMPORTANT_INFO, "POSIX attributes were requested "
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek "but are not present on the server side. Global Catalog "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "lookups will be disabled\n");
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek ret = dp_opt_set_bool(ad_options->basic,
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek AD_ENABLE_GC, false);
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek if (ret != EOK) {
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not turn off GC support\n");
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek /* Not fatal */
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek }
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek}
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozekstruct ad_handle_acct_info_state {
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct sdap_id_ctx *ctx;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct sdap_id_conn_ctx **conn;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct sdap_domain *sdom;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek size_t cindex;
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek struct ad_options *ad_options;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose bool using_pac;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek int dp_error;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek const char *err;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek};
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozekstatic errno_t ad_handle_acct_info_step(struct tevent_req *req);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozekstatic void ad_handle_acct_info_done(struct tevent_req *subreq);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
3d28e0e560b787b5c57ed7327d184310342a7e38Jakub Hrozekstruct tevent_req *
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozekad_handle_acct_info_send(TALLOC_CTX *mem_ctx,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar,
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct sdap_id_ctx *ctx,
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek struct ad_options *ad_options,
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct sdap_domain *sdom,
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct sdap_id_conn_ctx **conn)
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek{
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct tevent_req *req;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct ad_handle_acct_info_state *state;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct be_ctx *be_ctx = ctx->be;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek errno_t ret;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct ad_handle_acct_info_state);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek if (req == NULL) {
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek return NULL;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek state->ar = ar;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek state->ctx = ctx;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek state->sdom = sdom;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek state->conn = conn;
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek state->ad_options = ad_options;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek state->cindex = 0;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek if (sss_domain_get_state(sdom->dom) == DOM_INACTIVE) {
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek ret = ERR_SUBDOM_INACTIVE;
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek goto immediate;
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek }
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek ret = ad_handle_acct_info_step(req);
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek if (ret != EAGAIN) {
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek goto immediate;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek /* Lookup in progress */
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek return req;
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozekimmediate:
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek if (ret != EOK) {
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek tevent_req_error(req, ret);
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek } else {
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek tevent_req_done(req);
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek }
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek tevent_req_post(req, be_ctx->ev);
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek return req;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek}
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozekstatic errno_t
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozekad_handle_acct_info_step(struct tevent_req *req)
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek{
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct tevent_req *subreq = NULL;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct ad_handle_acct_info_state *state = tevent_req_data(req,
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct ad_handle_acct_info_state);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek bool noexist_delete = false;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct ldb_message *msg;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose int ret;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek if (state->conn[state->cindex] == NULL) {
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek return EOK;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek if (state->conn[state->cindex+1] == NULL) {
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek noexist_delete = true;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose state->using_pac = false;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose if ((state->ar->entry_type & BE_REQ_TYPE_MASK) == BE_REQ_INITGROUPS) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = check_if_pac_is_available(state, state->sdom->dom,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose state->ar, &msg);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose if (ret == EOK) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose /* evaluate PAC */
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose state->using_pac = true;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose subreq = ad_handle_pac_initgr_send(state, state->ctx->be,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose state->ar, state->ctx,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose state->sdom,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose state->conn[state->cindex],
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose noexist_delete,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose msg);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose if (subreq == NULL) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ad_handle_pac_initgr_send failed.\n");
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose return ENOMEM;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose /* Fall through if there is no PAC or any other error */
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
594b76cd86e32164a22172e054750fe18d09b0d6Pavel Březina if (subreq == NULL) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose subreq = sdap_handle_acct_req_send(state, state->ctx->be,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose state->ar, state->ctx,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose state->sdom,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose state->conn[state->cindex],
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose noexist_delete);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose if (subreq == NULL) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose return ENOMEM;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek tevent_req_set_callback(subreq, ad_handle_acct_info_done, req);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek return EAGAIN;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek}
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozekstatic void
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozekad_handle_acct_info_done(struct tevent_req *subreq)
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek{
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek errno_t ret;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek int dp_error;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek int sdap_err;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek const char *err;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct tevent_req);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct ad_handle_acct_info_state *state = tevent_req_data(req,
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct ad_handle_acct_info_state);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose if (state->using_pac) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = ad_handle_pac_initgr_recv(subreq, &dp_error, &err, &sdap_err);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose } else {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = sdap_handle_acct_req_recv(subreq, &dp_error, &err, &sdap_err);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
d67a80baf0bdc888297d3587c98f8a12d4827ebcLukas Slebodnik if (dp_error == DP_ERR_OFFLINE
7fc8692d49cdaa0368072f196433c07b475da679Jakub Hrozek && state->conn[state->cindex+1] != NULL
d67a80baf0bdc888297d3587c98f8a12d4827ebcLukas Slebodnik && state->conn[state->cindex]->ignore_mark_offline) {
d67a80baf0bdc888297d3587c98f8a12d4827ebcLukas Slebodnik /* This is a special case: GC does not work.
d67a80baf0bdc888297d3587c98f8a12d4827ebcLukas Slebodnik * We need to Fall back to ldap
d67a80baf0bdc888297d3587c98f8a12d4827ebcLukas Slebodnik */
d67a80baf0bdc888297d3587c98f8a12d4827ebcLukas Slebodnik ret = EOK;
d67a80baf0bdc888297d3587c98f8a12d4827ebcLukas Slebodnik sdap_err = ENOENT;
d67a80baf0bdc888297d3587c98f8a12d4827ebcLukas Slebodnik }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek talloc_zfree(subreq);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek if (ret != EOK) {
42bc7cb28858f8affa5bc7586f8d39b3afe4c387Lukas Slebodnik /* if GC was not used dp error should be set */
42bc7cb28858f8affa5bc7586f8d39b3afe4c387Lukas Slebodnik state->dp_error = dp_error;
42bc7cb28858f8affa5bc7586f8d39b3afe4c387Lukas Slebodnik state->err = err;
42bc7cb28858f8affa5bc7586f8d39b3afe4c387Lukas Slebodnik
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek goto fail;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek if (sdap_err == EOK) {
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek tevent_req_done(req);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek return;
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek } else if (sdap_err == ERR_NO_POSIX) {
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek disable_gc(state->ad_options);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek } else if (sdap_err != ENOENT) {
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek ret = EIO;
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek goto fail;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek /* Ret is only ENOENT or ERR_NO_POSIX now. Try the next connection */
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek state->cindex++;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek ret = ad_handle_acct_info_step(req);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek if (ret != EAGAIN) {
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek /* No additional search in progress. Save the last
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek * error status, we'll be returning it.
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek */
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek state->dp_error = dp_error;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek state->err = err;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek if (ret == EOK) {
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek /* No more connections */
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek tevent_req_done(req);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek } else {
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek goto fail;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek return;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek /* Another lookup in progress */
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek return;
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozekfail:
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek if (IS_SUBDOMAIN(state->sdom->dom)) {
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek /* Deactivate subdomain on lookup errors instead of going
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek * offline completely.
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek * This is a stopgap, until our failover is per-domain,
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek * not per-backend. Unfortunately, we can't rewrite the error
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek * code on some reported codes only, because sdap_id_op code
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek * encapsulated the failover as well..
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek */
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek ret = ERR_SUBDOM_INACTIVE;
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek }
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek tevent_req_error(req, ret);
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek return;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek}
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
3d28e0e560b787b5c57ed7327d184310342a7e38Jakub Hrozekerrno_t
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozekad_handle_acct_info_recv(struct tevent_req *req,
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek int *_dp_error, const char **_err)
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek{
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct ad_handle_acct_info_state *state = tevent_req_data(req,
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct ad_handle_acct_info_state);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek if (_dp_error) {
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek *_dp_error = state->dp_error;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek if (_err) {
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek *_err = state->err;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek return EOK;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek}
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozekstruct sdap_id_conn_ctx **
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaget_conn_list(TALLOC_CTX *mem_ctx, struct ad_id_ctx *ad_ctx,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct sss_domain_info *dom, struct dp_id_data *ar)
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek{
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct sdap_id_conn_ctx **clist;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek switch (ar->entry_type & BE_REQ_TYPE_MASK) {
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek case BE_REQ_USER: /* user */
a3ade2e98d397d000f224ae80c6512c959cca18eLukas Slebodnik clist = ad_user_conn_list(ad_ctx, dom);
bb8a08118db0916bf8252a9481c16271ec20acd3Jakub Hrozek break;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek case BE_REQ_BY_SECID: /* by SID */
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek case BE_REQ_USER_AND_GROUP: /* get SID */
008e1ee835602023891ac45408483d87f41e4d5cSumit Bose case BE_REQ_GROUP: /* group */
008e1ee835602023891ac45408483d87f41e4d5cSumit Bose case BE_REQ_INITGROUPS: /* init groups for user */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina clist = ad_gc_conn_list(mem_ctx, ad_ctx, dom);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek break;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek default:
72ae534f5aef6d2e5d3f2f51299aede5abf9687eJakub Hrozek /* Requests for other object should only contact LDAP by default */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina clist = ad_ldap_conn_list(mem_ctx, ad_ctx, dom);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek break;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek return clist;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek}
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
4cde267bec52ae1723a125d19439a5c75b47ebb7Pavel Březinastatic bool ad_account_can_shortcut(struct be_ctx *be_ctx,
4cde267bec52ae1723a125d19439a5c75b47ebb7Pavel Březina struct sdap_idmap_ctx *idmap_ctx,
4cde267bec52ae1723a125d19439a5c75b47ebb7Pavel Březina int filter_type,
4cde267bec52ae1723a125d19439a5c75b47ebb7Pavel Březina const char *filter_value,
4cde267bec52ae1723a125d19439a5c75b47ebb7Pavel Březina const char *filter_domain)
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina{
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina struct sss_domain_info *domain = be_ctx->domain;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina struct sss_domain_info *req_dom = NULL;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina enum idmap_error_code err;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina char *sid = NULL;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina const char *csid = NULL;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina uint32_t id;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina bool shortcut = false;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina errno_t ret;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina if (!sdap_idmap_domain_has_algorithmic_mapping(idmap_ctx, domain->name,
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina domain->domain_id)) {
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina goto done;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina }
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina switch (filter_type) {
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina case BE_FILTER_IDNUM:
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina /* convert value to ID */
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina errno = 0;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina id = strtouint32(filter_value, NULL, 10);
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina if (errno != 0) {
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina ret = errno;
4cde267bec52ae1723a125d19439a5c75b47ebb7Pavel Březina DEBUG(SSSDBG_MINOR_FAILURE, "Unable to convert filter value to "
4cde267bec52ae1723a125d19439a5c75b47ebb7Pavel Březina "number [%d]: %s\n", ret, strerror(ret));
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina goto done;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina }
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina /* convert the ID to its SID equivalent */
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina err = sss_idmap_unix_to_sid(idmap_ctx->map, id, &sid);
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina if (err != IDMAP_SUCCESS) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Mapping ID [%s] to SID failed: "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "[%s]\n", filter_value, idmap_error_string(err));
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina goto done;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina }
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina /* fall through */
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina case BE_FILTER_SECID:
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina csid = sid == NULL ? filter_value : sid;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl req_dom = find_domain_by_sid(domain, csid);
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina if (req_dom == NULL) {
0f1ca83d9a87953e6e44f94e5948f1675b4adda2Lukas Slebodnik DEBUG(SSSDBG_OP_FAILURE, "Invalid domain for SID:%s\n", csid);
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina goto done;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina }
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina if (strcasecmp(req_dom->name, filter_domain) != 0) {
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina shortcut = true;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina }
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina break;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina default:
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina break;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina }
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březinadone:
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina if (sid != NULL) {
4537e95f6741ae05ec620e5b46ca1d4a3a1ceae5Pavel Březina sss_idmap_free_sid(idmap_ctx->map, sid);
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina }
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina
4cde267bec52ae1723a125d19439a5c75b47ebb7Pavel Březina return shortcut;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina}
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastruct ad_account_info_handler_state {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct sss_domain_info *domain;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_reply_std reply;
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek};
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic void ad_account_info_handler_done(struct tevent_req *subreq);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastruct tevent_req *
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaad_account_info_handler_send(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct ad_id_ctx *id_ctx,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *data,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_req_params *params)
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct ad_account_info_handler_state *state;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct sdap_id_conn_ctx **clist;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher struct sdap_id_ctx *sdap_id_ctx;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct sss_domain_info *domain;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek struct sdap_domain *sdom;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct tevent_req *subreq;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct tevent_req *req;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct be_ctx *be_ctx;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina bool shortcut;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek errno_t ret;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina sdap_id_ctx = id_ctx->sdap_id_ctx;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina be_ctx = params->be_ctx;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina req = tevent_req_create(mem_ctx, &state,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct ad_account_info_handler_state);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (req == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return NULL;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (sdap_is_enum_request(data)) {
40bc389bc79bc41429b5a92d5ce75955f8eefaf5Jakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Skipping enumeration on demand\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = EOK;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto immediately;
40bc389bc79bc41429b5a92d5ce75955f8eefaf5Jakub Hrozek }
40bc389bc79bc41429b5a92d5ce75955f8eefaf5Jakub Hrozek
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina /* Try to shortcut if this is ID or SID search and it belongs to
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina * other domain range than is in ar->domain. */
4cde267bec52ae1723a125d19439a5c75b47ebb7Pavel Březina shortcut = ad_account_can_shortcut(be_ctx, sdap_id_ctx->opts->idmap_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina data->filter_type, data->filter_value,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina data->domain);
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina if (shortcut) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "This ID is from different domain\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = EOK;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto immediately;
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina }
76da70d5a5b5b05b926840d7692a31915d3ca8ebPavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina domain = be_ctx->domain;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (strcasecmp(data->domain, be_ctx->domain->name) != 0) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* Subdomain request, verify subdomain. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina domain = find_domain_by_name(be_ctx->domain, data->domain, true);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (domain == NULL) {
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek ret = EINVAL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto immediately;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* Determine whether to connect to GC, LDAP or try both. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina clist = get_conn_list(state, id_ctx, domain, data);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek if (clist == NULL) {
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek ret = EIO;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto immediately;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina sdom = sdap_domain_get(sdap_id_ctx->opts, domain);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek if (sdom == NULL) {
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek ret = EIO;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto immediately;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina state->domain = sdom->dom;
64d4b1e5fd4a3c99ef8d8fef6ad0db52c5152c1cJakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina subreq = ad_handle_acct_info_send(state, data, sdap_id_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina id_ctx->ad_options, sdom, clist);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (subreq == NULL) {
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek ret = ENOMEM;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto immediately;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek }
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina tevent_req_set_callback(subreq, ad_account_info_handler_done, req);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return req;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaimmediately:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&state->reply, DP_ERR_DECIDE, ret, NULL);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* TODO For backward compatibility we always return EOK to DP now. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina tevent_req_done(req);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina tevent_req_post(req, params->ev);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return req;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek}
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic void ad_account_info_handler_done(struct tevent_req *subreq)
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct ad_account_info_handler_state *state;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct tevent_req *req;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina const char *err_msg;
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek int dp_error;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina errno_t ret;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina state = tevent_req_data(req, struct ad_account_info_handler_state);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = ad_handle_acct_info_recv(subreq, &dp_error, &err_msg);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina talloc_zfree(subreq);
5546876b121d674077e93fe908f3a602de8ec31fJakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* TODO For backward compatibility we always return EOK to DP now. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&state->reply, dp_error, ret, err_msg);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina tevent_req_done(req);
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher}
e523233315f44b8f77ab9c5143a3d80364ebf955Ondrej Kos
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaerrno_t ad_account_info_handler_recv(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct tevent_req *req,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_reply_std *data)
e523233315f44b8f77ab9c5143a3d80364ebf955Ondrej Kos{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct ad_account_info_handler_state *state = NULL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina state = tevent_req_data(req, struct ad_account_info_handler_state);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina TEVENT_REQ_RETURN_ON_ERROR(req);
e523233315f44b8f77ab9c5143a3d80364ebf955Ondrej Kos
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina *data = state->reply;
e523233315f44b8f77ab9c5143a3d80364ebf955Ondrej Kos
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return EOK;
e523233315f44b8f77ab9c5143a3d80364ebf955Ondrej Kos}
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozekstruct ad_enumeration_state {
f8407faaeb6726bef6463d84f183f2b0ad1f99d4Jakub Hrozek struct ad_id_ctx *id_ctx;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct ldap_enum_ctx *ectx;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct sdap_id_op *sdap_op;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct tevent_context *ev;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek const char *realm;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct sdap_domain *sdom;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct sdap_domain *sditer;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek};
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozekstatic void ad_enumeration_conn_done(struct tevent_req *subreq);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozekstatic void ad_enumeration_master_done(struct tevent_req *subreq);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekstatic errno_t ad_enum_sdom(struct tevent_req *req, struct sdap_domain *sd,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct ad_id_ctx *id_ctx);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozekstatic void ad_enumeration_done(struct tevent_req *subreq);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozekstruct tevent_req *
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozekad_enumeration_send(TALLOC_CTX *mem_ctx,
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct tevent_context *ev,
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct be_ctx *be_ctx,
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct be_ptask *be_ptask,
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek void *pvt)
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek{
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct tevent_req *req;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct tevent_req *subreq;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct ad_enumeration_state *state;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct ldap_enum_ctx *ectx;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek errno_t ret;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct ad_enumeration_state);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek if (req == NULL) return NULL;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek ectx = talloc_get_type(pvt, struct ldap_enum_ctx);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek if (ectx == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Cannot retrieve ldap_enum_ctx!\n");
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek ret = EFAULT;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek goto fail;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek }
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek state->ectx = ectx;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek state->ev = ev;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek state->sdom = ectx->sdom;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek state->sditer = state->sdom;
f8407faaeb6726bef6463d84f183f2b0ad1f99d4Jakub Hrozek state->id_ctx = talloc_get_type(ectx->pvt, struct ad_id_ctx);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek state->realm = dp_opt_get_cstring(state->id_ctx->ad_options->basic,
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek AD_KRB5_REALM);
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek if (state->realm == NULL) {
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek DEBUG(SSSDBG_CONF_SETTINGS, "Missing realm\n");
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek ret = EINVAL;
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek goto fail;
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek }
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek
f8407faaeb6726bef6463d84f183f2b0ad1f99d4Jakub Hrozek state->sdap_op = sdap_id_op_create(state,
f8407faaeb6726bef6463d84f183f2b0ad1f99d4Jakub Hrozek state->id_ctx->ldap_ctx->conn_cache);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek if (state->sdap_op == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sdap_id_op_create failed.\n");
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek ret = ENOMEM;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek goto fail;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek }
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek subreq = sdap_id_op_connect_send(state->sdap_op, state, &ret);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek if (subreq == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sdap_id_op_connect_send failed: %d(%s).\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek goto fail;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek }
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek tevent_req_set_callback(subreq, ad_enumeration_conn_done, req);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek return req;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozekfail:
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek tevent_req_error(req, ret);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek tevent_req_post(req, ev);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek return req;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek}
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozekstatic void
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozekad_enumeration_conn_done(struct tevent_req *subreq)
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek{
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct tevent_req);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct ad_enumeration_state *state = tevent_req_data(req,
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct ad_enumeration_state);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek int ret, dp_error;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek ret = sdap_id_op_connect_recv(subreq, &dp_error);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek talloc_zfree(subreq);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek if (ret != EOK) {
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek if (dp_error == DP_ERR_OFFLINE) {
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Backend is marked offline, retry later!\n");
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek tevent_req_done(req);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek } else {
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Domain enumeration failed to connect to " \
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "LDAP server: (%d)[%s]\n", ret, strerror(ret));
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek tevent_req_error(req, ret);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek }
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek return;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek }
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek subreq = ad_master_domain_send(state, state->ev,
f8407faaeb6726bef6463d84f183f2b0ad1f99d4Jakub Hrozek state->id_ctx->ldap_ctx,
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek state->sdap_op,
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek state->sdom->dom->name);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek if (subreq == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "ad_master_domain_send failed.\n");
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek tevent_req_error(req, ret);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek return;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek }
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek tevent_req_set_callback(subreq, ad_enumeration_master_done, req);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek}
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozekstatic void
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozekad_enumeration_master_done(struct tevent_req *subreq)
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek{
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek errno_t ret;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct tevent_req);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct ad_enumeration_state *state = tevent_req_data(req,
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct ad_enumeration_state);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek char *flat_name;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek char *master_sid;
17195241500e46272018d7897d6e87249870caf2Pavel Reichl char *forest;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek ret = ad_master_domain_recv(subreq, state,
60cab26b12df9a2153823972cde0c38ca86e01b9Yassir Elley &flat_name, &master_sid, NULL, &forest);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek talloc_zfree(subreq);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Cannot retrieve master domain info\n");
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek tevent_req_error(req, ret);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek return;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek }
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek ret = sysdb_master_domain_add_info(state->sdom->dom, state->realm,
132b31fd5fb74a7627896cdceaf29c7601ed4795Sumit Bose flat_name, master_sid, forest, NULL);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Cannot save master domain info\n");
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek tevent_req_error(req, ret);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek return;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek }
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = ad_enum_sdom(req, state->sdom, state->id_ctx);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (ret != EOK) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not enumerate domain %s\n", state->sdom->dom->name);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek tevent_req_error(req, ret);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek return;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek /* Execution will resume in ad_enumeration_done */
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek}
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekstatic errno_t
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekad_enum_sdom(struct tevent_req *req,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct sdap_domain *sd,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct ad_id_ctx *id_ctx)
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek{
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct sdap_id_conn_ctx *user_conn;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct tevent_req *subreq;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct ad_enumeration_state *state = tevent_req_data(req,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct ad_enumeration_state);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (dp_opt_get_bool(id_ctx->ad_options->basic, AD_ENABLE_GC)) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek user_conn = id_ctx->gc_ctx;
dde2f0b4fcabc7093ddfcdda3dbacff00b82df46Jakub Hrozek } else {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek user_conn = id_ctx->ldap_ctx;
dde2f0b4fcabc7093ddfcdda3dbacff00b82df46Jakub Hrozek }
dde2f0b4fcabc7093ddfcdda3dbacff00b82df46Jakub Hrozek
dde2f0b4fcabc7093ddfcdda3dbacff00b82df46Jakub Hrozek /* Groups are searched for in LDAP, users in GC. Services (if present,
dde2f0b4fcabc7093ddfcdda3dbacff00b82df46Jakub Hrozek * which is unlikely in AD) from LDAP as well
dde2f0b4fcabc7093ddfcdda3dbacff00b82df46Jakub Hrozek */
dde2f0b4fcabc7093ddfcdda3dbacff00b82df46Jakub Hrozek subreq = sdap_dom_enum_ex_send(state, state->ev,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek id_ctx->sdap_id_ctx,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek sd,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek user_conn, /* Users */
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek id_ctx->ldap_ctx, /* Groups */
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek id_ctx->ldap_ctx); /* Services */
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek if (subreq == NULL) {
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek /* The ptask API will reschedule the enumeration on its own on
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek * failure */
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to schedule enumeration, retrying later!\n");
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek return ENOMEM;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek }
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek tevent_req_set_callback(subreq, ad_enumeration_done, req);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek return EOK;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek}
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekstatic errno_t ad_enum_cross_dom_members(struct sdap_options *opts,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct sss_domain_info *dom);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozekstatic void
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozekad_enumeration_done(struct tevent_req *subreq)
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek{
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek errno_t ret;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct tevent_req);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct ad_enumeration_state *state = tevent_req_data(req,
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek struct ad_enumeration_state);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
dde2f0b4fcabc7093ddfcdda3dbacff00b82df46Jakub Hrozek ret = sdap_dom_enum_ex_recv(subreq);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek talloc_zfree(subreq);
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek if (ret == ERR_NO_POSIX) {
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek /* Retry enumerating the same domain again, this time w/o
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek * connecting to GC
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek */
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek disable_gc(state->id_ctx->ad_options);
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek ret = ad_enum_sdom(req, state->sditer, state->id_ctx);
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek if (ret != EOK) {
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not retry domain %s\n", state->sditer->dom->name);
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek tevent_req_error(req, ret);
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek return;
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek }
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek /* Execution will resume in ad_enumeration_done */
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek return;
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek } else if (ret != EOK) {
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not enumerate domain %s\n", state->sditer->dom->name);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek tevent_req_error(req, ret);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek return;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek }
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
957c55df7a7086166fb3c14cead6a0dab8f574c1Jakub Hrozek do {
957c55df7a7086166fb3c14cead6a0dab8f574c1Jakub Hrozek state->sditer = state->sditer->next;
957c55df7a7086166fb3c14cead6a0dab8f574c1Jakub Hrozek } while (state->sditer &&
957c55df7a7086166fb3c14cead6a0dab8f574c1Jakub Hrozek state->sditer->dom->enumerate == false);
957c55df7a7086166fb3c14cead6a0dab8f574c1Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (state->sditer != NULL) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = ad_enum_sdom(req, state->sditer, state->sditer->pvt);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not enumerate domain %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov state->sditer->dom->name);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek tevent_req_error(req, ret);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek return;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek /* Execution will resume in ad_enumeration_done */
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek return;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek /* No more subdomains to enumerate. Check if we need to fixup
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek * cross-domain membership
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek */
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (state->sditer != state->sdom) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek /* We did enumerate at least one subdomain. Walk the subdomains
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek * and fixup members for each of them
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek */
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek for (state->sditer = state->sdom;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek state->sditer;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek state->sditer = state->sditer->next) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = ad_enum_cross_dom_members(state->id_ctx->ad_options->id,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek state->sditer->dom);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Could not check cross-domain "
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek "memberships for %s, group memberships might be "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "incomplete!\n", state->sdom->dom->name);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek continue;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek tevent_req_done(req);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek}
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekstatic errno_t ad_group_extra_members(TALLOC_CTX *mem_ctx,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek const struct ldb_message *group,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct sss_domain_info *dom,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek char ***_group_only);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekstatic errno_t ad_group_add_member(struct sdap_options *opts,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct sss_domain_info *group_domain,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct ldb_dn *group_dn,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek const char *member);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekstatic errno_t
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekad_enum_cross_dom_members(struct sdap_options *opts,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct sss_domain_info *dom)
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek{
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek errno_t ret;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek errno_t sret;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek char *filter;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek TALLOC_CTX *tmp_ctx;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek const char *attrs[] = {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek SYSDB_NAME,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek SYSDB_MEMBER,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek SYSDB_ORIG_MEMBER,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek NULL
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek };
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek size_t count, i, mi;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct ldb_message **msgs;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek bool in_transaction = false;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek char **group_only;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek tmp_ctx = talloc_new(NULL);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (tmp_ctx == NULL) return ENOMEM;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = sysdb_transaction_start(dom->sysdb);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek in_transaction = true;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek filter = talloc_asprintf(tmp_ctx, "(%s=*)", SYSDB_NAME);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (filter == NULL) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = ENOMEM;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = sysdb_search_groups(tmp_ctx, dom, filter, attrs, &count, &msgs);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (ret != EOK) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek for (i = 0; i < count; i++) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = ad_group_extra_members(tmp_ctx, msgs[i], dom, &group_only);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to check extra members\n");
bad65473c4c28ecbf2b6bd374a7ae2d634d57d8dLukas Slebodnik continue;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek } else if (group_only == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "No extra members\n");
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek continue;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek /* Group has extra members */
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek for (mi = 0; group_only[mi]; mi++) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = ad_group_add_member(opts, dom, msgs[i]->dn, group_only[mi]);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Failed to add [%s]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov group_only[mi], strerror(ret));
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek continue;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek talloc_zfree(group_only);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = sysdb_transaction_commit(dom->sysdb);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek in_transaction = false;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = EOK;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekdone:
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (in_transaction) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek sret = sysdb_transaction_cancel(dom->sysdb);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (sret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not cancel transaction\n");
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek talloc_free(tmp_ctx);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek return ret;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek}
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekstatic errno_t
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekad_group_stored_orig_members(TALLOC_CTX *mem_ctx, struct sss_domain_info *dom,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct ldb_dn *dn, char ***_odn_list);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekstatic errno_t
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekad_group_extra_members(TALLOC_CTX *mem_ctx, const struct ldb_message *group,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct sss_domain_info *dom, char ***_group_only)
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek{
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek TALLOC_CTX *tmp_ctx;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct ldb_message_element *m, *om;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek const char *name;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek errno_t ret;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek char **sysdb_odn_list;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek const char **group_odn_list;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek char **group_only = NULL;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (_group_only == NULL) return EINVAL;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek *_group_only = NULL;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek tmp_ctx = talloc_new(NULL);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (tmp_ctx == NULL) return ENOMEM;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek om = ldb_msg_find_element(group, SYSDB_ORIG_MEMBER);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek m = ldb_msg_find_element(group, SYSDB_MEMBER);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek name = ldb_msg_find_attr_as_string(group, SYSDB_NAME, NULL);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (name == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "A group with no name!\n");
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = EFAULT;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (om == NULL || om->num_values == 0) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Group %s has no original members\n", name);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = EOK;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (m == NULL || (m->num_values < om->num_values)) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Group %s has %d members but %d original members\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov name, m ? m->num_values : 0, om->num_values);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek /* Get the list of originalDN attributes that are already
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek * linked to the group
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek */
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = ad_group_stored_orig_members(tmp_ctx, dom, group->dn,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek &sysdb_odn_list);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (ret != EOK) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not retrieve list of original members for %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov name);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek /* Get the list of original DN attributes the group had in AD */
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek group_odn_list = sss_ldb_el_to_string_list(tmp_ctx, om);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (group_odn_list == NULL) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = EFAULT;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek /* Compare the two lists */
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = diff_string_lists(tmp_ctx, discard_const(group_odn_list),
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek sysdb_odn_list, &group_only, NULL, NULL);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (ret != EOK) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not compare lists of members for %s\n", name);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = EOK;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek *_group_only = talloc_steal(mem_ctx, group_only);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekdone:
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek talloc_free(tmp_ctx);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek return ret;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek}
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekstatic errno_t
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekad_group_stored_orig_members(TALLOC_CTX *mem_ctx, struct sss_domain_info *dom,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct ldb_dn *dn, char ***_odn_list)
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek{
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek errno_t ret;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek TALLOC_CTX *tmp_ctx;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek size_t m_count, i;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct ldb_message **members;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek const char *attrs[] = {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek SYSDB_NAME,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek SYSDB_ORIG_DN,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek NULL
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek };
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek char **odn_list;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek const char *odn;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek size_t oi;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek tmp_ctx = talloc_new(NULL);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (tmp_ctx == NULL) return ENOMEM;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek /* Get all entries member element points to */
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = sysdb_asq_search(tmp_ctx, dom, dn, NULL, SYSDB_MEMBER,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek attrs, &m_count, &members);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (ret != EOK) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek odn_list = talloc_zero_array(tmp_ctx, char *, m_count + 1);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (odn_list == NULL) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = ENOMEM;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek /* Get a list of their original DNs */
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek oi = 0;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek for (i = 0; i < m_count; i++) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek odn = ldb_msg_find_attr_as_string(members[i], SYSDB_ORIG_DN, NULL);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (odn == NULL) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek continue;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek odn_list[oi] = talloc_strdup(odn_list, odn);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (odn_list[oi] == NULL) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = ENOMEM;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek oi++;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Member %s already in sysdb\n", odn);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = EOK;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek *_odn_list = talloc_steal(mem_ctx, odn_list);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekdone:
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek talloc_free(tmp_ctx);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek return ret;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek}
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekstatic errno_t
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekad_group_add_member(struct sdap_options *opts,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct sss_domain_info *group_domain,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct ldb_dn *group_dn,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek const char *member)
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek{
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct sdap_domain *sd;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct ldb_dn *base_dn;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek TALLOC_CTX *tmp_ctx;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek errno_t ret;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek const char *mem_filter;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek size_t msgs_count;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek struct ldb_message **msgs;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek /* This member would be from a different domain */
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek sd = sdap_domain_get_by_dn(opts, member);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (sd == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "No matching domain for %s\n", member);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek return ENOENT;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek tmp_ctx = talloc_new(NULL);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (tmp_ctx == NULL) return ENOMEM;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek mem_filter = talloc_asprintf(tmp_ctx, "(%s=%s)",
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek SYSDB_ORIG_DN, member);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (mem_filter == NULL) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = ENOMEM;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek base_dn = sysdb_domain_dn(tmp_ctx, sd->dom);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (base_dn == NULL) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = ENOMEM;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = sysdb_search_entry(tmp_ctx, sd->dom->sysdb, base_dn,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek LDB_SCOPE_SUBTREE, mem_filter, NULL,
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek &msgs_count, &msgs);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (ret == ENOENT) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "No member [%s] in sysdb\n", member);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = EOK;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek } else if (ret != EOK) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "[%s] found in sysdb\n", member);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (msgs_count != 1) {
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Search by orig DN returned %zd results!\n", msgs_count);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = EFAULT;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = sysdb_mod_group_member(group_domain, msgs[0]->dn, group_dn, SYSDB_MOD_ADD);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not add [%s] as a member of [%s]\n",
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ldb_dn_get_linearized(msgs[0]->dn),
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_get_linearized(group_dn));
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek goto done;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek }
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek ret = EOK;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozekdone:
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek talloc_free(tmp_ctx);
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek return ret;
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek}
b4ffa4d19e912740af6df3c1a4fabcea69729885Jakub Hrozek
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozekerrno_t
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozekad_enumeration_recv(struct tevent_req *req)
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek{
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek return EOK;
74802794554e0f87d1354b6788f1719cd7d80a6cJakub Hrozek}
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina