This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.(This used to...
[ira/wip.git] / docs / docbook / projdoc / passdb.sgml
1 <chapter id="passdb">
2 <chapterinfo>
3         <author>
4                 <firstname>Jelmer</firstname><surname>Vernooij</surname>
5                 <affiliation>
6                         <orgname>The Samba Team</orgname>
7                         <address><email>jelmer@samba.org</email></address>
8                 </affiliation>
9         </author>
10         <author>
11                 <firstname>Gerald (Jerry)</firstname><surname>Carter</surname>
12                 <affiliation>
13                         <orgname>Samba Team</orgname>
14                         <address><email>jerry@samba.org</email></address>
15                 </affiliation>
16         </author>
17         <author>
18                 <firstname>Olivier (lem)</firstname><surname>Lemaire</surname>
19                 <affiliation>
20                         <orgname>IDEALX</orgname>
21                         <address><email>olem@IDEALX.org</email></address>
22                 </affiliation>
23         </author>
24         <author>
25                 <firstname>Jeremy</firstname><surname>Allison</surname>
26                 <affiliation>
27                         <orgname>Samba Team</orgname>
28                         <address>
29                                 <email>jra@samba.org</email>
30                         </address>
31                 </affiliation>
32         </author>
33         <author>
34                 <firstname>John H</firstname><surname>Terpstra</surname>
35                 <affiliation>
36                         <orgname>Samba Team</orgname>
37                         <address>
38                                 <email>jht@samba.org</email>
39                         </address>
40                 </affiliation>
41         </author>
42         
43         <pubdate>February 2003</pubdate>
44 </chapterinfo>
45
46 <title>User information database</title>
47
48 <sect1>
49         <title>Introduction</title>
50
51         <para>Old windows clients send plain text passwords over the wire. 
52         Samba can check these passwords by crypting them and comparing them 
53         to the hash stored in the unix user database.
54         </para>
55         
56         <para>
57         Newer windows clients send encrypted passwords (so-called 
58         Lanman and NT hashes) over 
59         the wire, instead of plain text passwords. The newest clients 
60         will only send encrypted passwords and refuse to send plain text 
61         passwords, unless their registry is tweaked.
62         </para>
63
64         <para>These passwords can't be converted to unix style encrypted 
65         passwords. Because of that you can't use the standard unix 
66         user database, and you have to store the Lanman and NT hashes 
67         somewhere else. </para>
68         
69         <para>Next to a differently encrypted passwords, 
70         windows also stores certain data for each user 
71         that is not stored in a unix user database, e.g. 
72         workstations the user may logon from, the location where his/her 
73         profile is stored, etc.
74         Samba retrieves and stores this information using a "passdb backend".
75         Commonly
76         available backends are LDAP, plain text file, MySQL and nisplus.
77         For more information, see the documentation about the 
78         <command>passdb backend = </command> parameter.
79         </para>
80 </sect1>
81
82 <sect1>
83         <title>Important Notes About Security</title>
84         
85         <para>The unix and SMB password encryption techniques seem similar 
86         on the surface. This similarity is, however, only skin deep. The unix 
87         scheme typically sends clear text passwords over the network when 
88         logging in. This is bad. The SMB encryption scheme never sends the 
89         cleartext password over the network but it does store the 16 byte 
90         hashed values on disk. This is also bad. Why? Because the 16 byte hashed 
91         values are a "password equivalent". You cannot derive the user's 
92         password from them, but they could potentially be used in a modified 
93         client to gain access to a server. This would require considerable 
94         technical knowledge on behalf of the attacker but is perfectly possible. 
95         You should thus treat the data stored in whatever 
96         passdb backend you use (smbpasswd file, ldap, mysql) as though it contained the 
97         cleartext passwords of all your users. Its contents must be kept 
98         secret, and the file should be protected accordingly.</para>
99         
100         <para>Ideally we would like a password scheme which neither requires 
101         plain text passwords on the net or on disk. Unfortunately this 
102         is not available as Samba is stuck with being compatible with 
103         other SMB systems (WinNT, WfWg, Win95 etc). </para>
104
105         <warning>
106                 <para>Note that Windows NT 4.0 Service pack 3 changed the 
107                 default for permissible authentication so that plaintext 
108                 passwords are <emphasis>never</emphasis> sent over the wire. 
109                 The solution to this is either to switch to encrypted passwords 
110                 with Samba or edit the Windows NT registry to re-enable plaintext 
111                 passwords. See the document WinNT.txt for details on how to do 
112                 this.</para>
113                 
114                 <para>Other Microsoft operating systems which also exhibit 
115                 this behavior includes</para>
116                 
117                 <para> These versions of MS Windows do not support full domain
118                 security protocols, although they may log onto a domain environment.
119                 Of these Only MS Windows XP Home does NOT support domain logons.</para>
120
121                 <simplelist>
122                         <member>MS DOS Network client 3.0 with 
123                         the basic network redirector installed</member>
124                         
125                         <member>Windows 95 with the network redirector 
126                         update installed</member>
127                         
128                         <member>Windows 98 [se]</member>
129
130                         <member>Windows Me</member>
131
132                         <member>Windows XP Home</member>
133                 </simplelist>
134
135                 <para> The following versions of MS Windows fully support domain
136                 security protocols.</para>
137
138                 <simplelist>
139                         <member>Windows NT 3.5x</member>
140
141                         <member>Windows NT 4.0</member>
142                         
143                         <member>Windows 2000 Professional</member>
144
145                         <member>Windows 200x Server/Advanced Server</member>
146
147                         <member>Windows XP Professional</member>
148                 </simplelist>
149                 
150                 <para><emphasis>Note :</emphasis>All current release of 
151                 Microsoft SMB/CIFS clients support authentication via the
152                 SMB Challenge/Response mechanism described here.  Enabling
153                 clear text authentication does not disable the ability
154                 of the client to participate in encrypted authentication.</para>
155
156
157                 <para>MS Windows clients will cache the encrypted password alone.
158                 Even when plain text passwords are re-enabled, through the appropriate
159                 registry change, the plain text password is NEVER cached. This means that
160                 in the event that a network connections should become disconnected (broken)
161                 only the cached (encrypted) password will be sent to the resource server
162                 to affect a auto-reconnect. If the resource server does not support encrypted
163                 passwords the auto-reconnect will fail. <emphasis>USE OF ENCRYPTED PASSWORDS
164                 IS STRONGLY ADVISED.</emphasis></para>
165         </warning>
166
167         <sect2>
168                 <title>Advantages of SMB Encryption</title>
169
170                 <simplelist>
171                         <member>Plain text passwords are not passed across 
172                         the network. Someone using a network sniffer cannot just 
173                         record passwords going to the SMB server.</member>
174                  
175                         <member>WinNT doesn't like talking to a server 
176                         that SM not support encrypted passwords. It will refuse 
177                         to browse the server if the server is also in user level 
178                         security mode. It will insist on prompting the user for the 
179                         password on each connection, which is very annoying. The
180                         only things you can do to stop this is to use SMB encryption.
181                         </member>
182
183                         <member>Encrypted password support allows auto-matic share
184                         (resource) reconnects.</member>
185                 </simplelist>
186         </sect2>
187
188
189         <sect2>
190                 <title>Advantages of non-encrypted passwords</title>
191
192                 <simplelist>
193                         <member>Plain text passwords are not kept 
194                         on disk, and are NOT cached in memory. </member>
195                         
196                         <member>Uses same password file as other unix 
197                         services such as login and ftp</member>
198                         
199                         <member>Use of other services (such as telnet and ftp) which
200                         send plain text passwords over the net, so sending them for SMB
201                         isn't such a big deal.</member>
202                 </simplelist>
203         </sect2>
204 </sect1>
205
206
207 <sect1>
208         <title>The smbpasswd Command</title>
209         
210         <para>The smbpasswd utility is a utility similar to the 
211         <command>passwd</command> or <command>yppasswd</command> programs.
212         It maintains the two 32 byte password fields in the passdb backend. </para>
213
214         <para><command>smbpasswd</command> works in a client-server mode 
215         where it contacts the local smbd to change the user's password on its 
216         behalf. This has enormous benefits - as follows.</para>
217
218         <para><command>smbpasswd</command> has the capability 
219         to change passwords on Windows NT servers (this only works when 
220         the request is sent to the NT Primary Domain Controller if you 
221         are changing an NT Domain user's password).</para>
222         
223         <para>To run smbpasswd as a normal user just type :</para>
224         
225         <para><prompt>$ </prompt><userinput>smbpasswd</userinput></para>
226         <para><prompt>Old SMB password: </prompt><userinput>&lt;type old value here - 
227         or hit return if there was no old password&gt;</userinput></para>
228         <para><prompt>New SMB Password: </prompt><userinput>&lt;type new value&gt;
229         </userinput></para>
230         <para><prompt>Repeat New SMB Password: </prompt><userinput>&lt;re-type new value
231         </userinput></para>
232         
233         <para>If the old value does not match the current value stored for 
234         that user, or the two new values do not match each other, then the 
235         password will not be changed.</para>
236         
237         <para>If invoked by an ordinary user it will only allow the user 
238         to change his or her own Samba password.</para>
239         
240         <para>If run by the root user smbpasswd may take an optional 
241         argument, specifying the user name whose SMB password you wish to 
242         change.  Note that when run as root smbpasswd does not prompt for 
243         or check the old password value, thus allowing root to set passwords 
244         for users who have forgotten their passwords.</para>
245         
246         <para><command>smbpasswd</command> is designed to work in the same way 
247         and be familiar to UNIX users who use the <command>passwd</command> or 
248         <command>yppasswd</command> commands.</para>
249
250         <para>For more details on using <command>smbpasswd</command> refer 
251         to the man page which will always be the definitive reference.</para>
252 </sect1>
253
254 <!--
255 <sect1>
256 <title>The <command>pdbedit</command> command</title>
257 FIXME
258 </sect1>
259 -->
260
261 <sect1>
262 <title>Plain text</title>
263 <para>
264 Older versions of samba retrieved user information from the unix user database 
265 and eventually some other fields from the file <filename>/etc/samba/smbpasswd</filename>
266 or <filename>/etc/smbpasswd</filename>. When password encryption is disabled, no 
267 data is stored at all.
268 </para>
269 </sect1>
270
271 <sect1>
272 <title>TDB</title>
273 <para>Samba can also store the user data in a "TDB" (Trivial Database). Using this backend 
274 doesn't require any additional configuration. This backend is recommended for new installations who 
275 don't require LDAP.
276 </para>
277 </sect1>
278
279 <sect1>
280 <title>LDAP</title>
281
282 <sect2>
283 <title>Introduction</title>
284
285 <para>
286 This document describes how to use an LDAP directory for storing Samba user
287 account information traditionally stored in the smbpasswd(5) file.  It is
288 assumed that the reader already has a basic understanding of LDAP concepts
289 and has a working directory server already installed.  For more information
290 on LDAP architectures and Directories, please refer to the following sites.
291 </para>
292
293 <itemizedlist>
294         <listitem><para>OpenLDAP - <ulink url="http://www.openldap.org/">http://www.openldap.org/</ulink></para></listitem>
295         <listitem><para>iPlanet Directory Server - <ulink url="http://iplanet.netscape.com/directory">http://iplanet.netscape.com/directory</ulink></para></listitem>
296 </itemizedlist>
297
298 <para>
299 Note that <ulink url="http://www.ora.com/">O'Reilly Publishing</ulink> is working on
300 a guide to LDAP for System Administrators which has a planned release date of
301 early summer, 2002.
302 </para>
303
304 <para>
305 Two additional Samba resources which may prove to be helpful are
306 </para>
307
308 <itemizedlist>
309         <listitem><para>The <ulink url="http://www.unav.es/cti/ldap-smb/ldap-smb-3-howto.html">Samba-PDC-LDAP-HOWTO</ulink>
310         maintained by Ignacio Coupeau.</para></listitem>
311
312         <listitem><para>The NT migration scripts from <ulink url="http://samba.idealx.org/">IDEALX</ulink> that are
313         geared to manage users and group in such a Samba-LDAP Domain Controller configuration.
314         </para></listitem>
315 </itemizedlist>
316
317 </sect2>
318
319 <sect2>
320 <title>Introduction</title>
321
322 <para>
323 Traditionally, when configuring <ulink url="smb.conf.5.html#ENCRYPTPASSWORDS">"encrypt
324 passwords = yes"</ulink> in Samba's <filename>smb.conf</filename> file, user account
325 information such as username, LM/NT password hashes, password change times, and account
326 flags have been stored in the <filename>smbpasswd(5)</filename> file.  There are several
327 disadvantages to this approach for sites with very large numbers of users (counted
328 in the thousands).
329 </para>
330
331 <itemizedlist>
332 <listitem><para>
333 The first is that all lookups must be performed sequentially.  Given that
334 there are approximately two lookups per domain logon (one for a normal
335 session connection such as when mapping a network drive or printer), this
336 is a performance bottleneck for lareg sites.  What is needed is an indexed approach
337 such as is used in databases.
338 </para></listitem>
339
340 <listitem><para>
341 The second problem is that administrators who desired to replicate a
342 smbpasswd file to more than one Samba server were left to use external
343 tools such as <command>rsync(1)</command> and <command>ssh(1)</command>
344 and wrote custom, in-house scripts.
345 </para></listitem>
346
347 <listitem><para>
348 And finally, the amount of information which is stored in an
349 smbpasswd entry leaves no room for additional attributes such as
350 a home directory, password expiration time, or even a Relative
351 Identified (RID).
352 </para></listitem>
353 </itemizedlist>
354
355 <para>
356 As a result of these defeciencies, a more robust means of storing user attributes
357 used by smbd was developed.  The API which defines access to user accounts
358 is commonly referred to as the samdb interface (previously this was called the passdb
359 API, and is still so named in the CVS trees). In Samba 2.2.3, enabling support
360 for a samdb backend (e.g. <parameter>--with-ldapsam</parameter> or
361 <parameter>--with-tdbsam</parameter>) requires compile time support.
362 </para>
363
364 <para>
365 When compiling Samba to include the <parameter>--with-ldapsam</parameter> autoconf
366 option, smbd (and associated tools) will store and lookup user accounts in
367 an LDAP directory.  In reality, this is very easy to understand.  If you are
368 comfortable with using an smbpasswd file, simply replace "smbpasswd" with
369 "LDAP directory" in all the documentation.
370 </para>
371
372 <para>
373 There are a few points to stress about what the <parameter>--with-ldapsam</parameter>
374 does not provide.  The LDAP support referred to in the this documentation does not
375 include:
376 </para>
377
378 <itemizedlist>
379         <listitem><para>A means of retrieving user account information from
380         an Windows 2000 Active Directory server.</para></listitem>
381         <listitem><para>A means of replacing /etc/passwd.</para></listitem>
382 </itemizedlist>
383
384 <para>
385 The second item can be accomplished by using LDAP NSS and PAM modules.  LGPL
386 versions of these libraries can be obtained from PADL Software
387 (<ulink url="http://www.padl.com/">http://www.padl.com/</ulink>).  However,
388 the details of configuring these packages are beyond the scope of this document.
389 </para>
390
391 </sect2>
392
393 <sect2>
394 <title>Supported LDAP Servers</title>
395
396 <para>
397 The LDAP samdb code in 2.2.3 (and later) has been developed and tested
398 using the OpenLDAP 2.0 server and client libraries. 
399 The same code should be able to work with Netscape's Directory Server
400 and client SDK. However, due to lack of testing so far, there are bound
401 to be compile errors and bugs.  These should not be hard to fix.
402 If you are so inclined, please be sure to forward all patches to
403 <ulink url="samba-patches@samba.org">samba-patches@samba.org</ulink> and
404 <ulink url="jerry@samba.org">jerry@samba.org</ulink>.
405 </para>
406
407 </sect2>
408
409 <sect2>
410 <title>Schema and Relationship to the RFC 2307 posixAccount</title>
411
412
413 <para>
414 Samba 3.0 includes the necessary schema file for OpenLDAP 2.0 in
415 <filename>examples/LDAP/samba.schema</filename>.  The sambaAccount objectclass is given here:
416 </para>
417
418 <para><programlisting>
419 objectclass ( 1.3.1.5.1.4.1.7165.2.2.2 NAME 'sambaAccount' SUP top STRUCTURAL
420      DESC 'Samba Account'
421      MUST ( uid $ rid )
422      MAY  ( cn $ lmPassword $ ntPassword $ pwdLastSet $ logonTime $
423             logoffTime $ kickoffTime $ pwdCanChange $ pwdMustChange $ acctFlags $
424             displayName $ smbHome $ homeDrive $ scriptPath $ profilePath $
425             description $ userWorkstations $ primaryGroupID $ domain ))
426 </programlisting></para>
427
428 <para>
429 The samba.schema file has been formatted for OpenLDAP 2.0.  The OID's are
430 owned by the Samba Team and as such is legal to be openly published.
431 If you translate the schema to be used with Netscape DS, please
432 submit the modified schema file as a patch to <ulink
433 url="jerry@samba.org">jerry@samba.org</ulink>
434 </para>
435
436 <para>
437 Just as the smbpasswd file is mean to store information which supplements a
438 user's <filename>/etc/passwd</filename> entry, so is the sambaAccount object
439 meant to supplement the UNIX user account information.  A sambaAccount is a
440 <constant>STRUCTURAL</constant> objectclass so it can be stored individually
441 in the directory.  However, there are several fields (e.g. uid) which overlap
442 with the posixAccount objectclass outlined in RFC2307.  This is by design.
443 </para>
444
445 <!--olem: we should perhaps have a note about shadowAccounts too as many
446 systems use them, isn'it ? -->
447
448 <para>
449 In order to store all user account information (UNIX and Samba) in the directory,
450 it is necessary to use the sambaAccount and posixAccount objectclasses in
451 combination.  However, smbd will still obtain the user's UNIX account
452 information via the standard C library calls (e.g. getpwnam(), et. al.).
453 This means that the Samba server must also have the LDAP NSS library installed
454 and functioning correctly.  This division of information makes it possible to
455 store all Samba account information in LDAP, but still maintain UNIX account
456 information in NIS while the network is transitioning to a full LDAP infrastructure.
457 </para>
458 </sect2>
459
460 <sect2>
461 <title>Configuring Samba with LDAP</title>
462
463
464 <sect3>
465 <title>OpenLDAP configuration</title>
466
467 <para>
468 To include support for the sambaAccount object in an OpenLDAP directory
469 server, first copy the samba.schema file to slapd's configuration directory.
470 </para>
471
472 <para>
473 <prompt>root# </prompt><command>cp samba.schema /etc/openldap/schema/</command>
474 </para>
475
476 <para>
477 Next, include the <filename>samba.schema</filename> file in <filename>slapd.conf</filename>.
478 The sambaAccount object contains two attributes which depend upon other schema
479 files.  The 'uid' attribute is defined in <filename>cosine.schema</filename> and
480 the 'displayName' attribute is defined in the <filename>inetorgperson.schema</filename>
481 file.  Both of these must be included before the <filename>samba.schema</filename> file.
482 </para>
483
484 <para><programlisting>
485 ## /etc/openldap/slapd.conf
486
487 ## schema files (core.schema is required by default)
488 include            /etc/openldap/schema/core.schema
489
490 ## needed for sambaAccount
491 include            /etc/openldap/schema/cosine.schema
492 include            /etc/openldap/schema/inetorgperson.schema
493 include            /etc/openldap/schema/samba.schema
494
495 ## uncomment this line if you want to support the RFC2307 (NIS) schema
496 ## include         /etc/openldap/schema/nis.schema
497
498 ....
499 </programlisting></para>
500
501 <para>
502 It is recommended that you maintain some indices on some of the most usefull attributes,
503 like in the following example, to speed up searches made on sambaAccount objectclasses
504 (and possibly posixAccount and posixGroup as well).
505 </para>
506 <para><programlisting>
507 # Indices to maintain
508 ## required by OpenLDAP 2.0
509 index objectclass   eq
510
511 ## support pb_getsampwnam()
512 index uid           pres,eq
513 ## support pdb_getsambapwrid()
514 index rid           eq
515
516 ## uncomment these if you are storing posixAccount and
517 ## posixGroup entries in the directory as well
518 ##index uidNumber     eq
519 ##index gidNumber     eq
520 ##index cn            eq
521 ##index memberUid     eq
522 </programlisting></para>
523 </sect3>
524
525
526 <sect3>
527 <title>Configuring Samba</title>
528 <!--lem: <title>smb.conf LDAP parameters</title> -->
529
530 <para>
531 The following parameters are available in smb.conf only with <parameter>--with-ldapsam</parameter>
532 was included with compiling Samba.
533 </para>
534
535 <itemizedlist>
536         <listitem><para><ulink url="smb.conf.5.html#LDAPSSL">ldap ssl</ulink></para></listitem>
537         <listitem><para><ulink url="smb.conf.5.html#LDAPSERVER">ldap server</ulink></para></listitem>
538         <listitem><para><ulink url="smb.conf.5.html#LDAPADMINDN">ldap admin dn</ulink></para></listitem>
539         <listitem><para><ulink url="smb.conf.5.html#LDAPSUFFIX">ldap suffix</ulink></para></listitem>
540         <listitem><para><ulink url="smb.conf.5.html#LDAPFILTER">ldap filter</ulink></para></listitem>
541         <listitem><para><ulink url="smb.conf.5.html#LDAPPORT">ldap port</ulink></para></listitem>
542 </itemizedlist>
543
544 <para>
545 These are described in the <ulink url="smb.conf.5.html">smb.conf(5)</ulink> man
546 page and so will not be repeated here.  However, a sample smb.conf file for
547 use with an LDAP directory could appear as
548 </para>
549
550 <para><programlisting>
551 ## /usr/local/samba/lib/smb.conf
552 [global]
553      security = user
554      encrypt passwords = yes
555
556      netbios name = TASHTEGO
557      workgroup = NARNIA
558
559      # ldap related parameters
560
561      # define the DN to use when binding to the directory servers
562      # The password for this DN is not stored in smb.conf.  Rather it
563      # must be set by using 'smbpasswd -w <replaceable>secretpw</replaceable>' to store the
564      # passphrase in the secrets.tdb file.  If the "ldap admin dn" values
565      # changes, this password will need to be reset.
566      ldap admin dn = "cn=Samba Manager,ou=people,dc=samba,dc=org"
567
568      #  specify the LDAP server's hostname (defaults to locahost)
569      ldap server = ahab.samba.org
570
571      # Define the SSL option when connecting to the directory
572      # ('off', 'start tls', or 'on' (default))
573      ldap ssl = start tls
574
575      # define the port to use in the LDAP session (defaults to 636 when
576      # "ldap ssl = on")
577      ldap port = 389
578
579      # specify the base DN to use when searching the directory
580      ldap suffix = "ou=people,dc=samba,dc=org"
581
582      # generally the default ldap search filter is ok
583      # ldap filter = "(&amp;(uid=%u)(objectclass=sambaAccount))"
584 </programlisting></para>
585
586
587 </sect3>
588 </sect2>
589
590
591 <sect2>
592 <title>Accounts and Groups management</title>
593
594 <para>
595 As users accounts are managed thru the sambaAccount objectclass, you should
596 modify you existing administration tools to deal with sambaAccount attributes.
597 </para>
598
599 <para>
600 Machines accounts are managed with the sambaAccount objectclass, just
601 like users accounts. However, it's up to you to stored thoses accounts
602 in a different tree of you LDAP namespace: you should use
603 "ou=Groups,dc=plainjoe,dc=org" to store groups and
604 "ou=People,dc=plainjoe,dc=org" to store users. Just configure your
605 NSS and PAM accordingly (usually, in the /etc/ldap.conf configuration
606 file).
607 </para>
608
609 <para>
610 In Samba release 3.0, the group management system is based on posix
611 groups. This means that Samba make usage of the posixGroup objectclass.
612 For now, there is no NT-like group system management (global and local
613 groups).
614 </para>
615
616 </sect2>
617
618 <sect2>
619 <title>Security and sambaAccount</title>
620
621
622 <para>
623 There are two important points to remember when discussing the security
624 of sambaAccount entries in the directory.
625 </para>
626
627 <itemizedlist>
628         <listitem><para><emphasis>Never</emphasis> retrieve the lmPassword or
629         ntPassword attribute values over an unencrypted LDAP session.</para></listitem>
630         <listitem><para><emphasis>Never</emphasis> allow non-admin users to
631         view the lmPassword or ntPassword attribute values.</para></listitem>
632 </itemizedlist>
633
634 <para>
635 These password hashes are clear text equivalents and can be used to impersonate
636 the user without deriving the original clear text strings.  For more information
637 on the details of LM/NT password hashes, refer to the <ulink
638 url="ENCRYPTION.html">ENCRYPTION chapter</ulink> of the Samba-HOWTO-Collection.
639 </para>
640
641 <para>
642 To remedy the first security issue, the "ldap ssl" smb.conf parameter defaults
643 to require an encrypted session (<command>ldap ssl = on</command>) using
644 the default port of 636
645 when contacting the directory server.  When using an OpenLDAP 2.0 server, it
646 is possible to use the use the StartTLS LDAP extended  operation in the place of
647 LDAPS.  In either case, you are strongly discouraged to disable this security
648 (<command>ldap ssl = off</command>).
649 </para>
650
651 <para>
652 Note that the LDAPS protocol is deprecated in favor of the LDAPv3 StartTLS
653 extended operation.  However, the OpenLDAP library still provides support for
654 the older method of securing communication between clients and servers.
655 </para>
656
657 <para>
658 The second security precaution is to prevent non-administrative users from
659 harvesting password hashes from the directory.  This can be done using the
660 following ACL in <filename>slapd.conf</filename>:
661 </para>
662
663 <para><programlisting>
664 ## allow the "ldap admin dn" access, but deny everyone else
665 access to attrs=lmPassword,ntPassword
666      by dn="cn=Samba Admin,ou=people,dc=plainjoe,dc=org" write
667      by * none
668 </programlisting></para>
669
670
671 </sect2>
672
673
674
675 <sect2>
676 <title>LDAP specials attributes for sambaAccounts</title>
677
678 <para>
679 The sambaAccount objectclass is composed of the following attributes:
680 </para>
681
682 <itemizedlist>
683
684         <listitem><para><constant>lmPassword</constant>: the LANMAN password 16-byte hash stored as a character
685         representation of a hexidecimal string.</para></listitem>
686
687         <listitem><para><constant>ntPassword</constant>: the NT password hash 16-byte stored as a character
688         representation of a hexidecimal string.</para></listitem>
689
690         <listitem><para><constant>pwdLastSet</constant>: The integer time in seconds since 1970 when the
691         <constant>lmPassword</constant> and <constant>ntPassword</constant> attributes were last set.
692         </para></listitem>
693
694         <listitem><para><constant>acctFlags</constant>: string of 11 characters surrounded by square brackets []
695         representing account flags such as U (user), W(workstation), X(no password expiration), and
696         D(disabled).</para></listitem>
697
698         <listitem><para><constant>logonTime</constant>: Integer value currently unused</para></listitem>
699
700         <listitem><para><constant>logoffTime</constant>: Integer value currently unused</para></listitem>
701
702         <listitem><para><constant>kickoffTime</constant>: Integer value currently unused</para></listitem>
703
704         <listitem><para><constant>pwdCanChange</constant>: Integer value currently unused</para></listitem>
705
706         <listitem><para><constant>pwdMustChange</constant>: Integer value currently unused</para></listitem>
707
708         <listitem><para><constant>homeDrive</constant>: specifies the drive letter to which to map the
709         UNC path specified by homeDirectory. The drive letter must be specified in the form "X:"
710         where X is the letter of the drive to map. Refer to the "logon drive" parameter in the
711         smb.conf(5) man page for more information.</para></listitem>
712
713         <listitem><para><constant>scriptPath</constant>: The scriptPath property specifies the path of
714         the user's logon script, .CMD, .EXE, or .BAT file. The string can be null. The path
715         is relative to the netlogon share.  Refer to the "logon script" parameter in the
716         smb.conf(5) man page for more information.</para></listitem>
717
718         <listitem><para><constant>profilePath</constant>: specifies a path to the user's profile.
719         This value can be a null string, a local absolute path, or a UNC path.  Refer to the
720         "logon path" parameter in the smb.conf(5) man page for more information.</para></listitem>
721
722         <listitem><para><constant>smbHome</constant>: The homeDirectory property specifies the path of
723         the home directory for the user. The string can be null. If homeDrive is set and specifies
724         a drive letter, homeDirectory should be a UNC path. The path must be a network
725         UNC path of the form \\server\share\directory. This value can be a null string.
726         Refer to the "logon home" parameter in the smb.conf(5) man page for more information.
727         </para></listitem>
728
729         <listitem><para><constant>userWorkstation</constant>: character string value currently unused.
730         </para></listitem>
731
732         <listitem><para><constant>rid</constant>: the integer representation of the user's relative identifier
733         (RID).</para></listitem>
734
735         <listitem><para><constant>primaryGroupID</constant>: the relative identifier (RID) of the primary group
736         of the user.</para></listitem>
737
738 </itemizedlist>
739
740 <para>
741 The majority of these parameters are only used when Samba is acting as a PDC of
742 a domain (refer to the <ulink url="Samba-PDC-HOWTO.html">Samba-PDC-HOWTO</ulink> for details on
743 how to configure Samba as a Primary Domain Controller). The following four attributes
744 are only stored with the sambaAccount entry if the values are non-default values:
745 </para>
746
747 <itemizedlist>
748         <listitem><para>smbHome</para></listitem>
749         <listitem><para>scriptPath</para></listitem>
750         <listitem><para>logonPath</para></listitem>
751         <listitem><para>homeDrive</para></listitem>
752 </itemizedlist>
753
754 <para>
755 These attributes are only stored with the sambaAccount entry if
756 the values are non-default values.  For example, assume TASHTEGO has now been
757 configured as a PDC and that <command>logon home = \\%L\%u</command> was defined in
758 its <filename>smb.conf</filename> file. When a user named "becky" logons to the domain,
759 the <parameter>logon home</parameter> string is expanded to \\TASHTEGO\becky.
760 If the smbHome attribute exists in the entry "uid=becky,ou=people,dc=samba,dc=org",
761 this value is used.  However, if this attribute does not exist, then the value
762 of the <parameter>logon home</parameter> parameter is used in its place.  Samba
763 will only write the attribute value to the directory entry is the value is
764 something other than the default (e.g. \\MOBY\becky).
765 </para>
766
767
768 </sect2>
769
770
771
772 <sect2>
773 <title>Example LDIF Entries for a sambaAccount</title>
774
775
776 <para>
777 The following is a working LDIF with the inclusion of the posixAccount objectclass:
778 </para>
779
780 <para><programlisting>
781 dn: uid=guest2, ou=people,dc=plainjoe,dc=org
782 ntPassword: 878D8014606CDA29677A44EFA1353FC7
783 pwdMustChange: 2147483647
784 primaryGroupID: 1201
785 lmPassword: 552902031BEDE9EFAAD3B435B51404EE
786 pwdLastSet: 1010179124
787 logonTime: 0
788 objectClass: sambaAccount
789 uid: guest2
790 kickoffTime: 2147483647
791 acctFlags: [UX         ]
792 logoffTime: 2147483647
793 rid: 19006
794 pwdCanChange: 0
795 </programlisting></para>
796
797 <para>
798 The following is an LDIF entry for using both the sambaAccount and
799 posixAccount objectclasses:
800 </para>
801
802 <para><programlisting>
803 dn: uid=gcarter, ou=people,dc=plainjoe,dc=org
804 logonTime: 0
805 displayName: Gerald Carter
806 lmPassword: 552902031BEDE9EFAAD3B435B51404EE
807 primaryGroupID: 1201
808 objectClass: posixAccount
809 objectClass: sambaAccount
810 acctFlags: [UX         ]
811 userPassword: {crypt}BpM2ej8Rkzogo
812 uid: gcarter
813 uidNumber: 9000
814 cn: Gerald Carter
815 loginShell: /bin/bash
816 logoffTime: 2147483647
817 gidNumber: 100
818 kickoffTime: 2147483647
819 pwdLastSet: 1010179230
820 rid: 19000
821 homeDirectory: /home/tashtego/gcarter
822 pwdCanChange: 0
823 pwdMustChange: 2147483647
824 ntPassword: 878D8014606CDA29677A44EFA1353FC7
825 </programlisting></para>
826
827 </sect2>
828 </sect1>
829
830 <sect1>
831 <title>MySQL</title>
832
833 <sect2>
834 <title>Building</title>
835
836 <para>To build the plugin, run <command>make bin/pdb_mysql.so</command>
837 in the <filename>source/</filename> directory of samba distribution. 
838 </para>
839
840 <para>Next, copy pdb_mysql.so to any location you want. I 
841 strongly recommend installing it in $PREFIX/lib or /usr/lib/samba/</para>
842
843 </sect2>
844
845 <sect2>
846 <title>Creating the database</title>
847
848 <para>
849 You either can set up your own table and specify the field names to pdb_mysql (see below
850 for the column names) or use the default table. The file <filename>examples/pdb/mysql/mysql.dump</filename> 
851 contains the correct queries to create the required tables. Use the command :
852
853 <command>mysql -u<replaceable>username</replaceable> -h<replaceable>hostname</replaceable> -p<replaceable>password</replaceable> <replaceable>databasename</replaceable> < <filename>/path/to/samba/examples/pdb/mysql/mysql.dump</filename></command>
854
855 </para>
856 </sect2>
857
858 <sect2>
859 <title>Configuring</title>
860
861 <para>This plugin lacks some good documentation, but here is some short info:</para>
862
863 <para>Add a the following to the <command>passdb backend</command> variable in your <filename>smb.conf</filename>:
864 <programlisting>
865 passdb backend = [other-plugins] plugin:/location/to/pdb_mysql.so:identifier [other-plugins]
866 </programlisting>
867 </para>
868
869 <para>The identifier can be any string you like, as long as it doesn't collide with 
870 the identifiers of other plugins or other instances of pdb_mysql. If you 
871 specify multiple pdb_mysql.so entries in 'passdb backend', you also need to 
872 use different identifiers!
873 </para>
874
875 <para>
876 Additional options can be given thru the smb.conf file in the [global] section.
877 </para>
878
879 <para><programlisting>
880 identifier:mysql host                     - host name, defaults to 'localhost'
881 identifier:mysql password
882 identifier:mysql user                     - defaults to 'samba'
883 identifier:mysql database                 - defaults to 'samba'
884 identifier:mysql port                     - defaults to 3306
885 identifier:table                          - Name of the table containing users
886 </programlisting></para>
887
888 <warning>
889 <para>
890 Since the password for the mysql user is stored in the 
891 smb.conf file, you should make the the smb.conf file 
892 readable only to the user that runs samba. This is considered a security 
893 bug and will be fixed soon.
894 </para>
895 </warning>
896
897 <para>Names of the columns in this table(I've added column types those columns should have first):</para>
898
899 <para><programlisting>
900 identifier:logon time column             - int(9)
901 identifier:logoff time column            - int(9)
902 identifier:kickoff time column           - int(9)
903 identifier:pass last set time column     - int(9)
904 identifier:pass can change time column   - int(9)
905 identifier:pass must change time column  - int(9)
906 identifier:username column               - varchar(255) - unix username
907 identifier:domain column                 - varchar(255) - NT domain user is part of
908 identifier:nt username column            - varchar(255) - NT username
909 identifier:fullname column            - varchar(255) - Full name of user
910 identifier:home dir column               - varchar(255) - Unix homedir path
911 identifier:dir drive column              - varchar(2) - Directory drive path (eg: 'H:')
912 identifier:logon script column           - varchar(255) - Batch file to run on client side when logging on
913 identifier:profile path column           - varchar(255) - Path of profile
914 identifier:acct desc column              - varchar(255) - Some ASCII NT user data
915 identifier:workstations column           - varchar(255) - Workstations user can logon to (or NULL for all)
916 identifier:unknown string column         - varchar(255) - unknown string
917 identifier:munged dial column            - varchar(255) - ?
918 identifier:uid column                    - int(9) - Unix user ID (uid)
919 identifier:gid column                    - int(9) - Unix user group (gid)
920 identifier:user sid column               - varchar(255) - NT user SID
921 identifier:group sid column              - varchar(255) - NT group ID
922 identifier:lanman pass column            - varchar(255) - encrypted lanman password
923 identifier:nt pass column                - varchar(255) - encrypted nt passwd
924 identifier:plain pass column             - varchar(255) - plaintext password
925 identifier:acct control column           - int(9) - nt user data
926 identifier:unknown 3 column              - int(9) - unknown
927 identifier:logon divs column             - int(9) - ?
928 identifier:hours len column              - int(9) - ?
929 identifier:unknown 5 column              - int(9) - unknown
930 identifier:unknown 6 column              - int(9) - unknown
931 </programlisting></para>
932
933 <para>
934 Eventually, you can put a colon (:) after the name of each column, which 
935 should specify the column to update when updating the table. You can also
936 specify nothing behind the colon - then the data from the field will not be 
937 updated. 
938 </para>
939
940 </sect2>
941
942 <sect2>
943 <title>Using plaintext passwords or encrypted password</title>
944
945 <para>
946 I strongly discourage the use of plaintext passwords, however, you can use them:
947 </para>
948
949 <para>
950 If you would like to use plaintext passwords, set 'identifier:lanman pass column' and 'identifier:nt pass column' to 'NULL' (without the quotes) and 'identifier:plain pass column' to the name of the column containing the plaintext passwords. 
951 </para>
952
953 <para>
954 If you use encrypted passwords, set the 'identifier:plain pass column' to 'NULL' (without the quotes). This is the default.
955 </para>
956
957 </sect2>
958
959 <sect2>
960 <title>Getting non-column data from the table</title>
961
962 <para>
963 It is possible to have not all data in the database and making some 'constant'.
964 </para>
965
966 <para>
967 For example, you can set 'identifier:fullname column' to : 
968 <command>CONCAT(First_name,' ',Sur_name)</command>
969 </para>
970
971 <para>
972 Or, set 'identifier:workstations column' to :
973 <command>NULL</command></para>
974
975 <para>See the MySQL documentation for more language constructs.</para>
976
977 </sect2>
978 </sect1>
979
980 <sect1>
981 <title>Passdb XML plugin</title>
982
983 <sect2>
984 <title>Building</title>
985
986 <para>This module requires libxml2 to be installed.</para>
987
988 <para>To build pdb_xml, run: <command>make bin/pdb_xml.so</command> in 
989 the directory <filename>source/</filename>. </para>
990
991 </sect2>
992
993 <sect2>
994 <title>Usage</title>
995
996 <para>The usage of pdb_xml is pretty straightforward. To export data, use:
997
998 <command>pdbedit -e plugin:/usr/lib/samba/pdb_xml.so:filename</command>
999
1000 (where filename is the name of the file to put the data in)
1001 </para>
1002
1003 <para>
1004 To import data, use:
1005 <command>pdbedit -i plugin:/usr/lib/samba/pdb_xml.so:filename -e current-pdb</command>
1006
1007 Where filename is the name to read the data from and current-pdb to put it in.
1008 </para>
1009 </sect2>
1010 </sect1>
1011
1012 </chapter>