From aef2ac961abfe73c799354f5cfa0331ab44ac765 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Fri, 29 Oct 2010 10:11:05 -0400 Subject: Add sysdb utility function for sanitizing DN --- src/db/sysdb.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/db/sysdb.c') diff --git a/src/db/sysdb.c b/src/db/sysdb.c index bc6f8fc97..b2691526a 100644 --- a/src/db/sysdb.c +++ b/src/db/sysdb.c @@ -25,6 +25,30 @@ #include "confdb/confdb.h" #include +errno_t sysdb_dn_sanitize(void *mem_ctx, const char *input, + char **sanitized) +{ + struct ldb_val val; + errno_t ret = EOK; + + val.data = (uint8_t *)talloc_strdup(mem_ctx, input); + if (!val.data) { + return ENOMEM; + } + + /* We can't include the trailing NULL because it would + * be escaped and result in an unterminated string + */ + val.length = strlen(input); + + *sanitized = ldb_dn_escape_value(mem_ctx, val); + if (!*sanitized) { + ret = ENOMEM; + } + + talloc_free(val.data); + return ret; +} struct ldb_dn *sysdb_custom_subtree_dn(struct sysdb_ctx *ctx, void *memctx, const char *domain, -- cgit