X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fldap.pm;h=a28504313f74fced3b470db897dd0a61b8c5ffe9;hb=96c1150cabe382dbafbdc8f4e89a2719fe24d605;hp=ec1d37fd5e062963a60f3639c56c1769b8259e8d;hpb=789c34c5251f4b831a7cb27bd2a9af700ccf2ced;p=freeside.git diff --git a/FS/FS/part_export/ldap.pm b/FS/FS/part_export/ldap.pm index ec1d37fd5..a28504313 100644 --- a/FS/FS/part_export/ldap.pm +++ b/FS/FS/part_export/ldap.pm @@ -27,7 +27,10 @@ sub _export_insert { $saltset[int(rand(64))].$saltset[int(rand(64))] ); - my %attrib = map { /^\s*(\w+)\s+(.*\S)\s*$/; ( $1 => eval(qq("$2")) ); } + my $username_attrib; + my %attrib = map { /^\s*(\w+)\s+(.*\S)\s*$/; + $username_attrib = $1 if $2 eq '$username'; + ( $1 => eval(qq("$2")) ); } grep { /^\s*(\w+)\s+(.*\S)\s*$/ } split("\n", $self->option('attributes')); @@ -44,6 +47,7 @@ sub _export_insert { my $err_or_queue = $self->ldap_queue( $svc_acct->svcnum, 'insert', #$svc_acct->username, + $username_attrib, %attrib ); return $err_or_queue unless ref($err_or_queue); @@ -202,8 +206,14 @@ sub ldap_queue { } sub ldap_insert { #subroutine, not method - my $dn = ldap_connect(shift, shift, shift); - my %attrib = @_; + my $ldap = ldap_connect(shift, (my $dn = shift), shift); + my( $username_attrib, %attrib ) = @_; + + $dn = "$username_attrib=$attrib{$username_attrib}, $dn" if $username_attrib; + #icky hack, but should be unsurprising to the LDAPers + foreach my $key ( grep { $attrib{$_} =~ /,/ } keys %attrib ) { + $attrib{$key} = [ split(/,/, $attrib{$key}) ]; + } my $status = $ldap->add( $dn, attrs => [ %attrib ] ); die $status->error if $status->is_error; @@ -225,14 +235,16 @@ sub ldap_insert { #subroutine, not method sub ldap_connect { my( $machine, $dn, $password ) = @_; + my %bind_options; + $bind_options{password} = $password if length($password); eval "use Net::LDAP"; die $@ if $@; - my $ldap = Net::LDAP->net($machine) or die $@; - my $status = $ldap->bind( $dn, password=>$password ); + my $ldap = Net::LDAP->new($machine) or die $@; + my $status = $ldap->bind( $dn, %bind_options ); die $status->error if $status->is_error; - $dn; + $ldap; }