-
Notifications
You must be signed in to change notification settings - Fork 0
/
e-smith-ldap-5.2.0-ldap-init.patch
1258 lines (1250 loc) · 45 KB
/
e-smith-ldap-5.2.0-ldap-init.patch
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
diff -ruN e-smith-ldap-5.2.0.ldap-init/root/etc/e-smith/events/actions/ldap-update e-smith-ldap-5.2.0/root/etc/e-smith/events/actions/ldap-update
--- e-smith-ldap-5.2.0.ldap-init/root/etc/e-smith/events/actions/ldap-update 2010-12-01 11:12:30.000000000 -0700
+++ e-smith-ldap-5.2.0/root/etc/e-smith/events/actions/ldap-update 2010-12-01 12:08:29.000000000 -0700
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/bin/bash
#----------------------------------------------------------------------
# copyright (C) 1999, 2000 e-smith, inc.
@@ -22,456 +22,4 @@
# call us on 1 888 ESMITH 1 (US/Canada toll free) or +1 613 564 8000
#----------------------------------------------------------------------
-package esmith;
-
-use strict;
-use Errno;
-use esmith::ConfigDB;
-use esmith::AccountsDB;
-use esmith::util;
-use Net::LDAP;
-use Date::Parse;
-
-my $c = esmith::ConfigDB->open_ro;
-my $a = esmith::AccountsDB->open_ro;
-
-my $l = $c->get('ldap');
-my $status = $l->prop('status') || "disabled";
-unless ($status eq "enabled" )
-{
- warn "Not running action script $0, LDAP service not enabled!\n";
- exit(0);
-}
-
-my $hostname = $c->get('SystemName')
- || die("Couldn't determine system name");
-$hostname = $hostname->value;
-
-my $domain = $c->get('DomainName')
- || die("Couldn't determine domain name");
-$domain = $domain->value;
-
-my $schema = '/etc/openldap/schema/samba.schema';
-my $map = { 'FirstName' => 'givenName',
- 'LastName' => 'sn',
- 'Phone' => 'telephoneNumber',
- 'Company' => 'o',
- 'Dept' => 'ou',
- 'City' => 'l',
- 'Street' => 'street',
- };
-
-my @accounts;
-my $account;
-my $event = shift || die "Event name must be specified";
-if ($event eq 'ldap-update' or $event eq 'bootstrap-ldap-save')
-{
- @accounts = ($a->users, $a->groups, $a->ibays, $a->get_all_by_prop(type => 'machine'));
- push(@accounts, $a->get('admin'));
-}
-else
-{
- my @name = @ARGV;
- die "Account name argument missing." unless scalar (@name) >= 1;
-
- foreach my $name (@name)
- {
- $account = $a->get($name);
- die "Account $name not found.\n" unless defined $account;
- my $type = $account->prop('type') || "unknown";
-
- die "Account $name is not a user, group, ibay, machine account; update LDAP entry failed.\n"
- unless ($type =~ m{^(?:user|group|ibay|machine)$} or $name eq 'admin');
- push @accounts, $account;
- }
-}
-
-#------------------------------------------------------------
-# Read all samba groups (can't do individual lookups)
-#------------------------------------------------------------
-
-my $groupmap = ();
-
-# Only do if schema is found
-if ( -f "$schema" and -x '/usr/bin/net' )
-{
- foreach (`/usr/bin/net groupmap list 2> /dev/null`){
- chomp;
- next if m{\(S-1-5-32-\d+\)};
- $groupmap->{$3} = { name => "$1", sid => "$2" } if (/^(.*) \((S-.*-\d+)\) -> (.*)$/);
- }
-}
-
-#------------------------------------------------------------
-# Update LDAP database entry.
-#------------------------------------------------------------
-my $base = esmith::util::ldapBase ($domain);
-my $pw = esmith::util::LdapPassword();
-
-my $ldap = Net::LDAP->new('localhost')
- or die "$@";
-
-$ldap->bind(
- dn => "cn=root,$base",
- password => $pw
-);
-
-my ($dc,undef) = split (/\./, $domain);
-my $o = $l->prop('defaultCompany') || $domain;
-
-# Try and find base record
-my $seen;
-my @objects = qw(top organization dcObject);
-my $result = $ldap->search( base => $base, filter => '(objectClass=*)', scope => 'base' );
-if ($result->code == 32)
-{
- $result = $ldap->add( $base, attr => [ dc => $dc, o => $o, objectClass => \@objects ] );
-}
-elsif ($result->code)
-{
- warn "failed checking base entry $base: ", $result->error;
-}
-else
-{
- # Don't overwrite objectClass (just update if necessary)
- $seen = ();
- @objects = grep { ! $seen->{$_} ++ } (@objects, $result->entry(0)->get_value('objectClass') );
- $ldap->modify( $base, replace => { dc => $dc, o => $o, objectClass => \@objects } );
-}
-warn "failed to add/update entry $base: ", $result->error if $result->code;
-
-# Try and find container records
-foreach my $obj ( qw(Users Groups Computers) )
-{
- @objects = qw(top organizationalUnit);
- $result = $ldap->search( base => "ou=$obj,$base", filter => '(objectClass=*)', scope => 'base' );
- if ($result->code == 32)
- {
- $result = $ldap->add( "ou=$obj,$base", attr => [ ou => $obj, objectClass => \@objects ] );
- }
- elsif ($result->code)
- {
- warn "failed checking base entry ou=$obj,$base: ", $result->error;
- }
- else
- {
- # Don't overwrite objectClass (just update if necessary)
- $seen = ();
- @objects = grep { ! $seen->{$_} ++ } (@objects, $result->entry(0)->get_value('objectClass') );
- $result = $ldap->modify( "ou=$obj,$base", replace => { ou => $obj, objectClass => \@objects } );
- }
- warn "failed to add/update entry ou=$obj,$base: ", $result->error if $result->code;
-}
-
-my $updates;
-
-#------------------------------------------------------------
-# Ensure nobody, shared, www objects are there
-#------------------------------------------------------------
-foreach my $user (qw/www/){
- my $dn = "uid=$user,ou=Users,$base";
- utf8::upgrade($dn);
- $updates->{$dn}->{objectClass} = ['account', 'posixAccount', 'shadowAccount'];
-
- # Read information from getent passwd
- @{$updates->{$dn}}{'uid','userPassword','uidNumber','gidNumber','junk','junk','gecos','homeDirectory','loginShell'} = getpwnam($user);
- $updates->{$dn}->{userPassword} = "!*" if $updates->{$dn}->{userPassword} eq '!!';
- $updates->{$dn}->{userPassword} =~ s/^/{CRYPT}/ unless $updates->{$dn}->{userPassword} =~ m/^{/;
- $updates->{$dn}->{cn} = $updates->{$dn}->{gecos};
-
- # Samba parameters if we find the samba.schema
- if ( -f "$schema" and -x '/usr/bin/pdbedit' )
- {
- my $line = `/usr/bin/pdbedit -wu '$user' 2> /dev/null`;
- chomp($line);
- if ($line)
- {
- @{$updates->{$dn}}{'junk','junk','sambaLMPassword','sambaNTPassword'} = split(/:/,$line);
- foreach $line (`/usr/bin/pdbedit -vu '$user' 2> /dev/null`)
- {
- chomp($line);
- $updates->{$dn}->{sambaSID} = $1 if $line =~ m{User SID:\s+(S-.*)$};
- $updates->{$dn}->{displayName} = $1 if $line =~ m{Full Name:\s+(.*)$};
- $updates->{$dn}->{sambaPrimaryGroupSID} = $1 if $line =~ m{Primary Group SID:\s+(S-.*)$};
- $updates->{$dn}->{sambaAcctFlags} = $1 if $line =~ m{Account Flags:\s+(.*)$};
- $updates->{$dn}->{sambaPwdLastSet} = str2time($1) if $line =~ m{Password last set:\s+(.*)$};
- }
- push @{$updates->{$dn}->{objectClass}}, 'sambaSamAccount';
- }
- else
- {
- $updates->{$dn}->{sambaLMPassword} = [];
- $updates->{$dn}->{sambaNTPassword} = [];
- $updates->{$dn}->{sambaSID} = [];
- $updates->{$dn}->{displayName} = [];
- $updates->{$dn}->{sambaPrimaryGroupSID} = [];
- $updates->{$dn}->{sambaAcctFlags} = [];
- $updates->{$dn}->{sambaPwdLastSet} = [];
- }
- }
-}
-endpwent();
-
-foreach my $group (qw/nobody shared www/){
- my $dn = "cn=$group,ou=Groups,$base";
- utf8::upgrade($dn);
- $updates->{$dn}->{objectClass} = ['posixGroup'];
-
- # Read information from getent group
- @{$updates->{$dn}}{'cn','junk','gidNumber','memberUid'} = getgrnam($group);
- $updates->{$dn}->{memberUid} = [ split /\s+/, $updates->{$dn}->{memberUid} ];
-
- # Ensure groups have the needed properties
- if ($group eq 'shared'){
- push @{$updates->{$dn}->{objectClass}}, 'mailboxRelatedObject';
- $updates->{$dn}->{mail} = "everyone\@$domain";
- }
-
- # Samba parameters if we find the samba.schema
- if ( -f "$schema" )
- {
- if ( exists $groupmap->{$group} )
- {
- push @{$updates->{$dn}->{objectClass}}, 'sambaGroupMapping';
- $updates->{$dn}->{displayName} = $groupmap->{$group}->{name};
- $updates->{$dn}->{sambaSID} = $groupmap->{$group}->{sid};
- $updates->{$dn}->{sambaGroupType} = '2';
- }
- else
- {
- $updates->{$dn}->{displayName} = [];
- $updates->{$dn}->{sambaSID} = [];
- $updates->{$dn}->{sambaGroupType} = [];
- }
- }
-}
-endgrent();
-
-#------------------------------------------------------------
-# Create a list of updates that need to happen
-#------------------------------------------------------------
-foreach my $acct (@accounts)
-{
- my $key = $acct->key;
- my $type = $acct->prop('type');
- my $desc = undef;
- my $dn;
-
- if ($type =~ m{^(?:user|group|ibay|machine)$} or $key eq 'admin')
- {
- #------------------------------------------------------------
- # Do the user portion
- #------------------------------------------------------------
- if ($type eq 'machine')
- {
- $dn = "uid=$key,ou=Computers,$base";
- }
- else
- {
- $dn = "uid=$key,ou=Users,$base";
- }
- utf8::upgrade($dn);
- $updates->{$dn}->{objectClass} = ['posixAccount', 'shadowAccount'];
-
- # Read information from getent passwd
- @{$updates->{$dn}}{'uid','userPassword','uidNumber','gidNumber','junk','junk','gecos','homeDirectory','loginShell'} = getpwnam($key);
- unless ($updates->{$dn}->{uid})
- {
- delete $updates->{$dn};
- next;
- }
- $updates->{$dn}->{userPassword} = "!*" if $updates->{$dn}->{userPassword} eq '!!';
- $updates->{$dn}->{userPassword} =~ s/^/{CRYPT}/ unless $updates->{$dn}->{userPassword} =~ m/^{/;
- $desc = $updates->{$dn}->{cn} = $updates->{$dn}->{gecos};
-
- # Load values from db record
- foreach my $attr ( keys %$map )
- {
- my $val = $acct->prop($attr);
- $updates->{$dn}->{$map->{$attr}} = $val if defined $val;
- }
-
- # Ensure users have the needed properties
- if ($type eq 'user' or $key eq 'admin')
- {
- push @{$updates->{$dn}->{objectClass}}, 'inetOrgPerson';
- $updates->{$dn}->{mail} = "$key\@$domain";
- }
- else
- {
- push @{$updates->{$dn}->{objectClass}}, 'account';
- }
-
- # Samba parameters if we find the samba.schema
- if ( -f "$schema" and -x '/usr/bin/pdbedit' )
- {
- my $line = `/usr/bin/pdbedit -wu '$key' 2> /dev/null`;
- chomp($line);
- if ($line)
- {
- @{$updates->{$dn}}{'junk','junk','sambaLMPassword','sambaNTPassword'} = split(/:/,$line);
- foreach $line (`/usr/bin/pdbedit -vu '$key' 2> /dev/null`)
- {
- chomp($line);
- $updates->{$dn}->{sambaSID} = $1 if $line =~ m{User SID:\s+(S-.*)$};
- $updates->{$dn}->{displayName} = $1 if $line =~ m{Full Name:\s+(.*)$};
- $updates->{$dn}->{sambaPrimaryGroupSID} = $1 if $line =~ m{Primary Group SID:\s+(S-.*)$};
- $updates->{$dn}->{sambaAcctFlags} = $1 if $line =~ m{Account Flags:\s+(.*)$};
- $updates->{$dn}->{sambaPwdLastSet} = str2time($1) if $line =~ m{Password last set:\s+(.*)$};
- }
- push @{$updates->{$dn}->{objectClass}}, 'sambaSamAccount';
- }
- else
- {
- $updates->{$dn}->{sambaLMPassword} = [];
- $updates->{$dn}->{sambaNTPassword} = [];
- $updates->{$dn}->{sambaSID} = [];
- $updates->{$dn}->{displayName} = [];
- $updates->{$dn}->{sambaPrimaryGroupSID} = [];
- $updates->{$dn}->{sambaAcctFlags} = [];
- $updates->{$dn}->{sambaPwdLastSet} = [];
- }
- }
-
- #------------------------------------------------------------
- # Do the group portion
- #------------------------------------------------------------
- $dn = "cn=$key,ou=Groups,$base";
- utf8::upgrade($dn);
- $updates->{$dn}->{objectClass} = ['posixGroup'];
-
- # Read information from getent group
- @{$updates->{$dn}}{'cn','junk','gidNumber','memberUid'} = getgrnam($key);
- $updates->{$dn}->{memberUid} = [ split /\s+/, $updates->{$dn}->{memberUid} ];
-
- # Ensure groups have the needed properties
- if ($type eq 'group')
- {
- push @{$updates->{$dn}->{objectClass}}, 'mailboxRelatedObject';
- $updates->{$dn}->{mail} = "$key\@$domain";
- $updates->{$dn}->{description} = $desc if $desc;
- }
-
- # Samba parameters if we find the samba.schema
- if ( -f "$schema" )
- {
- if ( exists $groupmap->{$key} )
- {
- push @{$updates->{$dn}->{objectClass}}, 'sambaGroupMapping';
- $updates->{$dn}->{displayName} = $groupmap->{$key}->{name};
- $updates->{$dn}->{sambaSID} = $groupmap->{$key}->{sid};
- $updates->{$dn}->{sambaGroupType} = '2';
- }
- else
- {
- $updates->{$dn}->{displayName} = [];
- $updates->{$dn}->{sambaSID} = [];
- $updates->{$dn}->{sambaGroupType} = [];
- }
- }
- }
-}
-endpwent();
-endgrent();
-
-#------------------------------------------------------------
-# Update LDAP database entry.
-#------------------------------------------------------------
-foreach my $dn (keys %$updates)
-{
- # Try and find record
- $result = $ldap->search( base => $dn, filter => '(objectClass=*)', scope => 'base' );
- warn "failed looking up entry $dn: ", $result->error if $result->code && $result->code != 32;
- my $code = $result->code;
- my @objectClass = $code == 32 ? () : $result->entry(0)->get_value('objectClass');
-
- # Clean up attributes and convert to utf8
- delete $updates->{$dn}->{'junk'};
- foreach my $attr ( keys %{$updates->{$dn}} )
- {
- if ( ref($updates->{$dn}->{$attr}) eq 'ARRAY' )
- {
- if ( $code == 32 and scalar(@{$updates->{$dn}->{$attr}}) == 0 )
- {
- delete $updates->{$dn}->{$attr};
- }
- else
- {
- for (my $c = 0; $c < scalar(@{$updates->{$dn}->{$attr}}); $c++)
- {
- utf8::upgrade($updates->{$dn}->{$attr}[$c]);
- }
- }
- }
- else
- {
- if ($updates->{$dn}->{$attr} !~ /^\s*$/)
- {
- utf8::upgrade($updates->{$dn}->{$attr});
- }
- elsif ( $code == 32 )
- {
- delete $updates->{$dn}->{$attr};
- }
- else
- {
- $updates->{$dn}->{$attr} = [];
- }
- }
- }
-
- # Try and find old record (sme7)
- my ($oldfilter, undef, $oldsearchbase) = split /,/, $dn, 3;
- my $oldresult = $ldap->search( base => "$oldfilter,$oldsearchbase", filter => '(objectClass=*)', scope => 'base' );
- if ($oldresult->code)
- {
- warn "failed looking up old entry $oldfilter,$oldsearchbase: ", $result->error if $oldresult->code != 32;
- }
- else
- {
- if ($code == 32)
- {
- my ($newdn, $newbase) = split /,/, $dn, 2;
-
- # Ensure key entry exist in old record before renaming
- $result = $ldap->modify( "$oldfilter,$oldsearchbase", replace => { split('=', $newdn) } );
- warn "failed to add attributes to old entry $oldfilter,$oldsearchbase: ", $result->error if $result->code;
-
- # Move old record to new location
- $result = $ldap->moddn( "$oldfilter,$oldsearchbase", newrdn => $newdn, newsuperior => $newbase, deleteoldrdn => 1 );
- warn "failed to rename old entry $oldfilter,$oldsearchbase: ", $result->error if $result->code;
-
- # Set things up as if we had found the new entry
- $code = $oldresult->code;
- @objectClass = $oldresult->entry(0)->get_value('objectClass');
- }
- else
- {
- $result = $ldap->delete( "$oldfilter,$oldsearchbase" );
- warn "failed to remove old entry $oldfilter,$oldsearchbase: ", $result->error if $result->code;
- }
- }
-
- # Perform insert or update
- if ( $code == 32 )
- {
- $result = $ldap->add( $dn, attrs => [ %{$updates->{$dn}} ] );
- $result->code && warn "failed to add entry $dn: ", $result->error;
- }
- else
- {
- # Don't overwrite objectClass (just remove person if existing)
- $seen = { person => 1 };
-
- # Remove samba objectClasses if removing samba attributes
- @{$seen}{'sambaSamAccount','sambaGroupMapping'} = (1,1) if ref($updates->{$dn}->{sambaSID}) eq 'ARRAY';
-
- @{$updates->{$dn}->{objectClass}} = grep { ! $seen->{$_}++ } (@{$updates->{$dn}->{objectClass}}, @objectClass );
-
- $result = $ldap->modify( $dn, replace => $updates->{$dn});
- $result->code && warn "failed to modify entry $dn: ", $result->error;
- }
-}
-$ldap->unbind;
-
-exit (0);
+/var/service/ldap/ldif-fix --update
diff -ruN e-smith-ldap-5.2.0.ldap-init/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/20ldif e-smith-ldap-5.2.0/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/20ldif
--- e-smith-ldap-5.2.0.ldap-init/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/20ldif 2010-12-01 11:12:30.000000000 -0700
+++ e-smith-ldap-5.2.0/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/20ldif 1969-12-31 17:00:00.000000000 -0700
@@ -1,20 +0,0 @@
-{
- foreach my $dn (keys %$ldif)
- {
- delete $ldif->{$dn}->{'junk'};
- $OUT .= "dn: $dn\n";
- foreach my $attr ( keys %{$ldif->{$dn}} )
- {
- if (ref($ldif->{$dn}->{$attr}) eq 'ARRAY')
- {
- my %seen = ();
- $OUT .= "$attr: $_\n" foreach grep { ! $seen{$_}++ } @{$ldif->{$dn}->{$attr}};
- }
- else
- {
- $OUT .= "$attr: ".$ldif->{$dn}->{$attr}."\n" if $ldif->{$dn}->{$attr};
- }
- }
- $OUT .= "\n";
- }
-}
diff -ruN e-smith-ldap-5.2.0.ldap-init/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/template-begin e-smith-ldap-5.2.0/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/template-begin
--- e-smith-ldap-5.2.0.ldap-init/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/template-begin 2010-12-01 11:12:30.000000000 -0700
+++ e-smith-ldap-5.2.0/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/template-begin 1969-12-31 17:00:00.000000000 -0700
@@ -1,207 +0,0 @@
-{
- use esmith::AccountsDB;
- use esmith::util;
- use Date::Parse;
-
- my $schema = '/etc/openldap/schema/samba.schema';
-
- $a = esmith::AccountsDB->open_ro;
- $ldapBase = esmith::util::ldapBase ($DomainName);
-
- local ($dn, $dc, $obj, $attr, $account, $type);
- ($dc) = split (/\./, $DomainName);
-
- $ldif = ();
-
- # Top domain object
- utf8::upgrade($ldapBase);
- $ldif->{$ldapBase}->{objectClass} = [ qw(top organization dcObject) ];
- $ldif->{$ldapBase}->{dc} = $dc;
- $ldif->{$ldapBase}->{o} = $ldap{defaultCompany} || $DomainName;
-
- # Top level groups
- foreach $obj ( qw(Users Groups Computers) )
- {
- $dn = "ou=$obj,$ldapBase";
- utf8::upgrade($dn);
-
- $ldif->{$dn}->{objectClass} = [ qw(top organizationalUnit) ];
- $ldif->{$dn}->{ou} = $obj;
- }
-
- local $dnmap = ();
-
- # Read in user details
- while(my ($key,$pwd,$uid,$gid,undef,undef,$gecos,$dir,$shell) = getpwent())
- {
- # skip non sme users
- $account = $a->get($key) || next;
- $type = $account->prop('type') || 'unknown';
- next unless ($type =~ m{^(?:user|group|ibay|machine)$} or $key eq 'admin');
-
- if ($type eq 'machine')
- {
- $dn = "uid=$key,ou=Computers,$ldapBase";
- utf8::upgrade($dn);
- }
- else
- {
- $dn = "uid=$key,ou=Users,$ldapBase";
- utf8::upgrade($dn);
- }
-
- $dnmap->{$key}->{user} = $dn;
-
- $ldif->{$dn}->{objectClass} = [ qw(posixAccount shadowAccount) ];
- $ldif->{$dn}->{uid} = $key;
- $pwd = "!*" if $pwd eq '!!';
- $ldif->{$dn}->{userPassword} = ($pwd =~ m/^\{/) ? $pwd : "\{CRYPT\}$pwd";
- $ldif->{$dn}->{uidNumber} = $uid;
- $ldif->{$dn}->{gidNumber} = $gid;
- $ldif->{$dn}->{gecos} = $gecos || '';
- $ldif->{$dn}->{cn} = $gecos || '';
- $ldif->{$dn}->{homeDirectory} = $dir;
- $ldif->{$dn}->{loginShell} = $shell;
-
- if ($type eq 'user' or $key eq 'admin')
- {
- push @{$ldif->{$dn}->{objectClass}}, 'inetOrgPerson';
- $ldif->{$dn}->{mail} = "$key\@$DomainName";
- $ldif->{$dn}->{givenName} = $account->prop('FirstName') || '';
- $ldif->{$dn}->{sn} = $account->prop('LastName') || '';
- $ldif->{$dn}->{telephoneNumber} = $account->prop('Phone') || '';
- $ldif->{$dn}->{o} = $account->prop('Company') || '';
- $ldif->{$dn}->{ou} = $account->prop('Dept') || '';
- $ldif->{$dn}->{l} = $account->prop('City') || '';
- $ldif->{$dn}->{street} = $account->prop('Street') || '';
- }
- else
- {
- push @{$ldif->{$dn}->{objectClass}}, 'account';
- }
- }
- endpwent();
-
- # www is a special user for all accounts
- foreach my $user (qw/www/)
- {
- $dn = "uid=$user,ou=Users,$ldapBase";
- utf8::upgrade($dn);
-
- $dnmap->{$user}->{user} = $dn;
-
- $ldif->{$dn}->{objectClass} = [ qw(account posixAccount shadowAccount) ];
- @{$ldif->{$dn}}{'uid','userPassword','uidNumber','gidNumber','junk','junk','gecos','homeDirectory','loginShell'} = getpwnam($user);
- $ldif->{$dn}->{userPassword} = "!*" if $ldif->{$dn}->{userPassword} eq '!!';
- $ldif->{$dn}->{userPassword} =~ s/^/{CRYPT}/ unless $ldif->{$dn}->{userPassword} =~ m/^\{/;
- $ldif->{$dn}->{cn} = $ldif->{$dn}->{gecos} || '';
- }
- endpwent();
-
- # Read in group details
- while(my ($key,undef,$gid,$members) = getgrent())
- {
- # skip non sme groups
- $account = $a->get($key) || next;
- $type = $account->prop('type') || 'unknown';
- next unless ($type =~ m{^(?:user|group|ibay|machine)$} or $key eq 'admin');
-
- $dn = "cn=$key,ou=Groups,$ldapBase";
- utf8::upgrade($dn);
-
- $dnmap->{$key}->{group} = $dn;
-
- $ldif->{$dn}->{objectClass} = [ qw(posixGroup) ];
- $ldif->{$dn}->{cn} = $key;
- $ldif->{$dn}->{gidNumber} = $gid;
- $ldif->{$dn}->{memberUid} = [ split /\s+/, $members ];
-
- if ($type eq 'group')
- {
- push @{$ldif->{$dn}->{objectClass}}, 'mailboxRelatedObject';
- $ldif->{$dn}->{mail} = "$key\@$DomainName";
- $ldif->{$dn}->{description} = $ldif->{$dnmap->{$key}->{user}}->{cn} if exists $ldif->{$dnmap->{$key}->{user}}->{cn};
- }
- }
- endgrent();
-
- # Nobody and shared are special groups used by samba
- foreach my $group (qw/nobody shared www/)
- {
- $dn = "cn=$group,ou=Groups,$ldapBase";
- utf8::upgrade($dn);
-
- $dnmap->{$group}->{group} = $dn;
-
- $ldif->{$dn}->{objectClass} = [ qw(posixGroup) ];
- @{$ldif->{$dn}}{'cn','junk','gidNumber','memberUid'} = getgrnam($group);
- $ldif->{$dn}->{memberUid} = [ split /\s+/, $ldif->{$dn}->{memberUid} ];
-
- if ($group eq 'shared'){
- push @{$ldif->{$dn}->{objectClass}}, 'mailboxRelatedObject';
- $ldif->{$dn}->{mail} = "everyone\@$DomainName";
- }
- }
- endgrent();
-
- # Read in samba user details
- if ( -f "$schema" and -x '/usr/bin/pdbedit' )
- {
- foreach my $line (`/usr/bin/pdbedit -Lw 2> /dev/null`)
- {
- my ($key,undef,$lmpass,$ntpass) = split(/:/,$line);
- next unless exists $dnmap->{$key};
-
- push @{$ldif->{$dnmap->{$key}->{user}}->{objectClass}}, 'sambaSamAccount';
- $ldif->{$dnmap->{$key}->{user}}->{sambaLMPassword} = $lmpass;
- $ldif->{$dnmap->{$key}->{user}}->{sambaNTPassword} = $ntpass;
-
- foreach my $info (`/usr/bin/pdbedit -v '$key' 2> /dev/null`){
- $ldif->{$dnmap->{$key}->{user}}->{sambaSID} = $1 if $info =~ m{User SID:\s+(S-.*)$};
- $ldif->{$dnmap->{$key}->{user}}->{displayName} = $1 if $info =~ m{Full Name:\s+(.*)$};
- $ldif->{$dnmap->{$key}->{user}}->{sambaPrimaryGroupSID} = $1 if $info =~ m{Primary Group SID:\s+(S-.*)$};
- $ldif->{$dnmap->{$key}->{user}}->{sambaAcctFlags} = $1 if $info =~ m{Account Flags:\s+(.*)$};
- $ldif->{$dnmap->{$key}->{user}}->{sambaPwdLastSet} = str2time($1) if $info =~ m{Password last set:\s+(.*)$};
- }
- }
- }
-
- # Read in samba group mappings
- if ( -f "$schema" and -x '/usr/bin/net' )
- {
- foreach (`/usr/bin/net groupmap list 2> /dev/null`){
- chomp;
- next if m{\(S-1-5-32-\d+\)};
- if (/^(.*) \((S-.*-\d+)\) -> (.*)$/)
- {
- next unless exists $dnmap->{$3};
-
- push @{$ldif->{$dnmap->{$3}->{group}}->{objectClass}}, 'sambaGroupMapping';
- $ldif->{$dnmap->{$3}->{group}}->{displayName} = $1;
- $ldif->{$dnmap->{$3}->{group}}->{sambaSID} = $2;
- $ldif->{$dnmap->{$3}->{group}}->{sambaGroupType} = '2';
- }
- }
- }
-
- # Ensure that attributes are utf8
- foreach $dn (keys %$ldif)
- {
- foreach $attr ( keys %{$ldif->{$dn}} )
- {
- if ( ref($ldif->{$dn}->{$attr}) eq 'ARRAY' )
- {
- for (my $c = 0; $c < scalar(@{$ldif->{$dn}->{$attr}}); $c++)
- {
- utf8::upgrade($ldif->{$dn}->{$attr}[$c]);
- }
- }
- else
- {
- utf8::upgrade($ldif->{$dn}->{$attr});
- }
- }
- }
-
- $OUT = "";
-}
diff -ruN e-smith-ldap-5.2.0.ldap-init/root/var/service/ldap/convert_ldif e-smith-ldap-5.2.0/root/var/service/ldap/convert_ldif
--- e-smith-ldap-5.2.0.ldap-init/root/var/service/ldap/convert_ldif 2010-12-01 11:12:29.000000000 -0700
+++ e-smith-ldap-5.2.0/root/var/service/ldap/convert_ldif 1969-12-31 17:00:00.000000000 -0700
@@ -1,67 +0,0 @@
-#! /usr/bin/perl
-
-use strict;
-use warnings;
-
-
-use Net::LDAP::LDIF;
-use esmith::util;
-
-my $olddomain = shift;
-my $newdomain = shift;
-
-my $ldif = Net::LDAP::LDIF->new( "/dev/stdin", "r", onerror => 'undef' );
-my $writer = Net::LDAP::LDIF->new("/dev/stdout", "w", onerror => 'undef' );
-
-my $new = esmith::util::ldapBase($newdomain);
-my $old = esmith::util::ldapBase($olddomain);
-
-while( not $ldif->eof())
-{
- my $entry = $ldif->read_entry();
- if ($ldif->error())
- {
- print "Error msg: ", $ldif->error(), "\n";
- print "Error lines:\n", $ldif->error_lines(), "\n";
- next;
- }
- next unless $entry;
- my $dn = $entry->dn;
- my @object_classes = $entry->get_value('objectClass');
- my %object_classes = map { $_ => 1 } @object_classes;
- if ($dn eq $old)
- {
- # this is the domain container object - objectClasses will be
- # 'top' and 'domain'
- my $dc = $new;
- $dc =~ s/,.*//g;
- $dc =~ s/^dc=//;
- $entry->replace(dc => $dc);
- }
- if ($object_classes{group})
- {
- # We used to create group entries with invalid objectClass group
- # - fix these if we find them
- # possibly not required any more, but harmless
- @object_classes = grep { $_ ne 'group' } @object_classes;
- $entry->replace(objectClass => [ @object_classes, 'posixGroup' ] );
- }
- # do any other object transformations
-
- # Update the mail attributes
- if ($entry->exists('mail')){
- my @newmails = ();
- foreach ($entry->get_value('mail')){
- $_ =~ s/\@$olddomain$/\@$newdomain/;
- push (@newmails,$_);
- }
- $entry->replace(mail => [ @newmails ]);
- }
-
- # Update basedb suffix
- $dn =~ s/$old$/$new/;
- $entry->dn($dn);
- $writer->write($entry);
-}
-$ldif->done( );
-
diff -ruN e-smith-ldap-5.2.0.ldap-init/root/var/service/ldap/ldif-fix e-smith-ldap-5.2.0/root/var/service/ldap/ldif-fix
--- e-smith-ldap-5.2.0.ldap-init/root/var/service/ldap/ldif-fix 1969-12-31 17:00:00.000000000 -0700
+++ e-smith-ldap-5.2.0/root/var/service/ldap/ldif-fix 2010-12-01 12:09:24.000000000 -0700
@@ -0,0 +1,414 @@
+#!/usr/bin/perl -T
+
+use strict;
+use warnings;
+use Net::LDAP;
+use Net::LDAP::LDIF;
+use Date::Parse;
+use esmith::ConfigDB;
+use esmith::AccountsDB;
+use esmith::util;
+use Getopt::Long qw(:config bundling);
+
+$ENV{'PATH'} = '/bin:/usr/bin:/sbin:/usr/sbin';
+$ENV{'LANG'} = 'C';
+
+sub dnsort {
+ my %type = ( add => 1, modrdn => 2, moddn => 2, modify => 3, delete => 4);
+ my %attr = ( dc => 1, ou => 2, cn => 3, uid => 4);
+
+ my ($oa) = ($a->get_value('newrdn') || $a->dn) =~ /^([^=]+)=/;
+ my ($ob) = ($b->get_value('newrdn') || $b->dn) =~ /^([^=]+)=/;
+ my ($ua, $ub) = map { my $tu = $_->get_value('uidnumber'); defined $tu && $tu ne '' ? $tu : -1 } ($a, $b);
+ my ($ga, $gb) = map { my $tg = $_->get_value('gidnumber'); defined $tg && $tg ne '' ? $tg : -1 } ($a, $b);
+
+ ($attr{$oa} || 9) <=> ($attr{$ob} || 9) || ($type{$a->changetype} || 9) <=> ($type{$b->changetype} || 9) ||
+ $ua <=> $ub || $ga <=> $gb || ($a->get_value('newrdn') || $a->dn) cmp ($b->get_value('newrdn') || $b->dn);
+}
+
+my $c = esmith::ConfigDB->open_ro;
+my $a = esmith::AccountsDB->open_ro;
+
+my $auth = $c->get('ldap')->prop('Authentication') || 'disabled';
+my $schema = '/etc/openldap/schema/samba.schema';
+
+my $domain = $c->get('DomainName')->value;
+my $basedn = esmith::util::ldapBase($domain);
+
+my $userou = 'ou=Users';
+my $groupou = 'ou=Groups';
+my $compou = 'ou=Computers';
+
+my ($dc) = split /\./, $domain;
+my $company = $c->get_prop('ldap', 'defaultCompany') || $domain;
+
+my %opt;
+GetOptions ( \%opt, "diff|d", "update|u", "input|i=s", "output|o=s" );
+$opt{input} = '/usr/sbin/slapcat -c 2> /dev/null|' unless $opt{input} && ($opt{input} eq '-' || -f "$opt{input}" || -c "$opt{input}");
+$opt{diff} = 1 if $opt{update};
+if ( $opt{output} && $opt{output} =~ m{^([-\w/.]+)$}) {
+ $opt{output} = $1;
+} else {
+ $opt{output} = '-';
+}
+
+my ($data, $dn);
+
+# Top object (base)
+$data->{$basedn} = {
+ objectclass => [qw/organization dcObject top/],
+ dc => $dc,
+ o => $company,
+};
+
+# Top containers for users/groups/computers
+foreach (qw/Users Groups Computers/) {
+ $data->{"ou=$_,$basedn"} = {
+ objectclass => [qw/organizationalUnit top/],
+ ou => $_,
+ };
+}
+
+# Common accounts needed for SME to work properly
+$data->{"cn=nobody,$groupou,$basedn"}->{objectclass} = [ qw/posixGroup/ ];
+$data->{"uid=www,$userou,$basedn"}->{objectclass} = [ qw/account/ ];
+$data->{"cn=www,$groupou,$basedn"} = { objectclass => [ qw/posixGroup/ ], memberuid => [ qw/admin/ ] };
+$data->{"cn=shared,$groupou,$basedn"} = {
+ objectclass => [ qw/posixGroup mailboxRelatedObject/ ],
+ mail => "everyone\@$domain",
+ memberuid => [ qw/www/ ]
+};
+
+# Read in accounts database information
+foreach my $acct ($a->get('admin'), $a->users, $a->groups, $a->ibays, $a->get_all_by_prop(type => 'machine')) {
+ my $key = $acct->key;
+ my $type = $acct->prop('type');
+
+ next if $key eq 'Primary';
+
+ $dn = "uid=$key,".($type eq 'machine' ? $compou : $userou).",$basedn";
+ if ($type =~ /^(?:user|group|machine|ibay)$/ || $key eq 'admin') {
+ if ($type eq 'user' || $key eq 'admin') {
+ # Allow removal of obsolete person objectclass and samba attributes
+ push @{$data->{$dn}->{_delete}->{objectclass}}, 'person';
+
+
+ push @{$data->{$dn}->{objectclass}}, 'inetOrgPerson';
+ $data->{$dn}->{mail} = "$key\@$domain";
+ @{$data->{$dn}}{qw/givenname sn telephonenumber o ou l street/} =
+ map { $acct->prop($_) || [] } qw/FirstName LastName Phone Company Dept City Street/;
+ $data->{$dn}->{cn} = $data->{$dn}->{gecos} = $acct->prop('FirstName').' '.$acct->prop('LastName');
+ }
+ else {
+ push @{$data->{$dn}->{objectclass}}, 'account';
+ }
+
+ # users/ibays need to be a member of shared
+ push @{$data->{"cn=shared,$groupou,$basedn"}->{memberuid}}, $key if $type =~ /^(user|ibay)$/ || $key eq 'admin';
+
+ if ($auth ne 'enabled') {
+ # Allow removal of shadow properties
+ push @{$data->{$dn}->{_delete}->{objectclass}}, 'shadowAccount';
+ $data->{$dn}->{_delete}->{lc($_)} = 1 foreach qw/userPassword shadowLastChange shadowMin shadowMax
+ shadowWarning shadowInactive shadowExpire shadowFlag/;
+
+ if ( -f "$schema" ) {
+ # If we will be adding samba properties then allow removal
+ push @{$data->{$dn}->{_delete}->{objectclass}}, 'sambaSamAccount';
+ $data->{$dn}->{_delete}->{lc($_)} = 1 foreach qw/displayName sambaAcctFlags sambaLMPassword sambaNTPassword
+ sambaNTPassword sambaPrimaryGroupSID sambaPwdLastSet sambaSID/;
+ }
+ }
+ }
+
+ $dn = "cn=$key,$groupou,$basedn";
+ push @{$data->{$dn}->{objectclass}}, 'posixGroup';
+ if ($type eq 'group') {
+ # Allways replace memberuid with new set
+ $data->{$dn}->{_delete}->{memberuid} = 1;
+
+ push @{$data->{$dn}->{objectclass}}, 'mailboxRelatedObject';
+
+ $data->{$dn}->{mail} = "$key\@$domain";
+ $data->{$dn}->{description} = $acct->prop('Description') || [];
+ push @{$data->{$dn}->{memberuid}}, split /,/, ($acct->prop('Members') || '');
+
+ # www needs to be a memeber of every group
+ push @{$data->{$dn}->{memberuid}}, 'www';
+
+ if ($auth ne 'enabled' && -f "$schema" ) {
+ # If we will be adding samba properties then allow removal
+ push @{$data->{$dn}->{_delete}->{objectclass}}, 'sambaGroupMapping';
+ $data->{$dn}->{_delete}->{lc($_)} = 1 foreach qw/displayName sambaGroupType sambaSID/;
+ }
+ }
+ elsif ($type eq 'ibay') {
+ $dn = "cn=".$acct->prop('Group').",$groupou,$basedn";
+ push @{$data->{$dn}->{memberuid}}, $acct->key;
+ }
+}
+
+if ($auth ne 'enabled') {
+ # Read in information from unix (passwd) system
+ open PASSWD, '/etc/passwd';
+ while (<PASSWD>) {
+ chomp;
+ my @passwd = split /:/, $_;
+ next unless scalar @passwd == 7;
+
+ $dn = "uid=$passwd[0],".($passwd[0] =~ /\$$/ ? $compou : $userou).",$basedn";
+ next unless exists $data->{$dn};
+
+ push @{$data->{$dn}->{objectclass}}, 'posixAccount';
+ @{$data->{$dn}}{qw/cn uid uidnumber gidnumber homedirectory loginshell gecos/} =
+ map { $passwd[$_] ? $passwd[$_] : [] } (4,0,2,3,5,6,4);
+ }
+ close (PASSWD);
+
+ # Shadow file defaults (pulled from cpu.conf)
+ my %shadow_def = ( 1 => [], 2 => 11192, 3 => -1, 4 => 99999, 5 => 7, 6 => -1, 7 => -1, 8 => 134538308 );
+
+ # Read in information from unix (shadow) system
+ open SHADOW, '/etc/shadow';
+ while (<SHADOW>) {
+ chomp;
+ my @shadow = split /:/, $_;
+ next unless scalar @shadow >= 6;
+ $shadow[1] = '!*' if $shadow[1] eq '!!';
+ $shadow[1] = "{CRYPT}$shadow[1]" unless $shadow[1] =~ /^\{/;
+
+ $dn = "uid=$shadow[0],".($shadow[0] =~ /\$$/ ? $compou : $userou).",$basedn";
+ next unless exists $data->{$dn};
+
+ push @{$data->{$dn}->{objectclass}}, 'shadowAccount';
+ @{$data->{$dn}}{ map { lc($_) } qw/userPassword shadowLastChange shadowMin shadowMax shadowWarning shadowInactive
+ shadowExpire shadowFlag/} = map { $shadow[$_] ? $shadow[$_] : $shadow_def{$_} } (1..8);
+ }
+ close (SHADOW);
+
+ # Read in information from unix (group) system
+ open GROUP, '/etc/group';
+ while (<GROUP>) {
+ chomp;
+ my @group = split /:/, $_;
+ next unless scalar @group >= 3;
+ $group[3] = [ split /,/, ($group[3] || '') ];
+
+ $dn = "cn=$group[0],$groupou,$basedn";
+ next unless exists $data->{$dn};
+
+ push @{$data->{$dn}->{objectclass}}, 'posixGroup';
+ @{$data->{$dn}}{qw/cn gidnumber/} = map { $group[$_] ? $group[$_] : [] } (0,2);
+ push @{$data->{$dn}->{memberuid}}, @{$group[3]};
+ }
+ close (GROUP);
+
+ my %smbprop = (
+ 'User SID' => 'sambasid',
+ 'Account Flags' => 'sambaacctflags',
+ 'Primary Group SID' => 'sambaprimarygroupsid',
+ 'Full Name' => 'displayname',
+ 'Password last set' => 'sambapwdlastset',
+ );
+
+ # Read in information from unix (smbpasswd) system
+ if ( -f "$schema" && -x '/usr/bin/pdbedit' ) {
+ $dn = undef;
+ open SMBDETAIL, '/usr/bin/pdbedit -vL 2> /dev/null|';
+ while (<SMBDETAIL>) {
+ chomp;
+
+ $dn = ("uid=$1,".($1 =~ /\$$/ ? $compou : $userou).",$basedn") if m/^Unix username:\s+(\S.*)$/;
+ next unless $dn && exists $data->{$dn};
+