1 |
diff -up e-smith-ldap-5.2.0/root/etc/e-smith/events/actions/ldap-update.base_oid e-smith-ldap-5.2.0/root/etc/e-smith/events/actions/ldap-update |
2 |
--- e-smith-ldap-5.2.0/root/etc/e-smith/events/actions/ldap-update.base_oid 2010-09-25 12:11:23.000000000 -0600 |
3 |
+++ e-smith-ldap-5.2.0/root/etc/e-smith/events/actions/ldap-update 2010-09-25 12:13:25.000000000 -0600 |
4 |
@@ -115,6 +115,47 @@ $ldap->bind( |
5 |
password => $pw |
6 |
); |
7 |
|
8 |
+my ($dc,undef) = split (/\./, $domain); |
9 |
+my $o = $l->prop('defaultCompany') || $domain; |
10 |
+ |
11 |
+# Try and find base record |
12 |
+my %seen; |
13 |
+my @objects = qw(top organization dcObject); |
14 |
+my $result = $ldap->search( base => $base, filter => '(objectClass=*)', scope => 'base' ); |
15 |
+warn "failed checking base entry $base: ", $result->error if $result->code; |
16 |
+if ($result->count == 0) |
17 |
+{ |
18 |
+ $result = $ldap->add( $base, attr => [ dc => $dc, o => $o, objectClass => \@objects ] ); |
19 |
+} |
20 |
+else |
21 |
+{ |
22 |
+ # Don't overwrite objectClass (just update if necessary) |
23 |
+ %seen = (); |
24 |
+ @objects = grep { ! $seen{$_} ++ } (@objects, $result->entry(0)->get_value('objectClass') ); |
25 |
+ $ldap->modify( $base, replace => { dc => $dc, o => $o, objectClass => \@objects } ); |
26 |
+} |
27 |
+warn "failed(",$result->code,") to add/update entry $base: ", $result->error if $result->code; |
28 |
+ |
29 |
+# Try and find container records |
30 |
+foreach my $obj ( qw(Users Groups Computers) ) |
31 |
+{ |
32 |
+ @objects = qw(top organizationalUnit); |
33 |
+ $result = $ldap->search( base => $base, filter => "(ou=$obj)" ); |
34 |
+ warn "failed checking base entry ou=$obj,$base: ", $result->error if $result->code; |
35 |
+ if ($result->count == 0) |
36 |
+ { |
37 |
+ $result = $ldap->add( "ou=$obj,$base", attr => [ ou => $obj, objectClass => \@objects ] ); |
38 |
+ } |
39 |
+ else |
40 |
+ { |
41 |
+ # Don't overwrite objectClass (just update if necessary) |
42 |
+ %seen = (); |
43 |
+ @objects = grep { ! $seen{$_} ++ } (@objects, $result->entry(0)->get_value('objectClass') ); |
44 |
+ $result = $ldap->modify( "ou=$obj,$base", replace => { ou => $obj, objectClass => \@objects } ); |
45 |
+ } |
46 |
+ warn "failed to add/update entry ou=$obj,$base: ", $result->error if $result->code; |
47 |
+} |
48 |
+ |
49 |
#------------------------------------------------------------ |
50 |
# Create a list of updates that need to happen |
51 |
#------------------------------------------------------------ |