This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.(This used to...
[samba.git] / docs / htmldocs / Samba-Developers-Guide.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//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.77"></HEAD
9 ><BODY
10 CLASS="BOOK"
11 BGCOLOR="#FFFFFF"
12 TEXT="#000000"
13 LINK="#0000FF"
14 VLINK="#840084"
15 ALINK="#0000FF"
16 ><DIV
17 CLASS="BOOK"
18 ><A
19 NAME="SAMBA-DEVELOPERS-GUIDE"
20 ></A
21 ><DIV
22 CLASS="TITLEPAGE"
23 ><H1
24 CLASS="TITLE"
25 ><A
26 NAME="SAMBA-DEVELOPERS-GUIDE"
27 ></A
28 >SAMBA Developers Guide</H1
29 ><H3
30 CLASS="AUTHOR"
31 ><A
32 NAME="AEN4"
33 ></A
34 >SAMBA Team</H3
35 ><HR></DIV
36 ><HR><H1
37 ><A
38 NAME="AEN8"
39 ></A
40 >Abstract</H1
41 ><P
42 ><SPAN
43 CLASS="emphasis"
44 ><I
45 CLASS="EMPHASIS"
46 >Last Update</I
47 ></SPAN
48 > : Mon Sep 30 15:23:53 CDT 2002</P
49 ><P
50 >This book is a collection of documents that might be useful for 
51 people developing samba or those interested in doing so.
52 It's nothing more than a collection of documents written by samba developers about 
53 the internals of various parts of samba and the SMB protocol. It's still incomplete.
54 The most recent version of this document
55 can be found at <A
56 HREF="http://devel.samba.org/"
57 TARGET="_top"
58 >http://devel.samba.org/</A
59 >.
60 Please send updates to <A
61 HREF="mailto:jelmer@samba.org"
62 TARGET="_top"
63 >jelmer@samba.org</A
64 >.</P
65 ><P
66 >This documentation is distributed under the GNU General Public License (GPL) 
67 version 2.  A copy of the license is included with the Samba source
68 distribution.  A copy can be found on-line at <A
69 HREF="http://www.fsf.org/licenses/gpl.txt"
70 TARGET="_top"
71 >http://www.fsf.org/licenses/gpl.txt</A
72 ></P
73 ><DIV
74 CLASS="TOC"
75 ><DL
76 ><DT
77 ><B
78 >Table of Contents</B
79 ></DT
80 ><DT
81 >1. <A
82 HREF="#NETBIOS"
83 >Definition of NetBIOS Protocol and Name Resolution Modes</A
84 ></DT
85 ><DD
86 ><DL
87 ><DT
88 >1.1. <A
89 HREF="#AEN24"
90 >NETBIOS</A
91 ></DT
92 ><DT
93 >1.2. <A
94 HREF="#AEN35"
95 >BROADCAST NetBIOS</A
96 ></DT
97 ><DT
98 >1.3. <A
99 HREF="#AEN39"
100 >NBNS NetBIOS</A
101 ></DT
102 ></DL
103 ></DD
104 ><DT
105 >2. <A
106 HREF="#ARCHITECTURE"
107 >Samba Architecture</A
108 ></DT
109 ><DD
110 ><DL
111 ><DT
112 >2.1. <A
113 HREF="#AEN54"
114 >Introduction</A
115 ></DT
116 ><DT
117 >2.2. <A
118 HREF="#AEN65"
119 >Multithreading and Samba</A
120 ></DT
121 ><DT
122 >2.3. <A
123 HREF="#AEN70"
124 >Threading smbd</A
125 ></DT
126 ><DT
127 >2.4. <A
128 HREF="#AEN86"
129 >Threading nmbd</A
130 ></DT
131 ><DT
132 >2.5. <A
133 HREF="#AEN92"
134 >nbmd Design</A
135 ></DT
136 ></DL
137 ></DD
138 ><DT
139 >3. <A
140 HREF="#DEBUG"
141 >The samba DEBUG system</A
142 ></DT
143 ><DD
144 ><DL
145 ><DT
146 >3.1. <A
147 HREF="#AEN103"
148 >New Output Syntax</A
149 ></DT
150 ><DT
151 >3.2. <A
152 HREF="#AEN128"
153 >The DEBUG() Macro</A
154 ></DT
155 ><DT
156 >3.3. <A
157 HREF="#AEN151"
158 >The DEBUGADD() Macro</A
159 ></DT
160 ><DT
161 >3.4. <A
162 HREF="#AEN159"
163 >The DEBUGLVL() Macro</A
164 ></DT
165 ><DT
166 >3.5. <A
167 HREF="#AEN179"
168 >New Functions</A
169 ></DT
170 ><DD
171 ><DL
172 ><DT
173 >3.5.1. <A
174 HREF="#AEN181"
175 >dbgtext()</A
176 ></DT
177 ><DT
178 >3.5.2. <A
179 HREF="#AEN184"
180 >dbghdr()</A
181 ></DT
182 ><DT
183 >3.5.3. <A
184 HREF="#AEN188"
185 >format_debug_text()</A
186 ></DT
187 ></DL
188 ></DD
189 ></DL
190 ></DD
191 ><DT
192 >4. <A
193 HREF="#CODINGSUGGESTIONS"
194 >Coding Suggestions</A
195 ></DT
196 ><DT
197 >5. <A
198 HREF="#INTERNALS"
199 >Samba Internals</A
200 ></DT
201 ><DD
202 ><DL
203 ><DT
204 >5.1. <A
205 HREF="#AEN284"
206 >Character Handling</A
207 ></DT
208 ><DT
209 >5.2. <A
210 HREF="#AEN288"
211 >The new functions</A
212 ></DT
213 ><DT
214 >5.3. <A
215 HREF="#AEN317"
216 >Macros in byteorder.h</A
217 ></DT
218 ><DD
219 ><DL
220 ><DT
221 >5.3.1. <A
222 HREF="#AEN320"
223 >CVAL(buf,pos)</A
224 ></DT
225 ><DT
226 >5.3.2. <A
227 HREF="#AEN323"
228 >PVAL(buf,pos)</A
229 ></DT
230 ><DT
231 >5.3.3. <A
232 HREF="#AEN326"
233 >SCVAL(buf,pos,val)</A
234 ></DT
235 ><DT
236 >5.3.4. <A
237 HREF="#AEN329"
238 >SVAL(buf,pos)</A
239 ></DT
240 ><DT
241 >5.3.5. <A
242 HREF="#AEN332"
243 >IVAL(buf,pos)</A
244 ></DT
245 ><DT
246 >5.3.6. <A
247 HREF="#AEN335"
248 >SVALS(buf,pos)</A
249 ></DT
250 ><DT
251 >5.3.7. <A
252 HREF="#AEN338"
253 >IVALS(buf,pos)</A
254 ></DT
255 ><DT
256 >5.3.8. <A
257 HREF="#AEN341"
258 >SSVAL(buf,pos,val)</A
259 ></DT
260 ><DT
261 >5.3.9. <A
262 HREF="#AEN344"
263 >SIVAL(buf,pos,val)</A
264 ></DT
265 ><DT
266 >5.3.10. <A
267 HREF="#AEN347"
268 >SSVALS(buf,pos,val)</A
269 ></DT
270 ><DT
271 >5.3.11. <A
272 HREF="#AEN350"
273 >SIVALS(buf,pos,val)</A
274 ></DT
275 ><DT
276 >5.3.12. <A
277 HREF="#AEN353"
278 >RSVAL(buf,pos)</A
279 ></DT
280 ><DT
281 >5.3.13. <A
282 HREF="#AEN356"
283 >RIVAL(buf,pos)</A
284 ></DT
285 ><DT
286 >5.3.14. <A
287 HREF="#AEN359"
288 >RSSVAL(buf,pos,val)</A
289 ></DT
290 ><DT
291 >5.3.15. <A
292 HREF="#AEN362"
293 >RSIVAL(buf,pos,val)</A
294 ></DT
295 ></DL
296 ></DD
297 ><DT
298 >5.4. <A
299 HREF="#AEN365"
300 >LAN Manager Samba API</A
301 ></DT
302 ><DD
303 ><DL
304 ><DT
305 >5.4.1. <A
306 HREF="#AEN371"
307 >Parameters</A
308 ></DT
309 ><DT
310 >5.4.2. <A
311 HREF="#AEN406"
312 >Return value</A
313 ></DT
314 ></DL
315 ></DD
316 ><DT
317 >5.5. <A
318 HREF="#AEN420"
319 >Code character table</A
320 ></DT
321 ></DL
322 ></DD
323 ><DT
324 >6. <A
325 HREF="#PARSING"
326 >The smb.conf file</A
327 ></DT
328 ><DD
329 ><DL
330 ><DT
331 >6.1. <A
332 HREF="#AEN451"
333 >Lexical Analysis</A
334 ></DT
335 ><DD
336 ><DL
337 ><DT
338 >6.1.1. <A
339 HREF="#AEN472"
340 >Handling of Whitespace</A
341 ></DT
342 ><DT
343 >6.1.2. <A
344 HREF="#AEN484"
345 >Handling of Line Continuation</A
346 ></DT
347 ><DT
348 >6.1.3. <A
349 HREF="#AEN495"
350 >Line Continuation Quirks</A
351 ></DT
352 ></DL
353 ></DD
354 ><DT
355 >6.2. <A
356 HREF="#AEN515"
357 >Syntax</A
358 ></DT
359 ><DD
360 ><DL
361 ><DT
362 >6.2.1. <A
363 HREF="#AEN530"
364 >About params.c</A
365 ></DT
366 ></DL
367 ></DD
368 ></DL
369 ></DD
370 ><DT
371 >7. <A
372 HREF="#UNIX-SMB"
373 >NetBIOS in a Unix World</A
374 ></DT
375 ><DD
376 ><DL
377 ><DT
378 >7.1. <A
379 HREF="#AEN540"
380 >Introduction</A
381 ></DT
382 ><DT
383 >7.2. <A
384 HREF="#AEN544"
385 >Usernames</A
386 ></DT
387 ><DT
388 >7.3. <A
389 HREF="#AEN552"
390 >File Ownership</A
391 ></DT
392 ><DT
393 >7.4. <A
394 HREF="#AEN557"
395 >Passwords</A
396 ></DT
397 ><DT
398 >7.5. <A
399 HREF="#AEN563"
400 >Locking</A
401 ></DT
402 ><DT
403 >7.6. <A
404 HREF="#AEN571"
405 >Deny Modes</A
406 ></DT
407 ><DT
408 >7.7. <A
409 HREF="#AEN575"
410 >Trapdoor UIDs</A
411 ></DT
412 ><DT
413 >7.8. <A
414 HREF="#AEN579"
415 >Port numbers</A
416 ></DT
417 ><DT
418 >7.9. <A
419 HREF="#AEN584"
420 >Protocol Complexity</A
421 ></DT
422 ></DL
423 ></DD
424 ><DT
425 >8. <A
426 HREF="#TRACING"
427 >Tracing samba system calls</A
428 ></DT
429 ><DT
430 >9. <A
431 HREF="#NTDOMAIN"
432 >NT Domain RPC's</A
433 ></DT
434 ><DD
435 ><DL
436 ><DT
437 >9.1. <A
438 HREF="#AEN652"
439 >Introduction</A
440 ></DT
441 ><DD
442 ><DL
443 ><DT
444 >9.1.1. <A
445 HREF="#AEN688"
446 >Sources</A
447 ></DT
448 ><DT
449 >9.1.2. <A
450 HREF="#AEN695"
451 >Credits</A
452 ></DT
453 ></DL
454 ></DD
455 ><DT
456 >9.2. <A
457 HREF="#AEN702"
458 >Notes and Structures</A
459 ></DT
460 ><DD
461 ><DL
462 ><DT
463 >9.2.1. <A
464 HREF="#AEN704"
465 >Notes</A
466 ></DT
467 ><DT
468 >9.2.2. <A
469 HREF="#AEN717"
470 >Enumerations</A
471 ></DT
472 ><DT
473 >9.2.3. <A
474 HREF="#AEN775"
475 >Structures</A
476 ></DT
477 ></DL
478 ></DD
479 ><DT
480 >9.3. <A
481 HREF="#AEN1571"
482 >MSRPC over Transact Named Pipe</A
483 ></DT
484 ><DD
485 ><DL
486 ><DT
487 >9.3.1. <A
488 HREF="#AEN1574"
489 >MSRPC Pipes</A
490 ></DT
491 ><DT
492 >9.3.2. <A
493 HREF="#AEN1588"
494 >Header</A
495 ></DT
496 ><DT
497 >9.3.3. <A
498 HREF="#AEN1842"
499 >Tail</A
500 ></DT
501 ><DT
502 >9.3.4. <A
503 HREF="#AEN1854"
504 >RPC Bind / Bind Ack</A
505 ></DT
506 ><DT
507 >9.3.5. <A
508 HREF="#AEN1898"
509 >NTLSA Transact Named Pipe</A
510 ></DT
511 ><DT
512 >9.3.6. <A
513 HREF="#AEN1939"
514 >LSA Open Policy</A
515 ></DT
516 ><DT
517 >9.3.7. <A
518 HREF="#AEN1973"
519 >LSA Query Info Policy</A
520 ></DT
521 ><DT
522 >9.3.8. <A
523 HREF="#AEN2001"
524 >LSA Enumerate Trusted Domains</A
525 ></DT
526 ><DT
527 >9.3.9. <A
528 HREF="#AEN2025"
529 >LSA Open Secret</A
530 ></DT
531 ><DT
532 >9.3.10. <A
533 HREF="#AEN2054"
534 >LSA Close</A
535 ></DT
536 ><DT
537 >9.3.11. <A
538 HREF="#AEN2071"
539 >LSA Lookup SIDS</A
540 ></DT
541 ><DT
542 >9.3.12. <A
543 HREF="#AEN2130"
544 >LSA Lookup Names</A
545 ></DT
546 ></DL
547 ></DD
548 ><DT
549 >9.4. <A
550 HREF="#AEN2193"
551 >NETLOGON rpc Transact Named Pipe</A
552 ></DT
553 ><DD
554 ><DL
555 ><DT
556 >9.4.1. <A
557 HREF="#AEN2232"
558 >LSA Request Challenge</A
559 ></DT
560 ><DT
561 >9.4.2. <A
562 HREF="#AEN2267"
563 >LSA Authenticate 2</A
564 ></DT
565 ><DT
566 >9.4.3. <A
567 HREF="#AEN2306"
568 >LSA Server Password Set</A
569 ></DT
570 ><DT
571 >9.4.4. <A
572 HREF="#AEN2335"
573 >LSA SAM Logon</A
574 ></DT
575 ><DT
576 >9.4.5. <A
577 HREF="#AEN2359"
578 >LSA SAM Logoff</A
579 ></DT
580 ></DL
581 ></DD
582 ><DT
583 >9.5. <A
584 HREF="#AEN2382"
585 >\\MAILSLOT\NET\NTLOGON</A
586 ></DT
587 ><DD
588 ><DL
589 ><DT
590 >9.5.1. <A
591 HREF="#AEN2386"
592 >Query for PDC</A
593 ></DT
594 ><DT
595 >9.5.2. <A
596 HREF="#AEN2460"
597 >SAM Logon</A
598 ></DT
599 ></DL
600 ></DD
601 ><DT
602 >9.6. <A
603 HREF="#AEN2550"
604 >SRVSVC Transact Named Pipe</A
605 ></DT
606 ><DD
607 ><DL
608 ><DT
609 >9.6.1. <A
610 HREF="#AEN2562"
611 >Net Share Enum</A
612 ></DT
613 ><DT
614 >9.6.2. <A
615 HREF="#AEN2623"
616 >Net Server Get Info</A
617 ></DT
618 ></DL
619 ></DD
620 ><DT
621 >9.7. <A
622 HREF="#AEN2654"
623 >Cryptographic side of NT Domain Authentication</A
624 ></DT
625 ><DD
626 ><DL
627 ><DT
628 >9.7.1. <A
629 HREF="#AEN2656"
630 >Definitions</A
631 ></DT
632 ><DT
633 >9.7.2. <A
634 HREF="#AEN2699"
635 >Protocol</A
636 ></DT
637 ><DT
638 >9.7.3. <A
639 HREF="#AEN2709"
640 >Comments</A
641 ></DT
642 ></DL
643 ></DD
644 ><DT
645 >9.8. <A
646 HREF="#AEN2716"
647 >SIDs and RIDs</A
648 ></DT
649 ><DD
650 ><DL
651 ><DT
652 >9.8.1. <A
653 HREF="#AEN2724"
654 >Well-known SIDs</A
655 ></DT
656 ><DT
657 >9.8.2. <A
658 HREF="#AEN2812"
659 >Well-known RIDS</A
660 ></DT
661 ></DL
662 ></DD
663 ></DL
664 ></DD
665 ><DT
666 >10. <A
667 HREF="#PRINTING"
668 >Samba Printing Internals</A
669 ></DT
670 ><DD
671 ><DL
672 ><DT
673 >10.1. <A
674 HREF="#AEN2896"
675 >Abstract</A
676 ></DT
677 ><DT
678 >10.2. <A
679 HREF="#AEN2899"
680 >Printing Interface to Various Back ends</A
681 ></DT
682 ><DT
683 >10.3. <A
684 HREF="#AEN2925"
685 >Print Queue TDB's</A
686 ></DT
687 ><DT
688 >10.4. <A
689 HREF="#AEN2959"
690 >ChangeID &#38; Client Caching of Printer Information</A
691 ></DT
692 ><DT
693 >10.5. <A
694 HREF="#AEN2962"
695 >Windows NT/2K Printer Change Notify</A
696 ></DT
697 ></DL
698 ></DD
699 ><DT
700 >11. <A
701 HREF="#WINS"
702 >Samba WINS Internals</A
703 ></DT
704 ><DD
705 ><DL
706 ><DT
707 >11.1. <A
708 HREF="#AEN3033"
709 >WINS Failover</A
710 ></DT
711 ></DL
712 ></DD
713 ><DT
714 >12. <A
715 HREF="#SAM"
716 >The Upcoming SAM System</A
717 ></DT
718 ><DD
719 ><DL
720 ><DT
721 >12.1. <A
722 HREF="#AEN3054"
723 >Security in the 'new SAM'</A
724 ></DT
725 ><DT
726 >12.2. <A
727 HREF="#AEN3071"
728 >Standalone from UNIX</A
729 ></DT
730 ><DT
731 >12.3. <A
732 HREF="#AEN3075"
733 >Handles and Races in the new SAM</A
734 ></DT
735 ><DT
736 >12.4. <A
737 HREF="#AEN3086"
738 >Layers</A
739 ></DT
740 ><DD
741 ><DL
742 ><DT
743 >12.4.1. <A
744 HREF="#AEN3088"
745 >Application</A
746 ></DT
747 ><DT
748 >12.4.2. <A
749 HREF="#AEN3091"
750 >SAM Interface</A
751 ></DT
752 ><DT
753 >12.4.3. <A
754 HREF="#AEN3095"
755 >SAM Modules</A
756 ></DT
757 ></DL
758 ></DD
759 ><DT
760 >12.5. <A
761 HREF="#AEN3098"
762 >SAM Modules</A
763 ></DT
764 ><DD
765 ><DL
766 ><DT
767 >12.5.1. <A
768 HREF="#AEN3100"
769 >Special Module: sam_passdb</A
770 ></DT
771 ><DT
772 >12.5.2. <A
773 HREF="#AEN3103"
774 >sam_ads</A
775 ></DT
776 ></DL
777 ></DD
778 ><DT
779 >12.6. <A
780 HREF="#AEN3107"
781 >Memory Management</A
782 ></DT
783 ><DT
784 >12.7. <A
785 HREF="#AEN3121"
786 >Testing</A
787 ></DT
788 ></DL
789 ></DD
790 ><DT
791 >13. <A
792 HREF="#PWENCRYPT"
793 >LanMan and NT Password Encryption</A
794 ></DT
795 ><DD
796 ><DL
797 ><DT
798 >13.1. <A
799 HREF="#AEN3147"
800 >Introduction</A
801 ></DT
802 ><DT
803 >13.2. <A
804 HREF="#AEN3151"
805 >How does it work?</A
806 ></DT
807 ><DT
808 >13.3. <A
809 HREF="#AEN3162"
810 ><A
811 NAME="SMBPASSWDFILEFORMAT"
812 ></A
813 >The smbpasswd file</A
814 ></DT
815 ></DL
816 ></DD
817 ></DL
818 ></DIV
819 ><DIV
820 CLASS="CHAPTER"
821 ><HR><H1
822 ><A
823 NAME="NETBIOS"
824 ></A
825 >Chapter 1. Definition of NetBIOS Protocol and Name Resolution Modes</H1
826 ><DIV
827 CLASS="SECT1"
828 ><H2
829 CLASS="SECT1"
830 ><A
831 NAME="AEN24"
832 ></A
833 >1.1. NETBIOS</H2
834 ><P
835 >NetBIOS runs over the following tranports: TCP/IP; NetBEUI and IPX/SPX.
836 Samba only uses NetBIOS over TCP/IP.  For details on the TCP/IP NetBIOS 
837 Session Service NetBIOS Datagram Service, and NetBIOS Names, see
838 rfc1001.txt and rfc1002.txt.</P
839 ><P
840
841 NetBEUI is a raw NetBIOS frame protocol implementation that allows NetBIOS
842 datagrams to be sent out over the 'wire' embedded within LLC frames.
843 NetBEUI is not required when using NetBIOS over TCP/IP protocols and it
844 is preferable NOT to install NetBEUI if it can be avoided.</P
845 ><P
846
847 IPX/SPX is also not required when using NetBIOS over TCP/IP, and it is
848 preferable NOT to install the IPX/SPX transport unless you are using Novell
849 servers.  At the very least, it is recommended that you do not install
850 'NetBIOS over IPX/SPX'.</P
851 ><P
852 >[When installing Windows 95, you will find that NetBEUI and IPX/SPX are
853 installed as the default protocols.  This is because they are the simplest
854 to manage: no Windows 95 user-configuration is required].</P
855 ><P
856
857 NetBIOS applications (such as samba) offer their services (for example,
858 SMB file and print sharing) on a NetBIOS name.  They must claim this name
859 on the network before doing so.  The NetBIOS session service will then
860 accept connections on the application's behalf (on the NetBIOS name
861 claimed by the application).  A NetBIOS session between the application
862 and the client can then commence.</P
863 ><P
864
865 NetBIOS names consist of 15 characters plus a 'type' character.  This is
866 similar, in concept, to an IP address and a TCP port number, respectively.
867 A NetBIOS-aware application on a host will offer different services under
868 different NetBIOS name types, just as a host will offer different TCP/IP
869 services on different port numbers.</P
870 ><P
871
872 NetBIOS names must be claimed on a network, and must be defended.  The use
873 of NetBIOS names is most suitable on a single subnet; a Local Area Network
874 or a Wide Area Network.</P
875 ><P
876
877 NetBIOS names are either UNIQUE or GROUP.  Only one application can claim a
878 UNIQUE NetBIOS name on a network.</P
879 ><P
880 >There are two kinds of NetBIOS Name resolution: Broadcast and Point-to-Point.</P
881 ></DIV
882 ><DIV
883 CLASS="SECT1"
884 ><HR><H2
885 CLASS="SECT1"
886 ><A
887 NAME="AEN35"
888 ></A
889 >1.2. BROADCAST NetBIOS</H2
890 ><P
891
892 Clients can claim names, and therefore offer services on successfully claimed
893 names, on their broadcast-isolated subnet.  One way to get NetBIOS services
894 (such as browsing: see ftp.microsoft.com/drg/developr/CIFS/browdiff.txt; and
895 SMB file/print sharing: see cifs4.txt) working on a LAN or WAN is to make
896 your routers forward all broadcast packets from TCP/IP ports 137, 138 and 139.</P
897 ><P
898
899 This, however, is not recommended.  If you have a large LAN or WAN, you will
900 find that some of your hosts spend 95 percent of their time dealing with
901 broadcast traffic.  [If you have IPX/SPX on your LAN or WAN, you will find
902 that this is already happening: a packet analyzer will show, roughly
903 every twelve minutes, great swathes of broadcast traffic!].</P
904 ></DIV
905 ><DIV
906 CLASS="SECT1"
907 ><HR><H2
908 CLASS="SECT1"
909 ><A
910 NAME="AEN39"
911 ></A
912 >1.3. NBNS NetBIOS</H2
913 ><P
914 >rfc1001.txt describes, amongst other things, the implementation and use
915 of, a 'NetBIOS Name Service'.  NT/AS offers 'Windows Internet Name Service'
916 which is fully rfc1001/2 compliant, but has had to take specific action
917 with certain NetBIOS names in order to make it useful.  (for example, it
918 deals with the registration of &#60;1c&#62; &#60;1d&#62; &#60;1e&#62; names all in different ways.
919 I recommend the reading of the Microsoft WINS Server Help files for full
920 details).</P
921 ><P
922
923 The use of a WINS server cuts down on broadcast network traffic for
924 NetBIOS name resolution.  It has the effect of pulling all the broadcast
925 isolated subnets together into a single NetBIOS scope, across your LAN
926 or WAN, while avoiding the use of TCP/IP broadcast packets.</P
927 ><P
928 >When you have a WINS server on your LAN, WINS clients will be able to
929 contact the WINS server to resolve NetBIOS names.  Note that only those
930 WINS clients that have registered with the same WINS server will be
931 visible.  The WINS server _can_ have static NetBIOS entries added to its
932 database (usually for security reasons you might want to consider putting
933 your domain controllers or other important servers as static entries,
934 but you should not rely on this as your sole means of security), but for
935 the most part, NetBIOS names are registered dynamically.</P
936 ><P
937 >This provides some confusion for lots of people, and is worth mentioning
938 here:  a Browse Server is NOT a WINS Server, even if these services are
939 implemented in the same application.  A Browse Server _needs_ a WINS server
940 because a Browse Server is a WINS client, which is _not_ the same thing].</P
941 ><P
942 >Clients can claim names, and therefore offer services on successfully claimed
943 names, on their broadcast-isolated subnet.  One way to get NetBIOS services
944 (such as browsing: see ftp.microsoft.com/drg/developr/CIFS/browdiff.txt; and
945 SMB file/print sharing: see cifs6.txt) working on a LAN or WAN is to make
946 your routers forward all broadcast packets from TCP/IP ports 137, 138 and 139.
947 You will find, however, if you do this on a large LAN or a WAN, that your
948 network is completely swamped by NetBIOS and browsing packets, which is why
949 WINS was developed to minimise the necessity of broadcast traffic.</P
950 ><P
951
952 WINS Clients therefore claim names from the WINS server.  If the WINS
953 server allows them to register a name, the client's NetBIOS session service
954 can then offer services on this name.  Other WINS clients will then
955 contact the WINS server to resolve a NetBIOS name.</P
956 ></DIV
957 ></DIV
958 ><DIV
959 CLASS="CHAPTER"
960 ><HR><H1
961 ><A
962 NAME="ARCHITECTURE"
963 ></A
964 >Chapter 2. Samba Architecture</H1
965 ><DIV
966 CLASS="SECT1"
967 ><H2
968 CLASS="SECT1"
969 ><A
970 NAME="AEN54"
971 ></A
972 >2.1. Introduction</H2
973 ><P
974 >This document gives a general overview of how Samba works
975 internally. The Samba Team has tried to come up with a model which is
976 the best possible compromise between elegance, portability, security
977 and the constraints imposed by the very messy SMB and CIFS
978 protocol. </P
979 ><P
980 >It also tries to answer some of the frequently asked questions such as:</P
981 ><P
982 ></P
983 ><OL
984 TYPE="1"
985 ><LI
986 ><P
987 >       Is Samba secure when running on Unix? The xyz platform?
988         What about the root priveliges issue?</P
989 ></LI
990 ><LI
991 ><P
992 >Pros and cons of multithreading in various parts of Samba</P
993 ></LI
994 ><LI
995 ><P
996 >Why not have a separate process for name resolution, WINS, and browsing?</P
997 ></LI
998 ></OL
999 ></DIV
1000 ><DIV
1001 CLASS="SECT1"
1002 ><HR><H2
1003 CLASS="SECT1"
1004 ><A
1005 NAME="AEN65"
1006 ></A
1007 >2.2. Multithreading and Samba</H2
1008 ><P
1009 >People sometimes tout threads as a uniformly good thing. They are very
1010 nice in their place but are quite inappropriate for smbd. nmbd is
1011 another matter, and multi-threading it would be very nice. </P
1012 ><P
1013 >The short version is that smbd is not multithreaded, and alternative
1014 servers that take this approach under Unix (such as Syntax, at the
1015 time of writing) suffer tremendous performance penalties and are less
1016 robust. nmbd is not threaded either, but this is because it is not
1017 possible to do it while keeping code consistent and portable across 35
1018 or more platforms. (This drawback also applies to threading smbd.)</P
1019 ><P
1020 >The longer versions is that there are very good reasons for not making
1021 smbd multi-threaded.  Multi-threading would actually make Samba much
1022 slower, less scalable, less portable and much less robust. The fact
1023 that we use a separate process for each connection is one of Samba's
1024 biggest advantages.</P
1025 ></DIV
1026 ><DIV
1027 CLASS="SECT1"
1028 ><HR><H2
1029 CLASS="SECT1"
1030 ><A
1031 NAME="AEN70"
1032 ></A
1033 >2.3. Threading smbd</H2
1034 ><P
1035 >A few problems that would arise from a threaded smbd are:</P
1036 ><P
1037 ></P
1038 ><OL
1039 TYPE="1"
1040 ><LI
1041 ><P
1042 >       It's not only to create threads instead of processes, but you
1043         must care about all variables if they have to be thread specific
1044         (currently they would be global).</P
1045 ></LI
1046 ><LI
1047 ><P
1048 >       if one thread dies (eg. a seg fault) then all threads die. We can
1049         immediately throw robustness out the window.</P
1050 ></LI
1051 ><LI
1052 ><P
1053 >       many of the system calls we make are blocking. Non-blocking
1054         equivalents of many calls are either not available or are awkward (and
1055         slow) to use. So while we block in one thread all clients are
1056         waiting. Imagine if one share is a slow NFS filesystem and the others 
1057         are fast, we will end up slowing all clients to the speed of NFS.</P
1058 ></LI
1059 ><LI
1060 ><P
1061 >       you can't run as a different uid in different threads. This means
1062         we would have to switch uid/gid on _every_ SMB packet. It would be
1063         horrendously slow.</P
1064 ></LI
1065 ><LI
1066 ><P
1067 >       the per process file descriptor limit would mean that we could only
1068         support a limited number of clients.</P
1069 ></LI
1070 ><LI
1071 ><P
1072 >       we couldn't use the system locking calls as the locking context of
1073         fcntl() is a process, not a thread.</P
1074 ></LI
1075 ></OL
1076 ></DIV
1077 ><DIV
1078 CLASS="SECT1"
1079 ><HR><H2
1080 CLASS="SECT1"
1081 ><A
1082 NAME="AEN86"
1083 ></A
1084 >2.4. Threading nmbd</H2
1085 ><P
1086 >This would be ideal, but gets sunk by portability requirements.</P
1087 ><P
1088 >Andrew tried to write a test threads library for nmbd that used only
1089 ansi-C constructs (using setjmp and longjmp). Unfortunately some OSes
1090 defeat this by restricting longjmp to calling addresses that are
1091 shallower than the current address on the stack (apparently AIX does
1092 this). This makes a truly portable threads library impossible. So to
1093 support all our current platforms we would have to code nmbd both with
1094 and without threads, and as the real aim of threads is to make the
1095 code clearer we would not have gained anything. (it is a myth that
1096 threads make things faster. threading is like recursion, it can make
1097 things clear but the same thing can always be done faster by some
1098 other method)</P
1099 ><P
1100 >Chris tried to spec out a general design that would abstract threading
1101 vs separate processes (vs other methods?) and make them accessible
1102 through some general API. This doesn't work because of the data
1103 sharing requirements of the protocol (packets in the future depending
1104 on packets now, etc.) At least, the code would work but would be very
1105 clumsy, and besides the fork() type model would never work on Unix. (Is there an OS that it would work on, for nmbd?)</P
1106 ><P
1107 >A fork() is cheap, but not nearly cheap enough to do on every UDP
1108 packet that arrives. Having a pool of processes is possible but is
1109 nasty to program cleanly due to the enormous amount of shared data (in
1110 complex structures) between the processes. We can't rely on each
1111 platform having a shared memory system.</P
1112 ></DIV
1113 ><DIV
1114 CLASS="SECT1"
1115 ><HR><H2
1116 CLASS="SECT1"
1117 ><A
1118 NAME="AEN92"
1119 ></A
1120 >2.5. nbmd Design</H2
1121 ><P
1122 >Originally Andrew used recursion to simulate a multi-threaded
1123 environment, which use the stack enormously and made for really
1124 confusing debugging sessions. Luke Leighton rewrote it to use a
1125 queuing system that keeps state information on each packet.  The
1126 first version used a single structure which was used by all the
1127 pending states.  As the initialisation of this structure was
1128 done by adding arguments, as the functionality developed, it got
1129 pretty messy.  So, it was replaced with a higher-order function
1130 and a pointer to a user-defined memory block.  This suddenly
1131 made things much simpler: large numbers of functions could be
1132 made static, and modularised.  This is the same principle as used
1133 in NT's kernel, and achieves the same effect as threads, but in
1134 a single process.</P
1135 ><P
1136 >Then Jeremy rewrote nmbd. The packet data in nmbd isn't what's on the
1137 wire. It's a nice format that is very amenable to processing but still
1138 keeps the idea of a distinct packet. See "struct packet_struct" in
1139 nameserv.h.  It has all the detail but none of the on-the-wire
1140 mess. This makes it ideal for using in disk or memory-based databases
1141 for browsing and WINS support. </P
1142 ></DIV
1143 ></DIV
1144 ><DIV
1145 CLASS="CHAPTER"
1146 ><HR><H1
1147 ><A
1148 NAME="DEBUG"
1149 ></A
1150 >Chapter 3. The samba DEBUG system</H1
1151 ><DIV
1152 CLASS="SECT1"
1153 ><H2
1154 CLASS="SECT1"
1155 ><A
1156 NAME="AEN103"
1157 ></A
1158 >3.1. New Output Syntax</H2
1159 ><P
1160 >   The syntax of a debugging log file is represented as:</P
1161 ><P
1162 ><PRE
1163 CLASS="PROGRAMLISTING"
1164 >  &gt;debugfile&lt; :== { &gt;debugmsg&lt; }
1165
1166   &gt;debugmsg&lt;  :== &gt;debughdr&lt; '\n' &gt;debugtext&lt;
1167
1168   &gt;debughdr&lt;  :== '[' TIME ',' LEVEL ']' FILE ':' [FUNCTION] '(' LINE ')'
1169
1170   &gt;debugtext&lt; :== { &gt;debugline&lt; }
1171
1172   &gt;debugline&lt; :== TEXT '\n'</PRE
1173 ></P
1174 ><P
1175 >TEXT is a string of characters excluding the newline character.</P
1176 ><P
1177 >LEVEL is the DEBUG level of the message (an integer in the range
1178                 0..10).</P
1179 ><P
1180 >TIME is a timestamp.</P
1181 ><P
1182 >FILE is the name of the file from which the debug message was
1183 generated.</P
1184 ><P
1185 >FUNCTION is the function from which the debug message was generated.</P
1186 ><P
1187 >LINE is the line number of the debug statement that generated the
1188 message.</P
1189 ><P
1190 >Basically, what that all means is:</P
1191 ><P
1192 ></P
1193 ><OL
1194 TYPE="1"
1195 ><LI
1196 ><P
1197 >A debugging log file is made up of debug messages.</P
1198 ></LI
1199 ><LI
1200 ><P
1201 >Each debug message is made up of a header and text. The header is
1202 separated from the text by a newline.</P
1203 ></LI
1204 ><LI
1205 ><P
1206 >The header begins with the timestamp and debug level of the
1207 message enclosed in brackets. The filename, function, and line
1208 number at which the message was generated follow. The filename is
1209 terminated by a colon, and the function name is terminated by the
1210 parenthesis which contain the line number. Depending upon the
1211 compiler, the function name may be missing (it is generated by the
1212 __FUNCTION__ macro, which is not universally implemented, dangit).</P
1213 ></LI
1214 ><LI
1215 ><P
1216 >The message text is made up of zero or more lines, each terminated
1217 by a newline.</P
1218 ></LI
1219 ></OL
1220 ><P
1221 >Here's some example output:</P
1222 ><P
1223 ><PRE
1224 CLASS="PROGRAMLISTING"
1225 >    [1998/08/03 12:55:25, 1] nmbd.c:(659)
1226       Netbios nameserver version 1.9.19-prealpha started.
1227       Copyright Andrew Tridgell 1994-1997
1228     [1998/08/03 12:55:25, 3] loadparm.c:(763)
1229       Initializing global parameters</PRE
1230 ></P
1231 ><P
1232 >Note that in the above example the function names are not listed on
1233 the header line. That's because the example above was generated on an
1234 SGI Indy, and the SGI compiler doesn't support the __FUNCTION__ macro.</P
1235 ></DIV
1236 ><DIV
1237 CLASS="SECT1"
1238 ><HR><H2
1239 CLASS="SECT1"
1240 ><A
1241 NAME="AEN128"
1242 ></A
1243 >3.2. The DEBUG() Macro</H2
1244 ><P
1245 >Use of the DEBUG() macro is unchanged. DEBUG() takes two parameters.
1246 The first is the message level, the second is the body of a function
1247 call to the Debug1() function.</P
1248 ><P
1249 >That's confusing.</P
1250 ><P
1251 >Here's an example which may help a bit. If you would write</P
1252 ><P
1253 ><PRE
1254 CLASS="PROGRAMLISTING"
1255 >printf( "This is a %s message.\n", "debug" );</PRE
1256 ></P
1257 ><P
1258 >to send the output to stdout, then you would write</P
1259 ><P
1260 ><PRE
1261 CLASS="PROGRAMLISTING"
1262 >DEBUG( 0, ( "This is a %s message.\n", "debug" ) );</PRE
1263 ></P
1264 ><P
1265 >to send the output to the debug file.  All of the normal printf()
1266 formatting escapes work.</P
1267 ><P
1268 >Note that in the above example the DEBUG message level is set to 0.
1269 Messages at level 0 always print.  Basically, if the message level is
1270 less than or equal to the global value DEBUGLEVEL, then the DEBUG
1271 statement is processed.</P
1272 ><P
1273 >The output of the above example would be something like:</P
1274 ><P
1275 ><PRE
1276 CLASS="PROGRAMLISTING"
1277 >    [1998/07/30 16:00:51, 0] file.c:function(128)
1278       This is a debug message.</PRE
1279 ></P
1280 ><P
1281 >Each call to DEBUG() creates a new header *unless* the output produced
1282 by the previous call to DEBUG() did not end with a '\n'. Output to the
1283 debug file is passed through a formatting buffer which is flushed
1284 every time a newline is encountered. If the buffer is not empty when
1285 DEBUG() is called, the new input is simply appended.</P
1286 ><P
1287 >...but that's really just a Kludge. It was put in place because
1288 DEBUG() has been used to write partial lines. Here's a simple (dumb)
1289 example of the kind of thing I'm talking about:</P
1290 ><P
1291 ><PRE
1292 CLASS="PROGRAMLISTING"
1293 >    DEBUG( 0, ("The test returned " ) );
1294     if( test() )
1295       DEBUG(0, ("True") );
1296     else
1297       DEBUG(0, ("False") );
1298     DEBUG(0, (".\n") );</PRE
1299 ></P
1300 ><P
1301 >Without the format buffer, the output (assuming test() returned true)
1302 would look like this:</P
1303 ><P
1304 ><PRE
1305 CLASS="PROGRAMLISTING"
1306 >    [1998/07/30 16:00:51, 0] file.c:function(256)
1307       The test returned
1308     [1998/07/30 16:00:51, 0] file.c:function(258)
1309       True
1310     [1998/07/30 16:00:51, 0] file.c:function(261)
1311       .</PRE
1312 ></P
1313 ><P
1314 >Which isn't much use. The format buffer kludge fixes this problem.</P
1315 ></DIV
1316 ><DIV
1317 CLASS="SECT1"
1318 ><HR><H2
1319 CLASS="SECT1"
1320 ><A
1321 NAME="AEN151"
1322 ></A
1323 >3.3. The DEBUGADD() Macro</H2
1324 ><P
1325 >In addition to the kludgey solution to the broken line problem
1326 described above, there is a clean solution. The DEBUGADD() macro never
1327 generates a header. It will append new text to the current debug
1328 message even if the format buffer is empty. The syntax of the
1329 DEBUGADD() macro is the same as that of the DEBUG() macro.</P
1330 ><P
1331 ><PRE
1332 CLASS="PROGRAMLISTING"
1333 >    DEBUG( 0, ("This is the first line.\n" ) );
1334     DEBUGADD( 0, ("This is the second line.\nThis is the third line.\n" ) );</PRE
1335 ></P
1336 ><P
1337 >Produces</P
1338 ><P
1339 ><PRE
1340 CLASS="PROGRAMLISTING"
1341 >    [1998/07/30 16:00:51, 0] file.c:function(512)
1342       This is the first line.
1343       This is the second line.
1344       This is the third line.</PRE
1345 ></P
1346 ></DIV
1347 ><DIV
1348 CLASS="SECT1"
1349 ><HR><H2
1350 CLASS="SECT1"
1351 ><A
1352 NAME="AEN159"
1353 ></A
1354 >3.4. The DEBUGLVL() Macro</H2
1355 ><P
1356 >One of the problems with the DEBUG() macro was that DEBUG() lines
1357 tended to get a bit long. Consider this example from
1358 nmbd_sendannounce.c:</P
1359 ><P
1360 ><PRE
1361 CLASS="PROGRAMLISTING"
1362 >  DEBUG(3,("send_local_master_announcement: type %x for name %s on subnet %s for workgroup %s\n",
1363             type, global_myname, subrec-&#62;subnet_name, work-&#62;work_group));</PRE
1364 ></P
1365 ><P
1366 >One solution to this is to break it down using DEBUG() and DEBUGADD(),
1367 as follows:</P
1368 ><P
1369 ><PRE
1370 CLASS="PROGRAMLISTING"
1371 >  DEBUG( 3, ( "send_local_master_announcement: " ) );
1372   DEBUGADD( 3, ( "type %x for name %s ", type, global_myname ) );
1373   DEBUGADD( 3, ( "on subnet %s ", subrec-&#62;subnet_name ) );
1374   DEBUGADD( 3, ( "for workgroup %s\n", work-&#62;work_group ) );</PRE
1375 ></P
1376 ><P
1377 >A similar, but arguably nicer approach is to use the DEBUGLVL() macro.
1378 This macro returns True if the message level is less than or equal to
1379 the global DEBUGLEVEL value, so:</P
1380 ><P
1381 ><PRE
1382 CLASS="PROGRAMLISTING"
1383 >  if( DEBUGLVL( 3 ) )
1384     {
1385     dbgtext( "send_local_master_announcement: " );
1386     dbgtext( "type %x for name %s ", type, global_myname );
1387     dbgtext( "on subnet %s ", subrec-&#62;subnet_name );
1388     dbgtext( "for workgroup %s\n", work-&#62;work_group );
1389     }</PRE
1390 ></P
1391 ><P
1392 >(The dbgtext() function is explained below.)</P
1393 ><P
1394 >There are a few advantages to this scheme:</P
1395 ><P
1396 ></P
1397 ><OL
1398 TYPE="1"
1399 ><LI
1400 ><P
1401 >The test is performed only once.</P
1402 ></LI
1403 ><LI
1404 ><P
1405 >You can allocate variables off of the stack that will only be used
1406 within the DEBUGLVL() block.</P
1407 ></LI
1408 ><LI
1409 ><P
1410 >Processing that is only relevant to debug output can be contained
1411 within the DEBUGLVL() block.</P
1412 ></LI
1413 ></OL
1414 ></DIV
1415 ><DIV
1416 CLASS="SECT1"
1417 ><HR><H2
1418 CLASS="SECT1"
1419 ><A
1420 NAME="AEN179"
1421 ></A
1422 >3.5. New Functions</H2
1423 ><DIV
1424 CLASS="SECT2"
1425 ><H3
1426 CLASS="SECT2"
1427 ><A
1428 NAME="AEN181"
1429 ></A
1430 >3.5.1. dbgtext()</H3
1431 ><P
1432 >This function prints debug message text to the debug file (and
1433 possibly to syslog) via the format buffer. The function uses a
1434 variable argument list just like printf() or Debug1(). The
1435 input is printed into a buffer using the vslprintf() function,
1436 and then passed to format_debug_text().
1437
1438 If you use DEBUGLVL() you will probably print the body of the
1439 message using dbgtext(). </P
1440 ></DIV
1441 ><DIV
1442 CLASS="SECT2"
1443 ><HR><H3
1444 CLASS="SECT2"
1445 ><A
1446 NAME="AEN184"
1447 ></A
1448 >3.5.2. dbghdr()</H3
1449 ><P
1450 >This is the function that writes a debug message header.
1451 Headers are not processed via the format buffer. Also note that
1452 if the format buffer is not empty, a call to dbghdr() will not
1453 produce any output. See the comments in dbghdr() for more info.</P
1454 ><P
1455 >It is not likely that this function will be called directly. It
1456 is used by DEBUG() and DEBUGADD().</P
1457 ></DIV
1458 ><DIV
1459 CLASS="SECT2"
1460 ><HR><H3
1461 CLASS="SECT2"
1462 ><A
1463 NAME="AEN188"
1464 ></A
1465 >3.5.3. format_debug_text()</H3
1466 ><P
1467 >This is a static function in debug.c. It stores the output text
1468 for the body of the message in a buffer until it encounters a
1469 newline. When the newline character is found, the buffer is
1470 written to the debug file via the Debug1() function, and the
1471 buffer is reset. This allows us to add the indentation at the
1472 beginning of each line of the message body, and also ensures
1473 that the output is written a line at a time (which cleans up
1474 syslog output).</P
1475 ></DIV
1476 ></DIV
1477 ></DIV
1478 ><DIV
1479 CLASS="CHAPTER"
1480 ><HR><H1
1481 ><A
1482 NAME="CODINGSUGGESTIONS"
1483 ></A
1484 >Chapter 4. Coding Suggestions</H1
1485 ><P
1486 >So you want to add code to Samba ...</P
1487 ><P
1488 >One of the daunting tasks facing a programmer attempting to write code for
1489 Samba is understanding the various coding conventions used by those most
1490 active in the project.  These conventions were mostly unwritten and helped
1491 improve either the portability, stability or consistency of the code. This
1492 document will attempt to document a few of the more important coding
1493 practices used at this time on the Samba project.  The coding practices are
1494 expected to change slightly over time, and even to grow as more is learned
1495 about obscure portability considerations.  Two existing documents
1496 <TT
1497 CLASS="FILENAME"
1498 >samba/source/internals.doc</TT
1499 > and 
1500 <TT
1501 CLASS="FILENAME"
1502 >samba/source/architecture.doc</TT
1503 > provide
1504 additional information.</P
1505 ><P
1506 >The loosely related question of coding style is very personal and this
1507 document does not attempt to address that subject, except to say that I
1508 have observed that eight character tabs seem to be preferred in Samba
1509 source.  If you are interested in the topic of coding style, two oft-quoted
1510 documents are:</P
1511 ><P
1512 ><A
1513 HREF="http://lxr.linux.no/source/Documentation/CodingStyle"
1514 TARGET="_top"
1515 >http://lxr.linux.no/source/Documentation/CodingStyle</A
1516 ></P
1517 ><P
1518 ><A
1519 HREF="http://www.fsf.org/prep/standards_toc.html"
1520 TARGET="_top"
1521 >http://www.fsf.org/prep/standards_toc.html</A
1522 ></P
1523 ><P
1524 >But note that coding style in Samba varies due to the many different
1525 programmers who have contributed.</P
1526 ><P
1527 >Following are some considerations you should use when adding new code to
1528 Samba.  First and foremost remember that:</P
1529 ><P
1530 >Portability is a primary consideration in adding function, as is network
1531 compatability with de facto, existing, real world CIFS/SMB implementations.
1532 There are lots of platforms that Samba builds on so use caution when adding
1533 a call to a library function that is not invoked in existing Samba code.
1534 Also note that there are many quite different SMB/CIFS clients that Samba
1535 tries to support, not all of which follow the SNIA CIFS Technical Reference
1536 (or the earlier Microsoft reference documents or the X/Open book on the SMB
1537 Standard) perfectly.</P
1538 ><P
1539 >Here are some other suggestions:</P
1540 ><P
1541 ></P
1542 ><OL
1543 TYPE="1"
1544 ><LI
1545 ><P
1546 >       use d_printf instead of printf for display text
1547         reason: enable auto-substitution of translated language text </P
1548 ></LI
1549 ><LI
1550 ><P
1551 >       use SAFE_FREE instead of free
1552         reason: reduce traps due to null pointers</P
1553 ></LI
1554 ><LI
1555 ><P
1556 >       don't use bzero use memset, or ZERO_STRUCT and ZERO_STRUCTP macros
1557         reason: not POSIX</P
1558 ></LI
1559 ><LI
1560 ><P
1561 >       don't use strcpy and strlen (use safe_* equivalents)
1562         reason: to avoid traps due to buffer overruns</P
1563 ></LI
1564 ><LI
1565 ><P
1566 >       don't use getopt_long, use popt functions instead
1567         reason: portability</P
1568 ></LI
1569 ><LI
1570 ><P
1571 >       explicitly add const qualifiers on parm passing in functions where parm
1572         is input only (somewhat controversial but const can be #defined away)</P
1573 ></LI
1574 ><LI
1575 ><P
1576 >       when passing a va_list as an arg, or assigning one to another
1577         please use the VA_COPY() macro
1578         reason: on some platforms, va_list is a struct that must be 
1579         initialized in each function...can SEGV if you don't.</P
1580 ></LI
1581 ><LI
1582 ><P
1583 >       discourage use of threads
1584         reason: portability (also see architecture.doc)</P
1585 ></LI
1586 ><LI
1587 ><P
1588 >       don't explicitly include new header files in C files - new h files 
1589         should be included by adding them once to includes.h
1590         reason: consistency</P
1591 ></LI
1592 ><LI
1593 ><P
1594 >       don't explicitly extern functions (they are autogenerated by 
1595         "make proto" into proto.h)
1596         reason: consistency</P
1597 ></LI
1598 ><LI
1599 ><P
1600 >       use endian safe macros when unpacking SMBs (see byteorder.h and
1601         internals.doc)
1602         reason: not everyone uses Intel</P
1603 ></LI
1604 ><LI
1605 ><P
1606 >       Note Unicode implications of charset handling (see internals.doc).  See
1607         pull_*  and push_* and convert_string functions.
1608         reason: Internationalization</P
1609 ></LI
1610 ><LI
1611 ><P
1612 >       Don't assume English only
1613         reason: See above</P
1614 ></LI
1615 ><LI
1616 ><P
1617 >       Try to avoid using in/out parameters (functions that return data which
1618         overwrites input parameters)
1619         reason: Can cause stability problems</P
1620 ></LI
1621 ><LI
1622 ><P
1623 >       Ensure copyright notices are correct, don't append Tridge's name to code
1624         that he didn't write.  If you did not write the code, make sure that it
1625         can coexist with the rest of the Samba GPLed code.</P
1626 ></LI
1627 ><LI
1628 ><P
1629 >       Consider usage of DATA_BLOBs for length specified byte-data.
1630         reason: stability</P
1631 ></LI
1632 ><LI
1633 ><P
1634 >       Take advantage of tdbs for database like function
1635         reason: consistency</P
1636 ></LI
1637 ><LI
1638 ><P
1639 >       Don't access the SAM_ACCOUNT structure directly, they should be accessed
1640         via pdb_get...() and pdb_set...() functions.
1641         reason: stability, consistency</P
1642 ></LI
1643 ><LI
1644 ><P
1645 >       Don't check a password directly against the passdb, always use the
1646         check_password() interface.
1647         reason: long term pluggability</P
1648 ></LI
1649 ><LI
1650 ><P
1651 >       Try to use asprintf rather than pstrings and fstrings where possible</P
1652 ></LI
1653 ><LI
1654 ><P
1655 >       Use normal C comments / * instead of C++ comments // like
1656         this.  Although the C++ comment format is part of the C99
1657         standard, some older vendor C compilers do not accept it.</P
1658 ></LI
1659 ><LI
1660 ><P
1661 >       Try to write documentation for API functions and structures
1662         explaining the point of the code, the way it should be used, and
1663         any special conditions or results.  Mark these with a double-star
1664         comment start / ** so that they can be picked up by Doxygen, as in
1665         this file.</P
1666 ></LI
1667 ><LI
1668 ><P
1669 >       Keep the scope narrow. This means making functions/variables
1670         static whenever possible. We don't want our namespace
1671         polluted. Each module should have a minimal number of externally
1672         visible functions or variables.</P
1673 ></LI
1674 ><LI
1675 ><P
1676 >       Use function pointers to keep knowledge about particular pieces of
1677         code isolated in one place. We don't want a particular piece of
1678         functionality to be spread out across lots of places - that makes
1679         for fragile, hand to maintain code. Instead, design an interface
1680         and use tables containing function pointers to implement specific
1681         functionality. This is particularly important for command
1682         interpreters. </P
1683 ></LI
1684 ><LI
1685 ><P
1686 >       Think carefully about what it will be like for someone else to add
1687         to and maintain your code. If it would be hard for someone else to
1688         maintain then do it another way. </P
1689 ></LI
1690 ></OL
1691 ><P
1692 >The suggestions above are simply that, suggestions, but the information may
1693 help in reducing the routine rework done on new code.  The preceeding list
1694 is expected to change routinely as new support routines and macros are
1695 added.</P
1696 ></DIV
1697 ><DIV
1698 CLASS="CHAPTER"
1699 ><HR><H1
1700 ><A
1701 NAME="INTERNALS"
1702 ></A
1703 >Chapter 5. Samba Internals</H1
1704 ><DIV
1705 CLASS="SECT1"
1706 ><H2
1707 CLASS="SECT1"
1708 ><A
1709 NAME="AEN284"
1710 ></A
1711 >5.1. Character Handling</H2
1712 ><P
1713 >This section describes character set handling in Samba, as implemented in
1714 Samba 3.0 and above</P
1715 ><P
1716 >In the past Samba had very ad-hoc character set handling. Scattered
1717 throughout the code were numerous calls which converted particular
1718 strings to/from DOS codepages. The problem is that there was no way of
1719 telling if a particular char* is in dos codepage or unix
1720 codepage. This led to a nightmare of code that tried to cope with
1721 particular cases without handlingt the general case.</P
1722 ></DIV
1723 ><DIV
1724 CLASS="SECT1"
1725 ><HR><H2
1726 CLASS="SECT1"
1727 ><A
1728 NAME="AEN288"
1729 ></A
1730 >5.2. The new functions</H2
1731 ><P
1732 >The new system works like this:</P
1733 ><P
1734 ></P
1735 ><OL
1736 TYPE="1"
1737 ><LI
1738 ><P
1739 >       all char* strings inside Samba are "unix" strings. These are
1740         multi-byte strings that are in the charset defined by the "unix
1741         charset" option in smb.conf. </P
1742 ></LI
1743 ><LI
1744 ><P
1745 >       there is no single fixed character set for unix strings, but any
1746         character set that is used does need the following properties:
1747         </P
1748 ><P
1749 ></P
1750 ><OL
1751 TYPE="a"
1752 ><LI
1753 ><P
1754 >               must not contain NULLs except for termination
1755         </P
1756 ></LI
1757 ><LI
1758 ><P
1759 >               must be 7-bit compatible with C strings, so that a constant
1760                 string or character in C will be byte-for-byte identical to the
1761                 equivalent string in the chosen character set. 
1762         </P
1763 ></LI
1764 ><LI
1765 ><P
1766 >               when you uppercase or lowercase a string it does not become
1767                 longer than the original string
1768         </P
1769 ></LI
1770 ><LI
1771 ><P
1772 >               must be able to correctly hold all characters that your client
1773                 will throw at it
1774         </P
1775 ></LI
1776 ></OL
1777 ><P
1778 >       For example, UTF-8 is fine, and most multi-byte asian character sets
1779         are fine, but UCS2 could not be used for unix strings as they
1780         contain nulls.
1781         </P
1782 ></LI
1783 ><LI
1784 ><P
1785 >       when you need to put a string into a buffer that will be sent on the
1786         wire, or you need a string in a character set format that is
1787         compatible with the clients character set then you need to use a
1788         pull_ or push_ function. The pull_ functions pull a string from a
1789         wire buffer into a (multi-byte) unix string. The push_ functions
1790         push a string out to a wire buffer. </P
1791 ></LI
1792 ><LI
1793 ><P
1794 >       the two main pull_ and push_ functions you need to understand are
1795         pull_string and push_string. These functions take a base pointer
1796         that should point at the start of the SMB packet that the string is
1797         in. The functions will check the flags field in this packet to
1798         automatically determine if the packet is marked as a unicode packet,
1799         and they will choose whether to use unicode for this string based on
1800         that flag. You may also force this decision using the STR_UNICODE or
1801         STR_ASCII flags. For use in smbd/ and libsmb/ there are wrapper
1802         functions clistr_ and srvstr_ that call the pull_/push_ functions
1803         with the appropriate first argument.
1804         </P
1805 ><P
1806 >       You may also call the pull_ascii/pull_ucs2 or push_ascii/push_ucs2
1807         functions if you know that a particular string is ascii or
1808         unicode. There are also a number of other convenience functions in
1809         charcnv.c that call the pull_/push_ functions with particularly
1810         common arguments, such as pull_ascii_pstring()
1811         </P
1812 ></LI
1813 ><LI
1814 ><P
1815 >       The biggest thing to remember is that internal (unix) strings in Samba
1816         may now contain multi-byte characters. This means you cannot assume
1817         that characters are always 1 byte long. Often this means that you will
1818         have to convert strings to ucs2 and back again in order to do some
1819         (seemingly) simple task. For examples of how to do this see functions
1820         like strchr_m(). I know this is very slow, and we will eventually
1821         speed it up but right now we want this stuff correct not fast.</P
1822 ></LI
1823 ><LI
1824 ><P
1825 >       all lp_ functions now return unix strings. The magic "DOS" flag on
1826         parameters is gone.</P
1827 ></LI
1828 ><LI
1829 ><P
1830 >       all vfs functions take unix strings. Don't convert when passing to them</P
1831 ></LI
1832 ></OL
1833 ></DIV
1834 ><DIV
1835 CLASS="SECT1"
1836 ><HR><H2
1837 CLASS="SECT1"
1838 ><A
1839 NAME="AEN317"
1840 ></A
1841 >5.3. Macros in byteorder.h</H2
1842 ><P
1843 >This section describes the macros defined in byteorder.h.  These macros 
1844 are used extensively in the Samba code.</P
1845 ><DIV
1846 CLASS="SECT2"
1847 ><HR><H3
1848 CLASS="SECT2"
1849 ><A
1850 NAME="AEN320"
1851 ></A
1852 >5.3.1. CVAL(buf,pos)</H3
1853 ><P
1854 >returns the byte at offset pos within buffer buf as an unsigned character.</P
1855 ></DIV
1856 ><DIV
1857 CLASS="SECT2"
1858 ><HR><H3
1859 CLASS="SECT2"
1860 ><A
1861 NAME="AEN323"
1862 ></A
1863 >5.3.2. PVAL(buf,pos)</H3
1864 ><P
1865 >returns the value of CVAL(buf,pos) cast to type unsigned integer.</P
1866 ></DIV
1867 ><DIV
1868 CLASS="SECT2"
1869 ><HR><H3
1870 CLASS="SECT2"
1871 ><A
1872 NAME="AEN326"
1873 ></A
1874 >5.3.3. SCVAL(buf,pos,val)</H3
1875 ><P
1876 >sets the byte at offset pos within buffer buf to value val.</P
1877 ></DIV
1878 ><DIV
1879 CLASS="SECT2"
1880 ><HR><H3
1881 CLASS="SECT2"
1882 ><A
1883 NAME="AEN329"
1884 ></A
1885 >5.3.4. SVAL(buf,pos)</H3
1886 ><P
1887 >       returns the value of the unsigned short (16 bit) little-endian integer at 
1888         offset pos within buffer buf.  An integer of this type is sometimes
1889         refered to as "USHORT".</P
1890 ></DIV
1891 ><DIV
1892 CLASS="SECT2"
1893 ><HR><H3
1894 CLASS="SECT2"
1895 ><A
1896 NAME="AEN332"
1897 ></A
1898 >5.3.5. IVAL(buf,pos)</H3
1899 ><P
1900 >returns the value of the unsigned 32 bit little-endian integer at offset 
1901 pos within buffer buf.</P
1902 ></DIV
1903 ><DIV
1904 CLASS="SECT2"
1905 ><HR><H3
1906 CLASS="SECT2"
1907 ><A
1908 NAME="AEN335"
1909 ></A
1910 >5.3.6. SVALS(buf,pos)</H3
1911 ><P
1912 >returns the value of the signed short (16 bit) little-endian integer at 
1913 offset pos within buffer buf.</P
1914 ></DIV
1915 ><DIV
1916 CLASS="SECT2"
1917 ><HR><H3
1918 CLASS="SECT2"
1919 ><A
1920 NAME="AEN338"
1921 ></A
1922 >5.3.7. IVALS(buf,pos)</H3
1923 ><P
1924 >returns the value of the signed 32 bit little-endian integer at offset pos
1925 within buffer buf.</P
1926 ></DIV
1927 ><DIV
1928 CLASS="SECT2"
1929 ><HR><H3
1930 CLASS="SECT2"
1931 ><A
1932 NAME="AEN341"
1933 ></A
1934 >5.3.8. SSVAL(buf,pos,val)</H3
1935 ><P
1936 >sets the unsigned short (16 bit) little-endian integer at offset pos within 
1937 buffer buf to value val.</P
1938 ></DIV
1939 ><DIV
1940 CLASS="SECT2"
1941 ><HR><H3
1942 CLASS="SECT2"
1943 ><A
1944 NAME="AEN344"
1945 ></A
1946 >5.3.9. SIVAL(buf,pos,val)</H3
1947 ><P
1948 >sets the unsigned 32 bit little-endian integer at offset pos within buffer 
1949 buf to the value val.</P
1950 ></DIV
1951 ><DIV
1952 CLASS="SECT2"
1953 ><HR><H3
1954 CLASS="SECT2"
1955 ><A
1956 NAME="AEN347"
1957 ></A
1958 >5.3.10. SSVALS(buf,pos,val)</H3
1959 ><P
1960 >sets the short (16 bit) signed little-endian integer at offset pos within 
1961 buffer buf to the value val.</P
1962 ></DIV
1963 ><DIV
1964 CLASS="SECT2"
1965 ><HR><H3
1966 CLASS="SECT2"
1967 ><A
1968 NAME="AEN350"
1969 ></A
1970 >5.3.11. SIVALS(buf,pos,val)</H3
1971 ><P
1972 >sets the signed 32 bit little-endian integer at offset pos withing buffer
1973 buf to the value val.</P
1974 ></DIV
1975 ><DIV
1976 CLASS="SECT2"
1977 ><HR><H3
1978 CLASS="SECT2"
1979 ><A
1980 NAME="AEN353"
1981 ></A
1982 >5.3.12. RSVAL(buf,pos)</H3
1983 ><P
1984 >returns the value of the unsigned short (16 bit) big-endian integer at 
1985 offset pos within buffer buf.</P
1986 ></DIV
1987 ><DIV
1988 CLASS="SECT2"
1989 ><HR><H3
1990 CLASS="SECT2"
1991 ><A
1992 NAME="AEN356"
1993 ></A
1994 >5.3.13. RIVAL(buf,pos)</H3
1995 ><P
1996 >returns the value of the unsigned 32 bit big-endian integer at offset 
1997 pos within buffer buf.</P
1998 ></DIV
1999 ><DIV
2000 CLASS="SECT2"
2001 ><HR><H3
2002 CLASS="SECT2"
2003 ><A
2004 NAME="AEN359"
2005 ></A
2006 >5.3.14. RSSVAL(buf,pos,val)</H3
2007 ><P
2008 >sets the value of the unsigned short (16 bit) big-endian integer at 
2009 offset pos within buffer buf to value val.
2010 refered to as "USHORT".</P
2011 ></DIV
2012 ><DIV
2013 CLASS="SECT2"
2014 ><HR><H3
2015 CLASS="SECT2"
2016 ><A
2017 NAME="AEN362"
2018 ></A
2019 >5.3.15. RSIVAL(buf,pos,val)</H3
2020 ><P
2021 >sets the value of the unsigned 32 bit big-endian integer at offset 
2022 pos within buffer buf to value val.</P
2023 ></DIV
2024 ></DIV
2025 ><DIV
2026 CLASS="SECT1"
2027 ><HR><H2
2028 CLASS="SECT1"
2029 ><A
2030 NAME="AEN365"
2031 ></A
2032 >5.4. LAN Manager Samba API</H2
2033 ><P
2034 >This section describes the functions need to make a LAN Manager RPC call.
2035 This information had been obtained by examining the Samba code and the LAN
2036 Manager 2.0 API documentation.  It should not be considered entirely
2037 reliable.</P
2038 ><P
2039 ><PRE
2040 CLASS="PROGRAMLISTING"
2041 >call_api(int prcnt, int drcnt, int mprcnt, int mdrcnt, 
2042         char *param, char *data, char **rparam, char **rdata);</PRE
2043 ></P
2044 ><P
2045 >This function is defined in client.c.  It uses an SMB transaction to call a
2046 remote api.</P
2047 ><DIV
2048 CLASS="SECT2"
2049 ><HR><H3
2050 CLASS="SECT2"
2051 ><A
2052 NAME="AEN371"
2053 ></A
2054 >5.4.1. Parameters</H3
2055 ><P
2056 >The parameters are as follows:</P
2057 ><P
2058 ></P
2059 ><OL
2060 TYPE="1"
2061 ><LI
2062 ><P
2063 >       prcnt: the number of bytes of parameters begin sent.</P
2064 ></LI
2065 ><LI
2066 ><P
2067 >       drcnt:   the number of bytes of data begin sent.</P
2068 ></LI
2069 ><LI
2070 ><P
2071 >       mprcnt:  the maximum number of bytes of parameters which should be returned</P
2072 ></LI
2073 ><LI
2074 ><P
2075 >       mdrcnt:  the maximum number of bytes of data which should be returned</P
2076 ></LI
2077 ><LI
2078 ><P
2079 >       param:   a pointer to the parameters to be sent.</P
2080 ></LI
2081 ><LI
2082 ><P
2083 >       data:    a pointer to the data to be sent.</P
2084 ></LI
2085 ><LI
2086 ><P
2087 >       rparam:  a pointer to a pointer which will be set to point to the returned
2088         paramters.  The caller of call_api() must deallocate this memory.</P
2089 ></LI
2090 ><LI
2091 ><P
2092 >       rdata:   a pointer to a pointer which will be set to point to the returned 
2093         data.  The caller of call_api() must deallocate this memory.</P
2094 ></LI
2095 ></OL
2096 ><P
2097 >These are the parameters which you ought to send, in the order of their
2098 appearance in the parameter block:</P
2099 ><P
2100 ></P
2101 ><OL
2102 TYPE="1"
2103 ><LI
2104 ><P
2105 >An unsigned 16 bit integer API number.  You should set this value with
2106 SSVAL().  I do not know where these numbers are described.</P
2107 ></LI
2108 ><LI
2109 ><P
2110 >An ASCIIZ string describing the parameters to the API function as defined
2111 in the LAN Manager documentation.  The first parameter, which is the server
2112 name, is ommited.  This string is based uppon the API function as described
2113 in the manual, not the data which is actually passed.</P
2114 ></LI
2115 ><LI
2116 ><P
2117 >An ASCIIZ string describing the data structure which ought to be returned.</P
2118 ></LI
2119 ><LI
2120 ><P
2121 >Any parameters which appear in the function call, as defined in the LAN
2122 Manager API documentation, after the "Server" and up to and including the
2123 "uLevel" parameters.</P
2124 ></LI
2125 ><LI
2126 ><P
2127 >An unsigned 16 bit integer which gives the size in bytes of the buffer we
2128 will use to receive the returned array of data structures.  Presumably this
2129 should be the same as mdrcnt.  This value should be set with SSVAL().</P
2130 ></LI
2131 ><LI
2132 ><P
2133 >An ASCIIZ string describing substructures which should be returned.  If no 
2134 substructures apply, this string is of zero length.</P
2135 ></LI
2136 ></OL
2137 ><P
2138 >The code in client.c always calls call_api() with no data.  It is unclear
2139 when a non-zero length data buffer would be sent.</P
2140 ></DIV
2141 ><DIV
2142 CLASS="SECT2"
2143 ><HR><H3
2144 CLASS="SECT2"
2145 ><A
2146 NAME="AEN406"
2147 ></A
2148 >5.4.2. Return value</H3
2149 ><P
2150 >The returned parameters (pointed to by rparam), in their order of appearance
2151 are:</P
2152 ><P
2153 ></P
2154 ><OL
2155 TYPE="1"
2156 ><LI
2157 ><P
2158 >An unsigned 16 bit integer which contains the API function's return code. 
2159 This value should be read with SVAL().</P
2160 ></LI
2161 ><LI
2162 ><P
2163 >An adjustment which tells the amount by which pointers in the returned
2164 data should be adjusted.  This value should be read with SVAL().  Basically, 
2165 the address of the start of the returned data buffer should have the returned
2166 pointer value added to it and then have this value subtracted from it in
2167 order to obtain the currect offset into the returned data buffer.</P
2168 ></LI
2169 ><LI
2170 ><P
2171 >A count of the number of elements in the array of structures returned. 
2172 It is also possible that this may sometimes be the number of bytes returned.</P
2173 ></LI
2174 ></OL
2175 ><P
2176 >When call_api() returns, rparam points to the returned parameters.  The
2177 first if these is the result code.  It will be zero if the API call
2178 suceeded.  This value by be read with "SVAL(rparam,0)".</P
2179 ><P
2180 >The second parameter may be read as "SVAL(rparam,2)".  It is a 16 bit offset
2181 which indicates what the base address of the returned data buffer was when
2182 it was built on the server.  It should be used to correct pointer before
2183 use.</P
2184 ><P
2185 >The returned data buffer contains the array of returned data structures. 
2186 Note that all pointers must be adjusted before use.  The function
2187 fix_char_ptr() in client.c can be used for this purpose.</P
2188 ><P
2189 >The third parameter (which may be read as "SVAL(rparam,4)") has something to
2190 do with indicating the amount of data returned or possibly the amount of
2191 data which can be returned if enough buffer space is allowed.</P
2192 ></DIV
2193 ></DIV
2194 ><DIV
2195 CLASS="SECT1"
2196 ><HR><H2
2197 CLASS="SECT1"
2198 ><A
2199 NAME="AEN420"
2200 ></A
2201 >5.5. Code character table</H2
2202 ><P
2203 >Certain data structures are described by means of ASCIIz strings containing
2204 code characters.  These are the code characters:</P
2205 ><P
2206 ></P
2207 ><OL
2208 TYPE="1"
2209 ><LI
2210 ><P
2211 >W      a type byte little-endian unsigned integer</P
2212 ></LI
2213 ><LI
2214 ><P
2215 >N      a count of substructures which follow</P
2216 ></LI
2217 ><LI
2218 ><P
2219 >D      a four byte little-endian unsigned integer</P
2220 ></LI
2221 ><LI
2222 ><P
2223 >B      a byte (with optional count expressed as trailing ASCII digits)</P
2224 ></LI
2225 ><LI
2226 ><P
2227 >z      a four byte offset to a NULL terminated string</P
2228 ></LI
2229 ><LI
2230 ><P
2231 >l      a four byte offset to non-string user data</P
2232 ></LI
2233 ><LI
2234 ><P
2235 >b      an offset to data (with count expressed as trailing ASCII digits)</P
2236 ></LI
2237 ><LI
2238 ><P
2239 >r      pointer to returned data buffer???</P
2240 ></LI
2241 ><LI
2242 ><P
2243 >L      length in bytes of returned data buffer???</P
2244 ></LI
2245 ><LI
2246 ><P
2247 >h      number of bytes of information available???</P
2248 ></LI
2249 ></OL
2250 ></DIV
2251 ></DIV
2252 ><DIV
2253 CLASS="CHAPTER"
2254 ><HR><H1
2255 ><A
2256 NAME="PARSING"
2257 ></A
2258 >Chapter 6. The smb.conf file</H1
2259 ><DIV
2260 CLASS="SECT1"
2261 ><H2
2262 CLASS="SECT1"
2263 ><A
2264 NAME="AEN451"
2265 ></A
2266 >6.1. Lexical Analysis</H2
2267 ><P
2268 >Basically, the file is processed on a line by line basis.  There are
2269 four types of lines that are recognized by the lexical analyzer
2270 (params.c):</P
2271 ><P
2272 ></P
2273 ><OL
2274 TYPE="1"
2275 ><LI
2276 ><P
2277 >Blank lines - Lines containing only whitespace.</P
2278 ></LI
2279 ><LI
2280 ><P
2281 >Comment lines - Lines beginning with either a semi-colon or a
2282 pound sign (';' or '#').</P
2283 ></LI
2284 ><LI
2285 ><P
2286 >Section header lines - Lines beginning with an open square bracket ('[').</P
2287 ></LI
2288 ><LI
2289 ><P
2290 >Parameter lines - Lines beginning with any other character.
2291 (The default line type.)</P
2292 ></LI
2293 ></OL
2294 ><P
2295 >The first two are handled exclusively by the lexical analyzer, which
2296 ignores them.  The latter two line types are scanned for</P
2297 ><P
2298 ></P
2299 ><OL
2300 TYPE="1"
2301 ><LI
2302 ><P
2303 >  - Section names</P
2304 ></LI
2305 ><LI
2306 ><P
2307 >  - Parameter names</P
2308 ></LI
2309 ><LI
2310 ><P
2311 >  - Parameter values</P
2312 ></LI
2313 ></OL
2314 ><P
2315 >These are the only tokens passed to the parameter loader
2316 (loadparm.c).  Parameter names and values are divided from one
2317 another by an equal sign: '='.</P
2318 ><DIV
2319 CLASS="SECT2"
2320 ><HR><H3
2321 CLASS="SECT2"
2322 ><A
2323 NAME="AEN472"
2324 ></A
2325 >6.1.1. Handling of Whitespace</H3
2326 ><P
2327 >Whitespace is defined as all characters recognized by the isspace()
2328 function (see ctype(3C)) except for the newline character ('\n')
2329 The newline is excluded because it identifies the end of the line.</P
2330 ><P
2331 ></P
2332 ><OL
2333 TYPE="1"
2334 ><LI
2335 ><P
2336 >The lexical analyzer scans past white space at the beginning of a line.</P
2337 ></LI
2338 ><LI
2339 ><P
2340 >Section and parameter names may contain internal white space.  All
2341 whitespace within a name is compressed to a single space character. </P
2342 ></LI
2343 ><LI
2344 ><P
2345 >Internal whitespace within a parameter value is kept verbatim with 
2346 the exception of carriage return characters ('\r'), all of which
2347 are removed.</P
2348 ></LI
2349 ><LI
2350 ><P
2351 >Leading and trailing whitespace is removed from names and values.</P
2352 ></LI
2353 ></OL
2354 ></DIV
2355 ><DIV
2356 CLASS="SECT2"
2357 ><HR><H3
2358 CLASS="SECT2"
2359 ><A
2360 NAME="AEN484"
2361 ></A
2362 >6.1.2. Handling of Line Continuation</H3
2363 ><P
2364 >Long section header and parameter lines may be extended across
2365 multiple lines by use of the backslash character ('\\').  Line
2366 continuation is ignored for blank and comment lines.</P
2367 ><P
2368 >If the last (non-whitespace) character within a section header or on
2369 a parameter line is a backslash, then the next line will be
2370 (logically) concatonated with the current line by the lexical
2371 analyzer.  For example:</P
2372 ><P
2373 ><PRE
2374 CLASS="PROGRAMLISTING"
2375 >       param name = parameter value string \
2376         with line continuation.</PRE
2377 ></P
2378 ><P
2379 >Would be read as</P
2380 ><P
2381 ><PRE
2382 CLASS="PROGRAMLISTING"
2383 >    param name = parameter value string     with line continuation.</PRE
2384 ></P
2385 ><P
2386 >Note that there are five spaces following the word 'string',
2387 representing the one space between 'string' and '\\' in the top
2388 line, plus the four preceeding the word 'with' in the second line.
2389 (Yes, I'm counting the indentation.)</P
2390 ><P
2391 >Line continuation characters are ignored on blank lines and at the end
2392 of comments.  They are *only* recognized within section and parameter
2393 lines.</P
2394 ></DIV
2395 ><DIV
2396 CLASS="SECT2"
2397 ><HR><H3
2398 CLASS="SECT2"
2399 ><A
2400 NAME="AEN495"
2401 ></A
2402 >6.1.3. Line Continuation Quirks</H3
2403 ><P
2404 >Note the following example:</P
2405 ><P
2406 ><PRE
2407 CLASS="PROGRAMLISTING"
2408 >       param name = parameter value string \
2409     \
2410     with line continuation.</PRE
2411 ></P
2412 ><P
2413 >The middle line is *not* parsed as a blank line because it is first
2414 concatonated with the top line.  The result is</P
2415 ><P
2416 ><PRE
2417 CLASS="PROGRAMLISTING"
2418 >param name = parameter value string         with line continuation.</PRE
2419 ></P
2420 ><P
2421 >The same is true for comment lines.</P
2422 ><P
2423 ><PRE
2424 CLASS="PROGRAMLISTING"
2425 >       param name = parameter value string \
2426         ; comment \
2427     with a comment.</PRE
2428 ></P
2429 ><P
2430 >This becomes:</P
2431 ><P
2432 ><PRE
2433 CLASS="PROGRAMLISTING"
2434 >param name = parameter value string     ; comment     with a comment.</PRE
2435 ></P
2436 ><P
2437 >On a section header line, the closing bracket (']') is considered a
2438 terminating character, and the rest of the line is ignored.  The lines</P
2439 ><P
2440 ><PRE
2441 CLASS="PROGRAMLISTING"
2442 >       [ section   name ] garbage \
2443     param  name  = value</PRE
2444 ></P
2445 ><P
2446 >are read as</P
2447 ><P
2448 ><PRE
2449 CLASS="PROGRAMLISTING"
2450 >       [section name]
2451     param name = value</PRE
2452 ></P
2453 ></DIV
2454 ></DIV
2455 ><DIV
2456 CLASS="SECT1"
2457 ><HR><H2
2458 CLASS="SECT1"
2459 ><A
2460 NAME="AEN515"
2461 ></A
2462 >6.2. Syntax</H2
2463 ><P
2464 >The syntax of the smb.conf file is as follows:</P
2465 ><P
2466 ><PRE
2467 CLASS="PROGRAMLISTING"
2468 >  &lt;file&gt;            :==  { &lt;section&gt; } EOF
2469   &lt;section&gt;         :==  &lt;section header&gt; { &lt;parameter line&gt; }
2470   &lt;section header&gt;  :==  '[' NAME ']'
2471   &lt;parameter line&gt;  :==  NAME '=' VALUE NL</PRE
2472 ></P
2473 ><P
2474 >Basically, this means that</P
2475 ><P
2476 ></P
2477 ><OL
2478 TYPE="1"
2479 ><LI
2480 ><P
2481 >       a file is made up of zero or more sections, and is terminated by
2482         an EOF (we knew that).</P
2483 ></LI
2484 ><LI
2485 ><P
2486 >       A section is made up of a section header followed by zero or more
2487         parameter lines.</P
2488 ></LI
2489 ><LI
2490 ><P
2491 >       A section header is identified by an opening bracket and
2492         terminated by the closing bracket.  The enclosed NAME identifies
2493         the section.</P
2494 ></LI
2495 ><LI
2496 ><P
2497 >       A parameter line is divided into a NAME and a VALUE.  The *first*
2498         equal sign on the line separates the NAME from the VALUE.  The
2499         VALUE is terminated by a newline character (NL = '\n').</P
2500 ></LI
2501 ></OL
2502 ><DIV
2503 CLASS="SECT2"
2504 ><HR><H3
2505 CLASS="SECT2"
2506 ><A
2507 NAME="AEN530"
2508 ></A
2509 >6.2.1. About params.c</H3
2510 ><P
2511 >The parsing of the config file is a bit unusual if you are used to
2512 lex, yacc, bison, etc.  Both lexical analysis (scanning) and parsing
2513 are performed by params.c.  Values are loaded via callbacks to
2514 loadparm.c.</P
2515 ></DIV
2516 ></DIV
2517 ></DIV
2518 ><DIV
2519 CLASS="CHAPTER"
2520 ><HR><H1
2521 ><A
2522 NAME="UNIX-SMB"
2523 ></A
2524 >Chapter 7. NetBIOS in a Unix World</H1
2525 ><DIV
2526 CLASS="SECT1"
2527 ><H2
2528 CLASS="SECT1"
2529 ><A
2530 NAME="AEN540"
2531 ></A
2532 >7.1. Introduction</H2
2533 ><P
2534 >This is a short document that describes some of the issues that
2535 confront a SMB implementation on unix, and how Samba copes with
2536 them. They may help people who are looking at unix&#60;-&#62;PC
2537 interoperability.</P
2538 ><P
2539 >It was written to help out a person who was writing a paper on unix to
2540 PC connectivity.</P
2541 ></DIV
2542 ><DIV
2543 CLASS="SECT1"
2544 ><HR><H2
2545 CLASS="SECT1"
2546 ><A
2547 NAME="AEN544"
2548 ></A
2549 >7.2. Usernames</H2
2550 ><P
2551 >The SMB protocol has only a loose username concept. Early SMB
2552 protocols (such as CORE and COREPLUS) have no username concept at
2553 all. Even in later protocols clients often attempt operations
2554 (particularly printer operations) without first validating a username
2555 on the server.</P
2556 ><P
2557 >Unix security is based around username/password pairs. A unix box
2558 should not allow clients to do any substantive operation without some
2559 sort of validation. </P
2560 ><P
2561 >The problem mostly manifests itself when the unix server is in "share
2562 level" security mode. This is the default mode as the alternative
2563 "user level" security mode usually forces a client to connect to the
2564 server as the same user for each connected share, which is
2565 inconvenient in many sites.</P
2566 ><P
2567 >In "share level" security the client normally gives a username in the
2568 "session setup" protocol, but does not supply an accompanying
2569 password. The client then connects to resources using the "tree
2570 connect" protocol, and supplies a password. The problem is that the
2571 user on the PC types the username and the password in different
2572 contexts, unaware that they need to go together to give access to the
2573 server. The username is normally the one the user typed in when they
2574 "logged onto" the PC (this assumes Windows for Workgroups). The
2575 password is the one they chose when connecting to the disk or printer.</P
2576 ><P
2577 >The user often chooses a totally different username for their login as
2578 for the drive connection. Often they also want to access different
2579 drives as different usernames. The unix server needs some way of
2580 divining the correct username to combine with each password.</P
2581 ><P
2582 >Samba tries to avoid this problem using several methods. These succeed
2583 in the vast majority of cases. The methods include username maps, the
2584 service%user syntax, the saving of session setup usernames for later
2585 validation and the derivation of the username from the service name
2586 (either directly or via the user= option).</P
2587 ></DIV
2588 ><DIV
2589 CLASS="SECT1"
2590 ><HR><H2
2591 CLASS="SECT1"
2592 ><A
2593 NAME="AEN552"
2594 ></A
2595 >7.3. File Ownership</H2
2596 ><P
2597 >The commonly used SMB protocols have no way of saying "you can't do
2598 that because you don't own the file". They have, in fact, no concept
2599 of file ownership at all.</P
2600 ><P
2601 >This brings up all sorts of interesting problems. For example, when
2602 you copy a file to a unix drive, and the file is world writeable but
2603 owned by another user the file will transfer correctly but will
2604 receive the wrong date. This is because the utime() call under unix
2605 only succeeds for the owner of the file, or root, even if the file is
2606 world writeable. For security reasons Samba does all file operations
2607 as the validated user, not root, so the utime() fails. This can stuff
2608 up shared development diectories as programs like "make" will not get
2609 file time comparisons right.</P
2610 ><P
2611 >There are several possible solutions to this problem, including
2612 username mapping, and forcing a specific username for particular
2613 shares.</P
2614 ></DIV
2615 ><DIV
2616 CLASS="SECT1"
2617 ><HR><H2
2618 CLASS="SECT1"
2619 ><A
2620 NAME="AEN557"
2621 ></A
2622 >7.4. Passwords</H2
2623 ><P
2624 >Many SMB clients uppercase passwords before sending them. I have no
2625 idea why they do this. Interestingly WfWg uppercases the password only
2626 if the server is running a protocol greater than COREPLUS, so
2627 obviously it isn't just the data entry routines that are to blame.</P
2628 ><P
2629 >Unix passwords are case sensitive. So if users use mixed case
2630 passwords they are in trouble.</P
2631 ><P
2632 >Samba can try to cope with this by either using the "password level"
2633 option which causes Samba to try the offered password with up to the
2634 specified number of case changes, or by using the "password server"
2635 option which allows Samba to do its validation via another machine
2636 (typically a WinNT server).</P
2637 ><P
2638 >Samba supports the password encryption method used by SMB
2639 clients. Note that the use of password encryption in Microsoft
2640 networking leads to password hashes that are "plain text equivalent".
2641 This means that it is *VERY* important to ensure that the Samba
2642 smbpasswd file containing these password hashes is only readable
2643 by the root user. See the documentation ENCRYPTION.txt for more
2644 details.</P
2645 ></DIV
2646 ><DIV
2647 CLASS="SECT1"
2648 ><HR><H2
2649 CLASS="SECT1"
2650 ><A
2651 NAME="AEN563"
2652 ></A
2653 >7.5. Locking</H2
2654 ><P
2655 >Since samba 2.2, samba supports other types of locking as well. This 
2656 section is outdated.</P
2657 ><P
2658 >The locking calls available under a DOS/Windows environment are much
2659 richer than those available in unix. This means a unix server (like
2660 Samba) choosing to use the standard fcntl() based unix locking calls
2661 to implement SMB locking has to improvise a bit.</P
2662 ><P
2663 >One major problem is that dos locks can be in a 32 bit (unsigned)
2664 range. Unix locking calls are 32 bits, but are signed, giving only a 31
2665 bit range. Unfortunately OLE2 clients use the top bit to select a
2666 locking range used for OLE semaphores.</P
2667 ><P
2668 >To work around this problem Samba compresses the 32 bit range into 31
2669 bits by appropriate bit shifting. This seems to work but is not
2670 ideal. In a future version a separate SMB lockd may be added to cope
2671 with the problem.</P
2672 ><P
2673 >It also doesn't help that many unix lockd daemons are very buggy and
2674 crash at the slightest provocation. They normally go mostly unused in
2675 a unix environment because few unix programs use byte range
2676 locking. The stress of huge numbers of lock requests from dos/windows
2677 clients can kill the daemon on some systems.</P
2678 ><P
2679 >The second major problem is the "opportunistic locking" requested by
2680 some clients. If a client requests opportunistic locking then it is
2681 asking the server to notify it if anyone else tries to do something on
2682 the same file, at which time the client will say if it is willing to
2683 give up its lock. Unix has no simple way of implementing
2684 opportunistic locking, and currently Samba has no support for it.</P
2685 ></DIV
2686 ><DIV
2687 CLASS="SECT1"
2688 ><HR><H2
2689 CLASS="SECT1"
2690 ><A
2691 NAME="AEN571"
2692 ></A
2693 >7.6. Deny Modes</H2
2694 ><P
2695 >When a SMB client opens a file it asks for a particular "deny mode" to
2696 be placed on the file. These modes (DENY_NONE, DENY_READ, DENY_WRITE,
2697 DENY_ALL, DENY_FCB and DENY_DOS) specify what actions should be
2698 allowed by anyone else who tries to use the file at the same time. If
2699 DENY_READ is placed on the file, for example, then any attempt to open
2700 the file for reading should fail.</P
2701 ><P
2702 >Unix has no equivalent notion. To implement this Samba uses either lock
2703 files based on the files inode and placed in a separate lock
2704 directory or a shared memory implementation. The lock file method 
2705 is clumsy and consumes processing and file resources,
2706 the shared memory implementation is vastly prefered and is turned on
2707 by default for those systems that support it.</P
2708 ></DIV
2709 ><DIV
2710 CLASS="SECT1"
2711 ><HR><H2
2712 CLASS="SECT1"
2713 ><A
2714 NAME="AEN575"
2715 ></A
2716 >7.7. Trapdoor UIDs</H2
2717 ><P
2718 >A SMB session can run with several uids on the one socket. This
2719 happens when a user connects to two shares with different
2720 usernames. To cope with this the unix server needs to switch uids
2721 within the one process. On some unixes (such as SCO) this is not
2722 possible. This means that on those unixes the client is restricted to
2723 a single uid.</P
2724 ><P
2725 >Note that you can also get the "trapdoor uid" message for other
2726 reasons. Please see the FAQ for details.</P
2727 ></DIV
2728 ><DIV
2729 CLASS="SECT1"
2730 ><HR><H2
2731 CLASS="SECT1"
2732 ><A
2733 NAME="AEN579"
2734 ></A
2735 >7.8. Port numbers</H2
2736 ><P
2737 >There is a convention that clients on sockets use high "unprivilaged"
2738 port numbers (&#62;1000) and connect to servers on low "privilaged" port
2739 numbers. This is enforced in Unix as non-root users can't open a
2740 socket for listening on port numbers less than 1000.</P
2741 ><P
2742 >Most PC based SMB clients (such as WfWg and WinNT) don't follow this
2743 convention completely. The main culprit is the netbios nameserving on
2744 udp port 137. Name query requests come from a source port of 137. This
2745 is a problem when you combine it with the common firewalling technique
2746 of not allowing incoming packets on low port numbers. This means that
2747 these clients can't query a netbios nameserver on the other side of a
2748 low port based firewall.</P
2749 ><P
2750 >The problem is more severe with netbios node status queries. I've
2751 found that WfWg, Win95 and WinNT3.5 all respond to netbios node status
2752 queries on port 137 no matter what the source port was in the
2753 request. This works between machines that are both using port 137, but
2754 it means it's not possible for a unix user to do a node status request
2755 to any of these OSes unless they are running as root. The answer comes
2756 back, but it goes to port 137 which the unix user can't listen
2757 on. Interestingly WinNT3.1 got this right - it sends node status
2758 responses back to the source port in the request.</P
2759 ></DIV
2760 ><DIV
2761 CLASS="SECT1"
2762 ><HR><H2
2763 CLASS="SECT1"
2764 ><A
2765 NAME="AEN584"
2766 ></A
2767 >7.9. Protocol Complexity</H2
2768 ><P
2769 >There are many "protocol levels" in the SMB protocol. It seems that
2770 each time new functionality was added to a Microsoft operating system,
2771 they added the equivalent functions in a new protocol level of the SMB
2772 protocol to "externalise" the new capabilities.</P
2773 ><P
2774 >This means the protocol is very "rich", offering many ways of doing
2775 each file operation. This means SMB servers need to be complex and
2776 large. It also means it is very difficult to make them bug free. It is
2777 not just Samba that suffers from this problem, other servers such as
2778 WinNT don't support every variation of every call and it has almost
2779 certainly been a headache for MS developers to support the myriad of
2780 SMB calls that are available.</P
2781 ><P
2782 >There are about 65 "top level" operations in the SMB protocol (things
2783 like SMBread and SMBwrite). Some of these include hundreds of
2784 sub-functions (SMBtrans has at least 120 sub-functions, like
2785 DosPrintQAdd and NetSessionEnum). All of them take several options
2786 that can change the way they work. Many take dozens of possible
2787 "information levels" that change the structures that need to be
2788 returned. Samba supports all but 2 of the "top level" functions. It
2789 supports only 8 (so far) of the SMBtrans sub-functions. Even NT
2790 doesn't support them all.</P
2791 ><P
2792 >Samba currently supports up to the "NT LM 0.12" protocol, which is the
2793 one preferred by Win95 and WinNT3.5. Luckily this protocol level has a
2794 "capabilities" field which specifies which super-duper new-fangled
2795 options the server suports. This helps to make the implementation of
2796 this protocol level much easier.</P
2797 ><P
2798 >There is also a problem with the SMB specications. SMB is a X/Open
2799 spec, but the X/Open book is far from ideal, and fails to cover many
2800 important issues, leaving much to the imagination. Microsoft recently
2801 renamed the SMB protocol CIFS (Common Internet File System) and have 
2802 published new specifications. These are far superior to the old 
2803 X/Open documents but there are still undocumented calls and features. 
2804 This specification is actively being worked on by a CIFS developers 
2805 mailing list hosted by Microsft.</P
2806 ></DIV
2807 ></DIV
2808 ><DIV
2809 CLASS="CHAPTER"
2810 ><HR><H1
2811 ><A
2812 NAME="TRACING"
2813 ></A
2814 >Chapter 8. Tracing samba system calls</H1
2815 ><P
2816 >This file describes how to do a system call trace on Samba to work out
2817 what its doing wrong. This is not for the faint of heart, but if you
2818 are reading this then you are probably desperate.</P
2819 ><P
2820 >Actually its not as bad as the the above makes it sound, just don't
2821 expect the output to be very pretty :-)</P
2822 ><P
2823 >Ok, down to business. One of the big advantages of unix systems is
2824 that they nearly all come with a system trace utility that allows you
2825 to monitor all system calls that a program is making. This is
2826 extremely using for debugging and also helps when trying to work out
2827 why something is slower than you expect. You can use system tracing
2828 without any special compilation options. </P
2829 ><P
2830 >The system trace utility is called different things on different
2831 systems. On Linux systems its called strace. Under SunOS 4 its called
2832 trace. Under SVR4 style systems (including solaris) its called
2833 truss. Under many BSD systems its called ktrace. </P
2834 ><P
2835 >The first thing you should do is read the man page for your native
2836 system call tracer. In the discussion below I'll assume its called
2837 strace as strace is the only portable system tracer (its available for
2838 free for many unix types) and its also got some of the nicest
2839 features.</P
2840 ><P
2841 >Next, try using strace on some simple commands. For example, <B
2842 CLASS="COMMAND"
2843 >strace
2844 ls</B
2845 > or <B
2846 CLASS="COMMAND"
2847 >strace echo hello</B
2848 >.</P
2849 ><P
2850
2851 You'll notice that it produces a LOT of output. It is showing you the
2852 arguments to every system call that the program makes and the
2853 result. Very little happens in a program without a system call so you
2854 get lots of output. You'll also find that it produces a lot of
2855 "preamble" stuff showing the loading of shared libraries etc. Ignore
2856 this (unless its going wrong!)</P
2857 ><P
2858 >For example, the only line that really matters in the <B
2859 CLASS="COMMAND"
2860 >strace echo
2861 hello</B
2862 > output is:</P
2863 ><P
2864 ><PRE
2865 CLASS="PROGRAMLISTING"
2866 >write(1, "hello\n", 6)                  = 6</PRE
2867 ></P
2868 ><P
2869 >all the rest is just setting up to run the program.</P
2870 ><P
2871 >Ok, now you're familiar with strace. To use it on Samba you need to
2872 strace the running smbd daemon. The way I tend ot use it is to first
2873 login from my Windows PC to the Samba server, then use smbstatus to
2874 find which process ID that client is attached to, then as root I do
2875 <B
2876 CLASS="COMMAND"
2877 >strace -p PID</B
2878 > to attach to that process. I normally redirect the
2879 stderr output from this command to a file for later perusal. For
2880 example, if I'm using a csh style shell:</P
2881 ><P
2882 ><B
2883 CLASS="COMMAND"
2884 >strace -f -p 3872 &#62;&#38; strace.out</B
2885 ></P
2886 ><P
2887 >or with a sh style shell:</P
2888 ><P
2889 ><B
2890 CLASS="COMMAND"
2891 >strace -f -p 3872 &#62; strace.out 2&#62;&#38;1</B
2892 ></P
2893 ><P
2894 >Note the "-f" option. This is only available on some systems, and
2895 allows you to trace not just the current process, but any children it
2896 forks. This is great for finding printing problems caused by the
2897 "print command" being wrong.</P
2898 ><P
2899 >Once you are attached you then can do whatever it is on the client
2900 that is causing problems and you will capture all the system calls
2901 that smbd makes. </P
2902 ><P
2903 >So how do you interpret the results? Generally I search through the
2904 output for strings that I know will appear when the problem
2905 happens. For example, if I am having touble with permissions on a file
2906 I would search for that files name in the strace output and look at
2907 the surrounding lines. Another trick is to match up file descriptor
2908 numbers and "follow" what happens to an open file until it is closed.</P
2909 ><P
2910 >Beyond this you will have to use your initiative. To give you an idea
2911 of what you are looking for here is a piece of strace output that
2912 shows that <TT
2913 CLASS="FILENAME"
2914 >/dev/null</TT
2915 > is not world writeable, which
2916 causes printing to fail with Samba:</P
2917 ><P
2918 ><PRE
2919 CLASS="PROGRAMLISTING"
2920 >[pid 28268] open("/dev/null", O_RDWR)   = -1 EACCES (Permission denied)
2921 [pid 28268] open("/dev/null", O_WRONLY) = -1 EACCES (Permission denied)</PRE
2922 ></P
2923 ><P
2924 >The process is trying to first open <TT
2925 CLASS="FILENAME"
2926 >/dev/null</TT
2927 > read-write 
2928 then read-only. Both fail. This means <TT
2929 CLASS="FILENAME"
2930 >/dev/null</TT
2931 > has 
2932 incorrect permissions.</P
2933 ></DIV
2934 ><DIV
2935 CLASS="CHAPTER"
2936 ><HR><H1
2937 ><A
2938 NAME="NTDOMAIN"
2939 ></A
2940 >Chapter 9. NT Domain RPC's</H1
2941 ><DIV
2942 CLASS="SECT1"
2943 ><H2
2944 CLASS="SECT1"
2945 ><A
2946 NAME="AEN652"
2947 ></A
2948 >9.1. Introduction</H2
2949 ><P
2950 >This document contains information to provide an NT workstation with login
2951 services, without the need for an NT server. It is the sgml version of <A
2952 HREF="http://mailhost.cb1.com/~lkcl/cifsntdomain.txt"
2953 TARGET="_top"
2954 >http://mailhost.cb1.com/~lkcl/cifsntdomain.txt</A
2955 >, controlled by Luke.</P
2956 ><P
2957 >It should be possible to select a domain instead of a workgroup (in the NT
2958 workstation's TCP/IP settings) and after the obligatory reboot, type in a
2959 username, password, select a domain and successfully log in.  I would
2960 appreciate any feedback on your experiences with this process, and any
2961 comments, corrections and additions to this document.</P
2962 ><P
2963 >The packets described here can be easily derived from (and are probably
2964 better understood using) Netmon.exe.  You will need to use the version
2965 of Netmon that matches your system, in order to correctly decode the
2966 NETLOGON, lsarpc and srvsvc Transact pipes.  This document is derived from
2967 NT Service Pack 1 and its corresponding version of Netmon.  It is intended
2968 that an annotated packet trace be produced, which will likely be more
2969 instructive than this document.</P
2970 ><P
2971 >Also needed, to fully implement NT Domain Login Services, is the 
2972 document describing the cryptographic part of the NT authentication.
2973 This document is available from comp.protocols.smb; from the ntsecurity.net
2974 digest and from the samba digest, amongst other sources.</P
2975 ><P
2976 >A copy is available from:</P
2977 ><P
2978 ><A
2979 HREF="http://ntbugtraq.rc.on.ca/SCRIPTS/WA.EXE?A2=ind9708;L=ntbugtraq;O=A;P=2935"
2980 TARGET="_top"
2981 >http://ntbugtraq.rc.on.ca/SCRIPTS/WA.EXE?A2=ind9708;L=ntbugtraq;O=A;P=2935</A
2982 ></P
2983 ><P
2984 ><A
2985 HREF="http://mailhost.cb1.com/~lkcl/crypt.html"
2986 TARGET="_top"
2987 >http://mailhost.cb1.com/~lkcl/crypt.html</A
2988 ></P
2989 ><P
2990 >A c-code implementation, provided by <A
2991 HREF="mailto:linus@incolumitas.se"
2992 TARGET="_top"
2993 >Linus Nordberg</A
2994 >
2995 of this protocol is available from:</P
2996 ><P
2997 ><A
2998 HREF="http://samba.org/cgi-bin/mfs/01/digest/1997/97aug/0391.html"
2999 TARGET="_top"
3000 >http://samba.org/cgi-bin/mfs/01/digest/1997/97aug/0391.html</A
3001 ></P
3002 ><P
3003 ><A
3004 HREF="http://mailhost.cb1.com/~lkcl/crypt.txt"
3005 TARGET="_top"
3006 >http://mailhost.cb1.com/~lkcl/crypt.txt</A
3007 ></P
3008 ><P
3009 >Also used to provide debugging information is the Check Build version of
3010 NT workstation, and enabling full debugging in NETLOGON.  This is
3011 achieved by setting the following REG_SZ registry key to 0x1ffffff:</P
3012 ><P
3013 ><TT
3014 CLASS="FILENAME"
3015 >HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters</TT
3016 ></P
3017 ><P
3018 ><SPAN
3019 CLASS="emphasis"
3020 ><I
3021 CLASS="EMPHASIS"
3022 >Incorrect direct editing of the registry can cause your
3023 machine to fail. Then again, so can incorrect implementation of this 
3024 protocol. See "Liability:" above.</I
3025 ></SPAN
3026 ></P
3027 ><P
3028 >Bear in mind that each packet over-the-wire will have its origin in an
3029 API call.  Therefore, there are likely to be structures, enumerations
3030 and defines that are usefully documented elsewhere.</P
3031 ><P
3032 >This document is by no means complete or authoritative.  Missing sections
3033 include, but are not limited to:</P
3034 ><P
3035 ></P
3036 ><OL
3037 TYPE="1"
3038 ><LI
3039 ><P
3040 >Mappings of RIDs to usernames (and vice-versa).</P
3041 ></LI
3042 ><LI
3043 ><P
3044 >What a User ID is and what a Group ID is.</P
3045 ></LI
3046 ><LI
3047 ><P
3048 >The exact meaning/definition of various magic constants or enumerations.</P
3049 ></LI
3050 ><LI
3051 ><P
3052 >The reply error code and use of that error code when a
3053 workstation becomes a member of a domain (to be described later).  
3054 Failure to return this error code will make the workstation report 
3055 that it is already a member of the domain.</P
3056 ></LI
3057 ><LI
3058 ><P
3059 >the cryptographic side of the NetrServerPasswordSet command, 
3060 which would allow the workstation to change its password.  This password is
3061 used to generate the long-term session key.  [It is possible to reject this
3062 command, and keep the default workstation password].</P
3063 ></LI
3064 ></OL
3065 ><DIV
3066 CLASS="SECT2"
3067 ><HR><H3
3068 CLASS="SECT2"
3069 ><A
3070 NAME="AEN688"
3071 ></A
3072 >9.1.1. Sources</H3
3073 ><P
3074 ></P
3075 ><TABLE
3076 BORDER="0"
3077 ><TBODY
3078 ><TR
3079 ><TD
3080 >cket Traces from Netmonitor (Service Pack 1 and above)</TD
3081 ></TR
3082 ><TR
3083 ><TD
3084 >ul Ashton and Luke Leighton's other "NT Domain" doc.</TD
3085 ></TR
3086 ><TR
3087 ><TD
3088 >FS documentation - cifs6.txt</TD
3089 ></TR
3090 ><TR
3091 ><TD
3092 >FS documentation - cifsrap2.txt</TD
3093 ></TR
3094 ></TBODY
3095 ></TABLE
3096 ><P
3097 ></P
3098 ></DIV
3099 ><DIV
3100 CLASS="SECT2"
3101 ><HR><H3
3102 CLASS="SECT2"
3103 ><A
3104 NAME="AEN695"
3105 ></A
3106 >9.1.2. Credits</H3
3107 ><P
3108 ></P
3109 ><TABLE
3110 BORDER="0"
3111 ><TBODY
3112 ><TR
3113 ><TD
3114 >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
3115 ></TR
3116 ><TR
3117 ><TD
3118 >Duncan Stansfield: low-level analysis of MSRPC Pipes.</TD
3119 ></TR
3120 ><TR
3121 ><TD
3122 >Linus Nordberg: producing c-code from Paul's crypto spec.</TD
3123 ></TR
3124 ><TR
3125 ><TD
3126 >Windows Sourcer development team</TD
3127 ></TR
3128 ></TBODY
3129 ></TABLE
3130 ><P
3131 ></P
3132 ></DIV
3133 ></DIV
3134 ><DIV
3135 CLASS="SECT1"
3136 ><HR><H2
3137 CLASS="SECT1"
3138 ><A
3139 NAME="AEN702"
3140 ></A
3141 >9.2. Notes and Structures</H2
3142 ><DIV
3143 CLASS="SECT2"
3144 ><H3
3145 CLASS="SECT2"
3146 ><A
3147 NAME="AEN704"
3148 ></A
3149 >9.2.1. Notes</H3
3150 ><P
3151 ></P
3152 ><OL
3153 TYPE="1"
3154 ><LI
3155 ><P
3156 >In the SMB Transact pipes, some "Structures", described here, appear to be
3157 4-byte aligned with the SMB header, at their start.  Exactly which
3158 "Structures" need aligning is not precisely known or documented.</P
3159 ></LI
3160 ><LI
3161 ><P
3162 >In the UDP NTLOGON Mailslots, some "Structures", described here, appear to be
3163 2-byte aligned with the start of the mailslot, at their start.</P
3164 ></LI
3165 ><LI
3166 ><P
3167 >Domain SID is of the format S-revision-version-auth1-auth2...authN.
3168 e.g S-1-5-123-456-789-123-456.  the 5 could be a sub-revision.</P
3169 ></LI
3170 ><LI
3171 ><P
3172 >any undocumented buffer pointers must be non-zero if the string buffer it
3173 refers to contains characters.  exactly what value they should be is unknown.
3174 0x0000 0002 seems to do the trick to indicate that the buffer exists.  a
3175 NULL buffer pointer indicates that the string buffer is of zero length.
3176 If the buffer pointer is NULL, then it is suspected that the structure it
3177 refers to is NOT put into (or taken out of) the SMB data stream.  This is
3178 empirically derived from, for example, the LSA SAM Logon response packet,
3179 where if the buffer pointer is NULL, the user information is not inserted
3180 into the data stream.  Exactly what happens with an array of buffer pointers
3181 is not known, although an educated guess can be made.</P
3182 ></LI
3183 ><LI
3184 ><P
3185 >an array of structures (a container) appears to have a count and a pointer.
3186 if the count is zero, the pointer is also zero.  no further data is put
3187 into or taken out of the SMB data stream.  if the count is non-zero, then
3188 the pointer is also non-zero.  immediately following the pointer is the
3189 count again, followed by an array of container sub-structures.  the count
3190 appears a third time after the last sub-structure.</P
3191 ></LI
3192 ></OL
3193 ></DIV
3194 ><DIV
3195 CLASS="SECT2"
3196 ><HR><H3
3197 CLASS="SECT2"
3198 ><A
3199 NAME="AEN717"
3200 ></A
3201 >9.2.2. Enumerations</H3
3202 ><DIV
3203 CLASS="SECT3"
3204 ><H4
3205 CLASS="SECT3"
3206 ><A
3207 NAME="AEN719"
3208 ></A
3209 >9.2.2.1. MSRPC Header type</H4
3210 ><P
3211 >command number in the msrpc packet header</P
3212 ><P
3213 ></P
3214 ><DIV
3215 CLASS="VARIABLELIST"
3216 ><DL
3217 ><DT
3218 >MSRPC_Request:</DT
3219 ><DD
3220 ><P
3221 >0x00</P
3222 ></DD
3223 ><DT
3224 >MSRPC_Response:</DT
3225 ><DD
3226 ><P
3227 >0x02</P
3228 ></DD
3229 ><DT
3230 >MSRPC_Bind:</DT
3231 ><DD
3232 ><P
3233 >0x0B</P
3234 ></DD
3235 ><DT
3236 >MSRPC_BindAck:</DT
3237 ><DD
3238 ><P
3239 >0x0C</P
3240 ></DD
3241 ></DL
3242 ></DIV
3243 ></DIV
3244 ><DIV
3245 CLASS="SECT3"
3246 ><HR><H4
3247 CLASS="SECT3"
3248 ><A
3249 NAME="AEN739"
3250 ></A
3251 >9.2.2.2. MSRPC Packet info</H4
3252 ><P
3253 >The meaning of these flags is undocumented</P
3254 ><P
3255 ></P
3256 ><DIV
3257 CLASS="VARIABLELIST"
3258 ><DL
3259 ><DT
3260 >FirstFrag:</DT
3261 ><DD
3262 ><P
3263 >0x01 </P
3264 ></DD
3265 ><DT
3266 >LastFrag:</DT
3267 ><DD
3268 ><P
3269 >0x02 </P
3270 ></DD
3271 ><DT
3272 >NotaFrag:</DT
3273 ><DD
3274 ><P
3275 >0x04  </P
3276 ></DD
3277 ><DT
3278 >RecRespond:</DT
3279 ><DD
3280 ><P
3281 >0x08  </P
3282 ></DD
3283 ><DT
3284 >NoMultiplex:</DT
3285 ><DD
3286 ><P
3287 >0x10  </P
3288 ></DD
3289 ><DT
3290 >NotForIdemp:</DT
3291 ><DD
3292 ><P
3293 >0x20  </P
3294 ></DD
3295 ><DT
3296 >NotforBcast:</DT
3297 ><DD
3298 ><P
3299 >0x40  </P
3300 ></DD
3301 ><DT
3302 >NoUuid:</DT
3303 ><DD
3304 ><P
3305 >0x80 </P
3306 ></DD
3307 ></DL
3308 ></DIV
3309 ></DIV
3310 ></DIV
3311 ><DIV
3312 CLASS="SECT2"
3313 ><HR><H3
3314 CLASS="SECT2"
3315 ><A
3316 NAME="AEN775"
3317 ></A
3318 >9.2.3. Structures</H3
3319 ><DIV
3320 CLASS="SECT3"
3321 ><H4
3322 CLASS="SECT3"
3323 ><A
3324 NAME="AEN777"
3325 ></A
3326 >9.2.3.1. VOID *</H4
3327 ><P
3328 >sizeof VOID* is 32 bits.</P
3329 ></DIV
3330 ><DIV
3331 CLASS="SECT3"
3332 ><HR><H4
3333 CLASS="SECT3"
3334 ><A
3335 NAME="AEN780"
3336 ></A
3337 >9.2.3.2. char</H4
3338 ><P
3339 >sizeof char is 8 bits.</P
3340 ></DIV
3341 ><DIV
3342 CLASS="SECT3"
3343 ><HR><H4
3344 CLASS="SECT3"
3345 ><A
3346 NAME="AEN783"
3347 ></A
3348 >9.2.3.3. UTIME</H4
3349 ><P
3350 >UTIME is 32 bits, indicating time in seconds since 01jan1970.  documented in cifs6.txt (section 3.5 page, page 30).</P
3351 ></DIV
3352 ><DIV
3353 CLASS="SECT3"
3354 ><HR><H4
3355 CLASS="SECT3"
3356 ><A
3357 NAME="AEN786"
3358 ></A
3359 >9.2.3.4. NTTIME</H4
3360 ><P
3361 >NTTIME is 64 bits.  documented in cifs6.txt (section 3.5 page, page 30).</P
3362 ></DIV
3363 ><DIV
3364 CLASS="SECT3"
3365 ><HR><H4
3366 CLASS="SECT3"
3367 ><A
3368 NAME="AEN789"
3369 ></A
3370 >9.2.3.5. DOM_SID (domain SID structure)</H4
3371 ><P
3372 ></P
3373 ><DIV
3374 CLASS="VARIABLELIST"
3375 ><DL
3376 ><DT
3377 >UINT32</DT
3378 ><DD
3379 ><P
3380 >num of sub-authorities in domain SID</P
3381 ></DD
3382 ><DT
3383 >UINT8</DT
3384 ><DD
3385 ><P
3386 >SID revision number</P
3387 ></DD
3388 ><DT
3389 >UINT8</DT
3390 ><DD
3391 ><P
3392 >num of sub-authorities in domain SID</P
3393 ></DD
3394 ><DT
3395 >UINT8[6]</DT
3396 ><DD
3397 ><P
3398 >6 bytes for domain SID - Identifier Authority.</P
3399 ></DD
3400 ><DT
3401 >UINT16[n_subauths]</DT
3402 ><DD
3403 ><P
3404 >domain SID sub-authorities</P
3405 ></DD
3406 ></DL
3407 ></DIV
3408 ><P
3409 ><SPAN
3410 CLASS="emphasis"
3411 ><I
3412 CLASS="EMPHASIS"
3413 >Note: the domain SID is documented elsewhere.</I
3414 ></SPAN
3415 ></P
3416 ></DIV
3417 ><DIV
3418 CLASS="SECT3"
3419 ><HR><H4
3420 CLASS="SECT3"
3421 ><A
3422 NAME="AEN814"
3423 ></A
3424 >9.2.3.6. STR (string)</H4
3425 ><P
3426 >STR (string) is a char[] : a null-terminated string of ascii characters.</P
3427 ></DIV
3428 ><DIV
3429 CLASS="SECT3"
3430 ><HR><H4
3431 CLASS="SECT3"
3432 ><A
3433 NAME="AEN817"
3434 ></A
3435 >9.2.3.7. UNIHDR (unicode string header)</H4
3436 ><P
3437 ></P
3438 ><DIV
3439 CLASS="VARIABLELIST"
3440 ><DL
3441 ><DT
3442 >UINT16</DT
3443 ><DD
3444 ><P
3445 >length of unicode string</P
3446 ></DD
3447 ><DT
3448 >UINT16</DT
3449 ><DD
3450 ><P
3451 >max length of unicode string</P
3452 ></DD
3453 ><DT
3454 >UINT32</DT
3455 ><DD
3456 ><P
3457 >4 - undocumented.</P
3458 ></DD
3459 ></DL
3460 ></DIV
3461 ></DIV
3462 ><DIV
3463 CLASS="SECT3"
3464 ><HR><H4
3465 CLASS="SECT3"
3466 ><A
3467 NAME="AEN832"
3468 ></A
3469 >9.2.3.8. UNIHDR2 (unicode string header plus buffer pointer)</H4
3470 ><P
3471 ></P
3472 ><DIV
3473 CLASS="VARIABLELIST"
3474 ><DL
3475 ><DT
3476 >UNIHDR</DT
3477 ><DD
3478 ><P
3479 >unicode string header</P
3480 ></DD
3481 ><DT
3482 >VOID*</DT
3483 ><DD
3484 ><P
3485 >undocumented buffer pointer</P
3486 ></DD
3487 ></DL
3488 ></DIV
3489 ></DIV
3490 ><DIV
3491 CLASS="SECT3"
3492 ><HR><H4
3493 CLASS="SECT3"
3494 ><A
3495 NAME="AEN843"
3496 ></A
3497 >9.2.3.9. UNISTR (unicode string)</H4
3498 ><P
3499 ></P
3500 ><DIV
3501 CLASS="VARIABLELIST"
3502 ><DL
3503 ><DT
3504 >UINT16[]</DT
3505 ><DD
3506 ><P
3507 >null-terminated string of unicode characters.</P
3508 ></DD
3509 ></DL
3510 ></DIV
3511 ></DIV
3512 ><DIV
3513 CLASS="SECT3"
3514 ><HR><H4
3515 CLASS="SECT3"
3516 ><A
3517 NAME="AEN850"
3518 ></A
3519 >9.2.3.10. NAME (length-indicated unicode string)</H4
3520 ><P
3521 ></P
3522 ><DIV
3523 CLASS="VARIABLELIST"
3524 ><DL
3525 ><DT
3526 >UINT32</DT
3527 ><DD
3528 ><P
3529 >length of unicode string</P
3530 ></DD
3531 ><DT
3532 >UINT16[]</DT
3533 ><DD
3534 ><P
3535 >null-terminated string of unicode characters.</P
3536 ></DD
3537 ></DL
3538 ></DIV
3539 ></DIV
3540 ><DIV
3541 CLASS="SECT3"
3542 ><HR><H4
3543 CLASS="SECT3"
3544 ><A
3545 NAME="AEN861"
3546 ></A
3547 >9.2.3.11. UNISTR2 (aligned unicode string)</H4
3548 ><P
3549 ></P
3550 ><DIV
3551 CLASS="VARIABLELIST"
3552 ><DL
3553 ><DT
3554 >UINT8[]</DT
3555 ><DD
3556 ><P
3557 >padding to get unicode string 4-byte aligned with the start of the SMB header.</P
3558 ></DD
3559 ><DT
3560 >UINT32</DT
3561 ><DD
3562 ><P
3563 >max length of unicode string</P
3564 ></DD
3565 ><DT
3566 >UINT32</DT
3567 ><DD
3568 ><P
3569 >0 - undocumented</P
3570 ></DD
3571 ><DT
3572 >UINT32</DT
3573 ><DD
3574 ><P
3575 >length of unicode string</P
3576 ></DD
3577 ><DT
3578 >UINT16[]</DT
3579 ><DD
3580 ><P
3581 >string of uncode characters</P
3582 ></DD
3583 ></DL
3584 ></DIV
3585 ></DIV
3586 ><DIV
3587 CLASS="SECT3"
3588 ><HR><H4
3589 CLASS="SECT3"
3590 ><A
3591 NAME="AEN884"
3592 ></A
3593 >9.2.3.12. OBJ_ATTR (object attributes)</H4
3594 ><P
3595 ></P
3596 ><DIV
3597 CLASS="VARIABLELIST"
3598 ><DL
3599 ><DT
3600 >UINT32</DT
3601 ><DD
3602 ><P
3603 >0x18 - length (in bytes) including the length field.</P
3604 ></DD
3605 ><DT
3606 >VOID*</DT
3607 ><DD
3608 ><P
3609 >0 - root directory (pointer)</P
3610 ></DD
3611 ><DT
3612 >VOID*</DT
3613 ><DD
3614 ><P
3615 >0 - object name (pointer)</P
3616 ></DD
3617 ><DT
3618 >UINT32</DT
3619 ><DD
3620 ><P
3621 >0 - attributes (undocumented)</P
3622 ></DD
3623 ><DT
3624 >VOID*</DT
3625 ><DD
3626 ><P
3627 >0 - security descriptior (pointer)</P
3628 ></DD
3629 ><DT
3630 >UINT32</DT
3631 ><DD
3632 ><P
3633 >0 - security quality of service</P
3634 ></DD
3635 ></DL
3636 ></DIV
3637 ></DIV
3638 ><DIV
3639 CLASS="SECT3"
3640 ><HR><H4
3641 CLASS="SECT3"
3642 ><A
3643 NAME="AEN911"
3644 ></A
3645 >9.2.3.13. POL_HND (LSA policy handle)</H4
3646 ><P
3647 ></P
3648 ><DIV
3649 CLASS="VARIABLELIST"
3650 ><DL
3651 ><DT
3652 >char[20]</DT
3653 ><DD
3654 ><P
3655 >policy handle</P
3656 ></DD
3657 ></DL
3658 ></DIV
3659 ></DIV
3660 ><DIV
3661 CLASS="SECT3"
3662 ><HR><H4
3663 CLASS="SECT3"
3664 ><A
3665 NAME="AEN918"
3666 ></A
3667 >9.2.3.14. DOM_SID2 (domain SID structure, SIDS stored in unicode)</H4
3668 ><P
3669 ></P
3670 ><DIV
3671 CLASS="VARIABLELIST"
3672 ><DL
3673 ><DT
3674 >UINT32</DT
3675 ><DD
3676 ><P
3677 >5 - SID type</P
3678 ></DD
3679 ><DT
3680 >UINT32</DT
3681 ><DD
3682 ><P
3683 >0 - undocumented</P
3684 ></DD
3685 ><DT
3686 >UNIHDR2</DT
3687 ><DD
3688 ><P
3689 >domain SID unicode string header</P
3690 ></DD
3691 ><DT
3692 >UNISTR</DT
3693 ><DD
3694 ><P
3695 >domain SID unicode string</P
3696 ></DD
3697 ></DL
3698 ></DIV
3699 ><P
3700 ><SPAN
3701 CLASS="emphasis"
3702 ><I
3703 CLASS="EMPHASIS"
3704 >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
3705 ></SPAN
3706 ></P
3707 ><P
3708 ><SPAN
3709 CLASS="emphasis"
3710 ><I
3711 CLASS="EMPHASIS"
3712 >Note:  the SID type indicates, for example, an alias; a well-known group etc. this is documented somewhere.</I
3713 ></SPAN
3714 ></P
3715 ></DIV
3716 ><DIV
3717 CLASS="SECT3"
3718 ><HR><H4
3719 CLASS="SECT3"
3720 ><A
3721 NAME="AEN941"
3722 ></A
3723 >9.2.3.15. DOM_RID (domain RID structure)</H4
3724 ><P
3725 ></P
3726 ><DIV
3727 CLASS="VARIABLELIST"
3728 ><DL
3729 ><DT
3730 >UINT32</DT
3731 ><DD
3732 ><P
3733 >5 - well-known SID.  1 - user SID (see ShowACLs)</P
3734 ></DD
3735 ><DT
3736 >UINT32</DT
3737 ><DD
3738 ><P
3739 >5 - undocumented</P
3740 ></DD
3741 ><DT
3742 >UINT32</DT
3743 ><DD
3744 ><P
3745 >domain RID </P
3746 ></DD
3747 ><DT
3748 >UINT32</DT
3749 ><DD
3750 ><P
3751 >0 - domain index out of above reference domains</P
3752 ></DD
3753 ></DL
3754 ></DIV
3755 ></DIV
3756 ><DIV
3757 CLASS="SECT3"
3758 ><HR><H4
3759 CLASS="SECT3"
3760 ><A
3761 NAME="AEN960"
3762 ></A
3763 >9.2.3.16. LOG_INFO (server, account, client structure)</H4
3764 ><P
3765 ><SPAN
3766 CLASS="emphasis"
3767 ><I
3768 CLASS="EMPHASIS"
3769 >Note:  logon server name starts with two '\' characters and is upper case.</I
3770 ></SPAN
3771 ></P
3772 ><P
3773 ><SPAN
3774 CLASS="emphasis"
3775 ><I
3776 CLASS="EMPHASIS"
3777 >Note:  account name is the logon client name from the LSA Request Challenge, with a $ on the end of it, in upper case.</I
3778 ></SPAN
3779 ></P
3780 ><P
3781 ></P
3782 ><DIV
3783 CLASS="VARIABLELIST"
3784 ><DL
3785 ><DT
3786 >VOID*</DT
3787 ><DD
3788 ><P
3789 >undocumented buffer pointer</P
3790 ></DD
3791 ><DT
3792 >UNISTR2</DT
3793 ><DD
3794 ><P
3795 >logon server unicode string</P
3796 ></DD
3797 ><DT
3798 >UNISTR2</DT
3799 ><DD
3800 ><P
3801 >account name unicode string</P
3802 ></DD
3803 ><DT
3804 >UINT16</DT
3805 ><DD
3806 ><P
3807 >sec_chan - security channel type</P
3808 ></DD
3809 ><DT
3810 >UNISTR2</DT
3811 ><DD
3812 ><P
3813 >logon client machine unicode string</P
3814 ></DD
3815 ></DL
3816 ></DIV
3817 ></DIV
3818 ><DIV
3819 CLASS="SECT3"
3820 ><HR><H4
3821 CLASS="SECT3"
3822 ><A
3823 NAME="AEN987"
3824 ></A
3825 >9.2.3.17. CLNT_SRV (server, client names structure)</H4
3826 ><P
3827 ><SPAN
3828 CLASS="emphasis"
3829 ><I
3830 CLASS="EMPHASIS"
3831 >Note:  logon server name starts with two '\' characters and is upper case.</I
3832 ></SPAN
3833 ></P
3834 ><P
3835 ></P
3836 ><DIV
3837 CLASS="VARIABLELIST"
3838 ><DL
3839 ><DT
3840 >VOID*</DT
3841 ><DD
3842 ><P
3843 >undocumented buffer pointer</P
3844 ></DD
3845 ><DT
3846 >UNISTR2</DT
3847 ><DD
3848 ><P
3849 >logon server unicode string</P
3850 ></DD
3851 ><DT
3852 >VOID*</DT
3853 ><DD
3854 ><P
3855 >undocumented buffer pointer</P
3856 ></DD
3857 ><DT
3858 >UNISTR2</DT
3859 ><DD
3860 ><P
3861 >logon client machine unicode string</P
3862 ></DD
3863 ></DL
3864 ></DIV
3865 ></DIV
3866 ><DIV
3867 CLASS="SECT3"
3868 ><HR><H4
3869 CLASS="SECT3"
3870 ><A
3871 NAME="AEN1008"
3872 ></A
3873 >9.2.3.18. CREDS (credentials + time stamp)</H4
3874 ><P
3875 ></P
3876 ><DIV
3877 CLASS="VARIABLELIST"
3878 ><DL
3879 ><DT
3880 >char[8]</DT
3881 ><DD
3882 ><P
3883 >credentials</P
3884 ></DD
3885 ><DT
3886 >UTIME</DT
3887 ><DD
3888 ><P
3889 >time stamp</P
3890 ></DD
3891 ></DL
3892 ></DIV
3893 ></DIV
3894 ><DIV
3895 CLASS="SECT3"
3896 ><HR><H4
3897 CLASS="SECT3"
3898 ><A
3899 NAME="AEN1019"
3900 ></A
3901 >9.2.3.19. CLNT_INFO2 (server, client structure, client credentials)</H4
3902 ><P
3903 ><SPAN
3904 CLASS="emphasis"
3905 ><I
3906 CLASS="EMPHASIS"
3907 >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
3908         maintain an authenticated request/response trail.</I
3909 ></SPAN
3910 ></P
3911 ><P
3912 ></P
3913 ><DIV
3914 CLASS="VARIABLELIST"
3915 ><DL
3916 ><DT
3917 >CLNT_SRV</DT
3918 ><DD
3919 ><P
3920 >client and server names</P
3921 ></DD
3922 ><DT
3923 >UINT8[]</DT
3924 ><DD
3925 ><P
3926 >???? padding, for 4-byte alignment with SMB header.</P
3927 ></DD
3928 ><DT
3929 >VOID*</DT
3930 ><DD
3931 ><P
3932 >pointer to client credentials.</P
3933 ></DD
3934 ><DT
3935 >CREDS</DT
3936 ><DD
3937 ><P
3938 >client-calculated credentials + client time</P
3939 ></DD
3940 ></DL
3941 ></DIV
3942 ></DIV
3943 ><DIV
3944 CLASS="SECT3"
3945 ><HR><H4
3946 CLASS="SECT3"
3947 ><A
3948 NAME="AEN1040"
3949 ></A
3950 >9.2.3.20. CLNT_INFO (server, account, client structure, client credentials)</H4
3951 ><P
3952 ><SPAN
3953 CLASS="emphasis"
3954 ><I
3955 CLASS="EMPHASIS"
3956 >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
3957 ></SPAN
3958 ></P
3959 ><P
3960 ></P
3961 ><DIV
3962 CLASS="VARIABLELIST"
3963 ><DL
3964 ><DT
3965 >LOG_INFO</DT
3966 ><DD
3967 ><P
3968 >logon account info</P
3969 ></DD
3970 ><DT
3971 >CREDS</DT
3972 ><DD
3973 ><P
3974 >client-calculated credentials + client time</P
3975 ></DD
3976 ></DL
3977 ></DIV
3978 ></DIV
3979 ><DIV
3980 CLASS="SECT3"
3981 ><HR><H4
3982 CLASS="SECT3"
3983 ><A
3984 NAME="AEN1053"
3985 ></A
3986 >9.2.3.21. ID_INFO_1 (id info structure, auth level 1)</H4
3987 ><P
3988 ></P
3989 ><DIV
3990 CLASS="VARIABLELIST"
3991 ><DL
3992 ><DT
3993 >VOID*</DT
3994 ><DD
3995 ><P
3996 >ptr_id_info_1</P
3997 ></DD
3998 ><DT
3999 >UNIHDR</DT
4000 ><DD
4001 ><P
4002 >domain name unicode header</P
4003 ></DD
4004 ><DT
4005 >UINT32</DT
4006 ><DD
4007 ><P
4008 >param control</P
4009 ></DD
4010 ><DT
4011 >UINT64</DT
4012 ><DD
4013 ><P
4014 >logon ID</P
4015 ></DD
4016 ><DT
4017 >UNIHDR</DT
4018 ><DD
4019 ><P
4020 >user name unicode header</P
4021 ></DD
4022 ><DT
4023 >UNIHDR</DT
4024 ><DD
4025 ><P
4026 >workgroup name unicode header</P
4027 ></DD
4028 ><DT
4029 >char[16]</DT
4030 ><DD
4031 ><P
4032 >arc4 LM OWF Password</P
4033 ></DD
4034 ><DT
4035 >char[16]</DT
4036 ><DD
4037 ><P
4038 >arc4 NT OWF Password</P
4039 ></DD
4040 ><DT
4041 >UNISTR2</DT
4042 ><DD
4043 ><P
4044 >domain name unicode string</P
4045 ></DD
4046 ><DT
4047 >UNISTR2</DT
4048 ><DD
4049 ><P
4050 >user name unicode string</P
4051 ></DD
4052 ><DT
4053 >UNISTR2</DT
4054 ><DD
4055 ><P
4056 >workstation name unicode string</P
4057 ></DD
4058 ></DL
4059 ></DIV
4060 ></DIV
4061 ><DIV
4062 CLASS="SECT3"
4063 ><HR><H4
4064 CLASS="SECT3"
4065 ><A
4066 NAME="AEN1100"
4067 ></A
4068 >9.2.3.22. SAM_INFO (sam logon/logoff id info structure)</H4
4069 ><P
4070 ><SPAN
4071 CLASS="emphasis"
4072 ><I
4073 CLASS="EMPHASIS"
4074 >Note: presumably, the return credentials is supposedly for the server to verify that the credential chain hasn't been compromised.</I
4075 ></SPAN
4076 ></P
4077 ><P
4078 ></P
4079 ><DIV
4080 CLASS="VARIABLELIST"
4081 ><DL
4082 ><DT
4083 >CLNT_INFO2</DT
4084 ><DD
4085 ><P
4086 >client identification/authentication info</P
4087 ></DD
4088 ><DT
4089 >VOID*</DT
4090 ><DD
4091 ><P
4092 >pointer to return credentials.</P
4093 ></DD
4094 ><DT
4095 >CRED</DT
4096 ><DD
4097 ><P
4098 >return credentials - ignored.</P
4099 ></DD
4100 ><DT
4101 >UINT16</DT
4102 ><DD
4103 ><P
4104 >logon level</P
4105 ></DD
4106 ><DT
4107 >UINT16</DT
4108 ><DD
4109 ><P
4110 >switch value</P
4111 ></DD
4112 ></DL
4113 ></DIV
4114 ><P
4115 ><PRE
4116 CLASS="PROGRAMLISTING"
4117 >        switch (switch_value)
4118         case 1:
4119         {
4120             ID_INFO_1     id_info_1;
4121         }</PRE
4122 ></P
4123 ></DIV
4124 ><DIV
4125 CLASS="SECT3"
4126 ><HR><H4
4127 CLASS="SECT3"
4128 ><A
4129 NAME="AEN1127"
4130 ></A
4131 >9.2.3.23. GID (group id info)</H4
4132 ><P
4133 ></P
4134 ><DIV
4135 CLASS="VARIABLELIST"
4136 ><DL
4137 ><DT
4138 >UINT32</DT
4139 ><DD
4140 ><P
4141 >group id</P
4142 ></DD
4143 ><DT
4144 >UINT32</DT
4145 ><DD
4146 ><P
4147 >user attributes (only used by NT 3.1 and 3.51)</P
4148 ></DD
4149 ></DL
4150 ></DIV
4151 ></DIV
4152 ><DIV
4153 CLASS="SECT3"
4154 ><HR><H4
4155 CLASS="SECT3"
4156 ><A
4157 NAME="AEN1138"
4158 ></A
4159 >9.2.3.24. DOM_REF (domain reference info)</H4
4160 ><P
4161 ></P
4162 ><DIV
4163 CLASS="VARIABLELIST"
4164 ><DL
4165 ><DT
4166 >VOID*</DT
4167 ><DD
4168 ><P
4169 >undocumented buffer pointer.</P
4170 ></DD
4171 ><DT
4172 >UINT32</DT
4173 ><DD
4174 ><P
4175 >num referenced domains?</P
4176 ></DD
4177 ><DT
4178 >VOID*</DT
4179 ><DD
4180 ><P
4181 >undocumented domain name buffer pointer.</P
4182 ></DD
4183 ><DT
4184 >UINT32</DT
4185 ><DD
4186 ><P
4187 >32 - max number of entries</P
4188 ></DD
4189 ><DT
4190 >UINT32</DT
4191 ><DD
4192 ><P
4193 >4 - num referenced domains?</P
4194 ></DD
4195 ><DT
4196 >UNIHDR2</DT
4197 ><DD
4198 ><P
4199 >domain name unicode string header</P
4200 ></DD
4201 ><DT
4202 >UNIHDR2[num_ref_doms-1]</DT
4203 ><DD
4204 ><P
4205 >referenced domain unicode string headers</P
4206 ></DD
4207 ><DT
4208 >UNISTR</DT
4209 ><DD
4210 ><P
4211 >domain name unicode string</P
4212 ></DD
4213 ><DT
4214 >DOM_SID[num_ref_doms]</DT
4215 ><DD
4216 ><P
4217 >referenced domain SIDs</P
4218 ></DD
4219 ></DL
4220 ></DIV
4221 ></DIV
4222 ><DIV
4223 CLASS="SECT3"
4224 ><HR><H4
4225 CLASS="SECT3"
4226 ><A
4227 NAME="AEN1177"
4228 ></A
4229 >9.2.3.25. DOM_INFO (domain info, levels 3 and 5 are the same))</H4
4230 ><P
4231 ></P
4232 ><DIV
4233 CLASS="VARIABLELIST"
4234 ><DL
4235 ><DT
4236 >UINT8[]</DT
4237 ><DD
4238 ><P
4239 >??? padding to get 4-byte alignment with start of SMB header</P
4240 ></DD
4241 ><DT
4242 >UINT16</DT
4243 ><DD
4244 ><P
4245 >domain name string length * 2</P
4246 ></DD
4247 ><DT
4248 >UINT16</DT
4249 ><DD
4250 ><P
4251 >domain name string length * 2</P
4252 ></DD
4253 ><DT
4254 >VOID*</DT
4255 ><DD
4256 ><P
4257 >undocumented domain name string buffer pointer</P
4258 ></DD
4259 ><DT
4260 >VOID*</DT
4261 ><DD
4262 ><P
4263 >undocumented domain SID string buffer pointer</P
4264 ></DD
4265 ><DT
4266 >UNISTR2</DT
4267 ><DD
4268 ><P
4269 >domain name (unicode string)</P
4270 ></DD
4271 ><DT
4272 >DOM_SID</DT
4273 ><DD
4274 ><P
4275 >domain SID</P
4276 ></DD
4277 ></DL
4278 ></DIV
4279 ></DIV
4280 ><DIV
4281 CLASS="SECT3"
4282 ><HR><H4
4283 CLASS="SECT3"
4284 ><A
4285 NAME="AEN1208"
4286 ></A
4287 >9.2.3.26. USER_INFO (user logon info)</H4
4288 ><P
4289 ><SPAN
4290 CLASS="emphasis"
4291 ><I
4292 CLASS="EMPHASIS"
4293 >Note: it would be nice to know what the 16 byte user session key is for.</I
4294 ></SPAN
4295 ></P
4296 ><P
4297 ></P
4298 ><DIV
4299 CLASS="VARIABLELIST"
4300 ><DL
4301 ><DT
4302 >NTTIME</DT
4303 ><DD
4304 ><P
4305 >logon time</P
4306 ></DD
4307 ><DT
4308 >NTTIME</DT
4309 ><DD
4310 ><P
4311 >logoff time</P
4312 ></DD
4313 ><DT
4314 >NTTIME</DT
4315 ><DD
4316 ><P
4317 >kickoff time</P
4318 ></DD
4319 ><DT
4320 >NTTIME</DT
4321 ><DD
4322 ><P
4323 >password last set time</P
4324 ></DD
4325 ><DT
4326 >NTTIME</DT
4327 ><DD
4328 ><P
4329 >password can change time</P
4330 ></DD
4331 ><DT
4332 >NTTIME</DT
4333 ><DD
4334 ><P
4335 >password must change time</P
4336 ></DD
4337 ><DT
4338 >UNIHDR</DT
4339 ><DD
4340 ><P
4341 >username unicode string header</P
4342 ></DD
4343 ><DT
4344 >UNIHDR</DT
4345 ><DD
4346 ><P
4347 >user's full name unicode string header</P
4348 ></DD
4349 ><DT
4350 >UNIHDR</DT
4351 ><DD
4352 ><P
4353 >logon script unicode string header</P
4354 ></DD
4355 ><DT
4356 >UNIHDR</DT
4357 ><DD
4358 ><P
4359 >profile path unicode string header</P
4360 ></DD
4361 ><DT
4362 >UNIHDR</DT
4363 ><DD
4364 ><P
4365 >home directory unicode string header</P
4366 ></DD
4367 ><DT
4368 >UNIHDR</DT
4369 ><DD
4370 ><P
4371 >home directory drive unicode string header</P
4372 ></DD
4373 ><DT
4374 >UINT16</DT
4375 ><DD
4376 ><P
4377 >logon count</P
4378 ></DD
4379 ><DT
4380 >UINT16</DT
4381 ><DD
4382 ><P
4383 >bad password count</P
4384 ></DD
4385 ><DT
4386 >UINT32</DT
4387 ><DD
4388 ><P
4389 >User ID</P
4390 ></DD
4391 ><DT
4392 >UINT32</DT
4393 ><DD
4394 ><P
4395 >Group ID</P
4396 ></DD
4397 ><DT
4398 >UINT32</DT
4399 ><DD
4400 ><P
4401 >num groups</P
4402 ></DD
4403 ><DT
4404 >VOID*</DT
4405 ><DD
4406 ><P
4407 >undocumented buffer pointer to groups.</P
4408 ></DD
4409 ><DT
4410 >UINT32</DT
4411 ><DD
4412 ><P
4413 >user flags</P
4414 ></DD
4415 ><DT
4416 >char[16]</DT
4417 ><DD
4418 ><P
4419 >user session key</P
4420 ></DD
4421 ><DT
4422 >UNIHDR</DT
4423 ><DD
4424 ><P
4425 >logon server unicode string header</P
4426 ></DD
4427 ><DT
4428 >UNIHDR</DT
4429 ><DD
4430 ><P
4431 >logon domain unicode string header</P
4432 ></DD
4433 ><DT
4434 >VOID*</DT
4435 ><DD
4436 ><P
4437 >undocumented logon domain id pointer</P
4438 ></DD
4439 ><DT
4440 >char[40]</DT
4441 ><DD
4442 ><P
4443 >40 undocumented padding bytes.  future expansion?</P
4444 ></DD
4445 ><DT
4446 >UINT32</DT
4447 ><DD
4448 ><P
4449 >0 - num_other_sids?</P
4450 ></DD
4451 ><DT
4452 >VOID*</DT
4453 ><DD
4454 ><P
4455 >NULL - undocumented pointer to other domain SIDs.</P
4456 ></DD
4457 ><DT
4458 >UNISTR2</DT
4459 ><DD
4460 ><P
4461 >username unicode string</P
4462 ></DD
4463 ><DT
4464 >UNISTR2</DT
4465 ><DD
4466 ><P
4467 >user's full name unicode string</P
4468 ></DD
4469 ><DT
4470 >UNISTR2</DT
4471 ><DD
4472 ><P
4473 >logon script unicode string</P
4474 ></DD
4475 ><DT
4476 >UNISTR2</DT
4477 ><DD
4478 ><P
4479 >profile path unicode string</P
4480 ></DD
4481 ><DT
4482 >UNISTR2</DT
4483 ><DD
4484 ><P
4485 >home directory unicode string</P
4486 ></DD
4487 ><DT
4488 >UNISTR2</DT
4489 ><DD
4490 ><P
4491 >home directory drive unicode string</P
4492 ></DD
4493 ><DT
4494 >UINT32</DT
4495 ><DD
4496 ><P
4497 >num groups</P
4498 ></DD
4499 ><DT
4500 >GID[num_groups]</DT
4501 ><DD
4502 ><P
4503 >group info</P
4504 ></DD
4505 ><DT
4506 >UNISTR2</DT
4507 ><DD
4508 ><P
4509 >logon server unicode string</P
4510 ></DD
4511 ><DT
4512 >UNISTR2</DT
4513 ><DD
4514 ><P
4515 >logon domain unicode string</P
4516 ></DD
4517 ><DT
4518 >DOM_SID</DT
4519 ><DD
4520 ><P
4521 >domain SID</P
4522 ></DD
4523 ><DT
4524 >DOM_SID[num_sids]</DT
4525 ><DD
4526 ><P
4527 >other domain SIDs?</P
4528 ></DD
4529 ></DL
4530 ></DIV
4531 ></DIV
4532 ><DIV
4533 CLASS="SECT3"
4534 ><HR><H4
4535 CLASS="SECT3"
4536 ><A
4537 NAME="AEN1365"
4538 ></A
4539 >9.2.3.27. SH_INFO_1_PTR (pointers to level 1 share info strings)</H4
4540 ><P
4541 ><SPAN
4542 CLASS="emphasis"
4543 ><I
4544 CLASS="EMPHASIS"
4545 >Note:  see cifsrap2.txt section5, page 10.</I
4546 ></SPAN
4547 ></P
4548 ><P
4549 ></P
4550 ><TABLE
4551 BORDER="0"
4552 ><TBODY
4553 ><TR
4554 ><TD
4555 >0 for shi1_type indicates a  Disk.</TD
4556 ></TR
4557 ><TR
4558 ><TD
4559 >1 for shi1_type indicates a  Print Queue.</TD
4560 ></TR
4561 ><TR
4562 ><TD
4563 >2 for shi1_type indicates a  Device.</TD
4564 ></TR
4565 ><TR
4566 ><TD
4567 >3 for shi1_type indicates an IPC pipe.</TD
4568 ></TR
4569 ><TR
4570 ><TD
4571 >0x8000 0000 (top bit set in shi1_type) indicates a hidden share.</TD
4572 ></TR
4573 ></TBODY
4574 ></TABLE
4575 ><P
4576 ></P
4577 ><P
4578 ></P
4579 ><DIV
4580 CLASS="VARIABLELIST"
4581 ><DL
4582 ><DT
4583 >VOID*</DT
4584 ><DD
4585 ><P
4586 >shi1_netname - pointer to net name</P
4587 ></DD
4588 ><DT
4589 >UINT32</DT
4590 ><DD
4591 ><P
4592 >shi1_type    - type of share.  0 - undocumented.</P
4593 ></DD
4594 ><DT
4595 >VOID*</DT
4596 ><DD
4597 ><P
4598 >shi1_remark  - pointer to comment.</P
4599 ></DD
4600 ></DL
4601 ></DIV
4602 ></DIV
4603 ><DIV
4604 CLASS="SECT3"
4605 ><HR><H4
4606 CLASS="SECT3"
4607 ><A
4608 NAME="AEN1388"
4609 ></A
4610 >9.2.3.28. SH_INFO_1_STR (level 1 share info strings)</H4
4611 ><P
4612 ></P
4613 ><DIV
4614 CLASS="VARIABLELIST"
4615 ><DL
4616 ><DT
4617 >UNISTR2</DT
4618 ><DD
4619 ><P
4620 >shi1_netname - unicode string of net name</P
4621 ></DD
4622 ><DT
4623 >UNISTR2</DT
4624 ><DD
4625 ><P
4626 >shi1_remark  - unicode string of comment.</P
4627 ></DD
4628 ></DL
4629 ></DIV
4630 ></DIV
4631 ><DIV
4632 CLASS="SECT3"
4633 ><HR><H4
4634 CLASS="SECT3"
4635 ><A
4636 NAME="AEN1399"
4637 ></A
4638 >9.2.3.29. SHARE_INFO_1_CTR</H4
4639 ><P
4640 >share container with 0 entries:</P
4641 ><P
4642 ></P
4643 ><DIV
4644 CLASS="VARIABLELIST"
4645 ><DL
4646 ><DT
4647 >UINT32</DT
4648 ><DD
4649 ><P
4650 >0 - EntriesRead</P
4651 ></DD
4652 ><DT
4653 >UINT32</DT
4654 ><DD
4655 ><P
4656 >0 - Buffer</P
4657 ></DD
4658 ></DL
4659 ></DIV
4660 ><P
4661 >share container with &#62; 0 entries:</P
4662 ><P
4663 ></P
4664 ><DIV
4665 CLASS="VARIABLELIST"
4666 ><DL
4667 ><DT
4668 >UINT32</DT
4669 ><DD
4670 ><P
4671 >EntriesRead</P
4672 ></DD
4673 ><DT
4674 >UINT32</DT
4675 ><DD
4676 ><P
4677 >non-zero - Buffer</P
4678 ></DD
4679 ><DT
4680 >UINT32</DT
4681 ><DD
4682 ><P
4683 >EntriesRead</P
4684 ></DD
4685 ><DT
4686 >SH_INFO_1_PTR[EntriesRead]</DT
4687 ><DD
4688 ><P
4689 >share entry pointers</P
4690 ></DD
4691 ><DT
4692 >SH_INFO_1_STR[EntriesRead]</DT
4693 ><DD
4694 ><P
4695 >share entry strings</P
4696 ></DD
4697 ><DT
4698 >UINT8[]</DT
4699 ><DD
4700 ><P
4701 >padding to get unicode string 4-byte aligned with start of the SMB header.</P
4702 ></DD
4703 ><DT
4704 >UINT32</DT
4705 ><DD
4706 ><P
4707 >EntriesRead</P
4708 ></DD
4709 ><DT
4710 >UINT32</DT
4711 ><DD
4712 ><P
4713 >0 - padding</P
4714 ></DD
4715 ></DL
4716 ></DIV
4717 ></DIV
4718 ><DIV
4719 CLASS="SECT3"
4720 ><HR><H4
4721 CLASS="SECT3"
4722 ><A
4723 NAME="AEN1445"
4724 ></A
4725 >9.2.3.30. SERVER_INFO_101</H4
4726 ><P
4727 ><SPAN
4728 CLASS="emphasis"
4729 ><I
4730 CLASS="EMPHASIS"
4731 >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
4732 ></SPAN
4733 ></P
4734 ><P
4735 ></P
4736 ><DIV
4737 CLASS="VARIABLELIST"
4738 ><DL
4739 ><DT
4740 >SV_TYPE_WORKSTATION</DT
4741 ><DD
4742 ><P
4743 >0x00000001  All workstations</P
4744 ></DD
4745 ><DT
4746 >SV_TYPE_SERVER</DT
4747 ><DD
4748 ><P
4749 >0x00000002  All servers</P
4750 ></DD
4751 ><DT
4752 >SV_TYPE_SQLSERVER</DT
4753 ><DD
4754 ><P
4755 >0x00000004  Any server running with SQL server</P
4756 ></DD
4757 ><DT
4758 >SV_TYPE_DOMAIN_CTRL</DT
4759 ><DD
4760 ><P
4761 >0x00000008  Primary domain controller</P
4762 ></DD
4763 ><DT
4764 >SV_TYPE_DOMAIN_BAKCTRL</DT
4765 ><DD
4766 ><P
4767 >0x00000010  Backup domain controller</P
4768 ></DD
4769 ><DT
4770 >SV_TYPE_TIME_SOURCE</DT
4771 ><DD
4772 ><P
4773 >0x00000020  Server running the timesource service</P
4774 ></DD
4775 ><DT
4776 >SV_TYPE_AFP</DT
4777 ><DD
4778 ><P
4779 >0x00000040  Apple File Protocol servers</P
4780 ></DD
4781 ><DT
4782 >SV_TYPE_NOVELL</DT
4783 ><DD
4784 ><P
4785 >0x00000080  Novell servers</P
4786 ></DD
4787 ><DT
4788 >SV_TYPE_DOMAIN_MEMBER</DT
4789 ><DD
4790 ><P
4791 >0x00000100  Domain Member</P
4792 ></DD
4793 ><DT
4794 >SV_TYPE_PRINTQ_SERVER</DT
4795 ><DD
4796 ><P
4797 >0x00000200  Server sharing print queue</P
4798 ></DD
4799 ><DT
4800 >SV_TYPE_DIALIN_SERVER</DT
4801 ><DD
4802 ><P
4803 >0x00000400  Server running dialin service.</P
4804 ></DD
4805 ><DT
4806 >SV_TYPE_XENIX_SERVER</DT
4807 ><DD
4808 ><P
4809 >0x00000800  Xenix server</P
4810 ></DD
4811 ><DT
4812 >SV_TYPE_NT</DT
4813 ><DD
4814 ><P
4815 >0x00001000  NT server</P
4816 ></DD
4817 ><DT
4818 >SV_TYPE_WFW</DT
4819 ><DD
4820 ><P
4821 >0x00002000  Server running Windows for </P
4822 ></DD
4823 ><DT
4824 >SV_TYPE_SERVER_NT</DT
4825 ><DD
4826 ><P
4827 >0x00008000  Windows NT non DC server</P
4828 ></DD
4829 ><DT
4830 >SV_TYPE_POTENTIAL_BROWSER</DT
4831 ><DD
4832 ><P
4833 >0x00010000  Server that can run the browser service</P
4834 ></DD
4835 ><DT
4836 >SV_TYPE_BACKUP_BROWSER</DT
4837 ><DD
4838 ><P
4839 >0x00020000  Backup browser server</P
4840 ></DD
4841 ><DT
4842 >SV_TYPE_MASTER_BROWSER</DT
4843 ><DD
4844 ><P
4845 >0x00040000  Master browser server</P
4846 ></DD
4847 ><DT
4848 >SV_TYPE_DOMAIN_MASTER</DT
4849 ><DD
4850 ><P
4851 >0x00080000  Domain Master Browser server</P
4852 ></DD
4853 ><DT
4854 >SV_TYPE_LOCAL_LIST_ONLY</DT
4855 ><DD
4856 ><P
4857 >0x40000000  Enumerate only entries marked "local"</P
4858 ></DD
4859 ><DT
4860 >SV_TYPE_DOMAIN_ENUM</DT
4861 ><DD
4862 ><P
4863 >0x80000000  Enumerate Domains. The pszServer and pszDomain parameters must be NULL.</P
4864 ></DD
4865 ></DL
4866 ></DIV
4867 ><P
4868 ></P
4869 ><DIV
4870 CLASS="VARIABLELIST"
4871 ><DL
4872 ><DT
4873 >UINT32</DT
4874 ><DD
4875 ><P
4876 >500 - platform_id</P
4877 ></DD
4878 ><DT
4879 >VOID*</DT
4880 ><DD
4881 ><P
4882 >pointer to name</P
4883 ></DD
4884 ><DT
4885 >UINT32</DT
4886 ><DD
4887 ><P
4888 >5 - major version</P
4889 ></DD
4890 ><DT
4891 >UINT32</DT
4892 ><DD
4893 ><P
4894 >4 - minor version</P
4895 ></DD
4896 ><DT
4897 >UINT32</DT
4898 ><DD
4899 ><P
4900 >type (SV_TYPE_... bit field)</P
4901 ></DD
4902 ><DT
4903 >VOID*</DT
4904 ><DD
4905 ><P
4906 >pointer to comment</P
4907 ></DD
4908 ><DT
4909 >UNISTR2</DT
4910 ><DD
4911 ><P
4912 >sv101_name - unicode string of server name</P
4913 ></DD
4914 ><DT
4915 >UNISTR2</DT
4916 ><DD
4917 ><P
4918 >sv_101_comment  - unicode string of server comment.</P
4919 ></DD
4920 ><DT
4921 >UINT8[]</DT
4922 ><DD
4923 ><P
4924 >padding to get unicode string 4-byte aligned with start of the SMB header.</P
4925 ></DD
4926 ></DL
4927 ></DIV
4928 ></DIV
4929 ></DIV
4930 ></DIV
4931 ><DIV
4932 CLASS="SECT1"
4933 ><HR><H2
4934 CLASS="SECT1"
4935 ><A
4936 NAME="AEN1571"
4937 ></A
4938 >9.3. MSRPC over Transact Named Pipe</H2
4939 ><P
4940 >For details on the SMB Transact Named Pipe, see cifs6.txt</P
4941 ><DIV
4942 CLASS="SECT2"
4943 ><HR><H3
4944 CLASS="SECT2"
4945 ><A
4946 NAME="AEN1574"
4947 ></A
4948 >9.3.1. MSRPC Pipes</H3
4949 ><P
4950 >The MSRPC is conducted over an SMB Transact Pipe with a name of 
4951 <TT
4952 CLASS="FILENAME"
4953 >\PIPE\</TT
4954 >.  You must first obtain a 16 bit file handle, by
4955 sending a SMBopenX with the pipe name <TT
4956 CLASS="FILENAME"
4957 >\PIPE\srvsvc</TT
4958 > for
4959 example.  You can then perform an SMB Trans,
4960 and must carry out an SMBclose on the file handle once you are finished.</P
4961 ><P
4962 >Trans Requests must be sent with two setup UINT16s, no UINT16 params (none
4963 known about), and UINT8 data parameters sufficient to contain the MSRPC
4964 header, and MSRPC data.  The first UINT16 setup parameter must be either
4965 0x0026 to indicate an RPC, or 0x0001 to indicate Set Named Pipe Handle
4966 state.  The second UINT16 parameter must be the file handle for the pipe,
4967 obtained above.</P
4968 ><P
4969 >The Data section for an API Command of 0x0026 (RPC pipe) in the Trans
4970 Request is the RPC Header, followed by the RPC Data.  The Data section for
4971 an API Command of 0x0001 (Set Named Pipe Handle state) is two bytes.  The
4972 only value seen for these two bytes is 0x00 0x43.</P
4973 ><P
4974 >MSRPC Responses are sent as response data inside standard SMB Trans
4975 responses, with the MSRPC Header, MSRPC Data and MSRPC tail.</P
4976 ><P
4977 >It is suspected that the Trans Requests will need to be at least 2-byte
4978 aligned (probably 4-byte).  This is standard practice for SMBs.  It is also
4979 independent of the observed 4-byte alignments with the start of the MSRPC
4980 header, including the 4-byte alignment between the MSRPC header and the
4981 MSRPC data.</P
4982 ><P
4983 >First, an SMBtconX connection is made to the IPC$ share.  The connection
4984 must be made using encrypted passwords, not clear-text.  Then, an SMBopenX
4985 is made on the pipe.  Then, a Set Named Pipe Handle State must be sent,
4986 after which the pipe is ready to accept API commands.  Lastly, and SMBclose
4987 is sent.</P
4988 ><P
4989 >To be resolved:</P
4990 ><P
4991 >lkcl/01nov97 there appear to be two additional bytes after the null-terminated \PIPE\ name for the RPC pipe.  Values seen so far are
4992 listed below:</P
4993 ><P
4994 ><PRE
4995 CLASS="PROGRAMLISTING"
4996 >        initial SMBopenX request:         RPC API command 0x26 params:
4997         "\\PIPE\\lsarpc"                  0x65 0x63; 0x72 0x70; 0x44 0x65;
4998         "\\PIPE\\srvsvc"                  0x73 0x76; 0x4E 0x00; 0x5C 0x43;</PRE
4999 ></P
5000 ></DIV
5001 ><DIV
5002 CLASS="SECT2"
5003 ><HR><H3
5004 CLASS="SECT2"
5005 ><A
5006 NAME="AEN1588"
5007 ></A
5008 >9.3.2. Header</H3
5009 ><P
5010 >[section to be rewritten, following receipt of work by Duncan Stansfield]</P
5011 ><P
5012 >Interesting note: if you set packed data representation to 0x0100 0000
5013 then all 4-byte and 2-byte word ordering is turned around!</P
5014 ><P
5015 >The start of each of the NTLSA and NETLOGON named pipes begins with:</P
5016 ><P
5017 ><B
5018 >offset: </B
5019 >00</P
5020 ><P
5021 ><B
5022 >Variable type: </B
5023 >UINT8</P
5024 ><P
5025 ><B
5026 >Variable data: </B
5027 >5 - RPC major version</P
5028 ><P
5029 ><B
5030 >offset: </B
5031 >01</P
5032 ><P
5033 ><B
5034 >Variable type: </B
5035 >UINT8</P
5036 ><P
5037 ><B
5038 >Variable data: </B
5039 >0 - RPC minor version</P
5040 ><P
5041 ><B
5042 >offset: </B
5043 >02</P
5044 ><P
5045 ><B
5046 >Variable type: </B
5047 >UINT8</P
5048 ><P
5049 ><B
5050 >Variable data: </B
5051 >2 - RPC response packet</P
5052 ><P
5053 ><B
5054 >offset: </B
5055 >03</P
5056 ><P
5057 ><B
5058 >Variable type: </B
5059 >UINT8</P
5060 ><P
5061 ><B
5062 >Variable data: </B
5063 >3 - (FirstFrag bit-wise or with LastFrag)</P
5064 ><P
5065 ><B
5066 >offset: </B
5067 >04</P
5068 ><P
5069 ><B
5070 >Variable type: </B
5071 >UINT32</P
5072 ><P
5073 ><B
5074 >Variable data: </B
5075 >0x1000 0000 - packed data representation</P
5076 ><P
5077 ><B
5078 >offset: </B
5079 >08</P
5080 ><P
5081 ><B
5082 >Variable type: </B
5083 >UINT16</P
5084 ><P
5085 ><B
5086 >Variable data: </B
5087 >fragment length - data size (bytes) inc header and tail.</P
5088 ><P
5089 ><B
5090 >offset: </B
5091 >0A</P
5092 ><P
5093 ><B
5094 >Variable type: </B
5095 >UINT16</P
5096 ><P
5097 ><B
5098 >Variable data: </B
5099 >0 - authentication length </P
5100 ><P
5101 ><B
5102 >offset: </B
5103 >0C</P
5104 ><P
5105 ><B
5106 >Variable type: </B
5107 >UINT32</P
5108 ><P
5109 ><B
5110 >Variable data: </B
5111 >call identifier. matches 12th UINT32 of incoming RPC data.</P
5112 ><P
5113 ><B
5114 >offset: </B
5115 >10</P
5116 ><P
5117 ><B
5118 >Variable type: </B
5119 >UINT32</P
5120 ><P
5121 ><B
5122 >Variable data: </B
5123 >allocation hint - data size (bytes) minus header and tail.</P
5124 ><P
5125 ><B
5126 >offset: </B
5127 >14</P
5128 ><P
5129 ><B
5130 >Variable type: </B
5131 >UINT16</P
5132 ><P
5133 ><B
5134 >Variable data: </B
5135 >0 - presentation context identifier</P
5136 ><P
5137 ><B
5138 >offset: </B
5139 >16</P
5140 ><P
5141 ><B
5142 >Variable type: </B
5143 >UINT8</P
5144 ><P
5145 ><B
5146 >Variable data: </B
5147 >0 - cancel count</P
5148 ><P
5149 ><B
5150 >offset: </B
5151 >17</P
5152 ><P
5153 ><B
5154 >Variable type: </B
5155 >UINT8</P
5156 ><P
5157 ><B
5158 >Variable data: </B
5159 >in replies: 0 - reserved; in requests: opnum - see #defines.</P
5160 ><P
5161 ><B
5162 >offset: </B
5163 >18</P
5164 ><P
5165 ><B
5166 >Variable type: </B
5167 >......</P
5168 ><P
5169 ><B
5170 >Variable data: </B
5171 >start of data (goes on for allocation_hint bytes)</P
5172 ><DIV
5173 CLASS="SECT3"
5174 ><HR><H4
5175 CLASS="SECT3"
5176 ><A
5177 NAME="AEN1649"
5178 ></A
5179 >9.3.2.1. RPC_Packet for request, response, bind and bind acknowledgement</H4
5180 ><P
5181 ></P
5182 ><DIV
5183 CLASS="VARIABLELIST"
5184 ><DL
5185 ><DT
5186 >UINT8 versionmaj</DT
5187 ><DD
5188 ><P
5189 >reply same as request (0x05)</P
5190 ></DD
5191 ><DT
5192 >UINT8 versionmin</DT
5193 ><DD
5194 ><P
5195 >reply same as request (0x00)</P
5196 ></DD
5197 ><DT
5198 >UINT8 type</DT
5199 ><DD
5200 ><P
5201 >one of the MSRPC_Type enums</P
5202 ></DD
5203 ><DT
5204 >UINT8 flags</DT
5205 ><DD
5206 ><P
5207 >reply same as request (0x00 for Bind, 0x03 for Request)</P
5208 ></DD
5209 ><DT
5210 >UINT32 representation</DT
5211 ><DD
5212 ><P
5213 >reply same as request (0x00000010)</P
5214 ></DD
5215 ><DT
5216 >UINT16 fraglength</DT
5217 ><DD
5218 ><P
5219 >the length of the data section of the SMB trans packet</P
5220 ></DD
5221 ><DT
5222 >UINT16 authlength</DT
5223 ><DD
5224 ><P
5225 ></P
5226 ></DD
5227 ><DT
5228 >UINT32 callid</DT
5229 ><DD
5230 ><P
5231 >call identifier. (e.g. 0x00149594)</P
5232 ></DD
5233 ><DT
5234 >* stub USE TvPacket</DT
5235 ><DD
5236 ><P
5237 >the remainder of the packet depending on the "type"</P
5238 ></DD
5239 ></DL
5240 ></DIV
5241 ></DIV
5242 ><DIV
5243 CLASS="SECT3"
5244 ><HR><H4
5245 CLASS="SECT3"
5246 ><A
5247 NAME="AEN1688"
5248 ></A
5249 >9.3.2.2. Interface identification</H4
5250 ><P
5251 >the interfaces are numbered. as yet I haven't seen more than one interface used on the same pipe name srvsvc</P
5252 ><P
5253 ><PRE
5254 CLASS="PROGRAMLISTING"
5255 >abstract (0x4B324FC8, 0x01D31670, 0x475A7812, 0x88E16EBF, 0x00000003)
5256 transfer (0x8A885D04, 0x11C91CEB, 0x0008E89F, 0x6048102B, 0x00000002)</PRE
5257 ></P
5258 ></DIV
5259 ><DIV
5260 CLASS="SECT3"
5261 ><HR><H4
5262 CLASS="SECT3"
5263 ><A
5264 NAME="AEN1693"
5265 ></A
5266 >9.3.2.3. RPC_Iface RW</H4
5267 ><P
5268 ></P
5269 ><DIV
5270 CLASS="VARIABLELIST"
5271 ><DL
5272 ><DT
5273 >UINT8 byte[16]</DT
5274 ><DD
5275 ><P
5276 >16 bytes of number</P
5277 ></DD
5278 ><DT
5279 >UINT32 version</DT
5280 ><DD
5281 ><P
5282 >the interface number</P
5283 ></DD
5284 ></DL
5285 ></DIV
5286 ></DIV
5287 ><DIV
5288 CLASS="SECT3"
5289 ><HR><H4
5290 CLASS="SECT3"
5291 ><A
5292 NAME="AEN1704"
5293 ></A
5294 >9.3.2.4. RPC_ReqBind RW</H4
5295 ><P
5296 >the remainder of the packet after the header if "type" was Bind in the response header, "type" should be BindAck</P
5297 ><P
5298 ></P
5299 ><DIV
5300 CLASS="VARIABLELIST"
5301 ><DL
5302 ><DT
5303 >UINT16 maxtsize</DT
5304 ><DD
5305 ><P
5306 >maximum transmission fragment size (0x1630)</P
5307 ></DD
5308 ><DT
5309 >UINT16 maxrsize</DT
5310 ><DD
5311 ><P
5312 >max receive fragment size (0x1630)</P
5313 ></DD
5314 ><DT
5315 >UINT32 assocgid</DT
5316 ><DD
5317 ><P
5318 >associated group id (0x0)</P
5319 ></DD
5320 ><DT
5321 >UINT32 numelements</DT
5322 ><DD
5323 ><P
5324 >the number of elements (0x1)</P
5325 ></DD
5326 ><DT
5327 >UINT16 contextid</DT
5328 ><DD
5329 ><P
5330 >presentation context identifier (0x0)</P
5331 ></DD
5332 ><DT
5333 >UINT8 numsyntaxes</DT
5334 ><DD
5335 ><P
5336 >the number of syntaxes (has always been 1?)(0x1)</P
5337 ></DD
5338 ><DT
5339 >UINT8[]</DT
5340 ><DD
5341 ><P
5342 >4-byte alignment padding, against SMB header</P
5343 ></DD
5344 ><DT
5345 >* abstractint USE RPC_Iface</DT
5346 ><DD
5347 ><P
5348 >num and vers. of interface client is using</P
5349 ></DD
5350 ><DT
5351 >* transferint USE RPC_Iface</DT
5352 ><DD
5353 ><P
5354 >num and vers. of interface to use for replies</P
5355 ></DD
5356 ></DL
5357 ></DIV
5358 ></DIV
5359 ><DIV
5360 CLASS="SECT3"
5361 ><HR><H4
5362 CLASS="SECT3"
5363 ><A
5364 NAME="AEN1744"
5365 ></A
5366 >9.3.2.5. RPC_Address RW</H4
5367 ><P
5368 ></P
5369 ><DIV
5370 CLASS="VARIABLELIST"
5371 ><DL
5372 ><DT
5373 >UINT16 length</DT
5374 ><DD
5375 ><P
5376 >length of the string including null terminator</P
5377 ></DD
5378 ><DT
5379 >* port USE string</DT
5380 ><DD
5381 ><P
5382 >the string above in single byte, null terminated form</P
5383 ></DD
5384 ></DL
5385 ></DIV
5386 ></DIV
5387 ><DIV
5388 CLASS="SECT3"
5389 ><HR><H4
5390 CLASS="SECT3"
5391 ><A
5392 NAME="AEN1755"
5393 ></A
5394 >9.3.2.6. RPC_ResBind RW</H4
5395 ><P
5396 >the response to place after the header in the reply packet</P
5397 ><P
5398 ></P
5399 ><DIV
5400 CLASS="VARIABLELIST"
5401 ><DL
5402 ><DT
5403 >UINT16 maxtsize</DT
5404 ><DD
5405 ><P
5406 >same as request</P
5407 ></DD
5408 ><DT
5409 >UINT16 maxrsize</DT
5410 ><DD
5411 ><P
5412 >same as request</P
5413 ></DD
5414 ><DT
5415 >UINT32 assocgid</DT
5416 ><DD
5417 ><P
5418 >zero</P
5419 ></DD
5420 ><DT
5421 >* secondaddr USE RPC_Address</DT
5422 ><DD
5423 ><P
5424 >the address string, as described earlier</P
5425 ></DD
5426 ><DT
5427 >UINT8[]</DT
5428 ><DD
5429 ><P
5430 >4-byte alignment padding, against SMB header</P
5431 ></DD
5432 ><DT
5433 >UINT8 numresults</DT
5434 ><DD
5435 ><P
5436 >the number of results (0x01)</P
5437 ></DD
5438 ><DT
5439 >UINT8[]</DT
5440 ><DD
5441 ><P
5442 >4-byte alignment padding, against SMB header</P
5443 ></DD
5444 ><DT
5445 >UINT16 result</DT
5446 ><DD
5447 ><P
5448 >result (0x00 = accept)</P
5449 ></DD
5450 ><DT
5451 >UINT16 reason</DT
5452 ><DD
5453 ><P
5454 >reason (0x00 = no reason specified)</P
5455 ></DD
5456 ><DT
5457 >* transfersyntax USE RPC_Iface</DT
5458 ><DD
5459 ><P
5460 >the transfer syntax from the request</P
5461 ></DD
5462 ></DL
5463 ></DIV
5464 ></DIV
5465 ><DIV
5466 CLASS="SECT3"
5467 ><HR><H4
5468 CLASS="SECT3"
5469 ><A
5470 NAME="AEN1799"
5471 ></A
5472 >9.3.2.7. RPC_ReqNorm RW</H4
5473 ><P
5474 >the remainder of the packet after the header for every other other request</P
5475 ><P
5476 ></P
5477 ><DIV
5478 CLASS="VARIABLELIST"
5479 ><DL
5480 ><DT
5481 >UINT32 allochint</DT
5482 ><DD
5483 ><P
5484 >the size of the stub data in bytes</P
5485 ></DD
5486 ><DT
5487 >UINT16 prescontext</DT
5488 ><DD
5489 ><P
5490 >presentation context identifier (0x0)</P
5491 ></DD
5492 ><DT
5493 >UINT16 opnum</DT
5494 ><DD
5495 ><P
5496 >operation number (0x15)</P
5497 ></DD
5498 ><DT
5499 >* stub USE TvPacket</DT
5500 ><DD
5501 ><P
5502 >a packet dependent on the pipe name (probably the interface) and the op number)</P
5503 ></DD
5504 ></DL
5505 ></DIV
5506 ></DIV
5507 ><DIV
5508 CLASS="SECT3"
5509 ><HR><H4
5510 CLASS="SECT3"
5511 ><A
5512 NAME="AEN1819"
5513 ></A
5514 >9.3.2.8. RPC_ResNorm RW</H4
5515 ><P
5516 ></P
5517 ><DIV
5518 CLASS="VARIABLELIST"
5519 ><DL
5520 ><DT
5521 >UINT32 allochint</DT
5522 ><DD
5523 ><P
5524 ># size of the stub data in bytes</P
5525 ></DD
5526 ><DT
5527 >UINT16 prescontext</DT
5528 ><DD
5529 ><P
5530 ># presentation context identifier (same as request)</P
5531 ></DD
5532 ><DT
5533 >UINT8 cancelcount</DT
5534 ><DD
5535 ><P
5536 ># cancel count? (0x0)</P
5537 ></DD
5538 ><DT
5539 >UINT8 reserved</DT
5540 ><DD
5541 ><P
5542 ># 0 - one byte padding</P
5543 ></DD
5544 ><DT
5545 >* stub USE TvPacket</DT
5546 ><DD
5547 ><P
5548 ># the remainder of the reply</P
5549 ></DD
5550 ></DL
5551 ></DIV
5552 ></DIV
5553 ></DIV
5554 ><DIV
5555 CLASS="SECT2"
5556 ><HR><H3
5557 CLASS="SECT2"
5558 ><A
5559 NAME="AEN1842"
5560 ></A
5561 >9.3.3. Tail</H3
5562 ><P
5563 >The end of each of the NTLSA and NETLOGON named pipes ends with:</P
5564 ><P
5565 ></P
5566 ><DIV
5567 CLASS="VARIABLELIST"
5568 ><DL
5569 ><DT
5570 >......</DT
5571 ><DD
5572 ><P
5573 >end of data</P
5574 ></DD
5575 ><DT
5576 >UINT32</DT
5577 ><DD
5578 ><P
5579 >return code</P
5580 ></DD
5581 ></DL
5582 ></DIV
5583 ></DIV
5584 ><DIV
5585 CLASS="SECT2"
5586 ><HR><H3
5587 CLASS="SECT2"
5588 ><A
5589 NAME="AEN1854"
5590 ></A
5591 >9.3.4. RPC Bind / Bind Ack</H3
5592 ><P
5593 >RPC Binds are the process of associating an RPC pipe (e.g \PIPE\lsarpc)
5594 with a "transfer syntax" (see RPC_Iface structure).  The purpose for doing
5595 this is unknown.</P
5596 ><P
5597 ><SPAN
5598 CLASS="emphasis"
5599 ><I
5600 CLASS="EMPHASIS"
5601 >Note: The RPC_ResBind SMB Transact request is sent with two uint16 setup parameters.  The first is 0x0026; the second is the file handle
5602         returned by the SMBopenX Transact response.</I
5603 ></SPAN
5604 ></P
5605 ><P
5606 ><SPAN
5607 CLASS="emphasis"
5608 ><I
5609 CLASS="EMPHASIS"
5610 >Note:  The RPC_ResBind members maxtsize, maxrsize and assocgid are the same in the response as the same members in the RPC_ReqBind.  The
5611         RPC_ResBind member transfersyntax is the same in the response as
5612         the</I
5613 ></SPAN
5614 ></P
5615 ><P
5616 ><SPAN
5617 CLASS="emphasis"
5618 ><I
5619 CLASS="EMPHASIS"
5620 >Note:  The RPC_ResBind response member secondaddr contains the name of what is presumed to be the service behind the RPC pipe.  The
5621         mapping identified so far is:</I
5622 ></SPAN
5623 ></P
5624 ><P
5625 ></P
5626 ><DIV
5627 CLASS="VARIABLELIST"
5628 ><DL
5629 ><DT
5630 >initial SMBopenX request:</DT
5631 ><DD
5632 ><P
5633 >RPC_ResBind response:</P
5634 ></DD
5635 ><DT
5636 >"\\PIPE\\srvsvc"</DT
5637 ><DD
5638 ><P
5639 >"\\PIPE\\ntsvcs"</P
5640 ></DD
5641 ><DT
5642 >"\\PIPE\\samr"</DT
5643 ><DD
5644 ><P
5645 >"\\PIPE\\lsass"</P
5646 ></DD
5647 ><DT
5648 >"\\PIPE\\lsarpc"</DT
5649 ><DD
5650 ><P
5651 >"\\PIPE\\lsass"</P
5652 ></DD
5653 ><DT
5654 >"\\PIPE\\wkssvc"</DT
5655 ><DD
5656 ><P
5657 >"\\PIPE\\wksvcs"</P
5658 ></DD
5659 ><DT
5660 >"\\PIPE\\NETLOGON"</DT
5661 ><DD
5662 ><P
5663 >"\\PIPE\\NETLOGON"</P
5664 ></DD
5665 ></DL
5666 ></DIV
5667 ><P
5668 ><SPAN
5669 CLASS="emphasis"
5670 ><I
5671 CLASS="EMPHASIS"
5672 >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
5673 ></SPAN
5674 ></P
5675 ><P
5676 >Request:</P
5677 ><P
5678 ></P
5679 ><TABLE
5680 BORDER="0"
5681 ><TBODY
5682 ><TR
5683 ><TD
5684 >RPC_Packet</TD
5685 ></TR
5686 ><TR
5687 ><TD
5688 >RPC_ReqBind</TD
5689 ></TR
5690 ></TBODY
5691 ></TABLE
5692 ><P
5693 ></P
5694 ><P
5695 >Response:</P
5696 ><P
5697 ></P
5698 ><TABLE
5699 BORDER="0"
5700 ><TBODY
5701 ><TR
5702 ><TD
5703 >RPC_Packet</TD
5704 ></TR
5705 ><TR
5706 ><TD
5707 >RPC_ResBind</TD
5708 ></TR
5709 ></TBODY
5710 ></TABLE
5711 ><P
5712 ></P
5713 ></DIV
5714 ><DIV
5715 CLASS="SECT2"
5716 ><HR><H3
5717 CLASS="SECT2"
5718 ><A
5719 NAME="AEN1898"
5720 ></A
5721 >9.3.5. NTLSA Transact Named Pipe</H3
5722 ><P
5723 >The sequence of actions taken on this pipe are:</P
5724 ><P
5725 ></P
5726 ><TABLE
5727 BORDER="0"
5728 ><TBODY
5729 ><TR
5730 ><TD
5731 >Establish a connection to the IPC$ share (SMBtconX).  use encrypted passwords.</TD
5732 ></TR
5733 ><TR
5734 ><TD
5735 >Open an RPC Pipe with the name "\\PIPE\\lsarpc".  Store the file handle.</TD
5736 ></TR
5737 ><TR
5738 ><TD
5739 >Using the file handle, send a Set Named Pipe Handle state to 0x4300.</TD
5740 ></TR
5741 ><TR
5742 ><TD
5743 >Send an LSA Open Policy request.  Store the Policy Handle.</TD
5744 ></TR
5745 ><TR
5746 ><TD
5747 >Using the Policy Handle, send LSA Query Info Policy requests, etc.</TD
5748 ></TR
5749 ><TR
5750 ><TD
5751 >Using the Policy Handle, send an LSA Close.</TD
5752 ></TR
5753 ><TR
5754 ><TD
5755 >Close the IPC$ share.</TD
5756 ></TR
5757 ></TBODY
5758 ></TABLE
5759 ><P
5760 ></P
5761 ><P
5762 >Defines for this pipe, identifying the query are:</P
5763 ><P
5764 ></P
5765 ><DIV
5766 CLASS="VARIABLELIST"
5767 ><DL
5768 ><DT
5769 >LSA Open Policy:</DT
5770 ><DD
5771 ><P
5772 >0x2c</P
5773 ></DD
5774 ><DT
5775 >LSA Query Info Policy:</DT
5776 ><DD
5777 ><P
5778 >0x07</P
5779 ></DD
5780 ><DT
5781 >LSA Enumerate Trusted Domains:</DT
5782 ><DD
5783 ><P
5784 >0x0d</P
5785 ></DD
5786 ><DT
5787 >LSA Open Secret:</DT
5788 ><DD
5789 ><P
5790 >0xff</P
5791 ></DD
5792 ><DT
5793 >LSA Lookup SIDs:</DT
5794 ><DD
5795 ><P
5796 >0xfe</P
5797 ></DD
5798 ><DT
5799 >LSA Lookup Names:</DT
5800 ><DD
5801 ><P
5802 >0xfd</P
5803 ></DD
5804 ><DT
5805 >LSA Close:</DT
5806 ><DD
5807 ><P
5808 >0x00</P
5809 ></DD
5810 ></DL
5811 ></DIV
5812 ></DIV
5813 ><DIV
5814 CLASS="SECT2"
5815 ><HR><H3
5816 CLASS="SECT2"
5817 ><A
5818 NAME="AEN1939"
5819 ></A
5820 >9.3.6. LSA Open Policy</H3
5821 ><P
5822 ><SPAN
5823 CLASS="emphasis"
5824 ><I
5825 CLASS="EMPHASIS"
5826 >Note:  The policy handle can be anything you like.</I
5827 ></SPAN
5828 ></P
5829 ><DIV
5830 CLASS="SECT3"
5831 ><HR><H4
5832 CLASS="SECT3"
5833 ><A
5834 NAME="AEN1943"
5835 ></A
5836 >9.3.6.1. Request</H4
5837 ><P
5838 ></P
5839 ><DIV
5840 CLASS="VARIABLELIST"
5841 ><DL
5842 ><DT
5843 >VOID*</DT
5844 ><DD
5845 ><P
5846 >buffer pointer</P
5847 ></DD
5848 ><DT
5849 >UNISTR2</DT
5850 ><DD
5851 ><P
5852 >server name - unicode string starting with two '\'s</P
5853 ></DD
5854 ><DT
5855 >OBJ_ATTR</DT
5856 ><DD
5857 ><P
5858 >object attributes</P
5859 ></DD
5860 ><DT
5861 >UINT32</DT
5862 ><DD
5863 ><P
5864 >1 - desired access</P
5865 ></DD
5866 ></DL
5867 ></DIV
5868 ></DIV
5869 ><DIV
5870 CLASS="SECT3"
5871 ><HR><H4
5872 CLASS="SECT3"
5873 ><A
5874 NAME="AEN1962"
5875 ></A
5876 >9.3.6.2. Response</H4
5877 ><P
5878 ></P
5879 ><DIV
5880 CLASS="VARIABLELIST"
5881 ><DL
5882 ><DT
5883 >POL_HND</DT
5884 ><DD
5885 ><P
5886 >LSA policy handle</P
5887 ></DD
5888 ><DT
5889 >return</DT
5890 ><DD
5891 ><P
5892 >0 - indicates success</P
5893 ></DD
5894 ></DL
5895 ></DIV
5896 ></DIV
5897 ></DIV
5898 ><DIV
5899 CLASS="SECT2"
5900 ><HR><H3
5901 CLASS="SECT2"
5902 ><A
5903 NAME="AEN1973"
5904 ></A
5905 >9.3.7. LSA Query Info Policy</H3
5906 ><P
5907 ><SPAN
5908 CLASS="emphasis"
5909 ><I
5910 CLASS="EMPHASIS"
5911 >Note:  The info class in response must be the same as that in the request.</I
5912 ></SPAN
5913 ></P
5914 ><DIV
5915 CLASS="SECT3"
5916 ><HR><H4
5917 CLASS="SECT3"
5918 ><A
5919 NAME="AEN1977"
5920 ></A
5921 >9.3.7.1. Request</H4
5922 ><P
5923 ></P
5924 ><DIV
5925 CLASS="VARIABLELIST"
5926 ><DL
5927 ><DT
5928 >POL_HND</DT
5929 ><DD
5930 ><P
5931 >LSA policy handle</P
5932 ></DD
5933 ><DT
5934 >UINT16</DT
5935 ><DD
5936 ><P
5937 >info class (also a policy handle?)</P
5938 ></DD
5939 ></DL
5940 ></DIV
5941 ></DIV
5942 ><DIV
5943 CLASS="SECT3"
5944 ><HR><H4
5945 CLASS="SECT3"
5946 ><A
5947 NAME="AEN1988"
5948 ></A
5949 >9.3.7.2. Response</H4
5950 ><P
5951 ></P
5952 ><DIV
5953 CLASS="VARIABLELIST"
5954 ><DL
5955 ><DT
5956 >VOID*</DT
5957 ><DD
5958 ><P
5959 >undocumented buffer pointer</P
5960 ></DD
5961 ><DT
5962 >UINT16</DT
5963 ><DD
5964 ><P
5965 >info class (same as info class in request).</P
5966 ></DD
5967 ></DL
5968 ></DIV
5969 ><P
5970 ><PRE
5971 CLASS="PROGRAMLISTING"
5972 >switch (info class)
5973 case 3:
5974 case 5:
5975 {
5976 DOM_INFO domain info, levels 3 and 5 (are the same).
5977 }
5978
5979 return    0 - indicates success</PRE
5980 ></P
5981 ></DIV
5982 ></DIV
5983 ><DIV
5984 CLASS="SECT2"
5985 ><HR><H3
5986 CLASS="SECT2"
5987 ><A
5988 NAME="AEN2001"
5989 ></A
5990 >9.3.8. LSA Enumerate Trusted Domains</H3
5991 ><DIV
5992 CLASS="SECT3"
5993 ><H4
5994 CLASS="SECT3"
5995 ><A
5996 NAME="AEN2003"
5997 ></A
5998 >9.3.8.1. Request</H4
5999 ><P
6000 >no extra data</P
6001 ></DIV
6002 ><DIV
6003 CLASS="SECT3"
6004 ><HR><H4
6005 CLASS="SECT3"
6006 ><A
6007 NAME="AEN2006"
6008 ></A
6009 >9.3.8.2. Response</H4
6010 ><P
6011 ></P
6012 ><DIV
6013 CLASS="VARIABLELIST"
6014 ><DL
6015 ><DT
6016 >UINT32</DT
6017 ><DD
6018 ><P
6019 >0 - enumeration context</P
6020 ></DD
6021 ><DT
6022 >UINT32</DT
6023 ><DD
6024 ><P
6025 >0 - entries read</P
6026 ></DD
6027 ><DT
6028 >UINT32</DT
6029 ><DD
6030 ><P
6031 >0 - trust information</P
6032 ></DD
6033 ><DT
6034 >return</DT
6035 ><DD
6036 ><P
6037 >0x8000 001a - "no trusted domains" success code</P
6038 ></DD
6039 ></DL
6040 ></DIV
6041 ></DIV
6042 ></DIV
6043 ><DIV
6044 CLASS="SECT2"
6045 ><HR><H3
6046 CLASS="SECT2"
6047 ><A
6048 NAME="AEN2025"
6049 ></A
6050 >9.3.9. LSA Open Secret</H3
6051 ><DIV
6052 CLASS="SECT3"
6053 ><H4
6054 CLASS="SECT3"
6055 ><A
6056 NAME="AEN2027"
6057 ></A
6058 >9.3.9.1. Request</H4
6059 ><P
6060 >no extra data</P
6061 ></DIV
6062 ><DIV
6063 CLASS="SECT3"
6064 ><HR><H4
6065 CLASS="SECT3"
6066 ><A
6067 NAME="AEN2030"
6068 ></A
6069 >9.3.9.2. Response</H4
6070 ><P
6071 ></P
6072 ><DIV
6073 CLASS="VARIABLELIST"
6074 ><DL
6075 ><DT
6076 >UINT32</DT
6077 ><DD
6078 ><P
6079 >0 - undocumented</P
6080 ></DD
6081 ><DT
6082 >UINT32</DT
6083 ><DD
6084 ><P
6085 >0 - undocumented</P
6086 ></DD
6087 ><DT
6088 >UINT32</DT
6089 ><DD
6090 ><P
6091 >0 - undocumented</P
6092 ></DD
6093 ><DT
6094 >UINT32</DT
6095 ><DD
6096 ><P
6097 >0 - undocumented</P
6098 ></DD
6099 ><DT
6100 >UINT32</DT
6101 ><DD
6102 ><P
6103 >0 - undocumented</P
6104 ></DD
6105 ></DL
6106 ></DIV
6107 ><P
6108 >return    0x0C00 0034 - "no such secret" success code</P
6109 ></DIV
6110 ></DIV
6111 ><DIV
6112 CLASS="SECT2"
6113 ><HR><H3
6114 CLASS="SECT2"
6115 ><A
6116 NAME="AEN2054"
6117 ></A
6118 >9.3.10. LSA Close</H3
6119 ><DIV
6120 CLASS="SECT3"
6121 ><H4
6122 CLASS="SECT3"
6123 ><A
6124 NAME="AEN2056"
6125 ></A
6126 >9.3.10.1. Request</H4
6127 ><P
6128 ></P
6129 ><DIV
6130 CLASS="VARIABLELIST"
6131 ><DL
6132 ><DT
6133 >POL_HND</DT
6134 ><DD
6135 ><P
6136 >policy handle to be closed</P
6137 ></DD
6138 ></DL
6139 ></DIV
6140 ></DIV
6141 ><DIV
6142 CLASS="SECT3"
6143 ><HR><H4
6144 CLASS="SECT3"
6145 ><A
6146 NAME="AEN2063"
6147 ></A
6148 >9.3.10.2. Response</H4
6149 ><P
6150 ></P
6151 ><DIV
6152 CLASS="VARIABLELIST"
6153 ><DL
6154 ><DT
6155 >POL_HND</DT
6156 ><DD
6157 ><P
6158 >0s - closed policy handle (all zeros)</P
6159 ></DD
6160 ></DL
6161 ></DIV
6162 ><P
6163 >return    0 - indicates success</P
6164 ></DIV
6165 ></DIV
6166 ><DIV
6167 CLASS="SECT2"
6168 ><HR><H3
6169 CLASS="SECT2"
6170 ><A
6171 NAME="AEN2071"
6172 ></A
6173 >9.3.11. LSA Lookup SIDS</H3
6174 ><P
6175 ><SPAN
6176 CLASS="emphasis"
6177 ><I
6178 CLASS="EMPHASIS"
6179 >Note:  num_entries in response must be same as num_entries in request.</I
6180 ></SPAN
6181 ></P
6182 ><DIV
6183 CLASS="SECT3"
6184 ><HR><H4
6185 CLASS="SECT3"
6186 ><A
6187 NAME="AEN2075"
6188 ></A
6189 >9.3.11.1. Request</H4
6190 ><P
6191 ></P
6192 ><DIV
6193 CLASS="VARIABLELIST"
6194 ><DL
6195 ><DT
6196 >POL_HND</DT
6197 ><DD
6198 ><P
6199 >LSA policy handle</P
6200 ></DD
6201 ><DT
6202 >UINT32</DT
6203 ><DD
6204 ><P
6205 >num_entries</P
6206 ></DD
6207 ><DT
6208 >VOID*</DT
6209 ><DD
6210 ><P
6211 >undocumented domain SID buffer pointer</P
6212 ></DD
6213 ><DT
6214 >VOID*</DT
6215 ><DD
6216 ><P
6217 >undocumented domain name buffer pointer</P
6218 ></DD
6219 ><DT
6220 >VOID*[num_entries] undocumented domain SID pointers to be looked up.</DT
6221 ><DD
6222 ><P
6223 >DOM_SID[num_entries] domain SIDs to be looked up.</P
6224 ></DD
6225 ><DT
6226 >char[16]</DT
6227 ><DD
6228 ><P
6229 >completely undocumented 16 bytes.</P
6230 ></DD
6231 ></DL
6232 ></DIV
6233 ></DIV
6234 ><DIV
6235 CLASS="SECT3"
6236 ><HR><H4
6237 CLASS="SECT3"
6238 ><A
6239 NAME="AEN2102"
6240 ></A
6241 >9.3.11.2. Response</H4
6242 ><P
6243 ></P
6244 ><DIV
6245 CLASS="VARIABLELIST"
6246 ><DL
6247 ><DT
6248 >DOM_REF</DT
6249 ><DD
6250 ><P
6251 >domain reference response</P
6252 ></DD
6253 ><DT
6254 >UINT32</DT
6255 ><DD
6256 ><P
6257 >num_entries (listed above)</P
6258 ></DD
6259 ><DT
6260 >VOID*</DT
6261 ><DD
6262 ><P
6263 >undocumented buffer pointer</P
6264 ></DD
6265 ><DT
6266 >UINT32</DT
6267 ><DD
6268 ><P
6269 >num_entries (listed above)</P
6270 ></DD
6271 ><DT
6272 >DOM_SID2[num_entries]</DT
6273 ><DD
6274 ><P
6275 >domain SIDs (from Request, listed above).</P
6276 ></DD
6277 ><DT
6278 >UINT32</DT
6279 ><DD
6280 ><P
6281 >num_entries (listed above)</P
6282 ></DD
6283 ></DL
6284 ></DIV
6285 ><P
6286 >return                0 - indicates success</P
6287 ></DIV
6288 ></DIV
6289 ><DIV
6290 CLASS="SECT2"
6291 ><HR><H3
6292 CLASS="SECT2"
6293 ><A
6294 NAME="AEN2130"
6295 ></A
6296 >9.3.12. LSA Lookup Names</H3
6297 ><P
6298 ><SPAN
6299 CLASS="emphasis"
6300 ><I
6301 CLASS="EMPHASIS"
6302 >Note:  num_entries in response must be same as num_entries in request.</I
6303 ></SPAN
6304 ></P
6305 ><DIV
6306 CLASS="SECT3"
6307 ><HR><H4
6308 CLASS="SECT3"
6309 ><A
6310 NAME="AEN2134"
6311 ></A
6312 >9.3.12.1. Request</H4
6313 ><P
6314 ></P
6315 ><DIV
6316 CLASS="VARIABLELIST"
6317 ><DL
6318 ><DT
6319 >POL_HND</DT
6320 ><DD
6321 ><P
6322 >LSA policy handle</P
6323 ></DD
6324 ><DT
6325 >UINT32</DT
6326 ><DD
6327 ><P
6328 >num_entries</P
6329 ></DD
6330 ><DT
6331 >UINT32</DT
6332 ><DD
6333 ><P
6334 >num_entries</P
6335 ></DD
6336 ><DT
6337 >VOID*</DT
6338 ><DD
6339 ><P
6340 >undocumented domain SID buffer pointer</P
6341 ></DD
6342 ><DT
6343 >VOID*</DT
6344 ><DD
6345 ><P
6346 >undocumented domain name buffer pointer</P
6347 ></DD
6348 ><DT
6349 >NAME[num_entries]</DT
6350 ><DD
6351 ><P
6352 >names to be looked up.</P
6353 ></DD
6354 ><DT
6355 >char[]</DT
6356 ><DD
6357 ><P
6358 >undocumented bytes - falsely translated SID structure?</P
6359 ></DD
6360 ></DL
6361 ></DIV
6362 ></DIV
6363 ><DIV
6364 CLASS="SECT3"
6365 ><HR><H4
6366 CLASS="SECT3"
6367 ><A
6368 NAME="AEN2165"
6369 ></A
6370 >9.3.12.2. Response</H4
6371 ><P
6372 ></P
6373 ><DIV
6374 CLASS="VARIABLELIST"
6375 ><DL
6376 ><DT
6377 >DOM_REF</DT
6378 ><DD
6379 ><P
6380 >domain reference response</P
6381 ></DD
6382 ><DT
6383 >UINT32</DT
6384 ><DD
6385 ><P
6386 >num_entries (listed above)</P
6387 ></DD
6388 ><DT
6389 >VOID*</DT
6390 ><DD
6391 ><P
6392 >undocumented buffer pointer</P
6393 ></DD
6394 ><DT
6395 >UINT32</DT
6396 ><DD
6397 ><P
6398 >num_entries (listed above)</P
6399 ></DD
6400 ><DT
6401 >DOM_RID[num_entries]</DT
6402 ><DD
6403 ><P
6404 >domain SIDs (from Request, listed above).</P
6405 ></DD
6406 ><DT
6407 >UINT32</DT
6408 ><DD
6409 ><P
6410 >num_entries (listed above)</P
6411 ></DD
6412 ></DL
6413 ></DIV
6414 ><P
6415 >return                0 - indicates success</P
6416 ></DIV
6417 ></DIV
6418 ></DIV
6419 ><DIV
6420 CLASS="SECT1"
6421 ><HR><H2
6422 CLASS="SECT1"
6423 ><A
6424 NAME="AEN2193"
6425 ></A
6426 >9.4. NETLOGON rpc Transact Named Pipe</H2
6427 ><P
6428 >The sequence of actions taken on this pipe are:</P
6429 ><P
6430 ></P
6431 ><TABLE
6432 BORDER="0"
6433 ><TBODY
6434 ><TR
6435 ><TD
6436 >tablish a connection to the IPC$ share (SMBtconX).  use encrypted passwords.</TD
6437 ></TR
6438 ><TR
6439 ><TD
6440 >en an RPC Pipe with the name "\\PIPE\\NETLOGON".  Store the file handle.</TD
6441 ></TR
6442 ><TR
6443 ><TD
6444 >ing the file handle, send a Set Named Pipe Handle state to 0x4300.</TD
6445 ></TR
6446 ><TR
6447 ><TD
6448 >eate Client Challenge. Send LSA Request Challenge.  Store Server Challenge.</TD
6449 ></TR
6450 ><TR
6451 ><TD
6452 >lculate Session Key.  Send an LSA Auth 2 Challenge.  Store Auth2 Challenge.</TD
6453 ></TR
6454 ><TR
6455 ><TD
6456 >lc/Verify Client Creds.  Send LSA Srv PW Set.  Calc/Verify Server Creds.</TD
6457 ></TR
6458 ><TR
6459 ><TD
6460 >lc/Verify Client Creds.  Send LSA SAM Logon .  Calc/Verify Server Creds.</TD
6461 ></TR
6462 ><TR
6463 ><TD
6464 >lc/Verify Client Creds.  Send LSA SAM Logoff.  Calc/Verify Server Creds.</TD
6465 ></TR
6466 ><TR
6467 ><TD
6468 >ose the IPC$ share.</TD
6469 ></TR
6470 ></TBODY
6471 ></TABLE
6472 ><P
6473 ></P
6474 ><P
6475 >Defines for this pipe, identifying the query are</P
6476 ><P
6477 ></P
6478 ><DIV
6479 CLASS="VARIABLELIST"
6480 ><DL
6481 ><DT
6482 >LSA Request Challenge:</DT
6483 ><DD
6484 ><P
6485 >0x04</P
6486 ></DD
6487 ><DT
6488 >LSA Server Password Set:</DT
6489 ><DD
6490 ><P
6491 >0x06</P
6492 ></DD
6493 ><DT
6494 >LSA SAM Logon:</DT
6495 ><DD
6496 ><P
6497 >0x02</P
6498 ></DD
6499 ><DT
6500 >LSA SAM Logoff:</DT
6501 ><DD
6502 ><P
6503 >0x03</P
6504 ></DD
6505 ><DT
6506 >LSA Auth 2:</DT
6507 ><DD
6508 ><P
6509 >0x0f</P
6510 ></DD
6511 ><DT
6512 >LSA Logon Control:</DT
6513 ><DD
6514 ><P
6515 >0x0e</P
6516 ></DD
6517 ></DL
6518 ></DIV
6519 ><DIV
6520 CLASS="SECT2"
6521 ><HR><H3
6522 CLASS="SECT2"
6523 ><A
6524 NAME="AEN2232"
6525 ></A
6526 >9.4.1. LSA Request Challenge</H3
6527 ><P
6528 ><SPAN
6529 CLASS="emphasis"
6530 ><I
6531 CLASS="EMPHASIS"
6532 >Note:  logon server name starts with two '\' characters and is upper case.</I
6533 ></SPAN
6534 ></P
6535 ><P
6536 ><SPAN
6537 CLASS="emphasis"
6538 ><I
6539 CLASS="EMPHASIS"
6540 >Note:  logon client is the machine, not the user.</I
6541 ></SPAN
6542 ></P
6543 ><P
6544 ><SPAN
6545 CLASS="emphasis"
6546 ><I
6547 CLASS="EMPHASIS"
6548 >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
6549 ></SPAN
6550 ></P
6551 ><DIV
6552 CLASS="SECT3"
6553 ><HR><H4
6554 CLASS="SECT3"
6555 ><A
6556 NAME="AEN2240"
6557 ></A
6558 >9.4.1.1. Request</H4
6559 ><P
6560 ></P
6561 ><DIV
6562 CLASS="VARIABLELIST"
6563 ><DL
6564 ><DT
6565 >VOID*</DT
6566 ><DD
6567 ><P
6568 >undocumented buffer pointer</P
6569 ></DD
6570 ><DT
6571 >UNISTR2</DT
6572 ><DD
6573 ><P
6574 >logon server unicode string</P
6575 ></DD
6576 ><DT
6577 >UNISTR2</DT
6578 ><DD
6579 ><P
6580 >logon client unicode string</P
6581 ></DD
6582 ><DT
6583 >char[8]</DT
6584 ><DD
6585 ><P
6586 >client challenge</P
6587 ></DD
6588 ></DL
6589 ></DIV
6590 ></DIV
6591 ><DIV
6592 CLASS="SECT3"
6593 ><HR><H4
6594 CLASS="SECT3"
6595 ><A
6596 NAME="AEN2259"
6597 ></A
6598 >9.4.1.2. Response</H4
6599 ><P
6600 ></P
6601 ><DIV
6602 CLASS="VARIABLELIST"
6603 ><DL
6604 ><DT
6605 >char[8]</DT
6606 ><DD
6607 ><P
6608 >server challenge</P
6609 ></DD
6610 ></DL
6611 ></DIV
6612 ><P
6613 >return    0 - indicates success</P
6614 ></DIV
6615 ></DIV
6616 ><DIV
6617 CLASS="SECT2"
6618 ><HR><H3
6619 CLASS="SECT2"
6620 ><A
6621 NAME="AEN2267"
6622 ></A
6623 >9.4.2. LSA Authenticate 2</H3
6624 ><P
6625 ><SPAN
6626 CLASS="emphasis"
6627 ><I
6628 CLASS="EMPHASIS"
6629 >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
6630 ></SPAN
6631 ></P
6632 ><P
6633 ><SPAN
6634 CLASS="emphasis"
6635 ><I
6636 CLASS="EMPHASIS"
6637 >Note:  neg_flags in the response is the same as that in the request.</I
6638 ></SPAN
6639 ></P
6640 ><P
6641 ><SPAN
6642 CLASS="emphasis"
6643 ><I
6644 CLASS="EMPHASIS"
6645 >Note:  you must take a copy of the client-calculated credentials received      here, because they will be used in subsequent authentication packets.</I
6646 ></SPAN
6647 ></P
6648 ><DIV
6649 CLASS="SECT3"
6650 ><HR><H4
6651 CLASS="SECT3"
6652 ><A
6653 NAME="AEN2275"
6654 ></A
6655 >9.4.2.1. Request</H4
6656 ><P
6657 ></P
6658 ><DIV
6659 CLASS="VARIABLELIST"
6660 ><DL
6661 ><DT
6662 >LOG_INFO</DT
6663 ><DD
6664 ><P
6665 >client identification info</P
6666 ></DD
6667 ><DT
6668 >char[8]</DT
6669 ><DD
6670 ><P
6671 >client-calculated credentials</P
6672 ></DD
6673 ><DT
6674 >UINT8[]</DT
6675 ><DD
6676 ><P
6677 >padding to 4-byte align with start of SMB header.</P
6678 ></DD
6679 ><DT
6680 >UINT32</DT
6681 ><DD
6682 ><P
6683 >neg_flags - negotiated flags (usual value is 0x0000 01ff)</P
6684 ></DD
6685 ></DL
6686 ></DIV
6687 ></DIV
6688 ><DIV
6689 CLASS="SECT3"
6690 ><HR><H4
6691 CLASS="SECT3"
6692 ><A
6693 NAME="AEN2294"
6694 ></A
6695 >9.4.2.2. Response</H4
6696 ><P
6697 ></P
6698 ><DIV
6699 CLASS="VARIABLELIST"
6700 ><DL
6701 ><DT
6702 >char[8]</DT
6703 ><DD
6704 ><P
6705 >server credentials.</P
6706 ></DD
6707 ><DT
6708 >UINT32</DT
6709 ><DD
6710 ><P
6711 >neg_flags - same as neg_flags in request.</P
6712 ></DD
6713 ></DL
6714 ></DIV
6715 ><P
6716 >return    0 - indicates success.  failure value unknown.</P
6717 ></DIV
6718 ></DIV
6719 ><DIV
6720 CLASS="SECT2"
6721 ><HR><H3
6722 CLASS="SECT2"
6723 ><A
6724 NAME="AEN2306"
6725 ></A
6726 >9.4.3. LSA Server Password Set</H3
6727 ><P
6728 ><SPAN
6729 CLASS="emphasis"
6730 ><I
6731 CLASS="EMPHASIS"
6732 >Note: the new password is suspected to be a DES encryption using the old password to generate the key.</I
6733 ></SPAN
6734 ></P
6735 ><P
6736 ><SPAN
6737 CLASS="emphasis"
6738 ><I
6739 CLASS="EMPHASIS"
6740 >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
6741 ></SPAN
6742 ></P
6743 ><P
6744 ><SPAN
6745 CLASS="emphasis"
6746 ><I
6747 CLASS="EMPHASIS"
6748 >Note: the server credentials are constructed from the client-calculated credentials and the client time + 1 second.</I
6749 ></SPAN
6750 ></P
6751 ><P
6752 ><SPAN
6753 CLASS="emphasis"
6754 ><I
6755 CLASS="EMPHASIS"
6756 >Note: you must take a copy of the client-calculated credentials received here, because they will be used in subsequent authentication packets.</I
6757 ></SPAN
6758 ></P
6759 ><DIV
6760 CLASS="SECT3"
6761 ><HR><H4
6762 CLASS="SECT3"
6763 ><A
6764 NAME="AEN2316"
6765 ></A
6766 >9.4.3.1. Request</H4
6767 ><P
6768 ></P
6769 ><DIV
6770 CLASS="VARIABLELIST"
6771 ><DL
6772 ><DT
6773 >CLNT_INFO</DT
6774 ><DD
6775 ><P
6776 >client identification/authentication info</P
6777 ></DD
6778 ><DT
6779 >char[]</DT
6780 ><DD
6781 ><P
6782 >new password - undocumented.</P
6783 ></DD
6784 ></DL
6785 ></DIV
6786 ></DIV
6787 ><DIV
6788 CLASS="SECT3"
6789 ><HR><H4
6790 CLASS="SECT3"
6791 ><A
6792 NAME="AEN2327"
6793 ></A
6794 >9.4.3.2. Response</H4
6795 ><P
6796 ></P
6797 ><DIV
6798 CLASS="VARIABLELIST"
6799 ><DL
6800 ><DT
6801 >CREDS</DT
6802 ><DD
6803 ><P
6804 >server credentials.  server time stamp appears to be ignored.</P
6805 ></DD
6806 ></DL
6807 ></DIV
6808 ><P
6809 >return    0 - indicates success; 0xC000 006a indicates failure</P
6810 ></DIV
6811 ></DIV
6812 ><DIV
6813 CLASS="SECT2"
6814 ><HR><H3
6815 CLASS="SECT2"
6816 ><A
6817 NAME="AEN2335"
6818 ></A
6819 >9.4.4. LSA SAM Logon</H3
6820 ><P
6821 ><SPAN
6822 CLASS="emphasis"
6823 ><I
6824 CLASS="EMPHASIS"
6825 >Note:  valid_user is True iff the username and password hash are valid for
6826         the requested domain.</I
6827 ></SPAN
6828 ></P
6829 ><DIV
6830 CLASS="SECT3"
6831 ><HR><H4
6832 CLASS="SECT3"
6833 ><A
6834 NAME="AEN2339"
6835 ></A
6836 >9.4.4.1. Request</H4
6837 ><P
6838 ></P
6839 ><DIV
6840 CLASS="VARIABLELIST"
6841 ><DL
6842 ><DT
6843 >SAM_INFO</DT
6844 ><DD
6845 ><P
6846 >sam_id structure</P
6847 ></DD
6848 ></DL
6849 ></DIV
6850 ></DIV
6851 ><DIV
6852 CLASS="SECT3"
6853 ><HR><H4
6854 CLASS="SECT3"
6855 ><A
6856 NAME="AEN2346"
6857 ></A
6858 >9.4.4.2. Response</H4
6859 ><P
6860 ></P
6861 ><DIV
6862 CLASS="VARIABLELIST"
6863 ><DL
6864 ><DT
6865 >VOID*</DT
6866 ><DD
6867 ><P
6868 >undocumented buffer pointer</P
6869 ></DD
6870 ><DT
6871 >CREDS</DT
6872 ><DD
6873 ><P
6874 >server credentials.  server time stamp appears to be ignored.</P
6875 ></DD
6876 ></DL
6877 ></DIV
6878 ><P
6879 ><PRE
6880 CLASS="PROGRAMLISTING"
6881 >if (valid_user)
6882 {
6883         UINT16      3 - switch value indicating USER_INFO structure.
6884     VOID*     non-zero - pointer to USER_INFO structure
6885     USER_INFO user logon information
6886
6887     UINT32    1 - Authoritative response; 0 - Non-Auth?
6888
6889     return    0 - indicates success
6890 }
6891 else
6892 {
6893         UINT16    0 - switch value.  value to indicate no user presumed.
6894     VOID*     0x0000 0000 - indicates no USER_INFO structure.
6895
6896     UINT32    1 - Authoritative response; 0 - Non-Auth?
6897
6898     return    0xC000 0064 - NT_STATUS_NO_SUCH_USER.
6899 }</PRE
6900 ></P
6901 ></DIV
6902 ></DIV
6903 ><DIV
6904 CLASS="SECT2"
6905 ><HR><H3
6906 CLASS="SECT2"
6907 ><A
6908 NAME="AEN2359"
6909 ></A
6910 >9.4.5. LSA SAM Logoff</H3
6911 ><P
6912 ><SPAN
6913 CLASS="emphasis"
6914 ><I
6915 CLASS="EMPHASIS"
6916 >Note:  presumably, the SAM_INFO structure is validated, and a (currently
6917         undocumented) error code returned if the Logoff is invalid.</I
6918 ></SPAN
6919 ></P
6920 ><DIV
6921 CLASS="SECT3"
6922 ><HR><H4
6923 CLASS="SECT3"
6924 ><A
6925 NAME="AEN2363"
6926 ></A
6927 >9.4.5.1. Request</H4
6928 ><P
6929 ></P
6930 ><DIV
6931 CLASS="VARIABLELIST"
6932 ><DL
6933 ><DT
6934 >SAM_INFO</DT
6935 ><DD
6936 ><P
6937 >sam_id structure</P
6938 ></DD
6939 ></DL
6940 ></DIV
6941 ></DIV
6942 ><DIV
6943 CLASS="SECT3"
6944 ><HR><H4
6945 CLASS="SECT3"
6946 ><A
6947 NAME="AEN2370"
6948 ></A
6949 >9.4.5.2. Response</H4
6950 ><P
6951 ></P
6952 ><DIV
6953 CLASS="VARIABLELIST"
6954 ><DL
6955 ><DT
6956 >VOID*</DT
6957 ><DD
6958 ><P
6959 >undocumented buffer pointer</P
6960 ></DD
6961 ><DT
6962 >CREDS</DT
6963 ><DD
6964 ><P
6965 >server credentials.  server time stamp appears to be ignored.</P
6966 ></DD
6967 ></DL
6968 ></DIV
6969 ><P
6970 >return      0 - indicates success.  undocumented failure indication.</P
6971 ></DIV
6972 ></DIV
6973 ></DIV
6974 ><DIV
6975 CLASS="SECT1"
6976 ><HR><H2
6977 CLASS="SECT1"
6978 ><A
6979 NAME="AEN2382"
6980 ></A
6981 >9.5. \\MAILSLOT\NET\NTLOGON</H2
6982 ><P
6983 ><SPAN
6984 CLASS="emphasis"
6985 ><I
6986 CLASS="EMPHASIS"
6987 >Note:  mailslots will contain a response mailslot, to which the response
6988         should be sent.  the target NetBIOS name is REQUEST_NAME&#60;20&#62;, where
6989         REQUEST_NAME is the name of the machine that sent the request.</I
6990 ></SPAN
6991 ></P
6992 ><DIV
6993 CLASS="SECT2"
6994 ><HR><H3
6995 CLASS="SECT2"
6996 ><A
6997 NAME="AEN2386"
6998 ></A
6999 >9.5.1. Query for PDC</H3
7000 ><P
7001 ><SPAN
7002 CLASS="emphasis"
7003 ><I
7004 CLASS="EMPHASIS"
7005 >Note:  NTversion, LMNTtoken, LM20token in response are the same as those       given in the request.</I
7006 ></SPAN
7007 ></P
7008 ><DIV
7009 CLASS="SECT3"
7010 ><HR><H4
7011 CLASS="SECT3"
7012 ><A
7013 NAME="AEN2390"
7014 ></A
7015 >9.5.1.1. Request</H4
7016 ><P
7017 ></P
7018 ><DIV
7019 CLASS="VARIABLELIST"
7020 ><DL
7021 ><DT
7022 >UINT16</DT
7023 ><DD
7024 ><P
7025 >0x0007 - Query for PDC</P
7026 ></DD
7027 ><DT
7028 >STR</DT
7029 ><DD
7030 ><P
7031 >machine name</P
7032 ></DD
7033 ><DT
7034 >STR</DT
7035 ><DD
7036 ><P
7037 >response mailslot</P
7038 ></DD
7039 ><DT
7040 >UINT8[]</DT
7041 ><DD
7042 ><P
7043 >padding to 2-byte align with start of mailslot.</P
7044 ></DD
7045 ><DT
7046 >UNISTR</DT
7047 ><DD
7048 ><P
7049 >machine name</P
7050 ></DD
7051 ><DT
7052 >UINT32</DT
7053 ><DD
7054 ><P
7055 >NTversion</P
7056 ></DD
7057 ><DT
7058 >UINT16</DT
7059 ><DD
7060 ><P
7061 >LMNTtoken</P
7062 ></DD
7063 ><DT
7064 >UINT16</DT
7065 ><DD
7066 ><P
7067 >LM20token</P
7068 ></DD
7069 ></DL
7070 ></DIV
7071 ></DIV
7072 ><DIV
7073 CLASS="SECT3"
7074 ><HR><H4
7075 CLASS="SECT3"
7076 ><A
7077 NAME="AEN2425"
7078 ></A
7079 >9.5.1.2. Response</H4
7080 ><P
7081 ></P
7082 ><DIV
7083 CLASS="VARIABLELIST"
7084 ><DL
7085 ><DT
7086 >UINT16</DT
7087 ><DD
7088 ><P
7089 >0x000A - Respose to Query for PDC</P
7090 ></DD
7091 ><DT
7092 >STR</DT
7093 ><DD
7094 ><P
7095 >machine name (in uppercase)</P
7096 ></DD
7097 ><DT
7098 >UINT8[]</DT
7099 ><DD
7100 ><P
7101 >padding to 2-byte align with start of mailslot.</P
7102 ></DD
7103 ><DT
7104 >UNISTR</DT
7105 ><DD
7106 ><P
7107 >machine name</P
7108 ></DD
7109 ><DT
7110 >UNISTR</DT
7111 ><DD
7112 ><P
7113 >domain name</P
7114 ></DD
7115 ><DT
7116 >UINT32</DT
7117 ><DD
7118 ><P
7119 >NTversion (same as received in request)</P
7120 ></DD
7121 ><DT
7122 >UINT16</DT
7123 ><DD
7124 ><P
7125 >LMNTtoken (same as received in request)</P
7126 ></DD
7127 ><DT
7128 >UINT16</DT
7129 ><DD
7130 ><P
7131 >LM20token (same as received in request)</P
7132 ></DD
7133 ></DL
7134 ></DIV
7135 ></DIV
7136 ></DIV
7137 ><DIV
7138 CLASS="SECT2"
7139 ><HR><H3
7140 CLASS="SECT2"
7141 ><A
7142 NAME="AEN2460"
7143 ></A
7144 >9.5.2. SAM Logon</H3
7145 ><P
7146 ><SPAN
7147 CLASS="emphasis"
7148 ><I
7149 CLASS="EMPHASIS"
7150 >Note: machine name in response is preceded by two '\' characters.</I
7151 ></SPAN
7152 ></P
7153 ><P
7154 ><SPAN
7155 CLASS="emphasis"
7156 ><I
7157 CLASS="EMPHASIS"
7158 >Note:  NTversion, LMNTtoken, LM20token in response are the same as those given in the request.</I
7159 ></SPAN
7160 ></P
7161 ><P
7162 ><SPAN
7163 CLASS="emphasis"
7164 ><I
7165 CLASS="EMPHASIS"
7166 >Note:  user name in the response is presumably the same as that in the request.</I
7167 ></SPAN
7168 ></P
7169 ><DIV
7170 CLASS="SECT3"
7171 ><HR><H4
7172 CLASS="SECT3"
7173 ><A
7174 NAME="AEN2468"
7175 ></A
7176 >9.5.2.1. Request</H4
7177 ><P
7178 ></P
7179 ><DIV
7180 CLASS="VARIABLELIST"
7181 ><DL
7182 ><DT
7183 >UINT16</DT
7184 ><DD
7185 ><P
7186 >0x0012 - SAM Logon</P
7187 ></DD
7188 ><DT
7189 >UINT16</DT
7190 ><DD
7191 ><P
7192 >request count</P
7193 ></DD
7194 ><DT
7195 >UNISTR</DT
7196 ><DD
7197 ><P
7198 >machine name</P
7199 ></DD
7200 ><DT
7201 >UNISTR</DT
7202 ><DD
7203 ><P
7204 >user name</P
7205 ></DD
7206 ><DT
7207 >STR</DT
7208 ><DD
7209 ><P
7210 >response mailslot</P
7211 ></DD
7212 ><DT
7213 >UINT32</DT
7214 ><DD
7215 ><P
7216 >alloweable account</P
7217 ></DD
7218 ><DT
7219 >UINT32</DT
7220 ><DD
7221 ><P
7222 >domain SID size</P
7223 ></DD
7224 ><DT
7225 >char[sid_size]</DT
7226 ><DD
7227 ><P
7228 >domain SID, of sid_size bytes.</P
7229 ></DD
7230 ><DT
7231 >UINT8[]</DT
7232 ><DD
7233 ><P
7234 >???? padding to 4? 2? -byte align with start of mailslot.</P
7235 ></DD
7236 ><DT
7237 >UINT32</DT
7238 ><DD
7239 ><P
7240 >NTversion</P
7241 ></DD
7242 ><DT
7243 >UINT16</DT
7244 ><DD
7245 ><P
7246 >LMNTtoken</P
7247 ></DD
7248 ><DT
7249 >UINT16</DT
7250 ><DD
7251 ><P
7252 >LM20token</P
7253 ></DD
7254 ></DL
7255 ></DIV
7256 ></DIV
7257 ><DIV
7258 CLASS="SECT3"
7259 ><HR><H4
7260 CLASS="SECT3"
7261 ><A
7262 NAME="AEN2519"
7263 ></A
7264 >9.5.2.2. Response</H4
7265 ><P
7266 ></P
7267 ><DIV
7268 CLASS="VARIABLELIST"
7269 ><DL
7270 ><DT
7271 >UINT16</DT
7272 ><DD
7273 ><P
7274 >0x0013 - Response to SAM Logon</P
7275 ></DD
7276 ><DT
7277 >UNISTR</DT
7278 ><DD
7279 ><P
7280 >machine name</P
7281 ></DD
7282 ><DT
7283 >UNISTR</DT
7284 ><DD
7285 ><P
7286 >user name - workstation trust account</P
7287 ></DD
7288 ><DT
7289 >UNISTR</DT
7290 ><DD
7291 ><P
7292 >domain name </P
7293 ></DD
7294 ><DT
7295 >UINT32</DT
7296 ><DD
7297 ><P
7298 >NTversion</P
7299 ></DD
7300 ><DT
7301 >UINT16</DT
7302 ><DD
7303 ><P
7304 >LMNTtoken</P
7305 ></DD
7306 ><DT
7307 >UINT16</DT
7308 ><DD
7309 ><P
7310 >LM20token</P
7311 ></DD
7312 ></DL
7313 ></DIV
7314 ></DIV
7315 ></DIV
7316 ></DIV
7317 ><DIV
7318 CLASS="SECT1"
7319 ><HR><H2
7320 CLASS="SECT1"
7321 ><A
7322 NAME="AEN2550"
7323 ></A
7324 >9.6. SRVSVC Transact Named Pipe</H2
7325 ><P
7326 >Defines for this pipe, identifying the query are:</P
7327 ><P
7328 ></P
7329 ><DIV
7330 CLASS="VARIABLELIST"
7331 ><DL
7332 ><DT
7333 >Net Share Enum</DT
7334 ><DD
7335 ><P
7336 >0x0f</P
7337 ></DD
7338 ><DT
7339 >Net Server Get Info</DT
7340 ><DD
7341 ><P
7342 >0x15</P
7343 ></DD
7344 ></DL
7345 ></DIV
7346 ><DIV
7347 CLASS="SECT2"
7348 ><HR><H3
7349 CLASS="SECT2"
7350 ><A
7351 NAME="AEN2562"
7352 ></A
7353 >9.6.1. Net Share Enum</H3
7354 ><P
7355 ><SPAN
7356 CLASS="emphasis"
7357 ><I
7358 CLASS="EMPHASIS"
7359 >Note:  share level and switch value in the response are presumably the same as those in the request.</I
7360 ></SPAN
7361 ></P
7362 ><P
7363 ><SPAN
7364 CLASS="emphasis"
7365 ><I
7366 CLASS="EMPHASIS"
7367 >Note:  cifsrap2.txt (section 5) may be of limited assistance here.</I
7368 ></SPAN
7369 ></P
7370 ><DIV
7371 CLASS="SECT3"
7372 ><HR><H4
7373 CLASS="SECT3"
7374 ><A
7375 NAME="AEN2568"
7376 ></A
7377 >9.6.1.1. Request</H4
7378 ><P
7379 ></P
7380 ><DIV
7381 CLASS="VARIABLELIST"
7382 ><DL
7383 ><DT
7384 >VOID*</DT
7385 ><DD
7386 ><P
7387 >pointer (to server name?)</P
7388 ></DD
7389 ><DT
7390 >UNISTR2</DT
7391 ><DD
7392 ><P
7393 >server name</P
7394 ></DD
7395 ><DT
7396 >UINT8[]</DT
7397 ><DD
7398 ><P
7399 >padding to get unicode string 4-byte aligned with the start of the SMB header.</P
7400 ></DD
7401 ><DT
7402 >UINT32</DT
7403 ><DD
7404 ><P
7405 >share level</P
7406 ></DD
7407 ><DT
7408 >UINT32</DT
7409 ><DD
7410 ><P
7411 >switch value</P
7412 ></DD
7413 ><DT
7414 >VOID*</DT
7415 ><DD
7416 ><P
7417 >pointer to SHARE_INFO_1_CTR</P
7418 ></DD
7419 ><DT
7420 >SHARE_INFO_1_CTR</DT
7421 ><DD
7422 ><P
7423 >share info with 0 entries</P
7424 ></DD
7425 ><DT
7426 >UINT32</DT
7427 ><DD
7428 ><P
7429 >preferred maximum length (0xffff ffff)</P
7430 ></DD
7431 ></DL
7432 ></DIV
7433 ></DIV
7434 ><DIV
7435 CLASS="SECT3"
7436 ><HR><H4
7437 CLASS="SECT3"
7438 ><A
7439 NAME="AEN2603"
7440 ></A
7441 >9.6.1.2. Response</H4
7442 ><P
7443 ></P
7444 ><DIV
7445 CLASS="VARIABLELIST"
7446 ><DL
7447 ><DT
7448 >UINT32</DT
7449 ><DD
7450 ><P
7451 >share level</P
7452 ></DD
7453 ><DT
7454 >UINT32</DT
7455 ><DD
7456 ><P
7457 >switch value</P
7458 ></DD
7459 ><DT
7460 >VOID*</DT
7461 ><DD
7462 ><P
7463 >pointer to SHARE_INFO_1_CTR</P
7464 ></DD
7465 ><DT
7466 >SHARE_INFO_1_CTR</DT
7467 ><DD
7468 ><P
7469 >share info (only added if share info ptr is non-zero)</P
7470 ></DD
7471 ></DL
7472 ></DIV
7473 ><P
7474 >return            0 - indicates success</P
7475 ></DIV
7476 ></DIV
7477 ><DIV
7478 CLASS="SECT2"
7479 ><HR><H3
7480 CLASS="SECT2"
7481 ><A
7482 NAME="AEN2623"
7483 ></A
7484 >9.6.2. Net Server Get Info</H3
7485 ><P
7486 ><SPAN
7487 CLASS="emphasis"
7488 ><I
7489 CLASS="EMPHASIS"
7490 >Note:  level is the same value as in the request.</I
7491 ></SPAN
7492 ></P
7493 ><DIV
7494 CLASS="SECT3"
7495 ><HR><H4
7496 CLASS="SECT3"
7497 ><A
7498 NAME="AEN2627"
7499 ></A
7500 >9.6.2.1. Request</H4
7501 ><P
7502 ></P
7503 ><DIV
7504 CLASS="VARIABLELIST"
7505 ><DL
7506 ><DT
7507 >UNISTR2</DT
7508 ><DD
7509 ><P
7510 >server name</P
7511 ></DD
7512 ><DT
7513 >UINT32</DT
7514 ><DD
7515 ><P
7516 >switch level</P
7517 ></DD
7518 ></DL
7519 ></DIV
7520 ></DIV
7521 ><DIV
7522 CLASS="SECT3"
7523 ><HR><H4
7524 CLASS="SECT3"
7525 ><A
7526 NAME="AEN2638"
7527 ></A
7528 >9.6.2.2. Response</H4
7529 ><P
7530 ></P
7531 ><DIV
7532 CLASS="VARIABLELIST"
7533 ><DL
7534 ><DT
7535 >UINT32</DT
7536 ><DD
7537 ><P
7538 >switch level</P
7539 ></DD
7540 ><DT
7541 >VOID*</DT
7542 ><DD
7543 ><P
7544 >pointer to SERVER_INFO_101</P
7545 ></DD
7546 ><DT
7547 >SERVER_INFO_101</DT
7548 ><DD
7549 ><P
7550 >server info (only added if server info ptr is non-zero)</P
7551 ></DD
7552 ></DL
7553 ></DIV
7554 ><P
7555 >return            0 - indicates success</P
7556 ></DIV
7557 ></DIV
7558 ></DIV
7559 ><DIV
7560 CLASS="SECT1"
7561 ><HR><H2
7562 CLASS="SECT1"
7563 ><A
7564 NAME="AEN2654"
7565 ></A
7566 >9.7. Cryptographic side of NT Domain Authentication</H2
7567 ><DIV
7568 CLASS="SECT2"
7569 ><H3
7570 CLASS="SECT2"
7571 ><A
7572 NAME="AEN2656"
7573 ></A
7574 >9.7.1. Definitions</H3
7575 ><P
7576 ></P
7577 ><DIV
7578 CLASS="VARIABLELIST"
7579 ><DL
7580 ><DT
7581 >Add(A1,A2)</DT
7582 ><DD
7583 ><P
7584 >Intel byte ordered addition of corresponding 4 byte words in arrays A1 and A2</P
7585 ></DD
7586 ><DT
7587 >E(K,D)</DT
7588 ><DD
7589 ><P
7590 >DES ECB encryption of 8 byte data D using 7 byte key K</P
7591 ></DD
7592 ><DT
7593 >lmowf()</DT
7594 ><DD
7595 ><P
7596 >Lan man hash</P
7597 ></DD
7598 ><DT
7599 >ntowf()</DT
7600 ><DD
7601 ><P
7602 >NT hash</P
7603 ></DD
7604 ><DT
7605 >PW</DT
7606 ><DD
7607 ><P
7608 >md4(machine_password) == md4(lsadump $machine.acc) ==
7609 pwdump(machine$) (initially) == md4(lmowf(unicode(machine)))</P
7610 ></DD
7611 ><DT
7612 >ARC4(K,Lk,D,Ld)</DT
7613 ><DD
7614 ><P
7615 >ARC4 encryption of data D of length Ld with key K of length Lk</P
7616 ></DD
7617 ><DT
7618 >v[m..n(,l)]</DT
7619 ><DD
7620 ><P
7621 >subset of v from bytes m to n, optionally padded with zeroes to length l</P
7622 ></DD
7623 ><DT
7624 >Cred(K,D)</DT
7625 ><DD
7626 ><P
7627 >E(K[7..7,7],E(K[0..6],D)) computes a credential</P
7628 ></DD
7629 ><DT
7630 >Time()</DT
7631 ><DD
7632 ><P
7633 >4 byte current time</P
7634 ></DD
7635 ><DT
7636 >Cc,Cs</DT
7637 ><DD
7638 ><P
7639 >8 byte client and server challenges Rc,Rs: 8 byte client and server credentials</P
7640 ></DD
7641 ></DL
7642 ></DIV
7643 ></DIV
7644 ><DIV
7645 CLASS="SECT2"
7646 ><HR><H3
7647 CLASS="SECT2"
7648 ><A
7649 NAME="AEN2699"
7650 ></A
7651 >9.7.2. Protocol</H3
7652 ><P
7653 >C-&#62;S ReqChal,Cc S-&#62;C Cs</P
7654 ><P
7655 >C &#38; S compute session key Ks = E(PW[9..15],E(PW[0..6],Add(Cc,Cs)))</P
7656 ><P
7657 >C: Rc = Cred(Ks,Cc) C-&#62;S Authenticate,Rc S: Rs = Cred(Ks,Cs),
7658 assert(Rc == Cred(Ks,Cc)) S-&#62;C Rs C: assert(Rs == Cred(Ks,Cs))</P
7659 ><P
7660 >On joining the domain the client will optionally attempt to change its
7661 password and the domain controller may refuse to update it depending
7662 on registry settings. This will also occur weekly afterwards.</P
7663 ><P
7664 >C: Tc = Time(), Rc' = Cred(Ks,Rc+Tc) C-&#62;S ServerPasswordSet,Rc',Tc,
7665 arc4(Ks[0..7,16],lmowf(randompassword()) C: Rc = Cred(Ks,Rc+Tc+1) S:
7666 assert(Rc' == Cred(Ks,Rc+Tc)), Ts = Time() S: Rs' = Cred(Ks,Rs+Tc+1)
7667 S-&#62;C Rs',Ts C: assert(Rs' == Cred(Ks,Rs+Tc+1)) S: Rs = Rs'</P
7668 ><P
7669 >User: U with password P wishes to login to the domain (incidental data
7670 such as workstation and domain omitted)</P
7671 ><P
7672 >C: Tc = Time(), Rc' = Cred(Ks,Rc+Tc) C-&#62;S NetLogonSamLogon,Rc',Tc,U,
7673 arc4(Ks[0..7,16],16,ntowf(P),16), arc4(Ks[0..7,16],16,lmowf(P),16) S:
7674 assert(Rc' == Cred(Ks,Rc+Tc)) assert(passwords match those in SAM) S:
7675 Ts = Time()</P
7676 ><P
7677 >S-&#62;C Cred(Ks,Cred(Ks,Rc+Tc+1)),userinfo(logon script,UID,SIDs,etc) C:
7678 assert(Rs == Cred(Ks,Cred(Rc+Tc+1)) C: Rc = Cred(Ks,Rc+Tc+1)</P
7679 ></DIV
7680 ><DIV
7681 CLASS="SECT2"
7682 ><HR><H3
7683 CLASS="SECT2"
7684 ><A
7685 NAME="AEN2709"
7686 ></A
7687 >9.7.3. Comments</H3
7688 ><P
7689 >On first joining the domain the session key could be computed by
7690 anyone listening in on the network as the machine password has a well
7691 known value. Until the machine is rebooted it will use this session
7692 key to encrypt NT and LM one way functions of passwords which are
7693 password equivalents. Any user who logs in before the machine has been
7694 rebooted a second time will have their password equivalent exposed. Of
7695 course the new machine password is exposed at this time anyway.</P
7696 ><P
7697 >None of the returned user info such as logon script, profile path and
7698 SIDs *appear* to be protected by anything other than the TCP checksum.</P
7699 ><P
7700 >The server time stamps appear to be ignored.</P
7701 ><P
7702 >The client sends a ReturnAuthenticator in the SamLogon request which I
7703 can't find a use for.  However its time is used as the timestamp
7704 returned by the server.</P
7705 ><P
7706 >The password OWFs should NOT be sent over the network reversibly
7707 encrypted. They should be sent using ARC4(Ks,md4(owf)) with the server
7708 computing the same function using the owf values in the SAM.</P
7709 ></DIV
7710 ></DIV
7711 ><DIV
7712 CLASS="SECT1"
7713 ><HR><H2
7714 CLASS="SECT1"
7715 ><A
7716 NAME="AEN2716"
7717 ></A
7718 >9.8. SIDs and RIDs</H2
7719 ><P
7720 >SIDs and RIDs are well documented elsewhere.</P
7721 ><P
7722 >A SID is an NT Security ID (see DOM_SID structure).  They are of the form:</P
7723 ><P
7724 ></P
7725 ><TABLE
7726 BORDER="0"
7727 ><TBODY
7728 ><TR
7729 ><TD
7730 >revision-NN-SubAuth1-SubAuth2-SubAuth3... </TD
7731 ></TR
7732 ><TR
7733 ><TD
7734 >revision-0xNNNNNNNNNNNN-SubAuth1-SubAuth2-SubAuth3...</TD
7735 ></TR
7736 ></TBODY
7737 ></TABLE
7738 ><P
7739 ></P
7740 ><P
7741 >currently, the SID revision is 1.
7742 The Sub-Authorities are known as Relative IDs (RIDs).</P
7743 ><DIV
7744 CLASS="SECT2"
7745 ><HR><H3
7746 CLASS="SECT2"
7747 ><A
7748 NAME="AEN2724"
7749 ></A
7750 >9.8.1. Well-known SIDs</H3
7751 ><DIV
7752 CLASS="SECT3"
7753 ><H4
7754 CLASS="SECT3"
7755 ><A
7756 NAME="AEN2726"
7757 ></A
7758 >9.8.1.1. Universal well-known SIDs</H4
7759 ><P
7760 ></P
7761 ><DIV
7762 CLASS="VARIABLELIST"
7763 ><DL
7764 ><DT
7765 >Null SID</DT
7766 ><DD
7767 ><P
7768 >S-1-0-0</P
7769 ></DD
7770 ><DT
7771 >World</DT
7772 ><DD
7773 ><P
7774 >S-1-1-0</P
7775 ></DD
7776 ><DT
7777 >Local</DT
7778 ><DD
7779 ><P
7780 >S-1-2-0</P
7781 ></DD
7782 ><DT
7783 >Creator Owner ID</DT
7784 ><DD
7785 ><P
7786 >S-1-3-0</P
7787 ></DD
7788 ><DT
7789 >Creator Group ID</DT
7790 ><DD
7791 ><P
7792 >S-1-3-1</P
7793 ></DD
7794 ><DT
7795 >Creator Owner Server ID</DT
7796 ><DD
7797 ><P
7798 >S-1-3-2</P
7799 ></DD
7800 ><DT
7801 >Creator Group Server ID</DT
7802 ><DD
7803 ><P
7804 >S-1-3-3</P
7805 ></DD
7806 ><DT
7807 >(Non-unique IDs)</DT
7808 ><DD
7809 ><P
7810 >S-1-4</P
7811 ></DD
7812 ></DL
7813 ></DIV
7814 ></DIV
7815 ><DIV
7816 CLASS="SECT3"
7817 ><HR><H4
7818 CLASS="SECT3"
7819 ><A
7820 NAME="AEN2761"
7821 ></A
7822 >9.8.1.2. NT well-known SIDs</H4
7823 ><P
7824 ></P
7825 ><DIV
7826 CLASS="VARIABLELIST"
7827 ><DL
7828 ><DT
7829 >NT Authority</DT
7830 ><DD
7831 ><P
7832 >S-1-5</P
7833 ></DD
7834 ><DT
7835 >Dialup</DT
7836 ><DD
7837 ><P
7838 >S-1-5-1</P
7839 ></DD
7840 ><DT
7841 >Network</DT
7842 ><DD
7843 ><P
7844 >S-1-5-2</P
7845 ></DD
7846 ><DT
7847 >Batch</DT
7848 ><DD
7849 ><P
7850 >S-1-5-3</P
7851 ></DD
7852 ><DT
7853 >Interactive</DT
7854 ><DD
7855 ><P
7856 >S-1-5-4</P
7857 ></DD
7858 ><DT
7859 >Service</DT
7860 ><DD
7861 ><P
7862 >S-1-5-6</P
7863 ></DD
7864 ><DT
7865 >AnonymousLogon(aka null logon session)</DT
7866 ><DD
7867 ><P
7868 >S-1-5-7</P
7869 ></DD
7870 ><DT
7871 >Proxy</DT
7872 ><DD
7873 ><P
7874 >S-1-5-8</P
7875 ></DD
7876 ><DT
7877 >ServerLogon(aka domain controller account)</DT
7878 ><DD
7879 ><P
7880 >S-1-5-8</P
7881 ></DD
7882 ><DT
7883 >(Logon IDs)</DT
7884 ><DD
7885 ><P
7886 >S-1-5-5-X-Y</P
7887 ></DD
7888 ><DT
7889 >(NT non-unique IDs)</DT
7890 ><DD
7891 ><P
7892 >S-1-5-0x15-...</P
7893 ></DD
7894 ><DT
7895 >(Built-in domain)</DT
7896 ><DD
7897 ><P
7898 >s-1-5-0x20</P
7899 ></DD
7900 ></DL
7901 ></DIV
7902 ></DIV
7903 ></DIV
7904 ><DIV
7905 CLASS="SECT2"
7906 ><HR><H3
7907 CLASS="SECT2"
7908 ><A
7909 NAME="AEN2812"
7910 ></A
7911 >9.8.2. Well-known RIDS</H3
7912 ><P
7913 >A RID is a sub-authority value, as part of either a SID, or in the case
7914 of Group RIDs, part of the DOM_GID structure, in the USER_INFO_1
7915 structure, in the LSA SAM Logon response.</P
7916 ><DIV
7917 CLASS="SECT3"
7918 ><HR><H4
7919 CLASS="SECT3"
7920 ><A
7921 NAME="AEN2815"
7922 ></A
7923 >9.8.2.1. Well-known RID users</H4
7924 ><P
7925 ><B
7926 >Groupname: </B
7927 >DOMAIN_USER_RID_ADMIN</P
7928 ><P
7929 ><B
7930 >????: </B
7931 >0x0000</P
7932 ><P
7933 ><B
7934 >RID: </B
7935 >01F4</P
7936 ><P
7937 ><B
7938 >Groupname: </B
7939 >DOMAIN_USER_RID_GUEST</P
7940 ><P
7941 ><B
7942 >????: </B
7943 >0x0000</P
7944 ><P
7945 ><B
7946 >RID: </B
7947 >01F5</P
7948 ></DIV
7949 ><DIV
7950 CLASS="SECT3"
7951 ><HR><H4
7952 CLASS="SECT3"
7953 ><A
7954 NAME="AEN2829"
7955 ></A
7956 >9.8.2.2. Well-known RID groups</H4
7957 ><P
7958 ><B
7959 >Groupname: </B
7960 >       DOMAIN_GROUP_RID_ADMINS</P
7961 ><P
7962 ><B
7963 >????: </B
7964 >0x0000</P
7965 ><P
7966 ><B
7967 >RID: </B
7968 >0200</P
7969 ><P
7970 ><B
7971 >Groupname: </B
7972 >       DOMAIN_GROUP_RID_USERS</P
7973 ><P
7974 ><B
7975 >????: </B
7976 >0x0000</P
7977 ><P
7978 ><B
7979 >RID: </B
7980 >0201</P
7981 ><P
7982 ><B
7983 >Groupname: </B
7984 >       DOMAIN_GROUP_RID_GUESTS</P
7985 ><P
7986 ><B
7987 >????: </B
7988 >0x0000</P
7989 ><P
7990 ><B
7991 >RID: </B
7992 >0202</P
7993 ></DIV
7994 ><DIV
7995 CLASS="SECT3"
7996 ><HR><H4
7997 CLASS="SECT3"
7998 ><A
7999 NAME="AEN2847"
8000 ></A
8001 >9.8.2.3. Well-known RID aliases</H4
8002 ><P
8003 ><B
8004 >Groupname: </B
8005 >       DOMAIN_ALIAS_RID_ADMINS</P
8006 ><P
8007 ><B
8008 >????: </B
8009 >0x0000</P
8010 ><P
8011 ><B
8012 >RID: </B
8013 >0220</P
8014 ><P
8015 ><B
8016 >Groupname: </B
8017 >       DOMAIN_ALIAS_RID_USERS</P
8018 ><P
8019 ><B
8020 >????: </B
8021 >0x0000</P
8022 ><P
8023 ><B
8024 >RID: </B
8025 >0221</P
8026 ><P
8027 ><B
8028 >Groupname: </B
8029 >       DOMAIN_ALIAS_RID_GUESTS</P
8030 ><P
8031 ><B
8032 >????: </B
8033 >0x0000</P
8034 ><P
8035 ><B
8036 >RID: </B
8037 >0222</P
8038 ><P
8039 ><B
8040 >Groupname: </B
8041 >       DOMAIN_ALIAS_RID_POWER_USERS</P
8042 ><P
8043 ><B
8044 >????: </B
8045 >0x0000</P
8046 ><P
8047 ><B
8048 >RID: </B
8049 >0223</P
8050 ><P
8051 ><B
8052 >Groupname: </B
8053 >       DOMAIN_ALIAS_RID_ACCOUNT_OPS</P
8054 ><P
8055 ><B
8056 >????: </B
8057 >0x0000</P
8058 ><P
8059 ><B
8060 >RID: </B
8061 >0224</P
8062 ><P
8063 ><B
8064 >Groupname: </B
8065 >       DOMAIN_ALIAS_RID_SYSTEM_OPS</P
8066 ><P
8067 ><B
8068 >????: </B
8069 >0x0000</P
8070 ><P
8071 ><B
8072 >RID: </B
8073 >0225</P
8074 ><P
8075 ><B
8076 >Groupname: </B
8077 >       DOMAIN_ALIAS_RID_PRINT_OPS</P
8078 ><P
8079 ><B
8080 >????: </B
8081 >0x0000</P
8082 ><P
8083 ><B
8084 >RID: </B
8085 >0226</P
8086 ><P
8087 ><B
8088 >Groupname: </B
8089 >       DOMAIN_ALIAS_RID_BACKUP_OPS</P
8090 ><P
8091 ><B
8092 >????: </B
8093 >0x0000</P
8094 ><P
8095 ><B
8096 >RID: </B
8097 >0227</P
8098 ><P
8099 ><B
8100 >Groupname: </B
8101 >       DOMAIN_ALIAS_RID_REPLICATOR</P
8102 ><P
8103 ><B
8104 >????: </B
8105 >0x0000</P
8106 ><P
8107 ><B
8108 >RID: </B
8109 >0228</P
8110 ></DIV
8111 ></DIV
8112 ></DIV
8113 ></DIV
8114 ><DIV
8115 CLASS="CHAPTER"
8116 ><HR><H1
8117 ><A
8118 NAME="PRINTING"
8119 ></A
8120 >Chapter 10. Samba Printing Internals</H1
8121 ><DIV
8122 CLASS="SECT1"
8123 ><H2
8124 CLASS="SECT1"
8125 ><A
8126 NAME="AEN2896"
8127 ></A
8128 >10.1. Abstract</H2
8129 ><P
8130 >The purpose of this document is to provide some insight into
8131 Samba's printing functionality and also to describe the semantics
8132 of certain features of Windows client printing.</P
8133 ></DIV
8134 ><DIV
8135 CLASS="SECT1"
8136 ><HR><H2
8137 CLASS="SECT1"
8138 ><A
8139 NAME="AEN2899"
8140 ></A
8141 >10.2. Printing Interface to Various Back ends</H2
8142 ><P
8143 >Samba uses a table of function pointers to seven functions.  The
8144 function prototypes are defined in the <TT
8145 CLASS="VARNAME"
8146 >printif</TT
8147 > structure declared
8148 in <TT
8149 CLASS="FILENAME"
8150 >printing.h</TT
8151 >.</P
8152 ><P
8153 ></P
8154 ><UL
8155 ><LI
8156 ><P
8157 >retrieve the contents of a print queue</P
8158 ></LI
8159 ><LI
8160 ><P
8161 >pause the print queue</P
8162 ></LI
8163 ><LI
8164 ><P
8165 >resume a paused print queue</P
8166 ></LI
8167 ><LI
8168 ><P
8169 >delete a job from the queue</P
8170 ></LI
8171 ><LI
8172 ><P
8173 >pause a job in the print queue</P
8174 ></LI
8175 ><LI
8176 ><P
8177 >result a paused print job in the queue</P
8178 ></LI
8179 ><LI
8180 ><P
8181 >submit a job to the print queue</P
8182 ></LI
8183 ></UL
8184 ><P
8185 >Currently there are only two printing back end implementations
8186 defined.</P
8187 ><P
8188 ></P
8189 ><UL
8190 ><LI
8191 ><P
8192 >a generic set of functions for working with standard UNIX
8193         printing subsystems</P
8194 ></LI
8195 ><LI
8196 ><P
8197 >a set of CUPS specific functions (this is only enabled if
8198         the CUPS libraries were located at compile time).</P
8199 ></LI
8200 ></UL
8201 ></DIV
8202 ><DIV
8203 CLASS="SECT1"
8204 ><HR><H2
8205 CLASS="SECT1"
8206 ><A
8207 NAME="AEN2925"
8208 ></A
8209 >10.3. Print Queue TDB's</H2
8210 ><P
8211 >Samba provides periodic caching of the output from the "lpq command"
8212 for performance reasons.  This cache time is configurable in seconds.
8213 Obviously the longer the cache time the less often smbd will be
8214 required to exec a copy of lpq.  However, the accuracy of the print
8215 queue contents displayed to clients will be diminished as well.</P
8216 ><P
8217 >The list of currently opened print queue TDB's can be found
8218 be examining the list of tdb_print_db structures ( see print_db_head
8219 in printing.c ). A queue TDB is opened using the wrapper function
8220 printing.c:get_print_db_byname().  The function ensures that smbd
8221 does not open more than MAX_PRINT_DBS_OPEN in an effort to prevent
8222 a large print server from exhausting all available file descriptors.
8223 If the number of open queue TDB's exceeds the MAX_PRINT_DBS_OPEN
8224 limit, smbd falls back to a most recently used algorithm for maintaining
8225 a list of open TDB's.</P
8226 ><P
8227 >There are two ways in which a a print job can be entered into
8228 a print queue's TDB.  The first is to submit the job from a Windows
8229 client which will insert the job information directly into the TDB.
8230 The second method is to have the print job picked up by executing the
8231 "lpq command".</P
8232 ><P
8233 ><PRE
8234 CLASS="PROGRAMLISTING"
8235 >/* included from printing.h */
8236 struct printjob {
8237         pid_t pid; /* which process launched the job */
8238         int sysjob; /* the system (lp) job number */
8239         int fd; /* file descriptor of open file if open */
8240         time_t starttime; /* when the job started spooling */
8241         int status; /* the status of this job */
8242         size_t size; /* the size of the job so far */
8243         int page_count; /* then number of pages so far */
8244         BOOL spooled; /* has it been sent to the spooler yet? */
8245         BOOL smbjob; /* set if the job is a SMB job */
8246         fstring filename; /* the filename used to spool the file */
8247         fstring jobname; /* the job name given to us by the client */
8248         fstring user; /* the user who started the job */
8249         fstring queuename; /* service number of printer for this job */
8250         NT_DEVICEMODE *nt_devmode;
8251 };</PRE
8252 ></P
8253 ><P
8254 >The current manifestation of the printjob structure contains a field
8255 for the UNIX job id returned from the "lpq command" and a Windows job
8256 ID (32-bit bounded by PRINT_MAX_JOBID).  When a print job is returned
8257 by the "lpq command" that does not match an existing job in the queue's
8258 TDB, a 32-bit job ID above the &lt;*vance doesn't know what word is missing here*&gt; is generating by adding UNIX_JOB_START to
8259 the id reported by lpq.</P
8260 ><P
8261 >In order to match a 32-bit Windows jobid onto a 16-bit lanman print job
8262 id, smbd uses an in memory TDB to match the former to a number appropriate
8263 for old lanman clients.</P
8264 ><P
8265 >When updating a print queue, smbd will perform the following
8266 steps ( refer to <TT
8267 CLASS="FILENAME"
8268 >print.c:print_queue_update()</TT
8269 > ):</P
8270 ><P
8271 ></P
8272 ><OL
8273 TYPE="1"
8274 ><LI
8275 ><P
8276 >Check to see if another smbd is currently in 
8277         the process of updating the queue contents by checking the pid 
8278         stored in <TT
8279 CLASS="CONSTANT"
8280 >LOCK/<TT
8281 CLASS="REPLACEABLE"
8282 ><I
8283 >printer_name</I
8284 ></TT
8285 ></TT
8286 >.  
8287         If so, then do not update the TDB.</P
8288 ></LI
8289 ><LI
8290 ><P
8291 >Lock the mutex entry in the TDB and store our own pid.
8292         Check that this succeeded, else fail.</P
8293 ></LI
8294 ><LI
8295 ><P
8296 >Store the updated time stamp for the new cache
8297         listing</P
8298 ></LI
8299 ><LI
8300 ><P
8301 >Retrieve the queue listing via "lpq command"</P
8302 ></LI
8303 ><LI
8304 ><P
8305 ><PRE
8306 CLASS="PROGRAMLISTING"
8307 >       foreach job in the queue
8308         {
8309                 if the job is a UNIX job, create a new entry;
8310                 if the job has a Windows based jobid, then
8311                 {
8312                         Lookup the record by the jobid;
8313                         if the lookup failed, then
8314                                 treat it as a UNIX job;
8315                         else
8316                                 update the job status only
8317                 }
8318         }</PRE
8319 ></P
8320 ></LI
8321 ><LI
8322 ><P
8323 >Delete any jobs in the TDB that are not
8324         in the in the lpq listing</P
8325 ></LI
8326 ><LI
8327 ><P
8328 >Store the print queue status in the TDB</P
8329 ></LI
8330 ><LI
8331 ><P
8332 >update the cache time stamp again</P
8333 ></LI
8334 ></OL
8335 ><P
8336 >Note that it is the contents of this TDB that is returned to Windows
8337 clients and not the actual listing from the "lpq command".</P
8338 ><P
8339 >The NT_DEVICEMODE stored as part of the printjob structure is used to
8340 store a pointer to a non-default DeviceMode associated with the print
8341 job.  The pointer will be non-null when the client included a Device
8342 Mode in the OpenPrinterEx() call and subsequently submitted a job for
8343 printing on that same handle.  If the client did not include a Device
8344 Mode in the OpenPrinterEx() request, the nt_devmode field is NULL
8345 and the job has the printer's device mode associated with it by default.</P
8346 ><P
8347 >Only non-default Device Mode are stored with print jobs in the print
8348 queue TDB.  Otherwise, the Device Mode is obtained from the printer
8349 object when the client issues a GetJob(level == 2) request.</P
8350 ></DIV
8351 ><DIV
8352 CLASS="SECT1"
8353 ><HR><H2
8354 CLASS="SECT1"
8355 ><A
8356 NAME="AEN2959"
8357 ></A
8358 >10.4. ChangeID &#38; Client Caching of Printer Information</H2
8359 ><P
8360 >[To be filled in later]</P
8361 ></DIV
8362 ><DIV
8363 CLASS="SECT1"
8364 ><HR><H2
8365 CLASS="SECT1"
8366 ><A
8367 NAME="AEN2962"
8368 ></A
8369 >10.5. Windows NT/2K Printer Change Notify</H2
8370 ><P
8371 >When working with Windows NT+ clients, it is possible for a
8372 print server to use RPC to send asynchronous change notification
8373 events to clients for certain printer and print job attributes.
8374 This can be useful when the client needs to know that a new
8375 job has been added to the queue for a given printer or that the
8376 driver for a printer has been changed.  Note that this is done
8377 entirely orthogonal to cache updates based on a new ChangeID for
8378 a printer object.</P
8379 ><P
8380 >The basic set of RPC's used to implement change notification are</P
8381 ><P
8382 ></P
8383 ><UL
8384 ><LI
8385 ><P
8386 >RemoteFindFirstPrinterChangeNotifyEx ( RFFPCN )</P
8387 ></LI
8388 ><LI
8389 ><P
8390 >RemoteFindNextPrinterChangeNotifyEx ( RFNPCN )</P
8391 ></LI
8392 ><LI
8393 ><P
8394 >FindClosePrinterChangeNotify( FCPCN )</P
8395 ></LI
8396 ><LI
8397 ><P
8398 >ReplyOpenPrinter</P
8399 ></LI
8400 ><LI
8401 ><P
8402 >ReplyClosePrinter</P
8403 ></LI
8404 ><LI
8405 ><P
8406 >RouteRefreshPrinterChangeNotify ( RRPCN )</P
8407 ></LI
8408 ></UL
8409 ><P
8410 >One additional RPC is available to a server, but is never used by the
8411 Windows spooler service:</P
8412 ><P
8413 ></P
8414 ><UL
8415 ><LI
8416 ><P
8417 >RouteReplyPrinter()</P
8418 ></LI
8419 ></UL
8420 ><P
8421 >The opnum for all of these RPC's are defined in include/rpc_spoolss.h</P
8422 ><P
8423 >Windows NT print servers use a bizarre method of sending print
8424 notification event to clients.  The process of registering a new change
8425 notification handle is as follows.  The 'C' is for client and the
8426 'S' is for server.  All error conditions have been eliminated.</P
8427 ><P
8428 ><PRE
8429 CLASS="PROGRAMLISTING"
8430 >C:     Obtain handle to printer or to the printer
8431         server via the standard OpenPrinterEx() call.
8432 S:      Respond with a valid handle to object
8433
8434 C:      Send a RFFPCN request with the previously obtained
8435         handle with either (a) set of flags for change events
8436         to monitor, or (b) a PRINTER_NOTIFY_OPTIONS structure
8437         containing the event information to monitor.  The windows
8438         spooler has only been observed to use (b).
8439 S:      The &lt;* another missing word*&gt; opens a new TCP session to the client (thus requiring
8440         all print clients to be CIFS servers as well) and sends
8441         a ReplyOpenPrinter() request to the client.
8442 C:      The client responds with a printer handle that can be used to
8443         send event notification messages.
8444 S:      The server replies success to the RFFPCN request.
8445
8446 C:      The windows spooler follows the RFFPCN with a RFNPCN
8447         request to fetch the current values of all monitored
8448         attributes.
8449 S:      The server replies with an array SPOOL_NOTIFY_INFO_DATA
8450         structures (contained in a SPOOL_NOTIFY_INFO structure).
8451
8452 C:      If the change notification handle is ever released by the
8453         client via a FCPCN request, the server sends a ReplyClosePrinter()
8454         request back to the client first.  However a request of this
8455         nature from the client is often an indication that the previous
8456         notification event was not marshalled correctly by the server
8457         or a piece of data was wrong.
8458 S:      The server closes the internal change notification handle
8459         (POLICY_HND) and does not send any further change notification
8460         events to the client for that printer or job.</PRE
8461 ></P
8462 ><P
8463 >The current list of notification events supported by Samba can be
8464 found by examining the internal tables in srv_spoolss_nt.c</P
8465 ><P
8466 ></P
8467 ><UL
8468 ><LI
8469 ><P
8470 >printer_notify_table[]</P
8471 ></LI
8472 ><LI
8473 ><P
8474 >job_notify_table[]</P
8475 ></LI
8476 ></UL
8477 ><P
8478 >When an event occurs that could be monitored, smbd sends a message
8479 to itself about the change.  The list of events to be transmitted
8480 are queued by the smbd process sending the message to prevent an
8481 overload of TDB usage and the internal message is sent during smbd's
8482 idle loop (refer to printing/notify.c and the functions
8483 send_spoolss_notify2_msg() and print_notify_send_messages() ).</P
8484 ><P
8485 >The decision of whether or not the change is to be sent to connected
8486 clients is made by the routine which actually sends the notification.
8487 ( refer to srv_spoolss_nt.c:recieve_notify2_message() ).</P
8488 ><P
8489 >Because it possible to receive a listing of multiple changes for
8490 multiple printers, the notification events must be split into
8491 categories by the printer name.  This makes it possible to group
8492 multiple change events to be sent in a single RPC according to the
8493 printer handle obtained via a ReplyOpenPrinter().</P
8494 ><P
8495 >The actual change notification is performed using the RRPCN request
8496 RPC.  This packet contains</P
8497 ><P
8498 ></P
8499 ><UL
8500 ><LI
8501 ><P
8502 >the printer handle registered with the
8503 client's spooler on which the change occurred</P
8504 ></LI
8505 ><LI
8506 ><P
8507 >The change_low value which was sent as part
8508 of the last RFNPCN request from the client</P
8509 ></LI
8510 ><LI
8511 ><P
8512 >The SPOOL_NOTIFY_INFO container with the event
8513 information</P
8514 ></LI
8515 ></UL
8516 ><P
8517 >A <TT
8518 CLASS="VARNAME"
8519 >SPOOL_NOTIFY_INFO</TT
8520 > contains:</P
8521 ><P
8522 ></P
8523 ><UL
8524 ><LI
8525 ><P
8526 >the version and flags field are predefined
8527 and should not be changed</P
8528 ></LI
8529 ><LI
8530 ><P
8531 >The count field is the number of entries
8532 in the SPOOL_NOTIFY_INFO_DATA array</P
8533 ></LI
8534 ></UL
8535 ><P
8536 >The <TT
8537 CLASS="VARNAME"
8538 >SPOOL_NOTIFY_INFO_DATA</TT
8539 > entries contain:</P
8540 ><P
8541 ></P
8542 ><UL
8543 ><LI
8544 ><P
8545 >The type defines whether or not this event
8546 is for a printer or a print job</P
8547 ></LI
8548 ><LI
8549 ><P
8550 >The field is the flag identifying the event</P
8551 ></LI
8552 ><LI
8553 ><P
8554 >the notify_data union contains the new valuie of the
8555 attribute</P
8556 ></LI
8557 ><LI
8558 ><P
8559 >The enc_type defines the size of the structure for marshalling
8560 and unmarshalling</P
8561 ></LI
8562 ><LI
8563 ><P
8564 >(a) the id must be 0 for a printer event on a printer handle.
8565 (b) the id must be the job id for an event on a printer job
8566 (c) the id must be the matching number of the printer index used
8567 in the response packet to the RFNPCN when using a print server
8568 handle for notification.  Samba currently uses the snum of
8569 the printer for this which can break if the list of services
8570 has been modified since the notification handle was registered.</P
8571 ></LI
8572 ><LI
8573 ><P
8574 >The size is either (a) the string length in UNICODE for strings,
8575 (b) the size in bytes of the security descriptor, or (c) 0 for
8576 data values.</P
8577 ></LI
8578 ></UL
8579 ></DIV
8580 ></DIV
8581 ><DIV
8582 CLASS="CHAPTER"
8583 ><HR><H1
8584 ><A
8585 NAME="WINS"
8586 ></A
8587 >Chapter 11. Samba WINS Internals</H1
8588 ><DIV
8589 CLASS="SECT1"
8590 ><H2
8591 CLASS="SECT1"
8592 ><A
8593 NAME="AEN3033"
8594 ></A
8595 >11.1. WINS Failover</H2
8596 ><P
8597 >The current Samba codebase possesses the capability to use groups of WINS
8598 servers that share a common namespace for NetBIOS name registration and 
8599 resolution.  The formal parameter syntax is</P
8600 ><P
8601 ><PRE
8602 CLASS="PROGRAMLISTING"
8603 >       WINS_SERVER_PARAM       = SERVER [ SEPARATOR SERVER_LIST ]
8604         WINS_SERVER_PARAM       = &quot;wins server&quot;
8605         SERVER                  = ADDR[:TAG]
8606         ADDR                    = ip_addr | fqdn
8607         TAG                     = string
8608         SEPARATOR               = comma | \s+
8609         SERVER_LIST             = SERVER [ SEPARATOR SERVER_LIST ]</PRE
8610 ></P
8611 ><P
8612 >A simple example of a valid wins server setting is</P
8613 ><P
8614 ><PRE
8615 CLASS="PROGRAMLISTING"
8616 >[global]
8617         wins server = 192.168.1.2 192.168.1.3</PRE
8618 ></P
8619 ><P
8620 >In the event that no TAG is defined in for a SERVER in the list, smbd assigns a default
8621 TAG of &quot;*&quot;.  A TAG is used to group servers of a shared NetBIOS namespace together.  Upon
8622 startup, nmbd will attempt to register the netbios name value with one server in each
8623 tagged group.</P
8624 ><P
8625 >An example using tags to group WINS servers together is show here.  Note that the use of
8626 interface names in the tags is only by convention and is not a technical requirement.</P
8627 ><P
8628 ><PRE
8629 CLASS="PROGRAMLISTING"
8630 >[global]
8631         wins server = 192.168.1.2:eth0 192.168.1.3:eth0 192.168.2.2:eth1</PRE
8632 ></P
8633 ><P
8634 >Using this configuration, nmbd would attempt to register the server's NetBIOS name 
8635 with one WINS server in each group.  Because the &quot;eth0&quot; group has two servers, the 
8636 second server would only be used when a registration (or resolution) request to 
8637 the first server in that group timed out.</P
8638 ><P
8639 >NetBIOS name resolution follows a similar pattern as name registration.  When resolving 
8640 a NetBIOS name via WINS, smbd and other Samba programs will attempt to query a single WINS 
8641 server in a tagged group until either a positive response is obtained at least once or 
8642 until a server from every tagged group has responded negatively to the name query request.
8643 If a timeout occurs when querying a specific WINS server, that server is marked as down to 
8644 prevent further timeouts and the next server in the WINS group is contacted.  Once marked as 
8645 dead, Samba will not attempt to contact that server for name registration/resolution queries 
8646 for a period of 10 minutes.</P
8647 ></DIV
8648 ></DIV
8649 ><DIV
8650 CLASS="CHAPTER"
8651 ><HR><H1
8652 ><A
8653 NAME="SAM"
8654 ></A
8655 >Chapter 12. The Upcoming SAM System</H1
8656 ><DIV
8657 CLASS="SECT1"
8658 ><H2
8659 CLASS="SECT1"
8660 ><A
8661 NAME="AEN3054"
8662 ></A
8663 >12.1. Security in the 'new SAM'</H2
8664 ><P
8665 >One of the biggest problems with passdb is it's implementation of
8666 'security'.  Access control is on a 'are you root at the moment' basis,
8667 and it has no concept of NT ACLs.  Things like ldapsam had to add
8668 'magic' 'are you root' checks.</P
8669 ><P
8670 >We took this very seriously when we started work, and the new structure
8671 is designed with this in mind, from the ground up.  Each call to the SAM
8672 has a NT_TOKEN and (if relevant) an 'access desired'.  This is either
8673 provided as a parameter, or implicitly supplied by the object being
8674 accessed.</P
8675 ><P
8676 >For example, when you call </P
8677 ><PRE
8678 CLASS="PROGRAMLISTING"
8679 >&#60;
8680 NTSTATUS sam_get_account_by_name(const SAM_CONTEXT *context, const
8681 NT_USER_TOKEN *access_token, uint32 access_desired, const char *domain,
8682 const char *name, SAM_ACCOUNT_HANDLE **account)</PRE
8683 ><P
8684 >The context can be NULL (and is used to allow import/export by setting
8685 up 2 contexts, and allowing calls on both simultaneously)</P
8686 ><P
8687 >The access token *must* be specified.  Normally the user's token out of
8688 current_user, this can also be a global 'system' context.</P
8689 ><P
8690 >The access desired is as per the ACL, for passing to the seaccess stuff.</P
8691 ><P
8692 >The domain/username are standard.  Even if we only have one domain,
8693 keeping this ensures that we don't get 'unqualified' usernames (same
8694 problem as we had with unqualified SIDs).</P
8695 ><P
8696 >We return a 'handle'.  This is opaque to the rest of Samba, but is
8697 operated on by get/set routines, all of which return NTSTATUS.</P
8698 ><P
8699 >The access checking is done by the SAM module.   The reason it is not
8700 done 'above' the interface is to ensure a 'choke point'.  I put a lot of
8701 effort into the auth subsystem to ensure we never 'accidentally' forgot
8702 to check for null passwords, missed a restriction etc.  I intend the SAM
8703 to be written with the same caution.</P
8704 ><P
8705 >The reason the access checking is not handled by the interface itself is
8706 due to the different implementations it make take on.  For example, on
8707 ADS, you cannot set a password over a non-SSL connection.  Other
8708 backends may have similar requirements - we need to leave this policy up
8709 to the modules.  They will naturally have access to 'helper' procedures
8710 and good examples to avoid mishaps.</P
8711 ><P
8712 >(Furthermore, some backends my actually chose to push the whole ACL
8713 issue to the remote server, and - assuming ldap for this example - bind
8714 as the user directly)</P
8715 ><P
8716 >Each returned handle has an internal 'access permitted', which allows
8717 the 'get' and 'set' routines to return 'ACCESS_DENIED' for things that
8718 were not able to be retrieved from the backend.  This removes the need
8719 to specify the NT_TOKEN on every operation, and allows for 'object not
8720 present' to be easily distinguished from 'access denied'.</P
8721 ><P
8722 >When you 'set' an object (calling sam_update_account) the internal
8723 details are again used.  Each change that has been made to the object
8724 has been flagged, so as to avoid race conditions (on unmodified
8725 components) and to avoid violating any extra ACL requirements on the
8726 actual data store (like the LDAP server).</P
8727 ><P
8728 >Finally, we have generic get_sec_desc() and set_sec_desc() routines to
8729 allow external ACL manipulation.  These do lookups based on SID.</P
8730 ></DIV
8731 ><DIV
8732 CLASS="SECT1"
8733 ><HR><H2
8734 CLASS="SECT1"
8735 ><A
8736 NAME="AEN3071"
8737 ></A
8738 >12.2. Standalone from UNIX</H2
8739 ><P
8740 >One of the primary tenants of the 'new SAM' is that it would not attempt
8741 to deal with 'what unix id for that'.  This would be left to the 'SMS'
8742 (Sid Mapping System') or SID farm, and probably administered via
8743 winbind.  We have had constructive discussion on how 'basic' unix
8744 accounts like 'root' would be handled, and we think this can work.  
8745 Accounts not preexisting in unix would be served up via winbind.</P
8746 ><P
8747 >This is an *optional* part, and my preferred end-game.  We have a fare
8748 way to go before things like winbind up to it however.</P
8749 ></DIV
8750 ><DIV
8751 CLASS="SECT1"
8752 ><HR><H2
8753 CLASS="SECT1"
8754 ><A
8755 NAME="AEN3075"
8756 ></A
8757 >12.3. Handles and Races in the new SAM</H2
8758 ><P
8759 >One of the things that the 'new SAM' work has tried to face is both
8760 compatibility with existing code, and a closer alignment to the SAMR
8761 interface.  I consider SAMR to be a 'primary customer' to the this work,
8762 because if we get alignment with that wrong, things get more, rather
8763 than less complex.  Also, most other parts of Samba are much more
8764 flexible with what they can allow.</P
8765 ><P
8766 >In any case, that was a decision taken as to how the general design
8767 would progress.  BTW, my understanding of SAMR may be completely flawed.</P
8768 ><P
8769 >One of the most race-prone areas of the new code is the conflicting
8770 update problem.  We have taken two approaches:  </P
8771 ><P
8772 ></P
8773 ><UL
8774 ><LI
8775 ><P
8776 >'Not conflicting' conflicts.  Due to the way usrmgr operates, it will
8777 open a user, display all the properties and *save* them all, even if you
8778 don't change any.</P
8779 ><P
8780 >For this, see what I've done in rpc_server/srv_samr_util.c.  I intend
8781 to take this one step further, and operate on the 'handle' that the
8782 values were read from.  This should mean that we only update things that
8783 have *really* changed.</P
8784 ></LI
8785 ><LI
8786 ><P
8787 >'conflicting' updates:  Currently we don't deal with this (in passdb
8788 or the new sam stuff), but the design is sufficiently flexible to 'deny'
8789 a second update.  I don't foresee locking records however.</P
8790 ></LI
8791 ></UL
8792 ></DIV
8793 ><DIV
8794 CLASS="SECT1"
8795 ><HR><H2
8796 CLASS="SECT1"
8797 ><A
8798 NAME="AEN3086"
8799 ></A
8800 >12.4. Layers</H2
8801 ><DIV
8802 CLASS="SECT2"
8803 ><H3
8804 CLASS="SECT2"
8805 ><A
8806 NAME="AEN3088"
8807 ></A
8808 >12.4.1. Application</H3
8809 ><P
8810 >This is where smbd, samtest and whatever end-user replacement we have
8811 for pdbedit sits.  They use only the SAM interface, and do not get
8812 'special knowledge' of what is below them.</P
8813 ></DIV
8814 ><DIV
8815 CLASS="SECT2"
8816 ><HR><H3
8817 CLASS="SECT2"
8818 ><A
8819 NAME="AEN3091"
8820 ></A
8821 >12.4.2. SAM Interface</H3
8822 ><P
8823 >This level 'owns' the various handle structures, the get/set routines on
8824 those structures and provides the public interface.  The application
8825 layer may initialize a 'context' to be passed to all interface routines,
8826 else a default, self-initialising context will be supplied.  This layser
8827 finds the appropriate backend module for the task, and tries very hard
8828 not to need to much 'knowledge'.  It should just provide the required
8829 abstraction to the modules below, and arrange for their initial loading.</P
8830 ><P
8831 >We could possibly add ACL checking at this layer, to avoid discrepancies
8832 in implementation modules.</P
8833 ></DIV
8834 ><DIV
8835 CLASS="SECT2"
8836 ><HR><H3
8837 CLASS="SECT2"
8838 ><A
8839 NAME="AEN3095"
8840 ></A
8841 >12.4.3. SAM Modules</H3
8842 ><P
8843 >These do not communicate with the application directly, only by setting
8844 values in the handles, and receiving requests from the interface.  These
8845 modules are responsible for translating values from the handle's
8846 .private into (say) an LDAP modification list.  The module is expected
8847 to 'know' things like it's own domain SID, domain name, and any other
8848 state attached to the SAM.  Simpler modules may call back to some helper
8849 routine.</P
8850 ></DIV
8851 ></DIV
8852 ><DIV
8853 CLASS="SECT1"
8854 ><HR><H2
8855 CLASS="SECT1"
8856 ><A
8857 NAME="AEN3098"
8858 ></A
8859 >12.5. SAM Modules</H2
8860 ><DIV
8861 CLASS="SECT2"
8862 ><H3
8863 CLASS="SECT2"
8864 ><A
8865 NAME="AEN3100"
8866 ></A
8867 >12.5.1. Special Module: sam_passdb</H3
8868 ><P
8869 >In order for there to be a smooth transition, kai is writing a module
8870 that reads existing passdb backends, and translates them into SAM
8871 replies.  (Also pulling data from the account policy DB etc).  We also
8872 intend to write a module that does the reverse - gives the SAM a passdb
8873 interface.</P
8874 ></DIV
8875 ><DIV
8876 CLASS="SECT2"
8877 ><HR><H3
8878 CLASS="SECT2"
8879 ><A
8880 NAME="AEN3103"
8881 ></A
8882 >12.5.2. sam_ads</H3
8883 ><P
8884 >This is the first of the SAM modules to be committed to the tree -
8885 mainly because I needed to coordinate work with metze (who authored most
8886 of it).  This module aims to use Samba's libads code to provide an
8887 Active Directory LDAP client, suitable for use on a mixed-mode DC. 
8888 While it is currently being tested against Win2k servers (with a
8889 password in the smb.conf file) it is expected to eventually use a
8890 (possibly modified) OpenLDAP server.  We hope that this will assist in
8891 the construction of an Samba AD DC.</P
8892 ><P
8893 >We also intend to construct a Samba 2.2/3.0 compatible ldap module,
8894 again using libads code.</P
8895 ></DIV
8896 ></DIV
8897 ><DIV
8898 CLASS="SECT1"
8899 ><HR><H2
8900 CLASS="SECT1"
8901 ><A
8902 NAME="AEN3107"
8903 ></A
8904 >12.6. Memory Management</H2
8905 ><P
8906
8907 The 'new SAM' development effort also concerned itself with getting a
8908 sane implementation of memory management.  It was decided that we would
8909 be (as much as possible) talloc based, using an 'internal talloc
8910 context' on many objects.  That is, the creation of an object would
8911 initiate it's own internal talloc context, and this would be used for
8912 all operations on that object.  Much of this is already implemented in
8913 passdb.  Also, like passdb, it will be possible to specify that some
8914 object actually be created on a specified context.  </P
8915 ><P
8916 >Memory management is important here because the APIs in the 'new SAM' do
8917 not use 'pdb_init()' or an equivalent.  They always allocate new
8918 objects.  Enumeration's are slightly different, and occur on a supplied
8919 context that 'owns' the entire list, rather than per-element.  (the
8920 enumeration functions return an array of all elements - not full handles
8921 just basic (and public) info)  Likewise for things that fill in a char
8922 **.</P
8923 ><P
8924 >For example:</P
8925 ><P
8926 ><PRE
8927 CLASS="PROGRAMLISTING"
8928 >NTSTATUS sam_lookup_sid(const SAM_CONTEXT *context, const NT_USER_TOKEN
8929 *access_token, TALLOC_CTX *mem_ctx, const DOM_SID *sid, char **name,
8930 uint32 *type)</PRE
8931 ></P
8932 ><P
8933 >Takes a context to allocate the 'name' on, while:</P
8934 ><P
8935 ><PRE
8936 CLASS="PROGRAMLISTING"
8937 >NTSTATUS sam_get_account_by_sid(const SAM_CONTEXT *context, const
8938 NT_USER_TOKEN *access_token, uint32 access_desired, const DOM_SID
8939 *accountsid, SAM_ACCOUNT_HANDLE **account)</PRE
8940 ></P
8941 ><P
8942 >Allocates a handle and stores the allocation context on that handle.</P
8943 ><P
8944 >I think that the following:</P
8945 ><P
8946 ><PRE
8947 CLASS="PROGRAMLISTING"
8948 >NTSTATUS sam_enum_accounts(const SAM_CONTEXT *context, const
8949 NT_USER_TOKEN *access_token, const DOM_SID *domainsid, uint16 acct_ctrl,
8950 int32 *account_count, SAM_ACCOUNT_ENUM **accounts)</PRE
8951 ></P
8952 ></DIV
8953 ><DIV
8954 CLASS="SECT1"
8955 ><HR><H2
8956 CLASS="SECT1"
8957 ><A
8958 NAME="AEN3121"
8959 ></A
8960 >12.7. Testing</H2
8961 ><P
8962 >Testing is vital in any piece of software, and Samba is certainly no
8963 exception. In designing this new subsystem, we have taken care to ensure
8964 it is easily tested, independent of outside protocols.</P
8965 ><P
8966 >To this end, Jelmer has constructed 'samtest'.  </P
8967 ><P
8968 >This utility (see torture/samtest.c) is structured like rpcclient, but
8969 instead operates on the SAM subsystem.  It creates a 'custom' SAM
8970 context, that may be distinct from the default values used by the rest
8971 of the system, and can load a separate configuration file.  </P
8972 ><P
8973 >A small number of commands are currently implemented, but these have
8974 already proved vital in testing.   I expect SAM module authors will find
8975 it particularly valuable.</P
8976 ><P
8977 >Example useage:</P
8978 ><P
8979 ><TT
8980 CLASS="PROMPT"
8981 >$</TT
8982 > <B
8983 CLASS="COMMAND"
8984 >bin/samtest</B
8985 ></P
8986 ><P
8987 ><PRE
8988 CLASS="PROGRAMLISTING"
8989 >&#62; context ads:ldap://192.168.1.96</PRE
8990 >
8991 (this loads a new context, using the new ADS module.  The parameter is
8992 the 'location' of the ldap server)</P
8993 ><P
8994 ><PRE
8995 CLASS="PROGRAMLISTING"
8996 >&#62; lookup_name DOMAIN abartlet</PRE
8997 >
8998 (returns a sid).</P
8999 ><P
9000 >Because the 'new SAM' is NT ACL based, there will be a command to
9001 specify an arbitrary NT ACL, but for now it uses 'system' by default.</P
9002 ></DIV
9003 ></DIV
9004 ><DIV
9005 CLASS="CHAPTER"
9006 ><HR><H1
9007 ><A
9008 NAME="PWENCRYPT"
9009 ></A
9010 >Chapter 13. LanMan and NT Password Encryption</H1
9011 ><DIV
9012 CLASS="SECT1"
9013 ><H2
9014 CLASS="SECT1"
9015 ><A
9016 NAME="AEN3147"
9017 ></A
9018 >13.1. Introduction</H2
9019 ><P
9020 >With the development of LanManager and Windows NT 
9021         compatible password encryption for Samba, it is now able 
9022         to validate user connections in exactly the same way as 
9023         a LanManager or Windows NT server.</P
9024 ><P
9025 >This document describes how the SMB password encryption 
9026         algorithm works and what issues there are in choosing whether 
9027         you want to use it. You should read it carefully, especially 
9028         the part about security and the "PROS and CONS" section.</P
9029 ></DIV
9030 ><DIV
9031 CLASS="SECT1"
9032 ><HR><H2
9033 CLASS="SECT1"
9034 ><A
9035 NAME="AEN3151"
9036 ></A
9037 >13.2. How does it work?</H2
9038 ><P
9039 >LanManager encryption is somewhat similar to UNIX 
9040         password encryption. The server uses a file containing a 
9041         hashed value of a user's password.  This is created by taking 
9042         the user's plaintext password, capitalising it, and either 
9043         truncating to 14 bytes or padding to 14 bytes with null bytes. 
9044         This 14 byte value is used as two 56 bit DES keys to encrypt 
9045         a 'magic' eight byte value, forming a 16 byte value which is 
9046         stored by the server and client. Let this value be known as 
9047         the "hashed password".</P
9048 ><P
9049 >Windows NT encryption is a higher quality mechanism, 
9050         consisting of doing an MD4 hash on a Unicode version of the user's 
9051         password. This also produces a 16 byte hash value that is 
9052         non-reversible.</P
9053 ><P
9054 >When a client (LanManager, Windows for WorkGroups, Windows 
9055         95 or Windows NT) wishes to mount a Samba drive (or use a Samba 
9056         resource), it first requests a connection and negotiates the 
9057         protocol that the client and server will use. In the reply to this 
9058         request the Samba server generates and appends an 8 byte, random 
9059         value - this is stored in the Samba server after the reply is sent 
9060         and is known as the "challenge".  The challenge is different for 
9061         every client connection.</P
9062 ><P
9063 >The client then uses the hashed password (16 byte values 
9064         described above), appended with 5 null bytes, as three 56 bit 
9065         DES keys, each of which is used to encrypt the challenge 8 byte 
9066         value, forming a 24 byte value known as the "response".</P
9067 ><P
9068 >In the SMB call SMBsessionsetupX (when user level security 
9069         is selected) or the call SMBtconX (when share level security is 
9070         selected), the 24 byte response is returned by the client to the 
9071         Samba server.  For Windows NT protocol levels the above calculation 
9072         is done on both hashes of the user's password and both responses are 
9073         returned in the SMB call, giving two 24 byte values.</P
9074 ><P
9075 >The Samba server then reproduces the above calculation, using 
9076         its own stored value of the 16 byte hashed password (read from the 
9077         <TT
9078 CLASS="FILENAME"
9079 >smbpasswd</TT
9080 > file - described later) and the challenge 
9081         value that it kept from the negotiate protocol reply. It then checks 
9082         to see if the 24 byte value it calculates matches the 24 byte value 
9083         returned to it from the client.</P
9084 ><P
9085 >If these values match exactly, then the client knew the 
9086         correct password (or the 16 byte hashed value - see security note 
9087         below) and is thus allowed access. If not, then the client did not 
9088         know the correct password and is denied access.</P
9089 ><P
9090 >Note that the Samba server never knows or stores the cleartext 
9091         of the user's password - just the 16 byte hashed values derived from 
9092         it. Also note that the cleartext password or 16 byte hashed values 
9093         are never transmitted over the network - thus increasing security.</P
9094 ></DIV
9095 ><DIV
9096 CLASS="SECT1"
9097 ><HR><H2
9098 CLASS="SECT1"
9099 ><A
9100 NAME="AEN3162"
9101 ></A
9102 >13.3. <A
9103 NAME="SMBPASSWDFILEFORMAT"
9104 ></A
9105 >The smbpasswd file</H2
9106 ><P
9107 >In order for Samba to participate in the above protocol 
9108         it must be able to look up the 16 byte hashed values given a user name.
9109         Unfortunately, as the UNIX password value is also a one way hash
9110         function (ie. it is impossible to retrieve the cleartext of the user's
9111         password given the UNIX hash of it), a separate password file
9112         containing this 16 byte value must be kept. To minimise problems with
9113         these two password files, getting out of sync, the UNIX <TT
9114 CLASS="FILENAME"
9115 >       /etc/passwd</TT
9116 > and the <TT
9117 CLASS="FILENAME"
9118 >smbpasswd</TT
9119 > file, 
9120         a utility, <B
9121 CLASS="COMMAND"
9122 >mksmbpasswd.sh</B
9123 >, is provided to generate
9124         a smbpasswd file from a UNIX <TT
9125 CLASS="FILENAME"
9126 >/etc/passwd</TT
9127 > file.
9128         </P
9129 ><P
9130 >To generate the smbpasswd file from your <TT
9131 CLASS="FILENAME"
9132 >/etc/passwd
9133         </TT
9134 > file use the following command :</P
9135 ><P
9136 ><TT
9137 CLASS="PROMPT"
9138 >$ </TT
9139 ><TT
9140 CLASS="USERINPUT"
9141 ><B
9142 >cat /etc/passwd | mksmbpasswd.sh
9143         &gt; /usr/local/samba/private/smbpasswd</B
9144 ></TT
9145 ></P
9146 ><P
9147 >If you are running on a system that uses NIS, use</P
9148 ><P
9149 ><TT
9150 CLASS="PROMPT"
9151 >$ </TT
9152 ><TT
9153 CLASS="USERINPUT"
9154 ><B
9155 >ypcat passwd | mksmbpasswd.sh
9156         &gt; /usr/local/samba/private/smbpasswd</B
9157 ></TT
9158 ></P
9159 ><P
9160 >The <B
9161 CLASS="COMMAND"
9162 >mksmbpasswd.sh</B
9163 > program is found in 
9164         the Samba source directory. By default, the smbpasswd file is 
9165         stored in :</P
9166 ><P
9167 ><TT
9168 CLASS="FILENAME"
9169 >/usr/local/samba/private/smbpasswd</TT
9170 ></P
9171 ><P
9172 >The owner of the <TT
9173 CLASS="FILENAME"
9174 >/usr/local/samba/private/</TT
9175
9176         directory should be set to root, and the permissions on it should 
9177         be set to 0500 (<B
9178 CLASS="COMMAND"
9179 >chmod 500 /usr/local/samba/private</B
9180 >).
9181         </P
9182 ><P
9183 >Likewise, the smbpasswd file inside the private directory should 
9184         be owned by root and the permissions on is should be set to 0600
9185         (<B
9186 CLASS="COMMAND"
9187 >chmod 600 smbpasswd</B
9188 >).</P
9189 ><P
9190 >The format of the smbpasswd file is (The line has been 
9191         wrapped here. It should appear as one entry per line in 
9192         your smbpasswd file.)</P
9193 ><P
9194 ><PRE
9195 CLASS="PROGRAMLISTING"
9196 >username:uid:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:
9197         [Account type]:LCT-&lt;last-change-time&gt;:Long name
9198         </PRE
9199 ></P
9200 ><P
9201 >Although only the <TT
9202 CLASS="REPLACEABLE"
9203 ><I
9204 >username</I
9205 ></TT
9206 >, 
9207         <TT
9208 CLASS="REPLACEABLE"
9209 ><I
9210 >uid</I
9211 ></TT
9212 >, <TT
9213 CLASS="REPLACEABLE"
9214 ><I
9215 >       XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</I
9216 ></TT
9217 >,
9218         [<TT
9219 CLASS="REPLACEABLE"
9220 ><I
9221 >Account type</I
9222 ></TT
9223 >] and <TT
9224 CLASS="REPLACEABLE"
9225 ><I
9226 >       last-change-time</I
9227 ></TT
9228 > sections are significant 
9229         and are looked at in the Samba code.</P
9230 ><P
9231 >It is <SPAN
9232 CLASS="emphasis"
9233 ><I
9234 CLASS="EMPHASIS"
9235 >VITALLY</I
9236 ></SPAN
9237 > important that there by 32 
9238         'X' characters between the two ':' characters in the XXX sections - 
9239         the smbpasswd and Samba code will fail to validate any entries that 
9240         do not have 32 characters  between ':' characters. The first XXX 
9241         section is for the Lanman password hash, the second is for the 
9242         Windows NT version.</P
9243 ><P
9244 >When the password file is created all users have password entries
9245         consisting of 32 'X' characters. By default this disallows any access
9246         as this user. When a user has a password set, the 'X' characters change
9247         to 32 ascii hexadecimal digits (0-9, A-F). These are an ascii
9248         representation of the 16 byte hashed value of a user's password.</P
9249 ><P
9250 >To set a user to have no password (not recommended), edit the file
9251         using vi, and replace the first 11 characters with the ascii text
9252         <TT
9253 CLASS="CONSTANT"
9254 >"NO PASSWORD"</TT
9255 > (minus the quotes).</P
9256 ><P
9257 >For example, to clear the password for user bob, his smbpasswd file 
9258         entry would look like :</P
9259 ><P
9260 ><PRE
9261 CLASS="PROGRAMLISTING"
9262 >       bob:100:NO PASSWORDXXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:[U          ]:LCT-00000000:Bob's full name:/bobhome:/bobshell
9263         </PRE
9264 ></P
9265 ><P
9266 >If you are allowing users to use the smbpasswd command to set 
9267         their own passwords, you may want to give users NO PASSWORD initially 
9268         so they do not have to enter a previous password when changing to their 
9269         new password (not recommended). In order for you to allow this the
9270         <B
9271 CLASS="COMMAND"
9272 >smbpasswd</B
9273 > program must be able to connect to the 
9274         <B
9275 CLASS="COMMAND"
9276 >smbd</B
9277 > daemon as that user with no password. Enable this 
9278         by adding the line :</P
9279 ><P
9280 ><B
9281 CLASS="COMMAND"
9282 >null passwords = yes</B
9283 ></P
9284 ><P
9285 >to the [global] section of the smb.conf file (this is why 
9286         the above scenario is not recommended). Preferably, allocate your
9287         users a default password to begin with, so you do not have
9288         to enable this on your server.</P
9289 ><P
9290 ><SPAN
9291 CLASS="emphasis"
9292 ><I
9293 CLASS="EMPHASIS"
9294 >Note : </I
9295 ></SPAN
9296 >This file should be protected very 
9297         carefully. Anyone with access to this file can (with enough knowledge of 
9298         the protocols) gain access to your SMB server. The file is thus more 
9299         sensitive than a normal unix <TT
9300 CLASS="FILENAME"
9301 >/etc/passwd</TT
9302 > file.</P
9303 ></DIV
9304 ></DIV
9305 ></DIV
9306 ></BODY
9307 ></HTML
9308 >