Line data Source code
1 : /*
2 : Authors:
3 : Jakub Hrozek <jhrozek@redhat.com>
4 :
5 : Copyright (C) 2013 Red Hat
6 :
7 : InfoPipe responder: the responder commands
8 :
9 : This program is free software; you can redistribute it and/or modify
10 : it under the terms of the GNU General Public License as published by
11 : the Free Software Foundation; either version 3 of the License, or
12 : (at your option) any later version.
13 :
14 : This program is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU General Public License for more details.
18 :
19 : You should have received a copy of the GNU General Public License
20 : along with this program. If not, see <http://www.gnu.org/licenses/>.
21 : */
22 :
23 : #include "db/sysdb.h"
24 :
25 : #include "responder/ifp/ifp_private.h"
26 : #include "responder/common/responder_cache_req.h"
27 :
28 : struct ifp_attr_req {
29 : const char *name;
30 : const char **attrs;
31 : int nattrs;
32 :
33 : struct ifp_req *ireq;
34 : };
35 :
36 : static struct tevent_req *
37 : ifp_user_get_attr_send(TALLOC_CTX *mem_ctx, struct resp_ctx *rctx,
38 : struct sss_nc_ctx *ncache, int neg_timeout,
39 : enum sss_dp_acct_type search_type,
40 : const char *inp, const char **attrs);
41 : static errno_t ifp_user_get_attr_recv(TALLOC_CTX *mem_ctx,
42 : struct tevent_req *req,
43 : struct ldb_result **_res,
44 : struct sss_domain_info **_domain);
45 :
46 : static void ifp_user_get_attr_process(struct tevent_req *req);
47 :
48 : static errno_t
49 : ifp_user_get_attr_handle_reply(struct sss_domain_info *domain,
50 : struct ifp_req *ireq,
51 : const char **attrs,
52 : struct ldb_result *res);
53 : static errno_t
54 : ifp_user_get_attr_unpack_msg(struct ifp_attr_req *attr_req);
55 :
56 0 : int ifp_user_get_attr(struct sbus_request *dbus_req, void *data)
57 : {
58 : errno_t ret;
59 : struct ifp_req *ireq;
60 : struct ifp_ctx *ifp_ctx;
61 : struct ifp_attr_req *attr_req;
62 : struct tevent_req *req;
63 :
64 0 : DEBUG(SSSDBG_IMPORTANT_INFO, "GetUserAttr is deprecated, please consider "
65 : "switching to org.freedesktop.sssd.infopipe.Users.User interface\n");
66 :
67 0 : ifp_ctx = talloc_get_type(data, struct ifp_ctx);
68 0 : if (ifp_ctx == NULL) {
69 0 : DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
70 0 : return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
71 : }
72 :
73 0 : ret = ifp_req_create(dbus_req, ifp_ctx, &ireq);
74 0 : if (ret != EOK) {
75 0 : return ifp_req_create_handle_failure(dbus_req, ret);
76 : }
77 :
78 0 : attr_req = talloc_zero(ireq, struct ifp_attr_req);
79 0 : if (attr_req == NULL) {
80 0 : return sbus_request_finish(dbus_req, NULL);
81 : }
82 0 : attr_req->ireq = ireq;
83 :
84 0 : ret = ifp_user_get_attr_unpack_msg(attr_req);
85 0 : if (ret != EOK) {
86 0 : return ret; /* handled internally */
87 : }
88 :
89 0 : DEBUG(SSSDBG_FUNC_DATA,
90 : "Looking up attributes of user [%s] on behalf of %"PRIi64"\n",
91 : attr_req->name, ireq->dbus_req->client);
92 :
93 0 : req = ifp_user_get_attr_send(ireq, ifp_ctx->rctx,
94 : ifp_ctx->ncache, ifp_ctx->neg_timeout,
95 : SSS_DP_USER,
96 : attr_req->name, attr_req->attrs);
97 0 : if (req == NULL) {
98 0 : return sbus_request_finish(dbus_req, NULL);
99 : }
100 0 : tevent_req_set_callback(req, ifp_user_get_attr_process, attr_req);
101 0 : return EOK;
102 : }
103 :
104 : static errno_t
105 0 : ifp_user_get_attr_unpack_msg(struct ifp_attr_req *attr_req)
106 : {
107 : bool parsed;
108 : char **attrs;
109 : int nattrs;
110 : int i, ai;
111 0 : const char **whitelist = attr_req->ireq->ifp_ctx->user_whitelist;
112 :
113 0 : parsed = sbus_request_parse_or_finish(attr_req->ireq->dbus_req,
114 : DBUS_TYPE_STRING, &attr_req->name,
115 : DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
116 : &attrs, &nattrs,
117 : DBUS_TYPE_INVALID);
118 0 : if (parsed == false) {
119 0 : DEBUG(SSSDBG_OP_FAILURE, "Could not parse arguments\n");
120 0 : return EOK; /* handled */
121 : }
122 :
123 : /* Copy the attributes to maintain memory hierarchy with talloc */
124 0 : attr_req->attrs = talloc_zero_array(attr_req, const char *, nattrs+1);
125 0 : if (attr_req->attrs == NULL) {
126 0 : return ENOMEM;
127 : }
128 :
129 0 : ai = 0;
130 0 : for (i = 0; i < nattrs; i++) {
131 0 : if (ifp_attr_allowed(whitelist, attrs[i]) == false) {
132 0 : DEBUG(SSSDBG_MINOR_FAILURE,
133 : "Attribute %s not present in the whitelist, skipping\n",
134 : attrs[i]);
135 0 : continue;
136 : }
137 :
138 0 : attr_req->attrs[ai] = talloc_strdup(attr_req->attrs, attrs[i]);
139 0 : if (attr_req->attrs[ai] == NULL) {
140 0 : return ENOMEM;
141 : }
142 0 : ai++;
143 : }
144 :
145 0 : return EOK;
146 : }
147 :
148 0 : static void ifp_user_get_attr_process(struct tevent_req *req)
149 : {
150 : struct ifp_attr_req *attr_req;
151 : errno_t ret;
152 0 : struct ldb_result *res = NULL;
153 0 : struct sss_domain_info *dom = NULL;
154 :
155 0 : attr_req = tevent_req_callback_data(req, struct ifp_attr_req);
156 :
157 0 : ret = ifp_user_get_attr_recv(attr_req, req, &res, &dom);
158 0 : talloc_zfree(req);
159 0 : if (ret == ENOENT) {
160 0 : sbus_request_fail_and_finish(attr_req->ireq->dbus_req,
161 0 : sbus_error_new(attr_req->ireq->dbus_req,
162 : DBUS_ERROR_FAILED,
163 : "No such user\n"));
164 0 : return;
165 0 : } else if (ret != EOK) {
166 0 : sbus_request_fail_and_finish(attr_req->ireq->dbus_req,
167 0 : sbus_error_new(attr_req->ireq->dbus_req,
168 : DBUS_ERROR_FAILED,
169 : "Failed to read user attribute\n"));
170 0 : return;
171 : }
172 :
173 0 : ret = ifp_user_get_attr_handle_reply(dom, attr_req->ireq,
174 : attr_req->attrs, res);
175 0 : if (ret != EOK) {
176 0 : sbus_request_fail_and_finish(attr_req->ireq->dbus_req,
177 0 : sbus_error_new(attr_req->ireq->dbus_req,
178 : DBUS_ERROR_FAILED,
179 : "Failed to build a reply\n"));
180 0 : return;
181 : }
182 : }
183 :
184 : static errno_t
185 0 : ifp_user_get_attr_replace_space(TALLOC_CTX *mem_ctx,
186 : struct ldb_message_element *el,
187 : const char sub)
188 : {
189 : int i;
190 :
191 0 : for (i = 0; i < el->num_values; i++) {
192 0 : el->values[i].data = (uint8_t *) sss_replace_space(mem_ctx,
193 0 : (const char *) el->values[i].data,
194 : sub);
195 0 : if (el->values[i].data == NULL) {
196 0 : DEBUG(SSSDBG_CRIT_FAILURE, "sss_replace_space failed, skipping\n");
197 0 : return ENOMEM;
198 : }
199 : }
200 :
201 0 : return EOK;
202 : }
203 :
204 : static errno_t
205 0 : ifp_user_get_attr_handle_reply(struct sss_domain_info *domain,
206 : struct ifp_req *ireq,
207 : const char **attrs,
208 : struct ldb_result *res)
209 : {
210 : errno_t ret;
211 : dbus_bool_t dbret;
212 : DBusMessage *reply;
213 : DBusMessageIter iter;
214 : DBusMessageIter iter_dict;
215 : struct ldb_message_element *el;
216 : int ai;
217 :
218 : /* Construct a reply */
219 0 : reply = dbus_message_new_method_return(ireq->dbus_req->message);
220 0 : if (!reply) {
221 0 : return sbus_request_finish(ireq->dbus_req, NULL);
222 : }
223 :
224 0 : dbus_message_iter_init_append(reply, &iter);
225 :
226 0 : dbret = dbus_message_iter_open_container(
227 : &iter, DBUS_TYPE_ARRAY,
228 : DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
229 : DBUS_TYPE_STRING_AS_STRING
230 : DBUS_TYPE_VARIANT_AS_STRING
231 : DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
232 : &iter_dict);
233 0 : if (!dbret) {
234 0 : return sbus_request_finish(ireq->dbus_req, NULL);
235 : }
236 :
237 0 : if (res->count > 0) {
238 0 : for (ai = 0; attrs[ai]; ai++) {
239 0 : el = sss_view_ldb_msg_find_element(domain, res->msgs[0], attrs[ai]);
240 0 : if (el == NULL || el->num_values == 0) {
241 0 : DEBUG(SSSDBG_MINOR_FAILURE,
242 : "Attribute %s not present or has no values\n",
243 : attrs[ai]);
244 0 : continue;
245 : }
246 :
247 : /* Normalize white space in user names */
248 0 : if (ireq->ifp_ctx->rctx->override_space != '\0' &&
249 0 : strcmp(attrs[ai], SYSDB_NAME) == 0) {
250 0 : ret = ifp_user_get_attr_replace_space(ireq, el,
251 0 : ireq->ifp_ctx->rctx->override_space);
252 0 : if (ret != EOK) {
253 0 : DEBUG(SSSDBG_MINOR_FAILURE, "Cannot normalize %s\n",
254 : attrs[ai]);
255 0 : continue;
256 : }
257 : }
258 :
259 0 : ret = ifp_add_ldb_el_to_dict(&iter_dict, el);
260 0 : if (ret != EOK) {
261 0 : DEBUG(SSSDBG_MINOR_FAILURE,
262 : "Cannot add attribute %s to message\n",
263 : attrs[ai]);
264 0 : continue;
265 : }
266 : }
267 : }
268 :
269 0 : dbret = dbus_message_iter_close_container(&iter, &iter_dict);
270 0 : if (!dbret) {
271 0 : return sbus_request_finish(ireq->dbus_req, NULL);
272 : }
273 :
274 0 : return sbus_request_finish(ireq->dbus_req, reply);
275 : }
276 :
277 : static void ifp_user_get_groups_process(struct tevent_req *req);
278 : static errno_t ifp_user_get_groups_reply(struct sss_domain_info *domain,
279 : struct ifp_req *ireq,
280 : struct ldb_result *res);
281 :
282 0 : int ifp_user_get_groups(struct sbus_request *dbus_req,
283 : void *data, const char *arg_user)
284 : {
285 : struct ifp_req *ireq;
286 : struct ifp_ctx *ifp_ctx;
287 : struct ifp_attr_req *group_req;
288 : struct tevent_req *req;
289 : errno_t ret;
290 :
291 0 : ifp_ctx = talloc_get_type(data, struct ifp_ctx);
292 0 : if (ifp_ctx == NULL) {
293 0 : DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
294 0 : return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
295 : }
296 :
297 0 : ret = ifp_req_create(dbus_req, ifp_ctx, &ireq);
298 0 : if (ret != EOK) {
299 0 : return ifp_req_create_handle_failure(dbus_req, ret);
300 : }
301 :
302 0 : group_req = talloc_zero(ireq, struct ifp_attr_req);
303 0 : if (group_req == NULL) {
304 0 : return sbus_request_finish(dbus_req, NULL);
305 : }
306 0 : group_req->ireq = ireq;
307 0 : group_req->name = arg_user;
308 :
309 0 : group_req->attrs = talloc_zero_array(group_req, const char *, 2);
310 0 : if (group_req->attrs == NULL) {
311 0 : return sbus_request_finish(dbus_req, NULL);
312 : }
313 :
314 0 : group_req->attrs[0] = talloc_strdup(group_req->attrs, SYSDB_MEMBEROF);
315 0 : if (group_req->attrs[0] == NULL) {
316 0 : return sbus_request_finish(dbus_req, NULL);
317 : }
318 :
319 0 : DEBUG(SSSDBG_FUNC_DATA,
320 : "Looking up groups of user [%s] on behalf of %"PRIi64"\n",
321 : group_req->name, group_req->ireq->dbus_req->client);
322 :
323 0 : req = ifp_user_get_attr_send(ireq, ifp_ctx->rctx,
324 : ifp_ctx->ncache, ifp_ctx->neg_timeout,
325 : SSS_DP_INITGROUPS,
326 : group_req->name, group_req->attrs);
327 0 : if (req == NULL) {
328 0 : return sbus_request_finish(dbus_req, NULL);
329 : }
330 0 : tevent_req_set_callback(req, ifp_user_get_groups_process, group_req);
331 0 : return EOK;
332 : }
333 :
334 0 : static void ifp_user_get_groups_process(struct tevent_req *req)
335 : {
336 : struct ifp_attr_req *group_req;
337 : errno_t ret;
338 : struct ldb_result *res;
339 : struct sss_domain_info *dom;
340 :
341 0 : group_req = tevent_req_callback_data(req, struct ifp_attr_req);
342 :
343 0 : ret = ifp_user_get_attr_recv(group_req, req, &res, &dom);
344 0 : talloc_zfree(req);
345 0 : if (ret == ENOENT) {
346 0 : sbus_request_fail_and_finish(group_req->ireq->dbus_req,
347 0 : sbus_error_new(group_req->ireq->dbus_req,
348 : DBUS_ERROR_FAILED,
349 : "No such user\n"));
350 0 : return;
351 0 : } else if (ret != EOK) {
352 0 : sbus_request_fail_and_finish(group_req->ireq->dbus_req,
353 0 : sbus_error_new(group_req->ireq->dbus_req,
354 : DBUS_ERROR_FAILED,
355 : "Failed to read attribute\n"));
356 0 : return;
357 : }
358 :
359 0 : ret = ifp_user_get_groups_reply(dom, group_req->ireq, res);
360 0 : if (ret != EOK) {
361 0 : sbus_request_fail_and_finish(group_req->ireq->dbus_req,
362 0 : sbus_error_new(group_req->ireq->dbus_req,
363 : DBUS_ERROR_FAILED,
364 : "Failed to build a reply\n"));
365 0 : return;
366 : }
367 : }
368 :
369 : static errno_t
370 0 : ifp_user_get_groups_reply(struct sss_domain_info *domain,
371 : struct ifp_req *ireq,
372 : struct ldb_result *res)
373 : {
374 : int i, num;
375 : const char *name;
376 : const char **groupnames;
377 : const char *tmpstr;
378 :
379 : /* one less, the first one is the user entry */
380 0 : num = res->count - 1;
381 0 : groupnames = talloc_zero_array(ireq, const char *, num);
382 0 : if (groupnames == NULL) {
383 0 : return sbus_request_finish(ireq->dbus_req, NULL);
384 : }
385 :
386 0 : for (i = 0; i < num; i++) {
387 0 : name = sss_view_ldb_msg_find_attr_as_string(domain,
388 0 : res->msgs[i + 1],
389 : SYSDB_NAME, NULL);
390 0 : if (name == NULL) {
391 0 : DEBUG(SSSDBG_MINOR_FAILURE, "Skipping a group with no name\n");
392 0 : continue;
393 : }
394 :
395 0 : if (ireq->ifp_ctx->rctx->override_space != '\0') {
396 0 : tmpstr = sss_replace_space(ireq, name,
397 0 : ireq->ifp_ctx->rctx->override_space);
398 0 : if (tmpstr == NULL) {
399 0 : DEBUG(SSSDBG_MINOR_FAILURE, "Cannot normalize %s\n", name);
400 0 : continue;
401 : }
402 : } else {
403 0 : tmpstr = name;
404 : }
405 :
406 0 : groupnames[i] = sss_get_cased_name(groupnames, tmpstr,
407 0 : domain->case_preserve);
408 0 : if (groupnames[i] == NULL) {
409 0 : DEBUG(SSSDBG_CRIT_FAILURE,
410 : "sss_get_cased_name failed, skipping\n");
411 0 : continue;
412 : }
413 :
414 0 : DEBUG(SSSDBG_TRACE_FUNC, "Adding group %s\n", groupnames[i]);
415 : }
416 :
417 0 : return iface_ifp_GetUserGroups_finish(ireq->dbus_req, groupnames, num);
418 : }
419 :
420 : struct ifp_user_get_attr_state {
421 : const char *inp;
422 : const char **attrs;
423 : struct ldb_result *res;
424 :
425 : enum sss_dp_acct_type search_type;
426 :
427 : char *name;
428 : char *domname;
429 :
430 : struct sss_domain_info *dom;
431 : bool check_next;
432 : bool check_provider;
433 :
434 : struct resp_ctx *rctx;
435 : struct sss_nc_ctx *ncache;
436 : int neg_timeout;
437 : };
438 :
439 : static void ifp_user_get_attr_lookup(struct tevent_req *subreq);
440 : static void ifp_user_get_attr_done(struct tevent_req *subreq);
441 :
442 : static struct tevent_req *
443 0 : ifp_user_get_attr_send(TALLOC_CTX *mem_ctx, struct resp_ctx *rctx,
444 : struct sss_nc_ctx *ncache, int neg_timeout,
445 : enum sss_dp_acct_type search_type,
446 : const char *inp, const char **attrs)
447 : {
448 : errno_t ret;
449 : struct tevent_req *req;
450 : struct tevent_req *subreq;
451 : struct ifp_user_get_attr_state *state;
452 :
453 0 : req = tevent_req_create(mem_ctx, &state, struct ifp_user_get_attr_state);
454 0 : if (req == NULL) {
455 0 : return NULL;
456 : }
457 0 : state->inp = inp;
458 0 : state->attrs = attrs;
459 0 : state->rctx = rctx;
460 0 : state->ncache = ncache;
461 0 : state->neg_timeout = neg_timeout;
462 0 : state->search_type = search_type;
463 :
464 0 : subreq = sss_parse_inp_send(req, rctx, inp);
465 0 : if (subreq == NULL) {
466 0 : ret = ENOMEM;
467 0 : goto done;
468 : }
469 0 : tevent_req_set_callback(subreq, ifp_user_get_attr_lookup, req);
470 :
471 0 : ret = EOK;
472 : done:
473 0 : if (ret != EOK) {
474 0 : tevent_req_error(req, ret);
475 : }
476 0 : return req;
477 : }
478 :
479 : static void
480 0 : ifp_user_get_attr_lookup(struct tevent_req *subreq)
481 : {
482 0 : struct ifp_user_get_attr_state *state = NULL;
483 0 : struct cache_req_input *input = NULL;
484 0 : struct tevent_req *req = NULL;
485 : errno_t ret;
486 :
487 0 : req = tevent_req_callback_data(subreq, struct tevent_req);
488 0 : state = tevent_req_data(req, struct ifp_user_get_attr_state);
489 :
490 0 : ret = sss_parse_inp_recv(subreq, state, &state->name, &state->domname);
491 0 : talloc_zfree(subreq);
492 0 : if (ret != EOK) {
493 0 : tevent_req_error(req, ret);
494 0 : return;
495 : }
496 :
497 0 : switch (state->search_type) {
498 : case SSS_DP_USER:
499 0 : input = cache_req_input_create(state, CACHE_REQ_USER_BY_NAME,
500 0 : state->name, 0, NULL);
501 0 : break;
502 : case SSS_DP_INITGROUPS:
503 0 : input = cache_req_input_create(state, CACHE_REQ_INITGROUPS,
504 0 : state->name, 0, NULL);
505 0 : break;
506 : default:
507 0 : DEBUG(SSSDBG_CRIT_FAILURE, "Unsupported search type [%d]!\n",
508 : state->search_type);
509 0 : tevent_req_error(req, ERR_INTERNAL);
510 0 : return;
511 : }
512 :
513 0 : if (input == NULL) {
514 0 : tevent_req_error(req, ENOMEM);
515 0 : return;
516 : }
517 :
518 0 : subreq = cache_req_send(state, state->rctx->ev, state->rctx,
519 : state->ncache, state->neg_timeout, 0,
520 0 : state->domname, input);
521 0 : if (subreq == NULL) {
522 0 : tevent_req_error(req, ENOMEM);
523 0 : return;
524 : }
525 :
526 0 : tevent_req_set_callback(subreq, ifp_user_get_attr_done, req);
527 : }
528 :
529 0 : static void ifp_user_get_attr_done(struct tevent_req *subreq)
530 : {
531 0 : struct ifp_user_get_attr_state *state = NULL;
532 0 : struct tevent_req *req = NULL;
533 : errno_t ret;
534 :
535 0 : req = tevent_req_callback_data(subreq, struct tevent_req);
536 0 : state = tevent_req_data(req, struct ifp_user_get_attr_state);
537 :
538 0 : ret = cache_req_recv(state, subreq, &state->res, &state->dom, NULL);
539 0 : talloc_zfree(subreq);
540 0 : if (ret != EOK) {
541 0 : tevent_req_error(req, ret);
542 0 : return;
543 : }
544 :
545 0 : if (state->search_type == SSS_DP_USER) {
546 : /* throw away the result and perform attr search */
547 0 : talloc_zfree(state->res);
548 :
549 0 : ret = sysdb_get_user_attr_with_views(state, state->dom, state->name,
550 : state->attrs, &state->res);
551 0 : if (ret != EOK) {
552 0 : DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_get_user_attr_with_views() "
553 : "failed [%d]: %s\n", ret, sss_strerror(ret));
554 0 : tevent_req_error(req, ret);
555 0 : return;
556 0 : } else if (state->res->count == 0) {
557 0 : tevent_req_error(req, ENOENT);
558 0 : return;
559 0 : } else if (state->res->count != 1) {
560 0 : DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_get_user_attr_with_views() "
561 : "returned more than one result!\n");
562 0 : tevent_req_error(req, ENOENT);
563 0 : return;
564 : }
565 : }
566 :
567 0 : tevent_req_done(req);
568 : }
569 :
570 : static errno_t
571 0 : ifp_user_get_attr_recv(TALLOC_CTX *mem_ctx,
572 : struct tevent_req *req,
573 : struct ldb_result **_res,
574 : struct sss_domain_info **_domain)
575 : {
576 0 : struct ifp_user_get_attr_state *state = tevent_req_data(req,
577 : struct ifp_user_get_attr_state);
578 :
579 0 : TEVENT_REQ_RETURN_ON_ERROR(req);
580 :
581 0 : if (state->res == NULL) {
582 : /* Did the request end with success but with no data? */
583 0 : return ENOENT;
584 : }
585 :
586 0 : if (_res) {
587 0 : *_res = talloc_steal(mem_ctx, state->res);
588 : }
589 :
590 0 : if (_domain) {
591 0 : *_domain = state->dom;
592 : }
593 :
594 0 : return EOK;
595 : }
596 :
597 0 : struct cli_protocol_version *register_cli_protocol_version(void)
598 : {
599 : static struct cli_protocol_version ssh_cli_protocol_version[] = {
600 : {0, NULL, NULL}
601 : };
602 :
603 0 : return ssh_cli_protocol_version;
604 : }
605 :
606 : /* This is a throwaway method to ease the review of the patch.
607 : * It will be removed later */
608 0 : int ifp_ping(struct sbus_request *dbus_req, void *data)
609 : {
610 0 : struct ifp_ctx *ifp_ctx = talloc_get_type(data, struct ifp_ctx);
611 : static const char *pong = "PONG";
612 : const char *request;
613 : DBusError dberr;
614 : errno_t ret;
615 : struct ifp_req *ifp_req;
616 :
617 0 : if (ifp_ctx == NULL) {
618 0 : DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
619 0 : return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
620 : }
621 :
622 0 : ret = ifp_req_create(dbus_req, ifp_ctx, &ifp_req);
623 0 : if (ret != EOK) {
624 0 : return ifp_req_create_handle_failure(dbus_req, ret);
625 : }
626 :
627 0 : if (!sbus_request_parse_or_finish(dbus_req,
628 : DBUS_TYPE_STRING, &request,
629 : DBUS_TYPE_INVALID)) {
630 0 : return EOK; /* handled */
631 : }
632 :
633 0 : DEBUG(SSSDBG_CONF_SETTINGS, "Got request for [%s]\n", request);
634 :
635 0 : if (strcasecmp(request, "ping") != 0) {
636 0 : dbus_error_init(&dberr);
637 0 : dbus_set_error_const(&dberr,
638 : DBUS_ERROR_INVALID_ARGS,
639 : "Ping() only accepts ping as a param\n");
640 0 : return sbus_request_fail_and_finish(dbus_req, &dberr);
641 : }
642 :
643 0 : return sbus_request_return_and_finish(dbus_req,
644 : DBUS_TYPE_STRING, &pong,
645 : DBUS_TYPE_INVALID);
646 : }
|