Brian May <brian(a)microcomaustralia.com.au> wrote:
This is LDAP, the order the server gives the results
is undefined.
Can you look up a user/group by ID? If so, one idea would be:
1. Perform an initial scan of the users/groups.
2. Cache (i.e., memoize) the greatest uid/gid.
3. To add a new user/group, retrieve the highest uid/gid from the
database/file/whatever, then probe consecutive uids/gids until an unused one
is found, then (locking if necessary) allocate a new user/group and update the
stored value accordingly.
This way you only perform the expensive scan once.