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