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