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"
83 #include "lib/util/string_wrappers.h"
86 #define DBGC_CLASS DBGC_IDMAP
88 #define IDMAP_AUTORID_ALLOC_RESERVED 500
90 /* handle to the tdb storing domain <-> range assignments */
91 static struct db_context
*autorid_db
;
93 static bool ignore_builtin
= false;
95 static NTSTATUS
idmap_autorid_get_alloc_range(struct idmap_domain
*dom
,
96 struct autorid_range_config
*range
)
102 fstrcpy(range
->domsid
, ALLOC_RANGE
);
104 status
= idmap_autorid_get_domainrange(autorid_db
,
111 static NTSTATUS
idmap_autorid_allocate_id(struct idmap_domain
*dom
,
112 struct unixid
*xid
) {
115 struct autorid_range_config range
;
117 if (dom
->read_only
) {
118 DEBUG(3, ("Backend is read-only, refusing "
119 "new allocation request\n"));
120 return NT_STATUS_UNSUCCESSFUL
;
123 /* fetch the range for the allocation pool */
125 ret
= idmap_autorid_get_alloc_range(dom
, &range
);
126 if (!NT_STATUS_IS_OK(ret
)) {
127 DEBUG(3, ("Could not determine range for allocation pool, "
128 "check previous messages for reason\n"));
132 ret
= idmap_tdb_common_get_new_id(dom
, xid
);
134 if (!NT_STATUS_IS_OK(ret
)) {
135 DEBUG(1, ("Fatal error while allocating new ID!\n"));
139 xid
->id
= xid
->id
+ range
.low_id
;
141 DEBUG(10, ("Returned new %s %d from allocation range\n",
142 (xid
->type
==ID_TYPE_UID
)?"uid":"gid", xid
->id
));
148 * map a xid to SID using the idmap_tdb like pool
150 static NTSTATUS
idmap_autorid_id_to_sid_alloc(struct idmap_domain
*dom
,
155 /* look out for the mapping */
156 ret
= idmap_tdb_common_unixid_to_sid(dom
, map
);
158 if (NT_STATUS_IS_OK(ret
)) {
159 map
->status
= ID_MAPPED
;
163 map
->status
= ID_UNKNOWN
;
165 DEBUG(10, ("no ID->SID mapping for %d could be found\n", map
->xid
.id
));
170 static NTSTATUS
idmap_autorid_id_to_sid(struct autorid_global_config
*cfg
,
171 struct idmap_domain
*dom
,
174 uint32_t range_number
;
175 uint32_t domain_range_index
;
176 uint32_t normalized_id
;
177 uint32_t reduced_rid
;
179 TDB_DATA data
= tdb_null
;
181 struct dom_sid domsid
;
184 const char *q
= NULL
;
186 /* can this be one of our ids? */
187 if (map
->xid
.id
< cfg
->minvalue
) {
188 DEBUG(10, ("id %d is lower than minimum value, "
189 "ignoring mapping request\n", map
->xid
.id
));
190 map
->status
= ID_UNKNOWN
;
194 if (map
->xid
.id
> (cfg
->minvalue
+ cfg
->rangesize
* cfg
->maxranges
)) {
195 DEBUG(10, ("id %d is outside of maximum id value, "
196 "ignoring mapping request\n", map
->xid
.id
));
197 map
->status
= ID_UNKNOWN
;
201 /* determine the range of this uid */
203 normalized_id
= map
->xid
.id
- cfg
->minvalue
;
204 range_number
= normalized_id
/ cfg
->rangesize
;
206 keystr
= talloc_asprintf(talloc_tos(), "%u", range_number
);
208 return NT_STATUS_NO_MEMORY
;
211 status
= dbwrap_fetch_bystring(autorid_db
, talloc_tos(), keystr
, &data
);
214 if (!NT_STATUS_IS_OK(status
)) {
215 DEBUG(4, ("id %d belongs to range %d which does not have "
216 "domain mapping, ignoring mapping request\n",
217 map
->xid
.id
, range_number
));
218 TALLOC_FREE(data
.dptr
);
219 map
->status
= ID_UNKNOWN
;
223 if ((data
.dsize
== 0) || (data
.dptr
[data
.dsize
-1] != '\0')) {
224 DBG_WARNING("Invalid range %"PRIu32
"\n", range_number
);
225 TALLOC_FREE(data
.dptr
);
226 map
->status
= ID_UNKNOWN
;
230 if (strncmp((const char *)data
.dptr
,
232 strlen(ALLOC_RANGE
)) == 0) {
234 * this is from the alloc range, check if there is a mapping
236 DEBUG(5, ("id %d belongs to allocation range, "
237 "checking for mapping\n",
239 TALLOC_FREE(data
.dptr
);
240 return idmap_autorid_id_to_sid_alloc(dom
, map
);
243 ok
= dom_sid_parse_endp((const char *)data
.dptr
, &domsid
, &q
);
245 TALLOC_FREE(data
.dptr
);
246 map
->status
= ID_UNKNOWN
;
251 * Allow for sid#range_index, just sid is range index 0
256 domain_range_index
= 0;
259 if (sscanf(q
+1, "%"SCNu32
, &domain_range_index
) == 1) {
262 /* If we end up here, something weird is in the record. */
266 DBG_DEBUG("SID/domain range: %s\n",
267 (const char *)data
.dptr
);
268 TALLOC_FREE(data
.dptr
);
269 map
->status
= ID_UNKNOWN
;
273 TALLOC_FREE(data
.dptr
);
275 reduced_rid
= normalized_id
% cfg
->rangesize
;
276 rid
= reduced_rid
+ domain_range_index
* cfg
->rangesize
;
278 sid_compose(map
->sid
, &domsid
, rid
);
280 /* We **really** should have some way of validating
281 the SID exists and is the correct type here. But
282 that is a deficiency in the idmap_rid design. */
284 map
->status
= ID_MAPPED
;
285 map
->xid
.type
= ID_TYPE_BOTH
;
290 /**********************************
291 Single sid to id lookup function.
292 **********************************/
294 static NTSTATUS
idmap_autorid_sid_to_id_rid(
300 uint32_t reduced_rid
;
302 sid_peek_rid(map
->sid
, &rid
);
304 reduced_rid
= rid
% rangesize
;
306 map
->xid
.id
= reduced_rid
+ low_id
;
307 map
->xid
.type
= ID_TYPE_BOTH
;
308 map
->status
= ID_MAPPED
;
313 /**********************************
314 lookup a set of unix ids.
315 **********************************/
317 static NTSTATUS
idmap_autorid_unixids_to_sids(struct idmap_domain
*dom
,
320 struct idmap_tdb_common_context
*commoncfg
;
321 struct autorid_global_config
*globalcfg
;
327 /* initialize the status to avoid surprise */
328 for (i
= 0; ids
[i
]; i
++) {
329 ids
[i
]->status
= ID_UNKNOWN
;
334 talloc_get_type_abort(dom
->private_data
,
335 struct idmap_tdb_common_context
);
337 globalcfg
= talloc_get_type(commoncfg
->private_data
,
338 struct autorid_global_config
);
340 for (i
= 0; ids
[i
]; i
++) {
342 ret
= idmap_autorid_id_to_sid(globalcfg
, dom
, ids
[i
]);
344 if ((!NT_STATUS_IS_OK(ret
)) &&
345 (!NT_STATUS_EQUAL(ret
, NT_STATUS_NONE_MAPPED
))) {
346 /* some fatal error occurred, log it */
347 DBG_NOTICE("Unexpected error resolving an ID "
348 "(%d): %s\n", ids
[i
]->xid
.id
,
353 if (NT_STATUS_IS_OK(ret
) && ids
[i
]->status
== ID_MAPPED
) {
359 if (num_tomap
== num_mapped
) {
362 if (num_mapped
== 0) {
363 return NT_STATUS_NONE_MAPPED
;
366 return STATUS_SOME_UNMAPPED
;
373 static bool idmap_autorid_sid_is_special(struct dom_sid
*sid
)
377 match
= sid_check_is_in_wellknown_domain(sid
);
385 static NTSTATUS
idmap_autorid_sid_to_id_special(struct idmap_domain
*dom
,
388 struct idmap_tdb_common_context
*common
=
389 talloc_get_type_abort(dom
->private_data
,
390 struct idmap_tdb_common_context
);
392 struct autorid_range_config range
;
396 status
= idmap_autorid_get_alloc_range(dom
, &range
);
397 if (!NT_STATUS_IS_OK(status
)) {
401 /* Take the next free ID, counting from the top */
403 for (count
= 0; count
< IDMAP_AUTORID_ALLOC_RESERVED
; count
++) {
404 struct id_map test_map
;
408 test_map
.xid
.type
= map
->xid
.type
;
409 test_map
.xid
.id
= range
.high_id
- count
;
410 test_map
.status
= ID_UNKNOWN
;
412 status
= idmap_tdb_common_unixid_to_sid(dom
, &test_map
);
413 if (NT_STATUS_EQUAL(NT_STATUS_NONE_MAPPED
, status
)) {
414 free_id
= test_map
.xid
.id
;
418 if (!NT_STATUS_IS_OK(status
)) {
419 /* error - get out */
423 /* mapping exists - try next ID */
427 return NT_STATUS_NONE_MAPPED
;
430 map
->status
= ID_MAPPED
;
431 map
->xid
.id
= free_id
;
433 status
= common
->rw_ops
->set_mapping(dom
, map
);
434 if (!NT_STATUS_IS_OK(status
)) {
435 DEBUG(2, ("Error storing new mapping: %s\n",
443 struct idmap_autorid_sid_to_id_alloc_ctx
{
444 struct idmap_domain
*dom
;
448 static NTSTATUS
idmap_autorid_sid_to_id_alloc_action(
449 struct db_context
*db
,
452 struct idmap_autorid_sid_to_id_alloc_ctx
*ctx
;
454 ctx
= (struct idmap_autorid_sid_to_id_alloc_ctx
*)private_data
;
456 if (idmap_autorid_sid_is_special(ctx
->map
->sid
)) {
457 struct dom_sid_buf buf
;
460 ret
= idmap_autorid_sid_to_id_special(ctx
->dom
, ctx
->map
);
461 if (NT_STATUS_IS_OK(ret
)) {
464 if (!NT_STATUS_EQUAL(NT_STATUS_NONE_MAPPED
, ret
)) {
468 DEBUG(10, ("Special sid %s not mapped. falling back to "
469 "regular allocation\n",
470 dom_sid_str_buf(ctx
->map
->sid
, &buf
)));
473 return idmap_tdb_common_new_mapping(ctx
->dom
, ctx
->map
);
477 * map a SID to xid using the idmap_tdb like pool
479 static NTSTATUS
idmap_autorid_sid_to_id_alloc(
480 struct idmap_tdb_common_context
*ctx
,
481 struct idmap_domain
*dom
,
485 struct idmap_autorid_sid_to_id_alloc_ctx alloc_ctx
;
486 struct dom_sid_buf buf
;
488 map
->status
= ID_UNKNOWN
;
490 /* see if we already have a mapping */
491 ret
= idmap_tdb_common_sid_to_unixid(dom
, map
);
493 if (NT_STATUS_IS_OK(ret
)) {
494 map
->status
= ID_MAPPED
;
498 /* bad things happened */
499 if (!NT_STATUS_EQUAL(ret
, NT_STATUS_NONE_MAPPED
)) {
500 DEBUG(1, ("Looking up SID->ID mapping for %s failed: %s\n",
501 dom_sid_str_buf(map
->sid
, &buf
),
506 if (dom
->read_only
) {
507 DEBUG(3, ("Not allocating new mapping for %s, because backend "
509 dom_sid_str_buf(map
->sid
, &buf
)));
510 map
->status
= ID_UNMAPPED
;
511 return NT_STATUS_NONE_MAPPED
;
514 DEBUG(10, ("Creating new mapping in pool for %s\n",
515 dom_sid_str_buf(map
->sid
, &buf
)));
520 ret
= dbwrap_trans_do(ctx
->db
, idmap_autorid_sid_to_id_alloc_action
,
522 if (!NT_STATUS_IS_OK(ret
)) {
523 DEBUG(1, ("Failed to create a new mapping in alloc range: %s\n",
525 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
528 map
->status
= ID_MAPPED
;
532 static bool idmap_autorid_domsid_is_for_alloc(struct dom_sid
*sid
)
536 match
= sid_check_is_wellknown_domain(sid
, NULL
);
544 static NTSTATUS
idmap_autorid_sid_to_id(struct idmap_tdb_common_context
*common
,
545 struct idmap_domain
*dom
,
548 struct autorid_global_config
*global
=
549 talloc_get_type_abort(common
->private_data
,
550 struct autorid_global_config
);
551 struct autorid_range_config range
;
553 struct dom_sid domainsid
;
554 struct dom_sid_buf buf
;
558 map
->status
= ID_UNKNOWN
;
560 DEBUG(10, ("Trying to map %s\n", dom_sid_str_buf(map
->sid
, &buf
)));
562 sid_copy(&domainsid
, map
->sid
);
563 if (!sid_split_rid(&domainsid
, &rid
)) {
564 DEBUG(4, ("Could not determine domain SID from %s, "
565 "ignoring mapping request\n",
566 dom_sid_str_buf(map
->sid
, &buf
)));
567 map
->status
= ID_UNMAPPED
;
568 return NT_STATUS_NONE_MAPPED
;
571 if (idmap_autorid_domsid_is_for_alloc(&domainsid
)) {
572 DEBUG(10, ("SID %s is for ALLOC range.\n",
573 dom_sid_str_buf(map
->sid
, &buf
)));
575 return idmap_autorid_sid_to_id_alloc(common
, dom
, map
);
578 if (dom_sid_equal(&domainsid
, &global_sid_Builtin
) && ignore_builtin
) {
579 DEBUG(10, ("Ignoring request for BUILTIN domain\n"));
580 map
->status
= ID_UNMAPPED
;
581 return NT_STATUS_NONE_MAPPED
;
584 sid_to_fstring(range
.domsid
, &domainsid
);
586 range
.domain_range_index
= rid
/ (global
->rangesize
);
588 ret
= idmap_autorid_getrange(autorid_db
, range
.domsid
,
589 range
.domain_range_index
,
590 &range
.rangenum
, &range
.low_id
);
591 if (NT_STATUS_IS_OK(ret
)) {
592 return idmap_autorid_sid_to_id_rid(
593 global
->rangesize
, range
.low_id
, map
);
596 if (dom
->read_only
) {
597 DBG_DEBUG("read-only is enabled, did not allocate "
598 "new range for domain %s\n", range
.domsid
);
599 map
->status
= ID_UNMAPPED
;
600 return NT_STATUS_NONE_MAPPED
;
604 * Check if we should allocate a domain range. We need to
605 * protect against unknown domains to not fill our ranges
609 if (sid_check_is_builtin(&domainsid
) ||
610 sid_check_is_our_sam(&domainsid
)) {
615 struct winbindd_domain
*domain
;
618 * Deterministic check for domain members: We can be
619 * sure that the domain we are member of is worth to
623 domain
= find_our_domain();
624 if ((domain
!= NULL
) &&
625 dom_sid_equal(&domain
->sid
, &domainsid
)) {
631 * If we have already allocated range index 0, this domain is
632 * worth allocating for in higher ranges.
634 if (range
.domain_range_index
!= 0) {
635 uint32_t zero_rangenum
, zero_low_id
;
637 ret
= idmap_autorid_getrange(autorid_db
, range
.domsid
, 0,
638 &zero_rangenum
, &zero_low_id
);
639 if (NT_STATUS_IS_OK(ret
)) {
645 * If the caller already did a lookup sid and made sure the
646 * domain sid is valid, we can allocate a new range.
648 * Currently the winbindd parent already does a lookup sids
649 * first, but hopefully changes in future. If the
650 * caller knows the domain sid, ID_TYPE_BOTH should be
651 * passed instead of ID_TYPE_NOT_SPECIFIED.
653 if (map
->xid
.type
!= ID_TYPE_NOT_SPECIFIED
) {
658 * Check of last resort: A domain is valid if a user from that
659 * domain has recently logged in. The samlogon_cache these
660 * days also stores the domain sid.
662 * We used to check the list of trusted domains we received
663 * from "our" dc, but this is not reliable enough.
665 if (netsamlogon_cache_have(&domainsid
)) {
670 * Nobody knows this domain, so refuse to allocate a fresh
674 DBG_NOTICE("Allocating range for domain %s required type_hint\n", range
.domsid
);
675 map
->status
= ID_REQUIRE_TYPE
;
676 return NT_STATUS_SOME_NOT_MAPPED
;
679 ret
= idmap_autorid_acquire_range(autorid_db
, &range
);
680 if (!NT_STATUS_IS_OK(ret
)) {
681 DBG_NOTICE("Could not determine range for domain: %s, "
682 "check previous messages for reason\n",
687 return idmap_autorid_sid_to_id_rid(global
->rangesize
, range
.low_id
,
691 /**********************************
692 lookup a set of sids.
693 **********************************/
695 static NTSTATUS
idmap_autorid_sids_to_unixids(struct idmap_domain
*dom
,
698 struct idmap_tdb_common_context
*commoncfg
;
701 size_t num_tomap
= 0;
702 size_t num_mapped
= 0;
703 size_t num_required
= 0;
705 /* initialize the status to avoid surprise */
706 for (i
= 0; ids
[i
]; i
++) {
707 ids
[i
]->status
= ID_UNKNOWN
;
712 talloc_get_type_abort(dom
->private_data
,
713 struct idmap_tdb_common_context
);
715 for (i
= 0; ids
[i
]; i
++) {
716 ret
= idmap_autorid_sid_to_id(commoncfg
, dom
, ids
[i
]);
717 if (NT_STATUS_EQUAL(ret
, NT_STATUS_SOME_NOT_MAPPED
) &&
718 ids
[i
]->status
== ID_REQUIRE_TYPE
)
723 if ((!NT_STATUS_IS_OK(ret
)) &&
724 (!NT_STATUS_EQUAL(ret
, NT_STATUS_NONE_MAPPED
))) {
725 struct dom_sid_buf buf
;
726 /* some fatal error occurred, log it */
727 DEBUG(3, ("Unexpected error resolving a SID (%s)\n",
728 dom_sid_str_buf(ids
[i
]->sid
, &buf
)));
732 if (NT_STATUS_IS_OK(ret
) && ids
[i
]->status
== ID_MAPPED
) {
737 if (num_tomap
== num_mapped
) {
739 } else if (num_required
> 0) {
740 return STATUS_SOME_UNMAPPED
;
741 } else if (num_mapped
== 0) {
742 return NT_STATUS_NONE_MAPPED
;
745 return STATUS_SOME_UNMAPPED
;
748 static NTSTATUS
idmap_autorid_preallocate_wellknown(struct idmap_domain
*dom
)
750 const char *groups
[] = { "S-1-1-0", "S-1-2-0", "S-1-2-1",
751 "S-1-3-0", "S-1-3-1", "S-1-3-2", "S-1-3-3", "S-1-3-4",
752 "S-1-5-1", "S-1-5-2", "S-1-5-3", "S-1-5-4", "S-1-5-6",
753 "S-1-5-7", "S-1-5-8", "S-1-5-9", "S-1-5-10", "S-1-5-11",
754 "S-1-5-12", "S-1-5-13", "S-1-5-14", "S-1-5-15",
755 "S-1-5-17", "S-1-5-18", "S-1-5-19", "S-1-5-20"
758 struct id_map
**maps
;
762 if (dom
->read_only
) {
766 num
= ARRAY_SIZE(groups
);
768 maps
= talloc_array(talloc_tos(), struct id_map
*, num
+1);
770 return NT_STATUS_NO_MEMORY
;
773 for (i
= 0; i
< num
; i
++) {
774 maps
[i
] = talloc(maps
, struct id_map
);
775 if (maps
[i
] == NULL
) {
777 return NT_STATUS_NO_MEMORY
;
779 maps
[i
]->xid
.type
= ID_TYPE_GID
;
780 maps
[i
]->sid
= dom_sid_parse_talloc(maps
, groups
[i
]);
785 status
= idmap_autorid_sids_to_unixids(dom
, maps
);
787 DEBUG(10,("Preallocation run finished with status %s\n",
792 return NT_STATUS_IS_OK(status
)?NT_STATUS_OK
:NT_STATUS_UNSUCCESSFUL
;
795 static NTSTATUS
idmap_autorid_initialize_action(struct db_context
*db
,
798 struct idmap_domain
*dom
;
799 struct idmap_tdb_common_context
*common
;
800 struct autorid_global_config
*config
;
803 dom
= (struct idmap_domain
*)private_data
;
804 common
= (struct idmap_tdb_common_context
*)dom
->private_data
;
805 config
= (struct autorid_global_config
*)common
->private_data
;
807 status
= idmap_autorid_init_hwms(db
);
808 if (!NT_STATUS_IS_OK(status
)) {
812 status
= idmap_autorid_saveconfig(db
, config
);
813 if (!NT_STATUS_IS_OK(status
)) {
814 DEBUG(1, ("Failed to store configuration data!\n"));
818 status
= idmap_autorid_preallocate_wellknown(dom
);
819 if (!NT_STATUS_IS_OK(status
)) {
820 DEBUG(1, ("Failed to preallocate wellknown sids: %s\n",
828 static NTSTATUS
idmap_autorid_initialize(struct idmap_domain
*dom
)
830 struct idmap_tdb_common_context
*commonconfig
;
831 struct autorid_global_config
*config
;
835 if (!strequal(dom
->name
, "*")) {
836 DEBUG(0, ("idmap_autorid_initialize: Error: autorid configured "
837 "for domain '%s'. But autorid can only be used for "
838 "the default idmap configuration.\n", dom
->name
));
839 return NT_STATUS_INVALID_PARAMETER
;
842 commonconfig
= talloc_zero(dom
, struct idmap_tdb_common_context
);
844 DEBUG(0, ("Out of memory!\n"));
845 return NT_STATUS_NO_MEMORY
;
847 dom
->private_data
= commonconfig
;
849 commonconfig
->rw_ops
= talloc_zero(commonconfig
, struct idmap_rw_ops
);
850 if (commonconfig
->rw_ops
== NULL
) {
851 DEBUG(0, ("Out of memory!\n"));
852 return NT_STATUS_NO_MEMORY
;
855 config
= talloc_zero(commonconfig
, struct autorid_global_config
);
857 DEBUG(0, ("Out of memory!\n"));
858 return NT_STATUS_NO_MEMORY
;
860 commonconfig
->private_data
= config
;
862 config
->minvalue
= dom
->low_id
;
863 config
->rangesize
= idmap_config_int("*", "rangesize", 100000);
865 config
->maxranges
= (dom
->high_id
- dom
->low_id
+ 1) /
868 if (config
->maxranges
< 2) {
869 DBG_WARNING("Allowed idmap range is not a least double the "
870 "size of the rangesize. Please increase idmap "
872 status
= NT_STATUS_INVALID_PARAMETER
;
876 /* check if the high-low limit is a multiple of the rangesize */
877 if ((dom
->high_id
- dom
->low_id
+ 1) % config
->rangesize
!= 0) {
878 DEBUG(5, ("High uid-low uid difference of %d "
879 "is not a multiple of the rangesize %d, "
880 "limiting ranges to lower boundary number of %d\n",
881 (dom
->high_id
- dom
->low_id
+ 1), config
->rangesize
,
885 DEBUG(5, ("%d domain ranges with a size of %d are available\n",
886 config
->maxranges
, config
->rangesize
));
888 ignore_builtin
= idmap_config_bool("*", "ignore builtin", false);
890 /* fill the TDB common configuration */
892 commonconfig
->max_id
= config
->rangesize
- 1
893 - IDMAP_AUTORID_ALLOC_RESERVED
;
894 commonconfig
->hwmkey_uid
= ALLOC_HWM_UID
;
895 commonconfig
->hwmkey_gid
= ALLOC_HWM_GID
;
896 commonconfig
->rw_ops
->get_new_id
= idmap_autorid_allocate_id
;
897 commonconfig
->rw_ops
->set_mapping
= idmap_tdb_common_set_mapping
;
899 db_path
= state_path(talloc_tos(), "autorid.tdb");
900 if (db_path
== NULL
) {
901 status
= NT_STATUS_NO_MEMORY
;
905 status
= idmap_autorid_db_open(db_path
,
906 NULL
, /* TALLOC_CTX */
908 TALLOC_FREE(db_path
);
909 if (!NT_STATUS_IS_OK(status
)) {
913 commonconfig
->db
= autorid_db
;
915 status
= dbwrap_trans_do(autorid_db
,
916 idmap_autorid_initialize_action
,
918 if (!NT_STATUS_IS_OK(status
)) {
919 DEBUG(1, ("Failed to init the idmap database: %s\n",
933 static const struct idmap_methods autorid_methods
= {
934 .init
= idmap_autorid_initialize
,
935 .unixids_to_sids
= idmap_autorid_unixids_to_sids
,
936 .sids_to_unixids
= idmap_autorid_sids_to_unixids
,
937 .allocate_id
= idmap_autorid_allocate_id
941 NTSTATUS
idmap_autorid_init(TALLOC_CTX
*ctx
)
943 return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION
,
944 "autorid", &autorid_methods
);