ipc.c :
[kai/samba.git] / source / include / smb.h
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    SMB parameters and setup
5    Copyright (C) Andrew Tridgell 1992-1997
6    Copyright (C) John H Terpstra 1996-1997
7    Copyright (C) Luke Kenneth Casson Leighton 1996-1997
8    Copyright (C) Paul Ashton 1997
9    
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14    
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19    
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24 #ifndef _SMB_H
25 #define _SMB_H
26
27 #ifndef MAX_CONNECTIONS
28 #define MAX_CONNECTIONS 127
29 #endif
30
31 #ifndef MAX_OPEN_FILES
32 #define MAX_OPEN_FILES 50
33 #endif
34
35 #ifndef GUEST_ACCOUNT
36 #define GUEST_ACCOUNT "nobody"
37 #endif
38
39 #define BUFFER_SIZE (0xFFFF)
40 #define SAFETY_MARGIN 1024
41
42 /* Default size of shared memory used for share mode locking */
43 #ifndef SHMEM_SIZE
44 #define SHMEM_SIZE 102400
45 #endif
46
47 #define NMB_PORT 137
48 #define DGRAM_PORT 138
49 #define SMB_PORT 139
50
51 #define False (0)
52 #define True (1)
53 #define BOOLSTR(b) ((b) ? "Yes" : "No")
54 #define BITSETB(ptr,bit) ((((char *)ptr)[0] & (1<<(bit)))!=0)
55 #define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0)
56 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((char *)(p1)) - (char *)(p2)))
57
58 typedef int BOOL;
59
60 /* limiting size of ipc replies */
61 #define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024))
62
63 /*
64    Samba needs type definitions for int16, int32, uint16 and uint32.
65    
66    Normally these are signed and unsigned 16 and 32 bit integers, but
67    they actually only need to be at least 16 and 32 bits
68    respectively. Thus if your word size is 8 bytes just defining them
69    as signed and unsigned int will work.
70 */
71
72 /* afs/stds.h defines int16 and int32 */
73 #ifndef AFS_AUTH
74 typedef short int16;
75 typedef int int32;
76 #endif
77
78 #ifndef uint8
79 typedef unsigned char uint8;
80 #endif
81
82 #ifndef uint16
83 typedef unsigned short uint16;
84 #endif
85
86 #ifndef uint32
87 typedef unsigned int uint32;
88 #endif
89
90 #ifndef uchar
91 #define uchar unsigned char
92 #endif
93 #ifndef int16
94 #define int16 short
95 #endif
96 #ifndef uint16
97 #define uint16 unsigned short
98 #endif
99 #ifndef uint32
100 #define uint32 unsigned int
101 #endif
102
103 #define SIZEOFWORD 2
104
105 #ifndef DEF_CREATE_MASK
106 #define DEF_CREATE_MASK (0755)
107 #endif
108
109 /* how long to wait for secondary SMB packets (milli-seconds) */
110 #define SMB_SECONDARY_WAIT (60*1000)
111
112 /* debugging code */
113 #ifndef SYSLOG
114 #define DEBUG(level,body) ((DEBUGLEVEL>=(level))?(Debug1 body):0)
115 #else
116 extern int syslog_level;
117
118 #define DEBUG(level,body) ((DEBUGLEVEL>=(level))? (syslog_level = (level), Debug1 body):0)
119 #endif
120
121 /* this defines the error codes that receive_smb can put in smb_read_error */
122 #define READ_TIMEOUT 1
123 #define READ_EOF 2
124 #define READ_ERROR 3
125
126
127 #define DIR_STRUCT_SIZE 43
128
129 /* these define all the command types recognised by the server - there
130 are lots of gaps so probably there are some rare commands that are not
131 implemented */
132
133 #define pSETDIR '\377'
134
135 /* these define the attribute byte as seen by DOS */
136 #define aRONLY (1L<<0)
137 #define aHIDDEN (1L<<1)
138 #define aSYSTEM (1L<<2)
139 #define aVOLID (1L<<3)
140 #define aDIR (1L<<4)
141 #define aARCH (1L<<5)
142
143 /* deny modes */
144 #define DENY_DOS 0
145 #define DENY_ALL 1
146 #define DENY_WRITE 2
147 #define DENY_READ 3
148 #define DENY_NONE 4
149 #define DENY_FCB 7
150
151 /* share types */
152 #define STYPE_DISKTREE  0       /* Disk drive */
153 #define STYPE_PRINTQ    1       /* Spooler queue */
154 #define STYPE_DEVICE    2       /* Serial device */
155 #define STYPE_IPC       3       /* Interprocess communication (IPC) */
156 #define STYPE_HIDDEN    0x80000000 /* share is a hidden one (ends with $) */
157
158 /* SMB X/Open error codes for the ERRdos error class */
159 #define ERRbadfunc 1 /* Invalid function (or system call) */
160 #define ERRbadfile 2 /* File not found (pathname error) */
161 #define ERRbadpath 3 /* Directory not found */
162 #define ERRnofids 4 /* Too many open files */
163 #define ERRnoaccess 5 /* Access denied */
164 #define ERRbadfid 6 /* Invalid fid */
165 #define ERRnomem 8 /* Out of memory */
166 #define ERRbadmem 9 /* Invalid memory block address */
167 #define ERRbadenv 10 /* Invalid environment */
168 #define ERRbadaccess 12 /* Invalid open mode */
169 #define ERRbaddata 13 /* Invalid data (only from ioctl call) */
170 #define ERRres 14 /* reserved */
171 #define ERRbaddrive 15 /* Invalid drive */
172 #define ERRremcd 16 /* Attempt to delete current directory */
173 #define ERRdiffdevice 17 /* rename/move across different filesystems */
174 #define ERRnofiles 18 /* no more files found in file search */
175 #define ERRbadshare 32 /* Share mode on file conflict with open mode */
176 #define ERRlock 33 /* Lock request conflicts with existing lock */
177 #define ERRfilexists 80 /* File in operation already exists */
178 #define ERRcannotopen 110 /* Cannot open the file specified */
179 #define ERRunknownlevel 124
180 #define ERRbadpipe 230 /* Named pipe invalid */
181 #define ERRpipebusy 231 /* All instances of pipe are busy */
182 #define ERRpipeclosing 232 /* named pipe close in progress */
183 #define ERRnotconnected 233 /* No process on other end of named pipe */
184 #define ERRmoredata 234 /* More data to be returned */
185 #define ERRbaddirectory 267 /* Invalid directory name in a path. */
186 #define ERROR_EAS_DIDNT_FIT 275 /* Extended attributes didn't fit */
187 #define ERROR_EAS_NOT_SUPPORTED 282 /* Extended attributes not supported */
188 #define ERRunknownipc 2142
189
190
191 /* here's a special one from observing NT */
192 #define ERRnoipc 66 /* don't support ipc */
193
194 /* Error codes for the ERRSRV class */
195
196 #define ERRerror 1 /* Non specific error code */
197 #define ERRbadpw 2 /* Bad password */
198 #define ERRbadtype 3 /* reserved */
199 #define ERRaccess 4 /* No permissions to do the requested operation */
200 #define ERRinvnid 5 /* tid invalid */
201 #define ERRinvnetname 6 /* Invalid servername */
202 #define ERRinvdevice 7 /* Invalid device */
203 #define ERRqfull 49 /* Print queue full */
204 #define ERRqtoobig 50 /* Queued item too big */
205 #define ERRinvpfid 52 /* Invalid print file in smb_fid */
206 #define ERRsmbcmd 64 /* Unrecognised command */
207 #define ERRsrverror 65 /* smb server internal error */
208 #define ERRfilespecs 67 /* fid and pathname invalid combination */
209 #define ERRbadlink 68 /* reserved */
210 #define ERRbadpermits 69 /* Access specified for a file is not valid */
211 #define ERRbadpid 70 /* reserved */
212 #define ERRsetattrmode 71 /* attribute mode invalid */
213 #define ERRpaused 81 /* Message server paused */
214 #define ERRmsgoff 82 /* Not receiving messages */
215 #define ERRnoroom 83 /* No room for message */
216 #define ERRrmuns 87 /* too many remote usernames */
217 #define ERRtimeout 88 /* operation timed out */
218 #define ERRnoresource  89 /* No resources currently available for request. */
219 #define ERRtoomanyuids 90 /* too many userids */
220 #define ERRbaduid 91 /* bad userid */
221 #define ERRuseMPX 250 /* temporarily unable to use raw mode, use MPX mode */
222 #define ERRuseSTD 251 /* temporarily unable to use raw mode, use standard mode */
223 #define ERRcontMPX 252 /* resume MPX mode */
224 #define ERRbadPW /* reserved */
225 #define ERRnosupport 0xFFFF
226 #define ERRunknownsmb 22 /* from NT 3.5 response */
227
228
229 /* Error codes for the ERRHRD class */
230
231 #define ERRnowrite 19 /* read only media */
232 #define ERRbadunit 20 /* Unknown device */
233 #define ERRnotready 21 /* Drive not ready */
234 #define ERRbadcmd 22 /* Unknown command */
235 #define ERRdata 23 /* Data (CRC) error */
236 #define ERRbadreq 24 /* Bad request structure length */
237 #define ERRseek 25
238 #define ERRbadmedia 26
239 #define ERRbadsector 27
240 #define ERRnopaper 28
241 #define ERRwrite 29 /* write fault */
242 #define ERRread 30 /* read fault */
243 #define ERRgeneral 31 /* General hardware failure */
244 #define ERRwrongdisk 34
245 #define ERRFCBunavail 35
246 #define ERRsharebufexc 36 /* share buffer exceeded */
247 #define ERRdiskfull 39
248
249
250 typedef char pstring[1024];
251 typedef char fstring[128];
252 typedef fstring string;
253
254
255 /* pipe strings */
256 #define PIPE_LANMAN   "\\PIPE\\LANMAN"
257 #define PIPE_SRVSVC   "\\PIPE\\srvsvc"
258 #define PIPE_SAMR     "\\PIPE\\samr"
259 #define PIPE_WKSSVC   "\\PIPE\\wkssvc"
260 #define PIPE_NETLOGON "\\PIPE\\NETLOGON"
261 #define PIPE_NTLSA    "\\PIPE\\ntlsa"
262 #define PIPE_NTSVCS   "\\PIPE\\ntsvcs"
263 #define PIPE_LSASS    "\\PIPE\\lsass"
264 #define PIPE_LSARPC   "\\PIPE\\lsarpc"
265
266 /* NETLOGON opcodes and data structures */
267
268 enum RPC_PKT_TYPE
269 {
270         RPC_REQUEST = 0x00,
271         RPC_RESPONSE = 0x02,
272         RPC_BIND     = 0x0B,
273         RPC_BINDACK  = 0x0C
274 };
275
276 #define NET_QUERYFORPDC      7 /* Query for PDC */
277 #define NET_QUERYFORPDC_R   12 /* Response to Query for PDC */
278 #define NET_SAMLOGON        18
279 #define NET_SAMLOGON_R      19
280
281 /* Allowable account control bits */
282 #define ACB_DISABLED   1 /* 1 = User account disabled */
283 #define ACB_HOMDIRREQ  2 /* 1 = Home directory required */
284 #define ACB_PWNOTREQ   4 /* 1 = User password not required */
285 #define ACB_TEMPDUP      /* 1 = Temporary duplicate account */
286 #define ACB_NORMAL       /* 1 = Normal user account */
287 #define ACB_MNS          /* 1 = MNS logon user account */
288 #define ACB_DOMTRUST     /* 1 = Interdomain trust account */
289 #define ACB_WSTRUST      /* 1 = Workstation trust account */
290 #define ACB_SVRTRUST     /* 1 = Server trust account */
291 #define ACB_PWNOEXP      /* 1 = User password does not expire */
292 #define ACB_AUTOLOCK     /* 1 = Account auto locked */
293
294 #define SAMR_CLOSE          0x01
295 #define SAMR_OPEN_SECRET    0x07
296 #define SAMR_LOOKUP_RIDS    0x11
297 #define SAMR_UNKNOWN_3      0x03
298 #define SAMR_UNKNOWN_22     0x22
299 #define SAMR_UNKNOWN_24     0x24
300 #define SAMR_UNKNOWN_34     0x34
301 #define SAMR_OPEN_POLICY    0x39
302
303 #define LSA_OPENPOLICY      0x2c
304 #define LSA_QUERYINFOPOLICY 0x07
305 #define LSA_ENUMTRUSTDOM    0x0d
306 #define LSA_REQCHAL         0x04
307 #define LSA_SRVPWSET        0x06
308 #define LSA_SAMLOGON        0x02
309 #define LSA_SAMLOGOFF       0x03
310 #define LSA_AUTH2           0x0f
311 #define LSA_CLOSE           0x00
312
313 /* XXXX these are here to get a compile! */
314
315 #define LSA_OPENSECRET      0xFF
316 #define LSA_LOOKUPSIDS      0xFE
317 #define LSA_LOOKUPRIDS      0xFD
318 #define LSA_LOOKUPNAMES     0xFC
319
320 /* srvsvc pipe */
321 #define NETSERVERGETINFO 0x15
322 #define NETSHAREENUM     0x0f
323
324 /* well-known RIDs - Relative IDs */
325
326 /* RIDs - Well-known users ... */
327 #define DOMAIN_USER_RID_ADMIN          (0x000001F4L)
328 #define DOMAIN_USER_RID_GUEST          (0x000001F5L)
329
330 /* RIDs - well-known groups ... */
331 #define DOMAIN_GROUP_RID_ADMINS        (0x00000200L)
332 #define DOMAIN_GROUP_RID_USERS         (0x00000201L)
333 #define DOMAIN_GROUP_RID_GUESTS        (0x00000202L)
334
335 /* RIDs - well-known aliases ... */
336 #define DOMAIN_ALIAS_RID_ADMINS        (0x00000220L)
337 #define DOMAIN_ALIAS_RID_USERS         (0x00000221L)
338 #define DOMAIN_ALIAS_RID_GUESTS        (0x00000222L)
339 #define DOMAIN_ALIAS_RID_POWER_USERS   (0x00000223L)
340
341 #define DOMAIN_ALIAS_RID_ACCOUNT_OPS   (0x00000224L)
342 #define DOMAIN_ALIAS_RID_SYSTEM_OPS    (0x00000225L)
343 #define DOMAIN_ALIAS_RID_PRINT_OPS     (0x00000226L)
344 #define DOMAIN_ALIAS_RID_BACKUP_OPS    (0x00000227L)
345
346 #define DOMAIN_ALIAS_RID_REPLICATOR    (0x00000228L)
347
348
349
350 /* 32 bit time (sec) since 01jan1970 - cifs6.txt, section 3.5, page 30 */
351 typedef struct time_info
352 {
353   uint32 time;
354
355 } UTIME;
356
357 /* 64 bit time (100usec) since ????? - cifs6.txt, section 3.5, page 30 */
358 typedef struct nttime_info
359 {
360   uint32 low;
361   uint32 high;
362
363 } NTTIME;
364  
365
366 #define MAXSUBAUTHS 15 /* max sub authorities in a SID */
367
368 /* DOM_SID - security id */
369 typedef struct sid_info
370 {
371   uint8  sid_rev_num;             /* SID revision number */
372   uint8  num_auths;               /* number of sub-authorities */
373   uint8  id_auth[6];              /* Identifier Authority */
374   uint32 sub_auths[MAXSUBAUTHS];  /* pointer to sub-authorities. */
375
376 } DOM_SID;
377
378 /* UNIHDR - unicode string header */
379 typedef struct unihdr_info
380 {
381   uint16 uni_max_len;
382   uint16 uni_str_len;
383   uint32 undoc; /* usually has a value of 4 */
384
385 } UNIHDR;
386
387 /* UNIHDR2 - unicode string header and undocumented buffer */
388 typedef struct unihdr2_info
389 {
390   UNIHDR unihdr;
391   uint32 undoc_buffer; /* undocumented 32 bit buffer pointer */
392
393 } UNIHDR2;
394
395 /* clueless as to what maximum length should be */
396 #define MAX_UNISTRLEN 1024
397
398 /* UNISTR - unicode string size and buffer */
399 typedef struct unistr_info
400 {
401   uint16 buffer[MAX_UNISTRLEN]; /* unicode characters. ***MUST*** be null-terminated */
402
403 } UNISTR;
404
405 /* UNISTR2 - unicode string size and buffer */
406 typedef struct unistr2_info
407 {
408   uint32 uni_max_len;
409   uint32 undoc;
410   uint32 uni_str_len;
411   uint16 buffer[MAX_UNISTRLEN]; /* unicode characters. **NOT** necessarily null-terminated */
412
413 } UNISTR2;
414
415 /* DOM_SID2 - domain SID structure - SIDs stored in unicode */
416 typedef struct domsid2_info
417 {
418   uint32 type; /* value is 5 */
419   uint32 undoc; /* value is 0 */
420
421   UNIHDR2 hdr; /* XXXX conflict between hdr and str for length */
422   UNISTR  str; /* XXXX conflict between hdr and str for length */
423
424 } DOM_SID2;
425
426 /* DOM_RID2 - domain RID structure for ntlsa pipe */
427 typedef struct domrid2_info
428 {
429   uint32 type; /* value is 5 */
430   uint32 undoc; /* value is non-zero */
431   uint32 rid;
432   uint32 rid_idx; /* don't know what this is */
433
434 } DOM_RID2;
435
436 /* DOM_RID3 - domain RID structure for samr pipe */
437 typedef struct domrid3_info
438 {
439   uint32 rid;        /* domain-relative (to a SID) id */
440   uint32 type1;      /* value is 0x1 */
441   uint32 ptr_type;   /* undocumented pointer */
442   uint32 type2;      /* value is 0x1 */
443
444 } DOM_RID3;
445
446 /* DOM_CLNT_SRV - client / server names */
447 typedef struct clnt_srv_info
448 {
449   uint32  undoc_buffer; /* undocumented 32 bit buffer pointer */
450   UNISTR2 uni_logon_srv; /* logon server name */
451   uint32  undoc_buffer2; /* undocumented 32 bit buffer pointer */
452   UNISTR2 uni_comp_name; /* client machine name */
453
454 } DOM_CLNT_SRV;
455
456 /* DOM_LOG_INFO - login info */
457 typedef struct log_info
458 {
459   uint32  undoc_buffer; /* undocumented 32 bit buffer pointer */
460   UNISTR2 uni_logon_srv; /* logon server name */
461   UNISTR2 uni_acct_name; /* account name */
462   uint16  sec_chan;      /* secure channel type */
463   UNISTR2 uni_comp_name; /* client machine name */
464
465 } DOM_LOG_INFO;
466
467 /* DOM_CHAL - challenge info */
468 typedef struct chal_info
469 {
470   uchar data[8]; /* credentials */
471 } DOM_CHAL;
472
473 /* DOM_CREDs - timestamped client or server credentials */
474 typedef struct cred_info
475 {
476   DOM_CHAL challenge; /* credentials */
477   UTIME timestamp;    /* credential time-stamp */
478
479 } DOM_CRED;
480
481 /* DOM_CLNT_INFO - client info */
482 typedef struct clnt_info
483 {
484   DOM_LOG_INFO login;
485   DOM_CRED     cred;
486
487 } DOM_CLNT_INFO;
488
489 /* DOM_CLNT_INFO2 - client info */
490 typedef struct clnt_info2
491 {
492   DOM_CLNT_SRV login;
493   uint32        ptr_cred;
494   DOM_CRED      cred;
495
496 } DOM_CLNT_INFO2;
497
498 /* DOM_LOGON_ID - logon id */
499 typedef struct logon_info
500 {
501   uint32 low;
502   uint32 high;
503
504 } DOM_LOGON_ID;
505
506 /* ARC4_OWF */
507 typedef struct arc4_owf_info
508 {
509   uint8 data[16];
510
511 } ARC4_OWF;
512
513
514 /* DOM_ID_INFO_1 */
515 typedef struct id_info_1
516 {
517   uint32            ptr_id_info1;        /* pointer to id_info_1 */
518   UNIHDR            hdr_domain_name;     /* domain name unicode header */
519   uint32            param_ctrl;          /* param control */
520   DOM_LOGON_ID      logon_id;            /* logon ID */
521   UNIHDR            hdr_user_name;       /* user name unicode header */
522   UNIHDR            hdr_wksta_name;      /* workgroup name unicode header */
523   ARC4_OWF          arc4_lm_owf;         /* arc4 LM OWF Password */
524   ARC4_OWF          arc4_nt_owf;         /* arc4 NT OWF Password */
525   UNISTR2           uni_domain_name;     /* domain name unicode string */
526   UNISTR2           uni_user_name;       /* user name unicode string */
527   UNISTR2           uni_wksta_name;      /* workgroup name unicode string */
528
529 } DOM_ID_INFO_1;
530
531 /* SAM_INFO - sam logon/off id structure */
532 typedef struct sam_info
533 {
534   DOM_CLNT_INFO2 client;
535   uint32         ptr_rtn_cred; /* pointer to return credentials */
536   DOM_CRED       rtn_cred; /* return credentials */
537   uint16         logon_level;
538   uint16         switch_value;
539   
540   union
541   {
542     DOM_ID_INFO_1 *id1; /* auth-level 1 */
543
544   } auth;
545   
546 } DOM_SAM_INFO;
547
548 /* DOM_GID - group id + user attributes */
549 typedef struct gid_info
550 {
551   uint32 g_rid;  /* a group RID */
552   uint32 attr;
553
554 } DOM_GID;
555
556 /* RPC_HDR - ms rpc header */
557 typedef struct rpc_hdr_info
558 {
559   uint8  major; /* 5 - RPC major version */
560   uint8  minor; /* 0 - RPC minor version */
561   uint8  pkt_type; /* 2 - RPC response packet */
562   uint8  frag; /* 3 - first frag + last frag */
563   uint32 pack_type; /* 0x1000 0000 - packed data representation */
564   uint16 frag_len; /* fragment length - data size (bytes) inc header and tail. */
565   uint16 auth_len; /* 0 - authentication length  */
566   uint32 call_id; /* call identifier.  matches 12th uint32 of incoming RPC data. */
567
568 } RPC_HDR;
569
570 /* RPC_HDR_RR - ms request / response rpc header */
571 typedef struct rpc_hdr_rr_info
572 {
573   RPC_HDR hdr;
574
575   uint32 alloc_hint; /* allocation hint - data size (bytes) minus header and tail. */
576   uint16 context_id; /* 0 - presentation context identifier */
577   uint8  cancel_count; /* 0 - cancel count */
578   uint8  opnum; /* request: 0 - reserved.  response: opnum */
579
580 } RPC_HDR_RR;
581
582 /* the interfaces are numbered. as yet I haven't seen more than one interface
583  * used on the same pipe name
584  * srvsvc
585  *   abstract (0x4B324FC8, 0x01D31670, 0x475A7812, 0x88E16EBF, 0x00000003)
586  *   transfer (0x8A885D04, 0x11C91CEB, 0x0008E89F, 0x6048102B, 0x00000002)
587  */
588 /* RPC_IFACE */
589 typedef struct rpc_iface_info
590 {
591   uint8 data[16];    /* 16 bytes of number */
592   uint32 version;    /* the interface number */
593
594 } RPC_IFACE;
595
596
597 /* this seems to be the same string name depending on the name of the pipe,
598  * but is more likely to be linked to the interface name
599  * "srvsvc", "\\PIPE\\ntsvcs"
600  * "samr", "\\PIPE\\lsass"
601  * "wkssvc", "\\PIPE\\wksvcs"
602  * "NETLOGON", "\\PIPE\\NETLOGON"
603  */
604 /* RPC_ADDR_STR */
605 typedef struct rpc_addr_info
606 {
607   uint16 len;   /* length of the string including null terminator */
608   fstring str; /* the string above in single byte, null terminated form */
609
610 } RPC_ADDR_STR;
611
612 /* RPC_HDR_BBA */
613 typedef struct rpc_hdr_bba_info
614 {
615   uint16 max_tsize;       /* maximum transmission fragment size (0x1630) */
616   uint16 max_rsize;       /* max receive fragment size (0x1630) */
617   uint32 assoc_gid;       /* associated group id (0x0) */
618
619 } RPC_HDR_BBA;
620
621 /* RPC_BIND_REQ - ms req bind */
622 typedef struct rpc_bind_req_info
623 {
624   RPC_HDR_BBA bba;
625
626   uint32 num_elements;    /* the number of elements (0x1) */
627   uint16 context_id;      /* presentation context identifier (0x0) */
628   uint8 num_syntaxes;     /* the number of syntaxes (has always been 1?)(0x1) */
629
630   RPC_IFACE abstract;     /* num and vers. of interface client is using */
631   RPC_IFACE transfer;     /* num and vers. of interface to use for replies */
632   
633 } RPC_HDR_RB;
634
635 /* RPC_RESULTS - can only cope with one reason, right now... */
636 typedef struct rpc_results_info
637 {
638 /* uint8[] # 4-byte alignment padding, against SMB header */
639
640   uint8 num_results; /* the number of results (0x01) */
641
642 /* uint8[] # 4-byte alignment padding, against SMB header */
643
644   uint16 result; /* result (0x00 = accept) */
645   uint16 reason; /* reason (0x00 = no reason specified) */
646
647 } RPC_RESULTS;
648
649 /* RPC_HDR_BA */
650 typedef struct rpc_hdr_ba_info
651 {
652   RPC_HDR_BBA bba;
653
654   RPC_ADDR_STR addr    ;  /* the secondary address string, as described earlier */
655   RPC_RESULTS  res     ; /* results and reasons */
656   RPC_IFACE    transfer; /* the transfer syntax from the request */
657
658 } RPC_HDR_BA;
659
660
661 /* DOM_QUERY - info class 3 and 5 LSA Query response */
662 typedef struct dom_query_info
663 {
664   uint16 uni_dom_max_len; /* domain name string length * 2 */
665   uint16 uni_dom_str_len; /* domain name string length * 2 */
666   uint32 buffer_dom_name; /* undocumented domain name string buffer pointer */
667   uint32 buffer_dom_sid; /* undocumented domain SID string buffer pointer */
668   UNISTR2 uni_domain_name; /* domain name (unicode string) */
669   DOM_SID dom_sid; /* domain SID */
670
671 } DOM_QUERY;
672
673 /* level 5 is same as level 3.  we hope. */
674 typedef DOM_QUERY DOM_QUERY_3;
675 typedef DOM_QUERY DOM_QUERY_5;
676
677 #define POL_HND_SIZE 20
678
679 /* LSA_POL_HND */
680 typedef struct lsa_policy_info
681 {
682   uint8 data[POL_HND_SIZE]; /* policy handle */
683
684 } LSA_POL_HND;
685
686 /* OBJ_ATTR (object attributes) */
687 typedef struct object_attributes_info
688 {
689         uint32 len;          /* 0x18 - length (in bytes) inc. the length field. */
690         uint32 ptr_root_dir; /* 0 - root directory (pointer) */
691         uint32 ptr_obj_name; /* 0 - object name (pointer) */
692         uint32 attributes;   /* 0 - attributes (undocumented) */
693         uint32 ptr_sec_desc; /* 0 - security descriptior (pointer) */
694         uint32 sec_qos;      /* 0 - security quality of service */
695
696 } LSA_OBJ_ATTR;
697
698 /* LSA_Q_OPEN_POL - LSA Query Open Policy */
699 typedef struct lsa_q_open_pol_info
700 {
701         uint32       ptr;             /* undocumented buffer pointer */
702         UNISTR2      uni_server_name; /* server name, starting with two '\'s */
703         LSA_OBJ_ATTR attr           ; /* object attributes */
704
705         uint32 des_access; /* desired access attributes */
706
707 } LSA_Q_OPEN_POL;
708
709 /* LSA_R_OPEN_POL - response to LSA Open Policy */
710 typedef struct lsa_r_open_pol_info
711 {
712         LSA_POL_HND pol; /* policy handle */
713
714         uint32 status; /* return code */
715
716 } LSA_R_OPEN_POL;
717
718 /* LSA_Q_QUERY_INFO - LSA query info policy */
719 typedef struct lsa_query_info
720 {
721         LSA_POL_HND pol; /* policy handle */
722     uint16 info_class; /* info class */
723
724 } LSA_Q_QUERY_INFO;
725
726 /* LSA_R_QUERY_INFO - response to LSA query info policy */
727 typedef struct lsa_r_query_info
728 {
729     uint32 undoc_buffer; /* undocumented buffer pointer */
730     uint16 info_class; /* info class (same as info class in request) */
731     
732         union
733     {
734         DOM_QUERY_3 id3;
735                 DOM_QUERY_5 id5;
736
737     } dom;
738
739         uint32 status; /* return code */
740
741 } LSA_R_QUERY_INFO;
742
743 /* LSA_Q_ENUM_TRUST_DOM - LSA enumerate trusted domains */
744 typedef struct lsa_enum_trust_dom_info
745 {
746         LSA_POL_HND pol; /* policy handle */
747     uint32 enum_context; /* enumeration context handle */
748     uint32 preferred_len; /* preferred maximum length */
749
750 } LSA_Q_ENUM_TRUST_DOM;
751
752 /* LSA_R_ENUM_TRUST_DOM - response to LSA enumerate trusted domains */
753 typedef struct lsa_r_enum_trust_dom_info
754 {
755         LSA_POL_HND pol; /* policy handle */
756
757     uint32 status; /* return code */
758
759 } LSA_R_ENUM_TRUST_DOM;
760
761 /* LSA_Q_CLOSE */
762 typedef struct lsa_q_close_info
763 {
764         LSA_POL_HND pol; /* policy handle */
765
766 } LSA_Q_CLOSE;
767
768 /* LSA_R_CLOSE */
769 typedef struct lsa_r_close_info
770 {
771         LSA_POL_HND pol; /* policy handle.  should be all zeros. */
772
773         uint32 status; /* return code */
774
775 } LSA_R_CLOSE;
776
777
778 #define MAX_REF_DOMAINS 10
779
780 /* DOM_R_REF */
781 typedef struct dom_ref_info
782 {
783     uint32 undoc_buffer; /* undocumented buffer pointer. */
784     uint32 num_ref_doms_1; /* num referenced domains? */
785     uint32 buffer_dom_name; /* undocumented domain name buffer pointer. */
786     uint32 max_entries; /* 32 - max number of entries */
787     uint32 num_ref_doms_2; /* 4 - num referenced domains? */
788
789     UNIHDR2 hdr_dom_name; /* domain name unicode string header */
790     UNIHDR2 hdr_ref_dom[MAX_REF_DOMAINS]; /* referenced domain unicode string headers */
791
792     UNISTR uni_dom_name; /* domain name unicode string */
793     DOM_SID ref_dom[MAX_REF_DOMAINS]; /* referenced domain SIDs */
794
795 } DOM_R_REF;
796
797 #define MAX_LOOKUP_SIDS 10
798
799 /* LSA_Q_LOOKUP_SIDS - LSA Lookup SIDs */
800 typedef struct lsa_q_lookup_sids
801 {
802     LSA_POL_HND pol_hnd; /* policy handle */
803     uint32 num_entries;
804     uint32 buffer_dom_sid; /* undocumented domain SID buffer pointer */
805     uint32 buffer_dom_name; /* undocumented domain name buffer pointer */
806     uint32 buffer_lookup_sids[MAX_LOOKUP_SIDS]; /* undocumented domain SID pointers to be looked up. */
807     DOM_SID dom_sids[MAX_LOOKUP_SIDS]; /* domain SIDs to be looked up. */
808     uint8 undoc[16]; /* completely undocumented 16 bytes */
809
810 } LSA_Q_LOOKUP_SIDS;
811
812 /* LSA_R_LOOKUP_SIDS - response to LSA Lookup SIDs */
813 typedef struct lsa_r_lookup_sids
814 {
815     DOM_R_REF dom_ref; /* domain reference info */
816
817     uint32 num_entries;
818     uint32 undoc_buffer; /* undocumented buffer pointer */
819     uint32 num_entries2; 
820
821     DOM_SID2 dom_sid[MAX_LOOKUP_SIDS]; /* domain SIDs being looked up */
822
823     uint32 num_entries3; 
824
825   uint32 status; /* return code */
826
827 } LSA_R_LOOKUP_SIDS;
828
829 /* DOM_NAME - XXXX not sure about this structure */
830 typedef struct dom_name_info
831 {
832     uint32 uni_str_len;
833         UNISTR str;
834
835 } DOM_NAME;
836
837
838 #define UNKNOWN_LEN 1
839
840 /* LSA_Q_LOOKUP_RIDS - LSA Lookup RIDs */
841 typedef struct lsa_q_lookup_rids
842 {
843
844     LSA_POL_HND pol_hnd; /* policy handle */
845     uint32 num_entries;
846     uint32 num_entries2;
847     uint32 buffer_dom_sid; /* undocumented domain SID buffer pointer */
848     uint32 buffer_dom_name; /* undocumented domain name buffer pointer */
849     DOM_NAME lookup_name[MAX_LOOKUP_SIDS]; /* names to be looked up */
850     uint8 undoc[UNKNOWN_LEN]; /* completely undocumented bytes of unknown length */
851
852 } LSA_Q_LOOKUP_RIDS;
853
854 /* LSA_R_LOOKUP_RIDS - response to LSA Lookup RIDs by name */
855 typedef struct lsa_r_lookup_rids
856 {
857     DOM_R_REF dom_ref; /* domain reference info */
858
859     uint32 num_entries;
860     uint32 undoc_buffer; /* undocumented buffer pointer */
861
862     uint32 num_entries2; 
863     DOM_RID2 dom_rid[MAX_LOOKUP_SIDS]; /* domain RIDs being looked up */
864
865     uint32 num_entries3; 
866
867   uint32 status; /* return code */
868
869 } LSA_R_LOOKUP_RIDS;
870
871
872
873 /* NEG_FLAGS */
874 typedef struct lsa_neg_flags_info
875 {
876     uint32 neg_flags; /* negotiated flags */
877
878 } NEG_FLAGS;
879
880
881 /* LSA_Q_REQ_CHAL */
882 typedef struct lsa_q_req_chal_info
883 {
884     uint32  undoc_buffer; /* undocumented buffer pointer */
885     UNISTR2 uni_logon_srv; /* logon server unicode string */
886     UNISTR2 uni_logon_clnt; /* logon client unicode string */
887     DOM_CHAL clnt_chal; /* client challenge */
888
889 } LSA_Q_REQ_CHAL;
890
891
892 /* LSA_R_REQ_CHAL */
893 typedef struct lsa_r_req_chal_info
894 {
895     DOM_CHAL srv_chal; /* server challenge */
896
897   uint32 status; /* return code */
898
899 } LSA_R_REQ_CHAL;
900
901
902
903 /* LSA_Q_AUTH_2 */
904 typedef struct lsa_q_auth2_info
905 {
906     DOM_LOG_INFO clnt_id; /* client identification info */
907     DOM_CHAL clnt_chal;     /* client-calculated credentials */
908
909     NEG_FLAGS clnt_flgs; /* usually 0x0000 01ff */
910
911 } LSA_Q_AUTH_2;
912
913
914 /* LSA_R_AUTH_2 */
915 typedef struct lsa_r_auth2_info
916 {
917     DOM_CHAL srv_chal;     /* server-calculated credentials */
918     NEG_FLAGS srv_flgs; /* usually 0x0000 01ff */
919
920   uint32 status; /* return code */
921
922 } LSA_R_AUTH_2;
923
924
925 /* LSA_Q_SRV_PWSET */
926 typedef struct lsa_q_srv_pwset_info
927 {
928     DOM_CLNT_INFO clnt_id; /* client identification/authentication info */
929     char pwd[16]; /* new password - undocumented. */
930
931 } LSA_Q_SRV_PWSET;
932     
933 /* LSA_R_SRV_PWSET */
934 typedef struct lsa_r_srv_pwset_info
935 {
936     DOM_CRED srv_cred;     /* server-calculated credentials */
937
938   uint32 status; /* return code */
939
940 } LSA_R_SRV_PWSET;
941
942 #define LSA_MAX_GROUPS 32
943 #define LSA_MAX_SIDS 32
944
945 /* LSA_USER_INFO */
946 typedef struct lsa_q_user_info
947 {
948         uint32 ptr_user_info;
949
950         NTTIME logon_time;            /* logon time */
951         NTTIME logoff_time;           /* logoff time */
952         NTTIME kickoff_time;          /* kickoff time */
953         NTTIME pass_last_set_time;    /* password last set time */
954         NTTIME pass_can_change_time;  /* password can change time */
955         NTTIME pass_must_change_time; /* password must change time */
956
957         UNIHDR hdr_user_name;    /* username unicode string header */
958         UNIHDR hdr_full_name;    /* user's full name unicode string header */
959         UNIHDR hdr_logon_script; /* logon script unicode string header */
960         UNIHDR hdr_profile_path; /* profile path unicode string header */
961         UNIHDR hdr_home_dir;     /* home directory unicode string header */
962         UNIHDR hdr_dir_drive;    /* home directory drive unicode string header */
963
964         uint16 logon_count;  /* logon count */
965         uint16 bad_pw_count; /* bad password count */
966
967         uint32 user_id;       /* User ID */
968         uint32 group_id;      /* Group ID */
969         uint32 num_groups;    /* num groups */
970         uint32 buffer_groups; /* undocumented buffer pointer to groups. */
971         uint32 user_flgs;     /* user flags */
972
973         char user_sess_key[16]; /* unused user session key */
974
975         UNIHDR hdr_logon_srv; /* logon server unicode string header */
976         UNIHDR hdr_logon_dom; /* logon domain unicode string header */
977
978         uint32 buffer_dom_id; /* undocumented logon domain id pointer */
979         char padding[40];    /* unused padding bytes.  expansion room */
980
981         uint32 num_other_sids; /* 0 - num_sids */
982         uint32 buffer_other_sids; /* NULL - undocumented pointer to SIDs. */
983         
984         UNISTR2 uni_user_name;    /* username unicode string */
985         UNISTR2 uni_full_name;    /* user's full name unicode string */
986         UNISTR2 uni_logon_script; /* logon script unicode string */
987         UNISTR2 uni_profile_path; /* profile path unicode string */
988         UNISTR2 uni_home_dir;     /* home directory unicode string */
989         UNISTR2 uni_dir_drive;    /* home directory drive unicode string */
990
991         uint32 num_groups2;        /* num groups */
992         DOM_GID gids[LSA_MAX_GROUPS]; /* group info */
993
994         UNISTR2 uni_logon_srv; /* logon server unicode string */
995         UNISTR2 uni_logon_dom; /* logon domain unicode string */
996
997         DOM_SID dom_sid;           /* domain SID */
998         DOM_SID other_sids[LSA_MAX_SIDS]; /* undocumented - domain SIDs */
999
1000 } LSA_USER_INFO;
1001
1002
1003 /* LSA_Q_SAM_LOGON */
1004 typedef struct lsa_q_sam_logon_info
1005 {
1006     DOM_SAM_INFO sam_id;
1007
1008 } LSA_Q_SAM_LOGON;
1009
1010 /* LSA_R_SAM_LOGON */
1011 typedef struct lsa_r_sam_logon_info
1012 {
1013     uint32 buffer_creds; /* undocumented buffer pointer */
1014     DOM_CRED srv_creds; /* server credentials.  server time stamp appears to be ignored. */
1015     
1016         uint16 switch_value; /* 3 - indicates type of USER INFO */
1017     LSA_USER_INFO *user;
1018
1019     uint32 auth_resp; /* 1 - Authoritative response; 0 - Non-Auth? */
1020
1021   uint32 status; /* return code */
1022
1023 } LSA_R_SAM_LOGON;
1024
1025
1026 /* LSA_Q_SAM_LOGOFF */
1027 typedef struct lsa_q_sam_logoff_info
1028 {
1029     DOM_SAM_INFO sam_id;
1030
1031 } LSA_Q_SAM_LOGOFF;
1032
1033 /* LSA_R_SAM_LOGOFF */
1034 typedef struct lsa_r_sam_logoff_info
1035 {
1036     uint32 buffer_creds; /* undocumented buffer pointer */
1037     DOM_CRED srv_creds; /* server credentials.  server time stamp appears to be ignored. */
1038     
1039   uint32 status; /* return code */
1040
1041 } LSA_R_SAM_LOGOFF;
1042
1043
1044 /* SH_INFO_1 (pointers to level 1 share info strings) */
1045 typedef struct ptr_share_info1
1046 {
1047         uint32 ptr_netname; /* pointer to net name. */
1048         uint32 type;        /* type of share.  0 - undocumented. */
1049         uint32 ptr_remark;  /* pointer to comment. */
1050
1051 } SH_INFO_1;
1052
1053 /* SH_INFO_1_STR (level 1 share info strings) */
1054 typedef struct str_share_info1
1055 {
1056         UNISTR2 uni_netname; /* unicode string of net name */
1057         UNISTR2 uni_remark;  /* unicode string of comment. */
1058
1059 } SH_INFO_1_STR;
1060
1061 /* oops - this is going to take up a *massive* amount of stack. */
1062 /* the UNISTR2s already have 1024 uint16 chars in them... */
1063 #define MAX_SHARE_ENTRIES 32
1064
1065 /* SHARE_INFO_1_CONTAINER  */
1066 typedef struct share_info_ctr
1067 {
1068         uint32 num_entries_read;                     /* EntriesRead */
1069         uint32 ptr_share_info;                       /* Buffer */
1070         uint32 num_entries_read2;                    /* EntriesRead */
1071         SH_INFO_1     info_1    [MAX_SHARE_ENTRIES]; /* share entry pointers */
1072         SH_INFO_1_STR info_1_str[MAX_SHARE_ENTRIES]; /* share entry strings */
1073         uint32 num_entries_read3;                    /* EntriesRead2 */
1074         uint32 padding;                              /* padding */
1075
1076 } SHARE_INFO_1_CTR;
1077
1078
1079 /* SRV_Q_NET_SHARE_ENUM */
1080 typedef struct q_net_share_enum_info
1081 {
1082         uint32 ptr_srv_name;         /* pointer (to server name?) */
1083         UNISTR2 uni_srv_name;        /* server name */
1084
1085         uint32 share_level;          /* share level */
1086         uint32 switch_value;         /* switch value */
1087
1088         uint32 ptr_share_info;       /* pointer to SHARE_INFO_1_CTR */
1089
1090         union
1091     {
1092                 SHARE_INFO_1_CTR info1; /* share info with 0 entries */
1093
1094     } share;
1095
1096         uint32 preferred_len;        /* preferred maximum length (0xffff ffff) */
1097
1098 } SRV_Q_NET_SHARE_ENUM;
1099
1100
1101 /* SRV_R_NET_SHARE_ENUM */
1102 typedef struct r_net_share_enum_info
1103 {
1104         uint32 share_level;          /* share level */
1105         uint32 switch_value;         /* switch value */
1106
1107         uint32 ptr_share_info;       /* pointer to SHARE_INFO_1_CTR */
1108         union
1109     {
1110                 SHARE_INFO_1_CTR info1; /* share info container */
1111
1112     } share;
1113
1114         uint32 status;               /* return status */
1115
1116 } SRV_R_NET_SHARE_ENUM;
1117
1118
1119 /* SAMR_Q_CLOSE - probably a policy handle close */
1120 typedef struct q_samr_close_info
1121 {
1122     LSA_POL_HND pol;          /* policy handle */
1123
1124 } SAMR_Q_CLOSE;
1125
1126
1127 /* SAMR_R_CLOSE - probably a policy handle close */
1128 typedef struct r_samr_close_info
1129 {
1130     LSA_POL_HND pol;       /* policy handle */
1131         uint32 status;         /* return status */
1132
1133 } SAMR_R_CLOSE;
1134
1135
1136 /****************************************************************************
1137 SAMR_Q_OPEN_SECRET - unknown_0 values seen associated with SIDs:
1138
1139 0x0000 0200 and a specific   domain sid - S-1-5-21-44c01ca6-797e5c3d-33f83fd0
1140 0x0000 0280 and a well-known domain sid - S-1-5-20
1141 0x2000 0000 and a well-known domain sid - S-1-5-20
1142 0x2000 0000 and a specific   domain sid - S-1-5-21-44c01ca6-797e5c3d-33f83fd0
1143 *****************************************************************************/
1144
1145 /* SAMR_Q_OPEN_SECRET - probably an open secret */
1146 typedef struct q_samr_open_secret_info
1147 {
1148     LSA_POL_HND pol;          /* policy handle */
1149         uint32 unknown_0;         /* 0x2000 0000; 0x0000 0211; 0x0000 0280; 0x0000 0200 - unknown */
1150         DOM_SID dom_sid;          /* domain SID */
1151
1152 } SAMR_Q_OPEN_SECRET;
1153
1154
1155 /* SAMR_R_OPEN_SECRET - probably an open */
1156 typedef struct r_samr_open_secret_info
1157 {
1158     LSA_POL_HND pol;       /* policy handle associated with the SID */
1159         uint32 status;         /* return status */
1160
1161 } SAMR_R_OPEN_SECRET;
1162
1163
1164 /****************************************************************************
1165 SAMR_Q_LOOKUP_RIDS - do a conversion (only one!) from name to RID.
1166
1167 the policy handle allocated by an "samr open secret" call is associated
1168 with a SID.  this policy handle is what is queried here, *not* the SID
1169 itself.  the response to the lookup rids is relative to this SID.
1170 *****************************************************************************/
1171 /* SAMR_Q_LOOKUP_RIDS - probably a "read SAM entry" */
1172 typedef struct q_samr_lookup_names_info
1173 {
1174     LSA_POL_HND pol;             /* policy handle */
1175
1176         uint32 num_rids1;            /* 1          - number of rids being looked up */
1177         uint32 rid;                  /* 0000 03e8  - RID of the server being queried? */
1178         uint32 ptr;                  /* 0          - 32 bit unknown */
1179         uint32 num_rids2;            /* 1          - number of rids being looked up */
1180
1181         UNIHDR  hdr_mach_acct;       /* unicode machine account name header */
1182         UNISTR2 uni_mach_acct;       /* unicode machine account name */
1183
1184 } SAMR_Q_LOOKUP_RIDS;
1185
1186
1187 /* SAMR_R_LOOKUP_RIDS - probably an open */
1188 typedef struct r_samr_lookup_names_info
1189 {
1190         uint32 num_entries;
1191         uint32 undoc_buffer; /* undocumented buffer pointer */
1192
1193         uint32 num_entries2; 
1194         DOM_RID3 dom_rid[MAX_LOOKUP_SIDS]; /* domain RIDs being looked up */
1195
1196         uint32 num_entries3; 
1197
1198         uint32 status; /* return code */
1199
1200 } SAMR_R_LOOKUP_RIDS;
1201
1202
1203 /* SAMR_Q_UNKNOWN_22 - probably an open */
1204 typedef struct q_samr_unknown_22_info
1205 {
1206     LSA_POL_HND pol;          /* policy handle */
1207         uint32 unknown_id_0;      /* 0x0000 03E8 - 32 bit unknown id */
1208
1209 } SAMR_Q_UNKNOWN_22;
1210
1211
1212 /* SAMR_R_UNKNOWN_22 - probably an open */
1213 typedef struct r_samr_unknown_22_info
1214 {
1215     LSA_POL_HND pol;       /* policy handle associated with unknown id */
1216         uint32 status;         /* return status */
1217
1218 } SAMR_R_UNKNOWN_22;
1219
1220
1221 /* SAMR_Q_UNKNOWN_24 - probably a get sam info */
1222 typedef struct q_samr_unknown_24_info
1223 {
1224     LSA_POL_HND pol;          /* policy handle associated with unknown id */
1225         uint16 unknown_0;         /* 0x0015 or 0x0011 - 16 bit unknown */
1226
1227 } SAMR_Q_UNKNOWN_24;
1228
1229
1230 /* SAMR_R_UNKNOWN_24 - probably a get sam info */
1231 typedef struct r_samr_unknown_24_info
1232 {
1233         uint32 ptr;            /* pointer */
1234         uint16 unknown_0;      /* 0x0015 or 0x0011 - 16 bit unknown (same as above) */
1235         uint16 unknown_1;      /* 0x8b73 - 16 bit unknown */
1236         uint8  padding_0[16];  /* 0 - padding 16 bytes */
1237         NTTIME expiry;         /* expiry time or something? */
1238         uint8  padding_1[24];  /* 0 - padding 24 bytes */
1239
1240         UNIHDR hdr_mach_acct;  /* unicode header for machine account */
1241         uint32 padding_2;      /* 0 - padding 4 bytes */
1242
1243         uint32 ptr_1;          /* pointer */
1244         uint8  padding_3[32];  /* 0 - padding 32 bytes */
1245         uint32 padding_4;      /* 0 - padding 4 bytes */
1246
1247         uint32 ptr_2;          /* pointer */
1248         uint32 padding_5;      /* 0 - padding 4 bytes */
1249
1250         uint32 ptr_3;          /* pointer */
1251         uint8  padding_6[32];  /* 0 - padding 32 bytes */
1252
1253         uint32 unknown_id_0;   /* unknown id associated with policy handle */
1254         uint16 unknown_2;      /* 0x0201      - 16 bit unknown */
1255         uint32 unknown_3;      /* 0x0000 0080 - 32 bit unknown */
1256         uint16 unknown_4;      /* 0x003f      - 16 bit unknown */
1257         uint16 unknown_5;      /* 0x003c      - 16 bit unknown */
1258
1259         uint8  padding_7[16];  /* 0 - padding 16 bytes */
1260         uint32 padding_8;      /* 0 - padding 4 bytes */
1261         
1262         UNISTR2 uni_mach_acct; /* unicode string for machine account */
1263
1264         uint8  padding_9[48];  /* 0 - padding 48 bytes */
1265
1266         uint32 status;         /* return status */
1267
1268 } SAMR_R_UNKNOWN_24;
1269
1270
1271 /* SAMR_Q_UNKNOWN_32 - probably a "create SAM entry" */
1272 typedef struct q_samr_unknown_32_info
1273 {
1274     LSA_POL_HND pol;             /* policy handle */
1275
1276         UNIHDR  hdr_mach_acct;       /* unicode machine account name header */
1277         UNISTR2 uni_mach_acct;       /* unicode machine account name */
1278
1279         uint32 unknown_0;            /* 32 bit unknown */
1280         uint16 unknown_1;            /* 16 bit unknown */
1281         uint16 unknown_2;            /* 16 bit unknown */
1282
1283 } SAMR_Q_UNKNOWN_32;
1284
1285
1286 /* SAMR_R_UNKNOWN_32 - probably a "create SAM entry" */
1287 typedef struct r_samr_unknown_32_info
1288 {
1289     LSA_POL_HND pol;       /* policy handle */
1290         uint32 unknown_0;      /* 0x0000 0030 - 32 bit unknown */
1291         uint32 padding;        /* 0           - 4 byte padding */
1292
1293         uint32 status;         /* return status - 0xC000 0099: user exists */
1294
1295 } SAMR_R_UNKNOWN_32;
1296
1297
1298 /* SAMR_Q_OPEN_POLICY - probably an open */
1299 typedef struct q_samr_open_policy_info
1300 {
1301         uint32 ptr_srv_name;         /* pointer (to server name?) */
1302         UNISTR2 uni_srv_name;        /* unicode server name starting with '\\' */
1303
1304         uint32 unknown_0;            /* 32 bit unknown */
1305
1306 } SAMR_Q_OPEN_POLICY;
1307
1308
1309 /* SAMR_R_OPEN_POLICY - probably an open */
1310 typedef struct r_samr_open_policy_info
1311 {
1312     LSA_POL_HND pol;       /* policy handle */
1313         uint32 status;             /* return status */
1314
1315 } SAMR_R_OPEN_POLICY;
1316
1317
1318 /* WKS_Q_UNKNOWN_0 - probably a capabilities request */
1319 typedef struct q_wks_unknown_0_info
1320 {
1321         uint32 ptr_srv_name;         /* pointer (to server name?) */
1322         UNISTR2 uni_srv_name;        /* unicode server name starting with '\\' */
1323
1324         uint32 unknown_0;            /* 0x64 - 32 bit unknown */
1325         uint16 unknown_1;            /* 16 bit unknown */
1326
1327 } WKS_Q_UNKNOWN_0;
1328
1329
1330 /* WKS_R_UNKNOWN_0 - probably a capabilities request */
1331 typedef struct r_wks_unknown_0_info
1332 {
1333         uint32 unknown_0;          /* 64 - unknown */
1334         uint32 ptr_1;              /* pointer 1 */
1335         uint32 unknown_1;          /* 0x0000 01f4 - unknown */
1336         uint32 ptr_srv_name;       /* pointer to server name */
1337         uint32 ptr_dom_name;       /* pointer to domain name */
1338         uint32 unknown_2;          /* 4 - unknown */
1339         uint32 unknown_3;          /* 0 - unknown */
1340
1341         UNISTR2 uni_srv_name;      /* unicode server name */
1342         UNISTR2 uni_dom_name;      /* unicode domainn name */
1343         uint32 status;             /* return status */
1344
1345 } WKS_R_UNKNOWN_0;
1346
1347
1348 struct smb_passwd
1349 {
1350         int smb_userid;
1351         char *smb_name;
1352         unsigned char *smb_passwd; /* Null if no password */
1353         unsigned char *smb_nt_passwd; /* Null if no password */
1354         /* Other fields / flags may be added later */
1355 };
1356
1357 struct cli_state {
1358         int fd;
1359         int cnum;
1360         int pid;
1361         int mid;
1362         int uid;
1363         int protocol;
1364         int sec_mode;
1365         int error;
1366         int privilages;
1367         fstring eff_name;
1368         fstring desthost;
1369         char cryptkey[8];
1370         uint32 sesskey;
1371         int serverzone;
1372         uint32 servertime;
1373         int readbraw_supported;
1374         int writebraw_supported;
1375         int timeout;
1376         int max_xmit;
1377         char *outbuf;
1378         char *inbuf;
1379         int bufsize;
1380         int initialised;
1381 };
1382
1383
1384 struct current_user
1385 {
1386   int cnum, id;
1387   int uid, gid;
1388   int ngroups;
1389   gid_t *groups;
1390   int *igroups;
1391   int *attrs;
1392 };
1393
1394 typedef struct
1395 {
1396   int size;
1397   int mode;
1398   int uid;
1399   int gid;
1400   /* these times are normally kept in GMT */
1401   time_t mtime;
1402   time_t atime;
1403   time_t ctime;
1404   pstring name;
1405
1406 } file_info;
1407
1408
1409 /* Structure used when SMBwritebmpx is active */
1410 typedef struct
1411         {
1412         int   wr_total_written; /* So we know when to discard this */
1413         int32 wr_timeout;
1414         int32 wr_errclass;
1415         int32 wr_error; /* Cached errors */
1416         BOOL  wr_mode; /* write through mode) */
1417         BOOL  wr_discard; /* discard all further data */
1418         } write_bmpx_struct;
1419
1420 /*
1421  * Structure used to indirect fd's from the files_struct.
1422  * Needed as POSIX locking is based on file and process, not
1423  * file descriptor and process.
1424  */
1425
1426 typedef struct
1427 {
1428   uint16 ref_count;
1429   uint32 dev;
1430   uint32 inode;
1431   int fd;
1432   int fd_readonly;
1433   int fd_writeonly;
1434   int real_open_flags;
1435 } file_fd_struct;
1436
1437 typedef struct
1438 {
1439   int cnum;
1440   file_fd_struct *fd_ptr;
1441   int pos;
1442   uint32 size;
1443   int mode;
1444   int uid;
1445   char *mmap_ptr;
1446   uint32 mmap_size;
1447   write_bmpx_struct *wbmpx_ptr;
1448   struct timeval open_time;
1449   BOOL open;
1450   BOOL can_lock;
1451   BOOL can_read;
1452   BOOL can_write;
1453   BOOL share_mode;
1454   BOOL print_file;
1455   BOOL modified;
1456   BOOL granted_oplock;
1457   char *name;
1458 } files_struct;
1459
1460
1461 struct uid_cache {
1462   int entries;
1463   int list[UID_CACHE_SIZE];
1464 };
1465
1466 typedef struct
1467 {
1468   char *name;
1469   BOOL is_wild;
1470 } name_compare_entry;
1471
1472 typedef struct
1473 {
1474   int service;
1475   BOOL force_user;
1476   struct uid_cache uid_cache;
1477   void *dirptr;
1478   BOOL open;
1479   BOOL printer;
1480   BOOL ipc;
1481   BOOL read_only;
1482   BOOL admin_user;
1483   char *dirpath;
1484   char *connectpath;
1485   char *origpath;
1486   char *user; /* name of user who *opened* this connection */
1487   int uid; /* uid of user who *opened* this connection */
1488   int gid; /* gid of user who *opened* this connection */
1489
1490   uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
1491
1492   /* following groups stuff added by ih */
1493
1494   /* This groups info is valid for the user that *opened* the connection */
1495   int ngroups;
1496   gid_t *groups;
1497   int *igroups; /* an integer version - some OSes are broken :-( */
1498   int *attrs;
1499
1500   time_t lastused;
1501   BOOL used;
1502   int num_files_open;
1503   name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */
1504   name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */
1505
1506 } connection_struct;
1507
1508 /* Domain controller authentication protocol info */
1509 struct dcinfo
1510 {
1511   DOM_CHAL clnt_chal; /* Initial challenge received from client */
1512   DOM_CHAL srv_chal;  /* Initial server challenge */
1513   DOM_CRED clnt_cred; /* Last client credential */
1514   DOM_CRED srv_cred;  /* Last server credential */
1515
1516   uchar  sess_key[8]; /* Session key */
1517   uchar  md4pw[16];   /* md4(machine password) */
1518 };
1519
1520 typedef struct
1521 {
1522   int uid; /* uid of a validated user */
1523   int gid; /* gid of a validated user */
1524
1525   fstring name; /* name of a validated user */
1526   fstring real_name;   /* to store real name from password file - simeon */
1527   BOOL guest;
1528
1529   /* following groups stuff added by ih */
1530   /* This groups info is needed for when we become_user() for this uid */
1531   int n_groups;
1532   gid_t *groups;
1533   int *igroups; /* an integer version - some OSes are broken :-( */
1534   int *attrs; /* attributes associated with each gid */
1535
1536   int n_sids;
1537   int *sids;
1538
1539   /* per-user authentication information on NT RPCs */
1540   struct dcinfo dc;
1541
1542 } user_struct;
1543
1544
1545 enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING};
1546
1547 typedef struct
1548 {
1549   int job;
1550   int size;
1551   int status;
1552   int priority;
1553   time_t time;
1554   char user[30];
1555   char file[100];
1556 } print_queue_struct;
1557
1558 enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
1559
1560 typedef struct
1561 {
1562   fstring message;
1563   int status;
1564 }  print_status_struct;
1565
1566 /* used for server information: client, nameserv and ipc */
1567 struct server_info_struct
1568 {
1569   fstring name;
1570   uint32 type;
1571   fstring comment;
1572   fstring domain; /* used ONLY in ipc.c NOT namework.c */
1573   BOOL server_added; /* used ONLY in ipc.c NOT namework.c */
1574 };
1575
1576
1577 /* used for network interfaces */
1578 struct interface
1579 {
1580         struct interface *next;
1581         struct in_addr ip;
1582         struct in_addr bcast;
1583         struct in_addr nmask;
1584 };
1585
1586 /* struct returned by get_share_modes */
1587 typedef struct
1588 {
1589   int pid;
1590   uint16 op_port;
1591   uint16 op_type;
1592   int share_mode;
1593   struct timeval time;
1594 } share_mode_entry;
1595
1596
1597 /* each implementation of the share mode code needs
1598    to support the following operations */
1599 struct share_ops {
1600         BOOL (*stop_mgmt)(void);
1601         BOOL (*lock_entry)(int , uint32 , uint32 , int *);
1602         BOOL (*unlock_entry)(int , uint32 , uint32 , int );
1603         BOOL (*get_entries)(int , int , uint32 , uint32 , share_mode_entry **);
1604         void (*del_entry)(int , int );
1605         BOOL (*set_entry)(int , int , uint16 , uint16 );
1606         BOOL (*remove_oplock)(int , int);
1607         int (*forall)(void (*)(share_mode_entry *, char *));
1608         void (*status)(FILE *);
1609 };
1610
1611 /* each implementation of the shared memory code needs
1612    to support the following operations */
1613 struct shmem_ops {
1614         BOOL (*close)( void );
1615         int (*alloc)(int );
1616         BOOL (*free)(int );
1617         int (*get_userdef_off)(void);
1618         void *(*offset2addr)(int );
1619         int (*addr2offset)(void *addr);
1620         BOOL (*lock_hash_entry)(unsigned int);
1621         BOOL (*unlock_hash_entry)( unsigned int );
1622         BOOL (*get_usage)(int *,int *,int *);
1623         unsigned (*hash_size)(void);
1624 };
1625
1626
1627 /* this is used for smbstatus */
1628 struct connect_record
1629 {
1630   int magic;
1631   int pid;
1632   int cnum;
1633   int uid;
1634   int gid;
1635   char name[24];
1636   char addr[24];
1637   char machine[128];
1638   time_t start;
1639 };
1640
1641 #ifndef LOCKING_VERSION
1642 #define LOCKING_VERSION 4
1643 #endif /* LOCKING_VERSION */
1644
1645 /* these are useful macros for checking validity of handles */
1646 #define VALID_FNUM(fnum)   (((fnum) >= 0) && ((fnum) < MAX_OPEN_FILES))
1647 #define OPEN_FNUM(fnum)    (VALID_FNUM(fnum) && Files[fnum].open)
1648 #define VALID_CNUM(cnum)   (((cnum) >= 0) && ((cnum) < MAX_CONNECTIONS))
1649 #define OPEN_CNUM(cnum)    (VALID_CNUM(cnum) && Connections[cnum].open)
1650 #define IS_IPC(cnum)       (VALID_CNUM(cnum) && Connections[cnum].ipc)
1651 #define IS_PRINT(cnum)       (VALID_CNUM(cnum) && Connections[cnum].printer)
1652 #define FNUM_OK(fnum,c) (OPEN_FNUM(fnum) && (c)==Files[fnum].cnum)
1653
1654 #define CHECK_FNUM(fnum,c) if (!FNUM_OK(fnum,c)) \
1655                                return(ERROR(ERRDOS,ERRbadfid))
1656 #define CHECK_READ(fnum) if (!Files[fnum].can_read) \
1657                                return(ERROR(ERRDOS,ERRbadaccess))
1658 #define CHECK_WRITE(fnum) if (!Files[fnum].can_write) \
1659                                return(ERROR(ERRDOS,ERRbadaccess))
1660 #define CHECK_ERROR(fnum) if (HAS_CACHED_ERROR(fnum)) \
1661                                return(CACHED_ERROR(fnum))
1662
1663 /* translates a connection number into a service number */
1664 #define SNUM(cnum)         (Connections[cnum].service)
1665
1666 /* access various service details */
1667 #define SERVICE(snum)      (lp_servicename(snum))
1668 #define PRINTCAP           (lp_printcapname())
1669 #define PRINTCOMMAND(snum) (lp_printcommand(snum))
1670 #define PRINTERNAME(snum)  (lp_printername(snum))
1671 #define CAN_WRITE(cnum)    (OPEN_CNUM(cnum) && !Connections[cnum].read_only)
1672 #define VALID_SNUM(snum)   (lp_snum_ok(snum))
1673 #define GUEST_OK(snum)     (VALID_SNUM(snum) && lp_guest_ok(snum))
1674 #define GUEST_ONLY(snum)   (VALID_SNUM(snum) && lp_guest_only(snum))
1675 #define CAN_SETDIR(snum)   (!lp_no_set_dir(snum))
1676 #define CAN_PRINT(cnum)    (OPEN_CNUM(cnum) && lp_print_ok(SNUM(cnum)))
1677 #define POSTSCRIPT(cnum)   (OPEN_CNUM(cnum) && lp_postscript(SNUM(cnum)))
1678 #define MAP_HIDDEN(cnum)   (OPEN_CNUM(cnum) && lp_map_hidden(SNUM(cnum)))
1679 #define MAP_SYSTEM(cnum)   (OPEN_CNUM(cnum) && lp_map_system(SNUM(cnum)))
1680 #define MAP_ARCHIVE(cnum)   (OPEN_CNUM(cnum) && lp_map_archive(SNUM(cnum)))
1681 #define IS_HIDDEN_PATH(cnum,path)  (is_in_path((path),Connections[(cnum)].hide_list))
1682 #define IS_VETO_PATH(cnum,path)  (is_in_path((path),Connections[(cnum)].veto_list))
1683
1684 #define SMBENCRYPT()       (lp_encrypted_passwords())
1685
1686 /* the basic packet size, assuming no words or bytes */
1687 #define smb_size 39
1688
1689 /* offsets into message for common items */
1690 #define smb_com 8
1691 #define smb_rcls 9
1692 #define smb_reh 10
1693 #define smb_err 11
1694 #define smb_flg 13
1695 #define smb_flg2 14
1696 #define smb_reb 13
1697 #define smb_tid 28
1698 #define smb_pid 30
1699 #define smb_uid 32
1700 #define smb_mid 34
1701 #define smb_wct 36
1702 #define smb_vwv 37
1703 #define smb_vwv0 37
1704 #define smb_vwv1 39
1705 #define smb_vwv2 41
1706 #define smb_vwv3 43
1707 #define smb_vwv4 45
1708 #define smb_vwv5 47
1709 #define smb_vwv6 49
1710 #define smb_vwv7 51
1711 #define smb_vwv8 53
1712 #define smb_vwv9 55
1713 #define smb_vwv10 57
1714 #define smb_vwv11 59
1715 #define smb_vwv12 61
1716 #define smb_vwv13 63
1717 #define smb_vwv14 65
1718 #define smb_vwv15 67
1719 #define smb_vwv16 69
1720 #define smb_vwv17 71
1721
1722
1723 /* the complete */
1724 #define SMBmkdir      0x00   /* create directory */
1725 #define SMBrmdir      0x01   /* delete directory */
1726 #define SMBopen       0x02   /* open file */
1727 #define SMBcreate     0x03   /* create file */
1728 #define SMBclose      0x04   /* close file */
1729 #define SMBflush      0x05   /* flush file */
1730 #define SMBunlink     0x06   /* delete file */
1731 #define SMBmv         0x07   /* rename file */
1732 #define SMBgetatr     0x08   /* get file attributes */
1733 #define SMBsetatr     0x09   /* set file attributes */
1734 #define SMBread       0x0A   /* read from file */
1735 #define SMBwrite      0x0B   /* write to file */
1736 #define SMBlock       0x0C   /* lock byte range */
1737 #define SMBunlock     0x0D   /* unlock byte range */
1738 #define SMBctemp      0x0E   /* create temporary file */
1739 #define SMBmknew      0x0F   /* make new file */
1740 #define SMBchkpth     0x10   /* check directory path */
1741 #define SMBexit       0x11   /* process exit */
1742 #define SMBlseek      0x12   /* seek */
1743 #define SMBtcon       0x70   /* tree connect */
1744 #define SMBtconX      0x75   /* tree connect and X*/
1745 #define SMBtdis       0x71   /* tree disconnect */
1746 #define SMBnegprot    0x72   /* negotiate protocol */
1747 #define SMBdskattr    0x80   /* get disk attributes */
1748 #define SMBsearch     0x81   /* search directory */
1749 #define SMBsplopen    0xC0   /* open print spool file */
1750 #define SMBsplwr      0xC1   /* write to print spool file */
1751 #define SMBsplclose   0xC2   /* close print spool file */
1752 #define SMBsplretq    0xC3   /* return print queue */
1753 #define SMBsends      0xD0   /* send single block message */
1754 #define SMBsendb      0xD1   /* send broadcast message */
1755 #define SMBfwdname    0xD2   /* forward user name */
1756 #define SMBcancelf    0xD3   /* cancel forward */
1757 #define SMBgetmac     0xD4   /* get machine name */
1758 #define SMBsendstrt   0xD5   /* send start of multi-block message */
1759 #define SMBsendend    0xD6   /* send end of multi-block message */
1760 #define SMBsendtxt    0xD7   /* send text of multi-block message */
1761
1762 /* Core+ protocol */
1763 #define SMBlockread       0x13   /* Lock a range and read */
1764 #define SMBwriteunlock 0x14 /* Unlock a range then write */
1765 #define SMBreadbraw   0x1a  /* read a block of data with no smb header */
1766 #define SMBwritebraw  0x1d  /* write a block of data with no smb header */
1767 #define SMBwritec     0x20  /* secondary write request */
1768 #define SMBwriteclose 0x2c  /* write a file then close it */
1769
1770 /* dos extended protocol */
1771 #define SMBreadBraw      0x1A   /* read block raw */
1772 #define SMBreadBmpx      0x1B   /* read block multiplexed */
1773 #define SMBreadBs        0x1C   /* read block (secondary response) */
1774 #define SMBwriteBraw     0x1D   /* write block raw */
1775 #define SMBwriteBmpx     0x1E   /* write block multiplexed */
1776 #define SMBwriteBs       0x1F   /* write block (secondary request) */
1777 #define SMBwriteC        0x20   /* write complete response */
1778 #define SMBsetattrE      0x22   /* set file attributes expanded */
1779 #define SMBgetattrE      0x23   /* get file attributes expanded */
1780 #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
1781 #define SMBtrans         0x25   /* transaction - name, bytes in/out */
1782 #define SMBtranss        0x26   /* transaction (secondary request/response) */
1783 #define SMBioctl         0x27   /* IOCTL */
1784 #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
1785 #define SMBcopy          0x29   /* copy */
1786 #define SMBmove          0x2A   /* move */
1787 #define SMBecho          0x2B   /* echo */
1788 #define SMBopenX         0x2D   /* open and X */
1789 #define SMBreadX         0x2E   /* read and X */
1790 #define SMBwriteX        0x2F   /* write and X */
1791 #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
1792 #define SMBffirst        0x82   /* find first */
1793 #define SMBfunique       0x83   /* find unique */
1794 #define SMBfclose        0x84   /* find close */
1795 #define SMBinvalid       0xFE   /* invalid command */
1796
1797 /* Extended 2.0 protocol */
1798 #define SMBtrans2        0x32   /* TRANS2 protocol set */
1799 #define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
1800 #define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
1801 #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
1802 #define SMBulogoffX      0x74   /* user logoff */
1803
1804 /* NT SMB extensions. */
1805 #define SMBnttrans       0xA0   /* NT transact */
1806 #define SMBnttranss      0xA1   /* NT transact secondary */
1807 #define SMBntcreateX     0xA2   /* NT create and X */
1808 #define SMBntcancel      0xA4   /* NT cancel */
1809
1810 /* These are the TRANS2 sub commands */
1811 #define TRANSACT2_OPEN                        0
1812 #define TRANSACT2_FINDFIRST                   1
1813 #define TRANSACT2_FINDNEXT                    2
1814 #define TRANSACT2_QFSINFO                     3
1815 #define TRANSACT2_SETFSINFO                   4
1816 #define TRANSACT2_QPATHINFO                   5
1817 #define TRANSACT2_SETPATHINFO                 6
1818 #define TRANSACT2_QFILEINFO                   7
1819 #define TRANSACT2_SETFILEINFO                 8
1820 #define TRANSACT2_FSCTL                       9
1821 #define TRANSACT2_IOCTL                     0xA
1822 #define TRANSACT2_FINDNOTIFYFIRST           0xB
1823 #define TRANSACT2_FINDNOTIFYNEXT            0xC
1824 #define TRANSACT2_MKDIR                     0xD
1825 #define TRANSACT2_SESSION_SETUP             0xE
1826 #define TRANSACT2_GET_DFS_REFERRAL         0x10
1827 #define TRANSACT2_REPORT_DFS_INCONSISTANCY 0x11
1828
1829 /* These are the NT transact sub commands. */
1830 #define NT_TRANSACT_CREATE                1
1831 #define NT_TRANSACT_IOCTL                 2
1832 #define NT_TRANSACT_SET_SECURITY_DESC     3
1833 #define NT_TRANSACT_NOTIFY_CHANGE         4
1834 #define NT_TRANSACT_RENAME                5
1835 #define NT_TRANSACT_QUERY_SECURITY_DESC   6
1836
1837 /* these are the trans2 sub fields for primary requests */
1838 #define smb_tpscnt smb_vwv0
1839 #define smb_tdscnt smb_vwv1
1840 #define smb_mprcnt smb_vwv2
1841 #define smb_mdrcnt smb_vwv3
1842 #define smb_msrcnt smb_vwv4
1843 #define smb_flags smb_vwv5
1844 #define smb_timeout smb_vwv6
1845 #define smb_pscnt smb_vwv9
1846 #define smb_psoff smb_vwv10
1847 #define smb_dscnt smb_vwv11
1848 #define smb_dsoff smb_vwv12
1849 #define smb_suwcnt smb_vwv13
1850 #define smb_setup smb_vwv14
1851 #define smb_setup0 smb_setup
1852 #define smb_setup1 (smb_setup+2)
1853 #define smb_setup2 (smb_setup+4)
1854
1855 /* these are for the secondary requests */
1856 #define smb_spscnt smb_vwv2
1857 #define smb_spsoff smb_vwv3
1858 #define smb_spsdisp smb_vwv4
1859 #define smb_sdscnt smb_vwv5
1860 #define smb_sdsoff smb_vwv6
1861 #define smb_sdsdisp smb_vwv7
1862 #define smb_sfid smb_vwv8
1863
1864 /* and these for responses */
1865 #define smb_tprcnt smb_vwv0
1866 #define smb_tdrcnt smb_vwv1
1867 #define smb_prcnt smb_vwv3
1868 #define smb_proff smb_vwv4
1869 #define smb_prdisp smb_vwv5
1870 #define smb_drcnt smb_vwv6
1871 #define smb_droff smb_vwv7
1872 #define smb_drdisp smb_vwv8
1873
1874 /* where to find the base of the SMB packet proper */
1875 #define smb_base(buf) (((char *)(buf))+4)
1876
1877
1878 #define SUCCESS 0  /* The request was successful. */
1879 #define ERRDOS 0x01 /*  Error is from the core DOS operating system set. */
1880 #define ERRSRV 0x02  /* Error is generated by the server network file manager.*/
1881 #define ERRHRD 0x03  /* Error is an hardware error. */
1882 #define ERRCMD 0xFF  /* Command was not in the "SMB" format. */
1883
1884 #ifdef __STDC__
1885 int Debug1(char *, ...);
1886 #else
1887 int Debug1();
1888 #endif
1889
1890 #ifdef DFS_AUTH
1891 void dfs_unlogin(void);
1892 extern int dcelogin_atmost_once;
1893 #endif
1894
1895 #if AJT
1896 void ajt_panic(void);
1897 #endif
1898
1899 #ifdef NOSTRDUP
1900 char *strdup(char *s);
1901 #endif
1902
1903 #ifdef REPLACE_STRLEN
1904 int Strlen(char *);
1905 #endif
1906
1907 #ifdef REPLACE_STRSTR
1908 char *Strstr(char *s, char *p);
1909 #endif
1910
1911 #ifndef MIN
1912 #define MIN(a,b) ((a)<(b)?(a):(b))
1913 #endif
1914 #ifndef MAX
1915 #define MAX(a,b) ((a)>(b)?(a):(b))
1916 #endif
1917
1918 #ifndef ABS
1919 #define ABS(a) ((a)>0?(a):(-(a)))
1920 #endif
1921
1922 #ifndef SIGNAL_CAST
1923 #define SIGNAL_CAST
1924 #endif
1925
1926 #ifndef SELECT_CAST
1927 #define SELECT_CAST
1928 #endif
1929
1930
1931 /* Some POSIX definitions for those without */
1932  
1933 #ifndef S_IFDIR
1934 #define S_IFDIR         0x4000
1935 #endif
1936 #ifndef S_ISDIR
1937 #define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
1938 #endif
1939 #ifndef S_IRWXU
1940 #define S_IRWXU 00700           /* read, write, execute: owner */
1941 #endif
1942 #ifndef S_IRUSR
1943 #define S_IRUSR 00400           /* read permission: owner */
1944 #endif
1945 #ifndef S_IWUSR
1946 #define S_IWUSR 00200           /* write permission: owner */
1947 #endif
1948 #ifndef S_IXUSR
1949 #define S_IXUSR 00100           /* execute permission: owner */
1950 #endif
1951 #ifndef S_IRWXG
1952 #define S_IRWXG 00070           /* read, write, execute: group */
1953 #endif
1954 #ifndef S_IRGRP
1955 #define S_IRGRP 00040           /* read permission: group */
1956 #endif
1957 #ifndef S_IWGRP
1958 #define S_IWGRP 00020           /* write permission: group */
1959 #endif
1960 #ifndef S_IXGRP
1961 #define S_IXGRP 00010           /* execute permission: group */
1962 #endif
1963 #ifndef S_IRWXO
1964 #define S_IRWXO 00007           /* read, write, execute: other */
1965 #endif
1966 #ifndef S_IROTH
1967 #define S_IROTH 00004           /* read permission: other */
1968 #endif
1969 #ifndef S_IWOTH
1970 #define S_IWOTH 00002           /* write permission: other */
1971 #endif
1972 #ifndef S_IXOTH
1973 #define S_IXOTH 00001           /* execute permission: other */
1974 #endif
1975
1976
1977 /* these are used in NetServerEnum to choose what to receive */
1978 #define SV_TYPE_WORKSTATION         0x00000001
1979 #define SV_TYPE_SERVER              0x00000002
1980 #define SV_TYPE_SQLSERVER           0x00000004
1981 #define SV_TYPE_DOMAIN_CTRL         0x00000008
1982 #define SV_TYPE_DOMAIN_BAKCTRL      0x00000010
1983 #define SV_TYPE_TIME_SOURCE         0x00000020
1984 #define SV_TYPE_AFP                 0x00000040
1985 #define SV_TYPE_NOVELL              0x00000080
1986 #define SV_TYPE_DOMAIN_MEMBER       0x00000100
1987 #define SV_TYPE_PRINTQ_SERVER       0x00000200
1988 #define SV_TYPE_DIALIN_SERVER       0x00000400
1989 #define SV_TYPE_SERVER_UNIX         0x00000800
1990 #define SV_TYPE_NT                  0x00001000
1991 #define SV_TYPE_WFW                 0x00002000
1992 #define SV_TYPE_SERVER_MFPN         0x00004000
1993 #define SV_TYPE_SERVER_NT           0x00008000
1994 #define SV_TYPE_POTENTIAL_BROWSER   0x00010000
1995 #define SV_TYPE_BACKUP_BROWSER      0x00020000
1996 #define SV_TYPE_MASTER_BROWSER      0x00040000
1997 #define SV_TYPE_DOMAIN_MASTER       0x00080000
1998 #define SV_TYPE_SERVER_OSF          0x00100000
1999 #define SV_TYPE_SERVER_VMS          0x00200000
2000 #define SV_TYPE_WIN95_PLUS          0x00400000
2001 #define SV_TYPE_ALTERNATE_XPORT     0x20000000  
2002 #define SV_TYPE_LOCAL_LIST_ONLY     0x40000000  
2003 #define SV_TYPE_DOMAIN_ENUM         0x80000000
2004 #define SV_TYPE_ALL                 0xFFFFFFFF  
2005
2006 /* what server type are we currently  - JHT Says we ARE 4.20 */
2007 /* this was set by JHT in liaison with Jeremy Allison early 1997 */
2008 /* setting to 4.20 at same time as announcing ourselves as NT Server */
2009 /* History: */
2010 /* Version 4.0 - never made public */
2011 /* Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9 */
2012 /*              - Reappeared in 1.9.16p11 with fixed smbd services */
2013 /* Version 4.20 - To indicate that nmbd and browsing now works better */
2014
2015 #define DEFAULT_MAJOR_VERSION 0x04
2016 #define DEFAULT_MINOR_VERSION 0x02
2017
2018 /* Browser Election Values */
2019 #define BROWSER_ELECTION_VERSION        0x010f
2020 #define BROWSER_CONSTANT        0xaa55
2021
2022
2023 /* Capabilities.  see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
2024
2025 #define CAP_RAW_MODE         0x0001
2026 #define CAP_MPX_MODE         0x0002
2027 #define CAP_UNICODE          0x0004
2028 #define CAP_LARGE_FILES      0x0008
2029 #define CAP_NT_SMBS          0x0010
2030 #define CAP_RPC_REMOTE_APIS  0x0020
2031 #define CAP_STATUS32         0x0040
2032 #define CAP_LEVEL_II_OPLOCKS 0x0080
2033 #define CAP_LOCK_AND_READ    0x0100
2034 #define CAP_NT_FIND          0x0200
2035 #define CAP_DFS              0x1000
2036 #define CAP_LARGE_READX      0x4000
2037
2038 /* protocol types. It assumes that higher protocols include lower protocols
2039    as subsets */
2040 enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
2041
2042 /* security levels */
2043 enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER};
2044
2045 /* printing types */
2046 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
2047                      PRINT_QNX,PRINT_PLP,PRINT_LPRNG};
2048
2049 /* Remote architectures we know about. */
2050 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_SAMBA};
2051
2052 /* case handling */
2053 enum case_handling {CASE_LOWER,CASE_UPPER};
2054
2055
2056 /* Macros to get at offsets within smb_lkrng and smb_unlkrng
2057    structures. We cannot define these as actual structures
2058    due to possible differences in structure packing
2059    on different machines/compilers. */
2060
2061 #define SMB_LPID_OFFSET(indx) (10 * (indx))
2062 #define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
2063 #define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
2064
2065 /* Macro to cache an error in a write_bmpx_struct */
2066 #define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
2067                             w->wr_discard = True, -1)
2068 /* Macro to test if an error has been cached for this fnum */
2069 #define HAS_CACHED_ERROR(fnum) (Files[(fnum)].open && \
2070                                 Files[(fnum)].wbmpx_ptr && \
2071                                 Files[(fnum)].wbmpx_ptr->wr_discard)
2072 /* Macro to turn the cached error into an error packet */
2073 #define CACHED_ERROR(fnum) cached_error_packet(inbuf,outbuf,fnum,__LINE__)
2074
2075 /* these are the datagram types */
2076 #define DGRAM_DIRECT_UNIQUE 0x10
2077
2078 #define ERROR(class,x) error_packet(inbuf,outbuf,class,x,__LINE__)
2079
2080 /* this is how errors are generated */
2081 #define UNIXERROR(defclass,deferror) unix_error_packet(inbuf,outbuf,defclass,deferror,__LINE__)
2082
2083 #define ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
2084
2085 /*
2086  * Global value meaing that the smb_uid field should be
2087  * ingored (in share level security and protocol level == CORE)
2088  */
2089
2090 #define UID_FIELD_INVALID 0
2091 #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
2092
2093 #endif 
2094
2095 /* Defines needed for multi-codepage support. */
2096 #define KANJI_CODEPAGE 932
2097
2098 #ifdef KANJI
2099 /* 
2100  * Default client code page - Japanese 
2101  */
2102 #define DEFAULT_CLIENT_CODE_PAGE KANJI_CODEPAGE
2103 #else /* KANJI */
2104 /* 
2105  * Default client code page - 850 - Western European 
2106  */
2107 #define DEFAULT_CLIENT_CODE_PAGE 850
2108 #endif /* KANJI */
2109
2110 /* 
2111  * Size of buffer to use when moving files across filesystems. 
2112  */
2113 #define COPYBUF_SIZE (8*1024)
2114
2115 /* 
2116  * Integers used to override error codes. 
2117  */
2118 extern int unix_ERR_class;
2119 extern int unix_ERR_code;
2120
2121 /*
2122  * Map the Core and Extended Oplock requesst bits down
2123  * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK).
2124  */
2125
2126 /*
2127  * Core protocol.
2128  */
2129 #define CORE_OPLOCK_REQUEST(inbuf) ((CVAL(inbuf,smb_flg)&((1<<5)|(1<<6)))>>5)
2130
2131 /*
2132  * Extended protocol.
2133  */
2134 #define EXTENDED_OPLOCK_REQUEST(inbuf) ((SVAL(inbuf,smb_vwv2)&((1<<1)|(1<<2)))>>1)
2135
2136 /* Lock types. */
2137 #define LOCKING_ANDX_SHARED_LOCK 0x1
2138 #define LOCKING_ANDX_OPLOCK_RELEASE 0x2
2139 #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x4
2140 #define LOCKING_ANDX_CANCEL_LOCK 0x8
2141 #define LOCKING_ANDX_LARGE_FILES 0x10
2142
2143 /* Oplock levels */
2144 #define OPLOCKLEVEL_NONE 0
2145 #define OPLOCKLEVEL_II 1
2146
2147 /*
2148  * Bits we test with.
2149  */
2150 #define EXCLUSIVE_OPLOCK 1
2151 #define BATCH_OPLOCK 2
2152
2153 #define CORE_OPLOCK_GRANTED (1<<5)
2154 #define EXTENDED_OPLOCK_GRANTED (1<<15)
2155
2156 /*
2157  * Loopback command offsets.
2158  */
2159
2160 #define UDP_CMD_LEN_OFFSET 0
2161 #define UDP_CMD_PORT_OFFSET 4
2162 #define UDP_CMD_HEADER_LEN 6
2163
2164 #define UDP_MESSAGE_CMD_OFFSET 0
2165
2166 /*
2167  * Oplock break command code to send over the udp socket.
2168  * 
2169  * Form of this is :
2170  *
2171  *  0     2       6        10       14      18       22
2172  *  +----+--------+--------+--------+-------+--------+
2173  *  | cmd| pid    | dev    | inode  | sec   |  usec  |
2174  *  +----+--------+--------+--------+-------+--------+
2175  */
2176
2177 #define OPLOCK_BREAK_CMD 0x1
2178 #define OPLOCK_BREAK_PID_OFFSET 2
2179 #define OPLOCK_BREAK_DEV_OFFSET 6
2180 #define OPLOCK_BREAK_INODE_OFFSET 10
2181 #define OPLOCK_BREAK_SEC_OFFSET 14
2182 #define OPLOCK_BREAK_USEC_OFFSET 18
2183 #define OPLOCK_BREAK_MSG_LEN 22
2184
2185
2186 #define CMD_REPLY 0x8000
2187
2188 /* _SMB_H */