summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/providers/proxy.c11
-rw-r--r--server/util/memory.c51
-rw-r--r--server/util/util.h25
3 files changed, 51 insertions, 36 deletions
diff --git a/server/providers/proxy.c b/server/providers/proxy.c
index 4acec90af..3252a7455 100644
--- a/server/providers/proxy.c
+++ b/server/providers/proxy.c
@@ -318,17 +318,6 @@ static void cache_pw_op(struct sysdb_req *req, void *pvt)
}
}
-static int password_destructor(void *memctx)
-{
- char *password = (char *)memctx;
- int i;
-
- /* zero out password */
- for (i = 0; password[i]; i++) password[i] = '\0';
-
- return 0;
-}
-
static void cache_password(struct be_req *req,
const char *username,
struct authtok_conv *ac)
diff --git a/server/util/memory.c b/server/util/memory.c
index 87fefd2f2..8ffad49aa 100644
--- a/server/util/memory.c
+++ b/server/util/memory.c
@@ -1,30 +1,47 @@
#include "talloc.h"
+#include "util/util.h"
/*
- * sssd_mem_takeover
- * This function will take a non-talloc pointer and add it to a talloc
+ * sssd_mem_attach
+ * This function will take a non-talloc pointer and "attach" it to a talloc
* memory context. It will accept a destructor for the original pointer
* so that when the parent memory context is freed, the non-talloc
* pointer will also be freed properly.
*/
-TALLOC_CTX *sssd_mem_takeover(TALLOC_CTX *mem_ctx,
- void *ptr,
- int (*destructor)(void **))
+
+int password_destructor(void *memctx)
+{
+ char *password = (char *)memctx;
+ int i;
+
+ /* zero out password */
+ for (i = 0; password[i]; i++) password[i] = '\0';
+
+ return 0;
+}
+
+static int mem_holder_destructor(void *ptr)
+{
+ struct mem_holder *h;
+
+ h = talloc_get_type(ptr, struct mem_holder);
+ return h->fn(h->mem);
+}
+
+void *sss_mem_attach(TALLOC_CTX *mem_ctx,
+ void *ptr,
+ void_destructor_fn_t *fn)
{
- TALLOC_CTX **handle;
+ struct mem_holder *h;
- if (ptr == NULL) {
- return NULL;
- }
+ if (!ptr || !fn) return NULL;
- handle = talloc_named_const(mem_ctx, sizeof(void *),
- "sssd_mem_takeover destructor handle");
- if (handle == NULL) {
- return NULL;
- }
+ h = talloc(mem_ctx, struct mem_holder);
+ if (!h) return NULL;
- *handle = ptr;
- talloc_set_destructor(handle, destructor);
+ h->mem = ptr;
+ h->fn = fn;
+ talloc_set_destructor((TALLOC_CTX *)h, mem_holder_destructor);
- return handle;
+ return h;
}
diff --git a/server/util/util.h b/server/util/util.h
index 61f63feff..7acbfe613 100644
--- a/server/util/util.h
+++ b/server/util/util.h
@@ -52,11 +52,6 @@ void debug_fn(const char *format, ...);
#define talloc_zfree(ptr) do { talloc_free(ptr); ptr = NULL; } while(0)
#endif
-struct main_context {
- struct tevent_context *event_ctx;
- struct confdb_ctx *confdb_ctx;
-};
-
#include "util/dlinklist.h"
/* From debug.c */
@@ -64,6 +59,11 @@ void ldb_debug_messages(void *context, enum ldb_debug_level level,
const char *fmt, va_list ap);
/* from server.c */
+struct main_context {
+ struct tevent_context *event_ctx;
+ struct confdb_ctx *confdb_ctx;
+};
+
int server_setup(const char *name, int flags,
const char *conf_entry,
struct main_context **main_ctx);
@@ -77,9 +77,18 @@ void CatchChild(void);
void CatchChildLeaveStatus(void);
/* from memory.c */
-TALLOC_CTX *sssd_mem_takeover(TALLOC_CTX *mem_ctx,
- void *ptr,
- int (*destructor)(void **));
+typedef int (void_destructor_fn_t)(void *);
+
+struct mem_holder {
+ void *mem;
+ void_destructor_fn_t *fn;
+};
+
+void *sss_mem_attach(TALLOC_CTX *mem_ctx,
+ void *ptr,
+ void_destructor_fn_t *fn);
+
+int password_destructor(void *memctx);
/* from usertools.c */
char *get_username_from_uid(TALLOC_CTX *mem_ctx, uid_t uid);