|
|
ad2a64 |
From 96ff6873b024718fcbb7b011eee58aab84c3086f Mon Sep 17 00:00:00 2001
|
|
|
ad2a64 |
From: Alexander Bokovoy <abokovoy@redhat.com>
|
|
|
ad2a64 |
Date: Mon, 11 Sep 2017 15:32:38 +0300
|
|
|
ad2a64 |
Subject: [PATCH 11/17] Move a helper to build DN to a format.c
|
|
|
ad2a64 |
|
|
|
ad2a64 |
---
|
|
|
ad2a64 |
src/back-sch-nss.c | 45 ++-------------------------------------------
|
|
|
ad2a64 |
src/format.c | 41 +++++++++++++++++++++++++++++++++++++++++
|
|
|
ad2a64 |
src/format.h | 2 ++
|
|
|
ad2a64 |
3 files changed, 45 insertions(+), 43 deletions(-)
|
|
|
ad2a64 |
|
|
|
ad2a64 |
diff --git a/src/back-sch-nss.c b/src/back-sch-nss.c
|
|
|
ad2a64 |
index db63e59..e4d027e 100644
|
|
|
ad2a64 |
--- a/src/back-sch-nss.c
|
|
|
ad2a64 |
+++ b/src/back-sch-nss.c
|
|
|
ad2a64 |
@@ -186,47 +186,6 @@ backend_search_filter_has_cn_uid(Slapi_Filter *filter, void *arg)
|
|
|
ad2a64 |
return SLAPI_FILTER_SCAN_CONTINUE;
|
|
|
ad2a64 |
}
|
|
|
ad2a64 |
|
|
|
ad2a64 |
-static char *
|
|
|
ad2a64 |
-backend_build_dn(const char *attribute, const char *value,
|
|
|
ad2a64 |
- const char *container_sdn)
|
|
|
ad2a64 |
-{
|
|
|
ad2a64 |
- Slapi_RDN *rdn;
|
|
|
ad2a64 |
- Slapi_DN *sdn;
|
|
|
ad2a64 |
- char *val, *dn = NULL;
|
|
|
ad2a64 |
- const char *ndn, *hexchars = "0123456789ABCDEF";
|
|
|
ad2a64 |
- int i;
|
|
|
ad2a64 |
-
|
|
|
ad2a64 |
- val = malloc(strlen(value) * 3 + 1);
|
|
|
ad2a64 |
- if (val == NULL) {
|
|
|
ad2a64 |
- return NULL;
|
|
|
ad2a64 |
- }
|
|
|
ad2a64 |
- rdn = slapi_rdn_new();
|
|
|
ad2a64 |
- if (rdn == NULL) {
|
|
|
ad2a64 |
- free(val);
|
|
|
ad2a64 |
- return NULL;
|
|
|
ad2a64 |
- }
|
|
|
ad2a64 |
- for (i = 0; value[i] != '\0'; i++) {
|
|
|
ad2a64 |
- val[i * 3] = '\\';
|
|
|
ad2a64 |
- val[i * 3 + 1] = hexchars[(value[i] & 0xf0) >> 4];
|
|
|
ad2a64 |
- val[i * 3 + 2] = hexchars[value[i] & 0xf];
|
|
|
ad2a64 |
- }
|
|
|
ad2a64 |
- val[i * 3] = '\0';
|
|
|
ad2a64 |
- if (slapi_rdn_add(rdn, attribute, val) == 1) {
|
|
|
ad2a64 |
- sdn = slapi_sdn_new_dn_byval(container_sdn);
|
|
|
ad2a64 |
- if (sdn != NULL) {
|
|
|
ad2a64 |
- sdn = slapi_sdn_add_rdn(sdn, rdn);
|
|
|
ad2a64 |
- ndn = slapi_sdn_get_ndn(sdn);
|
|
|
ad2a64 |
- if (ndn != NULL) {
|
|
|
ad2a64 |
- dn = slapi_ch_strdup(ndn);
|
|
|
ad2a64 |
- }
|
|
|
ad2a64 |
- slapi_sdn_free(&sdn;;
|
|
|
ad2a64 |
- }
|
|
|
ad2a64 |
- }
|
|
|
ad2a64 |
- free(val);
|
|
|
ad2a64 |
- slapi_rdn_free(&rdn;;
|
|
|
ad2a64 |
- return dn;
|
|
|
ad2a64 |
-}
|
|
|
ad2a64 |
-
|
|
|
ad2a64 |
static Slapi_Entry *
|
|
|
ad2a64 |
backend_make_user_entry_from_nsswitch_passwd(struct passwd *pwd,
|
|
|
ad2a64 |
char *container_sdn,
|
|
|
ad2a64 |
@@ -257,7 +216,7 @@ backend_make_user_entry_from_nsswitch_passwd(struct passwd *pwd,
|
|
|
ad2a64 |
return NULL;
|
|
|
ad2a64 |
}
|
|
|
ad2a64 |
|
|
|
ad2a64 |
- dn = backend_build_dn("uid", name, container_sdn);
|
|
|
ad2a64 |
+ dn = format_build_dn("uid", name, container_sdn);
|
|
|
ad2a64 |
if (dn == NULL) {
|
|
|
ad2a64 |
slapi_log_error(SLAPI_LOG_FATAL,
|
|
|
ad2a64 |
cbdata->state->plugin_desc->spd_id,
|
|
|
ad2a64 |
@@ -556,7 +515,7 @@ backend_make_group_entry_from_nsswitch_group(struct group *grp,
|
|
|
ad2a64 |
return NULL;
|
|
|
ad2a64 |
}
|
|
|
ad2a64 |
|
|
|
ad2a64 |
- dn = backend_build_dn("cn", grp->gr_name, container_sdn);
|
|
|
ad2a64 |
+ dn = format_build_dn("cn", grp->gr_name, container_sdn);
|
|
|
ad2a64 |
if (dn == NULL) {
|
|
|
ad2a64 |
slapi_log_error(SLAPI_LOG_FATAL,
|
|
|
ad2a64 |
cbdata->state->plugin_desc->spd_id,
|
|
|
ad2a64 |
diff --git a/src/format.c b/src/format.c
|
|
|
ad2a64 |
index ee6b8f3..ae4824c 100644
|
|
|
ad2a64 |
--- a/src/format.c
|
|
|
ad2a64 |
+++ b/src/format.c
|
|
|
ad2a64 |
@@ -4825,3 +4825,44 @@ format_escape_for_filter(const char *unescaped)
|
|
|
ad2a64 |
}
|
|
|
ad2a64 |
return ret;
|
|
|
ad2a64 |
}
|
|
|
ad2a64 |
+
|
|
|
ad2a64 |
+char *
|
|
|
ad2a64 |
+format_build_dn(const char *attribute, const char *value,
|
|
|
ad2a64 |
+ const char *container_sdn)
|
|
|
ad2a64 |
+{
|
|
|
ad2a64 |
+ Slapi_RDN *rdn;
|
|
|
ad2a64 |
+ Slapi_DN *sdn;
|
|
|
ad2a64 |
+ char *val, *dn = NULL;
|
|
|
ad2a64 |
+ const char *ndn, *hexchars = "0123456789ABCDEF";
|
|
|
ad2a64 |
+ int i;
|
|
|
ad2a64 |
+
|
|
|
ad2a64 |
+ val = malloc(strlen(value) * 3 + 1);
|
|
|
ad2a64 |
+ if (val == NULL) {
|
|
|
ad2a64 |
+ return NULL;
|
|
|
ad2a64 |
+ }
|
|
|
ad2a64 |
+ rdn = slapi_rdn_new();
|
|
|
ad2a64 |
+ if (rdn == NULL) {
|
|
|
ad2a64 |
+ free(val);
|
|
|
ad2a64 |
+ return NULL;
|
|
|
ad2a64 |
+ }
|
|
|
ad2a64 |
+ for (i = 0; value[i] != '\0'; i++) {
|
|
|
ad2a64 |
+ val[i * 3] = '\\';
|
|
|
ad2a64 |
+ val[i * 3 + 1] = hexchars[(value[i] & 0xf0) >> 4];
|
|
|
ad2a64 |
+ val[i * 3 + 2] = hexchars[value[i] & 0xf];
|
|
|
ad2a64 |
+ }
|
|
|
ad2a64 |
+ val[i * 3] = '\0';
|
|
|
ad2a64 |
+ if (slapi_rdn_add(rdn, attribute, val) == 1) {
|
|
|
ad2a64 |
+ sdn = slapi_sdn_new_dn_byval(container_sdn);
|
|
|
ad2a64 |
+ if (sdn != NULL) {
|
|
|
ad2a64 |
+ sdn = slapi_sdn_add_rdn(sdn, rdn);
|
|
|
ad2a64 |
+ ndn = slapi_sdn_get_ndn(sdn);
|
|
|
ad2a64 |
+ if (ndn != NULL) {
|
|
|
ad2a64 |
+ dn = slapi_ch_strdup(ndn);
|
|
|
ad2a64 |
+ }
|
|
|
ad2a64 |
+ slapi_sdn_free(&sdn;;
|
|
|
ad2a64 |
+ }
|
|
|
ad2a64 |
+ }
|
|
|
ad2a64 |
+ free(val);
|
|
|
ad2a64 |
+ slapi_rdn_free(&rdn;;
|
|
|
ad2a64 |
+ return dn;
|
|
|
ad2a64 |
+}
|
|
|
ad2a64 |
diff --git a/src/format.h b/src/format.h
|
|
|
ad2a64 |
index 4cde2dc..626d4a9 100644
|
|
|
ad2a64 |
--- a/src/format.h
|
|
|
ad2a64 |
+++ b/src/format.h
|
|
|
ad2a64 |
@@ -83,4 +83,6 @@ char **format_get_data_set(struct plugin_state *state,
|
|
|
ad2a64 |
unsigned int **data_lengths);
|
|
|
ad2a64 |
|
|
|
ad2a64 |
char *format_escape_for_filter(const char *unescaped);
|
|
|
ad2a64 |
+char *format_build_dn(const char *attribute, const char *value,
|
|
|
ad2a64 |
+ const char *container_sdn);
|
|
|
ad2a64 |
#endif
|
|
|
ad2a64 |
--
|
|
|
ad2a64 |
2.13.6
|
|
|
ad2a64 |
|