Skip to content

Commit

Permalink
sbus: centralize communication to a single dbus server
Browse files Browse the repository at this point in the history
Now there is only one dbus server in the monitor process instead of
having a server in each running process. This will simplify the
communication and allow us to use signals effectively.
  • Loading branch information
lamabro23 authored and pbrezina committed Oct 4, 2023
1 parent 6c74c5e commit 005f2b1
Show file tree
Hide file tree
Showing 29 changed files with 184 additions and 376 deletions.
2 changes: 1 addition & 1 deletion src/monitor/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,7 @@ static int monitor_process_init(struct mt_ctx *ctx,
talloc_zfree(tmp_ctx);

req = sbus_server_create_and_connect_send(ctx, ctx->ev, SSS_BUS_MONITOR,
NULL, SSS_MONITOR_ADDRESS,
NULL, SSS_BUS_ADDRESS,
false, 100, ctx->uid, ctx->gid,
NULL, NULL);
if (req == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/providers/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct be_ctx {
/* Periodically check if we can go online. */
struct be_ptask *check_if_online_ptask;

struct sbus_connection *mon_conn;
struct sbus_connection *sbus_conn;

struct be_refresh_ctx *refresh_ctx;

Expand Down
29 changes: 13 additions & 16 deletions src/providers/data_provider/dp.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "providers/data_provider/dp.h"
#include "providers/data_provider/dp_private.h"
#include "providers/data_provider/dp_iface.h"
#include "sbus/sbus.h"
#include "sss_iface/sss_iface_async.h"
#include "providers/backend.h"
#include "util/util.h"
Expand Down Expand Up @@ -149,7 +150,6 @@ dp_init_send(TALLOC_CTX *mem_ctx,
struct dp_init_state *state;
struct tevent_req *subreq;
struct tevent_req *req;
char *sbus_address;
errno_t ret;

req = tevent_req_create(mem_ctx, &state, struct dp_init_state);
Expand All @@ -158,13 +158,6 @@ dp_init_send(TALLOC_CTX *mem_ctx,
return NULL;
}

sbus_address = sss_iface_domain_address(state, be_ctx->domain);
if (sbus_address == NULL) {
DEBUG(SSSDBG_FATAL_FAILURE, "Could not get sbus backend address.\n");
ret = ENOMEM;
goto done;
}

state->provider = talloc_zero(be_ctx, struct data_provider);
if (state->provider == NULL) {
ret = ENOMEM;
Expand All @@ -184,10 +177,9 @@ dp_init_send(TALLOC_CTX *mem_ctx,
*/
talloc_set_destructor(state->provider, dp_destructor);

subreq = sbus_server_create_and_connect_send(state->provider, ev,
sbus_name, NULL, sbus_address, true, 1000, uid, gid,
(sbus_server_on_connection_cb)dp_client_init,
(sbus_server_on_connection_data)state->provider);
subreq = sbus_connect_private_send(state->provider, ev,
SSS_BUS_ADDRESS,
sbus_name, NULL);
if (subreq == NULL) {
DEBUG(SSSDBG_FATAL_FAILURE, "Unable to create subrequest!\n");
ret = ENOMEM;
Expand Down Expand Up @@ -216,9 +208,8 @@ static void dp_init_done(struct tevent_req *subreq)
req = tevent_req_callback_data(subreq, struct tevent_req);
state = tevent_req_data(req, struct dp_init_state);

ret = sbus_server_create_and_connect_recv(state->provider, subreq,
&state->provider->sbus_server,
&state->provider->sbus_conn);
ret = sbus_connect_private_recv(state->provider, subreq,
&state->provider->sbus_conn);
talloc_zfree(subreq);
if (ret != EOK) {
tevent_req_error(req, ret);
Expand Down Expand Up @@ -260,10 +251,16 @@ static void dp_init_done(struct tevent_req *subreq)
}

errno_t dp_init_recv(TALLOC_CTX *mem_ctx,
struct tevent_req *req)
struct tevent_req *req,
struct sbus_connection **_conn)
{
struct dp_init_state *state;
state = tevent_req_data(req, struct dp_init_state);

TEVENT_REQ_RETURN_ON_ERROR(req);

*_conn = talloc_steal(mem_ctx, state->provider->sbus_conn);

return EOK;
}

Expand Down
3 changes: 2 additions & 1 deletion src/providers/data_provider/dp.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ dp_init_send(TALLOC_CTX *mem_ctx,
const char *sbus_name);

errno_t dp_init_recv(TALLOC_CTX *mem_ctx,
struct tevent_req *req);
struct tevent_req *req,
struct sbus_connection **_conn);

void dp_client_cancel_timeout(struct sbus_connection *conn);

Expand Down
11 changes: 5 additions & 6 deletions src/providers/data_provider_be.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ be_register_monitor_iface(struct sbus_connection *conn, struct be_ctx *be_ctx)
{NULL, NULL}
};

return sbus_connection_add_path_map(be_ctx->mon_conn, paths);
return sbus_connection_add_path_map(be_ctx->sbus_conn, paths);
}

static void dp_initialized(struct tevent_req *req);
Expand Down Expand Up @@ -695,21 +695,20 @@ static void dp_initialized(struct tevent_req *req)

be_ctx = tevent_req_callback_data(req, struct be_ctx);

ret = dp_init_recv(be_ctx, req);
ret = dp_init_recv(be_ctx, req, &be_ctx->sbus_conn);
talloc_zfree(req);
if (ret != EOK) {
goto done;
}

ret = sss_monitor_service_init(be_ctx, be_ctx->ev, be_ctx->sbus_name,
be_ctx->identity, DATA_PROVIDER_VERSION,
MT_SVC_PROVIDER, NULL, &be_ctx->mon_conn);
ret = sss_monitor_provider_init(be_ctx->sbus_conn, be_ctx->identity,
DATA_PROVIDER_VERSION, MT_SVC_PROVIDER);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, "Unable to initialize monitor connection\n");
goto done;
}

ret = be_register_monitor_iface(be_ctx->mon_conn, be_ctx);
ret = be_register_monitor_iface(be_ctx->sbus_conn, be_ctx);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, "Unable to register monitor interface "
"[%d]: %s\n", ret, sss_strerror(ret));
Expand Down
21 changes: 7 additions & 14 deletions src/providers/proxy/proxy_child.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

#include <stdio.h>
#include <talloc.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
Expand Down Expand Up @@ -53,8 +54,7 @@ struct pc_ctx {
struct sss_domain_info *domain;
const char *identity;
const char *conf_path;
struct sbus_connection *mon_conn;
struct sbus_connection *conn;
struct sbus_connection *sbus_conn;
const char *pam_target;
uint32_t id;
};
Expand Down Expand Up @@ -338,7 +338,6 @@ proxy_cli_init(struct pc_ctx *ctx)
{
TALLOC_CTX *tmp_ctx;
struct tevent_req *subreq;
char *sbus_address;
char *sbus_busname;
char *sbus_cliname;
errno_t ret;
Expand All @@ -363,12 +362,6 @@ proxy_cli_init(struct pc_ctx *ctx)
{NULL, NULL}
};

sbus_address = sss_iface_domain_address(tmp_ctx, ctx->domain);
if (sbus_address == NULL) {
ret = ENOMEM;
goto done;
}

sbus_busname = confdb_get_domain_bus(tmp_ctx, ctx->domain);
if (sbus_busname == NULL) {
ret = ENOMEM;
Expand All @@ -381,14 +374,14 @@ proxy_cli_init(struct pc_ctx *ctx)
goto done;
}

ret = sss_iface_connect_address(ctx, ctx->ev, sbus_cliname, sbus_address,
NULL, &ctx->conn);
ret = sss_iface_connect_address(ctx, ctx->ev, sbus_cliname, SSS_BUS_ADDRESS,
NULL, &ctx->sbus_conn);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, "Unable to connect to %s\n", sbus_address);
DEBUG(SSSDBG_FATAL_FAILURE, "Unable to connect to %s\n", SSS_BUS_ADDRESS);
goto done;
}

ret = sbus_connection_add_path_map(ctx->conn, paths);
ret = sbus_connection_add_path_map(ctx->sbus_conn, paths);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, "Unable to add paths [%d]: %s\n",
ret, sss_strerror(ret));
Expand All @@ -398,7 +391,7 @@ proxy_cli_init(struct pc_ctx *ctx)
DEBUG(SSSDBG_TRACE_FUNC, "Sending ID to Proxy Backend: (%"PRIu32")\n",
ctx->id);

subreq = sbus_call_proxy_client_Register_send(ctx, ctx->conn, sbus_busname,
subreq = sbus_call_proxy_client_Register_send(ctx, ctx->sbus_conn, sbus_busname,
SSS_BUS_PATH, ctx->id);
if (subreq == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create subrequest!\n");
Expand Down
4 changes: 2 additions & 2 deletions src/responder/autofs/autofssrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ autofs_register_service_iface(struct autofs_ctx *autofs_ctx,
)
);

ret = sbus_connection_add_path(rctx->mon_conn, SSS_BUS_PATH, &iface_svc);
ret = sbus_connection_add_path(rctx->sbus_conn, SSS_BUS_PATH, &iface_svc);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, "Unable to register service interface"
"[%d]: %s\n", ret, sss_strerror(ret));
Expand Down Expand Up @@ -155,7 +155,7 @@ autofs_process_init(TALLOC_CTX *mem_ctx,
SSS_AUTOFS_SBUS_SERVICE_NAME,
SSS_AUTOFS_SBUS_SERVICE_VERSION,
MT_SVC_SERVICE,
&rctx->last_request_time, &rctx->mon_conn);
&rctx->last_request_time, &rctx->sbus_conn);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, "fatal error setting up message bus\n");
goto fail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,14 @@ cache_req_autofs_entry_by_name_dp_send(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
struct ldb_result *result)
{
struct be_conn *be_conn;
errno_t ret;

ret = sss_dp_get_domain_conn(cr->rctx, domain->conn_name, &be_conn);
if (ret != EOK) {
if (cr->rctx->sbus_conn == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE,
"BUG: The Data Provider connection for %s is not available!\n",
domain->name);
"BUG: The D-Bus connection is not available!\n");
return NULL;
}

return sbus_call_dp_autofs_GetEntry_send(mem_ctx, be_conn->conn,
be_conn->bus_name, SSS_BUS_PATH,
return sbus_call_dp_autofs_GetEntry_send(mem_ctx, cr->rctx->sbus_conn,
domain->conn_name, SSS_BUS_PATH,
0, data->name.name,
data->autofs_entry_name,
sss_chain_id_get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,14 @@ cache_req_autofs_map_by_name_dp_send(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
struct ldb_result *result)
{
struct be_conn *be_conn;
errno_t ret;

ret = sss_dp_get_domain_conn(cr->rctx, domain->conn_name, &be_conn);
if (ret != EOK) {
if (cr->rctx->sbus_conn == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE,
"BUG: The Data Provider connection for %s is not available!\n",
domain->name);
"BUG: The D-Bus connection is not available!\n");
return NULL;
}

return sbus_call_dp_autofs_GetMap_send(mem_ctx, be_conn->conn,
be_conn->bus_name, SSS_BUS_PATH,
return sbus_call_dp_autofs_GetMap_send(mem_ctx, cr->rctx->sbus_conn,
domain->conn_name, SSS_BUS_PATH,
0, data->name.name,
sss_chain_id_get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,14 @@ cache_req_autofs_map_entries_dp_send(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
struct ldb_result *result)
{
struct be_conn *be_conn;
errno_t ret;

ret = sss_dp_get_domain_conn(cr->rctx, domain->conn_name, &be_conn);
if (ret != EOK) {
if (cr->rctx->sbus_conn == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE,
"BUG: The Data Provider connection for %s is not available!\n",
domain->name);
"BUG: The D-Bus connection is not available!\n");
return NULL;
}

return sbus_call_dp_autofs_Enumerate_send(mem_ctx, be_conn->conn,
be_conn->bus_name, SSS_BUS_PATH,
return sbus_call_dp_autofs_Enumerate_send(mem_ctx, cr->rctx->sbus_conn,
domain->conn_name, SSS_BUS_PATH,
0, data->name.name,
sss_chain_id_get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,14 @@ cache_req_host_by_name_dp_send(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
struct ldb_result *result)
{
struct be_conn *be_conn;
errno_t ret;

ret = sss_dp_get_domain_conn(cr->rctx, domain->conn_name, &be_conn);
if (ret != EOK) {
if (cr->rctx->sbus_conn == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE,
"BUG: The Data Provider connection for %s is not available!\n",
domain->name);
"BUG: The D-Bus connection is not available!\n");
return NULL;
}

return sbus_call_dp_dp_hostHandler_send(mem_ctx, be_conn->conn,
be_conn->bus_name, SSS_BUS_PATH,
return sbus_call_dp_dp_hostHandler_send(mem_ctx, cr->rctx->sbus_conn,
domain->conn_name, SSS_BUS_PATH,
0, data->name.name, data->alias,
sss_chain_id_get());
}
Expand Down
21 changes: 1 addition & 20 deletions src/responder/common/responder.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,6 @@ struct cli_protocol {
struct cli_protocol_version *cli_protocol_version;
};

struct resp_ctx;

struct be_conn {
struct be_conn *next;
struct be_conn *prev;

struct resp_ctx *rctx;

const char *cli_name;
struct sss_domain_info *domain;

char *bus_name;
char *sbus_address;
struct sbus_connection *conn;
};

struct resp_ctx {
struct tevent_context *ev;
struct tevent_fd *lfde;
Expand All @@ -99,8 +83,7 @@ struct resp_ctx {
struct sss_nc_ctx *ncache;
struct sss_names_ctx *global_names;

struct sbus_connection *mon_conn;
struct be_conn *be_conns;
struct sbus_connection *sbus_conn;

struct sss_domain_info *domains;
int domains_timeout;
Expand Down Expand Up @@ -203,8 +186,6 @@ int sss_process_init(TALLOC_CTX *mem_ctx,
connection_setup_t conn_setup,
struct resp_ctx **responder_ctx);

int sss_dp_get_domain_conn(struct resp_ctx *rctx, const char *domain,
struct be_conn **_conn);
struct sss_domain_info *
responder_get_domain(struct resp_ctx *rctx, const char *domain);

Expand Down
Loading

0 comments on commit 005f2b1

Please sign in to comment.