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