83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina Pavel Březina <pbrezina@redhat.com>
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina Copyright (C) 2016 Red Hat
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina This program is free software; you can redistribute it and/or modify
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina it under the terms of the GNU General Public License as published by
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina the Free Software Foundation; either version 3 of the License, or
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina (at your option) any later version.
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina This program is distributed in the hope that it will be useful,
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina GNU General Public License for more details.
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina You should have received a copy of the GNU General Public License
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina#include "responder/common/data_provider/rdp.h"
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březinardp_message_send_internal(struct resp_ctx *rctx,
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina ret = sss_dp_get_domain_conn(rctx, domain->conn_name, &be_conn);
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "BUG: The Data Provider connection for "
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina msg = dbus_message_new_method_call(NULL, path, iface, method);
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create message\n");
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina bret = dbus_message_append_args_valist(msg, first_arg_type, va);
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Failed to build message\n");
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina DEBUG(SSSDBG_TRACE_FUNC, "DP Request: %s %s.%s\n", path, iface, method);
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina ret = sbus_conn_send(be_conn->conn, msg, 3000,
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to contact Data Provider "
439e08cdc5c83b3e5835cb0435983f1da2ffbaf1Pavel Březinastatic errno_t rdp_process_pending_call(TALLOC_CTX *mem_ctx,
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina reply = dbus_pending_call_steal_reply(pending);
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina DEBUG(SSSDBG_FATAL_FAILURE, "Severe error. A reply callback was "
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina "called but no reply was received and no timeout occurred\n");
439e08cdc5c83b3e5835cb0435983f1da2ffbaf1Pavel Březina ret = sbus_talloc_bound_message(mem_ctx, reply);
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina bret = dbus_set_error_from_message(&error, reply);
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina if (bret == false) {
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to read error from message\n");
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "DP Error [%s]: %s\n",
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina error.name, (error.message == NULL ? "(null)" : error.message));
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unexpected type?\n");
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březinastatic void rdp_message_done(DBusPendingCall *pending, void *ptr);
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březinastruct tevent_req *_rdp_message_send(TALLOC_CTX *mem_ctx,
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina req = tevent_req_create(mem_ctx, &state, struct rdp_message_state);
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina ret = rdp_message_send_internal(rctx, domain, rdp_message_done, req,
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to contact Data Provider "
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březinastatic void rdp_message_done(DBusPendingCall *pending, void *ptr)
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina req = talloc_get_type(ptr, struct tevent_req);
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina state = tevent_req_data(req, struct rdp_message_state);
439e08cdc5c83b3e5835cb0435983f1da2ffbaf1Pavel Březina ret = rdp_process_pending_call(state, pending, &state->reply);
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březinaerrno_t _rdp_message_recv(struct tevent_req *req,
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina state = tevent_req_data(req, struct rdp_message_state);
439e08cdc5c83b3e5835cb0435983f1da2ffbaf1Pavel Březina ret = sbus_parse_message_valist(state->reply, false, first_arg_type, va);
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březinastatic void rdp_message_send_and_reply_done(DBusPendingCall *pending,
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březinavoid _rdp_message_send_and_reply(struct sbus_request *sbus_req,
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to contact Data Provider "
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březinastatic void rdp_message_send_and_reply_done(DBusPendingCall *pending,
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina sbus_req = talloc_get_type(ptr, struct sbus_request);
439e08cdc5c83b3e5835cb0435983f1da2ffbaf1Pavel Březina ret = rdp_process_pending_call(sbus_req, pending, &reply);
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina /* Something bad happened. Just kill the request. */
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina /* Otherwise we have a valid reply and we do not care about returned
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina * value. We set destination and serial in reply to point to the original
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina * client request. */
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina sender = dbus_message_get_sender(sbus_req->message);
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina serial = dbus_message_get_serial(sbus_req->message);
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina dbret = dbus_message_set_destination(reply, sender);
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina if (dbret == false) {
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to set reply sender!\n");
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina dbret = dbus_message_set_reply_serial(reply, serial);
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina if (dbret == false) {
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to set reply serial!\n");
a40d9cc11d17d9c3c22a0462cd8c419d1e79ffb8Pavel Březina /* Something bad happend, just kill the request. */