[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 #!/usr/bin/perl 2 3 use Net::LDAP; 4 5 require '/etc/SeConfig.ph'; 6 7 $ldap = Net::LDAP->new( 8 "$slapdIp", 9 port => "$slapdPort", 10 debug => "$slapdDebug", 11 timeout => "$slapdTimeout", 12 version => "$slapdVersion" 13 ); 14 $ldap->bind( 15 $adminDn, 16 password => $adminPw 17 ); 18 19 $res = $ldap->search( 20 base => "ou=People,$baseDn", 21 scope => 'one', 22 filter => 'uid=*' 23 ); 24 25 warn $res->error if $res->code != LDAP_SUCCESS; 26 27 foreach $entry ($res->entries) { 28 29 $dn = $entry->dn; 30 $uid = $entry->get_value('uid'); 31 32 if (length($uid) <= 20) { 33 next; 34 } else { 35 $trunkedUid = trunk($uid); 36 37 $res = $ldap->modify( 38 $dn, 39 replace => { 40 mail => "$trunkedUid@$domain", 41 homeDirectory => "/home/$trunkedUid" 42 } 43 ); 44 45 warn $res->error if $res->code != LDAP_SUCCESS; 46 47 $res = $ldap->moddn( 48 $dn, 49 newrdn => "uid=$trunkedUid", 50 deleteoldrdn => '1' 51 ); 52 53 warn $res->error if $res->code != LDAP_SUCCESS; 54 } 55 56 } 57 58 $res = $ldap->search( 59 base => "ou=Groups,$baseDn", 60 scope => 'one', 61 filter => 'owner=*' 62 ); 63 64 warn $res->error if $res->code != LDAP_SUCCESS; 65 66 foreach $entry ($res->entries) { 67 68 $dn = $entry->dn; 69 70 @owners= (); 71 @trunkedOwners= (); 72 73 @owners = $entry->get_value('owner'); 74 75 foreach $owner (@owners) { 76 $res = $ldap->modify( 77 $dn, 78 delete => { owner => $owner } 79 ); 80 warn $res->error if $res->code != LDAP_SUCCESS; 81 $uid = extractUid($owner); 82 if (length($uid) <= 20) { 83 push @trunkedOwners, $owner; 84 } else { 85 $trunkedUid = trunk($uid); 86 $trunkedOwner = concatUid($trunkedUid); 87 push @trunkedOwners, $trunkedOwner; 88 } 89 } 90 91 foreach $owner (@trunkedOwners) { 92 $res = $ldap->modify( 93 $dn, 94 add => { owner => $owner } 95 ); 96 97 warn $res->error if $res->code != LDAP_SUCCESS; 98 } 99 100 } 101 102 $res = $ldap->search( 103 base => "ou=Groups,$baseDn", 104 scope => 'one', 105 filter => 'member=*' 106 ); 107 108 warn $res->error if $res->code != LDAP_SUCCESS; 109 110 foreach $entry ($res->entries) { 111 112 $dn = $entry->dn; 113 114 @members = (); 115 @trunkedMembers = (); 116 117 @members = $entry->get_value('member'); 118 119 foreach $member (@members) { 120 $res = $ldap->modify( 121 $dn, 122 delete => { member => $member } 123 ); 124 warn $res->error if $res->code != LDAP_SUCCESS; 125 $uid = extractUid($member); 126 if (length($uid) <= 20) { 127 push @trunkedMembers, $member; 128 } else { 129 $trunkedUid = trunk($uid); 130 $trunkedMember = concatUid($trunkedUid); 131 push @trunkedMembers, $trunkedMember; 132 } 133 } 134 135 foreach $member (@trunkedMembers) { 136 $res = $ldap->modify( 137 $dn, 138 add => { member => $member } 139 ); 140 141 warn $res->error if $res->code != LDAP_SUCCESS; 142 } 143 144 } 145 146 $res = $ldap->search( 147 base => "ou=Groups,$baseDn", 148 scope => 'one', 149 filter => 'memberUid=*' 150 ); 151 152 warn $res->error if $res->code != LDAP_SUCCESS; 153 154 foreach $entry ($res->entries) { 155 156 $dn = $entry->dn; 157 158 @memberUids = (); 159 @trunkedMemberUids = (); 160 161 @memberUids = $entry->get_value('memberUid'); 162 163 foreach $memberUid (@memberUids) { 164 $res = $ldap->modify( 165 $dn, 166 delete=> { memberUid => $memberUid } 167 ); 168 169 warn $res->error if $res->code != LDAP_SUCCESS; 170 if (length($memberUid) <= 20) { 171 push @trunkedMemberUids, $memberUid; 172 } else { 173 $trunkedUid = trunk($memberUid); 174 push @trunkedMemberUids, $trunkedUid; 175 } 176 } 177 178 foreach $memberUid (@trunkedMemberUids) { 179 $res = $ldap->modify( 180 $dn, 181 add => { memberUid => $memberUid } 182 ); 183 184 warn $res->error if $res->code != LDAP_SUCCESS; 185 } 186 187 } 188 189 sub trunk { 190 191 my $uid = shift; 192 if (length($uid) <= 20) { 193 $trunkedUid = $uid; 194 } else { 195 $uid =~ /([\w\d-\._]{20})/; 196 $trunkedUid = $1; 197 #print "Truncating $uid to $trunkedUid !\n"; 198 } 199 return $trunkedUid; 200 201 } 202 203 sub extractUid { 204 my $member = shift; 205 $member =~ /^uid=([\w\d-\._]+),/; 206 my $uid = $1; 207 return $uid; 208 } 209 210 sub concatUid { 211 my $uid = shift; 212 my $member = "uid=$uid,ou=People,$baseDn"; 213 return $member; 214 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |