2 * idmap_autorid: static map between Active Directory/NT RIDs
3 * and RFC 2307 accounts
5 * based on the idmap_rid module, but this module defines the ranges
6 * for the domains by automatically allocating a range for each domain
8 * Copyright (C) Christian Ambach, 2010-2012
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 #include "system/filesys.h"
28 #include "dbwrap/dbwrap.h"
29 #include "dbwrap/dbwrap_open.h"
32 #include "../libcli/security/dom_sid.h"
34 #include "winbindd/idmap_tdb_common.h"
37 #define DBGC_CLASS DBGC_IDMAP
39 #define HWM "NEXT RANGE"
40 #define ALLOC_HWM_UID "NEXT ALLOC UID"
41 #define ALLOC_HWM_GID "NEXT ALLOC GID"
42 #define ALLOC_RANGE "ALLOC"
43 #define CONFIGKEY "CONFIG"
45 struct autorid_global_config {
52 struct autorid_domain_config {
57 struct autorid_global_config *globalcfg;
60 /* handle to the tdb storing domain <-> range assignments */
61 static struct db_context *autorid_db;
63 static NTSTATUS idmap_autorid_get_domainrange_action(struct db_context *db,
67 uint32_t rangenum, hwm;
69 struct autorid_domain_config *cfg;
71 cfg = (struct autorid_domain_config *)private_data;
73 ret = dbwrap_fetch_uint32_bystring(db, cfg->keystr,
76 if (NT_STATUS_IS_OK(ret)) {
77 /* entry is already present*/
81 DEBUG(10, ("Acquiring new range for domain %s (multiplier=%"PRIu32")\n",
82 cfg->sid, cfg->multiplier));
84 /* fetch the current HWM */
85 ret = dbwrap_fetch_uint32_bystring(db, HWM, &hwm);
86 if (!NT_STATUS_IS_OK(ret)) {
87 DEBUG(1, ("Fatal error while fetching current "
88 "HWM value: %s\n", nt_errstr(ret)));
89 ret = NT_STATUS_INTERNAL_ERROR;
93 /* do we have a range left? */
94 if (hwm >= cfg->globalcfg->maxranges) {
95 DEBUG(1, ("No more domain ranges available!\n"));
96 ret = NT_STATUS_NO_MEMORY;
100 /* increase the HWM */
101 ret = dbwrap_change_uint32_atomic_bystring(db, HWM, &rangenum, 1);
102 if (!NT_STATUS_IS_OK(ret)) {
103 DEBUG(1, ("Fatal error while fetching a new "
104 "domain range value!\n"));
108 /* store away the new mapping in both directions */
109 ret = dbwrap_store_uint32_bystring(db, cfg->keystr, rangenum);
110 if (!NT_STATUS_IS_OK(ret)) {
111 DEBUG(1, ("Fatal error while storing new "
112 "domain->range assignment!\n"));
116 numstr = talloc_asprintf(db, "%u", rangenum);
118 ret = NT_STATUS_NO_MEMORY;
122 ret = dbwrap_store_bystring(db, numstr,
123 string_term_tdb_data(cfg->keystr), TDB_INSERT);
126 if (!NT_STATUS_IS_OK(ret)) {
127 DEBUG(1, ("Fatal error while storing "
128 "new domain->range assignment!\n"));
131 DEBUG(5, ("Acquired new range #%d for domain %s "
132 "(multiplier=%"PRIu32")\n", rangenum, cfg->keystr,
135 cfg->rangenum = rangenum;
144 static NTSTATUS idmap_autorid_get_domainrange(struct autorid_domain_config *dom,
150 * try to find mapping without locking the database,
151 * if it is not found create a mapping in a transaction unless
152 * read-only mode has been set
154 if (dom->multiplier > 0) {
155 snprintf(dom->keystr, FSTRING_LEN, "%s#%"PRIu32, dom->sid,
158 fstrcpy(dom->keystr, dom->sid);
161 ret = dbwrap_fetch_uint32_bystring(autorid_db, dom->keystr,
164 if (!NT_STATUS_IS_OK(ret)) {
166 return NT_STATUS_NOT_FOUND;
168 ret = dbwrap_trans_do(autorid_db,
169 idmap_autorid_get_domainrange_action, dom);
172 DEBUG(10, ("Using range #%d for domain %s (multiplier=%"PRIu32")\n",
173 dom->rangenum, dom->sid, dom->multiplier));
178 static NTSTATUS idmap_autorid_allocate_id(struct idmap_domain *dom,
179 struct unixid *xid) {
182 struct idmap_tdb_common_context *commoncfg;
183 struct autorid_global_config *globalcfg;
184 struct autorid_domain_config domaincfg;
187 talloc_get_type_abort(dom->private_data,
188 struct idmap_tdb_common_context);
190 globalcfg = talloc_get_type(commoncfg->private_data,
191 struct autorid_global_config);
193 if (dom->read_only) {
194 DEBUG(3, ("Backend is read-only, refusing "
195 "new allocation request\n"));
196 return NT_STATUS_UNSUCCESSFUL;
199 /* fetch the range for the allocation pool */
201 ZERO_STRUCT(domaincfg);
203 domaincfg.globalcfg = globalcfg;
204 fstrcpy(domaincfg.sid, ALLOC_RANGE);
206 ret = idmap_autorid_get_domainrange(&domaincfg, dom->read_only);
208 if (!NT_STATUS_IS_OK(ret)) {
209 DEBUG(3, ("Could not determine range for allocation pool, "
210 "check previous messages for reason\n"));
214 ret = idmap_tdb_common_get_new_id(dom, xid);
216 if (!NT_STATUS_IS_OK(ret)) {
217 DEBUG(1, ("Fatal error while allocating new ID!\n"));
221 xid->id = globalcfg->minvalue +
222 globalcfg->rangesize * domaincfg.rangenum +
225 DEBUG(10, ("Returned new %s %d from allocation range\n",
226 (xid->type==ID_TYPE_UID)?"uid":"gid", xid->id));
232 * map a SID to xid using the idmap_tdb like pool
234 static NTSTATUS idmap_autorid_map_id_to_sid(struct idmap_domain *dom,
239 /* look out for the mapping */
240 ret = idmap_tdb_common_unixid_to_sid(dom, map);
242 if (NT_STATUS_IS_OK(ret)) {
243 map->status = ID_MAPPED;
247 map->status = ID_UNKNOWN;
249 DEBUG(10, ("no ID->SID mapping for %d could be found\n", map->xid.id));
254 static NTSTATUS idmap_autorid_id_to_sid(struct autorid_global_config *cfg,
255 struct idmap_domain *dom,
259 uint32_t multiplier = 0;
260 TDB_DATA data = tdb_null;
265 const char *q = NULL;
267 /* can this be one of our ids? */
268 if (map->xid.id < cfg->minvalue) {
269 DEBUG(10, ("id %d is lower than minimum value, "
270 "ignoring mapping request\n", map->xid.id));
271 map->status = ID_UNKNOWN;
275 if (map->xid.id > (cfg->minvalue + cfg->rangesize * cfg->maxranges)) {
276 DEBUG(10, ("id %d is outside of maximum id value, "
277 "ignoring mapping request\n", map->xid.id));
278 map->status = ID_UNKNOWN;
282 /* determine the range of this uid */
283 range = ((map->xid.id - cfg->minvalue) / cfg->rangesize);
285 keystr = talloc_asprintf(talloc_tos(), "%u", range);
287 return NT_STATUS_NO_MEMORY;
290 status = dbwrap_fetch_bystring(autorid_db, talloc_tos(), keystr, &data);
293 if (!NT_STATUS_IS_OK(status)) {
294 DEBUG(4, ("id %d belongs to range %d which does not have "
295 "domain mapping, ignoring mapping request\n",
296 map->xid.id, range));
297 TALLOC_FREE(data.dptr);
298 map->status = ID_UNKNOWN;
302 if (strncmp((const char *)data.dptr,
304 strlen(ALLOC_RANGE)) == 0) {
306 * this is from the alloc range, check if there is a mapping
308 DEBUG(5, ("id %d belongs to allocation range, "
309 "checking for mapping\n",
311 TALLOC_FREE(data.dptr);
312 return idmap_autorid_map_id_to_sid(dom, map);
315 ok = dom_sid_parse_endp((const char *)data.dptr, &sid, &q);
316 TALLOC_FREE(data.dptr);
318 map->status = ID_UNKNOWN;
322 if (sscanf(q+1, "%"SCNu32, &multiplier) != 1) {
323 DEBUG(10, ("Multiplier not found! "
324 "ignoring mapping request\n"));
325 map->status = ID_UNKNOWN;
329 sid_compose(map->sid, &sid,
330 (map->xid.id - cfg->minvalue -
331 range * cfg->rangesize + (cfg->rangesize * multiplier)));
333 /* We **really** should have some way of validating
334 the SID exists and is the correct type here. But
335 that is a deficiency in the idmap_rid design. */
337 map->status = ID_MAPPED;
338 map->xid.type = ID_TYPE_BOTH;
343 /**********************************
344 Single sid to id lookup function.
345 **********************************/
347 static NTSTATUS idmap_autorid_sid_to_id(struct autorid_global_config *global,
348 struct autorid_domain_config *domain,
353 sid_peek_rid(map->sid, &rid);
355 map->xid.id = global->minvalue +
356 (global->rangesize * domain->rangenum) + rid -
357 (global->rangesize * domain->multiplier);
358 map->xid.type = ID_TYPE_BOTH;
360 /* We **really** should have some way of validating
361 the SID exists and is the correct type here. But
362 that is a deficiency in the idmap_rid design. */
364 map->status = ID_MAPPED;
369 /**********************************
370 lookup a set of unix ids.
371 **********************************/
373 static NTSTATUS idmap_autorid_unixids_to_sids(struct idmap_domain *dom,
376 struct idmap_tdb_common_context *commoncfg;
377 struct autorid_global_config *globalcfg;
383 /* initialize the status to avoid surprise */
384 for (i = 0; ids[i]; i++) {
385 ids[i]->status = ID_UNKNOWN;
390 talloc_get_type_abort(dom->private_data,
391 struct idmap_tdb_common_context);
393 globalcfg = talloc_get_type(commoncfg->private_data,
394 struct autorid_global_config);
396 for (i = 0; ids[i]; i++) {
398 ret = idmap_autorid_id_to_sid(globalcfg, dom, ids[i]);
400 if ((!NT_STATUS_IS_OK(ret)) &&
401 (!NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED))) {
402 /* some fatal error occurred, log it */
403 DEBUG(3, ("Unexpected error resolving an ID "
404 " (%d)\n", ids[i]->xid.id));
408 if (NT_STATUS_IS_OK(ret) && ids[i]->status == ID_MAPPED) {
414 if (num_tomap == num_mapped) {
416 } else if (num_mapped == 0) {
417 return NT_STATUS_NONE_MAPPED;
420 return STATUS_SOME_UNMAPPED;
428 * map a SID to xid using the idmap_tdb like pool
430 static NTSTATUS idmap_autorid_map_sid_to_id(struct idmap_domain *dom,
432 struct idmap_tdb_common_context *ctx)
437 /* see if we already have a mapping */
438 ret = idmap_tdb_common_sid_to_unixid(dom, map);
440 if (NT_STATUS_IS_OK(ret)) {
441 map->status = ID_MAPPED;
445 /* bad things happened */
446 if (!NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED)) {
447 DEBUG(1, ("Looking up SID->ID mapping for %s failed\n",
448 sid_string_dbg(map->sid)));
452 if (dom->read_only) {
453 DEBUG(3, ("Not allocating new mapping for %s, because backend "
454 "is read-only\n", sid_string_dbg(map->sid)));
455 return NT_STATUS_NONE_MAPPED;
458 DEBUG(10, ("Creating new mapping in pool for %s\n",
459 sid_string_dbg(map->sid)));
461 /* create new mapping */
462 res = dbwrap_transaction_start(ctx->db);
464 DEBUG(2, ("transaction_start failed\n"));
465 return NT_STATUS_INTERNAL_DB_CORRUPTION;
468 ret = idmap_tdb_common_new_mapping(dom, map);
470 map->status = (NT_STATUS_IS_OK(ret))?ID_MAPPED:ID_UNMAPPED;
472 if (!NT_STATUS_IS_OK(ret)) {
473 if (dbwrap_transaction_cancel(ctx->db) != 0) {
474 smb_panic("Cancelling transaction failed");
479 res = dbwrap_transaction_commit(ctx->db);
484 DEBUG(2, ("transaction_commit failed\n"));
485 return NT_STATUS_INTERNAL_DB_CORRUPTION;
489 /**********************************
490 lookup a set of sids.
491 **********************************/
493 static NTSTATUS idmap_autorid_sids_to_unixids(struct idmap_domain *dom,
496 struct idmap_tdb_common_context *commoncfg;
497 struct autorid_global_config *global;
503 /* initialize the status to avoid surprise */
504 for (i = 0; ids[i]; i++) {
505 ids[i]->status = ID_UNKNOWN;
510 talloc_get_type_abort(dom->private_data,
511 struct idmap_tdb_common_context);
513 global = talloc_get_type(commoncfg->private_data,
514 struct autorid_global_config);
516 for (i = 0; ids[i]; i++) {
517 struct winbindd_tdc_domain *domain;
518 struct autorid_domain_config domaincfg;
520 struct dom_sid domainsid;
522 ZERO_STRUCT(domaincfg);
524 DEBUG(10, ("Trying to map %s\n", sid_string_dbg(ids[i]->sid)));
526 sid_copy(&domainsid, ids[i]->sid);
527 if (!sid_split_rid(&domainsid, &rid)) {
528 DEBUG(4, ("Could not determine domain SID from %s, "
529 "ignoring mapping request\n",
530 sid_string_dbg(ids[i]->sid)));
534 /* is this a well-known SID? */
536 if (sid_check_is_wellknown_domain(&domainsid, NULL)) {
538 DEBUG(10, ("SID %s is well-known, using pool\n",
539 sid_string_dbg(ids[i]->sid)));
541 ret = idmap_autorid_map_sid_to_id(dom, ids[i],
544 if (!NT_STATUS_IS_OK(ret) &&
545 !NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED)) {
546 DEBUG(3, ("Unexpected error resolving "
548 sid_string_dbg(ids[i]->sid)));
552 if (ids[i]->status == ID_MAPPED) {
559 /* BUILTIN is passdb's job */
560 if (dom_sid_equal(&domainsid, &global_sid_Builtin) &&
561 global->ignore_builtin) {
562 DEBUG(10, ("Ignoring request for BUILTIN domain\n"));
567 * Check if the domain is around
569 domain = wcache_tdc_fetch_domainbysid(talloc_tos(),
571 if (domain == NULL) {
572 DEBUG(10, ("Ignoring unknown domain sid %s\n",
573 sid_string_dbg(&domainsid)));
578 domaincfg.globalcfg = global;
579 sid_to_fstring(domaincfg.sid, &domainsid);
581 /* Calculate multiplier for multi-range support */
582 domaincfg.multiplier = rid / (global->rangesize);
584 ret = idmap_autorid_get_domainrange(&domaincfg, dom->read_only);
586 /* read-only mode and a new domain range would be required? */
587 if (NT_STATUS_EQUAL(ret, NT_STATUS_NOT_FOUND) &&
589 DEBUG(10, ("read-only is enabled, did not allocate "
590 "new range for domain %s\n",
591 sid_string_dbg(&domainsid)));
595 if (!NT_STATUS_IS_OK(ret)) {
596 DEBUG(3, ("Could not determine range for domain, "
597 "check previous messages for reason\n"));
601 ret = idmap_autorid_sid_to_id(global, &domaincfg, ids[i]);
603 if ((!NT_STATUS_IS_OK(ret)) &&
604 (!NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED))) {
605 /* some fatal error occurred, log it */
606 DEBUG(3, ("Unexpected error resolving a SID (%s)\n",
607 sid_string_dbg(ids[i]->sid)));
611 if (NT_STATUS_IS_OK(ret)) {
616 if (num_tomap == num_mapped) {
618 } else if (num_mapped == 0) {
619 return NT_STATUS_NONE_MAPPED;
622 return STATUS_SOME_UNMAPPED;
629 /* initialize the given HWM to 0 if it does not exist yet */
630 static NTSTATUS idmap_autorid_init_hwm(const char *hwm) {
635 status = dbwrap_fetch_uint32_bystring(autorid_db, hwm, &hwmval);
636 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
637 status = dbwrap_trans_store_int32_bystring(autorid_db, hwm, 0);
638 if (!NT_STATUS_IS_OK(status)) {
640 ("Unable to initialise HWM (%s) in autorid "
641 "database: %s\n", hwm, nt_errstr(status)));
642 return NT_STATUS_INTERNAL_DB_ERROR;
644 } else if (!NT_STATUS_IS_OK(status)) {
645 DEBUG(0, ("unable to fetch HWM (%s) from autorid "
646 "database: %s\n", hwm, nt_errstr(status)));
654 * open and initialize the database which stores the ranges for the domains
656 static NTSTATUS idmap_autorid_db_init(void)
661 /* its already open */
665 /* Open idmap repository */
666 autorid_db = db_open(NULL, state_path("autorid.tdb"), 0,
667 TDB_DEFAULT, O_RDWR | O_CREAT, 0644,
668 DBWRAP_LOCK_ORDER_1);
671 DEBUG(0, ("Unable to open idmap_autorid database '%s'\n",
672 state_path("autorid.tdb")));
673 return NT_STATUS_UNSUCCESSFUL;
676 /* Initialize high water mark for the currently used range to 0 */
678 status = idmap_autorid_init_hwm(HWM);
679 NT_STATUS_NOT_OK_RETURN(status);
681 status = idmap_autorid_init_hwm(ALLOC_HWM_UID);
682 NT_STATUS_NOT_OK_RETURN(status);
684 status = idmap_autorid_init_hwm(ALLOC_HWM_GID);
689 static struct autorid_global_config *idmap_autorid_loadconfig(TALLOC_CTX * ctx)
693 struct autorid_global_config *cfg;
694 unsigned long minvalue, rangesize, maxranges;
697 status = dbwrap_fetch_bystring(autorid_db, ctx, CONFIGKEY, &data);
699 if (!NT_STATUS_IS_OK(status)) {
700 DEBUG(10, ("No saved config found\n"));
704 cfg = talloc_zero(ctx, struct autorid_global_config);
709 if (sscanf((char *)data.dptr,
710 "minvalue:%lu rangesize:%lu maxranges:%lu",
711 &minvalue, &rangesize, &maxranges) != 3) {
713 ("Found invalid configuration data"
714 "creating new config\n"));
718 cfg->minvalue = minvalue;
719 cfg->rangesize = rangesize;
720 cfg->maxranges = maxranges;
722 DEBUG(10, ("Loaded previously stored configuration "
723 "minvalue:%d rangesize:%d\n",
724 cfg->minvalue, cfg->rangesize));
730 static NTSTATUS idmap_autorid_saveconfig(struct autorid_global_config *cfg)
738 talloc_asprintf(talloc_tos(),
739 "minvalue:%u rangesize:%u maxranges:%u",
740 cfg->minvalue, cfg->rangesize, cfg->maxranges);
743 return NT_STATUS_NO_MEMORY;
746 data = string_tdb_data(cfgstr);
748 status = dbwrap_trans_store_bystring(autorid_db, CONFIGKEY,
756 static NTSTATUS idmap_autorid_preallocate_wellknown(struct idmap_domain *dom)
758 const char *groups[] = { "S-1-1-0", "S-1-2-0", "S-1-2-1",
759 "S-1-3-0", "S-1-3-1", "S-1-3-2", "S-1-3-3", "S-1-3-4",
760 "S-1-5-1", "S-1-5-2", "S-1-5-3", "S-1-5-4", "S-1-5-6",
761 "S-1-5-7", "S-1-5-8", "S-1-5-9", "S-1-5-10", "S-1-5-11",
762 "S-1-5-12", "S-1-5-13", "S-1-5-14", "S-1-5-15",
763 "S-1-5-17", "S-1-5-18", "S-1-5-19", "S-1-5-20"
766 struct id_map **maps;
770 if (dom->read_only) {
774 num = sizeof(groups)/sizeof(char*);
776 maps = talloc_zero_array(talloc_tos(), struct id_map*, num+1);
778 return NT_STATUS_NO_MEMORY;
781 for (i = 0; i < num; i++) {
782 maps[i] = talloc(maps, struct id_map);
783 maps[i]->xid.type = ID_TYPE_GID;
784 maps[i]->sid = dom_sid_parse_talloc(maps, groups[i]);
789 status = idmap_autorid_sids_to_unixids(dom, maps);
791 DEBUG(10,("Preallocation run finished with status %s\n",
796 return NT_STATUS_IS_OK(status)?NT_STATUS_OK:NT_STATUS_UNSUCCESSFUL;
799 static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
801 struct idmap_tdb_common_context *commonconfig;
802 struct autorid_global_config *config;
803 struct autorid_global_config *storedconfig = NULL;
807 if (!strequal(dom->name, "*")) {
808 DEBUG(0, ("idmap_autorid_initialize: Error: autorid configured "
809 "for domain '%s'. But autorid can only be used for "
810 "the default idmap configuration.\n", dom->name));
811 return NT_STATUS_INVALID_PARAMETER;
814 commonconfig = talloc_zero(dom, struct idmap_tdb_common_context);
816 DEBUG(0, ("Out of memory!\n"));
817 return NT_STATUS_NO_MEMORY;
820 commonconfig->rw_ops = talloc_zero(commonconfig, struct idmap_rw_ops);
821 if (commonconfig->rw_ops == NULL) {
822 DEBUG(0, ("Out of memory!\n"));
823 return NT_STATUS_NO_MEMORY;
826 config = talloc_zero(commonconfig, struct autorid_global_config);
828 DEBUG(0, ("Out of memory!\n"));
829 return NT_STATUS_NO_MEMORY;
832 status = idmap_autorid_db_init();
833 if (!NT_STATUS_IS_OK(status)) {
837 config->minvalue = dom->low_id;
838 config->rangesize = lp_parm_int(-1, "idmap config *",
839 "rangesize", 100000);
841 if (config->rangesize < 2000) {
842 DEBUG(1, ("autorid rangesize must be at least 2000\n"));
843 status = NT_STATUS_INVALID_PARAMETER;
847 config->maxranges = (dom->high_id - dom->low_id + 1) /
850 if (config->maxranges == 0) {
851 DEBUG(1, ("allowed uid range is smaller then rangesize, "
852 "increase uid range or decrease rangesize\n"));
853 status = NT_STATUS_INVALID_PARAMETER;
857 /* check if the high-low limit is a multiple of the rangesize */
858 if ((dom->high_id - dom->low_id + 1) % config->rangesize != 0) {
859 DEBUG(5, ("High uid-low uid difference of %d "
860 "is not a multiple of the rangesize %d, "
861 "limiting ranges to lower boundary number of %d\n",
862 (dom->high_id - dom->low_id + 1), config->rangesize,
866 DEBUG(10, ("Current configuration in config is "
867 "minvalue:%d rangesize:%d maxranges:%d\n",
868 config->minvalue, config->rangesize, config->maxranges));
870 /* read previously stored config and current HWM */
871 storedconfig = idmap_autorid_loadconfig(talloc_tos());
873 status = dbwrap_fetch_uint32_bystring(autorid_db, HWM, &hwm);
874 if (!NT_STATUS_IS_OK(status)) {
875 DEBUG(1, ("Fatal error while fetching current "
876 "HWM value: %s\n", nt_errstr(status)));
877 status = NT_STATUS_INTERNAL_ERROR;
881 /* did the minimum value or rangesize change? */
883 ((storedconfig->minvalue != config->minvalue) ||
884 (storedconfig->rangesize != config->rangesize))) {
885 DEBUG(1, ("New configuration values for rangesize or "
886 "minimum uid value conflict with previously "
887 "used values! Aborting initialization\n"));
888 status = NT_STATUS_INVALID_PARAMETER;
893 * has the highest uid value been reduced to setting that is not
894 * sufficient any more for already existing ranges?
896 if (hwm > config->maxranges) {
897 DEBUG(1, ("New upper uid limit is too low to cover "
898 "existing mappings! Aborting initialization\n"));
899 status = NT_STATUS_INVALID_PARAMETER;
903 status = idmap_autorid_saveconfig(config);
905 if (!NT_STATUS_IS_OK(status)) {
906 DEBUG(1, ("Failed to store configuration data!\n"));
910 DEBUG(5, ("%d domain ranges with a size of %d are available\n",
911 config->maxranges, config->rangesize));
913 config->ignore_builtin = lp_parm_bool(-1, "idmap config *",
914 "ignore builtin", false);
916 /* fill the TDB common configuration */
917 commonconfig->private_data = config;
919 commonconfig->db = autorid_db;
920 commonconfig->max_id = config->rangesize -1;
921 commonconfig->hwmkey_uid = ALLOC_HWM_UID;
922 commonconfig->hwmkey_gid = ALLOC_HWM_GID;
923 commonconfig->rw_ops->get_new_id = idmap_autorid_allocate_id;
924 commonconfig->rw_ops->set_mapping = idmap_tdb_common_set_mapping;
926 dom->private_data = commonconfig;
928 /* preallocate well-known SIDs in the pool */
929 status = idmap_autorid_preallocate_wellknown(dom);
937 talloc_free(storedconfig);
943 Close the idmap tdb instance
945 static struct idmap_methods autorid_methods = {
946 .init = idmap_autorid_initialize,
947 .unixids_to_sids = idmap_autorid_unixids_to_sids,
948 .sids_to_unixids = idmap_autorid_sids_to_unixids,
949 .allocate_id = idmap_autorid_allocate_id
952 NTSTATUS samba_init_module(void)
954 return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION,
955 "autorid", &autorid_methods);