[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: Greatest value (or unique id?)

Do you really need a maximum value?
If you are just trying to give
each user a unique id then try this:

pick a random start value;
while ( an ldap_search shows that value is already in the directory ) value++;

This will generally succeed first time
(and only do one highly-targeted LDAP operation).


At 21:32 22/11/00 -0500, weston@itdonline.net wrote:
I ran into this same problem. As far as I know, there is nothing intrinsic in
OpenLDAP that provides for auto-incrementing numbers or searching for the
maximum value, like SQL does. Although, I may be wrong. Here's some pseudo code
for the rather inefficient way I ended up solving this problem. (it's close to
something I wrote in PHP)

ldap_search( uid=* ) //find all entries
new_uidnumber = count(results) + 1 // add 1 to the total
while ( ldap_search( uidnumber=new_uidnumber ) )
      //loop and increment until the new number does
      //not match an existing entry
//Use new number, confident it is unique....

Now, this is probably really dumb code, but it works for me. If anyone has any
other suggestions, please let me know.

Quoting Matthew Hoskins <matth@ponyexpress.net>:

> This might be off topic, and if it is, I'd be happy to repost in the proper
> list.
> Is there a way to search the directory for a maximum value?
> Example:
> My LDAP stores UIDnumbers for users on the UNIX systems we administer.
> create a new user, I need the next available UID (which is the highest UID +
> 1).
> In a standard sql database, I could just set this value as a key and have it
> auto-increment with each new record. Is there a similar feature in LDAP, or
> a search filter that will give me the greatest value of an attribute?
> Thank you for any support. And again, I will be happy to repost in an
> appropriate place.
> Matthew Hoskins -- Cisco Certified Network Associate
> Ponyexpress.net / MagicCablePC / NPGCO
> Systems Administrator

------------------------------------------------- This mail sent through IMP: http://horde.org/imp/

------------------------------------------------- This mail sent through IMP: http://horde.org/imp/