36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose/*
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose SSSD
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose IPA Helper routines - external users and groups with s2n plugin
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose Copyright (C) Sumit Bose <sbose@redhat.com> - 2011
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose This program is free software; you can redistribute it and/or modify
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose it under the terms of the GNU General Public License as published by
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose the Free Software Foundation; either version 3 of the License, or
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose (at your option) any later version.
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose This program is distributed in the hope that it will be useful,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose GNU General Public License for more details.
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose You should have received a copy of the GNU General Public License
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose*/
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose#include "util/util.h"
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose#include "util/sss_nss.h"
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose#include "util/strtonum.h"
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose#include "util/crypto/sss_crypto.h"
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose#include "providers/ldap/sdap_async_private.h"
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose#include "providers/ldap/sdap_async_ad.h"
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose#include "providers/ldap/ldap_common.h"
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose#include "providers/ldap/sdap_idmap.h"
5cd4414fce1e0eb4133dfc6fc828bf25c8a959f9Lukas Slebodnik#include "providers/ipa/ipa_id.h"
2962b3d1e072ff2ebbe343095812dad697d6bf1dSumit Bose#include "providers/ipa/ipa_subdomains.h"
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose#include "providers/ad/ad_pac.h"
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose#include "db/sysdb.h"
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Boseenum input_types {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose INP_SID = 1,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose INP_NAME,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose INP_POSIX_UID,
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose INP_POSIX_GID,
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose INP_CERT
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose};
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Boseenum request_types {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose REQ_SIMPLE = 1,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose REQ_FULL,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose REQ_FULL_WITH_MEMBERS
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose};
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Boseenum response_types {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose RESP_SID = 1,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose RESP_NAME,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose RESP_USER,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose RESP_GROUP,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose RESP_USER_GROUPLIST,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose RESP_GROUP_MEMBERS,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose RESP_NAME_LIST
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose};
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose/* ==Sid2Name Extended Operation============================================= */
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosestruct ipa_s2n_exop_state {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct sdap_handle *sh;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct sdap_op *op;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose char *retoid;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct berval *retdata;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose};
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosestatic void ipa_s2n_exop_done(struct sdap_op *op,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct sdap_msg *reply,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose int error, void *pvt);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosestatic struct tevent_req *ipa_s2n_exop_send(TALLOC_CTX *mem_ctx,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct tevent_context *ev,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct sdap_handle *sh,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose bool is_v1,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose int timeout,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct berval *bv)
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose{
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct tevent_req *req = NULL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct ipa_s2n_exop_state *state;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose int ret;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose int msgid;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose req = tevent_req_create(mem_ctx, &state, struct ipa_s2n_exop_state);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (!req) return NULL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose state->sh = sh;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose state->retoid = NULL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose state->retdata = NULL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Executing extended operation\n");
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = ldap_extended_operation(state->sh->ldap,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose is_v1 ? EXOP_SID2NAME_V1_OID : EXOP_SID2NAME_OID,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose bv, NULL, NULL, &msgid);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (ret == -1 || msgid == -1) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "ldap_extended_operation failed\n");
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce ret = ERR_NETWORK_IO;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto fail;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_TRACE_INTERNAL, "ldap_extended_operation sent, msgid = %d\n",
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose msgid);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = sdap_op_add(state, ev, state->sh, msgid, ipa_s2n_exop_done, req,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose timeout, &state->op);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to set up operation!\n");
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce ret = ERR_INTERNAL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto fail;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return req;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosefail:
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce tevent_req_error(req, ret);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose tevent_req_post(req, ev);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return req;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose}
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosestatic void ipa_s2n_exop_done(struct sdap_op *op,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct sdap_msg *reply,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose int error, void *pvt)
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose{
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct tevent_req *req = talloc_get_type(pvt, struct tevent_req);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct ipa_s2n_exop_state *state = tevent_req_data(req,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct ipa_s2n_exop_state);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose int ret;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose char *errmsg = NULL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose char *retoid = NULL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct berval *retdata = NULL;
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce int result;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (error) {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose tevent_req_error(req, error);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = ldap_parse_result(state->sh->ldap, reply->msg,
bc85b7e2b7b1569e64d8832c52cab9ad165e6fc1Sumit Bose &result, NULL, &errmsg, NULL,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose NULL, 0);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (ret != LDAP_SUCCESS) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldap_parse_result failed (%d)\n",
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose state->op->msgid);
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce ret = ERR_NETWORK_IO;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
bc85b7e2b7b1569e64d8832c52cab9ad165e6fc1Sumit Bose DEBUG(result == LDAP_SUCCESS ? SSSDBG_TRACE_FUNC : SSSDBG_OP_FAILURE,
bc85b7e2b7b1569e64d8832c52cab9ad165e6fc1Sumit Bose "ldap_extended_operation result: %s(%d), %s.\n",
bc85b7e2b7b1569e64d8832c52cab9ad165e6fc1Sumit Bose sss_ldap_err2string(result), result, errmsg);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce if (result != LDAP_SUCCESS) {
3e9712c2fdbba8f9cd25886943331e76e0b2ceddSumit Bose if (result == LDAP_NO_SUCH_OBJECT) {
3e9712c2fdbba8f9cd25886943331e76e0b2ceddSumit Bose ret = ENOENT;
3e9712c2fdbba8f9cd25886943331e76e0b2ceddSumit Bose } else {
3e9712c2fdbba8f9cd25886943331e76e0b2ceddSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldap_extended_operation failed, server " \
3e9712c2fdbba8f9cd25886943331e76e0b2ceddSumit Bose "logs might contain more details.\n");
3e9712c2fdbba8f9cd25886943331e76e0b2ceddSumit Bose ret = ERR_NETWORK_IO;
3e9712c2fdbba8f9cd25886943331e76e0b2ceddSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = ldap_parse_extended_result(state->sh->ldap, reply->msg,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose &retoid, &retdata, 0);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (ret != LDAP_SUCCESS) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldap_parse_extendend_result failed (%d)\n",
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret);
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce ret = ERR_NETWORK_IO;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
7ee9ac32485483beece872d6fcb3096fa77a004bSumit Bose if (retdata == NULL) {
7ee9ac32485483beece872d6fcb3096fa77a004bSumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Missing exop result data.\n");
7ee9ac32485483beece872d6fcb3096fa77a004bSumit Bose ret = EINVAL;
7ee9ac32485483beece872d6fcb3096fa77a004bSumit Bose goto done;
7ee9ac32485483beece872d6fcb3096fa77a004bSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose state->retoid = talloc_strdup(state, retoid);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (state->retoid == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = ENOMEM;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose state->retdata = talloc(state, struct berval);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (state->retdata == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "talloc failed.\n");
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = ENOMEM;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose state->retdata->bv_len = retdata->bv_len;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose state->retdata->bv_val = talloc_memdup(state->retdata, retdata->bv_val,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose retdata->bv_len);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (state->retdata->bv_val == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "talloc_memdup failed.\n");
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = ENOMEM;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = EOK;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosedone:
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ldap_memfree(errmsg);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ldap_memfree(retoid);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ber_bvfree(retdata);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (ret == EOK) {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose tevent_req_done(req);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose } else {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose tevent_req_error(req, ret);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose}
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosestatic int ipa_s2n_exop_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce char **retoid, struct berval **retdata)
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose{
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct ipa_s2n_exop_state *state = tevent_req_data(req,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct ipa_s2n_exop_state);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose TEVENT_REQ_RETURN_ON_ERROR(req);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce *retoid = talloc_steal(mem_ctx, state->retoid);
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce *retdata = talloc_steal(mem_ctx, state->retdata);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return EOK;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose}
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosestatic errno_t talloc_ber_flatten(TALLOC_CTX *mem_ctx, BerElement *ber,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct berval **_bv)
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose{
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose int ret;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct berval *bv = NULL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct berval *tbv = NULL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = ber_flatten(ber, &bv);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (ret == -1) {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = EFAULT;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose tbv = talloc_zero(mem_ctx, struct berval);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (tbv == NULL) {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = ENOMEM;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose tbv->bv_len = bv->bv_len;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose tbv->bv_val = talloc_memdup(tbv, bv->bv_val, bv->bv_len);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (tbv->bv_val == NULL) {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = ENOMEM;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = EOK;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosedone:
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ber_bvfree(bv);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (ret == EOK) {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose *_bv = tbv;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose } else {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose talloc_free(tbv);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return ret;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose}
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose/* The extended operation expect the following ASN.1 encoded request data:
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose *
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * ExtdomRequestValue ::= SEQUENCE {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * inputType ENUMERATED {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * sid (1),
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * name (2),
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * posix uid (3),
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * posix gid (3)
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * },
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * requestType ENUMERATED {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * simple (1),
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * full (2)
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * full_with_members (3)
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * },
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * data InputData
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose *
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * InputData ::= CHOICE {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * sid OCTET STRING,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * name NameDomainData
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * uid PosixUid,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * gid PosixGid
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose *
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * NameDomainData ::= SEQUENCE {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * domain_name OCTET STRING,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * object_name OCTET STRING
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose *
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * PosixUid ::= SEQUENCE {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * domain_name OCTET STRING,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * uid INTEGER
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose *
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * PosixGid ::= SEQUENCE {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * domain_name OCTET STRING,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * gid INTEGER
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose *
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose */
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosestatic errno_t s2n_encode_request(TALLOC_CTX *mem_ctx,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose const char *domain_name,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose int entry_type,
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose enum request_types request_type,
2962b3d1e072ff2ebbe343095812dad697d6bf1dSumit Bose struct req_input *req_input,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct berval **_bv)
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose{
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose BerElement *ber = NULL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose int ret;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ber = ber_alloc_t( LBER_USE_DER );
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (ber == NULL) {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return ENOMEM;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose switch (entry_type) {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose case BE_REQ_USER:
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose case BE_REQ_USER_AND_GROUP: /* the extdom exop does not care if the
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ID belongs to a user or a group */
2962b3d1e072ff2ebbe343095812dad697d6bf1dSumit Bose if (req_input->type == REQ_INP_NAME) {
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = ber_printf(ber, "{ee{ss}}", INP_NAME, request_type,
2962b3d1e072ff2ebbe343095812dad697d6bf1dSumit Bose domain_name,
2962b3d1e072ff2ebbe343095812dad697d6bf1dSumit Bose req_input->inp.name);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose } else if (req_input->type == REQ_INP_ID) {
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = ber_printf(ber, "{ee{si}}", INP_POSIX_UID, request_type,
2962b3d1e072ff2ebbe343095812dad697d6bf1dSumit Bose domain_name,
2962b3d1e072ff2ebbe343095812dad697d6bf1dSumit Bose req_input->inp.id);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose } else {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Unexpected input type [%d].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov req_input->type == REQ_INP_ID);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = EINVAL;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose break;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose case BE_REQ_GROUP:
2962b3d1e072ff2ebbe343095812dad697d6bf1dSumit Bose if (req_input->type == REQ_INP_NAME) {
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = ber_printf(ber, "{ee{ss}}", INP_NAME, request_type,
2962b3d1e072ff2ebbe343095812dad697d6bf1dSumit Bose domain_name,
2962b3d1e072ff2ebbe343095812dad697d6bf1dSumit Bose req_input->inp.name);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose } else if (req_input->type == REQ_INP_ID) {
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = ber_printf(ber, "{ee{si}}", INP_POSIX_GID, request_type,
2962b3d1e072ff2ebbe343095812dad697d6bf1dSumit Bose domain_name,
2962b3d1e072ff2ebbe343095812dad697d6bf1dSumit Bose req_input->inp.id);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose } else {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Unexpected input type [%d].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov req_input->type == REQ_INP_ID);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = EINVAL;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose break;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose case BE_REQ_BY_SECID:
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (req_input->type == REQ_INP_SECID) {
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose ret = ber_printf(ber, "{ees}", INP_SID, request_type,
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose req_input->inp.secid);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose } else {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Unexpected input type [%d].\n",
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose req_input->type == REQ_INP_ID);
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose ret = EINVAL;
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose goto done;
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose }
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose break;
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose case BE_REQ_BY_CERT:
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose if (req_input->type == REQ_INP_CERT) {
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose ret = ber_printf(ber, "{ees}", INP_CERT, request_type,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose req_input->inp.cert);
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose } else {
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "Unexpected input type [%d].\n",
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose req_input->type);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = EINVAL;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose break;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose default:
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = EINVAL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (ret == -1) {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = EFAULT;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = talloc_ber_flatten(mem_ctx, ber, _bv);
210e57203a1502f78a16b05010d52c9121b644e3Lukas Slebodnik if (ret != EOK) {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = EOK;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosedone:
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ber_free(ber, 1);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return ret;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose}
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose/* If the extendend operation is successful it returns the following ASN.1
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * encoded response:
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose *
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * ExtdomResponseValue ::= SEQUENCE {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * responseType ENUMERATED {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * sid (1),
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * name (2),
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * posix_user (3),
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * posix_group (4),
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * posix_user_grouplist (5),
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * posix_group_members (6)
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * },
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * data OutputData
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose *
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * OutputData ::= CHOICE {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * sid OCTET STRING,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * name NameDomainData,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * user PosixUser,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * group PosixGroup,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * usergrouplist PosixUserGrouplist,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * groupmembers PosixGroupMembers
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose *
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose *
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * NameDomainData ::= SEQUENCE {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * domain_name OCTET STRING,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * object_name OCTET STRING
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose *
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * PosixUser ::= SEQUENCE {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * domain_name OCTET STRING,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * user_name OCTET STRING,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * uid INTEGER
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * gid INTEGER
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose *
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * PosixGroup ::= SEQUENCE {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * domain_name OCTET STRING,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * group_name OCTET STRING,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * gid INTEGER
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose * }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose *
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * PosixUserGrouplist ::= SEQUENCE {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * domain_name OCTET STRING,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * user_name OCTET STRING,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * uid INTEGER,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * gid INTEGER,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * gecos OCTET STRING,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * home_directory OCTET STRING,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * shell OCTET STRING,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * grouplist GroupNameList
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose *
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * GroupNameList ::= SEQUENCE OF OCTET STRING
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose *
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * PosixGroupMembers ::= SEQUENCE {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * domain_name OCTET STRING,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * group_name OCTET STRING,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * gid INTEGER,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * members GroupMemberList
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose *
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose * GroupMemberList ::= SEQUENCE OF OCTET STRING
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose */
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bosestruct name_list {
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose char *domain_name;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose char *name;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose};
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosestruct resp_attrs {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose enum response_types response_type;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose char *domain_name;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose union {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct passwd user;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct group group;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose char *sid_str;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose char *name;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose } a;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose size_t ngroups;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose char **groups;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct sysdb_attrs *sysdb_attrs;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose char **name_list;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose};
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bosestatic errno_t get_extra_attrs(BerElement *ber, struct resp_attrs *resp_attrs)
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose{
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ber_tag_t tag;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ber_len_t ber_len;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose char *ber_cookie;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose char *name;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct berval **values;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct ldb_val v;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose int ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose size_t c;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (resp_attrs->sysdb_attrs == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose resp_attrs->sysdb_attrs = sysdb_new_attrs(resp_attrs);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (resp_attrs->sysdb_attrs == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_new_attrs failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return ENOMEM;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "Found new sequence.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose for (tag = ber_first_element(ber, &ber_len, &ber_cookie);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tag != LBER_DEFAULT;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tag = ber_next_element(ber, &ber_len, ber_cookie)) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tag = ber_scanf(ber, "{a{V}}", &name, &values);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (tag == LBER_ERROR) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ber_scanf failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return EINVAL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "Extra attribute [%s].\n", name);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose for (c = 0; values[c] != NULL; c++) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose if (strcmp(name, SYSDB_USER_CERT) == 0) {
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose if (values[c]->bv_val[values[c]->bv_len] != '\0') {
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose "base64 encoded certificate not 0-terminated.\n");
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose return EINVAL;
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose }
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose v.data = sss_base64_decode(NULL, values[c]->bv_val, &v.length);
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose if (v.data == NULL) {
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_base64_decode failed.\n");
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose return EINVAL;
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose }
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose } else {
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose v.data = (uint8_t *)values[c]->bv_val;
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose v.length = values[c]->bv_len;
cf89f552f06b95bd69d8c61aaa55a330a5d9f6e6Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = sysdb_attrs_add_val(resp_attrs->sysdb_attrs, name, &v);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_add_val failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ldap_memfree(name);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ber_bvecfree(values);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ldap_memfree(name);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ber_bvecfree(values);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return EOK;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose}
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozekstatic errno_t add_v1_user_data(struct sss_domain_info *dom,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek BerElement *ber,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek struct resp_attrs *attrs)
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose{
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ber_tag_t tag;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ber_len_t ber_len;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose int ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose char *gecos = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose char *homedir = NULL;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek char *name = NULL;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek char *domain = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose char *shell = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose char **list = NULL;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek size_t c, gc;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek struct sss_domain_info *parent_domain;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek struct sss_domain_info *obj_domain;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tag = ber_scanf(ber, "aaa", &gecos, &homedir, &shell);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (tag == LBER_ERROR) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ber_scanf failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = EINVAL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (gecos == NULL || *gecos == '\0') {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose attrs->a.user.pw_gecos = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose } else {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose attrs->a.user.pw_gecos = talloc_strdup(attrs, gecos);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (attrs->a.user.pw_gecos == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = ENOMEM;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (homedir == NULL || *homedir == '\0') {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose attrs->a.user.pw_dir = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose } else {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose attrs->a.user.pw_dir = talloc_strdup(attrs, homedir);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (attrs->a.user.pw_dir == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = ENOMEM;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (shell == NULL || *shell == '\0') {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose attrs->a.user.pw_shell = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose } else {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose attrs->a.user.pw_shell = talloc_strdup(attrs, shell);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (attrs->a.user.pw_shell == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = ENOMEM;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tag = ber_scanf(ber, "{v}", &list);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (tag == LBER_ERROR) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ber_scanf failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = EINVAL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose for (attrs->ngroups = 0; list[attrs->ngroups] != NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose attrs->ngroups++);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (attrs->ngroups > 0) {
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose attrs->groups = talloc_zero_array(attrs, char *, attrs->ngroups + 1);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (attrs->groups == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_array failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = ENOMEM;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek parent_domain = get_domains_head(dom);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek for (c = 0, gc = 0; c < attrs->ngroups; c++) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek ret = sss_parse_name(attrs, dom->names, list[c],
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek &domain, &name);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek if (ret != EOK) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek "Cannot parse member %s\n", list[c]);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek continue;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek }
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek if (domain != NULL) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek obj_domain = find_domain_by_name(parent_domain, domain, true);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek if (obj_domain == NULL) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "find_domain_by_name failed.\n");
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek return ENOMEM;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek }
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek } else {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek obj_domain = parent_domain;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek }
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek attrs->groups[gc] = sss_create_internal_fqname(attrs->groups,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek name, obj_domain->name);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek if (attrs->groups[gc] == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = ENOMEM;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek gc++;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tag = ber_peek_tag(ber, &ber_len);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "BER tag is [%d]\n", (int) tag);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (tag == LBER_SEQUENCE) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = get_extra_attrs(ber, attrs);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "get_extra_attrs failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = EOK;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bosedone:
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ber_memfree(gecos);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ber_memfree(homedir);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ber_memfree(shell);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ber_memvfree((void **) list);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose}
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozekstatic errno_t add_v1_group_data(BerElement *ber,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek struct sss_domain_info *dom,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek struct resp_attrs *attrs)
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose{
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ber_tag_t tag;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ber_len_t ber_len;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose int ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose char **list = NULL;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek size_t c, mc;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek char *name = NULL;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek char *domain = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tag = ber_scanf(ber, "{v}", &list);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (tag == LBER_ERROR) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ber_scanf failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = EINVAL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
abee3216261e3378430e472f0c992470b33976f0Sumit Bose if (list != NULL) {
abee3216261e3378430e472f0c992470b33976f0Sumit Bose for (attrs->ngroups = 0; list[attrs->ngroups] != NULL;
abee3216261e3378430e472f0c992470b33976f0Sumit Bose attrs->ngroups++);
abee3216261e3378430e472f0c992470b33976f0Sumit Bose
abee3216261e3378430e472f0c992470b33976f0Sumit Bose if (attrs->ngroups > 0) {
abee3216261e3378430e472f0c992470b33976f0Sumit Bose attrs->a.group.gr_mem = talloc_zero_array(attrs, char *,
abee3216261e3378430e472f0c992470b33976f0Sumit Bose attrs->ngroups + 1);
abee3216261e3378430e472f0c992470b33976f0Sumit Bose if (attrs->a.group.gr_mem == NULL) {
abee3216261e3378430e472f0c992470b33976f0Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_array failed.\n");
abee3216261e3378430e472f0c992470b33976f0Sumit Bose ret = ENOMEM;
abee3216261e3378430e472f0c992470b33976f0Sumit Bose goto done;
abee3216261e3378430e472f0c992470b33976f0Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek for (c = 0, mc=0; c < attrs->ngroups; c++) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek ret = sss_parse_name(attrs, dom->names, list[c],
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek &domain, &name);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek if (ret != EOK) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek "Cannot parse member %s\n", list[c]);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek continue;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek }
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek if (domain == NULL) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek domain = dom->name;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek }
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek attrs->a.group.gr_mem[mc] =
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek sss_create_internal_fqname(attrs->a.group.gr_mem,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek name, domain);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek if (attrs->a.group.gr_mem[mc] == NULL) {
abee3216261e3378430e472f0c992470b33976f0Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
abee3216261e3378430e472f0c992470b33976f0Sumit Bose ret = ENOMEM;
abee3216261e3378430e472f0c992470b33976f0Sumit Bose goto done;
abee3216261e3378430e472f0c992470b33976f0Sumit Bose }
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek mc++;
abee3216261e3378430e472f0c992470b33976f0Sumit Bose }
abee3216261e3378430e472f0c992470b33976f0Sumit Bose }
abee3216261e3378430e472f0c992470b33976f0Sumit Bose } else {
abee3216261e3378430e472f0c992470b33976f0Sumit Bose attrs->a.group.gr_mem = talloc_zero_array(attrs, char *, 1);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (attrs->a.group.gr_mem == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_array failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = ENOMEM;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tag = ber_peek_tag(ber, &ber_len);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "BER tag is [%d]\n", (int) tag);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (tag == LBER_SEQUENCE) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = get_extra_attrs(ber, attrs);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "get_extra_attrs failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = EOK;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bosedone:
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ber_memvfree((void **) list);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose}
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bosestatic errno_t ipa_s2n_save_objects(struct sss_domain_info *dom,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct req_input *req_input,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct resp_attrs *attrs,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose struct resp_attrs *simple_attrs,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose const char *view_name,
cffe3135f29c737f2598f3c1384bfba1694fb843Sumit Bose struct sysdb_attrs *override_attrs,
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose struct sysdb_attrs *mapped_attrs,
cffe3135f29c737f2598f3c1384bfba1694fb843Sumit Bose bool update_initgr_timeout);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosestatic errno_t s2n_response_to_attrs(TALLOC_CTX *mem_ctx,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek struct sss_domain_info *dom,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose char *retoid,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct berval *retdata,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct resp_attrs **resp_attrs)
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose{
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose BerElement *ber = NULL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ber_tag_t tag;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose int ret;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose enum response_types type;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose char *domain_name = NULL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose char *name = NULL;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek char *lc_name = NULL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose uid_t uid;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose gid_t gid;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct resp_attrs *attrs = NULL;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose char *sid_str;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose bool is_v1 = false;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose char **name_list = NULL;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose ber_len_t ber_len;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose char *fq_name = NULL;
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose struct sss_domain_info *root_domain = NULL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (retoid == NULL || retdata == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Missing OID or data.\n");
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return EINVAL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (strcmp(retoid, EXOP_SID2NAME_V1_OID) == 0) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose is_v1 = true;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose } else if (strcmp(retoid, EXOP_SID2NAME_OID) == 0) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose is_v1 = false;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose } else {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose DEBUG(SSSDBG_OP_FAILURE,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose "Result has wrong OID, expected [%s] or [%s], got [%s].\n",
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose EXOP_SID2NAME_OID, EXOP_SID2NAME_V1_OID, retoid);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return EINVAL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ber = ber_init(retdata);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (ber == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "ber_init failed.\n");
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return EINVAL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose tag = ber_scanf(ber, "{e", &type);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (tag == LBER_ERROR) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "ber_scanf failed.\n");
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = EINVAL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose attrs = talloc_zero(mem_ctx, struct resp_attrs);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (attrs == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "talloc_zero failed.\n");
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = ENOMEM;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose switch (type) {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose case RESP_USER:
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose case RESP_USER_GROUPLIST:
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tag = ber_scanf(ber, "{aaii", &domain_name, &name, &uid, &gid);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (tag == LBER_ERROR) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "ber_scanf failed.\n");
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = EINVAL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
ac7a7ee3d1e138818a1ed78758f7dd3c3306a56bSumit Bose /* Winbind is not consistent with the case of the returned user
ac7a7ee3d1e138818a1ed78758f7dd3c3306a56bSumit Bose * name. In general all names should be lower case but there are
ac7a7ee3d1e138818a1ed78758f7dd3c3306a56bSumit Bose * bug in some version of winbind which might lead to upper case
ac7a7ee3d1e138818a1ed78758f7dd3c3306a56bSumit Bose * letters in the name. To be on the safe side we explicitly
ac7a7ee3d1e138818a1ed78758f7dd3c3306a56bSumit Bose * lowercase the name. */
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek lc_name = sss_tc_utf8_str_tolower(attrs, name);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek if (lc_name == NULL) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek ret = ENOMEM;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek goto done;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek }
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek attrs->a.user.pw_name = sss_create_internal_fqname(attrs,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek lc_name,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek domain_name);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek talloc_free(lc_name);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (attrs->a.user.pw_name == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = ENOMEM;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose attrs->a.user.pw_uid = uid;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose attrs->a.user.pw_gid = gid;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
2fc12875f7d51248799016c19c1298b85e06a286Sumit Bose if (is_v1 && type == RESP_USER_GROUPLIST) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek ret = add_v1_user_data(dom, ber, attrs);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "add_v1_user_data failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tag = ber_scanf(ber, "}}");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (tag == LBER_ERROR) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ber_scanf failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = EINVAL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose break;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose case RESP_GROUP:
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose case RESP_GROUP_MEMBERS:
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tag = ber_scanf(ber, "{aai", &domain_name, &name, &gid);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (tag == LBER_ERROR) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "ber_scanf failed.\n");
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = EINVAL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose /* Winbind is not consistent with the case of the returned user
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose * name. In general all names should be lower case but there are
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose * bug in some version of winbind which might lead to upper case
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose * letters in the name. To be on the safe side we explicitly
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose * lowercase the name. */
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek lc_name = sss_tc_utf8_str_tolower(attrs, name);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek if (lc_name == NULL) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek ret = ENOMEM;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek goto done;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek }
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek attrs->a.group.gr_name = sss_create_internal_fqname(attrs,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek lc_name,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek domain_name);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek talloc_free(lc_name);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (attrs->a.group.gr_name == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = ENOMEM;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose attrs->a.group.gr_gid = gid;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
2fc12875f7d51248799016c19c1298b85e06a286Sumit Bose if (is_v1 && type == RESP_GROUP_MEMBERS) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek ret = add_v1_group_data(ber, dom, attrs);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "add_v1_group_data failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tag = ber_scanf(ber, "}}");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (tag == LBER_ERROR) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ber_scanf failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = EINVAL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose break;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose case RESP_SID:
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose tag = ber_scanf(ber, "a}", &sid_str);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (tag == LBER_ERROR) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "ber_scanf failed.\n");
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = EINVAL;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose attrs->a.sid_str = talloc_strdup(attrs, sid_str);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (attrs->a.sid_str == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = ENOMEM;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose break;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose case RESP_NAME:
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose tag = ber_scanf(ber, "{aa}", &domain_name, &name);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (tag == LBER_ERROR) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "ber_scanf failed.\n");
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = EINVAL;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose attrs->a.name = sss_tc_utf8_str_tolower(attrs, name);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (attrs->a.name == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sss_tc_utf8_str_tolower failed.\n");
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = ENOMEM;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose break;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose case RESP_NAME_LIST:
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose tag = ber_scanf(ber, "{");
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose if (tag == LBER_ERROR) {
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ber_scanf failed.\n");
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose ret = EINVAL;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose goto done;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose }
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose root_domain = get_domains_head(dom);
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose while (ber_peek_tag(ber, &ber_len) == LBER_SEQUENCE) {
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose tag = ber_scanf(ber, "{aa}", &domain_name, &name);
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose if (tag == LBER_ERROR) {
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ber_scanf failed.\n");
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose ret = EINVAL;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose goto done;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose }
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose fq_name = sss_create_internal_fqname(attrs, name, domain_name);
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose if (fq_name == NULL) {
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose "sss_create_internal_fqname failed.\n");
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose ret = ENOMEM;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose goto done;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose }
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "[%s][%s][%s].\n", domain_name, name,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose fq_name);
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose if (strcasecmp(root_domain->name, domain_name) != 0) {
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose ret = add_string_to_list(attrs, fq_name, &name_list);
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose } else {
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose DEBUG(SSSDBG_TRACE_ALL,
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose "[%s] from root domain, skipping.\n", fq_name);
3e3034199b44e01899ec7ba8152fef3738a0e093Jakub Hrozek ret = EOK; /* Free resources and continue in the loop */
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose }
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose ber_memfree(domain_name);
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose ber_memfree(name);
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose talloc_free(fq_name);
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose domain_name = NULL;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose name = NULL;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose fq_name = NULL;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose if (ret != EOK) {
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "add_to_name_list failed.\n");
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose goto done;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose }
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose }
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose tag = ber_scanf(ber, "}}");
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose if (tag == LBER_ERROR) {
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ber_scanf failed.\n");
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose ret = EINVAL;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose goto done;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose }
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose attrs->name_list = name_list;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose break;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose default:
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Unexpected response type [%d].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov type);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = EINVAL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose attrs->response_type = type;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose if (type != RESP_SID && type != RESP_NAME_LIST) {
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose attrs->domain_name = talloc_strdup(attrs, domain_name);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (attrs->domain_name == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = ENOMEM;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = EOK;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosedone:
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ber_memfree(domain_name);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ber_memfree(name);
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose talloc_free(fq_name);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ber_free(ber, 1);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (ret == EOK) {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose *resp_attrs = attrs;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose } else {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose talloc_free(attrs);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return ret;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose}
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephensonstatic const char *ipa_s2n_reqtype2str(enum request_types request_type)
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephenson{
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephenson switch (request_type) {
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephenson case REQ_SIMPLE:
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephenson return "REQ_SIMPLE";
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephenson case REQ_FULL:
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephenson return "REQ_FULL";
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephenson case REQ_FULL_WITH_MEMBERS:
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephenson return "REQ_FULL_WITH_MEMBERS";
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephenson default:
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephenson break;
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephenson }
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephenson
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephenson return "Unknown request type";
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephenson}
a04bef313508c423ed06cc54805a3b8106ab90cdJustin Stephenson
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březinastatic const char *ipa_s2n_reqinp2str(TALLOC_CTX *mem_ctx,
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina struct req_input *req_input)
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina{
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina const char *str = NULL;
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina switch (req_input->type) {
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina case REQ_INP_NAME:
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina str = talloc_strdup(mem_ctx, req_input->inp.name);
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina break;
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina case REQ_INP_SECID:
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina str = talloc_strdup(mem_ctx, req_input->inp.secid);
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina break;
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina case REQ_INP_CERT:
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina str = talloc_strdup(mem_ctx, req_input->inp.cert);
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina break;
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina case REQ_INP_ID:
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina str = talloc_asprintf(mem_ctx, "%u", req_input->inp.id);
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina break;
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina }
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina if (str == NULL) {
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory!\n");
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina }
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina return str;
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina}
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bosestruct ipa_s2n_get_list_state {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct tevent_context *ev;
00c283ca719717ed483958571982d0e9ff95c4b1Sumit Bose struct ipa_id_ctx *ipa_ctx;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct sss_domain_info *dom;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct sdap_handle *sh;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct req_input req_input;
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose char **list;
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose size_t list_idx;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose int exop_timeout;
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose int entry_type;
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose enum request_types request_type;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose struct resp_attrs *attrs;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose struct sss_domain_info *obj_domain;
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose struct sysdb_attrs *override_attrs;
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose struct sysdb_attrs *mapped_attrs;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose};
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bosestatic errno_t ipa_s2n_get_list_step(struct tevent_req *req);
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bosestatic void ipa_s2n_get_list_get_override_done(struct tevent_req *subreq);
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bosestatic void ipa_s2n_get_list_next(struct tevent_req *subreq);
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bosestatic errno_t ipa_s2n_get_list_save_step(struct tevent_req *req);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bosestatic struct tevent_req *ipa_s2n_get_list_send(TALLOC_CTX *mem_ctx,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose struct tevent_context *ev,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose struct ipa_id_ctx *ipa_ctx,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose struct sss_domain_info *dom,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose struct sdap_handle *sh,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose int exop_timeout,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose int entry_type,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose enum request_types request_type,
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose enum req_input_type list_type,
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose char **list,
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose struct sysdb_attrs *mapped_attrs)
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose{
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose int ret;
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose struct ipa_s2n_get_list_state *state;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct tevent_req *req;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose req = tevent_req_create(mem_ctx, &state, struct ipa_s2n_get_list_state);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (req == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose if ((entry_type == BE_REQ_BY_SECID && list_type != REQ_INP_SECID)
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose || (entry_type != BE_REQ_BY_SECID && list_type == REQ_INP_SECID)) {
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose DEBUG(SSSDBG_OP_FAILURE, "Invalid parameter combination [%d][%d].\n",
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose request_type, list_type);
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose ret = EINVAL;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose goto done;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose }
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose state->ev = ev;
00c283ca719717ed483958571982d0e9ff95c4b1Sumit Bose state->ipa_ctx = ipa_ctx;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose state->dom = dom;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose state->sh = sh;
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose state->list = list;
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose state->list_idx = 0;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose state->req_input.type = list_type;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose state->req_input.inp.name = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose state->exop_timeout = exop_timeout;
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose state->entry_type = entry_type;
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose state->request_type = request_type;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose state->attrs = NULL;
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose state->override_attrs = NULL;
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose state->mapped_attrs = mapped_attrs;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose ret = ipa_s2n_get_list_step(req);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_s2n_get_list_step failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bosedone:
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tevent_req_error(req, ret);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tevent_req_post(req, ev);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return req;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose}
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bosestatic errno_t ipa_s2n_get_list_step(struct tevent_req *req)
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose{
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose int ret;
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose struct ipa_s2n_get_list_state *state = tevent_req_data(req,
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose struct ipa_s2n_get_list_state);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct berval *bv_req;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct tevent_req *subreq;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct sss_domain_info *parent_domain;
f1f22df95996390f63266ebacb624e521d934592Sumit Bose char *short_name = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose char *domain_name = NULL;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose uint32_t id;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose char *endptr;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose bool need_v1 = false;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose parent_domain = get_domains_head(state->dom);
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose switch (state->req_input.type) {
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose case REQ_INP_NAME:
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek ret = sss_parse_name(state, state->dom->names, state->list[state->list_idx],
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose &domain_name, &short_name);
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose if (ret != EOK) {
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse name '%s' [%d]: %s\n",
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose state->list[state->list_idx],
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose ret, sss_strerror(ret));
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose return ret;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose }
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose if (domain_name) {
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose state->obj_domain = find_domain_by_name(parent_domain,
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose domain_name, true);
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose if (state->obj_domain == NULL) {
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose DEBUG(SSSDBG_OP_FAILURE, "find_domain_by_name failed.\n");
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose return ENOMEM;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose }
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose } else {
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose state->obj_domain = parent_domain;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose }
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose state->req_input.inp.name = short_name;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose break;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose case REQ_INP_ID:
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose errno = 0;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose id = strtouint32(state->list[state->list_idx], &endptr, 10);
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose if (errno != 0 || *endptr != '\0'
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose || (state->list[state->list_idx] == endptr)) {
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose DEBUG(SSSDBG_OP_FAILURE, "strtouint32 failed.\n");
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose return EINVAL;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose }
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose state->req_input.inp.id = id;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose state->obj_domain = state->dom;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose break;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose case REQ_INP_SECID:
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose state->req_input.inp.secid = state->list[state->list_idx];
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose state->obj_domain = find_domain_by_sid(parent_domain,
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose state->req_input.inp.secid);
1b2a9e3f17e54bcbe5c9bee82a91ae694b7ea0ebJakub Hrozek if (state->obj_domain == NULL) {
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose DEBUG(SSSDBG_OP_FAILURE,
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose "find_domain_by_sid failed for SID [%s].\n",
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose state->req_input.inp.secid);
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose return EINVAL;
1b2a9e3f17e54bcbe5c9bee82a91ae694b7ea0ebJakub Hrozek }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose break;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose default:
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "Unexpected input type [%d].\n",
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose state->req_input.type);
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose return EINVAL;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose ret = s2n_encode_request(state, state->obj_domain->name, state->entry_type,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose state->request_type,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose &state->req_input, &bv_req);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "s2n_encode_request failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose if (state->request_type == REQ_FULL_WITH_MEMBERS) {
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose need_v1 = true;
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose }
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson if (state->req_input.type == REQ_INP_NAME
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson && state->req_input.inp.name != NULL) {
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose DEBUG(SSSDBG_TRACE_FUNC,
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose "Sending request_type: [%s] for object [%s].\n",
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose ipa_s2n_reqtype2str(state->request_type),
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose state->list[state->list_idx]);
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson }
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose subreq = ipa_s2n_exop_send(state, state->ev, state->sh, need_v1,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose state->exop_timeout, bv_req);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (subreq == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_s2n_exop_send failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return ENOMEM;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose tevent_req_set_callback(subreq, ipa_s2n_get_list_next, req);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return EOK;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose}
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bosestatic void ipa_s2n_get_list_next(struct tevent_req *subreq)
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose{
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose int ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct tevent_req *req = tevent_req_callback_data(subreq,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct tevent_req);
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose struct ipa_s2n_get_list_state *state = tevent_req_data(req,
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose struct ipa_s2n_get_list_state);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose char *retoid = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct berval *retdata = NULL;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose const char *sid_str;
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = ipa_s2n_exop_recv(subreq, state, &retoid, &retdata);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose talloc_zfree(subreq);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "s2n exop request failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto fail;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose talloc_zfree(state->attrs);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek ret = s2n_response_to_attrs(state, state->dom, retoid, retdata,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek &state->attrs);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "s2n_response_to_attrs failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto fail;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson DEBUG(SSSDBG_TRACE_FUNC, "Received [%s] attributes from IPA server.\n",
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson state->attrs->a.name);
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson
9ac2a33f4cdc4941fa63118dcffe8058854f33c4Michal Židek if (is_default_view(state->ipa_ctx->view_name)) {
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose ret = ipa_s2n_get_list_save_step(req);
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose if (ret == EOK) {
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose tevent_req_done(req);
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose } else if (ret != EAGAIN) {
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_s2n_get_list_save_step failed.\n");
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose goto fail;
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose }
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose return;
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose }
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = sysdb_attrs_get_string(state->attrs->sysdb_attrs, SYSDB_SID_STR,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose &sid_str);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (ret != EOK) {
ef019268d2d112ebff3577e551cd19478d73d93bJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
ef019268d2d112ebff3577e551cd19478d73d93bJakub Hrozek "Object [%s] has no SID, please check the "
ef019268d2d112ebff3577e551cd19478d73d93bJakub Hrozek "ipaNTSecurityIdentifier attribute on the server-side",
ef019268d2d112ebff3577e551cd19478d73d93bJakub Hrozek state->attrs->a.name);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto fail;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
3d29430867cf92b2d71afa95abb679711231117cPavel Březina ret = get_dp_id_data_for_sid(state, sid_str, state->obj_domain->name, &ar);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose if (ret != EOK) {
3d29430867cf92b2d71afa95abb679711231117cPavel Březina DEBUG(SSSDBG_OP_FAILURE, "get_dp_id_data_for_sid failed.\n");
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose goto fail;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose }
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose subreq = ipa_get_ad_override_send(state, state->ev,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose state->ipa_ctx->sdap_id_ctx,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose state->ipa_ctx->ipa_options,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose dp_opt_get_string(state->ipa_ctx->ipa_options->basic,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose IPA_KRB5_REALM),
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose state->ipa_ctx->view_name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ar);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (subreq == NULL) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_get_ad_override_send failed.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = ENOMEM;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto fail;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose tevent_req_set_callback(subreq, ipa_s2n_get_list_get_override_done, req);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose return;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bosefail:
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose tevent_req_error(req,ret);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose return;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose}
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bosestatic void ipa_s2n_get_list_get_override_done(struct tevent_req *subreq)
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose{
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose int ret;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose struct tevent_req *req = tevent_req_callback_data(subreq,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose struct tevent_req);
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose struct ipa_s2n_get_list_state *state = tevent_req_data(req,
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose struct ipa_s2n_get_list_state);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose ret = ipa_get_ad_override_recv(subreq, NULL, state, &state->override_attrs);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose talloc_zfree(subreq);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (ret != EOK) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "IPA override lookup failed: %d\n", ret);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto fail;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose ret = ipa_s2n_get_list_save_step(req);
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose if (ret == EOK) {
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose tevent_req_done(req);
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose } else if (ret != EAGAIN) {
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_s2n_get_list_save_step failed.\n");
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose goto fail;
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose }
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose return;
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bosefail:
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose tevent_req_error(req,ret);
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose return;
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose}
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bosestatic errno_t ipa_s2n_get_list_save_step(struct tevent_req *req)
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose{
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose int ret;
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose struct ipa_s2n_get_list_state *state = tevent_req_data(req,
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose struct ipa_s2n_get_list_state);
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = ipa_s2n_save_objects(state->dom, &state->req_input, state->attrs,
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose NULL, state->ipa_ctx->view_name,
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose state->override_attrs, state->mapped_attrs,
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose false);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_s2n_save_objects failed.\n");
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose return ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose state->list_idx++;
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose if (state->list[state->list_idx] == NULL) {
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose return EOK;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose ret = ipa_s2n_get_list_step(req);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_s2n_get_list_step failed.\n");
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose return ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose return EAGAIN;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose}
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bosestatic int ipa_s2n_get_list_recv(struct tevent_req *req)
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose{
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose TEVENT_REQ_RETURN_ON_ERROR(req);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return EOK;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose}
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosestruct ipa_s2n_get_user_state {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct tevent_context *ev;
00c283ca719717ed483958571982d0e9ff95c4b1Sumit Bose struct ipa_id_ctx *ipa_ctx;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct sdap_options *opts;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct sss_domain_info *dom;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct sdap_handle *sh;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose struct req_input *req_input;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose int entry_type;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose enum request_types request_type;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose struct resp_attrs *attrs;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct resp_attrs *simple_attrs;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose struct sysdb_attrs *override_attrs;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose struct sysdb_attrs *mapped_attrs;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose int exop_timeout;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose};
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosestatic void ipa_s2n_get_user_done(struct tevent_req *subreq);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosestruct tevent_req *ipa_s2n_get_acct_info_send(TALLOC_CTX *mem_ctx,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose struct tevent_context *ev,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose struct ipa_id_ctx *ipa_ctx,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose struct sdap_options *opts,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose struct sss_domain_info *dom,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose struct sysdb_attrs *override_attrs,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose struct sdap_handle *sh,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose int entry_type,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose struct req_input *req_input)
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose{
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct ipa_s2n_get_user_state *state;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct tevent_req *req;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct tevent_req *subreq;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct berval *bv_req = NULL;
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina const char *input;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose int ret = EFAULT;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose bool is_v1 = false;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose req = tevent_req_create(mem_ctx, &state, struct ipa_s2n_get_user_state);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (req == NULL) {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return NULL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose state->ev = ev;
00c283ca719717ed483958571982d0e9ff95c4b1Sumit Bose state->ipa_ctx = ipa_ctx;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose state->opts = opts;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose state->dom = dom;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose state->sh = sh;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose state->req_input = req_input;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose state->entry_type = entry_type;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose state->attrs = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose state->simple_attrs = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose state->exop_timeout = dp_opt_get_int(opts->basic, SDAP_SEARCH_TIMEOUT);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose state->override_attrs = override_attrs;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (sdap_is_extension_supported(sh, EXOP_SID2NAME_V1_OID)) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose state->request_type = REQ_FULL_WITH_MEMBERS;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose is_v1 = true;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose } else if (sdap_is_extension_supported(sh, EXOP_SID2NAME_OID)) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose state->request_type = REQ_FULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose is_v1 = false;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose } else {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Extdom not supported on the server, "
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose "cannot resolve objects from trusted domains.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = EIO;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto fail;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose if (entry_type == BE_REQ_BY_CERT) {
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose /* Only REQ_SIMPLE is supported for BE_REQ_BY_CERT */
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose state->request_type = REQ_SIMPLE;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose }
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = s2n_encode_request(state, dom->name, entry_type, state->request_type,
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose req_input, &bv_req);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (ret != EOK) {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto fail;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina if (DEBUG_IS_SET(SSSDBG_TRACE_FUNC)) {
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina input = ipa_s2n_reqinp2str(state, req_input);
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina DEBUG(SSSDBG_TRACE_FUNC,
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina "Sending request_type: [%s] for trust user [%s] to IPA server\n",
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina ipa_s2n_reqtype2str(state->request_type),
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina input);
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina talloc_zfree(input);
b07bcd8b99590bd404733fa7ff1add37c55126bcPavel Březina }
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose subreq = ipa_s2n_exop_send(state, state->ev, state->sh, is_v1,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose state->exop_timeout, bv_req);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (subreq == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "ipa_s2n_exop_send failed.\n");
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = ENOMEM;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto fail;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose tevent_req_set_callback(subreq, ipa_s2n_get_user_done, req);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return req;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosefail:
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose tevent_req_error(req, ret);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose tevent_req_post(req, ev);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return req;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose}
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bosestatic errno_t process_members(struct sss_domain_info *domain,
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose bool is_default_view,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct sysdb_attrs *group_attrs,
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose char **members,
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose TALLOC_CTX *mem_ctx, char ***_missing_members)
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose{
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose int ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose size_t c;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose TALLOC_CTX *tmp_ctx;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct ldb_message *msg;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose const char *dn_str;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct sss_domain_info *obj_domain;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct sss_domain_info *parent_domain;
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose char **missing_members = NULL;
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose size_t miss_count = 0;
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose const char *attrs[] = {SYSDB_NAME, SYSDB_OVERRIDE_DN, NULL};
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
35863245aa8b8404caedfc95e68b3aa5af14542eJakub Hrozek if (members == NULL) {
35863245aa8b8404caedfc95e68b3aa5af14542eJakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL, "No members\n");
abb093b4ae10f2a5748bf9f194bf76794002eba0Sumit Bose if (_missing_members != NULL) {
abb093b4ae10f2a5748bf9f194bf76794002eba0Sumit Bose *_missing_members = NULL;
abb093b4ae10f2a5748bf9f194bf76794002eba0Sumit Bose }
35863245aa8b8404caedfc95e68b3aa5af14542eJakub Hrozek return EOK;
35863245aa8b8404caedfc95e68b3aa5af14542eJakub Hrozek }
35863245aa8b8404caedfc95e68b3aa5af14542eJakub Hrozek
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tmp_ctx = talloc_new(NULL);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (tmp_ctx == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return ENOMEM;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose if (_missing_members != NULL && mem_ctx != NULL) {
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose /* count members */
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose for (c = 0; members[c] != NULL; c++);
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose missing_members = talloc_zero_array(tmp_ctx, char *, c + 1);
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose if (missing_members == NULL) {
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_array_zero failed.\n");
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose ret = ENOMEM;
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose goto done;
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose }
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose }
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose parent_domain = get_domains_head(domain);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose for (c = 0; members[c] != NULL; c++) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose obj_domain = find_domain_by_object_name(parent_domain, members[c]);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (obj_domain == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "find_domain_by_object_name failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = ENOMEM;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose ret = sysdb_search_user_by_name(tmp_ctx, obj_domain, members[c], attrs,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose &msg);
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose if (ret == EOK || ret == ENOENT) {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose if (ret == ENOENT
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose || (!is_default_view
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose && ldb_msg_find_attr_as_string(msg, SYSDB_OVERRIDE_DN,
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose NULL) == NULL)) {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose /* only add ghost if the member is really missing */
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose if (group_attrs != NULL && ret == ENOENT) {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "Adding ghost member [%s]\n",
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose members[c]);
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose /* There were cases where the server returned the same user
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose * multiple times */
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose ret = sysdb_attrs_add_string_safe(group_attrs, SYSDB_GHOST,
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose members[c]);
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose if (ret != EOK) {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose "sysdb_attrs_add_string failed.\n");
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose goto done;
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose }
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose if (missing_members != NULL) {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose missing_members[miss_count] = talloc_strdup(missing_members,
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose members[c]);
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose if (missing_members[miss_count] == NULL) {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose ret = ENOMEM;
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose goto done;
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose }
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose miss_count++;
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose }
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose } else {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose if (group_attrs != NULL) {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose dn_str = ldb_dn_get_linearized(msg->dn);
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose if (dn_str == NULL) {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_get_linearized failed.\n");
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose ret = EINVAL;
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose goto done;
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose }
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "Adding member [%s][%s]\n",
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose members[c], dn_str);
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose ret = sysdb_attrs_add_string_safe(group_attrs, SYSDB_MEMBER,
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose dn_str);
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose if (ret != EOK) {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose "sysdb_attrs_add_string_safe failed.\n");
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose goto done;
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose }
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose } else {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_user_by_name failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose if (_missing_members != NULL) {
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose if (miss_count == 0) {
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose *_missing_members = NULL;
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose } else {
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose if (mem_ctx != NULL) {
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose *_missing_members = talloc_steal(mem_ctx, missing_members);
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose } else {
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose "Missing memory context for missing members list.\n");
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose ret = EINVAL;
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose goto done;
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose }
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose }
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose }
942ebb62c8df766a22271103abd518ddae02ea3aSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = EOK;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bosedone:
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose talloc_free(tmp_ctx);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose}
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bosestatic errno_t get_group_dn_list(TALLOC_CTX *mem_ctx,
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose bool is_default_view,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct sss_domain_info *dom,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose size_t ngroups, char **groups,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct ldb_dn ***_dn_list,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose char ***_missing_groups)
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose{
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose int ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose size_t c;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose TALLOC_CTX *tmp_ctx;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct ldb_dn **dn_list = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose char **missing_groups = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct ldb_message *msg = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose size_t n_dns = 0;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose size_t n_missing = 0;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct sss_domain_info *obj_domain;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct sss_domain_info *parent_domain;
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose const char *attrs[] = {SYSDB_NAME, SYSDB_OVERRIDE_DN, NULL};
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tmp_ctx = talloc_new(NULL);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (tmp_ctx == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return ENOMEM;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose dn_list = talloc_zero_array(tmp_ctx, struct ldb_dn *, ngroups + 1);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose missing_groups = talloc_zero_array(tmp_ctx, char *, ngroups + 1);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (dn_list == NULL || missing_groups == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_array_zero failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = ENOMEM;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose parent_domain = (dom->parent == NULL) ? dom : dom->parent;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose for (c = 0; c < ngroups; c++) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose obj_domain = find_domain_by_object_name(parent_domain, groups[c]);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (obj_domain == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "find_domain_by_object_name failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = ENOMEM;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose ret = sysdb_search_group_by_name(tmp_ctx, obj_domain, groups[c], attrs,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose &msg);
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose if (ret == EOK || ret == ENOENT) {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose if (ret == ENOENT
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose || (!is_default_view
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose && ldb_msg_find_attr_as_string(msg, SYSDB_OVERRIDE_DN,
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose NULL) == NULL)) {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose missing_groups[n_missing] = talloc_strdup(missing_groups,
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose groups[c]);
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose if (missing_groups[n_missing] == NULL) {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose ret = ENOMEM;
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose goto done;
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose }
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose n_missing++;
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose } else {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose dn_list[n_dns] = ldb_dn_copy(dn_list, msg->dn);
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose if (dn_list[n_dns] == NULL) {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_copy failed.\n");
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose ret = ENOMEM;
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose goto done;
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose }
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose n_dns++;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose } else {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_group_by_name failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (n_missing != 0) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose *_missing_groups = talloc_steal(mem_ctx, missing_groups);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose } else {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose *_missing_groups = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (n_dns != 0) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose *_dn_list = talloc_steal(mem_ctx, dn_list);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose } else {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose *dn_list = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = EOK;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bosedone:
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose talloc_free(tmp_ctx);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose}
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bosestatic void ipa_s2n_get_list_done(struct tevent_req *subreq);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bosestatic void ipa_s2n_get_user_get_override_done(struct tevent_req *subreq);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosestatic void ipa_s2n_get_user_done(struct tevent_req *subreq)
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose{
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct tevent_req *req = tevent_req_callback_data(subreq,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct tevent_req);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct ipa_s2n_get_user_state *state = tevent_req_data(req,
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct ipa_s2n_get_user_state);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose int ret;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose char *retoid = NULL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose struct berval *retdata = NULL;
9f37bb2012faa136ef7c1f9fe93689ce2be85637Ondrej Kos struct resp_attrs *attrs = NULL;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose struct berval *bv_req = NULL;
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose char **missing_list = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct ldb_dn **group_dn_list = NULL;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose const char *sid_str;
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce ret = ipa_s2n_exop_recv(subreq, state, &retoid, &retdata);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose talloc_zfree(subreq);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "s2n exop request failed.\n");
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose if (state->req_input->type == REQ_INP_CERT) {
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose "Maybe the server does not support lookups by "
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose "certificates.\n");
21513e51a4a2eb08f245333bf8f223713a3d7cb3Sumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose switch (state->request_type) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose case REQ_FULL_WITH_MEMBERS:
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose case REQ_FULL:
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek ret = s2n_response_to_attrs(state, state->dom, retoid, retdata,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek &attrs);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "s2n_response_to_attrs failed.\n");
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (!(strcasecmp(state->dom->name, attrs->domain_name) == 0 ||
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose (state->dom->flat_name != NULL &&
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose strcasecmp(state->dom->flat_name, attrs->domain_name) == 0))) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Unexpected domain name returned, "
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose "expected [%s] or [%s], got [%s].\n",
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose state->dom->name,
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose state->dom->flat_name == NULL ? "" :
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose state->dom->flat_name,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov attrs->domain_name);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = EINVAL;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose state->attrs = attrs;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (attrs->response_type == RESP_USER_GROUPLIST) {
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson if (DEBUG_IS_SET(SSSDBG_TRACE_FUNC)) {
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson size_t c;
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson DEBUG(SSSDBG_TRACE_FUNC, "Received [%zu] groups in group list "
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson "from IPA Server\n", attrs->ngroups);
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson for (c = 0; c < attrs->ngroups; c++) {
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson DEBUG(SSSDBG_TRACE_FUNC, "[%s].\n", attrs->groups[c]);
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson }
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson }
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson
cd83aead3c9799ac05d8f8977dbb92bbd399c6d5Justin Stephenson
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose ret = get_group_dn_list(state,
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose is_default_view(state->ipa_ctx->view_name),
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose state->dom,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose attrs->ngroups, attrs->groups,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose &group_dn_list, &missing_list);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "get_group_dn_list failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose if (missing_list != NULL) {
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose subreq = ipa_s2n_get_list_send(state, state->ev,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose state->ipa_ctx, state->dom,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose state->sh, state->exop_timeout,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose BE_REQ_GROUP,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose REQ_FULL_WITH_MEMBERS,
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose REQ_INP_NAME,
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose missing_list, NULL);
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose if (subreq == NULL) {
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose DEBUG(SSSDBG_OP_FAILURE,
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose "ipa_s2n_get_list_send failed.\n");
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose ret = ENOMEM;
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose goto done;
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose }
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose tevent_req_set_callback(subreq, ipa_s2n_get_list_done,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose req);
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose return;
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose }
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose break;
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose } else if (attrs->response_type == RESP_GROUP_MEMBERS) {
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose ret = process_members(state->dom,
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose is_default_view(state->ipa_ctx->view_name),
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose NULL, attrs->a.group.gr_mem, state,
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose &missing_list);
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose if (ret != EOK) {
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose DEBUG(SSSDBG_OP_FAILURE, "process_members failed.\n");
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose goto done;
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose }
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose if (missing_list != NULL) {
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose subreq = ipa_s2n_get_list_send(state, state->ev,
00c283ca719717ed483958571982d0e9ff95c4b1Sumit Bose state->ipa_ctx, state->dom,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose state->sh, state->exop_timeout,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose BE_REQ_USER,
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose REQ_FULL_WITH_MEMBERS,
1df6751f81f7d9c225463f76b9789b0cc7a0de8bSumit Bose REQ_INP_NAME,
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose missing_list, NULL);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (subreq == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose "ipa_s2n_get_list_send failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = ENOMEM;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose tevent_req_set_callback(subreq, ipa_s2n_get_list_done,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose req);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
e6046d23b3e90102fb3c796737ced03fb5a60feaSumit Bose break;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
3cd287313d93e29f9754feb46017dba2a039affdSumit Bose if (state->req_input->type == REQ_INP_SECID) {
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose /* We already know the SID, we do not have to read it. */
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose break;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose state->request_type = REQ_SIMPLE;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = s2n_encode_request(state, state->dom->name, state->entry_type,
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose state->request_type, state->req_input,
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose &bv_req);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (ret != EOK) {
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose subreq = ipa_s2n_exop_send(state, state->ev, state->sh, false,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose state->exop_timeout, bv_req);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (subreq == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "ipa_s2n_exop_send failed.\n");
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = ENOMEM;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose tevent_req_set_callback(subreq, ipa_s2n_get_user_done, req);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose return;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose case REQ_SIMPLE:
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek ret = s2n_response_to_attrs(state, state->dom, retoid, retdata,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose &state->simple_attrs);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "s2n_response_to_attrs failed.\n");
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose if (state->simple_attrs->response_type == RESP_NAME_LIST
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose && state->req_input->type == REQ_INP_CERT) {
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose if (state->simple_attrs->name_list == NULL) {
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose /* No results from sub-domains, nothing to do */
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose ret = EOK;
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose goto done;
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose }
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose state->mapped_attrs = sysdb_new_attrs(state);
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose if (state->mapped_attrs == NULL) {
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_new_attrs failed.\n");
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose ret = ENOMEM;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose goto done;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose }
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose ret = sysdb_attrs_add_base64_blob(state->mapped_attrs,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose SYSDB_USER_MAPPED_CERT,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose state->req_input->inp.cert);
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose if (ret != EOK) {
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_add_base64_blob failed.\n");
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose goto done;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose }
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose subreq = ipa_s2n_get_list_send(state, state->ev,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose state->ipa_ctx, state->dom,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose state->sh, state->exop_timeout,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose BE_REQ_USER,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose REQ_FULL_WITH_MEMBERS,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose REQ_INP_NAME,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose state->simple_attrs->name_list,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose state->mapped_attrs);
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose if (subreq == NULL) {
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose "ipa_s2n_get_list_send failed.\n");
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose ret = ENOMEM;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose goto done;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose }
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose tevent_req_set_callback(subreq, ipa_s2n_get_list_done,
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose req);
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose return;
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose }
2cf7becc05996eb6d8a3352d3d7b97c75652e590Sumit Bose
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose break;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose default:
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Unexpected request type.\n");
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose ret = EINVAL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (state->attrs == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Missing data of full request.\n");
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = EINVAL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (state->simple_attrs != NULL
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose && state->simple_attrs->response_type == RESP_SID) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose sid_str = state->simple_attrs->a.sid_str;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = EOK;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose } else if (state->attrs->sysdb_attrs != NULL) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = sysdb_attrs_get_string(state->attrs->sysdb_attrs, SYSDB_SID_STR,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose &sid_str);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose } else if (state->req_input->type == REQ_INP_SECID) {
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose sid_str = state->req_input->inp.secid;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ret = EOK;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose } else {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_TRACE_FUNC, "No SID available.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = ENOENT;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
9ac2a33f4cdc4941fa63118dcffe8058854f33c4Michal Židek if (ret == ENOENT || is_default_view(state->ipa_ctx->view_name)) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = ipa_s2n_save_objects(state->dom, state->req_input, state->attrs,
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose state->simple_attrs, NULL, NULL, NULL, true);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (ret != EOK) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_s2n_save_objects failed.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto done;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose } else if (ret == EOK) {
3d29430867cf92b2d71afa95abb679711231117cPavel Březina ret = get_dp_id_data_for_sid(state, sid_str, state->dom->name, &ar);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose if (ret != EOK) {
3d29430867cf92b2d71afa95abb679711231117cPavel Březina DEBUG(SSSDBG_OP_FAILURE, "get_dp_id_data_for_sid failed.\n");
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose goto done;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose }
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose subreq = ipa_get_ad_override_send(state, state->ev,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose state->ipa_ctx->sdap_id_ctx,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose state->ipa_ctx->ipa_options,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose dp_opt_get_string(state->ipa_ctx->ipa_options->basic,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose IPA_KRB5_REALM),
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose state->ipa_ctx->view_name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ar);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (subreq == NULL) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_get_ad_override_send failed.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = ENOMEM;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto done;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose tevent_req_set_callback(subreq, ipa_s2n_get_user_get_override_done,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose req);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose return;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose } else {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_get_string failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bosedone:
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret == EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tevent_req_done(req);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose } else {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tevent_req_error(req, ret);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose}
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bosestatic errno_t get_groups_dns(TALLOC_CTX *mem_ctx, struct sss_domain_info *dom,
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose char **name_list, char ***_dn_list)
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose{
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose int ret;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose TALLOC_CTX *tmp_ctx;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose int c;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose struct sss_domain_info *root_domain;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose char **dn_list;
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose struct ldb_message *msg;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose if (name_list == NULL) {
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose *_dn_list = NULL;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose return EOK;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose /* To handle cross-domain memberships we have to check the domain for
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose * each group the member should be added or deleted. Since sub-domains
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose * use fully-qualified names by default any short name can only belong
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose * to the root/head domain. find_domain_by_object_name() will return
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose * the domain given in the first argument if the second argument is a
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose * a short name hence we always use root_domain as first argument. */
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose root_domain = get_domains_head(dom);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose if (root_domain->fqnames) {
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose DEBUG(SSSDBG_TRACE_FUNC,
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose "Root domain uses fully-qualified names, " \
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose "objects might not be correctly added to groups with " \
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose "short names.\n");
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose tmp_ctx = talloc_new(NULL);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose if (tmp_ctx == NULL) {
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose return ENOMEM;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose for (c = 0; name_list[c] != NULL; c++);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose dn_list = talloc_zero_array(tmp_ctx, char *, c + 1);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose if (dn_list == NULL) {
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_zero_array failed.\n");
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose ret = ENOMEM;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose goto done;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose for (c = 0; name_list[c] != NULL; c++) {
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose dom = find_domain_by_object_name(root_domain, name_list[c]);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose if (dom == NULL) {
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose "Cannot find domain for [%s].\n", name_list[c]);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose ret = ENOENT;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose goto done;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose /* If the group name is overridden in the default view we have to
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose * search for the name and cannot construct it because the extdom
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose * plugin will return the overridden name but the DN of the related
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose * group object in the cache will contain the original name. */
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose ret = sysdb_search_group_by_name(tmp_ctx, dom, name_list[c], NULL,
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose &msg);
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose if (ret == EOK) {
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose dn_list[c] = ldb_dn_alloc_linearized(dn_list, msg->dn);
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose } else {
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose /* best effort, try to construct the DN */
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose DEBUG(SSSDBG_TRACE_FUNC,
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose "sysdb_search_group_by_name failed with [%d], "
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose "generating DN for [%s] in domain [%s].\n",
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose ret, name_list[c], dom->name);
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose dn_list[c] = sysdb_group_strdn(dn_list, dom->name, name_list[c]);
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose if (dn_list[c] == NULL) {
f29040342a6d69e170f4543662621f2e27221f91Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_alloc_linearized failed.\n");
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose ret = ENOMEM;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose goto done;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
3fe2e555edd3963d72483600e5d9616873afd00aSumit Bose
3fe2e555edd3963d72483600e5d9616873afd00aSumit Bose DEBUG(SSSDBG_TRACE_ALL, "Added [%s][%s].\n", name_list[c], dn_list[c]);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose *_dn_list = talloc_steal(mem_ctx, dn_list);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose ret = EOK;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bosedone:
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose talloc_free(tmp_ctx);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose return ret;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose}
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
9a310913d696d190db14c625080678db853a33fdSumit Bosestatic errno_t add_emails_to_aliases(struct sysdb_attrs *attrs,
9a310913d696d190db14c625080678db853a33fdSumit Bose struct sss_domain_info *dom)
9a310913d696d190db14c625080678db853a33fdSumit Bose{
9a310913d696d190db14c625080678db853a33fdSumit Bose int ret;
9a310913d696d190db14c625080678db853a33fdSumit Bose const char **emails;
9a310913d696d190db14c625080678db853a33fdSumit Bose size_t c;
9a310913d696d190db14c625080678db853a33fdSumit Bose TALLOC_CTX *tmp_ctx;
9a310913d696d190db14c625080678db853a33fdSumit Bose
9a310913d696d190db14c625080678db853a33fdSumit Bose tmp_ctx = talloc_new(NULL);
9a310913d696d190db14c625080678db853a33fdSumit Bose if (tmp_ctx == NULL) {
9a310913d696d190db14c625080678db853a33fdSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
9a310913d696d190db14c625080678db853a33fdSumit Bose return ENOMEM;
9a310913d696d190db14c625080678db853a33fdSumit Bose }
9a310913d696d190db14c625080678db853a33fdSumit Bose
9a310913d696d190db14c625080678db853a33fdSumit Bose ret = sysdb_attrs_get_string_array(attrs, SYSDB_USER_EMAIL, tmp_ctx,
9a310913d696d190db14c625080678db853a33fdSumit Bose &emails);
9a310913d696d190db14c625080678db853a33fdSumit Bose if (ret == EOK) {
9a310913d696d190db14c625080678db853a33fdSumit Bose for (c = 0; emails[c] != NULL; c++) {
9a310913d696d190db14c625080678db853a33fdSumit Bose if (is_email_from_domain(emails[c], dom)) {
9a310913d696d190db14c625080678db853a33fdSumit Bose ret = sysdb_attrs_add_lc_name_alias_safe(attrs, emails[c]);
9a310913d696d190db14c625080678db853a33fdSumit Bose if (ret != EOK) {
9a310913d696d190db14c625080678db853a33fdSumit Bose DEBUG(SSSDBG_OP_FAILURE,
9a310913d696d190db14c625080678db853a33fdSumit Bose "Failed to add lower-cased version of email [%s] "
9a310913d696d190db14c625080678db853a33fdSumit Bose "into the alias list\n", emails[c]);
9a310913d696d190db14c625080678db853a33fdSumit Bose goto done;
9a310913d696d190db14c625080678db853a33fdSumit Bose }
9a310913d696d190db14c625080678db853a33fdSumit Bose }
9a310913d696d190db14c625080678db853a33fdSumit Bose }
9a310913d696d190db14c625080678db853a33fdSumit Bose } else if (ret == ENOENT) {
9a310913d696d190db14c625080678db853a33fdSumit Bose DEBUG(SSSDBG_TRACE_ALL, "No email addresses available.\n");
9a310913d696d190db14c625080678db853a33fdSumit Bose } else {
9a310913d696d190db14c625080678db853a33fdSumit Bose DEBUG(SSSDBG_OP_FAILURE,
9a310913d696d190db14c625080678db853a33fdSumit Bose "sysdb_attrs_get_string_array failed, skipping ...\n");
9a310913d696d190db14c625080678db853a33fdSumit Bose }
9a310913d696d190db14c625080678db853a33fdSumit Bose
9a310913d696d190db14c625080678db853a33fdSumit Bose ret = EOK;
9a310913d696d190db14c625080678db853a33fdSumit Bose
9a310913d696d190db14c625080678db853a33fdSumit Bosedone:
9a310913d696d190db14c625080678db853a33fdSumit Bose talloc_free(tmp_ctx);
9a310913d696d190db14c625080678db853a33fdSumit Bose
9a310913d696d190db14c625080678db853a33fdSumit Bose return ret;
9a310913d696d190db14c625080678db853a33fdSumit Bose}
9a310913d696d190db14c625080678db853a33fdSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bosestatic errno_t ipa_s2n_save_objects(struct sss_domain_info *dom,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct req_input *req_input,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct resp_attrs *attrs,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose struct resp_attrs *simple_attrs,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose const char *view_name,
cffe3135f29c737f2598f3c1384bfba1694fb843Sumit Bose struct sysdb_attrs *override_attrs,
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose struct sysdb_attrs *mapped_attrs,
cffe3135f29c737f2598f3c1384bfba1694fb843Sumit Bose bool update_initgr_timeout)
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose{
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose int ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose time_t now;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct sss_nss_homedir_ctx homedir_ctx;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose char *name = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose char *realm;
0302e3e7b3b06b809bd63c7911a42ab3e0a7ebf9Jakub Hrozek char *short_name = NULL;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose char *upn = NULL;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose gid_t gid;
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose gid_t orig_gid = 0;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose TALLOC_CTX *tmp_ctx;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose const char *sid_str;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose const char *tmp_str;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose struct ldb_result *res;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose enum sysdb_member_type type;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose char **sysdb_grouplist;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose char **add_groups_dns;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose char **del_groups_dns;
a52226c651308a0a7732544b492eb4db56b84f1dSumit Bose char **groups_dns;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose bool in_transaction = false;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose int tret;
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose struct sysdb_attrs *gid_override_attrs = NULL;
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek struct ldb_message *msg;
9a2f018c0f68a3ada4cea4128a861a7f85893f22Sumit Bose struct ldb_message_element *el = NULL;
43003851129556acea15539a1dc0d4350d54cac8Sumit Bose
56f015ef6a161e01681f79e4ea0d1b642f9737b4Fabiano Fidêncio /* The list of elements that might be missing are:
56f015ef6a161e01681f79e4ea0d1b642f9737b4Fabiano Fidêncio * - SYSDB_ORIG_MEMBEROF
56f015ef6a161e01681f79e4ea0d1b642f9737b4Fabiano Fidêncio * - SYSDB_SSH_PUBKEY
43003851129556acea15539a1dc0d4350d54cac8Sumit Bose * - SYSDB_USER_CERT
56f015ef6a161e01681f79e4ea0d1b642f9737b4Fabiano Fidêncio * Note that the list includes the trailing NULL at the end. */
56f015ef6a161e01681f79e4ea0d1b642f9737b4Fabiano Fidêncio size_t missing_count = 0;
43003851129556acea15539a1dc0d4350d54cac8Sumit Bose const char *missing[] = {NULL, NULL, NULL, NULL};
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tmp_ctx = talloc_new(NULL);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (tmp_ctx == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return ENOMEM;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose now = time(NULL);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (attrs->sysdb_attrs == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose attrs->sysdb_attrs = sysdb_new_attrs(attrs);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (attrs->sysdb_attrs == NULL) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_new_attrs failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = ENOMEM;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (attrs->sysdb_attrs != NULL) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = sysdb_attrs_get_string(attrs->sysdb_attrs,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ORIGINALAD_PREFIX SYSDB_NAME, &tmp_str);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (ret == EOK) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose name = talloc_strdup(tmp_ctx, tmp_str);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (name == NULL) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = ENOMEM;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto done;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_TRACE_ALL, "Found original AD name [%s].\n", name);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose } else if (ret == ENOENT) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose name = NULL;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose } else {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_get_string failed.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto done;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = sysdb_attrs_get_string(attrs->sysdb_attrs,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose SYSDB_DEFAULT_OVERRIDE_NAME, &tmp_str);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (ret == EOK) {
aedc71fe8360a51785933523f14bb5c4e7e2c38bSumit Bose ret = sysdb_attrs_add_lc_name_alias_safe(attrs->sysdb_attrs,
aedc71fe8360a51785933523f14bb5c4e7e2c38bSumit Bose tmp_str);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (ret != EOK) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE,
aedc71fe8360a51785933523f14bb5c4e7e2c38bSumit Bose "sysdb_attrs_add_lc_name_alias_safe failed.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto done;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose } else if (ret != ENOENT) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_get_string failed.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto done;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = sysdb_attrs_get_string(attrs->sysdb_attrs, SYSDB_UPN, &tmp_str);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (ret == EOK) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose upn = talloc_strdup(tmp_ctx, tmp_str);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (upn == NULL) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = ENOMEM;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto done;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_TRACE_ALL, "Found original AD upn [%s].\n", upn);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose } else if (ret == ENOENT) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose upn = NULL;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose } else {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_get_string failed.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto done;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
b2c5e98def89a0c3d16f5cf7e07ce2020338b540Jakub Hrozek if (strcmp(dom->name, attrs->domain_name) != 0) {
b2c5e98def89a0c3d16f5cf7e07ce2020338b540Jakub Hrozek dom = find_domain_by_name(get_domains_head(dom),
b2c5e98def89a0c3d16f5cf7e07ce2020338b540Jakub Hrozek attrs->domain_name, true);
b2c5e98def89a0c3d16f5cf7e07ce2020338b540Jakub Hrozek if (dom == NULL) {
b2c5e98def89a0c3d16f5cf7e07ce2020338b540Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
b2c5e98def89a0c3d16f5cf7e07ce2020338b540Jakub Hrozek "Cannot find domain: [%s]\n", attrs->domain_name);
b2c5e98def89a0c3d16f5cf7e07ce2020338b540Jakub Hrozek ret = EINVAL;
b2c5e98def89a0c3d16f5cf7e07ce2020338b540Jakub Hrozek goto done;
b2c5e98def89a0c3d16f5cf7e07ce2020338b540Jakub Hrozek }
b2c5e98def89a0c3d16f5cf7e07ce2020338b540Jakub Hrozek }
b2c5e98def89a0c3d16f5cf7e07ce2020338b540Jakub Hrozek
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose switch (attrs->response_type) {
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose case RESP_USER:
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose case RESP_USER_GROUPLIST:
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose type = SYSDB_MEMBER_USER;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (dom->subdomain_homedir
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose && attrs->a.user.pw_dir == NULL) {
5cd660aaa885bca95ac3dca660bb77e5786d5f8eLukas Slebodnik ZERO_STRUCT(homedir_ctx);
5cd660aaa885bca95ac3dca660bb77e5786d5f8eLukas Slebodnik homedir_ctx.username = attrs->a.user.pw_name;
5cd660aaa885bca95ac3dca660bb77e5786d5f8eLukas Slebodnik homedir_ctx.uid = attrs->a.user.pw_uid;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose homedir_ctx.domain = dom->name;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose homedir_ctx.flatname = dom->flat_name;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose homedir_ctx.config_homedir_substr = dom->homedir_substr;
5cd660aaa885bca95ac3dca660bb77e5786d5f8eLukas Slebodnik
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose attrs->a.user.pw_dir = expand_homedir_template(attrs,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose dom->subdomain_homedir,
accff8ebe158251b1d25a95b3b035fe7e08fd1eeJakub Hrozek dom->case_preserve,
5cd660aaa885bca95ac3dca660bb77e5786d5f8eLukas Slebodnik &homedir_ctx);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (attrs->a.user.pw_dir == NULL) {
4cf3bc3b94ccf1e60d29c0eb765f02cb49fbac2dSumit Bose ret = ENOMEM;
4cf3bc3b94ccf1e60d29c0eb765f02cb49fbac2dSumit Bose goto done;
4cf3bc3b94ccf1e60d29c0eb765f02cb49fbac2dSumit Bose }
4cf3bc3b94ccf1e60d29c0eb765f02cb49fbac2dSumit Bose }
4cf3bc3b94ccf1e60d29c0eb765f02cb49fbac2dSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (name == NULL) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek name = attrs->a.user.pw_name;
8d9e0547a864cee05ab36bc988300c0cfa986025Simo Sorce }
8d9e0547a864cee05ab36bc988300c0cfa986025Simo Sorce
aedc71fe8360a51785933523f14bb5c4e7e2c38bSumit Bose ret = sysdb_attrs_add_lc_name_alias_safe(attrs->sysdb_attrs, name);
8d9e0547a864cee05ab36bc988300c0cfa986025Simo Sorce if (ret != EOK) {
c9124effceb40890bc9dd157155618067a7b8d2fSumit Bose DEBUG(SSSDBG_OP_FAILURE,
aedc71fe8360a51785933523f14bb5c4e7e2c38bSumit Bose "sysdb_attrs_add_lc_name_alias_safe failed.\n");
8d9e0547a864cee05ab36bc988300c0cfa986025Simo Sorce goto done;
8d9e0547a864cee05ab36bc988300c0cfa986025Simo Sorce }
8d9e0547a864cee05ab36bc988300c0cfa986025Simo Sorce
9a310913d696d190db14c625080678db853a33fdSumit Bose ret = add_emails_to_aliases(attrs->sysdb_attrs, dom);
9a310913d696d190db14c625080678db853a33fdSumit Bose if (ret != EOK) {
9a310913d696d190db14c625080678db853a33fdSumit Bose DEBUG(SSSDBG_OP_FAILURE,
9a310913d696d190db14c625080678db853a33fdSumit Bose "add_emails_to_aliases failed, skipping ...\n");
9a310913d696d190db14c625080678db853a33fdSumit Bose }
9a310913d696d190db14c625080678db853a33fdSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (upn == NULL) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose /* We also have to store a fake UPN here, because otherwise the
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose * krb5 child later won't be able to properly construct one as
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose * the username is fully qualified but the child doesn't have
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose * access to the regex to deconstruct it */
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose /* FIXME: The real UPN is available from the PAC, we should get
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose * it from there. */
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose realm = get_uppercase_realm(tmp_ctx, dom->name);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (!realm) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "failed to get realm.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = ENOMEM;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto done;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
0302e3e7b3b06b809bd63c7911a42ab3e0a7ebf9Jakub Hrozek
0302e3e7b3b06b809bd63c7911a42ab3e0a7ebf9Jakub Hrozek ret = sss_parse_internal_fqname(tmp_ctx, attrs->a.user.pw_name,
0302e3e7b3b06b809bd63c7911a42ab3e0a7ebf9Jakub Hrozek &short_name, NULL);
0302e3e7b3b06b809bd63c7911a42ab3e0a7ebf9Jakub Hrozek if (ret != EOK) {
0302e3e7b3b06b809bd63c7911a42ab3e0a7ebf9Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
0302e3e7b3b06b809bd63c7911a42ab3e0a7ebf9Jakub Hrozek "Cannot parse internal name %s\n",
0302e3e7b3b06b809bd63c7911a42ab3e0a7ebf9Jakub Hrozek attrs->a.user.pw_name);
0302e3e7b3b06b809bd63c7911a42ab3e0a7ebf9Jakub Hrozek goto done;
0302e3e7b3b06b809bd63c7911a42ab3e0a7ebf9Jakub Hrozek }
0302e3e7b3b06b809bd63c7911a42ab3e0a7ebf9Jakub Hrozek
0302e3e7b3b06b809bd63c7911a42ab3e0a7ebf9Jakub Hrozek upn = talloc_asprintf(tmp_ctx, "%s@%s", short_name, realm);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (!upn) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "failed to format UPN.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = ENOMEM;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto done;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
8d9e0547a864cee05ab36bc988300c0cfa986025Simo Sorce
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose /* We might already have the SID or the UPN from other sources
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose * hence sysdb_attrs_add_string_safe is used to avoid double
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose * entries. */
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = sysdb_attrs_add_string_safe(attrs->sysdb_attrs, SYSDB_UPN,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose upn);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (ret != EOK) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose "sysdb_attrs_add_string failed.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto done;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
ac7a7ee3d1e138818a1ed78758f7dd3c3306a56bSumit Bose }
ac7a7ee3d1e138818a1ed78758f7dd3c3306a56bSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (req_input->type == REQ_INP_SECID) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = sysdb_attrs_add_string_safe(attrs->sysdb_attrs,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose SYSDB_SID_STR,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose req_input->inp.secid);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose "sysdb_attrs_add_string failed.\n");
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (simple_attrs != NULL
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose && simple_attrs->response_type == RESP_SID) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = sysdb_attrs_add_string_safe(attrs->sysdb_attrs,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose SYSDB_SID_STR,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose simple_attrs->a.sid_str);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose "sysdb_attrs_add_string failed.\n");
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
cffe3135f29c737f2598f3c1384bfba1694fb843Sumit Bose if (attrs->response_type == RESP_USER_GROUPLIST
cffe3135f29c737f2598f3c1384bfba1694fb843Sumit Bose && update_initgr_timeout) {
62d919aea98edd1095f6a22241903d4c045b46edSumit Bose /* Since RESP_USER_GROUPLIST contains all group memberships it
62d919aea98edd1095f6a22241903d4c045b46edSumit Bose * is effectively an initgroups request hence
62d919aea98edd1095f6a22241903d4c045b46edSumit Bose * SYSDB_INITGR_EXPIRE will be set.*/
62d919aea98edd1095f6a22241903d4c045b46edSumit Bose ret = sysdb_attrs_add_time_t(attrs->sysdb_attrs,
62d919aea98edd1095f6a22241903d4c045b46edSumit Bose SYSDB_INITGR_EXPIRE,
acce97e8d97e81a9e660d46c4e3c00bcb423c035Sumit Bose time(NULL) + dom->user_timeout);
62d919aea98edd1095f6a22241903d4c045b46edSumit Bose if (ret != EOK) {
62d919aea98edd1095f6a22241903d4c045b46edSumit Bose DEBUG(SSSDBG_OP_FAILURE,
62d919aea98edd1095f6a22241903d4c045b46edSumit Bose "sysdb_attrs_add_time_t failed.\n");
62d919aea98edd1095f6a22241903d4c045b46edSumit Bose goto done;
62d919aea98edd1095f6a22241903d4c045b46edSumit Bose }
62d919aea98edd1095f6a22241903d4c045b46edSumit Bose }
62d919aea98edd1095f6a22241903d4c045b46edSumit Bose
68c26d9ec785b8af0b45247705b20e82656bfd05Jakub Hrozek gid = 0;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (dom->mpg == false) {
68c26d9ec785b8af0b45247705b20e82656bfd05Jakub Hrozek gid = attrs->a.user.pw_gid;
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose } else {
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose /* The extdom plugin always returns the objects with the
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose * default view applied. Since the GID is handled specially
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose * for MPG domains we have add any overridden GID separately.
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose */
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose ret = sysdb_attrs_get_uint32_t(attrs->sysdb_attrs,
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose ORIGINALAD_PREFIX SYSDB_GIDNUM,
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose &orig_gid);
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose if (ret == EOK || ret == ENOENT) {
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose if ((orig_gid != 0 && orig_gid != attrs->a.user.pw_gid)
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose || attrs->a.user.pw_uid != attrs->a.user.pw_gid) {
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose gid_override_attrs = sysdb_new_attrs(tmp_ctx);
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose if (gid_override_attrs == NULL) {
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose "sysdb_new_attrs failed.\n");
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose ret = ENOMEM;
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose goto done;
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose }
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose ret = sysdb_attrs_add_uint32(gid_override_attrs,
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose SYSDB_GIDNUM,
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose attrs->a.user.pw_gid);
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose if (ret != EOK) {
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose "sysdb_attrs_add_uint32 failed.\n");
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose goto done;
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose }
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose }
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose } else {
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose "sysdb_attrs_get_uint32_t failed.\n");
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose goto done;
034dcabb40e654a95f3714d871db471ff7bf97f8Sumit Bose }
68c26d9ec785b8af0b45247705b20e82656bfd05Jakub Hrozek }
68c26d9ec785b8af0b45247705b20e82656bfd05Jakub Hrozek
9a2f018c0f68a3ada4cea4128a861a7f85893f22Sumit Bose ret = sysdb_attrs_get_el_ext(attrs->sysdb_attrs,
9a2f018c0f68a3ada4cea4128a861a7f85893f22Sumit Bose SYSDB_ORIG_MEMBEROF, false, &el);
9a2f018c0f68a3ada4cea4128a861a7f85893f22Sumit Bose if (ret == ENOENT) {
56f015ef6a161e01681f79e4ea0d1b642f9737b4Fabiano Fidêncio missing[missing_count++] = SYSDB_ORIG_MEMBEROF;
56f015ef6a161e01681f79e4ea0d1b642f9737b4Fabiano Fidêncio }
56f015ef6a161e01681f79e4ea0d1b642f9737b4Fabiano Fidêncio
56f015ef6a161e01681f79e4ea0d1b642f9737b4Fabiano Fidêncio ret = sysdb_attrs_get_el_ext(attrs->sysdb_attrs,
56f015ef6a161e01681f79e4ea0d1b642f9737b4Fabiano Fidêncio SYSDB_SSH_PUBKEY, false, &el);
56f015ef6a161e01681f79e4ea0d1b642f9737b4Fabiano Fidêncio if (ret == ENOENT) {
56f015ef6a161e01681f79e4ea0d1b642f9737b4Fabiano Fidêncio missing[missing_count++] = SYSDB_SSH_PUBKEY;
9a2f018c0f68a3ada4cea4128a861a7f85893f22Sumit Bose }
9a2f018c0f68a3ada4cea4128a861a7f85893f22Sumit Bose
43003851129556acea15539a1dc0d4350d54cac8Sumit Bose ret = sysdb_attrs_get_el_ext(attrs->sysdb_attrs,
43003851129556acea15539a1dc0d4350d54cac8Sumit Bose SYSDB_USER_CERT, false, &el);
43003851129556acea15539a1dc0d4350d54cac8Sumit Bose if (ret == ENOENT) {
43003851129556acea15539a1dc0d4350d54cac8Sumit Bose missing[missing_count++] = SYSDB_USER_CERT;
43003851129556acea15539a1dc0d4350d54cac8Sumit Bose }
43003851129556acea15539a1dc0d4350d54cac8Sumit Bose
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose ret = sysdb_transaction_start(dom->sysdb);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose if (ret != EOK) {
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose goto done;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose in_transaction = true;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = sysdb_store_user(dom, name, NULL,
68c26d9ec785b8af0b45247705b20e82656bfd05Jakub Hrozek attrs->a.user.pw_uid,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose gid, attrs->a.user.pw_gecos,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose attrs->a.user.pw_dir, attrs->a.user.pw_shell,
9a2f018c0f68a3ada4cea4128a861a7f85893f22Sumit Bose NULL, attrs->sysdb_attrs,
9a2f018c0f68a3ada4cea4128a861a7f85893f22Sumit Bose missing[0] == NULL ? NULL
9a2f018c0f68a3ada4cea4128a861a7f85893f22Sumit Bose : discard_const(missing),
acce97e8d97e81a9e660d46c4e3c00bcb423c035Sumit Bose dom->user_timeout, now);
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek if (ret == EEXIST && dom->mpg == true) {
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek /* This handles the case where getgrgid() was called for
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek * this user, so a group was created in the cache
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek */
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek ret = sysdb_search_group_by_name(tmp_ctx, dom, name, NULL, &msg);
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek if (ret != EOK) {
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek /* Fail even on ENOENT, the group must be around */
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek "Could not delete MPG group [%d]: %s\n",
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek ret, sss_strerror(ret));
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek goto done;
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek }
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek ret = sysdb_delete_group(dom, NULL, attrs->a.user.pw_uid);
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek if (ret != EOK) {
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek "sysdb_delete_group failed for MPG group [%d]: %s\n",
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek ret, sss_strerror(ret));
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek goto done;
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek }
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek ret = sysdb_store_user(dom, name, NULL,
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek attrs->a.user.pw_uid,
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek gid, attrs->a.user.pw_gecos,
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek attrs->a.user.pw_dir,
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek attrs->a.user.pw_shell,
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek NULL, attrs->sysdb_attrs, NULL,
acce97e8d97e81a9e660d46c4e3c00bcb423c035Sumit Bose dom->user_timeout, now);
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek if (ret != EOK) {
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek "sysdb_store_user failed for MPG user [%d]: %s\n",
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek ret, sss_strerror(ret));
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek goto done;
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek }
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek } else if (ret != EOK) {
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek "sysdb_store_user failed [%d]: %s\n",
6fe057efb981ee4b45dcadf131c03f8501fce28dJakub Hrozek ret, sss_strerror(ret));
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto done;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose if (mapped_attrs != NULL) {
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose ret = sysdb_set_user_attr(dom, name, mapped_attrs,
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose SYSDB_MOD_ADD);
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose if (ret != EOK) {
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_set_user_attr failed.\n");
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose goto done;
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose }
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose }
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose if (gid_override_attrs != NULL) {
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose ret = sysdb_set_user_attr(dom, name, gid_override_attrs,
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose SYSDB_MOD_REP);
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose if (ret != EOK) {
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_set_user_attr failed.\n");
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose goto done;
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose }
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose }
ba818cc39dfe94c2b8613f4badf7912811f0f737Sumit Bose
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose if (attrs->response_type == RESP_USER_GROUPLIST) {
a52226c651308a0a7732544b492eb4db56b84f1dSumit Bose ret = get_sysdb_grouplist_dn(tmp_ctx, dom->sysdb, dom, name,
a52226c651308a0a7732544b492eb4db56b84f1dSumit Bose &sysdb_grouplist);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose if (ret != EOK) {
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "get_sysdb_grouplist failed.\n");
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose goto done;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
a52226c651308a0a7732544b492eb4db56b84f1dSumit Bose ret = get_groups_dns(tmp_ctx, dom, attrs->groups, &groups_dns);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose if (ret != EOK) {
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "get_groups_dns failed.\n");
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose goto done;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
a52226c651308a0a7732544b492eb4db56b84f1dSumit Bose ret = diff_string_lists(tmp_ctx, groups_dns,
a52226c651308a0a7732544b492eb4db56b84f1dSumit Bose sysdb_grouplist, &add_groups_dns,
a52226c651308a0a7732544b492eb4db56b84f1dSumit Bose &del_groups_dns, NULL);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose if (ret != EOK) {
a52226c651308a0a7732544b492eb4db56b84f1dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "diff_string_lists failed.\n");
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose goto done;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose DEBUG(SSSDBG_TRACE_INTERNAL, "Updating memberships for %s\n",
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose name);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose ret = sysdb_update_members_dn(dom, name, SYSDB_MEMBER_USER,
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose (const char *const *) add_groups_dns,
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose (const char *const *) del_groups_dns);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose if (ret != EOK) {
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Membership update failed [%d]: %s\n",
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose ret, sss_strerror(ret));
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose goto done;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose ret = sysdb_transaction_commit(dom->sysdb);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose if (ret != EOK) {
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose goto done;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose in_transaction = false;
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose break;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose case RESP_GROUP:
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose case RESP_GROUP_MEMBERS:
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose type = SYSDB_MEMBER_GROUP;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (name == NULL) {
8f9d7684a47cd4715dce22c8254ddde205db9afeLukas Slebodnik name = attrs->a.group.gr_name;
8f9d7684a47cd4715dce22c8254ddde205db9afeLukas Slebodnik }
8f9d7684a47cd4715dce22c8254ddde205db9afeLukas Slebodnik
35863245aa8b8404caedfc95e68b3aa5af14542eJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "Processing group %s\n", name);
8d9e0547a864cee05ab36bc988300c0cfa986025Simo Sorce
aedc71fe8360a51785933523f14bb5c4e7e2c38bSumit Bose ret = sysdb_attrs_add_lc_name_alias_safe(attrs->sysdb_attrs, name);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (ret != EOK) {
c9124effceb40890bc9dd157155618067a7b8d2fSumit Bose DEBUG(SSSDBG_OP_FAILURE,
aedc71fe8360a51785933523f14bb5c4e7e2c38bSumit Bose "sysdb_attrs_add_lc_name_alias_safe failed.\n");
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose /* We might already have the SID from other sources hence
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose * sysdb_attrs_add_string_safe is used to avoid double entries. */
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (req_input->type == REQ_INP_SECID) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = sysdb_attrs_add_string_safe(attrs->sysdb_attrs,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose SYSDB_SID_STR,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose req_input->inp.secid);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose "sysdb_attrs_add_string failed.\n");
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (simple_attrs != NULL
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose && simple_attrs->response_type == RESP_SID) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = sysdb_attrs_add_string_safe(attrs->sysdb_attrs,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose SYSDB_SID_STR,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose simple_attrs->a.sid_str);
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose "sysdb_attrs_add_string failed.\n");
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose goto done;
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose }
e2f6326ea56217afab7623c542a237ee84eb74daSumit Bose
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose ret = process_members(dom, is_default_view(view_name),
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose attrs->sysdb_attrs, attrs->a.group.gr_mem,
919b5d76057d31877e0c25ca495711ff76c713d6Sumit Bose NULL, NULL);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "process_members failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose goto done;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = sysdb_store_group(dom, name, attrs->a.group.gr_gid,
acce97e8d97e81a9e660d46c4e3c00bcb423c035Sumit Bose attrs->sysdb_attrs, dom->group_timeout,
acce97e8d97e81a9e660d46c4e3c00bcb423c035Sumit Bose now);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (ret != EOK) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_store_group failed.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto done;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose break;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose default:
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Unexpected response type [%d].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov attrs->response_type);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose ret = EINVAL;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose goto done;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = sysdb_attrs_get_string(attrs->sysdb_attrs, SYSDB_SID_STR, &sid_str);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (ret != EOK) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
0c5f463e9629ac08d647c70cffb30bccdd57ae96Justin Stephenson "Cannot find SID of object.\n");
0c5f463e9629ac08d647c70cffb30bccdd57ae96Justin Stephenson if (name != NULL) {
0c5f463e9629ac08d647c70cffb30bccdd57ae96Justin Stephenson DEBUG(SSSDBG_CRIT_FAILURE,
0c5f463e9629ac08d647c70cffb30bccdd57ae96Justin Stephenson "Object [%s] has no SID, please check the "
0c5f463e9629ac08d647c70cffb30bccdd57ae96Justin Stephenson "ipaNTSecurityIdentifier attribute on the server-side.\n",
0c5f463e9629ac08d647c70cffb30bccdd57ae96Justin Stephenson name);
0c5f463e9629ac08d647c70cffb30bccdd57ae96Justin Stephenson }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto done;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = sysdb_search_object_by_sid(tmp_ctx, dom, sid_str, NULL, &res);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (ret != EOK) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose "Cannot find object with override with SID [%s].\n", sid_str);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto done;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
9ac2a33f4cdc4941fa63118dcffe8058854f33c4Michal Židek if (!is_default_view(view_name)) {
2ab9a4538eb2e1a255e645f7efdcfd6bb722d265Sumit Bose /* For the default view the data return by the extdom plugin already
2ab9a4538eb2e1a255e645f7efdcfd6bb722d265Sumit Bose * contains all needed data and it is not expected to have a separate
2ab9a4538eb2e1a255e645f7efdcfd6bb722d265Sumit Bose * override object. */
2ab9a4538eb2e1a255e645f7efdcfd6bb722d265Sumit Bose ret = sysdb_store_override(dom, view_name, type, override_attrs,
2ab9a4538eb2e1a255e645f7efdcfd6bb722d265Sumit Bose res->msgs[0]->dn);
2ab9a4538eb2e1a255e645f7efdcfd6bb722d265Sumit Bose if (ret != EOK) {
2ab9a4538eb2e1a255e645f7efdcfd6bb722d265Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_store_override failed.\n");
2ab9a4538eb2e1a255e645f7efdcfd6bb722d265Sumit Bose goto done;
2ab9a4538eb2e1a255e645f7efdcfd6bb722d265Sumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bosedone:
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose if (in_transaction) {
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose tret = sysdb_transaction_cancel(dom->sysdb);
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose if (tret != EOK) {
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n");
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose }
ad463501d3bdea4c24c17d792efc1c3e65c08c19Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose talloc_free(tmp_ctx);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose}
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bosestatic void ipa_s2n_get_list_done(struct tevent_req *subreq)
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose{
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose int ret;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct tevent_req *req = tevent_req_callback_data(subreq,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct tevent_req);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct ipa_s2n_get_user_state *state = tevent_req_data(req,
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose struct ipa_s2n_get_user_state);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose const char *sid_str;
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
aa0f39c7c09a55efc8d2282ca56e0e93e220aebaSumit Bose ret = ipa_s2n_get_list_recv(subreq);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose talloc_zfree(subreq);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
f1f22df95996390f63266ebacb624e521d934592Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "s2n get_fqlist request failed.\n");
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tevent_req_error(req, ret);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return;
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose if (state->attrs == NULL) {
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose /* If this is a request by certificate we are done */
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose if (state->req_input->type == REQ_INP_CERT) {
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose tevent_req_done(req);
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose } else {
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose tevent_req_error(req, EINVAL);
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose }
eb404bcdbbff7e080a93d816e17b8cec04f79fc4Jakub Hrozek return;
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose }
eb7095099b2dd0afb1d028dbc15d8c5a897d90f8Sumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = sysdb_attrs_get_string(state->attrs->sysdb_attrs, SYSDB_SID_STR,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose &sid_str);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (ret == ENOENT) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = ipa_s2n_save_objects(state->dom, state->req_input, state->attrs,
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose state->simple_attrs, NULL, NULL, NULL, true);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (ret != EOK) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_s2n_save_objects failed.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto fail;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose tevent_req_done(req);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose return;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose } else if (ret != EOK) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_get_string failed.\n");
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose goto fail;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
3d29430867cf92b2d71afa95abb679711231117cPavel Březina ret = get_dp_id_data_for_sid(state, sid_str, state->dom->name, &ar);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose if (ret != EOK) {
3d29430867cf92b2d71afa95abb679711231117cPavel Březina DEBUG(SSSDBG_OP_FAILURE, "get_dp_id_data_for_sid failed.\n");
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose goto fail;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose }
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
d8ceb194023a2cdc8bc183acc322e9a7fb6fe2b1Sumit Bose if (state->override_attrs == NULL
9ac2a33f4cdc4941fa63118dcffe8058854f33c4Michal Židek && !is_default_view(state->ipa_ctx->view_name)) {
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose subreq = ipa_get_ad_override_send(state, state->ev,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose state->ipa_ctx->sdap_id_ctx,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose state->ipa_ctx->ipa_options,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose dp_opt_get_string(state->ipa_ctx->ipa_options->basic,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose IPA_KRB5_REALM),
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose state->ipa_ctx->view_name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ar);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose if (subreq == NULL) {
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_get_ad_override_send failed.\n");
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ret = ENOMEM;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose goto fail;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose }
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose tevent_req_set_callback(subreq, ipa_s2n_get_user_get_override_done,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose req);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose } else {
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ret = ipa_s2n_save_objects(state->dom, state->req_input, state->attrs,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose state->simple_attrs,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose state->ipa_ctx->view_name,
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose state->override_attrs, NULL, true);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose if (ret != EOK) {
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_s2n_save_objects failed.\n");
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose tevent_req_error(req, ret);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose return;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose }
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose tevent_req_done(req);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose return;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bosefail:
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose tevent_req_error(req, ret);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose return;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose}
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bosestatic void ipa_s2n_get_user_get_override_done(struct tevent_req *subreq)
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose{
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose int ret;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose struct tevent_req *req = tevent_req_callback_data(subreq,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose struct tevent_req);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose struct ipa_s2n_get_user_state *state = tevent_req_data(req,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose struct ipa_s2n_get_user_state);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose struct sysdb_attrs *override_attrs = NULL;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose ret = ipa_get_ad_override_recv(subreq, NULL, state, &override_attrs);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose talloc_zfree(subreq);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose if (ret != EOK) {
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "IPA override lookup failed: %d\n", ret);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose tevent_req_error(req, ret);
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose return;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose }
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose ret = ipa_s2n_save_objects(state->dom, state->req_input, state->attrs,
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose state->simple_attrs, state->ipa_ctx->view_name,
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose override_attrs, NULL, true);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose if (ret != EOK) {
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_s2n_save_objects failed.\n");
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose tevent_req_error(req, ret);
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose return;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose }
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose
28c70f003c7b330ab1d998a4eff1248d272a6ba9Sumit Bose tevent_req_done(req);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose}
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Boseint ipa_s2n_get_acct_info_recv(struct tevent_req *req)
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose{
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose TEVENT_REQ_RETURN_ON_ERROR(req);
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose return EOK;
36a12aea020a935ffa40505fa02860c3d921ad0cSumit Bose}
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bosestruct ipa_get_subdom_acct_process_pac_state {
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct tevent_context *ev;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct sdap_handle *sh;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct sss_domain_info *dom;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose char *username;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose size_t num_missing_sids;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose char **missing_sids;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose size_t num_cached_groups;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose char **cached_groups;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose};
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bosestatic void ipa_get_subdom_acct_process_pac_done(struct tevent_req *subreq);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bosestruct tevent_req *ipa_get_subdom_acct_process_pac_send(TALLOC_CTX *mem_ctx,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct tevent_context *ev,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct sdap_handle *sh,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct ipa_id_ctx *ipa_ctx,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct sss_domain_info *dom,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct ldb_message *user_msg)
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose{
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose int ret;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct ipa_get_subdom_acct_process_pac_state *state;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct tevent_req *req;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct tevent_req *subreq;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose char *user_sid;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose char *primary_group_sid;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose size_t num_sids;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose char **group_sids;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose req = tevent_req_create(mem_ctx, &state,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct ipa_get_subdom_acct_process_pac_state);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose if (req == NULL) {
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "tevent_req_create failed.\n");
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose return NULL;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose }
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose state->ev = ev;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose state->sh = sh;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose state->dom = dom;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose ret = ad_get_pac_data_from_user_entry(state, user_msg,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose ipa_ctx->sdap_id_ctx->opts->idmap_ctx->map,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose &state->username,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose &user_sid, &primary_group_sid,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose &num_sids, &group_sids);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose if (ret != EOK) {
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ad_get_pac_data_from_user_entry failed.\n");
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose goto done;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose }
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose ret = sdap_ad_tokengroups_get_posix_members(state, state->dom,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose num_sids, group_sids,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose &state->num_missing_sids,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose &state->missing_sids,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose &state->num_cached_groups,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose &state->cached_groups);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose if (ret != EOK) {
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose "sdap_ad_tokengroups_get_posix_members failed.\n");
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose goto done;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose }
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose if (state->num_missing_sids == 0) {
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose ret = sdap_ad_tokengroups_update_members(state->username,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose state->dom->sysdb,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose state->dom,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose state->cached_groups);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose if (ret != EOK) {
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose DEBUG(SSSDBG_MINOR_FAILURE, "Membership update failed [%d]: %s\n",
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose ret, strerror(ret));
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose }
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose goto done;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose }
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose subreq = ipa_s2n_get_list_send(state, state->ev, ipa_ctx, state->dom,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose state->sh,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose dp_opt_get_int(ipa_ctx->sdap_id_ctx->opts->basic,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose SDAP_SEARCH_TIMEOUT),
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose BE_REQ_BY_SECID, REQ_FULL, REQ_INP_SECID,
415d93196533a6fcd90889c67396ef5af5bf791aSumit Bose state->missing_sids, NULL);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose if (subreq == NULL) {
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_s2n_get_list_send failed.\n");
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose ret = ENOMEM;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose goto done;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose }
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose tevent_req_set_callback(subreq, ipa_get_subdom_acct_process_pac_done, req);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose return req;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bosedone:
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose if (ret == EOK) {
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose tevent_req_done(req);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose } else {
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose tevent_req_error(req, ret);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose }
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose tevent_req_post(req, ev);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose return req;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose}
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bosestatic void ipa_get_subdom_acct_process_pac_done(struct tevent_req *subreq)
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose{
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose int ret;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct tevent_req *req = tevent_req_callback_data(subreq,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct tevent_req);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct ipa_get_subdom_acct_process_pac_state *state = tevent_req_data(req,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose struct ipa_get_subdom_acct_process_pac_state);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose char **cached_groups;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose size_t num_cached_groups;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose ret = ipa_s2n_get_list_recv(subreq);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose talloc_zfree(subreq);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose if (ret != EOK) {
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "s2n get_fqlist request failed.\n");
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose tevent_req_error(req, ret);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose return;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose }
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose /* from ad_pac.c */
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose ret = sdap_ad_tokengroups_get_posix_members(state, state->dom,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose state->num_missing_sids,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose state->missing_sids,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose NULL, NULL,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose &num_cached_groups,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose &cached_groups);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose if (ret != EOK){
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose DEBUG(SSSDBG_MINOR_FAILURE,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose "sdap_ad_tokengroups_get_posix_members failed [%d]: %s\n",
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose ret, strerror(ret));
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose goto done;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose }
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose state->cached_groups = concatenate_string_array(state,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose state->cached_groups,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose state->num_cached_groups,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose cached_groups,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose num_cached_groups);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose if (state->cached_groups == NULL) {
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose ret = ENOMEM;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose goto done;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose }
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose /* update membership of existing groups */
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose ret = sdap_ad_tokengroups_update_members(state->username,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose state->dom->sysdb,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose state->dom,
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose state->cached_groups);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose if (ret != EOK) {
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose DEBUG(SSSDBG_MINOR_FAILURE, "Membership update failed [%d]: %s\n",
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose ret, strerror(ret));
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose goto done;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose }
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose ret = EOK;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bosedone:
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose if (ret == EOK) {
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose tevent_req_done(req);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose } else {
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose tevent_req_error(req, ret);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose }
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose return;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose}
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Boseerrno_t ipa_get_subdom_acct_process_pac_recv(struct tevent_req *req)
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose{
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose TEVENT_REQ_RETURN_ON_ERROR(req);
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose return EOK;
c371993cce13edb9185a5f0db76fbee03f0edc04Sumit Bose}