r107415 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107414‎ | r107415 | r107416 >
Date:20:36, 27 December 2011
Author:laner
Status:resolved
Tags:
Comment:
* Compatibility with LdapAuthentication 2.0a ldap function wrappers
* Initial changes for project-level puppet configuration
Modified paths:
  • /trunk/extensions/OpenStackManager/OpenStackManager.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaDomain.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaHost.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaProject.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaPuppetGroup.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaRole.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaSudoer.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaUser.php (modified) (history)
  • /trunk/extensions/OpenStackManager/openstack.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/OpenStackNovaSudoer.php
@@ -31,11 +31,9 @@
3232 if ( is_array( $sudoerInfo ) ) {
3333 $this->sudoerInfo = $sudoerInfo;
3434 } else {
35 - wfSuppressWarnings();
36 - $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPSudoerBaseDN,
 35+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPSudoerBaseDN,
3736 '(cn=' . $this->sudoername . ')' );
38 - $this->sudoerInfo = ldap_get_entries( $wgAuth->ldapconn, $result );
39 - wfRestoreWarnings();
 37+ $this->sudoerInfo = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
4038 $wgMemc->set( $key, $this->sudoerInfo, 3600 * 24 );
4139 }
4240 if ( $this->sudoerInfo ) {
@@ -138,9 +136,7 @@
139137 $sudoer['sudooption'][] = $option;
140138 }
141139
142 - wfSuppressWarnings();
143 - $success = ldap_modify( $wgAuth->ldapconn, $this->sudoerDN, $sudoer );
144 - wfRestoreWarnings();
 140+ $success = LdapAuthenticationPlugin::ldap_modify( $wgAuth->ldapconn, $this->sudoerDN, $sudoer );
145141 if ( $success ) {
146142 $wgAuth->printDebug( "Successfully modified sudoer $this->sudoerDN", NONSENSITIVE );
147143 return true;
@@ -162,13 +158,9 @@
163159 OpenStackNovaLdapConnection::connect();
164160
165161 $sudoers = array();
166 - wfSuppressWarnings();
167 - $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPSudoerBaseDN, '(&(cn=*)(objectclass=sudorole))' );
168 - wfRestoreWarnings();
 162+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPSudoerBaseDN, '(&(cn=*)(objectclass=sudorole))' );
169163 if ( $result ) {
170 - wfSuppressWarnings();
171 - $entries = ldap_get_entries( $wgAuth->ldapconn, $result );
172 - wfRestoreWarnings();
 164+ $entries = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
173165 if ( $entries ) {
174166 # First entry is always a count
175167 array_shift( $entries );
@@ -232,9 +224,7 @@
233225 $sudoer['cn'] = $sudoername;
234226 $dn = 'cn=' . $sudoername . ',' . $wgOpenStackManagerLDAPSudoerBaseDN;
235227
236 - wfSuppressWarnings();
237 - $success = ldap_add( $wgAuth->ldapconn, $dn, $sudoer );
238 - wfRestoreWarnings();
 228+ $success = LdapAuthenticationPlugin::ldap_add( $wgAuth->ldapconn, $dn, $sudoer );
239229 if ( $success ) {
240230 $wgAuth->printDebug( "Successfully added sudoer $sudoername", NONSENSITIVE );
241231 return new OpenStackNovaSudoer( $sudoername );
@@ -263,9 +253,7 @@
264254 }
265255 $dn = $sudoer->sudoerDN;
266256
267 - wfSuppressWarnings();
268 - $success = ldap_delete( $wgAuth->ldapconn, $dn );
269 - wfRestoreWarnings();
 257+ $success = LdapAuthenticationPlugin::ldap_delete( $wgAuth->ldapconn, $dn );
270258 if ( $success ) {
271259 $wgAuth->printDebug( "Successfully deleted sudoer $sudoername", NONSENSITIVE );
272260 return true;
Index: trunk/extensions/OpenStackManager/OpenStackNovaRole.php
@@ -45,10 +45,8 @@
4646 $dn = $this->project->projectDN;
4747 $query = '(cn=' . $this->rolename . ')';
4848 }
49 - wfSuppressWarnings();
50 - $result = ldap_search( $wgAuth->ldapconn, $dn, $query );
51 - $this->roleInfo = ldap_get_entries( $wgAuth->ldapconn, $result );
52 - wfRestoreWarnings();
 49+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $dn, $query );
 50+ $this->roleInfo = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
5351 if ( $this->roleInfo['count'] != "0" ) {
5452 $this->roleDN = $this->roleInfo[0]['dn'];
5553 }
@@ -117,9 +115,7 @@
118116 foreach ( $members as $member ) {
119117 $values['member'][] = $member;
120118 }
121 - wfSuppressWarnings();
122 - $success = ldap_modify( $wgAuth->ldapconn, $this->roleDN, $values );
123 - wfRestoreWarnings();
 119+ $success = LdapAuthenticationPlugin::ldap_modify( $wgAuth->ldapconn, $this->roleDN, $values );
124120 if ( $success ) {
125121 $this->fetchRoleInfo();
126122 $wgAuth->printDebug( "Successfully removed $user->userDN from $this->roleDN", NONSENSITIVE );
@@ -153,9 +149,7 @@
154150 $members[] = $user->userDN;
155151 $values = array();
156152 $values['member'] = $members;
157 - wfSuppressWarnings();
158 - $success = ldap_modify( $wgAuth->ldapconn, $this->roleDN, $values );
159 - wfRestoreWarnings();
 153+ $success = LdapAuthenticationPlugin::ldap_modify( $wgAuth->ldapconn, $this->roleDN, $values );
160154 if ( $success ) {
161155 $this->fetchRoleInfo();
162156 $wgAuth->printDebug( "Successfully added $user->userDN to $this->roleDN", NONSENSITIVE );
@@ -228,9 +222,7 @@
229223 $role['objectclass'][] = 'groupofnames';
230224 $role['cn'] = $rolename;
231225 $roledn = 'cn=' . $rolename . ',' . $project->projectDN;
232 - wfSuppressWarnings();
233 - $success = ldap_add( $wgAuth->ldapconn, $roledn, $role );
234 - wfRestoreWarnings();
 226+ $success = LdapAuthenticationPlugin::ldap_add( $wgAuth->ldapconn, $roledn, $role );
235227 # TODO: If role addition fails, find a way to fail gracefully
236228 # Though, if the project was added successfully, it is unlikely
237229 # that role addition will fail.
Index: trunk/extensions/OpenStackManager/openstack.sql
@@ -9,6 +9,9 @@
1010 -- Position of group when displayed
1111 group_position int not null
1212
 13+ -- OpenStack project to which this group belongs, if any
 14+ group_project varchar(255) binary,
 15+
1316 ) /*$wgDBTableOptions*/;
1417
1518 CREATE INDEX /*i*/group_name on /*_*/openstack_puppet_groups (group_name);
@@ -26,6 +29,9 @@
2730 -- Position of variable inside its group
2831 var_position int not null
2932
 33+ -- OpenStack project to which this variable belongs, if any
 34+ var_project varchar(255) binary,
 35+
3036 ) /*$wgDBTableOptions*/;
3137
3238 CREATE TABLE /*_*/openstack_puppet_classes (
@@ -41,4 +47,7 @@
4248 -- Position of class inside its group
4349 class_position int not null
4450
 51+ -- OpenStack project to which this class belongs, if any
 52+ class_project varchar(255) binary,
 53+
4554 ) /*$wgDBTableOptions*/;
Index: trunk/extensions/OpenStackManager/OpenStackNovaProject.php
@@ -26,11 +26,9 @@
2727 global $wgAuth;
2828 global $wgOpenStackManagerLDAPProjectBaseDN;
2929
30 - wfSuppressWarnings();
31 - $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPProjectBaseDN,
 30+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPProjectBaseDN,
3231 '(&(cn=' . $this->projectname . ')(owner=*))' );
33 - $this->projectInfo = ldap_get_entries( $wgAuth->ldapconn, $result );
34 - wfRestoreWarnings();
 32+ $this->projectInfo = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
3533 $this->projectDN = $this->projectInfo[0]['dn'];
3634 $this->roles = array();
3735 foreach ( self::$rolenames as $rolename ) {
@@ -113,9 +111,7 @@
114112 foreach ( $members as $member ) {
115113 $values['member'][] = $member;
116114 }
117 - wfSuppressWarnings();
118 - $success = ldap_modify( $wgAuth->ldapconn, $this->projectDN, $values );
119 - wfRestoreWarnings();
 115+ $success = LdapAuthenticationPlugin::ldap_modify( $wgAuth->ldapconn, $this->projectDN, $values );
120116 if ( $success ) {
121117 foreach ( $this->roles as $role ) {
122118 $success = $role->deleteMember( $username );
@@ -156,9 +152,7 @@
157153 $members[] = $user->userDN;
158154 $values = array();
159155 $values['member'] = $members;
160 - wfSuppressWarnings();
161 - $success = ldap_modify( $wgAuth->ldapconn, $this->projectDN, $values );
162 - wfRestoreWarnings();
 156+ $success = LdapAuthenticationPlugin::ldap_modify( $wgAuth->ldapconn, $this->projectDN, $values );
163157 if ( $success ) {
164158 $this->fetchProjectInfo();
165159 $wgAuth->printDebug( "Successfully added $user->userDN to $this->projectDN", NONSENSITIVE );
@@ -198,13 +192,9 @@
199193 OpenStackNovaLdapConnection::connect();
200194
201195 $projects = array();
202 - wfSuppressWarnings();
203 - $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPProjectBaseDN, '(owner=*)' );
204 - wfRestoreWarnings();
 196+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPProjectBaseDN, '(owner=*)' );
205197 if ( $result ) {
206 - wfSuppressWarnings();
207 - $entries = ldap_get_entries( $wgAuth->ldapconn, $result );
208 - wfRestoreWarnings();
 198+ $entries = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
209199 if ( $entries ) {
210200 # First entry is always a count
211201 array_shift( $entries );
@@ -241,9 +231,7 @@
242232 $project['gidnumber'] = OpenStackNovaUser::getNextIdNumber( $wgAuth, 'gidnumber' );
243233 $projectdn = 'cn=' . $projectname . ',' . $wgOpenStackManagerLDAPProjectBaseDN;
244234
245 - wfSuppressWarnings();
246 - $success = ldap_add( $wgAuth->ldapconn, $projectdn, $project );
247 - wfRestoreWarnings();
 235+ $success = LdapAuthenticationPlugin::ldap_add( $wgAuth->ldapconn, $projectdn, $project );
248236 $project = new OpenStackNovaProject( $projectname );
249237 if ( $success ) {
250238 foreach ( self::$rolenames as $rolename ) {
@@ -279,23 +267,19 @@
280268 $dn = $project->projectDN;
281269
282270 # Projects can have roles as sub-entries, we need to delete them first
283 - $result = ldap_list( $wgAuth->ldapconn, $dn, 'objectclass=*' );
284 - $roles = ldap_get_entries( $wgAuth->ldapconn, $result );
 271+ $result = LdapAuthenticationPlugin::ldap_list( $wgAuth->ldapconn, $dn, 'objectclass=*' );
 272+ $roles = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
285273 array_shift( $roles );
286274 foreach ( $roles as $role ) {
287275 $roledn = $role['dn'];
288 - wfSuppressWarnings();
289 - $success = ldap_delete( $wgAuth->ldapconn, $roledn );
290 - wfRestoreWarnings();
 276+ $success = LdapAuthenticationPlugin::ldap_delete( $wgAuth->ldapconn, $roledn );
291277 if ( $success ){
292278 $wgAuth->printDebug( "Successfully deleted role $roledn", NONSENSITIVE );
293279 } else {
294280 $wgAuth->printDebug( "Failed to delete role $roledn", NONSENSITIVE );
295281 }
296282 }
297 - wfSuppressWarnings();
298 - $success = ldap_delete( $wgAuth->ldapconn, $dn );
299 - wfRestoreWarnings();
 283+ $success = LdapAuthenticationPlugin::ldap_delete( $wgAuth->ldapconn, $dn );
300284 if ( $success ) {
301285 $wgAuth->printDebug( "Successfully deleted project $projectname", NONSENSITIVE );
302286 return true;
@@ -319,8 +303,8 @@
320304
321305 OpenStackNovaLdapConnection::connect();
322306
323 - $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPProjectBaseDN, 'owner=*' );
324 - $entries = ldap_get_entries( $wgAuth->ldapconn, $result );
 307+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPProjectBaseDN, 'owner=*' );
 308+ $entries = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
325309 if ( $entries ) {
326310 array_shift( $entries );
327311 foreach ( $entries as $entry ) {
Index: trunk/extensions/OpenStackManager/OpenStackNovaDomain.php
@@ -32,11 +32,9 @@
3333 if ( is_array( $domainInfo ) ) {
3434 $this->domainInfo = $domainInfo;
3535 } else {
36 - wfSuppressWarnings();
37 - $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN,
 36+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN,
3837 '(dc=' . $this->domainname . ')' );
39 - $this->domainInfo = ldap_get_entries( $wgAuth->ldapconn, $result );
40 - wfRestoreWarnings();
 38+ $this->domainInfo = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
4139 $wgMemc->set( $key, $this->domainInfo, 3600 * 24 );
4240 }
4341 if ( $this->domainInfo ) {
@@ -88,9 +86,7 @@
8987
9088 $domain = array();
9189 $domain['soarecord'] = OpenStackNovaDomain::generateSOA();
92 - wfSuppressWarnings();
93 - $success = ldap_modify( $wgAuth->ldapconn, $this->domainDN, $domain );
94 - wfRestoreWarnings();
 90+ $success = LdapAuthenticationPlugin::ldap_modify( $wgAuth->ldapconn, $this->domainDN, $domain );
9591 if ( $success ) {
9692 $wgAuth->printDebug( "Successfully modified soarecord for " . $this->domainDN, NONSENSITIVE );
9793 $this->fetchDomainInfo();
@@ -122,13 +118,9 @@
123119 } else {
124120 $query = '(soarecord=*)';
125121 }
126 - wfSuppressWarnings();
127 - $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN, $query );
128 - wfRestoreWarnings();
 122+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN, $query );
129123 if ( $result ) {
130 - wfSuppressWarnings();
131 - $entries = ldap_get_entries( $wgAuth->ldapconn, $result );
132 - wfRestoreWarnings();
 124+ $entries = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
133125 if ( $entries ) {
134126 # First entry is always a count
135127 array_shift( $entries );
@@ -173,11 +165,9 @@
174166
175167 OpenStackNovaLdapConnection::connect();
176168
177 - wfSuppressWarnings();
178 - $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN,
 169+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN,
179170 '(arecord=' . $ip . ')' );
180 - $hostInfo = ldap_get_entries( $wgAuth->ldapconn, $result );
181 - wfRestoreWarnings();
 171+ $hostInfo = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
182172 if ( $hostInfo['count'] == "0" ) {
183173 return null;
184174 }
@@ -206,11 +196,9 @@
207197
208198 OpenStackNovaLdapConnection::connect();
209199
210 - wfSuppressWarnings();
211 - $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN,
 200+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN,
212201 '(associateddomain=' . $instanceid . '.*)' );
213 - $hostInfo = ldap_get_entries( $wgAuth->ldapconn, $result );
214 - wfRestoreWarnings();
 202+ $hostInfo = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
215203 if ( $hostInfo['count'] == "0" ) {
216204 return null;
217205 }
@@ -258,9 +246,7 @@
259247 }
260248 $dn = 'dc=' . $domainname . ',' . $wgOpenStackManagerLDAPInstanceBaseDN;
261249
262 - wfSuppressWarnings();
263 - $success = ldap_add( $wgAuth->ldapconn, $dn, $domain );
264 - wfRestoreWarnings();
 250+ $success = LdapAuthenticationPlugin::ldap_add( $wgAuth->ldapconn, $dn, $domain );
265251 if ( $success ) {
266252 $wgAuth->printDebug( "Successfully added domain $domainname", NONSENSITIVE );
267253 return new OpenStackNovaDomain( $domainname );
@@ -291,15 +277,12 @@
292278 $dn = $domain->domainDN;
293279
294280 # Domains can have records as sub entries. If sub-entries exist, fail.
295 - $result = ldap_list( $wgAuth->ldapconn, $dn, 'objectclass=*' );
296 - $hosts = ldap_get_entries( $wgAuth->ldapconn, $result );
 281+ $result = LdapAuthenticationPlugin::ldap_list( $wgAuth->ldapconn, $dn, 'objectclass=*' );
 282+ $hosts = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
297283 if ( $hosts['count'] != "0" ) {
298284 $wgAuth->printDebug( "Failed to delete domain $domainname, since it had sub entries", NONSENSITIVE );
299285 return false;
300286 }
301 - wfSuppressWarnings();
302 - $success = ldap_delete( $wgAuth->ldapconn, $dn );
303 - wfRestoreWarnings();
304287 if ( $success ) {
305288 $wgAuth->printDebug( "Successfully deleted domain $domainname", NONSENSITIVE );
306289 return true;
Index: trunk/extensions/OpenStackManager/OpenStackNovaHost.php
@@ -43,10 +43,8 @@
4444
4545 $this->searchvalue = $wgAuth->getLdapEscapedString( $this->searchvalue );
4646 $fqdn = $this->searchvalue . '.' . $this->domain->getFullyQualifiedDomainName();
47 - wfSuppressWarnings();
48 - $result = ldap_search( $wgAuth->ldapconn, $this->domain->domainDN, '(|(associateddomain=' . $fqdn . ')(cnamerecord=' . $fqdn . ')(dc=' . $this->searchvalue . '))' );
49 - $this->hostInfo = ldap_get_entries( $wgAuth->ldapconn, $result );
50 - wfRestoreWarnings();
 47+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $this->domain->domainDN, '(|(associateddomain=' . $fqdn . ')(cnamerecord=' . $fqdn . ')(dc=' . $this->searchvalue . '))' );
 48+ $this->hostInfo = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
5149 if ( $this->hostInfo["count"] == "0" ) {
5250 $this->hostInfo = null;
5351 } else {
@@ -194,9 +192,7 @@
195193 }
196194 }
197195 if ( $hostEntry ) {
198 - wfSuppressWarnings();
199 - $success = ldap_modify( $wgAuth->ldapconn, $this->hostDN, $hostEntry );
200 - wfRestoreWarnings();
 196+ $success = LdapAuthenticationPlugin::ldap_modify( $wgAuth->ldapconn, $this->hostDN, $hostEntry );
201197 if ( $success ) {
202198 $this->fetchHostInfo();
203199 $wgAuth->printDebug( "Successfully modified puppet configuration for host", NONSENSITIVE );
@@ -236,9 +232,7 @@
237233 foreach ( $associateddomains as $associateddomain ) {
238234 $values['associateddomain'][] = $associateddomain;
239235 }
240 - wfSuppressWarnings();
241 - $success = ldap_modify( $wgAuth->ldapconn, $this->hostDN, $values );
242 - wfRestoreWarnings();
 236+ $success = LdapAuthenticationPlugin::ldap_modify( $wgAuth->ldapconn, $this->hostDN, $values );
243237 if ( $success ) {
244238 $wgAuth->printDebug( "Successfully removed $fqdn from $this->hostDN", NONSENSITIVE );
245239 $this->domain->updateSOA();
@@ -276,9 +270,7 @@
277271 foreach ( $arecords as $arecord ) {
278272 $values['arecord'][] = $arecord;
279273 }
280 - wfSuppressWarnings();
281 - $success = ldap_modify( $wgAuth->ldapconn, $this->hostDN, $values );
282 - wfRestoreWarnings();
 274+ $success = LdapAuthenticationPlugin::ldap_modify( $wgAuth->ldapconn, $this->hostDN, $values );
283275 if ( $success ) {
284276 $wgAuth->printDebug( "Successfully removed $ip from $this->hostDN", NONSENSITIVE );
285277 $this->domain->updateSOA();
@@ -310,9 +302,7 @@
311303 $associatedomains[] = $fqdn;
312304 $values = array();
313305 $values['associateddomain'] = $associatedomains;
314 - wfSuppressWarnings();
315 - $success = ldap_modify( $wgAuth->ldapconn, $this->hostDN, $values );
316 - wfRestoreWarnings();
 306+ $success = LdapAuthenticationPlugin::ldap_modify( $wgAuth->ldapconn, $this->hostDN, $values );
317307 if ( $success ) {
318308 $wgAuth->printDebug( "Successfully added $fqdn to $this->hostDN", NONSENSITIVE );
319309 $this->domain->updateSOA();
@@ -341,9 +331,7 @@
342332 $arecords[] = $ip;
343333 $values = array();
344334 $values['arecord'] = $arecords;
345 - wfSuppressWarnings();
346 - $success = ldap_modify( $wgAuth->ldapconn, $this->hostDN, $values );
347 - wfRestoreWarnings();
 335+ $success = LdapAuthenticationPlugin::ldap_modify( $wgAuth->ldapconn, $this->hostDN, $values );
348336 if ( $success ) {
349337 $wgAuth->printDebug( "Successfully added $ip to $this->hostDN", NONSENSITIVE );
350338 $this->domain->updateSOA();
@@ -365,9 +353,7 @@
366354 global $wgAuth;
367355
368356 $values = array( 'arecord' => array( $ip ) );
369 - wfSuppressWarnings();
370 - $success = ldap_modify( $wgAuth->ldapconn, $this->hostDN, $values );
371 - wfRestoreWarnings();
 357+ $success = LdapAuthenticationPlugin::ldap_modify( $wgAuth->ldapconn, $this->hostDN, $values );
372358 if ( $success ) {
373359 $wgAuth->printDebug( "Successfully set $ip on $this->hostDN", NONSENSITIVE );
374360 $this->domain->updateSOA();
@@ -429,10 +415,8 @@
430416 if ( ! $domain ) {
431417 return null;
432418 }
433 - wfSuppressWarnings();
434 - $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN, '(arecord=' . $ip . ')' );
435 - $hostInfo = ldap_get_entries( $wgAuth->ldapconn, $result );
436 - wfRestoreWarnings();
 419+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN, '(arecord=' . $ip . ')' );
 420+ $hostInfo = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
437421 if ( $hostInfo["count"] == "0" ) {
438422 return null;
439423 } else {
@@ -455,10 +439,8 @@
456440 global $wgAuth;
457441 global $wgOpenStackManagerLDAPInstanceBaseDN;
458442
459 - wfSuppressWarnings();
460 - $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN, '(arecord=' . $ip . ')' );
461 - $hostsInfo = ldap_get_entries( $wgAuth->ldapconn, $result );
462 - wfRestoreWarnings();
 443+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN, '(arecord=' . $ip . ')' );
 444+ $hostsInfo = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
463445 if ( $hostsInfo["count"] == "0" ) {
464446 return array();
465447 } else {
@@ -492,13 +474,9 @@
493475 OpenStackNovaLdapConnection::connect();
494476
495477 $hosts = array();
496 - wfSuppressWarnings();
497 - $result = ldap_search( $wgAuth->ldapconn, $domain->domainDN, '(dc=*)' );
498 - wfRestoreWarnings();
 478+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $domain->domainDN, '(dc=*)' );
499479 if ( $result ) {
500 - wfSuppressWarnings();
501 - $entries = ldap_get_entries( $wgAuth->ldapconn, $result );
502 - wfRestoreWarnings();
 480+ $entries = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
503481 if ( $entries ) {
504482 # First entry is always a count
505483 array_shift( $entries );
@@ -531,9 +509,7 @@
532510 }
533511 $dn = $host->hostDN;
534512
535 - wfSuppressWarnings();
536 - $success = ldap_delete( $wgAuth->ldapconn, $dn );
537 - wfRestoreWarnings();
 513+ $success = LdapAuthenticationPlugin::ldap_delete( $wgAuth->ldapconn, $dn );
538514 if ( $success ) {
539515 $domain->updateSOA();
540516 $wgAuth->printDebug( "Successfully deleted host $hostname", NONSENSITIVE );
@@ -564,9 +540,7 @@
565541 $dn = $host->hostDN;
566542 $domain = $host->getDomain();
567543
568 - wfSuppressWarnings();
569 - $success = ldap_delete( $wgAuth->ldapconn, $dn );
570 - wfRestoreWarnings();
 544+ $success = LdapAuthenticationPlugin::ldap_delete( $wgAuth->ldapconn, $dn );
571545 if ( $success ) {
572546 $domain->updateSOA();
573547 $wgAuth->printDebug( "Successfully deleted host $instanceid", NONSENSITIVE );
@@ -648,9 +622,7 @@
649623 }
650624 $dn = 'dc=' . $instanceid . ',dc=' . $domain->getDomainName() . ',' . $wgOpenStackManagerLDAPInstanceBaseDN;
651625
652 - wfSuppressWarnings();
653 - $success = ldap_add( $wgAuth->ldapconn, $dn, $hostEntry );
654 - wfRestoreWarnings();
 626+ $success = LdapAuthenticationPlugin::ldap_add( $wgAuth->ldapconn, $dn, $hostEntry );
655627 if ( $success ) {
656628 $domain->updateSOA();
657629 $wgAuth->printDebug( "Successfully added host $hostname", NONSENSITIVE );
@@ -693,9 +665,7 @@
694666 $hostEntry['associateddomain'][] = $hostname . '.' . $domainname;
695667 $dn = 'dc=' . $hostname . ',dc=' . $domain->getDomainName() . ',' . $wgOpenStackManagerLDAPInstanceBaseDN;
696668
697 - wfSuppressWarnings();
698 - $success = ldap_add( $wgAuth->ldapconn, $dn, $hostEntry );
699 - wfRestoreWarnings();
 669+ $success = LdapAuthenticationPlugin::ldap_add( $wgAuth->ldapconn, $dn, $hostEntry );
700670 if ( $success ) {
701671 $domain->updateSOA();
702672 $wgAuth->printDebug( "Successfully added public host $hostname", NONSENSITIVE );
Index: trunk/extensions/OpenStackManager/OpenStackNovaUser.php
@@ -107,13 +107,9 @@
108108 # roles do not
109109 $projects = array();
110110 $filter = "(&(owner=*)(member=$this->userDN))";
111 - wfSuppressWarnings();
112 - $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPProjectBaseDN, $filter );
113 - wfRestoreWarnings();
 111+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPProjectBaseDN, $filter );
114112 if ( $result ) {
115 - wfSuppressWarnings();
116 - $entries = ldap_get_entries( $wgAuth->ldapconn, $result );
117 - wfRestoreWarnings();
 113+ $entries = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
118114 if ( $entries ) {
119115 # First entry is always a count
120116 array_shift( $entries );
@@ -145,13 +141,9 @@
146142 global $wgOpenStackManagerLDAPProjectBaseDN;
147143
148144 $filter = "(&(cn=$project)(member=$this->userDN)(owner=*))";
149 - wfSuppressWarnings();
150 - $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPProjectBaseDN, $filter );
151 - wfRestoreWarnings();
 145+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPProjectBaseDN, $filter );
152146 if ( $result ) {
153 - wfSuppressWarnings();
154 - $entries = ldap_get_entries( $wgAuth->ldapconn, $result );
155 - wfRestoreWarnings();
 147+ $entries = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
156148 if ( $entries ) {
157149 if ( $entries['count'] == "0" ) {
158150 $wgAuth->printDebug( "Couldn't find the user in project: $project", NONSENSITIVE );
@@ -195,13 +187,9 @@
196188 return false;
197189 }
198190 $filter = "(&(cn=$role)(member=$this->userDN))";
199 - wfSuppressWarnings();
200 - $result = ldap_search( $wgAuth->ldapconn, $project->projectDN, $filter );
201 - wfRestoreWarnings();
 191+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $project->projectDN, $filter );
202192 if ( $result ) {
203 - wfSuppressWarnings();
204 - $entries = ldap_get_entries( $wgAuth->ldapconn, $result );
205 - wfRestoreWarnings();
 193+ $entries = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
206194 if ( $entries ) {
207195 if ( $entries['count'] == "0" ) {
208196 $wgAuth->printDebug( "Couldn't find the user in role: $role", NONSENSITIVE );
@@ -238,13 +226,9 @@
239227 # Check global role
240228 $roledn = $wgOpenStackManagerLDAPGlobalRoles["$role"];
241229 $filter = "(member=$this->userDN)";
242 - wfSuppressWarnings();
243 - $result = ldap_search( $wgAuth->ldapconn, $roledn, $filter );
244 - wfRestoreWarnings();
 230+ $result = LdapAuthenticationPlugin::ldap_search( $wgAuth->ldapconn, $roledn, $filter );
245231 if ( $result ) {
246 - wfSuppressWarnings();
247 - $entries = ldap_get_entries( $wgAuth->ldapconn, $result );
248 - wfRestoreWarnings();
 232+ $entries = LdapAuthenticationPlugin::ldap_get_entries( $wgAuth->ldapconn, $result );
249233 return ( (int)$entries['count'] > 0 );
250234 }
251235 }
@@ -266,9 +250,7 @@
267251 $keypairs[] = $key;
268252 $values = array();
269253 $values['sshpublickey'] = $keypairs;
270 - wfSuppressWarnings();
271 - $success = ldap_modify( $wgAuth->ldapconn, $this->userDN, $values );
272 - wfRestoreWarnings();
 254+ $success = LdapAuthenticationPlugin::ldap_modify( $wgAuth->ldapconn, $this->userDN, $values );
273255 if ( $success ) {
274256 $wgAuth->printDebug( "Successfully imported the user's sshpublickey", NONSENSITIVE );
275257 $this->fetchUserInfo();
@@ -300,9 +282,7 @@
301283 foreach ( $keypairs as $keypair ) {
302284 $values['sshpublickey'][] = $keypair;
303285 }
304 - wfSuppressWarnings();
305 - $success = ldap_modify( $wgAuth->ldapconn, $this->userDN, $values );
306 - wfRestoreWarnings();
 286+ $success = LdapAuthenticationPlugin::ldap_modify( $wgAuth->ldapconn, $this->userDN, $values );
307287 if ( $success ) {
308288 $wgAuth->printDebug( "Successfully deleted the user's sshpublickey", NONSENSITIVE );
309289 $this->fetchUserInfo();
@@ -351,13 +331,9 @@
352332 $filter = "(objectclass=posixaccount)";
353333 $base = USERDN;
354334 }
355 - wfSuppressWarnings();
356 - $result = ldap_search( $auth->ldapconn, $auth->getBaseDN( $base ), $filter );
357 - wfRestoreWarnings();
 335+ $result = LdapAuthenticationPlugin::ldap_search( $auth->ldapconn, $auth->getBaseDN( $base ), $filter );
358336 if ( $result ) {
359 - wfSuppressWarnings();
360 - $entries = ldap_get_entries( $auth->ldapconn, $result );
361 - wfRestoreWarnings();
 337+ $entries = LdapAuthenticationPlugin::ldap_get_entries( $auth->ldapconn, $result );
362338 if ( $entries ) {
363339 if ( $entries['count'] == "0" ) {
364340 $highest = '500';
@@ -429,13 +405,9 @@
430406 $base = $auth->getBaseDN( USERDN );
431407 # Though the LDAP plugin checks to see if the user account exists,
432408 # it does not check to see if the uid attribute is already used.
433 - wfSuppressWarnings();
434 - $result = ldap_search( $auth->ldapconn, $base, "(uid=$username)" );
435 - wfRestoreWarnings();
 409+ $result = LdapAuthenticationPlugin::ldap_search( $auth->ldapconn, $base, "(uid=$username)" );
436410 if ( $result ) {
437 - wfSuppressWarnings();
438 - $entries = ldap_get_entries( $auth->ldapconn, $result );
439 - wfRestoreWarnings();
 411+ $entries = LdapAuthenticationPlugin::ldap_get_entries( $auth->ldapconn, $result );
440412 if ( (int)$entries['count'] > 0 ) {
441413 $auth->printDebug( "User $username already exists.", NONSENSITIVE );
442414 # uid attribute is already in use, fail.
@@ -473,10 +445,8 @@
474446 */
475447 static function LDAPSetNovaInfo( $auth ) {
476448 OpenStackNovaLdapConnection::connect();
477 - wfSuppressWarnings();
478 - $result = ldap_read( $auth->ldapconn, $auth->userInfo[0]['dn'], '(objectclass=*)', array( 'secretkey', 'accesskey', 'objectclass' ) );
479 - $userInfo = ldap_get_entries( $auth->ldapconn, $result );
480 - wfRestoreWarnings();
 449+ $result = LdapAuthenticationPlugin::ldap_read( $auth->ldapconn, $auth->userInfo[0]['dn'], '(objectclass=*)', array( 'secretkey', 'accesskey', 'objectclass' ) );
 450+ $userInfo = LdapAuthenticationPlugin::ldap_get_entries( $auth->ldapconn, $result );
481451 if ( !isset( $userInfo[0]['accesskey'] ) or !isset( $userInfo[0]['secretkey'] ) ) {
482452 $objectclasses = $userInfo[0]['objectclass'];
483453 # First entry is a count
@@ -494,9 +464,7 @@
495465 $values['secretkey'] = OpenStackNovaUser::uuid4();
496466 $values['isnovaadmin'] = 'FALSE';
497467
498 - wfSuppressWarnings();
499 - $success = ldap_modify( $auth->ldapconn, $auth->userdn, $values );
500 - wfRestoreWarnings();
 468+ $success = LdapAuthenticationPlugin::ldap_modify( $auth->ldapconn, $auth->userdn, $values );
501469 if ( $success ) {
502470 $auth->printDebug( "Successfully modified the user's nova attributes", NONSENSITIVE );
503471 return true;
Index: trunk/extensions/OpenStackManager/OpenStackManager.php
@@ -168,6 +168,12 @@
169169 $updater->addExtensionTable( 'openstack_puppet_groups', "$base/openstack.sql" );
170170 $updater->addExtensionTable( 'openstack_puppet_vars', "$base/openstack.sql" );
171171 $updater->addExtensionTable( 'openstack_puppet_classes', "$base/openstack.sql" );
 172+ $updater->addExtensionField( 'openstack_puppet_groups', 'group_project',
 173+ "$base/schema-changes/openstack_project_field.sql" );
 174+ $updater->addExtensionField( 'openstack_puppet_classes', 'class_project',
 175+ "$base/schema-changes/openstack_project_field.sql" );
 176+ $updater->addExtensionField( 'openstack_puppet_vars', 'var_project',
 177+ "$base/schema-changes/openstack_project_field.sql" );
172178 break;
173179 }
174180 return true;
Index: trunk/extensions/OpenStackManager/OpenStackNovaPuppetGroup.php
@@ -12,10 +12,11 @@
1313 * @param $id Int Database id for the group
1414 * @param $name String User-defined name of the group
1515 */
16 - public function __construct( $id, $name, $position ) {
 16+ public function __construct( $id, $name, $position, $project=null ) {
1717 $this->id = $id;
1818 $this->name = $name;
1919 $this->position = $position;
 20+ $this->project = $project;
2021 $this->loadVars( $id );
2122 $this->loadClasses( $id );
2223 }
@@ -40,6 +41,10 @@
4142 return $this->classes;
4243 }
4344
 45+ public funtion getProject() {
 46+ return $this->project;
 47+ }
 48+
4449 /**
4550 * @param $name string
4651 * @return OpenStackNovaPuppetGroup|null
@@ -97,10 +102,20 @@
98103 }
99104
100105 /**
 106+ * @param $projects array Optionally get list for a set of projects
101107 * @return array
102108 */
103 - public static function getGroupList() {
 109+ public static function getGroupList( $projects = array() ) {
104110 $dbr = wfGetDB( DB_SLAVE );
 111+ $condition = '';
 112+ if ( $projects ) {
 113+ $condition .= 'group_project =';
 114+ foreach ( $projects as $project ) {
 115+ $condition .= $project . ',';
 116+ }
 117+ $condition = $dbr->addQuotes( $condition );
 118+ $condition = $condition[0,-1];
 119+ }
105120 $rows = $dbr->select(
106121 'openstack_puppet_groups',
107122 array(
@@ -108,7 +123,7 @@
109124 'group_name',
110125 'group_position'
111126 ),
112 - '',
 127+ $condition,
113128 __METHOD__,
114129 array( 'ORDER BY' => 'group_position ASC' )
115130 );

Follow-up revisions

RevisionCommit summaryAuthorDate
r107422Use implode rather than a poor foreach equivalent. Follow up to r107415.laner21:12, 27 December 2011

Status & tagging log