diff options
author | Stephen Gallagher <sgallagh@redhat.com> | 2009-02-23 15:43:31 -0500 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2009-02-23 16:20:52 -0500 |
commit | 13421cbe0af4343f9d110600755ffa756690b282 (patch) | |
tree | fab749d3fd49148ec62d7d664c933fb40b36d9a9 | |
parent | f8469b71247b5a41cfdf0f54c25ceda1552e0ee9 (diff) | |
download | sssd-13421cbe0af4343f9d110600755ffa756690b282.tar.gz sssd-13421cbe0af4343f9d110600755ffa756690b282.tar.bz2 sssd-13421cbe0af4343f9d110600755ffa756690b282.zip |
Fixing serious memory allocation bug in sbus_message_handler.
dbus_message_append_args() adds a reference to memory that is not
copied to the outgoing message until dbus_connection_send() is
called. Since we compile our reply messages in functions and then
return the reply, we need a mechanism for deleting allocated
memory after invoking dbus_connection_send. I have changed the
arguments to sbus_msg_handler_fn so that it takes a talloc ctx
containing the sbus_message_handler_ctx and a pointer to a reply
object. We can now allocate memory as a child of the reply context
and free it after calling dbus_connection_send.
-rw-r--r-- | server/infopipe/infopipe.c | 30 | ||||
-rw-r--r-- | server/infopipe/infopipe.h | 29 | ||||
-rw-r--r-- | server/infopipe/infopipe_groups.c | 20 | ||||
-rw-r--r-- | server/infopipe/infopipe_users.c | 24 | ||||
-rw-r--r-- | server/monitor/monitor.c | 9 | ||||
-rw-r--r-- | server/nss/nsssrv.c | 28 | ||||
-rw-r--r-- | server/nss/nsssrv_dp.c | 8 | ||||
-rw-r--r-- | server/polkit/sssd_polkit.c | 20 | ||||
-rw-r--r-- | server/providers/data_provider.c | 46 | ||||
-rw-r--r-- | server/providers/data_provider_be.c | 71 | ||||
-rw-r--r-- | server/sbus/sssd_dbus.h | 8 | ||||
-rw-r--r-- | server/sbus/sssd_dbus_connection.c | 32 |
12 files changed, 156 insertions, 169 deletions
diff --git a/server/infopipe/infopipe.c b/server/infopipe/infopipe.c index 8fe7ee72..1e7a88c8 100644 --- a/server/infopipe/infopipe.c +++ b/server/infopipe/infopipe.c @@ -38,17 +38,16 @@ struct infp_ctx { struct sysbus_ctx *sysbus; }; -static int service_identity(DBusMessage *message, void *data, DBusMessage **r) +static int service_identity(DBusMessage *message, struct sbus_message_ctx *reply) { dbus_uint16_t version = INFOPIPE_VERSION; const char *name = INFOPIPE_SERVICE_NAME; - DBusMessage *reply; dbus_bool_t ret; DEBUG(4, ("Sending identity data [%s,%d]\n", name, version)); - reply = dbus_message_new_method_return(message); - ret = dbus_message_append_args(reply, + reply->reply_message = dbus_message_new_method_return(message); + ret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_STRING, &name, DBUS_TYPE_UINT16, &version, DBUS_TYPE_INVALID); @@ -56,33 +55,30 @@ static int service_identity(DBusMessage *message, void *data, DBusMessage **r) return EIO; } - *r = reply; return EOK; } -static int service_pong(DBusMessage *message, void *data, DBusMessage **r) +static int service_pong(DBusMessage *message, struct sbus_message_ctx *reply) { - DBusMessage *reply; dbus_bool_t ret; - reply = dbus_message_new_method_return(message); - ret = dbus_message_append_args(reply, DBUS_TYPE_INVALID); + reply->reply_message = dbus_message_new_method_return(message); + ret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_INVALID); if (!ret) { return EIO; } - *r = reply; return EOK; } -static int service_reload(DBusMessage *message, void *data, DBusMessage **r) { +static int service_reload(DBusMessage *message, struct sbus_message_ctx *reply) { /* Monitor calls this function when we need to reload * our configuration information. Perform whatever steps * are needed to update the configuration objects. */ /* Send an empty reply to acknowledge receipt */ - return service_pong(message, data, r); + return service_pong(message, reply); } struct sbus_method mon_sbus_methods[] = { @@ -136,12 +132,10 @@ struct sbus_method infp_methods[] = { { NULL, NULL } }; -int infp_introspect(DBusMessage *message, void *data, DBusMessage **r) +int infp_introspect(DBusMessage *message, struct sbus_message_ctx *reply) { - /* Return the Introspection XML */ - /* TODO: actually return the file */ - *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + reply->reply_message = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); return EOK; } @@ -185,9 +179,9 @@ static int infp_process_init(TALLOC_CTX *mem_ctx, return ret; } -int infp_check_permissions(DBusMessage *message, void *data, DBusMessage **r) +int infp_check_permissions(DBusMessage *message, struct sbus_message_ctx *reply) { - *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + reply->reply_message = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); return EOK; } diff --git a/server/infopipe/infopipe.h b/server/infopipe/infopipe.h index 8492c1b1..aabc2bfa 100644 --- a/server/infopipe/infopipe.h +++ b/server/infopipe/infopipe.h @@ -22,6 +22,9 @@ #ifndef INFOPIPE_H_ #define INFOPIPE_H_ +#include <dbus/dbus.h> +#include "sbus/sssd_dbus.h" + #define INFOPIPE_DBUS_NAME "org.freeipa.sssd.infopipe1" #define INFOPIPE_INTERFACE "org.freeipa.sssd.infopipe1" #define INFOPIPE_PATH "/org/freeipa/sssd/infopipe1" @@ -42,34 +45,34 @@ * org.freedesktop.DBus.Introspectable interface */ #define INFP_INTROSPECT "Introspect" -int infp_introspect(DBusMessage *message, void *data, DBusMessage **r); +int infp_introspect(DBusMessage *message, struct sbus_message_ctx *reply); /********************************************************** * Permission Methods (from infopipe.c) * **********************************************************/ #define INFP_CHECK_PERMISSIONS "CheckPermissions1" -int infp_check_permissions(DBusMessage *message, void *data, DBusMessage **r); +int infp_check_permissions(DBusMessage *message, struct sbus_message_ctx *reply); /********************************************************** * User Methods (from infopipe_users.c) * **********************************************************/ #define INFP_USERS_GET_CACHED "GetCachedUsers1" -int infp_users_get_cached(DBusMessage *message, void *data, DBusMessage **r); +int infp_users_get_cached(DBusMessage *message, struct sbus_message_ctx *reply); #define INFP_USERS_CREATE "CreateUser1" -int infp_users_create(DBusMessage *message, void *data, DBusMessage **r); +int infp_users_create(DBusMessage *message, struct sbus_message_ctx *reply); #define INFP_USERS_DELETE "DeleteUser1" -int infp_users_delete(DBusMessage *message, void *data, DBusMessage **r); +int infp_users_delete(DBusMessage *message, struct sbus_message_ctx *reply); #define INFP_USERS_GET_ATTR "GetUserAttributes1" -int infp_users_get_attr(DBusMessage *message, void *data, DBusMessage **r); +int infp_users_get_attr(DBusMessage *message, struct sbus_message_ctx *reply); #define INFP_USERS_SET_ATTR "SetUserAttributes1" -int infp_users_set_attr(DBusMessage *message, void *data, DBusMessage **r); +int infp_users_set_attr(DBusMessage *message, struct sbus_message_ctx *reply); #define INFP_USERS_SET_UID "Set_YouReallyDoNotWantToUseThisFunction_UserUID1" -int infp_users_set_uid(DBusMessage *message, void *data, DBusMessage **r); +int infp_users_set_uid(DBusMessage *message, struct sbus_message_ctx *reply); #define INFP_USER_METHODS \ {INFP_USERS_GET_CACHED, infp_users_get_cached}, \ @@ -84,19 +87,19 @@ int infp_users_set_uid(DBusMessage *message, void *data, DBusMessage **r); **********************************************************/ #define INFP_GROUPS_CREATE "CreateGroup1" -int infp_groups_create(DBusMessage *message, void *data, DBusMessage **r); +int infp_groups_create(DBusMessage *message, struct sbus_message_ctx *reply); #define INFP_GROUPS_DELETE "DeleteGroup1" -int infp_groups_delete(DBusMessage *message, void *data, DBusMessage **r); +int infp_groups_delete(DBusMessage *message, struct sbus_message_ctx *reply); #define INFP_GROUPS_ADD_MEMBERS "AddGroupMembers1" -int infp_groups_add_members(DBusMessage *message, void *data, DBusMessage **r); +int infp_groups_add_members(DBusMessage *message, struct sbus_message_ctx *reply); #define INFP_GROUPS_REMOVE_MEMBERS "RemoveGroupMembers1" -int infp_groups_remove_members(DBusMessage *message, void *data, DBusMessage **r); +int infp_groups_remove_members(DBusMessage *message, struct sbus_message_ctx *reply); #define INFP_GROUPS_SET_GID "Set_YouReallyDoNotWantToUseThisFunction_GroupGID1" -int infp_groups_set_gid(DBusMessage *message, void *data, DBusMessage **r); +int infp_groups_set_gid(DBusMessage *message, struct sbus_message_ctx *reply); #define INFP_GROUP_METHODS \ {INFP_GROUPS_CREATE, infp_groups_create}, \ diff --git a/server/infopipe/infopipe_groups.c b/server/infopipe/infopipe_groups.c index 4b9cfc22..6aa115f8 100644 --- a/server/infopipe/infopipe_groups.c +++ b/server/infopipe/infopipe_groups.c @@ -23,32 +23,32 @@ #include "util/util.h" #include "infopipe.h" -int infp_groups_create(DBusMessage *message, void *data, DBusMessage **r) +int infp_groups_create(DBusMessage *message, struct sbus_message_ctx *reply) { - *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + reply->reply_message = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); return EOK; } -int infp_groups_delete(DBusMessage *message, void *data, DBusMessage **r) +int infp_groups_delete(DBusMessage *message, struct sbus_message_ctx *reply) { - *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + reply->reply_message = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); return EOK; } -int infp_groups_add_members(DBusMessage *message, void *data, DBusMessage **r) +int infp_groups_add_members(DBusMessage *message, struct sbus_message_ctx *reply) { - *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + reply->reply_message = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); return EOK; } -int infp_groups_remove_members(DBusMessage *message, void *data, DBusMessage **r) +int infp_groups_remove_members(DBusMessage *message, struct sbus_message_ctx *reply) { - *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + reply->reply_message = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); return EOK; } -int infp_groups_set_gid(DBusMessage *message, void *data, DBusMessage **r) +int infp_groups_set_gid(DBusMessage *message, struct sbus_message_ctx *reply) { - *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + reply->reply_message = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); return EOK; } diff --git a/server/infopipe/infopipe_users.c b/server/infopipe/infopipe_users.c index 632e624f..566d5e16 100644 --- a/server/infopipe/infopipe_users.c +++ b/server/infopipe/infopipe_users.c @@ -22,38 +22,38 @@ #include "util/util.h" #include "infopipe.h" -int infp_users_get_cached(DBusMessage *message, void *data, DBusMessage **r) +int infp_users_get_cached(DBusMessage *message, struct sbus_message_ctx *reply) { - *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + reply->reply_message = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); return EOK; } -int infp_users_create(DBusMessage *message, void *data, DBusMessage **r) +int infp_users_create(DBusMessage *message, struct sbus_message_ctx *reply) { - *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + reply->reply_message = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); return EOK; } -int infp_users_delete(DBusMessage *message, void *data, DBusMessage **r) +int infp_users_delete(DBusMessage *message, struct sbus_message_ctx *reply) { - *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + reply->reply_message = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); return EOK; } -int infp_users_get_attr(DBusMessage *message, void *data, DBusMessage **r) +int infp_users_get_attr(DBusMessage *message, struct sbus_message_ctx *reply) { - *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + reply->reply_message = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); return EOK; } -int infp_users_set_attr(DBusMessage *message, void *data, DBusMessage **r) +int infp_users_set_attr(DBusMessage *message, struct sbus_message_ctx *reply) { - *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + reply->reply_message = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); return EOK; } -int infp_users_set_uid(DBusMessage *message, void *data, DBusMessage **r) +int infp_users_set_uid(DBusMessage *message, struct sbus_message_ctx *reply) { - *r = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); + reply->reply_message = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, "Not yet implemented"); return EOK; } diff --git a/server/monitor/monitor.c b/server/monitor/monitor.c index 166cf3cd..45191a68 100644 --- a/server/monitor/monitor.c +++ b/server/monitor/monitor.c @@ -88,22 +88,19 @@ static void set_global_checker(struct mt_ctx *ctx); /* dbus_get_monitor_version * Return the monitor version over D-BUS */ static int dbus_get_monitor_version(DBusMessage *message, - void *data, - DBusMessage **r) + struct sbus_message_ctx *reply) { const char *version = MONITOR_VERSION; - DBusMessage *reply; dbus_bool_t ret; - reply = dbus_message_new_method_return(message); - ret = dbus_message_append_args(reply, DBUS_TYPE_STRING, + reply->reply_message = dbus_message_new_method_return(message); + ret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_STRING, &version, DBUS_TYPE_INVALID); if (!ret) { return EIO; } - *r = reply; return EOK; } diff --git a/server/nss/nsssrv.c b/server/nss/nsssrv.c index b6191cce..0909f629 100644 --- a/server/nss/nsssrv.c +++ b/server/nss/nsssrv.c @@ -44,9 +44,9 @@ #define SSS_NSS_PIPE_NAME "nss" -static int service_identity(DBusMessage *message, void *data, DBusMessage **r); -static int service_pong(DBusMessage *message, void *data, DBusMessage **r); -static int service_reload(DBusMessage *message, void *data, DBusMessage **r); +static int service_identity(DBusMessage *message, struct sbus_message_ctx *reply); +static int service_pong(DBusMessage *message, struct sbus_message_ctx *reply); +static int service_reload(DBusMessage *message, struct sbus_message_ctx *reply); static int nss_init_domains(struct nss_ctx *nctx); static int _domain_comparator(const void *key1, const void *key2); @@ -227,18 +227,17 @@ static void accept_fd_handler(struct event_context *ev, return; } -static int service_identity(DBusMessage *message, void *data, DBusMessage **r) +static int service_identity(DBusMessage *message, struct sbus_message_ctx *reply) { dbus_uint16_t version = NSS_SBUS_SERVICE_VERSION; - const char *name = NSS_SBUS_SERVICE_NAME; - DBusMessage *reply; + const char *name = NSS_SBUS_SERVICE_NAME;\ dbus_bool_t ret; DEBUG(4,("Sending ID reply: (%s,%d)\n", name, version)); - reply = dbus_message_new_method_return(message); - ret = dbus_message_append_args(reply, + reply->reply_message = dbus_message_new_method_return(message); + ret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_STRING, &name, DBUS_TYPE_UINT16, &version, DBUS_TYPE_INVALID); @@ -246,33 +245,30 @@ static int service_identity(DBusMessage *message, void *data, DBusMessage **r) return EIO; } - *r = reply; return EOK; } -static int service_pong(DBusMessage *message, void *data, DBusMessage **r) +static int service_pong(DBusMessage *message, struct sbus_message_ctx *reply) { - DBusMessage *reply; dbus_bool_t ret; - reply = dbus_message_new_method_return(message); - ret = dbus_message_append_args(reply, DBUS_TYPE_INVALID); + reply->reply_message = dbus_message_new_method_return(message); + ret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_INVALID); if (!ret) { return EIO; } - *r = reply; return EOK; } -static int service_reload(DBusMessage *message, void *data, DBusMessage **r) { +static int service_reload(DBusMessage *message, struct sbus_message_ctx *reply) { /* Monitor calls this function when we need to reload * our configuration information. Perform whatever steps * are needed to update the configuration objects. */ /* Send an empty reply to acknowledge receipt */ - return service_pong(message, data, r); + return service_pong(message, reply); } static int nss_sbus_init(struct nss_ctx *nctx) diff --git a/server/nss/nsssrv_dp.c b/server/nss/nsssrv_dp.c index 487ac285..b5746e86 100644 --- a/server/nss/nsssrv_dp.c +++ b/server/nss/nsssrv_dp.c @@ -281,20 +281,19 @@ done: return err; } -static int nss_dp_identity(DBusMessage *message, void *data, DBusMessage **r) +static int nss_dp_identity(DBusMessage *message, struct sbus_message_ctx *reply) { dbus_uint16_t version = DATA_PROVIDER_VERSION; dbus_uint16_t clitype = DP_CLI_FRONTEND; const char *cliname = "NSS"; const char *nullname = ""; - DBusMessage *reply; dbus_bool_t ret; DEBUG(4,("Sending ID reply: (%d,%d,%s)\n", clitype, version, cliname)); - reply = dbus_message_new_method_return(message); - ret = dbus_message_append_args(reply, + reply->reply_message = dbus_message_new_method_return(message); + ret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_UINT16, &clitype, DBUS_TYPE_UINT16, &version, DBUS_TYPE_STRING, &cliname, @@ -304,7 +303,6 @@ static int nss_dp_identity(DBusMessage *message, void *data, DBusMessage **r) return EIO; } - *r = reply; return EOK; } diff --git a/server/polkit/sssd_polkit.c b/server/polkit/sssd_polkit.c index 6c7d0e1e..9eda5373 100644 --- a/server/polkit/sssd_polkit.c +++ b/server/polkit/sssd_polkit.c @@ -35,17 +35,16 @@ struct spk_ctx { struct sbus_srv_ctx *sbus_srv; }; -static int service_identity(DBusMessage *message, void *data, DBusMessage **r) +static int service_identity(DBusMessage *message, struct sbus_message_ctx *reply) { dbus_uint16_t version = POLKIT_VERSION; const char *name = POLKIT_SERVICE_NAME; - DBusMessage *reply; dbus_bool_t ret; DEBUG(4, ("Sending identity data [%s,%d]\n", name, version)); - reply = dbus_message_new_method_return(message); - ret = dbus_message_append_args(reply, + reply->reply_message = dbus_message_new_method_return(message); + ret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_STRING, &name, DBUS_TYPE_UINT16, &version, DBUS_TYPE_INVALID); @@ -53,33 +52,30 @@ static int service_identity(DBusMessage *message, void *data, DBusMessage **r) return EIO; } - *r = reply; return EOK; } -static int service_pong(DBusMessage *message, void *data, DBusMessage **r) +static int service_pong(DBusMessage *message, struct sbus_message_ctx *reply) { - DBusMessage *reply; dbus_bool_t ret; - reply = dbus_message_new_method_return(message); - ret = dbus_message_append_args(reply, DBUS_TYPE_INVALID); + reply->reply_message = dbus_message_new_method_return(message); + ret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_INVALID); if (!ret) { return EIO; } - *r = reply; return EOK; } -static int service_reload(DBusMessage *message, void *data, DBusMessage **r) { +static int service_reload(DBusMessage *message, struct sbus_message_ctx *reply) { /* Monitor calls this function when we need to reload * our configuration information. Perform whatever steps * are needed to update the configuration objects. */ /* Send an empty reply to acknowledge receipt */ - return service_pong(message, data, r); + return service_pong(message, reply); } struct sbus_method mon_sbus_methods[] = { diff --git a/server/providers/data_provider.c b/server/providers/data_provider.c index aa66c8e5..c1dc2801 100644 --- a/server/providers/data_provider.c +++ b/server/providers/data_provider.c @@ -76,9 +76,9 @@ struct dp_frontend { static int dp_backend_destructor(void *ctx); static int dp_frontend_destructor(void *ctx); -static int service_identity(DBusMessage *message, void *data, DBusMessage **r); -static int service_pong(DBusMessage *message, void *data, DBusMessage **r); -static int service_reload(DBusMessage *message, void *data, DBusMessage **r); +static int service_identity(DBusMessage *message, struct sbus_message_ctx *reply); +static int service_pong(DBusMessage *message, struct sbus_message_ctx *reply); +static int service_reload(DBusMessage *message, struct sbus_message_ctx *reply); struct sbus_method mon_sbus_methods[] = { { SERVICE_METHOD_IDENTITY, service_identity }, @@ -87,7 +87,7 @@ struct sbus_method mon_sbus_methods[] = { { NULL, NULL } }; -static int dp_get_account_info(DBusMessage *message, void *data, DBusMessage **r); +static int dp_get_account_info(DBusMessage *message, struct sbus_message_ctx *reply); struct sbus_method dp_sbus_methods[] = { { DP_SRV_METHOD_GETACCTINFO, dp_get_account_info }, @@ -108,17 +108,16 @@ struct dp_be_request { struct dp_backend *be; }; -static int service_identity(DBusMessage *message, void *data, DBusMessage **r) +static int service_identity(DBusMessage *message, struct sbus_message_ctx *reply) { dbus_uint16_t version = DATA_PROVIDER_VERSION; const char *name = DATA_PROVIDER_SERVICE_NAME; - DBusMessage *reply; dbus_bool_t ret; DEBUG(4, ("Sending identity data [%s,%d]\n", name, version)); - reply = dbus_message_new_method_return(message); - ret = dbus_message_append_args(reply, + reply->reply_message = dbus_message_new_method_return(message); + ret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_STRING, &name, DBUS_TYPE_UINT16, &version, DBUS_TYPE_INVALID); @@ -126,33 +125,30 @@ static int service_identity(DBusMessage *message, void *data, DBusMessage **r) return EIO; } - *r = reply; return EOK; } -static int service_pong(DBusMessage *message, void *data, DBusMessage **r) +static int service_pong(DBusMessage *message, struct sbus_message_ctx *reply) { - DBusMessage *reply; dbus_bool_t ret; - reply = dbus_message_new_method_return(message); - ret = dbus_message_append_args(reply, DBUS_TYPE_INVALID); + reply->reply_message = dbus_message_new_method_return(message); + ret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_INVALID); if (!ret) { return EIO; } - *r = reply; return EOK; } -static int service_reload(DBusMessage *message, void *data, DBusMessage **r) { +static int service_reload(DBusMessage *message, struct sbus_message_ctx *reply) { /* Monitor calls this function when we need to reload * our configuration information. Perform whatever steps * are needed to update the configuration objects. */ /* Send an empty reply to acknowledge receipt */ - return service_pong(message, data, r); + return service_pong(message, reply); } static int dp_monitor_init(struct dp_ctx *dpctx) @@ -538,14 +534,13 @@ static int dp_send_acct_req(struct dp_be_request *bereq, return EOK; } -static int dp_get_account_info(DBusMessage *message, void *data, DBusMessage **r) +static int dp_get_account_info(DBusMessage *message, struct sbus_message_ctx *reply) { struct sbus_message_handler_ctx *smh_ctx; struct dp_client *dpcli; struct dp_be_request *bereq; struct dp_request *dpreq = NULL; struct dp_backend *dpbe; - DBusMessage *reply; DBusError dbus_error; dbus_bool_t dbret; void *user_data; @@ -554,9 +549,11 @@ static int dp_get_account_info(DBusMessage *message, void *data, DBusMessage **r const char *errmsg = NULL; int dpret = 0, ret = 0; - if (!data) return EINVAL; - smh_ctx = talloc_get_type(data, struct sbus_message_handler_ctx); + if (!reply) return EINVAL; + + smh_ctx = reply->mh_ctx; if (!smh_ctx) return EINVAL; + user_data = sbus_conn_get_private_data(smh_ctx->conn_ctx); if (!user_data) return EINVAL; dpcli = talloc_get_type(user_data, struct dp_client); @@ -578,7 +575,7 @@ static int dp_get_account_info(DBusMessage *message, void *data, DBusMessage **r DEBUG(4, ("Got request for [%s][%u][%s][%s]\n", domain, type, attrs, filter)); - reply = dbus_message_new_method_return(message); + reply->reply_message = dbus_message_new_method_return(message); /* search for domain */ if (!domain) { @@ -606,7 +603,7 @@ static int dp_get_account_info(DBusMessage *message, void *data, DBusMessage **r goto respond; } - dpreq->reply = reply; + dpreq->reply = reply->reply_message; dpreq->src_cli = dpcli; dpreq->pending_replies = 0; @@ -662,7 +659,7 @@ static int dp_get_account_info(DBusMessage *message, void *data, DBusMessage **r goto respond; } - dpreq->reply = reply; + dpreq->reply = reply->reply_message; dpreq->src_cli = dpcli; dpreq->pending_replies = 1; @@ -698,14 +695,13 @@ static int dp_get_account_info(DBusMessage *message, void *data, DBusMessage **r return EOK; respond: - dbret = dbus_message_append_args(reply, + dbret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_UINT16, &dpret, DBUS_TYPE_UINT32, &ret, DBUS_TYPE_STRING, &errmsg, DBUS_TYPE_INVALID); if (!dbret) return EIO; - *r = reply; return EOK; } diff --git a/server/providers/data_provider_be.c b/server/providers/data_provider_be.c index 7b491ce7..c12e2b2f 100644 --- a/server/providers/data_provider_be.c +++ b/server/providers/data_provider_be.c @@ -44,8 +44,8 @@ typedef int (*be_init_fn_t)(TALLOC_CTX *, struct be_mod_ops **, void **); -static int service_identity(DBusMessage *message, void *data, DBusMessage **r); -static int service_pong(DBusMessage *message, void *data, DBusMessage **r); +static int service_identity(DBusMessage *message, struct sbus_message_ctx *reply); +static int service_pong(DBusMessage *message, struct sbus_message_ctx *reply); struct sbus_method mon_sbus_methods[] = { { SERVICE_METHOD_IDENTITY, service_identity }, @@ -53,9 +53,9 @@ struct sbus_method mon_sbus_methods[] = { { NULL, NULL } }; -static int be_identity(DBusMessage *message, void *data, DBusMessage **r); -static int be_check_online(DBusMessage *message, void *data, DBusMessage **r); -static int be_get_account_info(DBusMessage *message, void *data, DBusMessage **r); +static int be_identity(DBusMessage *message, struct sbus_message_ctx *reply); +static int be_check_online(DBusMessage *message, struct sbus_message_ctx *reply); +static int be_get_account_info(DBusMessage *message, struct sbus_message_ctx *reply); struct sbus_method be_methods[] = { { DP_CLI_METHOD_IDENTITY, be_identity }, @@ -64,17 +64,16 @@ struct sbus_method be_methods[] = { { NULL, NULL } }; -static int service_identity(DBusMessage *message, void *data, DBusMessage **r) +static int service_identity(DBusMessage *message, struct sbus_message_ctx *reply) { dbus_uint16_t version = DATA_PROVIDER_VERSION; struct sbus_message_handler_ctx *smh_ctx; struct be_ctx *ctx; - DBusMessage *reply; dbus_bool_t ret; void *user_data; - if (!data) return EINVAL; - smh_ctx = talloc_get_type(data, struct sbus_message_handler_ctx); + if (!reply) return EINVAL; + smh_ctx = reply->mh_ctx; if (!smh_ctx) return EINVAL; user_data = sbus_conn_get_private_data(smh_ctx->conn_ctx); if (!user_data) return EINVAL; @@ -83,8 +82,8 @@ static int service_identity(DBusMessage *message, void *data, DBusMessage **r) DEBUG(4,("Sending ID reply: (%s,%d)\n", ctx->identity, version)); - reply = dbus_message_new_method_return(message); - ret = dbus_message_append_args(reply, + reply->reply_message = dbus_message_new_method_return(message); + ret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_STRING, &ctx->identity, DBUS_TYPE_UINT16, &version, DBUS_TYPE_INVALID); @@ -92,37 +91,33 @@ static int service_identity(DBusMessage *message, void *data, DBusMessage **r) return EIO; } - *r = reply; return EOK; } -static int service_pong(DBusMessage *message, void *data, DBusMessage **r) +static int service_pong(DBusMessage *message, struct sbus_message_ctx *reply) { - DBusMessage *reply; dbus_bool_t ret; - reply = dbus_message_new_method_return(message); - ret = dbus_message_append_args(reply, DBUS_TYPE_INVALID); + reply->reply_message = dbus_message_new_method_return(message); + ret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_INVALID); if (!ret) { return EIO; } - *r = reply; return EOK; } -static int be_identity(DBusMessage *message, void *data, DBusMessage **r) +static int be_identity(DBusMessage *message, struct sbus_message_ctx *reply) { dbus_uint16_t version = DATA_PROVIDER_VERSION; dbus_uint16_t clitype = DP_CLI_BACKEND; struct sbus_message_handler_ctx *smh_ctx; struct be_ctx *ctx; - DBusMessage *reply; dbus_bool_t ret; void *user_data; - if (!data) return EINVAL; - smh_ctx = talloc_get_type(data, struct sbus_message_handler_ctx); + if (!reply) return EINVAL; + smh_ctx = reply->mh_ctx; if (!smh_ctx) return EINVAL; user_data = sbus_conn_get_private_data(smh_ctx->conn_ctx); if (!user_data) return EINVAL; @@ -132,8 +127,8 @@ static int be_identity(DBusMessage *message, void *data, DBusMessage **r) DEBUG(4,("Sending ID reply: (%d,%d,%s,%s)\n", clitype, version, ctx->name, ctx->domain)); - reply = dbus_message_new_method_return(message); - ret = dbus_message_append_args(reply, + reply->reply_message = dbus_message_new_method_return(message); + ret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_UINT16, &clitype, DBUS_TYPE_UINT16, &version, DBUS_TYPE_STRING, &ctx->name, @@ -143,7 +138,6 @@ static int be_identity(DBusMessage *message, void *data, DBusMessage **r) return EIO; } - *r = reply; return EOK; } @@ -237,13 +231,12 @@ static void online_chk_callback(struct be_req *req, int status, } -static int be_check_online(DBusMessage *message, void *data, DBusMessage **r) +static int be_check_online(DBusMessage *message, struct sbus_message_ctx *reply) { struct sbus_message_handler_ctx *smh_ctx; struct be_online_req *req; struct be_req *be_req; struct be_ctx *ctx; - DBusMessage *reply; dbus_bool_t dbret; void *user_data; int ret; @@ -252,15 +245,15 @@ static int be_check_online(DBusMessage *message, void *data, DBusMessage **r) dbus_uint32_t err_min; const char *err_msg; - if (!data) return EINVAL; - smh_ctx = talloc_get_type(data, struct sbus_message_handler_ctx); + if (!reply) return EINVAL; + smh_ctx = reply->mh_ctx; if (!smh_ctx) return EINVAL; user_data = sbus_conn_get_private_data(smh_ctx->conn_ctx); if (!user_data) return EINVAL; ctx = talloc_get_type(user_data, struct be_ctx); if (!ctx) return EINVAL; - reply = dbus_message_new_method_return(message); + reply->reply_message = dbus_message_new_method_return(message); /* process request */ be_req = talloc(ctx, struct be_req); @@ -273,7 +266,7 @@ static int be_check_online(DBusMessage *message, void *data, DBusMessage **r) } be_req->be_ctx = ctx; be_req->fn = online_chk_callback; - be_req->pvt = reply; + be_req->pvt = reply->reply_message; req = talloc(be_req, struct be_online_req); if (!req) { @@ -303,7 +296,7 @@ done: talloc_free(be_req); } - dbret = dbus_message_append_args(reply, + dbret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_UINT16, &online, DBUS_TYPE_UINT16, &err_maj, DBUS_TYPE_UINT32, &err_min, @@ -311,7 +304,6 @@ done: DBUS_TYPE_INVALID); if (!dbret) return EIO; - *r = reply; return EOK; } @@ -355,13 +347,12 @@ static void acctinfo_callback(struct be_req *req, int status, talloc_free(req); } -static int be_get_account_info(DBusMessage *message, void *data, DBusMessage **r) +static int be_get_account_info(DBusMessage *message, struct sbus_message_ctx *reply) { struct sbus_message_handler_ctx *smh_ctx; struct be_acct_req *req; struct be_req *be_req; struct be_ctx *ctx; - DBusMessage *reply; DBusError dbus_error; dbus_bool_t dbret; void *user_data; @@ -375,10 +366,9 @@ static int be_get_account_info(DBusMessage *message, void *data, DBusMessage **r const char *err_msg; be_req = NULL; - *r = NULL; - if (!data) return EINVAL; - smh_ctx = talloc_get_type(data, struct sbus_message_handler_ctx); + if (!reply) return EINVAL; + smh_ctx = reply->mh_ctx; if (!smh_ctx) return EINVAL; user_data = sbus_conn_get_private_data(smh_ctx->conn_ctx); if (!user_data) return EINVAL; @@ -399,7 +389,7 @@ static int be_get_account_info(DBusMessage *message, void *data, DBusMessage **r DEBUG(4, ("Got request for [%u][%s][%s]\n", type, attrs, filter)); - reply = dbus_message_new_method_return(message); + reply->reply_message = dbus_message_new_method_return(message); if (attrs) { if (strcmp(attrs, "core") == 0) attr_type = BE_ATTR_CORE; @@ -448,7 +438,7 @@ static int be_get_account_info(DBusMessage *message, void *data, DBusMessage **r } be_req->be_ctx = ctx; be_req->fn = acctinfo_callback; - be_req->pvt = reply; + be_req->pvt = reply->reply_message; req = talloc(be_req, struct be_acct_req); if (!req) { @@ -479,7 +469,7 @@ done: talloc_free(be_req); } - dbret = dbus_message_append_args(reply, + dbret = dbus_message_append_args(reply->reply_message, DBUS_TYPE_UINT16, &err_maj, DBUS_TYPE_UINT32, &err_min, DBUS_TYPE_STRING, &err_msg, @@ -489,7 +479,6 @@ done: DEBUG(4, ("Request processed. Returned %d,%d,%s\n", err_maj, err_min, err_msg)); - *r = reply; return EOK; } diff --git a/server/sbus/sssd_dbus.h b/server/sbus/sssd_dbus.h index c75bbc93..bc65e314 100644 --- a/server/sbus/sssd_dbus.h +++ b/server/sbus/sssd_dbus.h @@ -27,7 +27,8 @@ struct sbus_srv_ctx; #include "dbus/dbus.h" -typedef int (*sbus_msg_handler_fn)(DBusMessage *, void *, DBusMessage **); +struct sbus_message_ctx; +typedef int (*sbus_msg_handler_fn)(DBusMessage *, struct sbus_message_ctx *); /* * sbus_conn_destructor_fn @@ -71,6 +72,11 @@ struct sbus_message_handler_ctx { struct sbus_method_ctx *method_ctx; }; +struct sbus_message_ctx { + struct sbus_message_handler_ctx *mh_ctx; + DBusMessage *reply_message; +}; + /* Server Functions */ int sbus_new_server(TALLOC_CTX *mem_ctx, struct event_context *ev, struct sbus_method_ctx *ctx, diff --git a/server/sbus/sssd_dbus_connection.c b/server/sbus/sssd_dbus_connection.c index d02dc6c8..186df356 100644 --- a/server/sbus/sssd_dbus_connection.c +++ b/server/sbus/sssd_dbus_connection.c @@ -483,7 +483,7 @@ DBusHandlerResult sbus_message_handler(DBusConnection *conn, const char *method; const char *path; const char *msg_interface; - DBusMessage *reply = NULL; + struct sbus_message_ctx *reply = NULL; int i, ret; int found; @@ -503,14 +503,22 @@ DBusHandlerResult sbus_message_handler(DBusConnection *conn, if (strcmp(path, ctx->method_ctx->path) != 0) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + reply = talloc_zero(ctx, struct sbus_message_ctx); + if (!reply) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + reply->mh_ctx = ctx; + reply->reply_message = NULL; + /* Validate the method interface */ if (strcmp(msg_interface, ctx->method_ctx->interface) == 0) { found = 0; for (i = 0; ctx->method_ctx->methods[i].method != NULL; i++) { if (strcmp(method, ctx->method_ctx->methods[i].method) == 0) { found = 1; - ret = ctx->method_ctx->methods[i].fn(message, ctx, &reply); - if (ret != EOK) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + ret = ctx->method_ctx->methods[i].fn(message, reply); + if (ret != EOK) { + talloc_free(reply); + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } break; } } @@ -518,7 +526,7 @@ DBusHandlerResult sbus_message_handler(DBusConnection *conn, if (!found) { /* Reply DBUS_ERROR_UNKNOWN_METHOD */ DEBUG(1, ("No matching method found for %s.\n", method)); - reply = dbus_message_new_error(message, DBUS_ERROR_UNKNOWN_METHOD, NULL); + reply->reply_message = dbus_message_new_error(message, DBUS_ERROR_UNKNOWN_METHOD, NULL); } } else { @@ -532,20 +540,24 @@ DBusHandlerResult sbus_message_handler(DBusConnection *conn, /* If we have been asked for introspection data and we have * an introspection function registered, user that. */ - ret = ctx->method_ctx->introspect_fn(message, ctx, &reply); - if (ret != EOK) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + ret = ctx->method_ctx->introspect_fn(message, reply); + if (ret != EOK) { + talloc_free(reply); + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } } } else return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } - DEBUG(5, ("Method %s complete. Reply was %ssent.\n", method, reply?"":"not ")); + DEBUG(5, ("Method %s complete. Reply was %ssent.\n", method, reply->reply_message?"":"not ")); - if (reply) { - dbus_connection_send(conn, reply, NULL); - dbus_message_unref(reply); + if (reply->reply_message) { + dbus_connection_send(conn, reply->reply_message, NULL); + dbus_message_unref(reply->reply_message); } + talloc_free(reply); return DBUS_HANDLER_RESULT_HANDLED; } |