diff --git a/src/providers/ldap/ldap_id.c b/src/providers/ldap/ldap_id.c index ebc0ab8e4..2e7bfd2ff 100644 --- a/src/providers/ldap/ldap_id.c +++ b/src/providers/ldap/ldap_id.c @@ -226,21 +226,37 @@ struct tevent_req *users_get_send(TALLOC_CTX *memctx, goto done; } - ep_filter = get_enterprise_principal_string_filter(state, - ctx->opts->user_map[SDAP_AT_USER_PRINC].name, - clean_value, ctx->opts->basic); - /* TODO: Do we have to check the attribute names more carefully? */ - user_filter = talloc_asprintf(state, "(|(%s=%s)(%s=%s)%s)", - ctx->opts->user_map[SDAP_AT_USER_PRINC].name, - clean_value, - ctx->opts->user_map[SDAP_AT_USER_EMAIL].name, - clean_value, - ep_filter == NULL ? "" : ep_filter); - talloc_zfree(clean_value); - if (user_filter == NULL) { - DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n"); - ret = ENOMEM; - goto done; + /* If user principal and user email are set, do full filtering */ + if ((ctx->opts->user_map[SDAP_AT_USER_PRINC].name != NULL) && + (ctx->opts->user_map[SDAP_AT_USER_EMAIL].name != NULL)) { + ep_filter = get_enterprise_principal_string_filter(state, + ctx->opts->user_map[SDAP_AT_USER_PRINC].name, + clean_value, ctx->opts->basic); + user_filter = talloc_asprintf(state, "(|(%s=%s)(%s=%s)%s)", + ctx->opts->user_map[SDAP_AT_USER_PRINC].name, + clean_value, + ctx->opts->user_map[SDAP_AT_USER_EMAIL].name, + clean_value, + ep_filter == NULL ? "" : ep_filter); + talloc_zfree(clean_value); + if (user_filter == NULL) { + DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n"); + ret = ENOMEM; + goto done; + } + } else { + /* Otherwise, we deal with non-Kerberised schema, filter only by email */ + if (ctx->opts->user_map[SDAP_AT_USER_EMAIL].name != NULL) { + user_filter = talloc_asprintf(state, "(%s=%s)", + ctx->opts->user_map[SDAP_AT_USER_EMAIL].name, + clean_value); + talloc_zfree(clean_value); + if (user_filter == NULL) { + DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n"); + ret = ENOMEM; + goto done; + } + } } } else { attr_name = ctx->opts->user_map[SDAP_AT_USER_NAME].name;