diff options
author | Stef Walter <stefw@gnome.org> | 2014-01-17 12:54:42 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-03-14 13:42:17 +0100 |
commit | d9577dbd92555b0755881e37724019ef9c578404 (patch) | |
tree | 243d1ee45c7f8d0a7f30750bbb7cfd93983e6182 /src/responder | |
parent | 5bad17538eab85ce69e0355cd25b52b4a473cc36 (diff) | |
download | sssd-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/responder')
-rw-r--r-- | src/responder/autofs/autofssrv.c | 10 | ||||
-rw-r--r-- | src/responder/common/responder.h | 3 | ||||
-rw-r--r-- | src/responder/common/responder_common.c | 7 | ||||
-rw-r--r-- | src/responder/nss/nsssrv.c | 50 |
4 files changed, 23 insertions, 47 deletions
diff --git a/src/responder/autofs/autofssrv.c b/src/responder/autofs/autofssrv.c index 5ce9ae023..b447a0634 100644 --- a/src/responder/autofs/autofssrv.c +++ b/src/responder/autofs/autofssrv.c @@ -29,8 +29,7 @@ #include "providers/data_provider.h" #include "responder/autofs/autofs_private.h" -static int autofs_clean_hash_table(DBusMessage *message, - struct sbus_connection *conn); +static int autofs_clean_hash_table(struct sbus_request *dbus_req); struct mon_cli_iface monitor_autofs_methods = { { &mon_cli_iface_meta, 0 }, @@ -112,10 +111,9 @@ autofs_dp_reconnect_init(struct sbus_connection *conn, be_conn->domain->name); } -static int autofs_clean_hash_table(DBusMessage *message, - struct sbus_connection *conn) +static int autofs_clean_hash_table(struct sbus_request *dbus_req) { - struct resp_ctx *rctx = talloc_get_type(sbus_conn_get_private_data(conn), + struct resp_ctx *rctx = talloc_get_type(sbus_conn_get_private_data(dbus_req->conn), struct resp_ctx); struct autofs_ctx *actx = talloc_get_type(rctx->pvt_ctx, struct autofs_ctx); @@ -127,7 +125,7 @@ static int autofs_clean_hash_table(DBusMessage *message, return ret; } - return monitor_common_pong(message, conn); + return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID); } static int diff --git a/src/responder/common/responder.h b/src/responder/common/responder.h index 81082c675..3cf801516 100644 --- a/src/responder/common/responder.h +++ b/src/responder/common/responder.h @@ -207,8 +207,7 @@ struct dp_callback_ctx { void handle_requests_after_reconnect(struct resp_ctx *rctx); -int responder_logrotate(DBusMessage *message, - struct sbus_connection *conn); +int responder_logrotate(struct sbus_request *dbus_req); /* Each responder-specific request must create a constructor * function that creates a DBus Message that would be sent to diff --git a/src/responder/common/responder_common.c b/src/responder/common/responder_common.c index 298994a96..209bf5b01 100644 --- a/src/responder/common/responder_common.c +++ b/src/responder/common/responder_common.c @@ -990,17 +990,16 @@ done: return ret; } -int responder_logrotate(DBusMessage *message, - struct sbus_connection *conn) +int responder_logrotate(struct sbus_request *dbus_req) { errno_t ret; - struct resp_ctx *rctx = talloc_get_type(sbus_conn_get_private_data(conn), + struct resp_ctx *rctx = talloc_get_type(sbus_conn_get_private_data(dbus_req->conn), struct resp_ctx); ret = monitor_common_rotate_logs(rctx->cdb, rctx->confdb_service_path); if (ret != EOK) return ret; - return monitor_common_pong(message, conn); + return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID); } void responder_set_fd_limit(rlim_t fd_limit) diff --git a/src/responder/nss/nsssrv.c b/src/responder/nss/nsssrv.c index a385f2943..05bcdda07 100644 --- a/src/responder/nss/nsssrv.c +++ b/src/responder/nss/nsssrv.c @@ -55,10 +55,8 @@ #define SHELL_REALLOC_INCREMENT 5 #define SHELL_REALLOC_MAX 50 -static int nss_clear_memcache(DBusMessage *message, - struct sbus_connection *conn); -static int nss_clear_netgroup_hash_table(DBusMessage *message, - struct sbus_connection *conn); +static int nss_clear_memcache(struct sbus_request *dbus_req); +static int nss_clear_netgroup_hash_table(struct sbus_request *dbus_req); struct mon_cli_iface monitor_nss_methods = { { &mon_cli_iface_meta, 0 }, @@ -75,15 +73,14 @@ struct mon_cli_iface monitor_nss_methods = { struct sbus_interface monitor_nss_interface = { MONITOR_PATH, &monitor_nss_methods.vtable, - NULL + NULL, }; -static int nss_clear_memcache(DBusMessage *message, - struct sbus_connection *conn) +static int nss_clear_memcache(struct sbus_request *dbus_req) { errno_t ret; int memcache_timeout; - struct resp_ctx *rctx = talloc_get_type(sbus_conn_get_private_data(conn), + struct resp_ctx *rctx = talloc_get_type(sbus_conn_get_private_data(dbus_req->conn), struct resp_ctx); struct nss_ctx *nctx = (struct nss_ctx*) rctx->pvt_ctx; @@ -134,14 +131,13 @@ static int nss_clear_memcache(DBusMessage *message, } done: - return monitor_common_pong(message, conn); + return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID); } -static int nss_clear_netgroup_hash_table(DBusMessage *message, - struct sbus_connection *conn) +static int nss_clear_netgroup_hash_table(struct sbus_request *dbus_req) { errno_t ret; - struct resp_ctx *rctx = talloc_get_type(sbus_conn_get_private_data(conn), + struct resp_ctx *rctx = talloc_get_type(sbus_conn_get_private_data(dbus_req->conn), struct resp_ctx); struct nss_ctx *nctx = (struct nss_ctx*) rctx->pvt_ctx; @@ -152,7 +148,7 @@ static int nss_clear_netgroup_hash_table(DBusMessage *message, return ret; } - return monitor_common_pong(message, conn); + return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID); } static errno_t nss_get_etc_shells(TALLOC_CTX *mem_ctx, char ***_shells) @@ -308,10 +304,9 @@ done: return ret; } -static int nss_update_memcache(DBusMessage *message, - struct sbus_connection *conn) +static int nss_update_memcache(struct sbus_request *dbus_req) { - struct resp_ctx *rctx = talloc_get_type(sbus_conn_get_private_data(conn), + struct resp_ctx *rctx = talloc_get_type(sbus_conn_get_private_data(dbus_req->conn), struct resp_ctx); struct nss_ctx *nctx = talloc_get_type(rctx->pvt_ctx, struct nss_ctx); @@ -321,15 +316,13 @@ static int nss_update_memcache(DBusMessage *message, return EOK; } -static int nss_memcache_initgr_check(DBusMessage *message, - struct sbus_connection *conn) +static int nss_memcache_initgr_check(struct sbus_request *dbus_req) { - struct resp_ctx *rctx = talloc_get_type(sbus_conn_get_private_data(conn), + struct resp_ctx *rctx = talloc_get_type(sbus_conn_get_private_data(dbus_req->conn), struct resp_ctx); struct nss_ctx *nctx = talloc_get_type(rctx->pvt_ctx, struct nss_ctx); DBusError dbus_error; dbus_bool_t dbret; - DBusMessage *reply; char *user; char *domain; uint32_t *groups; @@ -337,7 +330,7 @@ static int nss_memcache_initgr_check(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_STRING, &user, DBUS_TYPE_STRING, &domain, DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, @@ -357,20 +350,7 @@ static int nss_memcache_initgr_check(DBusMessage *message, nss_update_initgr_memcache(nctx, user, domain, gnum, groups); - reply = dbus_message_new_method_return(message); - if (!reply) return ENOMEM; - - dbret = dbus_message_append_args(reply, DBUS_TYPE_INVALID); - if (!dbret) { - dbus_message_unref(reply); - return EIO; - } - - /* send reply back */ - sbus_conn_send_reply(conn, reply); - dbus_message_unref(reply); - - return EOK; + return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID); } static struct data_provider_rev_iface nss_dp_methods = { |