dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina/*
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina Authors:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina Pavel Březina <pbrezina@redhat.com>
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina Copyright (C) 2016 Red Hat
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
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
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
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*/
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina#include <talloc.h>
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina#include <tevent.h>
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina#include "sbus/sssd_dbus.h"
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina#include "providers/data_provider/dp_private.h"
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina#include "providers/data_provider/dp_iface.h"
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina#include "providers/backend.h"
04e870d99e72aa3160bdb6ab05d986fb4005c3edPavel Březina#include "responder/nss/nss_iface.h"
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina#include "util/util.h"
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina#define FILTER_TYPE(str, type) {str "=", sizeof(str "=") - 1, type}
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
3d29430867cf92b2d71afa95abb679711231117cPavel Březinastatic bool check_and_parse_filter(struct dp_id_data *data,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina const char *filter,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina const char *extra)
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina{
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 const char *name;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina size_t lenght;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina uint32_t type;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina } types[] = {FILTER_TYPE("name", BE_FILTER_NAME),
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina FILTER_TYPE("idnumber", BE_FILTER_IDNUM),
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina FILTER_TYPE(DP_SEC_ID, BE_FILTER_SECID),
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina FILTER_TYPE(DP_CERT, BE_FILTER_CERT),
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina FILTER_TYPE(DP_WILDCARD, BE_FILTER_WILDCARD),
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {0, 0, 0}};
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina int i;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dc30c60f166ad9adc63a47a1013508a71624ac87Petr Cech if (SBUS_IS_STRING_EMPTY(filter)) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return false;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina for (i = 0; types[i].name != NULL; i++) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (strncmp(filter, types[i].name, types[i].lenght) == 0) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina data->filter_type = types[i].type;
dc30c60f166ad9adc63a47a1013508a71624ac87Petr Cech data->filter_value = SBUS_SET_STRING(&filter[types[i].lenght]);
dc30c60f166ad9adc63a47a1013508a71624ac87Petr Cech data->extra_value = SBUS_SET_STRING(extra);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return true;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (strcmp(filter, ENUM_INDICATOR) == 0) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina data->filter_type = BE_FILTER_ENUM;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina data->filter_value = NULL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina data->extra_value = NULL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return true;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return false;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina}
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastruct dp_initgr_ctx {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina const char *domain;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct sss_domain_info *domain_info;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov const char *filter_value;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov const char *username;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina uint32_t gnum;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina uint32_t *groups;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina};
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashovstatic struct dp_initgr_ctx *create_initgr_ctx(
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov TALLOC_CTX *mem_ctx,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov const char *domain,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct sss_domain_info *domain_info,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov const char *filter_value,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct ldb_result *res)
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_initgr_ctx *ctx;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina const char *username;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina unsigned int i;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina errno_t ret;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ctx = talloc_zero(mem_ctx, struct dp_initgr_ctx);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (ctx == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return NULL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* Copy domain name */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ctx->domain = talloc_strdup(ctx, domain);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (ctx->domain == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = ENOMEM;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto done;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* Copy filter value */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ctx->filter_value = talloc_strdup(ctx, filter_value);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (ctx->filter_value == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = ENOMEM;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto done;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* Reference domain info */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ctx->domain_info = domain_info;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* If we had the data in sysdb */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (res != NULL) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* Copy original username */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov username = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_NAME, NULL);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (username == NULL) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ret = EINVAL;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov goto done;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ctx->username = talloc_strdup(ctx, username);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (ctx->username == NULL) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ret = ENOMEM;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov goto done;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* Copy group IDs */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ctx->groups = talloc_array(mem_ctx, uint32_t, res->count);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (ctx->groups == NULL) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ret = ENOMEM;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov goto done;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* The first GID is the primary so it might be duplicated
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov * later in the list. */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov for (ctx->gnum = 0, i = 0; i < res->count; i++) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ctx->groups[ctx->gnum] = ldb_msg_find_attr_as_uint(res->msgs[i],
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov SYSDB_GIDNUM, 0);
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz /* If 0 it may be a non-POSIX group, so we skip it. */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (ctx->groups[ctx->gnum] != 0) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ctx->gnum++;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = EOK;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinadone:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (ret != EOK) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina talloc_free(ctx);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return NULL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return ctx;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina}
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashovstatic void dp_req_initgr_pp_nss_notify(const char *req_name,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct data_provider *provider,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct dp_initgr_ctx *ctx)
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_client *dp_cli;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DBusMessage *msg;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dbus_bool_t dbret;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina int num;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* If user didn't exist in the cache previously */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (ctx->username == NULL) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* There is no point in contacting NSS responder */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov return;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_cli = provider->clients[DPC_NSS];
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (dp_cli == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina msg = dbus_message_new_method_call(NULL,
04e870d99e72aa3160bdb6ab05d986fb4005c3edPavel Březina NSS_MEMORYCACHE_PATH,
04e870d99e72aa3160bdb6ab05d986fb4005c3edPavel Březina IFACE_NSS_MEMORYCACHE,
04e870d99e72aa3160bdb6ab05d986fb4005c3edPavel Březina IFACE_NSS_MEMORYCACHE_UPDATEINITGROUPS);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (msg == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory?!\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina num = ctx->gnum;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dbret = dbus_message_append_args(msg,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DBUS_TYPE_STRING, &ctx->username,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DBUS_TYPE_STRING, &ctx->domain,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina &ctx->groups, num,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DBUS_TYPE_INVALID);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (!dbret) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory?!\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dbus_message_unref(msg);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_TRACE_FUNC,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "Ordering NSS responder to update memory cache\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina sbus_conn_send_reply(dp_client_conn(dp_cli), msg);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dbus_message_unref(msg);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina}
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashovstatic void dp_req_initgr_pp_sr_overlay(struct data_provider *provider,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct dp_initgr_ctx *ctx)
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov{
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov bool enabled = false;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct be_ctx *be = provider->be_ctx;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct ldb_result *res;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct ldb_message *msg;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov const char *name;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov char *output_name;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov char **conf_user;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov char **conf_group;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov size_t i;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov TALLOC_CTX *tmp_ctx = NULL;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov errno_t ret;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct ldb_message_element el = { 0, SYSDB_SESSION_RECORDING, 0, NULL };
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct sysdb_attrs del_attrs = { 1, &el };
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct sysdb_attrs *add_attrs;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* If selective session recording is not enabled */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (be->sr_conf.scope != SESSION_RECORDING_SCOPE_SOME) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov goto done;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* Allocate temporary talloc context */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov tmp_ctx = talloc_new(NULL);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (tmp_ctx == NULL) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov "Failed creating temporary talloc context\n");
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ret = ENOMEM;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov goto done;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* Get updated initgroups data with overrides */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ret = sysdb_initgroups_with_views(tmp_ctx, ctx->domain_info,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ctx->filter_value, &res);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (ret == ENOENT || (ret == EOK && res->count == 0)) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov goto done;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov } else if (ret != EOK) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get initgroups: %s\n",
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov sss_strerror(ret));
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov goto done;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* Delete sessionRecording attribute so we know when we failed */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ret = sysdb_set_entry_attr(ctx->domain_info->sysdb, res->msgs[0]->dn,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov &del_attrs, SYSDB_MOD_DEL);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (ret != EOK) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov "Failed removing %s attribute: %s\n",
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov SYSDB_SESSION_RECORDING, sss_strerror(ret));
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov goto done;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* Format output username */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov name = sss_get_name_from_msg(ctx->domain_info, res->msgs[0]);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ret = sss_output_fqname(tmp_ctx, ctx->domain_info, name,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov be->override_space, &output_name);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (ret != EOK) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov "Failed formatting output username from \"%s\": %s\n",
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov name, sss_strerror(ret));
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov goto done;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* For each user name in session recording config */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov conf_user = be->sr_conf.users;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (conf_user != NULL) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov for (; *conf_user != NULL && !enabled; conf_user++) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* If it matches the requested user name */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (strcmp(*conf_user, output_name) == 0) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov enabled = true;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* If we have groups in config and are not yet enabled */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (be->sr_conf.groups != NULL &&
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov be->sr_conf.groups[0] != NULL &&
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov !enabled) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* For each group in response */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov for (i = 0; i < res->count && !enabled; i++) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* Get the group msg */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (i == 0) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov gid_t gid;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct ldb_result *group_res;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* Get the primary group */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov gid = sss_view_ldb_msg_find_attr_as_uint64(ctx->domain_info,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov res->msgs[i],
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov SYSDB_GIDNUM, 0);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (gid == 0) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov continue;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ret = sysdb_getgrgid_with_views(tmp_ctx, ctx->domain_info,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov gid, &group_res);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (ret == ENOENT) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov continue;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov } else if (ret != EOK) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov "Failed retrieving group #%llu: %s\n",
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov (unsigned long long)gid, sss_strerror(ret));
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov goto done;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov } else if (group_res->count == 0) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov continue;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov msg = group_res->msgs[0];
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov } else {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov msg = res->msgs[i];
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* Get the group's output name */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov name = sss_get_name_from_msg(ctx->domain_info, msg);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (name == NULL) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov continue;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ret = sss_output_fqname(tmp_ctx, ctx->domain_info,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov name, be->override_space,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov &output_name);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (ret != EOK) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov "Failed formatting output group name from \"%s\": %s\n",
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov name, sss_strerror(ret));
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov goto done;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* For each group in configuration */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov for (conf_group = be->sr_conf.groups;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov *conf_group != NULL && !enabled;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov conf_group++) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (strcmp(*conf_group, output_name) == 0) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov enabled = true;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov /* Set sessionRecording attribute to enabled value */
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov add_attrs = sysdb_new_attrs(tmp_ctx);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (add_attrs == NULL) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov "Failed creating attributes\n");
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ret = ENOMEM;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov goto done;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ret = sysdb_attrs_add_bool(add_attrs, SYSDB_SESSION_RECORDING, enabled);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (ret != EOK) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov "Failed setting %s attribute: %s\n",
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov SYSDB_SESSION_RECORDING, sss_strerror(ret));
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov goto done;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ret = sysdb_set_entry_attr(ctx->domain_info->sysdb, res->msgs[0]->dn,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov add_attrs, SYSDB_MOD_ADD);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov if (ret != EOK) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov "Failed storing %s attribute: %s\n",
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov SYSDB_SESSION_RECORDING, sss_strerror(ret));
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov goto done;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov }
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashovdone:
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov talloc_free(tmp_ctx);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov}
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashovstatic void dp_req_initgr_pp(const char *req_name,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct data_provider *provider,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct dp_initgr_ctx *ctx,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct dp_reply_std *reply)
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov{
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov (void)reply;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov dp_req_initgr_pp_nss_notify(req_name, provider, ctx);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov dp_req_initgr_pp_sr_overlay(provider, ctx);
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov}
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic errno_t dp_initgroups(struct sbus_request *sbus_req,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_client *dp_cli,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina const char *key,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina uint32_t dp_flags,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *data)
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct be_ctx *be_ctx;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct sss_domain_info *domain;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_initgr_ctx *ctx;
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov struct ldb_result *res = NULL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina errno_t ret;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
2f18b8d67c86a1a277b59894f24ea6e09b41b7eaPavel Březina be_ctx = dp_client_be(dp_cli);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (data->domain == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina domain = be_ctx->domain;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina } else {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina domain = find_domain_by_name(be_ctx->domain, data->domain, true);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (domain == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return ERR_DOMAIN_NOT_FOUND;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = sysdb_initgroups(sbus_req, domain, data->filter_value, &res);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (ret == ENOENT || (ret == EOK && res->count == 0)) {
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov talloc_zfree(res);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina } else if (ret != EOK) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get initgroups [%d]: %s\n",
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret, sss_strerror(ret));
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto done;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov ctx = create_initgr_ctx(sbus_req, data->domain, domain,
24b3a7b91a54b5b55cfddb52b3d5ac565afdcff1Nikolai Kondrashov data->filter_value, res);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (ctx == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = ENOMEM;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto done;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
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řezina dp_req_initgr_pp, ctx, struct dp_initgr_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_req_reply_std, struct dp_reply_std);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = EOK;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinadone:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina talloc_free(res);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return ret;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina}
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaerrno_t dp_get_account_info_handler(struct sbus_request *sbus_req,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina void *dp_cli,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina uint32_t dp_flags,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina uint32_t entry_type,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina const char *filter,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina const char *domain,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina const char *extra)
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina{
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *data;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina const char *key;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina errno_t ret;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
3d29430867cf92b2d71afa95abb679711231117cPavel Březina data = talloc_zero(sbus_req, struct dp_id_data);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (data == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return ENOMEM;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina data->entry_type = entry_type;
a9aa70887985d37985093f1299fc15b2e060b2a0Pavel Březina data->domain = domain;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (!check_and_parse_filter(data, filter, extra)) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = EINVAL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto done;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
806f65f3c90dc0f7921932494228ad93f3ed3027Lukas Slebodnik DEBUG(SSSDBG_FUNC_DATA,
ca68b1b4ba06b1cda316ae8af470647bd7015a5aLukas Slebodnik "Got request for [%#"PRIx32"][%s][%s]\n",
806f65f3c90dc0f7921932494228ad93f3ed3027Lukas Slebodnik data->entry_type, be_req2str(data->entry_type),
ca68b1b4ba06b1cda316ae8af470647bd7015a5aLukas Slebodnik filter);
806f65f3c90dc0f7921932494228ad93f3ed3027Lukas Slebodnik
ca68b1b4ba06b1cda316ae8af470647bd7015a5aLukas Slebodnik key = talloc_asprintf(data, "%u:%s:%s:%s", data->entry_type,
ca68b1b4ba06b1cda316ae8af470647bd7015a5aLukas Slebodnik extra, domain, filter);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (key == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = ENOMEM;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto done;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if ((data->entry_type & BE_REQ_TYPE_MASK) == BE_REQ_INITGROUPS) {
6a611406e805a1707ca0b9e86b6aa96e02e43eccPavel Březina ret = dp_initgroups(sbus_req, dp_cli, key, dp_flags, data);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (ret != EAGAIN) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto done;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_req_with_reply(dp_cli, domain, "Account", key,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina sbus_req, DPT_ID, DPM_ACCOUNT_HANDLER, dp_flags, data,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_req_reply_std, struct dp_reply_std);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = EOK;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinadone:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (ret != EOK) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina talloc_free(data);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return ret;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina}
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozekstatic bool
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozekcheck_and_parse_acct_domain_filter(struct dp_get_acct_domain_data *data,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek const char *filter)
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek{
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek /* We will use sizeof() to determine the length of a string so we don't
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek * call strlen over and over again with each request. Not a bottleneck,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek * but unnecessary and simple to avoid. */
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek static struct {
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek const char *name;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek size_t lenght;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek uint32_t type;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek } types[] = {FILTER_TYPE("idnumber", BE_FILTER_IDNUM),
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek {0, 0, 0}};
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek int i;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek if (SBUS_IS_STRING_EMPTY(filter)) {
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek return false;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek }
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek for (i = 0; types[i].name != NULL; i++) {
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek if (strncmp(filter, types[i].name, types[i].lenght) == 0) {
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek data->filter_type = types[i].type;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek data->filter_value = SBUS_SET_STRING(&filter[types[i].lenght]);
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek return true;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek }
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek }
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek if (strcmp(filter, ENUM_INDICATOR) == 0) {
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek data->filter_type = BE_FILTER_ENUM;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek data->filter_value = NULL;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek return true;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek }
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek return false;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek}
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozekerrno_t dp_get_account_domain_handler(struct sbus_request *sbus_req,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek void *dp_cli,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek uint32_t entry_type,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek const char *filter)
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek{
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek struct dp_get_acct_domain_data *data;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek const char *key = NULL;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek errno_t ret;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek data = talloc_zero(sbus_req, struct dp_get_acct_domain_data);
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek if (data == NULL) {
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek return ENOMEM;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek }
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek data->entry_type = entry_type;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek if (!check_and_parse_acct_domain_filter(data, filter)) {
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek ret = EINVAL;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek goto done;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek }
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek dp_req_with_reply(dp_cli, NULL, "AccountDomain", key, sbus_req,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek DPT_ID, DPM_ACCT_DOMAIN_HANDLER, 0, data,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek dp_req_reply_std, struct dp_reply_std);
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek ret = EOK;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozekdone:
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek if (ret != EOK) {
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek talloc_free(data);
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek }
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek return ret;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek}
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozekstruct default_account_domain_state {
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek struct dp_reply_std reply;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek};
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozekstruct tevent_req *
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozekdefault_account_domain_send(TALLOC_CTX *mem_ctx,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek void *unused_ctx,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek struct dp_get_acct_domain_data *data,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek struct dp_req_params *params)
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek{
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek struct default_account_domain_state *state;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek struct tevent_req *req;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek req = tevent_req_create(mem_ctx, &state,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek struct default_account_domain_state);
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek if (req == NULL) {
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek return NULL;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek }
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek dp_reply_std_set(&state->reply,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek DP_ERR_DECIDE, ERR_GET_ACCT_DOM_NOT_SUPPORTED,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek NULL);
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek tevent_req_done(req);
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek tevent_req_post(req, params->ev);
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek return req;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek}
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozekerrno_t default_account_domain_recv(TALLOC_CTX *mem_ctx,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek struct tevent_req *req,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek struct dp_reply_std *data)
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek{
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek struct default_account_domain_state *state = NULL;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek state = tevent_req_data(req, struct default_account_domain_state);
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek *data = state->reply;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek return EOK;
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek}