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