Line data Source code
1 : /*
2 : Authors:
3 : Pavel Březina <pbrezina@redhat.com>
4 :
5 : Copyright (C) 2016 Red Hat
6 :
7 : This program is free software; you can redistribute it and/or modify
8 : it under the terms of the GNU General Public License as published by
9 : the Free Software Foundation; either version 3 of the License, or
10 : (at your option) any later version.
11 :
12 : This program is distributed in the hope that it will be useful,
13 : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : GNU General Public License for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with this program. If not, see <http://www.gnu.org/licenses/>.
19 : */
20 :
21 : #include <talloc.h>
22 :
23 : #include "config.h"
24 : #include "providers/data_provider/dp.h"
25 : #include "providers/data_provider/dp_private.h"
26 : #include "providers/backend.h"
27 : #include "util/util.h"
28 :
29 4 : void _dp_set_method(struct dp_method *methods,
30 : enum dp_methods method,
31 : dp_req_send_fn send_fn,
32 : dp_req_recv_fn recv_fn,
33 : void *method_data,
34 : const char *method_dtype,
35 : const char *request_dtype,
36 : const char *output_dtype,
37 : uint32_t output_size)
38 : {
39 4 : if (method >= DP_METHOD_SENTINEL) {
40 0 : DEBUG(SSSDBG_CRIT_FAILURE, "Bug: invalid method %d\n", method);
41 0 : return;
42 : }
43 :
44 : /* Each method can be set only once, if we attempt to set it twice it
45 : * is a bug in module initialization. */
46 4 : if (methods[method].send_fn != NULL) {
47 0 : DEBUG(SSSDBG_CRIT_FAILURE, "Bug: method %d is already set!\n", method);
48 0 : return;
49 : }
50 :
51 4 : if (send_fn == NULL || recv_fn == NULL || method_dtype == NULL
52 4 : || request_dtype == NULL || output_dtype == NULL) {
53 0 : DEBUG(SSSDBG_CRIT_FAILURE, "Bug: one or more required parameter was "
54 : "not provided for method %d\n", method);
55 0 : return;
56 : }
57 :
58 4 : methods[method].send_fn = send_fn;
59 4 : methods[method].recv_fn = recv_fn;
60 4 : methods[method].method_data = method_data;
61 :
62 4 : methods[method].method_dtype = method_dtype;
63 4 : methods[method].request_dtype = request_dtype;
64 4 : methods[method].output_dtype = output_dtype;
65 4 : methods[method].output_size = output_size;
66 : }
67 :
68 0 : bool dp_method_enabled(struct data_provider *provider,
69 : enum dp_targets target,
70 : enum dp_methods method)
71 : {
72 : struct dp_target *dp_target;
73 :
74 0 : if (target >= DP_TARGET_SENTINEL || method >= DP_METHOD_SENTINEL) {
75 0 : DEBUG(SSSDBG_CRIT_FAILURE, "Bug: Invalid target or method ID\n");
76 0 : return false;
77 : }
78 :
79 0 : dp_target = provider->targets[target];
80 0 : if (dp_target == NULL || dp_target->initialized == false) {
81 0 : DEBUG(SSSDBG_TRACE_FUNC, "Target %s is not configured\n",
82 : dp_target_to_string(target));
83 0 : return false;
84 : }
85 :
86 0 : if (dp_target->methods[method].send_fn == NULL) {
87 0 : return false;
88 : }
89 :
90 0 : return true;
91 : }
92 :
93 5 : errno_t dp_find_method(struct data_provider *provider,
94 : enum dp_targets target,
95 : enum dp_methods method,
96 : struct dp_method **_execute)
97 : {
98 : struct dp_method *execute;
99 :
100 5 : if (target >= DP_TARGET_SENTINEL || method >= DP_METHOD_SENTINEL) {
101 0 : DEBUG(SSSDBG_CRIT_FAILURE, "Bug: Invalid target or method ID\n");
102 0 : return ERR_INTERNAL;
103 : }
104 :
105 5 : if (!dp_target_initialized(provider->targets, target)) {
106 0 : DEBUG(SSSDBG_CRIT_FAILURE, "Target [%s] is not initialized\n",
107 : dp_target_to_string(target));
108 0 : return ERR_MISSING_DP_TARGET;
109 : }
110 :
111 5 : execute = &provider->targets[target]->methods[method];
112 5 : if (execute->send_fn == NULL || execute->recv_fn == NULL) {
113 0 : DEBUG(SSSDBG_CRIT_FAILURE,
114 : "Bug: Invalid combination of target [%s] and method [%d]\n",
115 : dp_target_to_string(target), method);
116 0 : return ERR_INTERNAL;
117 : }
118 :
119 5 : *_execute = execute;
120 :
121 5 : return EOK;
122 : }
|