summaryrefslogtreecommitdiffstats
path: root/src/responder/common/responder_cmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/responder/common/responder_cmd.c')
-rw-r--r--src/responder/common/responder_cmd.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/responder/common/responder_cmd.c b/src/responder/common/responder_cmd.c
index bfac8f979..28315e060 100644
--- a/src/responder/common/responder_cmd.c
+++ b/src/responder/common/responder_cmd.c
@@ -155,3 +155,82 @@ int sss_cmd_execute(struct cli_ctx *cctx, struct sss_cmd_table *sss_cmds)
return EINVAL;
}
+
+struct setent_req_list {
+ struct setent_req_list *prev;
+ struct setent_req_list *next;
+ /* Need to point to the head of the list from a talloc destructor */
+ struct setent_req_list *head;
+
+ void *pvt;
+
+ struct tevent_req *req;
+};
+
+struct tevent_req *
+setent_get_req(struct setent_req_list *sl)
+{
+ return sl->req;
+}
+
+int setent_remove_ref(TALLOC_CTX *ctx)
+{
+ struct setent_req_list *entry =
+ talloc_get_type(ctx, struct setent_req_list);
+ DLIST_REMOVE(entry->head, entry);
+ return 0;
+}
+
+errno_t setent_add_ref(TALLOC_CTX *memctx,
+ void *pvt,
+ struct setent_req_list **list,
+ struct tevent_req *req)
+{
+ struct setent_req_list *entry;
+
+ entry = talloc_zero(memctx, struct setent_req_list);
+ if (!entry) {
+ return ENOMEM;
+ }
+
+ entry->req = req;
+ entry->pvt = pvt;
+ DLIST_ADD_END(*list, entry, struct setent_req_list *);
+ entry->head = *list;
+
+ talloc_set_destructor((TALLOC_CTX *)entry, setent_remove_ref);
+ return EOK;
+}
+
+void setent_notify(struct setent_req_list *list, errno_t err)
+{
+ struct setent_req_list *reql;
+
+ /* Notify the waiting clients */
+ while ((reql = list)) {
+ /* Each tevent_req_done() call will free
+ * the request, removing it from the list.
+ */
+ if (err == EOK) {
+ tevent_req_done(reql->req);
+ } else {
+ tevent_req_error(reql->req, err);
+ }
+
+ if (reql == list) {
+ /* The consumer failed to free the
+ * request. Log a bug and continue.
+ */
+ DEBUG(SSSDBG_FATAL_FAILURE,
+ ("BUG: a callback did not free its request. "
+ "May leak memory\n"));
+ /* Skip to the next since a memory leak is non-fatal */
+ list = list->next;
+ }
+ }
+}
+
+void setent_notify_done(struct setent_req_list *list)
+{
+ return setent_notify(list, EOK);
+}