in reply to Looking for highest uidNumber in ldap

What do you need it for? Just letting Net::LDAP->add() deal w/it automatically isn't sufficient? I don't see anything specific in Net::LDAP that does it, so your approach (find all & sort & pop) seems like the way to go. Just two comments:

Replies are listed 'Best First'.
Re^2: Looking for highest uidNumber in ldap
by strat (Canon) on May 15, 2005 at 10:20 UTC

    Do you add the objects to the ldap directory? Have you got total control about this process? If yes, perhaps you could create an object which contains just the last used uidNumber, and read it at the beginning of each import or sync, and if new objects are to be created, just increase it and write it back. With this solution, you can also create more-than-life-long-unique uidNumbers for each person

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

Re^2: Looking for highest uidNumber in ldap
by rlb3 (Deacon) on May 14, 2005 at 19:26 UTC

    Thanks for the reply.

    Where is it documented that $ldap->add() increments uidNumber? Knowing that would have saved me some heartache.

      Hmm. I'm actually not familiar w/the internals of LDAP -- i just assumed that uidNumber was a LDAP primary key (thus unique and auto-incrementing), so that it would be necessary for add() (really whatever "ADD" command it sends to the ldap server) to result in the sequence (internal to the ldap server) being incremented .. So if the only need for trying to find the highest uidNumber was just to feed it back into add(), it didn't seem necessary, but I assume there's a broader need for it that i'm just missing...
Re^2: Looking for highest uidNumber in ldap
by g0n (Priest) on May 17, 2005 at 11:34 UTC
    $ldap->add() doesn't increment the uidNumber. If the uidNumber attribute is supposed to be unique in the directory, and you attempt to write one that exists, the directory will return a constraint violation.

    If the uidNumber attribute does not have a uniqueness constraint, the directory will accept it and write it in.

    LDAP does not have the concept of 'primary keys' as such. Each entry in LDAP is 'keyed' by it's distinguished name, which is made up of the distinguished name of its parent container, and its own naming attribute (often cn). So within container "ou=container,o=company" the cn must be unique (assuming cn is the naming attribute), but in "ou=container1,o=company" you can duplicate a cn that is already used in ou=container. Unless you define a constraint against an attribute, the only thing that must be unique is the distinguished name (dn).

    By default, iPlanet used to (and possibly still does - I work on a heavily customised iPlanet environment) have a uniqueness constraint on the uid attribute across the whole directory tree. If thats the case with the OP's directory environment on uidNumber, then attempting to write a uidNumber attribute that's already been used will result in a constraint violation. I would not recommend catching that error and incrementing until the error doesn't occur as an approach BTW, because LDAP is optimised for reads, not writes.

    strat's approach or a SSS (see my post below) would be the most LDAP'ish. Of the two strat's is the better method.

    Update:

    Hmm. I'm actually not familiar w/the internals of LDAP -- i just assumed that uidNumber was a LDAP primary key (thus unique and auto-incrementing)

    As per above, LDAP doesn't have the concept of primary keys, and most databases don't create numeric auto incrementing primary keys unless you tell them to. They generally have a ROWID or similar which is numeric and auto incrementing, but thats not the same thing as a primary key.

    --------------------------------------------------------------

    g0n, backpropagated monk