db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose Library for rule based certificate to user mapping - LDAP mapping rules
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose Sumit Bose <sbose@redhat.com>
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose Copyright (C) 2017 Red Hat
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose This program is free software; you can redistribute it and/or modify
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose it under the terms of the GNU General Public License as published by
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose the Free Software Foundation; either version 3 of the License, or
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose (at your option) any later version.
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose This program is distributed in the hope that it will be useful,
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose GNU General Public License for more details.
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose You should have received a copy of the GNU General Public License
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Boseconst char *x500_conv[] = {"ad_x500", "ad", "ad_ldap",
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bosestatic int check_parsed_template(struct sss_certmap_ctx *ctx,
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose for (n = 0; template_table[n].name != NULL; n++) {
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose if (strcmp(template_table[n].name, parsed->name) != 0) {
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose for (a = 0; template_table[n].attr_name[a] != NULL; a++) {
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose for (c = 0; template_table[n].conversion[c] != NULL; c++) {
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bosestatic int parse_template(TALLOC_CTX *mem_ctx, struct sss_certmap_ctx *ctx,
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose const char *p;
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose parsed = talloc_zero(mem_ctx, struct parsed_template);
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose CM_DEBUG(ctx, "Only one '.' allowed in template.");
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose CM_DEBUG(ctx, "Only one '!' allowed in template.");
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose parsed->conversion = talloc_strdup(parsed, excl + 1);
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose if (dot != NULL && dot[1] != '\0' && dot[1] != '!') {
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose parsed->attr_name = talloc_strdup(parsed, dot + 1);
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose parsed->attr_name = talloc_strndup(parsed, dot + 1,
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose parsed->name = talloc_strndup(parsed, template, (dot - template));
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose parsed->name = talloc_strndup(parsed, template, (excl - template));
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bosestatic int add_comp(struct sss_certmap_ctx *ctx, struct ldap_mapping_rule *rule,
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose comp = talloc_zero(rule, struct ldap_mapping_rule_comp);
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose ret = parse_template(comp, ctx, string, &comp->parsed_template);
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose DLIST_ADD_END(rule->list, comp, struct ldap_mapping_rule_comp *);
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bosestatic int add_string(struct sss_certmap_ctx *ctx,
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose struct ldap_mapping_rule *rule, const char *string)
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bosestatic int add_template(struct sss_certmap_ctx *ctx,
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose struct ldap_mapping_rule *rule, const char *string)
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose return add_comp(ctx, rule, string, comp_template);
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Boseint parse_ldap_mapping_rule(struct sss_certmap_ctx *ctx,
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose rule = talloc_zero(ctx, struct ldap_mapping_rule);
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose tmp_string = talloc_zero_size(ctx, tmp_string_size);
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose /* Add only a single '{' to the output */
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose if (c != 0) {
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose /* Add only a single '}' to the output */
db36dca3d45e6eefbb30042ee65876566f1a6014Sumit Bose if (c != 0) {