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 * This module allocates ranges for domains to be used in a
27 * algorithmic mode like idmap_rid. Multiple ranges are supported
28 * for a single domain: If a rid exceeds the range size, a matching
29 * range is allocated to hold the rid's id.
31 * Here are the formulas applied:
34 * For a sid of the form domain_sid-rid, we have
36 * rid = reduced_rid + domain_range_index * range_size
39 * reduced_rid := rid % range_size
40 * domain_range_index := rid / range_size
42 * And reduced_rid fits into a range.
44 * In the database, we associate a range_number to
45 * the pair domain_sid,domain_range_index.
47 * Now the unix id for the given sid calculates as:
49 * id = reduced_rid + range_low_id
53 * range_low_id = low_id + range_number * range_size
56 * The inverse calculation goes like this:
58 * Given a unix id, let
60 * normalized_id := id - low_id
61 * reduced_rid := normalized_id % range_size
62 * range_number = normalized_id / range_size
66 * id = reduced_rid + low_id + range_number * range_size
68 * From the database, get the domain_sid,domain_range_index pair
69 * belonging to the range_number (if there is already one).
71 * Then the rid for the unix id calculates as:
73 * rid = reduced_rid + domain_range_index * range_size
76 #include "idmap_autorid_tdb.h"
80 #include "../libcli/security/dom_sid.h"
81 #include "libsmb/samlogon_cache.h"
82 #include "passdb/machine_sid.h"
85 #define DBGC_CLASS DBGC_IDMAP
87 #define IDMAP_AUTORID_ALLOC_RESERVED 500
89 /* handle to the tdb storing domain <-> range assignments */
90 static struct db_context
*autorid_db
;
92 static bool ignore_builtin
= false;
94 static NTSTATUS
idmap_autorid_get_alloc_range(struct idmap_domain
*dom
,
95 struct autorid_range_config
*range
)
101 fstrcpy(range
->domsid
, ALLOC_RANGE
);
103 status
= idmap_autorid_get_domainrange(autorid_db
,
110 static NTSTATUS
idmap_autorid_allocate_id(struct idmap_domain
*dom
,
111 struct unixid
*xid
) {
114 struct autorid_range_config range
;
116 if (dom
->read_only
) {
117 DEBUG(3, ("Backend is read-only, refusing "
118 "new allocation request\n"));
119 return NT_STATUS_UNSUCCESSFUL
;
122 /* fetch the range for the allocation pool */
124 ret
= idmap_autorid_get_alloc_range(dom
, &range
);
125 if (!NT_STATUS_IS_OK(ret
)) {
126 DEBUG(3, ("Could not determine range for allocation pool, "
127 "check previous messages for reason\n"));
131 ret
= idmap_tdb_common_get_new_id(dom
, xid
);
133 if (!NT_STATUS_IS_OK(ret
)) {
134 DEBUG(1, ("Fatal error while allocating new ID!\n"));
138 xid
->id
= xid
->id
+ range
.low_id
;
140 DEBUG(10, ("Returned new %s %d from allocation range\n",
141 (xid
->type
==ID_TYPE_UID
)?"uid":"gid", xid
->id
));
147 * map a xid to SID using the idmap_tdb like pool
149 static NTSTATUS
idmap_autorid_id_to_sid_alloc(struct idmap_domain
*dom
,
154 /* look out for the mapping */
155 ret
= idmap_tdb_common_unixid_to_sid(dom
, map
);
157 if (NT_STATUS_IS_OK(ret
)) {
158 map
->status
= ID_MAPPED
;
162 map
->status
= ID_UNKNOWN
;
164 DEBUG(10, ("no ID->SID mapping for %d could be found\n", map
->xid
.id
));
169 static NTSTATUS
idmap_autorid_id_to_sid(struct autorid_global_config
*cfg
,
170 struct idmap_domain
*dom
,
173 uint32_t range_number
;
174 uint32_t domain_range_index
;
175 uint32_t normalized_id
;
176 uint32_t reduced_rid
;
178 TDB_DATA data
= tdb_null
;
180 struct dom_sid domsid
;
183 const char *q
= NULL
;
185 /* can this be one of our ids? */
186 if (map
->xid
.id
< cfg
->minvalue
) {
187 DEBUG(10, ("id %d is lower than minimum value, "
188 "ignoring mapping request\n", map
->xid
.id
));
189 map
->status
= ID_UNKNOWN
;
193 if (map
->xid
.id
> (cfg
->minvalue
+ cfg
->rangesize
* cfg
->maxranges
)) {
194 DEBUG(10, ("id %d is outside of maximum id value, "
195 "ignoring mapping request\n", map
->xid
.id
));
196 map
->status
= ID_UNKNOWN
;
200 /* determine the range of this uid */
202 normalized_id
= map
->xid
.id
- cfg
->minvalue
;
203 range_number
= normalized_id
/ cfg
->rangesize
;
205 keystr
= talloc_asprintf(talloc_tos(), "%u", range_number
);
207 return NT_STATUS_NO_MEMORY
;
210 status
= dbwrap_fetch_bystring(autorid_db
, talloc_tos(), keystr
, &data
);
213 if (!NT_STATUS_IS_OK(status
)) {
214 DEBUG(4, ("id %d belongs to range %d which does not have "
215 "domain mapping, ignoring mapping request\n",
216 map
->xid
.id
, range_number
));
217 TALLOC_FREE(data
.dptr
);
218 map
->status
= ID_UNKNOWN
;
222 if ((data
.dsize
== 0) || (data
.dptr
[data
.dsize
-1] != '\0')) {
223 DBG_WARNING("Invalid range %"PRIu32
"\n", range_number
);
224 TALLOC_FREE(data
.dptr
);
225 map
->status
= ID_UNKNOWN
;
229 if (strncmp((const char *)data
.dptr
,
231 strlen(ALLOC_RANGE
)) == 0) {
233 * this is from the alloc range, check if there is a mapping
235 DEBUG(5, ("id %d belongs to allocation range, "
236 "checking for mapping\n",
238 TALLOC_FREE(data
.dptr
);
239 return idmap_autorid_id_to_sid_alloc(dom
, map
);
242 ok
= dom_sid_parse_endp((const char *)data
.dptr
, &domsid
, &q
);
244 TALLOC_FREE(data
.dptr
);
245 map
->status
= ID_UNKNOWN
;
250 * Allow for sid#range_index, just sid is range index 0
255 domain_range_index
= 0;
258 if (sscanf(q
+1, "%"SCNu32
, &domain_range_index
) == 1) {
261 /* If we end up here, something weird is in the record. */
265 DBG_DEBUG("SID/domain range: %s\n",
266 (const char *)data
.dptr
);
267 TALLOC_FREE(data
.dptr
);
268 map
->status
= ID_UNKNOWN
;
272 TALLOC_FREE(data
.dptr
);
274 reduced_rid
= normalized_id
% cfg
->rangesize
;
275 rid
= reduced_rid
+ domain_range_index
* cfg
->rangesize
;
277 sid_compose(map
->sid
, &domsid
, rid
);
279 /* We **really** should have some way of validating
280 the SID exists and is the correct type here. But
281 that is a deficiency in the idmap_rid design. */
283 map
->status
= ID_MAPPED
;
284 map
->xid
.type
= ID_TYPE_BOTH
;
289 /**********************************
290 Single sid to id lookup function.
291 **********************************/
293 static NTSTATUS
idmap_autorid_sid_to_id_rid(
299 uint32_t reduced_rid
;
301 sid_peek_rid(map
->sid
, &rid
);
303 reduced_rid
= rid
% rangesize
;
305 map
->xid
.id
= reduced_rid
+ low_id
;
306 map
->xid
.type
= ID_TYPE_BOTH
;
307 map
->status
= ID_MAPPED
;
312 /**********************************
313 lookup a set of unix ids.
314 **********************************/
316 static NTSTATUS
idmap_autorid_unixids_to_sids(struct idmap_domain
*dom
,
319 struct idmap_tdb_common_context
*commoncfg
;
320 struct autorid_global_config
*globalcfg
;
326 /* initialize the status to avoid surprise */
327 for (i
= 0; ids
[i
]; i
++) {
328 ids
[i
]->status
= ID_UNKNOWN
;
333 talloc_get_type_abort(dom
->private_data
,
334 struct idmap_tdb_common_context
);
336 globalcfg
= talloc_get_type(commoncfg
->private_data
,
337 struct autorid_global_config
);
339 for (i
= 0; ids
[i
]; i
++) {
341 ret
= idmap_autorid_id_to_sid(globalcfg
, dom
, ids
[i
]);
343 if ((!NT_STATUS_IS_OK(ret
)) &&
344 (!NT_STATUS_EQUAL(ret
, NT_STATUS_NONE_MAPPED
))) {
345 /* some fatal error occurred, log it */
346 DBG_NOTICE("Unexpected error resolving an ID "
347 "(%d): %s\n", ids
[i
]->xid
.id
,
352 if (NT_STATUS_IS_OK(ret
) && ids
[i
]->status
== ID_MAPPED
) {
358 if (num_tomap
== num_mapped
) {
361 if (num_mapped
== 0) {
362 return NT_STATUS_NONE_MAPPED
;
365 return STATUS_SOME_UNMAPPED
;
372 static bool idmap_autorid_sid_is_special(struct dom_sid
*sid
)
376 match
= sid_check_is_in_wellknown_domain(sid
);
384 static NTSTATUS
idmap_autorid_sid_to_id_special(struct idmap_domain
*dom
,
387 struct idmap_tdb_common_context
*common
=
388 talloc_get_type_abort(dom
->private_data
,
389 struct idmap_tdb_common_context
);
391 struct autorid_range_config range
;
395 status
= idmap_autorid_get_alloc_range(dom
, &range
);
396 if (!NT_STATUS_IS_OK(status
)) {
400 /* Take the next free ID, counting from the top */
402 for (count
= 0; count
< IDMAP_AUTORID_ALLOC_RESERVED
; count
++) {
403 struct id_map test_map
;
407 test_map
.xid
.type
= map
->xid
.type
;
408 test_map
.xid
.id
= range
.high_id
- count
;
409 test_map
.status
= ID_UNKNOWN
;
411 status
= idmap_tdb_common_unixid_to_sid(dom
, &test_map
);
412 if (NT_STATUS_EQUAL(NT_STATUS_NONE_MAPPED
, status
)) {
413 free_id
= test_map
.xid
.id
;
417 if (!NT_STATUS_IS_OK(status
)) {
418 /* error - get out */
422 /* mapping exists - try next ID */
426 return NT_STATUS_NONE_MAPPED
;
429 map
->status
= ID_MAPPED
;
430 map
->xid
.id
= free_id
;
432 status
= common
->rw_ops
->set_mapping(dom
, map
);
433 if (!NT_STATUS_IS_OK(status
)) {
434 DEBUG(2, ("Error storing new mapping: %s\n",
442 struct idmap_autorid_sid_to_id_alloc_ctx
{
443 struct idmap_domain
*dom
;
447 static NTSTATUS
idmap_autorid_sid_to_id_alloc_action(
448 struct db_context
*db
,
451 struct idmap_autorid_sid_to_id_alloc_ctx
*ctx
;
453 ctx
= (struct idmap_autorid_sid_to_id_alloc_ctx
*)private_data
;
455 if (idmap_autorid_sid_is_special(ctx
->map
->sid
)) {
456 struct dom_sid_buf buf
;
459 ret
= idmap_autorid_sid_to_id_special(ctx
->dom
, ctx
->map
);
460 if (NT_STATUS_IS_OK(ret
)) {
463 if (!NT_STATUS_EQUAL(NT_STATUS_NONE_MAPPED
, ret
)) {
467 DEBUG(10, ("Special sid %s not mapped. falling back to "
468 "regular allocation\n",
469 dom_sid_str_buf(ctx
->map
->sid
, &buf
)));
472 return idmap_tdb_common_new_mapping(ctx
->dom
, ctx
->map
);
476 * map a SID to xid using the idmap_tdb like pool
478 static NTSTATUS
idmap_autorid_sid_to_id_alloc(
479 struct idmap_tdb_common_context
*ctx
,
480 struct idmap_domain
*dom
,
484 struct idmap_autorid_sid_to_id_alloc_ctx alloc_ctx
;
485 struct dom_sid_buf buf
;
487 map
->status
= ID_UNKNOWN
;
489 /* see if we already have a mapping */
490 ret
= idmap_tdb_common_sid_to_unixid(dom
, map
);
492 if (NT_STATUS_IS_OK(ret
)) {
493 map
->status
= ID_MAPPED
;
497 /* bad things happened */
498 if (!NT_STATUS_EQUAL(ret
, NT_STATUS_NONE_MAPPED
)) {
499 DEBUG(1, ("Looking up SID->ID mapping for %s failed: %s\n",
500 dom_sid_str_buf(map
->sid
, &buf
),
505 if (dom
->read_only
) {
506 DEBUG(3, ("Not allocating new mapping for %s, because backend "
508 dom_sid_str_buf(map
->sid
, &buf
)));
509 map
->status
= ID_UNMAPPED
;
510 return NT_STATUS_NONE_MAPPED
;
513 DEBUG(10, ("Creating new mapping in pool for %s\n",
514 dom_sid_str_buf(map
->sid
, &buf
)));
519 ret
= dbwrap_trans_do(ctx
->db
, idmap_autorid_sid_to_id_alloc_action
,
521 if (!NT_STATUS_IS_OK(ret
)) {
522 DEBUG(1, ("Failed to create a new mapping in alloc range: %s\n",
524 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
527 map
->status
= ID_MAPPED
;
531 static bool idmap_autorid_domsid_is_for_alloc(struct dom_sid
*sid
)
535 match
= sid_check_is_wellknown_domain(sid
, NULL
);
543 static NTSTATUS
idmap_autorid_sid_to_id(struct idmap_tdb_common_context
*common
,
544 struct idmap_domain
*dom
,
547 struct autorid_global_config
*global
=
548 talloc_get_type_abort(common
->private_data
,
549 struct autorid_global_config
);
550 struct autorid_range_config range
;
552 struct dom_sid domainsid
;
553 struct dom_sid_buf buf
;
557 map
->status
= ID_UNKNOWN
;
559 DEBUG(10, ("Trying to map %s\n", dom_sid_str_buf(map
->sid
, &buf
)));
561 sid_copy(&domainsid
, map
->sid
);
562 if (!sid_split_rid(&domainsid
, &rid
)) {
563 DEBUG(4, ("Could not determine domain SID from %s, "
564 "ignoring mapping request\n",
565 dom_sid_str_buf(map
->sid
, &buf
)));
566 map
->status
= ID_UNMAPPED
;
567 return NT_STATUS_NONE_MAPPED
;
570 if (idmap_autorid_domsid_is_for_alloc(&domainsid
)) {
571 DEBUG(10, ("SID %s is for ALLOC range.\n",
572 dom_sid_str_buf(map
->sid
, &buf
)));
574 return idmap_autorid_sid_to_id_alloc(common
, dom
, map
);
577 if (dom_sid_equal(&domainsid
, &global_sid_Builtin
) && ignore_builtin
) {
578 DEBUG(10, ("Ignoring request for BUILTIN domain\n"));
579 map
->status
= ID_UNMAPPED
;
580 return NT_STATUS_NONE_MAPPED
;
583 sid_to_fstring(range
.domsid
, &domainsid
);
585 range
.domain_range_index
= rid
/ (global
->rangesize
);
587 ret
= idmap_autorid_getrange(autorid_db
, range
.domsid
,
588 range
.domain_range_index
,
589 &range
.rangenum
, &range
.low_id
);
590 if (NT_STATUS_IS_OK(ret
)) {
591 return idmap_autorid_sid_to_id_rid(
592 global
->rangesize
, range
.low_id
, map
);
595 if (dom
->read_only
) {
596 DBG_DEBUG("read-only is enabled, did not allocate "
597 "new range for domain %s\n", range
.domsid
);
598 map
->status
= ID_UNMAPPED
;
599 return NT_STATUS_NONE_MAPPED
;
603 * Check if we should allocate a domain range. We need to
604 * protect against unknown domains to not fill our ranges
608 if (sid_check_is_builtin(&domainsid
) ||
609 sid_check_is_our_sam(&domainsid
)) {
614 struct winbindd_domain
*domain
;
617 * Deterministic check for domain members: We can be
618 * sure that the domain we are member of is worth to
622 domain
= find_our_domain();
623 if ((domain
!= NULL
) &&
624 dom_sid_equal(&domain
->sid
, &domainsid
)) {
630 * If we have already allocated range index 0, this domain is
631 * worth allocating for in higher ranges.
633 if (range
.domain_range_index
!= 0) {
634 uint32_t zero_rangenum
, zero_low_id
;
636 ret
= idmap_autorid_getrange(autorid_db
, range
.domsid
, 0,
637 &zero_rangenum
, &zero_low_id
);
638 if (NT_STATUS_IS_OK(ret
)) {
644 * If the caller already did a lookup sid and made sure the
645 * domain sid is valid, we can allocate a new range.
647 * Currently the winbindd parent already does a lookup sids
648 * first, but hopefully changes in future. If the
649 * caller knows the domain sid, ID_TYPE_BOTH should be
650 * passed instead of ID_TYPE_NOT_SPECIFIED.
652 if (map
->xid
.type
!= ID_TYPE_NOT_SPECIFIED
) {
657 * Check of last resort: A domain is valid if a user from that
658 * domain has recently logged in. The samlogon_cache these
659 * days also stores the domain sid.
661 * We used to check the list of trusted domains we received
662 * from "our" dc, but this is not reliable enough.
664 if (netsamlogon_cache_have(&domainsid
)) {
669 * Nobody knows this domain, so refuse to allocate a fresh
673 DBG_NOTICE("Allocating range for domain %s refused\n", range
.domsid
);
674 map
->status
= ID_UNMAPPED
;
675 return NT_STATUS_NONE_MAPPED
;
678 ret
= idmap_autorid_acquire_range(autorid_db
, &range
);
679 if (!NT_STATUS_IS_OK(ret
)) {
680 DBG_NOTICE("Could not determine range for domain: %s, "
681 "check previous messages for reason\n",
686 return idmap_autorid_sid_to_id_rid(global
->rangesize
, range
.low_id
,
690 /**********************************
691 lookup a set of sids.
692 **********************************/
694 static NTSTATUS
idmap_autorid_sids_to_unixids(struct idmap_domain
*dom
,
697 struct idmap_tdb_common_context
*commoncfg
;
703 /* initialize the status to avoid surprise */
704 for (i
= 0; ids
[i
]; i
++) {
705 ids
[i
]->status
= ID_UNKNOWN
;
710 talloc_get_type_abort(dom
->private_data
,
711 struct idmap_tdb_common_context
);
713 for (i
= 0; ids
[i
]; i
++) {
714 ret
= idmap_autorid_sid_to_id(commoncfg
, dom
, ids
[i
]);
715 if ((!NT_STATUS_IS_OK(ret
)) &&
716 (!NT_STATUS_EQUAL(ret
, NT_STATUS_NONE_MAPPED
))) {
717 struct dom_sid_buf buf
;
718 /* some fatal error occurred, log it */
719 DEBUG(3, ("Unexpected error resolving a SID (%s)\n",
720 dom_sid_str_buf(ids
[i
]->sid
, &buf
)));
724 if (NT_STATUS_IS_OK(ret
) && ids
[i
]->status
== ID_MAPPED
) {
729 if (num_tomap
== num_mapped
) {
731 } else if (num_mapped
== 0) {
732 return NT_STATUS_NONE_MAPPED
;
735 return STATUS_SOME_UNMAPPED
;
738 static NTSTATUS
idmap_autorid_preallocate_wellknown(struct idmap_domain
*dom
)
740 const char *groups
[] = { "S-1-1-0", "S-1-2-0", "S-1-2-1",
741 "S-1-3-0", "S-1-3-1", "S-1-3-2", "S-1-3-3", "S-1-3-4",
742 "S-1-5-1", "S-1-5-2", "S-1-5-3", "S-1-5-4", "S-1-5-6",
743 "S-1-5-7", "S-1-5-8", "S-1-5-9", "S-1-5-10", "S-1-5-11",
744 "S-1-5-12", "S-1-5-13", "S-1-5-14", "S-1-5-15",
745 "S-1-5-17", "S-1-5-18", "S-1-5-19", "S-1-5-20"
748 struct id_map
**maps
;
752 if (dom
->read_only
) {
756 num
= ARRAY_SIZE(groups
);
758 maps
= talloc_array(talloc_tos(), struct id_map
*, num
+1);
760 return NT_STATUS_NO_MEMORY
;
763 for (i
= 0; i
< num
; i
++) {
764 maps
[i
] = talloc(maps
, struct id_map
);
765 if (maps
[i
] == NULL
) {
767 return NT_STATUS_NO_MEMORY
;
769 maps
[i
]->xid
.type
= ID_TYPE_GID
;
770 maps
[i
]->sid
= dom_sid_parse_talloc(maps
, groups
[i
]);
775 status
= idmap_autorid_sids_to_unixids(dom
, maps
);
777 DEBUG(10,("Preallocation run finished with status %s\n",
782 return NT_STATUS_IS_OK(status
)?NT_STATUS_OK
:NT_STATUS_UNSUCCESSFUL
;
785 static NTSTATUS
idmap_autorid_initialize_action(struct db_context
*db
,
788 struct idmap_domain
*dom
;
789 struct idmap_tdb_common_context
*common
;
790 struct autorid_global_config
*config
;
793 dom
= (struct idmap_domain
*)private_data
;
794 common
= (struct idmap_tdb_common_context
*)dom
->private_data
;
795 config
= (struct autorid_global_config
*)common
->private_data
;
797 status
= idmap_autorid_init_hwms(db
);
798 if (!NT_STATUS_IS_OK(status
)) {
802 status
= idmap_autorid_saveconfig(db
, config
);
803 if (!NT_STATUS_IS_OK(status
)) {
804 DEBUG(1, ("Failed to store configuration data!\n"));
808 status
= idmap_autorid_preallocate_wellknown(dom
);
809 if (!NT_STATUS_IS_OK(status
)) {
810 DEBUG(1, ("Failed to preallocate wellknown sids: %s\n",
818 static NTSTATUS
idmap_autorid_initialize(struct idmap_domain
*dom
)
820 struct idmap_tdb_common_context
*commonconfig
;
821 struct autorid_global_config
*config
;
825 if (!strequal(dom
->name
, "*")) {
826 DEBUG(0, ("idmap_autorid_initialize: Error: autorid configured "
827 "for domain '%s'. But autorid can only be used for "
828 "the default idmap configuration.\n", dom
->name
));
829 return NT_STATUS_INVALID_PARAMETER
;
832 commonconfig
= talloc_zero(dom
, struct idmap_tdb_common_context
);
834 DEBUG(0, ("Out of memory!\n"));
835 return NT_STATUS_NO_MEMORY
;
837 dom
->private_data
= commonconfig
;
839 commonconfig
->rw_ops
= talloc_zero(commonconfig
, struct idmap_rw_ops
);
840 if (commonconfig
->rw_ops
== NULL
) {
841 DEBUG(0, ("Out of memory!\n"));
842 return NT_STATUS_NO_MEMORY
;
845 config
= talloc_zero(commonconfig
, struct autorid_global_config
);
847 DEBUG(0, ("Out of memory!\n"));
848 return NT_STATUS_NO_MEMORY
;
850 commonconfig
->private_data
= config
;
852 config
->minvalue
= dom
->low_id
;
853 config
->rangesize
= idmap_config_int("*", "rangesize", 100000);
855 config
->maxranges
= (dom
->high_id
- dom
->low_id
+ 1) /
858 if (config
->maxranges
== 0) {
859 DEBUG(1, ("Allowed uid range is smaller than rangesize. "
860 "Increase uid range or decrease rangesize.\n"));
861 status
= NT_STATUS_INVALID_PARAMETER
;
865 /* check if the high-low limit is a multiple of the rangesize */
866 if ((dom
->high_id
- dom
->low_id
+ 1) % config
->rangesize
!= 0) {
867 DEBUG(5, ("High uid-low uid difference of %d "
868 "is not a multiple of the rangesize %d, "
869 "limiting ranges to lower boundary number of %d\n",
870 (dom
->high_id
- dom
->low_id
+ 1), config
->rangesize
,
874 DEBUG(5, ("%d domain ranges with a size of %d are available\n",
875 config
->maxranges
, config
->rangesize
));
877 ignore_builtin
= idmap_config_bool("*", "ignore builtin", false);
879 /* fill the TDB common configuration */
881 commonconfig
->max_id
= config
->rangesize
- 1
882 - IDMAP_AUTORID_ALLOC_RESERVED
;
883 commonconfig
->hwmkey_uid
= ALLOC_HWM_UID
;
884 commonconfig
->hwmkey_gid
= ALLOC_HWM_GID
;
885 commonconfig
->rw_ops
->get_new_id
= idmap_autorid_allocate_id
;
886 commonconfig
->rw_ops
->set_mapping
= idmap_tdb_common_set_mapping
;
888 db_path
= state_path(talloc_tos(), "autorid.tdb");
889 if (db_path
== NULL
) {
890 status
= NT_STATUS_NO_MEMORY
;
894 status
= idmap_autorid_db_open(db_path
,
895 NULL
, /* TALLOC_CTX */
897 TALLOC_FREE(db_path
);
898 if (!NT_STATUS_IS_OK(status
)) {
902 commonconfig
->db
= autorid_db
;
904 status
= dbwrap_trans_do(autorid_db
,
905 idmap_autorid_initialize_action
,
907 if (!NT_STATUS_IS_OK(status
)) {
908 DEBUG(1, ("Failed to init the idmap database: %s\n",
922 static struct idmap_methods autorid_methods
= {
923 .init
= idmap_autorid_initialize
,
924 .unixids_to_sids
= idmap_autorid_unixids_to_sids
,
925 .sids_to_unixids
= idmap_autorid_sids_to_unixids
,
926 .allocate_id
= idmap_autorid_allocate_id
930 NTSTATUS
idmap_autorid_init(TALLOC_CTX
*ctx
)
932 return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION
,
933 "autorid", &autorid_methods
);