On 22/11/04 11:52 pm, John Woodell <[EMAIL PROTECTED]> wrote:
> I'm trying to create a way of provisioning numbers.
> I want to do something likr the command-line code below.
>
> Any suggestions?
>
> -----
>
> my $ldap = Net::LDAP->new("localhost") or die "$@";
> &assign_number("cn=John Doe");
>
> sub assign_number() {
> my ($rdn) = @_;
> $attr = "employeeNumbeNumber";
> # get the next number from LDAP
> my $result = $ldap->search ( base => 'cn=Registry,ou=Utils,'.$base,
> scope => 'base',
> filter => "($attr=*)",
> attrs => [ $attr ] );
> return("# ERROR: registry not found") if ($result->count != 1);
> my $next = $result->entry(0)->get_value($attr);
> # modify the person's entry
> my $mesg = $ldap->modify( $rdn.',ou=People,'.$base,
> changes => [
> delete => [ employeeNumber => [$next]],
> add => [ employeeNumber => $next ],
> ]
> );
> return ("# ERROR: assign failed") if $mesg-> ???
> }
There's no standard operation that will update (atomically or otherwise) two
entries - in your case the cn=Registry entry and the cn=John Doe entry.
So you need to do it in two steps - get the old value from cn=Registry like
you're doing, then change your modify operation so that it updates
cn=Registry (not $rdn). (Also you presumably want to store 1+$next in the
new value for employeeNumber.) If that succeeds, then go ahead and modify
the $rdn entry.
There's a gap between the search and the first modify in which another DUA
could change the value in cn=Registry. You will need a strategy for coping
with that - perhaps retry the search/modify a couple of times and only fail
when all the attempts have failed.
Cheers,
Chris