1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
5 >SAMBA Developers Guide</TITLE
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
20 NAME="SAMBA-DEVELOPER-DOCUMENTATION"><DIV
25 NAME="SAMBA-DEVELOPER-DOCUMENTATION">SAMBA Developers Guide</H1
29 NAME="AEN4">SAMBA Team</H3
33 NAME="AEN8">Abstract</H1
38 > : Mon Sep 30 15:23:53 CDT 2002</P
40 >This book is a collection of documents that might be useful for
41 people developing samba or those interested in doing so.
42 It's nothing more than a collection of documents written by samba developers about
43 the internals of various parts of samba and the SMB protocol. It's still incomplete.
44 The most recent version of this document
46 HREF="http://devel.samba.org/"
48 >http://devel.samba.org/</A
50 Please send updates to <A
51 HREF="mailto:jelmer@samba.org"
56 >This documentation is distributed under the GNU General Public License (GPL)
57 version 2. A copy of the license is included with the Samba source
58 distribution. A copy can be found on-line at <A
59 HREF="http://www.fsf.org/licenses/gpl.txt"
61 >http://www.fsf.org/licenses/gpl.txt</A
73 >Definition of NetBIOS Protocol and Name Resolution Modes</A
97 >Samba Architecture</A
109 >Multithreading and Samba</A
131 >The samba DEBUG system</A
138 >New Output Syntax</A
143 >The DEBUG() Macro</A
148 >The DEBUGADD() Macro</A
153 >The DEBUGLVL() Macro</A
175 >format_debug_text()</A
183 HREF="#CODINGSUGGESTIONS"
184 >Coding Suggestions</A
196 >Character Handling</A
201 >The new functions</A
206 >Macros in byteorder.h</A
223 >SCVAL(buf,pos,val)</A
248 >SSVAL(buf,pos,val)</A
253 >SIVAL(buf,pos,val)</A
258 >SSVALS(buf,pos,val)</A
263 >SIVALS(buf,pos,val)</A
278 >RSSVAL(buf,pos,val)</A
283 >RSIVAL(buf,pos,val)</A
290 >LAN Manager Samba API</A
309 >Code character table</A
316 >The smb.conf file</A
330 >Handling of Whitespace</A
335 >Handling of Line Continuation</A
340 >Line Continuation Quirks</A
363 >NetBIOS in a Unix World</A
410 >Protocol Complexity</A
417 >Tracing samba system calls</A
448 >Notes and Structures</A
472 >MSRPC over Transact Named Pipe</A
494 >RPC Bind / Bind Ack</A
499 >NTLSA Transact Named Pipe</A
509 >LSA Query Info Policy</A
514 >LSA Enumerate Trusted Domains</A
541 >NETLOGON rpc Transact Named Pipe</A
548 >LSA Request Challenge</A
553 >LSA Authenticate 2</A
558 >LSA Server Password Set</A
575 >\\MAILSLOT\NET\NTLOGON</A
594 >SRVSVC Transact Named Pipe</A
606 >Net Server Get Info</A
613 >Cryptographic side of NT Domain Authentication</A
658 >Samba Printing Internals</A
670 >Printing Interface to Various Back ends</A
675 >Print Queue TDB's</A
680 >ChangeID & Client Caching of Printer Information</A
685 >Windows NT/2K Printer Change Notify</A
692 >Samba WINS Internals</A
709 NAME="NETBIOS">Definition of NetBIOS Protocol and Name Resolution Modes</H1
715 NAME="AEN24">NETBIOS</H2
717 >NetBIOS runs over the following tranports: TCP/IP; NetBEUI and IPX/SPX.
718 Samba only uses NetBIOS over TCP/IP. For details on the TCP/IP NetBIOS
719 Session Service NetBIOS Datagram Service, and NetBIOS Names, see
720 rfc1001.txt and rfc1002.txt.</P
723 NetBEUI is a raw NetBIOS frame protocol implementation that allows NetBIOS
724 datagrams to be sent out over the 'wire' embedded within LLC frames.
725 NetBEUI is not required when using NetBIOS over TCP/IP protocols and it
726 is preferable NOT to install NetBEUI if it can be avoided.</P
729 IPX/SPX is also not required when using NetBIOS over TCP/IP, and it is
730 preferable NOT to install the IPX/SPX transport unless you are using Novell
731 servers. At the very least, it is recommended that you do not install
732 'NetBIOS over IPX/SPX'.</P
734 >[When installing Windows 95, you will find that NetBEUI and IPX/SPX are
735 installed as the default protocols. This is because they are the simplest
736 to manage: no Windows 95 user-configuration is required].</P
739 NetBIOS applications (such as samba) offer their services (for example,
740 SMB file and print sharing) on a NetBIOS name. They must claim this name
741 on the network before doing so. The NetBIOS session service will then
742 accept connections on the application's behalf (on the NetBIOS name
743 claimed by the application). A NetBIOS session between the application
744 and the client can then commence.</P
747 NetBIOS names consist of 15 characters plus a 'type' character. This is
748 similar, in concept, to an IP address and a TCP port number, respectively.
749 A NetBIOS-aware application on a host will offer different services under
750 different NetBIOS name types, just as a host will offer different TCP/IP
751 services on different port numbers.</P
754 NetBIOS names must be claimed on a network, and must be defended. The use
755 of NetBIOS names is most suitable on a single subnet; a Local Area Network
756 or a Wide Area Network.</P
759 NetBIOS names are either UNIQUE or GROUP. Only one application can claim a
760 UNIQUE NetBIOS name on a network.</P
762 >There are two kinds of NetBIOS Name resolution: Broadcast and Point-to-Point.</P
769 NAME="AEN35">BROADCAST NetBIOS</H2
772 Clients can claim names, and therefore offer services on successfully claimed
773 names, on their broadcast-isolated subnet. One way to get NetBIOS services
774 (such as browsing: see ftp.microsoft.com/drg/developr/CIFS/browdiff.txt; and
775 SMB file/print sharing: see cifs4.txt) working on a LAN or WAN is to make
776 your routers forward all broadcast packets from TCP/IP ports 137, 138 and 139.</P
779 This, however, is not recommended. If you have a large LAN or WAN, you will
780 find that some of your hosts spend 95 percent of their time dealing with
781 broadcast traffic. [If you have IPX/SPX on your LAN or WAN, you will find
782 that this is already happening: a packet analyzer will show, roughly
783 every twelve minutes, great swathes of broadcast traffic!].</P
790 NAME="AEN39">NBNS NetBIOS</H2
792 >rfc1001.txt describes, amongst other things, the implementation and use
793 of, a 'NetBIOS Name Service'. NT/AS offers 'Windows Internet Name Service'
794 which is fully rfc1001/2 compliant, but has had to take specific action
795 with certain NetBIOS names in order to make it useful. (for example, it
796 deals with the registration of <1c> <1d> <1e> names all in different ways.
797 I recommend the reading of the Microsoft WINS Server Help files for full
801 The use of a WINS server cuts down on broadcast network traffic for
802 NetBIOS name resolution. It has the effect of pulling all the broadcast
803 isolated subnets together into a single NetBIOS scope, across your LAN
804 or WAN, while avoiding the use of TCP/IP broadcast packets.</P
806 >When you have a WINS server on your LAN, WINS clients will be able to
807 contact the WINS server to resolve NetBIOS names. Note that only those
808 WINS clients that have registered with the same WINS server will be
809 visible. The WINS server _can_ have static NetBIOS entries added to its
810 database (usually for security reasons you might want to consider putting
811 your domain controllers or other important servers as static entries,
812 but you should not rely on this as your sole means of security), but for
813 the most part, NetBIOS names are registered dynamically.</P
815 >This provides some confusion for lots of people, and is worth mentioning
816 here: a Browse Server is NOT a WINS Server, even if these services are
817 implemented in the same application. A Browse Server _needs_ a WINS server
818 because a Browse Server is a WINS client, which is _not_ the same thing].</P
820 >Clients can claim names, and therefore offer services on successfully claimed
821 names, on their broadcast-isolated subnet. One way to get NetBIOS services
822 (such as browsing: see ftp.microsoft.com/drg/developr/CIFS/browdiff.txt; and
823 SMB file/print sharing: see cifs6.txt) working on a LAN or WAN is to make
824 your routers forward all broadcast packets from TCP/IP ports 137, 138 and 139.
825 You will find, however, if you do this on a large LAN or a WAN, that your
826 network is completely swamped by NetBIOS and browsing packets, which is why
827 WINS was developed to minimise the necessity of broadcast traffic.</P
830 WINS Clients therefore claim names from the WINS server. If the WINS
831 server allows them to register a name, the client's NetBIOS session service
832 can then offer services on this name. Other WINS clients will then
833 contact the WINS server to resolve a NetBIOS name.</P
840 NAME="ARCHITECTURE">Samba Architecture</H1
846 NAME="AEN54">Introduction</H2
848 >This document gives a general overview of how Samba works
849 internally. The Samba Team has tried to come up with a model which is
850 the best possible compromise between elegance, portability, security
851 and the constraints imposed by the very messy SMB and CIFS
854 >It also tries to answer some of the frequently asked questions such as:</P
861 > Is Samba secure when running on Unix? The xyz platform?
862 What about the root priveliges issue?</P
866 >Pros and cons of multithreading in various parts of Samba</P
870 >Why not have a separate process for name resolution, WINS, and browsing?</P
879 NAME="AEN65">Multithreading and Samba</H2
881 >People sometimes tout threads as a uniformly good thing. They are very
882 nice in their place but are quite inappropriate for smbd. nmbd is
883 another matter, and multi-threading it would be very nice. </P
885 >The short version is that smbd is not multithreaded, and alternative
886 servers that take this approach under Unix (such as Syntax, at the
887 time of writing) suffer tremendous performance penalties and are less
888 robust. nmbd is not threaded either, but this is because it is not
889 possible to do it while keeping code consistent and portable across 35
890 or more platforms. (This drawback also applies to threading smbd.)</P
892 >The longer versions is that there are very good reasons for not making
893 smbd multi-threaded. Multi-threading would actually make Samba much
894 slower, less scalable, less portable and much less robust. The fact
895 that we use a separate process for each connection is one of Samba's
896 biggest advantages.</P
903 NAME="AEN70">Threading smbd</H2
905 >A few problems that would arise from a threaded smbd are:</P
912 > It's not only to create threads instead of processes, but you
913 must care about all variables if they have to be thread specific
914 (currently they would be global).</P
918 > if one thread dies (eg. a seg fault) then all threads die. We can
919 immediately throw robustness out the window.</P
923 > many of the system calls we make are blocking. Non-blocking
924 equivalents of many calls are either not available or are awkward (and
925 slow) to use. So while we block in one thread all clients are
926 waiting. Imagine if one share is a slow NFS filesystem and the others
927 are fast, we will end up slowing all clients to the speed of NFS.</P
931 > you can't run as a different uid in different threads. This means
932 we would have to switch uid/gid on _every_ SMB packet. It would be
933 horrendously slow.</P
937 > the per process file descriptor limit would mean that we could only
938 support a limited number of clients.</P
942 > we couldn't use the system locking calls as the locking context of
943 fcntl() is a process, not a thread.</P
952 NAME="AEN86">Threading nmbd</H2
954 >This would be ideal, but gets sunk by portability requirements.</P
956 >Andrew tried to write a test threads library for nmbd that used only
957 ansi-C constructs (using setjmp and longjmp). Unfortunately some OSes
958 defeat this by restricting longjmp to calling addresses that are
959 shallower than the current address on the stack (apparently AIX does
960 this). This makes a truly portable threads library impossible. So to
961 support all our current platforms we would have to code nmbd both with
962 and without threads, and as the real aim of threads is to make the
963 code clearer we would not have gained anything. (it is a myth that
964 threads make things faster. threading is like recursion, it can make
965 things clear but the same thing can always be done faster by some
968 >Chris tried to spec out a general design that would abstract threading
969 vs separate processes (vs other methods?) and make them accessible
970 through some general API. This doesn't work because of the data
971 sharing requirements of the protocol (packets in the future depending
972 on packets now, etc.) At least, the code would work but would be very
973 clumsy, and besides the fork() type model would never work on Unix. (Is there an OS that it would work on, for nmbd?)</P
975 >A fork() is cheap, but not nearly cheap enough to do on every UDP
976 packet that arrives. Having a pool of processes is possible but is
977 nasty to program cleanly due to the enormous amount of shared data (in
978 complex structures) between the processes. We can't rely on each
979 platform having a shared memory system.</P
986 NAME="AEN92">nbmd Design</H2
988 >Originally Andrew used recursion to simulate a multi-threaded
989 environment, which use the stack enormously and made for really
990 confusing debugging sessions. Luke Leighton rewrote it to use a
991 queuing system that keeps state information on each packet. The
992 first version used a single structure which was used by all the
993 pending states. As the initialisation of this structure was
994 done by adding arguments, as the functionality developed, it got
995 pretty messy. So, it was replaced with a higher-order function
996 and a pointer to a user-defined memory block. This suddenly
997 made things much simpler: large numbers of functions could be
998 made static, and modularised. This is the same principle as used
999 in NT's kernel, and achieves the same effect as threads, but in
1000 a single process.</P
1002 >Then Jeremy rewrote nmbd. The packet data in nmbd isn't what's on the
1003 wire. It's a nice format that is very amenable to processing but still
1004 keeps the idea of a distinct packet. See "struct packet_struct" in
1005 nameserv.h. It has all the detail but none of the on-the-wire
1006 mess. This makes it ideal for using in disk or memory-based databases
1007 for browsing and WINS support. </P
1014 NAME="DEBUG">The samba DEBUG system</H1
1020 NAME="AEN103">New Output Syntax</H2
1022 > The syntax of a debugging log file is represented as:</P
1031 CLASS="PROGRAMLISTING"
1032 > >debugfile< :== { >debugmsg< }
1034 >debugmsg< :== >debughdr< '\n' >debugtext<
1036 >debughdr< :== '[' TIME ',' LEVEL ']' FILE ':' [FUNCTION] '(' LINE ')'
1038 >debugtext< :== { >debugline< }
1040 >debugline< :== TEXT '\n'</PRE
1046 >TEXT is a string of characters excluding the newline character.</P
1048 >LEVEL is the DEBUG level of the message (an integer in the range
1051 >TIME is a timestamp.</P
1053 >FILE is the name of the file from which the debug message was
1056 >FUNCTION is the function from which the debug message was generated.</P
1058 >LINE is the line number of the debug statement that generated the
1061 >Basically, what that all means is:</P
1068 >A debugging log file is made up of debug messages.</P
1072 >Each debug message is made up of a header and text. The header is
1073 separated from the text by a newline.</P
1077 >The header begins with the timestamp and debug level of the
1078 message enclosed in brackets. The filename, function, and line
1079 number at which the message was generated follow. The filename is
1080 terminated by a colon, and the function name is terminated by the
1081 parenthesis which contain the line number. Depending upon the
1082 compiler, the function name may be missing (it is generated by the
1083 __FUNCTION__ macro, which is not universally implemented, dangit).</P
1087 >The message text is made up of zero or more lines, each terminated
1092 >Here's some example output:</P
1101 CLASS="PROGRAMLISTING"
1102 > [1998/08/03 12:55:25, 1] nmbd.c:(659)
1103 Netbios nameserver version 1.9.19-prealpha started.
1104 Copyright Andrew Tridgell 1994-1997
1105 [1998/08/03 12:55:25, 3] loadparm.c:(763)
1106 Initializing global parameters</PRE
1112 >Note that in the above example the function names are not listed on
1113 the header line. That's because the example above was generated on an
1114 SGI Indy, and the SGI compiler doesn't support the __FUNCTION__ macro.</P
1121 NAME="AEN128">The DEBUG() Macro</H2
1123 >Use of the DEBUG() macro is unchanged. DEBUG() takes two parameters.
1124 The first is the message level, the second is the body of a function
1125 call to the Debug1() function.</P
1127 >That's confusing.</P
1129 >Here's an example which may help a bit. If you would write</P
1138 CLASS="PROGRAMLISTING"
1139 >printf( "This is a %s message.\n", "debug" );</PRE
1145 >to send the output to stdout, then you would write</P
1154 CLASS="PROGRAMLISTING"
1155 >DEBUG( 0, ( "This is a %s message.\n", "debug" ) );</PRE
1161 >to send the output to the debug file. All of the normal printf()
1162 formatting escapes work.</P
1164 >Note that in the above example the DEBUG message level is set to 0.
1165 Messages at level 0 always print. Basically, if the message level is
1166 less than or equal to the global value DEBUGLEVEL, then the DEBUG
1167 statement is processed.</P
1169 >The output of the above example would be something like:</P
1178 CLASS="PROGRAMLISTING"
1179 > [1998/07/30 16:00:51, 0] file.c:function(128)
1180 This is a debug message.</PRE
1186 >Each call to DEBUG() creates a new header *unless* the output produced
1187 by the previous call to DEBUG() did not end with a '\n'. Output to the
1188 debug file is passed through a formatting buffer which is flushed
1189 every time a newline is encountered. If the buffer is not empty when
1190 DEBUG() is called, the new input is simply appended.</P
1192 >...but that's really just a Kludge. It was put in place because
1193 DEBUG() has been used to write partial lines. Here's a simple (dumb)
1194 example of the kind of thing I'm talking about:</P
1203 CLASS="PROGRAMLISTING"
1204 > DEBUG( 0, ("The test returned " ) );
1206 DEBUG(0, ("True") );
1208 DEBUG(0, ("False") );
1209 DEBUG(0, (".\n") );</PRE
1215 >Without the format buffer, the output (assuming test() returned true)
1216 would look like this:</P
1225 CLASS="PROGRAMLISTING"
1226 > [1998/07/30 16:00:51, 0] file.c:function(256)
1228 [1998/07/30 16:00:51, 0] file.c:function(258)
1230 [1998/07/30 16:00:51, 0] file.c:function(261)
1237 >Which isn't much use. The format buffer kludge fixes this problem.</P
1244 NAME="AEN151">The DEBUGADD() Macro</H2
1246 >In addition to the kludgey solution to the broken line problem
1247 described above, there is a clean solution. The DEBUGADD() macro never
1248 generates a header. It will append new text to the current debug
1249 message even if the format buffer is empty. The syntax of the
1250 DEBUGADD() macro is the same as that of the DEBUG() macro.</P
1259 CLASS="PROGRAMLISTING"
1260 > DEBUG( 0, ("This is the first line.\n" ) );
1261 DEBUGADD( 0, ("This is the second line.\nThis is the third line.\n" ) );</PRE
1276 CLASS="PROGRAMLISTING"
1277 > [1998/07/30 16:00:51, 0] file.c:function(512)
1278 This is the first line.
1279 This is the second line.
1280 This is the third line.</PRE
1291 NAME="AEN159">The DEBUGLVL() Macro</H2
1293 >One of the problems with the DEBUG() macro was that DEBUG() lines
1294 tended to get a bit long. Consider this example from
1295 nmbd_sendannounce.c:</P
1304 CLASS="PROGRAMLISTING"
1305 > DEBUG(3,("send_local_master_announcement: type %x for name %s on subnet %s for workgroup %s\n",
1306 type, global_myname, subrec->subnet_name, work->work_group));</PRE
1312 >One solution to this is to break it down using DEBUG() and DEBUGADD(),
1322 CLASS="PROGRAMLISTING"
1323 > DEBUG( 3, ( "send_local_master_announcement: " ) );
1324 DEBUGADD( 3, ( "type %x for name %s ", type, global_myname ) );
1325 DEBUGADD( 3, ( "on subnet %s ", subrec->subnet_name ) );
1326 DEBUGADD( 3, ( "for workgroup %s\n", work->work_group ) );</PRE
1332 >A similar, but arguably nicer approach is to use the DEBUGLVL() macro.
1333 This macro returns True if the message level is less than or equal to
1334 the global DEBUGLEVEL value, so:</P
1343 CLASS="PROGRAMLISTING"
1344 > if( DEBUGLVL( 3 ) )
1346 dbgtext( "send_local_master_announcement: " );
1347 dbgtext( "type %x for name %s ", type, global_myname );
1348 dbgtext( "on subnet %s ", subrec->subnet_name );
1349 dbgtext( "for workgroup %s\n", work->work_group );
1356 >(The dbgtext() function is explained below.)</P
1358 >There are a few advantages to this scheme:</P
1365 >The test is performed only once.</P
1369 >You can allocate variables off of the stack that will only be used
1370 within the DEBUGLVL() block.</P
1374 >Processing that is only relevant to debug output can be contained
1375 within the DEBUGLVL() block.</P
1384 NAME="AEN179">New Functions</H2
1390 NAME="AEN181">dbgtext()</H3
1392 >This function prints debug message text to the debug file (and
1393 possibly to syslog) via the format buffer. The function uses a
1394 variable argument list just like printf() or Debug1(). The
1395 input is printed into a buffer using the vslprintf() function,
1396 and then passed to format_debug_text().
1398 If you use DEBUGLVL() you will probably print the body of the
1399 message using dbgtext(). </P
1406 NAME="AEN184">dbghdr()</H3
1408 >This is the function that writes a debug message header.
1409 Headers are not processed via the format buffer. Also note that
1410 if the format buffer is not empty, a call to dbghdr() will not
1411 produce any output. See the comments in dbghdr() for more info.</P
1413 >It is not likely that this function will be called directly. It
1414 is used by DEBUG() and DEBUGADD().</P
1421 NAME="AEN188">format_debug_text()</H3
1423 >This is a static function in debug.c. It stores the output text
1424 for the body of the message in a buffer until it encounters a
1425 newline. When the newline character is found, the buffer is
1426 written to the debug file via the Debug1() function, and the
1427 buffer is reset. This allows us to add the indentation at the
1428 beginning of each line of the message body, and also ensures
1429 that the output is written a line at a time (which cleans up
1438 NAME="CODINGSUGGESTIONS">Coding Suggestions</H1
1440 >So you want to add code to Samba ...</P
1442 >One of the daunting tasks facing a programmer attempting to write code for
1443 Samba is understanding the various coding conventions used by those most
1444 active in the project. These conventions were mostly unwritten and helped
1445 improve either the portability, stability or consistency of the code. This
1446 document will attempt to document a few of the more important coding
1447 practices used at this time on the Samba project. The coding practices are
1448 expected to change slightly over time, and even to grow as more is learned
1449 about obscure portability considerations. Two existing documents
1452 >samba/source/internals.doc</TT
1456 >samba/source/architecture.doc</TT
1458 additional information.</P
1460 >The loosely related question of coding style is very personal and this
1461 document does not attempt to address that subject, except to say that I
1462 have observed that eight character tabs seem to be preferred in Samba
1463 source. If you are interested in the topic of coding style, two oft-quoted
1467 HREF="http://lxr.linux.no/source/Documentation/CodingStyle"
1469 >http://lxr.linux.no/source/Documentation/CodingStyle</A
1473 HREF="http://www.fsf.org/prep/standards_toc.html"
1475 >http://www.fsf.org/prep/standards_toc.html</A
1478 >But note that coding style in Samba varies due to the many different
1479 programmers who have contributed.</P
1481 >Following are some considerations you should use when adding new code to
1482 Samba. First and foremost remember that:</P
1484 >Portability is a primary consideration in adding function, as is network
1485 compatability with de facto, existing, real world CIFS/SMB implementations.
1486 There are lots of platforms that Samba builds on so use caution when adding
1487 a call to a library function that is not invoked in existing Samba code.
1488 Also note that there are many quite different SMB/CIFS clients that Samba
1489 tries to support, not all of which follow the SNIA CIFS Technical Reference
1490 (or the earlier Microsoft reference documents or the X/Open book on the SMB
1491 Standard) perfectly.</P
1493 >Here are some other suggestions:</P
1500 > use d_printf instead of printf for display text
1501 reason: enable auto-substitution of translated language text </P
1505 > use SAFE_FREE instead of free
1506 reason: reduce traps due to null pointers</P
1510 > don't use bzero use memset, or ZERO_STRUCT and ZERO_STRUCTP macros
1511 reason: not POSIX</P
1515 > don't use strcpy and strlen (use safe_* equivalents)
1516 reason: to avoid traps due to buffer overruns</P
1520 > don't use getopt_long, use popt functions instead
1521 reason: portability</P
1525 > explicitly add const qualifiers on parm passing in functions where parm
1526 is input only (somewhat controversial but const can be #defined away)</P
1530 > when passing a va_list as an arg, or assigning one to another
1531 please use the VA_COPY() macro
1532 reason: on some platforms, va_list is a struct that must be
1533 initialized in each function...can SEGV if you don't.</P
1537 > discourage use of threads
1538 reason: portability (also see architecture.doc)</P
1542 > don't explicitly include new header files in C files - new h files
1543 should be included by adding them once to includes.h
1544 reason: consistency</P
1548 > don't explicitly extern functions (they are autogenerated by
1549 "make proto" into proto.h)
1550 reason: consistency</P
1554 > use endian safe macros when unpacking SMBs (see byteorder.h and
1556 reason: not everyone uses Intel</P
1560 > Note Unicode implications of charset handling (see internals.doc). See
1561 pull_* and push_* and convert_string functions.
1562 reason: Internationalization</P
1566 > Don't assume English only
1567 reason: See above</P
1571 > Try to avoid using in/out parameters (functions that return data which
1572 overwrites input parameters)
1573 reason: Can cause stability problems</P
1577 > Ensure copyright notices are correct, don't append Tridge's name to code
1578 that he didn't write. If you did not write the code, make sure that it
1579 can coexist with the rest of the Samba GPLed code.</P
1583 > Consider usage of DATA_BLOBs for length specified byte-data.
1584 reason: stability</P
1588 > Take advantage of tdbs for database like function
1589 reason: consistency</P
1593 > Don't access the SAM_ACCOUNT structure directly, they should be accessed
1594 via pdb_get...() and pdb_set...() functions.
1595 reason: stability, consistency</P
1599 > Don't check a password directly against the passdb, always use the
1600 check_password() interface.
1601 reason: long term pluggability</P
1605 > Try to use asprintf rather than pstrings and fstrings where possible</P
1609 > Use normal C comments / * instead of C++ comments // like
1610 this. Although the C++ comment format is part of the C99
1611 standard, some older vendor C compilers do not accept it.</P
1615 > Try to write documentation for API functions and structures
1616 explaining the point of the code, the way it should be used, and
1617 any special conditions or results. Mark these with a double-star
1618 comment start / ** so that they can be picked up by Doxygen, as in
1623 > Keep the scope narrow. This means making functions/variables
1624 static whenever possible. We don't want our namespace
1625 polluted. Each module should have a minimal number of externally
1626 visible functions or variables.</P
1630 > Use function pointers to keep knowledge about particular pieces of
1631 code isolated in one place. We don't want a particular piece of
1632 functionality to be spread out across lots of places - that makes
1633 for fragile, hand to maintain code. Instead, design an interface
1634 and use tables containing function pointers to implement specific
1635 functionality. This is particularly important for command
1640 > Think carefully about what it will be like for someone else to add
1641 to and maintain your code. If it would be hard for someone else to
1642 maintain then do it another way. </P
1646 >The suggestions above are simply that, suggestions, but the information may
1647 help in reducing the routine rework done on new code. The preceeding list
1648 is expected to change routinely as new support routines and macros are
1655 NAME="INTERNALS">Samba Internals</H1
1661 NAME="AEN284">Character Handling</H2
1663 >This section describes character set handling in Samba, as implemented in
1664 Samba 3.0 and above</P
1666 >In the past Samba had very ad-hoc character set handling. Scattered
1667 throughout the code were numerous calls which converted particular
1668 strings to/from DOS codepages. The problem is that there was no way of
1669 telling if a particular char* is in dos codepage or unix
1670 codepage. This led to a nightmare of code that tried to cope with
1671 particular cases without handlingt the general case.</P
1678 NAME="AEN288">The new functions</H2
1680 >The new system works like this:</P
1687 > all char* strings inside Samba are "unix" strings. These are
1688 multi-byte strings that are in the charset defined by the "unix
1689 charset" option in smb.conf. </P
1693 > there is no single fixed character set for unix strings, but any
1694 character set that is used does need the following properties:
1702 > must not contain NULLs except for termination
1707 > must be 7-bit compatible with C strings, so that a constant
1708 string or character in C will be byte-for-byte identical to the
1709 equivalent string in the chosen character set.
1714 > when you uppercase or lowercase a string it does not become
1715 longer than the original string
1720 > must be able to correctly hold all characters that your client
1726 > For example, UTF-8 is fine, and most multi-byte asian character sets
1727 are fine, but UCS2 could not be used for unix strings as they
1733 > when you need to put a string into a buffer that will be sent on the
1734 wire, or you need a string in a character set format that is
1735 compatible with the clients character set then you need to use a
1736 pull_ or push_ function. The pull_ functions pull a string from a
1737 wire buffer into a (multi-byte) unix string. The push_ functions
1738 push a string out to a wire buffer. </P
1742 > the two main pull_ and push_ functions you need to understand are
1743 pull_string and push_string. These functions take a base pointer
1744 that should point at the start of the SMB packet that the string is
1745 in. The functions will check the flags field in this packet to
1746 automatically determine if the packet is marked as a unicode packet,
1747 and they will choose whether to use unicode for this string based on
1748 that flag. You may also force this decision using the STR_UNICODE or
1749 STR_ASCII flags. For use in smbd/ and libsmb/ there are wrapper
1750 functions clistr_ and srvstr_ that call the pull_/push_ functions
1751 with the appropriate first argument.
1754 > You may also call the pull_ascii/pull_ucs2 or push_ascii/push_ucs2
1755 functions if you know that a particular string is ascii or
1756 unicode. There are also a number of other convenience functions in
1757 charcnv.c that call the pull_/push_ functions with particularly
1758 common arguments, such as pull_ascii_pstring()
1763 > The biggest thing to remember is that internal (unix) strings in Samba
1764 may now contain multi-byte characters. This means you cannot assume
1765 that characters are always 1 byte long. Often this means that you will
1766 have to convert strings to ucs2 and back again in order to do some
1767 (seemingly) simple task. For examples of how to do this see functions
1768 like strchr_m(). I know this is very slow, and we will eventually
1769 speed it up but right now we want this stuff correct not fast.</P
1773 > all lp_ functions now return unix strings. The magic "DOS" flag on
1774 parameters is gone.</P
1778 > all vfs functions take unix strings. Don't convert when passing to them</P
1787 NAME="AEN317">Macros in byteorder.h</H2
1789 >This section describes the macros defined in byteorder.h. These macros
1790 are used extensively in the Samba code.</P
1796 NAME="AEN320">CVAL(buf,pos)</H3
1798 >returns the byte at offset pos within buffer buf as an unsigned character.</P
1805 NAME="AEN323">PVAL(buf,pos)</H3
1807 >returns the value of CVAL(buf,pos) cast to type unsigned integer.</P
1814 NAME="AEN326">SCVAL(buf,pos,val)</H3
1816 >sets the byte at offset pos within buffer buf to value val.</P
1823 NAME="AEN329">SVAL(buf,pos)</H3
1825 > returns the value of the unsigned short (16 bit) little-endian integer at
1826 offset pos within buffer buf. An integer of this type is sometimes
1827 refered to as "USHORT".</P
1834 NAME="AEN332">IVAL(buf,pos)</H3
1836 >returns the value of the unsigned 32 bit little-endian integer at offset
1837 pos within buffer buf.</P
1844 NAME="AEN335">SVALS(buf,pos)</H3
1846 >returns the value of the signed short (16 bit) little-endian integer at
1847 offset pos within buffer buf.</P
1854 NAME="AEN338">IVALS(buf,pos)</H3
1856 >returns the value of the signed 32 bit little-endian integer at offset pos
1857 within buffer buf.</P
1864 NAME="AEN341">SSVAL(buf,pos,val)</H3
1866 >sets the unsigned short (16 bit) little-endian integer at offset pos within
1867 buffer buf to value val.</P
1874 NAME="AEN344">SIVAL(buf,pos,val)</H3
1876 >sets the unsigned 32 bit little-endian integer at offset pos within buffer
1877 buf to the value val.</P
1884 NAME="AEN347">SSVALS(buf,pos,val)</H3
1886 >sets the short (16 bit) signed little-endian integer at offset pos within
1887 buffer buf to the value val.</P
1894 NAME="AEN350">SIVALS(buf,pos,val)</H3
1896 >sets the signed 32 bit little-endian integer at offset pos withing buffer
1897 buf to the value val.</P
1904 NAME="AEN353">RSVAL(buf,pos)</H3
1906 >returns the value of the unsigned short (16 bit) big-endian integer at
1907 offset pos within buffer buf.</P
1914 NAME="AEN356">RIVAL(buf,pos)</H3
1916 >returns the value of the unsigned 32 bit big-endian integer at offset
1917 pos within buffer buf.</P
1924 NAME="AEN359">RSSVAL(buf,pos,val)</H3
1926 >sets the value of the unsigned short (16 bit) big-endian integer at
1927 offset pos within buffer buf to value val.
1928 refered to as "USHORT".</P
1935 NAME="AEN362">RSIVAL(buf,pos,val)</H3
1937 >sets the value of the unsigned 32 bit big-endian integer at offset
1938 pos within buffer buf to value val.</P
1946 NAME="AEN365">LAN Manager Samba API</H2
1948 >This section describes the functions need to make a LAN Manager RPC call.
1949 This information had been obtained by examining the Samba code and the LAN
1950 Manager 2.0 API documentation. It should not be considered entirely
1960 CLASS="PROGRAMLISTING"
1961 >call_api(int prcnt, int drcnt, int mprcnt, int mdrcnt,
1962 char *param, char *data, char **rparam, char **rdata);</PRE
1968 >This function is defined in client.c. It uses an SMB transaction to call a
1975 NAME="AEN371">Parameters</H3
1977 >The parameters are as follows:</P
1984 > prcnt: the number of bytes of parameters begin sent.</P
1988 > drcnt: the number of bytes of data begin sent.</P
1992 > mprcnt: the maximum number of bytes of parameters which should be returned</P
1996 > mdrcnt: the maximum number of bytes of data which should be returned</P
2000 > param: a pointer to the parameters to be sent.</P
2004 > data: a pointer to the data to be sent.</P
2008 > rparam: a pointer to a pointer which will be set to point to the returned
2009 paramters. The caller of call_api() must deallocate this memory.</P
2013 > rdata: a pointer to a pointer which will be set to point to the returned
2014 data. The caller of call_api() must deallocate this memory.</P
2018 >These are the parameters which you ought to send, in the order of their
2019 appearance in the parameter block:</P
2026 >An unsigned 16 bit integer API number. You should set this value with
2027 SSVAL(). I do not know where these numbers are described.</P
2031 >An ASCIIZ string describing the parameters to the API function as defined
2032 in the LAN Manager documentation. The first parameter, which is the server
2033 name, is ommited. This string is based uppon the API function as described
2034 in the manual, not the data which is actually passed.</P
2038 >An ASCIIZ string describing the data structure which ought to be returned.</P
2042 >Any parameters which appear in the function call, as defined in the LAN
2043 Manager API documentation, after the "Server" and up to and including the
2044 "uLevel" parameters.</P
2048 >An unsigned 16 bit integer which gives the size in bytes of the buffer we
2049 will use to receive the returned array of data structures. Presumably this
2050 should be the same as mdrcnt. This value should be set with SSVAL().</P
2054 >An ASCIIZ string describing substructures which should be returned. If no
2055 substructures apply, this string is of zero length.</P
2059 >The code in client.c always calls call_api() with no data. It is unclear
2060 when a non-zero length data buffer would be sent.</P
2067 NAME="AEN406">Return value</H3
2069 >The returned parameters (pointed to by rparam), in their order of appearance
2077 >An unsigned 16 bit integer which contains the API function's return code.
2078 This value should be read with SVAL().</P
2082 >An adjustment which tells the amount by which pointers in the returned
2083 data should be adjusted. This value should be read with SVAL(). Basically,
2084 the address of the start of the returned data buffer should have the returned
2085 pointer value added to it and then have this value subtracted from it in
2086 order to obtain the currect offset into the returned data buffer.</P
2090 >A count of the number of elements in the array of structures returned.
2091 It is also possible that this may sometimes be the number of bytes returned.</P
2095 >When call_api() returns, rparam points to the returned parameters. The
2096 first if these is the result code. It will be zero if the API call
2097 suceeded. This value by be read with "SVAL(rparam,0)".</P
2099 >The second parameter may be read as "SVAL(rparam,2)". It is a 16 bit offset
2100 which indicates what the base address of the returned data buffer was when
2101 it was built on the server. It should be used to correct pointer before
2104 >The returned data buffer contains the array of returned data structures.
2105 Note that all pointers must be adjusted before use. The function
2106 fix_char_ptr() in client.c can be used for this purpose.</P
2108 >The third parameter (which may be read as "SVAL(rparam,4)") has something to
2109 do with indicating the amount of data returned or possibly the amount of
2110 data which can be returned if enough buffer space is allowed.</P
2118 NAME="AEN420">Code character table</H2
2120 >Certain data structures are described by means of ASCIIz strings containing
2121 code characters. These are the code characters:</P
2128 >W a type byte little-endian unsigned integer</P
2132 >N a count of substructures which follow</P
2136 >D a four byte little-endian unsigned integer</P
2140 >B a byte (with optional count expressed as trailing ASCII digits)</P
2144 >z a four byte offset to a NULL terminated string</P
2148 >l a four byte offset to non-string user data</P
2152 >b an offset to data (with count expressed as trailing ASCII digits)</P
2156 >r pointer to returned data buffer???</P
2160 >L length in bytes of returned data buffer???</P
2164 >h number of bytes of information available???</P
2173 NAME="PARSING">The smb.conf file</H1
2179 NAME="AEN451">Lexical Analysis</H2
2181 >Basically, the file is processed on a line by line basis. There are
2182 four types of lines that are recognized by the lexical analyzer
2190 >Blank lines - Lines containing only whitespace.</P
2194 >Comment lines - Lines beginning with either a semi-colon or a
2195 pound sign (';' or '#').</P
2199 >Section header lines - Lines beginning with an open square bracket ('[').</P
2203 >Parameter lines - Lines beginning with any other character.
2204 (The default line type.)</P
2208 >The first two are handled exclusively by the lexical analyzer, which
2209 ignores them. The latter two line types are scanned for</P
2216 > - Section names</P
2220 > - Parameter names</P
2224 > - Parameter values</P
2228 >These are the only tokens passed to the parameter loader
2229 (loadparm.c). Parameter names and values are divided from one
2230 another by an equal sign: '='.</P
2236 NAME="AEN472">Handling of Whitespace</H3
2238 >Whitespace is defined as all characters recognized by the isspace()
2239 function (see ctype(3C)) except for the newline character ('\n')
2240 The newline is excluded because it identifies the end of the line.</P
2247 >The lexical analyzer scans past white space at the beginning of a line.</P
2251 >Section and parameter names may contain internal white space. All
2252 whitespace within a name is compressed to a single space character. </P
2256 >Internal whitespace within a parameter value is kept verbatim with
2257 the exception of carriage return characters ('\r'), all of which
2262 >Leading and trailing whitespace is removed from names and values.</P
2271 NAME="AEN484">Handling of Line Continuation</H3
2273 >Long section header and parameter lines may be extended across
2274 multiple lines by use of the backslash character ('\\'). Line
2275 continuation is ignored for blank and comment lines.</P
2277 >If the last (non-whitespace) character within a section header or on
2278 a parameter line is a backslash, then the next line will be
2279 (logically) concatonated with the current line by the lexical
2280 analyzer. For example:</P
2289 CLASS="PROGRAMLISTING"
2290 > param name = parameter value string \
2291 with line continuation.</PRE
2297 >Would be read as</P
2306 CLASS="PROGRAMLISTING"
2307 > param name = parameter value string with line continuation.</PRE
2313 >Note that there are five spaces following the word 'string',
2314 representing the one space between 'string' and '\\' in the top
2315 line, plus the four preceeding the word 'with' in the second line.
2316 (Yes, I'm counting the indentation.)</P
2318 >Line continuation characters are ignored on blank lines and at the end
2319 of comments. They are *only* recognized within section and parameter
2327 NAME="AEN495">Line Continuation Quirks</H3
2329 >Note the following example:</P
2338 CLASS="PROGRAMLISTING"
2339 > param name = parameter value string \
2341 with line continuation.</PRE
2347 >The middle line is *not* parsed as a blank line because it is first
2348 concatonated with the top line. The result is</P
2357 CLASS="PROGRAMLISTING"
2358 >param name = parameter value string with line continuation.</PRE
2364 >The same is true for comment lines.</P
2373 CLASS="PROGRAMLISTING"
2374 > param name = parameter value string \
2376 with a comment.</PRE
2391 CLASS="PROGRAMLISTING"
2392 >param name = parameter value string ; comment with a comment.</PRE
2398 >On a section header line, the closing bracket (']') is considered a
2399 terminating character, and the rest of the line is ignored. The lines</P
2408 CLASS="PROGRAMLISTING"
2409 > [ section name ] garbage \
2410 param name = value</PRE
2425 CLASS="PROGRAMLISTING"
2427 param name = value</PRE
2439 NAME="AEN515">Syntax</H2
2441 >The syntax of the smb.conf file is as follows:</P
2450 CLASS="PROGRAMLISTING"
2451 > <file> :== { <section> } EOF
2452 <section> :== <section header> { <parameter line> }
2453 <section header> :== '[' NAME ']'
2454 <parameter line> :== NAME '=' VALUE NL</PRE
2460 >Basically, this means that</P
2467 > a file is made up of zero or more sections, and is terminated by
2468 an EOF (we knew that).</P
2472 > A section is made up of a section header followed by zero or more
2477 > A section header is identified by an opening bracket and
2478 terminated by the closing bracket. The enclosed NAME identifies
2483 > A parameter line is divided into a NAME and a VALUE. The *first*
2484 equal sign on the line separates the NAME from the VALUE. The
2485 VALUE is terminated by a newline character (NL = '\n').</P
2493 NAME="AEN530">About params.c</H3
2495 >The parsing of the config file is a bit unusual if you are used to
2496 lex, yacc, bison, etc. Both lexical analysis (scanning) and parsing
2497 are performed by params.c. Values are loaded via callbacks to
2506 NAME="UNIX-SMB">NetBIOS in a Unix World</H1
2512 NAME="AEN540">Introduction</H2
2514 >This is a short document that describes some of the issues that
2515 confront a SMB implementation on unix, and how Samba copes with
2516 them. They may help people who are looking at unix<->PC
2517 interoperability.</P
2519 >It was written to help out a person who was writing a paper on unix to
2527 NAME="AEN544">Usernames</H2
2529 >The SMB protocol has only a loose username concept. Early SMB
2530 protocols (such as CORE and COREPLUS) have no username concept at
2531 all. Even in later protocols clients often attempt operations
2532 (particularly printer operations) without first validating a username
2535 >Unix security is based around username/password pairs. A unix box
2536 should not allow clients to do any substantive operation without some
2537 sort of validation. </P
2539 >The problem mostly manifests itself when the unix server is in "share
2540 level" security mode. This is the default mode as the alternative
2541 "user level" security mode usually forces a client to connect to the
2542 server as the same user for each connected share, which is
2543 inconvenient in many sites.</P
2545 >In "share level" security the client normally gives a username in the
2546 "session setup" protocol, but does not supply an accompanying
2547 password. The client then connects to resources using the "tree
2548 connect" protocol, and supplies a password. The problem is that the
2549 user on the PC types the username and the password in different
2550 contexts, unaware that they need to go together to give access to the
2551 server. The username is normally the one the user typed in when they
2552 "logged onto" the PC (this assumes Windows for Workgroups). The
2553 password is the one they chose when connecting to the disk or printer.</P
2555 >The user often chooses a totally different username for their login as
2556 for the drive connection. Often they also want to access different
2557 drives as different usernames. The unix server needs some way of
2558 divining the correct username to combine with each password.</P
2560 >Samba tries to avoid this problem using several methods. These succeed
2561 in the vast majority of cases. The methods include username maps, the
2562 service%user syntax, the saving of session setup usernames for later
2563 validation and the derivation of the username from the service name
2564 (either directly or via the user= option).</P
2571 NAME="AEN552">File Ownership</H2
2573 >The commonly used SMB protocols have no way of saying "you can't do
2574 that because you don't own the file". They have, in fact, no concept
2575 of file ownership at all.</P
2577 >This brings up all sorts of interesting problems. For example, when
2578 you copy a file to a unix drive, and the file is world writeable but
2579 owned by another user the file will transfer correctly but will
2580 receive the wrong date. This is because the utime() call under unix
2581 only succeeds for the owner of the file, or root, even if the file is
2582 world writeable. For security reasons Samba does all file operations
2583 as the validated user, not root, so the utime() fails. This can stuff
2584 up shared development diectories as programs like "make" will not get
2585 file time comparisons right.</P
2587 >There are several possible solutions to this problem, including
2588 username mapping, and forcing a specific username for particular
2596 NAME="AEN557">Passwords</H2
2598 >Many SMB clients uppercase passwords before sending them. I have no
2599 idea why they do this. Interestingly WfWg uppercases the password only
2600 if the server is running a protocol greater than COREPLUS, so
2601 obviously it isn't just the data entry routines that are to blame.</P
2603 >Unix passwords are case sensitive. So if users use mixed case
2604 passwords they are in trouble.</P
2606 >Samba can try to cope with this by either using the "password level"
2607 option which causes Samba to try the offered password with up to the
2608 specified number of case changes, or by using the "password server"
2609 option which allows Samba to do its validation via another machine
2610 (typically a WinNT server).</P
2612 >Samba supports the password encryption method used by SMB
2613 clients. Note that the use of password encryption in Microsoft
2614 networking leads to password hashes that are "plain text equivalent".
2615 This means that it is *VERY* important to ensure that the Samba
2616 smbpasswd file containing these password hashes is only readable
2617 by the root user. See the documentation ENCRYPTION.txt for more
2625 NAME="AEN563">Locking</H2
2627 >The locking calls available under a DOS/Windows environment are much
2628 richer than those available in unix. This means a unix server (like
2629 Samba) choosing to use the standard fcntl() based unix locking calls
2630 to implement SMB locking has to improvise a bit.</P
2632 >One major problem is that dos locks can be in a 32 bit (unsigned)
2633 range. Unix locking calls are 32 bits, but are signed, giving only a 31
2634 bit range. Unfortunately OLE2 clients use the top bit to select a
2635 locking range used for OLE semaphores.</P
2637 >To work around this problem Samba compresses the 32 bit range into 31
2638 bits by appropriate bit shifting. This seems to work but is not
2639 ideal. In a future version a separate SMB lockd may be added to cope
2640 with the problem.</P
2642 >It also doesn't help that many unix lockd daemons are very buggy and
2643 crash at the slightest provocation. They normally go mostly unused in
2644 a unix environment because few unix programs use byte range
2645 locking. The stress of huge numbers of lock requests from dos/windows
2646 clients can kill the daemon on some systems.</P
2648 >The second major problem is the "opportunistic locking" requested by
2649 some clients. If a client requests opportunistic locking then it is
2650 asking the server to notify it if anyone else tries to do something on
2651 the same file, at which time the client will say if it is willing to
2652 give up its lock. Unix has no simple way of implementing
2653 opportunistic locking, and currently Samba has no support for it.</P
2660 NAME="AEN570">Deny Modes</H2
2662 >When a SMB client opens a file it asks for a particular "deny mode" to
2663 be placed on the file. These modes (DENY_NONE, DENY_READ, DENY_WRITE,
2664 DENY_ALL, DENY_FCB and DENY_DOS) specify what actions should be
2665 allowed by anyone else who tries to use the file at the same time. If
2666 DENY_READ is placed on the file, for example, then any attempt to open
2667 the file for reading should fail.</P
2669 >Unix has no equivalent notion. To implement this Samba uses either lock
2670 files based on the files inode and placed in a separate lock
2671 directory or a shared memory implementation. The lock file method
2672 is clumsy and consumes processing and file resources,
2673 the shared memory implementation is vastly prefered and is turned on
2674 by default for those systems that support it.</P
2681 NAME="AEN574">Trapdoor UIDs</H2
2683 >A SMB session can run with several uids on the one socket. This
2684 happens when a user connects to two shares with different
2685 usernames. To cope with this the unix server needs to switch uids
2686 within the one process. On some unixes (such as SCO) this is not
2687 possible. This means that on those unixes the client is restricted to
2690 >Note that you can also get the "trapdoor uid" message for other
2691 reasons. Please see the FAQ for details.</P
2698 NAME="AEN578">Port numbers</H2
2700 >There is a convention that clients on sockets use high "unprivilaged"
2701 port numbers (>1000) and connect to servers on low "privilaged" port
2702 numbers. This is enforced in Unix as non-root users can't open a
2703 socket for listening on port numbers less than 1000.</P
2705 >Most PC based SMB clients (such as WfWg and WinNT) don't follow this
2706 convention completely. The main culprit is the netbios nameserving on
2707 udp port 137. Name query requests come from a source port of 137. This
2708 is a problem when you combine it with the common firewalling technique
2709 of not allowing incoming packets on low port numbers. This means that
2710 these clients can't query a netbios nameserver on the other side of a
2711 low port based firewall.</P
2713 >The problem is more severe with netbios node status queries. I've
2714 found that WfWg, Win95 and WinNT3.5 all respond to netbios node status
2715 queries on port 137 no matter what the source port was in the
2716 request. This works between machines that are both using port 137, but
2717 it means it's not possible for a unix user to do a node status request
2718 to any of these OSes unless they are running as root. The answer comes
2719 back, but it goes to port 137 which the unix user can't listen
2720 on. Interestingly WinNT3.1 got this right - it sends node status
2721 responses back to the source port in the request.</P
2728 NAME="AEN583">Protocol Complexity</H2
2730 >There are many "protocol levels" in the SMB protocol. It seems that
2731 each time new functionality was added to a Microsoft operating system,
2732 they added the equivalent functions in a new protocol level of the SMB
2733 protocol to "externalise" the new capabilities.</P
2735 >This means the protocol is very "rich", offering many ways of doing
2736 each file operation. This means SMB servers need to be complex and
2737 large. It also means it is very difficult to make them bug free. It is
2738 not just Samba that suffers from this problem, other servers such as
2739 WinNT don't support every variation of every call and it has almost
2740 certainly been a headache for MS developers to support the myriad of
2741 SMB calls that are available.</P
2743 >There are about 65 "top level" operations in the SMB protocol (things
2744 like SMBread and SMBwrite). Some of these include hundreds of
2745 sub-functions (SMBtrans has at least 120 sub-functions, like
2746 DosPrintQAdd and NetSessionEnum). All of them take several options
2747 that can change the way they work. Many take dozens of possible
2748 "information levels" that change the structures that need to be
2749 returned. Samba supports all but 2 of the "top level" functions. It
2750 supports only 8 (so far) of the SMBtrans sub-functions. Even NT
2751 doesn't support them all.</P
2753 >Samba currently supports up to the "NT LM 0.12" protocol, which is the
2754 one preferred by Win95 and WinNT3.5. Luckily this protocol level has a
2755 "capabilities" field which specifies which super-duper new-fangled
2756 options the server suports. This helps to make the implementation of
2757 this protocol level much easier.</P
2759 >There is also a problem with the SMB specications. SMB is a X/Open
2760 spec, but the X/Open book is far from ideal, and fails to cover many
2761 important issues, leaving much to the imagination. Microsoft recently
2762 renamed the SMB protocol CIFS (Common Internet File System) and have
2763 published new specifications. These are far superior to the old
2764 X/Open documents but there are still undocumented calls and features.
2765 This specification is actively being worked on by a CIFS developers
2766 mailing list hosted by Microsft.</P
2773 NAME="TRACING">Tracing samba system calls</H1
2775 >This file describes how to do a system call trace on Samba to work out
2776 what its doing wrong. This is not for the faint of heart, but if you
2777 are reading this then you are probably desperate.</P
2779 >Actually its not as bad as the the above makes it sound, just don't
2780 expect the output to be very pretty :-)</P
2782 >Ok, down to business. One of the big advantages of unix systems is
2783 that they nearly all come with a system trace utility that allows you
2784 to monitor all system calls that a program is making. This is
2785 extremely using for debugging and also helps when trying to work out
2786 why something is slower than you expect. You can use system tracing
2787 without any special compilation options. </P
2789 >The system trace utility is called different things on different
2790 systems. On Linux systems its called strace. Under SunOS 4 its called
2791 trace. Under SVR4 style systems (including solaris) its called
2792 truss. Under many BSD systems its called ktrace. </P
2794 >The first thing you should do is read the man page for your native
2795 system call tracer. In the discussion below I'll assume its called
2796 strace as strace is the only portable system tracer (its available for
2797 free for many unix types) and its also got some of the nicest
2800 >Next, try using strace on some simple commands. For example, <B
2806 >strace echo hello</B
2810 You'll notice that it produces a LOT of output. It is showing you the
2811 arguments to every system call that the program makes and the
2812 result. Very little happens in a program without a system call so you
2813 get lots of output. You'll also find that it produces a lot of
2814 "preamble" stuff showing the loading of shared libraries etc. Ignore
2815 this (unless its going wrong!)</P
2817 >For example, the only line that really matters in the <B
2830 CLASS="PROGRAMLISTING"
2831 >write(1, "hello\n", 6) = 6</PRE
2837 >all the rest is just setting up to run the program.</P
2839 >Ok, now you're familiar with strace. To use it on Samba you need to
2840 strace the running smbd daemon. The way I tend ot use it is to first
2841 login from my Windows PC to the Samba server, then use smbstatus to
2842 find which process ID that client is attached to, then as root I do
2846 > to attach to that process. I normally redirect the
2847 stderr output from this command to a file for later perusal. For
2848 example, if I'm using a csh style shell:</P
2852 >strace -f -p 3872 >& strace.out</B
2855 >or with a sh style shell:</P
2859 >strace -f -p 3872 > strace.out 2>&1</B
2862 >Note the "-f" option. This is only available on some systems, and
2863 allows you to trace not just the current process, but any children it
2864 forks. This is great for finding printing problems caused by the
2865 "print command" being wrong.</P
2867 >Once you are attached you then can do whatever it is on the client
2868 that is causing problems and you will capture all the system calls
2869 that smbd makes. </P
2871 >So how do you interpret the results? Generally I search through the
2872 output for strings that I know will appear when the problem
2873 happens. For example, if I am having touble with permissions on a file
2874 I would search for that files name in the strace output and look at
2875 the surrounding lines. Another trick is to match up file descriptor
2876 numbers and "follow" what happens to an open file until it is closed.</P
2878 >Beyond this you will have to use your initiative. To give you an idea
2879 of what you are looking for here is a piece of strace output that
2883 > is not world writeable, which
2884 causes printing to fail with Samba:</P
2893 CLASS="PROGRAMLISTING"
2894 >[pid 28268] open("/dev/null", O_RDWR) = -1 EACCES (Permission denied)
2895 [pid 28268] open("/dev/null", O_WRONLY) = -1 EACCES (Permission denied)</PRE
2901 >The process is trying to first open <TT
2905 then read-only. Both fail. This means <TT
2909 incorrect permissions.</P
2915 NAME="NTDOMAIN">NT Domain RPC's</H1
2921 NAME="AEN651">Introduction</H2
2923 >This document contains information to provide an NT workstation with login
2924 services, without the need for an NT server. It is the sgml version of <A
2925 HREF="http://mailhost.cb1.com/~lkcl/cifsntdomain.txt"
2927 >http://mailhost.cb1.com/~lkcl/cifsntdomain.txt</A
2928 >, controlled by Luke.</P
2930 >It should be possible to select a domain instead of a workgroup (in the NT
2931 workstation's TCP/IP settings) and after the obligatory reboot, type in a
2932 username, password, select a domain and successfully log in. I would
2933 appreciate any feedback on your experiences with this process, and any
2934 comments, corrections and additions to this document.</P
2936 >The packets described here can be easily derived from (and are probably
2937 better understood using) Netmon.exe. You will need to use the version
2938 of Netmon that matches your system, in order to correctly decode the
2939 NETLOGON, lsarpc and srvsvc Transact pipes. This document is derived from
2940 NT Service Pack 1 and its corresponding version of Netmon. It is intended
2941 that an annotated packet trace be produced, which will likely be more
2942 instructive than this document.</P
2944 >Also needed, to fully implement NT Domain Login Services, is the
2945 document describing the cryptographic part of the NT authentication.
2946 This document is available from comp.protocols.smb; from the ntsecurity.net
2947 digest and from the samba digest, amongst other sources.</P
2949 >A copy is available from:</P
2952 HREF="http://ntbugtraq.rc.on.ca/SCRIPTS/WA.EXE?A2=ind9708;L=ntbugtraq;O=A;P=2935"
2954 >http://ntbugtraq.rc.on.ca/SCRIPTS/WA.EXE?A2=ind9708;L=ntbugtraq;O=A;P=2935</A
2958 HREF="http://mailhost.cb1.com/~lkcl/crypt.html"
2960 >http://mailhost.cb1.com/~lkcl/crypt.html</A
2963 >A c-code implementation, provided by <A
2964 HREF="mailto:linus@incolumitas.se"
2968 of this protocol is available from:</P
2971 HREF="http://samba.org/cgi-bin/mfs/01/digest/1997/97aug/0391.html"
2973 >http://samba.org/cgi-bin/mfs/01/digest/1997/97aug/0391.html</A
2977 HREF="http://mailhost.cb1.com/~lkcl/crypt.txt"
2979 >http://mailhost.cb1.com/~lkcl/crypt.txt</A
2982 >Also used to provide debugging information is the Check Build version of
2983 NT workstation, and enabling full debugging in NETLOGON. This is
2984 achieved by setting the following REG_SZ registry key to 0x1ffffff:</P
2988 >HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters</TT
2993 >Incorrect direct editing of the registry can cause your
2994 machine to fail. Then again, so can incorrect implementation of this
2995 protocol. See "Liability:" above.</I
2998 >Bear in mind that each packet over-the-wire will have its origin in an
2999 API call. Therefore, there are likely to be structures, enumerations
3000 and defines that are usefully documented elsewhere.</P
3002 >This document is by no means complete or authoritative. Missing sections
3003 include, but are not limited to:</P
3010 >Mappings of RIDs to usernames (and vice-versa).</P
3014 >What a User ID is and what a Group ID is.</P
3018 >The exact meaning/definition of various magic constants or enumerations.</P
3022 >The reply error code and use of that error code when a
3023 workstation becomes a member of a domain (to be described later).
3024 Failure to return this error code will make the workstation report
3025 that it is already a member of the domain.</P
3029 >the cryptographic side of the NetrServerPasswordSet command,
3030 which would allow the workstation to change its password. This password is
3031 used to generate the long-term session key. [It is possible to reject this
3032 command, and keep the default workstation password].</P
3040 NAME="AEN687">Sources</H3
3048 >cket Traces from Netmonitor (Service Pack 1 and above)</TD
3052 >ul Ashton and Luke Leighton's other "NT Domain" doc.</TD
3056 >FS documentation - cifs6.txt</TD
3060 >FS documentation - cifsrap2.txt</TD
3072 NAME="AEN694">Credits</H3
3080 >Paul Ashton: loads of work with Net Monitor; understanding the NT authentication system; reference implementation of the NT domain support on which this document is originally based.</TD
3084 >Duncan Stansfield: low-level analysis of MSRPC Pipes.</TD
3088 >Linus Nordberg: producing c-code from Paul's crypto spec.</TD
3092 >Windows Sourcer development team</TD
3105 NAME="AEN701">Notes and Structures</H2
3111 NAME="AEN703">Notes</H3
3118 >In the SMB Transact pipes, some "Structures", described here, appear to be
3119 4-byte aligned with the SMB header, at their start. Exactly which
3120 "Structures" need aligning is not precisely known or documented.</P
3124 >In the UDP NTLOGON Mailslots, some "Structures", described here, appear to be
3125 2-byte aligned with the start of the mailslot, at their start.</P
3129 >Domain SID is of the format S-revision-version-auth1-auth2...authN.
3130 e.g S-1-5-123-456-789-123-456. the 5 could be a sub-revision.</P
3134 >any undocumented buffer pointers must be non-zero if the string buffer it
3135 refers to contains characters. exactly what value they should be is unknown.
3136 0x0000 0002 seems to do the trick to indicate that the buffer exists. a
3137 NULL buffer pointer indicates that the string buffer is of zero length.
3138 If the buffer pointer is NULL, then it is suspected that the structure it
3139 refers to is NOT put into (or taken out of) the SMB data stream. This is
3140 empirically derived from, for example, the LSA SAM Logon response packet,
3141 where if the buffer pointer is NULL, the user information is not inserted
3142 into the data stream. Exactly what happens with an array of buffer pointers
3143 is not known, although an educated guess can be made.</P
3147 >an array of structures (a container) appears to have a count and a pointer.
3148 if the count is zero, the pointer is also zero. no further data is put
3149 into or taken out of the SMB data stream. if the count is non-zero, then
3150 the pointer is also non-zero. immediately following the pointer is the
3151 count again, followed by an array of container sub-structures. the count
3152 appears a third time after the last sub-structure.</P
3161 NAME="AEN716">Enumerations</H3
3167 NAME="AEN718">MSRPC Header type</H4
3169 >command number in the msrpc packet header</P
3173 CLASS="VARIABLELIST"
3182 >MSRPC_Response:</DT
3207 NAME="AEN738">MSRPC Packet info</H4
3209 >The meaning of these flags is undocumented</P
3213 CLASS="VARIABLELIST"
3272 NAME="AEN774">Structures</H3
3278 NAME="AEN776">VOID *</H4
3280 >sizeof VOID* is 32 bits.</P
3287 NAME="AEN779">char</H4
3289 >sizeof char is 8 bits.</P
3296 NAME="AEN782">UTIME</H4
3298 >UTIME is 32 bits, indicating time in seconds since 01jan1970. documented in cifs6.txt (section 3.5 page, page 30).</P
3305 NAME="AEN785">NTTIME</H4
3307 >NTTIME is 64 bits. documented in cifs6.txt (section 3.5 page, page 30).</P
3314 NAME="AEN788">DOM_SID (domain SID structure)</H4
3318 CLASS="VARIABLELIST"
3324 >num of sub-authorities in domain SID</P
3330 >SID revision number</P
3336 >num of sub-authorities in domain SID</P
3342 >6 bytes for domain SID - Identifier Authority.</P
3345 >UINT16[n_subauths]</DT
3348 >domain SID sub-authorities</P
3355 >Note: the domain SID is documented elsewhere.</I
3363 NAME="AEN813">STR (string)</H4
3365 >STR (string) is a char[] : a null-terminated string of ascii characters.</P
3372 NAME="AEN816">UNIHDR (unicode string header)</H4
3376 CLASS="VARIABLELIST"
3382 >length of unicode string</P
3388 >max length of unicode string</P
3394 >4 - undocumented.</P
3404 NAME="AEN831">UNIHDR2 (unicode string header plus buffer pointer)</H4
3408 CLASS="VARIABLELIST"
3414 >unicode string header</P
3420 >undocumented buffer pointer</P
3430 NAME="AEN842">UNISTR (unicode string)</H4
3434 CLASS="VARIABLELIST"
3440 >null-terminated string of unicode characters.</P
3450 NAME="AEN849">NAME (length-indicated unicode string)</H4
3454 CLASS="VARIABLELIST"
3460 >length of unicode string</P
3466 >null-terminated string of unicode characters.</P
3476 NAME="AEN860">UNISTR2 (aligned unicode string)</H4
3480 CLASS="VARIABLELIST"
3486 >padding to get unicode string 4-byte aligned with the start of the SMB header.</P
3492 >max length of unicode string</P
3498 >0 - undocumented</P
3504 >length of unicode string</P
3510 >string of uncode characters</P
3520 NAME="AEN883">OBJ_ATTR (object attributes)</H4
3524 CLASS="VARIABLELIST"
3530 >0x18 - length (in bytes) including the length field.</P
3536 >0 - root directory (pointer)</P
3542 >0 - object name (pointer)</P
3548 >0 - attributes (undocumented)</P
3554 >0 - security descriptior (pointer)</P
3560 >0 - security quality of service</P
3570 NAME="AEN910">POL_HND (LSA policy handle)</H4
3574 CLASS="VARIABLELIST"
3590 NAME="AEN917">DOM_SID2 (domain SID structure, SIDS stored in unicode)</H4
3594 CLASS="VARIABLELIST"
3606 >0 - undocumented</P
3612 >domain SID unicode string header</P
3618 >domain SID unicode string</P
3625 >Note: there is a conflict between the unicode string header and the unicode string itself as to which to use to indicate string length. this will need to be resolved.</I
3630 >Note: the SID type indicates, for example, an alias; a well-known group etc. this is documented somewhere.</I
3638 NAME="AEN940">DOM_RID (domain RID structure)</H4
3642 CLASS="VARIABLELIST"
3648 >5 - well-known SID. 1 - user SID (see ShowACLs)</P
3654 >5 - undocumented</P
3666 >0 - domain index out of above reference domains</P
3676 NAME="AEN959">LOG_INFO (server, account, client structure)</H4
3680 >Note: logon server name starts with two '\' characters and is upper case.</I
3685 >Note: account name is the logon client name from the LSA Request Challenge, with a $ on the end of it, in upper case.</I
3690 CLASS="VARIABLELIST"
3696 >undocumented buffer pointer</P
3702 >logon server unicode string</P
3708 >account name unicode string</P
3714 >sec_chan - security channel type</P
3720 >logon client machine unicode string</P
3730 NAME="AEN986">CLNT_SRV (server, client names structure)</H4
3734 >Note: logon server name starts with two '\' characters and is upper case.</I
3739 CLASS="VARIABLELIST"
3745 >undocumented buffer pointer</P
3751 >logon server unicode string</P
3757 >undocumented buffer pointer</P
3763 >logon client machine unicode string</P
3773 NAME="AEN1007">CREDS (credentials + time stamp)</H4
3777 CLASS="VARIABLELIST"
3799 NAME="AEN1018">CLNT_INFO2 (server, client structure, client credentials)</H4
3803 >Note: whenever this structure appears in a request, you must take a copy of the client-calculated credentials received, because they will beused in subsequent credential checks. the presumed intention is to
3804 maintain an authenticated request/response trail.</I
3809 CLASS="VARIABLELIST"
3815 >client and server names</P
3821 >???? padding, for 4-byte alignment with SMB header.</P
3827 >pointer to client credentials.</P
3833 >client-calculated credentials + client time</P
3843 NAME="AEN1039">CLNT_INFO (server, account, client structure, client credentials)</H4
3847 >Note: whenever this structure appears in a request, you must take a copy of the client-calculated credentials received, because they will be used in subsequent credential checks. the presumed intention is to maintain an authenticated request/response trail.</I
3852 CLASS="VARIABLELIST"
3858 >logon account info</P
3864 >client-calculated credentials + client time</P
3874 NAME="AEN1052">ID_INFO_1 (id info structure, auth level 1)</H4
3878 CLASS="VARIABLELIST"
3890 >domain name unicode header</P
3908 >user name unicode header</P
3914 >workgroup name unicode header</P
3920 >arc4 LM OWF Password</P
3926 >arc4 NT OWF Password</P
3932 >domain name unicode string</P
3938 >user name unicode string</P
3944 >workstation name unicode string</P
3954 NAME="AEN1099">SAM_INFO (sam logon/logoff id info structure)</H4
3958 >Note: presumably, the return credentials is supposedly for the server to verify that the credential chain hasn't been compromised.</I
3963 CLASS="VARIABLELIST"
3969 >client identification/authentication info</P
3975 >pointer to return credentials.</P
3981 >return credentials - ignored.</P
4005 CLASS="PROGRAMLISTING"
4006 > switch (switch_value)
4009 ID_INFO_1 id_info_1;
4021 NAME="AEN1126">GID (group id info)</H4
4025 CLASS="VARIABLELIST"
4037 >user attributes (only used by NT 3.1 and 3.51)</P
4047 NAME="AEN1137">DOM_REF (domain reference info)</H4
4051 CLASS="VARIABLELIST"
4057 >undocumented buffer pointer.</P
4063 >num referenced domains?</P
4069 >undocumented domain name buffer pointer.</P
4075 >32 - max number of entries</P
4081 >4 - num referenced domains?</P
4087 >domain name unicode string header</P
4090 >UNIHDR2[num_ref_doms-1]</DT
4093 >referenced domain unicode string headers</P
4099 >domain name unicode string</P
4102 >DOM_SID[num_ref_doms]</DT
4105 >referenced domain SIDs</P
4115 NAME="AEN1176">DOM_INFO (domain info, levels 3 and 5 are the same))</H4
4119 CLASS="VARIABLELIST"
4125 >??? padding to get 4-byte alignment with start of SMB header</P
4131 >domain name string length * 2</P
4137 >domain name string length * 2</P
4143 >undocumented domain name string buffer pointer</P
4149 >undocumented domain SID string buffer pointer</P
4155 >domain name (unicode string)</P
4171 NAME="AEN1207">USER_INFO (user logon info)</H4
4175 >Note: it would be nice to know what the 16 byte user session key is for.</I
4180 CLASS="VARIABLELIST"
4204 >password last set time</P
4210 >password can change time</P
4216 >password must change time</P
4222 >username unicode string header</P
4228 >user's full name unicode string header</P
4234 >logon script unicode string header</P
4240 >profile path unicode string header</P
4246 >home directory unicode string header</P
4252 >home directory drive unicode string header</P
4264 >bad password count</P
4288 >undocumented buffer pointer to groups.</P
4300 >user session key</P
4306 >logon server unicode string header</P
4312 >logon domain unicode string header</P
4318 >undocumented logon domain id pointer</P
4324 >40 undocumented padding bytes. future expansion?</P
4330 >0 - num_other_sids?</P
4336 >NULL - undocumented pointer to other domain SIDs.</P
4342 >username unicode string</P
4348 >user's full name unicode string</P
4354 >logon script unicode string</P
4360 >profile path unicode string</P
4366 >home directory unicode string</P
4372 >home directory drive unicode string</P
4381 >GID[num_groups]</DT
4390 >logon server unicode string</P
4396 >logon domain unicode string</P
4405 >DOM_SID[num_sids]</DT
4408 >other domain SIDs?</P
4418 NAME="AEN1364">SH_INFO_1_PTR (pointers to level 1 share info strings)</H4
4422 >Note: see cifsrap2.txt section5, page 10.</I
4431 >0 for shi1_type indicates a Disk.</TD
4435 >1 for shi1_type indicates a Print Queue.</TD
4439 >2 for shi1_type indicates a Device.</TD
4443 >3 for shi1_type indicates an IPC pipe.</TD
4447 >0x8000 0000 (top bit set in shi1_type) indicates a hidden share.</TD
4456 CLASS="VARIABLELIST"
4462 >shi1_netname - pointer to net name</P
4468 >shi1_type - type of share. 0 - undocumented.</P
4474 >shi1_remark - pointer to comment.</P
4484 NAME="AEN1387">SH_INFO_1_STR (level 1 share info strings)</H4
4488 CLASS="VARIABLELIST"
4494 >shi1_netname - unicode string of net name</P
4500 >shi1_remark - unicode string of comment.</P
4510 NAME="AEN1398">SHARE_INFO_1_CTR</H4
4512 >share container with 0 entries:</P
4516 CLASS="VARIABLELIST"
4533 >share container with > 0 entries:</P
4537 CLASS="VARIABLELIST"
4549 >non-zero - Buffer</P
4558 >SH_INFO_1_PTR[EntriesRead]</DT
4561 >share entry pointers</P
4564 >SH_INFO_1_STR[EntriesRead]</DT
4567 >share entry strings</P
4573 >padding to get unicode string 4-byte aligned with start of the SMB header.</P
4595 NAME="AEN1444">SERVER_INFO_101</H4
4599 >Note: see cifs6.txt section 6.4 - the fields described therein will be of assistance here. for example, the type listed below is the same as fServerType, which is described in 6.4.1. </I
4604 CLASS="VARIABLELIST"
4607 >SV_TYPE_WORKSTATION</DT
4610 >0x00000001 All workstations</P
4616 >0x00000002 All servers</P
4619 >SV_TYPE_SQLSERVER</DT
4622 >0x00000004 Any server running with SQL server</P
4625 >SV_TYPE_DOMAIN_CTRL</DT
4628 >0x00000008 Primary domain controller</P
4631 >SV_TYPE_DOMAIN_BAKCTRL</DT
4634 >0x00000010 Backup domain controller</P
4637 >SV_TYPE_TIME_SOURCE</DT
4640 >0x00000020 Server running the timesource service</P
4646 >0x00000040 Apple File Protocol servers</P
4652 >0x00000080 Novell servers</P
4655 >SV_TYPE_DOMAIN_MEMBER</DT
4658 >0x00000100 Domain Member</P
4661 >SV_TYPE_PRINTQ_SERVER</DT
4664 >0x00000200 Server sharing print queue</P
4667 >SV_TYPE_DIALIN_SERVER</DT
4670 >0x00000400 Server running dialin service.</P
4673 >SV_TYPE_XENIX_SERVER</DT
4676 >0x00000800 Xenix server</P
4682 >0x00001000 NT server</P
4688 >0x00002000 Server running Windows for </P
4691 >SV_TYPE_SERVER_NT</DT
4694 >0x00008000 Windows NT non DC server</P
4697 >SV_TYPE_POTENTIAL_BROWSER</DT
4700 >0x00010000 Server that can run the browser service</P
4703 >SV_TYPE_BACKUP_BROWSER</DT
4706 >0x00020000 Backup browser server</P
4709 >SV_TYPE_MASTER_BROWSER</DT
4712 >0x00040000 Master browser server</P
4715 >SV_TYPE_DOMAIN_MASTER</DT
4718 >0x00080000 Domain Master Browser server</P
4721 >SV_TYPE_LOCAL_LIST_ONLY</DT
4724 >0x40000000 Enumerate only entries marked "local"</P
4727 >SV_TYPE_DOMAIN_ENUM</DT
4730 >0x80000000 Enumerate Domains. The pszServer and pszDomain parameters must be NULL.</P
4737 CLASS="VARIABLELIST"
4743 >500 - platform_id</P
4755 >5 - major version</P
4761 >4 - minor version</P
4767 >type (SV_TYPE_... bit field)</P
4773 >pointer to comment</P
4779 >sv101_name - unicode string of server name</P
4785 >sv_101_comment - unicode string of server comment.</P
4791 >padding to get unicode string 4-byte aligned with start of the SMB header.</P
4803 NAME="AEN1570">MSRPC over Transact Named Pipe</H2
4805 >For details on the SMB Transact Named Pipe, see cifs6.txt</P
4811 NAME="AEN1573">MSRPC Pipes</H3
4813 >The MSRPC is conducted over an SMB Transact Pipe with a name of
4817 >. You must first obtain a 16 bit file handle, by
4818 sending a SMBopenX with the pipe name <TT
4822 example. You can then perform an SMB Trans,
4823 and must carry out an SMBclose on the file handle once you are finished.</P
4825 >Trans Requests must be sent with two setup UINT16s, no UINT16 params (none
4826 known about), and UINT8 data parameters sufficient to contain the MSRPC
4827 header, and MSRPC data. The first UINT16 setup parameter must be either
4828 0x0026 to indicate an RPC, or 0x0001 to indicate Set Named Pipe Handle
4829 state. The second UINT16 parameter must be the file handle for the pipe,
4832 >The Data section for an API Command of 0x0026 (RPC pipe) in the Trans
4833 Request is the RPC Header, followed by the RPC Data. The Data section for
4834 an API Command of 0x0001 (Set Named Pipe Handle state) is two bytes. The
4835 only value seen for these two bytes is 0x00 0x43.</P
4837 >MSRPC Responses are sent as response data inside standard SMB Trans
4838 responses, with the MSRPC Header, MSRPC Data and MSRPC tail.</P
4840 >It is suspected that the Trans Requests will need to be at least 2-byte
4841 aligned (probably 4-byte). This is standard practice for SMBs. It is also
4842 independent of the observed 4-byte alignments with the start of the MSRPC
4843 header, including the 4-byte alignment between the MSRPC header and the
4846 >First, an SMBtconX connection is made to the IPC$ share. The connection
4847 must be made using encrypted passwords, not clear-text. Then, an SMBopenX
4848 is made on the pipe. Then, a Set Named Pipe Handle State must be sent,
4849 after which the pipe is ready to accept API commands. Lastly, and SMBclose
4854 >lkcl/01nov97 there appear to be two additional bytes after the null-terminated \PIPE\ name for the RPC pipe. Values seen so far are
4864 CLASS="PROGRAMLISTING"
4865 > initial SMBopenX request: RPC API command 0x26 params:
4866 "\\PIPE\\lsarpc" 0x65 0x63; 0x72 0x70; 0x44 0x65;
4867 "\\PIPE\\srvsvc" 0x73 0x76; 0x4E 0x00; 0x5C 0x43;</PRE
4878 NAME="AEN1587">Header</H3
4880 >[section to be rewritten, following receipt of work by Duncan Stansfield]</P
4882 >Interesting note: if you set packed data representation to 0x0100 0000
4883 then all 4-byte and 2-byte word ordering is turned around!</P
4885 >The start of each of the NTLSA and NETLOGON named pipes begins with:</P
4897 >5 - RPC major version</P
4909 >0 - RPC minor version</P
4921 >2 - RPC response packet</P
4933 >3 - (FirstFrag bit-wise or with LastFrag)</P
4945 >0x1000 0000 - packed data representation</P
4957 >fragment length - data size (bytes) inc header and tail.</P
4969 >0 - authentication length </P
4981 >call identifier. matches 12th UINT32 of incoming RPC data.</P
4993 >allocation hint - data size (bytes) minus header and tail.</P
5005 >0 - presentation context identifier</P
5017 >0 - cancel count</P
5029 >in replies: 0 - reserved; in requests: opnum - see #defines.</P
5041 >start of data (goes on for allocation_hint bytes)</P
5047 NAME="AEN1648">RPC_Packet for request, response, bind and bind acknowledgement</H4
5051 CLASS="VARIABLELIST"
5054 >UINT8 versionmaj</DT
5057 >reply same as request (0x05)</P
5060 >UINT8 versionmin</DT
5063 >reply same as request (0x00)</P
5069 >one of the MSRPC_Type enums</P
5075 >reply same as request (0x00 for Bind, 0x03 for Request)</P
5078 >UINT32 representation</DT
5081 >reply same as request (0x00000010)</P
5084 >UINT16 fraglength</DT
5087 >the length of the data section of the SMB trans packet</P
5090 >UINT16 authlength</DT
5099 >call identifier. (e.g. 0x00149594)</P
5102 >* stub USE TvPacket</DT
5105 >the remainder of the packet depending on the "type"</P
5115 NAME="AEN1687">Interface identification</H4
5117 >the interfaces are numbered. as yet I haven't seen more than one interface used on the same pipe name srvsvc</P
5126 CLASS="PROGRAMLISTING"
5127 >abstract (0x4B324FC8, 0x01D31670, 0x475A7812, 0x88E16EBF, 0x00000003)
5128 transfer (0x8A885D04, 0x11C91CEB, 0x0008E89F, 0x6048102B, 0x00000002)</PRE
5139 NAME="AEN1692">RPC_Iface RW</H4
5143 CLASS="VARIABLELIST"
5149 >16 bytes of number</P
5155 >the interface number</P
5165 NAME="AEN1703">RPC_ReqBind RW</H4
5167 >the remainder of the packet after the header if "type" was Bind in the response header, "type" should be BindAck</P
5171 CLASS="VARIABLELIST"
5174 >UINT16 maxtsize</DT
5177 >maximum transmission fragment size (0x1630)</P
5180 >UINT16 maxrsize</DT
5183 >max receive fragment size (0x1630)</P
5186 >UINT32 assocgid</DT
5189 >associated group id (0x0)</P
5192 >UINT32 numelements</DT
5195 >the number of elements (0x1)</P
5198 >UINT16 contextid</DT
5201 >presentation context identifier (0x0)</P
5204 >UINT8 numsyntaxes</DT
5207 >the number of syntaxes (has always been 1?)(0x1)</P
5213 >4-byte alignment padding, against SMB header</P
5216 >* abstractint USE RPC_Iface</DT
5219 >num and vers. of interface client is using</P
5222 >* transferint USE RPC_Iface</DT
5225 >num and vers. of interface to use for replies</P
5235 NAME="AEN1743">RPC_Address RW</H4
5239 CLASS="VARIABLELIST"
5245 >length of the string including null terminator</P
5248 >* port USE string</DT
5251 >the string above in single byte, null terminated form</P
5261 NAME="AEN1754">RPC_ResBind RW</H4
5263 >the response to place after the header in the reply packet</P
5267 CLASS="VARIABLELIST"
5270 >UINT16 maxtsize</DT
5276 >UINT16 maxrsize</DT
5282 >UINT32 assocgid</DT
5288 >* secondaddr USE RPC_Address</DT
5291 >the address string, as described earlier</P
5297 >4-byte alignment padding, against SMB header</P
5300 >UINT8 numresults</DT
5303 >the number of results (0x01)</P
5309 >4-byte alignment padding, against SMB header</P
5315 >result (0x00 = accept)</P
5321 >reason (0x00 = no reason specified)</P
5324 >* transfersyntax USE RPC_Iface</DT
5327 >the transfer syntax from the request</P
5337 NAME="AEN1798">RPC_ReqNorm RW</H4
5339 >the remainder of the packet after the header for every other other request</P
5343 CLASS="VARIABLELIST"
5346 >UINT32 allochint</DT
5349 >the size of the stub data in bytes</P
5352 >UINT16 prescontext</DT
5355 >presentation context identifier (0x0)</P
5361 >operation number (0x15)</P
5364 >* stub USE TvPacket</DT
5367 >a packet dependent on the pipe name (probably the interface) and the op number)</P
5377 NAME="AEN1818">RPC_ResNorm RW</H4
5381 CLASS="VARIABLELIST"
5384 >UINT32 allochint</DT
5387 ># size of the stub data in bytes</P
5390 >UINT16 prescontext</DT
5393 ># presentation context identifier (same as request)</P
5396 >UINT8 cancelcount</DT
5399 ># cancel count? (0x0)</P
5405 ># 0 - one byte padding</P
5408 >* stub USE TvPacket</DT
5411 ># the remainder of the reply</P
5422 NAME="AEN1841">Tail</H3
5424 >The end of each of the NTLSA and NETLOGON named pipes ends with:</P
5428 CLASS="VARIABLELIST"
5450 NAME="AEN1853">RPC Bind / Bind Ack</H3
5452 >RPC Binds are the process of associating an RPC pipe (e.g \PIPE\lsarpc)
5453 with a "transfer syntax" (see RPC_Iface structure). The purpose for doing
5458 >Note: The RPC_ResBind SMB Transact request is sent with two uint16 setup parameters. The first is 0x0026; the second is the file handle
5459 returned by the SMBopenX Transact response.</I
5464 >Note: The RPC_ResBind members maxtsize, maxrsize and assocgid are the same in the response as the same members in the RPC_ReqBind. The
5465 RPC_ResBind member transfersyntax is the same in the response as
5471 >Note: The RPC_ResBind response member secondaddr contains the name of what is presumed to be the service behind the RPC pipe. The
5472 mapping identified so far is:</I
5477 CLASS="VARIABLELIST"
5480 >initial SMBopenX request:</DT
5483 >RPC_ResBind response:</P
5486 >"\\PIPE\\srvsvc"</DT
5489 >"\\PIPE\\ntsvcs"</P
5498 >"\\PIPE\\lsarpc"</DT
5504 >"\\PIPE\\wkssvc"</DT
5507 >"\\PIPE\\wksvcs"</P
5510 >"\\PIPE\\NETLOGON"</DT
5513 >"\\PIPE\\NETLOGON"</P
5520 >Note: The RPC_Packet fraglength member in both the Bind Request and Bind Acknowledgment must contain the length of the entire RPC data, including the RPC_Packet header.</I
5566 NAME="AEN1897">NTLSA Transact Named Pipe</H3
5568 >The sequence of actions taken on this pipe are:</P
5576 >Establish a connection to the IPC$ share (SMBtconX). use encrypted passwords.</TD
5580 >Open an RPC Pipe with the name "\\PIPE\\lsarpc". Store the file handle.</TD
5584 >Using the file handle, send a Set Named Pipe Handle state to 0x4300.</TD
5588 >Send an LSA Open Policy request. Store the Policy Handle.</TD
5592 >Using the Policy Handle, send LSA Query Info Policy requests, etc.</TD
5596 >Using the Policy Handle, send an LSA Close.</TD
5600 >Close the IPC$ share.</TD
5607 >Defines for this pipe, identifying the query are:</P
5611 CLASS="VARIABLELIST"
5614 >LSA Open Policy:</DT
5620 >LSA Query Info Policy:</DT
5626 >LSA Enumerate Trusted Domains:</DT
5632 >LSA Open Secret:</DT
5638 >LSA Lookup SIDs:</DT
5644 >LSA Lookup Names:</DT
5663 NAME="AEN1938">LSA Open Policy</H3
5667 >Note: The policy handle can be anything you like.</I
5674 NAME="AEN1942">Request</H4
5678 CLASS="VARIABLELIST"
5690 >server name - unicode string starting with two '\'s</P
5696 >object attributes</P
5702 >1 - desired access</P
5712 NAME="AEN1961">Response</H4
5716 CLASS="VARIABLELIST"
5722 >LSA policy handle</P
5728 >0 - indicates success</P
5739 NAME="AEN1972">LSA Query Info Policy</H3
5743 >Note: The info class in response must be the same as that in the request.</I
5750 NAME="AEN1976">Request</H4
5754 CLASS="VARIABLELIST"
5760 >LSA policy handle</P
5766 >info class (also a policy handle?)</P
5776 NAME="AEN1987">Response</H4
5780 CLASS="VARIABLELIST"
5786 >undocumented buffer pointer</P
5792 >info class (same as info class in request).</P
5804 CLASS="PROGRAMLISTING"
5805 >switch (info class)
5809 DOM_INFO domain info, levels 3 and 5 (are the same).
5812 return 0 - indicates success</PRE
5824 NAME="AEN2000">LSA Enumerate Trusted Domains</H3
5830 NAME="AEN2002">Request</H4
5839 NAME="AEN2005">Response</H4
5843 CLASS="VARIABLELIST"
5849 >0 - enumeration context</P
5855 >0 - entries read</P
5861 >0 - trust information</P
5867 >0x8000 001a - "no trusted domains" success code</P
5878 NAME="AEN2024">LSA Open Secret</H3
5884 NAME="AEN2026">Request</H4
5893 NAME="AEN2029">Response</H4
5897 CLASS="VARIABLELIST"
5903 >0 - undocumented</P
5909 >0 - undocumented</P
5915 >0 - undocumented</P
5921 >0 - undocumented</P
5927 >0 - undocumented</P
5932 >return 0x0C00 0034 - "no such secret" success code</P
5940 NAME="AEN2053">LSA Close</H3
5946 NAME="AEN2055">Request</H4
5950 CLASS="VARIABLELIST"
5956 >policy handle to be closed</P
5966 NAME="AEN2062">Response</H4
5970 CLASS="VARIABLELIST"
5976 >0s - closed policy handle (all zeros)</P
5981 >return 0 - indicates success</P
5989 NAME="AEN2070">LSA Lookup SIDS</H3
5993 >Note: num_entries in response must be same as num_entries in request.</I
6000 NAME="AEN2074">Request</H4
6004 CLASS="VARIABLELIST"
6010 >LSA policy handle</P
6022 >undocumented domain SID buffer pointer</P
6028 >undocumented domain name buffer pointer</P
6031 >VOID*[num_entries] undocumented domain SID pointers to be looked up.</DT
6034 >DOM_SID[num_entries] domain SIDs to be looked up.</P
6040 >completely undocumented 16 bytes.</P
6050 NAME="AEN2101">Response</H4
6054 CLASS="VARIABLELIST"
6060 >domain reference response</P
6066 >num_entries (listed above)</P
6072 >undocumented buffer pointer</P
6078 >num_entries (listed above)</P
6081 >DOM_SID2[num_entries]</DT
6084 >domain SIDs (from Request, listed above).</P
6090 >num_entries (listed above)</P
6095 >return 0 - indicates success</P
6103 NAME="AEN2129">LSA Lookup Names</H3
6107 >Note: num_entries in response must be same as num_entries in request.</I
6114 NAME="AEN2133">Request</H4
6118 CLASS="VARIABLELIST"
6124 >LSA policy handle</P
6142 >undocumented domain SID buffer pointer</P
6148 >undocumented domain name buffer pointer</P
6151 >NAME[num_entries]</DT
6154 >names to be looked up.</P
6160 >undocumented bytes - falsely translated SID structure?</P
6170 NAME="AEN2164">Response</H4
6174 CLASS="VARIABLELIST"
6180 >domain reference response</P
6186 >num_entries (listed above)</P
6192 >undocumented buffer pointer</P
6198 >num_entries (listed above)</P
6201 >DOM_RID[num_entries]</DT
6204 >domain SIDs (from Request, listed above).</P
6210 >num_entries (listed above)</P
6215 >return 0 - indicates success</P
6224 NAME="AEN2192">NETLOGON rpc Transact Named Pipe</H2
6226 >The sequence of actions taken on this pipe are:</P
6234 >tablish a connection to the IPC$ share (SMBtconX). use encrypted passwords.</TD
6238 >en an RPC Pipe with the name "\\PIPE\\NETLOGON". Store the file handle.</TD
6242 >ing the file handle, send a Set Named Pipe Handle state to 0x4300.</TD
6246 >eate Client Challenge. Send LSA Request Challenge. Store Server Challenge.</TD
6250 >lculate Session Key. Send an LSA Auth 2 Challenge. Store Auth2 Challenge.</TD
6254 >lc/Verify Client Creds. Send LSA Srv PW Set. Calc/Verify Server Creds.</TD
6258 >lc/Verify Client Creds. Send LSA SAM Logon . Calc/Verify Server Creds.</TD
6262 >lc/Verify Client Creds. Send LSA SAM Logoff. Calc/Verify Server Creds.</TD
6266 >ose the IPC$ share.</TD
6273 >Defines for this pipe, identifying the query are</P
6277 CLASS="VARIABLELIST"
6280 >LSA Request Challenge:</DT
6286 >LSA Server Password Set:</DT
6298 >LSA SAM Logoff:</DT
6310 >LSA Logon Control:</DT
6322 NAME="AEN2231">LSA Request Challenge</H3
6326 >Note: logon server name starts with two '\' characters and is upper case.</I
6331 >Note: logon client is the machine, not the user.</I
6336 >Note: the initial LanManager password hash, against which the challenge is issued, is the machine name itself (lower case). there will becalls issued (LSA Server Password Set) which will change this, later. refusing these calls allows you to always deal with the same password (i.e the LM# of the machine name in lower case).</I
6343 NAME="AEN2239">Request</H4
6347 CLASS="VARIABLELIST"
6353 >undocumented buffer pointer</P
6359 >logon server unicode string</P
6365 >logon client unicode string</P
6371 >client challenge</P
6381 NAME="AEN2258">Response</H4
6385 CLASS="VARIABLELIST"
6391 >server challenge</P
6396 >return 0 - indicates success</P
6404 NAME="AEN2266">LSA Authenticate 2</H3
6408 >Note: in between request and response, calculate the client credentials, and check them against the client-calculated credentials (this process uses the previously received client credentials).</I
6413 >Note: neg_flags in the response is the same as that in the request.</I
6418 >Note: you must take a copy of the client-calculated credentials received here, because they will be used in subsequent authentication packets.</I
6425 NAME="AEN2274">Request</H4
6429 CLASS="VARIABLELIST"
6435 >client identification info</P
6441 >client-calculated credentials</P
6447 >padding to 4-byte align with start of SMB header.</P
6453 >neg_flags - negotiated flags (usual value is 0x0000 01ff)</P
6463 NAME="AEN2293">Response</H4
6467 CLASS="VARIABLELIST"
6473 >server credentials.</P
6479 >neg_flags - same as neg_flags in request.</P
6484 >return 0 - indicates success. failure value unknown.</P
6492 NAME="AEN2305">LSA Server Password Set</H3
6496 >Note: the new password is suspected to be a DES encryption using the old password to generate the key.</I
6501 >Note: in between request and response, calculate the client credentials, and check them against the client-calculated credentials (this process uses the previously received client credentials).</I
6506 >Note: the server credentials are constructed from the client-calculated credentials and the client time + 1 second.</I
6511 >Note: you must take a copy of the client-calculated credentials received here, because they will be used in subsequent authentication packets.</I
6518 NAME="AEN2315">Request</H4
6522 CLASS="VARIABLELIST"
6528 >client identification/authentication info</P
6534 >new password - undocumented.</P
6544 NAME="AEN2326">Response</H4
6548 CLASS="VARIABLELIST"
6554 >server credentials. server time stamp appears to be ignored.</P
6559 >return 0 - indicates success; 0xC000 006a indicates failure</P
6567 NAME="AEN2334">LSA SAM Logon</H3
6571 >Note: valid_user is True iff the username and password hash are valid for
6572 the requested domain.</I
6579 NAME="AEN2338">Request</H4
6583 CLASS="VARIABLELIST"
6589 >sam_id structure</P
6599 NAME="AEN2345">Response</H4
6603 CLASS="VARIABLELIST"
6609 >undocumented buffer pointer</P
6615 >server credentials. server time stamp appears to be ignored.</P
6627 CLASS="PROGRAMLISTING"
6630 UINT16 3 - switch value indicating USER_INFO structure.
6631 VOID* non-zero - pointer to USER_INFO structure
6632 USER_INFO user logon information
6634 UINT32 1 - Authoritative response; 0 - Non-Auth?
6636 return 0 - indicates success
6640 UINT16 0 - switch value. value to indicate no user presumed.
6641 VOID* 0x0000 0000 - indicates no USER_INFO structure.
6643 UINT32 1 - Authoritative response; 0 - Non-Auth?
6645 return 0xC000 0064 - NT_STATUS_NO_SUCH_USER.
6658 NAME="AEN2358">LSA SAM Logoff</H3
6662 >Note: presumably, the SAM_INFO structure is validated, and a (currently
6663 undocumented) error code returned if the Logoff is invalid.</I
6670 NAME="AEN2362">Request</H4
6674 CLASS="VARIABLELIST"
6680 >sam_id structure</P
6690 NAME="AEN2369">Response</H4
6694 CLASS="VARIABLELIST"
6700 >undocumented buffer pointer</P
6706 >server credentials. server time stamp appears to be ignored.</P
6711 >return 0 - indicates success. undocumented failure indication.</P
6720 NAME="AEN2381">\\MAILSLOT\NET\NTLOGON</H2
6724 >Note: mailslots will contain a response mailslot, to which the response
6725 should be sent. the target NetBIOS name is REQUEST_NAME<20>, where
6726 REQUEST_NAME is the name of the machine that sent the request.</I
6733 NAME="AEN2385">Query for PDC</H3
6737 >Note: NTversion, LMNTtoken, LM20token in response are the same as those given in the request.</I
6744 NAME="AEN2389">Request</H4
6748 CLASS="VARIABLELIST"
6754 >0x0007 - Query for PDC</P
6766 >response mailslot</P
6772 >padding to 2-byte align with start of mailslot.</P
6806 NAME="AEN2424">Response</H4
6810 CLASS="VARIABLELIST"
6816 >0x000A - Respose to Query for PDC</P
6822 >machine name (in uppercase)</P
6828 >padding to 2-byte align with start of mailslot.</P
6846 >NTversion (same as received in request)</P
6852 >LMNTtoken (same as received in request)</P
6858 >LM20token (same as received in request)</P
6869 NAME="AEN2459">SAM Logon</H3
6873 >Note: machine name in response is preceded by two '\' characters.</I
6878 >Note: NTversion, LMNTtoken, LM20token in response are the same as those given in the request.</I
6883 >Note: user name in the response is presumably the same as that in the request.</I
6890 NAME="AEN2467">Request</H4
6894 CLASS="VARIABLELIST"
6900 >0x0012 - SAM Logon</P
6924 >response mailslot</P
6930 >alloweable account</P
6942 >domain SID, of sid_size bytes.</P
6948 >???? padding to 4? 2? -byte align with start of mailslot.</P
6976 NAME="AEN2518">Response</H4
6980 CLASS="VARIABLELIST"
6986 >0x0013 - Response to SAM Logon</P
6998 >user name - workstation trust account</P
7034 NAME="AEN2549">SRVSVC Transact Named Pipe</H2
7036 >Defines for this pipe, identifying the query are:</P
7040 CLASS="VARIABLELIST"
7049 >Net Server Get Info</DT
7061 NAME="AEN2561">Net Share Enum</H3
7065 >Note: share level and switch value in the response are presumably the same as those in the request.</I
7070 >Note: cifsrap2.txt (section 5) may be of limited assistance here.</I
7077 NAME="AEN2567">Request</H4
7081 CLASS="VARIABLELIST"
7087 >pointer (to server name?)</P
7099 >padding to get unicode string 4-byte aligned with the start of the SMB header.</P
7117 >pointer to SHARE_INFO_1_CTR</P
7120 >SHARE_INFO_1_CTR</DT
7123 >share info with 0 entries</P
7129 >preferred maximum length (0xffff ffff)</P
7139 NAME="AEN2602">Response</H4
7143 CLASS="VARIABLELIST"
7161 >pointer to SHARE_INFO_1_CTR</P
7164 >SHARE_INFO_1_CTR</DT
7167 >share info (only added if share info ptr is non-zero)</P
7172 >return 0 - indicates success</P
7180 NAME="AEN2622">Net Server Get Info</H3
7184 >Note: level is the same value as in the request.</I
7191 NAME="AEN2626">Request</H4
7195 CLASS="VARIABLELIST"
7217 NAME="AEN2637">Response</H4
7221 CLASS="VARIABLELIST"
7233 >pointer to SERVER_INFO_101</P
7236 >SERVER_INFO_101</DT
7239 >server info (only added if server info ptr is non-zero)</P
7244 >return 0 - indicates success</P
7253 NAME="AEN2653">Cryptographic side of NT Domain Authentication</H2
7259 NAME="AEN2655">Definitions</H3
7263 CLASS="VARIABLELIST"
7269 >Intel byte ordered addition of corresponding 4 byte words in arrays A1 and A2</P
7275 >DES ECB encryption of 8 byte data D using 7 byte key K</P
7293 >md4(machine_password) == md4(lsadump $machine.acc) ==
7294 pwdump(machine$) (initially) == md4(lmowf(unicode(machine)))</P
7297 >ARC4(K,Lk,D,Ld)</DT
7300 >ARC4 encryption of data D of length Ld with key K of length Lk</P
7306 >subset of v from bytes m to n, optionally padded with zeroes to length l</P
7312 >E(K[7..7,7],E(K[0..6],D)) computes a credential</P
7318 >4 byte current time</P
7324 >8 byte client and server challenges Rc,Rs: 8 byte client and server credentials</P
7334 NAME="AEN2698">Protocol</H3
7336 >C->S ReqChal,Cc S->C Cs</P
7338 >C & S compute session key Ks = E(PW[9..15],E(PW[0..6],Add(Cc,Cs)))</P
7340 >C: Rc = Cred(Ks,Cc) C->S Authenticate,Rc S: Rs = Cred(Ks,Cs),
7341 assert(Rc == Cred(Ks,Cc)) S->C Rs C: assert(Rs == Cred(Ks,Cs))</P
7343 >On joining the domain the client will optionally attempt to change its
7344 password and the domain controller may refuse to update it depending
7345 on registry settings. This will also occur weekly afterwards.</P
7347 >C: Tc = Time(), Rc' = Cred(Ks,Rc+Tc) C->S ServerPasswordSet,Rc',Tc,
7348 arc4(Ks[0..7,16],lmowf(randompassword()) C: Rc = Cred(Ks,Rc+Tc+1) S:
7349 assert(Rc' == Cred(Ks,Rc+Tc)), Ts = Time() S: Rs' = Cred(Ks,Rs+Tc+1)
7350 S->C Rs',Ts C: assert(Rs' == Cred(Ks,Rs+Tc+1)) S: Rs = Rs'</P
7352 >User: U with password P wishes to login to the domain (incidental data
7353 such as workstation and domain omitted)</P
7355 >C: Tc = Time(), Rc' = Cred(Ks,Rc+Tc) C->S NetLogonSamLogon,Rc',Tc,U,
7356 arc4(Ks[0..7,16],16,ntowf(P),16), arc4(Ks[0..7,16],16,lmowf(P),16) S:
7357 assert(Rc' == Cred(Ks,Rc+Tc)) assert(passwords match those in SAM) S:
7360 >S->C Cred(Ks,Cred(Ks,Rc+Tc+1)),userinfo(logon script,UID,SIDs,etc) C:
7361 assert(Rs == Cred(Ks,Cred(Rc+Tc+1)) C: Rc = Cred(Ks,Rc+Tc+1)</P
7368 NAME="AEN2708">Comments</H3
7370 >On first joining the domain the session key could be computed by
7371 anyone listening in on the network as the machine password has a well
7372 known value. Until the machine is rebooted it will use this session
7373 key to encrypt NT and LM one way functions of passwords which are
7374 password equivalents. Any user who logs in before the machine has been
7375 rebooted a second time will have their password equivalent exposed. Of
7376 course the new machine password is exposed at this time anyway.</P
7378 >None of the returned user info such as logon script, profile path and
7379 SIDs *appear* to be protected by anything other than the TCP checksum.</P
7381 >The server time stamps appear to be ignored.</P
7383 >The client sends a ReturnAuthenticator in the SamLogon request which I
7384 can't find a use for. However its time is used as the timestamp
7385 returned by the server.</P
7387 >The password OWFs should NOT be sent over the network reversibly
7388 encrypted. They should be sent using ARC4(Ks,md4(owf)) with the server
7389 computing the same function using the owf values in the SAM.</P
7397 NAME="AEN2715">SIDs and RIDs</H2
7399 >SIDs and RIDs are well documented elsewhere.</P
7401 >A SID is an NT Security ID (see DOM_SID structure). They are of the form:</P
7409 >revision-NN-SubAuth1-SubAuth2-SubAuth3... </TD
7413 >revision-0xNNNNNNNNNNNN-SubAuth1-SubAuth2-SubAuth3...</TD
7420 >currently, the SID revision is 1.
7421 The Sub-Authorities are known as Relative IDs (RIDs).</P
7427 NAME="AEN2723">Well-known SIDs</H3
7433 NAME="AEN2725">Universal well-known SIDs</H4
7437 CLASS="VARIABLELIST"
7458 >Creator Owner ID</DT
7464 >Creator Group ID</DT
7470 >Creator Owner Server ID</DT
7476 >Creator Group Server ID</DT
7482 >(Non-unique IDs)</DT
7495 NAME="AEN2760">NT well-known SIDs</H4
7499 CLASS="VARIABLELIST"
7538 >AnonymousLogon(aka null logon session)</DT
7550 >ServerLogon(aka domain controller account)</DT
7562 >(NT non-unique IDs)</DT
7568 >(Built-in domain)</DT
7582 NAME="AEN2811">Well-known RIDS</H3
7584 >A RID is a sub-authority value, as part of either a SID, or in the case
7585 of Group RIDs, part of the DOM_GID structure, in the USER_INFO_1
7586 structure, in the LSA SAM Logon response.</P
7592 NAME="AEN2814">Well-known RID users</H4
7596 >DOMAIN_USER_RID_ADMIN</P
7608 >DOMAIN_USER_RID_GUEST</P
7623 NAME="AEN2828">Well-known RID groups</H4
7627 > DOMAIN_GROUP_RID_ADMINS</P
7639 > DOMAIN_GROUP_RID_USERS</P
7651 > DOMAIN_GROUP_RID_GUESTS</P
7666 NAME="AEN2846">Well-known RID aliases</H4
7670 > DOMAIN_ALIAS_RID_ADMINS</P
7682 > DOMAIN_ALIAS_RID_USERS</P
7694 > DOMAIN_ALIAS_RID_GUESTS</P
7706 > DOMAIN_ALIAS_RID_POWER_USERS</P
7718 > DOMAIN_ALIAS_RID_ACCOUNT_OPS</P
7730 > DOMAIN_ALIAS_RID_SYSTEM_OPS</P
7742 > DOMAIN_ALIAS_RID_PRINT_OPS</P
7754 > DOMAIN_ALIAS_RID_BACKUP_OPS</P
7766 > DOMAIN_ALIAS_RID_REPLICATOR</P
7783 NAME="PRINTING">Samba Printing Internals</H1
7789 NAME="AEN2895">Abstract</H2
7791 >The purpose of this document is to provide some insight into
7792 Samba's printing functionality and also to describe the semantics
7793 of certain features of Windows client printing.</P
7800 NAME="AEN2898">Printing Interface to Various Back ends</H2
7802 >Samba uses a table of function pointers to seven functions. The
7803 function prototypes are defined in the <TT
7806 > structure declared
7816 >retrieve the contents of a print queue</P
7820 >pause the print queue</P
7824 >resume a paused print queue</P
7828 >delete a job from the queue</P
7832 >pause a job in the print queue</P
7836 >result a paused print job in the queue</P
7840 >submit a job to the print queue</P
7844 >Currently there are only two printing back end implementations
7851 >a generic set of functions for working with standard UNIX
7852 printing subsystems</P
7856 >a set of CUPS specific functions (this is only enabled if
7857 the CUPS libraries were located at compile time).</P
7866 NAME="AEN2924">Print Queue TDB's</H2
7868 >Samba provides periodic caching of the output from the "lpq command"
7869 for performance reasons. This cache time is configurable in seconds.
7870 Obviously the longer the cache time the less often smbd will be
7871 required to exec a copy of lpq. However, the accuracy of the print
7872 queue contents displayed to clients will be diminished as well.</P
7874 >The list of currently opened print queue TDB's can be found
7875 be examining the list of tdb_print_db structures ( see print_db_head
7876 in printing.c ). A queue TDB is opened using the wrapper function
7877 printing.c:get_print_db_byname(). The function ensures that smbd
7878 does not open more than MAX_PRINT_DBS_OPEN in an effort to prevent
7879 a large print server from exhausting all available file descriptors.
7880 If the number of open queue TDB's exceeds the MAX_PRINT_DBS_OPEN
7881 limit, smbd falls back to a most recently used algorithm for maintaining
7882 a list of open TDB's.</P
7884 >There are two ways in which a a print job can be entered into
7885 a print queue's TDB. The first is to submit the job from a Windows
7886 client which will insert the job information directly into the TDB.
7887 The second method is to have the print job picked up by executing the
7897 CLASS="PROGRAMLISTING"
7898 >/* included from printing.h */
7900 pid_t pid; /* which process launched the job */
7901 int sysjob; /* the system (lp) job number */
7902 int fd; /* file descriptor of open file if open */
7903 time_t starttime; /* when the job started spooling */
7904 int status; /* the status of this job */
7905 size_t size; /* the size of the job so far */
7906 int page_count; /* then number of pages so far */
7907 BOOL spooled; /* has it been sent to the spooler yet? */
7908 BOOL smbjob; /* set if the job is a SMB job */
7909 fstring filename; /* the filename used to spool the file */
7910 fstring jobname; /* the job name given to us by the client */
7911 fstring user; /* the user who started the job */
7912 fstring queuename; /* service number of printer for this job */
7913 NT_DEVICEMODE *nt_devmode;
7920 >The current manifestation of the printjob structure contains a field
7921 for the UNIX job id returned from the "lpq command" and a Windows job
7922 ID (32-bit bounded by PRINT_MAX_JOBID). When a print job is returned
7923 by the "lpq command" that does not match an existing job in the queue's
7924 TDB, a 32-bit job ID above the <*vance doesn't know what word is missing here*> is generating by adding UNIX_JOB_START to
7925 the id reported by lpq.</P
7927 >In order to match a 32-bit Windows jobid onto a 16-bit lanman print job
7928 id, smbd uses an in memory TDB to match the former to a number appropriate
7929 for old lanman clients.</P
7931 >When updating a print queue, smbd will perform the following
7932 steps ( refer to <TT
7934 >print.c:print_queue_update()</TT
7942 >Check to see if another smbd is currently in
7943 the process of updating the queue contents by checking the pid
7953 If so, then do not update the TDB.</P
7957 >Lock the mutex entry in the TDB and store our own pid.
7958 Check that this succeeded, else fail.</P
7962 >Store the updated time stamp for the new cache
7967 >Retrieve the queue listing via "lpq command"</P
7978 CLASS="PROGRAMLISTING"
7979 > foreach job in the queue
7981 if the job is a UNIX job, create a new entry;
7982 if the job has a Windows based jobid, then
7984 Lookup the record by the jobid;
7985 if the lookup failed, then
7986 treat it as a UNIX job;
7988 update the job status only
7998 >Delete any jobs in the TDB that are not
7999 in the in the lpq listing</P
8003 >Store the print queue status in the TDB</P
8007 >update the cache time stamp again</P
8011 >Note that it is the contents of this TDB that is returned to Windows
8012 clients and not the actual listing from the "lpq command".</P
8014 >The NT_DEVICEMODE stored as part of the printjob structure is used to
8015 store a pointer to a non-default DeviceMode associated with the print
8016 job. The pointer will be non-null when the client included a Device
8017 Mode in the OpenPrinterEx() call and subsequently submitted a job for
8018 printing on that same handle. If the client did not include a Device
8019 Mode in the OpenPrinterEx() request, the nt_devmode field is NULL
8020 and the job has the printer's device mode associated with it by default.</P
8022 >Only non-default Device Mode are stored with print jobs in the print
8023 queue TDB. Otherwise, the Device Mode is obtained from the printer
8024 object when the client issues a GetJob(level == 2) request.</P
8031 NAME="AEN2958">ChangeID & Client Caching of Printer Information</H2
8033 >[To be filled in later]</P
8040 NAME="AEN2961">Windows NT/2K Printer Change Notify</H2
8042 >When working with Windows NT+ clients, it is possible for a
8043 print server to use RPC to send asynchronous change notification
8044 events to clients for certain printer and print job attributes.
8045 This can be useful when the client needs to know that a new
8046 job has been added to the queue for a given printer or that the
8047 driver for a printer has been changed. Note that this is done
8048 entirely orthogonal to cache updates based on a new ChangeID for
8049 a printer object.</P
8051 >The basic set of RPC's used to implement change notification are</P
8057 >RemoteFindFirstPrinterChangeNotifyEx ( RFFPCN )</P
8061 >RemoteFindNextPrinterChangeNotifyEx ( RFNPCN )</P
8065 >FindClosePrinterChangeNotify( FCPCN )</P
8069 >ReplyOpenPrinter</P
8073 >ReplyClosePrinter</P
8077 >RouteRefreshPrinterChangeNotify ( RRPCN )</P
8081 >One additional RPC is available to a server, but is never used by the
8082 Windows spooler service:</P
8088 >RouteReplyPrinter()</P
8092 >The opnum for all of these RPC's are defined in include/rpc_spoolss.h</P
8094 >Windows NT print servers use a bizarre method of sending print
8095 notification event to clients. The process of registering a new change
8096 notification handle is as follows. The 'C' is for client and the
8097 'S' is for server. All error conditions have been eliminated.</P
8106 CLASS="PROGRAMLISTING"
8107 >C: Obtain handle to printer or to the printer
8108 server via the standard OpenPrinterEx() call.
8109 S: Respond with a valid handle to object
8111 C: Send a RFFPCN request with the previously obtained
8112 handle with either (a) set of flags for change events
8113 to monitor, or (b) a PRINTER_NOTIFY_OPTIONS structure
8114 containing the event information to monitor. The windows
8115 spooler has only been observed to use (b).
8116 S: The <* another missing word*> opens a new TCP session to the client (thus requiring
8117 all print clients to be CIFS servers as well) and sends
8118 a ReplyOpenPrinter() request to the client.
8119 C: The client responds with a printer handle that can be used to
8120 send event notification messages.
8121 S: The server replies success to the RFFPCN request.
8123 C: The windows spooler follows the RFFPCN with a RFNPCN
8124 request to fetch the current values of all monitored
8126 S: The server replies with an array SPOOL_NOTIFY_INFO_DATA
8127 structures (contained in a SPOOL_NOTIFY_INFO structure).
8129 C: If the change notification handle is ever released by the
8130 client via a FCPCN request, the server sends a ReplyClosePrinter()
8131 request back to the client first. However a request of this
8132 nature from the client is often an indication that the previous
8133 notification event was not marshalled correctly by the server
8134 or a piece of data was wrong.
8135 S: The server closes the internal change notification handle
8136 (POLICY_HND) and does not send any further change notification
8137 events to the client for that printer or job.</PRE
8143 >The current list of notification events supported by Samba can be
8144 found by examining the internal tables in srv_spoolss_nt.c</P
8150 >printer_notify_table[]</P
8154 >job_notify_table[]</P
8158 >When an event occurs that could be monitored, smbd sends a message
8159 to itself about the change. The list of events to be transmitted
8160 are queued by the smbd process sending the message to prevent an
8161 overload of TDB usage and the internal message is sent during smbd's
8162 idle loop (refer to printing/notify.c and the functions
8163 send_spoolss_notify2_msg() and print_notify_send_messages() ).</P
8165 >The decision of whether or not the change is to be sent to connected
8166 clients is made by the routine which actually sends the notification.
8167 ( refer to srv_spoolss_nt.c:recieve_notify2_message() ).</P
8169 >Because it possible to receive a listing of multiple changes for
8170 multiple printers, the notification events must be split into
8171 categories by the printer name. This makes it possible to group
8172 multiple change events to be sent in a single RPC according to the
8173 printer handle obtained via a ReplyOpenPrinter().</P
8175 >The actual change notification is performed using the RRPCN request
8176 RPC. This packet contains</P
8182 >the printer handle registered with the
8183 client's spooler on which the change occurred</P
8187 >The change_low value which was sent as part
8188 of the last RFNPCN request from the client</P
8192 >The SPOOL_NOTIFY_INFO container with the event
8199 >SPOOL_NOTIFY_INFO</TT
8206 >the version and flags field are predefined
8207 and should not be changed</P
8211 >The count field is the number of entries
8212 in the SPOOL_NOTIFY_INFO_DATA array</P
8218 >SPOOL_NOTIFY_INFO_DATA</TT
8219 > entries contain:</P
8225 >The type defines whether or not this event
8226 is for a printer or a print job</P
8230 >The field is the flag identifying the event</P
8234 >the notify_data union contains the new valuie of the
8239 >The enc_type defines the size of the structure for marshalling
8240 and unmarshalling</P
8244 >(a) the id must be 0 for a printer event on a printer handle.
8245 (b) the id must be the job id for an event on a printer job
8246 (c) the id must be the matching number of the printer index used
8247 in the response packet to the RFNPCN when using a print server
8248 handle for notification. Samba currently uses the snum of
8249 the printer for this which can break if the list of services
8250 has been modified since the notification handle was registered.</P
8254 >The size is either (a) the string length in UNICODE for strings,
8255 (b) the size in bytes of the security descriptor, or (c) 0 for
8265 NAME="WINS">Samba WINS Internals</H1
8271 NAME="AEN3032">WINS Failover</H2
8273 >The current Samba codebase possesses the capability to use groups of WINS
8274 servers that share a common namespace for NetBIOS name registration and
8275 resolution. The formal parameter syntax is</P
8284 CLASS="PROGRAMLISTING"
8285 > WINS_SERVER_PARAM = SERVER [ SEPARATOR SERVER_LIST ]
8286 WINS_SERVER_PARAM = "wins server"
8288 ADDR = ip_addr | fqdn
8290 SEPARATOR = comma | \s+
8291 SERVER_LIST = SERVER [ SEPARATOR SERVER_LIST ]</PRE
8297 >A simple example of a valid wins server setting is</P
8306 CLASS="PROGRAMLISTING"
8308 wins server = 192.168.1.2 192.168.1.3</PRE
8314 >In the event that no TAG is defined in for a SERVER in the list, smbd assigns a default
8315 TAG of "*". A TAG is used to group servers of a shared NetBIOS namespace together. Upon
8316 startup, nmbd will attempt to register the netbios name value with one server in each
8319 >An example using tags to group WINS servers together is show here. Note that the use of
8320 interface names in the tags is only by convention and is not a technical requirement.</P
8329 CLASS="PROGRAMLISTING"
8331 wins server = 192.168.1.2:eth0 192.168.1.3:eth0 192.168.2.2:eth1</PRE
8337 >Using this configuration, nmbd would attempt to register the server's NetBIOS name
8338 with one WINS server in each group. Because the "eth0" group has two servers, the
8339 second server would only be used when a registration (or resolution) request to
8340 the first server in that group timed out.</P
8342 >NetBIOS name resolution follows a similar pattern as name registration. When resolving
8343 a NetBIOS name via WINS, smbd and other Samba programs will attempt to query a single WINS
8344 server in a tagged group until either a positive response is obtained at least once or
8345 until a server from every tagged group has responded negatively to the name query request.
8346 If a timeout occurs when querying a specific WINS server, that server is marked as down to
8347 prevent further timeouts and the next server in the WINS group is contacted. Once marked as
8348 dead, Samba will not attempt to contact that server for name registration/resolution queries
8349 for a period of 10 minutes.</P