dp.h revision 35fa5a83ce8badf6bc868937047f44c3f32b7c28
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/*
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen Authors:
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen Pavel Březina <pbrezina@redhat.com>
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen Copyright (C) 2016 Red Hat
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
7ab70e15c63c172c1715a40c8ffcff0285b6f05eTimo Sirainen This program is free software; you can redistribute it and/or modify
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen it under the terms of the GNU General Public License as published by
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen the Free Software Foundation; either version 3 of the License, or
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen (at your option) any later version.
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen This program is distributed in the hope that it will be useful,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen GNU General Public License for more details.
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen You should have received a copy of the GNU General Public License
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen along with this program. If not, see <http://www.gnu.org/licenses/>.
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen*/
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen#ifndef _DP_H_
#define _DP_H_
#include <stdint.h>
#include "sbus/sssd_dbus.h"
#include "providers/backend.h"
#include "providers/data_provider/dp_request.h"
#include "providers/data_provider/dp_custom_data.h"
#include "providers/data_provider/dp_flags.h"
struct data_provider;
struct dp_method;
/**
* Module constructor.
*
* It is possible to create a module data that is passed into all
* target initialization functions.
*/
typedef errno_t (*dp_module_init_fn)(TALLOC_CTX *mem_ctx,
struct be_ctx *be_ctx,
struct data_provider *provider,
const char *module_name,
void **_module_data);
/**
* Target initialization function.
*
* Pointer to dp_method is unique for all targets. Make sure that
* dp_set_method is called in all targets even if you are reusing
* some existing context or initialization function.
*/
typedef errno_t (*dp_target_init_fn)(TALLOC_CTX *mem_ctx,
struct be_ctx *be_ctx,
void *module_data,
struct dp_method *dp_methods);
enum dp_targets {
DPT_ID,
DPT_AUTH,
DPT_ACCESS,
DPT_CHPASS,
DPT_SUDO,
DPT_AUTOFS,
DPT_SELINUX,
DPT_HOSTID,
DPT_SUBDOMAINS,
DP_TARGET_SENTINEL
};
enum dp_methods {
DPM_CHECK_ONLINE,
DPM_ACCOUNT_HANDLER,
DPM_AUTH_HANDLER,
DPM_ACCESS_HANDLER,
DPM_SELINUX_HANDLER,
DPM_SUDO_HANDLER,
DPM_AUTOFS_HANDLER,
DPM_HOSTID_HANDLER,
DPM_DOMAINS_HANDLER,
DP_METHOD_SENTINEL
};
/* Method handler. */
struct dp_req_params {
struct tevent_context *ev;
struct be_ctx *be_ctx;
struct sss_domain_info *domain;
enum dp_targets target;
enum dp_methods method;
};
typedef struct tevent_req *
(*dp_req_send_fn)(TALLOC_CTX *mem_ctx, void *method_data, void *request_data,
struct dp_req_params *params);
typedef errno_t
(*dp_req_recv_fn)(TALLOC_CTX *mem_ctx, struct tevent_req *req, void *data);
/* Data provider initialization. */
errno_t dp_init(struct tevent_context *ev,
struct be_ctx *be_ctx,
uid_t uid,
gid_t gid);
bool _dp_target_enabled(struct data_provider *provider,
const char *module_name,
...);
#define dp_target_enabled(provider, module_name, ...) \
_dp_target_enabled(provider, module_name, ##__VA_ARGS__, DP_TARGET_SENTINEL)
struct dp_module *dp_target_module(struct data_provider *provider,
enum dp_targets target);
void *dp_get_module_data(struct dp_module *dp_module);
void _dp_set_method(struct dp_method *methods,
enum dp_methods method,
dp_req_send_fn send_fn,
dp_req_recv_fn recv_fn,
void *method_data,
const char *method_dtype,
const char *request_dtype,
const char *output_dtype,
uint32_t output_size);
/* We check function headers on compile time and data types on run time. This
* check requires that both method and request private data are talloc-created
* with talloc name set to data type name (which is done by talloc unless
* you use _size variations of talloc functions.
*
* This way we ensure that we always pass correct data and we can access them
* directly in request handler without the need to cast them explicitly
* from void pointer. */
#define dp_set_method(methods, method, send_fn, recv_fn, method_data, \
method_dtype, req_dtype, output_dtype) \
do { \
/* Check _send function parameter types. */ \
struct tevent_req *(*__send_fn)(TALLOC_CTX *, method_dtype *, \
req_dtype *, struct dp_req_params *params) = (send_fn); \
\
/* Check _recv function parameter types. */ \
errno_t (*__recv_fn)(TALLOC_CTX *, struct tevent_req *, \
output_dtype *) = (recv_fn); \
_dp_set_method(methods, method, (dp_req_send_fn)__send_fn, \
(dp_req_recv_fn)__recv_fn, method_data, \
#method_dtype, #req_dtype, \
#output_dtype, sizeof(output_dtype)); \
} while (0)
bool dp_method_enabled(struct data_provider *provider,
enum dp_targets target,
enum dp_methods method);
void dp_terminate_domain_requests(struct data_provider *provider,
const char *domain);
#endif /* _DP_H_ */