a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina Jan Cholasta <jcholast@redhat.com>
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina Copyright (C) 2012 Red Hat
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina This program is free software; you can redistribute it and/or modify
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina it under the terms of the GNU General Public License as published by
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina the Free Software Foundation; either version 3 of the License, or
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina (at your option) any later version.
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina This program is distributed in the hope that it will be useful,
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina GNU General Public License for more details.
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina You should have received a copy of the GNU General Public License
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina#include "responder/common/cache_req/cache_req.h"
bd1fa0ec90be717c3b7796d74b6f243f40178d16Sumit Bose/* Locally used flag for libldb's ldb_message_element structure to indicate
bd1fa0ec90be717c3b7796d74b6f243f40178d16Sumit Bose * binary data. Since the related data is only used in memory it is safe. If
bd1fa0ec90be717c3b7796d74b6f243f40178d16Sumit Bose * should be used with care if libldb's I/O operations are involved. */
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březinastatic errno_t get_valid_certs_keys(TALLOC_CTX *mem_ctx,
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina DEBUG(SSSDBG_TRACE_ALL, "Mssing element, nothing to do.\n");
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina ret = confdb_get_string(ssh_ctx->rctx->cdb, tmp_ctx,
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina "Failed to read p11_child_timeout from confdb: [%d] %s\n",
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina ret = parse_cert_verify_opts(tmp_ctx, cert_verification_opts,
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina "Failed to parse verifiy option.\n");
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina el_res = talloc_zero(tmp_ctx, struct ldb_message_element);
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina DEBUG(SSSDBG_OP_FAILURE, "talloc_zero failed.\n");
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina el_res->values = talloc_array(el_res, struct ldb_val, el_cert->num_values);
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina DEBUG(SSSDBG_OP_FAILURE, "talloc_array failed.\n");
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina ret = cert_to_ssh_key(tmp_ctx, ssh_ctx->ca_db,
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina DEBUG(SSSDBG_OP_FAILURE, "cert_to_ssh_key failed, ignoring.\n");
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina el_res->values[el_res->num_values].length = key_len;
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březinastatic errno_t decode_and_add_base64_data(struct sss_packet *packet,
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina DEBUG(SSSDBG_TRACE_ALL, "Mssing element, nothing to do.\n");
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
bd1fa0ec90be717c3b7796d74b6f243f40178d16Sumit Bose if (skip_base64_decode || (el->flags & SSS_EL_FLAG_BIN_DATA)) {
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina key = sss_base64_decode(tmp_ctx, (const char *) el->values[d].data,
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina DEBUG(SSSDBG_OP_FAILURE, "sss_base64_decode failed.\n");
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina DEBUG(SSSDBG_OP_FAILURE, "sss_packet_grow failed.\n");
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina sss_packet_get_body(packet, &body, &body_len);
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina SAFEALIGN_SET_UINT32(body+(*c), fqname_len, c);
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina safealign_memcpy(body+(*c), fqname, fqname_len, c);
1b5d6b1afc9c3dc696b7b45f2d73b2634f42800aSumit Bose elements = talloc_zero_array(mem_ctx, struct ldb_message_element *, 6);
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina elements[i] = ldb_msg_find_element(msg, SYSDB_SSH_PUBKEY);
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina elements[i] = ldb_msg_find_element(msg, ORIGINALAD_PREFIX SYSDB_SSH_PUBKEY);
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina elements[i] = ldb_msg_find_element(msg, OVERRIDE_PREFIX SYSDB_SSH_PUBKEY);
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina user_cert = ldb_msg_find_element(msg, SYSDB_USER_CERT);
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina ret = get_valid_certs_keys(elements, ssh_ctx, user_cert, &elements[i]);
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina DEBUG(SSSDBG_OP_FAILURE, "get_valid_certs_keys failed.\n");
1b5d6b1afc9c3dc696b7b45f2d73b2634f42800aSumit Bose user_cert = ldb_msg_find_element(msg, OVERRIDE_PREFIX SYSDB_USER_CERT);
1b5d6b1afc9c3dc696b7b45f2d73b2634f42800aSumit Bose ret = get_valid_certs_keys(elements, ssh_ctx, user_cert,
1b5d6b1afc9c3dc696b7b45f2d73b2634f42800aSumit Bose DEBUG(SSSDBG_OP_FAILURE, "get_valid_certs_keys failed.\n");
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina name = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina DEBUG(SSSDBG_OP_FAILURE, "Got unnamed result!\n");
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březinassh_protocol_build_reply(struct sss_packet *packet,
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory!\n");
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina ret = ssh_get_output_keys(tmp_ctx, ssh_ctx, result->domain,
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina ret = sss_packet_grow(packet, 2 * sizeof(uint32_t));
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina sss_packet_get_body(packet, &body, &body_len);
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina ret = decode_and_add_base64_data(packet, elements[i], false,
a8191ce7ad5364801ad9458c3194075a7ca77b8aPavel Březina DEBUG(SSSDBG_OP_FAILURE, "decode_and_add_base64_data failed.\n");