*id_to_*id call reshape to return NTSTATUS errors
[ira/wip.git] / source3 / sam / idmap_tdb.c
index f85d2db0864c7e0168032d0404d6eebe41b19dde..ab86eaf4ebf76c6f06522b15dbc76f1c126eb231 100644 (file)
@@ -213,7 +213,7 @@ idok:
 
 static NTSTATUS db_set_mapping(const DOM_SID *sid, unid_t id, int id_type)
 {
 
 static NTSTATUS db_set_mapping(const DOM_SID *sid, unid_t id, int id_type)
 {
-       TDB_DATA ksid, kid;
+       TDB_DATA ksid, kid, data;
        fstring ksidstr;
        fstring kidstr;
 
        fstring ksidstr;
        fstring kidstr;
 
@@ -235,6 +235,20 @@ static NTSTATUS db_set_mapping(const DOM_SID *sid, unid_t id, int id_type)
        kid.dptr = kidstr;
        kid.dsize = strlen(kidstr) + 1;
 
        kid.dptr = kidstr;
        kid.dsize = strlen(kidstr) + 1;
 
+       /* *DELETE* prevoius mappings if any.
+        * This is done both SID and [U|G]ID passed in */
+       
+       data = tdb_fetch(idmap_tdb, ksid);
+       if (data.dptr) {
+               tdb_delete(idmap_tdb, data);
+               tdb_delete(idmap_tdb, ksid);
+       }
+       data = tdb_fetch(idmap_tdb, kid);
+       if (data.dptr) {
+               tdb_delete(idmap_tdb, data);
+               tdb_delete(idmap_tdb, kid);
+       }
+
        if (tdb_store(idmap_tdb, ksid, kid, TDB_INSERT) == -1) {
                DEBUG(0, ("idb_set_mapping: tdb_store 1 error: %s\n", tdb_errorstr(idmap_tdb)));
                return NT_STATUS_UNSUCCESSFUL;
        if (tdb_store(idmap_tdb, ksid, kid, TDB_INSERT) == -1) {
                DEBUG(0, ("idb_set_mapping: tdb_store 1 error: %s\n", tdb_errorstr(idmap_tdb)));
                return NT_STATUS_UNSUCCESSFUL;
@@ -427,4 +441,3 @@ NTSTATUS idmap_reg_tdb(struct idmap_methods **meth)
 
        return NT_STATUS_OK;
 }
 
        return NT_STATUS_OK;
 }
-