f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek Stephen Gallagher <sgallagh@redhat.com>
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek Copyright (C) 2013 Red Hat
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek InfoPipe responder: Utility functions
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 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 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/>.
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina#define IFP_USER_DEFAULT_ATTRS {SYSDB_NAME, SYSDB_UIDNUM, \
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozekerrno_t ifp_req_create(struct sbus_request *dbus_req,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Responder not connected to sysbus!\n");
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek /* We got a sysbus message but couldn't identify the
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek * caller? Bail out! */
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek "BUG: Received a message without a known caller!\n");
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek "User %"PRIi64" not in ACL\n", dbus_req->client);
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek "Cannot check if user %"PRIi64" is present in ACL\n",
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozekint ifp_req_create_handle_failure(struct sbus_request *dbus_req, errno_t err)
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek "Cannot create IFP request\n"));
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březinaerrno_t ifp_add_value_to_dict(DBusMessageIter *iter_dict,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina const char *key,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_open_container(iter_dict,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina /* Start by appending the key */
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_append_basic(&iter_dict_entry,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_open_container(&iter_dict_entry,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina /* Open container for values */
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_open_container(&iter_dict_val,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_append_basic(&iter_array,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_close_container(&iter_dict_val,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_close_container(&iter_dict_entry,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina dbret = dbus_message_iter_close_container(iter_dict,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozekerrno_t ifp_add_ldb_el_to_dict(DBusMessageIter *iter_dict,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek unsigned int i;
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_open_container(iter_dict,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek /* Start by appending the key */
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_append_basic(&iter_dict_entry,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_open_container(&iter_dict_entry,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek /* Open container for values */
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_open_container(&iter_dict_val,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek /* Now add all the values */
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "element [%s] has value [%s]\n",
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_append_basic(&iter_array,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_close_container(&iter_dict_val,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_close_container(&iter_dict_entry,
f92ace4a52602e8c38a34f2392bec3deeac2ddddJakub Hrozek dbret = dbus_message_iter_close_container(iter_dict,
770dc892f867639f36f84455d65be6287935a529Jakub Hrozekifp_attr_allowed(const char *whitelist[], const char *attr)
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek return false;
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek for (i = 0; whitelist[i]; i++) {
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek return (whitelist[i]) ? true : false;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinaifp_parse_user_attr_list(TALLOC_CTX *mem_ctx, const char *csv)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina static const char *defaults[] = IFP_USER_DEFAULT_ATTRS;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return parse_attr_list_ex(mem_ctx, csv, defaults);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinaifp_get_user_extra_attributes(TALLOC_CTX *mem_ctx, struct ifp_ctx *ifp_ctx)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char **whitelist = ifp_ctx->user_whitelist;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina /* Just count number of attributes in whitelist. */
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina extra = talloc_zero_array(tmp_ctx, const char *, i + 1);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero_array() failed\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina extra[extra_num] = talloc_strdup(extra, whitelist[i]);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina extra = talloc_realloc(tmp_ctx, extra, const char *, extra_num + 1);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinaifp_is_user_attr_allowed(struct ifp_ctx *ifp_ctx, const char *attr)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return ifp_attr_allowed(ifp_ctx->user_whitelist, attr);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozekstatic uint32_t ifp_list_limit(struct ifp_ctx *ctx, uint32_t limit)
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozekstruct ifp_list_ctx *ifp_list_ctx_new(struct sbus_request *sbus_req,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx = talloc_zero(sbus_req, struct ifp_list_ctx);
510ac193900a7bb9dfae10c0ca4607c224b265afSumit Bose list_ctx->paths = talloc_zero_array(list_ctx, const char *,
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncioerrno_t ifp_list_ctx_remaining_capacity(struct ifp_list_ctx *list_ctx,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek size_t capacity = list_ctx->limit - list_ctx->path_count;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek "IFP list request has limit of %"PRIu32" entries but back end "
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 *,
b0b9222f7dd62b19ec702afe295ec71624888e87Fabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero_array() failed\n");
510ac193900a7bb9dfae10c0ca4607c224b265afSumit Bose for (c = list_ctx->path_count; c < list_ctx->paths_max; c++) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozekerrno_t ifp_ldb_el_output_name(struct resp_ctx *rctx,
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek ret = sss_parse_internal_fqname(tmp_ctx, in_name, &name, NULL);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek out_name = sss_output_name(tmp_ctx, in_name, dom->case_preserve,
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek out_name = sss_tc_fqname(tmp_ctx, dom->names, dom, out_name);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "sss_tc_fqname failed\n");
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek el->values[c].data = (uint8_t *) talloc_steal(el->values, out_name);
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 ret = sss_parse_internal_fqname(tmp_ctx, in_name, &shortname, NULL);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Unparseable name %s\n", in_name);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek out_name = sss_output_name(tmp_ctx, in_name, dom->case_preserve,
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek out_name = sss_tc_fqname(tmp_ctx, dom->names, dom, out_name);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "sss_tc_fqname failed\n");