summaryrefslogtreecommitdiffstats
path: root/src/providers
diff options
context:
space:
mode:
authorStef Walter <stefw@redhat.com>2014-02-18 14:32:54 +0100
committerJakub Hrozek <jhrozek@redhat.com>2014-06-02 19:03:26 +0200
commit5312bab5fa3a472111e0d6452ac326293adbfdbd (patch)
tree9c35700ff1e456391155b0aacfd6b27700983578 /src/providers
parent0a001b42869ebffdd6d82ca3a3fdbe31dc707035 (diff)
downloadsssd-5312bab5fa3a472111e0d6452ac326293adbfdbd.tar.gz
sssd-5312bab5fa3a472111e0d6452ac326293adbfdbd.tar.xz
sssd-5312bab5fa3a472111e0d6452ac326293adbfdbd.zip
sbus: Refactor how we export DBus interfaces
Most importantly, stop using per connection private data. This doesn't scale when you have more than one thing exporting or exported on a connection. Remove struct sbus_interface and expand sbus_conn_add_interface() function. Remove various struct sbus_interface args to connection initialization functions and make callers use sbus_conn_add_interface() directly. The old method was optimized for exporting one interface on a connection. We'll have connections that export zero, one or more interfaces. To export an interface on a DBus server, call sbus_conn_add_interface() from within the sbus_server_conn_init_fn. To export an interface on a DBus client, call sbus_conn_add_interface() after sbus_new_connection() returns. As before struct sbus_interface represents an object exported via DBus. However it is now talloc allocated. One can set instance data on the struct sbus_interface. This instance data is passed to the various handlers and used in their implementation. However, we now have type safe interface exporting in the various high level sss_process_init() sss_monitor_init() and so on. Introspection support was not in use, and is now gone until we implement it using the metadata (future patch). 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 07e941c1bbdc752142bbd3b838c540bc7ecd0ed7)
Diffstat (limited to 'src/providers')
-rw-r--r--src/providers/data_provider_be.c107
-rw-r--r--src/providers/proxy/proxy_child.c32
-rw-r--r--src/providers/proxy/proxy_init.c22
3 files changed, 59 insertions, 102 deletions
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index ea3939f7e..3c2dda230 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -54,10 +54,10 @@
#define ACCESS_DENY "deny"
#define NO_PROVIDER "none"
-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);
+static int data_provider_res_init(struct sbus_request *dbus_req, void *data);
+static int data_provider_go_offline(struct sbus_request *dbus_req, void *data);
+static int data_provider_reset_offline(struct sbus_request *dbus_req, void *data);
+static int data_provider_logrotate(struct sbus_request *dbus_req, void *data);
struct mon_cli_iface monitor_be_methods = {
{ &mon_cli_iface_meta, 0 },
@@ -71,19 +71,13 @@ struct mon_cli_iface monitor_be_methods = {
.clearEnumCache = NULL,
};
-struct sbus_interface monitor_be_interface = {
- MONITOR_PATH,
- &monitor_be_methods.vtable,
- NULL
-};
-
-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);
+static int client_registration(struct sbus_request *dbus_req, void *data);
+static int be_get_account_info(struct sbus_request *dbus_req, void *user_data);
+static int be_pam_handler(struct sbus_request *dbus_req, void *user_data);
+static int be_sudo_handler(struct sbus_request *dbus_req, void *user_data);
+static int be_autofs_handler(struct sbus_request *dbus_req, void *user_data);
+static int be_host_handler(struct sbus_request *dbus_req, void *user_data);
+static int be_get_subdomains(struct sbus_request *dbus_req, void *user_data);
struct data_provider_iface be_methods = {
{ &data_provider_iface_meta, 0 },
@@ -96,12 +90,6 @@ struct data_provider_iface be_methods = {
.getAccountInfo = be_get_account_info,
};
-struct sbus_interface be_interface = {
- DP_PATH,
- &be_methods.vtable,
- NULL
-};
-
static struct bet_data bet_data[] = {
{BET_NULL, NULL, NULL},
{BET_ID, CONFDB_DOMAIN_ID_PROVIDER, "sssm_%s_id_init"},
@@ -565,13 +553,12 @@ static void get_subdomains_callback(struct be_req *req,
talloc_free(req);
}
-static int be_get_subdomains(struct sbus_request *dbus_req)
+static int be_get_subdomains(struct sbus_request *dbus_req, void *user_data)
{
struct be_subdom_req *req;
struct be_req *be_req = NULL;
struct be_client *becli;
DBusError dbus_error;
- void *user_data;
dbus_bool_t force;
char *domain_hint;
dbus_uint16_t err_maj;
@@ -579,8 +566,6 @@ static int be_get_subdomains(struct sbus_request *dbus_req)
const char *err_msg;
int ret;
- 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;
@@ -1046,13 +1031,12 @@ errno_t be_get_account_info_recv(struct tevent_req *req,
return EOK;
}
-static int be_get_account_info(struct sbus_request *dbus_req)
+static int be_get_account_info(struct sbus_request *dbus_req, void *user_data)
{
struct be_acct_req *req;
struct be_req *be_req;
struct be_client *becli;
DBusError dbus_error;
- void *user_data;
uint32_t type;
char *filter;
char *domain;
@@ -1064,8 +1048,6 @@ static int be_get_account_info(struct sbus_request *dbus_req)
be_req = NULL;
- 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;
@@ -1303,19 +1285,16 @@ done:
talloc_free(req);
}
-static int be_pam_handler(struct sbus_request *dbus_req)
+static int be_pam_handler(struct sbus_request *dbus_req, void *user_data)
{
DBusError dbus_error;
DBusMessage *reply;
struct be_client *becli;
dbus_bool_t ret;
- void *user_data;
struct pam_data *pd = NULL;
struct be_req *be_req = NULL;
enum bet_type target = BET_NULL;
- 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;
@@ -1465,7 +1444,7 @@ static void be_sudo_handler_callback(struct be_req *req,
talloc_free(req);
}
-static int be_sudo_handler(struct sbus_request *dbus_req)
+static int be_sudo_handler(struct sbus_request *dbus_req, void *user_data)
{
DBusError dbus_error;
DBusMessageIter iter;
@@ -1473,7 +1452,6 @@ static int be_sudo_handler(struct sbus_request *dbus_req)
struct be_client *be_cli = NULL;
struct be_req *be_req = NULL;
struct be_sudo_req *sudo_req = NULL;
- void *user_data = NULL;
int ret = 0;
uint32_t type;
uint32_t rules_num = 0;
@@ -1483,11 +1461,6 @@ static int be_sudo_handler(struct sbus_request *dbus_req)
DEBUG(SSSDBG_TRACE_FUNC, "Entering be_sudo_handler()\n");
- user_data = sbus_conn_get_private_data(dbus_req->conn);
- if (user_data == NULL) {
- return EINVAL;
- }
-
be_cli = talloc_get_type(user_data, struct be_client);
if (be_cli == NULL) {
return EINVAL;
@@ -1632,13 +1605,12 @@ static void be_autofs_handler_callback(struct be_req *req,
int errnum,
const char *errstr);
-static int be_autofs_handler(struct sbus_request *dbus_req)
+static int be_autofs_handler(struct sbus_request *dbus_req, void *user_data)
{
DBusError dbus_error;
struct be_client *be_cli = NULL;
struct be_req *be_req = NULL;
struct be_autofs_req *be_autofs_req = NULL;
- void *user_data = NULL;
int ret = 0;
uint32_t type;
char *filter;
@@ -1649,12 +1621,6 @@ static int be_autofs_handler(struct sbus_request *dbus_req)
DEBUG(SSSDBG_TRACE_FUNC, "Entering be_autofs_handler()\n");
- 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;
- }
-
be_cli = talloc_get_type(user_data, struct be_client);
if (be_cli == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Cannot get back end client context\n");
@@ -1847,13 +1813,12 @@ static void be_autofs_handler_callback(struct be_req *req,
talloc_free(req);
}
-static int be_host_handler(struct sbus_request *dbus_req)
+static int be_host_handler(struct sbus_request *dbus_req, void *user_data)
{
struct be_host_req *req;
struct be_req *be_req;
struct be_client *becli;
DBusError dbus_error;
- void *user_data;
uint32_t flags;
char *filter;
int ret;
@@ -1863,8 +1828,6 @@ static int be_host_handler(struct sbus_request *dbus_req)
be_req = NULL;
- 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;
@@ -2030,7 +1993,7 @@ static int be_client_destructor(void *ctx)
return 0;
}
-static int client_registration(struct sbus_request *dbus_req)
+static int client_registration(struct sbus_request *dbus_req, void *data)
{
dbus_uint16_t version = DATA_PROVIDER_VERSION;
struct sbus_connection *conn;
@@ -2039,11 +2002,9 @@ static int client_registration(struct sbus_request *dbus_req)
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) {
DEBUG(SSSDBG_FATAL_FAILURE, "Connection holds no valid init data\n");
@@ -2230,6 +2191,7 @@ static void init_timeout(struct tevent_context *ev,
static int be_client_init(struct sbus_connection *conn, void *data)
{
+ struct sbus_interface *intf;
struct be_ctx *bectx;
struct be_client *becli;
struct timeval tv;
@@ -2264,9 +2226,12 @@ static int be_client_init(struct sbus_connection *conn, void *data)
/* Attach the client context to the connection context, so that it is
* always available when we need to manage the connection. */
- sbus_conn_set_private_data(conn, becli);
+ intf = sbus_new_interface(conn, DP_PATH, &be_methods.vtable, becli);
+ if (!intf) {
+ return ENOMEM;
+ }
- return EOK;
+ return sbus_conn_add_interface(conn, intf);
}
/* be_srv_init
@@ -2284,8 +2249,7 @@ static int be_srv_init(struct be_ctx *ctx)
}
ret = sbus_new_server(ctx, ctx->ev, sbus_address,
- &be_interface, true, &ctx->sbus_srv,
- be_client_init, ctx);
+ true, &ctx->sbus_srv, be_client_init, ctx);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, "Could not set up sbus server.\n");
return ret;
@@ -2599,7 +2563,7 @@ int be_process_init(TALLOC_CTX *mem_ctx,
goto fail;
}
- ret = sss_monitor_init(ctx, ctx->ev, &monitor_be_interface,
+ ret = sss_monitor_init(ctx, ctx->ev, &monitor_be_methods,
ctx->identity, DATA_PROVIDER_VERSION,
ctx, &ctx->mon_conn);
if (ret != EOK) {
@@ -2879,38 +2843,37 @@ int main(int argc, const char *argv[])
}
#endif
-static int data_provider_res_init(struct sbus_request *dbus_req)
+static int data_provider_res_init(struct sbus_request *dbus_req, void *data)
{
struct be_ctx *be_ctx;
- be_ctx = talloc_get_type(sbus_conn_get_private_data(dbus_req->conn), struct be_ctx);
+ be_ctx = talloc_get_type(data, struct be_ctx);
resolv_reread_configuration(be_ctx->be_res->resolv);
check_if_online(be_ctx);
- return monitor_common_res_init(dbus_req);
+ return monitor_common_res_init(dbus_req, data);
}
-static int data_provider_go_offline(struct sbus_request *dbus_req)
+static int data_provider_go_offline(struct sbus_request *dbus_req, void *data)
{
struct be_ctx *be_ctx;
- be_ctx = talloc_get_type(sbus_conn_get_private_data(dbus_req->conn), struct be_ctx);
+ be_ctx = talloc_get_type(data, struct be_ctx);
be_mark_offline(be_ctx);
return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
}
-static int data_provider_reset_offline(struct sbus_request *dbus_req)
+static int data_provider_reset_offline(struct sbus_request *dbus_req, void *data)
{
struct be_ctx *be_ctx;
- be_ctx = talloc_get_type(sbus_conn_get_private_data(dbus_req->conn), struct be_ctx);
+ be_ctx = talloc_get_type(data, struct be_ctx);
check_if_online(be_ctx);
return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
}
-static int data_provider_logrotate(struct sbus_request *dbus_req)
+static int data_provider_logrotate(struct sbus_request *dbus_req, void *data)
{
errno_t ret;
- struct be_ctx *be_ctx = talloc_get_type(sbus_conn_get_private_data(dbus_req->conn),
- struct be_ctx);
+ struct be_ctx *be_ctx = talloc_get_type(data, struct be_ctx);
ret = monitor_common_rotate_logs(be_ctx->cdb, be_ctx->conf_path);
if (ret != EOK) return ret;
diff --git a/src/providers/proxy/proxy_child.c b/src/providers/proxy/proxy_child.c
index 44d4fd662..8889be3b4 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(struct sbus_request *dbus_req);
+static int pc_pam_handler(struct sbus_request *dbus_req, void *user_data);
struct data_provider_iface pc_methods = {
{ &data_provider_iface_meta, 0 },
@@ -60,12 +60,6 @@ struct data_provider_iface pc_methods = {
.getAccountInfo = NULL,
};
-struct sbus_interface pc_interface = {
- DP_PATH,
- &pc_methods.vtable,
- NULL
-};
-
struct pc_ctx {
struct tevent_context *ev;
struct confdb_ctx *cdb;
@@ -310,20 +304,14 @@ fail:
return ret;
}
-static int pc_pam_handler(struct sbus_request *dbus_req)
+static int pc_pam_handler(struct sbus_request *dbus_req, void *user_data)
{
DBusError dbus_error;
DBusMessage *reply;
struct pc_ctx *pc_ctx;
errno_t ret;
- void *user_data;
struct pam_data *pd = NULL;
- user_data = sbus_conn_get_private_data(dbus_req->conn);
- if (!user_data) {
- ret = EINVAL;
- goto done;
- }
pc_ctx = talloc_get_type(user_data, struct pc_ctx);
if (!pc_ctx) {
ret = EINVAL;
@@ -393,6 +381,7 @@ int proxy_child_send_id(struct sbus_connection *conn,
uint32_t id);
static int proxy_cli_init(struct pc_ctx *ctx)
{
+ struct sbus_interface *intf;
char *sbus_address;
int ret;
@@ -404,14 +393,23 @@ static int proxy_cli_init(struct pc_ctx *ctx)
return ENOMEM;
}
- ret = sbus_client_init(ctx, ctx->ev, sbus_address,
- &pc_interface, &ctx->conn,
- NULL, ctx);
+ ret = sbus_client_init(ctx, ctx->ev, sbus_address, &ctx->conn);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, "sbus_client_init failed.\n");
return ret;
}
+ intf = sbus_new_interface(ctx, DP_PATH, &pc_methods.vtable, ctx);
+ if (!intf) {
+ ret = ENOMEM;
+ } else {
+ ret = sbus_conn_add_interface(ctx->conn, intf);
+ }
+ if (ret != EOK) {
+ DEBUG(SSSDBG_FATAL_FAILURE, "Failed to export proxy.\n");
+ return ret;
+ }
+
ret = proxy_child_send_id(ctx->conn, DATA_PROVIDER_VERSION, ctx->id);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, "dp_common_send_id failed.\n");
diff --git a/src/providers/proxy/proxy_init.c b/src/providers/proxy/proxy_init.c
index 70fe337cd..0206ec15b 100644
--- a/src/providers/proxy/proxy_init.c
+++ b/src/providers/proxy/proxy_init.c
@@ -27,7 +27,7 @@
#include "util/sss_format.h"
#include "providers/proxy/proxy.h"
-static int client_registration(struct sbus_request *dbus_req);
+static int client_registration(struct sbus_request *dbus_req, void *data);
static struct data_provider_iface proxy_methods = {
{ &data_provider_iface_meta, 0 },
@@ -40,12 +40,6 @@ static struct data_provider_iface proxy_methods = {
.getAccountInfo = NULL,
};
-struct sbus_interface proxy_interface = {
- DP_PATH,
- &proxy_methods.vtable,
- NULL
-};
-
static void proxy_shutdown(struct be_req *req)
{
/* TODO: Clean up any internal data */
@@ -337,6 +331,7 @@ static int proxy_client_init(struct sbus_connection *conn, void *data)
{
struct proxy_auth_ctx *proxy_auth_ctx;
struct proxy_client *proxy_cli;
+ struct sbus_interface *intf;
struct timeval tv;
proxy_auth_ctx = talloc_get_type(data, struct proxy_auth_ctx);
@@ -369,9 +364,12 @@ static int proxy_client_init(struct sbus_connection *conn, void *data)
/* Attach the client context to the connection context, so that it is
* always available when we need to manage the connection. */
- sbus_conn_set_private_data(conn, proxy_cli);
+ intf = sbus_new_interface(conn, DP_PATH, &proxy_methods.vtable, proxy_cli);
+ if (!intf) {
+ return ENOMEM;
+ }
- return EOK;
+ return sbus_conn_add_interface(conn, intf);
}
static void init_timeout(struct tevent_context *ev,
@@ -394,7 +392,7 @@ static void init_timeout(struct tevent_context *ev,
*/
}
-static int client_registration(struct sbus_request *dbus_req)
+static int client_registration(struct sbus_request *dbus_req, void *data)
{
dbus_uint16_t version = DATA_PROVIDER_VERSION;
struct sbus_connection *conn;
@@ -403,7 +401,6 @@ static int client_registration(struct sbus_request *dbus_req)
dbus_uint16_t cli_ver;
uint32_t cli_id;
dbus_bool_t dbret;
- void *data;
int hret;
hash_key_t key;
hash_value_t value;
@@ -413,7 +410,6 @@ static int client_registration(struct sbus_request *dbus_req)
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) {
DEBUG(SSSDBG_FATAL_FAILURE, "Connection holds no valid init data\n");
@@ -535,7 +531,7 @@ int sssm_proxy_auth_init(struct be_ctx *bectx,
goto done;
}
- ret = sbus_new_server(ctx, bectx->ev, sbus_address, &proxy_interface,
+ ret = sbus_new_server(ctx, bectx->ev, sbus_address,
false, &ctx->sbus_srv, proxy_client_init, ctx);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, "Could not set up sbus server.\n");