summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/sam/idmap_tdb.c44
-rw-r--r--source3/sam/idmap_util.c10
2 files changed, 22 insertions, 32 deletions
diff --git a/source3/sam/idmap_tdb.c b/source3/sam/idmap_tdb.c
index d494759a2b..1f53321c9b 100644
--- a/source3/sam/idmap_tdb.c
+++ b/source3/sam/idmap_tdb.c
@@ -404,29 +404,19 @@ static NTSTATUS db_idmap_init( char *params )
BOOL tdb_is_new = False;
/* use the old database if present */
- if (!file_exist(lock_path("idmap.tdb"), &stbuf)) {
- if (file_exist(lock_path("winbindd_idmap.tdb"), &stbuf)) {
- DEBUG(0, ("idmap_init: using winbindd_idmap.tdb file!\n"));
- tdbfile = strdup(lock_path("winbindd_idmap.tdb"));
- if (!tdbfile) {
- DEBUG(0, ("idmap_init: out of memory!\n"));
- return NT_STATUS_NO_MEMORY;
- }
- } else {
- tdb_is_new = True;
- }
- }
+ tdbfile = strdup(lock_path("winbindd_idmap.tdb"));
if (!tdbfile) {
- tdbfile = strdup(lock_path("idmap.tdb"));
- if (!tdbfile) {
- DEBUG(0, ("idmap_init: out of memory!\n"));
- return NT_STATUS_NO_MEMORY;
- }
+ DEBUG(0, ("idmap_init: out of memory!\n"));
+ return NT_STATUS_NO_MEMORY;
}
- DEBUG(10,("db_idmap_init: Opening tdbfile\n", tdbfile ));
+ if (!file_exist(tdbfile, &stbuf)) {
+ tdb_is_new = True;
+ }
+
+ DEBUG(10,("db_idmap_init: Opening tdbfile\n", tdbfile ));
- /* Open tdb cache */
+ /* Open idmap repository */
if (!(idmap_tdb = tdb_open_log(tdbfile, 0,
TDB_DEFAULT, O_RDWR | O_CREAT,
0644))) {
@@ -438,12 +428,16 @@ static NTSTATUS db_idmap_init( char *params )
SAFE_FREE(tdbfile);
/* check against earlier versions */
- if (tdb_is_new) {
- /* TODO: delete the file if this fail */
- tdb_store_int32(idmap_tdb, "IDMAP_VERSION", IDMAP_VERSION);
- } else {
- version = tdb_fetch_int32(idmap_tdb, "IDMAP_VERSION");
- if (version != IDMAP_VERSION) {
+ version = tdb_fetch_int32(idmap_tdb, "IDMAP_VERSION");
+ if (version != IDMAP_VERSION) {
+ if (tdb_is_new) {
+ /* the file didn't existed before opening it, let's
+ * store idmap version as nobody else yet opened and
+ * stored it. I do not like this method but didn't
+ * found a way to understand if an opened tdb have
+ * been just created or not --- SSS */
+ tdb_store_int32(idmap_tdb, "IDMAP_VERSION", IDMAP_VERSION);
+ } else {
DEBUG(0, ("idmap_init: Unable to open idmap database, it's in an old format!\n"));
return NT_STATUS_INTERNAL_DB_ERROR;
}
diff --git a/source3/sam/idmap_util.c b/source3/sam/idmap_util.c
index 7d7e716397..21f827bb9e 100644
--- a/source3/sam/idmap_util.c
+++ b/source3/sam/idmap_util.c
@@ -226,12 +226,11 @@ NTSTATUS sid_to_uid(const DOM_SID *sid, uid_t *uid)
}
}
- if (NT_STATUS_IS_OK(idmap_get_id_from_sid(&id, &flags, sid))) {
+ if (NT_STATUS_IS_OK(ret = idmap_get_id_from_sid(&id, &flags, sid))) {
DEBUG(10,("sid_to_uid: uid = [%d]\n", id.uid));
*uid = id.uid;
- ret = NT_STATUS_OK;
} else if (fallback) {
uint32 rid;
@@ -284,19 +283,17 @@ NTSTATUS sid_to_gid(const DOM_SID *sid, gid_t *gid)
}
}
- if (NT_STATUS_IS_OK(idmap_get_id_from_sid(&id, &flags, sid))) {
+ if (NT_STATUS_IS_OK(ret = idmap_get_id_from_sid(&id, &flags, sid))) {
DEBUG(10,("sid_to_gid: gid = [%d]\n", id.gid));
*gid = id.gid;
- ret = NT_STATUS_OK;
} else if (fallback) {
uint32 rid;
if (!sid_peek_rid(sid, &rid)) {
DEBUG(10,("sid_to_uid: invalid SID!\n"));
- ret = NT_STATUS_INVALID_PARAMETER;
- goto done;
+ return NT_STATUS_INVALID_PARAMETER;
}
DEBUG(10,("sid_to_gid: Fall back to algorithmic mapping\n"));
@@ -311,7 +308,6 @@ NTSTATUS sid_to_gid(const DOM_SID *sid, gid_t *gid)
}
}
-done:
return ret;
}