63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose/*
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose SSSD
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose Authors:
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose Sumit Bose <sbose@redhat.com>
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose Copyright (C) 2016 Red Hat
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose This program is free software; you can redistribute it and/or modify
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose it under the terms of the GNU General Public License as published by
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose the Free Software Foundation; either version 3 of the License, or
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose (at your option) any later version.
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose This program is distributed in the hope that it will be useful,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose GNU General Public License for more details.
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose You should have received a copy of the GNU General Public License
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose*/
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose#include "providers/ad/ad_pac.h"
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose#include "util/util.h"
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Boseerrno_t ad_get_data_from_pac(TALLOC_CTX *mem_ctx,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose uint8_t *pac_blob, size_t pac_len,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct PAC_LOGON_INFO **_logon_info)
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose{
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose DATA_BLOB blob;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct ndr_pull *ndr_pull;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose struct PAC_DATA *pac_data;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose enum ndr_err_code ndr_err;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose size_t c;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose int ret;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose TALLOC_CTX *tmp_ctx;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose tmp_ctx = talloc_new(NULL);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose if (tmp_ctx == NULL) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose return ENOMEM;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose blob.data = pac_blob;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose blob.length = pac_len;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ndr_pull = ndr_pull_init_blob(&blob, tmp_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose if (ndr_pull == NULL) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ndr_pull_init_blob failed.\n");
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = ENOMEM;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose goto done;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ndr_pull->flags |= LIBNDR_FLAG_REF_ALLOC; /* FIXME: is this really needed ? */
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose pac_data = talloc_zero(tmp_ctx, struct PAC_DATA);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose if (pac_data == NULL) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_zero failed.\n");
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = ENOMEM;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose goto done;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ndr_err = ndr_pull_PAC_DATA(ndr_pull, NDR_SCALARS|NDR_BUFFERS, pac_data);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ndr_pull_PAC_DATA failed [%d]\n", ndr_err);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = EBADMSG;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose goto done;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose for(c = 0; c < pac_data->num_buffers; c++) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose if (pac_data->buffers[c].type == PAC_TYPE_LOGON_INFO) {
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose *_logon_info = talloc_steal(mem_ctx,
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose pac_data->buffers[c].info->logon_info.info);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = EOK;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose goto done;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose }
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose ret = EINVAL;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bosedone:
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose talloc_free(tmp_ctx);
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose return ret;
63b8e826f62d2e8930c872de7d4cc8b5bc15d4a4Sumit Bose}