[SSSD] [PATCH] Save alias of the service primary name, too

Jakub Hrozek jhrozek at redhat.com
Mon Mar 19 08:10:48 UTC 2012


After the recent changes to sysdb_attrs_get_aliases() we stopped saving
the lowercased alias of the primary name.

Services are a different beast than the rest of the entries, because
with everything else the nss responder only uses the alias to match the
entry. With services, we also need to print the aliases.

The attached patch changes the behaviour so that all aliases are saved
lowercased in an insensitive domain, including the primary name, but
when returning the service, the alias that matches the primary name is
filtered out. Because all aliases are lowercased now, I also removed the
sss_get_cased_name() call, it is no longer needed.
-------------- next part --------------
From 79d5de8a58344470a4febd3472ec9b3c0b150132 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Mon, 19 Mar 2012 08:02:06 +0100
Subject: [PATCH 1/2] Make the string_equal() function public

---
 src/providers/simple/simple_access.c |   17 ++++-------------
 src/util/sss_utf8.c                  |    9 +++++++++
 src/util/util.h                      |    1 +
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/providers/simple/simple_access.c b/src/providers/simple/simple_access.c
index 06662e9dfe3ffd13d8dd785545a836b7e519c8c3..e00079cd3685389f689cd21f59b15b8c847d620a 100644
--- a/src/providers/simple/simple_access.c
+++ b/src/providers/simple/simple_access.c
@@ -35,15 +35,6 @@
 #define CONFDB_SIMPLE_ALLOW_GROUPS "simple_allow_groups"
 #define CONFDB_SIMPLE_DENY_GROUPS "simple_deny_groups"
 
-static bool 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;
-}
-
 errno_t simple_access_check(struct simple_ctx *ctx, const char *username,
                             bool *access_granted)
 {
@@ -68,7 +59,7 @@ errno_t simple_access_check(struct simple_ctx *ctx, const char *username,
     /* First, check whether the user is in the allowed users list */
     if (ctx->allow_users != NULL) {
         for(i = 0; ctx->allow_users[i] != NULL; i++) {
-            if (string_equal(cs, username, ctx->allow_users[i])) {
+            if (sss_string_equal(cs, username, ctx->allow_users[i])) {
                 DEBUG(9, ("User [%s] found in allow list, access granted.\n",
                       username));
 
@@ -89,7 +80,7 @@ errno_t simple_access_check(struct simple_ctx *ctx, const char *username,
     /* Next check whether this user has been specifically denied */
     if (ctx->deny_users != NULL) {
         for(i = 0; ctx->deny_users[i] != NULL; i++) {
-            if (string_equal(cs, username, ctx->deny_users[i])) {
+            if (sss_string_equal(cs, username, ctx->deny_users[i])) {
                 DEBUG(9, ("User [%s] found in deny list, access denied.\n",
                       username));
 
@@ -200,7 +191,7 @@ errno_t simple_access_check(struct simple_ctx *ctx, const char *username,
         matched = false;
         for (i = 0; ctx->allow_groups[i]; i++) {
             for(j = 0; groups[j]; j++) {
-                if (string_equal(cs, groups[j], ctx->allow_groups[i])) {
+                if (sss_string_equal(cs, groups[j], ctx->allow_groups[i])) {
                     matched = true;
                     break;
                 }
@@ -221,7 +212,7 @@ errno_t simple_access_check(struct simple_ctx *ctx, const char *username,
         matched = false;
         for (i = 0; ctx->deny_groups[i]; i++) {
             for(j = 0; groups[j]; j++) {
-                if (string_equal(cs, groups[j], ctx->deny_groups[i])) {
+                if (sss_string_equal(cs, groups[j], ctx->deny_groups[i])) {
                     matched = true;
                     break;
                 }
diff --git a/src/util/sss_utf8.c b/src/util/sss_utf8.c
index 7997a6df4454ef2ec7e5469e244bb5e1c444b1ba..27c5cb60ad5db56a8d92a57bddacf28d7fab21ea 100644
--- a/src/util/sss_utf8.c
+++ b/src/util/sss_utf8.c
@@ -171,3 +171,12 @@ errno_t sss_utf8_case_eq(const uint8_t *s1, const uint8_t *s2)
 #else
 #error No unicode library
 #endif
+
+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;
+}
diff --git a/src/util/util.h b/src/util/util.h
index 7eb62a9b94b9d6891ea51fd5b995804527c8030e..985c7898182c5e58ca79e049f99f37d724009cf1 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -516,6 +516,7 @@ char *
 sss_tc_utf8_str_tolower(TALLOC_CTX *mem_ctx, const char *s);
 uint8_t *
 sss_tc_utf8_tolower(TALLOC_CTX *mem_ctx, const uint8_t *s, size_t len, size_t *_nlen);
+bool sss_string_equal(bool cs, const char *s1, const char *s2);
 
 /* len includes terminating '\0' */
 struct sized_string {
-- 
1.7.7.6

-------------- next part --------------
From 05516d81b477dd437c22c9f67f4862d0283f7b6c Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Mon, 19 Mar 2012 08:03:32 +0100
Subject: [PATCH 2/2] Save alias of the primary name, too

---
 src/db/sysdb.c                      |   12 +++++++++---
 src/responder/nss/nsssrv_services.c |   22 ++++++++++++++--------
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index 1bf189238ab2761136fe2e039287b8b6f8cce536..5436fb832f13247064ee7739f2254dcfa2aafda4 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -1731,7 +1731,7 @@ errno_t sysdb_attrs_get_aliases(TALLOC_CTX *mem_ctx,
 {
     TALLOC_CTX *tmp_ctx = NULL;
     struct ldb_message_element *sysdb_name_el;
-    size_t i, ai;
+    size_t i, j, ai;
     errno_t ret;
     const char **aliases = NULL;
     const char *name;
@@ -1776,8 +1776,14 @@ errno_t sysdb_attrs_get_aliases(TALLOC_CTX *mem_ctx,
                 goto done;
             }
 
-            if (sss_utf8_case_eq((const uint8_t *) primary,
-                                 (const uint8_t *) lower) == ENOMATCH) {
+            for (j=0; j < ai; j++) {
+                if (sss_utf8_case_eq((const uint8_t *) aliases[j],
+                                     (const uint8_t *) lower) == ENOMATCH) {
+                    break;
+                }
+            }
+
+            if (ai == 0 || j < ai) {
                 aliases[ai] = talloc_strdup(aliases, lower);
                 if (!aliases[ai]) {
                     ret = ENOMEM;
diff --git a/src/responder/nss/nsssrv_services.c b/src/responder/nss/nsssrv_services.c
index 1b58986c44e800c44ace1de1136638572adec7e6..0739362c4d17368e023226028a995b4ea594345a 100644
--- a/src/responder/nss/nsssrv_services.c
+++ b/src/responder/nss/nsssrv_services.c
@@ -596,9 +596,9 @@ fill_service(struct sss_packet *packet,
 {
     errno_t ret;
     unsigned int msg_count = *count;
-    size_t rzero, rsize;
+    size_t rzero, rsize, aptr;
     unsigned int num, i, j;
-    uint32_t num_aliases;
+    uint32_t num_aliases, written_aliases;
     struct ldb_message *msg;
     struct ldb_message_element *el;
     TALLOC_CTX *tmp_ctx = NULL;
@@ -710,8 +710,9 @@ fill_service(struct sss_packet *packet,
             num_aliases = el->num_values;
         }
 
-        /* Store the alias count */
-        SAFEALIGN_SET_UINT32(&body[rzero + rsize], num_aliases, &rsize);
+        /* We'll store the alias count here */
+        aptr = rzero+rsize;
+        rsize += sizeof(uint32_t);
 
         /* Store the primary name */
         safealign_memcpy(&body[rzero + rsize],
@@ -725,11 +726,14 @@ fill_service(struct sss_packet *packet,
                          cased_proto.len,
                          &rsize);
 
+        written_aliases = 0;
         for (j = 0; j < num_aliases; j++) {
-            tmpstr = sss_get_cased_name(tmp_ctx,
-                                        (const char *)el->values[j].data,
-                                        dom->case_sensitive);
-            to_sized_string(&alias, tmpstr);
+            if (sss_string_equal(dom->case_sensitive,
+                             (const char *)el->values[j].data,
+                             cased_name.str)) {
+                continue;
+            }
+            to_sized_string(&alias, (const char *)el->values[j].data);
 
             ret = sss_packet_grow(packet, alias.len);
             if (ret != EOK) {
@@ -744,8 +748,10 @@ fill_service(struct sss_packet *packet,
                              alias.len,
                              &rsize);
 
+            written_aliases++;
             talloc_zfree(tmpstr);
         }
+        SAFEALIGN_SET_UINT32(&body[aptr], written_aliases, &rsize);
 
         num++;
     }
-- 
1.7.7.6



More information about the sssd-devel mailing list