dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina Pavel Březina <pbrezina@redhat.com>
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina Copyright (C) 2016 Red Hat
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina This program is free software; you can redistribute it and/or modify
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina it under the terms of the GNU General Public License as published by
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina the Free Software Foundation; either version 3 of the License, or
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina (at your option) any later version.
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina This program is distributed in the hope that it will be useful,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina GNU General Public License for more details.
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina You should have received a copy of the GNU General Public License
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina#include "providers/data_provider/dp_private.h"
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina#define FILTER_TYPE(str, type) {str "=", sizeof(str "=") - 1, type}
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic bool check_attr_type(uint32_t attr_type)
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return false;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return false;
3d29430867cf92b2d71afa95abb679711231117cPavel Březinastatic bool check_and_parse_filter(struct dp_id_data *data,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* We will use sizeof() to determine the length of a string so we don't
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina * call strlen over and over again with each request. Not a bottleneck,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina * but unnecessary and simple to avoid. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina static struct {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina } types[] = {FILTER_TYPE("name", BE_FILTER_NAME),
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return false;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (strncmp(filter, types[i].name, types[i].lenght) == 0) {
dc30c60f166ad9adc63a47a1013508a71624ac87Petr Cech data->filter_value = SBUS_SET_STRING(&filter[types[i].lenght]);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return false;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic struct dp_initgr_ctx *create_initgr_ctx(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina unsigned int i;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ctx = talloc_zero(mem_ctx, struct dp_initgr_ctx);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina username = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_NAME, NULL);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ctx->groups = talloc_array(mem_ctx, uint32_t, res->count);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* The first GID is the primary so it might be duplicated
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina * later in the list. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina for (ctx->gnum = 0, i = 0; i < res->count; i++) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ctx->groups[ctx->gnum] = ldb_msg_find_attr_as_uint(res->msgs[i],
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* If 0 it may be a non-posix group, so we skip it. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic void dp_req_initgr_pp(const char *req_name,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory?!\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory?!\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Ordering NSS responder to update memory cache\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina sbus_conn_send_reply(dp_client_conn(dp_cli), msg);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic errno_t dp_initgroups(struct sbus_request *sbus_req,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina const char *key,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina domain = find_domain_by_name(be_ctx->domain, data->domain, true);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = sysdb_initgroups(sbus_req, domain, data->filter_value, &res);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (ret == ENOENT || (ret == EOK && res->count == 0)) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* There is no point in concacting NSS responder. Proceed as usual. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get initgroups [%d]: %s\n",
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ctx = create_initgr_ctx(sbus_req, data->domain, res);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_req_with_reply_pp(dp_cli, data->domain, "Initgroups", key,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina sbus_req, DPT_ID, DPM_ACCOUNT_HANDLER, dp_flags, data,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaerrno_t dp_get_account_info_handler(struct sbus_request *sbus_req,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina data = talloc_zero(sbus_req, struct dp_id_data);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (!check_and_parse_filter(data, filter, extra)) {
806f65f3c90dc0f7921932494228ad93f3ed3027Lukas Slebodnik "Got request for [%#"PRIx32"][%s][%"PRId32"][%s]\n",
806f65f3c90dc0f7921932494228ad93f3ed3027Lukas Slebodnik data->entry_type, be_req2str(data->entry_type),
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina key = talloc_asprintf(data, "%u:%u:%s:%s:%s", data->entry_type,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if ((data->entry_type & BE_REQ_TYPE_MASK) == BE_REQ_INITGROUPS) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = dp_initgroups(sbus_req, dp_cli, key, dp_flags, data);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_req_with_reply(dp_cli, domain, "Account", key,