-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathposixAccount.inc
3974 lines (3873 loc) · 162 KB
/
posixAccount.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
use \LAM\TYPES\TypeManager;
use function LAM\TYPES\getScopeFromTypeId;
use LAM\TYPES\ConfiguredType;
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz
Copyright (C) 2005 - 2018 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Manages Unix accounts for users and hosts.
*
* @package modules
*
* @author Tilo Lutz
* @author Roland Gruber
* @author Michael Duergner
* @author Thomas Manninger
*/
/**
* Manages the object class "posixAccount" for users and hosts.
*
* @package modules
*/
class posixAccount extends baseModule implements passwordService {
// Variables
/** delimiter for lamdaemon commands */
private static $SPLIT_DELIMITER = "###x##y##x###";
/* These two variables keep an array of groups the user is also member of. */
/** current group list */
private $groups;
/** original group list */
private $groups_orig;
/* list of group of names that the user is member of */
/** current group of names list */
private $gonList = array();
/** original group of names list */
private $gonList_orig = array();
/** lamdaemon servers */
private $lamdaemonServers = array();
/** cache for group objects */
private $groupCache = null;
/** cache for group of names objects */
private $gonCache = null;
/** clear text password */
private $clearTextPassword;
/** caches the list of known UIDs */
private $cachedUIDList = null;
/** caches the list of known user names */
private $cachedUserNameList = null;
/** replacements for common umlauts */
private $umlautReplacements = array(
'ä' => 'ae', 'Ä' => 'Ae', 'ö' => 'oe', 'Ö' => 'Oe', 'ü' => 'ue', 'Ü' => 'Ue',
'ß' => 'ss', 'é' => 'e', 'è' => 'e', 'ô' => 'o', 'ç' => 'c'
);
/**
* This function fills the error message array with messages.
**/
function load_Messages() {
// error messages for input checks
$this->messages['minUID'][0] = array('ERROR', _('Users') . ': ' . _('Minimum UID number'), _("Minimum UID number is invalid!"));
$this->messages['maxUID'][0] = array('ERROR', _('Users') . ': ' . _('Maximum UID number'), _("Maximum UID number is invalid!"));
$this->messages['minMachine'][0] = array('ERROR', _('Hosts') . ': ' . _('Minimum UID number'), _("Minimum UID number is invalid!"));
$this->messages['maxMachine'][0] = array('ERROR', _('Hosts') . ': ' . _('Maximum UID number'), _("Maximum UID number is invalid!"));
$this->messages['cmp_UID'][0] = array('ERROR', _('Users') . ': ' . _('Maximum UID number'), _("Maximum UID number must be greater than minimum UID number!"));
$this->messages['cmp_Machine'][0] = array('ERROR', _('Hosts') . ': ' . _('Maximum UID number'), _("Maximum UID number must be greater than minimum UID number!"));
$this->messages['cmp_both'][0] = array('ERROR', _('UID ranges for Unix accounts'), _("The UID ranges for users and hosts overlap! This is a problem because LAM uses the highest UID in use + 1 for new accounts. Please set the minimum UID to equal values or use independent ranges."));
$this->messages['homeDirectory'][0] = array('ERROR', _('Home directory'), _('Homedirectory contains invalid characters.'));
$this->messages['homeDirectory'][1] = array('INFO', _('Home directory'), _('Replaced $user or $group in homedir.'));
$this->messages['homeDirectory'][2] = array('ERROR', _('Account %s:') . ' posixAccount_homedir', _('Homedirectory contains invalid characters.'));
$this->messages['homeDirectory'][3] = array('INFO', _('Home directory'), _('Home directory changed. To keep home directory you have to run the following command as root: \'mv %s %s\''));
$this->messages['uidNumber'][1] = array('ERROR', _('ID-Number'), _('No free ID-Number!'));
$this->messages['uidNumber'][2] = array('WARN', _('ID-Number'), _('It is possible that this ID-number is reused. This can cause several problems because files with old permissions might still exist. To avoid this warning set maxUID to a higher value.'));
$this->messages['uidNumber'][3] = array('ERROR', _('ID-Number'), _('ID is already in use'));
$this->messages['uidNumber'][4] = array('ERROR', _('Account %s:') . ' posixAccount_uid', _('UID must be a number. It has to be inside the UID range which is defined in your configuration profile.'));
$this->messages['uidNumber'][5] = array('INFO', _('UID number'), _('UID number has changed. To keep file ownership you have to run the following command as root: \'find / -uid %s -exec chown %s {} \;\''));
$this->messages['userPassword'][0] = array('ERROR', _('Password'), _('Please enter the same password in both password fields.'));
$this->messages['userPassword'][1] = array('ERROR', _('Password'), _('Password contains invalid characters. Valid characters are:') . ' a-z, A-Z, 0-9 and #*,.;:_-+!%&/|?{[()]}=@$ §°!');
$this->messages['userPassword'][4] = array('ERROR', _('Account %s:') . ' posixAccount_password', _('Password contains invalid characters. Valid characters are:') . ' a-z, A-Z, 0-9 and #*,.;:_-+!%&/|?{[()]}=@$ §°!');
$this->messages['uid'][0] = array('INFO', _('UID'), _('UID has changed. Do you want to change home directory?'));
$this->messages['uid'][1] = array('WARN', _('User name'), _('You are using capital letters. This can cause problems because Windows is not case-sensitive.'));
$this->messages['uid'][2] = array('ERROR', _('User name'), _('User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !'));
$this->messages['uid'][3] = array('WARN', _('Host name'), _('You are using capital letters. This can cause problems because Windows is not case-sensitive.'));
$this->messages['uid'][4] = array('ERROR', _('Host name'), _('Host name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !'));
$this->messages['uid'][5] = array('WARN', _('User name'), _('User name in use (%s). Selected next free user name.'));
$this->messages['uid'][6] = array('WARN', _('Host name'), _('Host name in use (%s). Selected next free host name.'));
$this->messages['uid'][7] = array('ERROR', _('Account %s:') . ' posixAccount_userName', _('User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !'));
$this->messages['uid'][8] = array('ERROR', _('Account %s:') . ' posixAccount_hostName', _('Host name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !'));
$this->messages['uid'][9] = array('WARN', _('Account %s:') . ' posixAccount_userName', _('User name already exists!') . ' ' . _('You might want to use %s instead of %s.') . ' %s');
$this->messages['uid'][10] = array('WARN', _('Account %s:') . ' posixAccount_hostName', _('Host name already exists!') . ' ' . _('You might want to use %s instead of %s.') . ' %s');
$this->messages['gidNumber'][0] = array('ERROR', _('Account %s:') . ' posixAccount_group', _('LAM was unable to find a group with this name!'));
$this->messages['gidNumber'][1] = array('ERROR', _('Account %s:') . ' posixAccount_group', _('This GID number is invalid! Please provide either a number or a group name.'));
$this->messages['gidNumber'][2] = array('INFO', _('GID number'), _('GID number has changed. To keep file ownership you have to run the following command as root: \'find / -gid %s -uid %s -exec chgrp %s {} \;\''));
$this->messages['gecos'][0] = array('ERROR', _('Account %s:') . ' posixAccount_gecos', _('This gecos value is invalid!'));
$this->messages['shell'][0] = array('ERROR', _('Account %s:') . ' posixAccount_shell', _('This login shell is invalid!'));
$this->messages['passwordDisabled'][0] = array('ERROR', _('Account %s:') . ' posixAccount_passwordDisabled', _('This value can only be "true" or "false".'));
$this->messages['cn'][0] = array('ERROR', _('Common name'), _('Please enter a valid common name!'));
$this->messages['cn'][1] = array('ERROR', _('Account %s:') . ' posixAccount_cn', _('Please enter a valid common name!'));
$this->messages['sambaIDPoolDN'][0] = array('ERROR', _('Samba ID pool DN'), _('This is not a valid DN!'));
$this->messages['windowsIDPoolDN'][0] = array('ERROR', _('Windows domain info DN'), _('This is not a valid DN!'));
}
/**
* Returns true if this module can manage accounts of the current type, otherwise false.
*
* @return boolean true if module fits
*/
public function can_manage() {
return in_array($this->get_scope(), array('user', 'host'));
}
/**
* Returns meta data that is interpreted by parent class
*
* @return array array with meta data
*
* @see baseModule::get_metaData()
*/
function get_metaData() {
$return = array();
// icon
$return['icon'] = 'tux.png';
// user specific data
if ($this->get_scope() == "user") {
// LDAP filter
$return["ldap_filter"] = array('or' => "(objectClass=posixAccount)", 'and' => "(!(uid=*$))");
// module dependencies
$return['dependencies'] = array('depends' => array(), 'conflicts' => array());
}
elseif ($this->get_scope() == "host") {
// LDAP filter
$return["ldap_filter"] = array('or' => "(objectClass=posixAccount)");
// module dependencies
$return['dependencies'] = array('depends' => array(), 'conflicts' => array());
}
// alias name
$return["alias"] = _("Unix");
// RDN attributes
$return["RDN"] = array("uid" => "high", "cn" => "low");
// managed object classes
$return['objectClasses'] = array('posixAccount');
// LDAP aliases
$return['LDAPaliases'] = array('commonName' => 'cn', 'userid' => 'uid');
// managed attributes
$return['attributes'] = array('uid', 'uidNumber', 'gidNumber',
'loginShell', 'gecos', 'INFO.userPasswordClearText');
if ($this->get_scope() == "user") {
// self service search attributes
$return['selfServiceSearchAttributes'] = array('uid');
// self service field settings
$return['selfServiceFieldSettings'] = array(
'password' => _('Password'),
'cn' => _('Common name'),
'loginShell' => _('Login shell'),
'syncWindowsPassword' => _('Sync Unix password with Windows password')
);
// possible self service read-only fields
$return['selfServiceReadOnlyFields'] = array('cn', 'loginShell');
// self service configuration settings
$selfServiceContainer = new htmlResponsiveRow();
$selfServiceContainer->add(new htmlResponsiveSelect('posixAccount_pwdHash', getSupportedHashTypes(),
array('SSHA'), _("Password hash type"), array('pwdHash', get_class($this))), 12);
$selfServiceContainer->add(new htmlResponsiveInputTextarea('posixAccount_shells', implode("\r\n", $this->getShells()), 30, 4, _('Login shells'), array('loginShells', get_class($this))), 12);
$selfServiceContainer->add(new htmlResponsiveInputCheckbox('posixAccount_useOldPwd', false, _('Password change with old password'), array('useOldPwd', get_class($this))), 12);
$return['selfServiceSettings'] = $selfServiceContainer;
}
// profile checks
$return['profile_checks']['posixAccount_homeDirectory'] = array('type' => 'ext_preg', 'regex' => 'homeDirectory',
'error_message' => $this->messages['homeDirectory'][0]);
// profile mappings
$return['profile_mappings'] = array(
'posixAccount_loginShell' => 'loginShell'
);
// upload
$return['upload_preDepends'] = array('inetOrgPerson');
// user specific upload options
if (($this->get_scope() == 'user') && isLoggedIn()) {
$return['upload_columns'] = array(
array(
'name' => 'posixAccount_userName',
'description' => _('User name'),
'help' => 'uid',
'example' => _('smiller'),
'required' => true,
'unique' => true
),
array(
'name' => 'posixAccount_uid',
'description' => _('UID number'),
'help' => 'uidNumber',
'example' => '1234'
),
array(
'name' => 'posixAccount_group',
'description' => _('Primary group'),
'help' => 'group_upload',
'example' => _('users'),
'required' => true
),
array(
'name' => 'posixAccount_additionalGroups',
'description' => _('Additional groups'),
'help' => 'addgroup_upload',
'example' => _('group01,group02')
),
array(
'name' => 'posixAccount_homedir',
'description' => _('Home directory'),
'help' => 'homeDirectory_upload',
'example' => _('/home/smiller'),
'default' => '/home/{posixAccount_userName}'
),
array(
'name' => 'posixAccount_createHomeDir',
'description' => _('Create home directory'),
'help' => 'createhomedir',
'example' => 'localhost',
'values' => $_SESSION['config']->get_scriptServers()
),
array(
'name' => 'posixAccount_shell',
'description' => _('Login shell'),
'help' => 'loginShell',
'example' => '/bin/bash',
'values' => implode(", ", $this->getShells()),
'default' => '/bin/bash'
),
array(
'name' => 'posixAccount_password',
'description' => _('Password'),
'help' => 'userPassword',
'example' => _('secret')
),
array(
'name' => 'posixAccount_passwordDisabled',
'description' => _('Lock password'),
'help' => 'userPassword_lock',
'example' => 'false',
'values' => 'true, false',
'default' => 'false'
),
);
if (self::areGroupOfNamesActive()) {
$return['upload_columns'][] = array(
'name' => 'posixAccount_gon',
'description' => _('Groups of names'),
'help' => 'addgroup_upload',
'example' => _('group01,group02')
);
}
}
// host specific upload options
elseif ($this->get_scope() == 'host') {
$return['upload_columns'] = array(
array(
'name' => 'posixAccount_hostName',
'description' => _('Host name'),
'help' => 'uid',
'example' => _('pc01$'),
'required' => true,
'unique' => true
),
array(
'name' => 'posixAccount_uid',
'description' => _('UID number'),
'help' => 'uidNumber',
'example' => '1234'
),
array(
'name' => 'posixAccount_group',
'description' => _('Primary group'),
'help' => 'group_upload',
'example' => _('machines'),
'required' => true
),
);
}
// available PDF fields
if ($this->get_scope() == 'host') {
$return['PDF_fields'] = array('uid' => _('Host name'));
}
else {
$return['PDF_fields'] = array('uid' => _('User name'));
}
$return['PDF_fields'] = array_merge($return['PDF_fields'], array(
'uidNumber' => _('UID number'),
'gidNumber' => _('GID number'),
'primaryGroup' => _('Primary group'),
'additionalGroups' => _('Additional groups'),
'homeDirectory' => _('Home directory'),
'loginShell' => _('Login shell'),
'userPassword' => _('Password')
));
if (self::areGroupOfNamesActive()) {
$return['PDF_fields']['gon'] = _('Groups of names');
}
// help Entries
$return['help'] = array(
'autoAdd' => array(
"Headline" => _("Automatically add this extension"),
"Text" => _("This will enable the extension automatically if this profile is loaded.")
),
'userNameSuggestion' => array(
"Headline" => _("User name suggestion"),
"Text" => _("LAM will suggest a user name based on e.g. first and last name. Here you can specify the suggestion. %sn% will be replaced by the last name. @givenname@ will be replaced by the first character of first name. Only attributes of tab Personal may be used.")
. '<br>' . _('Common examples are "@givenname@%sn%" or "%givenname%.%sn%".')
),
'hiddenOptions' => array(
"Headline" => _("Hidden options"),
"Text" => _("The selected options will not be managed inside LAM. You can use this to reduce the number of displayed input fields.")
),
'primaryGroupAsSecondary' => array(
'Headline' => _('Set primary group as memberUid'),
'Text' => _('Usually, users are not added to groups as memberUid if they have this group as primary group. If your application ignores primary groups then you can select this option to override this behaviour.')
),
'minMaxUser' => array(
'Headline' => _('UID number'),
'Text' => _('These are the minimum and maximum numbers to use for user IDs when creating new user accounts. The range should be different from that of machines. New user accounts will always get the highest number in use plus one.')
),
'minMaxHost' => array(
'Headline' => _('UID number'),
'Text' => _('These are the minimum and maximum numbers to use for machine IDs when creating new accounts for hosts. The range should be different from that of users. New host accounts will always get the highest number in use plus one.')
),
'pwdHash' => array(
"Headline" => _("Password hash type"),
"Text" => _("LAM supports CRYPT, CRYPT-SHA512, SHA, SSHA, MD5 and SMD5 to generate the hash value of passwords. SSHA and CRYPT are the most common but CRYPT does not support passwords greater than 8 letters. We do not recommend to use plain text passwords.")
. ' ' . _('K5KEY is only needed if you use Kerberos with smbk5pwd.')
),
'uidNumber' => array(
"Headline" => _("UID number"), 'attr' => 'uidNumber',
"Text" => _("If empty UID number will be generated automaticly.")
),
'group_upload' => array(
"Headline" => _("Primary group"),
"Text" => _("The primary group for this account. You can insert a GID number or a group name.")
),
'addgroup_upload' => array(
"Headline" => _("Additional groups"),
"Text" => _("Here you can enter a list of additional group memberships. The group names are separated by commas.")
),
'homeDirectory_upload' => array(
"Headline" => _("Home directory"),
"Text" => _("Please enter the path to the user's home directory.")
),
'homeDirectory' => array(
"Headline" => _("Home directory"),
"Text" => _("Please enter the path to the user's home directory.")
),
'deletehomedir' => array(
"Headline" => _("Home directory"),
"Text" => _("Activating this checkbox will remove the user's home directory.")
),
'createhomedir' => array(
"Headline" => _("Home directory"),
"Text" => _("This will create the user's home directory on the specified server.")
),
'deleteSudoers' => array(
"Headline" => _("Delete sudo rights"),
"Text" => _("Deletes the user from all existing sudo rights.")
),
'uidCheckSuffix' => array (
"Headline" => _("Suffix for UID/user name check"),
"Text" => _("LAM checks if the entered user name and UID are unique. Here you can enter the LDAP suffix that is used to search for duplicates. By default the account type suffix is used. You only need to change this if you use multiple server profiles with different OUs but need unique user names or UIDs.")
),
'loginShells' => array(
"Headline" => _("Login shells"),
"Text" => _("This is the list of valid login shells.")
),
'uidGenerator' => array (
"Headline" => _("UID generator"),
"Text" => _("LAM will automatically suggest UID/GID numbers. You can either use a fixed range of numbers or an LDAP entry with object class \"sambaUnixIdPool\" or \"msSFU30DomainInfo\".")
. ' ' . _('Magic number will set a fixed value that must match your server configuration.')
),
'sambaIDPoolDN' => array (
"Headline" => _("Samba ID pool DN"),
"Text" => _("Please enter the DN of the LDAP entry with object class \"sambaUnixIdPool\".")
),
'windowsIDPoolDN' => array (
"Headline" => _("Windows domain info DN"),
"Text" => _("Please enter the DN of the LDAP entry with object class \"msSFU30DomainInfo\".")
),
'magicNumber' => array(
"Headline" => _("Magic number"),
"Text" => _("Please enter the magic number you configured on server side.")
),
'noObjectClass' => array(
"Headline" => _("Do not add object class"),
"Text" => _("This will not add the posixAccount object class to the account.")
),
'excludeFromGroupSync' => array (
"Headline" => _('Exclude from group sync'),
"Text" => _('Enter one group per line that should be ignored when syncing groups.')
),
'user' => array(
'uid' => array(
"Headline" => _("User name"), 'attr' => 'uid',
"Text" => _("User name of the user who should be created. Valid characters are: a-z,A-Z,0-9, @.-_. If user name is already used user name will be expanded with a number. The next free number will be used.")
),
'gecos' => array(
"Headline" => _("Gecos"),
"Text" => _("User description. If left empty first and last name will be used.")
),
'gidNumber' => array(
"Headline" => _("Primary group"), 'attr' => 'gidNumber',
"Text" => _("The primary group the user should be member of.")
),
'userPassword' => array(
"Headline" => _("Password"),
"Text" => _("Please enter the password which you want to set for this account.")
),
'userPassword_lock' => array(
"Headline" => _("Account deactivated"),
"Text" => _("If checked account will be deactivated by putting a \"!\" before the encrypted password.")
),
'loginShell' => array(
"Headline" => _("Login shell"),
"Text" => _("To disable login use /bin/false.")
),
'addgroup' => array(
"Headline" => _("Additional groups"),
"Text" => _("Hold the CTRL-key to (de)select multiple groups."). ' '. _("Can be left empty.")
),
'cn' => array (
"Headline" => _("Common name"), 'attr' => 'cn',
"Text" => _("This is the natural name of the user. If empty, the first and last name or user name is used.")
),
'useOldPwd' => array (
"Headline" => _('Password change with old password'),
"Text" => _('Sends the old password together with the new password when the user sets a new password.')
)
),
'host' => array(
'uid' => array(
"Headline" => _("Host name"), 'attr' => 'uid',
"Text" => _("Host name of the host which should be created. Valid characters are: a-z,A-Z,0-9, .-_$. Host names are always ending with $. If last character is not $ it will be added. If host name is already used host name will be expanded with a number. The next free number will be used.")
),
'gecos' => array(
"Headline" => _("Gecos"),
"Text" => _("Host description. If left empty host name will be used.")
),
'gidNumber' => array(
"Headline" => _("Primary group"), 'attr' => 'gidNumber',
"Text" => _("The primary group the host should be member of.")
),
'description' => array (
"Headline" => _("Description"),
"Text" => _("Host description. If left empty host name will be used.")
),
'cn' => array (
"Headline" => _("Common name"), 'attr' => 'cn',
"Text" => _("This is the natural name of the host. If empty, the host name will be used.")
)
)
);
return $return;
}
/**
* Initializes the module after it became part of an accountContainer
*
* @param string $base the name of the accountContainer object ($_SESSION[$base])
*/
function init($base) {
// make optional if needed
$modules = $_SESSION[$base]->get_type()->getModules();
array_push($modules,'groupOfNames');
$typeId = $_SESSION[$base]->get_type()->getId();
$this->autoAddObjectClasses = !$this->isOptional($modules) && !$this->skipObjectClass();
// call parent init
parent::init($base);
$this->groups = array();
$this->groups_orig = array();
// list of all group names
$groups = $this->findGroups($modules);
if (count($groups)==0) {
StatusMessage("ERROR", _('No Unix groups found in LDAP! Please create one first.'), '');
return;
}
$this->gonList = array();
$this->gonList_orig = array();
}
/**
* {@inheritDoc}
* @see baseModule::getManagedAttributes()
*/
public function getManagedAttributes($typeId) {
$attrs = parent::getManagedAttributes($typeId);
$typeManager = new TypeManager();
if (!$typeManager->hasConfig()) {
return $attrs;
}
$modules = $typeManager->getConfiguredType($typeId)->getModules();
if ($this->manageCn($modules)) {
$attrs[] = 'cn';
}
$attrs[] = $this->getHomedirAttrName($modules);
$attrs[] = $this->getPasswordAttrName($modules);
return $attrs;
}
/**
* This functions is used to check if all settings for this module have been made.
*
* @return boolean true, if settings are complete
*/
function module_complete() {
$typeId = $this->getAccountContainer()->get_type()->getId();
if (!$this->skipObjectClass() && (!isset($this->attributes['objectClass']) || !in_array('posixAccount', $this->attributes['objectClass']))) {
// no checks if object class is not set
return true;
}
if (!isset($this->attributes['uid'][0]) || ($this->attributes['uid'][0] == '')) return false;
if (!isset($this->attributes['uidNumber'][0]) || ($this->attributes['uidNumber'][0] == '')) return false;
if (!isset($this->attributes['gidNumber'][0]) || ($this->attributes['gidNumber'][0] == '')) return false;
if (!isset($this->attributes['loginShell'][0]) || ($this->attributes['loginShell'][0] == '')) return false;
return true;
}
/**
* This function loads all needed LDAP attributes.
*
* @param array $attr list of attributes
*/
function load_attributes($attr) {
parent::load_attributes($attr);
$typeSettings = $_SESSION['config']->get_typeSettings();
// get additional group memberships
if (!isset($attr['uid'][0])) {
return;
}
$groupFilter = '(&(objectClass=member)(member=' . $attr['uid'][0] . '))';
if (!empty($typeSettings['filter_group'])) {
$typeFilter = $typeSettings['filter_group'];
if (strpos($typeFilter, '(') !== 0) {
$typeFilter = '(' . $typeFilter . ')';
}
$groupFilter = '(&' . $groupFilter . $typeFilter . ')';
}
$groupList = searchLDAPByFilter($groupFilter, array('cn'), array('group'));
for ($i = 0; $i < sizeof($groupList); $i++) {
$this->groups[] = $groupList[$i]['cn'][0];
}
$this->groups_orig = $this->groups;
// get additional group of names memberships
if (self::areGroupOfNamesActive()) {
$types = array('gon', 'group');
$gonList = array();
foreach ($types as $type) {
$gonFilter = '(|(&(objectClass=groupOfNames)(member=' . $this->getAccountContainer()->dn_orig . '))(&(objectClass=groupOfMembers)(member=' . $this->getAccountContainer()->dn_orig . '))(&(objectClass=groupOfUniqueNames)(uniqueMember=' . $this->getAccountContainer()->dn_orig . ')))';
if (!empty($typeSettings['filter_' . $type])) {
$typeFilter = $typeSettings['filter_' . $type];
if (strpos($typeFilter, '(') !== 0) {
$typeFilter = '(' . $typeFilter . ')';
}
$gonFilter = '(&' . $gonFilter . $typeFilter . ')';
}
$gonListPart = searchLDAPByFilter($gonFilter, array('dn'), array($type));
$gonList = array_merge($gonList, $gonListPart);
}
$this->gonList_orig = array();
for ($i = 0; $i < sizeof($gonList); $i++) {
$this->gonList_orig[] = $gonList[$i]['dn'];
}
$this->gonList_orig = array_values(array_unique($this->gonList_orig));
$this->gonList = $this->gonList_orig;
}
}
/**
* Returns a list of modifications which have to be made to the LDAP account.
*
* @return array list of modifications
* <br>This function returns an array with 3 entries:
* <br>array( DN1 ('add' => array($attr), 'remove' => array($attr), 'modify' => array($attr)), DN2 .... )
* <br>DN is the DN to change. It may be possible to change several DNs (e.g. create a new user and add him to some groups via attribute memberUid)
* <br>"add" are attributes which have to be added to LDAP entry
* <br>"remove" are attributes which have to be removed from LDAP entry
* <br>"modify" are attributes which have to been modified in LDAP entry
* <br>"info" are values with informational value (e.g. to be used later by pre/postModify actions)
*/
function save_attributes() {
$typeId = $this->getAccountContainer()->get_type()->getId();
if (!$this->skipObjectClass() && (!in_array('posixAccount', $this->attributes['objectClass']) && !in_array('posixAccount', $this->orig['objectClass']))) {
// skip saving if the extension was not added/modified
return array();
}
$modules = $this->getAccountContainer()->get_type()->getModules();
// get default changes
$return = $this->getAccountContainer()->save_module_attributes($this->attributes, $this->orig);
// add information about clear text password and password status change
$return[$this->getAccountContainer()->dn_orig]['info']['userPasswordClearText'][0] = $this->clearTextPassword;
$pwdAttrName = $this->getPasswordAttrName($modules);
if (isset($this->orig[$pwdAttrName][0]) && isset($this->attributes[$pwdAttrName][0])) {
if ((pwd_is_enabled($this->orig[$pwdAttrName][0]) && pwd_is_enabled($this->attributes[$pwdAttrName][0]))
|| (!pwd_is_enabled($this->orig[$pwdAttrName][0]) && !pwd_is_enabled($this->attributes[$pwdAttrName][0]))) {
$return[$this->getAccountContainer()->dn_orig]['info']['userPasswordStatusChange'][0] = 'unchanged';
}
elseif (pwd_is_enabled($this->orig[$pwdAttrName][0])) {
$return[$this->getAccountContainer()->dn_orig]['info']['userPasswordStatusChange'][0] = 'locked';
}
else {
$return[$this->getAccountContainer()->dn_orig]['info']['userPasswordStatusChange'][0] = 'unlocked';
}
}
if ($this->skipObjectClass() || in_array('posixAccount', $this->attributes['objectClass'])) {
// Remove primary group from additional groups
if (!isset($this->moduleSettings['posixAccount_primaryGroupAsSecondary'][0])
|| ($this->moduleSettings['posixAccount_primaryGroupAsSecondary'][0] != 'true')) {
for ($i=0; $i<count($this->groups); $i++) {
if ($this->groups[$i] == $this->getGroupName($this->attributes['gidNumber'][0])) {
unset($this->groups[$i]);
}
}
}
else {
// add user as memberuid in primary group
if (!in_array($this->getGroupName($this->attributes['gidNumber'][0]), $this->groups)) {
$this->groups[] = $this->getGroupName($this->attributes['gidNumber'][0]);
}
}
// Set additional group memberships
if (isset($this->orig['uid'][0]) && ($this->orig['uid'][0] != '') && ($this->attributes['uid'][0] != $this->orig['uid'][0])) {
// find affected groups
$groupList = searchLDAPByAttribute('memberUid', $this->orig['uid'][0], 'groupOfNames', array('dn'), array('group'));
for ($i = 0; $i < sizeof($groupList); $i++) {
// replace old user name with new one
$return[$groupList[$i]['dn']]['remove']['memberUid'][] = $this->orig['uid'][0];
$return[$groupList[$i]['dn']]['add']['memberUid'][] = $this->attributes['uid'][0];
}
}
else {
// update groups.
$add = array_delete($this->groups_orig, $this->groups);
$remove = array_delete($this->groups, $this->groups_orig);
$groupList = searchLDAPByAttribute('cn', '*', 'posixGroup', array('cn', 'dn'), array('group'));
$dn2cn = array();
for ($i = 0; $i < sizeof($groupList); $i++) {
$cn2dn[$groupList[$i]['cn'][0]] = $groupList[$i]['dn'];
}
for ($i = 0; $i < sizeof($add); $i++) {
if (isset($cn2dn[$add[$i]])) {
$return[$cn2dn[$add[$i]]]['add']['memberUid'][] = $this->attributes['uid'][0];
}
}
for ($i = 0; $i < sizeof($remove); $i++) {
if (isset($cn2dn[$remove[$i]])) {
$return[$cn2dn[$remove[$i]]]['remove']['memberUid'][] = $this->attributes['uid'][0];
}
}
}
}
elseif (in_array('posixAccount', $this->orig['objectClass']) && !empty($this->orig['uid'][0])) {
// Unix extension was removed, clean group memberships
$groupList = searchLDAPByAttribute('memberUid', $this->orig['uid'][0], 'posixGroup', array('dn'), array('group'));
for ($i = 0; $i < sizeof($groupList); $i++) {
// remove user name
$return[$groupList[$i]['dn']]['remove']['memberUid'][] = $this->orig['uid'][0];
}
}
return $return;
}
/**
* Runs the postmodify actions.
*
* @see baseModule::postModifyActions()
*
* @param boolean $newAccount
* @param array $attributes LDAP attributes of this entry
* @return array array which contains status messages. Each entry is an array containing the status message parameters.
*/
public function postModifyActions($newAccount, $attributes) {
$messages = array();
$accountContainer = $this->getAccountContainer();
if ($accountContainer == null) {
return $messages;
}
$modules = $accountContainer->get_type()->getModules();
// set exop password
$messages = array_merge($messages, $this->setExopPassword($this->moduleSettings));
// create home directories if needed
$homeDirAttr = $this->getHomedirAttrName($modules);
if (sizeof($this->lamdaemonServers) > 0) {
$server = null;
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
$temp = explode(":", $lamdaemonServers[$i]);
$server = $temp[0];
if (isset($temp[1])) {
if (!in_array($temp[1], $this->lamdaemonServers)) {
continue;
}
}
elseif (!in_array($temp[0], $this->lamdaemonServers)) {
continue;
}
$remote = new \LAM\REMOTE\Remote();
$remote->connect($server);
$result = $remote->execute(
implode(
self::$SPLIT_DELIMITER,
array(
$this->attributes['uid'][0],
"home",
"add",
$this->attributes[$homeDirAttr][0],
"0".$_SESSION['config']->get_scriptRights(),
$this->attributes['uidNumber'][0],
$this->attributes['gidNumber'][0])
));
$remote->disconnect();
// lamdaemon results
if (!empty($result)) {
$singleresult = explode(",", $result);
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'INFO') || ($singleresult[0] == 'WARN')) {
$messages[] = $singleresult;
}
else {
$messages[] = array('ERROR', $result[0]);
}
}
}
}
// move home directory if needed
if (!empty($this->orig[$homeDirAttr][0]) && !empty($this->attributes[$homeDirAttr][0])
&& ($this->orig[$homeDirAttr][0] != $this->attributes[$homeDirAttr][0])) {
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
if (empty($lamdaemonServers[$i])) {
continue;
}
$temp = explode(":", $lamdaemonServers[$i]);
$server = $temp[0];
$remote = new \LAM\REMOTE\Remote();
$remote->connect($server);
$result = $remote->execute(
implode(
self::$SPLIT_DELIMITER,
array(
$this->attributes['uid'][0],
"home",
"move",
$this->orig[$homeDirAttr][0],
$this->attributes['uidNumber'][0],
$this->attributes[$homeDirAttr][0])
));
$remote->disconnect();
// lamdaemon results
if (!empty($result)) {
$singleresult = explode(",", $result);
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'INFO') || ($singleresult[0] == 'WARN')) {
$messages[] = $singleresult;
}
}
}
}
// set new group on homedirectory
if (!empty($this->orig[$homeDirAttr][0]) && !empty($this->attributes[$homeDirAttr][0])
&& ($this->orig['gidNumber'][0] != $this->attributes['gidNumber'][0])) {
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
if (empty($lamdaemonServers[$i])) {
continue;
}
$temp = explode(":", $lamdaemonServers[$i]);
$server = $temp[0];
$remote = new \LAM\REMOTE\Remote();
$remote->connect($server);
$result = $remote->execute(
implode(
self::$SPLIT_DELIMITER,
array(
$this->attributes['uid'][0],
"home",
"chgrp",
$this->orig[$homeDirAttr][0],
$this->attributes['uidNumber'][0],
$this->attributes['gidNumber'][0])
));
$remote->disconnect();
// lamdaemon results
if (!empty($result)) {
$singleresult = explode(",", $result);
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'INFO') || ($singleresult[0] == 'WARN')) {
$messages[] = $singleresult;
}
}
}
}
// set group of names
if (self::areGroupOfNamesActive()) {
$gons = $this->findGroupOfNames();
$toAdd = array_values(array_diff($this->gonList, $this->gonList_orig));
$toRem = array_values(array_diff($this->gonList_orig, $this->gonList));
$ldapUser = $_SESSION['ldap']->decrypt_login();
$ldapUser = $ldapUser[0];
// update groups if DN changed
if (isset($accountContainer->dn_orig) && ($accountContainer->dn_orig != $accountContainer->finalDN)) {
// update owner/member/uniqueMember attributes
$searchAttrs = array('member', 'uniquemember', 'owner');
foreach ($searchAttrs as $searchAttr) {
$ownerGroups = searchLDAPByAttribute($searchAttr, $accountContainer->dn_orig, null, array('dn', $searchAttr), array('gon', 'group'));
for ($i = 0; $i < sizeof($ownerGroups); $i++) {
$found = false;
$newOwners = $ownerGroups[$i][$searchAttr];
for ($o = 0; $o < sizeof($newOwners); $o++) {
if ($newOwners[$o] == $accountContainer->dn_orig) {
$newOwners[$o] = $accountContainer->finalDN;
$found = true;
break;
}
}
if ($found) {
$success = @ldap_mod_replace($_SESSION['ldap']->server(), $ownerGroups[$i]['dn'], array($searchAttr => $newOwners));
if (!$success) {
$ldapError = getDefaultLDAPErrorString($_SESSION['ldap']->server());
logNewMessage(LOG_ERR, '[' . $ldapUser .'] Unable to modify attributes of DN: ' . $ownerGroups[$i]['dn'] . ' (' . $ldapError . ').');
$messages[] = array('ERROR', sprintf(_('Was unable to modify attributes of DN: %s.'), $ownerGroups[$i]['dn']), $ldapError);
}
}
}
}
}
// add groups
for ($i = 0; $i < sizeof($toAdd); $i++) {
if (isset($gons[$toAdd[$i]])) {
$attrName = 'member';
if (in_array('groupOfUniqueNames', $gons[$toAdd[$i]]['objectclass'])) {
$attrName = 'uniqueMember';
}
$success = @ldap_mod_add($_SESSION['ldap']->server(), $toAdd[$i], array($attrName => array($accountContainer->finalDN)));
if (!$success) {
logNewMessage(LOG_ERR, '[' . $ldapUser .'] Unable to add user ' . $accountContainer->finalDN . ' to group: ' . $toAdd[$i] . ' (' . ldap_error($_SESSION['ldap']->server()) . ').');
$messages[] = array('ERROR', sprintf(_('Was unable to add attributes to DN: %s.'), $toAdd[$i]), getDefaultLDAPErrorString($_SESSION['ldap']->server()));
}
else {
logNewMessage(LOG_NOTICE, '[' . $ldapUser .'] Added user ' . $accountContainer->finalDN . ' to group: ' . $toAdd[$i]);
}
}
}
// remove groups
for ($i = 0; $i < sizeof($toRem); $i++) {
if (isset($gons[$toRem[$i]])) {
$attrName = 'member';
if (in_array('groupOfUniqueNames', $gons[$toRem[$i]]['objectclass'])) {
$attrName = 'uniqueMember';
}
$success = @ldap_mod_del($_SESSION['ldap']->server(), $toRem[$i], array($attrName => array($accountContainer->dn_orig)));
if (!$success) {
logNewMessage(LOG_ERR, '[' . $ldapUser .'] Unable to delete user ' . $accountContainer->finalDN . ' from group: ' . $toRem[$i] . ' (' . ldap_error($_SESSION['ldap']->server()) . ').');
$messages[] = array('ERROR', sprintf(_('Was unable to remove attributes from DN: %s.'), $toRem[$i]), getDefaultLDAPErrorString($_SESSION['ldap']->server()));
}
else {
logNewMessage(LOG_NOTICE, '[' . $ldapUser .'] Removed user ' . $accountContainer->finalDN . ' from group: ' . $toRem[$i]);
}
}
}
}
return $messages;
}
/**
* Sets the password via ldap_exop if configured.
*
* @param array $settings settings
* @return array error message parameters if any
*/
private function setExopPassword($settings) {
if (!empty($this->clearTextPassword) && !empty($settings['posixAccount_pwdHash'][0])
&& ($settings['posixAccount_pwdHash'][0] === 'LDAP_EXOP')) {
$success = ldap_exop_passwd($_SESSION['ldap']->server(), $this->getAccountContainer()->finalDN, null, $this->clearTextPassword);
if (!$success) {
return array('ERROR', _('Unable to set password'), getExtendedLDAPErrorMessage($_SESSION['ldap']->server()));
}
}
return array();
}
/**
* Additional LDAP operations on delete.
*
* @return List of LDAP operations, same as for save_attributes()
*/
function delete_attributes() {
$return = array();
// remove memberUids if set
$groups = searchLDAPByAttribute('memberUid', $this->attributes['uid'][0], 'posixGroup', array('dn'), array('group'));
for ($i = 0; $i < sizeof($groups); $i++) {
$return[$groups[$i]['dn']]['remove']['memberUid'][] = $this->attributes['uid'][0];
}
// stop here if referential integrity overlay is active
$config = $this->getAccountContainer()->get_type()->getTypeManager()->getConfig();
if ($config->isReferentialIntegrityOverlayActive()) {
return $return;
}
// remove from group of names
$dn = $this->getAccountContainer()->dn_orig;
$gons = searchLDAPByFilter('(|(member=' . $dn . ')(uniqueMember=' . $dn . '))', array('member', 'uniqueMember'), array('group', 'gon'));
for ($i = 0; $i < sizeof($gons); $i++) {
if (isset($gons[$i]['member'])) {
$return[$gons[$i]['dn']]['remove']['member'][] = $dn;
}
elseif (isset($gons[$i]['uniquemember'])) {
$return[$gons[$i]['dn']]['remove']['uniqueMember'][] = $dn;
}
}
return $return;
}
/**
* Allows the module to run commands before the LDAP entry is deleted.
*
* @return array Array which contains status messages. Each entry is an array containing the status message parameters.
*/
function preDeleteActions() {
$return = array();
// delete home directory
if (isset($_POST['deletehomedir']) && ($_POST['deletehomedir'] == 'on')) {
$modules = $this->getAccountContainer()->get_type()->getModules();
$homeDirAttr = $this->getHomedirAttrName($modules);
// get list of lamdaemon servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
$temp = explode(":", $lamdaemonServers[$i]);
$lamdaemonServers[$i] = $temp[0];
}
// try to delete directory on all servers
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
$remote = new \LAM\REMOTE\Remote();
try {
$remote->connect($lamdaemonServers[$i]);
$result = $remote->execute(
implode(
self::$SPLIT_DELIMITER,
array(
$this->attributes['uid'][0],
"home",
"rem",
$this->attributes[$homeDirAttr][0],
$this->attributes['uidNumber'][0]
)
));
$remote->disconnect();
}
catch (LAMException $e) {
$return[] = array('ERROR', $e->getTitle(), $e->getMessage());
}
// lamdaemon results
if (!empty($result)) {
$singleresult = explode(",", $result);
if (is_array($singleresult)) {
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) {
$return[] = $singleresult;
}
}
}
}
}
// delete sudo rights
if (isset($_POST['deleteSudoers']) && ($_POST['deleteSudoers'] == 'on')) {
$result = searchLDAPByAttribute('sudoUser', $this->attributes['uid'][0], 'sudoRole', array('dn'), array('sudo'));
foreach ($result as $attrs) {
$dn = $attrs['dn'];
$success = @ldap_mod_del($_SESSION['ldap']->server(), $dn, array('sudoUser' => array($this->attributes['uid'][0])));
if (!$success) {
$return[] = array('ERROR', getDefaultLDAPErrorString($_SESSION['ldap']->server()));
}
}
}
return $return;
}
/**
* Processes user input of the primary module page.
* It checks if all input values are correct and updates the associated LDAP attributes.