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