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