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 ++++++++++++++++++++++++ src/db/sysdb.h | 3 +++ 2 files changed, 27 insertions(+) (limited to 'src') diff --git a/src/db/sysdb.c b/src/db/sysdb.c index bc6f8fc9..b2691526 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, diff --git a/src/db/sysdb.h b/src/db/sysdb.h index 0d8b29c9..fde27b93 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -697,4 +697,7 @@ errno_t sysdb_netgr_to_entries(TALLOC_CTX *mem_ctx, struct ldb_result *res, struct sysdb_netgroup_ctx ***entries); +errno_t sysdb_dn_sanitize(void *mem_ctx, const char *input, + char **sanitized); + #endif /* __SYS_DB_H__ */ -- cgit