On 11/17/2009 11:15 AM, Simo Sorce wrote:
> On Tue, 2009-11-17 at 09:58 -0500, Stephen Gallagher wrote:
>> +
>> +    *ver = "0.4";
>> +    return ret;
>> +}
> 
> Shouldn't you use SYSDB_VERSION_0_4 here ? :-)
> 
> Simo.
> 

Absolutely correct! I've also fixed the same in another place.

-- 
Stephen Gallagher
RHCE 804006346421761

Delivering value year after year.
Red Hat ranks #1 in value among software vendors.
http://www.redhat.com/promo/vendor/
From 601c39cdea7c3a3fef66b50e2e07f3c211e25b52 Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgall...@redhat.com>
Date: Fri, 13 Nov 2009 10:50:27 -0500
Subject: [PATCH 1/5] Make the sysdb user and group names case-sensitive

---
 server/db/sysdb_private.h  |    1 -
 server/tests/sysdb-tests.c |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/server/db/sysdb_private.h b/server/db/sysdb_private.h
index 1f603eb..ea4b246 100644
--- a/server/db/sysdb_private.h
+++ b/server/db/sysdb_private.h
@@ -34,7 +34,6 @@
      "cn: CASE_INSENSITIVE\n" \
      "dc: CASE_INSENSITIVE\n" \
      "dn: CASE_INSENSITIVE\n" \
-     "name: CASE_INSENSITIVE\n" \
      "objectclass: CASE_INSENSITIVE\n" \
      "\n" \
      "dn: @INDEXLIST\n" \
diff --git a/server/tests/sysdb-tests.c b/server/tests/sysdb-tests.c
index fffcb72..f1d3ae4 100644
--- a/server/tests/sysdb-tests.c
+++ b/server/tests/sysdb-tests.c
@@ -1398,6 +1398,7 @@ START_TEST (test_sysdb_getpwnam)
 {
     struct sysdb_test_ctx *test_ctx;
     struct test_data *data;
+    struct test_data *data_uc;
     int ret;
 
     /* Setup */
@@ -1428,6 +1429,25 @@ START_TEST (test_sysdb_getpwnam)
     }
     fail_unless(data->uid == _i,
                 "Did not find the expected UID");
+
+    /* Search for the user with the wrong case */
+    data_uc = talloc_zero(test_ctx, struct test_data);
+    data_uc->ctx = test_ctx;
+    data_uc->username = talloc_asprintf(data_uc, "TESTUSER%d", _i);
+
+    ret = sysdb_getpwnam(test_ctx,
+                         test_ctx->sysdb,
+                         data_uc->ctx->domain,
+                         data_uc->username,
+                         test_getpwent,
+                         data_uc);
+    if (ret == EOK) {
+        ret = test_loop(data_uc);
+    }
+
+    fail_unless(ret == ENOENT,
+                "The upper-case username search should fail. ");
+
 done:
     talloc_free(test_ctx);
 }
@@ -1437,6 +1457,7 @@ START_TEST (test_sysdb_getgrnam)
 {
     struct sysdb_test_ctx *test_ctx;
     struct test_data *data;
+    struct test_data *data_uc;
     int ret;
 
     /* Setup */
@@ -1468,6 +1489,24 @@ START_TEST (test_sysdb_getgrnam)
     fail_unless(data->gid == _i,
                 "Did not find the expected GID (found %d expected %d)",
                 data->gid, _i);
+
+    /* Search for the group with the wrong case */
+    data_uc = talloc_zero(test_ctx, struct test_data);
+    data_uc->ctx = test_ctx;
+    data_uc->groupname = talloc_asprintf(data_uc, "TESTGROUP%d", _i);
+
+    ret = sysdb_getgrnam(test_ctx,
+                         test_ctx->sysdb,
+                         data_uc->ctx->domain,
+                         data_uc->groupname,
+                         test_getgrent,
+                         data_uc);
+    if (ret == EOK) {
+        ret = test_loop(data_uc);
+    }
+
+    fail_unless(ret == ENOENT,
+                "The upper-case groupname search should fail. ");
 done:
     talloc_free(test_ctx);
 }
-- 
1.6.2.5

From 976e141750d047d8b71635bc4666639e6b841b51 Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgall...@redhat.com>
Date: Tue, 17 Nov 2009 09:47:04 -0500
Subject: [PATCH 2/5] Upgrade cache and local databases to case-sensitive names

---
 server/db/sysdb.c         |   94 ++++++++++++++++++++++++++++++++++++++++++++-
 server/db/sysdb_private.h |    4 +-
 2 files changed, 96 insertions(+), 2 deletions(-)

diff --git a/server/db/sysdb.c b/server/db/sysdb.c
index e4131f1..db68794 100644
--- a/server/db/sysdb.c
+++ b/server/db/sysdb.c
@@ -777,7 +777,7 @@ done:
         return EIO;
     }
 
-    *ver = "0.2";
+    *ver = SYSDB_VERSION_0_2;
     return ret;
 }
 
@@ -1065,6 +1065,93 @@ done:
     return ret;
 }
 
+static int sysdb_upgrade_03(struct sysdb_ctx *ctx, const char **ver)
+{
+    TALLOC_CTX *tmp_ctx;
+    int ret;
+    struct ldb_message *msg;
+
+    tmp_ctx = talloc_new(ctx);
+    if (!tmp_ctx) {
+        return ENOMEM;
+    }
+
+    ret = ldb_transaction_start(ctx->ldb);
+    if (ret != LDB_SUCCESS) {
+        ret = EIO;
+        goto done;
+    }
+
+    /* Make this database case-sensitive */
+    msg = ldb_msg_new(tmp_ctx);
+    if (!msg) {
+        ret = ENOMEM;
+        goto done;
+    }
+    msg->dn = ldb_dn_new(tmp_ctx, ctx->ldb, "@ATTRIBUTES");
+    if (!msg->dn) {
+        ret = ENOMEM;
+        goto done;
+    }
+
+    ret = ldb_msg_add_empty(msg, "name", LDB_FLAG_MOD_DELETE, NULL);
+    if (ret != LDB_SUCCESS) {
+        ret = ENOMEM;
+        goto done;
+    }
+
+    ret = ldb_modify(ctx->ldb, msg);
+    if (ret != LDB_SUCCESS) {
+        ret = sysdb_error_to_errno(ret);
+        goto done;
+    }
+
+    /* conversion done, upgrade version number */
+    msg = ldb_msg_new(tmp_ctx);
+    if (!msg) {
+        ret = ENOMEM;
+        goto done;
+    }
+    msg->dn = ldb_dn_new(tmp_ctx, ctx->ldb, "cn=sysdb");
+    if (!msg->dn) {
+        ret = ENOMEM;
+        goto done;
+    }
+
+    ret = ldb_msg_add_empty(msg, "version", LDB_FLAG_MOD_REPLACE, NULL);
+    if (ret != LDB_SUCCESS) {
+        ret = ENOMEM;
+        goto done;
+    }
+    ret = ldb_msg_add_string(msg, "version", SYSDB_VERSION_0_4);
+    if (ret != LDB_SUCCESS) {
+        ret = ENOMEM;
+        goto done;
+    }
+
+    ret = ldb_modify(ctx->ldb, msg);
+    if (ret != LDB_SUCCESS) {
+        ret = sysdb_error_to_errno(ret);
+        goto done;
+    }
+
+    ret = EOK;
+
+done:
+    talloc_zfree(tmp_ctx);
+
+    if (ret != EOK) {
+        ret = ldb_transaction_cancel(ctx->ldb);
+    } else {
+        ret = ldb_transaction_commit(ctx->ldb);
+    }
+    if (ret != LDB_SUCCESS) {
+        ret = EIO;
+    }
+
+    *ver = SYSDB_VERSION_0_4;
+    return ret;
+}
 
 static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
                                       struct tevent_context *ev,
@@ -1201,6 +1288,11 @@ static int sysdb_domain_init_internal(TALLOC_CTX 
*mem_ctx,
                 goto done;
             }
 
+            if (strcmp(version, SYSDB_VERSION_0_3) == 0) {
+                ret = sysdb_upgrade_03(ctx, &version);
+                if (ret != EOK) goto done;
+            }
+
         }
 
         DEBUG(0,("Unknown DB version [%s], expected [%s] for domain %s!\n",
diff --git a/server/db/sysdb_private.h b/server/db/sysdb_private.h
index ea4b246..4400665 100644
--- a/server/db/sysdb_private.h
+++ b/server/db/sysdb_private.h
@@ -23,11 +23,13 @@
 #ifndef __INT_SYS_DB_H__
 #define __INT_SYS_DB_H__
 
-#define SYSDB_VERSION "0.3"
+#define SYSDB_VERSION_0_4 "0.4"
 #define SYSDB_VERSION_0_3 "0.3"
 #define SYSDB_VERSION_0_2 "0.2"
 #define SYSDB_VERSION_0_1 "0.1"
 
+#define SYSDB_VERSION SYSDB_VERSION_0_4
+
 #define SYSDB_BASE_LDIF \
      "dn: @ATTRIBUTES\n" \
      "userPrincipalName: CASE_INSENSITIVE\n" \
-- 
1.6.2.5

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to