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