Text docs converted to sgml

Jelmer Vernooij <[email protected]> Fri, 28 Jun 2002 13:40:27 +0200
Newsgroups gmane.network.samba.documentation
Message-ID <[email protected]>
Hi Gerald,

I've attached some documents I converted to sgml. There current status 
of the documents in docs/textdocs is:

ADS-HOWTO.txt - current
Application_Serving.txt - current
BROWSING-Config.txt - current
BROWSING.txt - Converted to sgml
BUGS.txt - Converted to sgml
cifsntdomain.txt - current
DHCP-Server-Configuration.txt
DIAGNOSIS.txt - converted to sgml
DNIX.txt - current
Faxing.txt - current
GOTCHAS.txt - current
GROUP-MAPPING-HOWTO.txt - current
HINTS.txt - current
Imprints.txt - better docs are in the howto collection
INSTALL.sambatar - current
Macintosh_Clients.txt - already in the faq
NetBIOS.txt - current
outdated
Passwords.txt - current
Printing.txt - converted to sgml
PROFILES.txt - current
README.DCEDFS - current
README.jis - current
README.NOW - current
README.sambatar - current
Recent-FAQs.txt - current
RoutedNetworks.txt - current
SCO.txt - current
security_level.txt - converted to sgml
SMBTAR.notes - current
Solaris-Winbind-HOWTO.txt - integrated in winbind.sgml
Speed2.txt - converted to sgml (speed.sgml)
Speed.txt - converted to sgml (speed.sgml)
Tracing.txt - current
UNIX_SECURITY.txt - current
UNIX-SMB.txt - converted to sgml
Win95.txt - current
WinNT.txt - current

Would it be useful to add a 'samba coding guide' ? There's already
quite some info available: source/*.doc, source/CodingSuggestions and
docs/textdocs/ also contains some documents that are only useful for
developers(such as unix-smb.txt, the technical explanation of security 
levels, etc). CodingSuggestions might be a problem - the current
(text) version is used by doxygen.

Jelmer

-- 
Jelmer Vernooij <[email protected]> - http://nl.linux.org/~jelmer/
Development And Underdevelopment: http://library.thinkquest.org/C0110231/
Listening to Radio 3FM
 13:27:35 up 5 days, 23:23, 12 users,  load average: 0.21, 0.28, 0.26
Browsing.sgml (text/plain, 26.6 KB)
<chapter id="improved-browsing">
<chapterinfo>
	<author>
		<affiliation>
			<orgname>Samba Team</orgname>
		</affiliation>
	</author>


	<pubdate> (5 July 1998) </pubdate>
</chapterinfo>

<title>Improved browsing in samba</title>

<sect1>
<title>Overview of browsing</title>

<para>
SMB networking provides a mechanism by which clients can access a list
of machines in a network, a so-called "browse list".  This list
contains machines that are ready to offer file and/or print services
to other machines within the network. Thus it does not include
machines which aren't currently able to do server tasks.  The browse
list is heavily used by all SMB clients.  Configuration of SMB
browsing has been problematic for some Samba users, hence this
document.
</para>

<para>
Browsing will NOT work if name resolution from NetBIOS names to IP
addresses does not function correctly. Use of a WINS server is highly
recommended to aid the resolution of NetBIOS (SMB) names to IP addresses.
WINS allows remote segment clients to obtain NetBIOS name_type information
that can NOT be provided by any other means of name resolution.
</para>

</sect1>

<sect1>
<title>Browsing support in samba</title>

<para>
Samba now fully supports browsing.  The browsing is supported by nmbd
and is also controlled by options in the smb.conf file (see smb.conf(5)).
</para>

<para>
Samba can act as a local browse master for a workgroup and the ability
for samba to support domain logons and scripts is now available.  See
DOMAIN.txt for more information on domain logons.
</para>

<para>
Samba can also act as a domain master browser for a workgroup.  This
means that it will collate lists from local browse masters into a
wide area network server list.  In order for browse clients to
resolve the names they may find in this list, it is recommended that
both samba and your clients use a WINS server.
</para>

<para>
Note that you should NOT set Samba to be the domain master for a
workgroup that has the same name as an NT Domain: on each wide area
network, you must only ever have one domain master browser per workgroup,
regardless of whether it is NT, Samba or any other type of domain master
that is providing this service.
</para>

<para>
[Note that nmbd can be configured as a WINS server, but it is not
necessary to specifically use samba as your WINS server.  NTAS can
be configured as your WINS server.  In a mixed NT server and
samba environment on a Wide Area Network, it is recommended that
you use the NT server's WINS server capabilities.  In a samba-only
environment, it is recommended that you use one and only one nmbd
as your WINS server].
</para>

<para>
To get browsing to work you need to run nmbd as usual, but will need
to use the "workgroup" option in smb.conf to control what workgroup
Samba becomes a part of.
</para>

<para>
Samba also has a useful option for a Samba server to offer itself for
browsing on another subnet.  It is recommended that this option is only
used for 'unusual' purposes: announcements over the internet, for
example.  See "remote announce" in the smb.conf man page.  
</para>
</sect1>

<sect1>
<title>Problem resolution</title>

<para>
If something doesn't work then hopefully the log.nmb file will help
you track down the problem.  Try a debug level of 2 or 3 for finding
problems. Also note that the current browse list usually gets stored
in text form in a file called browse.dat.
</para>

<para>
Note that if it doesn't work for you, then you should still be able to
type the server name as \\SERVER in filemanager then hit enter and
filemanager should display the list of available shares.
</para>

<para>
Some people find browsing fails because they don't have the global
"guest account" set to a valid account.  Remember that the IPC$
connection that lists the shares is done as guest, and thus you must
have a valid guest account.
</para>

<para>
Also, a lot of people are getting bitten by the problem of too many
parameters on the command line of nmbd in inetd.conf.  This trick is to
not use spaces between the option and the parameter (eg: -d2 instead
of -d 2), and to not use the -B and -N options.  New versions of nmbd
are now far more likely to correctly find your broadcast and network
address, so in most cases these aren't needed.
</para>

<para>
The other big problem people have is that their broadcast address,
netmask or IP address is wrong (specified with the "interfaces" option
in smb.conf)
</para>
</sect1>

<sect1>
<title>Browsing across subnets</title>
<para>
With the release of Samba 1.9.17(alpha1 and above) Samba has been
updated to enable it to support the replication of browse lists
across subnet boundaries.  New code and options have been added to
achieve this.  This section describes how to set this feature up
in different settings.
</para>

<para>
To see browse lists that span TCP/IP subnets (ie.  networks separated
by routers that don't pass broadcast traffic) you must set up at least
one WINS server.  The WINS server acts as a DNS for NetBIOS names, allowing
NetBIOS name to IP address translation to be done by doing a direct
query of the WINS server.  This is done via a directed UDP packet on
port 137 to the WINS server machine.  The reason for a WINS server is
that by default, all NetBIOS name to IP address translation is done
by broadcasts from the querying machine.  This means that machines
on one subnet will not be able to resolve the names of machines on
another subnet without using a WINS server.
</para>

<para>
Remember, for browsing across subnets to work correctly, all machines,
be they Windows 95, Windows NT, or Samba servers must have the IP address
of a WINS server given to them by a DHCP server, or by manual configuration 
(for Win95 and WinNT, this is in the TCP/IP Properties, under Network 
settings) for Samba this is in the smb.conf file.
</para>

<sect2>
<title>How does cross subnet browsing work ?</title>

<para>
Cross subnet browsing is a complicated dance, containing multiple
moving parts.  It has taken Microsoft several years to get the code
that achieves this correct, and Samba lags behind in some areas.
However, with the 1.9.17 release, Samba is capable of cross subnet
browsing when configured correctly.
</para>

<para>
Consider a network set up as follows :
FIXME
                                   (DMB)
             N1_A      N1_B        N1_C       N1_D        N1_E
              |          |           |          |           |
          -------------------------------------------------------
            |          subnet 1                       |
          +---+                                      +---+
          |R1 | Router 1                  Router 2   |R2 |
          +---+                                      +---+
            |                                          |
            |  subnet 2              subnet 3          |
  --------------------------       ------------------------------------
  |     |     |      |               |        |         |           |
 N2_A  N2_B  N2_C   N2_D           N3_A     N3_B      N3_C        N3_D 
                    (WINS)
</para>
	
<para>
Consisting of 3 subnets (1, 2, 3) connected by two routers
(R1, R2) - these do not pass broadcasts.  Subnet 1 has 5 machines
on it, subnet 2 has 4 machines, subnet 3 has 4 machines.  Assume
for the moment that all these machines are configured to be in the
same workgroup (for simplicities sake).  Machine N1_C on subnet 1
is configured as Domain Master Browser (ie.  it will collate the
browse lists for the workgroup).  Machine N2_D is configured as
WINS server and all the other machines are configured to register
their NetBIOS names with it.
</para>

<para>
As all these machines are booted up, elections for master browsers
will take place on each of the three subnets.  Assume that machine
N1_C wins on subnet 1, N2_B wins on subnet 2, and N3_D wins on
subnet 3 - these machines are known as local master browsers for
their particular subnet.  N1_C has an advantage in winning as the
local master browser on subnet 1 as it is set up as Domain Master
Browser.
</para>

<para>
On each of the three networks, machines that are configured to 
offer sharing services will broadcast that they are offering
these services.  The local master browser on each subnet will
receive these broadcasts and keep a record of the fact that
the machine is offering a service.  This list of records is
the basis of the browse list.  For this case, assume that
all the machines are configured to offer services so all machines
will be on the browse list.
</para>

<para>
For each network, the local master browser on that network is
considered 'authoritative' for all the names it receives via
local broadcast.  This is because a machine seen by the local
master browser via a local broadcast must be on the same 
network as the local master browser and thus is a 'trusted'
and 'verifiable' resource.  Machines on other networks that
the local master browsers learn about when collating their
browse lists have not been directly seen - these records are
called 'non-authoritative'.
</para>

<para>
At this point the browse lists look as follows (these are 
the machines you would see in your network neighborhood if
you looked in it on a particular network right now).
</para>

<para>
FIXME
Subnet           Browse Master   List
------           -------------   ----
Subnet1          N1_C            N1_A, N1_B, N1_C, N1_D, N1_E

Subnet2          N2_B            N2_A, N2_B, N2_C, N2_D

Subnet3          N3_D            N3_A, N3_B, N3_C, N3_D
</para>

<para>
Note that at this point all the subnets are separate, no
machine is seen across any of the subnets.
</para>

<para>
Now examine subnet 2.  As soon as N2_B has become the local
master browser it looks for a Domain master browser to synchronize
its browse list with.  It does this by querying the WINS server
(N2_D) for the IP address associated with the NetBIOS name 
WORKGROUP&gt;1B&lt;.  This name was registerd by the Domain master
browser (N1_C) with the WINS server as soon as it was booted.
</para>

<para>
Once N2_B knows the address of the Domain master browser it
tells it that is the local master browser for subnet 2 by
sending a MasterAnnouncement packet as a UDP port 138 packet.
It then synchronizes with it by doing a NetServerEnum2 call.  This
tells the Domain Master Browser to send it all the server
names it knows about.  Once the domain master browser receives
the MasterAnnouncement packet it schedules a synchronization
request to the sender of that packet.  After both synchronizations
are done the browse lists look like :
</para>

<para>FIXME
Subnet           Browse Master   List
------           -------------   ----
Subnet1          N1_C            N1_A, N1_B, N1_C, N1_D, N1_E, 
                                 N2_A(*), N2_B(*), N2_C(*), N2_D(*)

Subnet2          N2_B            N2_A, N2_B, N2_C, N2_D
                                 N1_A(*), N1_B(*), N1_C(*), N1_D(*), N1_E(*)

Subnet3          N3_D            N3_A, N3_B, N3_C, N3_D

Servers with a (*) after them are non-authoritative names.
</para>

<para>
At this point users looking in their network neighborhood on
subnets 1 or 2 will see all the servers on both, users on
subnet 3 will still only see the servers on their own subnet.
</para>

<para>
The same sequence of events that occured for N2_B now occurs
for the local master browser on subnet 3 (N3_D).  When it
synchronizes browse lists with the domain master browser (N1_A)
it gets both the server entries on subnet 1, and those on
subnet 2.  After N3_D has synchronized with N1_C and vica-versa
the browse lists look like.
</para>

<para>FIXME
Subnet           Browse Master   List
------           -------------   ----
Subnet1          N1_C            N1_A, N1_B, N1_C, N1_D, N1_E, 
                                 N2_A(*), N2_B(*), N2_C(*), N2_D(*),
                                 N3_A(*), N3_B(*), N3_C(*), N3_D(*)

Subnet2          N2_B            N2_A, N2_B, N2_C, N2_D
                                 N1_A(*), N1_B(*), N1_C(*), N1_D(*), N1_E(*)

Subnet3          N3_D            N3_A, N3_B, N3_C, N3_D
                                 N1_A(*), N1_B(*), N1_C(*), N1_D(*), N1_E(*),
                                 N2_A(*), N2_B(*), N2_C(*), N2_D(*)

Servers with a (*) after them are non-authoritative names.
</para>

<para>
At this point users looking in their network neighborhood on
subnets 1 or 3 will see all the servers on all sunbets, users on
subnet 2 will still only see the servers on subnets 1 and 2, but not 3.
</para>

<para>
Finally, the local master browser for subnet 2 (N2_B) will sync again
with the domain master browser (N1_C) and will recieve the missing
server entries.  Finally - and as a steady state (if no machines
are removed or shut off) the browse lists will look like :
</para>

<para>FIXME
Subnet           Browse Master   List
------           -------------   ----
Subnet1          N1_C            N1_A, N1_B, N1_C, N1_D, N1_E, 
                                 N2_A(*), N2_B(*), N2_C(*), N2_D(*),
                                 N3_A(*), N3_B(*), N3_C(*), N3_D(*)

Subnet2          N2_B            N2_A, N2_B, N2_C, N2_D
                                 N1_A(*), N1_B(*), N1_C(*), N1_D(*), N1_E(*)
                                 N3_A(*), N3_B(*), N3_C(*), N3_D(*)

Subnet3          N3_D            N3_A, N3_B, N3_C, N3_D
                                 N1_A(*), N1_B(*), N1_C(*), N1_D(*), N1_E(*),
                                 N2_A(*), N2_B(*), N2_C(*), N2_D(*)
	
Servers with a (*) after them are non-authoritative names.
</para>

<para>
Synchronizations between the domain master browser and local
master browsers will continue to occur, but this should be a
steady state situation.
</para>

<para>
If either router R1 or R2 fails the following will occur:

<orderedlist>
<listitem>
	<para>
	Names of computers on each side of the inaccessible network fragments
	will be maintained for as long as 36 minutes, in the network neighbourhood
	lists.
	</para>
</listitem>

<listitem>
	<para>
	Attempts to connect to these inaccessible computers will fail, but the
	names will not be removed from the network neighbourhood lists.
	</para>
</listitem>

<listitem>
	<para>
	If one of the fragments is cut off from the WINS server, it will only
	be able to access servers on its local subnet, by using subnet-isolated
	broadcast NetBIOS name resolution.  The effects are similar to that of
	losing access to a DNS server.
	</para>
</listitem>
</orderedlist>
</sect2>
</sect1>

<sect1>
<title>Setting up a WINS server</title>

<para>
Either a Samba machine or a Windows NT Server machine may be set up
as a WINS server.  To set a Samba machine to be a WINS server you must
add the following option to the smb.conf file on the selected machine :
in the [globals] section add the line 
</para>

<para>
<command>		wins support = yes</command>
</para>

<para>
Versions of Samba previous to 1.9.17 had this parameter default to
yes.  If you have any older versions of Samba on your network it is
strongly suggested you upgrade to 1.9.17 or above, or at the very
least set the parameter to 'no' on all these machines.
</para>

<para>
Machines with "<command>wins support = yes</command>" will keep a list of 
all NetBIOS names registered with them, acting as a DNS for NetBIOS names.
</para>

<para>
You should set up only ONE wins server.  Do NOT set the
"<command>wins support = yes</command>" option on more than one Samba 
server.
</para>

<para>
To set up a Windows NT Server as a WINS server you need to set up
the WINS service - see your NT documentation for details.  Note that
Windows NT WINS Servers can replicate to each other, allowing more
than one to be set up in a complex subnet environment.  As Microsoft
refuse to document these replication protocols Samba cannot currently
participate in these replications.  It is possible in the future that
a Samba->Samba WINS replication protocol may be defined, in which
case more than one Samba machine could be set up as a WINS server
but currently only one Samba server should have the "wins support = yes"
parameter set.
</para>

<para>
After the WINS server has been configured you must ensure that all
machines participating on the network are configured with the address
of this WINS server.  If your WINS server is a Samba machine, fill in
the Samba machine IP address in the "Primary WINS Server" field of
the "Control Panel->Network->Protocols->TCP->WINS Server" dialogs
in Windows 95 or Windows NT.  To tell a Samba server the IP address
of the WINS server add the following line to the [global] section of
all smb.conf files :
</para>

<para>
<command>		wins server = &gt;name or IP address&lt;</command>
</para>

<para>
where &gt;name or IP address&lt; is either the DNS name of the WINS server
machine or its IP address.
</para>

<para>
Note that this line MUST NOT BE SET in the smb.conf file of the Samba
server acting as the WINS server itself.  If you set both the
"<command>wins support = yes</command>" option and the 
"<command>wins server = &gt;name&lt;</command>" option then
nmbd will fail to start.
<para>

<para>
There are two possible scenarios for setting up cross subnet browsing.
The first details setting up cross subnet browsing on a network containing
Windows 95, Samba and Windows NT machines that are not configured as
part of a Windows NT Domain.  The second details setting up cross subnet
browsing on networks that contain NT Domains.
</para>

</sect1>

<sect1>
<title>Setting up Browsing in a WORKGROUP</title>

<para>
To set up cross subnet browsing on a network containing machines
in up to be in a WORKGROUP, not an NT Domain you need to set up one
Samba server to be the Domain Master Browser (note that this is *NOT*
the same as a Primary Domain Controller, although in an NT Domain the
same machine plays both roles).  The role of a Domain master browser is
to collate the browse lists from local master browsers on all the
subnets that have a machine participating in the workgroup.  Without
one machine configured as a domain master browser each subnet would
be an isolated workgroup, unable to see any machines on any other
subnet.  It is the presense of a domain master browser that makes
cross subnet browsing possible for a workgroup.
</para>

<para>
In an WORKGROUP environment the domain master browser must be a
Samba server, and there must only be one domain master browser per
workgroup name.  To set up a Samba server as a domain master browser,
set the following option in the [global] section of the smb.conf file :
</para>

<para>
<command>		domain master = yes</command>
</para>

<para>
The domain master browser should also preferrably be the local master
browser for its own subnet.  In order to achieve this set the following
options in the [global] section of the smb.conf file :
</para>

<para>
<programlisting>
        domain master = yes
        local master = yes
        preferred master = yes
        os level = 65
</programlisting>
</para>

<para>
The domain master browser may be the same machine as the WINS
server, if you require.
</para>

<para>
Next, you should ensure that each of the subnets contains a
machine that can act as a local master browser for the
workgroup.  Any NT machine should be able to do this, as will
Windows 95 machines (although these tend to get rebooted more
often, so it's not such a good idea to use these).  To make a 
Samba server a local master browser set the following
options in the [global] section of the smb.conf file :
</para>

<para>
<programlisting>
        domain master = no
        local master = yes
        preferred master = yes
        os level = 65
</programlisting>
</para>

<para>
Do not do this for more than one Samba server on each subnet,
or they will war with each other over which is to be the local
master browser.
</para>

<para>
The "local master" parameter allows Samba to act as a local master
browser.  The "preferred master" causes nmbd to force a browser
election on startup and the "os level" parameter sets Samba high
enough so that it should win any browser elections.
</para>

<para>
If you have an NT machine on the subnet that you wish to
be the local master browser then you can disable Samba from
becoming a local master browser by setting the following
options in the [global] section of the smb.conf file :
</para>

<para>
<programlisting>
        domain master = no
        local master = no
        preferred master = no
        os level = 0
</programlisting>

</sect1>

<sect1>
<title>Setting up Browsing in a DOMAIN</title>

<para>
If you are adding Samba servers to a Windows NT Domain then
you must not set up a Samba server as a domain master browser.
By default, a Windows NT Primary Domain Controller for a Domain
name is also the Domain master browser for that name, and many
things will break if a Samba server registers the Domain master
browser NetBIOS name (DOMAIN&gt;1B&lt;) with WINS instead of the PDC.
</para>

<para>
For subnets other than the one containing the Windows NT PDC
you may set up Samba servers as local master browsers as
described.  To make a Samba server a local master browser set 
the following options in the [global] section of the smb.conf 
file :
</para>

<para>
<programlisting>
        domain master = no
        local master = yes
        preferred master = yes
        os level = 65
</programlisting>
</para>

<para>
If you wish to have a Samba server fight the election with machines
on the same subnet you may set the "os level" parameter to lower
levels.  By doing this you can tune the order of machines that
will become local master browsers if they are running.  For
more details on this see the section "FORCING SAMBA TO BE THE MASTER"
below.
</para>

<para>
If you have Windows NT machines that are members of the domain
on all subnets, and you are sure they will always be running then
you can disable Samba from taking part in browser elections and
ever becoming a local master browser by setting following options 
in the [global] section of the smb.conf file :
</para>

<para>
<command>
        domain master = no
        local master = no
        preferred master = no
        os level = 0
</command>
</para>

</sect1>

<sect1>
<title>Forcing samba to be the master</title>

<para>
Who becomes the "master browser" is determined by an election process
using broadcasts.  Each election packet contains a number of parameters
which determine what precedence (bias) a host should have in the
election.  By default Samba uses a very low precedence and thus loses
elections to just about anyone else.
</para>

<para>
If you want Samba to win elections then just set the "os level" global
option in smb.conf to a higher number.  It defaults to 0.  Using 34
would make it win all elections over every other system (except other
samba systems!)
</para>

<para>
A "os level" of 2 would make it beat WfWg and Win95, but not NTAS.  A
NTAS domain controller uses level 32.
</para>

<para>The maximum os level is 255</para>

<para>
If you want samba to force an election on startup, then set the
"preferred master" global option in smb.conf to "yes".  Samba will
then have a slight advantage over other potential master browsers
that are not preferred master browsers.  Use this parameter with
care, as if you have two hosts (whether they are windows 95 or NT or
samba) on the same local subnet both set with "preferred master" to
"yes", then periodically and continually they will force an election
in order to become the local master browser.
</para>

<para>
If you want samba to be a "domain master browser", then it is
recommended that you also set "preferred master" to "yes", because
samba will not become a domain master browser for the whole of your
LAN or WAN if it is not also a local master browser on its own
broadcast isolated subnet.
</para>

<para>
It is possible to configure two samba servers to attempt to become
the domain master browser for a domain.  The first server that comes
up will be the domain master browser.  All other samba servers will
attempt to become the domain master browser every 5 minutes.  They
will find that another samba server is already the domain master
browser and will fail.  This provides automatic redundancy, should
the current domain master browser fail.
</para>

</sect1>

<sect1>
<title>Making samba the domain master</title>

<para>
The domain master is responsible for collating the browse lists of
multiple subnets so that browsing can occur between subnets.  You can
make samba act as the domain master by setting "domain master = yes"
in smb.conf.  By default it will not be a domain master.
</para>

<para>
Note that you should NOT set Samba to be the domain master for a
workgroup that has the same name as an NT Domain.
</para>

<para>
When samba is the domain master and the master browser it will listen
for master announcements (made roughly every twelve minutes) from local
master browsers on other subnets and then contact them to synchronise
browse lists.
</para>

<para>
If you want samba to be the domain master then I suggest you also set
the "os level" high enough to make sure it wins elections, and set
"preferred master" to "yes", to get samba to force an election on
startup.
</para>

<para>
Note that all your servers (including samba) and clients should be
using a WINS server to resolve NetBIOS names.  If your clients are only
using broadcasting to resolve NetBIOS names, then two things will occur:
</para>

<orderedlist>
<listitem>
	<para>
	your local master browsers will be unable to find a domain master
	browser, as it will only be looking on the local subnet.
	</para>
</listitem>

<listitem>
	<para>
	if a client happens to get hold of a domain-wide browse list, and
	a user attempts to access a host in that list, it will be unable to
	resolve the NetBIOS name of that host.
	</para>
</listitem>
</orderedlist>

<para>
If, however, both samba and your clients are using a WINS server, then:
</para>

<orderedlist>
<listitem>
	<para>
	your local master browsers will contact the WINS server and, as long as
	samba has registered that it is a domain master browser with the WINS
	server, your local master browser will receive samba's ip address
	as its domain master browser.
	</para>
</listitem>

<listitem>
	<para>
	when a client receives a domain-wide browse list, and a user attempts
	to access a host in that list, it will contact the WINS server to
	resolve the NetBIOS name of that host.  as long as that host has
	registered its NetBIOS name with the same WINS server, the user will
	be able to see that host.  
	</para>
</listitem>
</orderedlist>

</sect1>

<sect1>
<title>Note about broadcast addresses</title>

<para>
If your network uses a "0" based broadcast address (for example if it
ends in a 0) then you will strike problems.  Windows for Workgroups
does not seem to support a 0's broadcast and you will probably find
that browsing and name lookups won't work.
</para>
</sect1>

<sect1>
<title>Multiple interfaces</title>

<para>
Samba now supports machines with multiple network interfaces.  If you
have multiple interfaces then you will need to use the "interfaces"
option in smb.conf to configure them.  See smb.conf(5) for details.
</para>
</sect1>
</chapter>
Bugs.sgml (text/plain, 6.1 KB)
<chapter id="bugreport">

<chapterinfo>
	<author>
		<affiliation>
			<orgname>Samba Team</orgname>
		</affiliation>
	</author>
	<pubdate> 27 June 1997 </pubdate>
</chapterinfo>

<title>Reporting Bugs</title>

<sect1>
<title>Introduction</title>

<para>
The email address for bug reports is [email protected]
</para>

<para>
Please take the time to read this file before you submit a bug
report. Also, please see if it has changed between releases, as we
may be changing the bug reporting mechanism at some time.
</para>

<para>
Please also do as much as you can yourself to help track down the
bug. Samba is maintained by a dedicated group of people who volunteer
their time, skills and efforts. We receive far more mail about it than
we can possibly answer, so you have a much higher chance of an answer
and a fix if you send us a "developer friendly" bug report that lets
us fix it fast. 
</para>

<para>
Do not assume that if you post the bug to the comp.protocols.smb
newsgroup or the mailing list that we will read it. If you suspect that your 
problem is not a bug but a configuration problem then it is better to send 
it to the Samba mailing list, as there are (at last count) 5000 other users on
that list that may be able to help you.
</para>

<para>
You may also like to look though the recent mailing list archives,
which are conveniently accessible on the Samba web pages
at http://samba.org/samba/ 
</para>

</sect1>

<sect1>
<title>General info</title>

<para>
Before submitting a bug report check your config for silly
errors. Look in your log files for obvious messages that tell you that
you've misconfigured something and run testparm to test your config
file for correct syntax.
</para>

<para>
Have you run through the <ulink url="Diagnosis.html">diagnosis</ulink>? 
This is very important.
</para>

<para>
If you include part of a log file with your bug report then be sure to
annotate it with exactly what you were doing on the client at the
time, and exactly what the results were.
</para>

</sect1>

<sect1>
<title>Debug levels</title>

<para>
If the bug has anything to do with Samba behaving incorrectly as a
server (like refusing to open a file) then the log files will probably
be very useful. Depending on the problem a log level of between 3 and
10 showing the problem may be appropriate. A higher level givesmore
detail, but may use too much disk space.
</para>

<para>
To set the debug level use <command>log level =</command> in your 
<filename>smb.conf</filename>. You may also find it useful to set the log 
level higher for just one machine and keep separate logs for each machine. 
To do this use:
</para>

<para><programlisting>
log level = 10
log file = /usr/local/samba/lib/log.%m
include = /usr/local/samba/lib/smb.conf.%m
</programlisting></para>

<para>
then create a file 
<filename>/usr/local/samba/lib/smb.conf.machine</filename> where
"machine" is the name of the client you wish to debug. In that file
put any smb.conf commands you want, for example 
<command>log level=</command> may be useful. This also allows you to 
experiment with different security systems, protocol levels etc on just 
one machine.
</para>

<para>
The <filename>smb.conf</filename> entry <command>log level =</command> 
is synonymous with the entry <command>debuglevel =</command> that has been 
used in older versions of Samba and is being retained for backwards 
compatibility of smb.conf files.
</para>

<para>
As the <command>log level =</command> value is increased you will record 
a significantly increasing level of debugging information. For most 
debugging operations you may not need a setting higher than 3. Nearly 
all bugs can be tracked at a setting of 10, but be prepared for a VERY 
large volume of log data.
</para>

</sect1>

<sect1>
<title>Internal errors</title>

<para>
If you get a "INTERNAL ERROR" message in your log files it means that
Samba got an unexpected signal while running. It is probably a
segmentation fault and almost certainly means a bug in Samba (unless
you have faulty hardware or system software)
</para>

<para>
If the message came from smbd then it will probably be accompanied by
a message which details the last SMB message received by smbd. This
info is often very useful in tracking down the problem so please
include it in your bug report.
</para>

<para>
You should also detail how to reproduce the problem, if
possible. Please make this reasonably detailed.
</para>

<para>
You may also find that a core file appeared in a "corefiles"
subdirectory of the directory where you keep your samba log
files. This file is the most useful tool for tracking down the bug. To
use it you do this:
</para>

<para><command>gdb smbd core</command></para>

<para>
adding appropriate paths to smbd and core so gdb can find them. If you
don't have gdb then try "dbx". Then within the debugger use the
command "where" to give a stack trace of where the problem
occurred. Include this in your mail.
</para>

<para>
If you known any assembly language then do a "disass" of the routine
where the problem occurred (if its in a library routine then
disassemble the routine that called it) and try to work out exactly
where the problem is by looking at the surrounding code. Even if you
don't know assembly then incuding this info in the bug report can be
useful. 
</para>

<sect1>
<title>Attaching to a running process</title>

<para>
Unfortunately some unixes (in particular some recent linux kernels)
refuse to dump a core file if the task has changed uid (which smbd
does often). To debug with this sort of system you could try to attach
to the running process using "gdb smbd PID" where you get PID from
smbstatus. Then use "c" to continue and try to cause the core dump
using the client. The debugger should catch the fault and tell you
where it occurred.
</para>

</sect1>

<sect1>
<title>Patches</title>

<para>
The best sort of bug report is one that includes a fix! If you send us
patches please use <command>diff -u</command> format if your version of 
diff supports it, otherwise use <command>diff -c4</command>. Make sure 
your do the diff against a clean version of the source and let me know 
exactly what version you used. 
</para>

</sect1>
</chapter>
Diagnosis.sgml (text/plain, 14.5 KB)
<chapter id="diagnosis">
<chapterinfo>
	<author>
		<firstname>Andrew</firstname><surname>Tridgell</surname>
		<affiliation>
			<orgname>Samba Team</orgname>
			<address><email>[email protected]</email></address>
		</affiliation>
	</author>
	<pubdate> 1 November 1999</pubdate>
</chapterinfo>

<title>Diagnosing your samba server</title>

<sect1>
<title>Introduction</title>

<para>
This file contains a list of tests you can perform to validate your
Samba server. It also tells you what the likely cause of the problem
is if it fails any one of these steps. If it passes all these tests
then it is probably working fine.
</para>

<para>
You should do ALL the tests, in the order shown. I have tried to
carefully choose them so later tests only use capabilities verified in
the earlier tests.
</para>

<para>
If you send me an email saying "it doesn't work" and you have not
followed this test procedure then you should not be surprised if I
ignore your email.
</para>

</sect1>

<sect1>
<title>Assumptions</title>

<para>
In all of the tests I assume you have a Samba server called BIGSERVER
and a PC called ACLIENT both in workgroup TESTGROUP. I also assume the
PC is running windows for workgroups with a recent copy of the
microsoft tcp/ip stack. Alternatively, your PC may be running Windows
95 or Windows NT (Workstation or Server).
</para>

<para>
The procedure is similar for other types of clients.
</para>

<para>
I also assume you know the name of an available share in your
smb.conf. I will assume this share is called "tmp". You can add a
"tmp" share like by adding the following to smb.conf:
</para>

<para><programlisting>

[tmp]
 comment = temporary files 
 path = /tmp
 read only = yes

</programlisting>
</para>

<para>
THESE TESTS ASSUME VERSION 2.0.6 OR LATER OF THE SAMBA SUITE. SOME
COMMANDS SHOWN DID NOT EXIST IN EARLIER VERSIONS
</para>

<para>
Please pay attention to the error messages you receive. If any error message
reports that your server is being unfriendly you should first check that you
IP name resolution is correctly set up. eg: Make sure your /etc/resolv.conf
file points to name servers that really do exist.
</para>

<para>
Also, if you do not have DNS server access for name resolution please check
that the settings for your smb.conf file results in "dns proxy = no". The
best way to check this is with "testparm smb.conf"
</para>

<sect1>
<title>Tests</title>

<sect2>
<title>Test 1</title>
<para>
In the directory in which you store your smb.conf file, run the command
"testparm smb.conf". If it reports any errors then your smb.conf
configuration file is faulty.
</para>

<para>
Note:	Your smb.conf file may be located in: <filename>/etc</filename>
	Or in:   <filename>/usr/local/samba/lib</filename>
</para>
</sect2>

<sect2>
<title>Test 2</title>

<para>
Run the command "ping BIGSERVER" from the PC and "ping ACLIENT" from
the unix box. If you don't get a valid response then your TCP/IP
software is not correctly installed. 
</para>

<para>
Note that you will need to start a "dos prompt" window on the PC to
run ping.
</para>

<para>
If you get a message saying "host not found" or similar then your DNS
software or /etc/hosts file is not correctly setup. It is possible to
run samba without DNS entries for the server and client, but I assume
you do have correct entries for the remainder of these tests. 
</para>

<para>
Another reason why ping might fail is if your host is running firewall 
software. You will need to relax the rules to let in the workstation
in question, perhaps by allowing access from another subnet (on Linux
this is done via the ipfwadm program.)
</para>
</sect2>

<sect2>
<title>Test 3</title>

<para>
Run the command "smbclient -L BIGSERVER" on the unix box. You
should get a list of available shares back. 
</para>

<para>
If you get a error message containing the string "Bad password" then
you probably have either an incorrect "hosts allow", "hosts deny" or
"valid users" line in your smb.conf, or your guest account is not
valid. Check what your guest account is using "testparm" and
temporarily remove any "hosts allow", "hosts deny", "valid users" or
"invalid users" lines.
</para>

<para>
If you get a "connection refused" response then the smbd server may
not be running. If you installed it in inetd.conf then you probably edited
that file incorrectly. If you installed it as a daemon then check that
it is running, and check that the netbios-ssn port is in a LISTEN
state using "netstat -a".
</para>

<para>
If you get a "session request failed" then the server refused the
connection. If it says "Your server software is being unfriendly" then
its probably because you have invalid command line parameters to smbd,
or a similar fatal problem with the initial startup of smbd. Also
check your config file (smb.conf) for syntax errors with "testparm"
and that the various directories where samba keeps its log and lock
files exist.
</para>

<para>
There are a number of reasons for which smbd may refuse or decline
a session request. The most common of these involve one or more of
the following smb.conf file entries:
</para>

<para><programlisting>
	hosts deny = ALL
	hosts allow = xxx.xxx.xxx.xxx/yy
	bind interfaces only = Yes
</programlisting></para>

<para>
In the above, no allowance has been made for any session requests that
will automatically translate to the loopback adaptor address 127.0.0.1.
To solve this problem change these lines to:
</para>

<para><programlisting>
	hosts deny = ALL
	hosts allow = xxx.xxx.xxx.xxx/yy 127.
</programlisting></para>

<para>
Do NOT use the "bind interfaces only" parameter where you may wish to
use the samba password change facility, or where smbclient may need to
access local service for name resolution or for local resource
connections. (Note: the "bind interfaces only" parameter deficiency
where it will not allow connections to the loopback address will be
fixed soon).
</para>

<para>
Another common cause of these two errors is having something already running 
on port 139, such as Samba (ie: smbd is running from inetd already) or
something like Digital's Pathworks. Check your inetd.conf file before trying
to start smbd as a daemon, it can avoid a lot of frustration!
</para>

<para>
And yet another possible cause for failure of TEST 3 is when the subnet mask
and / or broadcast address settings are incorrect. Please check that the
network interface IP Address / Broadcast Address / Subnet Mask settings are
correct and that Samba has correctly noted these in the log.nmb file.
</para>

</sect2>

<sect2>
<title>Test 4</title>

<para>
Run the command "nmblookup -B BIGSERVER __SAMBA__". You should get the
IP address of your Samba server back.
</para>

<para>
If you don't then nmbd is incorrectly installed. Check your inetd.conf
if you run it from there, or that the daemon is running and listening
to udp port 137.
</para>

<para>
One common problem is that many inetd implementations can't take many
parameters on the command line. If this is the case then create a
one-line script that contains the right parameters and run that from
inetd.
</para>

</sect2>

<sect2>
<title>Test 5</title>

<para>run the command <command>nmblookup -B ACLIENT '*'</command></para>

<para>
You should get the PCs IP address back. If you don't then the client
software on the PC isn't installed correctly, or isn't started, or you
got the name of the PC wrong. 
</para>

<para>
If ACLIENT doesn't resolve via DNS then use the IP address of the
client in the above test.
</para>

</sect2>

<sect2>
<title>Test 6</title>

<para>
Run the command <command>nmblookup -d 2 '*'</command>
</para>

<para>
This time we are trying the same as the previous test but are trying
it via a broadcast to the default broadcast address. A number of
Netbios/TCPIP hosts on the network should respond, although Samba may
not catch all of the responses in the short time it listens. You
should see "got a positive name query response" messages from several
hosts.
</para>

<para>
If this doesn't give a similar result to the previous test then
nmblookup isn't correctly getting your broadcast address through its
automatic mechanism. In this case you should experiment use the
"interfaces" option in smb.conf to manually configure your IP
address, broadcast and netmask. 
</para>

<para>
If your PC and server aren't on the same subnet then you will need to
use the -B option to set the broadcast address to the that of the PCs
subnet.
</para>

<para>
This test will probably fail if your subnet mask and broadcast address are
not correct. (Refer to TEST 3 notes above).
</para>

</sect2>

<sect2>
<title>Test 7</title>

<para>
Run the command <command>smbclient //BIGSERVER/TMP</command>. You should 
then be prompted for a password. You should use the password of the account
you are logged into the unix box with. If you want to test with
another account then add the -U &gt;accountname&lt; option to the end of
the command line.  eg: 
<command>smbclient //bigserver/tmp -Ujohndoe</command>
</para>

<para>
Note: It is possible to specify the password along with the username
as follows:
<command>smbclient //bigserver/tmp -Ujohndoe%secret</command>
</para>

<para>
Once you enter the password you should get the "smb>" prompt. If you
don't then look at the error message. If it says "invalid network
name" then the service "tmp" is not correctly setup in your smb.conf.
</para>

<para>
If it says "bad password" then the likely causes are:
</para>

<orderedlist>
<listitem>
	<para>
	you have shadow passords (or some other password system) but didn't
	compile in support for them in smbd
	</para>
</listitem>

<listitem>
	<para>
	your "valid users" configuration is incorrect
	</para>
</listitem>

<listitem>
	<para>
	you have a mixed case password and you haven't enabled the "password
	level" option at a high enough level
	</para>
</listitem>

<listitem>
	<para>
	the "path =" line in smb.conf is incorrect. Check it with testparm
	</para>
</listitem>

<listitem>
	<para>
	you enabled password encryption but didn't create the SMB encrypted
	password file
	</para>
</listitem>
</orderedlist>

<para>
Once connected you should be able to use the commands 
<command>dir</command> <command>get</command> <command>put</command> etc. 
Type <command>help &gt;command&lt;</command> for instructions. You should
especially check that the amount of free disk space shown is correct
when you type <command>dir</command>.
</para>

</sect2>

<sect2>
<title>Test 8</title>

<para>
On the PC type the command <command>net view \\BIGSERVER</command>. You will 
need to do this from within a "dos prompt" window. You should get back a 
list of available shares on the server.
</para>

<para>
If you get a "network name not found" or similar error then netbios
name resolution is not working. This is usually caused by a problem in
nmbd. To overcome it you could do one of the following (you only need
to choose one of them):
</para>

<orderedlist>
<listitem><para>
	fixup the nmbd installation
</para></listitem>

<listitem><para>
	add the IP address of BIGSERVER to the "wins server" box in the
	advanced tcp/ip setup on the PC.
</para></listitem>

<listitem><para>
	enable windows name resolution via DNS in the advanced section of
	the tcp/ip setup
</para></listitem>

<listitem><para>
	add BIGSERVER to your lmhosts file on the PC.
</para></listitem>
</orderedlist>

<para>
If you get a "invalid network name" or "bad password error" then the
same fixes apply as they did for the "smbclient -L" test above. In
particular, make sure your "hosts allow" line is correct (see the man
pages)
</para>

<para>
Also, do not overlook that fact that when the workstation requests the
connection to the samba server it will attempt to connect using the 
name with which you logged onto your Windows machine. You need to make
sure that an account exists on your Samba server with that exact same
name and password.
</para>

<para>
If you get "specified computer is not receiving requests" or similar
it probably means that the host is not contactable via tcp services.
Check to see if the host is running tcp wrappers, and if so add an entry in
the hosts.allow file for your client (or subnet, etc.)
</para>

</sect2>

<sect2>
<title>Test 9</title>

<para>
Run the command <command>net use x: \\BIGSERVER\TMP</command>. You should 
be prompted for a password then you should get a "command completed 
successfully" message. If not then your PC software is incorrectly 
installed or your smb.conf is incorrect. make sure your "hosts allow" 
and other config lines in smb.conf are correct.
</para>

<para>
It's also possible that the server can't work out what user name to
connect you as. To see if this is the problem add the line "user =
USERNAME" to the [tmp] section of smb.conf where "USERNAME" is the
username corresponding to the password you typed. If you find this
fixes things you may need the username mapping option.
</para>

</sect2>

<sect2>
<title>Test 10</title>

<para>
Run the command <command>nmblookup -M TESTGROUP</command> where 
TESTGROUP is the name of the workgroup that your Samba server and 
Windows PCs belong to. You should get back the IP address of the 
master browser for that workgroup.
</para>

<para>
If you don't then the election process has failed. Wait a minute to
see if it is just being slow then try again. If it still fails after
that then look at the browsing options you have set in smb.conf. Make
sure you have <command>preferred master = yes</command> to ensure that 
an election is held at startup.
</para>

</sect2>

<sect2>
<title>Test 11</title>

<para>
From file manager try to browse the server. Your samba server should
appear in the browse list of your local workgroup (or the one you
specified in smb.conf). You should be able to double click on the name
of the server and get a list of shares. If you get a "invalid
password" error when you do then you are probably running WinNT and it
is refusing to browse a server that has no encrypted password
capability and is in user level security mode. In this case either set
<command>security = server</command> AND 
<command>password server = Windows_NT_Machine</command> in your
smb.conf file, or enable encrypted passwords AFTER compiling in support
for encrypted passwords (refer to the Makefile).
</para>

</sect2>
</sect1>

<sect1>
<title>Still having troubles?</title>

<para>
Try the mailing list or newsgroup, or use the ethereal utility to
sniff the problem. The official samba mailing list can be reached at
<ulink url="mailto:[email protected]">[email protected]</ulink>. To find 
out more about samba and how to subscribe to the mailing list check 
out the samba web page at 
<ulink url="http://samba.org/samba">http://samba.org/samba</ulink>
</para>

<para>
Also look at the other docs in the Samba package!
</para>

</sect1>
Speed.sgml (text/plain, 16.5 KB)
<chapter id="speed">

<chapterinfo>
	<author>
		<affiliation>
			<orgname>Samba Team</orgname>
			<address><email>[email protected]</email></address>
		</affiliation>
	</author>
	<author>
		<firstname>Paul</firstname><surname>Cochrane</surname>
		<affiliation>
			<orgname>Dundee Limb Fitting Centre</orgname>
			<address><email>[email protected]</email></address>
		</affiliation>
	</author>
</chapterinfo>

<title>Samba performance issues</title>

<sect1>
<title>Comparisons</title>

<para>
The Samba server uses TCP to talk to the client. Thus if you are
trying to see if it performs well you should really compare it to
programs that use the same protocol. The most readily available
programs for file transfer that use TCP are ftp or another TCP based
SMB server.
</para>

<para>
If you want to test against something like a NT or WfWg server then
you will have to disable all but TCP on either the client or
server. Otherwise you may well be using a totally different protocol
(such as Netbeui) and comparisons may not be valid.
</para>

<para>
Generally you should find that Samba performs similarly to ftp at raw
transfer speed. It should perform quite a bit faster than NFS,
although this very much depends on your system.
</para>

<para>
Several people have done comparisons between Samba and Novell, NFS or
WinNT. In some cases Samba performed the best, in others the worst. I
suspect the biggest factor is not Samba vs some other system but the
hardware and drivers used on the various systems. Given similar
hardware Samba should certainly be competitive in speed with other
systems.
</para>

</sect1>

<sect1>
<title>Oplocks</title>

<sect2>
<title>Overview</title>

<para>
Oplocks are the way that SMB clients get permission from a server to
locally cache file operations. If a server grants an oplock
(opportunistic lock) then the client is free to assume that it is the
only one accessing the file and it will agressively cache file
data. With some oplock types the client may even cache file open/close
operations. This can give enormous performance benefits.
</para>

<para>
With the release of Samba 1.9.18 we now correctly support opportunistic 
locks. This is turned on by default, and can be turned off on a share-
by-share basis by setting the parameter :
</para>

<para>
<command>oplocks = False</command>
</para>

<para>
We recommend that you leave oplocks on however, as current benchmark
tests with NetBench seem to give approximately a 30% improvement in
speed with them on. This is on average however, and the actual 
improvement seen can be orders of magnitude greater, depending on
what the client redirector is doing.
</para>

<para>
Previous to Samba 1.9.18 there was a 'fake oplocks' option. This
option has been left in the code for backwards compatibility reasons
but it's use is now deprecated. A short summary of what the old
code did follows.
</para>

</sect2>

<sect2>
<title>Level2 Oplocks</title>

<para>
With Samba 2.0.5 a new capability - level2 (read only) oplocks is
supported (although the option is off by default - see the smb.conf
man page for details). Turning on level2 oplocks (on a share-by-share basis)
by setting the parameter :
</para>

<para>
<command>level2 oplocks = true</command>
</para>

<para>
should speed concurrent access to files that are not commonly written
to, such as application serving shares (ie. shares that contain common
.EXE files - such as a Microsoft Office share) as it allows clients to
read-ahread cache copies of these files.
</para>

</sect2>

<sect2>
<title>Old 'fake oplocks' option - deprecated</title>

<para>
Samba can also fake oplocks, by granting a oplock whenever a client 
asks for one. This is controlled using the smb.conf option "fake 
oplocks". If you set "fake oplocks = yes" then you are telling the 
client that it may agressively cache the file data for all opens.
</para>

<para>
Enabling 'fake oplocks' on all read-only shares or shares that you know
will only be accessed from one client at a time you will see a big
performance improvement on many operations. If you enable this option
on shares where multiple clients may be accessing the files read-write
at the same time you can get data corruption.
</para>

</sect2>
</sect1>

<sect1>
<title>Socket options</title>

<para>
There are a number of socket options that can greatly affect the
performance of a TCP based server like Samba.
</para>

<para>
The socket options that Samba uses are settable both on the command
line with the -O option, or in the smb.conf file.

<para>
The "socket options" section of the smb.conf manual page describes how
to set these and gives recommendations.
</para>

<para>
Getting the socket options right can make a big difference to your
performance, but getting them wrong can degrade it by just as
much. The correct settings are very dependent on your local network.
</para>

<para>
The socket option TCP_NODELAY is the one that seems to make the
biggest single difference for most networks. Many people report that
adding "socket options = TCP_NODELAY" doubles the read performance of
a Samba drive. The best explanation I have seen for this is that the
Microsoft TCP/IP stack is slow in sending tcp ACKs.
</para>

</sect1>

<sect1>
<title>Read size</title>

<para>
The option "read size" affects the overlap of disk reads/writes with
network reads/writes. If the amount of data being transferred in
several of the SMB commands (currently SMBwrite, SMBwriteX and
SMBreadbraw) is larger than this value then the server begins writing
the data before it has received the whole packet from the network, or
in the case of SMBreadbraw, it begins writing to the network before
all the data has been read from disk.
</para>

<para>
This overlapping works best when the speeds of disk and network access
are similar, having very little effect when the speed of one is much
greater than the other.
</para>

<para>
The default value is 16384, but very little experimentation has been
done yet to determine the optimal value, and it is likely that the best
value will vary greatly between systems anyway. A value over 65536 is
pointless and will cause you to allocate memory unnecessarily.
</para>

</sect1>

<sect1>
<title>Max xmit</title>

<para>
At startup the client and server negotiate a "maximum transmit" size,
which limits the size of nearly all SMB commands. You can set the
maximum size that Samba will negotiate using the "max xmit = " option
in smb.conf. Note that this is the maximum size of SMB request that 
Samba will accept, but not the maximum size that the *client* will accept.
The client maximum receive size is sent to Samba by the client and Samba
honours this limit.
</para>

<para>
It defaults to 65536 bytes (the maximum), but it is possible that some
clients may perform better with a smaller transmit unit. Trying values
of less than 2048 is likely to cause severe problems.
</para>

<para>
In most cases the default is the best option.
</para>

</sect1>

<sect1>
<title>Locking</title>

<para>
By default Samba does not implement strict locking on each read/write
call (although it did in previous versions). If you enable strict
locking (using "strict locking = yes") then you may find that you
suffer a severe performance hit on some systems.
</para>

<para>
The performance hit will probably be greater on NFS mounted
filesystems, but could be quite high even on local disks.
</para>

</sect1>

<sect1>
<title>Share modes</title>

<para>
Some people find that opening files is very slow. This is often
because of the "share modes" code needed to fully implement the dos
share modes stuff. You can disable this code using "share modes =
no". This will gain you a lot in opening and closing files but will
mean that (in some cases) the system won't force a second user of a
file to open the file read-only if the first has it open
read-write. For many applications that do their own locking this
doesn't matter, but for some it may. Most Windows applications
depend heavily on "share modes" working correctly and it is
recommended that the Samba share mode support be left at the
default of "on".
</para>

<para>
The share mode code in Samba has been re-written in the 1.9.17
release following tests with the Ziff-Davis NetBench PC Benchmarking
tool. It is now believed that Samba 1.9.17 implements share modes
similarly to Windows NT.
</para>

<para>
NOTE: In the most recent versions of Samba there is an option to use
shared memory via mmap() to implement the share modes. This makes
things much faster. See the Makefile for how to enable this.
</para>

</sect1>

<sect1>
<title>Log level</title>

<para>
If you set the log level (also known as "debug level") higher than 2
then you may suffer a large drop in performance. This is because the
server flushes the log file after each operation, which can be very
expensive. 
</para>

<sect1>
<title>Wide lines</title>

<para>
The "wide links" option is now enabled by default, but if you disable
it (for better security) then you may suffer a performance hit in
resolving filenames. The performance loss is lessened if you have
"getwd cache = yes", which is now the default.
</para>

</sect1>

<sect1>
<title>Read raw</title>

<para>
The "read raw" operation is designed to be an optimised, low-latency
file read operation. A server may choose to not support it,
however. and Samba makes support for "read raw" optional, with it
being enabled by default.
</para>

<para>
In some cases clients don't handle "read raw" very well and actually
get lower performance using it than they get using the conventional
read operations. 
</para>

<para>
So you might like to try "read raw = no" and see what happens on your
network. It might lower, raise or not affect your performance. Only
testing can really tell.
</para>

</sect1>

<sect1>
<title>Write raw</title>

<para>
The "write raw" operation is designed to be an optimised, low-latency
file write operation. A server may choose to not support it,
however. and Samba makes support for "write raw" optional, with it
being enabled by default.
</para>

<para>
Some machines may find "write raw" slower than normal write, in which
case you may wish to change this option.
</para>

</sect1>

<sect1>
<title>Read prediction</title>

<para>
Samba can do read prediction on some of the SMB commands. Read
prediction means that Samba reads some extra data on the last file it
read while waiting for the next SMB command to arrive. It can then
respond more quickly when the next read request arrives.
</para>

<para>
This is disabled by default. You can enable it by using "read
prediction = yes".
</para>

<para>
Note that read prediction is only used on files that were opened read
only.
</para>

<para>
Read prediction should particularly help for those silly clients (such
as "Write" under NT) which do lots of very small reads on a file.
</para>

<para>
Samba will not read ahead more data than the amount specified in the
"read size" option. It always reads ahead on 1k block boundaries.
</para>

</sect1>

<sect1>
<title>Memory mapping</title>

<para>
Samba supports reading files via memory mapping them. One some
machines this can give a large boost to performance, on others it
makes not difference at all, and on some it may reduce performance.
</para>

<para>
To enable you you have to recompile Samba with the -DUSE_MMAP option
on the FLAGS line of the Makefile.
</para>

<para>
Note that memory mapping is only used on files opened read only, and
is not used by the "read raw" operation. Thus you may find memory
mapping is more effective if you disable "read raw" using "read raw =
no".
</para>

</sect1>

<sect1>
<title>Slow Clients</title>

<para>
One person has reported that setting the protocol to COREPLUS rather
than LANMAN2 gave a dramatic speed improvement (from 10k/s to 150k/s).
</para>

<para>
I suspect that his PC's (386sx16 based) were asking for more data than
they could chew. I suspect a similar speed could be had by setting
"read raw = no" and "max xmit = 2048", instead of changing the
protocol. Lowering the "read size" might also help.
</para>

</sect1>

<sect1>
<title>Slow Logins</title>

<para>
Slow logins are almost always due to the password checking time. Using
the lowest practical "password level" will improve things a lot. You
could also enable the "UFC crypt" option in the Makefile.
</para>

</sect1>

<sect1>
<title>Client tuning</title>

<para>
Often a speed problem can be traced to the client. The client (for
example Windows for Workgroups) can often be tuned for better TCP
performance.
</para>

<para>
See your client docs for details. In particular, I have heard rumours
that the WfWg options TCPWINDOWSIZE and TCPSEGMENTSIZE can have a
large impact on performance.
</para>

<para>
Also note that some people have found that setting DefaultRcvWindow in
the [MSTCP] section of the SYSTEM.INI file under WfWg to 3072 gives a
big improvement. I don't know why.
</para>

<para>
My own experience wth DefaultRcvWindow is that I get much better
performance with a large value (16384 or larger). Other people have
reported that anything over 3072 slows things down enourmously. One
person even reported a speed drop of a factor of 30 when he went from
3072 to 8192. I don't know why.
</para>

<para>
It probably depends a lot on your hardware, and the type of unix box
you have at the other end of the link.
</para>

<para>
Paul Cochrane has done some testing on client side tuning and come 
to the following conclusions:
</para>

<para>
Install the W2setup.exe file from www.microsoft.com. This is an 
update for the winsock stack and utilities which improve performance.
</para>

<para>
Configure the win95 TCPIP registry settings to give better 
perfomance. I use a program called MTUSPEED.exe which I got off the 
net. There are various other utilities of this type freely available. 
The setting which give the best performance for me are:
</para>

<orderedlist>
<listitem><para>
MaxMTU                  Remove
</para></listitem>
<listitem><para>
RWIN                    Remove
</para></listitem>
<listitem><para>
MTUAutoDiscover         Disable
</para></listitem>
<listitem><para>
MTUBlackHoleDetect      Disable
</para></listitem>
<listitem><para>
Time To Live            Enabled
</para></listitem>
<listitem><para>
Time To Live - HOPS     32
</para></listitem>
<listitem><para>
NDI Cache Size          0
</para></listitem>
</orderedlist>

<para>
I tried virtually all of the items mentioned in the document and 
the only one which made a difference to me was the socket options. It 
turned out I was better off without any!!!!!
</para>

<para>
In terms of overall speed of transfer, between various win95 clients 
and a DX2-66 20MB server with a crappy NE2000 compatible and old IDE 
drive (Kernel 2.0.30). The transfer rate was reasonable for 10 baseT.
</para>

<para>
FIXME
The figures are:          Put              Get 
P166 client 3Com card:    420-440kB/s      500-520kB/s
P100 client 3Com card:    390-410kB/s      490-510kB/s
DX4-75 client NE2000:     370-380kB/s      330-350kB/s
</para>

<para>
I based these test on transfer two files a 4.5MB text file and a 15MB 
textfile. The results arn't bad considering the hardware Samba is 
running on. It's a crap machine!!!!
</para>

<para>
The updates mentioned in 1 and 2 brought up the transfer rates from 
just over 100kB/s in some clients.
</para>

<para>
A new client is a P333 connected via a 100MB/s card and hub. The 
transfer rates from this were good: 450-500kB/s on put and 600+kB/s 
on get.
</para>

<para>
Looking at standard FTP throughput, Samba is a bit slower (100kB/s 
upwards). I suppose there is more going on in the samba protocol, but 
if it could get up to the rate of FTP the perfomance would be quite 
staggering.
</para>

</sect1>

<sect1>
<title>My Results</title>

<para>
Some people want to see real numbers in a document like this, so here
they are. I have a 486sx33 client running WfWg 3.11 with the 3.11b
tcp/ip stack. It has a slow IDE drive and 20Mb of ram. It has a SMC
Elite-16 ISA bus ethernet card. The only WfWg tuning I've done is to
set DefaultRcvWindow in the [MSTCP] section of system.ini to 16384. My
server is a 486dx3-66 running Linux. It also has 20Mb of ram and a SMC
Elite-16 card. You can see my server config in the examples/tridge/
subdirectory of the distribution.
</para>

<para>
I get 490k/s on reading a 8Mb file with copy.
I get 441k/s writing the same file to the samba server.
</para>

<para>
Of course, there's a lot more to benchmarks than 2 raw throughput
figures, but it gives you a ballpark figure.
</para>

<para>
I've also tested Win95 and WinNT, and found WinNT gave me the best
speed as a samba client. The fastest client of all (for me) is
smbclient running on another linux box. Maybe I'll add those results
here someday ...
</para>

</sect1>
</chapter>
winbind.diff (text/plain, 8.4 KB)
Index: winbind.sgml
===================================================================
RCS file: /cvsroot/samba/docs/docbook/projdoc/winbind.sgml,v
retrieving revision 1.7
diff -u -3 -p -r1.7 winbind.sgml
--- winbind.sgml	8 May 2002 15:34:58 -0000	1.7
+++ winbind.sgml	28 Jun 2002 11:29:52 -0000
@@ -23,9 +23,19 @@
 			<address><email>[email protected]</email></address>
 		</affiliation>
 	</author>
-	
-		
-	<pubdate>16 Oct 2000</pubdate>
+	<author>
+		<firstname>Naag</firstname><surname>Mummaneni</surname>
+		<affiliation>
+			<address><email>[email protected]</email></address>
+		</affiliation>
+	</author>
+	<author>
+		<firstname>Jelmer</firstname><surname>Vernooij</surname>
+		<affiliation>
+			<address><email>[email protected]</email></address>
+		</affiliation>
+	</author>
+	<pubdate>27 June 2002</pubdate>
 </chapterinfo>
 
 <title>Unified Logons between Windows NT and UNIX using Winbind</title>
@@ -489,6 +499,12 @@ I also found it necessary to make the fo
 <prompt>root#</prompt> <command>ln -s /lib/libnss_winbind.so /lib/libnss_winbind.so.2</command>
 </para>
 
+<para>And, in the case of Sun solaris:
+<prompt>root#</prompt> <command>ln -s /usr/lib/libnss_winbind.so /usr/lib/libnss_winbind.so.1</command>
+<prompt>root#</prompt> <command>ln -s /usr/lib/libnss_winbind.so /usr/lib/nss_winbind.so.1</command>
+<prompt>root#</prompt> <command>ln -s /usr/lib/libnss_winbind.so /usr/lib/nss_winbind.so.2</command>
+</para>
+
 <para>
 Now, as root you need to edit <filename>/etc/nsswitch.conf</filename> to 
 allow user and group entries to be visible from the <command>winbindd</command> 
@@ -682,14 +698,18 @@ The same thing can be done for groups wi
 
 
 <sect3>
-<title>Fix the <filename>/etc/rc.d/init.d/smb</filename> startup files</title>
+<title>Fix the init.d startup scripts</title>
+
+<sect4>
+<title>Linux</title>
 
 <para>
 The <command>winbindd</command> daemon needs to start up after the 
 <command>smbd</command> and <command>nmbd</command> daemons are running.  
-To accomplish this task, you need to modify the <filename>/etc/init.d/smb</filename>
+To accomplish this task, you need to modify the startup scripts of your system. They are located at <filename>/etc/init.d/smb</filename> in RedHat and 
+<filename>/etc/init.d/samba</filename> in Debian.
 script to add commands to invoke this daemon in the proper sequence.  My 
-<filename>/etc/init.d/smb</filename> file starts up <command>smbd</command>, 
+startup script starts up <command>smbd</command>, 
 <command>nmbd</command>, and <command>winbindd</command> from the 
 <filename>/usr/local/samba/bin</filename> directory directly.  The 'start' 
 function in the script looks like this:
@@ -744,18 +764,79 @@ stop() {
         return $RETVAL
 }
 </programlisting></para>
+</sect4>
+
+<sect4>
+<title>Solaris</title>
+
+<para>On solaris, you need to modify the 
+<filename>/etc/init.d/samba.server</filename> startup script. It usually 
+only starts smbd and nmbd but should now start winbindd too. If you 
+have samba installed in <filename>/usr/local/samba/bin</filename>, 
+the file could contains something like this:
+</para>
+
+<para><programlisting>
+##
+## samba.server
+##
+
+if [ ! -d /usr/bin ]
+then                    # /usr not mounted
+        exit
+fi
+
+killproc() {            # kill the named process(es)
+        pid=`/usr/bin/ps -e |
+             /usr/bin/grep -w $1 |
+             /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
+        [ "$pid" != "" ] && kill $pid
+}
+ 
+# Start/stop processes required for samba server
+
+case "$1" in
+
+'start')
+#
+# Edit these lines to suit your installation (paths, workgroup, host)
+#
+echo Starting SMBD
+   /usr/local/samba/bin/smbd -D -s \
+	/usr/local/samba/smb.conf
+
+echo Starting NMBD
+   /usr/local/samba/bin/nmbd -D -l \
+	/usr/local/samba/var/log -s /usr/local/samba/smb.conf
+
+echo Starting Winbind Daemon
+   /usr/local/samba/bin/winbindd
+   ;;
+
+'stop')
+   killproc nmbd
+   killproc smbd
+   killproc winbindd
+   ;;
+
+*)
+   echo "Usage: /etc/init.d/samba.server { start | stop }"
+   ;;
+esac
+</programlisting></para>
+</sect4>
 
+<sect4>
+<title>Restarting</title>
 <para>
 If you restart the <command>smbd</command>, <command>nmbd</command>, 
 and <command>winbindd</command> daemons at this point, you
 should be able to connect to the samba server as a domain member just as
 if you were a local user.
 </para>
-
+</sect4>
 </sect3>
 
-
-
 <sect3>
 <title>Configure Winbind and PAM</title>
 
@@ -781,13 +862,17 @@ by invoking the command
 from the <filename>../source</filename> directory.  The
 <filename>pam_winbind.so</filename> file should be copied to the location of
 your other pam security modules.  On my RedHat system, this was the
-<filename>/lib/security</filename> directory.
+<filename>/lib/security</filename> directory. On Solaris, the pam security 
+modules reside in <filename>/usr/lib/security</filename>.
 </para>
 
 <para>
 <prompt>root#</prompt> <command>cp ../samba/source/nsswitch/pam_winbind.so /lib/security</command>
 </para>
 
+<sect4>
+<title>Linux/FreeBSD-specific PAM configuration</title>
+
 <para>
 The <filename>/etc/pam.d/samba</filename> file does not need to be changed. I 
 just left this fileas it was:
@@ -875,6 +960,92 @@ line after the <command>winbind.so</comm
 double prompts for passwords.
 </para>
 
+</sect4>
+
+<sect4>
+<title>Solaris-specific configuration</title>
+
+<para>
+The /etc/pam.conf needs to be changed. I changed this file so that my Domain
+users can logon both locally as well as telnet.The following are the changes
+that I made.You can customize the pam.conf file as per your requirements,but
+be sure of those changes because in the worst case it will leave your system
+nearly impossible to boot.
+</para>
+
+<para><programlisting>
+#
+#ident	"@(#)pam.conf	1.14	99/09/16 SMI"
+#
+# Copyright (c) 1996-1999, Sun Microsystems, Inc.
+# All Rights Reserved.
+#
+# PAM configuration
+#
+# Authentication management
+#
+login   auth required   /usr/lib/security/pam_winbind.so
+login	auth required 	/usr/lib/security/$ISA/pam_unix.so.1 try_first_pass 
+login	auth required 	/usr/lib/security/$ISA/pam_dial_auth.so.1 try_first_pass 
+#
+rlogin  auth sufficient /usr/lib/security/pam_winbind.so
+rlogin  auth sufficient /usr/lib/security/$ISA/pam_rhosts_auth.so.1
+rlogin	auth required 	/usr/lib/security/$ISA/pam_unix.so.1 try_first_pass
+#
+dtlogin auth sufficient /usr/lib/security/pam_winbind.so
+dtlogin	auth required 	/usr/lib/security/$ISA/pam_unix.so.1 try_first_pass
+#
+rsh	auth required	/usr/lib/security/$ISA/pam_rhosts_auth.so.1
+other   auth sufficient /usr/lib/security/pam_winbind.so
+other	auth required	/usr/lib/security/$ISA/pam_unix.so.1 try_first_pass
+#
+# Account management
+#
+login   account sufficient      /usr/lib/security/pam_winbind.so
+login	account requisite	/usr/lib/security/$ISA/pam_roles.so.1 
+login	account required	/usr/lib/security/$ISA/pam_unix.so.1 
+#
+dtlogin account sufficient      /usr/lib/security/pam_winbind.so
+dtlogin	account requisite	/usr/lib/security/$ISA/pam_roles.so.1 
+dtlogin	account required	/usr/lib/security/$ISA/pam_unix.so.1 
+#
+other   account sufficient      /usr/lib/security/pam_winbind.so
+other	account requisite	/usr/lib/security/$ISA/pam_roles.so.1 
+other	account required	/usr/lib/security/$ISA/pam_unix.so.1 
+#
+# Session management
+#
+other	session required	/usr/lib/security/$ISA/pam_unix.so.1 
+#
+# Password management
+#
+#other   password sufficient     /usr/lib/security/pam_winbind.so
+other	password required	/usr/lib/security/$ISA/pam_unix.so.1 
+dtsession auth required	/usr/lib/security/$ISA/pam_unix.so.1
+#
+# Support for Kerberos V5 authentication (uncomment to use Kerberos)
+#
+#rlogin	auth optional	/usr/lib/security/$ISA/pam_krb5.so.1 try_first_pass
+#login	auth optional	/usr/lib/security/$ISA/pam_krb5.so.1 try_first_pass
+#dtlogin	auth optional	/usr/lib/security/$ISA/pam_krb5.so.1 try_first_pass
+#other	auth optional	/usr/lib/security/$ISA/pam_krb5.so.1 try_first_pass
+#dtlogin	account optional /usr/lib/security/$ISA/pam_krb5.so.1
+#other	account optional /usr/lib/security/$ISA/pam_krb5.so.1
+#other	session optional /usr/lib/security/$ISA/pam_krb5.so.1
+#other	password optional /usr/lib/security/$ISA/pam_krb5.so.1 try_first_pass
+</programlisting></para>
+
+<para>
+I also added a try_first_pass line after the winbind.so line to get rid of
+annoying double prompts for passwords.
+</para>
+
+<para>
+Now restart your Samba & try connecting through your application that you
+configured in the pam.conf.
+</para>
+
+</sect4>
 
 </sect3>
CodingSuggestions.sgml (text/plain, 7.3 KB)
<chapter id="CodingSuggestions">
<chapterinfo>
	<author>
		<firstname>Steve</firstname><surname>French</surname>
	</author>
	<author>
		<firstname>Simo</firstname><surname>Sorce</surname>
	</author>
	<author>
		<firstname>Andrew</firstname><surname>Bartlett</surname>
	</author>
	<author>
		<firstname>Tim</firstname><surname>Potter</surname>
	</author>
	<author>
		<firstname>Martin</firstname><surname>Pool</surname>
	</author>
</chapterinfo>

<title>Coding Suggestions</title>

<para>
So you want to add code to Samba ...
</para>

<para>
One of the daunting tasks facing a programmer attempting to write code for
Samba is understanding the various coding conventions used by those most
active in the project.  These conventions were mostly unwritten and helped
improve either the portability, stability or consistency of the code. This
document will attempt to document a few of the more important coding
practices used at this time on the Samba project.  The coding practices are
expected to change slightly over time, and even to grow as more is learned
about obscure portability considerations.  Two existing documents
<filename>samba/source/internals.doc</filename> and 
<filename>samba/source/architecture.doc</filename> provide
additional information.
</para>

<para>
The loosely related question of coding style is very personal and this
document does not attempt to address that subject, except to say that I
have observed that eight character tabs seem to be preferred in Samba
source.  If you are interested in the topic of coding style, two oft-quoted
documents are:
</para>

<para>
<ulink url="http://lxr.linux.no/source/Documentation/CodingStyle">http://lxr.linux.no/source/Documentation/CodingStyle</ulink>
</para>

<para>
<ulink url="http://www.fsf.org/prep/standards_toc.html">http://www.fsf.org/prep/standards_toc.html</ulink>
</para>

<para>
But note that coding style in Samba varies due to the many different
programmers who have contributed.
</para>

<para>
Following are some considerations you should use when adding new code to
Samba.  First and foremost remember that:
</para>

<para>
Portability is a primary consideration in adding function, as is network
compatability with de facto, existing, real world CIFS/SMB implementations.
There are lots of platforms that Samba builds on so use caution when adding
a call to a library function that is not invoked in existing Samba code.
Also note that there are many quite different SMB/CIFS clients that Samba
tries to support, not all of which follow the SNIA CIFS Technical Reference
(or the earlier Microsoft reference documents or the X/Open book on the SMB
Standard) perfectly.
</para>

<para>
Here are some other suggestions:
</para>

<orderedlist>

<listitem><para>
	use d_printf instead of printf for display text
	reason: enable auto-substitution of translated language text 
</para></listitem>

<listitem><para>
	use SAFE_FREE instead of free
	reason: reduce traps due to null pointers
</para></listitem>

<listitem><para>
	don't use bzero use memset, or ZERO_STRUCT and ZERO_STRUCTP macros
	reason: not POSIX
</para></lisitem>

<listitem><para>
	don't use strcpy and strlen (use safe_* equivalents)
	reason: to avoid traps due to buffer overruns
</para></listitem>

<listitem><para>
	don't use getopt_long, use popt functions instead
	reason: portability
</para></listitem>

<listitem><para>
	explicitly add const qualifiers on parm passing in functions where parm
	is input only (somewhat controversial but const can be #defined away)
</para></listitem>

<listitem><para>
	when passing a va_list as an arg, or assigning one to another
	please use the VA_COPY() macro
	reason: on some platforms, va_list is a struct that must be 
	initialized in each function...can SEGV if you don't.
</para></listitem>

<listitem><para>
	discourage use of threads
	reason: portability (also see architecture.doc)
</para></listitem>

<listitem><para>
	don't explicitly include new header files in C files - new h files 
	should be included by adding them once to includes.h
	reason: consistency
</para></listitem>

<listitem><para>
	don't explicitly extern functions (they are autogenerated by 
	"make proto" into proto.h)
	reason: consistency
</para></listitem>

<listitem><para>
	use endian safe macros when unpacking SMBs (see byteorder.h and
	internals.doc)
	reason: not everyone uses Intel
</para></listitem>

<listitem><para>
	Note Unicode implications of charset handling (see internals.doc).  See
	pull_*  and push_* and convert_string functions.
	reason: Internationalization
</para></listitem>

<listitem><para>
	Don't assume English only
	reason: See above
</para></listitem>

<listitem><para>
	Try to avoid using in/out parameters (functions that return data which
	overwrites input parameters)
	reason: Can cause stability problems
</para></listitem>

<listitem><para>
	Ensure copyright notices are correct, don't append Tridge's name to code
	that he didn't write.  If you did not write the code, make sure that it
	can coexist with the rest of the Samba GPLed code.
</para></listitem>

<listitem><para>
	Consider usage of DATA_BLOBs for length specified byte-data.
	reason: stability
</para></listitem>

<listitem><para>
	Take advantage of tdbs for database like function
	reason: consistency
</para></listitem>

<listitem><para>
	Don't access the SAM_ACCOUNT structure directly, they should be accessed
	via pdb_get...() and pdb_set...() functions.
	reason: stability, consistency
</para></listitem>

<listitem><para>
	Don't check a password directly against the passdb, always use the
	check_password() interface.
	reason: long term pluggability
</para></listitem>

<listitem><para>
	Try to use asprintf rather than pstrings and fstrings where possible
</para></listitem>

<listitem><para>
	Use normal C comments / * instead of C++ comments // like
	this.  Although the C++ comment format is part of the C99
	standard, some older vendor C compilers do not accept it.
</para></listitem>

<listitem><para>
	Try to write documentation for API functions and structures
	explaining the point of the code, the way it should be used, and
	any special conditions or results.  Mark these with a double-star
	comment start / ** so that they can be picked up by Doxygen, as in
	this file.
</para></listitem>

<listitem><para>
	Keep the scope narrow. This means making functions/variables
	static whenever possible. We don't want our namespace
	polluted. Each module should have a minimal number of externally
	visible functions or variables.
</para></listitem>

<listitem><para>
	Use function pointers to keep knowledge about particular pieces of
	code isolated in one place. We don't want a particular piece of
	functionality to be spread out across lots of places - that makes
	for fragile, hand to maintain code. Instead, design an interface
	and use tables containing function pointers to implement specific
	functionality. This is particularly important for command
	interpreters. 
</para></listitem>

<listitem><para>
	Think carefully about what it will be like for someone else to add
	to and maintain your code. If it would be hard for someone else to
	maintain then do it another way. 
</para></listitem>

<para>
The suggestions above are simply that, suggestions, but the information may
help in reducing the routine rework done on new code.  The preceeding list
is expected to change routinely as new support routines and macros are
added.
</para>
</chapter>
Printing.sgml (text/plain, 11.4 KB)
<chaptor id="printing_debug">
<chaptorinfo>
	<author>
		<firstname>Patrick</firstname><surname>Powell</surname>
		<afilliate>
			<address><email>[email protected]</email></address>
		</afilliate>
	</author>
	<pubdate>11 August 2000</pubdate>
</chaptorinfo>

<title>Debugging Printing Problems</title>

<sect1>
<title>Introduction</title>

<para>
This is a short description of how to debug printing problems with
Samba. This describes how to debug problems with printing from a SMB
client to a Samba server, not the other way around. For the reverse
see the examples/printing directory.
</para>

<para>
Ok, so you want to print to a Samba server from your PC. The first
thing you need to understand is that Samba does not actually do any
printing itself, it just acts as a middleman between your PC client
and your Unix printing subsystem. Samba receives the file from the PC
then passes the file to a external "print command". What print command
you use is up to you.
</para>

<para>
The whole things is controlled using options in smb.conf. The most
relevant options (which you should look up in the smb.conf man page)
are:
</para>

<para><programlisting>
      [global]
        print command     - send a file to a spooler
        lpq command       - get spool queue status
        lprm command      - remove a job
      [printers]
        path = /var/spool/lpd/samba
</programlisting></para>

<para>
The following are nice to know about:
</para>

<para><programlisting>
        queuepause command   - stop a printer or print queue
        queueresume command  - start a printer or print queue
</programlisting></para>

<para>
Example:
</para>

<para><programlisting>
        print command = /usr/bin/lpr -r -P%p %s
        lpq command   = /usr/bin/lpq    -P%p %s
        lprm command  = /usr/bin/lprm   -P%p %j
        queuepause command = /usr/sbin/lpc -P%p stop
        queuepause command = /usr/sbin/lpc -P%p start
</programlisting></para>

<para>
Samba should set reasonable defaults for these depending on your
system type, but it isn't clairvoyant. It is not uncommon that you
have to tweak these for local conditions.  The commands should
always have fully specified pathnames,  as the smdb may not have
the correct PATH values.
</para>

<para>
When you send a job to Samba to be printed,  it will make a temporary
copy of it in the directory specified in the [printers] section.
and it should be periodically cleaned out.  The lpr -r option
requests that the temporary copy be removed after printing; If
printing fails then you might find leftover files in this directory,
and it should be periodically cleaned out.  Samba used the lpq
command to determine the "job number" assigned to your print job
by the spooler.
</para>

<para>
The %&gt;letter&lt; are "macros" that get dynamically replaced with appropriate
values when they are used. The %s gets replaced with the name of the spool
file that Samba creates and the %p gets replaced with the name of the
printer. The %j gets replaced with the "job number" which comes from
the lpq output.
</para>

</sect1>

<sect1>
<title>Debugging printer problems</title>

<para>
One way to debug printing problems is to start by replacing these
command with shell scripts that record the arguments and the contents
of the print file. A simple example of this kind of things might
be:
</para>

<para><programlisting>
	print command = /tmp/saveprint %p %s

    #!/bin/saveprint
    # we make sure that we are the right user
    /usr/bin/id -p >/tmp/tmp.print
    # we run the command and save the error messages
    # replace the command with the one appropriate for your system
    /usr/bin/lpr -r -P$1 $2 2>>&/tmp/tmp.print
</programlisting></para>

<para>
Then you print a file and try removing it.  You may find that the
print queue needs to be stopped in order to see the queue status
and remove the job:
</para>

<para><programlisting>

h4: {42} % echo hi >/tmp/hi
h4: {43} % smbclient //localhost/lw4
added interface ip=10.0.0.4 bcast=10.0.0.255 nmask=255.255.255.0
Password: 
Domain=[ASTART] OS=[Unix] Server=[Samba 2.0.7]
smb: \> print /tmp/hi
putting file /tmp/hi as hi-17534 (0.0 kb/s) (average 0.0 kb/s)
smb: \> queue
1049     3            hi-17534
smb: \> cancel 1049
Error cancelling job 1049 : code 0
smb: \> cancel 1049
Job 1049 cancelled
smb: \> queue
smb: \> exit
</programlisting></para>

<para>
The 'code 0' indicates that the job was removed.  The comment
by the  smbclient is a bit misleading on this.
You can observe the command output and then and look at the
/tmp/tmp.print file to see what the results are.  You can quickly
find out if the problem is with your printing system.  Often people
have problems with their /etc/printcap file or permissions on
various print queues.
</para>
</sect1>

<sect1>
<title>What printers do I have?</title>

<para>
You can use the 'testprns' program to check to see if the printer
name you are using is recognized by Samba.  For example,  you can
use:
</para>

<para><programlisting>
    testprns printer /etc/printcap
</programlisting></para>

<para>
Samba can get its printcap information from a file or from a program.
You can try the following to see the format of the extracted
information:
</para>

<para><programlisting>
    testprns -a printer /etc/printcap

    testprns -a printer '|/bin/cat printcap'
</programlisting></para>

</sect1>

<sect1>
<title>Setting up printcap and print servers</title>

<para>
You may need to set up some printcaps for your Samba system to use.
It is strongly recommended that you use the facilities provided by
the print spooler to set up queues and printcap information.
</para>

<para>
Samba requires either a printcap or program to deliver printcap
information.  This printcap information has the format:
</para>

<para><programlisting>
  name|alias1|alias2...:option=value:...
</programlisting></para>

<para>
For almost all printing systems, the printer 'name' must be composed
only of alphanumeric or underscore '_' characters.  Some systems also
allow hyphens ('-') as well.  An alias is an alternative name for the
printer,  and an alias with a space in it is used as a 'comment'
about the printer.  The printcap format optionally uses a \ at the end of lines
to extend the printcap to multiple lines.
</para>

<para>
Here are some examples of printcap files:
</para>

<para>
<orderedlist>
<listitem><para>
pr              just printer name
</para></listitem>
<listitem><para>
pr|alias        printer name and alias
</para></listitem>
<listitem><para>
pr|My Printer   printer name, alias used as comment
</para></listitem>
<listitem><para>
pr:sh:\        Same as pr:sh:cm= testing
  :cm= \ 
  testing
</para></listitem>
<listitem><para>
pr:sh           Same as pr:sh:cm= testing
  :cm= testing
</para></listitem>
</orderedlist>

<para>
Samba reads the printcap information when first started.  If you make
changes in the printcap information, then you must do the following:
</para>

<orderedlist>

<listitem><para>
make sure that the print spooler is aware of these changes.
The LPRng system uses the 'lpc reread' command to do this.
</para></listitem>

<listitem><para>
make sure that the spool queues, etc., exist and have the
correct permissions.  The LPRng system uses the 'checkpc -f'
command to do this.
</para></listitem>

<listitem><para>
You now should send a SIGHUP signal to the smbd server to have
it reread the printcap information.
</para></listitem>
</orderedlist>

</sect1>

<sect1>
<title>Job sent, no output</title>

<para>
This is the most frustrating part of printing.  You may have sent the
job,  verified that the job was forwarded,  set up a wrapper around
the command to send the file,  but there was no output from the printer.
</para>

<para>
First,  check to make sure that the job REALLY is getting to the
right print queue.  If you are using a BSD or LPRng print spooler,
you can temporarily stop the printing of jobs.  Jobs can still be
submitted, but they will not be printed.  Use:
</para>

<para><programlisting>
  lpc -Pprinter stop
</programlisting></para>

<para>
Now submit a print job and then use 'lpq -Pprinter' to see if the
job is in the print queue.  If it is not in the print queue then
you will have to find out why it is not being accepted for printing.
</para>

<para>
Next, you may want to check to see what the format of the job really
was.  With the assistance of the system administrator you can view
the submitted jobs files.  You may be surprised to find that these
are not in what you would expect to call a printable format.
You can use the UNIX 'file' utitily to determine what the job
format actually is:
</para>

<para><programlisting>
    cd /var/spool/lpd/printer   # spool directory of print jobs
    ls                          # find job files
    file dfA001myhost
</programlisting></para>

<para>
You should make sure that your printer supports this format OR that
your system administrator has installed a 'print filter' that will
convert the file to a format appropriate for your printer.
</para>

</sect1>

<sect1>
<title>Job sent, strange output</title>

<para>
Once you have the job printing, you can then start worrying about
making it print nicely.
</para>

<para>
The most common problem is extra pages of output: banner pages
OR blank pages at the end.
</para>

<para>
If you are getting banner pages,  check and make sure that the
printcap option or printer option is configured for no banners.
If you have a printcap,  this is the :sh (suppress header or banner
page) option.  You should have the following in your printer.
</para>

<para><programlisting>
   printer: ... :sh
</programlisting></para>

<para>
If you have this option and are still getting banner pages,  there
is a strong chance that your printer is generating them for you
automatically.  You should make sure that banner printing is disabled
for the printer.  This usually requires using the printer setup software
or procedures supplied by the printer manufacturer.
</para>

<para>
If you get an extra page of output,  this could be due to problems
with your job format,  or if you are generating PostScript jobs,
incorrect setting on your printer driver on the MicroSoft client.
For example, under Win95 there is a option:
</para>

<para><programlisting>
  Printers|Printer Name|(Right Click)Properties|Postscript|Advanced|
</programlisting></para>

<para>
that allows you to choose if a Ctrl-D is appended to all jobs.
This is a very bad thing to do, as most spooling systems will
automatically add a ^D to the end of the job if it is detected as
PostScript.  The multiple ^D may cause an additional page of output.
</para>

</sect1>

<sect1>
<title>Raw PostScript printed</title>

<para>
This is a problem that is usually caused by either the print spooling
system putting information at the start of the print job that makes
the printer think the job is a text file, or your printer simply
does not support PostScript.  You may need to enable 'Automatic
Format Detection' on your printer.
</para>

</sect1>

<sect1>
<title>Advanced Printing</title>

<para>
Note that you can do some pretty magic things by using your
imagination with the "print command" option and some shell scripts.
Doing print accounting is easy by passing the %U option to a print
command shell script. You could even make the print command detect
the type of output and its size and send it to an appropriate
printer.
</para>

</sect1>

<sect1>
<title>Real debugging</title>

<para>
If the above debug tips don't help, then maybe you need to bring in
the bug guns, system tracing. See Tracing.txt in this directory.
</para>
</sect1>
</chaptor>
architecture.sgml (text/plain, 6.1 KB)
<chaptor id="architecture">
<chaptorinfo>
	<author>
		<firstname>Dan</firstname><surname>Shearer</surname>
	</author>
	<pubname> November 1997</pubname>
</chaptorinfo>

<title>Samba Architecture</title>

<sect1>
<title>Introduction</title>

<para>
This document gives a general overview of how Samba works
internally. The Samba Team has tried to come up with a model which is
the best possible compromise between elegance, portability, security
and the constraints imposed by the very messy SMB and CIFS
protocol. 
</para>

<para>
It also tries to answer some of the frequently asked questions such as:
</para>

<orderedlist>
<listitem><para>
	Is Samba secure when running on Unix? The xyz platform?
	What about the root priveliges issue?
</para></listitem>

<listitem><para>Pros and cons of multithreading in various parts of Samba</para></listitem>

<listitem><para>Why not have a separate process for name resolution, WINS, and browsing?</para></listitem>

</orderedlist>

</sect1>

<sect1>
<title>Multithreading and Samba</title>

<para>
People sometimes tout threads as a uniformly good thing. They are very
nice in their place but are quite inappropriate for smbd. nmbd is
another matter, and multi-threading it would be very nice. 
</para>

<para>
The short version is that smbd is not multithreaded, and alternative
servers that take this approach under Unix (such as Syntax, at the
time of writing) suffer tremendous performance penalties and are less
robust. nmbd is not threaded either, but this is because it is not
possible to do it while keeping code consistent and portable across 35
or more platforms. (This drawback also applies to threading smbd.)
</para>

<para>
The longer versions is that there are very good reasons for not making
smbd multi-threaded.  Multi-threading would actually make Samba much
slower, less scalable, less portable and much less robust. The fact
that we use a separate process for each connection is one of Samba's
biggest advantages.
</para>

</sect1>

<sect1>
<title>Threading smbd</title>

<para>
A few problems that would arise from a threaded smbd are:
</para>

<orderedlist>
<listitem><para>
	It's not only to create threads instead of processes, but you
	must care about all variables if they have to be thread specific
	(currently they would be global).
</para></listitem>

<listitem><para>
	if one thread dies (eg. a seg fault) then all threads die. We can
	immediately throw robustness out the window.
</para></listitem>

<listitem><para>
	many of the system calls we make are blocking. Non-blocking
	equivalents of many calls are either not available or are awkward (and
	slow) to use. So while we block in one thread all clients are
	waiting. Imagine if one share is a slow NFS filesystem and the others 
	are fast, we will end up slowing all clients to the speed of NFS.
</para></listitem>

<listitem><para>
	you can't run as a different uid in different threads. This means
	we would have to switch uid/gid on _every_ SMB packet. It would be
	horrendously slow.
</para></listitem>

<listitem><para>
	the per process file descriptor limit would mean that we could only
	support a limited number of clients.
</para></listitem>

<listitem><para>
	we couldn't use the system locking calls as the locking context of
	fcntl() is a process, not a thread.
</para></listitem>

</sect1>

<sect1>
<title>Threading nmbd</title>

<para>
This would be ideal, but gets sunk by portability requirements.
</para>

<para>
Andrew tried to write a test threads library for nmbd that used only
ansi-C constructs (using setjmp and longjmp). Unfortunately some OSes
defeat this by restricting longjmp to calling addresses that are
shallower than the current address on the stack (apparently AIX does
this). This makes a truly portable threads library impossible. So to
support all our current platforms we would have to code nmbd both with
and without threads, and as the real aim of threads is to make the
code clearer we would not have gained anything. (it is a myth that
threads make things faster. threading is like recursion, it can make
things clear but the same thing can always be done faster by some
other method)
</para>

<para>
Chris tried to spec out a general design that would abstract threading
vs separate processes (vs other methods?) and make them accessible
through some general API. This doesn't work because of the data
sharing requirements of the protocol (packets in the future depending
on packets now, etc.) At least, the code would work but would be very
clumsy, and besides the fork() type model would never work on Unix. (Is there an OS that it would work on, for nmbd?)
</para>

<para>
A fork() is cheap, but not nearly cheap enough to do on every UDP
packet that arrives. Having a pool of processes is possible but is
nasty to program cleanly due to the enormous amount of shared data (in
complex structures) between the processes. We can't rely on each
platform having a shared memory system.
</para>

</sect1>

<sect1>
<title>nbmd Design</title>

<para>
Originally Andrew used recursion to simulate a multi-threaded
environment, which use the stack enormously and made for really
confusing debugging sessions. Luke Leighton rewrote it to use a
queuing system that keeps state information on each packet.  The
first version used a single structure which was used by all the
pending states.  As the initialisation of this structure was
done by adding arguments, as the functionality developed, it got
pretty messy.  So, it was replaced with a higher-order function
and a pointer to a user-defined memory block.  This suddenly
made things much simpler: large numbers of functions could be
made static, and modularised.  This is the same principle as used
in NT's kernel, and achieves the same effect as threads, but in
a single process.
</para>

<para>
Then Jeremy rewrote nmbd. The packet data in nmbd isn't what's on the
wire. It's a nice format that is very amenable to processing but still
keeps the idea of a distinct packet. See "struct packet_struct" in
nameserv.h.  It has all the detail but none of the on-the-wire
mess. This makes it ideal for using in disk or memory-based databases
for browsing and WINS support. 
</para>

</sect1>
</chaptor>
debug.sgml (text/plain, 8.7 KB)
<chaptor id="parsing">
<chaptorinfo>
	<author>
		<firstname>Chris</firstname><surname>Hertel</surname>
	</author>
	<pubdate>July 1998</pubdate>
</chaptorinfo>

<title>The samba DEBUG system</title>

<sect1>
<title>New Output Syntax</title>

<para>
   The syntax of a debugging log file is represented as:
</para>

<para><programlisting>
  &gt;debugfile&lt; :== { &gt;debugmsg&lt; }

  &gt;debugmsg&lt;  :== &gt;debughdr&lt; '\n' &gt;debugtext&lt;

  &gt;debughdr&lt;  :== '[' TIME ',' LEVEL ']' FILE ':' [FUNCTION] '(' LINE ')'

  &gt;debugtext&lt; :== { &gt;debugline&lt; }

  &gt;debugline&lt; :== TEXT '\n'
</programlisting>

<para>
TEXT is a string of characters excluding the newline character.
</para>

<para>
LEVEL is the DEBUG level of the message (an integer in the range
		0..10).
</para>

<para>
TIME is a timestamp.
</para>

<para>
FILE is the name of the file from which the debug message was
generated.
</para>

<para>
FUNCTION is the function from which the debug message was generated.
</para>

<para>
LINE is the line number of the debug statement that generated the
message.
</para<

<para>Basically, what that all means is:</para>
<orderedlist>
<listitem><para>
A debugging log file is made up of debug messages.
</para></listitem>
<listitem><para>
Each debug message is made up of a header and text. The header is
separated from the text by a newline.
</para></listitem>
<listitem><para>
The header begins with the timestamp and debug level of the
message enclosed in brackets. The filename, function, and line
number at which the message was generated follow. The filename is
terminated by a colon, and the function name is terminated by the
parenthesis which contain the line number. Depending upon the
compiler, the function name may be missing (it is generated by the
__FUNCTION__ macro, which is not universally implemented, dangit).
</para></listitem>
<listitem><para>
The message text is made up of zero or more lines, each terminated
by a newline.
</para></listitem>
</orderedlist>

<para>Here's some example output:</para>

<para><programlisting>

    [1998/08/03 12:55:25, 1] nmbd.c:(659)
      Netbios nameserver version 1.9.19-prealpha started.
      Copyright Andrew Tridgell 1994-1997
    [1998/08/03 12:55:25, 3] loadparm.c:(763)
      Initializing global parameters
</programlisting></para>

<para>
Note that in the above example the function names are not listed on
the header line. That's because the example above was generated on an
SGI Indy, and the SGI compiler doesn't support the __FUNCTION__ macro.
</para>

<sect2>
<title>The DEBUG() Macro</title>

<para>
Use of the DEBUG() macro is unchanged. DEBUG() takes two parameters.
The first is the message level, the second is the body of a function
call to the Debug1() function.
</para>

<para>That's confusing.</para>

<para>Here's an example which may help a bit. If you would write</para>

<para><programlisting>
printf( "This is a %s message.\n", "debug" );
</programlisting></para>

<para>
to send the output to stdout, then you would write
</para>

<para><programlisting>
DEBUG( 0, ( "This is a %s message.\n", "debug" ) );
</programlisting></para>

<para>
to send the output to the debug file.  All of the normal printf()
formatting escapes work.
</para>

<para>
Note that in the above example the DEBUG message level is set to 0.
Messages at level 0 always print.  Basically, if the message level is
less than or equal to the global value DEBUGLEVEL, then the DEBUG
statement is processed.
</para>

<para>
The output of the above example would be something like:
</para>

<para><programlisting>
    [1998/07/30 16:00:51, 0] file.c:function(128)
      This is a debug message.
</programlisting></para>

<para>
Each call to DEBUG() creates a new header *unless* the output produced
by the previous call to DEBUG() did not end with a '\n'. Output to the
debug file is passed through a formatting buffer which is flushed
every time a newline is encountered. If the buffer is not empty when
DEBUG() is called, the new input is simply appended.
</para>

<para>
...but that's really just a Kludge. It was put in place because
DEBUG() has been used to write partial lines. Here's a simple (dumb)
example of the kind of thing I'm talking about:
</para>

<para><programlisting>
    DEBUG( 0, ("The test returned " ) );
    if( test() )
      DEBUG(0, ("True") );
    else
      DEBUG(0, ("False") );
    DEBUG(0, (".\n") );
</programlisting></para>

<para>
Without the format buffer, the output (assuming test() returned true)
would look like this:
</para>

<para><programlisting>
    [1998/07/30 16:00:51, 0] file.c:function(256)
      The test returned
    [1998/07/30 16:00:51, 0] file.c:function(258)
      True
    [1998/07/30 16:00:51, 0] file.c:function(261)
      .
</programlisting></para>

<para>Which isn't much use. The format buffer kludge fixes this problem.
</para>

</sect2>

<sect2>
<title>The DEBUGADD() Macro</title>

<para>
In addition to the kludgey solution to the broken line problem
described above, there is a clean solution. The DEBUGADD() macro never
generates a header. It will append new text to the current debug
message even if the format buffer is empty. The syntax of the
DEBUGADD() macro is the same as that of the DEBUG() macro.
</para>

<para><programlisting>
    DEBUG( 0, ("This is the first line.\n" ) );
    DEBUGADD( 0, ("This is the second line.\nThis is the third line.\n" ) );
</programlisting></para>

<para>Produces</para>

<para><programlisting>
    [1998/07/30 16:00:51, 0] file.c:function(512)
      This is the first line.
      This is the second line.
      This is the third line.
</programlisting></para>

</sect2>

<sect2>
<title>The DEBUGLVL() Macro</title>

<para>
One of the problems with the DEBUG() macro was that DEBUG() lines
tended to get a bit long. Consider this example from
nmbd_sendannounce.c:
</para>

<para><programlisting>
  DEBUG(3,("send_local_master_announcement: type %x for name %s on subnet %s for workgroup %s\n",
            type, global_myname, subrec->subnet_name, work->work_group));
</programlisting></para>

<para>
One solution to this is to break it down using DEBUG() and DEBUGADD(),
as follows:
</para>

<para><programlisting>
  DEBUG( 3, ( "send_local_master_announcement: " ) );
  DEBUGADD( 3, ( "type %x for name %s ", type, global_myname ) );
  DEBUGADD( 3, ( "on subnet %s ", subrec->subnet_name ) );
  DEBUGADD( 3, ( "for workgroup %s\n", work->work_group ) );
</programlisting></para>

<para>
A similar, but arguably nicer approach is to use the DEBUGLVL() macro.
This macro returns True if the message level is less than or equal to
the global DEBUGLEVEL value, so:
</para>

<para><programlisting>
  if( DEBUGLVL( 3 ) )
    {
    dbgtext( "send_local_master_announcement: " );
    dbgtext( "type %x for name %s ", type, global_myname );
    dbgtext( "on subnet %s ", subrec->subnet_name );
    dbgtext( "for workgroup %s\n", work->work_group );
    }
</programlisting></para>

<para>(The dbgtext() function is explained below.)</para>

<para>There are a few advantages to this scheme:</para>
<orderedlist>
<listitem><para>
The test is performed only once.
</para></listitem>
<listitem><para>
You can allocate variables off of the stack that will only be used
within the DEBUGLVL() block.
</para></listitem>
<listitem><para>
Processing that is only relevant to debug output can be contained
within the DEBUGLVL() block.
</para></listitem>
</orderedlist>

</sect2>

<sect2>
<title>New Functions</title>

<sect3>
<title>dbgtext()</title>
<para>
This function prints debug message text to the debug file (and
possibly to syslog) via the format buffer. The function uses a
variable argument list just like printf() or Debug1(). The
input is printed into a buffer using the vslprintf() function,
and then passed to format_debug_text().

If you use DEBUGLVL() you will probably print the body of the
message using dbgtext(). 
</para>
</sect3>

<sect3>
<title>dbghdr()</title>
<para>
This is the function that writes a debug message header.
Headers are not processed via the format buffer. Also note that
if the format buffer is not empty, a call to dbghdr() will not
produce any output. See the comments in dbghdr() for more info.
</para>

<para>
It is not likely that this function will be called directly. It
is used by DEBUG() and DEBUGADD().
</para>
</sect3>

<sect3>
<title>format_debug_text()</title>
<para>
This is a static function in debug.c. It stores the output text
for the body of the message in a buffer until it encounters a
newline. When the newline character is found, the buffer is
written to the debug file via the Debug1() function, and the
buffer is reset. This allows us to add the indentation at the
beginning of each line of the message body, and also ensures
that the output is written a line at a time (which cleans up
syslog output).
</para>
</sect3>
</sect2>
</sect1>
</chaptor>
debug.sgml (text/plain, 8.7 KB)
<chaptor id="parsing">
<chaptorinfo>
	<author>
		<firstname>Chris</firstname><surname>Hertel</surname>
	</author>
	<pubdate>July 1998</pubdate>
</chaptorinfo>

<title>The samba DEBUG system</title>

<sect1>
<title>New Output Syntax</title>

<para>
   The syntax of a debugging log file is represented as:
</para>

<para><programlisting>
  &gt;debugfile&lt; :== { &gt;debugmsg&lt; }

  &gt;debugmsg&lt;  :== &gt;debughdr&lt; '\n' &gt;debugtext&lt;

  &gt;debughdr&lt;  :== '[' TIME ',' LEVEL ']' FILE ':' [FUNCTION] '(' LINE ')'

  &gt;debugtext&lt; :== { &gt;debugline&lt; }

  &gt;debugline&lt; :== TEXT '\n'
</programlisting>

<para>
TEXT is a string of characters excluding the newline character.
</para>

<para>
LEVEL is the DEBUG level of the message (an integer in the range
		0..10).
</para>

<para>
TIME is a timestamp.
</para>

<para>
FILE is the name of the file from which the debug message was
generated.
</para>

<para>
FUNCTION is the function from which the debug message was generated.
</para>

<para>
LINE is the line number of the debug statement that generated the
message.
</para<

<para>Basically, what that all means is:</para>
<orderedlist>
<listitem><para>
A debugging log file is made up of debug messages.
</para></listitem>
<listitem><para>
Each debug message is made up of a header and text. The header is
separated from the text by a newline.
</para></listitem>
<listitem><para>
The header begins with the timestamp and debug level of the
message enclosed in brackets. The filename, function, and line
number at which the message was generated follow. The filename is
terminated by a colon, and the function name is terminated by the
parenthesis which contain the line number. Depending upon the
compiler, the function name may be missing (it is generated by the
__FUNCTION__ macro, which is not universally implemented, dangit).
</para></listitem>
<listitem><para>
The message text is made up of zero or more lines, each terminated
by a newline.
</para></listitem>
</orderedlist>

<para>Here's some example output:</para>

<para><programlisting>

    [1998/08/03 12:55:25, 1] nmbd.c:(659)
      Netbios nameserver version 1.9.19-prealpha started.
      Copyright Andrew Tridgell 1994-1997
    [1998/08/03 12:55:25, 3] loadparm.c:(763)
      Initializing global parameters
</programlisting></para>

<para>
Note that in the above example the function names are not listed on
the header line. That's because the example above was generated on an
SGI Indy, and the SGI compiler doesn't support the __FUNCTION__ macro.
</para>

<sect2>
<title>The DEBUG() Macro</title>

<para>
Use of the DEBUG() macro is unchanged. DEBUG() takes two parameters.
The first is the message level, the second is the body of a function
call to the Debug1() function.
</para>

<para>That's confusing.</para>

<para>Here's an example which may help a bit. If you would write</para>

<para><programlisting>
printf( "This is a %s message.\n", "debug" );
</programlisting></para>

<para>
to send the output to stdout, then you would write
</para>

<para><programlisting>
DEBUG( 0, ( "This is a %s message.\n", "debug" ) );
</programlisting></para>

<para>
to send the output to the debug file.  All of the normal printf()
formatting escapes work.
</para>

<para>
Note that in the above example the DEBUG message level is set to 0.
Messages at level 0 always print.  Basically, if the message level is
less than or equal to the global value DEBUGLEVEL, then the DEBUG
statement is processed.
</para>

<para>
The output of the above example would be something like:
</para>

<para><programlisting>
    [1998/07/30 16:00:51, 0] file.c:function(128)
      This is a debug message.
</programlisting></para>

<para>
Each call to DEBUG() creates a new header *unless* the output produced
by the previous call to DEBUG() did not end with a '\n'. Output to the
debug file is passed through a formatting buffer which is flushed
every time a newline is encountered. If the buffer is not empty when
DEBUG() is called, the new input is simply appended.
</para>

<para>
...but that's really just a Kludge. It was put in place because
DEBUG() has been used to write partial lines. Here's a simple (dumb)
example of the kind of thing I'm talking about:
</para>

<para><programlisting>
    DEBUG( 0, ("The test returned " ) );
    if( test() )
      DEBUG(0, ("True") );
    else
      DEBUG(0, ("False") );
    DEBUG(0, (".\n") );
</programlisting></para>

<para>
Without the format buffer, the output (assuming test() returned true)
would look like this:
</para>

<para><programlisting>
    [1998/07/30 16:00:51, 0] file.c:function(256)
      The test returned
    [1998/07/30 16:00:51, 0] file.c:function(258)
      True
    [1998/07/30 16:00:51, 0] file.c:function(261)
      .
</programlisting></para>

<para>Which isn't much use. The format buffer kludge fixes this problem.
</para>

</sect2>

<sect2>
<title>The DEBUGADD() Macro</title>

<para>
In addition to the kludgey solution to the broken line problem
described above, there is a clean solution. The DEBUGADD() macro never
generates a header. It will append new text to the current debug
message even if the format buffer is empty. The syntax of the
DEBUGADD() macro is the same as that of the DEBUG() macro.
</para>

<para><programlisting>
    DEBUG( 0, ("This is the first line.\n" ) );
    DEBUGADD( 0, ("This is the second line.\nThis is the third line.\n" ) );
</programlisting></para>

<para>Produces</para>

<para><programlisting>
    [1998/07/30 16:00:51, 0] file.c:function(512)
      This is the first line.
      This is the second line.
      This is the third line.
</programlisting></para>

</sect2>

<sect2>
<title>The DEBUGLVL() Macro</title>

<para>
One of the problems with the DEBUG() macro was that DEBUG() lines
tended to get a bit long. Consider this example from
nmbd_sendannounce.c:
</para>

<para><programlisting>
  DEBUG(3,("send_local_master_announcement: type %x for name %s on subnet %s for workgroup %s\n",
            type, global_myname, subrec->subnet_name, work->work_group));
</programlisting></para>

<para>
One solution to this is to break it down using DEBUG() and DEBUGADD(),
as follows:
</para>

<para><programlisting>
  DEBUG( 3, ( "send_local_master_announcement: " ) );
  DEBUGADD( 3, ( "type %x for name %s ", type, global_myname ) );
  DEBUGADD( 3, ( "on subnet %s ", subrec->subnet_name ) );
  DEBUGADD( 3, ( "for workgroup %s\n", work->work_group ) );
</programlisting></para>

<para>
A similar, but arguably nicer approach is to use the DEBUGLVL() macro.
This macro returns True if the message level is less than or equal to
the global DEBUGLEVEL value, so:
</para>

<para><programlisting>
  if( DEBUGLVL( 3 ) )
    {
    dbgtext( "send_local_master_announcement: " );
    dbgtext( "type %x for name %s ", type, global_myname );
    dbgtext( "on subnet %s ", subrec->subnet_name );
    dbgtext( "for workgroup %s\n", work->work_group );
    }
</programlisting></para>

<para>(The dbgtext() function is explained below.)</para>

<para>There are a few advantages to this scheme:</para>
<orderedlist>
<listitem><para>
The test is performed only once.
</para></listitem>
<listitem><para>
You can allocate variables off of the stack that will only be used
within the DEBUGLVL() block.
</para></listitem>
<listitem><para>
Processing that is only relevant to debug output can be contained
within the DEBUGLVL() block.
</para></listitem>
</orderedlist>

</sect2>

<sect2>
<title>New Functions</title>

<sect3>
<title>dbgtext()</title>
<para>
This function prints debug message text to the debug file (and
possibly to syslog) via the format buffer. The function uses a
variable argument list just like printf() or Debug1(). The
input is printed into a buffer using the vslprintf() function,
and then passed to format_debug_text().

If you use DEBUGLVL() you will probably print the body of the
message using dbgtext(). 
</para>
</sect3>

<sect3>
<title>dbghdr()</title>
<para>
This is the function that writes a debug message header.
Headers are not processed via the format buffer. Also note that
if the format buffer is not empty, a call to dbghdr() will not
produce any output. See the comments in dbghdr() for more info.
</para>

<para>
It is not likely that this function will be called directly. It
is used by DEBUG() and DEBUGADD().
</para>
</sect3>

<sect3>
<title>format_debug_text()</title>
<para>
This is a static function in debug.c. It stores the output text
for the body of the message in a buffer until it encounters a
newline. When the newline character is found, the buffer is
written to the debug file via the Debug1() function, and the
buffer is reset. This allows us to add the indentation at the
beginning of each line of the message body, and also ensures
that the output is written a line at a time (which cleans up
syslog output).
</para>
</sect3>
</sect2>
</sect1>
</chaptor>
internals.sgml (text/plain, 12.6 KB)
<chaptor id="internals">
<chaptorinfo>
	<author>
		<firstname>David</firstname><surname>Chappell</surname>
		<affiliate>
			<address><email>[email protected]</email></address>
		</affiliate>
	</author>
	<pubdate>8 May 1996</pubdate>
</chaptorinfo>

<title>Samba Internals</title>

<sect1>
<title>Character Handling</title>
<para>
This section describes character set handling in Samba, as implemented in
Samba 3.0 and above
</para>

<para>
In the past Samba had very ad-hoc character set handling. Scattered
throughout the code were numerous calls which converted particular
strings to/from DOS codepages. The problem is that there was no way of
telling if a particular char* is in dos codepage or unix
codepage. This led to a nightmare of code that tried to cope with
particular cases without handlingt the general case.
</para>

<sect1>
<title>The new functions</title>

<para>
The new system works like this:
</para>

<orderedlist>
<listitem><para>
	all char* strings inside Samba are "unix" strings. These are
	multi-byte strings that are in the charset defined by the "unix
	charset" option in smb.conf. 
</para></listitem>

<listitem><para>
	there is no single fixed character set for unix strings, but any
	character set that is used does need the following properties:
	</para>
	<orderedlist>
	
	<listitem><para>
		must not contain NULLs except for termination
	</para></listitem>

	<listitem><para>
		must be 7-bit compatible with C strings, so that a constant
		string or character in C will be byte-for-byte identical to the
		equivalent string in the chosen character set. 
	</para></listitem>
	
	<listitem><para>
		when you uppercase or lowercase a string it does not become
		longer than the original string
	</para></listitem>

	<listitem><para>
		must be able to correctly hold all characters that your client
		will throw at it
	</para></listitem>
	</orderedlist>
	
	<para>
	For example, UTF-8 is fine, and most multi-byte asian character sets
	are fine, but UCS2 could not be used for unix strings as they
	contain nulls.
	</para>
</listitem>

<listitem><para>
	when you need to put a string into a buffer that will be sent on the
	wire, or you need a string in a character set format that is
	compatible with the clients character set then you need to use a
	pull_ or push_ function. The pull_ functions pull a string from a
	wire buffer into a (multi-byte) unix string. The push_ functions
	push a string out to a wire buffer. 
</para></listitem>

<listitem><para>
	the two main pull_ and push_ functions you need to understand are
	pull_string and push_string. These functions take a base pointer
	that should point at the start of the SMB packet that the string is
	in. The functions will check the flags field in this packet to
	automatically determine if the packet is marked as a unicode packet,
	and they will choose whether to use unicode for this string based on
	that flag. You may also force this decision using the STR_UNICODE or
	STR_ASCII flags. For use in smbd/ and libsmb/ there are wrapper
	functions clistr_ and srvstr_ that call the pull_/push_ functions
	with the appropriate first argument.
	</para>
	
	<para>
	You may also call the pull_ascii/pull_ucs2 or push_ascii/push_ucs2
	functions if you know that a particular string is ascii or
	unicode. There are also a number of other convenience functions in
	charcnv.c that call the pull_/push_ functions with particularly
	common arguments, such as pull_ascii_pstring()
	</para>
</listitem>

<listitem><para>
	The biggest thing to remember is that internal (unix) strings in Samba
	may now contain multi-byte characters. This means you cannot assume
	that characters are always 1 byte long. Often this means that you will
	have to convert strings to ucs2 and back again in order to do some
	(seemingly) simple task. For examples of how to do this see functions
	like strchr_m(). I know this is very slow, and we will eventually
	speed it up but right now we want this stuff correct not fast.
</para></listitem>

<listitem><para>
	all lp_ functions now return unix strings. The magic "DOS" flag on
	parameters is gone.
</para></listitem>

<listitem><para>
	all vfs functions take unix strings. Don't convert when passing to them
</para></listitem>

</orderedlist>

</sect1>

<sect1>
<title>Macros in byteorder.h</title>

<para>
This section describes the macros defined in byteorder.h.  These macros 
are used extensively in the Samba code.
</para>

<sect2>
<title>CVAL(buf,pos)</title>

<para>
returns the byte at offset pos within buffer buf as an unsigned character.
</para>
</sect2>

<sect2>
<title>PVAL(buf,pos)</title>
<para>returns the value of CVAL(buf,pos) cast to type unsigned integer.</para>
</sect2>

<sect2>
<title>SCVAL(buf,pos,val)</title>
<para>sets the byte at offset pos within buffer buf to value val.</para>
</sect2>

<sect2>
<title>SVAL(buf,pos)</title>
<para>
	returns the value of the unsigned short (16 bit) little-endian integer at 
	offset pos within buffer buf.  An integer of this type is sometimes
	refered to as "USHORT".
</para>
</sect2>

<sect2>
<title>IVAL(buf,pos)</title>
<para>returns the value of the unsigned 32 bit little-endian integer at offset 
pos within buffer buf.</para>
</sect2>

<sect2>
<title>SVALS(buf,pos)</title>
<para>returns the value of the signed short (16 bit) little-endian integer at 
offset pos within buffer buf.</para>
</sect2>

<sect2>
<title>IVALS(buf,pos)</title>
<para>returns the value of the signed 32 bit little-endian integer at offset pos
within buffer buf.</para>
</sect2>

<sect2>
<title>SSVAL(buf,pos,val)</title>
<para>sets the unsigned short (16 bit) little-endian integer at offset pos within 
buffer buf to value val.</para>
</sect2>

<sect2>
<title>SIVAL(buf,pos,val)</title>
<para>sets the unsigned 32 bit little-endian integer at offset pos within buffer 
buf to the value val.</para>
</sect2>

<sect2>
<title>SSVALS(buf,pos,val)</title>
<para>sets the short (16 bit) signed little-endian integer at offset pos within 
buffer buf to the value val.</para>
</sect2>

<sect2>
<title>SIVALS(buf,pos,val)</title>
<para>sets the signed 32 bit little-endian integer at offset pos withing buffer
buf to the value val.</para>
</sect2>

<sect2>
<title>RSVAL(buf,pos)</title>
<para>returns the value of the unsigned short (16 bit) big-endian integer at 
offset pos within buffer buf.</para>
</sect2>

<sect2>
<title>RIVAL(buf,pos)</title>
<para>returns the value of the unsigned 32 bit big-endian integer at offset 
pos within buffer buf.</para>
</sect2>

<sect2>
<title>RSSVAL(buf,pos,val)</title>
<para>sets the value of the unsigned short (16 bit) big-endian integer at 
offset pos within buffer buf to value val.
refered to as "USHORT".</para>
</sect2>

<sect2>
<title>RSIVAL(buf,pos,val)</title>
<para>sets the value of the unsigned 32 bit big-endian integer at offset 
pos within buffer buf to value val.</para>
</sect2>

</sect1>


<sect1>
<title>LAN Manager Samba API</title>

<para>
This section describes the functions need to make a LAN Manager RPC call.
This information had been obtained by examining the Samba code and the LAN
Manager 2.0 API documentation.  It should not be considered entirely
reliable.
</para>

<para>
<programlisting>
call_api(int prcnt, int drcnt, int mprcnt, int mdrcnt, 
	char *param, char *data, char **rparam, char **rdata);
</programlisting>
</para>

<para>
This function is defined in client.c.  It uses an SMB transaction to call a
remote api.
</para>

<sect2>
<title>Parameters</title>

<para>The parameters are as follows:

<orderedlist>
<listitem><para>
	prcnt: the number of bytes of parameters begin sent.
</para></listitem>
<listitem><para>
	drcnt:   the number of bytes of data begin sent.
</para></listitem>
<listitem><para>
	mprcnt:  the maximum number of bytes of parameters which should be returned
</para></listitem>
<listitem><para>
	mdrcnt:  the maximum number of bytes of data which should be returned
</para></listitem>
<listitem><para>
	param:   a pointer to the parameters to be sent.
</para></listitem>
<listitem><para>
	data:    a pointer to the data to be sent.
</para></listitem>
<listitem><para>
	rparam:  a pointer to a pointer which will be set to point to the returned
	paramters.  The caller of call_api() must deallocate this memory.
</para></listitem>
<listitem><para>
	rdata:   a pointer to a pointer which will be set to point to the returned 
	data.  The caller of call_api() must deallocate this memory.
</para></listitem>
</orderedlist>


<para>
These are the parameters which you ought to send, in the order of their
appearance in the parameter block:
</para>

<orderedlist>

<listitem><para>
An unsigned 16 bit integer API number.  You should set this value with
SSVAL().  I do not know where these numbers are described.
</para></listitem>

<listitem><para>
An ASCIIZ string describing the parameters to the API function as defined
in the LAN Manager documentation.  The first parameter, which is the server
name, is ommited.  This string is based uppon the API function as described
in the manual, not the data which is actually passed.
</para></listitem>

<listitem><para>
An ASCIIZ string describing the data structure which ought to be returned.
</para></listitem>

<listitem><para>
Any parameters which appear in the function call, as defined in the LAN
Manager API documentation, after the "Server" and up to and including the
"uLevel" parameters.
</para></listitem>

<listitem><para>
An unsigned 16 bit integer which gives the size in bytes of the buffer we
will use to receive the returned array of data structures.  Presumably this
should be the same as mdrcnt.  This value should be set with SSVAL().
</para></listitem>

<listitem><para>
An ASCIIZ string describing substructures which should be returned.  If no 
substructures apply, this string is of zero length.
</para></listitem>

</orderedlist>

<para>
The code in client.c always calls call_api() with no data.  It is unclear
when a non-zero length data buffer would be sent.
</para>

</sect2>

<sect2>
<title>Return value</title>

<para>
The returned parameters (pointed to by rparam), in their order of appearance
are:

<orderedlist>

<listitem><para>
An unsigned 16 bit integer which contains the API function's return code. 
This value should be read with SVAL().
</para></listitem>

<listitem><para>
An adjustment which tells the amount by which pointers in the returned
data should be adjusted.  This value should be read with SVAL().  Basically, 
the address of the start of the returned data buffer should have the returned
pointer value added to it and then have this value subtracted from it in
order to obtain the currect offset into the returned data buffer.
</para></listitem>

<listitem><para>
A count of the number of elements in the array of structures returned. 
It is also possible that this may sometimes be the number of bytes returned.
</para></listitem>
</orderedlist>

<para>
When call_api() returns, rparam points to the returned parameters.  The
first if these is the result code.  It will be zero if the API call
suceeded.  This value by be read with "SVAL(rparam,0)".
</para>

<para>
The second parameter may be read as "SVAL(rparam,2)".  It is a 16 bit offset
which indicates what the base address of the returned data buffer was when
it was built on the server.  It should be used to correct pointer before
use.
</para>

<para>
The returned data buffer contains the array of returned data structures. 
Note that all pointers must be adjusted before use.  The function
fix_char_ptr() in client.c can be used for this purpose.
</para>

<para>
The third parameter (which may be read as "SVAL(rparam,4)") has something to
do with indicating the amount of data returned or possibly the amount of
data which can be returned if enough buffer space is allowed.
</para>

</sect2>
</sect1>

<sect1>
<title>Code character table</title>
<para>
Certain data structures are described by means of ASCIIz strings containing
code characters.  These are the code characters:
</para>

<orderedlist>
<listitem><para>
W	a type byte little-endian unsigned integer
</para></listitem>
<listitem><para>
N	a count of substructures which follow
</para></listitem>
<listitem><para>
D	a four byte little-endian unsigned integer
</para></listitem>
<listitem><para>
B	a byte (with optional count expressed as trailing ASCII digits)
</para></listitem>
<listitem><para>
z	a four byte offset to a NULL terminated string
</para></listitem>
<listitem><para>
l	a four byte offset to non-string user data
</para></listitem>
<listitem><para>
b	an offset to data (with count expressed as trailing ASCII digits)
</para></listitem>
<listitem><para>
r	pointer to returned data buffer???
</para></listitem>
<listitem><para>
L	length in bytes of returned data buffer???
</para></listitem>
<listitem><para>
h	number of bytes of information available???
</para></listitem>
</orderedlist>

</sect1>
</chaptor>
parsing.sgml (text/plain, 5.8 KB)
<chaptor id="parsing">
<chaptorinfo>
	<author>
		<firstname>Chris</firstname><surname>Hertel</surname>
	</author>
	<pubdate>November 1997</pubdate>
</chaptorinfo>

<title>The smb.conf file</title>

<sect1>
<title>Lexical Analysis</title>

<para>
Basically, the file is processed on a line by line basis.  There are
four types of lines that are recognized by the lexical analyzer
(params.c):
</para>

<orderedlist>
<listitem><para>
Blank lines - Lines containing only whitespace.
</para></listitem>
<listitem><para>
Comment lines - Lines beginning with either a semi-colon or a
pound sign (';' or '#').
</para></listitem>
<listitem><para>
Section header lines - Lines beginning with an open square bracket ('[').
</para></listitem>
<listitem><para>
Parameter lines - Lines beginning with any other character.
(The default line type.)
</para></listitem>
</orderedlist>

<para>
The first two are handled exclusively by the lexical analyzer, which
ignores them.  The latter two line types are scanned for
</para>

<orderedlist>
<listitem><para>
  - Section names
</para></listitem>
<listitem><para>
  - Parameter names
</para></listitem>
<listitem><para>
  - Parameter values
</para></listitem>
</orderedlist>

<para>
These are the only tokens passed to the parameter loader
(loadparm.c).  Parameter names and values are divided from one
another by an equal sign: '='.
</para>

<sect2>
<title>Handling of Whitespace</title>

<para>
Whitespace is defined as all characters recognized by the isspace()
function (see ctype(3C)) except for the newline character ('\n')
The newline is excluded because it identifies the end of the line.
</para>

<orderedlist>
<listitem><para>
The lexical analyzer scans past white space at the beginning of a line.
</para></listitem>

<listitem><para>
Section and parameter names may contain internal white space.  All
whitespace within a name is compressed to a single space character. 
</para></listitem>

<listitem><para>
Internal whitespace within a parameter value is kept verbatim with 
the exception of carriage return characters ('\r'), all of which
are removed.
</para></listitem>

<listitem><para>
Leading and trailing whitespace is removed from names and values.
</para></listitem>

</orderedlist>

</sect2>

<sect2>
<title>Handling of Line Continuation</title>

<para>
Long section header and parameter lines may be extended across
multiple lines by use of the backslash character ('\\').  Line
continuation is ignored for blank and comment lines.
</para>

<para>
If the last (non-whitespace) character within a section header or on
a parameter line is a backslash, then the next line will be
(logically) concatonated with the current line by the lexical
analyzer.  For example:
</para>

<para><programlisting>
	param name = parameter value string \
	with line continuation.
</programlisting></para>

<para>Would be read as</para>

<para><programlisting>
    param name = parameter value string     with line continuation.
</programlisting></para>

<para>
Note that there are five spaces following the word 'string',
representing the one space between 'string' and '\\' in the top
line, plus the four preceeding the word 'with' in the second line.
(Yes, I'm counting the indentation.)
</para>

<para>
Line continuation characters are ignored on blank lines and at the end
of comments.  They are *only* recognized within section and parameter
lines.
</para>

</sect2>

<sect2>
<title>Line Continuation Quirks</title>

<para>Note the following example:</para>

<para><programlisting>
	param name = parameter value string \
    \
    with line continuation.
</programlisting></para>

<para>
The middle line is *not* parsed as a blank line because it is first
concatonated with the top line.  The result is
</para>

<para><programlisting>
param name = parameter value string         with line continuation.
</programlisting></para>

<para>The same is true for comment lines.</para>

<para><programlisting>
	param name = parameter value string \
	; comment \
    with a comment.
</programlisting></para>

<para>This becomes:</para>

<para><programlisting>
param name = parameter value string     ; comment     with a comment.
</programlisting></para>

<para>
On a section header line, the closing bracket (']') is considered a
terminating character, and the rest of the line is ignored.  The lines
</para>

<para><programlisting>
	[ section   name ] garbage \
    param  name  = value
</programlisting></para>

<para>are read as</para>

<para><programlisting>
	[section name]
    param name = value
</programlisting></para<

</sect2>
</sect1>

<sect1>
<title>Syntax</title>

<para>The syntax of the smb.conf file is as follows:</para>

<para><programlisting>
  <file>            :==  { <section> } EOF
  <section>         :==  <section header> { <parameter line> }
  <section header>  :==  '[' NAME ']'
  <parameter line>  :==  NAME '=' VALUE NL
</programlisting><para>

<para>Basically, this means that</para>

<orderedlist>
<listitem><para>
	a file is made up of zero or more sections, and is terminated by
	an EOF (we knew that).
</para></listitem>

<listitem><para>
	A section is made up of a section header followed by zero or more
	parameter lines.
</para></listitem>

<listitem><para>
	A section header is identified by an opening bracket and
	terminated by the closing bracket.  The enclosed NAME identifies
	the section.
</para></programlisting>

<listitem><para>
	A parameter line is divided into a NAME and a VALUE.  The *first*
	equal sign on the line separates the NAME from the VALUE.  The
	VALUE is terminated by a newline character (NL = '\n').
</para></programlisting>

</orderedlist>

</sect2>
<title>About params.c</title>

<para>
The parsing of the config file is a bit unusual if you are used to
lex, yacc, bison, etc.  Both lexical analysis (scanning) and parsing
are performed by params.c.  Values are loaded via callbacks to
loadparm.c.
</para>
</sect2>
</sect1>
</chaptor>
security_level.sgml (text/plain, 5.5 KB)
<chapter id="security_levels">
<chapterinfo>
	<author>
		<firstname>Andrew</firstname><surname>Tridgell</surname>
		<affiliate>
			<orgname>Samba Team</orgname>
			<address><email>[email protected]</email></address>
		</affiliate>
	</author>
</chapterinfo>

<title>Security levels</title>

<sect1>
<title>Introduction</title>

<para>
Samba supports the following options to the global smb.conf parameter
"security =":
	share, user, server
</para>

<para>
Note: Samba-2.0.0 now adds the "domain" security mode. Please refer to
the smb.conf man page for usage information and to the document
<filename>docs/textdocs/DOMAIN_MEMBER.txt</filename>
for further background details.
</para>

<para>
Of the above, "security = server" means that Samba reports to clients that
it is running in "user mode" but actually passes off all authentication
requests to another "user mode" server. This requires an additional
parameter "password server =" that points to the real authentication server.
That real authentication server can be another Samba server or can be a
Windows NT server, the later natively capable of encrypted password support.
</para>

</sect1>

<sect1>
<title>More complete description of security levels</title>

<para>
A SMB server tells the client at startup what "security level" it is
running. There are two options "share level" and "user level". Which
of these two the client receives affects the way the client then tries
to authenticate itself. It does not directly affect (to any great
extent) the way the Samba server does security. I know this is
strange, but it fits in with the client/server approach of SMB. In SMB
everything is initiated and controlled by the client, and the server
can only tell the client what is available and whether an action is
allowed. 
</para>

<para>
I'll describe user level security first, as its simpler. In user level
security the client will send a "session setup" command directly after
the protocol negotiation. This contains a username and password. The
server can either accept or reject that username/password
combination. Note that at this stage the server has no idea what
share the client will eventually try to connect to, so it can't base
the "accept/reject" on anything other than:
</para>

<orderedlist>
<listitem><para>the username/password</para></listitem>
<listitem><para>the machine that the client is coming from</para></listitem>
</orderedlist>

<para>
If the server accepts the username/password then the client expects to
be able to mount any share (using a "tree connection") without
specifying a password. It expects that all access rights will be as
the username/password specified in the "session setup". 
</para>

<para>
It is also possible for a client to send multiple "session setup"
requests. When the server responds it gives the client a "uid" to use
as an authentication tag for that username/password. The client can
maintain multiple authentication contexts in this way (WinDD is an
example of an application that does this)
</para>

<para>
Ok, now for share level security. In share level security the client
authenticates itself separately for each share. It will send a
password along with each "tree connection" (share mount). It does not
explicitly send a username with this operation. The client is
expecting a password to be associated with each share, independent of
the user. This means that samba has to work out what username the
client probably wants to use. It is never explicitly sent the
username. Some commercial SMB servers such as NT actually associate
passwords directly with shares in share level security, but samba
always uses the unix authentication scheme where it is a
username/password that is authenticated, not a "share/password".
</para>

<para>
Many clients send a "session setup" even if the server is in share
level security. They normally send a valid username but no
password. Samba records this username in a list of "possible
usernames". When the client then does a "tree connection" it also adds
to this list the name of the share they try to connect to (useful for
home directories) and any users listed in the "user =" smb.conf
line. The password is then checked in turn against these "possible
usernames". If a match is found then the client is authenticated as
that user.
</para>

<para>
Finally "server level" security. In server level security the samba
server reports to the client that it is in user level security. The
client then does a "session setup" as described earlier. The samba
server takes the username/password that the client sends and attempts
to login to the "password server" by sending exactly the same
username/password that it got from the client. If that server is in
user level security and accepts the password then samba accepts the
clients connection. This allows the samba server to use another SMB
server as the "password server". 
</para>

<para>
You should also note that at the very start of all this, where the
server tells the client what security level it is in, it also tells
the client if it supports encryption. If it does then it supplies the
client with a random "cryptkey". The client will then send all
passwords in encrypted form. You have to compile samba with encryption
enabled to support this feature, and you have to maintain a separate
smbpasswd file with SMB style encrypted passwords. It is
cryptographically impossible to translate from unix style encryption
to SMB style encryption, although there are some fairly simple management
schemes by which the two could be kept in sync.
</para>
</sect1>
</chaptor>
unix-smb.sgml (text/plain, 11 KB)
<chaptor id="unix-smb">
<chaptorinfo>
	<author>
		<firstname>Andrew</firstname><surname>Tridgell</surname>
	</author>
	<pubdate>April 1995</pubdate>
</chaptorinfo>

<title>NetBIOS in a Unix World</title>

<sect1>
<title>Introduction</title>
<para>
This is a short document that describes some of the issues that
confront a SMB implementation on unix, and how Samba copes with
them. They may help people who are looking at unix<->PC
interoperability.
</para>

<para>
It was written to help out a person who was writing a paper on unix to
PC connectivity.
</para>

</sect1>

<sect1>
<title>Usernames</title>
<para>
The SMB protocol has only a loose username concept. Early SMB
protocols (such as CORE and COREPLUS) have no username concept at
all. Even in later protocols clients often attempt operations
(particularly printer operations) without first validating a username
on the server.
</para>

<para>
Unix security is based around username/password pairs. A unix box
should not allow clients to do any substantive operation without some
sort of validation. 
</para>

<para>
The problem mostly manifests itself when the unix server is in "share
level" security mode. This is the default mode as the alternative
"user level" security mode usually forces a client to connect to the
server as the same user for each connected share, which is
inconvenient in many sites.
</para>

<para>
In "share level" security the client normally gives a username in the
"session setup" protocol, but does not supply an accompanying
password. The client then connects to resources using the "tree
connect" protocol, and supplies a password. The problem is that the
user on the PC types the username and the password in different
contexts, unaware that they need to go together to give access to the
server. The username is normally the one the user typed in when they
"logged onto" the PC (this assumes Windows for Workgroups). The
password is the one they chose when connecting to the disk or printer.
</para>

<para>
The user often chooses a totally different username for their login as
for the drive connection. Often they also want to access different
drives as different usernames. The unix server needs some way of
divining the correct username to combine with each password.
</para>

<para>
Samba tries to avoid this problem using several methods. These succeed
in the vast majority of cases. The methods include username maps, the
service%user syntax, the saving of session setup usernames for later
validation and the derivation of the username from the service name
(either directly or via the user= option).
</para>

</sect1>

<sect1>
<title>File Ownership</title>

<para>
The commonly used SMB protocols have no way of saying "you can't do
that because you don't own the file". They have, in fact, no concept
of file ownership at all.
</para>

<para>
This brings up all sorts of interesting problems. For example, when
you copy a file to a unix drive, and the file is world writeable but
owned by another user the file will transfer correctly but will
receive the wrong date. This is because the utime() call under unix
only succeeds for the owner of the file, or root, even if the file is
world writeable. For security reasons Samba does all file operations
as the validated user, not root, so the utime() fails. This can stuff
up shared development diectories as programs like "make" will not get
file time comparisons right.
</para>

<para>
There are several possible solutions to this problem, including
username mapping, and forcing a specific username for particular
shares.
</para>

</sect1>

<sect1>
<title>Passwords</title>

<para>
Many SMB clients uppercase passwords before sending them. I have no
idea why they do this. Interestingly WfWg uppercases the password only
if the server is running a protocol greater than COREPLUS, so
obviously it isn't just the data entry routines that are to blame.
</para>

<para>
Unix passwords are case sensitive. So if users use mixed case
passwords they are in trouble.
</para>

<para>
Samba can try to cope with this by either using the "password level"
option which causes Samba to try the offered password with up to the
specified number of case changes, or by using the "password server"
option which allows Samba to do its validation via another machine
(typically a WinNT server).
</para>

<para>
Samba supports the password encryption method used by SMB
clients. Note that the use of password encryption in Microsoft
networking leads to password hashes that are "plain text equivalent".
This means that it is *VERY* important to ensure that the Samba
smbpasswd file containing these password hashes is only readable
by the root user. See the documentation ENCRYPTION.txt for more
details.
</para>

</sect1>

<sect1>
<title>Locking</title>
<para>
The locking calls available under a DOS/Windows environment are much
richer than those available in unix. This means a unix server (like
Samba) choosing to use the standard fcntl() based unix locking calls
to implement SMB locking has to improvise a bit.
</para>

<para>
One major problem is that dos locks can be in a 32 bit (unsigned)
range. Unix locking calls are 32 bits, but are signed, giving only a 31
bit range. Unfortunately OLE2 clients use the top bit to select a
locking range used for OLE semaphores.
</para>

<para>
To work around this problem Samba compresses the 32 bit range into 31
bits by appropriate bit shifting. This seems to work but is not
ideal. In a future version a separate SMB lockd may be added to cope
with the problem.
</para>

<para>
It also doesn't help that many unix lockd daemons are very buggy and
crash at the slightest provocation. They normally go mostly unused in
a unix environment because few unix programs use byte range
locking. The stress of huge numbers of lock requests from dos/windows
clients can kill the daemon on some systems.
</para>

<para>
The second major problem is the "opportunistic locking" requested by
some clients. If a client requests opportunistic locking then it is
asking the server to notify it if anyone else tries to do something on
the same file, at which time the client will say if it is willing to
give up its lock. Unix has no simple way of implementing
opportunistic locking, and currently Samba has no support for it.
</para>

</sect1>

<sect1>
<title>Deny Modes</title>

<para>
When a SMB client opens a file it asks for a particular "deny mode" to
be placed on the file. These modes (DENY_NONE, DENY_READ, DENY_WRITE,
DENY_ALL, DENY_FCB and DENY_DOS) specify what actions should be
allowed by anyone else who tries to use the file at the same time. If
DENY_READ is placed on the file, for example, then any attempt to open
the file for reading should fail.
</para>

<para>
Unix has no equivalent notion. To implement this Samba uses either lock
files based on the files inode and placed in a separate lock
directory or a shared memory implementation. The lock file method 
is clumsy and consumes processing and file resources,
the shared memory implementation is vastly prefered and is turned on
by default for those systems that support it.
</para>

</sect1>

<sect1>
<title>Trapdoor UIDs</title>
<para>
A SMB session can run with several uids on the one socket. This
happens when a user connects to two shares with different
usernames. To cope with this the unix server needs to switch uids
within the one process. On some unixes (such as SCO) this is not
possible. This means that on those unixes the client is restricted to
a single uid.
</para>

<para>
Note that you can also get the "trapdoor uid" message for other
reasons. Please see the FAQ for details.
</para>

</sect1>

<sect1>
<title>Port numbers</title>
<para>
There is a convention that clients on sockets use high "unprivilaged"
port numbers (>1000) and connect to servers on low "privilaged" port
numbers. This is enforced in Unix as non-root users can't open a
socket for listening on port numbers less than 1000.
</para>

<para>
Most PC based SMB clients (such as WfWg and WinNT) don't follow this
convention completely. The main culprit is the netbios nameserving on
udp port 137. Name query requests come from a source port of 137. This
is a problem when you combine it with the common firewalling technique
of not allowing incoming packets on low port numbers. This means that
these clients can't query a netbios nameserver on the other side of a
low port based firewall.
</para>

<para>
The problem is more severe with netbios node status queries. I've
found that WfWg, Win95 and WinNT3.5 all respond to netbios node status
queries on port 137 no matter what the source port was in the
request. This works between machines that are both using port 137, but
it means it's not possible for a unix user to do a node status request
to any of these OSes unless they are running as root. The answer comes
back, but it goes to port 137 which the unix user can't listen
on. Interestingly WinNT3.1 got this right - it sends node status
responses back to the source port in the request.
</para>

</sect1>

<sect1>
<title>Protocol Complexity</title>
<para>
There are many "protocol levels" in the SMB protocol. It seems that
each time new functionality was added to a Microsoft operating system,
they added the equivalent functions in a new protocol level of the SMB
protocol to "externalise" the new capabilities.
</para>

<para>
This means the protocol is very "rich", offering many ways of doing
each file operation. This means SMB servers need to be complex and
large. It also means it is very difficult to make them bug free. It is
not just Samba that suffers from this problem, other servers such as
WinNT don't support every variation of every call and it has almost
certainly been a headache for MS developers to support the myriad of
SMB calls that are available.
</para>

<para>
There are about 65 "top level" operations in the SMB protocol (things
like SMBread and SMBwrite). Some of these include hundreds of
sub-functions (SMBtrans has at least 120 sub-functions, like
DosPrintQAdd and NetSessionEnum). All of them take several options
that can change the way they work. Many take dozens of possible
"information levels" that change the structures that need to be
returned. Samba supports all but 2 of the "top level" functions. It
supports only 8 (so far) of the SMBtrans sub-functions. Even NT
doesn't support them all.
</para>

<para>
Samba currently supports up to the "NT LM 0.12" protocol, which is the
one preferred by Win95 and WinNT3.5. Luckily this protocol level has a
"capabilities" field which specifies which super-duper new-fangled
options the server suports. This helps to make the implementation of
this protocol level much easier.
</para>

<para>
There is also a problem with the SMB specications. SMB is a X/Open
spec, but the X/Open book is far from ideal, and fails to cover many
important issues, leaving much to the imagination. Microsoft recently
renamed the SMB protocol CIFS (Common Internet File System) and have 
published new specifications. These are far superior to the old 
X/Open documents but there are still undocumented calls and features. 
This specification is actively being worked on by a CIFS developers 
mailing list hosted by Microsft.
</para>
</sect1>
</chaptor>
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9HEsrPa9Uoh7vUnYRAuJbAJ9qhLL4G1jdGr9y460unLjqvY62VACeJQB2
9OJFWOk8e3yELFXXHfzEKWw=
=TyaX
-----END PGP SIGNATURE-----