sssd_dbus_request.c revision 3d5908ed0faf400a5c7d9c3e4312597ee1b7786a
d9577dbd92555b0755881e37724019ef9c578404Stef Walter Stef Walter <stefw@redhat.com>
d9577dbd92555b0755881e37724019ef9c578404Stef Walter Copyright (C) 2014 Red Hat
d9577dbd92555b0755881e37724019ef9c578404Stef Walter This program is free software; you can redistribute it and/or modify
d9577dbd92555b0755881e37724019ef9c578404Stef Walter it under the terms of the GNU General Public License as published by
d9577dbd92555b0755881e37724019ef9c578404Stef Walter the Free Software Foundation; either version 3 of the License, or
d9577dbd92555b0755881e37724019ef9c578404Stef Walter (at your option) any later version.
d9577dbd92555b0755881e37724019ef9c578404Stef Walter This program is distributed in the hope that it will be useful,
d9577dbd92555b0755881e37724019ef9c578404Stef Walter but WITHOUT ANY WARRANTY; without even the implied warranty of
d9577dbd92555b0755881e37724019ef9c578404Stef Walter MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d9577dbd92555b0755881e37724019ef9c578404Stef Walter GNU General Public License for more details.
d9577dbd92555b0755881e37724019ef9c578404Stef Walter You should have received a copy of the GNU General Public License
d9577dbd92555b0755881e37724019ef9c578404Stef Walter along with this program. If not, see <http://www.gnu.org/licenses/>.
d9577dbd92555b0755881e37724019ef9c578404Stef Walterstatic int sbus_request_destructor(struct sbus_request *dbus_req)
d9577dbd92555b0755881e37724019ef9c578404Stef Walter dbus_req = talloc_zero(conn, struct sbus_request);
d9577dbd92555b0755881e37724019ef9c578404Stef Walter DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory allocating DBus request\n");
d9577dbd92555b0755881e37724019ef9c578404Stef Walter talloc_set_destructor(dbus_req, sbus_request_destructor);
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Waltersbus_request_invoke_or_finish(struct sbus_request *dbus_req,
dff909d473f43a6bd0f0286fa2d279c0ebe945c6Stef Walter DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory handling DBus message\n");
8779b9ee101ed3e5a6836b5366c006dc21dd36c0Pavel Březina dbus_set_error_const(&error, DBUS_ERROR_FAILED, INTERNAL_ERROR);
8779b9ee101ed3e5a6836b5366c006dc21dd36c0Pavel Březina sbus_request_fail_and_finish(dbus_req, &error);
d9577dbd92555b0755881e37724019ef9c578404Stef Walterint sbus_request_finish(struct sbus_request *dbus_req,
d9577dbd92555b0755881e37724019ef9c578404Stef Walterint sbus_request_return_and_finish(struct sbus_request *dbus_req,
d9577dbd92555b0755881e37724019ef9c578404Stef Walter reply = dbus_message_new_method_return(dbus_req->message);
d9577dbd92555b0755881e37724019ef9c578404Stef Walter DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory allocating DBus message\n");
d9577dbd92555b0755881e37724019ef9c578404Stef Walter dbret = dbus_message_append_args_valist(reply, first_arg_type, va);
d9577dbd92555b0755881e37724019ef9c578404Stef Walter DEBUG(SSSDBG_CRIT_FAILURE, "Couldn't build DBus message\n");
d9577dbd92555b0755881e37724019ef9c578404Stef Walterint sbus_request_fail_and_finish(struct sbus_request *dbus_req,
d9577dbd92555b0755881e37724019ef9c578404Stef Walter reply = dbus_message_new_error(dbus_req->message, error->name, error->message);
d9577dbd92555b0755881e37724019ef9c578404Stef Walter DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory allocating DBus message\n");
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walterstatic int array_arg_destructor(struct array_arg *arg)
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walterparent_dbus_string_arrays(struct sbus_request *request, int first_arg_type,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter * Here we iterate through the entire thing again and look for
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter * things we need to fix allocation for. Normally certain types
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter * returned from dbus_message_get_args() and friends require
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter * later freeing. We tie those to the talloc context here.
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter * The list of argument has already been validated by the previous
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter * dbus_message_get_args() call, so we can be cheap.
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter arg_type = va_arg(va, int); /* the array element type */
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter arg_ptr = va_arg(va, void **); /* the array elements */
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter /* Arrays of these things need to be freed */
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter array_arg = talloc_zero(request, struct array_arg);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter /* no kidding ... */
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory while trying not to leak memory\n");
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter return false;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter talloc_set_destructor(array_arg, array_arg_destructor);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter /* A non array argument */
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter /* The next type */
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter return true;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Waltersbus_request_parse_or_finish(struct sbus_request *request,
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter bool ret = true;
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter if (dbus_message_get_args_valist(request->message, &error,
3d5908ed0faf400a5c7d9c3e4312597ee1b7786aJakub Hrozek ret = parent_dbus_string_arrays(request, first_arg_type, va2);
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter /* Trying to send the error back to the caller in this case is a joke */
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter if (!dbus_error_is_set(&error) || dbus_error_has_name(&error, DBUS_ERROR_NO_MEMORY)) {
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory parsing DBus message\n");
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter /* Log other errors and send them back, this include o.f.d.InvalidArgs */
06b7bc8ca2e005ed510210d3b8dee16afbabbcc9Stef Walter DEBUG(SSSDBG_OP_FAILURE, "Couldn't parse DBus message %s.%s: %s\n",