sync 3_0 branch with HEAD
[samba.git] / docs / docbook / projdoc / Samba-LDAP-HOWTO.sgml
1 <chapter id="samba-ldap-howto">
2
3 <chapterinfo>
4         <author>
5                 <firstname>Gerald (Jerry)></firstname><surname>Carter</surname>
6                 <affiliation>
7                         <orgname>Samba Team</orgname>
8                         <address><email>jerry@samba.org</email></address>
9                 </affiliation>
10                 <firstname>Olivier (lem)></firstname><surname>Lemaire</surname>
11                 <affiliation>
12                         <orgname>IDEALX</orgname>
13                         <address><email>olem@IDEALX.org</email></address>
14                 </affiliation>
15         </author>
16
17
18         <pubdate> (13 Jan 2002) </pubdate>
19 </chapterinfo>
20
21 <title>Storing Samba's User/Machine Account information in an LDAP Directory</title>
22
23 <sect1>
24 <title>Purpose</title>
25
26 <para>
27 This document describes how to use an LDAP directory for storing Samba user
28 account information traditionally stored in the smbpasswd(5) file.  It is
29 assumed that the reader already has a basic understanding of LDAP concepts
30 and has a working directory server already installed.  For more information
31 on LDAP architectures and Directories, please refer to the following sites.
32 </para>
33
34 <itemizedlist>
35         <listitem><para>OpenLDAP - <ulink url="http://www.openldap.org/">http://www.openldap.org/</ulink></para></listitem>
36         <listitem><para>iPlanet Directory Server - <ulink url="http://iplanet.netscape.com/directory">http://iplanet.netscape.com/directory</ulink></para></listitem>
37 </itemizedlist>
38
39 <para>
40 Note that <ulink url="http://www.ora.com/">O'Reilly Publishing</ulink> is working on
41 a guide to LDAP for System Administrators which has a planned release date of
42 early summer, 2002.
43 </para>
44
45 <para>
46 Two additional Samba resources which may prove to be helpful are
47 </para>
48
49 <itemizedlist>
50         <listitem><para>The <ulink url="http://www.unav.es/cti/ldap-smb/ldap-smb-2_2-howto.html">Samba-PDC-LDAP-HOWTO</ulink>
51         maintained by Ignacio Coupeau.</para></listitem>
52
53         <listitem><para>The NT migration scripts from <ulink url="http://samba.idealx.org/">IDEALX</ulink> that are
54         geared to manage users and group in such a Samba-LDAP Domain Controller configuration.
55         </para></listitem>
56 </itemizedlist>
57
58 </sect1>
59
60
61 <sect1>
62 <title>Introduction</title>
63
64 <para>
65 Traditionally, when configuring <ulink url="smb.conf.5.html#ENCRYPTPASSWORDS">"encrypt
66 passwords = yes"</ulink> in Samba's <filename>smb.conf</filename> file, user account
67 information such as username, LM/NT password hashes, password change times, and account
68 flags have been stored in the <filename>smbpasswd(5)</filename> file.  There are several
69 disadvantages to this approach for sites with very large numbers of users (counted
70 in the thousands).
71 </para>
72
73 <itemizedlist>
74 <listitem><para>
75 The first is that all lookups must be performed sequentially.  Given that
76 there are approximately two lookups per domain logon (one for a normal
77 session connection such as when mapping a network drive or printer), this
78 is a performance bottleneck for lareg sites.  What is needed is an indexed approach
79 such as is used in databases.
80 </para></listitem>
81
82 <listitem><para>
83 The second problem is that administrators who desired to replicate a
84 smbpasswd file to more than one Samba server were left to use external
85 tools such as <command>rsync(1)</command> and <command>ssh(1)</command>
86 and wrote custom, in-house scripts.
87 </para></listitem>
88
89 <listitem><para>
90 And finally, the amount of information which is stored in an
91 smbpasswd entry leaves no room for additional attributes such as
92 a home directory, password expiration time, or even a Relative
93 Identified (RID).
94 </para></listitem>
95 </itemizedlist>
96
97 <para>
98 As a result of these defeciencies, a more robust means of storing user attributes
99 used by smbd was developed.  The API which defines access to user accounts
100 is commonly referred to as the samdb interface (previously this was called the passdb
101 API, and is still so named in the CVS trees). In Samba 2.2.3, enabling support
102 for a samdb backend (e.g. <parameter>--with-ldapsam</parameter> or
103 <parameter>--with-tdbsam</parameter>) requires compile time support.
104 </para>
105
106 <para>
107 When compiling Samba to include the <parameter>--with-ldapsam</parameter> autoconf
108 option, smbd (and associated tools) will store and lookup user accounts in
109 an LDAP directory.  In reality, this is very easy to understand.  If you are
110 comfortable with using an smbpasswd file, simply replace "smbpasswd" with
111 "LDAP directory" in all the documentation.
112 </para>
113
114 <para>
115 There are a few points to stress about what the <parameter>--with-ldapsam</parameter>
116 does not provide.  The LDAP support referred to in the this documentation does not
117 include:
118 </para>
119
120 <itemizedlist>
121         <listitem><para>A means of retrieving user account information from
122         an Windows 2000 Active Directory server.</para></listitem>
123         <listitem><para>A means of replacing /etc/passwd.</para></listitem>
124 </itemizedlist>
125
126 <para>
127 The second item can be accomplished by using LDAP NSS and PAM modules.  LGPL
128 versions of these libraries can be obtained from PADL Software
129 (<ulink url="http://www.padl.com/">http://www.padl.com/</ulink>).  However,
130 the details of configuring these packages are beyond the scope of this document.
131 </para>
132
133 </sect1>
134
135 <sect1>
136 <title>Supported LDAP Servers</title>
137
138 <para>
139 The LDAP samdb code in 2.2.3 has been developed and tested using the OpenLDAP
140 2.0 server and client libraries.  The same code should be able to work with
141 Netscape's Directory Server and client SDK. However, due to lack of testing
142 so far, there are bound to be compile errors and bugs.  These should not be
143 hard to fix. If you are so inclined, please be sure to forward all patches to
144 <ulink url="samba-patches@samba.org">samba-patches@samba.org</ulink> and
145 <ulink url="jerry@samba.org">jerry@samba.org</ulink>.
146 </para>
147
148 </sect1>
149
150
151
152
153 <sect1>
154 <title>Schema and Relationship to the RFC 2307 posixAccount</title>
155
156
157 <para>
158 Samba 2.2.3 includes the necessary schema file for OpenLDAP 2.0 in
159 <filename>examples/LDAP/samba.schema</filename>.  (Note that this schema
160 file has been modified since the experimental support initially included
161 in 2.2.2).  The sambaAccount objectclass is given here:
162 </para>
163
164 <para><programlisting>
165 objectclass ( 1.3.1.5.1.4.1.7165.2.2.2 NAME 'sambaAccount' SUP top STRUCTURAL
166      DESC 'Samba Account'
167      MUST ( uid $ rid )
168      MAY  ( cn $ lmPassword $ ntPassword $ pwdLastSet $ logonTime $
169             logoffTime $ kickoffTime $ pwdCanChange $ pwdMustChange $ acctFlags $
170             displayName $ smbHome $ homeDrive $ scriptPath $ profilePath $
171             description $ userWorkstations $ primaryGroupID $ domain ))
172 </programlisting></para>
173
174 <para>
175 The samba.schema file has been formatted for OpenLDAP 2.0.  The OID's are
176 owned by the Samba Team and as such is legal to be openly published.
177 If you translate the schema to be used with Netscape DS, please
178 submit the modified schema file as a patch to <ulink
179 url="jerry@samba.org">jerry@samba.org</ulink>
180 </para>
181
182 <para>
183 Just as the smbpasswd file is mean to store information which supplements a
184 user's <filename>/etc/passwd</filename> entry, so is the sambaAccount object
185 meant to supplement the UNIX user account information.  A sambaAccount is a
186 <constant>STRUCTURAL</constant> objectclass so it can be stored individually
187 in the directory.  However, there are several fields (e.g. uid) which overlap
188 with the posixAccount objectclass outlined in RFC2307.  This is by design.
189 </para>
190
191 <!--olem: we should perhaps have a note about shadowAccounts too as many
192 systems use them, isn'it ? -->
193
194 <para>
195 In order to store all user account information (UNIX and Samba) in the directory,
196 it is necessary to use the sambaAccount and posixAccount objectclasses in
197 combination.  However, smbd will still obtain the user's UNIX account
198 information via the standard C library calls (e.g. getpwnam(), et. al.).
199 This means that the Samba server must also have the LDAP NSS library installed
200 and functioning correctly.  This division of information makes it possible to
201 store all Samba account information in LDAP, but still maintain UNIX account
202 information in NIS while the network is transitioning to a full LDAP infrastructure.
203 </para>
204 </sect1>
205
206 <sect1>
207 <title>Configuring Samba with LDAP</title>
208
209
210 <sect2>
211 <title>OpenLDAP configuration</title>
212
213 <para>
214 To include support for the sambaAccount object in an OpenLDAP directory
215 server, first copy the samba.schema file to slapd's configuration directory.
216 </para>
217
218 <para>
219 <prompt>root# </prompt><command>cp samba.schema /etc/openldap/schema/</command>
220 </para>
221
222 <para>
223 Next, include the <filename>samba.schema</filename> file in <filename>slapd.conf</filename>.
224 The sambaAccount object contains two attributes which depend upon other schema
225 files.  The 'uid' attribute is defined in <filename>cosine.schema</filename> and
226 the 'displayName' attribute is defined in the <filename>inetorgperson.schema</filename>
227 file.  Both of these must be included before the <filename>samba.schema</filename> file.
228 </para>
229
230 <para><programlisting>
231 ## /etc/openldap/slapd.conf
232
233 ## schema files (core.schema is required by default)
234 include            /etc/openldap/schema/core.schema
235
236 ## needed for sambaAccount
237 include            /etc/openldap/schema/cosine.schema
238 include            /etc/openldap/schema/inetorgperson.schema
239 include            /etc/openldap/schema/samba.schema
240
241 ## uncomment this line if you want to support the RFC2307 (NIS) schema
242 ## include         /etc/openldap/schema/nis.schema
243
244 ....
245 </programlisting></para>
246
247 <para>
248 It is recommended that you maintain some indices on some of the most usefull attributes,
249 like in the following example, to speed up searches made on sambaAccount objectclasses
250 (and possibly posixAccount and posixGroup as well).
251 </para>
252 <para><programlisting>
253 # Indices to maintain
254 ## required by OpenLDAP 2.0
255 index objectclass   eq
256
257 ## support pb_getsampwnam()
258 index uid           pres,eq
259 ## support pdb_getsambapwrid()
260 index rid           eq
261
262 ## uncomment these if you are storing posixAccount and
263 ## posixGroup entries in the directory as well
264 ##index uidNumber     eq
265 ##index gidNumber     eq
266 ##index cn            eq
267 ##index memberUid     eq
268 </programlisting></para>
269 </sect2>
270
271
272 <sect2>
273 <title>Configuring Samba</title>
274 <!--lem: <title>smb.conf LDAP parameters</title> -->
275
276 <para>
277 The following parameters are available in smb.conf only with <parameter>--with-ldapsam</parameter>
278 was included with compiling Samba.
279 </para>
280
281 <itemizedlist>
282         <listitem><para><ulink url="smb.conf.5.html#LDAPSSL">ldap ssl</ulink></para></listitem>
283         <listitem><para><ulink url="smb.conf.5.html#LDAPSERVER">ldap server</ulink></para></listitem>
284         <listitem><para><ulink url="smb.conf.5.html#LDAPADMINDN">ldap admin dn</ulink></para></listitem>
285         <listitem><para><ulink url="smb.conf.5.html#LDAPSUFFIX">ldap suffix</ulink></para></listitem>
286         <listitem><para><ulink url="smb.conf.5.html#LDAPFILTER">ldap filter</ulink></para></listitem>
287         <listitem><para><ulink url="smb.conf.5.html#LDAPPORT">ldap port</ulink></para></listitem>
288 </itemizedlist>
289
290 <para>
291 These are described in the <ulink url="smb.conf.5.html">smb.conf(5)</ulink> man
292 page and so will not be repeated here.  However, a sample smb.conf file for
293 use with an LDAP directory could appear as
294 </para>
295
296 <para><programlisting>
297 ## /usr/local/samba/lib/smb.conf
298 [global]
299      security = user
300      encrypt passwords = yes
301
302      netbios name = TASHTEGO
303      workgroup = NARNIA
304
305      # ldap related parameters
306
307      # define the DN to use when binding to the directory servers
308      # The password for this DN is not stored in smb.conf.  Rather it
309      # must be set by using 'smbpasswd -w <replaceable>secretpw</replaceable>' to store the
310      # passphrase in the secrets.tdb file.  If the "ldap admin dn" values
311      # changes, this password will need to be reset.
312      ldap admin dn = "cn=Samba Manager,ou=people,dc=samba,dc=org"
313
314      #  specify the LDAP server's hostname (defaults to locahost)
315      ldap server = ahab.samba.org
316
317      # Define the SSL option when connecting to the directory
318      # ('off', 'start tls', or 'on' (default))
319      ldap ssl = start tls
320
321      # define the port to use in the LDAP session (defaults to 636 when
322      # "ldap ssl = on")
323      ldap port = 389
324
325      # specify the base DN to use when searching the directory
326      ldap suffix = "ou=people,dc=samba,dc=org"
327
328      # generally the default ldap search filter is ok
329      # ldap filter = "(&amp;(uid=%u)(objectclass=sambaAccount))"
330 </programlisting></para>
331
332
333 </sect2>
334 </sect1>
335
336
337 <sect1>
338 <title>Accounts and Groups management</title>
339
340 <para>
341 As users accounts are managed thru the sambaAccount objectclass, you should
342 modify you existing administration tools to deal with sambaAccount attributes.
343 </para>
344
345 <para>
346 Machines accounts are managed with the sambaAccount objectclass, just
347 like users accounts. However, it's up to you to stored thoses accounts
348 in a different tree of you LDAP namespace: you should use
349 "ou=Groups,dc=plainjoe,dc=org" to store groups and
350 "ou=People,dc=plainjoe,dc=org" to store users. Just configure your
351 NSS and PAM accordingly (usually, in the /etc/ldap.conf configuration
352 file).
353 </para>
354
355 <para>
356 In Samba release 2.2.3, the group management system is based on posix
357 groups. This meand that Samba make usage of the posixGroup objectclass.
358 For now, there is no NT-like group system management (global and local
359 groups).
360 </para>
361
362 </sect1>
363
364 <sect1>
365 <title>Security and sambaAccount</title>
366
367
368 <para>
369 There are two important points to remember when discussing the security
370 of sambaAccount entries in the directory.
371 </para>
372
373 <itemizedlist>
374         <listitem><para><emphasis>Never</emphasis> retrieve the lmPassword or
375         ntPassword attribute values over an unencrypted LDAP session.</para></listitem>
376         <listitem><para><emphasis>Never</emphasis> allow non-admin users to
377         view the lmPassword or ntPassword attribute values.</para></listitem>
378 </itemizedlist>
379
380 <para>
381 These password hashes are clear text equivalents and can be used to impersonate
382 the user without deriving the original clear text strings.  For more information
383 on the details of LM/NT password hashes, refer to the <ulink
384 url="ENCRYPTION.html">ENCRYPTION chapter</ulink> of the Samba-HOWTO-Collection.
385 </para>
386
387 <para>
388 To remedy the first security issue, the "ldap ssl" smb.conf parameter defaults
389 to require an encrypted session (<command>ldap ssl = on</command>) using
390 the default port of 636
391 when contacting the directory server.  When using an OpenLDAP 2.0 server, it
392 is possible to use the use the StartTLS LDAP extended  operation in the place of
393 LDAPS.  In either case, you are strongly discouraged to disable this security
394 (<command>ldap ssl = off</command>).
395 </para>
396
397 <para>
398 Note that the LDAPS protocol is deprecated in favor of the LDAPv3 StartTLS
399 extended operation.  However, the OpenLDAP library still provides support for
400 the older method of securing communication between clients and servers.
401 </para>
402
403 <para>
404 The second security precaution is to prevent non-administrative users from
405 harvesting password hashes from the directory.  This can be done using the
406 following ACL in <filename>slapd.conf</filename>:
407 </para>
408
409 <para><programlisting>
410 ## allow the "ldap admin dn" access, but deny everyone else
411 access to attrs=lmPassword,ntPassword
412      by dn="cn=Samba Admin,ou=people,dc=plainjoe,dc=org" write
413      by * none
414 </programlisting></para>
415
416
417 </sect1>
418
419
420
421 <sect1>
422 <title>LDAP specials attributes for sambaAccounts</title>
423
424 <para>
425 The sambaAccount objectclass is composed of the following attributes:
426 </para>
427
428 <itemizedlist>
429
430         <listitem><para><constant>lmPassword</constant>: the LANMAN password 16-byte hash stored as a character
431         representation of a hexidecimal string.</para></listitem>
432
433         <listitem><para><constant>ntPassword</constant>: the NT password hash 16-byte stored as a character
434         representation of a hexidecimal string.</para></listitem>
435
436         <listitem><para><constant>pwdLastSet</constant>: The integer time in seconds since 1970 when the
437         <constant>lmPassword</constant> and <constant>ntPassword</constant> attributes were last set.
438         </para></listitem>
439
440         <listitem><para><constant>acctFlags</constant>: string of 11 characters surrounded by square brackets []
441         representing account flags such as U (user), W(workstation), X(no password expiration), and
442         D(disabled).</para></listitem>
443
444         <listitem><para><constant>logonTime</constant>: Integer value currently unused</para></listitem>
445
446         <listitem><para><constant>logoffTime</constant>: Integer value currently unused</para></listitem>
447
448         <listitem><para><constant>kickoffTime</constant>: Integer value currently unused</para></listitem>
449
450         <listitem><para><constant>pwdCanChange</constant>: Integer value currently unused</para></listitem>
451
452         <listitem><para><constant>pwdMustChange</constant>: Integer value currently unused</para></listitem>
453
454         <listitem><para><constant>homeDrive</constant>: specifies the drive letter to which to map the
455         UNC path specified by homeDirectory. The drive letter must be specified in the form "X:"
456         where X is the letter of the drive to map. Refer to the "logon drive" parameter in the
457         smb.conf(5) man page for more information.</para></listitem>
458
459         <listitem><para><constant>scriptPath</constant>: The scriptPath property specifies the path of
460         the user's logon script, .CMD, .EXE, or .BAT file. The string can be null. The path
461         is relative to the netlogon share.  Refer to the "logon script" parameter in the
462         smb.conf(5) man page for more information.</para></listitem>
463
464         <listitem><para><constant>profilePath</constant>: specifies a path to the user's profile.
465         This value can be a null string, a local absolute path, or a UNC path.  Refer to the
466         "logon path" parameter in the smb.conf(5) man page for more information.</para></listitem>
467
468         <listitem><para><constant>smbHome</constant>: The homeDirectory property specifies the path of
469         the home directory for the user. The string can be null. If homeDrive is set and specifies
470         a drive letter, homeDirectory should be a UNC path. The path must be a network
471         UNC path of the form \\server\share\directory. This value can be a null string.
472         Refer to the "logon home" parameter in the smb.conf(5) man page for more information.
473         </para></listitem>
474
475         <listitem><para><constant>userWorkstation</constant>: character string value currently unused.
476         </para></listitem>
477
478         <listitem><para><constant>rid</constant>: the integer representation of the user's relative identifier
479         (RID).</para></listitem>
480
481         <listitem><para><constant>primaryGroupID</constant>: the relative identifier (RID) of the primary group
482         of the user.</para></listitem>
483
484 </itemizedlist>
485
486 <para>
487 The majority of these parameters are only used when Samba is acting as a PDC of
488 a domain (refer to the <ulink url="Samba-PDC-HOWTO.html">Samba-PDC-HOWTO</ulink> for details on
489 how to configure Samba as a Primary Domain Controller). The following four attributes
490 are only stored with the sambaAccount entry if the values are non-default values:
491 </para>
492
493 <itemizedlist>
494         <listitem><para>smbHome</para></listitem>
495         <listitem><para>scriptPath</para></listitem>
496         <listitem><para>logonPath</para></listitem>
497         <listitem><para>homeDrive</para></listitem>
498 </itemizedlist>
499
500 <para>
501 These attributes are only stored with the sambaAccount entry if
502 the values are non-default values.  For example, assume TASHTEGO has now been
503 configured as a PDC and that <command>logon home = \\%L\%u</command> was defined in
504 its <filename>smb.conf</filename> file. When a user named "becky" logons to the domain,
505 the <parameter>logon home</parameter> string is expanded to \\TASHTEGO\becky.
506 If the smbHome attribute exists in the entry "uid=becky,ou=people,dc=samba,dc=org",
507 this value is used.  However, if this attribute does not exist, then the value
508 of the <parameter>logon home</parameter> parameter is used in its place.  Samba
509 will only write the attribute value to the directory entry is the value is
510 something other than the default (e.g. \\MOBY\becky).
511 </para>
512
513
514 </sect1>
515
516
517
518 <sect1>
519 <title>Example LDIF Entries for a sambaAccount</title>
520
521
522 <para>
523 The following is a working LDIF with the inclusion of the posixAccount objectclass:
524 </para>
525
526 <para><programlisting>
527 dn: uid=guest2, ou=people,dc=plainjoe,dc=org
528 ntPassword: 878D8014606CDA29677A44EFA1353FC7
529 pwdMustChange: 2147483647
530 primaryGroupID: 1201
531 lmPassword: 552902031BEDE9EFAAD3B435B51404EE
532 pwdLastSet: 1010179124
533 logonTime: 0
534 objectClass: sambaAccount
535 uid: guest2
536 kickoffTime: 2147483647
537 acctFlags: [UX         ]
538 logoffTime: 2147483647
539 rid: 19006
540 pwdCanChange: 0
541 </programlisting></para>
542
543 <para>
544 The following is an LDIF entry for using both the sambaAccount and
545 posixAccount objectclasses:
546 </para>
547
548 <para><programlisting>
549 dn: uid=gcarter, ou=people,dc=plainjoe,dc=org
550 logonTime: 0
551 displayName: Gerald Carter
552 lmPassword: 552902031BEDE9EFAAD3B435B51404EE
553 primaryGroupID: 1201
554 objectClass: posixAccount
555 objectClass: sambaAccount
556 acctFlags: [UX         ]
557 userPassword: {crypt}BpM2ej8Rkzogo
558 uid: gcarter
559 uidNumber: 9000
560 cn: Gerald Carter
561 loginShell: /bin/bash
562 logoffTime: 2147483647
563 gidNumber: 100
564 kickoffTime: 2147483647
565 pwdLastSet: 1010179230
566 rid: 19000
567 homeDirectory: /home/tashtego/gcarter
568 pwdCanChange: 0
569 pwdMustChange: 2147483647
570 ntPassword: 878D8014606CDA29677A44EFA1353FC7
571 </programlisting></para>
572
573
574 </sect1>
575
576
577
578 <sect1>
579 <title>Comments</title>
580
581
582 <para>
583 Please mail all comments regarding this HOWTO to <ulink
584 url="mailto:jerry@samba.org">jerry@samba.org</ulink>.  This documents was
585 last updated to reflect the Samba 2.2.3 release.
586
587 </para>
588
589
590 </sect1>
591
592
593 </chapter>