A while back, Andrew and I talked about making the debug parsing code a
[garming/samba-autobuild/.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-1998
6    Copyright (C) John H Terpstra 1996-1998
7    Copyright (C) Luke Kenneth Casson Leighton 1996-1998
8    Copyright (C) Paul Ashton 1998
9    
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14    
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19    
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24 #ifndef _SMB_H
25 #define _SMB_H
26
27 #define BUFFER_SIZE (0xFFFF)
28 #define SAFETY_MARGIN 1024
29
30 #define NMB_PORT 137
31 #define DGRAM_PORT 138
32 #define SMB_PORT 139
33
34 #define False (0)
35 #define True (1)
36 #define BOOLSTR(b) ((b) ? "Yes" : "No")
37 #define BITSETB(ptr,bit) ((((char *)ptr)[0] & (1<<(bit)))!=0)
38 #define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0)
39
40 #define IS_BITS_SET_ALL(var,bit) (((var)&(bit))==(bit))
41 #define IS_BITS_SET_SOME(var,bit) (((var)&(bit))!=0)
42 #define IS_BITS_CLR_ALL(var,bit) (((var)&(~(bit)))==0)
43
44 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2)))
45
46 typedef int BOOL;
47
48 /* limiting size of ipc replies */
49 #define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024))
50
51 #define SIZEOFWORD 2
52
53 #ifndef DEF_CREATE_MASK
54 #define DEF_CREATE_MASK (0755)
55 #endif
56
57 /* how long to wait for secondary SMB packets (milli-seconds) */
58 #define SMB_SECONDARY_WAIT (60*1000)
59
60 /* -------------------------------------------------------------------------- **
61  * Debugging code.  See also debug.c
62  */
63
64 /* mkproto.awk has trouble with ifdef'd function definitions (it ignores
65  * the #ifdef directive and will read both definitions, thus creating two
66  * diffferent prototype declarations), so we must do these by hand.
67  */
68 /* I know the __attribute__ stuff is ugly, but it does ensure we get the 
69    arguemnts to DEBUG() right. We have got them wrong too often in the 
70    past.
71  */
72 #ifdef HAVE_STDARG_H
73 int  Debug1( char *, ... )
74 #ifdef __GNUC__
75      __attribute__ ((format (printf, 1, 2)))
76 #endif
77 ;
78 BOOL dbgtext( char *, ... )
79 #ifdef __GNUC__
80      __attribute__ ((format (printf, 1, 2)))
81 #endif
82 ;
83 #else
84 int  Debug1();
85 BOOL dbgtext();
86 #endif
87
88 /* If we have these macros, we can add additional info to the header. */
89 #ifdef HAVE_FILE_MACRO
90 #define FILE_MACRO (__FILE__)
91 #else
92 #define FILE_MACRO ("")
93 #endif
94
95 #ifdef HAVE_FUNCTION_MACRO
96 #define FUNCTION_MACRO  (__FUNCTION__)
97 #else
98 #define FUNCTION_MACRO  ("")
99 #endif
100
101 /* Debugging macros. 
102  *  DEBUGLVL() - If level is <= the system-wide DEBUGLEVEL then generate a
103  *               header using the default macros for file, line, and
104  *               function name.
105  *               Returns True if the debug level was <= DEBUGLEVEL.
106  *               Example usage:
107  *                 if( DEBUGLVL( 2 ) )
108  *                   dbgtext( "Some text.\n" );
109  *  DEGUG()    - Good old DEBUG().  Each call to DEBUG() will generate a new
110  *               header *unless* the previous debug output was unterminated
111  *               (i.e., no '\n').  See debug.c:dbghdr() for more info.
112  *               Example usage:
113  *                 DEBUG( 2, ("Some text.\n") );
114  *  DEBUGADD() - If level <= DEBUGLEVEL, then the text is appended to the
115  *               current message (i.e., no header).
116  *               Usage:
117  *                 DEBUGADD( 2, ("Some additional text.\n") );
118  */
119 #define DEBUGLVL( level ) \
120   ( (DEBUGLEVEL >= (level)) \
121    && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
122
123 #define DEBUG( level, body ) \
124   (void)( (DEBUGLEVEL >= (level)) \
125        && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \
126        && (dbgtext body) )
127
128 #define DEBUGADD( level, body ) \
129   (void)( (DEBUGLEVEL >= (level)) && (dbgtext body) )
130
131 /* -------------------------------------------------------------------------- **
132  * These are the tokens returned by dbg_char2token().
133  */
134
135 typedef enum
136   {
137   dbg_null = 0,
138   dbg_ignore,
139   dbg_header,
140   dbg_timestamp,
141   dbg_level,
142   dbg_sourcefile,
143   dbg_function,
144   dbg_lineno,
145   dbg_message,
146   dbg_eof
147   } dbg_Token;
148
149 /* End Debugging code section.
150  * -------------------------------------------------------------------------- **
151  */
152
153 /* this defines the error codes that receive_smb can put in smb_read_error */
154 #define READ_TIMEOUT 1
155 #define READ_EOF 2
156 #define READ_ERROR 3
157
158
159 #define DIR_STRUCT_SIZE 43
160
161 /* these define all the command types recognised by the server - there
162 are lots of gaps so probably there are some rare commands that are not
163 implemented */
164
165 #define pSETDIR '\377'
166
167 /* these define the attribute byte as seen by DOS */
168 #define aRONLY (1L<<0)
169 #define aHIDDEN (1L<<1)
170 #define aSYSTEM (1L<<2)
171 #define aVOLID (1L<<3)
172 #define aDIR (1L<<4)
173 #define aARCH (1L<<5)
174
175 /* for readability... */
176 #define IS_DOS_READONLY(test_mode) (((test_mode) & aRONLY) != 0)
177 #define IS_DOS_DIR(test_mode) (((test_mode) & aDIR) != 0)
178 #define IS_DOS_ARCHIVE(test_mode) (((test_mode) & aARCH) != 0)
179 #define IS_DOS_SYSTEM(test_mode) (((test_mode) & aSYSTEM) != 0)
180 #define IS_DOS_HIDDEN(test_mode) (((test_mode) & aHIDDEN) != 0)
181
182 /* deny modes */
183 #define DENY_DOS 0
184 #define DENY_ALL 1
185 #define DENY_WRITE 2
186 #define DENY_READ 3
187 #define DENY_NONE 4
188 #define DENY_FCB 7
189
190 /* open modes */
191 #define DOS_OPEN_RDONLY 0
192 #define DOS_OPEN_WRONLY 1
193 #define DOS_OPEN_RDWR 2
194 #define DOS_OPEN_FCB 0xF
195
196 /* define shifts and masks for share and open modes. */
197 #define OPEN_MODE_MASK 0xF
198 #define SHARE_MODE_SHIFT 4
199 #define SHARE_MODE_MASK 0x7
200 #define GET_OPEN_MODE(x) ((x) & OPEN_MODE_MASK)
201 #define SET_OPEN_MODE(x) ((x) & OPEN_MODE_MASK)
202 #define GET_DENY_MODE(x) (((x)>>SHARE_MODE_SHIFT) & SHARE_MODE_MASK)
203 #define SET_DENY_MODE(x) ((x)<<SHARE_MODE_SHIFT)
204
205 /* Sync on open file (not sure if used anymore... ?) */
206 #define FILE_SYNC_OPENMODE (1<<14)
207 #define GET_FILE_SYNC_OPENMODE(x) (((x) & FILE_SYNC_OPENMODE) ? True : False)
208
209 /* allow delete on open file mode (used by NT SMB's). */
210 #define ALLOW_SHARE_DELETE (1<<15)
211 #define GET_ALLOW_SHARE_DELETE(x) (((x) & ALLOW_SHARE_DELETE) ? True : False)
212 #define SET_ALLOW_SHARE_DELETE(x) ((x) ? ALLOW_SHARE_DELETE : 0)
213
214 /* delete on close flag (used by NT SMB's). */
215 #define DELETE_ON_CLOSE_FLAG (1<<16)
216 #define GET_DELETE_ON_CLOSE_FLAG(x) (((x) & DELETE_ON_CLOSE_FLAG) ? True : False)
217 #define SET_DELETE_ON_CLOSE_FLAG(x) ((x) ? DELETE_ON_CLOSE_FLAG : 0)
218
219 /* open disposition values */
220 #define FILE_EXISTS_FAIL 0
221 #define FILE_EXISTS_OPEN 1
222 #define FILE_EXISTS_TRUNCATE 2
223
224 /* mask for open disposition. */
225 #define FILE_OPEN_MASK 0x3
226
227 #define GET_FILE_OPEN_DISPOSITION(x) ((x) & FILE_OPEN_MASK)
228 #define SET_FILE_OPEN_DISPOSITION(x) ((x) & FILE_OPEN_MASK)
229
230 /* The above can be OR'ed with... */
231 #define FILE_CREATE_IF_NOT_EXIST 0x10
232 #define FILE_FAIL_IF_NOT_EXIST 0
233
234 #define GET_FILE_CREATE_DISPOSITION(x) ((x) & (FILE_CREATE_IF_NOT_EXIST|FILE_FAIL_IF_NOT_EXIST))
235
236 /* share types */
237 #define STYPE_DISKTREE  0       /* Disk drive */
238 #define STYPE_PRINTQ    1       /* Spooler queue */
239 #define STYPE_DEVICE    2       /* Serial device */
240 #define STYPE_IPC       3       /* Interprocess communication (IPC) */
241 #define STYPE_HIDDEN    0x80000000 /* share is a hidden one (ends with $) */
242
243 /* SMB X/Open error codes for the ERRDOS error class */
244 #define ERRbadfunc 1 /* Invalid function (or system call) */
245 #define ERRbadfile 2 /* File not found (pathname error) */
246 #define ERRbadpath 3 /* Directory not found */
247 #define ERRnofids 4 /* Too many open files */
248 #define ERRnoaccess 5 /* Access denied */
249 #define ERRbadfid 6 /* Invalid fid */
250 #define ERRnomem 8 /* Out of memory */
251 #define ERRbadmem 9 /* Invalid memory block address */
252 #define ERRbadenv 10 /* Invalid environment */
253 #define ERRbadaccess 12 /* Invalid open mode */
254 #define ERRbaddata 13 /* Invalid data (only from ioctl call) */
255 #define ERRres 14 /* reserved */
256 #define ERRbaddrive 15 /* Invalid drive */
257 #define ERRremcd 16 /* Attempt to delete current directory */
258 #define ERRdiffdevice 17 /* rename/move across different filesystems */
259 #define ERRnofiles 18 /* no more files found in file search */
260 #define ERRbadshare 32 /* Share mode on file conflict with open mode */
261 #define ERRlock 33 /* Lock request conflicts with existing lock */
262 #define ERRunsup 50 /* Request unsupported, returned by Win 95, RJS 20Jun98 */
263 #define ERRfilexists 80 /* File in operation already exists */
264 #define ERRcannotopen 110 /* Cannot open the file specified */
265 #define ERRunknownlevel 124
266 #define ERRrename 183
267 #define ERRbadpipe 230 /* Named pipe invalid */
268 #define ERRpipebusy 231 /* All instances of pipe are busy */
269 #define ERRpipeclosing 232 /* named pipe close in progress */
270 #define ERRnotconnected 233 /* No process on other end of named pipe */
271 #define ERRmoredata 234 /* More data to be returned */
272 #define ERRbaddirectory 267 /* Invalid directory name in a path. */
273 #define ERROR_EAS_DIDNT_FIT 275 /* Extended attributes didn't fit */
274 #define ERROR_EAS_NOT_SUPPORTED 282 /* Extended attributes not supported */
275 #define ERROR_NOTIFY_ENUM_DIR 1022 /* Buffer too small to return change notify. */
276 #define ERRunknownipc 2142
277
278
279 /* here's a special one from observing NT */
280 #define ERRnoipc 66 /* don't support ipc */
281
282 /* Error codes for the ERRSRV class */
283
284 #define ERRerror 1 /* Non specific error code */
285 #define ERRbadpw 2 /* Bad password */
286 #define ERRbadtype 3 /* reserved */
287 #define ERRaccess 4 /* No permissions to do the requested operation */
288 #define ERRinvnid 5 /* tid invalid */
289 #define ERRinvnetname 6 /* Invalid servername */
290 #define ERRinvdevice 7 /* Invalid device */
291 #define ERRqfull 49 /* Print queue full */
292 #define ERRqtoobig 50 /* Queued item too big */
293 #define ERRinvpfid 52 /* Invalid print file in smb_fid */
294 #define ERRsmbcmd 64 /* Unrecognised command */
295 #define ERRsrverror 65 /* smb server internal error */
296 #define ERRfilespecs 67 /* fid and pathname invalid combination */
297 #define ERRbadlink 68 /* reserved */
298 #define ERRbadpermits 69 /* Access specified for a file is not valid */
299 #define ERRbadpid 70 /* reserved */
300 #define ERRsetattrmode 71 /* attribute mode invalid */
301 #define ERRpaused 81 /* Message server paused */
302 #define ERRmsgoff 82 /* Not receiving messages */
303 #define ERRnoroom 83 /* No room for message */
304 #define ERRrmuns 87 /* too many remote usernames */
305 #define ERRtimeout 88 /* operation timed out */
306 #define ERRnoresource  89 /* No resources currently available for request. */
307 #define ERRtoomanyuids 90 /* too many userids */
308 #define ERRbaduid 91 /* bad userid */
309 #define ERRuseMPX 250 /* temporarily unable to use raw mode, use MPX mode */
310 #define ERRuseSTD 251 /* temporarily unable to use raw mode, use standard mode */
311 #define ERRcontMPX 252 /* resume MPX mode */
312 #define ERRbadPW /* reserved */
313 #define ERRnosupport 0xFFFF
314 #define ERRunknownsmb 22 /* from NT 3.5 response */
315
316
317 /* Error codes for the ERRHRD class */
318
319 #define ERRnowrite 19 /* read only media */
320 #define ERRbadunit 20 /* Unknown device */
321 #define ERRnotready 21 /* Drive not ready */
322 #define ERRbadcmd 22 /* Unknown command */
323 #define ERRdata 23 /* Data (CRC) error */
324 #define ERRbadreq 24 /* Bad request structure length */
325 #define ERRseek 25
326 #define ERRbadmedia 26
327 #define ERRbadsector 27
328 #define ERRnopaper 28
329 #define ERRwrite 29 /* write fault */
330 #define ERRread 30 /* read fault */
331 #define ERRgeneral 31 /* General hardware failure */
332 #define ERRwrongdisk 34
333 #define ERRFCBunavail 35
334 #define ERRsharebufexc 36 /* share buffer exceeded */
335 #define ERRdiskfull 39
336
337
338 typedef char pstring[1024];
339 typedef char fstring[128];
340
341 /* pipe string names */
342 #define PIPE_LANMAN   "\\PIPE\\LANMAN"
343 #define PIPE_SRVSVC   "\\PIPE\\srvsvc"
344 #define PIPE_SAMR     "\\PIPE\\samr"
345 #define PIPE_WINREG   "\\PIPE\\winreg"
346 #define PIPE_WKSSVC   "\\PIPE\\wkssvc"
347 #define PIPE_NETLOGON "\\PIPE\\NETLOGON"
348 #define PIPE_SVCCTL   "\\PIPE\\SVCCTL"
349 #define PIPE_NTLSA    "\\PIPE\\ntlsa"
350 #define PIPE_NTSVCS   "\\PIPE\\ntsvcs"
351 #define PIPE_LSASS    "\\PIPE\\lsass"
352 #define PIPE_LSARPC   "\\PIPE\\lsarpc"
353
354
355 /* 64 bit time (100usec) since ????? - cifs6.txt, section 3.5, page 30 */
356 typedef struct nttime_info
357 {
358   uint32 low;
359   uint32 high;
360
361 } NTTIME;
362
363 /* Allowable account control bits */
364 #define ACB_DISABLED   0x0001  /* 1 = User account disabled */
365 #define ACB_HOMDIRREQ  0x0002  /* 1 = Home directory required */
366 #define ACB_PWNOTREQ   0x0004  /* 1 = User password not required */
367 #define ACB_TEMPDUP    0x0008  /* 1 = Temporary duplicate account */
368 #define ACB_NORMAL     0x0010  /* 1 = Normal user account */
369 #define ACB_MNS        0x0020  /* 1 = MNS logon user account */
370 #define ACB_DOMTRUST   0x0040  /* 1 = Interdomain trust account */
371 #define ACB_WSTRUST    0x0080  /* 1 = Workstation trust account */
372 #define ACB_SVRTRUST   0x0100  /* 1 = Server trust account */
373 #define ACB_PWNOEXP    0x0200  /* 1 = User password does not expire */
374 #define ACB_AUTOLOCK   0x0400  /* 1 = Account auto locked */
375  
376 #define MAX_HOURS_LEN 32
377
378 struct sam_passwd
379 {
380         NTTIME logon_time;            /* logon time */
381         NTTIME logoff_time;           /* logoff time */
382         NTTIME kickoff_time;          /* kickoff time */
383         NTTIME pass_last_set_time;    /* password last set time */
384         NTTIME pass_can_change_time;  /* password can change time */
385         NTTIME pass_must_change_time; /* password must change time */
386
387         char *unix_name;    /* unix username string */
388         char *nt_name;      /* nt username string */
389         char *full_name;    /* user's full name string */
390         char *home_dir;     /* home directory string */
391         char *dir_drive;    /* home directory drive string */
392         char *logon_script; /* logon script string */
393         char *profile_path; /* profile path string */
394         char *acct_desc  ;  /* user description string */
395         char *workstations; /* login from workstations string */
396         char *unknown_str ; /* don't know what this is, yet. */
397         char *munged_dial ; /* munged path name and dial-back tel number */
398
399         uid_t unix_uid;       /* this is actually the unix uid_t */
400         gid_t unix_gid;        /* this is actually the unix gid_t */
401         uint32 user_rid;      /* Primary User ID */
402         uint32 group_rid;     /* Primary Group ID */
403
404         unsigned char *smb_passwd; /* Null if no password */
405         unsigned char *smb_nt_passwd; /* Null if no password */
406
407         uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */
408         uint32 unknown_3; /* 0x00ff ffff */
409
410         uint16 logon_divs; /* 168 - number of hours in a week */
411         uint32 hours_len; /* normally 21 bytes */
412         uint8 hours[MAX_HOURS_LEN];
413
414         uint32 unknown_5; /* 0x0002 0000 */
415         uint32 unknown_6; /* 0x0000 04ec */
416 };
417
418 struct smb_passwd
419 {
420         uid_t unix_uid;     /* unix userid */
421         char *unix_name;     /* unix username string */
422
423         uint32 user_rid;     /* Primary User ID */
424         char *nt_name;     /* unix username string */
425
426         unsigned char *smb_passwd; /* Null if no password */
427         unsigned char *smb_nt_passwd; /* Null if no password */
428
429         uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */
430         time_t pass_last_set_time;    /* password last set time */
431 };
432
433
434 struct sam_disp_info
435 {
436         uint32 user_rid;      /* Primary User ID */
437         char *nt_name;        /* username string */
438         char *full_name;      /* user's full name string */
439 };
440
441 #define MAXSUBAUTHS 15 /* max sub authorities in a SID */
442
443 /* DOM_SID - security id */
444 typedef struct sid_info
445 {
446   uint8  sid_rev_num;             /* SID revision number */
447   uint8  num_auths;               /* number of sub-authorities */
448   uint8  id_auth[6];              /* Identifier Authority */
449   /*
450    * Note that the values in these uint32's are in *native* byteorder,
451    * not neccessarily little-endian...... JRA.
452    */
453   uint32 sub_auths[MAXSUBAUTHS];  /* pointer to sub-authorities. */
454
455 } DOM_SID;
456
457
458 typedef struct group_name_info
459 {
460         char *nt_name;
461         char *nt_domain;
462         char *unix_name;
463
464         DOM_SID sid;
465         uint8 type;
466         uint32 unix_id;
467
468 } DOM_NAME_MAP;
469
470 /* map either local aliases, domain groups or builtin aliases */
471 typedef enum 
472 {
473         DOM_MAP_LOCAL,
474         DOM_MAP_DOMAIN,
475         DOM_MAP_USER,
476
477 } DOM_MAP_TYPE;
478
479
480 /*** query a local group, get a list of these: shows who is in that group ***/
481
482 /* local group member info */
483 typedef struct local_grp_member_info
484 {
485         DOM_SID sid    ; /* matches with name */
486         uint8   sid_use; /* usr=1 grp=2 dom=3 alias=4 wkng=5 del=6 inv=7 unk=8 */
487         fstring name   ; /* matches with sid: must be of the form "DOMAIN\account" */
488
489 } LOCAL_GRP_MEMBER;
490
491 /* enumerate these to get list of local groups */
492
493 /* local group info */
494 typedef struct local_grp_info
495 {
496         fstring name;
497         fstring comment;
498         uint32  rid; /* alias rid */
499
500 } LOCAL_GRP;
501
502 /*** query a domain group, get a list of these: shows who is in that group ***/
503
504 /* domain group info */
505 typedef struct domain_grp_member_info
506 {
507         fstring name;
508         uint8   attr; /* attributes forced to be set to 0x7: SE_GROUP_xxx */
509         uint32  rid; /* rid of domain group member */
510         uint8   sid_use; /* usr=1 grp=2 dom=3 alias=4 wkng=5 del=6 inv=7 unk=8 */
511
512 } DOMAIN_GRP_MEMBER;
513
514 /*** enumerate these to get list of domain groups ***/
515
516 /* domain group member info */
517 typedef struct domain_grp_info
518 {
519         fstring name;
520         fstring comment;
521         uint32  rid; /* group rid */
522         uint8   attr; /* attributes forced to be set to 0x7: SE_GROUP_xxx */
523
524 } DOMAIN_GRP;
525
526 /* DOM_CHAL - challenge info */
527 typedef struct chal_info
528 {
529   uchar data[8]; /* credentials */
530 } DOM_CHAL;
531
532 /* 32 bit time (sec) since 01jan1970 - cifs6.txt, section 3.5, page 30 */
533 typedef struct time_info
534 {
535   uint32 time;
536 } UTIME;
537
538 /* DOM_CREDs - timestamped client or server credentials */
539 typedef struct cred_info
540 {  
541   DOM_CHAL challenge; /* credentials */
542   UTIME timestamp;    /* credential time-stamp */
543 } DOM_CRED;
544
545 /* Structure used when SMBwritebmpx is active */
546 typedef struct
547 {
548   size_t wr_total_written; /* So we know when to discard this */
549   int32 wr_timeout;
550   int32 wr_errclass;
551   int32 wr_error; /* Cached errors */
552   BOOL  wr_mode; /* write through mode) */
553   BOOL  wr_discard; /* discard all further data */
554 } write_bmpx_struct;
555
556 /*
557  * Structure used to indirect fd's from the files_struct.
558  * Needed as POSIX locking is based on file and process, not
559  * file descriptor and process.
560  */
561
562 typedef struct file_fd_struct
563 {
564         struct file_fd_struct *next, *prev;
565         uint16 ref_count;
566         uint16 uid_cache_count;
567         uid_t uid_users_cache[10];
568         SMB_DEV_T dev;
569         SMB_INO_T inode;
570         int fd;
571         int fd_readonly;
572         int fd_writeonly;
573         int real_open_flags;
574         BOOL delete_on_close;
575 } file_fd_struct;
576
577 /*
578  * Structure used to keep directory state information around.
579  * Used in NT change-notify code.
580  */
581
582 typedef struct
583 {
584   time_t modify_time;
585   time_t status_time;
586 } dir_status_struct;
587
588 struct uid_cache {
589   int entries;
590   uid_t list[UID_CACHE_SIZE];
591 };
592
593 typedef struct
594 {
595   char *name;
596   BOOL is_wild;
597 } name_compare_entry;
598
599 typedef struct connection_struct
600 {
601         struct connection_struct *next, *prev;
602         unsigned cnum; /* an index passed over the wire */
603         int service;
604         BOOL force_user;
605         struct uid_cache uid_cache;
606         void *dirptr;
607         BOOL printer;
608         BOOL ipc;
609         BOOL read_only;
610         BOOL admin_user;
611         char *dirpath;
612         char *connectpath;
613         char *origpath;
614         char *user; /* name of user who *opened* this connection */
615         uid_t uid; /* uid of user who *opened* this connection */
616         gid_t gid; /* gid of user who *opened* this connection */
617
618         uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
619
620         /* following groups stuff added by ih */
621
622         /* This groups info is valid for the user that *opened* the connection */
623         int ngroups;
624         gid_t *groups;
625         
626         time_t lastused;
627         BOOL used;
628         int num_files_open;
629         name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */
630         name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */
631         name_compare_entry *veto_oplock_list; /* Per-share list of files to refuse oplocks on. */       
632
633 } connection_struct;
634
635 struct unix_sec_ctxt
636 {
637         uid_t uid;
638         gid_t gid;
639         int ngroups;
640         gid_t *groups;
641
642         char *name;
643 };
644
645 struct nt_sec_ctxt
646 {
647         /* this should (will?) probably become a SEC_DESC */
648         DOM_SID user_sid;
649         DOM_SID group_sid;
650
651         char *name;
652         char *domain;
653 };
654
655 #if 0
656 struct sec_ctxt
657 {
658         struct unix_sec_ctxt unix;
659         struct nt_sec_ctxt   nt;
660 };
661 #endif
662
663 struct current_user
664 {
665         connection_struct *conn;
666         uint16 vuid;
667         uid_t uid;
668         gid_t gid;
669         int ngroups;
670         gid_t *groups;
671 };
672
673 typedef struct files_struct
674 {
675         struct files_struct *next, *prev;
676         int fnum;
677         connection_struct *conn;
678         file_fd_struct *fd_ptr;
679         SMB_OFF_T pos;
680         SMB_OFF_T size;
681         mode_t mode;
682         uint16 vuid;
683         char *mmap_ptr;
684         SMB_OFF_T mmap_size;
685         write_bmpx_struct *wbmpx_ptr;
686         struct timeval open_time;
687         int share_mode;
688         time_t pending_modtime;
689         BOOL open;
690         BOOL can_lock;
691         BOOL can_read;
692         BOOL can_write;
693         BOOL print_file;
694         BOOL modified;
695         BOOL granted_oplock;
696         BOOL sent_oplock_break;
697         BOOL is_directory;
698         char *fsp_name;
699 } files_struct;
700
701 /* Domain controller authentication protocol info */
702 struct dcinfo
703 {
704   DOM_CHAL clnt_chal; /* Initial challenge received from client */
705   DOM_CHAL srv_chal;  /* Initial server challenge */
706   DOM_CRED clnt_cred; /* Last client credential */
707   DOM_CRED srv_cred;  /* Last server credential */
708
709   uchar  sess_key[8]; /* Session key */
710   uchar  md4pw[16];   /* md4(machine password) */
711 };
712
713 typedef struct
714 {
715   uid_t uid; /* uid of a validated user */
716   gid_t gid; /* gid of a validated user */
717
718   fstring requested_name; /* user name from the client */
719   fstring name; /* unix user name of a validated user */
720   fstring real_name;   /* to store real name from password file - simeon */
721   BOOL guest;
722
723   /* following groups stuff added by ih */
724   /* This groups info is needed for when we become_user() for this uid */
725   int n_groups;
726   gid_t *groups;
727
728   int n_sids;
729   int *sids;
730
731   /* per-user authentication information on NT RPCs */
732   struct dcinfo dc;
733
734 } user_struct;
735
736
737 enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING};
738
739 typedef struct
740 {
741   int job;
742   int size;
743   int status;
744   int priority;
745   time_t time;
746   char user[30];
747   char file[100];
748 } print_queue_struct;
749
750 enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
751
752 typedef struct
753 {
754   fstring message;
755   int status;
756 }  print_status_struct;
757
758 /* used for server information: client, nameserv and ipc */
759 struct server_info_struct
760 {
761   fstring name;
762   uint32 type;
763   fstring comment;
764   fstring domain; /* used ONLY in ipc.c NOT namework.c */
765   BOOL server_added; /* used ONLY in ipc.c NOT namework.c */
766 };
767
768
769 /* used for network interfaces */
770 struct interface
771 {
772         struct interface *next;
773         struct in_addr ip;
774         struct in_addr bcast;
775         struct in_addr nmask;
776 };
777
778 /* struct returned by get_share_modes */
779 typedef struct
780 {
781   int pid;
782   uint16 op_port;
783   uint16 op_type;
784   int share_mode;
785   struct timeval time;
786 } share_mode_entry;
787
788
789 /* each implementation of the share mode code needs
790    to support the following operations */
791 struct share_ops {
792         BOOL (*stop_mgmt)(void);
793         BOOL (*lock_entry)(connection_struct *, SMB_DEV_T , SMB_INO_T , int *);
794         BOOL (*unlock_entry)(connection_struct *, SMB_DEV_T , SMB_INO_T , int );
795         int (*get_entries)(connection_struct *, int , SMB_DEV_T , SMB_INO_T , share_mode_entry **);
796         void (*del_entry)(int , files_struct *);
797         BOOL (*set_entry)(int, files_struct *, uint16 , uint16 );
798     BOOL (*mod_entry)(int, files_struct *, void (*)(share_mode_entry *, SMB_DEV_T, SMB_INO_T, void *), void *);
799         int (*forall)(void (*)(share_mode_entry *, char *));
800         void (*status)(FILE *);
801 };
802
803 /* each implementation of the shared memory code needs
804    to support the following operations */
805 struct shmem_ops {
806         BOOL (*shm_close)( void );
807         int (*shm_alloc)(int );
808         BOOL (*shm_free)(int );
809         int (*get_userdef_off)(void);
810         void *(*offset2addr)(int );
811         int (*addr2offset)(void *addr);
812         BOOL (*lock_hash_entry)(unsigned int);
813         BOOL (*unlock_hash_entry)( unsigned int );
814         BOOL (*get_usage)(int *,int *,int *);
815         unsigned (*hash_size)(void);
816 };
817
818 /*
819  * Each implementation of the password database code needs
820  * to support the following operations.
821  */
822
823 struct smb_passdb_ops
824 {
825         /*
826          * Password database operations.
827          */
828         void *(*startsmbpwent)(BOOL);
829         void (*endsmbpwent)(void *);
830         SMB_BIG_UINT (*getsmbpwpos)(void *);
831         BOOL (*setsmbpwpos)(void *, SMB_BIG_UINT);
832
833         /*
834          * smb password database query functions.
835          */
836         struct smb_passwd *(*getsmbpwnam)(const char *);
837         struct smb_passwd *(*getsmbpwuid)(uid_t);
838         struct smb_passwd *(*getsmbpwent)(void *);
839
840         /*
841          * smb password database modification functions.
842          */
843         BOOL (*add_smbpwd_entry)(struct smb_passwd *);
844         BOOL (*mod_smbpwd_entry)(struct smb_passwd *, BOOL);
845
846 #if 0
847   /*
848    * password checking functions
849    */
850   struct smb_passwd *(*smb_password_chal  )(const char *username, const char lm_pass[24], const char nt_pass[24], char chal[8]);
851   struct smb_passwd *(*smb_password_check )(const char *username, const char lm_hash[16], const char nt_hash[16]);
852   struct passwd     *(*unix_password_check)(const char *username, const char *pass, int pass_len);
853 #endif
854 };
855
856 /*
857  * Each implementation of the password database code needs
858  * to support the following operations.
859  */
860
861 struct sam_passdb_ops {
862   /*
863    * Password database operations.
864    */
865   void *(*startsam21pwent)(BOOL);
866   void (*endsam21pwent)(void *);
867   SMB_BIG_UINT (*getsam21pwpos)(void *);
868   BOOL (*setsam21pwpos)(void *, SMB_BIG_UINT);
869
870   /*
871    * sam password database query functions.
872    */
873   struct sam_passwd *(*getsam21pwntnam)(const char *);
874   struct sam_passwd *(*getsam21pwuid)(uid_t);
875   struct sam_passwd *(*getsam21pwrid)(uint32);
876   struct sam_passwd *(*getsam21pwent)(void *);
877
878   /*
879    * sam password database modification functions.
880    */
881   BOOL (*add_sam21pwd_entry)(struct sam_passwd *);
882   BOOL (*mod_sam21pwd_entry)(struct sam_passwd *, BOOL);
883
884   /*
885    * sam query display info functions.
886    */
887   struct sam_disp_info *(*getsamdispntnam)(const char *);
888   struct sam_disp_info *(*getsamdisprid)(uint32);
889   struct sam_disp_info *(*getsamdispent)(void *);
890
891 };
892
893 /*
894  * Each implementation of the passgrp database code needs
895  * to support the following operations.
896  */
897
898 struct passgrp_ops
899 {
900         /*
901          * Password group database ops.
902          */
903         void *(*startsmbgrpent)(BOOL);
904         void (*endsmbgrpent)(void *);
905         SMB_BIG_UINT (*getsmbgrppos)(void *);
906         BOOL (*setsmbgrppos)(void *, SMB_BIG_UINT);
907
908         /*
909          * smb passgrp database query functions, by user attributes.
910          */
911         struct smb_passwd *(*getsmbgrpntnam)(const char *, uint32**, int*, uint32**, int*);
912         struct smb_passwd *(*getsmbgrpuid)(uid_t , uint32**, int*, uint32**, int*);
913         struct smb_passwd *(*getsmbgrprid)(uint32, uint32**, int*, uint32**, int*);
914         struct smb_passwd *(*getsmbgrpent)(void *, uint32**, int*, uint32**, int*);
915 };
916
917 /*
918  * Each implementation of the group database code needs
919  * to support the following operations.
920  *
921  * This allows enumeration, modification and addition of groups.  there
922  * is _no_ deletion of groups: you can only modify them to a status of
923  * "deleted" (this by the way is a requirement of c2 rating)
924  */
925
926 struct groupdb_ops
927 {
928         /*
929          * Group database ops.
930          */
931         void *(*startgroupent)(BOOL);
932         void (*endgroupent)(void *);
933         SMB_BIG_UINT (*getgrouppos)(void *);
934         BOOL (*setgrouppos)(void *, SMB_BIG_UINT);
935
936         /*
937          * group database query functions. 
938          */
939         DOMAIN_GRP *(*getgroupntnam)(const char *, DOMAIN_GRP_MEMBER **, int *);
940         DOMAIN_GRP *(*getgroupgid)(gid_t , DOMAIN_GRP_MEMBER **, int *);
941         DOMAIN_GRP *(*getgrouprid)(uint32, DOMAIN_GRP_MEMBER **, int *);
942         DOMAIN_GRP *(*getgroupent)(void *, DOMAIN_GRP_MEMBER **, int *);
943
944         /*
945          * group database modification functions.
946          */
947         BOOL (*add_group_entry)(DOMAIN_GRP *);
948         BOOL (*mod_group_entry)(DOMAIN_GRP *);
949         BOOL (*del_group_entry)(uint32);
950
951         BOOL (*add_group_member)(uint32, uint32);
952         BOOL (*del_group_member)(uint32, uint32);
953
954         /*
955          * user group functions
956          */
957         BOOL (*getusergroupsntnam)(const char *, DOMAIN_GRP **, int *);
958 };
959
960 /*
961  * Each implementation of the alias database code needs
962  * to support the following operations.
963  *
964  * This allows enumeration, modification and addition of aliases.  there
965  * is _no_ deletion of aliases: you can only modify them to a status of
966  * "deleted" (this by the way is a requirement of c2 rating)
967  */
968
969 struct aliasdb_ops
970 {
971         /*
972          * Alias database ops.
973          */
974         void *(*startaliasent)(BOOL);
975         void (*endaliasent)(void *);
976         SMB_BIG_UINT (*getaliaspos)(void *);
977         BOOL (*setaliaspos)(void *, SMB_BIG_UINT);
978
979         /*
980          * alias database query functions. 
981          */
982         LOCAL_GRP *(*getaliasntnam)(const char *, LOCAL_GRP_MEMBER **, int *);
983         LOCAL_GRP *(*getaliasgid)(gid_t , LOCAL_GRP_MEMBER **, int *);
984         LOCAL_GRP *(*getaliasrid)(uint32, LOCAL_GRP_MEMBER **, int *);
985         LOCAL_GRP *(*getaliasent)(void *, LOCAL_GRP_MEMBER **, int *);
986
987         /*
988          * alias database modification functions.
989          */
990         BOOL (*add_alias_entry)(LOCAL_GRP *);
991         BOOL (*mod_alias_entry)(LOCAL_GRP *);
992         BOOL (*del_alias_entry)(uint32);
993
994         BOOL (*add_alias_member)(uint32, DOM_SID*);
995         BOOL (*del_alias_member)(uint32, DOM_SID*);
996
997         /*
998          * user alias functions
999          */
1000         BOOL (*getuseraliasntnam)(const char *, LOCAL_GRP **, int *);
1001 };
1002
1003 /* this is used for smbstatus */
1004
1005 struct connect_record
1006 {
1007   int magic;
1008   int pid;
1009   int cnum;
1010   uid_t uid;
1011   gid_t gid;
1012   char name[24];
1013   char addr[24];
1014   char machine[128];
1015   time_t start;
1016 };
1017
1018 /* This is used by smbclient to send it to a smbfs mount point */
1019 struct connection_options {
1020   int protocol;
1021   /* Connection-Options */
1022   uint32 max_xmit;
1023   uint16 server_vuid;
1024   uint16 tid;
1025   /* The following are LANMAN 1.0 options */
1026   uint16 sec_mode;
1027   uint16 max_mux;
1028   uint16 max_vcs;
1029   uint16 rawmode;
1030   uint32 sesskey;
1031   /* The following are NT LM 0.12 options */
1032   uint32 maxraw;
1033   uint32 capabilities;
1034   uint16 serverzone;
1035 };
1036
1037 /* the following are used by loadparm for option lists */
1038 typedef enum
1039 {
1040   P_BOOL,P_BOOLREV,P_CHAR,P_INTEGER,P_OCTAL,
1041   P_STRING,P_USTRING,P_GSTRING,P_UGSTRING,P_ENUM,P_SEP
1042 } parm_type;
1043
1044 typedef enum
1045 {
1046   P_LOCAL,P_GLOBAL,P_SEPARATOR,P_NONE
1047 } parm_class;
1048
1049 struct enum_list {
1050         int value;
1051         char *name;
1052 };
1053
1054 struct parm_struct
1055 {
1056         char *label;
1057         parm_type type;
1058         parm_class class;
1059         void *ptr;
1060         BOOL (*special)(char *, char **);
1061         struct enum_list *enum_list;
1062         unsigned flags;
1063         union {
1064                 BOOL bvalue;
1065                 int ivalue;
1066                 char *svalue;
1067                 char cvalue;
1068         } def;
1069 };
1070
1071 struct bitmap {
1072         uint32 *b;
1073         int n;
1074 };
1075
1076 #define FLAG_BASIC 1 /* fundamental options */
1077 #define FLAG_HIDE  2 /* options that should be hidden in SWAT */
1078 #define FLAG_PRINT 4 /* printing options */
1079 #define FLAG_GLOBAL 8 /* local options that should be globally settable in SWAT */
1080 #define FLAG_DEPRECATED 0x10 /* options that should no longer be used */
1081
1082 #ifndef LOCKING_VERSION
1083 #define LOCKING_VERSION 4
1084 #endif /* LOCKING_VERSION */
1085
1086 /* these are useful macros for checking validity of handles */
1087 #define OPEN_FSP(fsp)    ((fsp) && (fsp)->open && !(fsp)->is_directory)
1088 #define OPEN_CONN(conn)    ((conn) && (conn)->open)
1089 #define IS_IPC(conn)       ((conn) && (conn)->ipc)
1090 #define IS_PRINT(conn)       ((conn) && (conn)->printer)
1091 #define FNUM_OK(fsp,c) (OPEN_FSP(fsp) && (c)==(fsp)->conn)
1092
1093 #define CHECK_FSP(fsp,conn) if (!FNUM_OK(fsp,conn)) \
1094                                return(ERROR(ERRDOS,ERRbadfid))
1095 #define CHECK_READ(fsp) if (!(fsp)->can_read) \
1096                                return(ERROR(ERRDOS,ERRbadaccess))
1097 #define CHECK_WRITE(fsp) if (!(fsp)->can_write) \
1098                                return(ERROR(ERRDOS,ERRbadaccess))
1099 #define CHECK_ERROR(fsp) if (HAS_CACHED_ERROR(fsp)) \
1100                                return(CACHED_ERROR(fsp))
1101
1102 /* translates a connection number into a service number */
1103 #define SNUM(conn)         ((conn)?(conn)->service:-1)
1104
1105 /* access various service details */
1106 #define SERVICE(snum)      (lp_servicename(snum))
1107 #define PRINTCAP           (lp_printcapname())
1108 #define PRINTCOMMAND(snum) (lp_printcommand(snum))
1109 #define PRINTERNAME(snum)  (lp_printername(snum))
1110 #define CAN_WRITE(conn)    (!conn->read_only)
1111 #define VALID_SNUM(snum)   (lp_snum_ok(snum))
1112 #define GUEST_OK(snum)     (VALID_SNUM(snum) && lp_guest_ok(snum))
1113 #define GUEST_ONLY(snum)   (VALID_SNUM(snum) && lp_guest_only(snum))
1114 #define CAN_SETDIR(snum)   (!lp_no_set_dir(snum))
1115 #define CAN_PRINT(conn)    ((conn) && lp_print_ok((conn)->service))
1116 #define MAP_HIDDEN(conn)   ((conn) && lp_map_hidden((conn)->service))
1117 #define MAP_SYSTEM(conn)   ((conn) && lp_map_system((conn)->service))
1118 #define MAP_ARCHIVE(conn)   ((conn) && lp_map_archive((conn)->service))
1119 #define IS_HIDDEN_PATH(conn,path)  ((conn) && is_in_path((path),(conn)->hide_list))
1120 #define IS_VETO_PATH(conn,path)  ((conn) && is_in_path((path),(conn)->veto_list))
1121 #define IS_VETO_OPLOCK_PATH(conn,path)  ((conn) && is_in_path((path),(conn)->veto_oplock_list))
1122
1123 /* 
1124  * Used by the stat cache code to check if a returned
1125  * stat structure is valid.
1126  */
1127
1128 #define VALID_STAT(st) (st.st_nlink != 0)  
1129 #define VALID_STAT_OF_DIR(st) (VALID_STAT(st) && S_ISDIR(st.st_mode))
1130
1131 #define SMBENCRYPT()       (lp_encrypted_passwords())
1132
1133 /* the basic packet size, assuming no words or bytes */
1134 #define smb_size 39
1135
1136 /* offsets into message for common items */
1137 #define smb_com 8
1138 #define smb_rcls 9
1139 #define smb_reh 10
1140 #define smb_err 11
1141 #define smb_flg 13
1142 #define smb_flg2 14
1143 #define smb_reb 13
1144 #define smb_tid 28
1145 #define smb_pid 30
1146 #define smb_uid 32
1147 #define smb_mid 34
1148 #define smb_wct 36
1149 #define smb_vwv 37
1150 #define smb_vwv0 37
1151 #define smb_vwv1 39
1152 #define smb_vwv2 41
1153 #define smb_vwv3 43
1154 #define smb_vwv4 45
1155 #define smb_vwv5 47
1156 #define smb_vwv6 49
1157 #define smb_vwv7 51
1158 #define smb_vwv8 53
1159 #define smb_vwv9 55
1160 #define smb_vwv10 57
1161 #define smb_vwv11 59
1162 #define smb_vwv12 61
1163 #define smb_vwv13 63
1164 #define smb_vwv14 65
1165 #define smb_vwv15 67
1166 #define smb_vwv16 69
1167 #define smb_vwv17 71
1168
1169 /* flag defines. CIFS spec 3.1.1 */
1170 #define FLAG_SUPPORT_LOCKREAD       0x01
1171 #define FLAG_CLIENT_BUF_AVAIL       0x02
1172 #define FLAG_RESERVED               0x04
1173 #define FLAG_CASELESS_PATHNAMES     0x08
1174 #define FLAG_CANONICAL_PATHNAMES    0x10
1175 #define FLAG_REQUEST_OPLOCK         0x20
1176 #define FLAG_REQUEST_BATCH_OPLOCK   0x40
1177 #define FLAG_REPLY                  0x80
1178
1179 /* the complete */
1180 #define SMBmkdir      0x00   /* create directory */
1181 #define SMBrmdir      0x01   /* delete directory */
1182 #define SMBopen       0x02   /* open file */
1183 #define SMBcreate     0x03   /* create file */
1184 #define SMBclose      0x04   /* close file */
1185 #define SMBflush      0x05   /* flush file */
1186 #define SMBunlink     0x06   /* delete file */
1187 #define SMBmv         0x07   /* rename file */
1188 #define SMBgetatr     0x08   /* get file attributes */
1189 #define SMBsetatr     0x09   /* set file attributes */
1190 #define SMBread       0x0A   /* read from file */
1191 #define SMBwrite      0x0B   /* write to file */
1192 #define SMBlock       0x0C   /* lock byte range */
1193 #define SMBunlock     0x0D   /* unlock byte range */
1194 #define SMBctemp      0x0E   /* create temporary file */
1195 #define SMBmknew      0x0F   /* make new file */
1196 #define SMBchkpth     0x10   /* check directory path */
1197 #define SMBexit       0x11   /* process exit */
1198 #define SMBlseek      0x12   /* seek */
1199 #define SMBtcon       0x70   /* tree connect */
1200 #define SMBtconX      0x75   /* tree connect and X*/
1201 #define SMBtdis       0x71   /* tree disconnect */
1202 #define SMBnegprot    0x72   /* negotiate protocol */
1203 #define SMBdskattr    0x80   /* get disk attributes */
1204 #define SMBsearch     0x81   /* search directory */
1205 #define SMBsplopen    0xC0   /* open print spool file */
1206 #define SMBsplwr      0xC1   /* write to print spool file */
1207 #define SMBsplclose   0xC2   /* close print spool file */
1208 #define SMBsplretq    0xC3   /* return print queue */
1209 #define SMBsends      0xD0   /* send single block message */
1210 #define SMBsendb      0xD1   /* send broadcast message */
1211 #define SMBfwdname    0xD2   /* forward user name */
1212 #define SMBcancelf    0xD3   /* cancel forward */
1213 #define SMBgetmac     0xD4   /* get machine name */
1214 #define SMBsendstrt   0xD5   /* send start of multi-block message */
1215 #define SMBsendend    0xD6   /* send end of multi-block message */
1216 #define SMBsendtxt    0xD7   /* send text of multi-block message */
1217
1218 /* Core+ protocol */
1219 #define SMBlockread       0x13   /* Lock a range and read */
1220 #define SMBwriteunlock 0x14 /* Unlock a range then write */
1221 #define SMBreadbraw   0x1a  /* read a block of data with no smb header */
1222 #define SMBwritebraw  0x1d  /* write a block of data with no smb header */
1223 #define SMBwritec     0x20  /* secondary write request */
1224 #define SMBwriteclose 0x2c  /* write a file then close it */
1225
1226 /* dos extended protocol */
1227 #define SMBreadBraw      0x1A   /* read block raw */
1228 #define SMBreadBmpx      0x1B   /* read block multiplexed */
1229 #define SMBreadBs        0x1C   /* read block (secondary response) */
1230 #define SMBwriteBraw     0x1D   /* write block raw */
1231 #define SMBwriteBmpx     0x1E   /* write block multiplexed */
1232 #define SMBwriteBs       0x1F   /* write block (secondary request) */
1233 #define SMBwriteC        0x20   /* write complete response */
1234 #define SMBsetattrE      0x22   /* set file attributes expanded */
1235 #define SMBgetattrE      0x23   /* get file attributes expanded */
1236 #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
1237 #define SMBtrans         0x25   /* transaction - name, bytes in/out */
1238 #define SMBtranss        0x26   /* transaction (secondary request/response) */
1239 #define SMBioctl         0x27   /* IOCTL */
1240 #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
1241 #define SMBcopy          0x29   /* copy */
1242 #define SMBmove          0x2A   /* move */
1243 #define SMBecho          0x2B   /* echo */
1244 #define SMBopenX         0x2D   /* open and X */
1245 #define SMBreadX         0x2E   /* read and X */
1246 #define SMBwriteX        0x2F   /* write and X */
1247 #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
1248 #define SMBffirst        0x82   /* find first */
1249 #define SMBfunique       0x83   /* find unique */
1250 #define SMBfclose        0x84   /* find close */
1251 #define SMBinvalid       0xFE   /* invalid command */
1252
1253 /* Extended 2.0 protocol */
1254 #define SMBtrans2        0x32   /* TRANS2 protocol set */
1255 #define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
1256 #define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
1257 #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
1258 #define SMBulogoffX      0x74   /* user logoff */
1259
1260 /* NT SMB extensions. */
1261 #define SMBnttrans       0xA0   /* NT transact */
1262 #define SMBnttranss      0xA1   /* NT transact secondary */
1263 #define SMBntcreateX     0xA2   /* NT create and X */
1264 #define SMBntcancel      0xA4   /* NT cancel */
1265
1266 /* These are the TRANS2 sub commands */
1267 #define TRANSACT2_OPEN                        0
1268 #define TRANSACT2_FINDFIRST                   1
1269 #define TRANSACT2_FINDNEXT                    2
1270 #define TRANSACT2_QFSINFO                     3
1271 #define TRANSACT2_SETFSINFO                   4
1272 #define TRANSACT2_QPATHINFO                   5
1273 #define TRANSACT2_SETPATHINFO                 6
1274 #define TRANSACT2_QFILEINFO                   7
1275 #define TRANSACT2_SETFILEINFO                 8
1276 #define TRANSACT2_FSCTL                       9
1277 #define TRANSACT2_IOCTL                     0xA
1278 #define TRANSACT2_FINDNOTIFYFIRST           0xB
1279 #define TRANSACT2_FINDNOTIFYNEXT            0xC
1280 #define TRANSACT2_MKDIR                     0xD
1281 #define TRANSACT2_SESSION_SETUP             0xE
1282 #define TRANSACT2_GET_DFS_REFERRAL         0x10
1283 #define TRANSACT2_REPORT_DFS_INCONSISTANCY 0x11
1284
1285 /* These are the NT transact sub commands. */
1286 #define NT_TRANSACT_CREATE                1
1287 #define NT_TRANSACT_IOCTL                 2
1288 #define NT_TRANSACT_SET_SECURITY_DESC     3
1289 #define NT_TRANSACT_NOTIFY_CHANGE         4
1290 #define NT_TRANSACT_RENAME                5
1291 #define NT_TRANSACT_QUERY_SECURITY_DESC   6
1292
1293 /* these are the trans2 sub fields for primary requests */
1294 #define smb_tpscnt smb_vwv0
1295 #define smb_tdscnt smb_vwv1
1296 #define smb_mprcnt smb_vwv2
1297 #define smb_mdrcnt smb_vwv3
1298 #define smb_msrcnt smb_vwv4
1299 #define smb_flags smb_vwv5
1300 #define smb_timeout smb_vwv6
1301 #define smb_pscnt smb_vwv9
1302 #define smb_psoff smb_vwv10
1303 #define smb_dscnt smb_vwv11
1304 #define smb_dsoff smb_vwv12
1305 #define smb_suwcnt smb_vwv13
1306 #define smb_setup smb_vwv14
1307 #define smb_setup0 smb_setup
1308 #define smb_setup1 (smb_setup+2)
1309 #define smb_setup2 (smb_setup+4)
1310
1311 /* these are for the secondary requests */
1312 #define smb_spscnt smb_vwv2
1313 #define smb_spsoff smb_vwv3
1314 #define smb_spsdisp smb_vwv4
1315 #define smb_sdscnt smb_vwv5
1316 #define smb_sdsoff smb_vwv6
1317 #define smb_sdsdisp smb_vwv7
1318 #define smb_sfid smb_vwv8
1319
1320 /* and these for responses */
1321 #define smb_tprcnt smb_vwv0
1322 #define smb_tdrcnt smb_vwv1
1323 #define smb_prcnt smb_vwv3
1324 #define smb_proff smb_vwv4
1325 #define smb_prdisp smb_vwv5
1326 #define smb_drcnt smb_vwv6
1327 #define smb_droff smb_vwv7
1328 #define smb_drdisp smb_vwv8
1329
1330 /* these are for the NT trans primary request. */
1331 #define smb_nt_MaxSetupCount smb_vwv0
1332 #define smb_nt_Flags (smb_vwv0 + 1)
1333 #define smb_nt_TotalParameterCount (smb_vwv0 + 3)
1334 #define smb_nt_TotalDataCount (smb_vwv0 + 7)
1335 #define smb_nt_MaxParameterCount (smb_vwv0 + 11)
1336 #define smb_nt_MaxDataCount (smb_vwv0 + 15)
1337 #define smb_nt_ParameterCount (smb_vwv0 + 19)
1338 #define smb_nt_ParameterOffset (smb_vwv0 + 23)
1339 #define smb_nt_DataCount (smb_vwv0 + 27)
1340 #define smb_nt_DataOffset (smb_vwv0 + 31)
1341 #define smb_nt_SetupCount (smb_vwv0 + 35)
1342 #define smb_nt_Function (smb_vwv0 + 36)
1343 #define smb_nt_SetupStart (smb_vwv0 + 38)
1344
1345 /* these are for the NT trans secondary request. */
1346 #define smb_nts_TotalParameterCount (smb_vwv0 + 3)
1347 #define smb_nts_TotalDataCount (smb_vwv0 + 7)
1348 #define smb_nts_ParameterCount (smb_vwv0 + 11)
1349 #define smb_nts_ParameterOffset (smb_vwv0 + 15)
1350 #define smb_nts_ParameterDisplacement (smb_vwv0 + 19)
1351 #define smb_nts_DataCount (smb_vwv0 + 23)
1352 #define smb_nts_DataOffset (smb_vwv0 + 27)
1353 #define smb_nts_DataDisplacement (smb_vwv0 + 31)
1354
1355 /* these are for the NT trans reply. */
1356 #define smb_ntr_TotalParameterCount (smb_vwv0 + 3)
1357 #define smb_ntr_TotalDataCount (smb_vwv0 + 7)
1358 #define smb_ntr_ParameterCount (smb_vwv0 + 11)
1359 #define smb_ntr_ParameterOffset (smb_vwv0 + 15)
1360 #define smb_ntr_ParameterDisplacement (smb_vwv0 + 19)
1361 #define smb_ntr_DataCount (smb_vwv0 + 23)
1362 #define smb_ntr_DataOffset (smb_vwv0 + 27)
1363 #define smb_ntr_DataDisplacement (smb_vwv0 + 31)
1364
1365 /* these are for the NT create_and_X */
1366 #define smb_ntcreate_NameLength (smb_vwv0 + 5)
1367 #define smb_ntcreate_Flags (smb_vwv0 + 7)
1368 #define smb_ntcreate_RootDirectoryFid (smb_vwv0 + 11)
1369 #define smb_ntcreate_DesiredAccess (smb_vwv0 + 15)
1370 #define smb_ntcreate_AllocationSize (smb_vwv0 + 19)
1371 #define smb_ntcreate_FileAttributes (smb_vwv0 + 27)
1372 #define smb_ntcreate_ShareAccess (smb_vwv0 + 31)
1373 #define smb_ntcreate_CreateDisposition (smb_vwv0 + 35)
1374 #define smb_ntcreate_CreateOptions (smb_vwv0 + 39)
1375 #define smb_ntcreate_ImpersonationLevel (smb_vwv0 + 43)
1376 #define smb_ntcreate_SecurityFlags (smb_vwv0 + 47)
1377
1378 /* this is used on a TConX. I'm not sure the name is very helpful though */
1379 #define SMB_SUPPORT_SEARCH_BITS        0x0001
1380
1381 /* these are the constants used in the above call. */
1382 /* DesiredAccess */
1383 /* File Specific access rights. */
1384 #define FILE_READ_DATA        0x001
1385 #define FILE_WRITE_DATA       0x002
1386 #define FILE_APPEND_DATA      0x004
1387 #define FILE_READ_EA          0x008
1388 #define FILE_WRITE_EA         0x010
1389 #define FILE_EXECUTE          0x020
1390 #define FILE_DELETE_CHILD     0x040
1391 #define FILE_READ_ATTRIBUTES  0x080
1392 #define FILE_WRITE_ATTRIBUTES 0x100
1393  
1394 /* Generic access masks & rights. */
1395 #define SPECIFIC_RIGHTS_MASK 0x00FFFFL
1396 #define STANDARD_RIGHTS_MASK 0xFF0000L
1397 #define DELETE_ACCESS        (1L<<16)
1398 #define READ_CONTROL_ACCESS  (1L<<17)
1399 #define WRITE_DAC_ACCESS     (1L<<18)
1400 #define WRITE_OWNER_ACCESS   (1L<<19)
1401 #define SYNCHRONIZE_ACCESS   (1L<<20)
1402 #define SYSTEM_SECURITY_ACCESS (1L<<24)
1403
1404 /* Flags field. */
1405 #define REQUEST_OPLOCK 2
1406 #define REQUEST_BATCH_OPLOCK 4
1407 #define OPEN_DIRECTORY 8
1408
1409 /* ShareAccess field. */
1410 #define FILE_SHARE_NONE 0 /* Cannot be used in bitmask. */
1411 #define FILE_SHARE_READ 1
1412 #define FILE_SHARE_WRITE 2
1413 #define FILE_SHARE_DELETE 4
1414
1415 /* FileAttributesField */
1416 #define FILE_ATTRIBUTE_READONLY aRONLY
1417 #define FILE_ATTRIBUTE_HIDDEN aHIDDEN
1418 #define FILE_ATTRIBUTE_SYSTEM aSYSTEM
1419 #define FILE_ATTRIBUTE_DIRECTORY aDIR
1420 #define FILE_ATTRIBUTE_ARCHIVE aARCH
1421 #define FILE_ATTRIBUTE_NORMAL 0x80L
1422 #define FILE_ATTRIBUTE_TEMPORARY 0x100L
1423 #define FILE_ATTRIBUTE_COMPRESSED 0x800L
1424 #define SAMBA_ATTRIBUTES_MASK 0x7F
1425
1426 /* Flags - combined with attributes. */
1427 #define FILE_FLAG_WRITE_THROUGH    0x80000000L
1428 #define FILE_FLAG_NO_BUFFERING     0x20000000L
1429 #define FILE_FLAG_RANDOM_ACCESS    0x10000000L
1430 #define FILE_FLAG_SEQUENTIAL_SCAN  0x08000000L
1431 #define FILE_FLAG_DELETE_ON_CLOSE  0x04000000L
1432 #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000L
1433 #define FILE_FLAG_POSIX_SEMANTICS  0x01000000L
1434
1435 /* CreateDisposition field. */
1436 #define FILE_SUPERSEDE 0
1437 #define FILE_OPEN 1
1438 #define FILE_CREATE 2
1439 #define FILE_OPEN_IF 3
1440 #define FILE_OVERWRITE 4
1441 #define FILE_OVERWRITE_IF 5
1442
1443 /* CreateOptions field. */
1444 #define FILE_DIRECTORY_FILE       0x0001
1445 #define FILE_WRITE_THROUGH        0x0002
1446 #define FILE_SEQUENTIAL_ONLY      0x0004
1447 #define FILE_NON_DIRECTORY_FILE   0x0040
1448 #define FILE_NO_EA_KNOWLEDGE      0x0200
1449 #define FILE_EIGHT_DOT_THREE_ONLY 0x0400
1450 #define FILE_RANDOM_ACCESS        0x0800
1451 #define FILE_DELETE_ON_CLOSE      0x1000
1452
1453 /* Responses when opening a file. */
1454 #define FILE_WAS_OPENED 1
1455 #define FILE_WAS_CREATED 2
1456 #define FILE_WAS_OVERWRITTEN 3
1457
1458 /* File type flags */
1459 #define FILE_TYPE_DISK  0
1460 #define FILE_TYPE_BYTE_MODE_PIPE 1
1461 #define FILE_TYPE_MESSAGE_MODE_PIPE 2
1462 #define FILE_TYPE_PRINTER 3
1463 #define FILE_TYPE_COMM_DEVICE 4
1464 #define FILE_TYPE_UNKNOWN 0xFFFF
1465
1466 /* Flag for NT transact rename call. */
1467 #define RENAME_REPLACE_IF_EXISTS 1
1468
1469 /* Filesystem Attributes. */
1470 #define FILE_CASE_SENSITIVE_SEARCH 0x1
1471 #define FILE_CASE_PRESERVED_NAMES 0x2
1472 #define FILE_UNICODE_ON_DISK 0x4
1473 #define FILE_PERISITANT_ACLS 0x8
1474
1475 /* ChangeNotify flags. */
1476 #define FILE_NOTIFY_CHANGE_FILE_NAME   0x001
1477 #define FILE_NOTIFY_CHANGE_DIR_NAME    0x002
1478 #define FILE_NOTIFY_CHANGE_ATTRIBUTES  0x004
1479 #define FILE_NOTIFY_CHANGE_SIZE        0x008
1480 #define FILE_NOTIFY_CHANGE_LAST_WRITE  0x010
1481 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x020
1482 #define FILE_NOTIFY_CHANGE_CREATION    0x040
1483 #define FILE_NOTIFY_CHANGE_EA          0x080
1484 #define FILE_NOTIFY_CHANGE_SECURITY    0x100
1485
1486 /* where to find the base of the SMB packet proper */
1487 #define smb_base(buf) (((char *)(buf))+4)
1488
1489
1490 #define SMB_SUCCESS 0  /* The request was successful. */
1491 #define ERRDOS 0x01 /*  Error is from the core DOS operating system set. */
1492 #define ERRSRV 0x02  /* Error is generated by the server network file manager.*/
1493 #define ERRHRD 0x03  /* Error is an hardware error. */
1494 #define ERRCMD 0xFF  /* Command was not in the "SMB" format. */
1495
1496 #ifdef HAVE_STDARG_H
1497 int slprintf(char *str, int n, char *format, ...)
1498 #ifdef __GNUC__
1499      __attribute__ ((format (printf, 3, 4)))
1500 #endif
1501 ;
1502 #else
1503 int slprintf();
1504 #endif
1505
1506 #ifdef WITH_DFS
1507 void dfs_unlogin(void);
1508 extern int dcelogin_atmost_once;
1509 #endif
1510
1511 #ifdef NOSTRDUP
1512 char *strdup(char *s);
1513 #endif
1514
1515 #ifndef MIN
1516 #define MIN(a,b) ((a)<(b)?(a):(b))
1517 #endif
1518 #ifndef MAX
1519 #define MAX(a,b) ((a)>(b)?(a):(b))
1520 #endif
1521
1522 #ifndef ABS
1523 #define ABS(a) ((a)>0?(a):(-(a)))
1524 #endif
1525
1526 #ifndef SIGNAL_CAST
1527 #define SIGNAL_CAST (RETSIGTYPE (*)(int))
1528 #endif
1529
1530 #ifndef SELECT_CAST
1531 #define SELECT_CAST
1532 #endif
1533
1534
1535 /* Some POSIX definitions for those without */
1536  
1537 #ifndef S_IFDIR
1538 #define S_IFDIR         0x4000
1539 #endif
1540 #ifndef S_ISDIR
1541 #define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
1542 #endif
1543 #ifndef S_IRWXU
1544 #define S_IRWXU 00700           /* read, write, execute: owner */
1545 #endif
1546 #ifndef S_IRUSR
1547 #define S_IRUSR 00400           /* read permission: owner */
1548 #endif
1549 #ifndef S_IWUSR
1550 #define S_IWUSR 00200           /* write permission: owner */
1551 #endif
1552 #ifndef S_IXUSR
1553 #define S_IXUSR 00100           /* execute permission: owner */
1554 #endif
1555 #ifndef S_IRWXG
1556 #define S_IRWXG 00070           /* read, write, execute: group */
1557 #endif
1558 #ifndef S_IRGRP
1559 #define S_IRGRP 00040           /* read permission: group */
1560 #endif
1561 #ifndef S_IWGRP
1562 #define S_IWGRP 00020           /* write permission: group */
1563 #endif
1564 #ifndef S_IXGRP
1565 #define S_IXGRP 00010           /* execute permission: group */
1566 #endif
1567 #ifndef S_IRWXO
1568 #define S_IRWXO 00007           /* read, write, execute: other */
1569 #endif
1570 #ifndef S_IROTH
1571 #define S_IROTH 00004           /* read permission: other */
1572 #endif
1573 #ifndef S_IWOTH
1574 #define S_IWOTH 00002           /* write permission: other */
1575 #endif
1576 #ifndef S_IXOTH
1577 #define S_IXOTH 00001           /* execute permission: other */
1578 #endif
1579
1580
1581 /* these are used in NetServerEnum to choose what to receive */
1582 #define SV_TYPE_WORKSTATION         0x00000001
1583 #define SV_TYPE_SERVER              0x00000002
1584 #define SV_TYPE_SQLSERVER           0x00000004
1585 #define SV_TYPE_DOMAIN_CTRL         0x00000008
1586 #define SV_TYPE_DOMAIN_BAKCTRL      0x00000010
1587 #define SV_TYPE_TIME_SOURCE         0x00000020
1588 #define SV_TYPE_AFP                 0x00000040
1589 #define SV_TYPE_NOVELL              0x00000080
1590 #define SV_TYPE_DOMAIN_MEMBER       0x00000100
1591 #define SV_TYPE_PRINTQ_SERVER       0x00000200
1592 #define SV_TYPE_DIALIN_SERVER       0x00000400
1593 #define SV_TYPE_SERVER_UNIX         0x00000800
1594 #define SV_TYPE_NT                  0x00001000
1595 #define SV_TYPE_WFW                 0x00002000
1596 #define SV_TYPE_SERVER_MFPN         0x00004000
1597 #define SV_TYPE_SERVER_NT           0x00008000
1598 #define SV_TYPE_POTENTIAL_BROWSER   0x00010000
1599 #define SV_TYPE_BACKUP_BROWSER      0x00020000
1600 #define SV_TYPE_MASTER_BROWSER      0x00040000
1601 #define SV_TYPE_DOMAIN_MASTER       0x00080000
1602 #define SV_TYPE_SERVER_OSF          0x00100000
1603 #define SV_TYPE_SERVER_VMS          0x00200000
1604 #define SV_TYPE_WIN95_PLUS          0x00400000
1605 #define SV_TYPE_ALTERNATE_XPORT     0x20000000  
1606 #define SV_TYPE_LOCAL_LIST_ONLY     0x40000000  
1607 #define SV_TYPE_DOMAIN_ENUM         0x80000000
1608 #define SV_TYPE_ALL                 0xFFFFFFFF  
1609
1610 /* what server type are we currently  - JHT Says we ARE 4.20 */
1611 /* this was set by JHT in liaison with Jeremy Allison early 1997 */
1612 /* setting to 4.20 at same time as announcing ourselves as NT Server */
1613 /* History: */
1614 /* Version 4.0 - never made public */
1615 /* Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9 */
1616 /*              - Reappeared in 1.9.16p11 with fixed smbd services */
1617 /* Version 4.20 - To indicate that nmbd and browsing now works better */
1618
1619 #define DEFAULT_MAJOR_VERSION 0x04
1620 #define DEFAULT_MINOR_VERSION 0x02
1621
1622 /* Browser Election Values */
1623 #define BROWSER_ELECTION_VERSION        0x010f
1624 #define BROWSER_CONSTANT        0xaa55
1625
1626 /* NT Flags2 bits - cifs6.txt section 3.1.2 */
1627    
1628 #define FLAGS2_LONG_PATH_COMPONENTS   0x0001
1629 #define FLAGS2_EXTENDED_ATTRIBUTES    0x0002
1630 #define FLAGS2_DFS_PATHNAMES          0x1000
1631 #define FLAGS2_READ_PERMIT_NO_EXECUTE 0x2000
1632 #define FLAGS2_32_BIT_ERROR_CODES     0x4000 
1633 #define FLAGS2_UNICODE_STRINGS        0x8000
1634
1635 /* Capabilities.  see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
1636
1637 #define CAP_RAW_MODE         0x0001
1638 #define CAP_MPX_MODE         0x0002
1639 #define CAP_UNICODE          0x0004
1640 #define CAP_LARGE_FILES      0x0008
1641 #define CAP_NT_SMBS          0x0010
1642 #define CAP_RPC_REMOTE_APIS  0x0020
1643 #define CAP_STATUS32         0x0040
1644 #define CAP_LEVEL_II_OPLOCKS 0x0080
1645 #define CAP_LOCK_AND_READ    0x0100
1646 #define CAP_NT_FIND          0x0200
1647 #define CAP_DFS              0x1000
1648 #define CAP_LARGE_READX      0x4000
1649
1650 /* protocol types. It assumes that higher protocols include lower protocols
1651    as subsets */
1652 enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
1653
1654 /* security levels */
1655 enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER,SEC_DOMAIN};
1656
1657 /* server roles */
1658 enum server_types
1659 {
1660         ROLE_DOMAIN_NONE,
1661         ROLE_DOMAIN_MEMBER,
1662         ROLE_DOMAIN_BDC,
1663         ROLE_DOMAIN_PDC
1664 };
1665
1666 /* printing types */
1667 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
1668                      PRINT_QNX,PRINT_PLP,PRINT_LPRNG,PRINT_SOFTQ};
1669
1670 /* Remote architectures we know about. */
1671 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_SAMBA};
1672
1673 /* case handling */
1674 enum case_handling {CASE_LOWER,CASE_UPPER};
1675
1676 #ifdef WITH_SSL
1677 /* SSL version options */
1678 enum ssl_version_enum {SMB_SSL_V2,SMB_SSL_V3,SMB_SSL_V23,SMB_SSL_TLS1};
1679 #endif /* WITH_SSL */
1680
1681 /* Macros to get at offsets within smb_lkrng and smb_unlkrng
1682    structures. We cannot define these as actual structures
1683    due to possible differences in structure packing
1684    on different machines/compilers. */
1685
1686 #define SMB_LPID_OFFSET(indx) (10 * (indx))
1687 #define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
1688 #define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
1689 #define SMB_LARGE_LKOFF_OFFSET_HIGH(indx) (4 + (20 * (indx)))
1690 #define SMB_LARGE_LKOFF_OFFSET_LOW(indx) (8 + (20 * (indx)))
1691 #define SMB_LARGE_LKLEN_OFFSET_HIGH(indx) (12 + (20 * (indx)))
1692 #define SMB_LARGE_LKLEN_OFFSET_LOW(indx) (16 + (20 * (indx)))
1693
1694 /* Macro to cache an error in a write_bmpx_struct */
1695 #define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
1696                             w->wr_discard = True, -1)
1697 /* Macro to test if an error has been cached for this fnum */
1698 #define HAS_CACHED_ERROR(fsp) ((fsp)->open && (fsp)->wbmpx_ptr && \
1699                                 (fsp)->wbmpx_ptr->wr_discard)
1700 /* Macro to turn the cached error into an error packet */
1701 #define CACHED_ERROR(fsp) cached_error_packet(inbuf,outbuf,fsp,__LINE__)
1702
1703 /* these are the datagram types */
1704 #define DGRAM_DIRECT_UNIQUE 0x10
1705
1706 #define ERROR(class,x) error_packet(inbuf,outbuf,class,x,__LINE__)
1707
1708 /* this is how errors are generated */
1709 #define UNIXERROR(defclass,deferror) unix_error_packet(inbuf,outbuf,defclass,deferror,__LINE__)
1710
1711 #define SMB_ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
1712
1713 /*
1714  * Global value meaing that the smb_uid field should be
1715  * ingored (in share level security and protocol level == CORE)
1716  */
1717
1718 #define UID_FIELD_INVALID 0
1719 #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
1720
1721 /* Defines needed for multi-codepage support. */
1722 #define MSDOS_LATIN_1_CODEPAGE 850
1723 #define KANJI_CODEPAGE 932
1724 #define HANGUL_CODEPAGE 949
1725 #define BIG5_CODEPAGE 950
1726 #define SIMPLIFIED_CHINESE_CODEPAGE 936
1727
1728 #ifdef KANJI
1729 /* 
1730  * Default client code page - Japanese 
1731  */
1732 #define DEFAULT_CLIENT_CODE_PAGE KANJI_CODEPAGE
1733 #else /* KANJI */
1734 /* 
1735  * Default client code page - 850 - Western European 
1736  */
1737 #define DEFAULT_CLIENT_CODE_PAGE MSDOS_LATIN_1_CODEPAGE
1738 #endif /* KANJI */
1739
1740 /* 
1741  * Size of buffer to use when moving files across filesystems. 
1742  */
1743 #define COPYBUF_SIZE (8*1024)
1744
1745 /* 
1746  * Integers used to override error codes. 
1747  */
1748 extern int unix_ERR_class;
1749 extern int unix_ERR_code;
1750
1751 /*
1752  * Map the Core and Extended Oplock requesst bits down
1753  * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK).
1754  */
1755
1756 /*
1757  * Core protocol.
1758  */
1759 #define CORE_OPLOCK_REQUEST(inbuf) \
1760     ((CVAL(inbuf,smb_flg)&(FLAG_REQUEST_OPLOCK|FLAG_REQUEST_BATCH_OPLOCK))>>5)
1761
1762 /*
1763  * Extended protocol.
1764  */
1765 #define EXTENDED_OPLOCK_REQUEST(inbuf) ((SVAL(inbuf,smb_vwv2)&((1<<1)|(1<<2)))>>1)
1766
1767 /* Lock types. */
1768 #define LOCKING_ANDX_SHARED_LOCK 0x1
1769 #define LOCKING_ANDX_OPLOCK_RELEASE 0x2
1770 #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x4
1771 #define LOCKING_ANDX_CANCEL_LOCK 0x8
1772 #define LOCKING_ANDX_LARGE_FILES 0x10
1773
1774 /* Oplock levels */
1775 #define OPLOCKLEVEL_NONE 0
1776 #define OPLOCKLEVEL_II 1
1777
1778 /*
1779  * Bits we test with.
1780  */
1781 #define EXCLUSIVE_OPLOCK 1
1782 #define BATCH_OPLOCK 2
1783
1784 #define CORE_OPLOCK_GRANTED (1<<5)
1785 #define EXTENDED_OPLOCK_GRANTED (1<<15)
1786
1787 /*
1788  * Loopback command offsets.
1789  */
1790
1791 #define OPBRK_CMD_LEN_OFFSET 0
1792 #define OPBRK_CMD_PORT_OFFSET 4
1793 #define OPBRK_CMD_HEADER_LEN 6
1794
1795 #define OPBRK_MESSAGE_CMD_OFFSET 0
1796
1797 /*
1798  * Oplock break command code to send over the udp socket.
1799  * 
1800  * Form of this is :
1801  *
1802  *  0     2       6        10       14    14+devsize 14+devsize+inodesize
1803  *  +----+--------+--------+--------+-------+--------+
1804  *  | cmd| pid    | sec    | usec   | dev   |  inode |
1805  *  +----+--------+--------+--------+-------+--------+
1806  */
1807
1808 #define OPLOCK_BREAK_CMD 0x1
1809 #define OPLOCK_BREAK_PID_OFFSET 2
1810 #define OPLOCK_BREAK_SEC_OFFSET 6
1811 #define OPLOCK_BREAK_USEC_OFFSET 10
1812 #define OPLOCK_BREAK_DEV_OFFSET 14
1813 #define OPLOCK_BREAK_INODE_OFFSET (OPLOCK_BREAK_DEV_OFFSET + sizeof(SMB_DEV_T))
1814 #define OPLOCK_BREAK_MSG_LEN (OPLOCK_BREAK_INODE_OFFSET + sizeof(SMB_INO_T))
1815
1816 /*
1817  * Capabilities abstracted for different systems.
1818  */
1819
1820 #define KERNEL_OPLOCK_CAPABILITY 0x1
1821
1822 #if defined(HAVE_KERNEL_OPLOCKS)
1823 /*
1824  * Oplock break command code sent via the kernel interface.
1825  *
1826  * Form of this is :
1827  *
1828  *  0     2       2+devsize 2+devsize+inodesize
1829  *  +----+--------+--------+
1830  *  | cmd| dev    |  inode |
1831  *  +----+--------+--------+
1832  */
1833
1834 #define KERNEL_OPLOCK_BREAK_CMD 0x2
1835 #define KERNEL_OPLOCK_BREAK_DEV_OFFSET 2
1836 #define KERNEL_OPLOCK_BREAK_INODE_OFFSET (KERNEL_OPLOCK_BREAK_DEV_OFFSET + sizeof(SMB_DEV_T))
1837 #define KERNEL_OPLOCK_BREAK_MSG_LEN (KERNEL_OPLOCK_BREAK_INODE_OFFSET + sizeof(SMB_INO_T))
1838
1839 #endif /* HAVE_KERNEL_OPLOCKS */
1840
1841 #define CMD_REPLY 0x8000
1842
1843 /* useful macros */
1844
1845 /* zero a structure */
1846 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
1847
1848 /* zero a structure given a pointer to the structure */
1849 #define ZERO_STRUCTP(x) { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); }
1850
1851 /* zero an array - note that sizeof(array) must work - ie. it must not be a 
1852    pointer */
1853 #define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x))
1854
1855 #define SMB_ASSERT(b) ((b)?(void)0: \
1856         (DEBUG(0,("PANIC: assert failed at %s(%d)\n", \
1857                  __FILE__, __LINE__)), smb_panic("assert failed")))
1858 #define SMB_ASSERT_ARRAY(a,n) SMB_ASSERT((sizeof(a)/sizeof((a)[0])) >= (n))
1859
1860 #include "ntdomain.h"
1861
1862 /* A netbios name structure. */
1863 struct nmb_name {
1864   char         name[17];
1865   char         scope[64];
1866   unsigned int name_type;
1867 };
1868
1869 #include "client.h"
1870 #include "rpcclient.h"
1871
1872 /*
1873  * Size of new password account encoding string. DO NOT CHANGE.
1874  */
1875
1876 #define NEW_PW_FORMAT_SPACE_PADDED_LEN 14
1877
1878 /*
1879    Do you want session setups at user level security with a invalid
1880    password to be rejected or allowed in as guest? WinNT rejects them
1881    but it can be a pain as it means "net view" needs to use a password
1882
1883    You have 3 choices in the setting of map_to_guest:
1884
1885    "NEVER_MAP_TO_GUEST" means session setups with an invalid password
1886    are rejected. This is the default.
1887
1888    "MAP_TO_GUEST_ON_BAD_USER" means session setups with an invalid password
1889    are rejected, unless the username does not exist, in which case it
1890    is treated as a guest login
1891
1892    "MAP_TO_GUEST_ON_BAD_PASSWORD" means session setups with an invalid password
1893    are treated as a guest login
1894
1895    Note that map_to_guest only has an effect in user or server
1896    level security.
1897 */
1898
1899 #define NEVER_MAP_TO_GUEST 0
1900 #define MAP_TO_GUEST_ON_BAD_USER 1
1901 #define MAP_TO_GUEST_ON_BAD_PASSWORD 2
1902
1903 #endif /* _SMB_H */
1904
1905 /* _SMB_H */