summaryrefslogtreecommitdiffstats
path: root/src/providers
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2014-01-17 12:54:42 +0100
committerJakub Hrozek <jhrozek@redhat.com>2014-06-02 19:03:26 +0200
commit0a001b42869ebffdd6d82ca3a3fdbe31dc707035 (patch)
tree6eb620fa58c7536a4085e392c0d9f0367fce7383 /src/providers
parent4221bd76e2b631684f2dc7e8c625fd7b27947cf8 (diff)
downloadsssd-0a001b42869ebffdd6d82ca3a3fdbe31dc707035.tar.gz
sssd-0a001b42869ebffdd6d82ca3a3fdbe31dc707035.tar.xz
sssd-0a001b42869ebffdd6d82ca3a3fdbe31dc707035.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> (cherry picked from commit d9577dbd92555b0755881e37724019ef9c578404) Conflicts: src/sbus/sssd_dbus.h
Diffstat (limited to 'src/providers')
-rw-r--r--src/providers/data_provider_be.c512
-rw-r--r--src/providers/proxy/proxy_child.c14
-rw-r--r--src/providers/proxy/proxy_init.c38
3 files changed, 202 insertions, 362 deletions
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index 15b0d1d96..ea3939f7e 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -54,14 +54,10 @@
#define ACCESS_DENY "deny"
#define NO_PROVIDER "none"
-static int data_provider_res_init(DBusMessage *message,
- struct sbus_connection *conn);
-static int data_provider_go_offline(DBusMessage *message,
- struct sbus_connection *conn);
-static int data_provider_reset_offline(DBusMessage *message,
- struct sbus_connection *conn);
-static int data_provider_logrotate(DBusMessage *message,
- struct sbus_connection *conn);
+static int data_provider_res_init(struct sbus_request *dbus_req);
+static int data_provider_go_offline(struct sbus_request *dbus_req);
+static int data_provider_reset_offline(struct sbus_request *dbus_req);
+static int data_provider_logrotate(struct sbus_request *dbus_req);
struct mon_cli_iface monitor_be_methods = {
{ &mon_cli_iface_meta, 0 },
@@ -81,13 +77,13 @@ struct sbus_interface monitor_be_interface = {
NULL
};
-static int client_registration(DBusMessage *message, struct sbus_connection *conn);
-static int be_get_account_info(DBusMessage *message, struct sbus_connection *conn);
-static int be_pam_handler(DBusMessage *message, struct sbus_connection *conn);
-static int be_sudo_handler(DBusMessage *message, struct sbus_connection *conn);
-static int be_autofs_handler(DBusMessage *message, struct sbus_connection *conn);
-static int be_host_handler(DBusMessage *message, struct sbus_connection *conn);
-static int be_get_subdomains(DBusMessage *message, struct sbus_connection *conn);
+static int client_registration(struct sbus_request *dbus_req);
+static int be_get_account_info(struct sbus_request *dbus_req);
+static int be_pam_handler(struct sbus_request *dbus_req);
+static int be_sudo_handler(struct sbus_request *dbus_req);
+static int be_autofs_handler(struct sbus_request *dbus_req);
+static int be_host_handler(struct sbus_request *dbus_req);
+static int be_get_subdomains(struct sbus_request *dbus_req);
struct data_provider_iface be_methods = {
{ &data_provider_iface_meta, 0 },
@@ -401,14 +397,12 @@ static void be_queue_next_request(struct be_req *be_req, enum bet_type type)
struct bet_queue_item *item;
struct bet_queue_item *current = NULL;
struct bet_queue_item **req_queue;
+ struct sbus_request *dbus_req;
int ret;
- DBusMessage *reply;
uint16_t err_maj;
uint32_t err_min;
const char *err_msg = "Cannot file back end request";
struct be_req *next_be_req = NULL;
- dbus_bool_t dbret;
- DBusConnection *dbus_conn;
req_queue = &be_req->becli->bectx->bet_info[type].req_queue;
@@ -445,9 +439,9 @@ static void be_queue_next_request(struct be_req *be_req, enum bet_type type)
be_queue_next_request(next_be_req, type);
- reply = (DBusMessage *) next_be_req->pvt;
+ dbus_req = (struct sbus_request *) next_be_req->pvt;
- if (reply) {
+ if (dbus_req) {
/* Return a reply if one was requested
* There may not be one if this request began
* while we were offline
@@ -455,28 +449,13 @@ static void be_queue_next_request(struct be_req *be_req, enum bet_type type)
err_maj = DP_ERR_FATAL;
err_min = ret;
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &err_maj,
- DBUS_TYPE_UINT32, &err_min,
- DBUS_TYPE_STRING, &err_msg,
- DBUS_TYPE_INVALID);
-
- if (!dbret) {
- DEBUG(SSSDBG_CRIT_FAILURE, "Failed to generate dbus reply\n");
- dbus_message_unref(reply);
- goto done;
- }
-
- dbus_conn = sbus_get_connection(next_be_req->becli->conn);
- if (dbus_conn == NULL) {
- DEBUG(SSSDBG_CRIT_FAILURE, "D-BUS not connected\n");
- goto done;
- }
- dbus_connection_send(dbus_conn, reply, NULL);
- dbus_message_unref(reply);
+ sbus_request_return_and_finish(dbus_req,
+ DBUS_TYPE_UINT16, &err_maj,
+ DBUS_TYPE_UINT32, &err_min,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
}
-done:
talloc_free(next_be_req);
}
@@ -545,9 +524,7 @@ static void get_subdomains_callback(struct be_req *req,
int errnum,
const char *errstr)
{
- DBusMessage *reply;
- DBusConnection *dbus_conn;
- dbus_bool_t dbret;
+ struct sbus_request *dbus_req;
dbus_uint16_t err_maj = 0;
dbus_uint32_t err_min = 0;
const char *err_msg = NULL;
@@ -558,9 +535,9 @@ static void get_subdomains_callback(struct be_req *req,
be_queue_next_request(req, BET_SUBDOMAINS);
- reply = (DBusMessage *)req->pvt;
+ dbus_req = (struct sbus_request *)req->pvt;
- if (reply) {
+ if (dbus_req) {
/* Return a reply if one was requested
* There may not be one if this request began
* while we were offline
@@ -578,39 +555,22 @@ static void get_subdomains_callback(struct be_req *req,
err_msg = "OOM";
}
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &err_maj,
- DBUS_TYPE_UINT32, &err_min,
- DBUS_TYPE_STRING, &err_msg,
- DBUS_TYPE_INVALID);
-
- if (!dbret) {
- DEBUG(SSSDBG_CRIT_FAILURE, "Failed to generate dbus reply\n");
- dbus_message_unref(reply);
- goto done;
- }
-
- dbus_conn = sbus_get_connection(req->becli->conn);
- if (dbus_conn == NULL) {
- DEBUG(SSSDBG_CRIT_FAILURE, "D-BUS not connected\n");
- goto done;
- }
- dbus_connection_send(dbus_conn, reply, NULL);
- dbus_message_unref(reply);
+ sbus_request_return_and_finish(dbus_req,
+ DBUS_TYPE_UINT16, &err_maj,
+ DBUS_TYPE_UINT32, &err_min,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
}
-done:
talloc_free(req);
}
-static int be_get_subdomains(DBusMessage *message, struct sbus_connection *conn)
+static int be_get_subdomains(struct sbus_request *dbus_req)
{
struct be_subdom_req *req;
struct be_req *be_req = NULL;
struct be_client *becli;
- DBusMessage *reply;
DBusError dbus_error;
- dbus_bool_t dbret;
void *user_data;
dbus_bool_t force;
char *domain_hint;
@@ -619,14 +579,14 @@ static int be_get_subdomains(DBusMessage *message, struct sbus_connection *conn)
const char *err_msg;
int ret;
- user_data = sbus_conn_get_private_data(conn);
+ user_data = sbus_conn_get_private_data(dbus_req->conn);
if (!user_data) return EINVAL;
becli = talloc_get_type(user_data, struct be_client);
if (!becli) return EINVAL;
dbus_error_init(&dbus_error);
- ret = dbus_message_get_args(message, &dbus_error,
+ ret = dbus_message_get_args(dbus_req->message, &dbus_error,
DBUS_TYPE_BOOLEAN, &force,
DBUS_TYPE_STRING, &domain_hint,
DBUS_TYPE_INVALID);
@@ -636,9 +596,6 @@ static int be_get_subdomains(DBusMessage *message, struct sbus_connection *conn)
return EIO;
}
- reply = dbus_message_new_method_return(message);
- if (!reply) return ENOMEM;
-
/* return an error if corresponding backend target is not configured */
if (becli->bectx->bet_info[BET_SUBDOMAINS].bet_ops == NULL) {
DEBUG(SSSDBG_TRACE_INTERNAL, "Undefined backend target.\n");
@@ -665,7 +622,7 @@ static int be_get_subdomains(DBusMessage *message, struct sbus_connection *conn)
/* process request */
be_req = be_req_create(becli, becli, becli->bectx,
- get_subdomains_callback, reply);
+ get_subdomains_callback, dbus_req);
if (!be_req) {
err_maj = DP_ERR_FATAL;
err_min = ENOMEM;
@@ -710,26 +667,16 @@ immediate:
talloc_free(be_req);
}
- if (reply) {
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &err_maj,
- DBUS_TYPE_UINT32, &err_min,
- DBUS_TYPE_STRING, &err_msg,
- DBUS_TYPE_INVALID);
- if (!dbret) {
- DEBUG(SSSDBG_CRIT_FAILURE, "Failed to generate dbus reply\n");
- dbus_message_unref(reply);
- return EIO;
- }
-
- if (!(err_maj == DP_ERR_FATAL && err_min == ENODEV)) {
- DEBUG(SSSDBG_TRACE_LIBS, "Request processed. Returned %d,%d,%s\n",
- err_maj, err_min, err_msg);
- }
+ /* send reply back */
+ sbus_request_return_and_finish(dbus_req,
+ DBUS_TYPE_UINT16, &err_maj,
+ DBUS_TYPE_UINT32, &err_min,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
- /* send reply back */
- sbus_conn_send_reply(conn, reply);
- dbus_message_unref(reply);
+ if (!(err_maj == DP_ERR_FATAL && err_min == ENODEV)) {
+ DEBUG(SSSDBG_TRACE_LIBS, "Request processed. Returned %d,%d,%s\n",
+ err_maj, err_min, err_msg);
}
return EOK;
@@ -740,16 +687,14 @@ static void acctinfo_callback(struct be_req *req,
int errnum,
const char *errstr)
{
- DBusMessage *reply;
- DBusConnection *dbus_conn;
- dbus_bool_t dbret;
+ struct sbus_request *dbus_req;
dbus_uint16_t err_maj = 0;
dbus_uint32_t err_min = 0;
const char *err_msg = NULL;
- reply = (DBusMessage *)req->pvt;
+ dbus_req = (struct sbus_request *)req->pvt;
- if (reply) {
+ if (dbus_req) {
/* Return a reply if one was requested
* There may not be one if this request began
* while we were offline
@@ -768,24 +713,11 @@ static void acctinfo_callback(struct be_req *req,
err_msg = "OOM";
}
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &err_maj,
- DBUS_TYPE_UINT32, &err_min,
- DBUS_TYPE_STRING, &err_msg,
- DBUS_TYPE_INVALID);
- if (!dbret) {
- DEBUG(SSSDBG_CRIT_FAILURE, "Failed to generate dbus reply\n");
- return;
- }
-
- dbus_conn = sbus_get_connection(req->becli->conn);
- if (!dbus_conn) {
- DEBUG(SSSDBG_CRIT_FAILURE, "D-BUS not connected\n");
- return;
- }
-
- dbus_connection_send(dbus_conn, reply, NULL);
- dbus_message_unref(reply);
+ sbus_request_return_and_finish(dbus_req,
+ DBUS_TYPE_UINT16, &err_maj,
+ DBUS_TYPE_UINT32, &err_min,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
DEBUG(SSSDBG_CONF_SETTINGS, "Request processed. Returned %d,%d,%s\n",
err_maj, err_min, err_msg);
@@ -1114,14 +1046,12 @@ errno_t be_get_account_info_recv(struct tevent_req *req,
return EOK;
}
-static int be_get_account_info(DBusMessage *message, struct sbus_connection *conn)
+static int be_get_account_info(struct sbus_request *dbus_req)
{
struct be_acct_req *req;
struct be_req *be_req;
struct be_client *becli;
- DBusMessage *reply;
DBusError dbus_error;
- dbus_bool_t dbret;
void *user_data;
uint32_t type;
char *filter;
@@ -1134,14 +1064,14 @@ static int be_get_account_info(DBusMessage *message, struct sbus_connection *con
be_req = NULL;
- user_data = sbus_conn_get_private_data(conn);
+ user_data = sbus_conn_get_private_data(dbus_req->conn);
if (!user_data) return EINVAL;
becli = talloc_get_type(user_data, struct be_client);
if (!becli) return EINVAL;
dbus_error_init(&dbus_error);
- ret = dbus_message_get_args(message, &dbus_error,
+ ret = dbus_message_get_args(dbus_req->message, &dbus_error,
DBUS_TYPE_UINT32, &type,
DBUS_TYPE_UINT32, &attr_type,
DBUS_TYPE_STRING, &filter,
@@ -1156,9 +1086,6 @@ static int be_get_account_info(DBusMessage *message, struct sbus_connection *con
DEBUG(SSSDBG_CONF_SETTINGS,
"Got request for [%u][%d][%s]\n", type, attr_type, filter);
- reply = dbus_message_new_method_return(message);
- if (!reply) return ENOMEM;
-
/* If we are offline and fast reply was requested
* return offline immediately
*/
@@ -1168,19 +1095,19 @@ static int be_get_account_info(DBusMessage *message, struct sbus_connection *con
err_min = EAGAIN;
err_msg = "Fast reply - offline";
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &err_maj,
- DBUS_TYPE_UINT32, &err_min,
- DBUS_TYPE_STRING, &err_msg,
- DBUS_TYPE_INVALID);
- if (!dbret) return EIO;
+ ret = sbus_request_return_and_finish(dbus_req,
+ DBUS_TYPE_UINT16, &err_maj,
+ DBUS_TYPE_UINT32, &err_min,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
+ if (ret != EOK) {
+ return ret;
+ }
DEBUG(SSSDBG_CONF_SETTINGS, "Request processed. Returned %d,%d,%s\n",
err_maj, err_min, err_msg);
- sbus_conn_send_reply(conn, reply);
- dbus_message_unref(reply);
- reply = NULL;
+ dbus_req = NULL;
/* This reply will be queued and sent
* when we reenter the mainloop.
*
@@ -1190,7 +1117,7 @@ static int be_get_account_info(DBusMessage *message, struct sbus_connection *con
}
be_req = be_req_create(becli, becli, becli->bectx,
- acctinfo_callback, reply);
+ acctinfo_callback, dbus_req);
if (!be_req) {
err_maj = DP_ERR_FATAL;
err_min = ENOMEM;
@@ -1291,20 +1218,18 @@ done:
talloc_free(be_req);
}
- if (reply) {
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &err_maj,
- DBUS_TYPE_UINT32, &err_min,
- DBUS_TYPE_STRING, &err_msg,
- DBUS_TYPE_INVALID);
- if (!dbret) return EIO;
+ if (dbus_req) {
+ ret = sbus_request_return_and_finish(dbus_req,
+ DBUS_TYPE_UINT16, &err_maj,
+ DBUS_TYPE_UINT32, &err_min,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
+ if (ret != EOK) {
+ return ret;
+ }
DEBUG(SSSDBG_CONF_SETTINGS, "Request processed. Returned %d,%d,%s\n",
err_maj, err_min, err_msg);
-
- /* send reply back */
- sbus_conn_send_reply(conn, reply);
- dbus_message_unref(reply);
}
return EOK;
@@ -1316,9 +1241,9 @@ static void be_pam_handler_callback(struct be_req *req,
const char *errstr)
{
struct be_client *becli = req->becli;
+ struct sbus_request *dbus_req;
struct pam_data *pd;
DBusMessage *reply;
- DBusConnection *dbus_conn;
dbus_bool_t dbret;
errno_t ret;
@@ -1353,7 +1278,14 @@ static void be_pam_handler_callback(struct be_req *req,
DEBUG(SSSDBG_CONF_SETTINGS,
"Sending result [%d][%s]\n", pd->pam_status, pd->domain);
- reply = (DBusMessage *)req->pvt;
+ dbus_req = (struct sbus_request *)req->pvt;
+ reply = dbus_message_new_method_return(dbus_req->message);
+ if (reply == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "dbus_message_new_method_return failed, cannot send reply.\n");
+ goto done;
+ }
+
dbret = dp_pack_pam_response(reply, pd);
if (!dbret) {
DEBUG(SSSDBG_CRIT_FAILURE, "Failed to generate dbus reply\n");
@@ -1361,13 +1293,7 @@ static void be_pam_handler_callback(struct be_req *req,
goto done;
}
- dbus_conn = sbus_get_connection(req->becli->conn);
- if (!dbus_conn) {
- DEBUG(SSSDBG_CRIT_FAILURE, "D-BUS not connected\n");
- goto done;
- }
-
- dbus_connection_send(dbus_conn, reply, NULL);
+ sbus_request_finish(dbus_req, reply);
dbus_message_unref(reply);
DEBUG(SSSDBG_CONF_SETTINGS,
@@ -1377,7 +1303,7 @@ done:
talloc_free(req);
}
-static int be_pam_handler(DBusMessage *message, struct sbus_connection *conn)
+static int be_pam_handler(struct sbus_request *dbus_req)
{
DBusError dbus_error;
DBusMessage *reply;
@@ -1388,29 +1314,21 @@ static int be_pam_handler(DBusMessage *message, struct sbus_connection *conn)
struct be_req *be_req = NULL;
enum bet_type target = BET_NULL;
- user_data = sbus_conn_get_private_data(conn);
+ user_data = sbus_conn_get_private_data(dbus_req->conn);
if (!user_data) return EINVAL;
becli = talloc_get_type(user_data, struct be_client);
if (!becli) return EINVAL;
- reply = dbus_message_new_method_return(message);
- if (!reply) {
- DEBUG(SSSDBG_CRIT_FAILURE,
- "dbus_message_new_method_return failed, cannot send reply.\n");
- return ENOMEM;
- }
-
be_req = be_req_create(becli, becli, becli->bectx,
- be_pam_handler_callback, reply);
+ be_pam_handler_callback, dbus_req);
if (!be_req) {
DEBUG(SSSDBG_TRACE_LIBS, "talloc_zero failed.\n");
- dbus_message_unref(reply);
return ENOMEM;
}
dbus_error_init(&dbus_error);
- ret = dp_unpack_pam_request(message, be_req, &pd, &dbus_error);
+ ret = dp_unpack_pam_request(dbus_req->message, be_req, &pd, &dbus_error);
if (!ret) {
DEBUG(SSSDBG_CRIT_FAILURE,"Failed, to parse message!\n");
talloc_free(be_req);
@@ -1488,6 +1406,13 @@ done:
DEBUG(SSSDBG_CONF_SETTINGS, "Sending result [%d][%s]\n",
pd->pam_status, pd->domain);
+ reply = dbus_message_new_method_return(dbus_req->message);
+ if (reply == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "dbus_message_new_method_return failed, cannot send reply.\n");
+ return ENOMEM;
+ }
+
ret = dp_pack_pam_response(reply, pd);
if (!ret) {
DEBUG(SSSDBG_CRIT_FAILURE, "Failed to generate dbus reply\n");
@@ -1497,7 +1422,7 @@ done:
}
/* send reply back immediately */
- sbus_conn_send_reply(conn, reply);
+ sbus_request_finish(dbus_req, reply);
dbus_message_unref(reply);
talloc_free(be_req);
@@ -1505,42 +1430,26 @@ done:
return EOK;
}
-static void be_sudo_handler_reply(struct sbus_connection *conn,
- DBusMessage *reply,
+static void be_sudo_handler_reply(struct sbus_request *dbus_req,
dbus_uint16_t dp_err,
dbus_uint32_t dp_ret,
const char *errstr)
{
- DBusConnection *dbus_conn = NULL;
- dbus_bool_t dbret;
const char *err_msg = NULL;
- if (reply == NULL) {
+ if (dbus_req == NULL) {
return;
}
err_msg = errstr ? errstr : "No errmsg set\n";
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &dp_err,
- DBUS_TYPE_UINT32, &dp_ret,
- DBUS_TYPE_STRING, &err_msg,
- DBUS_TYPE_INVALID);
- if (!dbret) {
- DEBUG(SSSDBG_CRIT_FAILURE, "Failed to generate dbus reply\n");
- return;
- }
+ sbus_request_return_and_finish(dbus_req,
+ DBUS_TYPE_UINT16, &dp_err,
+ DBUS_TYPE_UINT32, &dp_ret,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
DEBUG(SSSDBG_FUNC_DATA, "SUDO Backend returned: (%d, %d, %s)\n",
dp_err, dp_ret, errstr ? errstr : "<NULL>");
-
- dbus_conn = sbus_get_connection(conn);
- if (!dbus_conn) {
- DEBUG(SSSDBG_CRIT_FAILURE, "D-BUS not connected\n");
- return;
- }
-
- dbus_connection_send(dbus_conn, reply, NULL);
- dbus_message_unref(reply);
}
static void be_sudo_handler_callback(struct be_req *req,
@@ -1548,18 +1457,17 @@ static void be_sudo_handler_callback(struct be_req *req,
int dp_ret,
const char *errstr)
{
- DBusMessage *reply = NULL;
- reply = (DBusMessage*)(req->pvt);
+ struct sbus_request *dbus_req;
+ dbus_req = (struct sbus_request *)(req->pvt);
- be_sudo_handler_reply(req->becli->conn, reply, dp_err, dp_ret, errstr);
+ be_sudo_handler_reply(dbus_req, dp_err, dp_ret, errstr);
talloc_free(req);
}
-static int be_sudo_handler(DBusMessage *message, struct sbus_connection *conn)
+static int be_sudo_handler(struct sbus_request *dbus_req)
{
DBusError dbus_error;
- DBusMessage *reply = NULL;
DBusMessageIter iter;
dbus_bool_t iter_next = FALSE;
struct be_client *be_cli = NULL;
@@ -1575,7 +1483,7 @@ static int be_sudo_handler(DBusMessage *message, struct sbus_connection *conn)
DEBUG(SSSDBG_TRACE_FUNC, "Entering be_sudo_handler()\n");
- user_data = sbus_conn_get_private_data(conn);
+ user_data = sbus_conn_get_private_data(dbus_req->conn);
if (user_data == NULL) {
return EINVAL;
}
@@ -1585,24 +1493,16 @@ static int be_sudo_handler(DBusMessage *message, struct sbus_connection *conn)
return EINVAL;
}
- reply = dbus_message_new_method_return(message);
- if (!reply) {
- DEBUG(SSSDBG_CRIT_FAILURE,
- "dbus_message_new_method_return failed, cannot send reply.\n");
- return ENOMEM;
- }
-
/* create be request */
be_req = be_req_create(be_cli, be_cli, be_cli->bectx,
- be_sudo_handler_callback, reply);
+ be_sudo_handler_callback, dbus_req);
if (be_req == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero failed.\n");
- dbus_message_unref(reply);
return ENOMEM;
}
dbus_error_init(&dbus_error);
- dbus_message_iter_init(message, &iter);
+ dbus_message_iter_init(dbus_req->message, &iter);
/* get type of the request */
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32) {
@@ -1618,9 +1518,9 @@ static int be_sudo_handler(DBusMessage *message, struct sbus_connection *conn)
* return offline immediately
*/
if ((type & BE_REQ_FAST) && be_cli->bectx->offstat.offline) {
- be_sudo_handler_reply(conn, reply, DP_ERR_OFFLINE, EAGAIN,
+ be_sudo_handler_reply(dbus_req, DP_ERR_OFFLINE, EAGAIN,
"Fast reply - offline");
- reply = NULL;
+ be_req->pvt = dbus_req = NULL;
/* This reply will be queued and sent
* when we reenter the mainloop.
*
@@ -1732,11 +1632,9 @@ static void be_autofs_handler_callback(struct be_req *req,
int errnum,
const char *errstr);
-static int be_autofs_handler(DBusMessage *message, struct sbus_connection *conn)
+static int be_autofs_handler(struct sbus_request *dbus_req)
{
DBusError dbus_error;
- DBusMessage *reply = NULL;
- dbus_bool_t dbret;
struct be_client *be_cli = NULL;
struct be_req *be_req = NULL;
struct be_autofs_req *be_autofs_req = NULL;
@@ -1751,7 +1649,7 @@ static int be_autofs_handler(DBusMessage *message, struct sbus_connection *conn)
DEBUG(SSSDBG_TRACE_FUNC, "Entering be_autofs_handler()\n");
- user_data = sbus_conn_get_private_data(conn);
+ user_data = sbus_conn_get_private_data(dbus_req->conn);
if (user_data == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Cannot get SBUS private data\n");
return EINVAL;
@@ -1765,7 +1663,7 @@ static int be_autofs_handler(DBusMessage *message, struct sbus_connection *conn)
dbus_error_init(&dbus_error);
- ret = dbus_message_get_args(message, &dbus_error,
+ ret = dbus_message_get_args(dbus_req->message, &dbus_error,
DBUS_TYPE_UINT32, &type,
DBUS_TYPE_STRING, &filter,
DBUS_TYPE_INVALID);
@@ -1775,13 +1673,6 @@ static int be_autofs_handler(DBusMessage *message, struct sbus_connection *conn)
return EIO;
}
- reply = dbus_message_new_method_return(message);
- if (!reply) {
- DEBUG(SSSDBG_CRIT_FAILURE,
- "dbus_message_new_method_return failed, cannot send reply.\n");
- return ENOMEM;
- }
-
/* If we are offline and fast reply was requested
* return offline immediately
*/
@@ -1791,19 +1682,19 @@ static int be_autofs_handler(DBusMessage *message, struct sbus_connection *conn)
err_min = EAGAIN;
err_msg = "Fast reply - offline";
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &err_maj,
- DBUS_TYPE_UINT32, &err_min,
- DBUS_TYPE_STRING, &err_msg,
- DBUS_TYPE_INVALID);
- if (!dbret) return EIO;
+ ret = sbus_request_return_and_finish(dbus_req,
+ DBUS_TYPE_UINT16, &err_maj,
+ DBUS_TYPE_UINT32, &err_min,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
+ if (ret != EOK) {
+ return ret;
+ }
DEBUG(SSSDBG_TRACE_LIBS, "Request processed. Returned %d,%d,%s\n",
err_maj, err_min, err_msg);
- sbus_conn_send_reply(conn, reply);
- dbus_message_unref(reply);
- reply = NULL;
+ dbus_req = NULL;
/* This reply will be queued and sent
* when we reenter the mainloop.
*
@@ -1830,7 +1721,7 @@ static int be_autofs_handler(DBusMessage *message, struct sbus_connection *conn)
/* create be request */
be_req = be_req_create(be_cli, be_cli, be_cli->bectx,
- be_autofs_handler_callback, reply);
+ be_autofs_handler_callback, dbus_req);
if (be_req == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero failed.\n");
err_maj = DP_ERR_FATAL;
@@ -1893,20 +1784,18 @@ done:
talloc_free(be_req);
}
- if (reply) {
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &err_maj,
- DBUS_TYPE_UINT32, &err_min,
- DBUS_TYPE_STRING, &err_msg,
- DBUS_TYPE_INVALID);
- if (!dbret) return EIO;
+ if (dbus_req) {
+ ret = sbus_request_return_and_finish(dbus_req,
+ DBUS_TYPE_UINT16, &err_maj,
+ DBUS_TYPE_UINT32, &err_min,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
+ if (ret != EOK) {
+ return ret;
+ }
DEBUG(SSSDBG_TRACE_LIBS, "Request processed. Returned %d,%d,%s\n",
err_maj, err_min, err_msg);
-
- /* send reply back */
- sbus_conn_send_reply(conn, reply);
- dbus_message_unref(reply);
}
return EOK;
@@ -1917,16 +1806,14 @@ static void be_autofs_handler_callback(struct be_req *req,
int errnum,
const char *errstr)
{
- DBusMessage *reply;
- DBusConnection *dbus_conn;
- dbus_bool_t dbret;
+ struct sbus_request *dbus_req;
dbus_uint16_t err_maj = 0;
dbus_uint32_t err_min = 0;
const char *err_msg = NULL;
- reply = (DBusMessage *)req->pvt;
+ dbus_req = (struct sbus_request *)req->pvt;
- if (reply) {
+ if (dbus_req) {
/* Return a reply if one was requested
* There may not be one if this request began
* while we were offline
@@ -1945,24 +1832,11 @@ static void be_autofs_handler_callback(struct be_req *req,
err_msg = "OOM";
}
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &err_maj,
- DBUS_TYPE_UINT32, &err_min,
- DBUS_TYPE_STRING, &err_msg,
- DBUS_TYPE_INVALID);
- if (!dbret) {
- DEBUG(SSSDBG_CRIT_FAILURE, "Failed to generate dbus reply\n");
- return;
- }
-
- dbus_conn = sbus_get_connection(req->becli->conn);
- if (!dbus_conn) {
- DEBUG(SSSDBG_CRIT_FAILURE, "D-BUS not connected\n");
- return;
- }
-
- dbus_connection_send(dbus_conn, reply, NULL);
- dbus_message_unref(reply);
+ sbus_request_return_and_finish(dbus_req,
+ DBUS_TYPE_UINT16, &err_maj,
+ DBUS_TYPE_UINT32, &err_min,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
DEBUG(SSSDBG_TRACE_LIBS,
"Request processed. Returned %d,%d,%s\n",
@@ -1973,14 +1847,12 @@ static void be_autofs_handler_callback(struct be_req *req,
talloc_free(req);
}
-static int be_host_handler(DBusMessage *message, struct sbus_connection *conn)
+static int be_host_handler(struct sbus_request *dbus_req)
{
struct be_host_req *req;
struct be_req *be_req;
struct be_client *becli;
- DBusMessage *reply;
DBusError dbus_error;
- dbus_bool_t dbret;
void *user_data;
uint32_t flags;
char *filter;
@@ -1991,14 +1863,14 @@ static int be_host_handler(DBusMessage *message, struct sbus_connection *conn)
be_req = NULL;
- user_data = sbus_conn_get_private_data(conn);
+ user_data = sbus_conn_get_private_data(dbus_req->conn);
if (!user_data) return EINVAL;
becli = talloc_get_type(user_data, struct be_client);
if (!becli) return EINVAL;
dbus_error_init(&dbus_error);
- ret = dbus_message_get_args(message, &dbus_error,
+ ret = dbus_message_get_args(dbus_req->message, &dbus_error,
DBUS_TYPE_UINT32, &flags,
DBUS_TYPE_STRING, &filter,
DBUS_TYPE_INVALID);
@@ -2011,9 +1883,6 @@ static int be_host_handler(DBusMessage *message, struct sbus_connection *conn)
DEBUG(SSSDBG_TRACE_LIBS,
"Got request for [%u][%s]\n", flags, filter);
- reply = dbus_message_new_method_return(message);
- if (!reply) return ENOMEM;
-
/* If we are offline and fast reply was requested
* return offline immediately
*/
@@ -2023,20 +1892,20 @@ static int be_host_handler(DBusMessage *message, struct sbus_connection *conn)
err_min = EAGAIN;
err_msg = "Fast reply - offline";
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &err_maj,
- DBUS_TYPE_UINT32, &err_min,
- DBUS_TYPE_STRING, &err_msg,
- DBUS_TYPE_INVALID);
- if (!dbret) return EIO;
+ ret = sbus_request_return_and_finish(dbus_req,
+ DBUS_TYPE_UINT16, &err_maj,
+ DBUS_TYPE_UINT32, &err_min,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
+ if (ret != EOK) {
+ return ret;
+ }
DEBUG(SSSDBG_TRACE_LIBS,
"Request processed. Returned %d,%d,%s\n",
err_maj, err_min, err_msg);
- sbus_conn_send_reply(conn, reply);
- dbus_message_unref(reply);
- reply = NULL;
+ dbus_req = NULL;
/* This reply will be queued and sent
* when we reenter the mainloop.
*
@@ -2046,7 +1915,7 @@ static int be_host_handler(DBusMessage *message, struct sbus_connection *conn)
}
be_req = be_req_create(becli, becli, becli->bectx,
- acctinfo_callback, reply);
+ acctinfo_callback, dbus_req);
if (!be_req) {
err_maj = DP_ERR_FATAL;
err_min = ENOMEM;
@@ -2114,21 +1983,19 @@ done:
talloc_free(be_req);
}
- if (reply) {
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &err_maj,
- DBUS_TYPE_UINT32, &err_min,
- DBUS_TYPE_STRING, &err_msg,
- DBUS_TYPE_INVALID);
- if (!dbret) return EIO;
+ if (dbus_req) {
+ ret = sbus_request_return_and_finish(dbus_req,
+ DBUS_TYPE_UINT16, &err_maj,
+ DBUS_TYPE_UINT32, &err_min,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
+ if (ret != EOK) {
+ return ret;
+ }
DEBUG(SSSDBG_TRACE_LIBS,
"Request processed. Returned %d,%d,%s\n",
err_maj, err_min, err_msg);
-
- /* send reply back */
- sbus_conn_send_reply(conn, reply);
- dbus_message_unref(reply);
}
return EOK;
@@ -2163,18 +2030,19 @@ static int be_client_destructor(void *ctx)
return 0;
}
-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 be_client *becli;
- DBusMessage *reply;
DBusError dbus_error;
dbus_uint16_t cli_ver;
char *cli_name;
dbus_bool_t dbret;
void *data;
+ int ret;
+ conn = dbus_req->conn;
data = sbus_conn_get_private_data(conn);
becli = talloc_get_type(data, struct be_client);
if (!becli) {
@@ -2188,7 +2056,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_STRING, &cli_name,
DBUS_TYPE_INVALID);
@@ -2221,26 +2089,14 @@ static int client_registration(DBusMessage *message,
DEBUG(SSSDBG_CONF_SETTINGS, "Added Frontend client [%s]\n", cli_name);
/* 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);
-
becli->initialized = true;
return EOK;
}
@@ -3023,45 +2879,41 @@ int main(int argc, const char *argv[])
}
#endif
-static int data_provider_res_init(DBusMessage *message,
- struct sbus_connection *conn)
+static int data_provider_res_init(struct sbus_request *dbus_req)
{
struct be_ctx *be_ctx;
- be_ctx = talloc_get_type(sbus_conn_get_private_data(conn), struct be_ctx);
+ be_ctx = talloc_get_type(sbus_conn_get_private_data(dbus_req->conn), struct be_ctx);
resolv_reread_configuration(be_ctx->be_res->resolv);
check_if_online(be_ctx);
- return monitor_common_res_init(message, conn);
+ return monitor_common_res_init(dbus_req);
}
-static int data_provider_go_offline(DBusMessage *message,
- struct sbus_connection *conn)
+static int data_provider_go_offline(struct sbus_request *dbus_req)
{
struct be_ctx *be_ctx;
- be_ctx = talloc_get_type(sbus_conn_get_private_data(conn), struct be_ctx);
+ be_ctx = talloc_get_type(sbus_conn_get_private_data(dbus_req->conn), struct be_ctx);
be_mark_offline(be_ctx);
- return monitor_common_pong(message, conn);
+ return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
}
-static int data_provider_reset_offline(DBusMessage *message,
- struct sbus_connection *conn)
+static int data_provider_reset_offline(struct sbus_request *dbus_req)
{
struct be_ctx *be_ctx;
- be_ctx = talloc_get_type(sbus_conn_get_private_data(conn), struct be_ctx);
+ be_ctx = talloc_get_type(sbus_conn_get_private_data(dbus_req->conn), struct be_ctx);
check_if_online(be_ctx);
- return monitor_common_pong(message, conn);
+ return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
}
-static int data_provider_logrotate(DBusMessage *message,
- struct sbus_connection *conn)
+static int data_provider_logrotate(struct sbus_request *dbus_req)
{
errno_t ret;
- struct be_ctx *be_ctx = talloc_get_type(sbus_conn_get_private_data(conn),
+ struct be_ctx *be_ctx = talloc_get_type(sbus_conn_get_private_data(dbus_req->conn),
struct be_ctx);
ret = monitor_common_rotate_logs(be_ctx->cdb, be_ctx->conf_path);
if (ret != EOK) return ret;
- return monitor_common_pong(message, conn);
+ return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
}
diff --git a/src/providers/proxy/proxy_child.c b/src/providers/proxy/proxy_child.c
index 46b55b9b8..44d4fd662 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;