d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina/*
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina Authors:
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina Pavel Březina <pbrezina@redhat.com>
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina Copyright (C) 2016 Red Hat
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina This program is free software; you can redistribute it and/or modify
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina it under the terms of the GNU General Public License as published by
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina the Free Software Foundation; either version 3 of the License, or
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina (at your option) any later version.
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina This program is distributed in the hope that it will be useful,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina GNU General Public License for more details.
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina You should have received a copy of the GNU General Public License
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina*/
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina#ifndef _DP_H_
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina#define _DP_H_
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina#include <stdint.h>
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina#include "sbus/sssd_dbus.h"
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina#include "providers/backend.h"
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina#include "providers/data_provider/dp_request.h"
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina#include "providers/data_provider/dp_custom_data.h"
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina#include "providers/data_provider/dp_flags.h"
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinastruct data_provider;
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinastruct dp_method;
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina/**
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina * Module constructor.
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina *
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina * It is possible to create a module data that is passed into all
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina * target initialization functions.
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina */
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinatypedef errno_t (*dp_module_init_fn)(TALLOC_CTX *mem_ctx,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina struct be_ctx *be_ctx,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina struct data_provider *provider,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina const char *module_name,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina void **_module_data);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina/**
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina * Target initialization function.
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina *
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina * Pointer to dp_method is unique for all targets. Make sure that
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina * dp_set_method is called in all targets even if you are reusing
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina * some existing context or initialization function.
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina */
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinatypedef errno_t (*dp_target_init_fn)(TALLOC_CTX *mem_ctx,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina struct be_ctx *be_ctx,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina void *module_data,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina struct dp_method *dp_methods);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinaenum dp_targets {
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPT_ID,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPT_AUTH,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPT_ACCESS,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPT_CHPASS,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPT_SUDO,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPT_AUTOFS,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPT_SELINUX,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPT_HOSTID,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPT_SUBDOMAINS,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio DPT_SESSION,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DP_TARGET_SENTINEL
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina};
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinaenum dp_methods {
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPM_CHECK_ONLINE,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPM_ACCOUNT_HANDLER,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPM_AUTH_HANDLER,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPM_ACCESS_HANDLER,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPM_SELINUX_HANDLER,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPM_SUDO_HANDLER,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPM_AUTOFS_HANDLER,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPM_HOSTID_HANDLER,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DPM_DOMAINS_HANDLER,
f982039c75ec064894deb676ae53ee57de868590Fabiano Fidêncio DPM_SESSION_HANDLER,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek DPM_ACCT_DOMAIN_HANDLER,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
e737cdfa225e0d455c0e574bcb82c2cc16a17d9dPavel Březina DPM_REFRESH_ACCESS_RULES,
e737cdfa225e0d455c0e574bcb82c2cc16a17d9dPavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina DP_METHOD_SENTINEL
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina};
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina/* Method handler. */
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinastruct dp_req_params {
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina struct tevent_context *ev;
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina struct be_ctx *be_ctx;
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina struct sss_domain_info *domain;
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina enum dp_targets target;
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina enum dp_methods method;
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina};
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinatypedef struct tevent_req *
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina(*dp_req_send_fn)(TALLOC_CTX *mem_ctx, void *method_data, void *request_data,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina struct dp_req_params *params);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinatypedef errno_t
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina(*dp_req_recv_fn)(TALLOC_CTX *mem_ctx, struct tevent_req *req, void *data);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina/* Data provider initialization. */
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinaerrno_t dp_init(struct tevent_context *ev,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina struct be_ctx *be_ctx,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina uid_t uid,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina gid_t gid);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinabool _dp_target_enabled(struct data_provider *provider,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina const char *module_name,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina ...);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina#define dp_target_enabled(provider, module_name, ...) \
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina _dp_target_enabled(provider, module_name, ##__VA_ARGS__, DP_TARGET_SENTINEL)
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinastruct dp_module *dp_target_module(struct data_provider *provider,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina enum dp_targets target);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
35fa5a83ce8badf6bc868937047f44c3f32b7c28Sumit Bosevoid *dp_get_module_data(struct dp_module *dp_module);
35fa5a83ce8badf6bc868937047f44c3f32b7c28Sumit Bose
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinavoid _dp_set_method(struct dp_method *methods,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina enum dp_methods method,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina dp_req_send_fn send_fn,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina dp_req_recv_fn recv_fn,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina void *method_data,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina const char *method_dtype,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina const char *request_dtype,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina const char *output_dtype,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina uint32_t output_size);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina/* We check function headers on compile time and data types on run time. This
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina * check requires that both method and request private data are talloc-created
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina * with talloc name set to data type name (which is done by talloc unless
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina * you use _size variations of talloc functions.
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina *
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina * This way we ensure that we always pass correct data and we can access them
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina * directly in request handler without the need to cast them explicitly
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina * from void pointer. */
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina#define dp_set_method(methods, method, send_fn, recv_fn, method_data, \
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina method_dtype, req_dtype, output_dtype) \
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina do { \
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina /* Check _send function parameter types. */ \
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina struct tevent_req *(*__send_fn)(TALLOC_CTX *, method_dtype *, \
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina req_dtype *, struct dp_req_params *params) = (send_fn); \
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina \
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina /* Check _recv function parameter types. */ \
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina errno_t (*__recv_fn)(TALLOC_CTX *, struct tevent_req *, \
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina output_dtype *) = (recv_fn); \
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina _dp_set_method(methods, method, (dp_req_send_fn)__send_fn, \
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina (dp_req_recv_fn)__recv_fn, method_data, \
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina #method_dtype, #req_dtype, \
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina #output_dtype, sizeof(output_dtype)); \
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina } while (0)
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinabool dp_method_enabled(struct data_provider *provider,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina enum dp_targets target,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina enum dp_methods method);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březinavoid dp_terminate_domain_requests(struct data_provider *provider,
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina const char *domain);
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina
b3ee4be9e1794fa823696d70d4958f3b0269939cJakub Hrozekvoid dp_sbus_domain_active(struct data_provider *provider,
b3ee4be9e1794fa823696d70d4958f3b0269939cJakub Hrozek struct sss_domain_info *dom);
b3ee4be9e1794fa823696d70d4958f3b0269939cJakub Hrozekvoid dp_sbus_domain_inconsistent(struct data_provider *provider,
b3ee4be9e1794fa823696d70d4958f3b0269939cJakub Hrozek struct sss_domain_info *dom);
b3ee4be9e1794fa823696d70d4958f3b0269939cJakub Hrozek
af28fa659f7ffcd12ecf8bda64e79cf5dd225651Jakub Hrozekvoid dp_sbus_reset_users_ncache(struct data_provider *provider,
af28fa659f7ffcd12ecf8bda64e79cf5dd225651Jakub Hrozek struct sss_domain_info *dom);
af28fa659f7ffcd12ecf8bda64e79cf5dd225651Jakub Hrozekvoid dp_sbus_reset_groups_ncache(struct data_provider *provider,
af28fa659f7ffcd12ecf8bda64e79cf5dd225651Jakub Hrozek struct sss_domain_info *dom);
af28fa659f7ffcd12ecf8bda64e79cf5dd225651Jakub Hrozek
5007103e82f34e64a0ff3b278797b9fa42ba1ddaJakub Hrozekvoid dp_sbus_reset_users_memcache(struct data_provider *provider);
5007103e82f34e64a0ff3b278797b9fa42ba1ddaJakub Hrozekvoid dp_sbus_reset_groups_memcache(struct data_provider *provider);
5007103e82f34e64a0ff3b278797b9fa42ba1ddaJakub Hrozekvoid dp_sbus_reset_initgr_memcache(struct data_provider *provider);
709c42f0cabc96d0e0edf72753a0967593206ff4Fabiano Fidênciovoid dp_sbus_invalidate_group_memcache(struct data_provider *provider,
709c42f0cabc96d0e0edf72753a0967593206ff4Fabiano Fidêncio gid_t gid);
5007103e82f34e64a0ff3b278797b9fa42ba1ddaJakub Hrozek
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek/*
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek * A dummy handler for DPM_ACCT_DOMAIN_HANDLER.
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek *
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek * Its purpose is to always return ERR_GET_ACCT_DOM_NOT_SUPPORTED
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek * which the responder should evaluate as "this back end does not
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek * support locating entries' domain" and never call
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek * DPM_ACCT_DOMAIN_HANDLER again
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek *
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek * This request cannot fail, except for critical errors like OOM.
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 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
d3dee2a07f1a8ee9ae6f94e149ced754ef76c248Pavel Březina#endif /* _DP_H_ */