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