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) {
/* 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"));
/*
* 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;
"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);
map->status = ID_UNKNOWN;
return NT_STATUS_OK;
}
- if (q != NULL)
+ if ((q != NULL) && (*q != '\0'))
if (sscanf(q+1, "%"SCNu32, &domain_range_index) != 1) {
DEBUG(10, ("Domain range index not found, "
"ignoring mapping request\n"));
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)
{
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;
/*
* 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);
/* 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;
}
}
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"));
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)) {
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))) {
return NT_STATUS_IS_OK(status)?NT_STATUS_OK:NT_STATUS_UNSUCCESSFUL;
}
+static NTSTATUS idmap_autorid_initialize_action(struct db_context *db,
+ void *private_data)
+{
+ struct idmap_domain *dom;
+ struct idmap_tdb_common_context *common;
+ struct autorid_global_config *config;
+ NTSTATUS status;
+
+ dom = (struct idmap_domain *)private_data;
+ common = (struct idmap_tdb_common_context *)dom->private_data;
+ config = (struct autorid_global_config *)common->private_data;
+
+ status = idmap_autorid_init_hwms(db);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ status = idmap_autorid_saveconfig(db, config);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(1, ("Failed to store configuration data!\n"));
+ return status;
+ }
+
+ status = idmap_autorid_preallocate_wellknown(dom);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(1, ("Failed to preallocate wellknown sids: %s\n",
+ nt_errstr(status)));
+ return status;
+ }
+
+ return NT_STATUS_OK;
+}
+
static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
{
struct idmap_tdb_common_context *commonconfig;
DEBUG(0, ("Out of memory!\n"));
return NT_STATUS_NO_MEMORY;
}
+ dom->private_data = commonconfig;
commonconfig->rw_ops = talloc_zero(commonconfig, struct idmap_rw_ops);
if (commonconfig->rw_ops == NULL) {
DEBUG(0, ("Out of memory!\n"));
return NT_STATUS_NO_MEMORY;
}
-
- status = idmap_autorid_db_init(state_path("autorid.tdb"),
- NULL, /* TALLOC_CTX */
- &autorid_db);
- if (!NT_STATUS_IS_OK(status)) {
- goto error;
- }
+ commonconfig->private_data = config;
config->minvalue = dom->low_id;
config->rangesize = lp_parm_int(-1, "idmap config *",
config->rangesize;
if (config->maxranges == 0) {
- DEBUG(1, ("allowed uid range is smaller then rangesize, "
- "increase uid range or decrease rangesize\n"));
+ DEBUG(1, ("Allowed uid range is smaller than rangesize. "
+ "Increase uid range or decrease rangesize.\n"));
status = NT_STATUS_INVALID_PARAMETER;
goto error;
}
config->maxranges));
}
- status = idmap_autorid_saveconfig(autorid_db, config);
-
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(1, ("Failed to store configuration data!\n"));
- goto error;
- }
-
DEBUG(5, ("%d domain ranges with a size of %d are available\n",
config->maxranges, config->rangesize));
"ignore builtin", false);
/* fill the TDB common configuration */
- commonconfig->private_data = config;
- commonconfig->db = autorid_db;
commonconfig->max_id = config->rangesize -1;
commonconfig->hwmkey_uid = ALLOC_HWM_UID;
commonconfig->hwmkey_gid = ALLOC_HWM_GID;
commonconfig->rw_ops->get_new_id = idmap_autorid_allocate_id;
commonconfig->rw_ops->set_mapping = idmap_tdb_common_set_mapping;
- dom->private_data = commonconfig;
+ status = idmap_autorid_db_open(state_path("autorid.tdb"),
+ NULL, /* TALLOC_CTX */
+ &autorid_db);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto error;
+ }
- /* preallocate well-known SIDs in the pool */
- status = idmap_autorid_preallocate_wellknown(dom);
+ commonconfig->db = autorid_db;
+
+ status = dbwrap_trans_do(autorid_db,
+ idmap_autorid_initialize_action,
+ dom);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(1, ("Failed to init the idmap database: %s\n",
+ nt_errstr(status)));
+ goto error;
+ }
goto done;
.allocate_id = idmap_autorid_allocate_id
};
-NTSTATUS samba_init_module(void)
+NTSTATUS idmap_autorid_init(void)
{
return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION,
"autorid", &autorid_methods);