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"
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek#include "providers/ldap/sdap_async.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
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozekstatic bool ad_account_can_shortcut(struct sdap_idmap_ctx *idmap_ctx,
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek struct sss_domain_info *domain,
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek int filter_type,
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek const char *filter_value)
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek{
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek struct sss_domain_info *dom_head = NULL;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek struct sss_domain_info *sid_dom = NULL;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek enum idmap_error_code err;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek char *sid = NULL;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek const char *csid = NULL;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek uint32_t id;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek bool shortcut = false;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek errno_t ret;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek if (!sdap_idmap_domain_has_algorithmic_mapping(idmap_ctx, domain->name,
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek domain->domain_id)) {
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek goto done;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek }
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek switch (filter_type) {
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek case BE_FILTER_IDNUM:
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek /* convert value to ID */
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek errno = 0;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek id = strtouint32(filter_value, NULL, 10);
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek if (errno != 0) {
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek ret = errno;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE, "Unable to convert filter value to "
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek "number [%d]: %s\n", ret, strerror(ret));
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek goto done;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek }
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek /* convert the ID to its SID equivalent */
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek err = sss_idmap_unix_to_sid(idmap_ctx->map, id, &sid);
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek if (err != IDMAP_SUCCESS) {
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE, "Mapping ID [%s] to SID failed: "
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek "[%s]\n", filter_value, idmap_error_string(err));
a406b52a0d20e0ec502f52d63dee293636d1443aSumit Bose /* assume id is from a different domain */
a406b52a0d20e0ec502f52d63dee293636d1443aSumit Bose shortcut = true;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek goto done;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek }
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek /* fall through */
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek SSS_ATTRIBUTE_FALLTHROUGH;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek case BE_FILTER_SECID:
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek csid = sid == NULL ? filter_value : sid;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek dom_head = get_domains_head(domain);
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek if (dom_head == NULL) {
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Cannot find domain head\n");
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek goto done;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek }
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek sid_dom = find_domain_by_sid(dom_head, csid);
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek if (sid_dom == NULL) {
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Invalid domain for SID:%s\n", csid);
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek goto done;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek }
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek if (strcasecmp(sid_dom->name, domain->name) != 0) {
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek shortcut = true;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek }
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek break;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek default:
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek break;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek }
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozekdone:
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek if (sid != NULL) {
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek sss_idmap_free_sid(idmap_ctx->map, sid);
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek }
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek return shortcut;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek}
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub 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;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek bool shortcut;
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
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek /* Try to shortcut if this is ID or SID search and it belongs to
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek * other domain range than is in ar->domain. */
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek shortcut = ad_account_can_shortcut(ctx->opts->idmap_ctx,
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek sdom->dom,
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek ar->filter_type,
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek ar->filter_value);
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek if (shortcut) {
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "This ID is from different domain\n");
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek ret = EOK;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek goto immediate;
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub Hrozek }
dfe05f505dcfea16e7d66ca1a44206aa2570e861Jakub 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 */
e6ad16e05f42a1678a8c6cd14eb54ca75b8d775eSumit Bose clist = ad_user_conn_list(mem_ctx, 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
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;
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
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
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstatic errno_t ad_get_account_domain_prepare_search(struct tevent_req *req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstatic errno_t ad_get_account_domain_connect_retry(struct tevent_req *req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstatic void ad_get_account_domain_connect_done(struct tevent_req *subreq);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstatic void ad_get_account_domain_posix_check_done(struct tevent_req *subreq);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstatic void ad_get_account_domain_search(struct tevent_req *req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstatic void ad_get_account_domain_search_done(struct tevent_req *subreq);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstatic void ad_get_account_domain_evaluate(struct tevent_req *req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstruct ad_get_account_domain_state {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct tevent_context *ev;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_id_ctx *id_ctx;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct sdap_id_ctx *sdap_id_ctx;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct sdap_domain *sdom;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek uint32_t entry_type;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek uint32_t filter_type;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek char *clean_filter;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek bool twopass;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct sdap_search_base **search_bases;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek size_t base_iter;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek const char *base_filter;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek char *filter;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek const char **attrs;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek int dp_error;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct dp_reply_std reply;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct sdap_id_op *op;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct sysdb_attrs **objects;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek size_t count;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek const char *found_domain_name;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek};
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstruct tevent_req *
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekad_get_account_domain_send(TALLOC_CTX *mem_ctx,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_id_ctx *id_ctx,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct dp_get_acct_domain_data *data,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct dp_req_params *params)
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek{
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state *state;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct tevent_req *req;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek errno_t ret;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek bool use_id_mapping;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek req = tevent_req_create(mem_ctx, &state,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (req == NULL) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return NULL;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->ev = params->ev;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->id_ctx = id_ctx;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->sdap_id_ctx = id_ctx->sdap_id_ctx;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->entry_type = data->entry_type & BE_REQ_TYPE_MASK;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->filter_type = data->filter_type;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->attrs = talloc_array(state, const char *, 2);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (state->attrs == NULL) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ret = ENOMEM;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek goto immediately;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->attrs[0] = "objectclass";
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->attrs[1] = NULL;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (params->be_ctx->domain->mpg == true
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek || state->entry_type == BE_REQ_USER_AND_GROUP) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->twopass = true;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (state->entry_type == BE_REQ_USER_AND_GROUP) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->entry_type = BE_REQ_GROUP;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek /* The get-account-domain request only works with GC */
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (dp_opt_get_bool(id_ctx->ad_options->basic, AD_ENABLE_GC) == false) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_CONF_SETTINGS,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek "Global catalog support is not enabled, "
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek "cannot locate the account domain\n");
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ret = ERR_GET_ACCT_DOM_NOT_SUPPORTED;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek goto immediately;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->sdom = sdap_domain_get(id_ctx->sdap_id_ctx->opts,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek params->be_ctx->domain);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (state->sdom == NULL) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Cannot find sdap_domain\n");
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ret = EIO;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek goto immediately;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek /* Currently we only support locating the account domain
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek * if ID mapping is disabled. With ID mapping enabled, we can
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek * already shortcut the 'real' ID request
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek */
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek use_id_mapping = sdap_idmap_domain_has_algorithmic_mapping(
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->sdap_id_ctx->opts->idmap_ctx,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->sdom->dom->name,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->sdom->dom->domain_id);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (use_id_mapping == true) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_CONF_SETTINGS,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek "No point in locating domain with GC if ID-mapping "
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek "is enabled\n");
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ret = ERR_GET_ACCT_DOM_NOT_SUPPORTED;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek goto immediately;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ret = sss_filter_sanitize(state, data->filter_value, &state->clean_filter);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (ret != EOK) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek "Cannot sanitize filter [%d]: %s\n", ret, sss_strerror(ret));
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek goto immediately;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ret = ad_get_account_domain_prepare_search(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (ret != EOK) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek goto immediately;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek /* FIXME - should gc_ctx always default to ignore_offline on creation
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek * time rather than setting the flag on first use?
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek */
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek id_ctx->gc_ctx->ignore_mark_offline = true;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->op = sdap_id_op_create(state, id_ctx->gc_ctx->conn_cache);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (state->op == NULL) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "sdap_id_op_create failed\n");
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ret = ENOMEM;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek goto immediately;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ret = ad_get_account_domain_connect_retry(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (ret != EOK) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Connection error");
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek goto immediately;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return req;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekimmediately:
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek dp_reply_std_set(&state->reply, DP_ERR_DECIDE, ret, NULL);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek /* TODO For backward compatibility we always return EOK to DP now. */
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_done(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_post(req, params->ev);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return req;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek}
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstatic errno_t ad_get_account_domain_prepare_search(struct tevent_req *req)
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek{
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state *state = tevent_req_data(req,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek const char *attr_name = NULL;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek const char *objectclass = NULL;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek switch (state->entry_type) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek case BE_REQ_USER:
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->search_bases = state->sdom->user_search_bases;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek attr_name = state->sdap_id_ctx->opts->user_map[SDAP_AT_USER_UID].name;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek objectclass = state->sdap_id_ctx->opts->user_map[SDAP_OC_USER].name;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek break;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek case BE_REQ_GROUP:
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->search_bases = state->sdom->group_search_bases;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek attr_name = state->sdap_id_ctx->opts->group_map[SDAP_AT_GROUP_GID].name;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek objectclass = state->sdap_id_ctx->opts->group_map[SDAP_OC_GROUP].name;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek break;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek default:
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek "Unsupported request type %X\n",
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->entry_type & BE_REQ_TYPE_MASK);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return EINVAL;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek switch (state->filter_type) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek case BE_FILTER_IDNUM:
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek break;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek default:
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek "Unsupported filter type %X\n", state->filter_type);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return EINVAL;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek talloc_zfree(state->base_filter);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->base_filter = talloc_asprintf(state,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek "(&(%s=%s)(objectclass=%s))",
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek attr_name,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->clean_filter,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek objectclass);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (state->base_filter == NULL) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return ENOMEM;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return EOK;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek}
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstatic errno_t ad_get_account_domain_connect_retry(struct tevent_req *req)
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek{
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state *state = tevent_req_data(req,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct tevent_req *subreq;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek errno_t ret;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek subreq = sdap_id_op_connect_send(state->op, state, &ret);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (subreq == NULL) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return ENOMEM;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_set_callback(subreq, ad_get_account_domain_connect_done, req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return ret;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek}
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstatic void ad_get_account_domain_connect_done(struct tevent_req *subreq)
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek{
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct tevent_req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state *state = tevent_req_data(req,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek int dp_error = DP_ERR_FATAL;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek errno_t ret;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ret = sdap_id_op_connect_recv(subreq, &dp_error);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek talloc_zfree(subreq);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (ret != EOK) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->dp_error = dp_error;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_error(req, ret);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek /* If POSIX attributes have been requested with an AD server and we
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek * have no idea about POSIX attributes support, run a one-time check
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek */
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (state->sdap_id_ctx->srv_opts &&
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->sdap_id_ctx->srv_opts->posix_checked == false) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek subreq = sdap_gc_posix_check_send(state,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->ev,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->sdap_id_ctx->opts,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek sdap_id_op_handle(state->op),
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek dp_opt_get_int(
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->sdap_id_ctx->opts->basic,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek SDAP_SEARCH_TIMEOUT));
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (subreq == NULL) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_error(req, ENOMEM);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_set_callback(subreq, ad_get_account_domain_posix_check_done, req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ad_get_account_domain_search(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek}
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstatic void ad_get_account_domain_posix_check_done(struct tevent_req *subreq)
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek{
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct tevent_req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state *state = tevent_req_data(req,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek int dp_error = DP_ERR_FATAL;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek bool has_posix;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek errno_t ret;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek errno_t ret2;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ret = sdap_gc_posix_check_recv(subreq, &has_posix);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek talloc_zfree(subreq);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (ret != EOK) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek /* We can only finish the id_op on error as the connection
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek * is re-used by the real search
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek */
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ret2 = sdap_id_op_done(state->op, ret, &dp_error);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (dp_error == DP_ERR_OK && ret2 != EOK) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek /* retry */
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ret = ad_get_account_domain_connect_retry(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (ret != EOK) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_error(req, ret);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_error(req, ret);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->sdap_id_ctx->srv_opts->posix_checked = true;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek /*
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek * If the GC has no POSIX attributes, there is nothing we can do.
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek * Return an error and let the responders disable the functionality
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek * from now on.
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek */
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (has_posix == false) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_CONF_SETTINGS,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek "The Global Catalog has no POSIX attributes\n");
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek disable_gc(state->id_ctx->ad_options);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek dp_reply_std_set(&state->reply,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DP_ERR_DECIDE, ERR_GET_ACCT_DOM_NOT_SUPPORTED,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek NULL);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_done(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ad_get_account_domain_search(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek}
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstatic void ad_get_account_domain_search(struct tevent_req *req)
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek{
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state *state = tevent_req_data(req,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct tevent_req *subreq;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek talloc_zfree(state->filter);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->filter = sdap_combine_filters(state, state->base_filter,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->search_bases[state->base_iter]->filter);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (state->filter == NULL) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_error(req, ENOMEM);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek subreq = sdap_get_generic_send(state, state->ev, state->sdap_id_ctx->opts,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek sdap_id_op_handle(state->op),
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek "",
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek LDAP_SCOPE_SUBTREE,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->filter,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->attrs, NULL, 0,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek dp_opt_get_int(state->sdap_id_ctx->opts->basic,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek SDAP_SEARCH_TIMEOUT),
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek false);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (subreq == NULL) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "sdap_get_generic_send failed.\n");
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_error(req, EIO);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_set_callback(subreq, ad_get_account_domain_search_done, req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek}
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstatic void ad_get_account_domain_search_done(struct tevent_req *subreq)
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek{
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct tevent_req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state *state = tevent_req_data(req,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek size_t count;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct sysdb_attrs **objects;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek errno_t ret;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ret = sdap_get_generic_recv(subreq, state,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek &count, &objects);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek talloc_zfree(subreq);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (ret) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_error(req, ret);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek "Search returned %zu results.\n", count);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (count > 0) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek size_t copied;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->objects =
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek talloc_realloc(state,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->objects,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct sysdb_attrs *,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->count + count + 1);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (!state->objects) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_error(req, ENOMEM);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek copied = sdap_steal_objects_in_dom(state->sdap_id_ctx->opts,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->objects,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->count,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek NULL,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek objects, count,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek false);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->count += copied;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->objects[state->count] = NULL;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek /* Even though we search with an empty search base (=across all domains)
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek * the reason we iterate over search bases is that the search bases can
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek * also contain a filter which might restrict the IDs we find
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek */
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->base_iter++;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (state->search_bases[state->base_iter]) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek /* There are more search bases to try */
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ad_get_account_domain_search(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek /* No more searches, evaluate results */
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ad_get_account_domain_evaluate(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek}
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekstatic void ad_get_account_domain_evaluate(struct tevent_req *req)
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek{
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state *state = tevent_req_data(req,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct sss_domain_info *obj_dom;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek errno_t ret;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (state->count == 0) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (state->twopass
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek && state->entry_type != BE_REQ_USER) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "Retrying search\n");
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->entry_type = BE_REQ_USER;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->base_iter = 0;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ret = ad_get_account_domain_prepare_search(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (ret != EOK) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot retry search\n");
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_error(req, ret);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek ad_get_account_domain_search(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "Not found\n");
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek dp_reply_std_set(&state->reply, DP_ERR_DECIDE, ERR_NOT_FOUND, NULL);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_done(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek } else if (state->count > 1) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek /* FIXME: If more than one entry was found, return error for now
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek * as the account requsts have no way of returning multiple
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek * messages back until we switch to the rdp_* requests
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek * from the responder side
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek */
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Multiple entries found, error!\n");
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek dp_reply_std_set(&state->reply, DP_ERR_DECIDE, ERANGE, NULL);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_done(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek /* Exactly one entry was found */
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek obj_dom = sdap_get_object_domain(state->sdap_id_ctx->opts,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->objects[0],
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state->sdom->dom);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek if (obj_dom == NULL) {
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek "Could not match entry with domain!\n");
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek dp_reply_std_set(&state->reply, DP_ERR_DECIDE, ERR_NOT_FOUND, NULL);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_done(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek }
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek "Found object in domain %s\n", obj_dom->name);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek dp_reply_std_set(&state->reply, DP_ERR_DECIDE, EOK, obj_dom->name);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek tevent_req_done(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek}
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozekerrno_t ad_get_account_domain_recv(TALLOC_CTX *mem_ctx,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct tevent_req *req,
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct dp_reply_std *data)
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek{
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek struct ad_get_account_domain_state *state = NULL;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek state = tevent_req_data(req, struct ad_get_account_domain_state);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek *data = state->reply;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek return EOK;
095844d6b48aef483c33e5a369a405ae686e044dJakub Hrozek}