1 |
diff -up e-smith-ldap-5.2.0/root/etc/e-smith/events/actions/ldap-delete.delete_extra_items e-smith-ldap-5.2.0/root/etc/e-smith/events/actions/ldap-delete |
2 |
--- e-smith-ldap-5.2.0/root/etc/e-smith/events/actions/ldap-delete.delete_extra_items 2010-09-26 08:54:29.000000000 -0600 |
3 |
+++ e-smith-ldap-5.2.0/root/etc/e-smith/events/actions/ldap-delete 2010-09-26 09:08:00.000000000 -0600 |
4 |
@@ -57,23 +57,60 @@ $ldap->bind( |
5 |
password => $pw |
6 |
); |
7 |
|
8 |
-my @search_args = (); |
9 |
-if ($event eq 'user-delete'){ |
10 |
- @search_args = ( base => "ou=Users,$base", filter => "uid=$name" ); |
11 |
+# Delete any user object with this name |
12 |
+my $mesg = $ldap->search( base-> "uid=$name,ou=Users,$base", filter => '(ObjectClass=*)', scope => 'base' ); |
13 |
+if ($mesg->code && $mesg->code != 32) |
14 |
+{ |
15 |
+ warn "Failed ldap search uid=$name,ou=Users,$base: ", $mesg->error; |
16 |
} |
17 |
-elsif($event eq 'group-delete'){ |
18 |
- @search_args = ( base => "ou=Groups,$base", filter => "cn=$name" ); |
19 |
+else |
20 |
+{ |
21 |
+ $ldap->delete($mesg->entry(0)); |
22 |
} |
23 |
-my $mesg = $ldap->search(@search_args); |
24 |
|
25 |
-$mesg->code && die "Failed ldap search: ", $mesg->error; |
26 |
+# Delete any computer object with this name |
27 |
+my $mesg = $ldap->search( base-> "uid=$name,ou=Computers,$base", filter => '(ObjectClass=*)', scope => 'base' ); |
28 |
+if ($mesg->code && $mesg->code != 32) |
29 |
+{ |
30 |
+ warn "Failed ldap search uid=$name,ou=Computers,$base: ", $mesg->error; |
31 |
+} |
32 |
+else |
33 |
+{ |
34 |
+ $ldap->delete($mesg->entry(0)); |
35 |
+} |
36 |
|
37 |
-if ($mesg->count > 1) |
38 |
+# Delete any (old) user/computer object with this name |
39 |
+my $mesg = $ldap->search( base-> "uid=$name,$base", filter => '(ObjectClass=*)', scope => 'base' ); |
40 |
+if ($mesg->code && $mesg->code != 32) |
41 |
+{ |
42 |
+ warn "Failed ldap search uid=$name,$base: ", $mesg->error; |
43 |
+} |
44 |
+else |
45 |
{ |
46 |
- die("LDAP search for $name returned $mesg->count - 1 expected\n"); |
47 |
+ $ldap->delete($mesg->entry(0)); |
48 |
} |
49 |
|
50 |
-$ldap->delete($mesg->entry(0)); |
51 |
+# Delete any group object with this name |
52 |
+my $mesg = $ldap->search( base-> "cn=$name,ou=Groups,$base", filter => '(ObjectClass=*)', scope => 'base' ); |
53 |
+if ($mesg->code && $mesg->code != 32) |
54 |
+{ |
55 |
+ warn "Failed ldap search cn=$name,ou=Groups,$base: ", $mesg->error; |
56 |
+} |
57 |
+else |
58 |
+{ |
59 |
+ $ldap->delete($mesg->entry(0)); |
60 |
+} |
61 |
+ |
62 |
+# Delete any (old) group object with this name |
63 |
+my $mesg = $ldap->search( base-> "cn=$name,$base", filter => '(ObjectClass=*)', scope => 'base' ); |
64 |
+if ($mesg->code && $mesg->code != 32) |
65 |
+{ |
66 |
+ warn "Failed ldap search cn=$name,$base: ", $mesg->error; |
67 |
+} |
68 |
+else |
69 |
+{ |
70 |
+ $ldap->delete($mesg->entry(0)); |
71 |
+} |
72 |
|
73 |
$ldap->unbind; |
74 |
|