Example #1
0
END_TEST

static void
compare_map_id_name_to_krb_primary(struct map_id_name_to_krb_primary *a,
                                   const char **str,
                                   size_t len)
{
    int i = 0;
    errno_t ret;

    while (a[i].id_name != NULL && a[i].krb_primary != NULL) {
        fail_unless(i < len);
        ret = sss_utf8_case_eq((const uint8_t*)a[i].id_name,
                               (const uint8_t*)str[i*2]);
        fail_unless(ret == EOK,
                    "%s does not match %s", a[i].id_name, str[i*2]);

        ret = sss_utf8_case_eq((const uint8_t*)a[i].krb_primary,
                               (const uint8_t*)str[i*2+1]);
        fail_unless(ret == EOK, "%s does not match %s",
                    a[i].krb_primary, str[i*2+1]);
        i++;
    }
    fail_unless(len == i, "%u != %u", len, i);
}
Example #2
0
static errno_t hbac_evaluate_element(struct hbac_rule_element *rule_el,
                                     struct hbac_request_element *req_el,
                                     bool *matched)
{
    size_t i, j;
    const uint8_t *rule_name;
    const uint8_t *req_name;
    int ret;

    if (rule_el->category & HBAC_CATEGORY_ALL) {
        *matched = true;
        return EOK;
    }

    /* First check the name list */
    if (rule_el->names) {
        for (i = 0; rule_el->names[i]; i++) {
            if (req_el->name != NULL) {
                rule_name = (const uint8_t *) rule_el->names[i];
                req_name = (const uint8_t *) req_el->name;

                /* Do a case-insensitive comparison. */
                ret = sss_utf8_case_eq(rule_name, req_name);
                if (ret != EOK && ret != ENOMATCH) {
                    return ret;
                } else if (ret == EOK) {
                    *matched = true;
                    return EOK;
                }
            }
        }
    }

    if (rule_el->groups) {
        /* Not found in the name list
         * Check for group membership
         */
        for (i = 0; rule_el->groups[i]; i++) {
            rule_name = (const uint8_t *) rule_el->groups[i];

            for (j = 0; req_el->groups[j]; j++) {
                req_name = (const uint8_t *) req_el->groups[j];

                /* Do a case-insensitive comparison. */
                ret = sss_utf8_case_eq(rule_name, req_name);
                if (ret != EOK && ret != ENOMATCH) {
                    return ret;
                } else if (ret == EOK) {
                    *matched = true;
                    return EOK;
                }
            }
        }
    }

    /* Not found in groups either */
    *matched = false;
    return EOK;
}
Example #3
0
File: sss_utf8.c Project: SSSD/sssd
bool sss_string_equal(bool cs, const char *s1, const char *s2)
{
    if (cs) {
        return strcmp(s1, s2) == 0;
    }

    return sss_utf8_case_eq((const uint8_t *)s1, (const uint8_t *)s2) == EOK;
}
Example #4
0
END_TEST

START_TEST(test_utf8_caseeq)
{
    const uint8_t munchen_utf8_upcase[] = { 'M', 0xC3, 0x9C, 'N', 'C', 'H', 'E', 'N', 0x0 };
    const uint8_t munchen_utf8_lowcase[] = { 'm', 0xC3, 0xBC, 'n', 'c', 'h', 'e', 'n', 0x0 };
    const uint8_t czech_utf8_lowcase[] = { 0xC4, 0x8D, 'e', 'c', 'h', 0x0 };
    const uint8_t czech_utf8_upcase[] = { 0xC4, 0x8C, 'e', 'c', 'h', 0x0 };
    const uint8_t czech_utf8_lowcase_neg[] = { 0xC4, 0x8E, 'e', 'c', 'h', 0x0 };
    errno_t ret;

    ret = sss_utf8_case_eq(munchen_utf8_upcase, munchen_utf8_lowcase);
    fail_unless(ret == EOK, "Latin 1 Supplement comparison failed\n");

    ret = sss_utf8_case_eq(czech_utf8_upcase, czech_utf8_lowcase);
    fail_unless(ret == EOK, "Latin Extended A comparison failed\n");

    ret = sss_utf8_case_eq(czech_utf8_upcase, czech_utf8_lowcase_neg);
    fail_if(ret == EOK, "Negative test succeeded\n");
}