f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek/*
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek Authors:
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek Stephen Gallagher <sgallagh@redhat.com>
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek Copyright (C) 2013 Red Hat
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek InfoPipe responder: Utility functions
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek This program is free software; you can redistribute it and/or modify
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek it under the terms of the GNU General Public License as published by
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek the Free Software Foundation; either version 3 of the License, or
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek (at your option) any later version.
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek This program is distributed in the hope that it will be useful,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek GNU General Public License for more details.
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek You should have received a copy of the GNU General Public License
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek*/
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek#include <sys/param.h>
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek#include "db/sysdb.h"
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek#include "responder/ifp/ifp_private.h"
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina#define IFP_USER_DEFAULT_ATTRS {SYSDB_NAME, SYSDB_UIDNUM, \
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina SYSDB_GIDNUM, SYSDB_GECOS, \
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina SYSDB_HOMEDIR, SYSDB_SHELL, \
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina "groups", "domain", "domainname", \
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina NULL}
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozekerrno_t ifp_req_create(struct sbus_request *dbus_req,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek struct ifp_ctx *ifp_ctx,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek struct ifp_req **_ifp_req)
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek{
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek struct ifp_req *ireq = NULL;
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek errno_t ret;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek if (ifp_ctx->sysbus == NULL) {
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Responder not connected to sysbus!\n");
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek return EINVAL;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek }
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek ireq = talloc_zero(dbus_req, struct ifp_req);
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek if (ireq == NULL) {
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek return ENOMEM;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek }
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek ireq->ifp_ctx = ifp_ctx;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek ireq->dbus_req = dbus_req;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek if (dbus_req->client == -1) {
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek /* We got a sysbus message but couldn't identify the
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek * caller? Bail out! */
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek "BUG: Received a message without a known caller!\n");
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek ret = EACCES;
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek goto done;
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek }
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek ret = check_allowed_uids(dbus_req->client,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek ifp_ctx->rctx->allowed_uids_count,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek ifp_ctx->rctx->allowed_uids);
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek if (ret == EACCES) {
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek "User %"PRIi64" not in ACL\n", dbus_req->client);
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek goto done;
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek } else if (ret != EOK) {
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek "Cannot check if user %"PRIi64" is present in ACL\n",
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek dbus_req->client);
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek goto done;
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek }
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek *_ifp_req = ireq;
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek ret = EOK;
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekdone:
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek if (ret != EOK) {
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek talloc_free(ireq);
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek }
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek return ret;
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek}
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekint ifp_req_create_handle_failure(struct sbus_request *dbus_req, errno_t err)
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek{
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek if (err == EACCES) {
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek return sbus_request_fail_and_finish(dbus_req,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek sbus_error_new(dbus_req,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek DBUS_ERROR_ACCESS_DENIED,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek "User %"PRIi64" not in ACL\n",
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek dbus_req->client));
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek }
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek return sbus_request_fail_and_finish(dbus_req,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek sbus_error_new(dbus_req,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek DBUS_ERROR_FAILED,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek "Cannot create IFP request\n"));
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek}
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březinaerrno_t ifp_add_value_to_dict(DBusMessageIter *iter_dict,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina const char *key,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina const char *value)
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina{
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina DBusMessageIter iter_dict_entry;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina DBusMessageIter iter_dict_val;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina DBusMessageIter iter_array;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbus_bool_t dbret;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina if (value == NULL || key == NULL) {
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina return EINVAL;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina }
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_open_container(iter_dict,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina DBUS_TYPE_DICT_ENTRY, NULL,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina &iter_dict_entry);
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina if (!dbret) {
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina return ENOMEM;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina }
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina /* Start by appending the key */
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_append_basic(&iter_dict_entry,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina DBUS_TYPE_STRING, &key);
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina if (!dbret) {
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina return ENOMEM;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina }
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_open_container(&iter_dict_entry,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina DBUS_TYPE_VARIANT,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina DBUS_TYPE_ARRAY_AS_STRING
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina DBUS_TYPE_STRING_AS_STRING,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina &iter_dict_val);
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina if (!dbret) {
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina return ENOMEM;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina }
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina /* Open container for values */
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_open_container(&iter_dict_val,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina &iter_array);
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina if (!dbret) {
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina return ENOMEM;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina }
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_append_basic(&iter_array,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina DBUS_TYPE_STRING,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina &value);
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina if (!dbret) {
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina return ENOMEM;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina }
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_close_container(&iter_dict_val,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina &iter_array);
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina if (!dbret) {
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina return ENOMEM;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina }
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_close_container(&iter_dict_entry,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina &iter_dict_val);
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina if (!dbret) {
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina return ENOMEM;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina }
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_close_container(iter_dict,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina &iter_dict_entry);
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina if (!dbret) {
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina return ENOMEM;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina }
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina return EOK;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina}
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozekerrno_t ifp_add_ldb_el_to_dict(DBusMessageIter *iter_dict,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek struct ldb_message_element *el)
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek{
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek DBusMessageIter iter_dict_entry;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek DBusMessageIter iter_dict_val;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek DBusMessageIter iter_array;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbus_bool_t dbret;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek unsigned int i;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek if (el == NULL) {
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek return EINVAL;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek }
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_open_container(iter_dict,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek DBUS_TYPE_DICT_ENTRY, NULL,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek &iter_dict_entry);
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek if (!dbret) {
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek return ENOMEM;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek }
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek /* Start by appending the key */
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_append_basic(&iter_dict_entry,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek DBUS_TYPE_STRING, &(el->name));
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek if (!dbret) {
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek return ENOMEM;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek }
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_open_container(&iter_dict_entry,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek DBUS_TYPE_VARIANT,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek DBUS_TYPE_ARRAY_AS_STRING
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek DBUS_TYPE_STRING_AS_STRING,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek &iter_dict_val);
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek if (!dbret) {
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek return ENOMEM;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek }
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek /* Open container for values */
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_open_container(&iter_dict_val,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek &iter_array);
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek if (!dbret) {
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek return ENOMEM;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek }
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek /* Now add all the values */
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek for (i = 0; i < el->num_values; i++) {
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "element [%s] has value [%s]\n",
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek el->name, (const char *) el->values[i].data);
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_append_basic(&iter_array,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek DBUS_TYPE_STRING,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek &(el->values[i].data));
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek if (!dbret) {
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek return ENOMEM;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek }
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek }
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_close_container(&iter_dict_val,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek &iter_array);
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek if (!dbret) {
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek return ENOMEM;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek }
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_close_container(&iter_dict_entry,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek &iter_dict_val);
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek if (!dbret) {
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek return ENOMEM;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek }
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_close_container(iter_dict,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek &iter_dict_entry);
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek if (!dbret) {
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek return ENOMEM;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek }
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek return EOK;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek}
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek
770dc892f867639f36f84455d65be6287935a529Jakub Hrozekbool
770dc892f867639f36f84455d65be6287935a529Jakub Hrozekifp_attr_allowed(const char *whitelist[], const char *attr)
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek{
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek size_t i;
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek if (whitelist == NULL) {
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek return false;
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek }
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek for (i = 0; whitelist[i]; i++) {
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek if (strcasecmp(whitelist[i], attr) == 0) {
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek break;
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek }
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek }
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek return (whitelist[i]) ? true : false;
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinaconst char **
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinaifp_parse_user_attr_list(TALLOC_CTX *mem_ctx, const char *csv)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina static const char *defaults[] = IFP_USER_DEFAULT_ATTRS;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return parse_attr_list_ex(mem_ctx, csv, defaults);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinaconst char **
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinaifp_get_user_extra_attributes(TALLOC_CTX *mem_ctx, struct ifp_ctx *ifp_ctx)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina TALLOC_CTX *tmp_ctx = NULL;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char *std[] = IFP_USER_DEFAULT_ATTRS;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char **whitelist = ifp_ctx->user_whitelist;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char **extra;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina bool found;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina int extra_num;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina int i, j;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina tmp_ctx = talloc_new(NULL);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (tmp_ctx == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return NULL;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina for (i = 0; whitelist[i] != NULL; i++) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina /* Just count number of attributes in whitelist. */
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina extra = talloc_zero_array(tmp_ctx, const char *, i + 1);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (extra == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero_array() failed\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina goto fail;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina extra_num = 0;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina for (i = 0; whitelist[i] != NULL; i++) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina found = false;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina for (j = 0; std[j] != NULL; j++) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (strcmp(whitelist[i], std[j]) == 0) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina found = true;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina break;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (!found) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina extra[extra_num] = talloc_strdup(extra, whitelist[i]);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (extra[extra_num] == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina goto fail;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina extra_num++;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina extra = talloc_realloc(tmp_ctx, extra, const char *, extra_num + 1);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (extra == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina goto fail;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina talloc_steal(mem_ctx, extra);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina talloc_free(tmp_ctx);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return extra;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinafail:
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina talloc_free(tmp_ctx);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return NULL;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinabool
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinaifp_is_user_attr_allowed(struct ifp_ctx *ifp_ctx, const char *attr)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return ifp_attr_allowed(ifp_ctx->user_whitelist, attr);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozekstatic uint32_t ifp_list_limit(struct ifp_ctx *ctx, uint32_t limit)
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek{
ef7de95fc4827a660254a942fa394f34ed9694a9Pavel Březina if (limit == 0) {
ef7de95fc4827a660254a942fa394f34ed9694a9Pavel Březina return ctx->wildcard_limit;
ef7de95fc4827a660254a942fa394f34ed9694a9Pavel Březina } else if (ctx->wildcard_limit) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return MIN(ctx->wildcard_limit, limit);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek } else {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return limit;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek}
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozekstruct ifp_list_ctx *ifp_list_ctx_new(struct sbus_request *sbus_req,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek struct ifp_ctx *ctx,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek const char *filter,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek uint32_t limit)
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek{
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek struct ifp_list_ctx *list_ctx;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx = talloc_zero(sbus_req, struct ifp_list_ctx);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (list_ctx == NULL) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return NULL;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->sbus_req = sbus_req;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->limit = ifp_list_limit(ctx, limit);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->ctx = ctx;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->dom = ctx->rctx->domains;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->filter = filter;
510ac193900a7bb9dfae10c0ca4607c224b265afSumit Bose list_ctx->paths_max = 1;
510ac193900a7bb9dfae10c0ca4607c224b265afSumit Bose list_ctx->paths = talloc_zero_array(list_ctx, const char *,
510ac193900a7bb9dfae10c0ca4607c224b265afSumit Bose list_ctx->paths_max);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (list_ctx->paths == NULL) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek talloc_free(list_ctx);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return NULL;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return list_ctx;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek}
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncioerrno_t ifp_list_ctx_remaining_capacity(struct ifp_list_ctx *list_ctx,
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio size_t entries,
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio size_t *_capacity)
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek{
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek size_t capacity = list_ctx->limit - list_ctx->path_count;
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio errno_t ret;
510ac193900a7bb9dfae10c0ca4607c224b265afSumit Bose size_t c;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
3c31ce392ad9da4ac7c3d8190db89efcdbbc8b85Petr Čech if (list_ctx->limit == 0) {
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio capacity = entries;
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio goto immediately;
3c31ce392ad9da4ac7c3d8190db89efcdbbc8b85Petr Čech }
3c31ce392ad9da4ac7c3d8190db89efcdbbc8b85Petr Čech
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (capacity < entries) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek "IFP list request has limit of %"PRIu32" entries but back end "
510ac193900a7bb9dfae10c0ca4607c224b265afSumit Bose "returned %zu entries\n", list_ctx->limit,
510ac193900a7bb9dfae10c0ca4607c224b265afSumit Bose list_ctx->path_count + entries);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek } else {
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio capacity = entries;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncioimmediately:
510ac193900a7bb9dfae10c0ca4607c224b265afSumit Bose list_ctx->paths_max = list_ctx->path_count + capacity;
510ac193900a7bb9dfae10c0ca4607c224b265afSumit Bose list_ctx->paths = talloc_realloc(list_ctx, list_ctx->paths, const char *,
510ac193900a7bb9dfae10c0ca4607c224b265afSumit Bose list_ctx->paths_max);
b0b9222f7dd62b19ec702afe295ec71624888e87Fabiano Fidêncio if (list_ctx->paths == NULL) {
b0b9222f7dd62b19ec702afe295ec71624888e87Fabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero_array() failed\n");
b0b9222f7dd62b19ec702afe295ec71624888e87Fabiano Fidêncio ret = ENOMEM;
b0b9222f7dd62b19ec702afe295ec71624888e87Fabiano Fidêncio goto done;
b0b9222f7dd62b19ec702afe295ec71624888e87Fabiano Fidêncio }
510ac193900a7bb9dfae10c0ca4607c224b265afSumit Bose for (c = list_ctx->path_count; c < list_ctx->paths_max; c++) {
510ac193900a7bb9dfae10c0ca4607c224b265afSumit Bose list_ctx->paths[c] = NULL;
510ac193900a7bb9dfae10c0ca4607c224b265afSumit Bose }
b0b9222f7dd62b19ec702afe295ec71624888e87Fabiano Fidêncio
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio *_capacity = capacity;
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio ret = EOK;
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidênciodone:
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio return ret;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek}
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozekerrno_t ifp_ldb_el_output_name(struct resp_ctx *rctx,
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek struct ldb_message *msg,
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek const char *el_name,
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek struct sss_domain_info *dom)
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek{
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek struct ldb_message_element *el;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek char *in_name;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek char *out_name;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek errno_t ret;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek char *name;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek TALLOC_CTX *tmp_ctx;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek el = ldb_msg_find_element(msg, el_name);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek if (el == NULL) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek return EOK;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek tmp_ctx = talloc_new(NULL);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek if (tmp_ctx == NULL) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek return ENOMEM;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek for (size_t c = 0; c < el->num_values; c++) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek in_name = (char *) el->values[c].data;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek ret = sss_parse_internal_fqname(tmp_ctx, in_name, &name, NULL);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek if (ret != EOK) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek goto done;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek out_name = sss_output_name(tmp_ctx, in_name, dom->case_preserve,
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek rctx->override_space);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek if (out_name == NULL) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek ret = EIO;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek goto done;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek if (dom->fqnames) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek out_name = sss_tc_fqname(tmp_ctx, dom->names, dom, out_name);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek if (out_name == NULL) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "sss_tc_fqname failed\n");
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek ret = ENOMEM;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek goto done;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek talloc_free(el->values[c].data);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek el->values[c].data = (uint8_t *) talloc_steal(el->values, out_name);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek el->values[c].length = strlen(out_name);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek ret = EOK;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozekdone:
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek talloc_free(tmp_ctx);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek return ret;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek}
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozekchar *ifp_format_name_attr(TALLOC_CTX *mem_ctx, struct ifp_ctx *ifp_ctx,
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek const char *in_name, struct sss_domain_info *dom)
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek{
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek TALLOC_CTX *tmp_ctx;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek char *out_name;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek char *ret_name = NULL;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek char *shortname;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek errno_t ret;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek tmp_ctx = talloc_new(NULL);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek if (tmp_ctx == NULL) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek return NULL;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek ret = sss_parse_internal_fqname(tmp_ctx, in_name, &shortname, NULL);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek if (ret != EOK) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Unparseable name %s\n", in_name);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek goto done;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek out_name = sss_output_name(tmp_ctx, in_name, dom->case_preserve,
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek ifp_ctx->rctx->override_space);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek if (out_name == NULL) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek goto done;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek if (dom->fqnames) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek out_name = sss_tc_fqname(tmp_ctx, dom->names, dom, out_name);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek if (out_name == NULL) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "sss_tc_fqname failed\n");
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek goto done;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek ret_name = talloc_steal(mem_ctx, out_name);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozekdone:
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek talloc_free(tmp_ctx);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek return ret_name;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek}