diff options
author | Sumit Bose <sbose@redhat.com> | 2017-02-02 16:34:32 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2017-03-23 17:19:14 +0100 |
commit | b341ee51cffd98b642b9c68a417f8a7504e303a1 (patch) | |
tree | bc1a2f70566cf587376bf38db7c49ded080b9090 /src/util | |
parent | 81c564a0692aa4b719af2219f52894e6cd4bdf9f (diff) | |
download | sssd-b341ee51cffd98b642b9c68a417f8a7504e303a1.tar.gz sssd-b341ee51cffd98b642b9c68a417f8a7504e303a1.tar.xz sssd-b341ee51cffd98b642b9c68a417f8a7504e303a1.zip |
sss_cert_derb64_to_ldap_filter: add sss_certmap support
Use certificate mapping library if available to lookup a user by
certificate in LDAP.
Related to https://pagure.io/SSSD/sssd/issue/3050
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/cert.h | 3 | ||||
-rw-r--r-- | src/util/cert/cert_common.c | 76 |
2 files changed, 68 insertions, 11 deletions
diff --git a/src/util/cert.h b/src/util/cert.h index bb64d0d7a..4598aa8df 100644 --- a/src/util/cert.h +++ b/src/util/cert.h @@ -21,6 +21,7 @@ #include <talloc.h> #include "util/util.h" +#include "lib/certmap/sss_certmap.h" #ifndef __CERT_H__ #define __CERT_H__ @@ -39,6 +40,8 @@ errno_t sss_cert_pem_to_derb64(TALLOC_CTX *mem_ctx, const char *pem, errno_t sss_cert_derb64_to_ldap_filter(TALLOC_CTX *mem_ctx, const char *derb64, const char *attr_name, + struct sss_certmap_ctx *certmap_ctx, + struct sss_domain_info *dom, char **ldap_filter); errno_t bin_to_ldap_filter_value(TALLOC_CTX *mem_ctx, diff --git a/src/util/cert/cert_common.c b/src/util/cert/cert_common.c index a29696ed3..766877089 100644 --- a/src/util/cert/cert_common.c +++ b/src/util/cert/cert_common.c @@ -72,12 +72,17 @@ errno_t sss_cert_pem_to_derb64(TALLOC_CTX *mem_ctx, const char *pem, errno_t sss_cert_derb64_to_ldap_filter(TALLOC_CTX *mem_ctx, const char *derb64, const char *attr_name, + struct sss_certmap_ctx *certmap_ctx, + struct sss_domain_info *dom, char **ldap_filter) { int ret; unsigned char *der; size_t der_size; char *val; + char *filter = NULL; + char **domains = NULL; + size_t c; if (derb64 == NULL || attr_name == NULL) { return EINVAL; @@ -89,18 +94,67 @@ errno_t sss_cert_derb64_to_ldap_filter(TALLOC_CTX *mem_ctx, const char *derb64, return EINVAL; } - ret = bin_to_ldap_filter_value(mem_ctx, der, der_size, &val); - talloc_free(der); - if (ret != EOK) { - DEBUG(SSSDBG_OP_FAILURE, "bin_to_ldap_filter_value failed.\n"); - return ret; - } + if (certmap_ctx == NULL) { + ret = bin_to_ldap_filter_value(mem_ctx, der, der_size, &val); + talloc_free(der); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, "bin_to_ldap_filter_value failed.\n"); + return ret; + } - *ldap_filter = talloc_asprintf(mem_ctx, "(%s=%s)", attr_name, val); - talloc_free(val); - if (*ldap_filter == NULL) { - DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n"); - return ENOMEM; + *ldap_filter = talloc_asprintf(mem_ctx, "(%s=%s)", attr_name, val); + talloc_free(val); + if (*ldap_filter == NULL) { + DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n"); + return ENOMEM; + } + } else { + ret = sss_certmap_get_search_filter(certmap_ctx, der, der_size, + &filter, &domains); + talloc_free(der); + if (ret != 0) { + if (ret == ENOENT) { + DEBUG(SSSDBG_OP_FAILURE, + "Certificate does not match matching-rules.\n"); + } else { + DEBUG(SSSDBG_OP_FAILURE, + "sss_certmap_get_search_filter failed.\n"); + } + } else { + if (domains == NULL) { + if (IS_SUBDOMAIN(dom)) { + DEBUG(SSSDBG_TRACE_FUNC, + "Rule applies only to local domain.\n"); + ret = ENOENT; + } + } else { + for (c = 0; domains[c] != NULL; c++) { + if (strcasecmp(dom->name, domains[c]) == 0) { + DEBUG(SSSDBG_TRACE_FUNC, + "Rule applies to current domain [%s].\n", + dom->name); + ret = EOK; + break; + } + } + if (domains[c] == NULL) { + DEBUG(SSSDBG_TRACE_FUNC, + "Rule does not apply to current domain [%s].\n", + dom->name); + ret = ENOENT; + } + } + } + + if (ret == EOK) { + *ldap_filter = talloc_strdup(mem_ctx, filter); + if (*ldap_filter == NULL) { + DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n"); + ret = ENOMEM; + } + } + sss_certmap_free_filter_and_domains(filter, domains); + return ret; } return EOK; |