From 49a4994f0dd56e2478c5fac2e4bfd5613bb4d1f5 Mon Sep 17 00:00:00 2001
From: Jan Zeleny <jzeleny@redhat.com>
Date: Fri, 27 May 2011 07:32:17 -0400
Subject: [PATCH 1/2] Non-posix group processing - sysdb changes

---
 src/db/sysdb.h          |    5 +++--
 src/db/sysdb_ops.c      |   42 ++++++++++++++++++++++++------------------
 src/tests/sysdb-tests.c |   10 ++++++----
 3 files changed, 33 insertions(+), 24 deletions(-)

diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index 68fc698641c3719e63ff50528e6d67076f46b010..1eac748c01e02326033ade5ff0c79b88a4a3b137 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -62,6 +62,7 @@
 
 #define SYSDB_MEMBER "member"
 #define SYSDB_MEMBERUID "memberUid"
+#define SYSDB_POSIX "isPosix"
 
 #define SYSDB_DEFAULTGROUP "defaultGroup"
 #define SYSDB_GECOS "gecos"
@@ -154,7 +155,7 @@
                            NULL}
 
 #define SYSDB_INITGR_ATTR SYSDB_MEMBEROF
-#define SYSDB_INITGR_ATTRS {SYSDB_GIDNUM, \
+#define SYSDB_INITGR_ATTRS {SYSDB_GIDNUM, SYSDB_POSIX, \
                             SYSDB_DEFAULT_ATTRS, \
                             NULL}
 
@@ -518,7 +519,7 @@ int sysdb_add_incomplete_group(struct sysdb_ctx *ctx,
                                struct sss_domain_info *domain,
                                const char *name,
                                gid_t gid,
-                               const char *original_dn);
+                               const char *original_dn, bool posix);
 
 /* Add netgroup (only basic attrs and w/o checks) */
 int sysdb_add_basic_netgroup(struct sysdb_ctx *ctx,
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index 1fb389da9db50020098d696200acac26905f3095..a7911de4e7705707730c1bf42cec67ae5a019fc1 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -1062,6 +1062,7 @@ int sysdb_add_group(TALLOC_CTX *mem_ctx,
     uint32_t id;
     time_t now;
     int ret;
+    bool posix;
 
     if (domain->id_max != 0 && gid != 0 &&
         (gid < domain->id_min || gid > domain->id_max)) {
@@ -1110,30 +1111,31 @@ int sysdb_add_group(TALLOC_CTX *mem_ctx,
     ret = sysdb_add_basic_group(tmpctx, ctx, domain, name, gid);
     if (ret) goto done;
 
-    if (gid == 0) {
-        ret = sysdb_get_new_id(tmpctx, ctx, domain, &id);
-        if (ret) goto done;
-
+    if (!attrs) {
+        attrs = sysdb_new_attrs(tmpctx);
         if (!attrs) {
-            attrs = sysdb_new_attrs(tmpctx);
-            if (!attrs) {
-                ret = ENOMEM;
-                goto done;
-            }
+            ret = ENOMEM;
+            goto done;
         }
+    }
+
+    ret = sysdb_attrs_get_bool(attrs, SYSDB_POSIX, &posix);
+    if (ret == ENOENT) {
+        posix = true;
+        ret = sysdb_attrs_add_bool(attrs, SYSDB_POSIX, true);
+        if (ret) goto done;
+    } else if (ret != EOK) {
+        goto done;
+    }
+
+    if (posix && gid == 0) {
+        ret = sysdb_get_new_id(tmpctx, ctx, domain, &id);
+        if (ret) goto done;
 
         ret = sysdb_attrs_add_uint32(attrs, SYSDB_GIDNUM, id);
         if (ret) goto done;
     }
 
-    if (!attrs) {
-        attrs = sysdb_new_attrs(tmpctx);
-        if (!attrs) {
-            ret = ENOMEM;
-            goto done;
-        }
-    }
-
     now = time(NULL);
 
     ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now);
@@ -1163,7 +1165,8 @@ int sysdb_add_incomplete_group(struct sysdb_ctx *ctx,
                                struct sss_domain_info *domain,
                                const char *name,
                                gid_t gid,
-                               const char *original_dn)
+                               const char *original_dn,
+                               bool posix)
 {
     TALLOC_CTX *tmpctx;
     time_t now;
@@ -1194,6 +1197,9 @@ int sysdb_add_incomplete_group(struct sysdb_ctx *ctx,
                                  now-1);
     if (ret) goto done;
 
+    ret = sysdb_attrs_add_bool(attrs, SYSDB_POSIX, posix);
+    if (ret) goto done;
+
     if (original_dn) {
         ret = sysdb_attrs_add_string(attrs, SYSDB_ORIG_DN, original_dn);
         if (ret) goto done;
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index 03faa289bd6d1abc4e76b0947bb8beaf9d00d3f8..d0f7ab424eabdebff2071df71ad268c8a16a955b 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -268,7 +268,7 @@ static int test_add_incomplete_group(struct test_data *data)
     int ret;
 
     ret = sysdb_add_incomplete_group(data->ctx->sysdb, data->ctx->domain,
-                                     data->groupname, data->gid, NULL);
+                                     data->groupname, data->gid, NULL, true);
     return ret;
 }
 
@@ -2743,7 +2743,7 @@ START_TEST(test_odd_characters)
 
     /* Add */
     ret = sysdb_add_incomplete_group(test_ctx->sysdb, test_ctx->domain,
-                                     odd_groupname, 20000, NULL);
+                                     odd_groupname, 20000, NULL, true);
     fail_unless(ret == EOK, "sysdb_add_incomplete_group error [%d][%s]",
                             ret, strerror(ret));
 
@@ -2913,13 +2913,15 @@ START_TEST(test_sysdb_original_dn_case_insensitive)
 
     ret = sysdb_add_incomplete_group(test_ctx->sysdb, test_ctx->domain,
                                      "case_sensitive_group1", 29000,
-                                     "cn=case_sensitive_group1,cn=example,cn=com");
+                                     "cn=case_sensitive_group1,cn=example,cn=com",
+                                     true);
     fail_unless(ret == EOK, "sysdb_add_incomplete_group error [%d][%s]",
                             ret, strerror(ret));
 
     ret = sysdb_add_incomplete_group(test_ctx->sysdb, test_ctx->domain,
                                      "case_sensitive_group2", 29001,
-                                     "cn=CASE_SENSITIVE_GROUP1,cn=EXAMPLE,cn=COM");
+                                     "cn=CASE_SENSITIVE_GROUP1,cn=EXAMPLE,cn=COM",
+                                     true);
     fail_unless(ret == EOK, "sysdb_add_incomplete_group error [%d][%s]",
                             ret, strerror(ret));
 
-- 
1.7.4.1

