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