Skip to content

Commit

Permalink
sbus: convert calls in dp_resp_client.c into signals
Browse files Browse the repository at this point in the history
We do not require any reply from the destination so signals are
much better format for these calls.

Resolves: #6286
  • Loading branch information
pbrezina committed Oct 4, 2023
1 parent 005f2b1 commit 1fcc2cc
Show file tree
Hide file tree
Showing 10 changed files with 416 additions and 611 deletions.
35 changes: 35 additions & 0 deletions src/providers/data_provider/dp.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,48 @@ dp_init_interface(struct data_provider *provider)
SBUS_PROPERTIES(SBUS_NO_PROPERTIES)
);

SBUS_INTERFACE(iface_responder_domain,
sssd_Responder_Domain,
SBUS_METHODS(SBUS_NO_METHODS),
SBUS_SIGNALS(
SBUS_EMITS(sssd_Responder_Domain, SetActive),
SBUS_EMITS(sssd_Responder_Domain, SetInconsistent)
),
SBUS_PROPERTIES(SBUS_NO_PROPERTIES)
);

SBUS_INTERFACE(iface_responder_negativecache,
sssd_Responder_NegativeCache,
SBUS_METHODS(SBUS_NO_METHODS),
SBUS_SIGNALS(
SBUS_EMITS(sssd_Responder_NegativeCache, ResetUsers),
SBUS_EMITS(sssd_Responder_NegativeCache, ResetGroups)
),
SBUS_PROPERTIES(SBUS_NO_PROPERTIES)
);

SBUS_INTERFACE(iface_nss_memorycache,
sssd_nss_MemoryCache,
SBUS_METHODS(SBUS_NO_METHODS),
SBUS_SIGNALS(
SBUS_EMITS(sssd_nss_MemoryCache, InvalidateAllUsers),
SBUS_EMITS(sssd_nss_MemoryCache, InvalidateAllGroups),
SBUS_EMITS(sssd_nss_MemoryCache, InvalidateAllInitgroups),
SBUS_EMITS(sssd_nss_MemoryCache, InvalidateGroupById)
),
SBUS_PROPERTIES(SBUS_NO_PROPERTIES)
);

struct sbus_path paths[] = {
{SSS_BUS_PATH, &iface_dp_client},
{SSS_BUS_PATH, &iface_dp_backend},
{SSS_BUS_PATH, &iface_dp_failover},
{SSS_BUS_PATH, &iface_dp_access},
{SSS_BUS_PATH, &iface_dp},
{SSS_BUS_PATH, &iface_autofs},
{SSS_BUS_PATH, &iface_responder_domain},
{SSS_BUS_PATH, &iface_responder_negativecache},
{SSS_BUS_PATH, &iface_nss_memorycache},
{NULL, NULL}
};

Expand Down
152 changes: 10 additions & 142 deletions src/providers/data_provider/dp_resp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,9 @@
#include "providers/data_provider/dp_private.h"
#include "sss_iface/sss_iface_async.h"


/* List of DP clients that deal with users or groups */
/* FIXME - it would be much cleaner to implement sbus signals
* and let the responder subscribe to these messages rather than
* keep a list here..
* https://fedorahosted.org/sssd/ticket/2233
*/
static const char *user_clients[] = {
SSS_BUS_NSS,
SSS_BUS_PAM,
SSS_BUS_IFP,
SSS_BUS_PAC,
SSS_BUS_SUDO,
NULL
};

static const char *all_clients[] = {
SSS_BUS_NSS,
SSS_BUS_PAM,
SSS_BUS_IFP,
SSS_BUS_PAC,
SSS_BUS_SUDO,
SSS_BUS_SSH,
SSS_BUS_AUTOFS,
NULL
};

void dp_sbus_domain_active(struct data_provider *provider,
struct sss_domain_info *dom)
{
const char *bus;
struct tevent_req *subreq;
struct sbus_connection *conn;
int i;

if (provider == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "No provider pointer\n");
return;
Expand All @@ -69,29 +37,13 @@ void dp_sbus_domain_active(struct data_provider *provider,
DEBUG(SSSDBG_TRACE_FUNC, "Ordering responders to enable domain %s\n",
dom->name);

conn = provider->sbus_conn;
for (i = 0; all_clients[i] != NULL; i++) {
bus = all_clients[i];

subreq = sbus_call_resp_domain_SetActive_send(provider, conn,
bus, SSS_BUS_PATH, dom->name);
if (subreq == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create subrequest!\n");
return;
}

tevent_req_set_callback(subreq, sbus_unwanted_reply, NULL);
}
sbus_emit_resp_domain_SetActive(provider->sbus_conn, SSS_BUS_PATH,
dom->name);
}

void dp_sbus_domain_inconsistent(struct data_provider *provider,
struct sss_domain_info *dom)
{
const char *bus;
struct tevent_req *subreq;
struct sbus_connection *conn;
int i;

if (provider == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "No provider pointer\n");
return;
Expand All @@ -100,28 +52,13 @@ void dp_sbus_domain_inconsistent(struct data_provider *provider,
DEBUG(SSSDBG_TRACE_FUNC, "Ordering responders to disable domain %s\n",
dom->name);

conn = provider->sbus_conn;
for (i = 0; all_clients[i] != NULL; i++) {
bus = all_clients[i];
subreq = sbus_call_resp_domain_SetInconsistent_send(provider, conn,
bus, SSS_BUS_PATH, dom->name);
if (subreq == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create subrequest!\n");
return;
}

tevent_req_set_callback(subreq, sbus_unwanted_reply, NULL);
}
sbus_emit_resp_domain_SetInconsistent(provider->sbus_conn, SSS_BUS_PATH,
dom->name);
}

void dp_sbus_reset_users_ncache(struct data_provider *provider,
struct sss_domain_info *dom)
{
const char *bus;
struct tevent_req *subreq;
struct sbus_connection *conn;
int i;

if (provider == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "No provider pointer\n");
return;
Expand All @@ -130,28 +67,12 @@ void dp_sbus_reset_users_ncache(struct data_provider *provider,
DEBUG(SSSDBG_TRACE_FUNC,
"Ordering responders to reset user negative cache\n");

conn = provider->sbus_conn;
for (i = 0; user_clients[i] != NULL; i++) {
bus = user_clients[i];
subreq = sbus_call_resp_negcache_ResetUsers_send(provider, conn, bus,
SSS_BUS_PATH);
if (subreq == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create subrequest!\n");
return;
}

tevent_req_set_callback(subreq, sbus_unwanted_reply, NULL);
}
sbus_emit_resp_negcache_ResetUsers(provider->sbus_conn, SSS_BUS_PATH);
}

void dp_sbus_reset_groups_ncache(struct data_provider *provider,
struct sss_domain_info *dom)
{
const char *bus;
struct tevent_req *subreq;
struct sbus_connection *conn;
int i;

if (provider == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "No provider pointer\n");
return;
Expand All @@ -160,25 +81,11 @@ void dp_sbus_reset_groups_ncache(struct data_provider *provider,
DEBUG(SSSDBG_TRACE_FUNC,
"Ordering responders to reset group negative cache\n");

conn = provider->sbus_conn;
for (i = 0; user_clients[i] != NULL; i++) {
bus = user_clients[i];

subreq = sbus_call_resp_negcache_ResetGroups_send(provider, conn, bus,
SSS_BUS_PATH);
if (subreq == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create subrequest!\n");
return;
}

tevent_req_set_callback(subreq, sbus_unwanted_reply, NULL);
}
sbus_emit_resp_negcache_ResetGroups(provider->sbus_conn, SSS_BUS_PATH);
}

void dp_sbus_reset_users_memcache(struct data_provider *provider)
{
struct tevent_req *subreq;

if (provider == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "No provider pointer\n");
return;
Expand All @@ -187,22 +94,12 @@ void dp_sbus_reset_users_memcache(struct data_provider *provider)
DEBUG(SSSDBG_TRACE_FUNC,
"Ordering NSS responder to invalidate the users\n");

subreq = sbus_call_nss_memcache_InvalidateAllUsers_send(provider,
provider->sbus_conn, SSS_BUS_NSS, SSS_BUS_PATH);
if (subreq == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create subrequest!\n");
return;
}

tevent_req_set_callback(subreq, sbus_unwanted_reply, NULL);

sbus_emit_nss_memcache_InvalidateAllUsers(provider->sbus_conn, SSS_BUS_PATH);
return;
}

void dp_sbus_reset_groups_memcache(struct data_provider *provider)
{
struct tevent_req *subreq;

if (provider == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "No provider pointer\n");
return;
Expand All @@ -211,22 +108,12 @@ void dp_sbus_reset_groups_memcache(struct data_provider *provider)
DEBUG(SSSDBG_TRACE_FUNC,
"Ordering NSS responder to invalidate the groups\n");

subreq = sbus_call_nss_memcache_InvalidateAllGroups_send(provider,
provider->sbus_conn, SSS_BUS_NSS, SSS_BUS_PATH);
if (subreq == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create subrequest!\n");
return;
}

tevent_req_set_callback(subreq, sbus_unwanted_reply, NULL);

sbus_emit_nss_memcache_InvalidateAllGroups(provider->sbus_conn, SSS_BUS_PATH);
return;
}

void dp_sbus_reset_initgr_memcache(struct data_provider *provider)
{
struct tevent_req *subreq;

if (provider == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "No provider pointer\n");
return;
Expand All @@ -235,23 +122,13 @@ void dp_sbus_reset_initgr_memcache(struct data_provider *provider)
DEBUG(SSSDBG_TRACE_FUNC,
"Ordering NSS responder to invalidate the initgroups\n");

subreq = sbus_call_nss_memcache_InvalidateAllInitgroups_send(provider,
provider->sbus_conn, SSS_BUS_NSS, SSS_BUS_PATH);
if (subreq == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create subrequest!\n");
return;
}

tevent_req_set_callback(subreq, sbus_unwanted_reply, NULL);

sbus_emit_nss_memcache_InvalidateAllInitgroups(provider->sbus_conn, SSS_BUS_PATH);
return;
}

void dp_sbus_invalidate_group_memcache(struct data_provider *provider,
gid_t gid)
{
struct tevent_req *subreq;

if (provider == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "No provider pointer\n");
return;
Expand All @@ -261,15 +138,6 @@ void dp_sbus_invalidate_group_memcache(struct data_provider *provider,
"Ordering NSS responder to invalidate the group %"PRIu32" \n",
gid);

subreq = sbus_call_nss_memcache_InvalidateGroupById_send(provider,
provider->sbus_conn, SSS_BUS_NSS, SSS_BUS_PATH,
(uint32_t)gid);
if (subreq == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create subrequest!\n");
return;
}

tevent_req_set_callback(subreq, sbus_unwanted_reply, NULL);

sbus_emit_nss_memcache_InvalidateGroupById(provider->sbus_conn, SSS_BUS_PATH, (uint32_t)gid);
return;
}
37 changes: 11 additions & 26 deletions src/responder/common/responder_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,35 +99,20 @@ sss_resp_register_sbus_iface(struct sbus_connection *conn,
{
errno_t ret;

SBUS_INTERFACE(iface_resp_domain,
sssd_Responder_Domain,
SBUS_METHODS(
SBUS_SYNC(METHOD, sssd_Responder_Domain, SetActive, sss_resp_domain_active, rctx),
SBUS_SYNC(METHOD, sssd_Responder_Domain, SetInconsistent, sss_resp_domain_inconsistent, rctx)
),
SBUS_SIGNALS(SBUS_NO_SIGNALS),
SBUS_PROPERTIES(SBUS_NO_PROPERTIES)
struct sbus_listener listeners[] = SBUS_LISTENERS(
SBUS_LISTEN_SYNC(sssd_Responder_Domain, SetActive,
SSS_BUS_PATH, sss_resp_domain_active, rctx),
SBUS_LISTEN_SYNC(sssd_Responder_Domain, SetInconsistent,
SSS_BUS_PATH, sss_resp_domain_inconsistent, rctx),
SBUS_LISTEN_SYNC(sssd_Responder_NegativeCache, ResetUsers,
SSS_BUS_PATH, sss_resp_reset_ncache_users, rctx),
SBUS_LISTEN_SYNC(sssd_Responder_NegativeCache, ResetGroups,
SSS_BUS_PATH, sss_resp_reset_ncache_groups, rctx)
);

SBUS_INTERFACE(iface_resp_negcache,
sssd_Responder_NegativeCache,
SBUS_METHODS(
SBUS_SYNC(METHOD, sssd_Responder_NegativeCache, ResetUsers, sss_resp_reset_ncache_users, rctx),
SBUS_SYNC(METHOD, sssd_Responder_NegativeCache, ResetGroups, sss_resp_reset_ncache_groups, rctx)
),
SBUS_SIGNALS(SBUS_NO_SIGNALS),
SBUS_PROPERTIES(SBUS_NO_PROPERTIES)
);

struct sbus_path paths[] = {
{SSS_BUS_PATH, &iface_resp_domain},
{SSS_BUS_PATH, &iface_resp_negcache},
{NULL, NULL}
};

ret = sbus_connection_add_path_map(conn, paths);
ret = sbus_router_listen_map(conn, listeners);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, "Unable to add paths [%d]: %s\n",
DEBUG(SSSDBG_FATAL_FAILURE, "Unable to add listeners [%d]: %s\n",
ret, sss_strerror(ret));
}

Expand Down
31 changes: 25 additions & 6 deletions src/responder/nss/nss_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,15 @@ sss_nss_register_backend_iface(struct sbus_connection *conn,
SBUS_INTERFACE(iface,
sssd_nss_MemoryCache,
SBUS_METHODS(
SBUS_SYNC(METHOD, sssd_nss_MemoryCache, UpdateInitgroups, sss_nss_memorycache_update_initgroups, nss_ctx),
SBUS_SYNC(METHOD, sssd_nss_MemoryCache, InvalidateAllUsers, sss_nss_memorycache_invalidate_users, nss_ctx),
SBUS_SYNC(METHOD, sssd_nss_MemoryCache, InvalidateAllGroups, sss_nss_memorycache_invalidate_groups, nss_ctx),
SBUS_SYNC(METHOD, sssd_nss_MemoryCache, InvalidateAllInitgroups, sss_nss_memorycache_invalidate_initgroups, nss_ctx),
SBUS_SYNC(METHOD, sssd_nss_MemoryCache, InvalidateGroupById, sss_nss_memorycache_invalidate_group_by_id, nss_ctx)
SBUS_SYNC(METHOD, sssd_nss_MemoryCache, UpdateInitgroups,
sss_nss_memorycache_update_initgroups, nss_ctx)
),
SBUS_SIGNALS(
SBUS_EMITS(sssd_nss_MemoryCache, InvalidateAllUsers),
SBUS_EMITS(sssd_nss_MemoryCache, InvalidateAllGroups),
SBUS_EMITS(sssd_nss_MemoryCache, InvalidateAllInitgroups),
SBUS_EMITS(sssd_nss_MemoryCache, InvalidateGroupById)
),
SBUS_SIGNALS(SBUS_NO_SIGNALS),
SBUS_PROPERTIES(SBUS_NO_PROPERTIES)
);

Expand All @@ -238,5 +240,22 @@ sss_nss_register_backend_iface(struct sbus_connection *conn,
"[%d]: %s\n", ret, sss_strerror(ret));
}

struct sbus_listener listeners[] = SBUS_LISTENERS(
SBUS_LISTEN_SYNC(sssd_nss_MemoryCache, InvalidateAllUsers,
SSS_BUS_PATH, sss_nss_memorycache_invalidate_users, nss_ctx),
SBUS_LISTEN_SYNC(sssd_nss_MemoryCache, InvalidateAllGroups,
SSS_BUS_PATH, sss_nss_memorycache_invalidate_groups, nss_ctx),
SBUS_LISTEN_SYNC(sssd_nss_MemoryCache, InvalidateAllInitgroups,
SSS_BUS_PATH, sss_nss_memorycache_invalidate_initgroups, nss_ctx),
SBUS_LISTEN_SYNC(sssd_nss_MemoryCache, InvalidateGroupById,
SSS_BUS_PATH, sss_nss_memorycache_invalidate_group_by_id, nss_ctx)
);

ret = sbus_router_listen_map(conn, listeners);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, "Unable to add listeners [%d]: %s\n",
ret, sss_strerror(ret));
}

return ret;
}
Loading

0 comments on commit 1fcc2cc

Please sign in to comment.