The branch, v4-0-test has been updated
       via  73ac7c4a1ce937bddd3c52d048665cd0078c6aaa (commit)
       via  f56912e3b545325e941ee898337c5483ec435e39 (commit)
      from  3f2d12c61e95475009baf77c3e0fbea2abecc17a (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v4-0-test


- Log -----------------------------------------------------------------
commit 73ac7c4a1ce937bddd3c52d048665cd0078c6aaa
Author: Kai Blin <[EMAIL PROTECTED]>
Date:   Thu Mar 6 00:52:37 2008 +0100

    idmap: Map SIDs to unixids instead of uids/gids

commit f56912e3b545325e941ee898337c5483ec435e39
Author: Kai Blin <[EMAIL PROTECTED]>
Date:   Tue Mar 18 10:53:25 2008 +0100

    make: Fix make valgrindtest-env

-----------------------------------------------------------------------

Summary of changes:
 source/script/valgrind_run                      |    4 +-
 source/winbind/config.mk                        |    2 +
 source/winbind/idmap.c                          |  722 ++++++-----------------
 source/winbind/idmap.h                          |   20 +
 source/winbind/wb_gid2sid.c                     |   47 ++-
 source/winbind/wb_sid2gid.c                     |   48 ++-
 source/winbind/wb_sid2uid.c                     |   50 ++-
 source/winbind/{wb_gid2sid.c => wb_sids2xids.c} |   43 +-
 source/winbind/wb_uid2sid.c                     |   49 ++-
 source/winbind/{wb_gid2sid.c => wb_xids2sids.c} |   43 +-
 10 files changed, 400 insertions(+), 628 deletions(-)
 copy source/winbind/{wb_gid2sid.c => wb_sids2xids.c} (63%)
 copy source/winbind/{wb_gid2sid.c => wb_xids2sids.c} (63%)


Changeset truncated at 500 lines:

diff --git a/source/script/valgrind_run b/source/script/valgrind_run
index 45361c2..5171d17 100755
--- a/source/script/valgrind_run
+++ b/source/script/valgrind_run
@@ -4,4 +4,6 @@ ENV="$1"
 
 shift 1
 
-$ENV valgrind -q --db-attach=yes --num-callers=30 $@
+CMD="$ENV valgrind -q --db-attach=yes --num-callers=30 $@"
+echo $CMD
+eval $CMD
diff --git a/source/winbind/config.mk b/source/winbind/config.mk
index 2567d61..8c9b3f1 100644
--- a/source/winbind/config.mk
+++ b/source/winbind/config.mk
@@ -16,6 +16,8 @@ OBJ_FILES = \
                wb_dom_info_trusted.o \
                wb_sid2domain.o \
                wb_name2domain.o \
+               wb_sids2xids.o \
+               wb_xids2sids.o \
                wb_gid2sid.o \
                wb_sid2uid.o \
                wb_sid2gid.o \
diff --git a/source/winbind/idmap.c b/source/winbind/idmap.c
index 3372ad5..de8a43e 100644
--- a/source/winbind/idmap.c
+++ b/source/winbind/idmap.c
@@ -1,7 +1,7 @@
 /*
    Unix SMB/CIFS implementation.
 
-   Map SIDs to uids/gids and back
+   Map SIDs to unixids and back
 
    Copyright (C) Kai Blin 2008
 
@@ -177,39 +177,46 @@ struct idmap_context *idmap_init(TALLOC_CTX *mem_ctx,
                return NULL;
        }
 
+       idmap_ctx->unix_groups_sid = dom_sid_parse_talloc(mem_ctx, "S-1-22-2");
+       if (idmap_ctx->unix_groups_sid == NULL) {
+               return NULL;
+       }
+
+       idmap_ctx->unix_users_sid = dom_sid_parse_talloc(mem_ctx, "S-1-22-1");
+       if (idmap_ctx->unix_users_sid == NULL) {
+               return NULL;
+       }
+
        return idmap_ctx;
 }
 
 /**
- * Convert a uid to the corresponding SID
+ * Convert an unixid to the corresponding SID
  *
  * \param idmap_ctx idmap context to use
  * \param mem_ctx talloc context the memory for the struct dom_sid is allocated
  * from.
- * \param uid Unix uid to map to a SID
- * \param sid Pointer that will take the struct dom_sid pointer if the mapping
+ * \param unixid pointer to a unixid struct to convert
+ * \param sid pointer that will take the struct dom_sid pointer if the mapping
  * succeeds.
  * \return NT_STATUS_OK on success, NT_STATUS_NONE_MAPPED if mapping not
  * possible or some other NTSTATUS that is more descriptive on failure.
  */
 
-NTSTATUS idmap_uid_to_sid(struct idmap_context *idmap_ctx, TALLOC_CTX *mem_ctx,
-               const uid_t uid, struct dom_sid **sid)
+NTSTATUS idmap_xid_to_sid(struct idmap_context *idmap_ctx, TALLOC_CTX *mem_ctx,
+               const struct unixid *unixid, struct dom_sid **sid)
 {
        int ret;
        NTSTATUS status = NT_STATUS_NONE_MAPPED;
        struct ldb_context *ldb = idmap_ctx->ldb_ctx;
-       struct ldb_message *msg;
        struct ldb_result *res = NULL;
-       int trans = -1;
-       uid_t low, high;
-       char *sid_string, *uid_string;
-       struct dom_sid *unix_users_sid, *new_sid;
+       uint32_t low, high;
+       struct dom_sid *unix_sid, *new_sid;
        TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
 
        ret = ldb_search_exp_fmt(ldb, tmp_ctx, &res, NULL, LDB_SCOPE_SUBTREE,
-                                NULL, "(&(objectClass=sidMap)(uidNumber=%u))",
-                                uid);
+                                NULL, "(&(objectClass=sidMap)(xidNumber=%u))",
+                                unixid->id);
        if (ret != LDB_SUCCESS) {
                DEBUG(1, ("Search failed: %s\n", ldb_errstring(ldb)));
                status = NT_STATUS_NONE_MAPPED;
@@ -228,19 +235,13 @@ NTSTATUS idmap_uid_to_sid(struct idmap_context 
*idmap_ctx, TALLOC_CTX *mem_ctx,
                return NT_STATUS_OK;
        }
 
-       DEBUG(6, ("uid not found in idmap db, trying to allocate SID.\n"));
-
-       trans = ldb_transaction_start(ldb);
-       if (trans != LDB_SUCCESS) {
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
+       DEBUG(6, ("xid not found in idmap db, trying to allocate SID.\n"));
 
        /* Now redo the search to make sure noone added a mapping for that SID
         * while we weren't looking.*/
        ret = ldb_search_exp_fmt(ldb, tmp_ctx, &res, NULL, LDB_SCOPE_SUBTREE,
-                                NULL, "(&(objectClass=sidMap)(uidNumber=%u))",
-                                uid);
+                                NULL, "(&(objectClass=sidMap)(xidNumber=%u))",
+                                unixid->id);
        if (ret != LDB_SUCCESS) {
                DEBUG(1, ("Search failed: %s\n", ldb_errstring(ldb)));
                status = NT_STATUS_NONE_MAPPED;
@@ -260,285 +261,58 @@ NTSTATUS idmap_uid_to_sid(struct idmap_context 
*idmap_ctx, TALLOC_CTX *mem_ctx,
                goto failed;
        }
 
-       if (uid >= low && uid <= high) {
-               /* An existing user would have been mapped before */
-               status = NT_STATUS_NO_SUCH_USER;
+       if (unixid->id >= low && unixid->id <= high) {
+               /* An existing xid would have been mapped before */
+               status = NT_STATUS_NONE_MAPPED;
                goto failed;
        }
 
        /* For local users, we just create a rid = uid +1, so root doesn't end
         * up with a 0 rid */
-       unix_users_sid = dom_sid_parse_talloc(tmp_ctx, "S-1-22-1");
-       if (unix_users_sid == NULL) {
-               status = NT_STATUS_NO_MEMORY;
-               goto failed;
-       }
-
-       new_sid = dom_sid_add_rid(mem_ctx, unix_users_sid, uid + 1);
-       if (new_sid == NULL) {
-               status = NT_STATUS_NO_MEMORY;
-               goto failed;
-       }
-
-       sid_string = dom_sid_string(tmp_ctx, new_sid);
-       if (sid_string == NULL) {
-               status = NT_STATUS_NO_MEMORY;
-               goto failed;
-       }
-
-       uid_string = talloc_asprintf(tmp_ctx, "%u", uid);
-       if (uid_string == NULL) {
-               status = NT_STATUS_NO_MEMORY;
-               goto failed;
-       }
-
-       msg = ldb_msg_new(tmp_ctx);
-       if (msg == NULL) {
-               status = NT_STATUS_NO_MEMORY;
-               goto failed;
-       }
-
-       msg->dn = ldb_dn_new_fmt(tmp_ctx, ldb, "CN=%s", sid_string);
-       if (msg->dn == NULL) {
-               status = NT_STATUS_NO_MEMORY;
-               goto failed;
-       }
-
-       ret = ldb_msg_add_string(msg, "uidNumber", uid_string);
-       if (ret != LDB_SUCCESS) {
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
-       ret = idmap_msg_add_dom_sid(idmap_ctx, tmp_ctx, msg, "objectSid",
-                                   new_sid);
-       if (ret != LDB_SUCCESS) {
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
-       ret = ldb_msg_add_string(msg, "objectClass", "sidMap");
-       if (ret != LDB_SUCCESS) {
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
-       ret = ldb_msg_add_string(msg, "cn", sid_string);
-       if (ret != LDB_SUCCESS) {
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
-       ret = ldb_add(ldb, msg);
-       if (ret != LDB_SUCCESS) {
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
-       trans = ldb_transaction_commit(ldb);
-       if (trans != LDB_SUCCESS) {
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
-       *sid = new_sid;
-       talloc_free(tmp_ctx);
-       return NT_STATUS_OK;
-
-failed:
-       if (trans == LDB_SUCCESS) ldb_transaction_cancel(ldb);
-       talloc_free(tmp_ctx);
-       return status;
-}
-
-/**
- * Map a Unix gid to the corresponding SID
- *
- * \param idmap_ctx idmap context to use
- * \param mem_ctx talloc context the memory for the struct dom_sid is allocated
- * from.
- * \param gid Unix gid to map to a SID
- * \param sid Pointer that will take the struct dom_sid pointer if mapping
- * succeeds.
- * \return NT_STATUS_OK on success, NT_STATUS_NONE_MAPPED if mapping not
- * possible or some other NTSTATUS that is more descriptive on failure.
- */
-NTSTATUS idmap_gid_to_sid(struct idmap_context *idmap_ctx, TALLOC_CTX *mem_ctx,
-               const gid_t gid, struct dom_sid **sid)
-{
-       int ret;
-       NTSTATUS status = NT_STATUS_NONE_MAPPED;
-       struct ldb_context *ldb = idmap_ctx->ldb_ctx;
-       struct ldb_message *msg;
-       struct ldb_result *res = NULL;
-       int trans = -1;
-       gid_t low, high;
-       char *sid_string, *gid_string;
-       struct dom_sid *unix_groups_sid, *new_sid;
-       TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
-
-       ret = ldb_search_exp_fmt(ldb, tmp_ctx, &res, NULL, LDB_SCOPE_SUBTREE,
-                       NULL, "(&(objectClass=sidMap)(gidNumber=%u))", gid);
-       if (ret != LDB_SUCCESS) {
-               DEBUG(1, ("Search failed: %s\n", ldb_errstring(ldb)));
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
-       if (res->count == 1) {
-               *sid = idmap_msg_get_dom_sid(mem_ctx, res->msgs[0],
-                               "objectSid");
-               if (*sid == NULL) {
-                       DEBUG(1, ("Failed to get sid from db: %u\n", ret));
-                       status = NT_STATUS_NONE_MAPPED;
-                       goto failed;
-               }
-               /* No change, so cancel the transaction */
-               ldb_transaction_cancel(ldb);
-               talloc_free(tmp_ctx);
-               return NT_STATUS_OK;
-       }
-
-       DEBUG(6, ("gid not found in idmap db, trying to allocate SID.\n"));
-
-       trans = ldb_transaction_start(ldb);
-       if (trans != LDB_SUCCESS) {
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
-       /* Now redo the search to make sure noone added a mapping for that SID
-        * while we weren't looking.*/
-       ret = ldb_search_exp_fmt(ldb, tmp_ctx, &res, NULL, LDB_SCOPE_SUBTREE,
-                                NULL, "(&(objectClass=sidMap)(gidNumber=%u))",
-                                gid);
-       if (ret != LDB_SUCCESS) {
-               DEBUG(1, ("Search failed: %s\n", ldb_errstring(ldb)));
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
-       if (res->count > 0) {
-               DEBUG(1, ("sidMap modified while trying to add a mapping.\n"));
-               status = NT_STATUS_RETRY;
-               goto failed;
-       }
-
-       ret = idmap_get_bounds(idmap_ctx, &low, &high);
-       if (ret != LDB_SUCCESS) {
-               DEBUG(1, ("Failed to get id bounds from db: %u\n", ret));
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
-       if (gid >= low && gid <= high) {
-               /* An existing group would have been mapped before */
-               status = NT_STATUS_NO_SUCH_USER;
-               goto failed;
+       if (unixid->type == ID_TYPE_UID) {
+               unix_sid = dom_sid_parse_talloc(tmp_ctx, "S-1-22-1");
+       } else {
+               unix_sid = dom_sid_parse_talloc(tmp_ctx, "S-1-22-2");
        }
-
-       /* For local groups, we just create a rid = gid +1, so root doesn't end
-        * up with a 0 rid */
-       unix_groups_sid = dom_sid_parse_talloc(tmp_ctx, "S-1-22-2");
-       if (unix_groups_sid == NULL) {
+       if (unix_sid == NULL) {
                status = NT_STATUS_NO_MEMORY;
                goto failed;
        }
 
-       new_sid = dom_sid_add_rid(mem_ctx, unix_groups_sid, gid + 1);
+       new_sid = dom_sid_add_rid(mem_ctx, unix_sid, unixid->id + 1);
        if (new_sid == NULL) {
                status = NT_STATUS_NO_MEMORY;
                goto failed;
        }
 
-       sid_string = dom_sid_string(tmp_ctx, new_sid);
-       if (sid_string == NULL) {
-               status = NT_STATUS_NO_MEMORY;
-               goto failed;
-       }
-
-       gid_string = talloc_asprintf(tmp_ctx, "%u", gid);
-       if (gid_string == NULL) {
-               status = NT_STATUS_NO_MEMORY;
-               goto failed;
-       }
-
-       msg = ldb_msg_new(tmp_ctx);
-       if (msg == NULL) {
-               status = NT_STATUS_NO_MEMORY;
-               goto failed;
-       }
-
-       msg->dn = ldb_dn_new_fmt(tmp_ctx, ldb, "CN=%s", sid_string);
-       if (msg->dn == NULL) {
-               status = NT_STATUS_NO_MEMORY;
-               goto failed;
-       }
-
-       ret = ldb_msg_add_string(msg, "gidNumber", gid_string);
-       if (ret != LDB_SUCCESS) {
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
-       ret = idmap_msg_add_dom_sid(idmap_ctx, tmp_ctx, msg, "objectSid",
-                       new_sid);
-       if (ret != LDB_SUCCESS) {
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
-       ret = ldb_msg_add_string(msg, "objectClass", "sidMap");
-       if (ret != LDB_SUCCESS) {
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
-       ret = ldb_msg_add_string(msg, "cn", sid_string);
-       if (ret != LDB_SUCCESS) {
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
-       ret = ldb_add(ldb, msg);
-       if (ret != LDB_SUCCESS) {
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
-       trans = ldb_transaction_commit(ldb);
-       if (trans != LDB_SUCCESS) {
-               status = NT_STATUS_NONE_MAPPED;
-               goto failed;
-       }
-
        *sid = new_sid;
        talloc_free(tmp_ctx);
        return NT_STATUS_OK;
 
 failed:
-       if (trans == LDB_SUCCESS) ldb_transaction_cancel(ldb);
        talloc_free(tmp_ctx);
        return status;
 }
 
+
 /**
- * Map a SID to a Unix uid.
+ * Map a SID to an unixid struct.
  *
  * If no mapping exists, a new mapping will be created.
  *
  * \todo Check if SIDs can be resolved if lp_idmap_trusted_only() == true
+ * \todo Fix backwards compatibility for Samba3
  *
  * \param idmap_ctx idmap context to use
  * \param mem_ctx talloc context to use
- * \param sid SID to map to a Unix uid
- * \param uid pointer to receive the mapped uid
+ * \param sid SID to map to an unixid struct
+ * \param unixid pointer to a unixid struct pointer
  * \return NT_STATUS_OK on success, NT_STATUS_INVALID_SID if the sid is not 
from
  * a trusted domain and idmap trusted only = true, NT_STATUS_NONE_MAPPED if the
  * mapping failed.
  */
-NTSTATUS idmap_sid_to_uid(struct idmap_context *idmap_ctx, TALLOC_CTX *mem_ctx,
-               const struct dom_sid *sid, uid_t *uid)
+NTSTATUS idmap_sid_to_xid(struct idmap_context *idmap_ctx, TALLOC_CTX *mem_ctx,
+               const struct dom_sid *sid, struct unixid **unixid)
 {
        int ret;
        NTSTATUS status = NT_STATUS_NONE_MAPPED;
@@ -547,8 +321,8 @@ NTSTATUS idmap_sid_to_uid(struct idmap_context *idmap_ctx, 
TALLOC_CTX *mem_ctx,
        struct ldb_message *hwm_msg, *map_msg;
        struct ldb_result *res = NULL;
        int trans;
-       uid_t low, high, hwm, new_uid;
-       char *sid_string, *uid_string, *hwm_string;
+       uint32_t low, high, hwm, new_xid;
+       char *sid_string, *unixid_string, *hwm_string;
        bool hwm_entry_exists;
        TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
 
@@ -562,20 +336,65 @@ NTSTATUS idmap_sid_to_uid(struct idmap_context 
*idmap_ctx, TALLOC_CTX *mem_ctx,
        }
 
        if (res->count == 1) {
-               new_uid = ldb_msg_find_attr_as_uint(res->msgs[0], "uidNumber",
+               new_xid = ldb_msg_find_attr_as_uint(res->msgs[0], "xidNumber",
                                                    -1);
-               if (new_uid == (uid_t) -1) {
-                       DEBUG(1, ("Invalid uid mapping.\n"));
+               if (new_xid == (uint32_t) -1) {
+                       DEBUG(1, ("Invalid xid mapping.\n"));
                        status = NT_STATUS_NONE_MAPPED;
                        goto failed;
                }
-               *uid = new_uid;
+
+               *unixid = talloc(mem_ctx, struct unixid);
+               if (*unixid == NULL) {
+                       status = NT_STATUS_NO_MEMORY;
+                       goto failed;
+               }
+
+               (*unixid)->id = new_xid;
+               (*unixid)->type = ID_TYPE_BOTH;
+
                talloc_free(tmp_ctx);
                return NT_STATUS_OK;
        }
 
        DEBUG(6, ("No existing mapping found, attempting to create one.\n"));
 
+       if (dom_sid_in_domain(idmap_ctx->unix_users_sid, sid)) {
+               uint32_t rid;
+               DEBUG(6, ("This is a local unix uid, just calculate that.\n"));
+               status = dom_sid_split_rid(tmp_ctx, sid, NULL, &rid);
+               if (!NT_STATUS_IS_OK(status)) goto failed;
+
+               *unixid = talloc(mem_ctx, struct unixid);
+               if (*unixid == NULL) {
+                       status = NT_STATUS_NO_MEMORY;
+                       goto failed;
+               }
+               (*unixid)->id = rid - 1;
+               (*unixid)->type = ID_TYPE_UID;
+
+               talloc_free(tmp_ctx);
+               return NT_STATUS_OK;
+       }
+
+       if (dom_sid_in_domain(idmap_ctx->unix_groups_sid, sid)) {
+               uint32_t rid;
+               DEBUG(6, ("This is a local unix gid, just calculate that.\n"));
+               status = dom_sid_split_rid(tmp_ctx, sid, NULL, &rid);
+               if (!NT_STATUS_IS_OK(status)) goto failed;
+
+               *unixid = talloc(mem_ctx, struct unixid);
+               if (*unixid == NULL) {
+                       status = NT_STATUS_NO_MEMORY;
+                       goto failed;
+               }
+               (*unixid)->id = rid - 1;
+               (*unixid)->type = ID_TYPE_GID;
+
+               talloc_free(tmp_ctx);
+               return NT_STATUS_OK;
+        }
+


-- 
Samba Shared Repository

Reply via email to