@@ -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
@@ -164,9 +162,8 @@ public function exists()
164
162
165
163
public function setOrg ($ org )
166
164
{
167
- $ ldap_user = $ this ->entry ;
168
- $ ldap_user ->setAttribute ("o " , $ org );
169
- $ ldap_user ->write ();
165
+ $ this ->entry ->setAttribute ("o " , $ org );
166
+ $ this ->entry ->write ();
170
167
$ this ->REDIS ->setCache ($ this ->uid , "org " , $ org );
171
168
}
172
169
@@ -200,9 +197,8 @@ public function getOrg($ignorecache = false)
200
197
*/
201
198
public function setFirstname ($ firstname , $ operator = null )
202
199
{
203
- $ ldap_user = $ this ->entry ;
204
- $ ldap_user ->setAttribute ("givenname " , $ firstname );
205
- $ operator = is_null ($ operator ) ? $ this ->uid : $ operator ->uid ;
200
+ $ this ->entry ->setAttribute ("givenname " , $ firstname );
201
+ $ operator = is_null ($ operator ) ? $ this ->getUID () : $ operator ->uid ;
206
202
207
203
$ this ->SQL ->addLog (
208
204
$ operator ,
@@ -211,7 +207,7 @@ public function setFirstname($firstname, $operator = null)
211
207
$ this ->uid
212
208
);
213
209
214
- $ ldap_user ->write ();
210
+ $ this -> entry ->write ();
215
211
$ this ->REDIS ->setCache ($ this ->uid , "firstname " , $ firstname );
216
212
}
217
213
@@ -250,9 +246,8 @@ public function getFirstname($ignorecache = false)
250
246
*/
251
247
public function setLastname ($ lastname , $ operator = null )
252
248
{
253
- $ ldap_user = $ this ->entry ;
254
- $ ldap_user ->setAttribute ("sn " , $ lastname );
255
- $ operator = is_null ($ operator ) ? $ this ->uid : $ operator ->uid ;
249
+ $ this ->entry ->setAttribute ("sn " , $ lastname );
250
+ $ operator = is_null ($ operator ) ? $ this ->getUID () : $ operator ->uid ;
256
251
257
252
$ this ->SQL ->addLog (
258
253
$ operator ,
@@ -306,9 +301,8 @@ public function getFullname()
306
301
*/
307
302
public function setMail ($ email , $ operator = null )
308
303
{
309
- $ ldap_user = $ this ->entry ;
310
- $ ldap_user ->setAttribute ("mail " , $ email );
311
- $ operator = is_null ($ operator ) ? $ this ->uid : $ operator ->uid ;
304
+ $ this ->entry ->setAttribute ("mail " , $ email );
305
+ $ operator = is_null ($ operator ) ? $ this ->getUID () : $ operator ->uid ;
312
306
313
307
$ this ->SQL ->addLog (
314
308
$ operator ,
@@ -356,12 +350,11 @@ public function getMail($ignorecache = false)
356
350
*/
357
351
public function setSSHKeys ($ keys , $ operator = null , $ send_mail = true )
358
352
{
359
- $ ldapUser = $ this ->entry ;
360
353
$ operator = is_null ($ operator ) ? $ this ->getUID () : $ operator ->uid ;
361
354
$ keys_filt = array_values (array_unique ($ keys ));
362
- if ($ ldapUser ->exists ()) {
363
- $ ldapUser ->setAttribute ("sshpublickey " , $ keys_filt );
364
- $ ldapUser ->write ();
355
+ if ($ this -> entry ->exists ()) {
356
+ $ this -> entry ->setAttribute ("sshpublickey " , $ keys_filt );
357
+ $ this -> entry ->write ();
365
358
}
366
359
367
360
$ this ->REDIS ->setCache ($ this ->uid , "sshkeys " , $ keys_filt );
@@ -401,8 +394,7 @@ public function getSSHKeys($ignorecache = false)
401
394
}
402
395
403
396
if ($ this ->exists ()) {
404
- $ ldapUser = $ this ->entry ;
405
- $ result = $ ldapUser ->getAttribute ("sshpublickey " );
397
+ $ result = $ this ->entry ->getAttribute ("sshpublickey " );
406
398
if (is_null ($ result )) {
407
399
$ keys = array ();
408
400
} else {
@@ -436,10 +428,9 @@ public function setLoginShell($shell, $operator = null, $send_mail = true)
436
428
if (empty ($ shell )) {
437
429
throw new Exception ("login shell must not be empty! " );
438
430
}
439
- $ ldapUser = $ this ->entry ;
440
- if ($ ldapUser ->exists ()) {
441
- $ ldapUser ->setAttribute ("loginshell " , $ shell );
442
- $ ldapUser ->write ();
431
+ if ($ this ->entry ->exists ()) {
432
+ $ this ->entry ->setAttribute ("loginshell " , $ shell );
433
+ $ this ->entry ->write ();
443
434
}
444
435
445
436
$ operator = is_null ($ operator ) ? $ this ->uid : $ operator ->uid ;
@@ -478,9 +469,7 @@ public function getLoginShell($ignorecache = false)
478
469
}
479
470
480
471
if ($ this ->exists ()) {
481
- $ ldapUser = $ this ->entry ;
482
-
483
- $ loginshell = $ ldapUser ->getAttribute ("loginshell " )[0 ];
472
+ $ loginshell = $ this ->entry ->getAttribute ("loginshell " )[0 ];
484
473
485
474
if (!$ ignorecache ) {
486
475
$ this ->REDIS ->setCache ($ this ->uid , "loginshell " , $ loginshell );
@@ -494,11 +483,10 @@ public function getLoginShell($ignorecache = false)
494
483
495
484
public function setHomeDir ($ home , $ operator = null )
496
485
{
497
- $ ldapUser = $ this ->entry ;
498
- if ($ ldapUser ->exists ()) {
499
- $ ldapUser ->setAttribute ("homedirectory " , $ home );
500
- $ ldapUser ->write ();
501
- $ operator = is_null ($ operator ) ? $ this ->uid : $ operator ->uid ;
486
+ if ($ this ->entry ->exists ()) {
487
+ $ this ->entry ->setAttribute ("homedirectory " , $ home );
488
+ $ this ->entry ->write ();
489
+ $ operator = is_null ($ operator ) ? $ this ->getUID () : $ operator ->uid ;
502
490
503
491
$ this ->SQL ->addLog (
504
492
$ operator ,
@@ -527,9 +515,7 @@ public function getHomeDir($ignorecache = false)
527
515
}
528
516
529
517
if ($ this ->exists ()) {
530
- $ ldapUser = $ this ->entry ;
531
-
532
- $ homedir = $ ldapUser ->getAttribute ("homedirectory " );
518
+ $ homedir = $ this ->entry ->getAttribute ("homedirectory " );
533
519
534
520
if (!$ ignorecache ) {
535
521
$ this ->REDIS ->setCache ($ this ->uid , "homedir " , $ homedir );
0 commit comments