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