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/>.
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Get name. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina name = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina name = sss_get_cased_name(tmp_ctx, name, domain->case_preserve);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Get port. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina port = (uint16_t)ldb_msg_find_attr_as_uint(msg, SYSDB_SVC_PORT, 0);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "No port for service [%s]\n", name);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Get protocol.
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina * Use the requested protocol if present, otherwise take the
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina * first protocol returned by the sysdb. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina el = ldb_msg_find_element(msg, SYSDB_SVC_PROTO);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina protocol = sss_get_cased_name(tmp_ctx, protocol, domain->case_preserve);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Set output variables. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina el = ldb_msg_find_element(msg, SYSDB_NAME_ALIAS);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina aliases = talloc_zero_array(mem_ctx, struct sized_string,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina if (sss_string_equal(domain->case_sensitive, alias, name)) {
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Element value remains in the message, we don't need to strdup it. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina to_sized_string(&aliases[num_aliases], alias);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březinanss_protocol_fill_svcent(struct nss_ctx *nss_ctx,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* First two fields (length and reserved), filled up later. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = sss_packet_grow(packet, 2 * sizeof(uint32_t));
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = nss_get_svcent(tmp_ctx, result->domain, msg,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina cmd_ctx->svc_protocol, &name, &protocol, &port);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina "Unable to get service information, skipping... [%d]: %s\n",
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = nss_get_svc_aliases(tmp_ctx, result->domain, msg, name.str,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina "Unable to get service aliases, skipping... [%d]: %s\n",
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Adjust packet size. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = sss_packet_grow(packet, 2 * sizeof(uint16_t) + sizeof(uint32_t)
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sss_packet_get_body(packet, &body, &body_len);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Fill packet. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_UINT32(&body[rp], (uint32_t)htons(port), &rp);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_UINT32(&body[rp], num_aliases, &rp);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_STRING(&body[rp], name.str, name.len, &rp);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_STRING(&body[rp], protocol.str, protocol.len, &rp);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina /* Store aliases. */
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina for (j = 0; j < num_aliases; j++) {
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina ret = sss_packet_grow(packet, aliases[j].len);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sss_packet_get_body(packet, &body, &body_len);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SET_STRING(&body[rp], aliases[j].str, aliases[j].len,
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina sss_packet_get_body(packet, &body, &body_len);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_COPY_UINT32(body, &num_results, NULL);
4049b63f8c67ada17b453463b0451ca6be3d5de4Pavel Březina SAFEALIGN_SETMEM_UINT32(body + sizeof(uint32_t), 0, NULL); /* reserved */