summaryrefslogtreecommitdiffstats
path: root/src/providers/proxy
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2014-01-17 12:54:42 +0100
committerJakub Hrozek <jhrozek@redhat.com>2014-03-14 13:42:17 +0100
commitd9577dbd92555b0755881e37724019ef9c578404 (patch)
tree243d1ee45c7f8d0a7f30750bbb7cfd93983e6182 /src/providers/proxy
parent5bad17538eab85ce69e0355cd25b52b4a473cc36 (diff)
downloadsssd-d9577dbd92555b0755881e37724019ef9c578404.tar.gz
sssd-d9577dbd92555b0755881e37724019ef9c578404.tar.xz
sssd-d9577dbd92555b0755881e37724019ef9c578404.zip
sbus: Add struct sbus_request to represent a DBus invocation
struct sbus_request represents a request from a dbus client being handled by a dbus server implementation. The struct contains the message, connection and method (and in the future teh property) which is being requested. In the future it will contain caller information as well. sbus_request is a talloc memory context, and is a good place to attach any allocations and memory specific to the request. Each handler accepts an sbus_request. If a handler returns EOK, it is assumed that the handler will finish the request. Any of the sbus_request_*finish() methods can be used to complete the request and send back a reply. sbus_request_return_and_finish() uses the same argument varargs syntax as dbus_message_append_args(), which isn't a great syntax. Document it a bit, but don't try to redesign: The marshalling work (will follow this patch set) will remove the need to use varargs for most DBus implementation code. This patch migrates the monitor and data provider dbus code to use sbus_request, but does not try to rework the talloc context's to use it. Reviewed-by: Jakub Hrozek <jhrozek@redhat.com> Reviewed-by: Pavel Březina <pbrezina@redhat.com> Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
Diffstat (limited to 'src/providers/proxy')
-rw-r--r--src/providers/proxy/proxy_child.c14
-rw-r--r--src/providers/proxy/proxy_init.c38
2 files changed, 20 insertions, 32 deletions
diff --git a/src/providers/proxy/proxy_child.c b/src/providers/proxy/proxy_child.c
index b99c35317..eb47ae1e0 100644
--- a/src/providers/proxy/proxy_child.c
+++ b/src/providers/proxy/proxy_child.c
@@ -47,7 +47,7 @@
#include "providers/dp_backend.h"
-static int pc_pam_handler(DBusMessage *message, struct sbus_connection *conn);
+static int pc_pam_handler(struct sbus_request *dbus_req);
struct data_provider_iface pc_methods = {
{ &data_provider_iface_meta, 0 },
@@ -310,7 +310,7 @@ fail:
return ret;
}
-static int pc_pam_handler(DBusMessage *message, struct sbus_connection *conn)
+static int pc_pam_handler(struct sbus_request *dbus_req)
{
DBusError dbus_error;
DBusMessage *reply;
@@ -319,7 +319,7 @@ static int pc_pam_handler(DBusMessage *message, struct sbus_connection *conn)
void *user_data;
struct pam_data *pd = NULL;
- user_data = sbus_conn_get_private_data(conn);
+ user_data = sbus_conn_get_private_data(dbus_req->conn);
if (!user_data) {
ret = EINVAL;
goto done;
@@ -330,7 +330,7 @@ static int pc_pam_handler(DBusMessage *message, struct sbus_connection *conn)
goto done;
}
- reply = dbus_message_new_method_return(message);
+ reply = dbus_message_new_method_return(dbus_req->message);
if (!reply) {
DEBUG(SSSDBG_CRIT_FAILURE, "dbus_message_new_method_return failed, "
"cannot send reply.\n");
@@ -340,7 +340,7 @@ static int pc_pam_handler(DBusMessage *message, struct sbus_connection *conn)
dbus_error_init(&dbus_error);
- ret = dp_unpack_pam_request(message, pc_ctx, &pd, &dbus_error);
+ ret = dp_unpack_pam_request(dbus_req->message, pc_ctx, &pd, &dbus_error);
if (!ret) {
DEBUG(SSSDBG_CRIT_FAILURE,"Failed, to parse message!\n");
ret = EIO;
@@ -375,14 +375,14 @@ static int pc_pam_handler(DBusMessage *message, struct sbus_connection *conn)
goto done;
}
- sbus_conn_send_reply(conn, reply);
+ ret = sbus_request_finish(dbus_req, reply);
dbus_message_unref(reply);
talloc_free(pd);
/* We'll return the message and let the
* parent process kill us.
*/
- return EOK;
+ return ret;
done:
exit(ret);
diff --git a/src/providers/proxy/proxy_init.c b/src/providers/proxy/proxy_init.c
index 60ae4a950..70fe337cd 100644
--- a/src/providers/proxy/proxy_init.c
+++ b/src/providers/proxy/proxy_init.c
@@ -27,8 +27,7 @@
#include "util/sss_format.h"
#include "providers/proxy/proxy.h"
-static int client_registration(DBusMessage *message,
- struct sbus_connection *conn);
+static int client_registration(struct sbus_request *dbus_req);
static struct data_provider_iface proxy_methods = {
{ &data_provider_iface_meta, 0 },
@@ -395,12 +394,11 @@ static void init_timeout(struct tevent_context *ev,
*/
}
-static int client_registration(DBusMessage *message,
- struct sbus_connection *conn)
+static int client_registration(struct sbus_request *dbus_req)
{
dbus_uint16_t version = DATA_PROVIDER_VERSION;
+ struct sbus_connection *conn;
struct proxy_client *proxy_cli;
- DBusMessage *reply;
DBusError dbus_error;
dbus_uint16_t cli_ver;
uint32_t cli_id;
@@ -412,7 +410,9 @@ static int client_registration(DBusMessage *message,
struct tevent_req *req;
struct proxy_child_ctx *child_ctx;
struct pc_init_ctx *init_ctx;
+ int ret;
+ conn = dbus_req->conn;
data = sbus_conn_get_private_data(conn);
proxy_cli = talloc_get_type(data, struct proxy_client);
if (!proxy_cli) {
@@ -427,7 +427,7 @@ static int client_registration(DBusMessage *message,
dbus_error_init(&dbus_error);
- dbret = dbus_message_get_args(message, &dbus_error,
+ dbret = dbus_message_get_args(dbus_req->message, &dbus_error,
DBUS_TYPE_UINT16, &cli_ver,
DBUS_TYPE_UINT32, &cli_id,
DBUS_TYPE_INVALID);
@@ -453,31 +453,19 @@ static int client_registration(DBusMessage *message,
}
/* reply that all is ok */
- reply = dbus_message_new_method_return(message);
- if (!reply) {
- DEBUG(SSSDBG_FATAL_FAILURE, "Dbus Out of memory!\n");
- return ENOMEM;
- }
-
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &version,
- DBUS_TYPE_INVALID);
- if (!dbret) {
- DEBUG(SSSDBG_FATAL_FAILURE, "Failed to build dbus reply\n");
- dbus_message_unref(reply);
+ ret = sbus_request_return_and_finish(dbus_req,
+ DBUS_TYPE_UINT16, &version,
+ DBUS_TYPE_INVALID);
+ if (ret != EOK) {
sbus_disconnect(conn);
- return EIO;
+ return ret;
}
- /* send reply back */
- sbus_conn_send_reply(conn, reply);
- dbus_message_unref(reply);
-
hret = hash_lookup(proxy_cli->proxy_auth_ctx->request_table, &key, &value);
if (hret != HASH_SUCCESS) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Hash error [%d][%s]\n", hret, hash_error_string(hret));
- sbus_disconnect(conn);
+ sbus_disconnect(dbus_req->conn);
}
/* Signal that the child is up and ready to receive the request */
@@ -496,7 +484,7 @@ static int client_registration(DBusMessage *message,
}
init_ctx = tevent_req_data(child_ctx->init_req, struct pc_init_ctx);
- init_ctx->conn = conn;
+ init_ctx->conn = dbus_req->conn;
tevent_req_done(child_ctx->init_req);
child_ctx->init_req = NULL;