@@ -72,24 +72,22 @@ public function init($firstname, $lastname, $email, $org, $send_mail = true)
72
72
//
73
73
// Create LDAP user
74
74
//
75
- $ ldapUserEntry = $ this ->entry ;
76
-
77
- if (!$ ldapUserEntry ->exists ()) {
78
- $ ldapUserEntry ->setAttribute ("objectclass " , UnityLDAP::POSIX_ACCOUNT_CLASS );
79
- $ ldapUserEntry ->setAttribute ("uid " , $ this ->uid );
80
- $ ldapUserEntry ->setAttribute ("givenname " , $ firstname );
81
- $ ldapUserEntry ->setAttribute ("sn " , $ lastname );
82
- $ ldapUserEntry ->setAttribute (
75
+ if (!$ this ->entry ->exists ()) {
76
+ $ this ->entry ->setAttribute ("objectclass " , UnityLDAP::POSIX_ACCOUNT_CLASS );
77
+ $ this ->entry ->setAttribute ("uid " , $ this ->uid );
78
+ $ this ->entry ->setAttribute ("givenname " , $ firstname );
79
+ $ this ->entry ->setAttribute ("sn " , $ lastname );
80
+ $ this ->entry ->setAttribute (
83
81
"gecos " ,
84
82
\transliterator_transliterate ("Latin-ASCII " , "$ firstname $ lastname " )
85
83
);
86
- $ ldapUserEntry ->setAttribute ("mail " , $ email );
87
- $ ldapUserEntry ->setAttribute ("o " , $ org );
88
- $ ldapUserEntry ->setAttribute ("homedirectory " , self ::HOME_DIR . $ this ->uid );
89
- $ ldapUserEntry ->setAttribute ("loginshell " , $ this ->LDAP ->getDefUserShell ());
90
- $ ldapUserEntry ->setAttribute ("uidnumber " , strval ($ id ));
91
- $ ldapUserEntry ->setAttribute ("gidnumber " , strval ($ id ));
92
- $ ldapUserEntry ->write ();
84
+ $ this -> entry ->setAttribute ("mail " , $ email );
85
+ $ this -> entry ->setAttribute ("o " , $ org );
86
+ $ this -> entry ->setAttribute ("homedirectory " , self ::HOME_DIR . $ this ->uid );
87
+ $ this -> entry ->setAttribute ("loginshell " , $ this ->LDAP ->getDefUserShell ());
88
+ $ this -> entry ->setAttribute ("uidnumber " , strval ($ id ));
89
+ $ this -> entry ->setAttribute ("gidnumber " , strval ($ id ));
90
+ $ this -> entry ->write ();
93
91
}
94
92
95
93
// update cache
@@ -174,9 +172,8 @@ public function getUID()
174
172
175
173
public function setOrg ($ org )
176
174
{
177
- $ ldap_user = $ this ->entry ;
178
- $ ldap_user ->setAttribute ("o " , $ org );
179
- $ ldap_user ->write ();
175
+ $ this ->entry ->setAttribute ("o " , $ org );
176
+ $ this ->entry ->write ();
180
177
$ this ->REDIS ->setCache ($ this ->uid , "org " , $ org );
181
178
}
182
179
@@ -210,8 +207,7 @@ public function getOrg($ignorecache = false)
210
207
*/
211
208
public function setFirstname ($ firstname , $ operator = null )
212
209
{
213
- $ ldap_user = $ this ->entry ;
214
- $ ldap_user ->setAttribute ("givenname " , $ firstname );
210
+ $ this ->entry ->setAttribute ("givenname " , $ firstname );
215
211
$ operator = is_null ($ operator ) ? $ this ->getUID () : $ operator ->getUID ();
216
212
217
213
$ this ->SQL ->addLog (
@@ -221,7 +217,7 @@ public function setFirstname($firstname, $operator = null)
221
217
$ this ->getUID ()
222
218
);
223
219
224
- $ ldap_user ->write ();
220
+ $ this -> entry ->write ();
225
221
$ this ->REDIS ->setCache ($ this ->uid , "firstname " , $ firstname );
226
222
}
227
223
@@ -260,8 +256,7 @@ public function getFirstname($ignorecache = false)
260
256
*/
261
257
public function setLastname ($ lastname , $ operator = null )
262
258
{
263
- $ ldap_user = $ this ->entry ;
264
- $ ldap_user ->setAttribute ("sn " , $ lastname );
259
+ $ this ->entry ->setAttribute ("sn " , $ lastname );
265
260
$ operator = is_null ($ operator ) ? $ this ->getUID () : $ operator ->getUID ();
266
261
267
262
$ this ->SQL ->addLog (
@@ -316,8 +311,7 @@ public function getFullname()
316
311
*/
317
312
public function setMail ($ email , $ operator = null )
318
313
{
319
- $ ldap_user = $ this ->entry ;
320
- $ ldap_user ->setAttribute ("mail " , $ email );
314
+ $ this ->entry ->setAttribute ("mail " , $ email );
321
315
$ operator = is_null ($ operator ) ? $ this ->getUID () : $ operator ->getUID ();
322
316
323
317
$ this ->SQL ->addLog (
@@ -366,12 +360,11 @@ public function getMail($ignorecache = false)
366
360
*/
367
361
public function setSSHKeys ($ keys , $ operator = null , $ send_mail = true )
368
362
{
369
- $ ldapUser = $ this ->entry ;
370
363
$ operator = is_null ($ operator ) ? $ this ->getUID () : $ operator ->getUID ();
371
364
$ keys_filt = array_values (array_unique ($ keys ));
372
- if ($ ldapUser ->exists ()) {
373
- $ ldapUser ->setAttribute ("sshpublickey " , $ keys_filt );
374
- $ ldapUser ->write ();
365
+ if ($ this -> entry ->exists ()) {
366
+ $ this -> entry ->setAttribute ("sshpublickey " , $ keys_filt );
367
+ $ this -> entry ->write ();
375
368
}
376
369
377
370
$ this ->REDIS ->setCache ($ this ->uid , "sshkeys " , $ keys_filt );
@@ -411,8 +404,7 @@ public function getSSHKeys($ignorecache = false)
411
404
}
412
405
413
406
if ($ this ->exists ()) {
414
- $ ldapUser = $ this ->entry ;
415
- $ result = $ ldapUser ->getAttribute ("sshpublickey " );
407
+ $ result = $ this ->entry ->getAttribute ("sshpublickey " );
416
408
if (is_null ($ result )) {
417
409
$ keys = array ();
418
410
} else {
@@ -446,10 +438,9 @@ public function setLoginShell($shell, $operator = null, $send_mail = true)
446
438
if (empty ($ shell )) {
447
439
throw new Exception ("login shell must not be empty! " );
448
440
}
449
- $ ldapUser = $ this ->entry ;
450
- if ($ ldapUser ->exists ()) {
451
- $ ldapUser ->setAttribute ("loginshell " , $ shell );
452
- $ ldapUser ->write ();
441
+ if ($ this ->entry ->exists ()) {
442
+ $ this ->entry ->setAttribute ("loginshell " , $ shell );
443
+ $ this ->entry ->write ();
453
444
}
454
445
455
446
$ operator = is_null ($ operator ) ? $ this ->getUID () : $ operator ->getUID ();
@@ -488,9 +479,7 @@ public function getLoginShell($ignorecache = false)
488
479
}
489
480
490
481
if ($ this ->exists ()) {
491
- $ ldapUser = $ this ->entry ;
492
-
493
- $ loginshell = $ ldapUser ->getAttribute ("loginshell " )[0 ];
482
+ $ loginshell = $ this ->entry ->getAttribute ("loginshell " )[0 ];
494
483
495
484
if (!$ ignorecache ) {
496
485
$ this ->REDIS ->setCache ($ this ->getUID (), "loginshell " , $ loginshell );
@@ -504,10 +493,9 @@ public function getLoginShell($ignorecache = false)
504
493
505
494
public function setHomeDir ($ home , $ operator = null )
506
495
{
507
- $ ldapUser = $ this ->entry ;
508
- if ($ ldapUser ->exists ()) {
509
- $ ldapUser ->setAttribute ("homedirectory " , $ home );
510
- $ ldapUser ->write ();
496
+ if ($ this ->entry ->exists ()) {
497
+ $ this ->entry ->setAttribute ("homedirectory " , $ home );
498
+ $ this ->entry ->write ();
511
499
$ operator = is_null ($ operator ) ? $ this ->getUID () : $ operator ->getUID ();
512
500
513
501
$ this ->SQL ->addLog (
@@ -537,9 +525,7 @@ public function getHomeDir($ignorecache = false)
537
525
}
538
526
539
527
if ($ this ->exists ()) {
540
- $ ldapUser = $ this ->entry ;
541
-
542
- $ homedir = $ ldapUser ->getAttribute ("homedirectory " );
528
+ $ homedir = $ this ->entry ->getAttribute ("homedirectory " );
543
529
544
530
if (!$ ignorecache ) {
545
531
$ this ->REDIS ->setCache ($ this ->getUID (), "homedir " , $ homedir );
0 commit comments