autorid: explicitly return NTSTATUS_OK in idmap_autorid_sid_to_id_alloc().
[obnox/samba/samba-obnox.git] / source3 / winbindd / idmap_autorid.c
index 7e17b6634e06e5bde146374e213bbafac4f4b93c..0bdc96dd477a90c64bc93549d3493fdec0af9a0f 100644 (file)
@@ -87,6 +87,22 @@ static struct db_context *autorid_db;
 
 static bool ignore_builtin = false;
 
+static NTSTATUS idmap_autorid_get_alloc_range(struct idmap_domain *dom,
+                                       struct autorid_range_config *range)
+{
+       NTSTATUS status;
+
+       ZERO_STRUCT(*range);
+
+       fstrcpy(range->domsid, ALLOC_RANGE);
+
+       status = idmap_autorid_get_domainrange(autorid_db,
+                                              range,
+                                              dom->read_only);
+
+       return status;
+}
+
 static NTSTATUS idmap_autorid_allocate_id(struct idmap_domain *dom,
                                          struct unixid *xid) {
 
@@ -101,12 +117,7 @@ static NTSTATUS idmap_autorid_allocate_id(struct idmap_domain *dom,
 
        /* fetch the range for the allocation pool */
 
-       ZERO_STRUCT(range);
-
-       fstrcpy(range.domsid, ALLOC_RANGE);
-
-       ret = idmap_autorid_get_domainrange(autorid_db, &range, dom->read_only);
-
+       ret = idmap_autorid_get_alloc_range(dom, &range);
        if (!NT_STATUS_IS_OK(ret)) {
                DEBUG(3, ("Could not determine range for allocation pool, "
                          "check previous messages for reason\n"));
@@ -131,8 +142,8 @@ static NTSTATUS idmap_autorid_allocate_id(struct idmap_domain *dom,
 /*
  * map a SID to xid using the idmap_tdb like pool
  */
-static NTSTATUS idmap_autorid_map_id_to_sid(struct idmap_domain *dom,
-                                           struct id_map *map)
+static NTSTATUS idmap_autorid_id_to_sid_alloc(struct idmap_domain *dom,
+                                             struct id_map *map)
 {
        NTSTATUS ret;
 
@@ -214,7 +225,7 @@ static NTSTATUS idmap_autorid_id_to_sid(struct autorid_global_config *cfg,
                          "checking for mapping\n",
                          map->xid.id));
                TALLOC_FREE(data.dptr);
-               return idmap_autorid_map_id_to_sid(dom, map);
+               return idmap_autorid_id_to_sid_alloc(dom, map);
        }
 
        ok = dom_sid_parse_endp((const char *)data.dptr, &domsid, &q);
@@ -250,7 +261,8 @@ static NTSTATUS idmap_autorid_id_to_sid(struct autorid_global_config *cfg,
  Single sid to id lookup function.
 **********************************/
 
-static NTSTATUS idmap_autorid_sid_to_id(struct autorid_global_config *global,
+static NTSTATUS idmap_autorid_sid_to_id_rid(
+                                       struct autorid_global_config *global,
                                        struct autorid_range_config *range,
                                        struct id_map *map)
 {
@@ -263,11 +275,6 @@ static NTSTATUS idmap_autorid_sid_to_id(struct autorid_global_config *global,
 
        map->xid.id = reduced_rid + range->low_id;
        map->xid.type = ID_TYPE_BOTH;
-
-       /* We **really** should have some way of validating
-          the SID exists and is the correct type here.  But
-          that is a deficiency in the idmap_rid design. */
-
        map->status = ID_MAPPED;
 
        return NT_STATUS_OK;
@@ -334,13 +341,15 @@ static NTSTATUS idmap_autorid_unixids_to_sids(struct idmap_domain *dom,
 /*
  * map a SID to xid using the idmap_tdb like pool
  */
-static NTSTATUS idmap_autorid_map_sid_to_id(struct idmap_domain *dom,
-                                           struct id_map *map,
-                                           struct idmap_tdb_common_context *ctx)
+static NTSTATUS idmap_autorid_sid_to_id_alloc(struct idmap_domain *dom,
+                                       struct id_map *map,
+                                       struct idmap_tdb_common_context *ctx)
 {
        NTSTATUS ret;
        int res;
 
+       map->status = ID_UNKNOWN;
+
        /* see if we already have a mapping */
        ret = idmap_tdb_common_sid_to_unixid(dom, map);
 
@@ -351,14 +360,15 @@ static NTSTATUS idmap_autorid_map_sid_to_id(struct idmap_domain *dom,
 
        /* bad things happened */
        if (!NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED)) {
-               DEBUG(1, ("Looking up SID->ID mapping for %s failed\n",
-                         sid_string_dbg(map->sid)));
+               DEBUG(1, ("Looking up SID->ID mapping for %s failed: %s\n",
+                         sid_string_dbg(map->sid), nt_errstr(ret)));
                return ret;
        }
 
        if (dom->read_only) {
                DEBUG(3, ("Not allocating new mapping for %s, because backend "
                          "is read-only\n", sid_string_dbg(map->sid)));
+               map->status = ID_UNMAPPED;
                return NT_STATUS_NONE_MAPPED;
        }
 
@@ -373,19 +383,18 @@ static NTSTATUS idmap_autorid_map_sid_to_id(struct idmap_domain *dom,
        }
 
        ret = idmap_tdb_common_new_mapping(dom, map);
-
-       map->status = (NT_STATUS_IS_OK(ret))?ID_MAPPED:ID_UNMAPPED;
-
        if (!NT_STATUS_IS_OK(ret)) {
                if (dbwrap_transaction_cancel(ctx->db) != 0) {
                        smb_panic("Cancelling transaction failed");
                }
+               map->status = ID_UNMAPPED;
                return ret;
        }
 
        res = dbwrap_transaction_commit(ctx->db);
        if (res == 0) {
-               return ret;
+               map->status = ID_MAPPED;
+               return NT_STATUS_OK;
        }
 
        DEBUG(2, ("transaction_commit failed\n"));
@@ -445,8 +454,8 @@ static NTSTATUS idmap_autorid_sids_to_unixids(struct idmap_domain *dom,
                        DEBUG(10, ("SID %s is well-known, using pool\n",
                                   sid_string_dbg(ids[i]->sid)));
 
-                       ret = idmap_autorid_map_sid_to_id(dom, ids[i],
-                                                         commoncfg);
+                       ret = idmap_autorid_sid_to_id_alloc(dom, ids[i],
+                                                           commoncfg);
 
                        if (!NT_STATUS_IS_OK(ret) &&
                            !NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED)) {
@@ -505,7 +514,7 @@ static NTSTATUS idmap_autorid_sids_to_unixids(struct idmap_domain *dom,
                        goto failure;
                }
 
-               ret = idmap_autorid_sid_to_id(global, &range, ids[i]);
+               ret = idmap_autorid_sid_to_id_rid(global, &range, ids[i]);
 
                if ((!NT_STATUS_IS_OK(ret)) &&
                    (!NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED))) {
@@ -592,12 +601,12 @@ static NTSTATUS idmap_autorid_initialize_action(struct db_context *db,
        common = (struct idmap_tdb_common_context *)dom->private_data;
        config = (struct autorid_global_config *)common->private_data;
 
-       status = idmap_autorid_init_hwms(autorid_db);
+       status = idmap_autorid_init_hwms(db);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
 
-       status = idmap_autorid_saveconfig(autorid_db, config);
+       status = idmap_autorid_saveconfig(db, config);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(1, ("Failed to store configuration data!\n"));
                return status;