4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina Pavel Březina <pbrezina@redhat.com>
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina Copyright (C) 2016 Red Hat
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina This program is free software; you can redistribute it and/or modify
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina it under the terms of the GNU General Public License as published by
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina the Free Software Foundation; either version 3 of the License, or
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina (at your option) any later version.
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina This program is distributed in the hope that it will be useful,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina GNU General Public License for more details.
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina You should have received a copy of the GNU General Public License
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose el = ldb_msg_find_element(msg, SYSDB_OBJECTCATEGORY);
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "Objectcategory attribute not found.\n");
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina if (cmd_ctx->sid_id_type != SSS_ID_TYPE_NOT_SPECIFIED) {
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Well known objects are always groups. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = find_sss_id_type(result->msgs[0], result->domain->mpg, _type);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina "Unable to find ID type [%d]: %s\n", ret, sss_strerror(ret));
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = nss_get_id_type(cmd_ctx, result, &id_type);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sid = ldb_msg_find_attr_as_string(msg, SYSDB_SID_STR, NULL);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = sss_packet_grow(packet, sz_sid.len + 3 * sizeof(uint32_t));
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "sss_packet_grow failed.\n");
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sss_packet_get_body(packet, &body, &body_len);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_UINT32(&body[rp], 1, &rp); /* Num results. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_UINT32(&body[rp], 0, &rp); /* Reserved. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_UINT32(&body[rp], id_type, &rp);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_STRING(&body[rp], sz_sid.str, sz_sid.len, &rp);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březinastatic errno_t process_attr_list(TALLOC_CTX *mem_ctx, struct ldb_message *msg,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina keys = talloc_realloc(mem_ctx, keys, struct sized_string,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina vals = talloc_realloc(mem_ctx, vals, struct sized_string,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "talloc_array failed.\n");
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina if (strcmp(attr_list[c], SYSDB_USER_CERT) == 0) {
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina if (val.data == NULL || val.data[val.length] != '\0') {
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina "Unexpected attribute value found for [%s].\n",
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina to_sized_string(&vals[*found], (const char *)val.data);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březinanss_protocol_fill_orig(struct nss_ctx *nss_ctx,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = nss_get_id_type(cmd_ctx, result, &id_type);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina array_size = sizeof(orig_attrs) + extra_attrs_count;
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina keys = talloc_array(tmp_ctx, struct sized_string, array_size);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina vals = talloc_array(tmp_ctx, struct sized_string, array_size);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "talloc_array failed.\n");
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = process_attr_list(tmp_ctx, msg, orig_attrs, &keys, &vals,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "process_attr_list failed.\n");
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = process_attr_list(tmp_ctx, msg, extra_attrs, &keys, &vals,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "process_attr_list failed.\n");
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = sss_packet_grow(packet, sum + 3 * sizeof(uint32_t));
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "sss_packet_grow failed.\n");
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sss_packet_get_body(packet, &body, &body_len);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SETMEM_UINT32(&body[rp], 1, &rp); /* Num results */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SETMEM_UINT32(&body[rp], 0, &rp); /* reserved */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_COPY_UINT32(&body[rp], &id_type, &rp);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina for (i = 0; i < found; i++) {
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_STRING(&body[rp], keys[i].str, keys[i].len, &rp);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_STRING(&body[rp], vals[i].str, vals[i].len, &rp);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Missing name.\n");
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sz_name = talloc_zero(mem_ctx, struct sized_string);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina fq_name = sss_tc_fqname2(sz_name, rctx->global_names,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Conversion to fqname failed.\n");
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina return nss_get_well_known_name(mem_ctx, rctx, result, _sz_name);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina name = ldb_msg_find_attr_as_string(msg, ORIGINALAD_PREFIX SYSDB_NAME,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina name = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Missing name.\n");
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = sized_output_name(mem_ctx, rctx, name, result->domain, _sz_name);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina "Unable to create sized name [%d]: %s\n",
7aadfa5454e436e4c36ede00434ff9687a6c48e2Sumit Bosenss_protocol_fill_single_name(struct nss_ctx *nss_ctx,
7aadfa5454e436e4c36ede00434ff9687a6c48e2Sumit Bose DEBUG(SSSDBG_TRACE_FUNC, "Lookup returned more than one result "
7aadfa5454e436e4c36ede00434ff9687a6c48e2Sumit Bose "but only one was expected.\n");
7aadfa5454e436e4c36ede00434ff9687a6c48e2Sumit Bose return nss_protocol_fill_name(nss_ctx, cmd_ctx, packet, result);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březinanss_protocol_fill_name(struct nss_ctx *nss_ctx,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = nss_get_id_type(cmd_ctx, result, &id_type);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = nss_get_ad_name(cmd_ctx, nss_ctx->rctx, result, &sz_name);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = sss_packet_grow(packet, sz_name->len + 3 * sizeof(uint32_t));
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "sss_packet_grow failed.\n");
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sss_packet_get_body(packet, &body, &body_len);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_UINT32(&body[rp], 1, &rp); /* Num results. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_UINT32(&body[rp], 0, &rp); /* Reserved. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_UINT32(&body[rp], id_type, &rp);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_STRING(&body[rp], sz_name->str, sz_name->len, &rp);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* This was a well known SID. This is currently unsupported with id. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = nss_get_id_type(cmd_ctx, result, &id_type);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina id64 = ldb_msg_find_attr_as_uint64(msg, SYSDB_GIDNUM, 0);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina id64 = ldb_msg_find_attr_as_uint64(msg, SYSDB_UIDNUM, 0);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid POSIX ID.\n");
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = sss_packet_grow(packet, 4 * sizeof(uint32_t));
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "sss_packet_grow failed.\n");
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sss_packet_get_body(packet, &body, &body_len);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_UINT32(&body[rp], 1, &rp); /* Num results. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_UINT32(&body[rp], 0, &rp); /* Reserved. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_UINT32(&body[rp], id_type, &rp);
440797cba931aa491bf418035f55935943e22b4bSumit Bosenss_protocol_fill_name_list(struct nss_ctx *nss_ctx,
440797cba931aa491bf418035f55935943e22b4bSumit Bose sz_names = talloc_array(cmd_ctx, struct sized_string, result->count);
440797cba931aa491bf418035f55935943e22b4bSumit Bose id_types = talloc_array(cmd_ctx, enum sss_id_type, result->count);
440797cba931aa491bf418035f55935943e22b4bSumit Bose ret = nss_get_id_type(cmd_ctx, result, &(id_types[c]));
a012a71f21bf1a4687e58085f19c18cc5b2bbaddNikolai Kondrashov tmp_str = sss_get_name_from_msg(result->domain, result->msgs[c]);
440797cba931aa491bf418035f55935943e22b4bSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_packet_grow failed.\n");
440797cba931aa491bf418035f55935943e22b4bSumit Bose SAFEALIGN_SET_UINT32(&body[rp], result->count, &rp); /* Num results. */
440797cba931aa491bf418035f55935943e22b4bSumit Bose SAFEALIGN_SET_UINT32(&body[rp], 0, &rp); /* Reserved. */
440797cba931aa491bf418035f55935943e22b4bSumit Bose SAFEALIGN_SET_UINT32(&body[rp], id_types[c], &rp);
440797cba931aa491bf418035f55935943e22b4bSumit Bose SAFEALIGN_SET_STRING(&body[rp], sz_names[c].str, sz_names[c].len,
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bosenss_protocol_fill_name_list_all_domains(struct nss_ctx *nss_ctx,
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose sz_names = talloc_array(cmd_ctx, struct sized_string, total);
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose id_types = talloc_array(cmd_ctx, enum sss_id_type, total);
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose ret = nss_get_id_type(cmd_ctx, results[d], &(id_types[iter]));
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose tmp_str = sss_get_name_from_msg(results[d]->domain,
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_packet_grow failed.\n");
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose SAFEALIGN_SET_UINT32(&body[rp], total, &rp); /* Num results. */
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose SAFEALIGN_SET_UINT32(&body[rp], 0, &rp); /* Reserved. */
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose for (c = 0; c < total; c++) {
71731d26dc4f2c36989779f327b0e9a399486e14Sumit Bose SAFEALIGN_SET_UINT32(&body[rp], id_types[c], &rp);