4152494d2485eabc69c76ebe587a90ef36835b1f
[nivanova/samba-autobuild/.git] / docs / docbook / projdoc / passdb.xml
1 <chapter id="passdb">
2 <chapterinfo>
3         &author.jelmer;
4         &author.jerry;
5         &author.jeremy;
6         &author.jht;
7         <author>
8                 <firstname>Olivier (lem)</firstname><surname>Lemaire</surname>
9                 <affiliation>
10                         <orgname>IDEALX</orgname>
11                         <address><email>olem@IDEALX.org</email></address>
12                 </affiliation>
13         </author>
14         
15         <pubdate>May 24, 2003</pubdate>
16 </chapterinfo>
17 <title>Account Information Databases</title>
18
19 <para>
20 Samba-3 implements a new capability to work concurrently with mulitple account backends.
21 The possible new combinations of password backends allows Samba-3 a degree of flexibility
22 and scalability that previously could be achieved only with MS Windows Active Directory.
23 This chapter describes the new functionality and how to get the most out of it.
24 </para>
25
26 <para>
27 In the course of development of Samba-3 a number of requests were received to provide the
28 ability to migrate MS Windows NT4 SAM accounts to Samba-3 without the need to provide
29 matching Unix/Linux accounts. We called this the <emphasis>Non Unix Accounts (NUA)</emphasis>
30 capability. The intent was that an administrator could decide to use the <emphasis>tdbsam</emphasis>
31 backend and by simply specifying <emphasis>"passdb backedn = tdbsam_nua, guest"</emphasis>
32 this would allow Samba-3 to implement a solution that did not use Unix accounts per se. Late
33 in the development cycle the team doing this work hit upon some obstacles that prevents this
34 solution from being used. Given the delays with Samba-3 release a decision was made to NOT
35 deliver this functionality until a better method of recognising NT Group SIDs from NT User
36 SIDs could be found. This feature may thus return during the life cycle for the Samba-3 series.
37 </para>
38
39 <note><para>
40 Samba-3.0.0 does NOT support Non-Unix Account (NUA) operation.
41 </para></note>
42
43 <sect1>
44 <title>Features and Benefits</title>
45
46 <para>
47 Samba-3 provides for complete backwards compatibility with Samba-2.2.x functionality
48 as follows:
49 </para>
50
51 <variablelist>
52 <title>Backwards Compatibility Backends</title>
53         <varlistentry><term>Plain Text:</term>
54                 <listitem>
55                         <para>
56                         This option uses nothing but the Unix/Linux <filename>/etc/passwd</filename>
57                         style back end. On systems that have PAM (Pluggable Authentication Modules)
58                         support all PAM modules are supported. The behaviour is just as it was with
59                         Samba-2.2.x, and the protocol limitations imposed by MS Windows clients
60                         apply likewise.
61                         </para>
62                 </listitem>
63         </varlistentry>
64
65         <varlistentry><term>smbpasswd:</term>
66                 <listitem>
67                         <para>
68                         This option allows continues use of the <filename>smbpasswd</filename>
69                         file that maintains a plain ASCII (text) layout that includes the MS Windows
70                         LanMan and NT encrypted passwords as well as a field that stores some
71                         account information. This form of password backend does NOT store any of
72                         the MS Windows NT/200x SAM (Security Account Manager) information needed to
73                         provide the extended controls that are needed for more comprehensive 
74                         interoperation with MS Windows NT4 / 200x servers.
75                         </para>
76                 </listitem>
77         </varlistentry>
78
79         <varlistentry><term>ldapsam_compat (Samba-2.2 LDAP Compatibilty):</term>
80                 <listitem>
81                         <para>
82                         There is a password backend option that allows continued operation with
83                         a existing OpenLDAP backend that uses the Samba-2.2.x LDAP schema extension.
84                         This option is provided primarily as a migration tool, although there is
85                         no reason to force migration at this time.
86                         </para>
87                 </listitem>
88         </varlistentry>
89 </variablelist>
90
91 <para>
92 Samba-3 introduces the following new password backend capabilities:
93 </para>
94
95 <variablelist>
96 <title>New Backends</title>
97         <varlistentry><term>tdbsam:</term>
98                 <listitem>
99                         <para>
100                         The <emphasis>tdbsam</emphasis> password backend stores the old <emphasis>
101                         smbpasswd</emphasis> information PLUS the extended MS Windows NT / 200x
102                         SAM information into a binary format TDB (trivial database) file.
103                         The inclusion of the extended information makes it possible for Samba-3
104                         to implement the same account and system access controls that are possible
105                         with MS Windows NT4 and MS Windows 200x based systems.
106                         </para>
107
108                         <para>
109                         The inclusion of the <emphasis>tdbssam</emphasis> capability is a direct
110                         response to user requests to allow simple site operation without the overhead
111                         of the complexities of running OpenLDAP. It is recommended to use this only
112                         for sites that have fewer than 250 users. For larger sites or implementations
113                         the use of OpenLDAP or of Active Directory integration is strongly recommended.
114                         </para>
115                 </listitem>
116         </varlistentry>
117
118         <varlistentry><term>ldapsam:</term>
119                 <listitem>
120                         <para>
121                         Samba-3 has a new and extended LDAP implementation that requires configuration
122                         of OpenLDAP with a new format samba schema. The new format schema file is
123                         included in the <filename>~samba/examples/LDAP</filename> directory.
124                         </para>
125
126                         <para>
127                         The new LDAP implmentation significantly expands the control abilities that
128                         were possible with prior versions of Samba. It is not possible to specify
129                         "per user" profile settings, home directories, account access controls, and
130                         much more. Corporate sites will see that the Samba-Team has listened to their
131                         requests both for capability and to allow greater scalability.
132                         </para>
133                 </listitem>
134         </varlistentry>
135
136         <varlistentry><term>mysqlsam (MySQL based backend):</term>
137                 <listitem>
138                         <para>
139                         It is expected that the MySQL based SAM will be very popular in some corners.
140                         This database backend will be on considerable interest to sites that want to
141                         leverage existing MySQL technology.
142                         </para>
143                 </listitem>
144         </varlistentry>
145
146         <varlistentry><term>xmlsam (XML based datafile):</term>
147                 <listitem>
148                         <para>
149                         Allows the account and password data to be stored in an XML format
150                         data file. This backend is NOT recommended for normal operation, it is
151                         provided for developmental and for experimental use only. We recognise
152                         that this will not stop some people from using it anyhow, it should work
153                         but is NOT officially supported at this time (and likely will not be
154                         at any time).
155                         </para>
156
157                         <para>
158                         The xmlsam option can be useful for account migration between database
159                         backends. Use of this tool will allow the data to be edited before migration
160                         into another backend format.
161                         </para>
162                 </listitem>
163         </varlistentry>
164
165         <varlistentry><term>nisplussam:</term>
166                 <listitem>
167                         <para>
168                         The  NIS+ based passdb backend. Takes name NIS domain as an
169                         optional argument. Only works with Sun NIS+ servers.
170                         </para>
171                 </listitem>
172         </varlistentry>
173
174         <varlistentry><term>plugin:</term>
175                 <listitem>
176                         <para>
177                         This option allows any external non-Samba backend to interface directly
178                         to the samba code. This facility will allow third part vendors to provide
179                         a proprietary backend to Samba-3.
180                         </para>
181                 </listitem>
182         </varlistentry>
183 </variablelist>
184
185 </sect1>
186
187 <sect1>
188         <title>Technical Information</title>
189
190         <para>
191         Old windows clients send plain text passwords over the wire. Samba can check these
192         passwords by crypting them and comparing them to the hash stored in the unix user database.
193         </para>
194         
195         <para>
196         Newer windows clients send encrypted passwords (so-called Lanman and NT hashes) over 
197         the wire, instead of plain text passwords. The newest clients will send only encrypted
198         passwords and refuse to send plain text passwords, unless their registry is tweaked.
199         </para>
200
201         <para>
202         These passwords can't be converted to unix style encrypted passwords. Because of that
203         you can't use the standard unix user database, and you have to store the Lanman and NT
204         hashes somewhere else.
205         </para>
206         
207         <para>
208         In addition to differently encrypted passwords, windows also stores certain data for each
209         user that is not stored in a unix user database. e.g: workstations the user may logon from,
210         the location where the users' profile is stored, and so on. Samba retrieves and stores this
211         information using a <parameter>passdb backend</parameter>.  Commonly available backends are LDAP, plain text
212         file, MySQL and nisplus.  For more information, see the man page for &smb.conf; regarding the 
213         <parameter>passdb backend</parameter> parameter.
214         </para>
215
216         <sect2>
217         <title>Important Notes About Security</title>
218                 
219                 <para>
220                 The unix and SMB password encryption techniques seem similar on the surface. This
221                 similarity is, however, only skin deep. The unix scheme typically sends clear text
222                 passwords over the network when logging in. This is bad. The SMB encryption scheme
223                 never sends the cleartext password over the network but it does store the 16 byte 
224                 hashed values on disk. This is also bad. Why? Because the 16 byte hashed values
225                 are a "password equivalent". You cannot derive the user's password from them, but
226                 they could potentially be used in a modified client to gain access to a server.
227                 This would require considerable technical knowledge on behalf of the attacker but
228                 is perfectly possible. You should thus treat the data stored in whatever passdb
229                 backend you use (smbpasswd file, ldap, mysql) as though it contained the cleartext
230                 passwords of all your users. Its contents must be kept secret, and the file should
231                 be protected accordingly.
232                 </para>
233                 
234                 <para>
235                 Ideally we would like a password scheme that involves neither plain text passwords
236                 on the net nor on disk. Unfortunately this is not available as Samba is stuck with
237                 having to be compatible with other SMB systems (WinNT, WfWg, Win95 etc).
238                 </para>
239
240                 <para>
241                 Windows NT 4.0 Service pack 3 changed the default setting so that plaintext passwords
242                 are disabled from being sent over the wire. This mandates either the use of encrypted
243                 password support or edit the Windows NT registry to re-enable plaintext passwords.
244                 </para>
245                 
246                 <para>
247                 The following versions of MS Windows do not support full domain security protocols,
248                 although they may log onto a domain environment:
249                 </para>
250
251                 <itemizedlist>
252                         <listitem><para>
253                         MS DOS Network client 3.0 with the basic network redirector installed
254                         </para></listitem>
255
256                         <listitem><para>
257                         Windows 95 with the network redirector update installed
258                         </para></listitem>
259
260                         <listitem><para>
261                         Windows 98 [se]
262                         </para></listitem>
263
264                         <listitem><para>
265                         Windows Me</para>
266                         </listitem>
267                 </itemizedlist>
268
269                 <note>
270                 <para>
271                 MS Windows XP Home does not have facilities to become a domain member and it can
272                 not participate in domain logons.
273                 </para>
274                 </note>
275
276                 <para>
277                 The following versions of MS Windows fully support domain security protocols.
278                 </para>
279
280                 <itemizedlist>
281                         <listitem><para>Windows NT 3.5x</para></listitem>
282                         <listitem><para>Windows NT 4.0</para></listitem>
283                         <listitem><para>Windows 2000 Professional</para></listitem>
284                         <listitem><para>Windows 200x Server/Advanced Server</para></listitem>
285                         <listitem><para>Windows XP Professional</para></listitem>
286                 </itemizedlist>
287                         
288                 <para>
289                 All current release of Microsoft SMB/CIFS clients support authentication via the
290                 SMB Challenge/Response mechanism described here. Enabling clear text authentication
291                 does not disable the ability of the client to participate in encrypted authentication.
292                 Instead, it allows the client to negotiate either plain text _or_ encrypted password
293                 handling.
294                 </para>
295
296                 <para>
297                 MS Windows clients will cache the encrypted password alone. Where plain text passwords
298                 are re-enabled, through the appropriate registry change, the plain text password is NEVER
299                 cached. This means that in the event that a network connections should become disconnected
300                 (broken) only the cached (encrypted) password will be sent to the resource server to
301                 affect a auto-reconnect. If the resource server does not support encrypted passwords the
302                 auto-reconnect will fail. <emphasis>USE OF ENCRYPTED PASSWORDS IS STRONGLY ADVISED.</emphasis>
303                 </para>
304
305                 <sect3>
306                 <title>Advantages of Encrypted Passwords</title>
307
308                         <itemizedlist>
309                                 <listitem><para>Plain text passwords are not passed across 
310                                 the network. Someone using a network sniffer cannot just 
311                                 record passwords going to the SMB server.</para></listitem>
312
313                                 <listitem><para>Plain text passwords are not stored anywhere in
314                                 memory or on disk.</para></listitem>
315                          
316                                 <listitem><para>WinNT doesn't like talking to a server 
317                                 that does not support encrypted passwords. It will refuse 
318                                 to browse the server if the server is also in user level 
319                                 security mode. It will insist on prompting the user for the 
320                                 password on each connection, which is very annoying. The
321                                 only things you can do to stop this is to use SMB encryption.
322                                 </para></listitem>
323
324                                 <listitem><para>Encrypted password support allows automatic share
325                                 (resource) reconnects.</para></listitem>
326
327                                 <listitem><para>Encrypted passwords are essential for PDC/BDC
328                                 operation.</para></listitem>
329                         </itemizedlist>
330                 </sect3>
331
332
333                 <sect3>
334                 <title>Advantages of non-encrypted passwords</title>
335
336                         <itemizedlist>
337                                 <listitem><para>Plain text passwords are not kept 
338                                 on disk, and are NOT cached in memory. </para></listitem>
339                                 
340                                 <listitem><para>Uses same password file as other unix 
341                                 services such as login and ftp</para></listitem>
342                                 
343                                 <listitem><para>Use of other services (such as telnet and ftp) which
344                                 send plain text passwords over the net, so sending them for SMB
345                                 isn't such a big deal.</para></listitem>
346                         </itemizedlist>
347                 </sect3>
348         </sect2>
349
350         <sect2>
351         <title>Mapping User Identifiers between MS Windows and Unix</title>
352
353         <para>
354         Every operation in Unix/Linux requires a user identifier (UID), just as in
355         MS Windows NT4 / 200x this requires a Security Identifier (SID). Samba provides
356         two means for mapping an MS Windows user to a Unix/Linux UID.
357         </para>
358
359         <para>
360         Firstly, all Samba SAM (Security Account Management database) accounts require
361         a Unix/Linux UID that the account will map to. As users are added to the account
362         information database samba-3 will call the <command>add user script</command>
363         interface to add the account to the Samba host OS. In essence all accounts in
364         the local SAM require a local user account.
365         </para>
366
367         <para>
368         The second way to affect Windows SID to Unix UID mapping is via the
369         <emphasis>idmap uid, idmap gid</emphasis> parameters in &smb.conf;.
370         Please refer to the man page for information about these parameters.
371         These parameters are essential when mapping users from a remote SAM server.
372         </para>
373
374         </sect2>
375 </sect1>
376
377 <sect1>
378 <title>Account Management Tools</title>
379
380 <para>
381 Samba-3 provides two (2) tools for management of User and machine accounts. These tools are
382 called <filename>smbpasswd</filename> and <filename>pdbedit</filename>. A third tool is under
383 development but is NOT expected to ship in time for Samba-3.0.0. The new tool will be a TCL/TK
384 GUI tool that looks much like the MS Windows NT4 Domain User Manager - hopefully this will
385 be announced in time for samba-3.0.1 release timing.
386 </para>
387         <sect2>
388         <title>The <emphasis>smbpasswd</emphasis> Command</title>
389         
390                 <para>
391                 The smbpasswd utility is a utility similar to the <command>passwd</command>
392                 or <command>yppasswd</command> programs.  It maintains the two 32 byte password
393                 fields in the passdb backend.
394                 </para>
395
396                 <para>
397                 <command>smbpasswd</command> works in a client-server mode where it contacts the
398                 local smbd to change the user's password on its behalf.This has enormous benefits
399                 as follows:
400                 </para>
401
402                 <para>
403                 <command>smbpasswd</command> has the capability to change passwords on Windows NT
404                 servers (this only works when the request is sent to the NT Primary Domain Controller
405                 if changing an NT Domain user's password).
406                 </para>
407
408                 <para>
409                 <command>smbpasswd</command> can be used to:
410                 </para>
411                 
412                 <itemizedlist>
413                         <listitem><para>
414                         <emphasis>add</emphasis> user or machine accounts
415                         </para></listitem>
416
417                         <listitem><para>
418                         <emphasis>delete</emphasis> user or machine accounts
419                         </para></listitem>
420
421                         <listitem><para>
422                         <emphasis>enable</emphasis> user or machine accounts
423                         </para></listitem>
424
425                         <listitem><para>
426                         <emphasis>disable</emphasis> user or machine accounts
427                         </para></listitem>
428
429                         <listitem><para>
430                         <emphasis>set to NULL</emphasis> user passwords
431                         </para></listitem>
432
433                         <listitem><para>
434                         <emphasis>manage interdomain trust accounts</emphasis>
435                         </para></listitem>
436                 </itemizedlist>
437                 
438                 <para>
439                 To run smbpasswd as a normal user just type:
440                 </para>
441                 
442                 <para>
443                 <programlisting>
444                 <prompt>$ </prompt><userinput>smbpasswd</userinput>
445                 <prompt>Old SMB password: </prompt><userinput>&lt;secret&gt;</userinput>
446                 </programlisting>
447                 For <emphasis>secret</emphasis> type old value here - or hit return if
448                 there was no old password
449                 <programlisting>
450                 <prompt>New SMB Password: </prompt><userinput>&lt;new secret&gt;</userinput>
451                 <prompt>Repeat New SMB Password: </prompt><userinput>&lt;new secret&gt;</userinput>
452                 </programlisting>
453                 </para>
454                 
455                 <para>
456                 If the old value does not match the current value stored for that user, or the two
457                 new values do not match each other, then the password will not be changed.
458                 </para>
459                 
460                 <para>
461                 When invoked by an ordinary user it will only allow change of their own
462                 SMB password.
463                 </para>
464                 
465                 <para>
466                 When run by root smbpasswd may take an optional argument, specifying
467                 the user name whose SMB password you wish to change. When run as root, smbpasswd
468                 does not prompt for or check the old password value, thus allowing root to set passwords 
469                 for users who have forgotten their passwords.
470                 </para>
471                 
472                 <para>
473                 <command>smbpasswd</command> is designed to work in the way familiar to UNIX
474                 users who use the <command>passwd</command> or <command>yppasswd</command> commands.
475                 While designed for administrative use, this tool provides essential user level
476                 password change capabilities.
477                 </para>
478
479                 <para>
480                 For more details on using <command>smbpasswd</command> refer to the man page (the
481                 definitive reference).
482                 </para>
483         </sect2>
484
485         <sect2>
486         <title>The <emphasis>pdbedit</emphasis> Command</title>
487
488                 <para>
489                 <command>pdbedit</command> is a tool that can be used only by root. It is used to
490                 manage the passdb backend. <command>pdbedit</command> can be used to:
491                 </para>
492
493                 <itemizedlist>
494                         <listitem><para>
495                         add, remove or modify user accounts
496                         </para></listitem>
497
498                         <listitem><para>
499                         listing user accounts
500                         </para></listitem>
501
502                         <listitem><para>
503                         migrate user accounts
504                         </para></listitem>
505                 </itemizedlist>
506
507                 <para>
508                 The <command>pdbedit</command> tool is the only one that can manage the account
509                 security and policy settings. It is capable of all operations that smbpasswd can
510                 do as well as a super set of them.
511                 </para>
512
513                 <para>
514                 One particularly important purpose of the <command>pdbedit</command> is to allow
515                 the migration of account information from one passdb backend to another. See the
516                 <link linkend="XMLpassdb">XML</link> password backend section of this chapter.
517                 </para>
518
519                 <para>
520                 The following is an example of the user account information that is stored in
521                 a tdbsam password backend. This listing was produced by running:
522                 </para>
523
524                 <para>
525                 pdbedit -Lv met
526                 <programlisting>
527                 Unix username:        met
528                 NT username:
529                 Account Flags:        [UX         ]
530                 User SID:             S-1-5-21-1449123459-1407424037-3116680435-2004
531                 Primary Group SID:    S-1-5-21-1449123459-1407424037-3116680435-1201
532                 Full Name:            Melissa E Terpstra
533                 Home Directory:       \\frodo\met\Win9Profile
534                 HomeDir Drive:        H:
535                 Logon Script:         scripts\logon.bat
536                 Profile Path:         \\frodo\Profiles\met
537                 Domain:               MIDEARTH
538                 Account desc:
539                 Workstations:         melbelle
540                 Munged dial:
541                 Logon time:           0
542                 Logoff time:          Mon, 18 Jan 2038 20:14:07 GMT
543                 Kickoff time:         Mon, 18 Jan 2038 20:14:07 GMT
544                 Password last set:    Sat, 14 Dec 2002 14:37:03 GMT
545                 Password can change:  Sat, 14 Dec 2002 14:37:03 GMT
546                 Password must change: Mon, 18 Jan 2038 20:14:07 GMT
547                 </programlisting>
548                 </para>
549
550         </sect2>
551 </sect1>
552
553 <sect1>
554 <title>Password Backends</title>
555
556 <para>
557 Samba-3 offers the greatest flexibility in backend account database design of any SMB/CIFS server
558 technology available today. The flexibility is immediately obvious as one begins to explore this
559 capability.
560 </para>
561
562 <para>
563 It is possible to specify not only multiple different password backends, but even multiple
564 backends of the same type. For example, to use two different tdbsam databases:
565 </para>
566
567 <para>
568 <programlisting>
569 In smb.conf [globals]
570         passdb backend = tdbsam:/etc/samba/passdb.tdb, \
571                 tdbsam:/etc/samba/old-passdb.tdb, guest
572 </programlisting>
573 </para>
574
575
576         <sect2>
577         <title>Plain Text</title>
578
579                 <para>
580                 Older versions of samba retrieved user information from the unix user database 
581                 and eventually some other fields from the file <filename>/etc/samba/smbpasswd</filename>
582                 or <filename>/etc/smbpasswd</filename>. When password encryption is disabled, no 
583                 SMB specific data is stored at all. Instead all operations are conduected via the way
584                 that the samba host OS will access it's <filename>/etc/passwd</filename> database.
585                 eg: On Linux systems that is done via PAM.
586                 </para>
587
588         </sect2>
589
590         <sect2>
591         <title>smbpasswd - Encrypted Password Database</title>
592
593                 <para>
594                 Traditionally, when configuring <ulink url="smb.conf.5.html#ENCRYPTPASSWORDS">"encrypt
595                 passwords = yes"</ulink> in Samba's <filename>smb.conf</filename> file, user account
596                 information such as username, LM/NT password hashes, password change times, and account
597                 flags have been stored in the <filename>smbpasswd(5)</filename> file.  There are several
598                 disadvantages to this approach for sites with very large numbers of users (counted
599                 in the thousands).
600                 </para>
601
602                 <itemizedlist>
603                 <listitem><para>
604                 The first is that all lookups must be performed sequentially.  Given that
605                 there are approximately two lookups per domain logon (one for a normal
606                 session connection such as when mapping a network drive or printer), this
607                 is a performance bottleneck for large sites.  What is needed is an indexed approach
608                 such as is used in databases.
609                 </para></listitem>
610
611                 <listitem><para>
612                 The second problem is that administrators who desire to replicate a smbpasswd file
613                 to more than one Samba server were left to use external tools such as
614                 <command>rsync(1)</command> and <command>ssh(1)</command> and wrote custom,
615                 in-house scripts.
616                 </para></listitem>
617
618                 <listitem><para>
619                 And finally, the amount of information which is stored in an smbpasswd entry leaves
620                 no room for additional attributes such as a home directory, password expiration time,
621                 or even a Relative Identified (RID).
622                 </para></listitem>
623                 </itemizedlist>
624
625                 <para>
626                 As a result of these defeciencies, a more robust means of storing user attributes
627                 used by smbd was developed.  The API which defines access to user accounts
628                 is commonly referred to as the samdb interface (previously this was called the passdb
629                 API, and is still so named in the Samba CVS trees). 
630                 </para>
631
632                 <para>
633                 Samba-3 provides an enhanced set of passdb backends that overcome the deficiencies
634                 of the smbpasswd plain text database. These are tdbsam, ldapsam, and xmlsam.
635                 Of these ldapsam will be of most interest to large corporate or enterprise sites.
636                 </para>
637
638         </sect2>
639
640         <sect2>
641         <title>tdbsam</title>
642
643                 <para>Samba can store user and machine account data in a "TDB" (Trivial Database).
644                 Using this backend doesn't require any additional configuration. This backend is
645                 recommended for new installations that do not require LDAP.
646                 </para>
647
648                 <para>
649                 As a general guide the Samba-Team do NOT recommend using the tdbsam backend for sites
650                 that have 250 or more users. Additionally, tdbsam is not capable of scaling for use
651                 in sites that require PDB/BDC implmentations that requires replication of the account
652                 database. Clearly, for reason of scalability the use of ldapsam should be encouraged.
653                 </para>
654
655         </sect2>
656
657         <sect2>
658         <title>ldapsam</title>
659
660                 <para>
661                 There are a few points to stress that the ldapsam does not provide. The LDAP
662                 support referred to in the this documentation does not include:
663                 </para>
664
665                 <itemizedlist>
666                         <listitem><para>A means of retrieving user account information from
667                         an Windows 200x Active Directory server.</para></listitem>
668                         <listitem><para>A means of replacing /etc/passwd.</para></listitem>
669                 </itemizedlist>
670
671                 <para>
672                 The second item can be accomplished by using LDAP NSS and PAM modules.  LGPL
673                 versions of these libraries can be obtained from PADL Software
674                 (<ulink url="http://www.padl.com/">http://www.padl.com/</ulink>). More
675                 information about the configuration of these packages may be found at "LDAP,
676                 System Administration; Gerald Carter, O'Reilly; Chapter 6: Replacing NIS".
677                 Refer to <ulink url="http://safari.oreilly.com/?XmlId=1-56592-491-6">
678                 http://safari.oreilly.com/?XmlId=1-56592-491-6</ulink> for those who might wish to know
679                 more about configuration and adminstration of an OpenLDAP server.
680                 </para>
681
682                 <para>
683                 This document describes how to use an LDAP directory for storing Samba user
684                 account information traditionally stored in the smbpasswd(5) file.  It is
685                 assumed that the reader already has a basic understanding of LDAP concepts
686                 and has a working directory server already installed.  For more information
687                 on LDAP architectures and Directories, please refer to the following sites.
688                 </para>
689
690                 <itemizedlist>
691                         <listitem><para>OpenLDAP - <ulink url="http://www.openldap.org/">http://www.openldap.org/</ulink></para></listitem>
692                         <listitem><para>iPlanet Directory Server -
693                          <ulink url="http://iplanet.netscape.com/directory">http://iplanet.netscape.com/directory</ulink></para></listitem>
694                 </itemizedlist>
695
696                 <para>
697                 Two additional Samba resources which may prove to be helpful are
698                 </para>
699
700                 <itemizedlist>
701                         <listitem><para>The <ulink url="http://www.unav.es/cti/ldap-smb/ldap-smb-3-howto.html">Samba-PDC-LDAP-HOWTO</ulink>
702                         maintained by Ignacio Coupeau.</para></listitem>
703
704                         <listitem><para>The NT migration scripts from <ulink url="http://samba.idealx.org/">IDEALX</ulink> that are
705                         geared to manage users and group in such a Samba-LDAP Domain Controller configuration.
706                         </para></listitem>
707                 </itemizedlist>
708
709                 <sect3>
710                 <title>Supported LDAP Servers</title>
711
712                         <para>
713                         The LDAP ldapsam code has been developed and tested using the OpenLDAP 2.0 and 2.1 server and
714                         client libraries.  The same code should work with Netscape's Directory Server and client SDK.
715                         However, there are bound to be compile errors and bugs. These should not be hard to fix.
716                         Please submit fixes via <link linkend="bugreport">Bug reporting facility</link>.
717                         </para>
718
719                 </sect3>
720
721                 <sect3>
722                 <title>Schema and Relationship to the RFC 2307 posixAccount</title>
723
724
725                         <para>
726                         Samba 3.0 includes the necessary schema file for OpenLDAP 2.0 in
727                         <filename>examples/LDAP/samba.schema</filename>.  The sambaAccount objectclass is given here:
728                         </para>
729
730 <para>
731 <programlisting>
732 objectclass ( 1.3.6.1.4.1.7165.2.2.3 NAME 'sambaAccount' SUP top AUXILIARY
733     DESC 'Samba Auxilary Account'
734     MUST ( uid $ rid )
735     MAY  ( cn $ lmPassword $ ntPassword $ pwdLastSet $ logonTime $
736            logoffTime $ kickoffTime $ pwdCanChange $ pwdMustChange $ acctFlags $
737            displayName $ smbHome $ homeDrive $ scriptPath $ profilePath $
738            description $ userWorkstations $ primaryGroupID $ domain ))
739 </programlisting>
740 </para>
741
742                         <para>
743                         The <filename>samba.schema</filename> file has been formatted for OpenLDAP 2.0/2.1.
744                         The OID's are owned by the Samba Team and as such is legal to be openly published.
745                         If you translate the schema to be used with Netscape DS, please
746                         submit the modified schema file as a patch to
747                         <ulink url="mailto:jerry@samba.org">jerry@samba.org</ulink>.
748                         </para>
749
750                         <para>
751                         Just as the smbpasswd file is meant to store information which supplements a
752                         user's <filename>/etc/passwd</filename> entry, so is the sambaAccount object
753                         meant to supplement the UNIX user account information.  A sambaAccount is a
754                         <constant>STRUCTURAL</constant> objectclass so it can be stored individually
755                         in the directory.  However, there are several fields (e.g. uid) which overlap
756                         with the posixAccount objectclass outlined in RFC2307.  This is by design.
757                         </para>
758
759                         <!--olem: we should perhaps have a note about shadowAccounts too as many
760                         systems use them, isn'it ? -->
761
762                         <para>
763                         In order to store all user account information (UNIX and Samba) in the directory,
764                         it is necessary to use the sambaAccount and posixAccount objectclasses in
765                         combination.  However, smbd will still obtain the user's UNIX account
766                         information via the standard C library calls (e.g. getpwnam(), et. al.).
767                         This means that the Samba server must also have the LDAP NSS library installed
768                         and functioning correctly.  This division of information makes it possible to
769                         store all Samba account information in LDAP, but still maintain UNIX account
770                         information in NIS while the network is transitioning to a full LDAP infrastructure.
771                         </para>
772                 </sect3>
773
774                 <sect3>
775                 <title>OpenLDAP configuration</title>
776
777                         <para>
778                         To include support for the sambaAccount object in an OpenLDAP directory
779                         server, first copy the samba.schema file to slapd's configuration directory.
780                         The samba.schema file can be found in the directory <filename>examples/LDAP</filename>
781                         in the samba source distribution.
782                         </para>
783
784 <para>
785 <screen>
786 &rootprompt;<userinput>cp samba.schema /etc/openldap/schema/</userinput>
787 </screen>
788 </para>
789
790                         <para>
791                         Next, include the <filename>samba.schema</filename> file in <filename>slapd.conf</filename>.
792                         The sambaAccount object contains two attributes which depend upon other schema
793                         files.  The 'uid' attribute is defined in <filename>cosine.schema</filename> and
794                         the 'displayName' attribute is defined in the <filename>inetorgperson.schema</filename>
795                         file.  Both of these must be included before the <filename>samba.schema</filename> file.
796                         </para>
797
798 <para>
799 <programlisting>
800 ## /etc/openldap/slapd.conf
801
802 ## schema files (core.schema is required by default)
803 include            /etc/openldap/schema/core.schema
804
805 ## needed for sambaAccount
806 include            /etc/openldap/schema/cosine.schema
807 include            /etc/openldap/schema/inetorgperson.schema
808 include            /etc/openldap/schema/samba.schema
809 include            /etc/openldap/schema/nis.schema
810 ....
811 </programlisting>
812 </para>
813
814                 <para>
815                 It is recommended that you maintain some indices on some of the most usefull attributes,
816                 like in the following example, to speed up searches made on sambaAccount objectclasses
817                 (and possibly posixAccount and posixGroup as well).
818                 </para>
819
820 <para>
821 <screen>
822 # Indices to maintain
823 ## required by OpenLDAP
824 index objectclass             eq
825
826 index cn                      pres,sub,eq
827 index sn                      pres,sub,eq
828 ## required to support pdb_getsampwnam
829 index uid                     pres,sub,eq
830 ## required to support pdb_getsambapwrid()
831 index displayName             pres,sub,eq
832
833 ## uncomment these if you are storing posixAccount and
834 ## posixGroup entries in the directory as well
835 ##index uidNumber               eq
836 ##index gidNumber               eq
837 ##index memberUid               eq
838
839 index   sambaSID              eq
840 index   sambaPrimaryGroupSID  eq
841 index   sambaDomainName       eq
842 index   default               sub
843 </screen>
844 </para>
845
846                 <para>
847                 Create the new index by executing:
848                 </para>
849
850 <para>
851 <screen>
852 ./sbin/slapindex -f slapd.conf
853 </screen>
854 </para>
855
856                 <para>
857                 Remember to restart slapd after making these changes:
858                 </para>
859
860 <para>
861 <screen>
862 &rootprompt;<userinput>/etc/init.d/slapd restart</userinput>
863 </screen>
864 </para>
865
866                 </sect3>
867
868                 <sect3>
869                 <title>Initialise the LDAP database</title>
870
871                 <para>
872                 Before you can add accounts to the LDAP database you must create the account containers
873                 that they will be stored in. The following LDIF file should be modified to match your
874                 needs (ie: Your DNS entries, etc.).
875                 </para>
876                 
877 <para>
878 <screen>
879 # Organization for Samba Base
880 dn: dc=plainjoe,dc=org
881 objectclass: dbObject
882 objectclass: organization
883 dc: plainjoe
884 o: Terpstra Org Network
885 description: The Samba-3 Network LDAP Example
886
887 # Organizational Role for Directory Management
888 db: cn=Manager,dc=plainjoe,dc=org
889 objectclass: organizationalRole
890 cn: Manager
891 description: Directory Manager
892
893 # Setting up container for users
894 dn: ou=People,dc=plainjoe,dc=org
895 objectclass: top
896 objectclass: organizationalUnit
897 ou: People
898
899 # Setting up admin handle for People OU
900 dn: cn=admin,ou=People,dc=plainjoe,dc=org
901 cn: admin
902 objectclass: top
903 objectclass: organizationalRole
904 objectclass: simpleSecurityObject
905 userPassword: {SSHA}c3ZM9tBaBo9autm1dL3waDS21+JSfQVz
906 </screen>
907 </para>
908
909                 <para>
910                 The userPassword shown above should be generated using <command>slappasswd</command>.
911                 </para>
912
913                 <para>
914                 The following command will then load the contents of the LDIF file into the LDAP
915                 database.
916                 </para>
917
918 <para>
919 <screen>
920 slapadd -v -l initldap.dif
921 </screen>
922 </para>
923
924                 <para>
925                 Do not forget to secure your LDAP server with an adequate access control list,
926                 as well as an admin password.
927                 </para>
928
929                 <note>
930                 <para>
931                 Before Samba can access the LDAP server you need to stoe the LDAP admin password
932                 into the Samba-3 <filename>secrets.tdb</filename> database by:
933                 <screen>
934                 &rootprompt; <command>smbpasswd -w secret</command>
935                 </screen>
936                 </para>
937                 </note>
938
939                 </sect3>
940
941                 <sect3>
942                 <title>Configuring Samba</title>
943
944                         <para>
945                         The following parameters are available in smb.conf only if your
946                         version of samba was built with LDAP support. Samba automatically builds with LDAP support if the
947                         LDAP libraries are found.
948                         </para>
949
950                 <itemizedlist>
951                         <listitem><para><ulink url="smb.conf.5.html#PASSDBBACKEND">passdb backend = ldapsam:url</ulink></para></listitem>
952                         <listitem><para><ulink url="smb.conf.5.html#LDAPSSL">ldap ssl</ulink></para></listitem>
953                         <listitem><para><ulink url="smb.conf.5.html#LDAPADMINDN">ldap admin dn</ulink></para></listitem>
954                         <listitem><para><ulink url="smb.conf.5.html#LDAPSUFFIX">ldap suffix</ulink></para></listitem>
955                         <listitem><para><ulink url="smb.conf.5.html#LDAPFILTER">ldap filter</ulink></para></listitem>
956                         <listitem><para><ulink url="smb.conf.5.html#LDAPMACHINSUFFIX">ldap machine suffix</ulink></para></listitem>
957                         <listitem><para><ulink url="smb.conf.5.html#LDAPUSERSUFFIX">ldap user suffix</ulink></para></listitem>
958                         <listitem><para><ulink url="smb.conf.5.html#LDAPDELETEDN">ldap delete dn</ulink></para></listitem>
959                         <listitem><para><ulink url="smb.conf.5.html#LDAPPASSWDSYNC">ldap passwd sync</ulink></para></listitem>
960                         <listitem><para><ulink url="smb.conf.5.html#LDAPTRUSTIDS">ldap trust ids</ulink></para></listitem>
961
962                 </itemizedlist>
963
964                         <para>
965                         These are described in the &smb.conf; man
966                         page and so will not be repeated here.  However, a sample smb.conf file for
967                         use with an LDAP directory could appear as
968                         </para>
969
970 <para>
971 <screen>
972 ## /usr/local/samba/lib/smb.conf
973 [global]
974      security = user
975      encrypt passwords = yes
976
977      netbios name = TASHTEGO
978      workgroup = NARNIA
979
980      # ldap related parameters
981
982      # define the DN to use when binding to the directory servers
983      # The password for this DN is not stored in smb.conf.  Rather it
984      # must be set by using 'smbpasswd -w <replaceable>secretpw</replaceable>' to store the
985      # passphrase in the secrets.tdb file.  If the "ldap admin dn" values
986      # change, this password will need to be reset.
987      ldap admin dn = "cn=Samba Manager,ou=people,dc=samba,dc=org"
988
989      # Define the SSL option when connecting to the directory
990      # ('off', 'start tls', or 'on' (default))
991      ldap ssl = start tls
992
993      # syntax: passdb backend = ldapsam:ldap://server-name[:port]
994      passdb backend = ldapsam:ldap://funball.samba.org, guest
995
996      # smbpasswd -x delete the entire dn-entry
997      ldap delete dn = no
998
999      # the machine and user suffix added to the base suffix
1000      # wrote WITHOUT quotes. NULL siffixes by default
1001      ldap user suffix = ou=People
1002      ldap machine suffix = ou=Systems
1003
1004      # Trust unix account information in LDAP
1005      #  (see the smb.conf manpage for details)
1006      ldap trust ids = Yes
1007
1008      # specify the base DN to use when searching the directory
1009      ldap suffix = "ou=people,dc=samba,dc=org"
1010
1011      # generally the default ldap search filter is ok
1012      # ldap filter = "(&amp;(uid=%u)(objectclass=sambaAccount))"
1013 </screen>
1014 </para>
1015
1016                 </sect3>
1017
1018                 <sect3>
1019                 <title>Accounts and Groups management</title>
1020
1021                         <para>
1022                         As users accounts are managed thru the sambaAccount objectclass, you should
1023                         modify your existing administration tools to deal with sambaAccount attributes.
1024                         </para>
1025
1026                         <para>
1027                         Machines accounts are managed with the sambaAccount objectclass, just
1028                         like users accounts. However, it's up to you to store thoses accounts
1029                         in a different tree of your LDAP namespace: you should use
1030                         "ou=Groups,dc=plainjoe,dc=org" to store groups and
1031                         "ou=People,dc=plainjoe,dc=org" to store users. Just configure your
1032                         NSS and PAM accordingly (usually, in the /etc/ldap.conf configuration
1033                         file).
1034                         </para>
1035
1036                         <para>
1037                         In Samba release 3.0, the group management system is based on posix
1038                         groups. This means that Samba makes usage of the posixGroup objectclass.
1039                         For now, there is no NT-like group system management (global and local
1040                         groups).
1041                         </para>
1042
1043                 </sect3>
1044
1045                 <sect3>
1046                 <title>Security and sambaAccount</title>
1047
1048
1049                         <para>
1050                         There are two important points to remember when discussing the security
1051                         of sambaAccount entries in the directory.
1052                         </para>
1053
1054                         <itemizedlist>
1055                                 <listitem><para><emphasis>Never</emphasis> retrieve the lmPassword or
1056                                 ntPassword attribute values over an unencrypted LDAP session.</para></listitem>
1057                                 <listitem><para><emphasis>Never</emphasis> allow non-admin users to
1058                                 view the lmPassword or ntPassword attribute values.</para></listitem>
1059                         </itemizedlist>
1060
1061                         <para>
1062                         These password hashes are clear text equivalents and can be used to impersonate
1063                         the user without deriving the original clear text strings.  For more information
1064                         on the details of LM/NT password hashes, refer to the
1065                         <link linkend="passdb">Account Information Database</link> section of this chapter.
1066                         </para>
1067
1068                         <para>
1069                         To remedy the first security issue, the "ldap ssl" smb.conf parameter defaults
1070                         to require an encrypted session (<parameter>ldap ssl = on</parameter>) using
1071                         the default port of <constant>636</constant>
1072                         when contacting the directory server.  When using an OpenLDAP server, it
1073                         is possible to use the use the StartTLS LDAP extended  operation in the place of
1074                         LDAPS.  In either case, you are strongly discouraged to disable this security
1075                         (<parameter>ldap ssl = off</parameter>).
1076                         </para>
1077
1078                         <para>
1079                         Note that the LDAPS protocol is deprecated in favor of the LDAPv3 StartTLS
1080                         extended operation.  However, the OpenLDAP library still provides support for
1081                         the older method of securing communication between clients and servers.
1082                         </para>
1083
1084                         <para>
1085                         The second security precaution is to prevent non-administrative users from
1086                         harvesting password hashes from the directory.  This can be done using the
1087                         following ACL in <filename>slapd.conf</filename>:
1088                         </para>
1089
1090 <para>
1091 <screen>
1092 ## allow the "ldap admin dn" access, but deny everyone else
1093 access to attrs=lmPassword,ntPassword
1094      by dn="cn=Samba Admin,ou=people,dc=plainjoe,dc=org" write
1095      by * none
1096 </screen>
1097 </para>
1098
1099                 </sect3>
1100
1101                 <sect3>
1102                 <title>LDAP special attributes for sambaAccounts</title>
1103
1104                         <para>
1105                         The sambaAccount objectclass is composed of the following attributes:
1106                         </para>
1107
1108                         <itemizedlist>
1109                                 <listitem><para><constant>lmPassword</constant>: the LANMAN password 16-byte hash stored as a character
1110                                 representation of a hexidecimal string.</para></listitem>
1111
1112                                 <listitem><para><constant>ntPassword</constant>: the NT password hash 16-byte stored as a character
1113                                 representation of a hexidecimal string.</para></listitem>
1114
1115                                 <listitem><para><constant>pwdLastSet</constant>: The integer time in seconds since 1970 when the
1116                                 <constant>lmPassword</constant> and <constant>ntPassword</constant> attributes were last set.
1117                                 </para></listitem>
1118
1119                                 <listitem><para><constant>acctFlags</constant>: string of 11 characters surrounded by square brackets []
1120                                                 representing account flags such as U (user), W(workstation), X(no password expiration),
1121                                                 I(Domain trust account), H(Home dir required), S(Server trust account),
1122                                                 and D(disabled).</para></listitem>
1123
1124                                 <listitem><para><constant>logonTime</constant>: Integer value currently unused</para></listitem>
1125
1126                                 <listitem><para><constant>logoffTime</constant>: Integer value currently unused</para></listitem>
1127
1128                                 <listitem><para><constant>kickoffTime</constant>: Integer value currently unused</para></listitem>
1129
1130                                 <listitem><para><constant>pwdCanChange</constant>: Integer value currently unused</para></listitem>
1131
1132                                 <listitem><para><constant>pwdMustChange</constant>: Integer value currently unused</para></listitem>
1133
1134                                 <listitem><para><constant>homeDrive</constant>: specifies the drive letter to which to map the
1135                                 UNC path specified by homeDirectory. The drive letter must be specified in the form "X:"
1136                                 where X is the letter of the drive to map. Refer to the "logon drive" parameter in the
1137                                 smb.conf(5) man page for more information.</para></listitem>
1138
1139                                 <listitem><para><constant>scriptPath</constant>: The scriptPath property specifies the path of
1140                                 the user's logon script, .CMD, .EXE, or .BAT file. The string can be null. The path
1141                                 is relative to the netlogon share.  Refer to the "logon script" parameter in the
1142                                 smb.conf(5) man page for more information.</para></listitem>
1143
1144                                 <listitem><para><constant>profilePath</constant>: specifies a path to the user's profile.
1145                                 This value can be a null string, a local absolute path, or a UNC path.  Refer to the
1146                                 "logon path" parameter in the smb.conf(5) man page for more information.</para></listitem>
1147
1148                                 <listitem><para><constant>smbHome</constant>: The homeDirectory property specifies the path of
1149                                 the home directory for the user. The string can be null. If homeDrive is set and specifies
1150                                 a drive letter, homeDirectory should be a UNC path. The path must be a network
1151                                 UNC path of the form <filename>\\server\share\directory</filename>. This value can be a null string.
1152                                 Refer to the <command>logon home</command> parameter in the &smb.conf; man page for more information.
1153                                 </para></listitem>
1154
1155                                 <listitem><para><constant>userWorkstation</constant>: character string value currently unused.
1156                                 </para></listitem>
1157
1158                                 <listitem><para><constant>rid</constant>: the integer representation of the user's relative identifier
1159                                 (RID).</para></listitem>
1160
1161                                 <listitem><para><constant>primaryGroupID</constant>: the relative identifier (RID) of the primary group
1162                                 of the user.</para></listitem>
1163
1164                                 <listitem><para><constant>domain</constant>: domain the user is part of.</para></listitem>
1165                         </itemizedlist>
1166
1167                         <para>
1168                         The majority of these parameters are only used when Samba is acting as a PDC of
1169                         a domain (refer to the <link linkend="samba-pdc">Samba as a primary domain controller</link> chapter for details on
1170                         how to configure Samba as a Primary Domain Controller). The following four attributes
1171                         are only stored with the sambaAccount entry if the values are non-default values:
1172                         </para>
1173
1174                         <itemizedlist>
1175                                 <listitem><para>smbHome</para></listitem>
1176                                 <listitem><para>scriptPath</para></listitem>
1177                                 <listitem><para>logonPath</para></listitem>
1178                                 <listitem><para>homeDrive</para></listitem>
1179                         </itemizedlist>
1180
1181                         <para>
1182                         These attributes are only stored with the sambaAccount entry if
1183                         the values are non-default values.  For example, assume TASHTEGO has now been
1184                         configured as a PDC and that <command>logon home = \\%L\%u</command> was defined in
1185                         its <filename>smb.conf</filename> file. When a user named "becky" logons to the domain,
1186                         the <parameter>logon home</parameter> string is expanded to \\TASHTEGO\becky.
1187                         If the smbHome attribute exists in the entry "uid=becky,ou=people,dc=samba,dc=org",
1188                         this value is used.  However, if this attribute does not exist, then the value
1189                         of the <parameter>logon home</parameter> parameter is used in its place.  Samba
1190                         will only write the attribute value to the directory entry if the value is
1191                         something other than the default (e.g. <filename>\\MOBY\becky</filename>).
1192                         </para>
1193
1194                 </sect3>
1195
1196                 <sect3>
1197                 <title>Example LDIF Entries for a sambaAccount</title>
1198
1199                         <para>
1200                         The following is a working LDIF with the inclusion of the posixAccount objectclass:
1201                         </para>
1202
1203         <para>
1204         <screen>
1205         dn: uid=guest2, ou=people,dc=plainjoe,dc=org
1206         ntPassword: 878D8014606CDA29677A44EFA1353FC7
1207         pwdMustChange: 2147483647
1208         primaryGroupID: 1201
1209         lmPassword: 552902031BEDE9EFAAD3B435B51404EE
1210         pwdLastSet: 1010179124
1211         logonTime: 0
1212         objectClass: sambaAccount
1213         uid: guest2
1214         kickoffTime: 2147483647
1215         acctFlags: [UX         ]
1216         logoffTime: 2147483647
1217         rid: 19006
1218         pwdCanChange: 0
1219         </screen>
1220         </para>
1221
1222                         <para>
1223                         The following is an LDIF entry for using both the sambaAccount and
1224                         posixAccount objectclasses:
1225                         </para>
1226
1227         <para>
1228         <screen>
1229         dn: uid=gcarter, ou=people,dc=plainjoe,dc=org
1230         logonTime: 0
1231         displayName: Gerald Carter
1232         lmPassword: 552902031BEDE9EFAAD3B435B51404EE
1233         primaryGroupID: 1201
1234         objectClass: posixAccount
1235         objectClass: sambaAccount
1236         acctFlags: [UX         ]
1237         userPassword: {crypt}BpM2ej8Rkzogo
1238         uid: gcarter
1239         uidNumber: 9000
1240         cn: Gerald Carter
1241         loginShell: /bin/bash
1242         logoffTime: 2147483647
1243         gidNumber: 100
1244         kickoffTime: 2147483647
1245         pwdLastSet: 1010179230
1246         rid: 19000
1247         homeDirectory: /home/tashtego/gcarter
1248         pwdCanChange: 0
1249         pwdMustChange: 2147483647
1250         ntPassword: 878D8014606CDA29677A44EFA1353FC7
1251         </screen>
1252         </para>
1253
1254                 </sect3>
1255
1256                 <sect3>
1257                 <title>Password synchronisation</title>
1258
1259                 <para>
1260                 Since version 3.0 samba can update the non-samba (LDAP) password stored with an account. When
1261                 using pam_ldap, this allows changing both unix and windows passwords at once.
1262                 </para>
1263
1264                 <para>The <command>ldap passwd sync</command> options can have the following values:</para>
1265
1266                 <variablelist>
1267                        <varlistentry>
1268                                <term>yes</term>
1269                                <listitem><para>When the user changes his password, update
1270                                                <constant>ntPassword</constant>, <constant>lmPassword</constant>
1271                                                and the <constant>password</constant> fields.</para></listitem>
1272                        </varlistentry>
1273
1274                        <varlistentry>
1275                                <term>no</term>
1276                                <listitem><para>Only update <constant>ntPassword</constant> and <constant>lmPassword</constant>.</para></listitem>
1277                        </varlistentry>
1278
1279                        <varlistentry>
1280                                <term>only</term>
1281                                <listitem><para>Only update the LDAP password and let the LDAP server worry
1282                                                about the other fields. This option is only available when
1283                                                the LDAP library supports LDAP_EXOP_X_MODIFY_PASSWD. </para></listitem>
1284                        </varlistentry>
1285                 </variablelist>
1286
1287                 <para>More information can be found in the <ulink url="smb.conf.5.html#LDAPPASSWDSYNC">smb.conf</ulink> manpage.
1288                 </para>
1289
1290                 </sect3>
1291
1292                 <sect3>
1293                 <title>ldap trust ids</title>
1294
1295                 <para>
1296                 LDAP Performance can be improved by using the <command>ldap trust ids</command> parameter.
1297                 See the <ulink url="smb.conf.5.html#LDAPTRUSTIDS">smb.conf</ulink> manpage for details.
1298                 </para>
1299
1300                 </sect3>
1301
1302         </sect2>
1303
1304         <sect2>
1305         <title>MySQL</title>
1306
1307         <para>
1308         Every so often someone will come along with a great new idea. Storing of user accounts in an
1309         SQL backend is one of them. Those who want to do this are in the best position to know what the
1310         specific benefits are to them. This may sound like a cop-out, but in truth we can not attempt
1311         to document every nitty little detail why certain things of marginal utility to the bulk of
1312         Samba users might make sense to the rest. In any case, the following instructions should help
1313         the determined SQL user to implement a working system.
1314         </para>
1315
1316                 <sect3>
1317                 <title>Creating the database</title>
1318
1319                         <para>
1320                         You either can set up your own table and specify the field names to pdb_mysql (see below
1321                         for the column names) or use the default table. The file <filename>examples/pdb/mysql/mysql.dump</filename> 
1322                         contains the correct queries to create the required tables. Use the command :
1323
1324                         <screen>
1325                         <command>mysql -u<replaceable>username</replaceable> -h<replaceable>hostname</replaceable> -p<replaceable>password</replaceable> <replaceable>databasename</replaceable> &gt; <filename>/path/to/samba/examples/pdb/mysql/mysql.dump</filename></command>
1326                         </screen>
1327                         </para>
1328                 </sect3>
1329
1330                 <sect3>
1331                 <title>Configuring</title>
1332
1333                         <para>This plugin lacks some good documentation, but here is some short info:</para>
1334
1335                         <para>Add a the following to the <command>passdb backend</command> variable in your <filename>smb.conf</filename>:
1336                         <screen>
1337                         passdb backend = [other-plugins] mysql:identifier [other-plugins]
1338                         </screen>
1339                         </para>
1340
1341                         <para>The identifier can be any string you like, as long as it doesn't collide with 
1342                         the identifiers of other plugins or other instances of pdb_mysql. If you 
1343                         specify multiple pdb_mysql.so entries in <parameter>passdb backend</parameter>, you also need to 
1344                         use different identifiers!
1345                         </para>
1346
1347                         <para>
1348                                 Additional options can be given thru the &smb.conf; file in the <command>[global]</command> section.
1349                         </para>
1350
1351                 <para>
1352                 <screen>
1353                 identifier:mysql host                     - host name, defaults to 'localhost'
1354                 identifier:mysql password
1355                 identifier:mysql user                     - defaults to 'samba'
1356                 identifier:mysql database                 - defaults to 'samba'
1357                 identifier:mysql port                     - defaults to 3306
1358                 identifier:table                          - Name of the table containing users
1359                 </screen>
1360                 </para>
1361
1362                         <warning>
1363                         <para>
1364                         Since the password for the mysql user is stored in the 
1365                         &smb.conf; file, you should make the the &smb.conf; file 
1366                         readable only to the user that runs samba. This is considered a security 
1367                         bug and will be fixed soon.
1368                         </para>
1369                         </warning>
1370
1371                         <para>Names of the columns in this table(I've added column types those columns should have first):</para>
1372
1373                 <para>
1374                 <screen>
1375                 identifier:logon time column             - int(9)
1376                 identifier:logoff time column            - int(9)
1377                 identifier:kickoff time column           - int(9)
1378                 identifier:pass last set time column     - int(9)
1379                 identifier:pass can change time column   - int(9)
1380                 identifier:pass must change time column  - int(9)
1381                 identifier:username column               - varchar(255) - unix username
1382                 identifier:domain column                 - varchar(255) - NT domain user is part of
1383                 identifier:nt username column            - varchar(255) - NT username
1384                 identifier:fullname column               - varchar(255) - Full name of user
1385                 identifier:home dir column               - varchar(255) - Unix homedir path
1386                 identifier:dir drive column              - varchar(2)   - Directory drive path (eg: 'H:')
1387                 identifier:logon script column           - varchar(255)
1388                                                          - Batch file to run on client side when logging on
1389                 identifier:profile path column           - varchar(255) - Path of profile
1390                 identifier:acct desc column              - varchar(255) - Some ASCII NT user data
1391                 identifier:workstations column           - varchar(255)
1392                                                          - Workstations user can logon to (or NULL for all)
1393                 identifier:unknown string column         - varchar(255) - unknown string
1394                 identifier:munged dial column            - varchar(255) - ?
1395                 identifier:user sid column               - varchar(255) - NT user SID
1396                 identifier:group sid column              - varchar(255) - NT group ID
1397                 identifier:lanman pass column            - varchar(255) - encrypted lanman password
1398                 identifier:nt pass column                - varchar(255) - encrypted nt passwd
1399                 identifier:plain pass column             - varchar(255) - plaintext password
1400                 identifier:acct control column           - int(9) - nt user data
1401                 identifier:unknown 3 column              - int(9) - unknown
1402                 identifier:logon divs column             - int(9) - ?
1403                 identifier:hours len column              - int(9) - ?
1404                 identifier:unknown 5 column              - int(9) - unknown
1405                 identifier:unknown 6 column              - int(9) - unknown
1406                 </screen>
1407                 </para>
1408
1409                         <para>
1410                         Eventually, you can put a colon (:) after the name of each column, which 
1411                         should specify the column to update when updating the table. You can also
1412                         specify nothing behind the colon - then the data from the field will not be 
1413                         updated. 
1414                         </para>
1415
1416                 </sect3>
1417
1418                 <sect3>
1419                 <title>Using plaintext passwords or encrypted password</title>
1420
1421                         <para>
1422                         I strongly discourage the use of plaintext passwords, however, you can use them:
1423                         </para>
1424
1425                         <para>
1426                         If you would like to use plaintext passwords, set
1427                         'identifier:lanman pass column' and 'identifier:nt pass column' to
1428                         'NULL' (without the quotes) and 'identifier:plain pass column' to the
1429                         name of the column containing the plaintext passwords. 
1430                         </para>
1431
1432                         <para>
1433                         If you use encrypted passwords, set the 'identifier:plain pass
1434                         column' to 'NULL' (without the quotes). This is the default.
1435                         </para>
1436
1437                 </sect3>
1438
1439                 <sect3>
1440                 <title>Getting non-column data from the table</title>
1441
1442                         <para>
1443                         It is possible to have not all data in the database and making some 'constant'.
1444                         </para>
1445
1446                         <para>
1447                         For example, you can set 'identifier:fullname column' to : 
1448                         <command>CONCAT(First_name,' ',Sur_name)</command>
1449                         </para>
1450
1451                         <para>
1452                         Or, set 'identifier:workstations column' to :
1453                         <command>NULL</command></para>
1454
1455                         <para>See the MySQL documentation for more language constructs.</para>
1456
1457                 </sect3>
1458         </sect2>
1459
1460         <sect2 id="XMLpassdb">
1461         <title>XML</title>
1462
1463                 <para>This module requires libxml2 to be installed.</para>
1464
1465                 <para>The usage of pdb_xml is pretty straightforward. To export data, use:
1466                 </para>
1467
1468                 <para>
1469                         <userinput>pdbedit -e xml:filename</userinput>
1470                 </para>
1471
1472                 <para>
1473                 (where filename is the name of the file to put the data in)
1474                 </para>
1475
1476                 <para>
1477                 To import data, use:
1478                 <userinput>pdbedit -i xml:filename -e current-pdb</userinput>
1479                 </para>
1480
1481                 <para>
1482                 Where filename is the name to read the data from and current-pdb to put it in.
1483                 </para>
1484
1485                 <para>
1486                 For example: To migrate (copy) the smbpasswd database into a tdbsam database:
1487                 </para>
1488
1489                 <para>
1490                 then execute (as root):
1491                 <screen>
1492                 &rootprompt;<userinput>pdbedit -i smbpasswd -e tdbsam</userinput>
1493                 </screen>
1494                 </para>
1495         </sect2>
1496 </sect1>
1497
1498 <sect1>
1499 <title>Common Errors</title>
1500
1501         <sect2>
1502         <title>Users can not logon - Users not in Samba SAM</title>
1503
1504         <para>
1505         People forget to put their users in their backend and then complain samba won't authorize them.
1506         </para>
1507
1508         </sect2>
1509
1510         <sect2>
1511         <title>Users are being added to the wrong backend database</title>
1512
1513         <para>
1514         A few complaints have been recieved from users that just moved to samba-3. The following
1515         &smb.conf; file entries were causing problems, new accounts were being added to the old
1516         smbpasswd file, not to the tdbsam passdb.tdb file:
1517         </para>
1518
1519         <para>
1520         <screen>
1521         [globals]
1522                 ...
1523                 passdb backend = smbpasswd, tdbsam, guest
1524                 ...
1525         </screen>
1526         </para>
1527
1528         <para>
1529         Samba will add new accounts to the first entry in the <emphasis>passdb backend</emphasis>
1530         parameter entry. If you want to update to the tdbsam, then change the entry to:
1531         </para>
1532
1533         <para>
1534         <screen>
1535         [globals]
1536                 ...
1537                 passdb backend = tdbsam, smbpasswd, guest
1538                 ...
1539         </screen>
1540         </para>
1541
1542         </sect2>
1543 </sect1>
1544 </chapter>