diff options
author | Stephen Gallagher <sgallagh@redhat.com> | 2010-10-29 10:11:05 -0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2010-11-15 09:52:35 -0500 |
commit | aef2ac961abfe73c799354f5cfa0331ab44ac765 (patch) | |
tree | d04a1d371fb10d511a4743743a5f009184ca064a | |
parent | ca92350db6ad6ac344181f7b8ec695eda29da675 (diff) | |
download | sssd-aef2ac961abfe73c799354f5cfa0331ab44ac765.tar.gz sssd-aef2ac961abfe73c799354f5cfa0331ab44ac765.tar.bz2 sssd-aef2ac961abfe73c799354f5cfa0331ab44ac765.zip |
Add sysdb utility function for sanitizing DN
-rw-r--r-- | src/db/sysdb.c | 24 | ||||
-rw-r--r-- | src/db/sysdb.h | 3 |
2 files changed, 27 insertions, 0 deletions
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 <time.h> +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__ */ |