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