summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/db/sysdb.c48
-rw-r--r--server/db/sysdb.h4
-rw-r--r--server/db/sysdb_ops.c48
3 files changed, 58 insertions, 42 deletions
diff --git a/server/db/sysdb.c b/server/db/sysdb.c
index 5a274fb1..8ff96566 100644
--- a/server/db/sysdb.c
+++ b/server/db/sysdb.c
@@ -254,6 +254,54 @@ int sysdb_attrs_add_time_t(struct sysdb_attrs *attrs,
return ret;
}
+static char *build_dom_dn_str_escape(TALLOC_CTX *memctx, const char *template,
+ const char *domain, const char *name)
+{
+ char *ret;
+ int l;
+
+ l = strcspn(name, ",=\n+<>#;\\\"");
+ if (name[l] != '\0') {
+ struct ldb_val v;
+ char *tmp;
+
+ v.data = discard_const_p(uint8_t, name);
+ v.length = strlen(name);
+
+ tmp = ldb_dn_escape_value(memctx, v);
+ if (!tmp) {
+ return NULL;
+ }
+
+ ret = talloc_asprintf(memctx, template, tmp, domain);
+ talloc_zfree(tmp);
+ if (!ret) {
+ return NULL;
+ }
+
+ return ret;
+ }
+
+ ret = talloc_asprintf(memctx, template, name, domain);
+ if (!ret) {
+ return NULL;
+ }
+
+ return ret;
+}
+
+char *sysdb_user_strdn(TALLOC_CTX *memctx,
+ const char *domain, const char *name)
+{
+ return build_dom_dn_str_escape(memctx, SYSDB_TMPL_USER, domain, name);
+}
+
+char *sysdb_group_strdn(TALLOC_CTX *memctx,
+ const char *domain, const char *name)
+{
+ return build_dom_dn_str_escape(memctx, SYSDB_TMPL_GROUP, domain, name);
+}
+
/* TODO: make a more complete and precise mapping */
int sysdb_error_to_errno(int ldberr)
{
diff --git a/server/db/sysdb.h b/server/db/sysdb.h
index 9348c57f..c345caf8 100644
--- a/server/db/sysdb.h
+++ b/server/db/sysdb.h
@@ -192,6 +192,10 @@ struct ldb_dn *sysdb_custom_subtree_dn(struct sysdb_ctx *ctx, void *memctx,
const char *domain,
const char *subtree_name);
+char *sysdb_user_strdn(TALLOC_CTX *memctx,
+ const char *domain, const char *name);
+char *sysdb_group_strdn(TALLOC_CTX *memctx,
+ const char *domain, const char *name);
struct ldb_context *sysdb_ctx_get_ldb(struct sysdb_ctx *ctx);
diff --git a/server/db/sysdb_ops.c b/server/db/sysdb_ops.c
index c237473f..ae95b51b 100644
--- a/server/db/sysdb_ops.c
+++ b/server/db/sysdb_ops.c
@@ -2769,42 +2769,6 @@ int sysdb_store_user_recv(struct tevent_req *req)
/* =Store-Group-(Native/Legacy)-(replaces-existing-data)================== */
-static char *build_dom_dn_str_escape(TALLOC_CTX *memctx, const char *template,
- const char *domain, const char *name)
-{
- char *ret;
- int l;
-
- l = strcspn(name, ",=\n+<>#;\\\"");
- if (name[l] != '\0') {
- struct ldb_val v;
- char *tmp;
-
- v.data = discard_const_p(uint8_t, name);
- v.length = strlen(name);
-
- tmp = ldb_dn_escape_value(memctx, v);
- if (!tmp) {
- return NULL;
- }
-
- ret = talloc_asprintf(memctx, template, tmp, domain);
- talloc_zfree(tmp);
- if (!ret) {
- return NULL;
- }
-
- return ret;
- }
-
- ret = talloc_asprintf(memctx, template, name, domain);
- if (!ret) {
- return NULL;
- }
-
- return ret;
-}
-
/* this function does not check that all user members are actually present */
struct sysdb_store_group_state {
@@ -2909,9 +2873,9 @@ static void sysdb_store_group_check(struct tevent_req *subreq)
for (i = 0; state->member_users && state->member_users[i]; i++) {
char *member;
- member = build_dom_dn_str_escape(state, SYSDB_TMPL_USER,
- state->domain->name,
- state->member_users[i]);
+ member = sysdb_user_strdn(state,
+ state->domain->name,
+ state->member_users[i]);
if (!member) {
DEBUG(4, ("Error: Out of memory\n"));
tevent_req_error(req, ENOMEM);
@@ -2932,9 +2896,9 @@ static void sysdb_store_group_check(struct tevent_req *subreq)
for (i = 0; state->member_groups && state->member_groups[i]; i++) {
char *member;
- member = build_dom_dn_str_escape(state, SYSDB_TMPL_GROUP,
- state->domain->name,
- state->member_groups[i]);
+ member = sysdb_group_strdn(state,
+ state->domain->name,
+ state->member_groups[i]);
if (!member) {
DEBUG(4, ("Error: Out of memory\n"));
tevent_req_error(req, ENOMEM);