fixing typos spotted by eagle-eye-vance
[kai/samba.git] / docs / htmldocs / Samba-Developers-Guide.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
2 <HTML
3 ><HEAD
4 ><TITLE
5 >SAMBA Developers Guide</TITLE
6 ><META
7 NAME="GENERATOR"
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
9 "></HEAD
10 ><BODY
11 CLASS="BOOK"
12 BGCOLOR="#FFFFFF"
13 TEXT="#000000"
14 LINK="#0000FF"
15 VLINK="#840084"
16 ALINK="#0000FF"
17 ><DIV
18 CLASS="BOOK"
19 ><A
20 NAME="SAMBA-DEVELOPER-DOCUMENTATION"><DIV
21 CLASS="TITLEPAGE"
22 ><H1
23 CLASS="TITLE"
24 ><A
25 NAME="SAMBA-DEVELOPER-DOCUMENTATION">SAMBA Developers Guide</H1
26 ><H3
27 CLASS="AUTHOR"
28 ><A
29 NAME="AEN4">SAMBA Team</H3
30 ><HR></DIV
31 ><HR><H1
32 ><A
33 NAME="AEN8">Abstract</H1
34 ><P
35 ><I
36 CLASS="EMPHASIS"
37 >Last Update</I
38 > : Mon Sep 30 15:23:53 CDT 2002</P
39 ><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
45 can be found at <A
46 HREF="http://devel.samba.org/"
47 TARGET="_top"
48 >http://devel.samba.org/</A
49 >.
50 Please send updates to <A
51 HREF="mailto:jelmer@samba.org"
52 TARGET="_top"
53 >jelmer@samba.org</A
54 >.</P
55 ><P
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"
60 TARGET="_top"
61 >http://www.fsf.org/licenses/gpl.txt</A
62 ></P
63 ><DIV
64 CLASS="TOC"
65 ><DL
66 ><DT
67 ><B
68 >Table of Contents</B
69 ></DT
70 ><DT
71 ><A
72 HREF="#NETBIOS"
73 >Definition of NetBIOS Protocol and Name Resolution Modes</A
74 ></DT
75 ><DD
76 ><DL
77 ><DT
78 ><A
79 HREF="#AEN24"
80 >NETBIOS</A
81 ></DT
82 ><DT
83 ><A
84 HREF="#AEN35"
85 >BROADCAST NetBIOS</A
86 ></DT
87 ><DT
88 ><A
89 HREF="#AEN39"
90 >NBNS NetBIOS</A
91 ></DT
92 ></DL
93 ></DD
94 ><DT
95 ><A
96 HREF="#ARCHITECTURE"
97 >Samba Architecture</A
98 ></DT
99 ><DD
100 ><DL
101 ><DT
102 ><A
103 HREF="#AEN54"
104 >Introduction</A
105 ></DT
106 ><DT
107 ><A
108 HREF="#AEN65"
109 >Multithreading and Samba</A
110 ></DT
111 ><DT
112 ><A
113 HREF="#AEN70"
114 >Threading smbd</A
115 ></DT
116 ><DT
117 ><A
118 HREF="#AEN86"
119 >Threading nmbd</A
120 ></DT
121 ><DT
122 ><A
123 HREF="#AEN92"
124 >nbmd Design</A
125 ></DT
126 ></DL
127 ></DD
128 ><DT
129 ><A
130 HREF="#DEBUG"
131 >The samba DEBUG system</A
132 ></DT
133 ><DD
134 ><DL
135 ><DT
136 ><A
137 HREF="#AEN103"
138 >New Output Syntax</A
139 ></DT
140 ><DT
141 ><A
142 HREF="#AEN128"
143 >The DEBUG() Macro</A
144 ></DT
145 ><DT
146 ><A
147 HREF="#AEN151"
148 >The DEBUGADD() Macro</A
149 ></DT
150 ><DT
151 ><A
152 HREF="#AEN159"
153 >The DEBUGLVL() Macro</A
154 ></DT
155 ><DT
156 ><A
157 HREF="#AEN179"
158 >New Functions</A
159 ></DT
160 ><DD
161 ><DL
162 ><DT
163 ><A
164 HREF="#AEN181"
165 >dbgtext()</A
166 ></DT
167 ><DT
168 ><A
169 HREF="#AEN184"
170 >dbghdr()</A
171 ></DT
172 ><DT
173 ><A
174 HREF="#AEN188"
175 >format_debug_text()</A
176 ></DT
177 ></DL
178 ></DD
179 ></DL
180 ></DD
181 ><DT
182 ><A
183 HREF="#CODINGSUGGESTIONS"
184 >Coding Suggestions</A
185 ></DT
186 ><DT
187 ><A
188 HREF="#INTERNALS"
189 >Samba Internals</A
190 ></DT
191 ><DD
192 ><DL
193 ><DT
194 ><A
195 HREF="#AEN284"
196 >Character Handling</A
197 ></DT
198 ><DT
199 ><A
200 HREF="#AEN288"
201 >The new functions</A
202 ></DT
203 ><DT
204 ><A
205 HREF="#AEN317"
206 >Macros in byteorder.h</A
207 ></DT
208 ><DD
209 ><DL
210 ><DT
211 ><A
212 HREF="#AEN320"
213 >CVAL(buf,pos)</A
214 ></DT
215 ><DT
216 ><A
217 HREF="#AEN323"
218 >PVAL(buf,pos)</A
219 ></DT
220 ><DT
221 ><A
222 HREF="#AEN326"
223 >SCVAL(buf,pos,val)</A
224 ></DT
225 ><DT
226 ><A
227 HREF="#AEN329"
228 >SVAL(buf,pos)</A
229 ></DT
230 ><DT
231 ><A
232 HREF="#AEN332"
233 >IVAL(buf,pos)</A
234 ></DT
235 ><DT
236 ><A
237 HREF="#AEN335"
238 >SVALS(buf,pos)</A
239 ></DT
240 ><DT
241 ><A
242 HREF="#AEN338"
243 >IVALS(buf,pos)</A
244 ></DT
245 ><DT
246 ><A
247 HREF="#AEN341"
248 >SSVAL(buf,pos,val)</A
249 ></DT
250 ><DT
251 ><A
252 HREF="#AEN344"
253 >SIVAL(buf,pos,val)</A
254 ></DT
255 ><DT
256 ><A
257 HREF="#AEN347"
258 >SSVALS(buf,pos,val)</A
259 ></DT
260 ><DT
261 ><A
262 HREF="#AEN350"
263 >SIVALS(buf,pos,val)</A
264 ></DT
265 ><DT
266 ><A
267 HREF="#AEN353"
268 >RSVAL(buf,pos)</A
269 ></DT
270 ><DT
271 ><A
272 HREF="#AEN356"
273 >RIVAL(buf,pos)</A
274 ></DT
275 ><DT
276 ><A
277 HREF="#AEN359"
278 >RSSVAL(buf,pos,val)</A
279 ></DT
280 ><DT
281 ><A
282 HREF="#AEN362"
283 >RSIVAL(buf,pos,val)</A
284 ></DT
285 ></DL
286 ></DD
287 ><DT
288 ><A
289 HREF="#AEN365"
290 >LAN Manager Samba API</A
291 ></DT
292 ><DD
293 ><DL
294 ><DT
295 ><A
296 HREF="#AEN371"
297 >Parameters</A
298 ></DT
299 ><DT
300 ><A
301 HREF="#AEN406"
302 >Return value</A
303 ></DT
304 ></DL
305 ></DD
306 ><DT
307 ><A
308 HREF="#AEN420"
309 >Code character table</A
310 ></DT
311 ></DL
312 ></DD
313 ><DT
314 ><A
315 HREF="#PARSING"
316 >The smb.conf file</A
317 ></DT
318 ><DD
319 ><DL
320 ><DT
321 ><A
322 HREF="#AEN451"
323 >Lexical Analysis</A
324 ></DT
325 ><DD
326 ><DL
327 ><DT
328 ><A
329 HREF="#AEN472"
330 >Handling of Whitespace</A
331 ></DT
332 ><DT
333 ><A
334 HREF="#AEN484"
335 >Handling of Line Continuation</A
336 ></DT
337 ><DT
338 ><A
339 HREF="#AEN495"
340 >Line Continuation Quirks</A
341 ></DT
342 ></DL
343 ></DD
344 ><DT
345 ><A
346 HREF="#AEN515"
347 >Syntax</A
348 ></DT
349 ><DD
350 ><DL
351 ><DT
352 ><A
353 HREF="#AEN530"
354 >About params.c</A
355 ></DT
356 ></DL
357 ></DD
358 ></DL
359 ></DD
360 ><DT
361 ><A
362 HREF="#UNIX-SMB"
363 >NetBIOS in a Unix World</A
364 ></DT
365 ><DD
366 ><DL
367 ><DT
368 ><A
369 HREF="#AEN540"
370 >Introduction</A
371 ></DT
372 ><DT
373 ><A
374 HREF="#AEN544"
375 >Usernames</A
376 ></DT
377 ><DT
378 ><A
379 HREF="#AEN552"
380 >File Ownership</A
381 ></DT
382 ><DT
383 ><A
384 HREF="#AEN557"
385 >Passwords</A
386 ></DT
387 ><DT
388 ><A
389 HREF="#AEN563"
390 >Locking</A
391 ></DT
392 ><DT
393 ><A
394 HREF="#AEN570"
395 >Deny Modes</A
396 ></DT
397 ><DT
398 ><A
399 HREF="#AEN574"
400 >Trapdoor UIDs</A
401 ></DT
402 ><DT
403 ><A
404 HREF="#AEN578"
405 >Port numbers</A
406 ></DT
407 ><DT
408 ><A
409 HREF="#AEN583"
410 >Protocol Complexity</A
411 ></DT
412 ></DL
413 ></DD
414 ><DT
415 ><A
416 HREF="#TRACING"
417 >Tracing samba system calls</A
418 ></DT
419 ><DT
420 ><A
421 HREF="#NTDOMAIN"
422 >NT Domain RPC's</A
423 ></DT
424 ><DD
425 ><DL
426 ><DT
427 ><A
428 HREF="#AEN651"
429 >Introduction</A
430 ></DT
431 ><DD
432 ><DL
433 ><DT
434 ><A
435 HREF="#AEN687"
436 >Sources</A
437 ></DT
438 ><DT
439 ><A
440 HREF="#AEN694"
441 >Credits</A
442 ></DT
443 ></DL
444 ></DD
445 ><DT
446 ><A
447 HREF="#AEN701"
448 >Notes and Structures</A
449 ></DT
450 ><DD
451 ><DL
452 ><DT
453 ><A
454 HREF="#AEN703"
455 >Notes</A
456 ></DT
457 ><DT
458 ><A
459 HREF="#AEN716"
460 >Enumerations</A
461 ></DT
462 ><DT
463 ><A
464 HREF="#AEN774"
465 >Structures</A
466 ></DT
467 ></DL
468 ></DD
469 ><DT
470 ><A
471 HREF="#AEN1570"
472 >MSRPC over Transact Named Pipe</A
473 ></DT
474 ><DD
475 ><DL
476 ><DT
477 ><A
478 HREF="#AEN1573"
479 >MSRPC Pipes</A
480 ></DT
481 ><DT
482 ><A
483 HREF="#AEN1587"
484 >Header</A
485 ></DT
486 ><DT
487 ><A
488 HREF="#AEN1841"
489 >Tail</A
490 ></DT
491 ><DT
492 ><A
493 HREF="#AEN1853"
494 >RPC Bind / Bind Ack</A
495 ></DT
496 ><DT
497 ><A
498 HREF="#AEN1897"
499 >NTLSA Transact Named Pipe</A
500 ></DT
501 ><DT
502 ><A
503 HREF="#AEN1938"
504 >LSA Open Policy</A
505 ></DT
506 ><DT
507 ><A
508 HREF="#AEN1972"
509 >LSA Query Info Policy</A
510 ></DT
511 ><DT
512 ><A
513 HREF="#AEN2000"
514 >LSA Enumerate Trusted Domains</A
515 ></DT
516 ><DT
517 ><A
518 HREF="#AEN2024"
519 >LSA Open Secret</A
520 ></DT
521 ><DT
522 ><A
523 HREF="#AEN2053"
524 >LSA Close</A
525 ></DT
526 ><DT
527 ><A
528 HREF="#AEN2070"
529 >LSA Lookup SIDS</A
530 ></DT
531 ><DT
532 ><A
533 HREF="#AEN2129"
534 >LSA Lookup Names</A
535 ></DT
536 ></DL
537 ></DD
538 ><DT
539 ><A
540 HREF="#AEN2192"
541 >NETLOGON rpc Transact Named Pipe</A
542 ></DT
543 ><DD
544 ><DL
545 ><DT
546 ><A
547 HREF="#AEN2231"
548 >LSA Request Challenge</A
549 ></DT
550 ><DT
551 ><A
552 HREF="#AEN2266"
553 >LSA Authenticate 2</A
554 ></DT
555 ><DT
556 ><A
557 HREF="#AEN2305"
558 >LSA Server Password Set</A
559 ></DT
560 ><DT
561 ><A
562 HREF="#AEN2334"
563 >LSA SAM Logon</A
564 ></DT
565 ><DT
566 ><A
567 HREF="#AEN2358"
568 >LSA SAM Logoff</A
569 ></DT
570 ></DL
571 ></DD
572 ><DT
573 ><A
574 HREF="#AEN2381"
575 >\\MAILSLOT\NET\NTLOGON</A
576 ></DT
577 ><DD
578 ><DL
579 ><DT
580 ><A
581 HREF="#AEN2385"
582 >Query for PDC</A
583 ></DT
584 ><DT
585 ><A
586 HREF="#AEN2459"
587 >SAM Logon</A
588 ></DT
589 ></DL
590 ></DD
591 ><DT
592 ><A
593 HREF="#AEN2549"
594 >SRVSVC Transact Named Pipe</A
595 ></DT
596 ><DD
597 ><DL
598 ><DT
599 ><A
600 HREF="#AEN2561"
601 >Net Share Enum</A
602 ></DT
603 ><DT
604 ><A
605 HREF="#AEN2622"
606 >Net Server Get Info</A
607 ></DT
608 ></DL
609 ></DD
610 ><DT
611 ><A
612 HREF="#AEN2653"
613 >Cryptographic side of NT Domain Authentication</A
614 ></DT
615 ><DD
616 ><DL
617 ><DT
618 ><A
619 HREF="#AEN2655"
620 >Definitions</A
621 ></DT
622 ><DT
623 ><A
624 HREF="#AEN2698"
625 >Protocol</A
626 ></DT
627 ><DT
628 ><A
629 HREF="#AEN2708"
630 >Comments</A
631 ></DT
632 ></DL
633 ></DD
634 ><DT
635 ><A
636 HREF="#AEN2715"
637 >SIDs and RIDs</A
638 ></DT
639 ><DD
640 ><DL
641 ><DT
642 ><A
643 HREF="#AEN2723"
644 >Well-known SIDs</A
645 ></DT
646 ><DT
647 ><A
648 HREF="#AEN2811"
649 >Well-known RIDS</A
650 ></DT
651 ></DL
652 ></DD
653 ></DL
654 ></DD
655 ><DT
656 ><A
657 HREF="#PRINTING"
658 >Samba Printing Internals</A
659 ></DT
660 ><DD
661 ><DL
662 ><DT
663 ><A
664 HREF="#AEN2895"
665 >Abstract</A
666 ></DT
667 ><DT
668 ><A
669 HREF="#AEN2898"
670 >Printing Interface to Various Back ends</A
671 ></DT
672 ><DT
673 ><A
674 HREF="#AEN2924"
675 >Print Queue TDB's</A
676 ></DT
677 ><DT
678 ><A
679 HREF="#AEN2958"
680 >ChangeID &#38; Client Caching of Printer Information</A
681 ></DT
682 ><DT
683 ><A
684 HREF="#AEN2961"
685 >Windows NT/2K Printer Change Notify</A
686 ></DT
687 ></DL
688 ></DD
689 ><DT
690 ><A
691 HREF="#WINS"
692 >Samba WINS Internals</A
693 ></DT
694 ><DD
695 ><DL
696 ><DT
697 ><A
698 HREF="#AEN3032"
699 >WINS Failover</A
700 ></DT
701 ></DL
702 ></DD
703 ></DL
704 ></DIV
705 ><DIV
706 CLASS="CHAPTER"
707 ><HR><H1
708 ><A
709 NAME="NETBIOS">Definition of NetBIOS Protocol and Name Resolution Modes</H1
710 ><DIV
711 CLASS="SECT1"
712 ><H2
713 CLASS="SECT1"
714 ><A
715 NAME="AEN24">NETBIOS</H2
716 ><P
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
721 ><P
722
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
727 ><P
728
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
733 ><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
737 ><P
738
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
745 ><P
746
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
752 ><P
753
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
757 ><P
758
759 NetBIOS names are either UNIQUE or GROUP.  Only one application can claim a
760 UNIQUE NetBIOS name on a network.</P
761 ><P
762 >There are two kinds of NetBIOS Name resolution: Broadcast and Point-to-Point.</P
763 ></DIV
764 ><DIV
765 CLASS="SECT1"
766 ><HR><H2
767 CLASS="SECT1"
768 ><A
769 NAME="AEN35">BROADCAST NetBIOS</H2
770 ><P
771
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
777 ><P
778
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
784 ></DIV
785 ><DIV
786 CLASS="SECT1"
787 ><HR><H2
788 CLASS="SECT1"
789 ><A
790 NAME="AEN39">NBNS NetBIOS</H2
791 ><P
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 &#60;1c&#62; &#60;1d&#62; &#60;1e&#62; names all in different ways.
797 I recommend the reading of the Microsoft WINS Server Help files for full
798 details).</P
799 ><P
800
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
805 ><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
814 ><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
819 ><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
828 ><P
829
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
834 ></DIV
835 ></DIV
836 ><DIV
837 CLASS="CHAPTER"
838 ><HR><H1
839 ><A
840 NAME="ARCHITECTURE">Samba Architecture</H1
841 ><DIV
842 CLASS="SECT1"
843 ><H2
844 CLASS="SECT1"
845 ><A
846 NAME="AEN54">Introduction</H2
847 ><P
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
852 protocol. </P
853 ><P
854 >It also tries to answer some of the frequently asked questions such as:</P
855 ><P
856 ></P
857 ><OL
858 TYPE="1"
859 ><LI
860 ><P
861 >       Is Samba secure when running on Unix? The xyz platform?
862         What about the root priveliges issue?</P
863 ></LI
864 ><LI
865 ><P
866 >Pros and cons of multithreading in various parts of Samba</P
867 ></LI
868 ><LI
869 ><P
870 >Why not have a separate process for name resolution, WINS, and browsing?</P
871 ></LI
872 ></OL
873 ></DIV
874 ><DIV
875 CLASS="SECT1"
876 ><HR><H2
877 CLASS="SECT1"
878 ><A
879 NAME="AEN65">Multithreading and Samba</H2
880 ><P
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
884 ><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
891 ><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
897 ></DIV
898 ><DIV
899 CLASS="SECT1"
900 ><HR><H2
901 CLASS="SECT1"
902 ><A
903 NAME="AEN70">Threading smbd</H2
904 ><P
905 >A few problems that would arise from a threaded smbd are:</P
906 ><P
907 ></P
908 ><OL
909 TYPE="1"
910 ><LI
911 ><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
915 ></LI
916 ><LI
917 ><P
918 >       if one thread dies (eg. a seg fault) then all threads die. We can
919         immediately throw robustness out the window.</P
920 ></LI
921 ><LI
922 ><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
928 ></LI
929 ><LI
930 ><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
934 ></LI
935 ><LI
936 ><P
937 >       the per process file descriptor limit would mean that we could only
938         support a limited number of clients.</P
939 ></LI
940 ><LI
941 ><P
942 >       we couldn't use the system locking calls as the locking context of
943         fcntl() is a process, not a thread.</P
944 ></LI
945 ></OL
946 ></DIV
947 ><DIV
948 CLASS="SECT1"
949 ><HR><H2
950 CLASS="SECT1"
951 ><A
952 NAME="AEN86">Threading nmbd</H2
953 ><P
954 >This would be ideal, but gets sunk by portability requirements.</P
955 ><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
966 other method)</P
967 ><P
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
974 ><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
980 ></DIV
981 ><DIV
982 CLASS="SECT1"
983 ><HR><H2
984 CLASS="SECT1"
985 ><A
986 NAME="AEN92">nbmd Design</H2
987 ><P
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
1001 ><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
1008 ></DIV
1009 ></DIV
1010 ><DIV
1011 CLASS="CHAPTER"
1012 ><HR><H1
1013 ><A
1014 NAME="DEBUG">The samba DEBUG system</H1
1015 ><DIV
1016 CLASS="SECT1"
1017 ><H2
1018 CLASS="SECT1"
1019 ><A
1020 NAME="AEN103">New Output Syntax</H2
1021 ><P
1022 >   The syntax of a debugging log file is represented as:</P
1023 ><P
1024 ><TABLE
1025 BORDER="0"
1026 BGCOLOR="#E0E0E0"
1027 WIDTH="100%"
1028 ><TR
1029 ><TD
1030 ><PRE
1031 CLASS="PROGRAMLISTING"
1032 >  &#62;debugfile&#60; :== { &#62;debugmsg&#60; }
1033
1034   &#62;debugmsg&#60;  :== &#62;debughdr&#60; '\n' &#62;debugtext&#60;
1035
1036   &#62;debughdr&#60;  :== '[' TIME ',' LEVEL ']' FILE ':' [FUNCTION] '(' LINE ')'
1037
1038   &#62;debugtext&#60; :== { &#62;debugline&#60; }
1039
1040   &#62;debugline&#60; :== TEXT '\n'</PRE
1041 ></TD
1042 ></TR
1043 ></TABLE
1044 ></P
1045 ><P
1046 >TEXT is a string of characters excluding the newline character.</P
1047 ><P
1048 >LEVEL is the DEBUG level of the message (an integer in the range
1049                 0..10).</P
1050 ><P
1051 >TIME is a timestamp.</P
1052 ><P
1053 >FILE is the name of the file from which the debug message was
1054 generated.</P
1055 ><P
1056 >FUNCTION is the function from which the debug message was generated.</P
1057 ><P
1058 >LINE is the line number of the debug statement that generated the
1059 message.</P
1060 ><P
1061 >Basically, what that all means is:</P
1062 ><P
1063 ></P
1064 ><OL
1065 TYPE="1"
1066 ><LI
1067 ><P
1068 >A debugging log file is made up of debug messages.</P
1069 ></LI
1070 ><LI
1071 ><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
1074 ></LI
1075 ><LI
1076 ><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
1084 ></LI
1085 ><LI
1086 ><P
1087 >The message text is made up of zero or more lines, each terminated
1088 by a newline.</P
1089 ></LI
1090 ></OL
1091 ><P
1092 >Here's some example output:</P
1093 ><P
1094 ><TABLE
1095 BORDER="0"
1096 BGCOLOR="#E0E0E0"
1097 WIDTH="100%"
1098 ><TR
1099 ><TD
1100 ><PRE
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
1107 ></TD
1108 ></TR
1109 ></TABLE
1110 ></P
1111 ><P
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
1115 ></DIV
1116 ><DIV
1117 CLASS="SECT1"
1118 ><HR><H2
1119 CLASS="SECT1"
1120 ><A
1121 NAME="AEN128">The DEBUG() Macro</H2
1122 ><P
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
1126 ><P
1127 >That's confusing.</P
1128 ><P
1129 >Here's an example which may help a bit. If you would write</P
1130 ><P
1131 ><TABLE
1132 BORDER="0"
1133 BGCOLOR="#E0E0E0"
1134 WIDTH="100%"
1135 ><TR
1136 ><TD
1137 ><PRE
1138 CLASS="PROGRAMLISTING"
1139 >printf( "This is a %s message.\n", "debug" );</PRE
1140 ></TD
1141 ></TR
1142 ></TABLE
1143 ></P
1144 ><P
1145 >to send the output to stdout, then you would write</P
1146 ><P
1147 ><TABLE
1148 BORDER="0"
1149 BGCOLOR="#E0E0E0"
1150 WIDTH="100%"
1151 ><TR
1152 ><TD
1153 ><PRE
1154 CLASS="PROGRAMLISTING"
1155 >DEBUG( 0, ( "This is a %s message.\n", "debug" ) );</PRE
1156 ></TD
1157 ></TR
1158 ></TABLE
1159 ></P
1160 ><P
1161 >to send the output to the debug file.  All of the normal printf()
1162 formatting escapes work.</P
1163 ><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
1168 ><P
1169 >The output of the above example would be something like:</P
1170 ><P
1171 ><TABLE
1172 BORDER="0"
1173 BGCOLOR="#E0E0E0"
1174 WIDTH="100%"
1175 ><TR
1176 ><TD
1177 ><PRE
1178 CLASS="PROGRAMLISTING"
1179 >    [1998/07/30 16:00:51, 0] file.c:function(128)
1180       This is a debug message.</PRE
1181 ></TD
1182 ></TR
1183 ></TABLE
1184 ></P
1185 ><P
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
1191 ><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
1195 ><P
1196 ><TABLE
1197 BORDER="0"
1198 BGCOLOR="#E0E0E0"
1199 WIDTH="100%"
1200 ><TR
1201 ><TD
1202 ><PRE
1203 CLASS="PROGRAMLISTING"
1204 >    DEBUG( 0, ("The test returned " ) );
1205     if( test() )
1206       DEBUG(0, ("True") );
1207     else
1208       DEBUG(0, ("False") );
1209     DEBUG(0, (".\n") );</PRE
1210 ></TD
1211 ></TR
1212 ></TABLE
1213 ></P
1214 ><P
1215 >Without the format buffer, the output (assuming test() returned true)
1216 would look like this:</P
1217 ><P
1218 ><TABLE
1219 BORDER="0"
1220 BGCOLOR="#E0E0E0"
1221 WIDTH="100%"
1222 ><TR
1223 ><TD
1224 ><PRE
1225 CLASS="PROGRAMLISTING"
1226 >    [1998/07/30 16:00:51, 0] file.c:function(256)
1227       The test returned
1228     [1998/07/30 16:00:51, 0] file.c:function(258)
1229       True
1230     [1998/07/30 16:00:51, 0] file.c:function(261)
1231       .</PRE
1232 ></TD
1233 ></TR
1234 ></TABLE
1235 ></P
1236 ><P
1237 >Which isn't much use. The format buffer kludge fixes this problem.</P
1238 ></DIV
1239 ><DIV
1240 CLASS="SECT1"
1241 ><HR><H2
1242 CLASS="SECT1"
1243 ><A
1244 NAME="AEN151">The DEBUGADD() Macro</H2
1245 ><P
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
1251 ><P
1252 ><TABLE
1253 BORDER="0"
1254 BGCOLOR="#E0E0E0"
1255 WIDTH="100%"
1256 ><TR
1257 ><TD
1258 ><PRE
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
1262 ></TD
1263 ></TR
1264 ></TABLE
1265 ></P
1266 ><P
1267 >Produces</P
1268 ><P
1269 ><TABLE
1270 BORDER="0"
1271 BGCOLOR="#E0E0E0"
1272 WIDTH="100%"
1273 ><TR
1274 ><TD
1275 ><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
1281 ></TD
1282 ></TR
1283 ></TABLE
1284 ></P
1285 ></DIV
1286 ><DIV
1287 CLASS="SECT1"
1288 ><HR><H2
1289 CLASS="SECT1"
1290 ><A
1291 NAME="AEN159">The DEBUGLVL() Macro</H2
1292 ><P
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
1296 ><P
1297 ><TABLE
1298 BORDER="0"
1299 BGCOLOR="#E0E0E0"
1300 WIDTH="100%"
1301 ><TR
1302 ><TD
1303 ><PRE
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-&#62;subnet_name, work-&#62;work_group));</PRE
1307 ></TD
1308 ></TR
1309 ></TABLE
1310 ></P
1311 ><P
1312 >One solution to this is to break it down using DEBUG() and DEBUGADD(),
1313 as follows:</P
1314 ><P
1315 ><TABLE
1316 BORDER="0"
1317 BGCOLOR="#E0E0E0"
1318 WIDTH="100%"
1319 ><TR
1320 ><TD
1321 ><PRE
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-&#62;subnet_name ) );
1326   DEBUGADD( 3, ( "for workgroup %s\n", work-&#62;work_group ) );</PRE
1327 ></TD
1328 ></TR
1329 ></TABLE
1330 ></P
1331 ><P
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
1335 ><P
1336 ><TABLE
1337 BORDER="0"
1338 BGCOLOR="#E0E0E0"
1339 WIDTH="100%"
1340 ><TR
1341 ><TD
1342 ><PRE
1343 CLASS="PROGRAMLISTING"
1344 >  if( DEBUGLVL( 3 ) )
1345     {
1346     dbgtext( "send_local_master_announcement: " );
1347     dbgtext( "type %x for name %s ", type, global_myname );
1348     dbgtext( "on subnet %s ", subrec-&#62;subnet_name );
1349     dbgtext( "for workgroup %s\n", work-&#62;work_group );
1350     }</PRE
1351 ></TD
1352 ></TR
1353 ></TABLE
1354 ></P
1355 ><P
1356 >(The dbgtext() function is explained below.)</P
1357 ><P
1358 >There are a few advantages to this scheme:</P
1359 ><P
1360 ></P
1361 ><OL
1362 TYPE="1"
1363 ><LI
1364 ><P
1365 >The test is performed only once.</P
1366 ></LI
1367 ><LI
1368 ><P
1369 >You can allocate variables off of the stack that will only be used
1370 within the DEBUGLVL() block.</P
1371 ></LI
1372 ><LI
1373 ><P
1374 >Processing that is only relevant to debug output can be contained
1375 within the DEBUGLVL() block.</P
1376 ></LI
1377 ></OL
1378 ></DIV
1379 ><DIV
1380 CLASS="SECT1"
1381 ><HR><H2
1382 CLASS="SECT1"
1383 ><A
1384 NAME="AEN179">New Functions</H2
1385 ><DIV
1386 CLASS="SECT2"
1387 ><H3
1388 CLASS="SECT2"
1389 ><A
1390 NAME="AEN181">dbgtext()</H3
1391 ><P
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().
1397
1398 If you use DEBUGLVL() you will probably print the body of the
1399 message using dbgtext(). </P
1400 ></DIV
1401 ><DIV
1402 CLASS="SECT2"
1403 ><HR><H3
1404 CLASS="SECT2"
1405 ><A
1406 NAME="AEN184">dbghdr()</H3
1407 ><P
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
1412 ><P
1413 >It is not likely that this function will be called directly. It
1414 is used by DEBUG() and DEBUGADD().</P
1415 ></DIV
1416 ><DIV
1417 CLASS="SECT2"
1418 ><HR><H3
1419 CLASS="SECT2"
1420 ><A
1421 NAME="AEN188">format_debug_text()</H3
1422 ><P
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
1430 syslog output).</P
1431 ></DIV
1432 ></DIV
1433 ></DIV
1434 ><DIV
1435 CLASS="CHAPTER"
1436 ><HR><H1
1437 ><A
1438 NAME="CODINGSUGGESTIONS">Coding Suggestions</H1
1439 ><P
1440 >So you want to add code to Samba ...</P
1441 ><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
1450 <TT
1451 CLASS="FILENAME"
1452 >samba/source/internals.doc</TT
1453 > and 
1454 <TT
1455 CLASS="FILENAME"
1456 >samba/source/architecture.doc</TT
1457 > provide
1458 additional information.</P
1459 ><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
1464 documents are:</P
1465 ><P
1466 ><A
1467 HREF="http://lxr.linux.no/source/Documentation/CodingStyle"
1468 TARGET="_top"
1469 >http://lxr.linux.no/source/Documentation/CodingStyle</A
1470 ></P
1471 ><P
1472 ><A
1473 HREF="http://www.fsf.org/prep/standards_toc.html"
1474 TARGET="_top"
1475 >http://www.fsf.org/prep/standards_toc.html</A
1476 ></P
1477 ><P
1478 >But note that coding style in Samba varies due to the many different
1479 programmers who have contributed.</P
1480 ><P
1481 >Following are some considerations you should use when adding new code to
1482 Samba.  First and foremost remember that:</P
1483 ><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
1492 ><P
1493 >Here are some other suggestions:</P
1494 ><P
1495 ></P
1496 ><OL
1497 TYPE="1"
1498 ><LI
1499 ><P
1500 >       use d_printf instead of printf for display text
1501         reason: enable auto-substitution of translated language text </P
1502 ></LI
1503 ><LI
1504 ><P
1505 >       use SAFE_FREE instead of free
1506         reason: reduce traps due to null pointers</P
1507 ></LI
1508 ><LI
1509 ><P
1510 >       don't use bzero use memset, or ZERO_STRUCT and ZERO_STRUCTP macros
1511         reason: not POSIX</P
1512 ></LI
1513 ><LI
1514 ><P
1515 >       don't use strcpy and strlen (use safe_* equivalents)
1516         reason: to avoid traps due to buffer overruns</P
1517 ></LI
1518 ><LI
1519 ><P
1520 >       don't use getopt_long, use popt functions instead
1521         reason: portability</P
1522 ></LI
1523 ><LI
1524 ><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
1527 ></LI
1528 ><LI
1529 ><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
1534 ></LI
1535 ><LI
1536 ><P
1537 >       discourage use of threads
1538         reason: portability (also see architecture.doc)</P
1539 ></LI
1540 ><LI
1541 ><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
1545 ></LI
1546 ><LI
1547 ><P
1548 >       don't explicitly extern functions (they are autogenerated by 
1549         "make proto" into proto.h)
1550         reason: consistency</P
1551 ></LI
1552 ><LI
1553 ><P
1554 >       use endian safe macros when unpacking SMBs (see byteorder.h and
1555         internals.doc)
1556         reason: not everyone uses Intel</P
1557 ></LI
1558 ><LI
1559 ><P
1560 >       Note Unicode implications of charset handling (see internals.doc).  See
1561         pull_*  and push_* and convert_string functions.
1562         reason: Internationalization</P
1563 ></LI
1564 ><LI
1565 ><P
1566 >       Don't assume English only
1567         reason: See above</P
1568 ></LI
1569 ><LI
1570 ><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
1574 ></LI
1575 ><LI
1576 ><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
1580 ></LI
1581 ><LI
1582 ><P
1583 >       Consider usage of DATA_BLOBs for length specified byte-data.
1584         reason: stability</P
1585 ></LI
1586 ><LI
1587 ><P
1588 >       Take advantage of tdbs for database like function
1589         reason: consistency</P
1590 ></LI
1591 ><LI
1592 ><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
1596 ></LI
1597 ><LI
1598 ><P
1599 >       Don't check a password directly against the passdb, always use the
1600         check_password() interface.
1601         reason: long term pluggability</P
1602 ></LI
1603 ><LI
1604 ><P
1605 >       Try to use asprintf rather than pstrings and fstrings where possible</P
1606 ></LI
1607 ><LI
1608 ><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
1612 ></LI
1613 ><LI
1614 ><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
1619         this file.</P
1620 ></LI
1621 ><LI
1622 ><P
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
1627 ></LI
1628 ><LI
1629 ><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
1636         interpreters. </P
1637 ></LI
1638 ><LI
1639 ><P
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
1643 ></LI
1644 ></OL
1645 ><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
1649 added.</P
1650 ></DIV
1651 ><DIV
1652 CLASS="CHAPTER"
1653 ><HR><H1
1654 ><A
1655 NAME="INTERNALS">Samba Internals</H1
1656 ><DIV
1657 CLASS="SECT1"
1658 ><H2
1659 CLASS="SECT1"
1660 ><A
1661 NAME="AEN284">Character Handling</H2
1662 ><P
1663 >This section describes character set handling in Samba, as implemented in
1664 Samba 3.0 and above</P
1665 ><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
1672 ></DIV
1673 ><DIV
1674 CLASS="SECT1"
1675 ><HR><H2
1676 CLASS="SECT1"
1677 ><A
1678 NAME="AEN288">The new functions</H2
1679 ><P
1680 >The new system works like this:</P
1681 ><P
1682 ></P
1683 ><OL
1684 TYPE="1"
1685 ><LI
1686 ><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
1690 ></LI
1691 ><LI
1692 ><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:
1695         </P
1696 ><P
1697 ></P
1698 ><OL
1699 TYPE="a"
1700 ><LI
1701 ><P
1702 >               must not contain NULLs except for termination
1703         </P
1704 ></LI
1705 ><LI
1706 ><P
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. 
1710         </P
1711 ></LI
1712 ><LI
1713 ><P
1714 >               when you uppercase or lowercase a string it does not become
1715                 longer than the original string
1716         </P
1717 ></LI
1718 ><LI
1719 ><P
1720 >               must be able to correctly hold all characters that your client
1721                 will throw at it
1722         </P
1723 ></LI
1724 ></OL
1725 ><P
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
1728         contain nulls.
1729         </P
1730 ></LI
1731 ><LI
1732 ><P
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
1739 ></LI
1740 ><LI
1741 ><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.
1752         </P
1753 ><P
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()
1759         </P
1760 ></LI
1761 ><LI
1762 ><P
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
1770 ></LI
1771 ><LI
1772 ><P
1773 >       all lp_ functions now return unix strings. The magic "DOS" flag on
1774         parameters is gone.</P
1775 ></LI
1776 ><LI
1777 ><P
1778 >       all vfs functions take unix strings. Don't convert when passing to them</P
1779 ></LI
1780 ></OL
1781 ></DIV
1782 ><DIV
1783 CLASS="SECT1"
1784 ><HR><H2
1785 CLASS="SECT1"
1786 ><A
1787 NAME="AEN317">Macros in byteorder.h</H2
1788 ><P
1789 >This section describes the macros defined in byteorder.h.  These macros 
1790 are used extensively in the Samba code.</P
1791 ><DIV
1792 CLASS="SECT2"
1793 ><HR><H3
1794 CLASS="SECT2"
1795 ><A
1796 NAME="AEN320">CVAL(buf,pos)</H3
1797 ><P
1798 >returns the byte at offset pos within buffer buf as an unsigned character.</P
1799 ></DIV
1800 ><DIV
1801 CLASS="SECT2"
1802 ><HR><H3
1803 CLASS="SECT2"
1804 ><A
1805 NAME="AEN323">PVAL(buf,pos)</H3
1806 ><P
1807 >returns the value of CVAL(buf,pos) cast to type unsigned integer.</P
1808 ></DIV
1809 ><DIV
1810 CLASS="SECT2"
1811 ><HR><H3
1812 CLASS="SECT2"
1813 ><A
1814 NAME="AEN326">SCVAL(buf,pos,val)</H3
1815 ><P
1816 >sets the byte at offset pos within buffer buf to value val.</P
1817 ></DIV
1818 ><DIV
1819 CLASS="SECT2"
1820 ><HR><H3
1821 CLASS="SECT2"
1822 ><A
1823 NAME="AEN329">SVAL(buf,pos)</H3
1824 ><P
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
1828 ></DIV
1829 ><DIV
1830 CLASS="SECT2"
1831 ><HR><H3
1832 CLASS="SECT2"
1833 ><A
1834 NAME="AEN332">IVAL(buf,pos)</H3
1835 ><P
1836 >returns the value of the unsigned 32 bit little-endian integer at offset 
1837 pos within buffer buf.</P
1838 ></DIV
1839 ><DIV
1840 CLASS="SECT2"
1841 ><HR><H3
1842 CLASS="SECT2"
1843 ><A
1844 NAME="AEN335">SVALS(buf,pos)</H3
1845 ><P
1846 >returns the value of the signed short (16 bit) little-endian integer at 
1847 offset pos within buffer buf.</P
1848 ></DIV
1849 ><DIV
1850 CLASS="SECT2"
1851 ><HR><H3
1852 CLASS="SECT2"
1853 ><A
1854 NAME="AEN338">IVALS(buf,pos)</H3
1855 ><P
1856 >returns the value of the signed 32 bit little-endian integer at offset pos
1857 within buffer buf.</P
1858 ></DIV
1859 ><DIV
1860 CLASS="SECT2"
1861 ><HR><H3
1862 CLASS="SECT2"
1863 ><A
1864 NAME="AEN341">SSVAL(buf,pos,val)</H3
1865 ><P
1866 >sets the unsigned short (16 bit) little-endian integer at offset pos within 
1867 buffer buf to value val.</P
1868 ></DIV
1869 ><DIV
1870 CLASS="SECT2"
1871 ><HR><H3
1872 CLASS="SECT2"
1873 ><A
1874 NAME="AEN344">SIVAL(buf,pos,val)</H3
1875 ><P
1876 >sets the unsigned 32 bit little-endian integer at offset pos within buffer 
1877 buf to the value val.</P
1878 ></DIV
1879 ><DIV
1880 CLASS="SECT2"
1881 ><HR><H3
1882 CLASS="SECT2"
1883 ><A
1884 NAME="AEN347">SSVALS(buf,pos,val)</H3
1885 ><P
1886 >sets the short (16 bit) signed little-endian integer at offset pos within 
1887 buffer buf to the value val.</P
1888 ></DIV
1889 ><DIV
1890 CLASS="SECT2"
1891 ><HR><H3
1892 CLASS="SECT2"
1893 ><A
1894 NAME="AEN350">SIVALS(buf,pos,val)</H3
1895 ><P
1896 >sets the signed 32 bit little-endian integer at offset pos withing buffer
1897 buf to the value val.</P
1898 ></DIV
1899 ><DIV
1900 CLASS="SECT2"
1901 ><HR><H3
1902 CLASS="SECT2"
1903 ><A
1904 NAME="AEN353">RSVAL(buf,pos)</H3
1905 ><P
1906 >returns the value of the unsigned short (16 bit) big-endian integer at 
1907 offset pos within buffer buf.</P
1908 ></DIV
1909 ><DIV
1910 CLASS="SECT2"
1911 ><HR><H3
1912 CLASS="SECT2"
1913 ><A
1914 NAME="AEN356">RIVAL(buf,pos)</H3
1915 ><P
1916 >returns the value of the unsigned 32 bit big-endian integer at offset 
1917 pos within buffer buf.</P
1918 ></DIV
1919 ><DIV
1920 CLASS="SECT2"
1921 ><HR><H3
1922 CLASS="SECT2"
1923 ><A
1924 NAME="AEN359">RSSVAL(buf,pos,val)</H3
1925 ><P
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
1929 ></DIV
1930 ><DIV
1931 CLASS="SECT2"
1932 ><HR><H3
1933 CLASS="SECT2"
1934 ><A
1935 NAME="AEN362">RSIVAL(buf,pos,val)</H3
1936 ><P
1937 >sets the value of the unsigned 32 bit big-endian integer at offset 
1938 pos within buffer buf to value val.</P
1939 ></DIV
1940 ></DIV
1941 ><DIV
1942 CLASS="SECT1"
1943 ><HR><H2
1944 CLASS="SECT1"
1945 ><A
1946 NAME="AEN365">LAN Manager Samba API</H2
1947 ><P
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
1951 reliable.</P
1952 ><P
1953 ><TABLE
1954 BORDER="0"
1955 BGCOLOR="#E0E0E0"
1956 WIDTH="100%"
1957 ><TR
1958 ><TD
1959 ><PRE
1960 CLASS="PROGRAMLISTING"
1961 >call_api(int prcnt, int drcnt, int mprcnt, int mdrcnt, 
1962         char *param, char *data, char **rparam, char **rdata);</PRE
1963 ></TD
1964 ></TR
1965 ></TABLE
1966 ></P
1967 ><P
1968 >This function is defined in client.c.  It uses an SMB transaction to call a
1969 remote api.</P
1970 ><DIV
1971 CLASS="SECT2"
1972 ><HR><H3
1973 CLASS="SECT2"
1974 ><A
1975 NAME="AEN371">Parameters</H3
1976 ><P
1977 >The parameters are as follows:</P
1978 ><P
1979 ></P
1980 ><OL
1981 TYPE="1"
1982 ><LI
1983 ><P
1984 >       prcnt: the number of bytes of parameters begin sent.</P
1985 ></LI
1986 ><LI
1987 ><P
1988 >       drcnt:   the number of bytes of data begin sent.</P
1989 ></LI
1990 ><LI
1991 ><P
1992 >       mprcnt:  the maximum number of bytes of parameters which should be returned</P
1993 ></LI
1994 ><LI
1995 ><P
1996 >       mdrcnt:  the maximum number of bytes of data which should be returned</P
1997 ></LI
1998 ><LI
1999 ><P
2000 >       param:   a pointer to the parameters to be sent.</P
2001 ></LI
2002 ><LI
2003 ><P
2004 >       data:    a pointer to the data to be sent.</P
2005 ></LI
2006 ><LI
2007 ><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
2010 ></LI
2011 ><LI
2012 ><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
2015 ></LI
2016 ></OL
2017 ><P
2018 >These are the parameters which you ought to send, in the order of their
2019 appearance in the parameter block:</P
2020 ><P
2021 ></P
2022 ><OL
2023 TYPE="1"
2024 ><LI
2025 ><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
2028 ></LI
2029 ><LI
2030 ><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
2035 ></LI
2036 ><LI
2037 ><P
2038 >An ASCIIZ string describing the data structure which ought to be returned.</P
2039 ></LI
2040 ><LI
2041 ><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
2045 ></LI
2046 ><LI
2047 ><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
2051 ></LI
2052 ><LI
2053 ><P
2054 >An ASCIIZ string describing substructures which should be returned.  If no 
2055 substructures apply, this string is of zero length.</P
2056 ></LI
2057 ></OL
2058 ><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
2061 ></DIV
2062 ><DIV
2063 CLASS="SECT2"
2064 ><HR><H3
2065 CLASS="SECT2"
2066 ><A
2067 NAME="AEN406">Return value</H3
2068 ><P
2069 >The returned parameters (pointed to by rparam), in their order of appearance
2070 are:</P
2071 ><P
2072 ></P
2073 ><OL
2074 TYPE="1"
2075 ><LI
2076 ><P
2077 >An unsigned 16 bit integer which contains the API function's return code. 
2078 This value should be read with SVAL().</P
2079 ></LI
2080 ><LI
2081 ><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
2087 ></LI
2088 ><LI
2089 ><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
2092 ></LI
2093 ></OL
2094 ><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
2098 ><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
2102 use.</P
2103 ><P
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
2107 ><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
2111 ></DIV
2112 ></DIV
2113 ><DIV
2114 CLASS="SECT1"
2115 ><HR><H2
2116 CLASS="SECT1"
2117 ><A
2118 NAME="AEN420">Code character table</H2
2119 ><P
2120 >Certain data structures are described by means of ASCIIz strings containing
2121 code characters.  These are the code characters:</P
2122 ><P
2123 ></P
2124 ><OL
2125 TYPE="1"
2126 ><LI
2127 ><P
2128 >W      a type byte little-endian unsigned integer</P
2129 ></LI
2130 ><LI
2131 ><P
2132 >N      a count of substructures which follow</P
2133 ></LI
2134 ><LI
2135 ><P
2136 >D      a four byte little-endian unsigned integer</P
2137 ></LI
2138 ><LI
2139 ><P
2140 >B      a byte (with optional count expressed as trailing ASCII digits)</P
2141 ></LI
2142 ><LI
2143 ><P
2144 >z      a four byte offset to a NULL terminated string</P
2145 ></LI
2146 ><LI
2147 ><P
2148 >l      a four byte offset to non-string user data</P
2149 ></LI
2150 ><LI
2151 ><P
2152 >b      an offset to data (with count expressed as trailing ASCII digits)</P
2153 ></LI
2154 ><LI
2155 ><P
2156 >r      pointer to returned data buffer???</P
2157 ></LI
2158 ><LI
2159 ><P
2160 >L      length in bytes of returned data buffer???</P
2161 ></LI
2162 ><LI
2163 ><P
2164 >h      number of bytes of information available???</P
2165 ></LI
2166 ></OL
2167 ></DIV
2168 ></DIV
2169 ><DIV
2170 CLASS="CHAPTER"
2171 ><HR><H1
2172 ><A
2173 NAME="PARSING">The smb.conf file</H1
2174 ><DIV
2175 CLASS="SECT1"
2176 ><H2
2177 CLASS="SECT1"
2178 ><A
2179 NAME="AEN451">Lexical Analysis</H2
2180 ><P
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
2183 (params.c):</P
2184 ><P
2185 ></P
2186 ><OL
2187 TYPE="1"
2188 ><LI
2189 ><P
2190 >Blank lines - Lines containing only whitespace.</P
2191 ></LI
2192 ><LI
2193 ><P
2194 >Comment lines - Lines beginning with either a semi-colon or a
2195 pound sign (';' or '#').</P
2196 ></LI
2197 ><LI
2198 ><P
2199 >Section header lines - Lines beginning with an open square bracket ('[').</P
2200 ></LI
2201 ><LI
2202 ><P
2203 >Parameter lines - Lines beginning with any other character.
2204 (The default line type.)</P
2205 ></LI
2206 ></OL
2207 ><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
2210 ><P
2211 ></P
2212 ><OL
2213 TYPE="1"
2214 ><LI
2215 ><P
2216 >  - Section names</P
2217 ></LI
2218 ><LI
2219 ><P
2220 >  - Parameter names</P
2221 ></LI
2222 ><LI
2223 ><P
2224 >  - Parameter values</P
2225 ></LI
2226 ></OL
2227 ><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
2231 ><DIV
2232 CLASS="SECT2"
2233 ><HR><H3
2234 CLASS="SECT2"
2235 ><A
2236 NAME="AEN472">Handling of Whitespace</H3
2237 ><P
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
2241 ><P
2242 ></P
2243 ><OL
2244 TYPE="1"
2245 ><LI
2246 ><P
2247 >The lexical analyzer scans past white space at the beginning of a line.</P
2248 ></LI
2249 ><LI
2250 ><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
2253 ></LI
2254 ><LI
2255 ><P
2256 >Internal whitespace within a parameter value is kept verbatim with 
2257 the exception of carriage return characters ('\r'), all of which
2258 are removed.</P
2259 ></LI
2260 ><LI
2261 ><P
2262 >Leading and trailing whitespace is removed from names and values.</P
2263 ></LI
2264 ></OL
2265 ></DIV
2266 ><DIV
2267 CLASS="SECT2"
2268 ><HR><H3
2269 CLASS="SECT2"
2270 ><A
2271 NAME="AEN484">Handling of Line Continuation</H3
2272 ><P
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
2276 ><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
2281 ><P
2282 ><TABLE
2283 BORDER="0"
2284 BGCOLOR="#E0E0E0"
2285 WIDTH="100%"
2286 ><TR
2287 ><TD
2288 ><PRE
2289 CLASS="PROGRAMLISTING"
2290 >       param name = parameter value string \
2291         with line continuation.</PRE
2292 ></TD
2293 ></TR
2294 ></TABLE
2295 ></P
2296 ><P
2297 >Would be read as</P
2298 ><P
2299 ><TABLE
2300 BORDER="0"
2301 BGCOLOR="#E0E0E0"
2302 WIDTH="100%"
2303 ><TR
2304 ><TD
2305 ><PRE
2306 CLASS="PROGRAMLISTING"
2307 >    param name = parameter value string     with line continuation.</PRE
2308 ></TD
2309 ></TR
2310 ></TABLE
2311 ></P
2312 ><P
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
2317 ><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
2320 lines.</P
2321 ></DIV
2322 ><DIV
2323 CLASS="SECT2"
2324 ><HR><H3
2325 CLASS="SECT2"
2326 ><A
2327 NAME="AEN495">Line Continuation Quirks</H3
2328 ><P
2329 >Note the following example:</P
2330 ><P
2331 ><TABLE
2332 BORDER="0"
2333 BGCOLOR="#E0E0E0"
2334 WIDTH="100%"
2335 ><TR
2336 ><TD
2337 ><PRE
2338 CLASS="PROGRAMLISTING"
2339 >       param name = parameter value string \
2340     \
2341     with line continuation.</PRE
2342 ></TD
2343 ></TR
2344 ></TABLE
2345 ></P
2346 ><P
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
2349 ><P
2350 ><TABLE
2351 BORDER="0"
2352 BGCOLOR="#E0E0E0"
2353 WIDTH="100%"
2354 ><TR
2355 ><TD
2356 ><PRE
2357 CLASS="PROGRAMLISTING"
2358 >param name = parameter value string         with line continuation.</PRE
2359 ></TD
2360 ></TR
2361 ></TABLE
2362 ></P
2363 ><P
2364 >The same is true for comment lines.</P
2365 ><P
2366 ><TABLE
2367 BORDER="0"
2368 BGCOLOR="#E0E0E0"
2369 WIDTH="100%"
2370 ><TR
2371 ><TD
2372 ><PRE
2373 CLASS="PROGRAMLISTING"
2374 >       param name = parameter value string \
2375         ; comment \
2376     with a comment.</PRE
2377 ></TD
2378 ></TR
2379 ></TABLE
2380 ></P
2381 ><P
2382 >This becomes:</P
2383 ><P
2384 ><TABLE
2385 BORDER="0"
2386 BGCOLOR="#E0E0E0"
2387 WIDTH="100%"
2388 ><TR
2389 ><TD
2390 ><PRE
2391 CLASS="PROGRAMLISTING"
2392 >param name = parameter value string     ; comment     with a comment.</PRE
2393 ></TD
2394 ></TR
2395 ></TABLE
2396 ></P
2397 ><P
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
2400 ><P
2401 ><TABLE
2402 BORDER="0"
2403 BGCOLOR="#E0E0E0"
2404 WIDTH="100%"
2405 ><TR
2406 ><TD
2407 ><PRE
2408 CLASS="PROGRAMLISTING"
2409 >       [ section   name ] garbage \
2410     param  name  = value</PRE
2411 ></TD
2412 ></TR
2413 ></TABLE
2414 ></P
2415 ><P
2416 >are read as</P
2417 ><P
2418 ><TABLE
2419 BORDER="0"
2420 BGCOLOR="#E0E0E0"
2421 WIDTH="100%"
2422 ><TR
2423 ><TD
2424 ><PRE
2425 CLASS="PROGRAMLISTING"
2426 >       [section name]
2427     param name = value</PRE
2428 ></TD
2429 ></TR
2430 ></TABLE
2431 ></P
2432 ></DIV
2433 ></DIV
2434 ><DIV
2435 CLASS="SECT1"
2436 ><HR><H2
2437 CLASS="SECT1"
2438 ><A
2439 NAME="AEN515">Syntax</H2
2440 ><P
2441 >The syntax of the smb.conf file is as follows:</P
2442 ><P
2443 ><TABLE
2444 BORDER="0"
2445 BGCOLOR="#E0E0E0"
2446 WIDTH="100%"
2447 ><TR
2448 ><TD
2449 ><PRE
2450 CLASS="PROGRAMLISTING"
2451 >  &#60;file&#62;            :==  { &#60;section&#62; } EOF
2452   &#60;section&#62;         :==  &#60;section header&#62; { &#60;parameter line&#62; }
2453   &#60;section header&#62;  :==  '[' NAME ']'
2454   &#60;parameter line&#62;  :==  NAME '=' VALUE NL</PRE
2455 ></TD
2456 ></TR
2457 ></TABLE
2458 ></P
2459 ><P
2460 >Basically, this means that</P
2461 ><P
2462 ></P
2463 ><OL
2464 TYPE="1"
2465 ><LI
2466 ><P
2467 >       a file is made up of zero or more sections, and is terminated by
2468         an EOF (we knew that).</P
2469 ></LI
2470 ><LI
2471 ><P
2472 >       A section is made up of a section header followed by zero or more
2473         parameter lines.</P
2474 ></LI
2475 ><LI
2476 ><P
2477 >       A section header is identified by an opening bracket and
2478         terminated by the closing bracket.  The enclosed NAME identifies
2479         the section.</P
2480 ></LI
2481 ><LI
2482 ><P
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
2486 ></LI
2487 ></OL
2488 ><DIV
2489 CLASS="SECT2"
2490 ><HR><H3
2491 CLASS="SECT2"
2492 ><A
2493 NAME="AEN530">About params.c</H3
2494 ><P
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
2498 loadparm.c.</P
2499 ></DIV
2500 ></DIV
2501 ></DIV
2502 ><DIV
2503 CLASS="CHAPTER"
2504 ><HR><H1
2505 ><A
2506 NAME="UNIX-SMB">NetBIOS in a Unix World</H1
2507 ><DIV
2508 CLASS="SECT1"
2509 ><H2
2510 CLASS="SECT1"
2511 ><A
2512 NAME="AEN540">Introduction</H2
2513 ><P
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&#60;-&#62;PC
2517 interoperability.</P
2518 ><P
2519 >It was written to help out a person who was writing a paper on unix to
2520 PC connectivity.</P
2521 ></DIV
2522 ><DIV
2523 CLASS="SECT1"
2524 ><HR><H2
2525 CLASS="SECT1"
2526 ><A
2527 NAME="AEN544">Usernames</H2
2528 ><P
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
2533 on the server.</P
2534 ><P
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
2538 ><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
2544 ><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
2554 ><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
2559 ><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
2565 ></DIV
2566 ><DIV
2567 CLASS="SECT1"
2568 ><HR><H2
2569 CLASS="SECT1"
2570 ><A
2571 NAME="AEN552">File Ownership</H2
2572 ><P
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
2576 ><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
2586 ><P
2587 >There are several possible solutions to this problem, including
2588 username mapping, and forcing a specific username for particular
2589 shares.</P
2590 ></DIV
2591 ><DIV
2592 CLASS="SECT1"
2593 ><HR><H2
2594 CLASS="SECT1"
2595 ><A
2596 NAME="AEN557">Passwords</H2
2597 ><P
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
2602 ><P
2603 >Unix passwords are case sensitive. So if users use mixed case
2604 passwords they are in trouble.</P
2605 ><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
2611 ><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
2618 details.</P
2619 ></DIV
2620 ><DIV
2621 CLASS="SECT1"
2622 ><HR><H2
2623 CLASS="SECT1"
2624 ><A
2625 NAME="AEN563">Locking</H2
2626 ><P
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
2631 ><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
2636 ><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
2641 ><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
2647 ><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
2654 ></DIV
2655 ><DIV
2656 CLASS="SECT1"
2657 ><HR><H2
2658 CLASS="SECT1"
2659 ><A
2660 NAME="AEN570">Deny Modes</H2
2661 ><P
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
2668 ><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
2675 ></DIV
2676 ><DIV
2677 CLASS="SECT1"
2678 ><HR><H2
2679 CLASS="SECT1"
2680 ><A
2681 NAME="AEN574">Trapdoor UIDs</H2
2682 ><P
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
2688 a single uid.</P
2689 ><P
2690 >Note that you can also get the "trapdoor uid" message for other
2691 reasons. Please see the FAQ for details.</P
2692 ></DIV
2693 ><DIV
2694 CLASS="SECT1"
2695 ><HR><H2
2696 CLASS="SECT1"
2697 ><A
2698 NAME="AEN578">Port numbers</H2
2699 ><P
2700 >There is a convention that clients on sockets use high "unprivilaged"
2701 port numbers (&#62;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
2704 ><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
2712 ><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
2722 ></DIV
2723 ><DIV
2724 CLASS="SECT1"
2725 ><HR><H2
2726 CLASS="SECT1"
2727 ><A
2728 NAME="AEN583">Protocol Complexity</H2
2729 ><P
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
2734 ><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
2742 ><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
2752 ><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
2758 ><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
2767 ></DIV
2768 ></DIV
2769 ><DIV
2770 CLASS="CHAPTER"
2771 ><HR><H1
2772 ><A
2773 NAME="TRACING">Tracing samba system calls</H1
2774 ><P
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
2778 ><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
2781 ><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
2788 ><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
2793 ><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
2798 features.</P
2799 ><P
2800 >Next, try using strace on some simple commands. For example, <B
2801 CLASS="COMMAND"
2802 >strace
2803 ls</B
2804 > or <B
2805 CLASS="COMMAND"
2806 >strace echo hello</B
2807 >.</P
2808 ><P
2809
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
2816 ><P
2817 >For example, the only line that really matters in the <B
2818 CLASS="COMMAND"
2819 >strace echo
2820 hello</B
2821 > output is:</P
2822 ><P
2823 ><TABLE
2824 BORDER="0"
2825 BGCOLOR="#E0E0E0"
2826 WIDTH="100%"
2827 ><TR
2828 ><TD
2829 ><PRE
2830 CLASS="PROGRAMLISTING"
2831 >write(1, "hello\n", 6)                  = 6</PRE
2832 ></TD
2833 ></TR
2834 ></TABLE
2835 ></P
2836 ><P
2837 >all the rest is just setting up to run the program.</P
2838 ><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
2843 <B
2844 CLASS="COMMAND"
2845 >strace -p PID</B
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
2849 ><P
2850 ><B
2851 CLASS="COMMAND"
2852 >strace -f -p 3872 &#62;&#38; strace.out</B
2853 ></P
2854 ><P
2855 >or with a sh style shell:</P
2856 ><P
2857 ><B
2858 CLASS="COMMAND"
2859 >strace -f -p 3872 &#62; strace.out 2&#62;&#38;1</B
2860 ></P
2861 ><P
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
2866 ><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
2870 ><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
2877 ><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
2880 shows that <TT
2881 CLASS="FILENAME"
2882 >/dev/null</TT
2883 > is not world writeable, which
2884 causes printing to fail with Samba:</P
2885 ><P
2886 ><TABLE
2887 BORDER="0"
2888 BGCOLOR="#E0E0E0"
2889 WIDTH="100%"
2890 ><TR
2891 ><TD
2892 ><PRE
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
2896 ></TD
2897 ></TR
2898 ></TABLE
2899 ></P
2900 ><P
2901 >The process is trying to first open <TT
2902 CLASS="FILENAME"
2903 >/dev/null</TT
2904 > read-write 
2905 then read-only. Both fail. This means <TT
2906 CLASS="FILENAME"
2907 >/dev/null</TT
2908 > has 
2909 incorrect permissions.</P
2910 ></DIV
2911 ><DIV
2912 CLASS="CHAPTER"
2913 ><HR><H1
2914 ><A
2915 NAME="NTDOMAIN">NT Domain RPC's</H1
2916 ><DIV
2917 CLASS="SECT1"
2918 ><H2
2919 CLASS="SECT1"
2920 ><A
2921 NAME="AEN651">Introduction</H2
2922 ><P
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"
2926 TARGET="_top"
2927 >http://mailhost.cb1.com/~lkcl/cifsntdomain.txt</A
2928 >, controlled by Luke.</P
2929 ><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
2935 ><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
2943 ><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
2948 ><P
2949 >A copy is available from:</P
2950 ><P
2951 ><A
2952 HREF="http://ntbugtraq.rc.on.ca/SCRIPTS/WA.EXE?A2=ind9708;L=ntbugtraq;O=A;P=2935"
2953 TARGET="_top"
2954 >http://ntbugtraq.rc.on.ca/SCRIPTS/WA.EXE?A2=ind9708;L=ntbugtraq;O=A;P=2935</A
2955 ></P
2956 ><P
2957 ><A
2958 HREF="http://mailhost.cb1.com/~lkcl/crypt.html"
2959 TARGET="_top"
2960 >http://mailhost.cb1.com/~lkcl/crypt.html</A
2961 ></P
2962 ><P
2963 >A c-code implementation, provided by <A
2964 HREF="mailto:linus@incolumitas.se"
2965 TARGET="_top"
2966 >Linus Nordberg</A
2967 >
2968 of this protocol is available from:</P
2969 ><P
2970 ><A
2971 HREF="http://samba.org/cgi-bin/mfs/01/digest/1997/97aug/0391.html"
2972 TARGET="_top"
2973 >http://samba.org/cgi-bin/mfs/01/digest/1997/97aug/0391.html</A
2974 ></P
2975 ><P
2976 ><A
2977 HREF="http://mailhost.cb1.com/~lkcl/crypt.txt"
2978 TARGET="_top"
2979 >http://mailhost.cb1.com/~lkcl/crypt.txt</A
2980 ></P
2981 ><P
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
2985 ><P
2986 ><TT
2987 CLASS="FILENAME"
2988 >HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters</TT
2989 ></P
2990 ><P
2991 ><I
2992 CLASS="EMPHASIS"
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
2996 ></P
2997 ><P
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
3001 ><P
3002 >This document is by no means complete or authoritative.  Missing sections
3003 include, but are not limited to:</P
3004 ><P
3005 ></P
3006 ><OL
3007 TYPE="1"
3008 ><LI
3009 ><P
3010 >Mappings of RIDs to usernames (and vice-versa).</P
3011 ></LI
3012 ><LI
3013 ><P
3014 >What a User ID is and what a Group ID is.</P
3015 ></LI
3016 ><LI
3017 ><P
3018 >The exact meaning/definition of various magic constants or enumerations.</P
3019 ></LI
3020 ><LI
3021 ><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
3026 ></LI
3027 ><LI
3028 ><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
3033 ></LI
3034 ></OL
3035 ><DIV
3036 CLASS="SECT2"
3037 ><HR><H3
3038 CLASS="SECT2"
3039 ><A
3040 NAME="AEN687">Sources</H3
3041 ><P
3042 ></P
3043 ><TABLE
3044 BORDER="0"
3045 ><TBODY
3046 ><TR
3047 ><TD
3048 >cket Traces from Netmonitor (Service Pack 1 and above)</TD
3049 ></TR
3050 ><TR
3051 ><TD
3052 >ul Ashton and Luke Leighton's other "NT Domain" doc.</TD
3053 ></TR
3054 ><TR
3055 ><TD
3056 >FS documentation - cifs6.txt</TD
3057 ></TR
3058 ><TR
3059 ><TD
3060 >FS documentation - cifsrap2.txt</TD
3061 ></TR
3062 ></TBODY
3063 ></TABLE
3064 ><P
3065 ></P
3066 ></DIV
3067 ><DIV
3068 CLASS="SECT2"
3069 ><HR><H3
3070 CLASS="SECT2"
3071 ><A
3072 NAME="AEN694">Credits</H3
3073 ><P
3074 ></P
3075 ><TABLE
3076 BORDER="0"
3077 ><TBODY
3078 ><TR
3079 ><TD
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
3081 ></TR
3082 ><TR
3083 ><TD
3084 >Duncan Stansfield: low-level analysis of MSRPC Pipes.</TD
3085 ></TR
3086 ><TR
3087 ><TD
3088 >Linus Nordberg: producing c-code from Paul's crypto spec.</TD
3089 ></TR
3090 ><TR
3091 ><TD
3092 >Windows Sourcer development team</TD
3093 ></TR
3094 ></TBODY
3095 ></TABLE
3096 ><P
3097 ></P
3098 ></DIV
3099 ></DIV
3100 ><DIV
3101 CLASS="SECT1"
3102 ><HR><H2
3103 CLASS="SECT1"
3104 ><A
3105 NAME="AEN701">Notes and Structures</H2
3106 ><DIV
3107 CLASS="SECT2"
3108 ><H3
3109 CLASS="SECT2"
3110 ><A
3111 NAME="AEN703">Notes</H3
3112 ><P
3113 ></P
3114 ><OL
3115 TYPE="1"
3116 ><LI
3117 ><P
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
3121 ></LI
3122 ><LI
3123 ><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
3126 ></LI
3127 ><LI
3128 ><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
3131 ></LI
3132 ><LI
3133 ><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
3144 ></LI
3145 ><LI
3146 ><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
3153 ></LI
3154 ></OL
3155 ></DIV
3156 ><DIV
3157 CLASS="SECT2"
3158 ><HR><H3
3159 CLASS="SECT2"
3160 ><A
3161 NAME="AEN716">Enumerations</H3
3162 ><DIV
3163 CLASS="SECT3"
3164 ><H4
3165 CLASS="SECT3"
3166 ><A
3167 NAME="AEN718">MSRPC Header type</H4
3168 ><P
3169 >command number in the msrpc packet header</P
3170 ><P
3171 ></P
3172 ><DIV
3173 CLASS="VARIABLELIST"
3174 ><DL
3175 ><DT
3176 >MSRPC_Request:</DT
3177 ><DD
3178 ><P
3179 >0x00</P
3180 ></DD
3181 ><DT
3182 >MSRPC_Response:</DT
3183 ><DD
3184 ><P
3185 >0x02</P
3186 ></DD
3187 ><DT
3188 >MSRPC_Bind:</DT
3189 ><DD
3190 ><P
3191 >0x0B</P
3192 ></DD
3193 ><DT
3194 >MSRPC_BindAck:</DT
3195 ><DD
3196 ><P
3197 >0x0C</P
3198 ></DD
3199 ></DL
3200 ></DIV
3201 ></DIV
3202 ><DIV
3203 CLASS="SECT3"
3204 ><HR><H4
3205 CLASS="SECT3"
3206 ><A
3207 NAME="AEN738">MSRPC Packet info</H4
3208 ><P
3209 >The meaning of these flags is undocumented</P
3210 ><P
3211 ></P
3212 ><DIV
3213 CLASS="VARIABLELIST"
3214 ><DL
3215 ><DT
3216 >FirstFrag:</DT
3217 ><DD
3218 ><P
3219 >0x01 </P
3220 ></DD
3221 ><DT
3222 >LastFrag:</DT
3223 ><DD
3224 ><P
3225 >0x02 </P
3226 ></DD
3227 ><DT
3228 >NotaFrag:</DT
3229 ><DD
3230 ><P
3231 >0x04  </P
3232 ></DD
3233 ><DT
3234 >RecRespond:</DT
3235 ><DD
3236 ><P
3237 >0x08  </P
3238 ></DD
3239 ><DT
3240 >NoMultiplex:</DT
3241 ><DD
3242 ><P
3243 >0x10  </P
3244 ></DD
3245 ><DT
3246 >NotForIdemp:</DT
3247 ><DD
3248 ><P
3249 >0x20  </P
3250 ></DD
3251 ><DT
3252 >NotforBcast:</DT
3253 ><DD
3254 ><P
3255 >0x40  </P
3256 ></DD
3257 ><DT
3258 >NoUuid:</DT
3259 ><DD
3260 ><P
3261 >0x80 </P
3262 ></DD
3263 ></DL
3264 ></DIV
3265 ></DIV
3266 ></DIV
3267 ><DIV
3268 CLASS="SECT2"
3269 ><HR><H3
3270 CLASS="SECT2"
3271 ><A
3272 NAME="AEN774">Structures</H3
3273 ><DIV
3274 CLASS="SECT3"
3275 ><H4
3276 CLASS="SECT3"
3277 ><A
3278 NAME="AEN776">VOID *</H4
3279 ><P
3280 >sizeof VOID* is 32 bits.</P
3281 ></DIV
3282 ><DIV
3283 CLASS="SECT3"
3284 ><HR><H4
3285 CLASS="SECT3"
3286 ><A
3287 NAME="AEN779">char</H4
3288 ><P
3289 >sizeof char is 8 bits.</P
3290 ></DIV
3291 ><DIV
3292 CLASS="SECT3"
3293 ><HR><H4
3294 CLASS="SECT3"
3295 ><A
3296 NAME="AEN782">UTIME</H4
3297 ><P
3298 >UTIME is 32 bits, indicating time in seconds since 01jan1970.  documented in cifs6.txt (section 3.5 page, page 30).</P
3299 ></DIV
3300 ><DIV
3301 CLASS="SECT3"
3302 ><HR><H4
3303 CLASS="SECT3"
3304 ><A
3305 NAME="AEN785">NTTIME</H4
3306 ><P
3307 >NTTIME is 64 bits.  documented in cifs6.txt (section 3.5 page, page 30).</P
3308 ></DIV
3309 ><DIV
3310 CLASS="SECT3"
3311 ><HR><H4
3312 CLASS="SECT3"
3313 ><A
3314 NAME="AEN788">DOM_SID (domain SID structure)</H4
3315 ><P
3316 ></P
3317 ><DIV
3318 CLASS="VARIABLELIST"
3319 ><DL
3320 ><DT
3321 >UINT32</DT
3322 ><DD
3323 ><P
3324 >num of sub-authorities in domain SID</P
3325 ></DD
3326 ><DT
3327 >UINT8</DT
3328 ><DD
3329 ><P
3330 >SID revision number</P
3331 ></DD
3332 ><DT
3333 >UINT8</DT
3334 ><DD
3335 ><P
3336 >num of sub-authorities in domain SID</P
3337 ></DD
3338 ><DT
3339 >UINT8[6]</DT
3340 ><DD
3341 ><P
3342 >6 bytes for domain SID - Identifier Authority.</P
3343 ></DD
3344 ><DT
3345 >UINT16[n_subauths]</DT
3346 ><DD
3347 ><P
3348 >domain SID sub-authorities</P
3349 ></DD
3350 ></DL
3351 ></DIV
3352 ><P
3353 ><I
3354 CLASS="EMPHASIS"
3355 >Note: the domain SID is documented elsewhere.</I
3356 ></P
3357 ></DIV
3358 ><DIV
3359 CLASS="SECT3"
3360 ><HR><H4
3361 CLASS="SECT3"
3362 ><A
3363 NAME="AEN813">STR (string)</H4
3364 ><P
3365 >STR (string) is a char[] : a null-terminated string of ascii characters.</P
3366 ></DIV
3367 ><DIV
3368 CLASS="SECT3"
3369 ><HR><H4
3370 CLASS="SECT3"
3371 ><A
3372 NAME="AEN816">UNIHDR (unicode string header)</H4
3373 ><P
3374 ></P
3375 ><DIV
3376 CLASS="VARIABLELIST"
3377 ><DL
3378 ><DT
3379 >UINT16</DT
3380 ><DD
3381 ><P
3382 >length of unicode string</P
3383 ></DD
3384 ><DT
3385 >UINT16</DT
3386 ><DD
3387 ><P
3388 >max length of unicode string</P
3389 ></DD
3390 ><DT
3391 >UINT32</DT
3392 ><DD
3393 ><P
3394 >4 - undocumented.</P
3395 ></DD
3396 ></DL
3397 ></DIV
3398 ></DIV
3399 ><DIV
3400 CLASS="SECT3"
3401 ><HR><H4
3402 CLASS="SECT3"
3403 ><A
3404 NAME="AEN831">UNIHDR2 (unicode string header plus buffer pointer)</H4
3405 ><P
3406 ></P
3407 ><DIV
3408 CLASS="VARIABLELIST"
3409 ><DL
3410 ><DT
3411 >UNIHDR</DT
3412 ><DD
3413 ><P
3414 >unicode string header</P
3415 ></DD
3416 ><DT
3417 >VOID*</DT
3418 ><DD
3419 ><P
3420 >undocumented buffer pointer</P
3421 ></DD
3422 ></DL
3423 ></DIV
3424 ></DIV
3425 ><DIV
3426 CLASS="SECT3"
3427 ><HR><H4
3428 CLASS="SECT3"
3429 ><A
3430 NAME="AEN842">UNISTR (unicode string)</H4
3431 ><P
3432 ></P
3433 ><DIV
3434 CLASS="VARIABLELIST"
3435 ><DL
3436 ><DT
3437 >UINT16[]</DT
3438 ><DD
3439 ><P
3440 >null-terminated string of unicode characters.</P
3441 ></DD
3442 ></DL
3443 ></DIV
3444 ></DIV
3445 ><DIV
3446 CLASS="SECT3"
3447 ><HR><H4
3448 CLASS="SECT3"
3449 ><A
3450 NAME="AEN849">NAME (length-indicated unicode string)</H4
3451 ><P
3452 ></P
3453 ><DIV
3454 CLASS="VARIABLELIST"
3455 ><DL
3456 ><DT
3457 >UINT32</DT
3458 ><DD
3459 ><P
3460 >length of unicode string</P
3461 ></DD
3462 ><DT
3463 >UINT16[]</DT
3464 ><DD
3465 ><P
3466 >null-terminated string of unicode characters.</P
3467 ></DD
3468 ></DL
3469 ></DIV
3470 ></DIV
3471 ><DIV
3472 CLASS="SECT3"
3473 ><HR><H4
3474 CLASS="SECT3"
3475 ><A
3476 NAME="AEN860">UNISTR2 (aligned unicode string)</H4
3477 ><P
3478 ></P
3479 ><DIV
3480 CLASS="VARIABLELIST"
3481 ><DL
3482 ><DT
3483 >UINT8[]</DT
3484 ><DD
3485 ><P
3486 >padding to get unicode string 4-byte aligned with the start of the SMB header.</P
3487 ></DD
3488 ><DT
3489 >UINT32</DT
3490 ><DD
3491 ><P
3492 >max length of unicode string</P
3493 ></DD
3494 ><DT
3495 >UINT32</DT
3496 ><DD
3497 ><P
3498 >0 - undocumented</P
3499 ></DD
3500 ><DT
3501 >UINT32</DT
3502 ><DD
3503 ><P
3504 >length of unicode string</P
3505 ></DD
3506 ><DT
3507 >UINT16[]</DT
3508 ><DD
3509 ><P
3510 >string of uncode characters</P
3511 ></DD
3512 ></DL
3513 ></DIV
3514 ></DIV
3515 ><DIV
3516 CLASS="SECT3"
3517 ><HR><H4
3518 CLASS="SECT3"
3519 ><A
3520 NAME="AEN883">OBJ_ATTR (object attributes)</H4
3521 ><P
3522 ></P
3523 ><DIV
3524 CLASS="VARIABLELIST"
3525 ><DL
3526 ><DT
3527 >UINT32</DT
3528 ><DD
3529 ><P
3530 >0x18 - length (in bytes) including the length field.</P
3531 ></DD
3532 ><DT
3533 >VOID*</DT
3534 ><DD
3535 ><P
3536 >0 - root directory (pointer)</P
3537 ></DD
3538 ><DT
3539 >VOID*</DT
3540 ><DD
3541 ><P
3542 >0 - object name (pointer)</P
3543 ></DD
3544 ><DT
3545 >UINT32</DT
3546 ><DD
3547 ><P
3548 >0 - attributes (undocumented)</P
3549 ></DD
3550 ><DT
3551 >VOID*</DT
3552 ><DD
3553 ><P
3554 >0 - security descriptior (pointer)</P
3555 ></DD
3556 ><DT
3557 >UINT32</DT
3558 ><DD
3559 ><P
3560 >0 - security quality of service</P
3561 ></DD
3562 ></DL
3563 ></DIV
3564 ></DIV
3565 ><DIV
3566 CLASS="SECT3"
3567 ><HR><H4
3568 CLASS="SECT3"
3569 ><A
3570 NAME="AEN910">POL_HND (LSA policy handle)</H4
3571 ><P
3572 ></P
3573 ><DIV
3574 CLASS="VARIABLELIST"
3575 ><DL
3576 ><DT
3577 >char[20]</DT
3578 ><DD
3579 ><P
3580 >policy handle</P
3581 ></DD
3582 ></DL
3583 ></DIV
3584 ></DIV
3585 ><DIV
3586 CLASS="SECT3"
3587 ><HR><H4
3588 CLASS="SECT3"
3589 ><A
3590 NAME="AEN917">DOM_SID2 (domain SID structure, SIDS stored in unicode)</H4
3591 ><P
3592 ></P
3593 ><DIV
3594 CLASS="VARIABLELIST"
3595 ><DL
3596 ><DT
3597 >UINT32</DT
3598 ><DD
3599 ><P
3600 >5 - SID type</P
3601 ></DD
3602 ><DT
3603 >UINT32</DT
3604 ><DD
3605 ><P
3606 >0 - undocumented</P
3607 ></DD
3608 ><DT
3609 >UNIHDR2</DT
3610 ><DD
3611 ><P
3612 >domain SID unicode string header</P
3613 ></DD
3614 ><DT
3615 >UNISTR</DT
3616 ><DD
3617 ><P
3618 >domain SID unicode string</P
3619 ></DD
3620 ></DL
3621 ></DIV
3622 ><P
3623 ><I
3624 CLASS="EMPHASIS"
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
3626 ></P
3627 ><P
3628 ><I
3629 CLASS="EMPHASIS"
3630 >Note:  the SID type indicates, for example, an alias; a well-known group etc. this is documented somewhere.</I
3631 ></P
3632 ></DIV
3633 ><DIV
3634 CLASS="SECT3"
3635 ><HR><H4
3636 CLASS="SECT3"
3637 ><A
3638 NAME="AEN940">DOM_RID (domain RID structure)</H4
3639 ><P
3640 ></P
3641 ><DIV
3642 CLASS="VARIABLELIST"
3643 ><DL
3644 ><DT
3645 >UINT32</DT
3646 ><DD
3647 ><P
3648 >5 - well-known SID.  1 - user SID (see ShowACLs)</P
3649 ></DD
3650 ><DT
3651 >UINT32</DT
3652 ><DD
3653 ><P
3654 >5 - undocumented</P
3655 ></DD
3656 ><DT
3657 >UINT32</DT
3658 ><DD
3659 ><P
3660 >domain RID </P
3661 ></DD
3662 ><DT
3663 >UINT32</DT
3664 ><DD
3665 ><P
3666 >0 - domain index out of above reference domains</P
3667 ></DD
3668 ></DL
3669 ></DIV
3670 ></DIV
3671 ><DIV
3672 CLASS="SECT3"
3673 ><HR><H4
3674 CLASS="SECT3"
3675 ><A
3676 NAME="AEN959">LOG_INFO (server, account, client structure)</H4
3677 ><P
3678 ><I
3679 CLASS="EMPHASIS"
3680 >Note:  logon server name starts with two '\' characters and is upper case.</I
3681 ></P
3682 ><P
3683 ><I
3684 CLASS="EMPHASIS"
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
3686 ></P
3687 ><P
3688 ></P
3689 ><DIV
3690 CLASS="VARIABLELIST"
3691 ><DL
3692 ><DT
3693 >VOID*</DT
3694 ><DD
3695 ><P
3696 >undocumented buffer pointer</P
3697 ></DD
3698 ><DT
3699 >UNISTR2</DT
3700 ><DD
3701 ><P
3702 >logon server unicode string</P
3703 ></DD
3704 ><DT
3705 >UNISTR2</DT
3706 ><DD
3707 ><P
3708 >account name unicode string</P
3709 ></DD
3710 ><DT
3711 >UINT16</DT
3712 ><DD
3713 ><P
3714 >sec_chan - security channel type</P
3715 ></DD
3716 ><DT
3717 >UNISTR2</DT
3718 ><DD
3719 ><P
3720 >logon client machine unicode string</P
3721 ></DD
3722 ></DL
3723 ></DIV
3724 ></DIV
3725 ><DIV
3726 CLASS="SECT3"
3727 ><HR><H4
3728 CLASS="SECT3"
3729 ><A
3730 NAME="AEN986">CLNT_SRV (server, client names structure)</H4
3731 ><P
3732 ><I
3733 CLASS="EMPHASIS"
3734 >Note:  logon server name starts with two '\' characters and is upper case.</I
3735 ></P
3736 ><P
3737 ></P
3738 ><DIV
3739 CLASS="VARIABLELIST"
3740 ><DL
3741 ><DT
3742 >VOID*</DT
3743 ><DD
3744 ><P
3745 >undocumented buffer pointer</P
3746 ></DD
3747 ><DT
3748 >UNISTR2</DT
3749 ><DD
3750 ><P
3751 >logon server unicode string</P
3752 ></DD
3753 ><DT
3754 >VOID*</DT
3755 ><DD
3756 ><P
3757 >undocumented buffer pointer</P
3758 ></DD
3759 ><DT
3760 >UNISTR2</DT
3761 ><DD
3762 ><P
3763 >logon client machine unicode string</P
3764 ></DD
3765 ></DL
3766 ></DIV
3767 ></DIV
3768 ><DIV
3769 CLASS="SECT3"
3770 ><HR><H4
3771 CLASS="SECT3"
3772 ><A
3773 NAME="AEN1007">CREDS (credentials + time stamp)</H4
3774 ><P
3775 ></P
3776 ><DIV
3777 CLASS="VARIABLELIST"
3778 ><DL
3779 ><DT
3780 >char[8]</DT
3781 ><DD
3782 ><P
3783 >credentials</P
3784 ></DD
3785 ><DT
3786 >UTIME</DT
3787 ><DD
3788 ><P
3789 >time stamp</P
3790 ></DD
3791 ></DL
3792 ></DIV
3793 ></DIV
3794 ><DIV
3795 CLASS="SECT3"
3796 ><HR><H4
3797 CLASS="SECT3"
3798 ><A
3799 NAME="AEN1018">CLNT_INFO2 (server, client structure, client credentials)</H4
3800 ><P
3801 ><I
3802 CLASS="EMPHASIS"
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
3805 ></P
3806 ><P
3807 ></P
3808 ><DIV
3809 CLASS="VARIABLELIST"
3810 ><DL
3811 ><DT
3812 >CLNT_SRV</DT
3813 ><DD
3814 ><P
3815 >client and server names</P
3816 ></DD
3817 ><DT
3818 >UINT8[]</DT
3819 ><DD
3820 ><P
3821 >???? padding, for 4-byte alignment with SMB header.</P
3822 ></DD
3823 ><DT
3824 >VOID*</DT
3825 ><DD
3826 ><P
3827 >pointer to client credentials.</P
3828 ></DD
3829 ><DT
3830 >CREDS</DT
3831 ><DD
3832 ><P
3833 >client-calculated credentials + client time</P
3834 ></DD
3835 ></DL
3836 ></DIV
3837 ></DIV
3838 ><DIV
3839 CLASS="SECT3"
3840 ><HR><H4
3841 CLASS="SECT3"
3842 ><A
3843 NAME="AEN1039">CLNT_INFO (server, account, client structure, client credentials)</H4
3844 ><P
3845 ><I
3846 CLASS="EMPHASIS"
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
3848 ></P
3849 ><P
3850 ></P
3851 ><DIV
3852 CLASS="VARIABLELIST"
3853 ><DL
3854 ><DT
3855 >LOG_INFO</DT
3856 ><DD
3857 ><P
3858 >logon account info</P
3859 ></DD
3860 ><DT
3861 >CREDS</DT
3862 ><DD
3863 ><P
3864 >client-calculated credentials + client time</P
3865 ></DD
3866 ></DL
3867 ></DIV
3868 ></DIV
3869 ><DIV
3870 CLASS="SECT3"
3871 ><HR><H4
3872 CLASS="SECT3"
3873 ><A
3874 NAME="AEN1052">ID_INFO_1 (id info structure, auth level 1)</H4
3875 ><P
3876 ></P
3877 ><DIV
3878 CLASS="VARIABLELIST"
3879 ><DL
3880 ><DT
3881 >VOID*</DT
3882 ><DD
3883 ><P
3884 >ptr_id_info_1</P
3885 ></DD
3886 ><DT
3887 >UNIHDR</DT
3888 ><DD
3889 ><P
3890 >domain name unicode header</P
3891 ></DD
3892 ><DT
3893 >UINT32</DT
3894 ><DD
3895 ><P
3896 >param control</P
3897 ></DD
3898 ><DT
3899 >UINT64</DT
3900 ><DD
3901 ><P
3902 >logon ID</P
3903 ></DD
3904 ><DT
3905 >UNIHDR</DT
3906 ><DD
3907 ><P
3908 >user name unicode header</P
3909 ></DD
3910 ><DT
3911 >UNIHDR</DT
3912 ><DD
3913 ><P
3914 >workgroup name unicode header</P
3915 ></DD
3916 ><DT
3917 >char[16]</DT
3918 ><DD
3919 ><P
3920 >arc4 LM OWF Password</P
3921 ></DD
3922 ><DT
3923 >char[16]</DT
3924 ><DD
3925 ><P
3926 >arc4 NT OWF Password</P
3927 ></DD
3928 ><DT
3929 >UNISTR2</DT
3930 ><DD
3931 ><P
3932 >domain name unicode string</P
3933 ></DD
3934 ><DT
3935 >UNISTR2</DT
3936 ><DD
3937 ><P
3938 >user name unicode string</P
3939 ></DD
3940 ><DT
3941 >UNISTR2</DT
3942 ><DD
3943 ><P
3944 >workstation name unicode string</P
3945 ></DD
3946 ></DL
3947 ></DIV
3948 ></DIV
3949 ><DIV
3950 CLASS="SECT3"
3951 ><HR><H4
3952 CLASS="SECT3"
3953 ><A
3954 NAME="AEN1099">SAM_INFO (sam logon/logoff id info structure)</H4
3955 ><P
3956 ><I
3957 CLASS="EMPHASIS"
3958 >Note: presumably, the return credentials is supposedly for the server to verify that the credential chain hasn't been compromised.</I
3959 ></P
3960 ><P
3961 ></P
3962 ><DIV
3963 CLASS="VARIABLELIST"
3964 ><DL
3965 ><DT
3966 >CLNT_INFO2</DT
3967 ><DD
3968 ><P
3969 >client identification/authentication info</P
3970 ></DD
3971 ><DT
3972 >VOID*</DT
3973 ><DD
3974 ><P
3975 >pointer to return credentials.</P
3976 ></DD
3977 ><DT
3978 >CRED</DT
3979 ><DD
3980 ><P
3981 >return credentials - ignored.</P
3982 ></DD
3983 ><DT
3984 >UINT16</DT
3985 ><DD
3986 ><P
3987 >logon level</P
3988 ></DD
3989 ><DT
3990 >UINT16</DT
3991 ><DD
3992 ><P
3993 >switch value</P
3994 ></DD
3995 ></DL
3996 ></DIV
3997 ><P
3998 ><TABLE
3999 BORDER="0"
4000 BGCOLOR="#E0E0E0"
4001 WIDTH="100%"
4002 ><TR
4003 ><TD
4004 ><PRE
4005 CLASS="PROGRAMLISTING"
4006 >        switch (switch_value)
4007         case 1:
4008         {
4009             ID_INFO_1     id_info_1;
4010         }</PRE
4011 ></TD
4012 ></TR
4013 ></TABLE
4014 ></P
4015 ></DIV
4016 ><DIV
4017 CLASS="SECT3"
4018 ><HR><H4
4019 CLASS="SECT3"
4020 ><A
4021 NAME="AEN1126">GID (group id info)</H4
4022 ><P
4023 ></P
4024 ><DIV
4025 CLASS="VARIABLELIST"
4026 ><DL
4027 ><DT
4028 >UINT32</DT
4029 ><DD
4030 ><P
4031 >group id</P
4032 ></DD
4033 ><DT
4034 >UINT32</DT
4035 ><DD
4036 ><P
4037 >user attributes (only used by NT 3.1 and 3.51)</P
4038 ></DD
4039 ></DL
4040 ></DIV
4041 ></DIV
4042 ><DIV
4043 CLASS="SECT3"
4044 ><HR><H4
4045 CLASS="SECT3"
4046 ><A
4047 NAME="AEN1137">DOM_REF (domain reference info)</H4
4048 ><P
4049 ></P
4050 ><DIV
4051 CLASS="VARIABLELIST"
4052 ><DL
4053 ><DT
4054 >VOID*</DT
4055 ><DD
4056 ><P
4057 >undocumented buffer pointer.</P
4058 ></DD
4059 ><DT
4060 >UINT32</DT
4061 ><DD
4062 ><P
4063 >num referenced domains?</P
4064 ></DD
4065 ><DT
4066 >VOID*</DT
4067 ><DD
4068 ><P
4069 >undocumented domain name buffer pointer.</P
4070 ></DD
4071 ><DT
4072 >UINT32</DT
4073 ><DD
4074 ><P
4075 >32 - max number of entries</P
4076 ></DD
4077 ><DT
4078 >UINT32</DT
4079 ><DD
4080 ><P
4081 >4 - num referenced domains?</P
4082 ></DD
4083 ><DT
4084 >UNIHDR2</DT
4085 ><DD
4086 ><P
4087 >domain name unicode string header</P
4088 ></DD
4089 ><DT
4090 >UNIHDR2[num_ref_doms-1]</DT
4091 ><DD
4092 ><P
4093 >referenced domain unicode string headers</P
4094 ></DD
4095 ><DT
4096 >UNISTR</DT
4097 ><DD
4098 ><P
4099 >domain name unicode string</P
4100 ></DD
4101 ><DT
4102 >DOM_SID[num_ref_doms]</DT
4103 ><DD
4104 ><P
4105 >referenced domain SIDs</P
4106 ></DD
4107 ></DL
4108 ></DIV
4109 ></DIV
4110 ><DIV
4111 CLASS="SECT3"
4112 ><HR><H4
4113 CLASS="SECT3"
4114 ><A
4115 NAME="AEN1176">DOM_INFO (domain info, levels 3 and 5 are the same))</H4
4116 ><P
4117 ></P
4118 ><DIV
4119 CLASS="VARIABLELIST"
4120 ><DL
4121 ><DT
4122 >UINT8[]</DT
4123 ><DD
4124 ><P
4125 >??? padding to get 4-byte alignment with start of SMB header</P
4126 ></DD
4127 ><DT
4128 >UINT16</DT
4129 ><DD
4130 ><P
4131 >domain name string length * 2</P
4132 ></DD
4133 ><DT
4134 >UINT16</DT
4135 ><DD
4136 ><P
4137 >domain name string length * 2</P
4138 ></DD
4139 ><DT
4140 >VOID*</DT
4141 ><DD
4142 ><P
4143 >undocumented domain name string buffer pointer</P
4144 ></DD
4145 ><DT
4146 >VOID*</DT
4147 ><DD
4148 ><P
4149 >undocumented domain SID string buffer pointer</P
4150 ></DD
4151 ><DT
4152 >UNISTR2</DT
4153 ><DD
4154 ><P
4155 >domain name (unicode string)</P
4156 ></DD
4157 ><DT
4158 >DOM_SID</DT
4159 ><DD
4160 ><P
4161 >domain SID</P
4162 ></DD
4163 ></DL
4164 ></DIV
4165 ></DIV
4166 ><DIV
4167 CLASS="SECT3"
4168 ><HR><H4
4169 CLASS="SECT3"
4170 ><A
4171 NAME="AEN1207">USER_INFO (user logon info)</H4
4172 ><P
4173 ><I
4174 CLASS="EMPHASIS"
4175 >Note: it would be nice to know what the 16 byte user session key is for.</I
4176 ></P
4177 ><P
4178 ></P
4179 ><DIV
4180 CLASS="VARIABLELIST"
4181 ><DL
4182 ><DT
4183 >NTTIME</DT
4184 ><DD
4185 ><P
4186 >logon time</P
4187 ></DD
4188 ><DT
4189 >NTTIME</DT
4190 ><DD
4191 ><P
4192 >logoff time</P
4193 ></DD
4194 ><DT
4195 >NTTIME</DT
4196 ><DD
4197 ><P
4198 >kickoff time</P
4199 ></DD
4200 ><DT
4201 >NTTIME</DT
4202 ><DD
4203 ><P
4204 >password last set time</P
4205 ></DD
4206 ><DT
4207 >NTTIME</DT
4208 ><DD
4209 ><P
4210 >password can change time</P
4211 ></DD
4212 ><DT
4213 >NTTIME</DT
4214 ><DD
4215 ><P
4216 >password must change time</P
4217 ></DD
4218 ><DT
4219 >UNIHDR</DT
4220 ><DD
4221 ><P
4222 >username unicode string header</P
4223 ></DD
4224 ><DT
4225 >UNIHDR</DT
4226 ><DD
4227 ><P
4228 >user's full name unicode string header</P
4229 ></DD
4230 ><DT
4231 >UNIHDR</DT
4232 ><DD
4233 ><P
4234 >logon script unicode string header</P
4235 ></DD
4236 ><DT
4237 >UNIHDR</DT
4238 ><DD
4239 ><P
4240 >profile path unicode string header</P
4241 ></DD
4242 ><DT
4243 >UNIHDR</DT
4244 ><DD
4245 ><P
4246 >home directory unicode string header</P
4247 ></DD
4248 ><DT
4249 >UNIHDR</DT
4250 ><DD
4251 ><P
4252 >home directory drive unicode string header</P
4253 ></DD
4254 ><DT
4255 >UINT16</DT
4256 ><DD
4257 ><P
4258 >logon count</P
4259 ></DD
4260 ><DT
4261 >UINT16</DT
4262 ><DD
4263 ><P
4264 >bad password count</P
4265 ></DD
4266 ><DT
4267 >UINT32</DT
4268 ><DD
4269 ><P
4270 >User ID</P
4271 ></DD
4272 ><DT
4273 >UINT32</DT
4274 ><DD
4275 ><P
4276 >Group ID</P
4277 ></DD
4278 ><DT
4279 >UINT32</DT
4280 ><DD
4281 ><P
4282 >num groups</P
4283 ></DD
4284 ><DT
4285 >VOID*</DT
4286 ><DD
4287 ><P
4288 >undocumented buffer pointer to groups.</P
4289 ></DD
4290 ><DT
4291 >UINT32</DT
4292 ><DD
4293 ><P
4294 >user flags</P
4295 ></DD
4296 ><DT
4297 >char[16]</DT
4298 ><DD
4299 ><P
4300 >user session key</P
4301 ></DD
4302 ><DT
4303 >UNIHDR</DT
4304 ><DD
4305 ><P
4306 >logon server unicode string header</P
4307 ></DD
4308 ><DT
4309 >UNIHDR</DT
4310 ><DD
4311 ><P
4312 >logon domain unicode string header</P
4313 ></DD
4314 ><DT
4315 >VOID*</DT
4316 ><DD
4317 ><P
4318 >undocumented logon domain id pointer</P
4319 ></DD
4320 ><DT
4321 >char[40]</DT
4322 ><DD
4323 ><P
4324 >40 undocumented padding bytes.  future expansion?</P
4325 ></DD
4326 ><DT
4327 >UINT32</DT
4328 ><DD
4329 ><P
4330 >0 - num_other_sids?</P
4331 ></DD
4332 ><DT
4333 >VOID*</DT
4334 ><DD
4335 ><P
4336 >NULL - undocumented pointer to other domain SIDs.</P
4337 ></DD
4338 ><DT
4339 >UNISTR2</DT
4340 ><DD
4341 ><P
4342 >username unicode string</P
4343 ></DD
4344 ><DT
4345 >UNISTR2</DT
4346 ><DD
4347 ><P
4348 >user's full name unicode string</P
4349 ></DD
4350 ><DT
4351 >UNISTR2</DT
4352 ><DD
4353 ><P
4354 >logon script unicode string</P
4355 ></DD
4356 ><DT
4357 >UNISTR2</DT
4358 ><DD
4359 ><P
4360 >profile path unicode string</P
4361 ></DD
4362 ><DT
4363 >UNISTR2</DT
4364 ><DD
4365 ><P
4366 >home directory unicode string</P
4367 ></DD
4368 ><DT
4369 >UNISTR2</DT
4370 ><DD
4371 ><P
4372 >home directory drive unicode string</P
4373 ></DD
4374 ><DT
4375 >UINT32</DT
4376 ><DD
4377 ><P
4378 >num groups</P
4379 ></DD
4380 ><DT
4381 >GID[num_groups]</DT
4382 ><DD
4383 ><P
4384 >group info</P
4385 ></DD
4386 ><DT
4387 >UNISTR2</DT
4388 ><DD
4389 ><P
4390 >logon server unicode string</P
4391 ></DD
4392 ><DT
4393 >UNISTR2</DT
4394 ><DD
4395 ><P
4396 >logon domain unicode string</P
4397 ></DD
4398 ><DT
4399 >DOM_SID</DT
4400 ><DD
4401 ><P
4402 >domain SID</P
4403 ></DD
4404 ><DT
4405 >DOM_SID[num_sids]</DT
4406 ><DD
4407 ><P
4408 >other domain SIDs?</P
4409 ></DD
4410 ></DL
4411 ></DIV
4412 ></DIV
4413 ><DIV
4414 CLASS="SECT3"
4415 ><HR><H4
4416 CLASS="SECT3"
4417 ><A
4418 NAME="AEN1364">SH_INFO_1_PTR (pointers to level 1 share info strings)</H4
4419 ><P
4420 ><I
4421 CLASS="EMPHASIS"
4422 >Note:  see cifsrap2.txt section5, page 10.</I
4423 ></P
4424 ><P
4425 ></P
4426 ><TABLE
4427 BORDER="0"
4428 ><TBODY
4429 ><TR
4430 ><TD
4431 >0 for shi1_type indicates a  Disk.</TD
4432 ></TR
4433 ><TR
4434 ><TD
4435 >1 for shi1_type indicates a  Print Queue.</TD
4436 ></TR
4437 ><TR
4438 ><TD
4439 >2 for shi1_type indicates a  Device.</TD
4440 ></TR
4441 ><TR
4442 ><TD
4443 >3 for shi1_type indicates an IPC pipe.</TD
4444 ></TR
4445 ><TR
4446 ><TD
4447 >0x8000 0000 (top bit set in shi1_type) indicates a hidden share.</TD
4448 ></TR
4449 ></TBODY
4450 ></TABLE
4451 ><P
4452 ></P
4453 ><P
4454 ></P
4455 ><DIV
4456 CLASS="VARIABLELIST"
4457 ><DL
4458 ><DT
4459 >VOID*</DT
4460 ><DD
4461 ><P
4462 >shi1_netname - pointer to net name</P
4463 ></DD
4464 ><DT
4465 >UINT32</DT
4466 ><DD
4467 ><P
4468 >shi1_type    - type of share.  0 - undocumented.</P
4469 ></DD
4470 ><DT
4471 >VOID*</DT
4472 ><DD
4473 ><P
4474 >shi1_remark  - pointer to comment.</P
4475 ></DD
4476 ></DL
4477 ></DIV
4478 ></DIV
4479 ><DIV
4480 CLASS="SECT3"
4481 ><HR><H4
4482 CLASS="SECT3"
4483 ><A
4484 NAME="AEN1387">SH_INFO_1_STR (level 1 share info strings)</H4
4485 ><P
4486 ></P
4487 ><DIV
4488 CLASS="VARIABLELIST"
4489 ><DL
4490 ><DT
4491 >UNISTR2</DT
4492 ><DD
4493 ><P
4494 >shi1_netname - unicode string of net name</P
4495 ></DD
4496 ><DT
4497 >UNISTR2</DT
4498 ><DD
4499 ><P
4500 >shi1_remark  - unicode string of comment.</P
4501 ></DD
4502 ></DL
4503 ></DIV
4504 ></DIV
4505 ><DIV
4506 CLASS="SECT3"
4507 ><HR><H4
4508 CLASS="SECT3"
4509 ><A
4510 NAME="AEN1398">SHARE_INFO_1_CTR</H4
4511 ><P
4512 >share container with 0 entries:</P
4513 ><P
4514 ></P
4515 ><DIV
4516 CLASS="VARIABLELIST"
4517 ><DL
4518 ><DT
4519 >UINT32</DT
4520 ><DD
4521 ><P
4522 >0 - EntriesRead</P
4523 ></DD
4524 ><DT
4525 >UINT32</DT
4526 ><DD
4527 ><P
4528 >0 - Buffer</P
4529 ></DD
4530 ></DL
4531 ></DIV
4532 ><P
4533 >share container with &#62; 0 entries:</P
4534 ><P
4535 ></P
4536 ><DIV
4537 CLASS="VARIABLELIST"
4538 ><DL
4539 ><DT
4540 >UINT32</DT
4541 ><DD
4542 ><P
4543 >EntriesRead</P
4544 ></DD
4545 ><DT
4546 >UINT32</DT
4547 ><DD
4548 ><P
4549 >non-zero - Buffer</P
4550 ></DD
4551 ><DT
4552 >UINT32</DT
4553 ><DD
4554 ><P
4555 >EntriesRead</P
4556 ></DD
4557 ><DT
4558 >SH_INFO_1_PTR[EntriesRead]</DT
4559 ><DD
4560 ><P
4561 >share entry pointers</P
4562 ></DD
4563 ><DT
4564 >SH_INFO_1_STR[EntriesRead]</DT
4565 ><DD
4566 ><P
4567 >share entry strings</P
4568 ></DD
4569 ><DT
4570 >UINT8[]</DT
4571 ><DD
4572 ><P
4573 >padding to get unicode string 4-byte aligned with start of the SMB header.</P
4574 ></DD
4575 ><DT
4576 >UINT32</DT
4577 ><DD
4578 ><P
4579 >EntriesRead</P
4580 ></DD
4581 ><DT
4582 >UINT32</DT
4583 ><DD
4584 ><P
4585 >0 - padding</P
4586 ></DD
4587 ></DL
4588 ></DIV
4589 ></DIV
4590 ><DIV
4591 CLASS="SECT3"
4592 ><HR><H4
4593 CLASS="SECT3"
4594 ><A
4595 NAME="AEN1444">SERVER_INFO_101</H4
4596 ><P
4597 ><I
4598 CLASS="EMPHASIS"
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
4600 ></P
4601 ><P
4602 ></P
4603 ><DIV
4604 CLASS="VARIABLELIST"
4605 ><DL
4606 ><DT
4607 >SV_TYPE_WORKSTATION</DT
4608 ><DD
4609 ><P
4610 >0x00000001  All workstations</P
4611 ></DD
4612 ><DT
4613 >SV_TYPE_SERVER</DT
4614 ><DD
4615 ><P
4616 >0x00000002  All servers</P
4617 ></DD
4618 ><DT
4619 >SV_TYPE_SQLSERVER</DT
4620 ><DD
4621 ><P
4622 >0x00000004  Any server running with SQL server</P
4623 ></DD
4624 ><DT
4625 >SV_TYPE_DOMAIN_CTRL</DT
4626 ><DD
4627 ><P
4628 >0x00000008  Primary domain controller</P
4629 ></DD
4630 ><DT
4631 >SV_TYPE_DOMAIN_BAKCTRL</DT
4632 ><DD
4633 ><P
4634 >0x00000010  Backup domain controller</P
4635 ></DD
4636 ><DT
4637 >SV_TYPE_TIME_SOURCE</DT
4638 ><DD
4639 ><P
4640 >0x00000020  Server running the timesource service</P
4641 ></DD
4642 ><DT
4643 >SV_TYPE_AFP</DT
4644 ><DD
4645 ><P
4646 >0x00000040  Apple File Protocol servers</P
4647 ></DD
4648 ><DT
4649 >SV_TYPE_NOVELL</DT
4650 ><DD
4651 ><P
4652 >0x00000080  Novell servers</P
4653 ></DD
4654 ><DT
4655 >SV_TYPE_DOMAIN_MEMBER</DT
4656 ><DD
4657 ><P
4658 >0x00000100  Domain Member</P
4659 ></DD
4660 ><DT
4661 >SV_TYPE_PRINTQ_SERVER</DT
4662 ><DD
4663 ><P
4664 >0x00000200  Server sharing print queue</P
4665 ></DD
4666 ><DT
4667 >SV_TYPE_DIALIN_SERVER</DT
4668 ><DD
4669 ><P
4670 >0x00000400  Server running dialin service.</P
4671 ></DD
4672 ><DT
4673 >SV_TYPE_XENIX_SERVER</DT
4674 ><DD
4675 ><P
4676 >0x00000800  Xenix server</P
4677 ></DD
4678 ><DT
4679 >SV_TYPE_NT</DT
4680 ><DD
4681 ><P
4682 >0x00001000  NT server</P
4683 ></DD
4684 ><DT
4685 >SV_TYPE_WFW</DT
4686 ><DD
4687 ><P
4688 >0x00002000  Server running Windows for </P
4689 ></DD
4690 ><DT
4691 >SV_TYPE_SERVER_NT</DT
4692 ><DD
4693 ><P
4694 >0x00008000  Windows NT non DC server</P
4695 ></DD
4696 ><DT
4697 >SV_TYPE_POTENTIAL_BROWSER</DT
4698 ><DD
4699 ><P
4700 >0x00010000  Server that can run the browser service</P
4701 ></DD
4702 ><DT
4703 >SV_TYPE_BACKUP_BROWSER</DT
4704 ><DD
4705 ><P
4706 >0x00020000  Backup browser server</P
4707 ></DD
4708 ><DT
4709 >SV_TYPE_MASTER_BROWSER</DT
4710 ><DD
4711 ><P
4712 >0x00040000  Master browser server</P
4713 ></DD
4714 ><DT
4715 >SV_TYPE_DOMAIN_MASTER</DT
4716 ><DD
4717 ><P
4718 >0x00080000  Domain Master Browser server</P
4719 ></DD
4720 ><DT
4721 >SV_TYPE_LOCAL_LIST_ONLY</DT
4722 ><DD
4723 ><P
4724 >0x40000000  Enumerate only entries marked "local"</P
4725 ></DD
4726 ><DT
4727 >SV_TYPE_DOMAIN_ENUM</DT
4728 ><DD
4729 ><P
4730 >0x80000000  Enumerate Domains. The pszServer and pszDomain parameters must be NULL.</P
4731 ></DD
4732 ></DL
4733 ></DIV
4734 ><P
4735 ></P
4736 ><DIV
4737 CLASS="VARIABLELIST"
4738 ><DL
4739 ><DT
4740 >UINT32</DT
4741 ><DD
4742 ><P
4743 >500 - platform_id</P
4744 ></DD
4745 ><DT
4746 >VOID*</DT
4747 ><DD
4748 ><P
4749 >pointer to name</P
4750 ></DD
4751 ><DT
4752 >UINT32</DT
4753 ><DD
4754 ><P
4755 >5 - major version</P
4756 ></DD
4757 ><DT
4758 >UINT32</DT
4759 ><DD
4760 ><P
4761 >4 - minor version</P
4762 ></DD
4763 ><DT
4764 >UINT32</DT
4765 ><DD
4766 ><P
4767 >type (SV_TYPE_... bit field)</P
4768 ></DD
4769 ><DT
4770 >VOID*</DT
4771 ><DD
4772 ><P
4773 >pointer to comment</P
4774 ></DD
4775 ><DT
4776 >UNISTR2</DT
4777 ><DD
4778 ><P
4779 >sv101_name - unicode string of server name</P
4780 ></DD
4781 ><DT
4782 >UNISTR2</DT
4783 ><DD
4784 ><P
4785 >sv_101_comment  - unicode string of server comment.</P
4786 ></DD
4787 ><DT
4788 >UINT8[]</DT
4789 ><DD
4790 ><P
4791 >padding to get unicode string 4-byte aligned with start of the SMB header.</P
4792 ></DD
4793 ></DL
4794 ></DIV
4795 ></DIV
4796 ></DIV
4797 ></DIV
4798 ><DIV
4799 CLASS="SECT1"
4800 ><HR><H2
4801 CLASS="SECT1"
4802 ><A
4803 NAME="AEN1570">MSRPC over Transact Named Pipe</H2
4804 ><P
4805 >For details on the SMB Transact Named Pipe, see cifs6.txt</P
4806 ><DIV
4807 CLASS="SECT2"
4808 ><HR><H3
4809 CLASS="SECT2"
4810 ><A
4811 NAME="AEN1573">MSRPC Pipes</H3
4812 ><P
4813 >The MSRPC is conducted over an SMB Transact Pipe with a name of 
4814 <TT
4815 CLASS="FILENAME"
4816 >\PIPE\</TT
4817 >.  You must first obtain a 16 bit file handle, by
4818 sending a SMBopenX with the pipe name <TT
4819 CLASS="FILENAME"
4820 >\PIPE\srvsvc</TT
4821 > for
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
4824 ><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,
4830 obtained above.</P
4831 ><P
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
4836 ><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
4839 ><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
4844 MSRPC data.</P
4845 ><P
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
4850 is sent.</P
4851 ><P
4852 >To be resolved:</P
4853 ><P
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
4855 listed below:</P
4856 ><P
4857 ><TABLE
4858 BORDER="0"
4859 BGCOLOR="#E0E0E0"
4860 WIDTH="100%"
4861 ><TR
4862 ><TD
4863 ><PRE
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
4868 ></TD
4869 ></TR
4870 ></TABLE
4871 ></P
4872 ></DIV
4873 ><DIV
4874 CLASS="SECT2"
4875 ><HR><H3
4876 CLASS="SECT2"
4877 ><A
4878 NAME="AEN1587">Header</H3
4879 ><P
4880 >[section to be rewritten, following receipt of work by Duncan Stansfield]</P
4881 ><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
4884 ><P
4885 >The start of each of the NTLSA and NETLOGON named pipes begins with:</P
4886 ><P
4887 ><B
4888 >offset: </B
4889 >00</P
4890 ><P
4891 ><B
4892 >Variable type: </B
4893 >UINT8</P
4894 ><P
4895 ><B
4896 >Variable data: </B
4897 >5 - RPC major version</P
4898 ><P
4899 ><B
4900 >offset: </B
4901 >01</P
4902 ><P
4903 ><B
4904 >Variable type: </B
4905 >UINT8</P
4906 ><P
4907 ><B
4908 >Variable data: </B
4909 >0 - RPC minor version</P
4910 ><P
4911 ><B
4912 >offset: </B
4913 >02</P
4914 ><P
4915 ><B
4916 >Variable type: </B
4917 >UINT8</P
4918 ><P
4919 ><B
4920 >Variable data: </B
4921 >2 - RPC response packet</P
4922 ><P
4923 ><B
4924 >offset: </B
4925 >03</P
4926 ><P
4927 ><B
4928 >Variable type: </B
4929 >UINT8</P
4930 ><P
4931 ><B
4932 >Variable data: </B
4933 >3 - (FirstFrag bit-wise or with LastFrag)</P
4934 ><P
4935 ><B
4936 >offset: </B
4937 >04</P
4938 ><P
4939 ><B
4940 >Variable type: </B
4941 >UINT32</P
4942 ><P
4943 ><B
4944 >Variable data: </B
4945 >0x1000 0000 - packed data representation</P
4946 ><P
4947 ><B
4948 >offset: </B
4949 >08</P
4950 ><P
4951 ><B
4952 >Variable type: </B
4953 >UINT16</P
4954 ><P
4955 ><B
4956 >Variable data: </B
4957 >fragment length - data size (bytes) inc header and tail.</P
4958 ><P
4959 ><B
4960 >offset: </B
4961 >0A</P
4962 ><P
4963 ><B
4964 >Variable type: </B
4965 >UINT16</P
4966 ><P
4967 ><B
4968 >Variable data: </B
4969 >0 - authentication length </P
4970 ><P
4971 ><B
4972 >offset: </B
4973 >0C</P
4974 ><P
4975 ><B
4976 >Variable type: </B
4977 >UINT32</P
4978 ><P
4979 ><B
4980 >Variable data: </B
4981 >call identifier. matches 12th UINT32 of incoming RPC data.</P
4982 ><P
4983 ><B
4984 >offset: </B
4985 >10</P
4986 ><P
4987 ><B
4988 >Variable type: </B
4989 >UINT32</P
4990 ><P
4991 ><B
4992 >Variable data: </B
4993 >allocation hint - data size (bytes) minus header and tail.</P
4994 ><P
4995 ><B
4996 >offset: </B
4997 >14</P
4998 ><P
4999 ><B
5000 >Variable type: </B
5001 >UINT16</P
5002 ><P
5003 ><B
5004 >Variable data: </B
5005 >0 - presentation context identifier</P
5006 ><P
5007 ><B
5008 >offset: </B
5009 >16</P
5010 ><P
5011 ><B
5012 >Variable type: </B
5013 >UINT8</P
5014 ><P
5015 ><B
5016 >Variable data: </B
5017 >0 - cancel count</P
5018 ><P
5019 ><B
5020 >offset: </B
5021 >17</P
5022 ><P
5023 ><B
5024 >Variable type: </B
5025 >UINT8</P
5026 ><P
5027 ><B
5028 >Variable data: </B
5029 >in replies: 0 - reserved; in requests: opnum - see #defines.</P
5030 ><P
5031 ><B
5032 >offset: </B
5033 >18</P
5034 ><P
5035 ><B
5036 >Variable type: </B
5037 >......</P
5038 ><P
5039 ><B
5040 >Variable data: </B
5041 >start of data (goes on for allocation_hint bytes)</P
5042 ><DIV
5043 CLASS="SECT3"
5044 ><HR><H4
5045 CLASS="SECT3"
5046 ><A
5047 NAME="AEN1648">RPC_Packet for request, response, bind and bind acknowledgement</H4
5048 ><P
5049 ></P
5050 ><DIV
5051 CLASS="VARIABLELIST"
5052 ><DL
5053 ><DT
5054 >UINT8 versionmaj</DT
5055 ><DD
5056 ><P
5057 >reply same as request (0x05)</P
5058 ></DD
5059 ><DT
5060 >UINT8 versionmin</DT
5061 ><DD
5062 ><P
5063 >reply same as request (0x00)</P
5064 ></DD
5065 ><DT
5066 >UINT8 type</DT
5067 ><DD
5068 ><P
5069 >one of the MSRPC_Type enums</P
5070 ></DD
5071 ><DT
5072 >UINT8 flags</DT
5073 ><DD
5074 ><P
5075 >reply same as request (0x00 for Bind, 0x03 for Request)</P
5076 ></DD
5077 ><DT
5078 >UINT32 representation</DT
5079 ><DD
5080 ><P
5081 >reply same as request (0x00000010)</P
5082 ></DD
5083 ><DT
5084 >UINT16 fraglength</DT
5085 ><DD
5086 ><P
5087 >the length of the data section of the SMB trans packet</P
5088 ></DD
5089 ><DT
5090 >UINT16 authlength</DT
5091 ><DD
5092 ><P
5093 ></P
5094 ></DD
5095 ><DT
5096 >UINT32 callid</DT
5097 ><DD
5098 ><P
5099 >call identifier. (e.g. 0x00149594)</P
5100 ></DD
5101 ><DT
5102 >* stub USE TvPacket</DT
5103 ><DD
5104 ><P
5105 >the remainder of the packet depending on the "type"</P
5106 ></DD
5107 ></DL
5108 ></DIV
5109 ></DIV
5110 ><DIV
5111 CLASS="SECT3"
5112 ><HR><H4
5113 CLASS="SECT3"
5114 ><A
5115 NAME="AEN1687">Interface identification</H4
5116 ><P
5117 >the interfaces are numbered. as yet I haven't seen more than one interface used on the same pipe name srvsvc</P
5118 ><P
5119 ><TABLE
5120 BORDER="0"
5121 BGCOLOR="#E0E0E0"
5122 WIDTH="100%"
5123 ><TR
5124 ><TD
5125 ><PRE
5126 CLASS="PROGRAMLISTING"
5127 >abstract (0x4B324FC8, 0x01D31670, 0x475A7812, 0x88E16EBF, 0x00000003)
5128 transfer (0x8A885D04, 0x11C91CEB, 0x0008E89F, 0x6048102B, 0x00000002)</PRE
5129 ></TD
5130 ></TR
5131 ></TABLE
5132 ></P
5133 ></DIV
5134 ><DIV
5135 CLASS="SECT3"
5136 ><HR><H4
5137 CLASS="SECT3"
5138 ><A
5139 NAME="AEN1692">RPC_Iface RW</H4
5140 ><P
5141 ></P
5142 ><DIV
5143 CLASS="VARIABLELIST"
5144 ><DL
5145 ><DT
5146 >UINT8 byte[16]</DT
5147 ><DD
5148 ><P
5149 >16 bytes of number</P
5150 ></DD
5151 ><DT
5152 >UINT32 version</DT
5153 ><DD
5154 ><P
5155 >the interface number</P
5156 ></DD
5157 ></DL
5158 ></DIV
5159 ></DIV
5160 ><DIV
5161 CLASS="SECT3"
5162 ><HR><H4
5163 CLASS="SECT3"
5164 ><A
5165 NAME="AEN1703">RPC_ReqBind RW</H4
5166 ><P
5167 >the remainder of the packet after the header if "type" was Bind in the response header, "type" should be BindAck</P
5168 ><P
5169 ></P
5170 ><DIV
5171 CLASS="VARIABLELIST"
5172 ><DL
5173 ><DT
5174 >UINT16 maxtsize</DT
5175 ><DD
5176 ><P
5177 >maximum transmission fragment size (0x1630)</P
5178 ></DD
5179 ><DT
5180 >UINT16 maxrsize</DT
5181 ><DD
5182 ><P
5183 >max receive fragment size (0x1630)</P
5184 ></DD
5185 ><DT
5186 >UINT32 assocgid</DT
5187 ><DD
5188 ><P
5189 >associated group id (0x0)</P
5190 ></DD
5191 ><DT
5192 >UINT32 numelements</DT
5193 ><DD
5194 ><P
5195 >the number of elements (0x1)</P
5196 ></DD
5197 ><DT
5198 >UINT16 contextid</DT
5199 ><DD
5200 ><P
5201 >presentation context identifier (0x0)</P
5202 ></DD
5203 ><DT
5204 >UINT8 numsyntaxes</DT
5205 ><DD
5206 ><P
5207 >the number of syntaxes (has always been 1?)(0x1)</P
5208 ></DD
5209 ><DT
5210 >UINT8[]</DT
5211 ><DD
5212 ><P
5213 >4-byte alignment padding, against SMB header</P
5214 ></DD
5215 ><DT
5216 >* abstractint USE RPC_Iface</DT
5217 ><DD
5218 ><P
5219 >num and vers. of interface client is using</P
5220 ></DD
5221 ><DT
5222 >* transferint USE RPC_Iface</DT
5223 ><DD
5224 ><P
5225 >num and vers. of interface to use for replies</P
5226 ></DD
5227 ></DL
5228 ></DIV
5229 ></DIV
5230 ><DIV
5231 CLASS="SECT3"
5232 ><HR><H4
5233 CLASS="SECT3"
5234 ><A
5235 NAME="AEN1743">RPC_Address RW</H4
5236 ><P
5237 ></P
5238 ><DIV
5239 CLASS="VARIABLELIST"
5240 ><DL
5241 ><DT
5242 >UINT16 length</DT
5243 ><DD
5244 ><P
5245 >length of the string including null terminator</P
5246 ></DD
5247 ><DT
5248 >* port USE string</DT
5249 ><DD
5250 ><P
5251 >the string above in single byte, null terminated form</P
5252 ></DD
5253 ></DL
5254 ></DIV
5255 ></DIV
5256 ><DIV
5257 CLASS="SECT3"
5258 ><HR><H4
5259 CLASS="SECT3"
5260 ><A
5261 NAME="AEN1754">RPC_ResBind RW</H4
5262 ><P
5263 >the response to place after the header in the reply packet</P
5264 ><P
5265 ></P
5266 ><DIV
5267 CLASS="VARIABLELIST"
5268 ><DL
5269 ><DT
5270 >UINT16 maxtsize</DT
5271 ><DD
5272 ><P
5273 >same as request</P
5274 ></DD
5275 ><DT
5276 >UINT16 maxrsize</DT
5277 ><DD
5278 ><P
5279 >same as request</P
5280 ></DD
5281 ><DT
5282 >UINT32 assocgid</DT
5283 ><DD
5284 ><P
5285 >zero</P
5286 ></DD
5287 ><DT
5288 >* secondaddr USE RPC_Address</DT
5289 ><DD
5290 ><P
5291 >the address string, as described earlier</P
5292 ></DD
5293 ><DT
5294 >UINT8[]</DT
5295 ><DD
5296 ><P
5297 >4-byte alignment padding, against SMB header</P
5298 ></DD
5299 ><DT
5300 >UINT8 numresults</DT
5301 ><DD
5302 ><P
5303 >the number of results (0x01)</P
5304 ></DD
5305 ><DT
5306 >UINT8[]</DT
5307 ><DD
5308 ><P
5309 >4-byte alignment padding, against SMB header</P
5310 ></DD
5311 ><DT
5312 >UINT16 result</DT
5313 ><DD
5314 ><P
5315 >result (0x00 = accept)</P
5316 ></DD
5317 ><DT
5318 >UINT16 reason</DT
5319 ><DD
5320 ><P
5321 >reason (0x00 = no reason specified)</P
5322 ></DD
5323 ><DT
5324 >* transfersyntax USE RPC_Iface</DT
5325 ><DD
5326 ><P
5327 >the transfer syntax from the request</P
5328 ></DD
5329 ></DL
5330 ></DIV
5331 ></DIV
5332 ><DIV
5333 CLASS="SECT3"
5334 ><HR><H4
5335 CLASS="SECT3"
5336 ><A
5337 NAME="AEN1798">RPC_ReqNorm RW</H4
5338 ><P
5339 >the remainder of the packet after the header for every other other request</P
5340 ><P
5341 ></P
5342 ><DIV
5343 CLASS="VARIABLELIST"
5344 ><DL
5345 ><DT
5346 >UINT32 allochint</DT
5347 ><DD
5348 ><P
5349 >the size of the stub data in bytes</P
5350 ></DD
5351 ><DT
5352 >UINT16 prescontext</DT
5353 ><DD
5354 ><P
5355 >presentation context identifier (0x0)</P
5356 ></DD
5357 ><DT
5358 >UINT16 opnum</DT
5359 ><DD
5360 ><P
5361 >operation number (0x15)</P
5362 ></DD
5363 ><DT
5364 >* stub USE TvPacket</DT
5365 ><DD
5366 ><P
5367 >a packet dependent on the pipe name (probably the interface) and the op number)</P
5368 ></DD
5369 ></DL
5370 ></DIV
5371 ></DIV
5372 ><DIV
5373 CLASS="SECT3"
5374 ><HR><H4
5375 CLASS="SECT3"
5376 ><A
5377 NAME="AEN1818">RPC_ResNorm RW</H4
5378 ><P
5379 ></P
5380 ><DIV
5381 CLASS="VARIABLELIST"
5382 ><DL
5383 ><DT
5384 >UINT32 allochint</DT
5385 ><DD
5386 ><P
5387 ># size of the stub data in bytes</P
5388 ></DD
5389 ><DT
5390 >UINT16 prescontext</DT
5391 ><DD
5392 ><P
5393 ># presentation context identifier (same as request)</P
5394 ></DD
5395 ><DT
5396 >UINT8 cancelcount</DT
5397 ><DD
5398 ><P
5399 ># cancel count? (0x0)</P
5400 ></DD
5401 ><DT
5402 >UINT8 reserved</DT
5403 ><DD
5404 ><P
5405 ># 0 - one byte padding</P
5406 ></DD
5407 ><DT
5408 >* stub USE TvPacket</DT
5409 ><DD
5410 ><P
5411 ># the remainder of the reply</P
5412 ></DD
5413 ></DL
5414 ></DIV
5415 ></DIV
5416 ></DIV
5417 ><DIV
5418 CLASS="SECT2"
5419 ><HR><H3
5420 CLASS="SECT2"
5421 ><A
5422 NAME="AEN1841">Tail</H3
5423 ><P
5424 >The end of each of the NTLSA and NETLOGON named pipes ends with:</P
5425 ><P
5426 ></P
5427 ><DIV
5428 CLASS="VARIABLELIST"
5429 ><DL
5430 ><DT
5431 >......</DT
5432 ><DD
5433 ><P
5434 >end of data</P
5435 ></DD
5436 ><DT
5437 >UINT32</DT
5438 ><DD
5439 ><P
5440 >return code</P
5441 ></DD
5442 ></DL
5443 ></DIV
5444 ></DIV
5445 ><DIV
5446 CLASS="SECT2"
5447 ><HR><H3
5448 CLASS="SECT2"
5449 ><A
5450 NAME="AEN1853">RPC Bind / Bind Ack</H3
5451 ><P
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
5454 this is unknown.</P
5455 ><P
5456 ><I
5457 CLASS="EMPHASIS"
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
5460 ></P
5461 ><P
5462 ><I
5463 CLASS="EMPHASIS"
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
5466         the</I
5467 ></P
5468 ><P
5469 ><I
5470 CLASS="EMPHASIS"
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
5473 ></P
5474 ><P
5475 ></P
5476 ><DIV
5477 CLASS="VARIABLELIST"
5478 ><DL
5479 ><DT
5480 >initial SMBopenX request:</DT
5481 ><DD
5482 ><P
5483 >RPC_ResBind response:</P
5484 ></DD
5485 ><DT
5486 >"\\PIPE\\srvsvc"</DT
5487 ><DD
5488 ><P
5489 >"\\PIPE\\ntsvcs"</P
5490 ></DD
5491 ><DT
5492 >"\\PIPE\\samr"</DT
5493 ><DD
5494 ><P
5495 >"\\PIPE\\lsass"</P
5496 ></DD
5497 ><DT
5498 >"\\PIPE\\lsarpc"</DT
5499 ><DD
5500 ><P
5501 >"\\PIPE\\lsass"</P
5502 ></DD
5503 ><DT
5504 >"\\PIPE\\wkssvc"</DT
5505 ><DD
5506 ><P
5507 >"\\PIPE\\wksvcs"</P
5508 ></DD
5509 ><DT
5510 >"\\PIPE\\NETLOGON"</DT
5511 ><DD
5512 ><P
5513 >"\\PIPE\\NETLOGON"</P
5514 ></DD
5515 ></DL
5516 ></DIV
5517 ><P
5518 ><I
5519 CLASS="EMPHASIS"
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
5521 ></P
5522 ><P
5523 >Request:</P
5524 ><P
5525 ></P
5526 ><TABLE
5527 BORDER="0"
5528 ><TBODY
5529 ><TR
5530 ><TD
5531 >RPC_Packet</TD
5532 ></TR
5533 ><TR
5534 ><TD
5535 >RPC_ReqBind</TD
5536 ></TR
5537 ></TBODY
5538 ></TABLE
5539 ><P
5540 ></P
5541 ><P
5542 >Response:</P
5543 ><P
5544 ></P
5545 ><TABLE
5546 BORDER="0"
5547 ><TBODY
5548 ><TR
5549 ><TD
5550 >RPC_Packet</TD
5551 ></TR
5552 ><TR
5553 ><TD
5554 >RPC_ResBind</TD
5555 ></TR
5556 ></TBODY
5557 ></TABLE
5558 ><P
5559 ></P
5560 ></DIV
5561 ><DIV
5562 CLASS="SECT2"
5563 ><HR><H3
5564 CLASS="SECT2"
5565 ><A
5566 NAME="AEN1897">NTLSA Transact Named Pipe</H3
5567 ><P
5568 >The sequence of actions taken on this pipe are:</P
5569 ><P
5570 ></P
5571 ><TABLE
5572 BORDER="0"
5573 ><TBODY
5574 ><TR
5575 ><TD
5576 >Establish a connection to the IPC$ share (SMBtconX).  use encrypted passwords.</TD
5577 ></TR
5578 ><TR
5579 ><TD
5580 >Open an RPC Pipe with the name "\\PIPE\\lsarpc".  Store the file handle.</TD
5581 ></TR
5582 ><TR
5583 ><TD
5584 >Using the file handle, send a Set Named Pipe Handle state to 0x4300.</TD
5585 ></TR
5586 ><TR
5587 ><TD
5588 >Send an LSA Open Policy request.  Store the Policy Handle.</TD
5589 ></TR
5590 ><TR
5591 ><TD
5592 >Using the Policy Handle, send LSA Query Info Policy requests, etc.</TD
5593 ></TR
5594 ><TR
5595 ><TD
5596 >Using the Policy Handle, send an LSA Close.</TD
5597 ></TR
5598 ><TR
5599 ><TD
5600 >Close the IPC$ share.</TD
5601 ></TR
5602 ></TBODY
5603 ></TABLE
5604 ><P
5605 ></P
5606 ><P
5607 >Defines for this pipe, identifying the query are:</P
5608 ><P
5609 ></P
5610 ><DIV
5611 CLASS="VARIABLELIST"
5612 ><DL
5613 ><DT
5614 >LSA Open Policy:</DT
5615 ><DD
5616 ><P
5617 >0x2c</P
5618 ></DD
5619 ><DT
5620 >LSA Query Info Policy:</DT
5621 ><DD
5622 ><P
5623 >0x07</P
5624 ></DD
5625 ><DT
5626 >LSA Enumerate Trusted Domains:</DT
5627 ><DD
5628 ><P
5629 >0x0d</P
5630 ></DD
5631 ><DT
5632 >LSA Open Secret:</DT
5633 ><DD
5634 ><P
5635 >0xff</P
5636 ></DD
5637 ><DT
5638 >LSA Lookup SIDs:</DT
5639 ><DD
5640 ><P
5641 >0xfe</P
5642 ></DD
5643 ><DT
5644 >LSA Lookup Names:</DT
5645 ><DD
5646 ><P
5647 >0xfd</P
5648 ></DD
5649 ><DT
5650 >LSA Close:</DT
5651 ><DD
5652 ><P
5653 >0x00</P
5654 ></DD
5655 ></DL
5656 ></DIV
5657 ></DIV
5658 ><DIV
5659 CLASS="SECT2"
5660 ><HR><H3
5661 CLASS="SECT2"
5662 ><A
5663 NAME="AEN1938">LSA Open Policy</H3
5664 ><P
5665 ><I
5666 CLASS="EMPHASIS"
5667 >Note:  The policy handle can be anything you like.</I
5668 ></P
5669 ><DIV
5670 CLASS="SECT3"
5671 ><HR><H4
5672 CLASS="SECT3"
5673 ><A
5674 NAME="AEN1942">Request</H4
5675 ><P
5676 ></P
5677 ><DIV
5678 CLASS="VARIABLELIST"
5679 ><DL
5680 ><DT
5681 >VOID*</DT
5682 ><DD
5683 ><P
5684 >buffer pointer</P
5685 ></DD
5686 ><DT
5687 >UNISTR2</DT
5688 ><DD
5689 ><P
5690 >server name - unicode string starting with two '\'s</P
5691 ></DD
5692 ><DT
5693 >OBJ_ATTR</DT
5694 ><DD
5695 ><P
5696 >object attributes</P
5697 ></DD
5698 ><DT
5699 >UINT32</DT
5700 ><DD
5701 ><P
5702 >1 - desired access</P
5703 ></DD
5704 ></DL
5705 ></DIV
5706 ></DIV
5707 ><DIV
5708 CLASS="SECT3"
5709 ><HR><H4
5710 CLASS="SECT3"
5711 ><A
5712 NAME="AEN1961">Response</H4
5713 ><P
5714 ></P
5715 ><DIV
5716 CLASS="VARIABLELIST"
5717 ><DL
5718 ><DT
5719 >POL_HND</DT
5720 ><DD
5721 ><P
5722 >LSA policy handle</P
5723 ></DD
5724 ><DT
5725 >return</DT
5726 ><DD
5727 ><P
5728 >0 - indicates success</P
5729 ></DD
5730 ></DL
5731 ></DIV
5732 ></DIV
5733 ></DIV
5734 ><DIV
5735 CLASS="SECT2"
5736 ><HR><H3
5737 CLASS="SECT2"
5738 ><A
5739 NAME="AEN1972">LSA Query Info Policy</H3
5740 ><P
5741 ><I
5742 CLASS="EMPHASIS"
5743 >Note:  The info class in response must be the same as that in the request.</I
5744 ></P
5745 ><DIV
5746 CLASS="SECT3"
5747 ><HR><H4
5748 CLASS="SECT3"
5749 ><A
5750 NAME="AEN1976">Request</H4
5751 ><P
5752 ></P
5753 ><DIV
5754 CLASS="VARIABLELIST"
5755 ><DL
5756 ><DT
5757 >POL_HND</DT
5758 ><DD
5759 ><P
5760 >LSA policy handle</P
5761 ></DD
5762 ><DT
5763 >UINT16</DT
5764 ><DD
5765 ><P
5766 >info class (also a policy handle?)</P
5767 ></DD
5768 ></DL
5769 ></DIV
5770 ></DIV
5771 ><DIV
5772 CLASS="SECT3"
5773 ><HR><H4
5774 CLASS="SECT3"
5775 ><A
5776 NAME="AEN1987">Response</H4
5777 ><P
5778 ></P
5779 ><DIV
5780 CLASS="VARIABLELIST"
5781 ><DL
5782 ><DT
5783 >VOID*</DT
5784 ><DD
5785 ><P
5786 >undocumented buffer pointer</P
5787 ></DD
5788 ><DT
5789 >UINT16</DT
5790 ><DD
5791 ><P
5792 >info class (same as info class in request).</P
5793 ></DD
5794 ></DL
5795 ></DIV
5796 ><P
5797 ><TABLE
5798 BORDER="0"
5799 BGCOLOR="#E0E0E0"
5800 WIDTH="100%"
5801 ><TR
5802 ><TD
5803 ><PRE
5804 CLASS="PROGRAMLISTING"
5805 >switch (info class)
5806 case 3:
5807 case 5:
5808 {
5809 DOM_INFO domain info, levels 3 and 5 (are the same).
5810 }
5811
5812 return    0 - indicates success</PRE
5813 ></TD
5814 ></TR
5815 ></TABLE
5816 ></P
5817 ></DIV
5818 ></DIV
5819 ><DIV
5820 CLASS="SECT2"
5821 ><HR><H3
5822 CLASS="SECT2"
5823 ><A
5824 NAME="AEN2000">LSA Enumerate Trusted Domains</H3
5825 ><DIV
5826 CLASS="SECT3"
5827 ><H4
5828 CLASS="SECT3"
5829 ><A
5830 NAME="AEN2002">Request</H4
5831 ><P
5832 >no extra data</P
5833 ></DIV
5834 ><DIV
5835 CLASS="SECT3"
5836 ><HR><H4
5837 CLASS="SECT3"
5838 ><A
5839 NAME="AEN2005">Response</H4
5840 ><P
5841 ></P
5842 ><DIV
5843 CLASS="VARIABLELIST"
5844 ><DL
5845 ><DT
5846 >UINT32</DT
5847 ><DD
5848 ><P
5849 >0 - enumeration context</P
5850 ></DD
5851 ><DT
5852 >UINT32</DT
5853 ><DD
5854 ><P
5855 >0 - entries read</P
5856 ></DD
5857 ><DT
5858 >UINT32</DT
5859 ><DD
5860 ><P
5861 >0 - trust information</P
5862 ></DD
5863 ><DT
5864 >return</DT
5865 ><DD
5866 ><P
5867 >0x8000 001a - "no trusted domains" success code</P
5868 ></DD
5869 ></DL
5870 ></DIV
5871 ></DIV
5872 ></DIV
5873 ><DIV
5874 CLASS="SECT2"
5875 ><HR><H3
5876 CLASS="SECT2"
5877 ><A
5878 NAME="AEN2024">LSA Open Secret</H3
5879 ><DIV
5880 CLASS="SECT3"
5881 ><H4
5882 CLASS="SECT3"
5883 ><A
5884 NAME="AEN2026">Request</H4
5885 ><P
5886 >no extra data</P
5887 ></DIV
5888 ><DIV
5889 CLASS="SECT3"
5890 ><HR><H4
5891 CLASS="SECT3"
5892 ><A
5893 NAME="AEN2029">Response</H4
5894 ><P
5895 ></P
5896 ><DIV
5897 CLASS="VARIABLELIST"
5898 ><DL
5899 ><DT
5900 >UINT32</DT
5901 ><DD
5902 ><P
5903 >0 - undocumented</P
5904 ></DD
5905 ><DT
5906 >UINT32</DT
5907 ><DD
5908 ><P
5909 >0 - undocumented</P
5910 ></DD
5911 ><DT
5912 >UINT32</DT
5913 ><DD
5914 ><P
5915 >0 - undocumented</P
5916 ></DD
5917 ><DT
5918 >UINT32</DT
5919 ><DD
5920 ><P
5921 >0 - undocumented</P
5922 ></DD
5923 ><DT
5924 >UINT32</DT
5925 ><DD
5926 ><P
5927 >0 - undocumented</P
5928 ></DD
5929 ></DL
5930 ></DIV
5931 ><P
5932 >return    0x0C00 0034 - "no such secret" success code</P
5933 ></DIV
5934 ></DIV
5935 ><DIV
5936 CLASS="SECT2"
5937 ><HR><H3
5938 CLASS="SECT2"
5939 ><A
5940 NAME="AEN2053">LSA Close</H3
5941 ><DIV
5942 CLASS="SECT3"
5943 ><H4
5944 CLASS="SECT3"
5945 ><A
5946 NAME="AEN2055">Request</H4
5947 ><P
5948 ></P
5949 ><DIV
5950 CLASS="VARIABLELIST"
5951 ><DL
5952 ><DT
5953 >POL_HND</DT
5954 ><DD
5955 ><P
5956 >policy handle to be closed</P
5957 ></DD
5958 ></DL
5959 ></DIV
5960 ></DIV
5961 ><DIV
5962 CLASS="SECT3"
5963 ><HR><H4
5964 CLASS="SECT3"
5965 ><A
5966 NAME="AEN2062">Response</H4
5967 ><P
5968 ></P
5969 ><DIV
5970 CLASS="VARIABLELIST"
5971 ><DL
5972 ><DT
5973 >POL_HND</DT
5974 ><DD
5975 ><P
5976 >0s - closed policy handle (all zeros)</P
5977 ></DD
5978 ></DL
5979 ></DIV
5980 ><P
5981 >return    0 - indicates success</P
5982 ></DIV
5983 ></DIV
5984 ><DIV
5985 CLASS="SECT2"
5986 ><HR><H3
5987 CLASS="SECT2"
5988 ><A
5989 NAME="AEN2070">LSA Lookup SIDS</H3
5990 ><P
5991 ><I
5992 CLASS="EMPHASIS"
5993 >Note:  num_entries in response must be same as num_entries in request.</I
5994 ></P
5995 ><DIV
5996 CLASS="SECT3"
5997 ><HR><H4
5998 CLASS="SECT3"
5999 ><A
6000 NAME="AEN2074">Request</H4
6001 ><P
6002 ></P
6003 ><DIV
6004 CLASS="VARIABLELIST"
6005 ><DL
6006 ><DT
6007 >POL_HND</DT
6008 ><DD
6009 ><P
6010 >LSA policy handle</P
6011 ></DD
6012 ><DT
6013 >UINT32</DT
6014 ><DD
6015 ><P
6016 >num_entries</P
6017 ></DD
6018 ><DT
6019 >VOID*</DT
6020 ><DD
6021 ><P
6022 >undocumented domain SID buffer pointer</P
6023 ></DD
6024 ><DT
6025 >VOID*</DT
6026 ><DD
6027 ><P
6028 >undocumented domain name buffer pointer</P
6029 ></DD
6030 ><DT
6031 >VOID*[num_entries] undocumented domain SID pointers to be looked up.</DT
6032 ><DD
6033 ><P
6034 >DOM_SID[num_entries] domain SIDs to be looked up.</P
6035 ></DD
6036 ><DT
6037 >char[16]</DT
6038 ><DD
6039 ><P
6040 >completely undocumented 16 bytes.</P
6041 ></DD
6042 ></DL
6043 ></DIV
6044 ></DIV
6045 ><DIV
6046 CLASS="SECT3"
6047 ><HR><H4
6048 CLASS="SECT3"
6049 ><A
6050 NAME="AEN2101">Response</H4
6051 ><P
6052 ></P
6053 ><DIV
6054 CLASS="VARIABLELIST"
6055 ><DL
6056 ><DT
6057 >DOM_REF</DT
6058 ><DD
6059 ><P
6060 >domain reference response</P
6061 ></DD
6062 ><DT
6063 >UINT32</DT
6064 ><DD
6065 ><P
6066 >num_entries (listed above)</P
6067 ></DD
6068 ><DT
6069 >VOID*</DT
6070 ><DD
6071 ><P
6072 >undocumented buffer pointer</P
6073 ></DD
6074 ><DT
6075 >UINT32</DT
6076 ><DD
6077 ><P
6078 >num_entries (listed above)</P
6079 ></DD
6080 ><DT
6081 >DOM_SID2[num_entries]</DT
6082 ><DD
6083 ><P
6084 >domain SIDs (from Request, listed above).</P
6085 ></DD
6086 ><DT
6087 >UINT32</DT
6088 ><DD
6089 ><P
6090 >num_entries (listed above)</P
6091 ></DD
6092 ></DL
6093 ></DIV
6094 ><P
6095 >return                0 - indicates success</P
6096 ></DIV
6097 ></DIV
6098 ><DIV
6099 CLASS="SECT2"
6100 ><HR><H3
6101 CLASS="SECT2"
6102 ><A
6103 NAME="AEN2129">LSA Lookup Names</H3
6104 ><P
6105 ><I
6106 CLASS="EMPHASIS"
6107 >Note:  num_entries in response must be same as num_entries in request.</I
6108 ></P
6109 ><DIV
6110 CLASS="SECT3"
6111 ><HR><H4
6112 CLASS="SECT3"
6113 ><A
6114 NAME="AEN2133">Request</H4
6115 ><P
6116 ></P
6117 ><DIV
6118 CLASS="VARIABLELIST"
6119 ><DL
6120 ><DT
6121 >POL_HND</DT
6122 ><DD
6123 ><P
6124 >LSA policy handle</P
6125 ></DD
6126 ><DT
6127 >UINT32</DT
6128 ><DD
6129 ><P
6130 >num_entries</P
6131 ></DD
6132 ><DT
6133 >UINT32</DT
6134 ><DD
6135 ><P
6136 >num_entries</P
6137 ></DD
6138 ><DT
6139 >VOID*</DT
6140 ><DD
6141 ><P
6142 >undocumented domain SID buffer pointer</P
6143 ></DD
6144 ><DT
6145 >VOID*</DT
6146 ><DD
6147 ><P
6148 >undocumented domain name buffer pointer</P
6149 ></DD
6150 ><DT
6151 >NAME[num_entries]</DT
6152 ><DD
6153 ><P
6154 >names to be looked up.</P
6155 ></DD
6156 ><DT
6157 >char[]</DT
6158 ><DD
6159 ><P
6160 >undocumented bytes - falsely translated SID structure?</P
6161 ></DD
6162 ></DL
6163 ></DIV
6164 ></DIV
6165 ><DIV
6166 CLASS="SECT3"
6167 ><HR><H4
6168 CLASS="SECT3"
6169 ><A
6170 NAME="AEN2164">Response</H4
6171 ><P
6172 ></P
6173 ><DIV
6174 CLASS="VARIABLELIST"
6175 ><DL
6176 ><DT
6177 >DOM_REF</DT
6178 ><DD
6179 ><P
6180 >domain reference response</P
6181 ></DD
6182 ><DT
6183 >UINT32</DT
6184 ><DD
6185 ><P
6186 >num_entries (listed above)</P
6187 ></DD
6188 ><DT
6189 >VOID*</DT
6190 ><DD
6191 ><P
6192 >undocumented buffer pointer</P
6193 ></DD
6194 ><DT
6195 >UINT32</DT
6196 ><DD
6197 ><P
6198 >num_entries (listed above)</P
6199 ></DD
6200 ><DT
6201 >DOM_RID[num_entries]</DT
6202 ><DD
6203 ><P
6204 >domain SIDs (from Request, listed above).</P
6205 ></DD
6206 ><DT
6207 >UINT32</DT
6208 ><DD
6209 ><P
6210 >num_entries (listed above)</P
6211 ></DD
6212 ></DL
6213 ></DIV
6214 ><P
6215 >return                0 - indicates success</P
6216 ></DIV
6217 ></DIV
6218 ></DIV
6219 ><DIV
6220 CLASS="SECT1"
6221 ><HR><H2
6222 CLASS="SECT1"
6223 ><A
6224 NAME="AEN2192">NETLOGON rpc Transact Named Pipe</H2
6225 ><P
6226 >The sequence of actions taken on this pipe are:</P
6227 ><P
6228 ></P
6229 ><TABLE
6230 BORDER="0"
6231 ><TBODY
6232 ><TR
6233 ><TD
6234 >tablish a connection to the IPC$ share (SMBtconX).  use encrypted passwords.</TD
6235 ></TR
6236 ><TR
6237 ><TD
6238 >en an RPC Pipe with the name "\\PIPE\\NETLOGON".  Store the file handle.</TD
6239 ></TR
6240 ><TR
6241 ><TD
6242 >ing the file handle, send a Set Named Pipe Handle state to 0x4300.</TD
6243 ></TR
6244 ><TR
6245 ><TD
6246 >eate Client Challenge. Send LSA Request Challenge.  Store Server Challenge.</TD
6247 ></TR
6248 ><TR
6249 ><TD
6250 >lculate Session Key.  Send an LSA Auth 2 Challenge.  Store Auth2 Challenge.</TD
6251 ></TR
6252 ><TR
6253 ><TD
6254 >lc/Verify Client Creds.  Send LSA Srv PW Set.  Calc/Verify Server Creds.</TD
6255 ></TR
6256 ><TR
6257 ><TD
6258 >lc/Verify Client Creds.  Send LSA SAM Logon .  Calc/Verify Server Creds.</TD
6259 ></TR
6260 ><TR
6261 ><TD
6262 >lc/Verify Client Creds.  Send LSA SAM Logoff.  Calc/Verify Server Creds.</TD
6263 ></TR
6264 ><TR
6265 ><TD
6266 >ose the IPC$ share.</TD
6267 ></TR
6268 ></TBODY
6269 ></TABLE
6270 ><P
6271 ></P
6272 ><P
6273 >Defines for this pipe, identifying the query are</P
6274 ><P
6275 ></P
6276 ><DIV
6277 CLASS="VARIABLELIST"
6278 ><DL
6279 ><DT
6280 >LSA Request Challenge:</DT
6281 ><DD
6282 ><P
6283 >0x04</P
6284 ></DD
6285 ><DT
6286 >LSA Server Password Set:</DT
6287 ><DD
6288 ><P
6289 >0x06</P
6290 ></DD
6291 ><DT
6292 >LSA SAM Logon:</DT
6293 ><DD
6294 ><P
6295 >0x02</P
6296 ></DD
6297 ><DT
6298 >LSA SAM Logoff:</DT
6299 ><DD
6300 ><P
6301 >0x03</P
6302 ></DD
6303 ><DT
6304 >LSA Auth 2:</DT
6305 ><DD
6306 ><P
6307 >0x0f</P
6308 ></DD
6309 ><DT
6310 >LSA Logon Control:</DT
6311 ><DD
6312 ><P
6313 >0x0e</P
6314 ></DD
6315 ></DL
6316 ></DIV
6317 ><DIV
6318 CLASS="SECT2"
6319 ><HR><H3
6320 CLASS="SECT2"
6321 ><A
6322 NAME="AEN2231">LSA Request Challenge</H3
6323 ><P
6324 ><I
6325 CLASS="EMPHASIS"
6326 >Note:  logon server name starts with two '\' characters and is upper case.</I
6327 ></P
6328 ><P
6329 ><I
6330 CLASS="EMPHASIS"
6331 >Note:  logon client is the machine, not the user.</I
6332 ></P
6333 ><P
6334 ><I
6335 CLASS="EMPHASIS"
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
6337 ></P
6338 ><DIV
6339 CLASS="SECT3"
6340 ><HR><H4
6341 CLASS="SECT3"
6342 ><A
6343 NAME="AEN2239">Request</H4
6344 ><P
6345 ></P
6346 ><DIV
6347 CLASS="VARIABLELIST"
6348 ><DL
6349 ><DT
6350 >VOID*</DT
6351 ><DD
6352 ><P
6353 >undocumented buffer pointer</P
6354 ></DD
6355 ><DT
6356 >UNISTR2</DT
6357 ><DD
6358 ><P
6359 >logon server unicode string</P
6360 ></DD
6361 ><DT
6362 >UNISTR2</DT
6363 ><DD
6364 ><P
6365 >logon client unicode string</P
6366 ></DD
6367 ><DT
6368 >char[8]</DT
6369 ><DD
6370 ><P
6371 >client challenge</P
6372 ></DD
6373 ></DL
6374 ></DIV
6375 ></DIV
6376 ><DIV
6377 CLASS="SECT3"
6378 ><HR><H4
6379 CLASS="SECT3"
6380 ><A
6381 NAME="AEN2258">Response</H4
6382 ><P
6383 ></P
6384 ><DIV
6385 CLASS="VARIABLELIST"
6386 ><DL
6387 ><DT
6388 >char[8]</DT
6389 ><DD
6390 ><P
6391 >server challenge</P
6392 ></DD
6393 ></DL
6394 ></DIV
6395 ><P
6396 >return    0 - indicates success</P
6397 ></DIV
6398 ></DIV
6399 ><DIV
6400 CLASS="SECT2"
6401 ><HR><H3
6402 CLASS="SECT2"
6403 ><A
6404 NAME="AEN2266">LSA Authenticate 2</H3
6405 ><P
6406 ><I
6407 CLASS="EMPHASIS"
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
6409 ></P
6410 ><P
6411 ><I
6412 CLASS="EMPHASIS"
6413 >Note:  neg_flags in the response is the same as that in the request.</I
6414 ></P
6415 ><P
6416 ><I
6417 CLASS="EMPHASIS"
6418 >Note:  you must take a copy of the client-calculated credentials received      here, because they will be used in subsequent authentication packets.</I
6419 ></P
6420 ><DIV
6421 CLASS="SECT3"
6422 ><HR><H4
6423 CLASS="SECT3"
6424 ><A
6425 NAME="AEN2274">Request</H4
6426 ><P
6427 ></P
6428 ><DIV
6429 CLASS="VARIABLELIST"
6430 ><DL
6431 ><DT
6432 >LOG_INFO</DT
6433 ><DD
6434 ><P
6435 >client identification info</P
6436 ></DD
6437 ><DT
6438 >char[8]</DT
6439 ><DD
6440 ><P
6441 >client-calculated credentials</P
6442 ></DD
6443 ><DT
6444 >UINT8[]</DT
6445 ><DD
6446 ><P
6447 >padding to 4-byte align with start of SMB header.</P
6448 ></DD
6449 ><DT
6450 >UINT32</DT
6451 ><DD
6452 ><P
6453 >neg_flags - negotiated flags (usual value is 0x0000 01ff)</P
6454 ></DD
6455 ></DL
6456 ></DIV
6457 ></DIV
6458 ><DIV
6459 CLASS="SECT3"
6460 ><HR><H4
6461 CLASS="SECT3"
6462 ><A
6463 NAME="AEN2293">Response</H4
6464 ><P
6465 ></P
6466 ><DIV
6467 CLASS="VARIABLELIST"
6468 ><DL
6469 ><DT
6470 >char[8]</DT
6471 ><DD
6472 ><P
6473 >server credentials.</P
6474 ></DD
6475 ><DT
6476 >UINT32</DT
6477 ><DD
6478 ><P
6479 >neg_flags - same as neg_flags in request.</P
6480 ></DD
6481 ></DL
6482 ></DIV
6483 ><P
6484 >return    0 - indicates success.  failure value unknown.</P
6485 ></DIV
6486 ></DIV
6487 ><DIV
6488 CLASS="SECT2"
6489 ><HR><H3
6490 CLASS="SECT2"
6491 ><A
6492 NAME="AEN2305">LSA Server Password Set</H3
6493 ><P
6494 ><I
6495 CLASS="EMPHASIS"
6496 >Note: the new password is suspected to be a DES encryption using the old password to generate the key.</I
6497 ></P
6498 ><P
6499 ><I
6500 CLASS="EMPHASIS"
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
6502 ></P
6503 ><P
6504 ><I
6505 CLASS="EMPHASIS"
6506 >Note: the server credentials are constructed from the client-calculated credentials and the client time + 1 second.</I
6507 ></P
6508 ><P
6509 ><I
6510 CLASS="EMPHASIS"
6511 >Note: you must take a copy of the client-calculated credentials received here, because they will be used in subsequent authentication packets.</I
6512 ></P
6513 ><DIV
6514 CLASS="SECT3"
6515 ><HR><H4
6516 CLASS="SECT3"
6517 ><A
6518 NAME="AEN2315">Request</H4
6519 ><P
6520 ></P
6521 ><DIV
6522 CLASS="VARIABLELIST"
6523 ><DL
6524 ><DT
6525 >CLNT_INFO</DT
6526 ><DD
6527 ><P
6528 >client identification/authentication info</P
6529 ></DD
6530 ><DT
6531 >char[]</DT
6532 ><DD
6533 ><P
6534 >new password - undocumented.</P
6535 ></DD
6536 ></DL
6537 ></DIV
6538 ></DIV
6539 ><DIV
6540 CLASS="SECT3"
6541 ><HR><H4
6542 CLASS="SECT3"
6543 ><A
6544 NAME="AEN2326">Response</H4
6545 ><P
6546 ></P
6547 ><DIV
6548 CLASS="VARIABLELIST"
6549 ><DL
6550 ><DT
6551 >CREDS</DT
6552 ><DD
6553 ><P
6554 >server credentials.  server time stamp appears to be ignored.</P
6555 ></DD
6556 ></DL
6557 ></DIV
6558 ><P
6559 >return    0 - indicates success; 0xC000 006a indicates failure</P
6560 ></DIV
6561 ></DIV
6562 ><DIV
6563 CLASS="SECT2"
6564 ><HR><H3
6565 CLASS="SECT2"
6566 ><A
6567 NAME="AEN2334">LSA SAM Logon</H3
6568 ><P
6569 ><I
6570 CLASS="EMPHASIS"
6571 >Note:  valid_user is True iff the username and password hash are valid for
6572         the requested domain.</I
6573 ></P
6574 ><DIV
6575 CLASS="SECT3"
6576 ><HR><H4
6577 CLASS="SECT3"
6578 ><A
6579 NAME="AEN2338">Request</H4
6580 ><P
6581 ></P
6582 ><DIV
6583 CLASS="VARIABLELIST"
6584 ><DL
6585 ><DT
6586 >SAM_INFO</DT
6587 ><DD
6588 ><P
6589 >sam_id structure</P
6590 ></DD
6591 ></DL
6592 ></DIV
6593 ></DIV
6594 ><DIV
6595 CLASS="SECT3"
6596 ><HR><H4
6597 CLASS="SECT3"
6598 ><A
6599 NAME="AEN2345">Response</H4
6600 ><P
6601 ></P
6602 ><DIV
6603 CLASS="VARIABLELIST"
6604 ><DL
6605 ><DT
6606 >VOID*</DT
6607 ><DD
6608 ><P
6609 >undocumented buffer pointer</P
6610 ></DD
6611 ><DT
6612 >CREDS</DT
6613 ><DD
6614 ><P
6615 >server credentials.  server time stamp appears to be ignored.</P
6616 ></DD
6617 ></DL
6618 ></DIV
6619 ><P
6620 ><TABLE
6621 BORDER="0"
6622 BGCOLOR="#E0E0E0"
6623 WIDTH="100%"
6624 ><TR
6625 ><TD
6626 ><PRE
6627 CLASS="PROGRAMLISTING"
6628 >if (valid_user)
6629 {
6630         UINT16      3 - switch value indicating USER_INFO structure.
6631     VOID*     non-zero - pointer to USER_INFO structure
6632     USER_INFO user logon information
6633
6634     UINT32    1 - Authoritative response; 0 - Non-Auth?
6635
6636     return    0 - indicates success
6637 }
6638 else
6639 {
6640         UINT16    0 - switch value.  value to indicate no user presumed.
6641     VOID*     0x0000 0000 - indicates no USER_INFO structure.
6642
6643     UINT32    1 - Authoritative response; 0 - Non-Auth?
6644
6645     return    0xC000 0064 - NT_STATUS_NO_SUCH_USER.
6646 }</PRE
6647 ></TD
6648 ></TR
6649 ></TABLE
6650 ></P
6651 ></DIV
6652 ></DIV
6653 ><DIV
6654 CLASS="SECT2"
6655 ><HR><H3
6656 CLASS="SECT2"
6657 ><A
6658 NAME="AEN2358">LSA SAM Logoff</H3
6659 ><P
6660 ><I
6661 CLASS="EMPHASIS"
6662 >Note:  presumably, the SAM_INFO structure is validated, and a (currently
6663         undocumented) error code returned if the Logoff is invalid.</I
6664 ></P
6665 ><DIV
6666 CLASS="SECT3"
6667 ><HR><H4
6668 CLASS="SECT3"
6669 ><A
6670 NAME="AEN2362">Request</H4
6671 ><P
6672 ></P
6673 ><DIV
6674 CLASS="VARIABLELIST"
6675 ><DL
6676 ><DT
6677 >SAM_INFO</DT
6678 ><DD
6679 ><P
6680 >sam_id structure</P
6681 ></DD
6682 ></DL
6683 ></DIV
6684 ></DIV
6685 ><DIV
6686 CLASS="SECT3"
6687 ><HR><H4
6688 CLASS="SECT3"
6689 ><A
6690 NAME="AEN2369">Response</H4
6691 ><P
6692 ></P
6693 ><DIV
6694 CLASS="VARIABLELIST"
6695 ><DL
6696 ><DT
6697 >VOID*</DT
6698 ><DD
6699 ><P
6700 >undocumented buffer pointer</P
6701 ></DD
6702 ><DT
6703 >CREDS</DT
6704 ><DD
6705 ><P
6706 >server credentials.  server time stamp appears to be ignored.</P
6707 ></DD
6708 ></DL
6709 ></DIV
6710 ><P
6711 >return      0 - indicates success.  undocumented failure indication.</P
6712 ></DIV
6713 ></DIV
6714 ></DIV
6715 ><DIV
6716 CLASS="SECT1"
6717 ><HR><H2
6718 CLASS="SECT1"
6719 ><A
6720 NAME="AEN2381">\\MAILSLOT\NET\NTLOGON</H2
6721 ><P
6722 ><I
6723 CLASS="EMPHASIS"
6724 >Note:  mailslots will contain a response mailslot, to which the response
6725         should be sent.  the target NetBIOS name is REQUEST_NAME&#60;20&#62;, where
6726         REQUEST_NAME is the name of the machine that sent the request.</I
6727 ></P
6728 ><DIV
6729 CLASS="SECT2"
6730 ><HR><H3
6731 CLASS="SECT2"
6732 ><A
6733 NAME="AEN2385">Query for PDC</H3
6734 ><P
6735 ><I
6736 CLASS="EMPHASIS"
6737 >Note:  NTversion, LMNTtoken, LM20token in response are the same as those       given in the request.</I
6738 ></P
6739 ><DIV
6740 CLASS="SECT3"
6741 ><HR><H4
6742 CLASS="SECT3"
6743 ><A
6744 NAME="AEN2389">Request</H4
6745 ><P
6746 ></P
6747 ><DIV
6748 CLASS="VARIABLELIST"
6749 ><DL
6750 ><DT
6751 >UINT16</DT
6752 ><DD
6753 ><P
6754 >0x0007 - Query for PDC</P
6755 ></DD
6756 ><DT
6757 >STR</DT
6758 ><DD
6759 ><P
6760 >machine name</P
6761 ></DD
6762 ><DT
6763 >STR</DT
6764 ><DD
6765 ><P
6766 >response mailslot</P
6767 ></DD
6768 ><DT
6769 >UINT8[]</DT
6770 ><DD
6771 ><P
6772 >padding to 2-byte align with start of mailslot.</P
6773 ></DD
6774 ><DT
6775 >UNISTR</DT
6776 ><DD
6777 ><P
6778 >machine name</P
6779 ></DD
6780 ><DT
6781 >UINT32</DT
6782 ><DD
6783 ><P
6784 >NTversion</P
6785 ></DD
6786 ><DT
6787 >UINT16</DT
6788 ><DD
6789 ><P
6790 >LMNTtoken</P
6791 ></DD
6792 ><DT
6793 >UINT16</DT
6794 ><DD
6795 ><P
6796 >LM20token</P
6797 ></DD
6798 ></DL
6799 ></DIV
6800 ></DIV
6801 ><DIV
6802 CLASS="SECT3"
6803 ><HR><H4
6804 CLASS="SECT3"
6805 ><A
6806 NAME="AEN2424">Response</H4
6807 ><P
6808 ></P
6809 ><DIV
6810 CLASS="VARIABLELIST"
6811 ><DL
6812 ><DT
6813 >UINT16</DT
6814 ><DD
6815 ><P
6816 >0x000A - Respose to Query for PDC</P
6817 ></DD
6818 ><DT
6819 >STR</DT
6820 ><DD
6821 ><P
6822 >machine name (in uppercase)</P
6823 ></DD
6824 ><DT
6825 >UINT8[]</DT
6826 ><DD
6827 ><P
6828 >padding to 2-byte align with start of mailslot.</P
6829 ></DD
6830 ><DT
6831 >UNISTR</DT
6832 ><DD
6833 ><P
6834 >machine name</P
6835 ></DD
6836 ><DT
6837 >UNISTR</DT
6838 ><DD
6839 ><P
6840 >domain name</P
6841 ></DD
6842 ><DT
6843 >UINT32</DT
6844 ><DD
6845 ><P
6846 >NTversion (same as received in request)</P
6847 ></DD
6848 ><DT
6849 >UINT16</DT
6850 ><DD
6851 ><P
6852 >LMNTtoken (same as received in request)</P
6853 ></DD
6854 ><DT
6855 >UINT16</DT
6856 ><DD
6857 ><P
6858 >LM20token (same as received in request)</P
6859 ></DD
6860 ></DL
6861 ></DIV
6862 ></DIV
6863 ></DIV
6864 ><DIV
6865 CLASS="SECT2"
6866 ><HR><H3
6867 CLASS="SECT2"
6868 ><A
6869 NAME="AEN2459">SAM Logon</H3
6870 ><P
6871 ><I
6872 CLASS="EMPHASIS"
6873 >Note: machine name in response is preceded by two '\' characters.</I
6874 ></P
6875 ><P
6876 ><I
6877 CLASS="EMPHASIS"
6878 >Note:  NTversion, LMNTtoken, LM20token in response are the same as those given in the request.</I
6879 ></P
6880 ><P
6881 ><I
6882 CLASS="EMPHASIS"
6883 >Note:  user name in the response is presumably the same as that in the request.</I
6884 ></P
6885 ><DIV
6886 CLASS="SECT3"
6887 ><HR><H4
6888 CLASS="SECT3"
6889 ><A
6890 NAME="AEN2467">Request</H4
6891 ><P
6892 ></P
6893 ><DIV
6894 CLASS="VARIABLELIST"
6895 ><DL
6896 ><DT
6897 >UINT16</DT
6898 ><DD
6899 ><P
6900 >0x0012 - SAM Logon</P
6901 ></DD
6902 ><DT
6903 >UINT16</DT
6904 ><DD
6905 ><P
6906 >request count</P
6907 ></DD
6908 ><DT
6909 >UNISTR</DT
6910 ><DD
6911 ><P
6912 >machine name</P
6913 ></DD
6914 ><DT
6915 >UNISTR</DT
6916 ><DD
6917 ><P
6918 >user name</P
6919 ></DD
6920 ><DT
6921 >STR</DT
6922 ><DD
6923 ><P
6924 >response mailslot</P
6925 ></DD
6926 ><DT
6927 >UINT32</DT
6928 ><DD
6929 ><P
6930 >alloweable account</P
6931 ></DD
6932 ><DT
6933 >UINT32</DT
6934 ><DD
6935 ><P
6936 >domain SID size</P
6937 ></DD
6938 ><DT
6939 >char[sid_size]</DT
6940 ><DD
6941 ><P
6942 >domain SID, of sid_size bytes.</P
6943 ></DD
6944 ><DT
6945 >UINT8[]</DT
6946 ><DD
6947 ><P
6948 >???? padding to 4? 2? -byte align with start of mailslot.</P
6949 ></DD
6950 ><DT
6951 >UINT32</DT
6952 ><DD
6953 ><P
6954 >NTversion</P
6955 ></DD
6956 ><DT
6957 >UINT16</DT
6958 ><DD
6959 ><P
6960 >LMNTtoken</P
6961 ></DD
6962 ><DT
6963 >UINT16</DT
6964 ><DD
6965 ><P
6966 >LM20token</P
6967 ></DD
6968 ></DL
6969 ></DIV
6970 ></DIV
6971 ><DIV
6972 CLASS="SECT3"
6973 ><HR><H4
6974 CLASS="SECT3"
6975 ><A
6976 NAME="AEN2518">Response</H4
6977 ><P
6978 ></P
6979 ><DIV
6980 CLASS="VARIABLELIST"
6981 ><DL
6982 ><DT
6983 >UINT16</DT
6984 ><DD
6985 ><P
6986 >0x0013 - Response to SAM Logon</P
6987 ></DD
6988 ><DT
6989 >UNISTR</DT
6990 ><DD
6991 ><P
6992 >machine name</P
6993 ></DD
6994 ><DT
6995 >UNISTR</DT
6996 ><DD
6997 ><P
6998 >user name - workstation trust account</P
6999 ></DD
7000 ><DT
7001 >UNISTR</DT
7002 ><DD
7003 ><P
7004 >domain name </P
7005 ></DD
7006 ><DT
7007 >UINT32</DT
7008 ><DD
7009 ><P
7010 >NTversion</P
7011 ></DD
7012 ><DT
7013 >UINT16</DT
7014 ><DD
7015 ><P
7016 >LMNTtoken</P
7017 ></DD
7018 ><DT
7019 >UINT16</DT
7020 ><DD
7021 ><P
7022 >LM20token</P
7023 ></DD
7024 ></DL
7025 ></DIV
7026 ></DIV
7027 ></DIV
7028 ></DIV
7029 ><DIV
7030 CLASS="SECT1"
7031 ><HR><H2
7032 CLASS="SECT1"
7033 ><A
7034 NAME="AEN2549">SRVSVC Transact Named Pipe</H2
7035 ><P
7036 >Defines for this pipe, identifying the query are:</P
7037 ><P
7038 ></P
7039 ><DIV
7040 CLASS="VARIABLELIST"
7041 ><DL
7042 ><DT
7043 >Net Share Enum</DT
7044 ><DD
7045 ><P
7046 >0x0f</P
7047 ></DD
7048 ><DT
7049 >Net Server Get Info</DT
7050 ><DD
7051 ><P
7052 >0x15</P
7053 ></DD
7054 ></DL
7055 ></DIV
7056 ><DIV
7057 CLASS="SECT2"
7058 ><HR><H3
7059 CLASS="SECT2"
7060 ><A
7061 NAME="AEN2561">Net Share Enum</H3
7062 ><P
7063 ><I
7064 CLASS="EMPHASIS"
7065 >Note:  share level and switch value in the response are presumably the same as those in the request.</I
7066 ></P
7067 ><P
7068 ><I
7069 CLASS="EMPHASIS"
7070 >Note:  cifsrap2.txt (section 5) may be of limited assistance here.</I
7071 ></P
7072 ><DIV
7073 CLASS="SECT3"
7074 ><HR><H4
7075 CLASS="SECT3"
7076 ><A
7077 NAME="AEN2567">Request</H4
7078 ><P
7079 ></P
7080 ><DIV
7081 CLASS="VARIABLELIST"
7082 ><DL
7083 ><DT
7084 >VOID*</DT
7085 ><DD
7086 ><P
7087 >pointer (to server name?)</P
7088 ></DD
7089 ><DT
7090 >UNISTR2</DT
7091 ><DD
7092 ><P
7093 >server name</P
7094 ></DD
7095 ><DT
7096 >UINT8[]</DT
7097 ><DD
7098 ><P
7099 >padding to get unicode string 4-byte aligned with the start of the SMB header.</P
7100 ></DD
7101 ><DT
7102 >UINT32</DT
7103 ><DD
7104 ><P
7105 >share level</P
7106 ></DD
7107 ><DT
7108 >UINT32</DT
7109 ><DD
7110 ><P
7111 >switch value</P
7112 ></DD
7113 ><DT
7114 >VOID*</DT
7115 ><DD
7116 ><P
7117 >pointer to SHARE_INFO_1_CTR</P
7118 ></DD
7119 ><DT
7120 >SHARE_INFO_1_CTR</DT
7121 ><DD
7122 ><P
7123 >share info with 0 entries</P
7124 ></DD
7125 ><DT
7126 >UINT32</DT
7127 ><DD
7128 ><P
7129 >preferred maximum length (0xffff ffff)</P
7130 ></DD
7131 ></DL
7132 ></DIV
7133 ></DIV
7134 ><DIV
7135 CLASS="SECT3"
7136 ><HR><H4
7137 CLASS="SECT3"
7138 ><A
7139 NAME="AEN2602">Response</H4
7140 ><P
7141 ></P
7142 ><DIV
7143 CLASS="VARIABLELIST"
7144 ><DL
7145 ><DT
7146 >UINT32</DT
7147 ><DD
7148 ><P
7149 >share level</P
7150 ></DD
7151 ><DT
7152 >UINT32</DT
7153 ><DD
7154 ><P
7155 >switch value</P
7156 ></DD
7157 ><DT
7158 >VOID*</DT
7159 ><DD
7160 ><P
7161 >pointer to SHARE_INFO_1_CTR</P
7162 ></DD
7163 ><DT
7164 >SHARE_INFO_1_CTR</DT
7165 ><DD
7166 ><P
7167 >share info (only added if share info ptr is non-zero)</P
7168 ></DD
7169 ></DL
7170 ></DIV
7171 ><P
7172 >return            0 - indicates success</P
7173 ></DIV
7174 ></DIV
7175 ><DIV
7176 CLASS="SECT2"
7177 ><HR><H3
7178 CLASS="SECT2"
7179 ><A
7180 NAME="AEN2622">Net Server Get Info</H3
7181 ><P
7182 ><I
7183 CLASS="EMPHASIS"
7184 >Note:  level is the same value as in the request.</I
7185 ></P
7186 ><DIV
7187 CLASS="SECT3"
7188 ><HR><H4
7189 CLASS="SECT3"
7190 ><A
7191 NAME="AEN2626">Request</H4
7192 ><P
7193 ></P
7194 ><DIV
7195 CLASS="VARIABLELIST"
7196 ><DL
7197 ><DT
7198 >UNISTR2</DT
7199 ><DD
7200 ><P
7201 >server name</P
7202 ></DD
7203 ><DT
7204 >UINT32</DT
7205 ><DD
7206 ><P
7207 >switch level</P
7208 ></DD
7209 ></DL
7210 ></DIV
7211 ></DIV
7212 ><DIV
7213 CLASS="SECT3"
7214 ><HR><H4
7215 CLASS="SECT3"
7216 ><A
7217 NAME="AEN2637">Response</H4
7218 ><P
7219 ></P
7220 ><DIV
7221 CLASS="VARIABLELIST"
7222 ><DL
7223 ><DT
7224 >UINT32</DT
7225 ><DD
7226 ><P
7227 >switch level</P
7228 ></DD
7229 ><DT
7230 >VOID*</DT
7231 ><DD
7232 ><P
7233 >pointer to SERVER_INFO_101</P
7234 ></DD
7235 ><DT
7236 >SERVER_INFO_101</DT
7237 ><DD
7238 ><P
7239 >server info (only added if server info ptr is non-zero)</P
7240 ></DD
7241 ></DL
7242 ></DIV
7243 ><P
7244 >return            0 - indicates success</P
7245 ></DIV
7246 ></DIV
7247 ></DIV
7248 ><DIV
7249 CLASS="SECT1"
7250 ><HR><H2
7251 CLASS="SECT1"
7252 ><A
7253 NAME="AEN2653">Cryptographic side of NT Domain Authentication</H2
7254 ><DIV
7255 CLASS="SECT2"
7256 ><H3
7257 CLASS="SECT2"
7258 ><A
7259 NAME="AEN2655">Definitions</H3
7260 ><P
7261 ></P
7262 ><DIV
7263 CLASS="VARIABLELIST"
7264 ><DL
7265 ><DT
7266 >Add(A1,A2)</DT
7267 ><DD
7268 ><P
7269 >Intel byte ordered addition of corresponding 4 byte words in arrays A1 and A2</P
7270 ></DD
7271 ><DT
7272 >E(K,D)</DT
7273 ><DD
7274 ><P
7275 >DES ECB encryption of 8 byte data D using 7 byte key K</P
7276 ></DD
7277 ><DT
7278 >lmowf()</DT
7279 ><DD
7280 ><P
7281 >Lan man hash</P
7282 ></DD
7283 ><DT
7284 >ntowf()</DT
7285 ><DD
7286 ><P
7287 >NT hash</P
7288 ></DD
7289 ><DT
7290 >PW</DT
7291 ><DD
7292 ><P
7293 >md4(machine_password) == md4(lsadump $machine.acc) ==
7294 pwdump(machine$) (initially) == md4(lmowf(unicode(machine)))</P
7295 ></DD
7296 ><DT
7297 >ARC4(K,Lk,D,Ld)</DT
7298 ><DD
7299 ><P
7300 >ARC4 encryption of data D of length Ld with key K of length Lk</P
7301 ></DD
7302 ><DT
7303 >v[m..n(,l)]</DT
7304 ><DD
7305 ><P
7306 >subset of v from bytes m to n, optionally padded with zeroes to length l</P
7307 ></DD
7308 ><DT
7309 >Cred(K,D)</DT
7310 ><DD
7311 ><P
7312 >E(K[7..7,7],E(K[0..6],D)) computes a credential</P
7313 ></DD
7314 ><DT
7315 >Time()</DT
7316 ><DD
7317 ><P
7318 >4 byte current time</P
7319 ></DD
7320 ><DT
7321 >Cc,Cs</DT
7322 ><DD
7323 ><P
7324 >8 byte client and server challenges Rc,Rs: 8 byte client and server credentials</P
7325 ></DD
7326 ></DL
7327 ></DIV
7328 ></DIV
7329 ><DIV
7330 CLASS="SECT2"
7331 ><HR><H3
7332 CLASS="SECT2"
7333 ><A
7334 NAME="AEN2698">Protocol</H3
7335 ><P
7336 >C-&#62;S ReqChal,Cc S-&#62;C Cs</P
7337 ><P
7338 >C &#38; S compute session key Ks = E(PW[9..15],E(PW[0..6],Add(Cc,Cs)))</P
7339 ><P
7340 >C: Rc = Cred(Ks,Cc) C-&#62;S Authenticate,Rc S: Rs = Cred(Ks,Cs),
7341 assert(Rc == Cred(Ks,Cc)) S-&#62;C Rs C: assert(Rs == Cred(Ks,Cs))</P
7342 ><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
7346 ><P
7347 >C: Tc = Time(), Rc' = Cred(Ks,Rc+Tc) C-&#62;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-&#62;C Rs',Ts C: assert(Rs' == Cred(Ks,Rs+Tc+1)) S: Rs = Rs'</P
7351 ><P
7352 >User: U with password P wishes to login to the domain (incidental data
7353 such as workstation and domain omitted)</P
7354 ><P
7355 >C: Tc = Time(), Rc' = Cred(Ks,Rc+Tc) C-&#62;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:
7358 Ts = Time()</P
7359 ><P
7360 >S-&#62;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
7362 ></DIV
7363 ><DIV
7364 CLASS="SECT2"
7365 ><HR><H3
7366 CLASS="SECT2"
7367 ><A
7368 NAME="AEN2708">Comments</H3
7369 ><P
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
7377 ><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
7380 ><P
7381 >The server time stamps appear to be ignored.</P
7382 ><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
7386 ><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
7390 ></DIV
7391 ></DIV
7392 ><DIV
7393 CLASS="SECT1"
7394 ><HR><H2
7395 CLASS="SECT1"
7396 ><A
7397 NAME="AEN2715">SIDs and RIDs</H2
7398 ><P
7399 >SIDs and RIDs are well documented elsewhere.</P
7400 ><P
7401 >A SID is an NT Security ID (see DOM_SID structure).  They are of the form:</P
7402 ><P
7403 ></P
7404 ><TABLE
7405 BORDER="0"
7406 ><TBODY
7407 ><TR
7408 ><TD
7409 >revision-NN-SubAuth1-SubAuth2-SubAuth3... </TD
7410 ></TR
7411 ><TR
7412 ><TD
7413 >revision-0xNNNNNNNNNNNN-SubAuth1-SubAuth2-SubAuth3...</TD
7414 ></TR
7415 ></TBODY
7416 ></TABLE
7417 ><P
7418 ></P
7419 ><P
7420 >currently, the SID revision is 1.
7421 The Sub-Authorities are known as Relative IDs (RIDs).</P
7422 ><DIV
7423 CLASS="SECT2"
7424 ><HR><H3
7425 CLASS="SECT2"
7426 ><A
7427 NAME="AEN2723">Well-known SIDs</H3
7428 ><DIV
7429 CLASS="SECT3"
7430 ><H4
7431 CLASS="SECT3"
7432 ><A
7433 NAME="AEN2725">Universal well-known SIDs</H4
7434 ><P
7435 ></P
7436 ><DIV
7437 CLASS="VARIABLELIST"
7438 ><DL
7439 ><DT
7440 >Null SID</DT
7441 ><DD
7442 ><P
7443 >S-1-0-0</P
7444 ></DD
7445 ><DT
7446 >World</DT
7447 ><DD
7448 ><P
7449 >S-1-1-0</P
7450 ></DD
7451 ><DT
7452 >Local</DT
7453 ><DD
7454 ><P
7455 >S-1-2-0</P
7456 ></DD
7457 ><DT
7458 >Creator Owner ID</DT
7459 ><DD
7460 ><P
7461 >S-1-3-0</P
7462 ></DD
7463 ><DT
7464 >Creator Group ID</DT
7465 ><DD
7466 ><P
7467 >S-1-3-1</P
7468 ></DD
7469 ><DT
7470 >Creator Owner Server ID</DT
7471 ><DD
7472 ><P
7473 >S-1-3-2</P
7474 ></DD
7475 ><DT
7476 >Creator Group Server ID</DT
7477 ><DD
7478 ><P
7479 >S-1-3-3</P
7480 ></DD
7481 ><DT
7482 >(Non-unique IDs)</DT
7483 ><DD
7484 ><P
7485 >S-1-4</P
7486 ></DD
7487 ></DL
7488 ></DIV
7489 ></DIV
7490 ><DIV
7491 CLASS="SECT3"
7492 ><HR><H4
7493 CLASS="SECT3"
7494 ><A
7495 NAME="AEN2760">NT well-known SIDs</H4
7496 ><P
7497 ></P
7498 ><DIV
7499 CLASS="VARIABLELIST"
7500 ><DL
7501 ><DT
7502 >NT Authority</DT
7503 ><DD
7504 ><P
7505 >S-1-5</P
7506 ></DD
7507 ><DT
7508 >Dialup</DT
7509 ><DD
7510 ><P
7511 >S-1-5-1</P
7512 ></DD
7513 ><DT
7514 >Network</DT
7515 ><DD
7516 ><P
7517 >S-1-5-2</P
7518 ></DD
7519 ><DT
7520 >Batch</DT
7521 ><DD
7522 ><P
7523 >S-1-5-3</P
7524 ></DD
7525 ><DT
7526 >Interactive</DT
7527 ><DD
7528 ><P
7529 >S-1-5-4</P
7530 ></DD
7531 ><DT
7532 >Service</DT
7533 ><DD
7534 ><P
7535 >S-1-5-6</P
7536 ></DD
7537 ><DT
7538 >AnonymousLogon(aka null logon session)</DT
7539 ><DD
7540 ><P
7541 >S-1-5-7</P
7542 ></DD
7543 ><DT
7544 >Proxy</DT
7545 ><DD
7546 ><P
7547 >S-1-5-8</P
7548 ></DD
7549 ><DT
7550 >ServerLogon(aka domain controller account)</DT
7551 ><DD
7552 ><P
7553 >S-1-5-8</P
7554 ></DD
7555 ><DT
7556 >(Logon IDs)</DT
7557 ><DD
7558 ><P
7559 >S-1-5-5-X-Y</P
7560 ></DD
7561 ><DT
7562 >(NT non-unique IDs)</DT
7563 ><DD
7564 ><P
7565 >S-1-5-0x15-...</P
7566 ></DD
7567 ><DT
7568 >(Built-in domain)</DT
7569 ><DD
7570 ><P
7571 >s-1-5-0x20</P
7572 ></DD
7573 ></DL
7574 ></DIV
7575 ></DIV
7576 ></DIV
7577 ><DIV
7578 CLASS="SECT2"
7579 ><HR><H3
7580 CLASS="SECT2"
7581 ><A
7582 NAME="AEN2811">Well-known RIDS</H3
7583 ><P
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
7587 ><DIV
7588 CLASS="SECT3"
7589 ><HR><H4
7590 CLASS="SECT3"
7591 ><A
7592 NAME="AEN2814">Well-known RID users</H4
7593 ><P
7594 ><B
7595 >Groupname: </B
7596 >DOMAIN_USER_RID_ADMIN</P
7597 ><P
7598 ><B
7599 >????: </B
7600 >0x0000</P
7601 ><P
7602 ><B
7603 >RID: </B
7604 >01F4</P
7605 ><P
7606 ><B
7607 >Groupname: </B
7608 >DOMAIN_USER_RID_GUEST</P
7609 ><P
7610 ><B
7611 >????: </B
7612 >0x0000</P
7613 ><P
7614 ><B
7615 >RID: </B
7616 >01F5</P
7617 ></DIV
7618 ><DIV
7619 CLASS="SECT3"
7620 ><HR><H4
7621 CLASS="SECT3"
7622 ><A
7623 NAME="AEN2828">Well-known RID groups</H4
7624 ><P
7625 ><B
7626 >Groupname: </B
7627 >       DOMAIN_GROUP_RID_ADMINS</P
7628 ><P
7629 ><B
7630 >????: </B
7631 >0x0000</P
7632 ><P
7633 ><B
7634 >RID: </B
7635 >0200</P
7636 ><P
7637 ><B
7638 >Groupname: </B
7639 >       DOMAIN_GROUP_RID_USERS</P
7640 ><P
7641 ><B
7642 >????: </B
7643 >0x0000</P
7644 ><P
7645 ><B
7646 >RID: </B
7647 >0201</P
7648 ><P
7649 ><B
7650 >Groupname: </B
7651 >       DOMAIN_GROUP_RID_GUESTS</P
7652 ><P
7653 ><B
7654 >????: </B
7655 >0x0000</P
7656 ><P
7657 ><B
7658 >RID: </B
7659 >0202</P
7660 ></DIV
7661 ><DIV
7662 CLASS="SECT3"
7663 ><HR><H4
7664 CLASS="SECT3"
7665 ><A
7666 NAME="AEN2846">Well-known RID aliases</H4
7667 ><P
7668 ><B
7669 >Groupname: </B
7670 >       DOMAIN_ALIAS_RID_ADMINS</P
7671 ><P
7672 ><B
7673 >????: </B
7674 >0x0000</P
7675 ><P
7676 ><B
7677 >RID: </B
7678 >0220</P
7679 ><P
7680 ><B
7681 >Groupname: </B
7682 >       DOMAIN_ALIAS_RID_USERS</P
7683 ><P
7684 ><B
7685 >????: </B
7686 >0x0000</P
7687 ><P
7688 ><B
7689 >RID: </B
7690 >0221</P
7691 ><P
7692 ><B
7693 >Groupname: </B
7694 >       DOMAIN_ALIAS_RID_GUESTS</P
7695 ><P
7696 ><B
7697 >????: </B
7698 >0x0000</P
7699 ><P
7700 ><B
7701 >RID: </B
7702 >0222</P
7703 ><P
7704 ><B
7705 >Groupname: </B
7706 >       DOMAIN_ALIAS_RID_POWER_USERS</P
7707 ><P
7708 ><B
7709 >????: </B
7710 >0x0000</P
7711 ><P
7712 ><B
7713 >RID: </B
7714 >0223</P
7715 ><P
7716 ><B
7717 >Groupname: </B
7718 >       DOMAIN_ALIAS_RID_ACCOUNT_OPS</P
7719 ><P
7720 ><B
7721 >????: </B
7722 >0x0000</P
7723 ><P
7724 ><B
7725 >RID: </B
7726 >0224</P
7727 ><P
7728 ><B
7729 >Groupname: </B
7730 >       DOMAIN_ALIAS_RID_SYSTEM_OPS</P
7731 ><P
7732 ><B
7733 >????: </B
7734 >0x0000</P
7735 ><P
7736 ><B
7737 >RID: </B
7738 >0225</P
7739 ><P
7740 ><B
7741 >Groupname: </B
7742 >       DOMAIN_ALIAS_RID_PRINT_OPS</P
7743 ><P
7744 ><B
7745 >????: </B
7746 >0x0000</P
7747 ><P
7748 ><B
7749 >RID: </B
7750 >0226</P
7751 ><P
7752 ><B
7753 >Groupname: </B
7754 >       DOMAIN_ALIAS_RID_BACKUP_OPS</P
7755 ><P
7756 ><B
7757 >????: </B
7758 >0x0000</P
7759 ><P
7760 ><B
7761 >RID: </B
7762 >0227</P
7763 ><P
7764 ><B
7765 >Groupname: </B
7766 >       DOMAIN_ALIAS_RID_REPLICATOR</P
7767 ><P
7768 ><B
7769 >????: </B
7770 >0x0000</P
7771 ><P
7772 ><B
7773 >RID: </B
7774 >0228</P
7775 ></DIV
7776 ></DIV
7777 ></DIV
7778 ></DIV
7779 ><DIV
7780 CLASS="CHAPTER"
7781 ><HR><H1
7782 ><A
7783 NAME="PRINTING">Samba Printing Internals</H1
7784 ><DIV
7785 CLASS="SECT1"
7786 ><H2
7787 CLASS="SECT1"
7788 ><A
7789 NAME="AEN2895">Abstract</H2
7790 ><P
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
7794 ></DIV
7795 ><DIV
7796 CLASS="SECT1"
7797 ><HR><H2
7798 CLASS="SECT1"
7799 ><A
7800 NAME="AEN2898">Printing Interface to Various Back ends</H2
7801 ><P
7802 >Samba uses a table of function pointers to seven functions.  The
7803 function prototypes are defined in the <TT
7804 CLASS="VARNAME"
7805 >printif</TT
7806 > structure declared
7807 in <TT
7808 CLASS="FILENAME"
7809 >printing.h</TT
7810 >.</P
7811 ><P
7812 ></P
7813 ><UL
7814 ><LI
7815 ><P
7816 >retrieve the contents of a print queue</P
7817 ></LI
7818 ><LI
7819 ><P
7820 >pause the print queue</P
7821 ></LI
7822 ><LI
7823 ><P
7824 >resume a paused print queue</P
7825 ></LI
7826 ><LI
7827 ><P
7828 >delete a job from the queue</P
7829 ></LI
7830 ><LI
7831 ><P
7832 >pause a job in the print queue</P
7833 ></LI
7834 ><LI
7835 ><P
7836 >result a paused print job in the queue</P
7837 ></LI
7838 ><LI
7839 ><P
7840 >submit a job to the print queue</P
7841 ></LI
7842 ></UL
7843 ><P
7844 >Currently there are only two printing back end implementations
7845 defined.</P
7846 ><P
7847 ></P
7848 ><UL
7849 ><LI
7850 ><P
7851 >a generic set of functions for working with standard UNIX
7852         printing subsystems</P
7853 ></LI
7854 ><LI
7855 ><P
7856 >a set of CUPS specific functions (this is only enabled if
7857         the CUPS libraries were located at compile time).</P
7858 ></LI
7859 ></UL
7860 ></DIV
7861 ><DIV
7862 CLASS="SECT1"
7863 ><HR><H2
7864 CLASS="SECT1"
7865 ><A
7866 NAME="AEN2924">Print Queue TDB's</H2
7867 ><P
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
7873 ><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
7883 ><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
7888 "lpq command".</P
7889 ><P
7890 ><TABLE
7891 BORDER="0"
7892 BGCOLOR="#E0E0E0"
7893 WIDTH="100%"
7894 ><TR
7895 ><TD
7896 ><PRE
7897 CLASS="PROGRAMLISTING"
7898 >/* included from printing.h */
7899 struct printjob {
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;
7914 };</PRE
7915 ></TD
7916 ></TR
7917 ></TABLE
7918 ></P
7919 ><P
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 &#60;*vance doesn't know what word is missing here*&#62; is generating by adding UNIX_JOB_START to
7925 the id reported by lpq.</P
7926 ><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
7930 ><P
7931 >When updating a print queue, smbd will perform the following
7932 steps ( refer to <TT
7933 CLASS="FILENAME"
7934 >print.c:print_queue_update()</TT
7935 > ):</P
7936 ><P
7937 ></P
7938 ><OL
7939 TYPE="1"
7940 ><LI
7941 ><P
7942 >Check to see if another smbd is currently in 
7943         the process of updating the queue contents by checking the pid 
7944         stored in <TT
7945 CLASS="CONSTANT"
7946 >LOCK/<TT
7947 CLASS="REPLACEABLE"
7948 ><I
7949 >printer_name</I
7950 ></TT
7951 ></TT
7952 >.  
7953         If so, then do not update the TDB.</P
7954 ></LI
7955 ><LI
7956 ><P
7957 >Lock the mutex entry in the TDB and store our own pid.
7958         Check that this succeeded, else fail.</P
7959 ></LI
7960 ><LI
7961 ><P
7962 >Store the updated time stamp for the new cache
7963         listing</P
7964 ></LI
7965 ><LI
7966 ><P
7967 >Retrieve the queue listing via "lpq command"</P
7968 ></LI
7969 ><LI
7970 ><P
7971 ><TABLE
7972 BORDER="0"
7973 BGCOLOR="#E0E0E0"
7974 WIDTH="90%"
7975 ><TR
7976 ><TD
7977 ><PRE
7978 CLASS="PROGRAMLISTING"
7979 >       foreach job in the queue
7980         {
7981                 if the job is a UNIX job, create a new entry;
7982                 if the job has a Windows based jobid, then
7983                 {
7984                         Lookup the record by the jobid;
7985                         if the lookup failed, then
7986                                 treat it as a UNIX job;
7987                         else
7988                                 update the job status only
7989                 }
7990         }</PRE
7991 ></TD
7992 ></TR
7993 ></TABLE
7994 ></P
7995 ></LI
7996 ><LI
7997 ><P
7998 >Delete any jobs in the TDB that are not
7999         in the in the lpq listing</P
8000 ></LI
8001 ><LI
8002 ><P
8003 >Store the print queue status in the TDB</P
8004 ></LI
8005 ><LI
8006 ><P
8007 >update the cache time stamp again</P
8008 ></LI
8009 ></OL
8010 ><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
8013 ><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
8021 ><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
8025 ></DIV
8026 ><DIV
8027 CLASS="SECT1"
8028 ><HR><H2
8029 CLASS="SECT1"
8030 ><A
8031 NAME="AEN2958">ChangeID &#38; Client Caching of Printer Information</H2
8032 ><P
8033 >[To be filled in later]</P
8034 ></DIV
8035 ><DIV
8036 CLASS="SECT1"
8037 ><HR><H2
8038 CLASS="SECT1"
8039 ><A
8040 NAME="AEN2961">Windows NT/2K Printer Change Notify</H2
8041 ><P
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
8050 ><P
8051 >The basic set of RPC's used to implement change notification are</P
8052 ><P
8053 ></P
8054 ><UL
8055 ><LI
8056 ><P
8057 >RemoteFindFirstPrinterChangeNotifyEx ( RFFPCN )</P
8058 ></LI
8059 ><LI
8060 ><P
8061 >RemoteFindNextPrinterChangeNotifyEx ( RFNPCN )</P
8062 ></LI
8063 ><LI
8064 ><P
8065 >FindClosePrinterChangeNotify( FCPCN )</P
8066 ></LI
8067 ><LI
8068 ><P
8069 >ReplyOpenPrinter</P
8070 ></LI
8071 ><LI
8072 ><P
8073 >ReplyClosePrinter</P
8074 ></LI
8075 ><LI
8076 ><P
8077 >RouteRefreshPrinterChangeNotify ( RRPCN )</P
8078 ></LI
8079 ></UL
8080 ><P
8081 >One additional RPC is available to a server, but is never used by the
8082 Windows spooler service:</P
8083 ><P
8084 ></P
8085 ><UL
8086 ><LI
8087 ><P
8088 >RouteReplyPrinter()</P
8089 ></LI
8090 ></UL
8091 ><P
8092 >The opnum for all of these RPC's are defined in include/rpc_spoolss.h</P
8093 ><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
8098 ><P
8099 ><TABLE
8100 BORDER="0"
8101 BGCOLOR="#E0E0E0"
8102 WIDTH="100%"
8103 ><TR
8104 ><TD
8105 ><PRE
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
8110
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 &#60;* another missing word*&#62; 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.
8122
8123 C:      The windows spooler follows the RFFPCN with a RFNPCN
8124         request to fetch the current values of all monitored
8125         attributes.
8126 S:      The server replies with an array SPOOL_NOTIFY_INFO_DATA
8127         structures (contained in a SPOOL_NOTIFY_INFO structure).
8128
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
8138 ></TD
8139 ></TR
8140 ></TABLE
8141 ></P
8142 ><P
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
8145 ><P
8146 ></P
8147 ><UL
8148 ><LI
8149 ><P
8150 >printer_notify_table[]</P
8151 ></LI
8152 ><LI
8153 ><P
8154 >job_notify_table[]</P
8155 ></LI
8156 ></UL
8157 ><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
8164 ><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
8168 ><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
8174 ><P
8175 >The actual change notification is performed using the RRPCN request
8176 RPC.  This packet contains</P
8177 ><P
8178 ></P
8179 ><UL
8180 ><LI
8181 ><P
8182 >the printer handle registered with the
8183 client's spooler on which the change occurred</P
8184 ></LI
8185 ><LI
8186 ><P
8187 >The change_low value which was sent as part
8188 of the last RFNPCN request from the client</P
8189 ></LI
8190 ><LI
8191 ><P
8192 >The SPOOL_NOTIFY_INFO container with the event
8193 information</P
8194 ></LI
8195 ></UL
8196 ><P
8197 >A <TT
8198 CLASS="VARNAME"
8199 >SPOOL_NOTIFY_INFO</TT
8200 > contains:</P
8201 ><P
8202 ></P
8203 ><UL
8204 ><LI
8205 ><P
8206 >the version and flags field are predefined
8207 and should not be changed</P
8208 ></LI
8209 ><LI
8210 ><P
8211 >The count field is the number of entries
8212 in the SPOOL_NOTIFY_INFO_DATA array</P
8213 ></LI
8214 ></UL
8215 ><P
8216 >The <TT
8217 CLASS="VARNAME"
8218 >SPOOL_NOTIFY_INFO_DATA</TT
8219 > entries contain:</P
8220 ><P
8221 ></P
8222 ><UL
8223 ><LI
8224 ><P
8225 >The type defines whether or not this event
8226 is for a printer or a print job</P
8227 ></LI
8228 ><LI
8229 ><P
8230 >The field is the flag identifying the event</P
8231 ></LI
8232 ><LI
8233 ><P
8234 >the notify_data union contains the new valuie of the
8235 attribute</P
8236 ></LI
8237 ><LI
8238 ><P
8239 >The enc_type defines the size of the structure for marshalling
8240 and unmarshalling</P
8241 ></LI
8242 ><LI
8243 ><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
8251 ></LI
8252 ><LI
8253 ><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
8256 data values.</P
8257 ></LI
8258 ></UL
8259 ></DIV
8260 ></DIV
8261 ><DIV
8262 CLASS="CHAPTER"
8263 ><HR><H1
8264 ><A
8265 NAME="WINS">Samba WINS Internals</H1
8266 ><DIV
8267 CLASS="SECT1"
8268 ><H2
8269 CLASS="SECT1"
8270 ><A
8271 NAME="AEN3032">WINS Failover</H2
8272 ><P
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
8276 ><P
8277 ><TABLE
8278 BORDER="0"
8279 BGCOLOR="#E0E0E0"
8280 WIDTH="100%"
8281 ><TR
8282 ><TD
8283 ><PRE
8284 CLASS="PROGRAMLISTING"
8285 >       WINS_SERVER_PARAM       = SERVER [ SEPARATOR SERVER_LIST ]
8286         WINS_SERVER_PARAM       = "wins server"
8287         SERVER                  = ADDR[:TAG]
8288         ADDR                    = ip_addr | fqdn
8289         TAG                     = string
8290         SEPARATOR               = comma | \s+
8291         SERVER_LIST             = SERVER [ SEPARATOR SERVER_LIST ]</PRE
8292 ></TD
8293 ></TR
8294 ></TABLE
8295 ></P
8296 ><P
8297 >A simple example of a valid wins server setting is</P
8298 ><P
8299 ><TABLE
8300 BORDER="0"
8301 BGCOLOR="#E0E0E0"
8302 WIDTH="100%"
8303 ><TR
8304 ><TD
8305 ><PRE
8306 CLASS="PROGRAMLISTING"
8307 >[global]
8308         wins server = 192.168.1.2 192.168.1.3</PRE
8309 ></TD
8310 ></TR
8311 ></TABLE
8312 ></P
8313 ><P
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
8317 tagged group.</P
8318 ><P
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
8321 ><P
8322 ><TABLE
8323 BORDER="0"
8324 BGCOLOR="#E0E0E0"
8325 WIDTH="100%"
8326 ><TR
8327 ><TD
8328 ><PRE
8329 CLASS="PROGRAMLISTING"
8330 >[global]
8331         wins server = 192.168.1.2:eth0 192.168.1.3:eth0 192.168.2.2:eth1</PRE
8332 ></TD
8333 ></TR
8334 ></TABLE
8335 ></P
8336 ><P
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
8341 ><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
8350 ></DIV
8351 ></DIV
8352 ></DIV
8353 ></BODY
8354 ></HTML
8355 >