diff options
Diffstat (limited to 'src/back-sch-idview.c')
-rw-r--r-- | src/back-sch-idview.c | 86 |
1 files changed, 58 insertions, 28 deletions
diff --git a/src/back-sch-idview.c b/src/back-sch-idview.c index a56a9e9..f1150cd 100644 --- a/src/back-sch-idview.c +++ b/src/back-sch-idview.c @@ -290,21 +290,15 @@ idview_replace_target_dn(char **target, char **idview) } } -static int -idview_process_filter_cb(Slapi_Filter *filter, const char *filter_type, struct berval *bval, struct backend_search_filter_config *config) +int +idview_replace_bval_by_override(const char *bval_usage, const char *attr_name, + struct berval *bval, struct backend_search_cbdata *cbdata) { int res, i; - Slapi_Value *filter_val, *value, *anchor_val; + Slapi_Value *attr_val, *value, *anchor_val; Slapi_Attr *anchor, *attr = NULL; - struct backend_search_cbdata *cbdata = (struct backend_search_cbdata *) config->callback_data; - - if (cbdata == NULL || cbdata->idview == NULL) { - return SLAPI_FILTER_SCAN_CONTINUE; - } - - if (filter_type == NULL || config->name == NULL) { - return SLAPI_FILTER_SCAN_CONTINUE; - } + bool_t uid_override_found = FALSE; + bool_t anchor_override_found = FALSE; if (cbdata->overrides == NULL) { /* Only retrieve overrides for the view first time when neccessary */ @@ -312,31 +306,34 @@ idview_process_filter_cb(Slapi_Filter *filter, const char *filter_type, struct b } if (cbdata->overrides == NULL) { - return SLAPI_FILTER_SCAN_CONTINUE; + return 0; } - filter_val = slapi_value_new_berval(bval); + attr_val = slapi_value_new_berval(bval); + slapi_log_error(SLAPI_LOG_FATAL, cbdata->state->plugin_desc->spd_id, + "Searching for an override of the %s %s with %s=%*s from the overrides\n.", + bval_usage, attr_name, attr_name, (int) bval->bv_len, bval->bv_val); /* If filter contains an attribute name which is overridden in the view and filter value * corresponds to the override, replace the filter by (ipaAnchorUUID=...) from the override * to point to the original because otherwise an entry will not be found in the slapi-nis map */ for(i=0; cbdata->overrides[i] != NULL; i++) { - res = slapi_entry_attr_find(cbdata->overrides[i], filter_type, &attr); + res = slapi_entry_attr_find(cbdata->overrides[i], attr_name, &attr); if ((res == 0) && (attr != NULL)) { res = slapi_attr_first_value(attr, &value); - res = slapi_value_compare(attr, value, filter_val); + res = slapi_value_compare(attr, value, attr_val); if (res == 0) { /* For uid overrides we should have ipaOriginalUID in the override */ - if (strcasecmp(filter_type, "uid") == 0) { + if (strcasecmp(attr_name, "uid") == 0) { res = slapi_entry_attr_find(cbdata->overrides[i], IPA_IDVIEWS_ATTR_ORIGINALUID, &anchor); if (res == 0) { res = slapi_attr_first_value(anchor, &anchor_val); slapi_ber_bvdone(bval); slapi_ber_bvcpy(bval, slapi_value_get_berval(anchor_val)); - config->override_found = TRUE; - slapi_log_error(SLAPI_LOG_PLUGIN, cbdata->state->plugin_desc->spd_id, - "Overriding the filter %s with %s=%*s from the override %s\n.", - filter_type, filter_type, bval->bv_len, bval->bv_val, + uid_override_found = TRUE; + slapi_log_error(SLAPI_LOG_FATAL, cbdata->state->plugin_desc->spd_id, + "Overriding the %s %s with %s=%*s from the override %s\n.", + bval_usage, attr_name, attr_name, (int) bval->bv_len, bval->bv_val, slapi_entry_get_dn_const(cbdata->overrides[i])); break; } @@ -346,14 +343,13 @@ idview_process_filter_cb(Slapi_Filter *filter, const char *filter_type, struct b res = slapi_entry_attr_find(cbdata->overrides[i], IPA_IDVIEWS_ATTR_ANCHORUUID, &anchor); if (res == 0) { res = slapi_attr_first_value(anchor, &anchor_val); - slapi_filter_changetype(filter, IPA_IDVIEWS_ATTR_ANCHORUUID); slapi_ber_bvdone(bval); slapi_ber_bvcpy(bval, slapi_value_get_berval(anchor_val)); - config->override_found = TRUE; - slapi_log_error(SLAPI_LOG_PLUGIN, cbdata->state->plugin_desc->spd_id, - "Overriding the filter %s with %s=%*s from the override %s\n.", - filter_type, IPA_IDVIEWS_ATTR_ANCHORUUID, - bval->bv_len, bval->bv_val, + anchor_override_found = TRUE; + slapi_log_error(SLAPI_LOG_FATAL, cbdata->state->plugin_desc->spd_id, + "Overriding the %s %s with %s=%*s from the override %s\n.", + bval_usage, attr_name, IPA_IDVIEWS_ATTR_ANCHORUUID, + (int) bval->bv_len, bval->bv_val, slapi_entry_get_dn_const(cbdata->overrides[i])); break; } @@ -362,7 +358,41 @@ idview_process_filter_cb(Slapi_Filter *filter, const char *filter_type, struct b } } - slapi_value_free(&filter_val); + slapi_value_free(&attr_val); + + if (uid_override_found) { + return 1; + } + + if (anchor_override_found) { + return 2; + } + + return 0; +} + +static int +idview_process_filter_cb(Slapi_Filter *filter, const char *filter_type, + struct berval *bval, struct backend_search_filter_config *config) +{ + int res; + struct backend_search_cbdata *cbdata = (struct backend_search_cbdata *) config->callback_data; + + if (cbdata == NULL || cbdata->idview == NULL) { + return SLAPI_FILTER_SCAN_CONTINUE; + } + + if (filter_type == NULL || config->name == NULL) { + return SLAPI_FILTER_SCAN_CONTINUE; + } + + res = idview_replace_bval_by_override("filter", filter_type, bval, cbdata); + + if (res == 2) { + slapi_filter_changetype(filter, IPA_IDVIEWS_ATTR_ANCHORUUID); + } + + config->override_found = (res != 0); return SLAPI_FILTER_SCAN_CONTINUE; |