-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe-smith-ldap-5.2.0-add_samba_attr_in_ldap.patch
197 lines (189 loc) · 7.95 KB
/
e-smith-ldap-5.2.0-add_samba_attr_in_ldap.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
diff -Nur -x '*.orig' -x '*.rej' e-smith-ldap-5.2.0/root/etc/e-smith/events/actions/ldap-update mezzanine_patched_e-smith-ldap-5.2.0/root/etc/e-smith/events/actions/ldap-update
--- e-smith-ldap-5.2.0/root/etc/e-smith/events/actions/ldap-update 2010-09-24 18:47:32.000000000 +0200
+++ mezzanine_patched_e-smith-ldap-5.2.0/root/etc/e-smith/events/actions/ldap-update 2010-09-24 16:15:45.000000000 +0200
@@ -97,6 +97,41 @@
}
endpwent();
+# Now parse samba info
+# We want to copy all this into LDAP
+# so it'll be easier to switch to real LDAP auth later
+my %lmpass;
+my %ntpass;
+my %smbflag;
+my %smblct;
+my %smbsid;
+my %smbpgsid;
+
+# First, parse users data
+foreach my $line (`/usr/bin/pdbedit -Lw`){
+ my ($key,undef,$lmpass,$ntpass,$smbflag,$smblct) = split(/:/,$line);
+ $lmpass{$key} = $lmpass;
+ $ntpass{$key} = $ntpass;
+ $smbflag{$key} = $smbflag;
+ $smblct =~ s/LCT\-//;
+ $smblct{$key} = hex($smblct);
+ foreach my $info (`/usr/bin/pdbedit -v $key`){
+ $smbsid{$key} = $1 if ($info =~ m/User SID:\s+(S-.*)/);
+ $smbpgsid{$key} = $1 if ($info =~ m/Primary Group SID:\s+(S-.*)/);
+ }
+}
+
+# Now, parse groupmaps data
+foreach (`/usr/bin/net groupmap list`){
+ chomp;
+ next unless (/^(.*?) \((S-.*-\d+)\) -> (.*)$/);
+ my ($desc, $smbsid, $key) = ($1, $2, $3);
+ # We only want group sid
+ my $account = $a->get($key) || next;
+ next unless ($account->prop('type') eq 'group');
+ $smbsid{$key} = $smbsid;
+}
+
#------------------------------------------------------------
# Update LDAP database entry.
#------------------------------------------------------------
@@ -146,8 +181,14 @@
my $gid = $gid{$key} || '';
my $home = $home{$key} || '';
my $shell = $shell{$key} || '';
+ my $lmpass = $lmpass{$key} || '';
+ my $ntpass = $ntpass{$key} || '';
+ my $smbflag = $smbflag{$key} || '';
+ my $smblct = $smblct{$key} || '';
+ my $smbsid = $smbsid{$key} || '';
+ my $smbpgsid = $smbpgsid{$key} || '';
- push @attrs, (objectClass => ['inetOrgPerson', 'posixAccount']);
+ push @attrs, (objectClass => ['inetOrgPerson', 'posixAccount', 'sambaSamAccount']);
push @attrs, (uid => $key);
push @attrs, (cn => $name) unless ($name =~ /^\s*$/);
@@ -164,6 +205,12 @@
push @attrs, (gidNumber => $gid) unless $gid =~ /^\s*$/;
push @attrs, (homeDirectory => $home) unless $home =~ /^\s*$/;
push @attrs, (loginShell => $shell) unless $shell =~ /^\s*$/;
+ push @attrs, (sambaLMPassword => $lmpass) unless $lmpass =~ /^\s*$/;
+ push @attrs, (sambaNTPassword => $ntpass) unless $ntpass =~ /^\s*$/;
+ push @attrs, (sambaAcctFlags => $smbflag) unless $smbflag =~ /^\s*$/;
+ push @attrs, (sambaPwdLastSet => $smblct) unless $smblct =~ /^\s*$/;
+ push @attrs, (sambaSID => $smbsid) unless $smbsid =~ /^\s*$/;
+ push @attrs, (sambaPrimaryGroupSID => $smbpgsid) unless $smbpgsid =~ /^\s*$/;
}
elsif ($type eq 'group')
{
@@ -173,14 +220,19 @@
utf8::upgrade($desc);
my @members = split(/,/,($acct->prop('Members') || ''));
my $gid = $acct->prop('Gid');
+ my $smbsid = $smbsid{$key};
- push @attrs, (objectClass => ['posixGroup','mailboxRelatedObject']);
+ push @attrs, (objectClass => ['posixGroup','mailboxRelatedObject','sambaGroupMapping']);
push @attrs, (cn => $key);
push @attrs, (mail => "$key\@$domain");
push @attrs, (gidNumber => $gid);
push @attrs, (description => $desc) unless $desc =~ /^\s*$/;
push @attrs, (memberUid => \@members)
unless ((scalar @members == 0) && ($event eq 'group-create'));
+ # Samba requires the displayName attribute
+ push @attrs, (displayName => $desc) unless $desc =~ /^\s*$/;
+ push @attrs, (sambaGroupType => '2');
+ push @attrs, (sambaSID => $smbsid);
}
if (($event eq 'user-create') || ($event eq 'group-create'))
{
diff -Nur -x '*.orig' -x '*.rej' e-smith-ldap-5.2.0/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/50groups mezzanine_patched_e-smith-ldap-5.2.0/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/50groups
--- e-smith-ldap-5.2.0/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/50groups 2010-09-24 18:47:32.000000000 +0200
+++ mezzanine_patched_e-smith-ldap-5.2.0/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/50groups 2010-09-24 18:43:40.000000000 +0200
@@ -5,18 +5,23 @@
my $desc = $_->prop('Description') || '';
my $gid = $_->prop('Gid');
my @members = split( /,/, ($_->prop('Members') || '') );
+ my $smbsid = $smbsid{$key} || '';
$OUT .= "\n";
$OUT .= "dn: cn=$key,ou=Groups,$ldapBase\n";
$OUT .= "objectClass: posixGroup\n";
$OUT .= "objectClass: mailboxRelatedObject\n";
+ $OUT .= "objectClass: sambaGroupMapping\n";
$OUT .= "gidNumber: $gid\n";
$OUT .= "cn: $key\n";
$OUT .= "description: $desc\n";
+ $OUT .= "displayName: $desc\n";
$OUT .= "mail: $key\@$DomainName\n";
foreach my $member (@members){
$OUT .= "memberUid: $member\n";
}
+ $OUT .= "sambaGroupType: 2\n";
+ $OUT .= "sambaSID: $smbsid\n";
}
}
diff -Nur -x '*.orig' -x '*.rej' e-smith-ldap-5.2.0/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/50users mezzanine_patched_e-smith-ldap-5.2.0/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/50users
--- e-smith-ldap-5.2.0/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/50users 2010-09-24 18:47:32.000000000 +0200
+++ mezzanine_patched_e-smith-ldap-5.2.0/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/50users 2010-09-24 16:15:45.000000000 +0200
@@ -18,10 +18,19 @@
my $home = $home{$key};
my $shell = $shell{$key};
+ my $lmpass = $lmpass{$key} || '';
+ my $ntpass = $ntpass{$key} || '';
+ my $smbflag = $smbflag{$key} || '';
+ my $smblct = $smblct{$key} || '';
+ my $smbsid = $smbsid{$key} || '';
+ my $smbpgsid = $smbpgsid{$key} || '';
+
+
$OUT .= "\n";
$OUT .= utf8("dn: uid=$key,ou=Users,$ldapBase\n");
$OUT .= utf8("objectClass: inetOrgPerson\n");
$OUT .= utf8("objectClass: posixAccount\n");
+ $OUT .= utf8("objectClass: sambaSamAccount\n");
$OUT .= utf8("uid: $key\n");
$OUT .= utf8("cn: $name\n") if $name;
$OUT .= utf8("givenName: $first\n") if $first;
@@ -37,5 +46,12 @@
$OUT .= utf8("gidNumber: $gid\n") if $gid;
$OUT .= utf8("homeDirectory: $home\n") if $home;
$OUT .= utf8("loginShell: $shell\n") if $shell;
+ $OUT .= utf8("sambaLMPassword: $lmpass\n") if $lmpass;
+ $OUT .= utf8("sambaNTPassword: $ntpass\n") if $ntpass;
+ $OUT .= utf8("sambaAcctFlags: $smbflag\n") if $smbflag;
+ $OUT .= utf8("sambaPwdLastSet: $smblct\n") if $smblct;
+ $OUT .= utf8("sambaSID: $smbsid\n") if $smbsid;
+ $OUT .= utf8("sambaPrimaryGroupSID: $smbpgsid\n") if $smbpgsid;
+
}
}
diff -Nur -x '*.orig' -x '*.rej' e-smith-ldap-5.2.0/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/template-begin mezzanine_patched_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/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/template-begin 2010-09-24 18:47:32.000000000 +0200
+++ mezzanine_patched_e-smith-ldap-5.2.0/root/etc/e-smith/templates/home/e-smith/db/ldap/ldif/template-begin 2010-09-24 16:15:45.000000000 +0200
@@ -28,5 +28,35 @@
}
endpwent();
+ %lmpass = ();
+ %ntpass = ();
+ %smbflag = ();
+ %smblct = ();
+ %smbsid = ();
+ %smbpgsid = ();
+
+ foreach my $line (`/usr/bin/pdbedit -Lw`){
+ my ($key,undef,$lmpass,$ntpass,$smbflag,$smblct) = split(/:/,$line);
+ $lmpass{$key} = $lmpass;
+ $ntpass{$key} = $ntpass;
+ $smbflag{$key} = $smbflag;
+ $smblct =~ s/LCT\-//;
+ $smblct{$key} = hex($smblct);
+ foreach my $info (`/usr/bin/pdbedit -v $key`){
+ $smbsid{$key} = $1 if ($info =~ m/User SID:\s+(S-.*)/);
+ $smbpgsid{$key} = $1 if ($info =~ m/Primary Group SID:\s+(S-.*)/);
+ }
+ }
+
+ foreach (`/usr/bin/net groupmap list`){
+ chomp;
+ next unless (/^(.*?) \((S-.*-\d+)\) -> (.*)$/);
+ my ($desc, $smbsid, $key) = ($1, $2, $3);
+ # We only want group sid
+ my $account = $a->get($key) || next;
+ next unless ($account->prop('type') eq 'group');
+ $smbsid{$key} = $smbsid;
+ }
+
$OUT = "";
}