s3:idmap:autorid: make calculation in idmap_autorid_sid_to_id much more obvious
authorMichael Adam <obnox@samba.org>
Thu, 25 Apr 2013 17:47:00 +0000 (19:47 +0200)
committerChristian Ambach <ambi@samba.org>
Mon, 6 May 2013 14:33:39 +0000 (16:33 +0200)
This is my attempt to make the sid->unix-id calculation much more obvious.
Especially with the introduction of the multi-range support an the originally
named "multiplier", the calculation

id = low_id + range_size * domain_number + rid - range_size * multiplier

was rather opaque to me.

What really happens here is this:
The rid is split into a reduced_rid part that is < rangesize and
a multiple of rangesize. This is given by the formula

rid = rid % range_size + (rid / range_size) * range_size

We define
 reduced_rid := rid % range_size
and
 domain_range_index := rid / range_size ( == the original multiplier)

and the original formula is equivalent to:

id = reduced_rid + low_id + range_number * range_size;

and reads

id = reduced_rid + range_minvalue

if we set range_minvalue := low_id + range_number * range_size.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Christian Ambach <ambi@samba.org>
source3/winbindd/idmap_autorid.c

index ce55af97b6463f6065d0d136e9ba3076e8e05ad5..d0a7b675e3ebcd4e23a1069f63e6af750557b1fb 100644 (file)
@@ -351,12 +351,15 @@ static NTSTATUS idmap_autorid_sid_to_id(struct autorid_global_config *global,
                                        struct id_map *map)
 {
        uint32_t rid;
+       uint32_t reduced_rid;
+       uint32_t range_start;
 
        sid_peek_rid(map->sid, &rid);
 
-       map->xid.id = global->minvalue +
-           (global->rangesize * range->rangenum) + rid -
-           (global->rangesize * range->domain_range_index);
+       reduced_rid = rid % global->rangesize;
+       range_start = global->minvalue + range->rangenum * global->rangesize;
+
+       map->xid.id = reduced_rid + range_start;
        map->xid.type = ID_TYPE_BOTH;
 
        /* We **really** should have some way of validating