proto.h: Updated.
[kai/samba.git] / source / include / smb.h
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    SMB parameters and setup
5    Copyright (C) Andrew Tridgell 1992-1997
6    Copyright (C) John H Terpstra 1996-1997
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22 #ifndef _SMB_H
23 #define _SMB_H
24
25 #ifndef MAX_CONNECTIONS
26 #define MAX_CONNECTIONS 127
27 #endif
28
29 #ifndef MAX_OPEN_FILES
30 #define MAX_OPEN_FILES 50
31 #endif
32
33 #ifndef GUEST_ACCOUNT
34 #define GUEST_ACCOUNT "nobody"
35 #endif
36
37 #define BUFFER_SIZE (0xFFFF)
38 #define SAFETY_MARGIN 1024
39
40 /* Default size of shared memory used for share mode locking */
41 #ifndef SHMEM_SIZE
42 #define SHMEM_SIZE 102400
43 #endif
44
45 /* Default number of hash buckets used in shared memory share mode */
46 #ifndef SHMEM_HASH_SIZE
47 #define SHMEM_HASH_SIZE 113
48 #endif
49
50 #define NMB_PORT 137
51 #define DGRAM_PORT 138
52 #define SMB_PORT 139
53
54 #define False (0)
55 #define True (1)
56 #define BOOLSTR(b) ((b) ? "Yes" : "No")
57 #define BITSETB(ptr,bit) ((((char *)ptr)[0] & (1<<(bit)))!=0)
58 #define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0)
59 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((char *)(p1)) - (char *)(p2)))
60
61 typedef int BOOL;
62
63 /* offset in shared memory */
64 typedef  int smb_shm_offset_t;
65 #define NULL_OFFSET (smb_shm_offset_t)(0)
66
67
68 /*
69    Samba needs type definitions for int16, int32, uint16 and uint32.
70    
71    Normally these are signed and unsigned 16 and 32 bit integers, but
72    they actually only need to be at least 16 and 32 bits
73    respectively. Thus if your word size is 8 bytes just defining them
74    as signed and unsigned int will work.
75 */
76
77 /* afs/stds.h defines int16 and int32 */
78 #ifndef AFS_AUTH
79 typedef short int16;
80 typedef int int32;
81 #endif
82
83 #ifndef uint16
84 typedef unsigned short uint16;
85 #endif
86
87 #ifndef uint32
88 typedef unsigned int uint32;
89 #endif
90
91 #ifndef uchar
92 #define uchar unsigned char
93 #endif
94 #ifndef int16
95 #define int16 short
96 #endif
97 #ifndef uint16
98 #define uint16 unsigned short
99 #endif
100 #ifndef uint32
101 #define uint32 unsigned int
102 #endif
103
104 #define SIZEOFWORD 2
105
106 #ifndef DEF_CREATE_MASK
107 #define DEF_CREATE_MASK (0755)
108 #endif
109
110 /* how long to wait for secondary SMB packets (milli-seconds) */
111 #define SMB_SECONDARY_WAIT (60*1000)
112
113 /* debugging code */
114 #ifndef SYSLOG
115 #define DEBUG(level,body) ((DEBUGLEVEL>=(level))?(Debug1 body):0)
116 #else
117 extern int syslog_level;
118
119 #define DEBUG(level,body) ((DEBUGLEVEL>=(level))? (syslog_level = (level), Debug1 body):0)
120 #endif
121
122 /* this defines the error codes that receive_smb can put in smb_read_error */
123 #define READ_TIMEOUT 1
124 #define READ_EOF 2
125 #define READ_ERROR 3
126
127
128 #define DIR_STRUCT_SIZE 43
129
130 /* these define all the command types recognised by the server - there
131 are lots of gaps so probably there are some rare commands that are not
132 implemented */
133
134 #define pSETDIR '\377'
135
136 /* these define the attribute byte as seen by DOS */
137 #define aRONLY (1L<<0)
138 #define aHIDDEN (1L<<1)
139 #define aSYSTEM (1L<<2)
140 #define aVOLID (1L<<3)
141 #define aDIR (1L<<4)
142 #define aARCH (1L<<5)
143
144 /* deny modes */
145 #define DENY_DOS 0
146 #define DENY_ALL 1
147 #define DENY_WRITE 2
148 #define DENY_READ 3
149 #define DENY_NONE 4
150 #define DENY_FCB 7
151
152 /* share types */
153 #define STYPE_DISKTREE  0       /* Disk drive */
154 #define STYPE_PRINTQ    1       /* Spooler queue */
155 #define STYPE_DEVICE    2       /* Serial device */
156 #define STYPE_IPC       3       /* Interprocess communication (IPC) */
157
158 /* SMB X/Open error codes for the ERRdos error class */
159 #define ERRbadfunc 1 /* Invalid function (or system call) */
160 #define ERRbadfile 2 /* File not found (pathname error) */
161 #define ERRbadpath 3 /* Directory not found */
162 #define ERRnofids 4 /* Too many open files */
163 #define ERRnoaccess 5 /* Access denied */
164 #define ERRbadfid 6 /* Invalid fid */
165 #define ERRnomem 8 /* Out of memory */
166 #define ERRbadmem 9 /* Invalid memory block address */
167 #define ERRbadenv 10 /* Invalid environment */
168 #define ERRbadaccess 12 /* Invalid open mode */
169 #define ERRbaddata 13 /* Invalid data (only from ioctl call) */
170 #define ERRres 14 /* reserved */
171 #define ERRbaddrive 15 /* Invalid drive */
172 #define ERRremcd 16 /* Attempt to delete current directory */
173 #define ERRdiffdevice 17 /* rename/move across different filesystems */
174 #define ERRnofiles 18 /* no more files found in file search */
175 #define ERRbadshare 32 /* Share mode on file conflict with open mode */
176 #define ERRlock 33 /* Lock request conflicts with existing lock */
177 #define ERRfilexists 80 /* File in operation already exists */
178 #define ERRcannotopen 110 /* Cannot open the file specified */
179 #define ERRunknownlevel 124
180 #define ERRbadpipe 230 /* Named pipe invalid */
181 #define ERRpipebusy 231 /* All instances of pipe are busy */
182 #define ERRpipeclosing 232 /* named pipe close in progress */
183 #define ERRnotconnected 233 /* No process on other end of named pipe */
184 #define ERRmoredata 234 /* More data to be returned */
185 #define ERRbaddirectory 267 /* Invalid directory name in a path. */
186 #define ERROR_EAS_DIDNT_FIT 275 /* Extended attributes didn't fit */
187 #define ERROR_EAS_NOT_SUPPORTED 282 /* Extended attributes not supported */
188 #define ERRunknownipc 2142
189
190
191 /* here's a special one from observing NT */
192 #define ERRnoipc 66 /* don't support ipc */
193
194 /* Error codes for the ERRSRV class */
195
196 #define ERRerror 1 /* Non specific error code */
197 #define ERRbadpw 2 /* Bad password */
198 #define ERRbadtype 3 /* reserved */
199 #define ERRaccess 4 /* No permissions to do the requested operation */
200 #define ERRinvnid 5 /* tid invalid */
201 #define ERRinvnetname 6 /* Invalid servername */
202 #define ERRinvdevice 7 /* Invalid device */
203 #define ERRqfull 49 /* Print queue full */
204 #define ERRqtoobig 50 /* Queued item too big */
205 #define ERRinvpfid 52 /* Invalid print file in smb_fid */
206 #define ERRsmbcmd 64 /* Unrecognised command */
207 #define ERRsrverror 65 /* smb server internal error */
208 #define ERRfilespecs 67 /* fid and pathname invalid combination */
209 #define ERRbadlink 68 /* reserved */
210 #define ERRbadpermits 69 /* Access specified for a file is not valid */
211 #define ERRbadpid 70 /* reserved */
212 #define ERRsetattrmode 71 /* attribute mode invalid */
213 #define ERRpaused 81 /* Message server paused */
214 #define ERRmsgoff 82 /* Not receiving messages */
215 #define ERRnoroom 83 /* No room for message */
216 #define ERRrmuns 87 /* too many remote usernames */
217 #define ERRtimeout 88 /* operation timed out */
218 #define ERRnoresource  89 /* No resources currently available for request. */
219 #define ERRtoomanyuids 90 /* too many userids */
220 #define ERRbaduid 91 /* bad userid */
221 #define ERRuseMPX 250 /* temporarily unable to use raw mode, use MPX mode */
222 #define ERRuseSTD 251 /* temporarily unable to use raw mode, use standard mode */
223 #define ERRcontMPX 252 /* resume MPX mode */
224 #define ERRbadPW /* reserved */
225 #define ERRnosupport 0xFFFF
226 #define ERRunknownsmb 22 /* from NT 3.5 response */
227
228
229 /* Error codes for the ERRHRD class */
230
231 #define ERRnowrite 19 /* read only media */
232 #define ERRbadunit 20 /* Unknown device */
233 #define ERRnotready 21 /* Drive not ready */
234 #define ERRbadcmd 22 /* Unknown command */
235 #define ERRdata 23 /* Data (CRC) error */
236 #define ERRbadreq 24 /* Bad request structure length */
237 #define ERRseek 25
238 #define ERRbadmedia 26
239 #define ERRbadsector 27
240 #define ERRnopaper 28
241 #define ERRwrite 29 /* write fault */
242 #define ERRread 30 /* read fault */
243 #define ERRgeneral 31 /* General hardware failure */
244 #define ERRwrongdisk 34
245 #define ERRFCBunavail 35
246 #define ERRsharebufexc 36 /* share buffer exceeded */
247 #define ERRdiskfull 39
248
249
250 typedef char pstring[1024];
251 typedef char fstring[128];
252 typedef fstring string;
253
254
255 struct smb_passwd {
256         int smb_userid;
257         char *smb_name;
258         unsigned char *smb_passwd; /* Null if no password */
259         unsigned char *smb_nt_passwd; /* Null if no password */
260         /* Other fields / flags may be added later */
261 };
262
263
264 struct current_user {
265   int cnum, id;
266   int uid, gid;
267   int ngroups;
268   gid_t *groups;
269   int *igroups;
270 };
271
272 typedef struct
273 {
274   int size;
275   int mode;
276   int uid;
277   int gid;
278   /* these times are normally kept in GMT */
279   time_t mtime;
280   time_t atime;
281   time_t ctime;
282   pstring name;
283 } file_info;
284
285
286 /* Structure used when SMBwritebmpx is active */
287 typedef struct
288         {
289         int   wr_total_written; /* So we know when to discard this */
290         int32 wr_timeout;
291         int32 wr_errclass;
292         int32 wr_error; /* Cached errors */
293         BOOL  wr_mode; /* write through mode) */
294         BOOL  wr_discard; /* discard all further data */
295         } write_bmpx_struct;
296
297 /*
298  * Structure used to indirect fd's from the files_struct.
299  * Needed as POSIX locking is based on file and process, not
300  * file descriptor and process.
301  */
302
303 typedef struct
304 {
305   uint16 ref_count;
306   uint32 dev;
307   uint32 inode;
308   int fd;
309   int fd_readonly;
310   int fd_writeonly;
311   int real_open_flags;
312 } file_fd_struct;
313
314 typedef struct
315 {
316   int cnum;
317   file_fd_struct *fd_ptr;
318   int pos;
319   uint32 size;
320   int mode;
321   int uid;
322   char *mmap_ptr;
323   uint32 mmap_size;
324   write_bmpx_struct *wbmpx_ptr;
325   struct timeval open_time;
326   BOOL open;
327   BOOL can_lock;
328   BOOL can_read;
329   BOOL can_write;
330   BOOL share_mode;
331   BOOL print_file;
332   BOOL modified;
333   BOOL granted_oplock;
334   char *name;
335 } files_struct;
336
337
338 struct uid_cache {
339   int entries;
340   int list[UID_CACHE_SIZE];
341 };
342
343 typedef struct
344 {
345   char *name;
346   BOOL is_wild;
347 } name_compare_entry;
348
349 typedef struct
350 {
351   int service;
352   BOOL force_user;
353   struct uid_cache uid_cache;
354   void *dirptr;
355   BOOL open;
356   BOOL printer;
357   BOOL ipc;
358   BOOL read_only;
359   BOOL admin_user;
360   char *dirpath;
361   char *connectpath;
362   char *origpath;
363   char *user; /* name of user who *opened* this connection */
364   int uid; /* uid of user who *opened* this connection */
365   int gid; /* gid of user who *opened* this connection */
366   uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
367   /* following groups stuff added by ih */
368   /* This groups info is valid for the user that *opened* the connection */
369   int ngroups;
370   gid_t *groups;
371   int *igroups; /* an integer version - some OSes are broken :-( */
372   time_t lastused;
373   BOOL used;
374   int num_files_open;
375   name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */
376   name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */
377 } connection_struct;
378
379
380 typedef struct
381 {
382   int uid; /* uid of a validated user */
383   int gid; /* gid of a validated user */
384   fstring name; /* name of a validated user */
385   BOOL guest;
386   /* following groups stuff added by ih */
387   /* This groups info is needed for when we become_user() for this uid */
388   int user_ngroups;
389   gid_t *user_groups;
390   int *user_igroups; /* an integer version - some OSes are broken :-( */
391 #if (defined(NETGROUP) && defined(AUTOMOUNT))
392   char *home_share;  /* to store NIS home of a user - simeon */
393 #endif
394   char *real_name;   /* to store real name from password file - simeon */
395 } user_struct;
396
397
398 enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING};
399
400 typedef struct
401 {
402   int job;
403   int size;
404   int status;
405   int priority;
406   time_t time;
407   char user[30];
408   char file[100];
409 } print_queue_struct;
410
411 enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
412
413 typedef struct
414 {
415   fstring message;
416   int status;
417 }  print_status_struct;
418
419 /* used for server information: client, nameserv and ipc */
420 struct server_info_struct
421 {
422   fstring name;
423   uint32 type;
424   fstring comment;
425   fstring domain; /* used ONLY in ipc.c NOT namework.c */
426   BOOL server_added; /* used ONLY in ipc.c NOT namework.c */
427 };
428
429
430 /* used for network interfaces */
431 struct interface
432 {
433         struct interface *next;
434         struct in_addr ip;
435         struct in_addr bcast;
436         struct in_addr nmask;
437 };
438
439 /* share mode record pointed to in shared memory hash bucket */
440 typedef struct
441 {
442   smb_shm_offset_t next_offset; /* offset of next record in chain from hash bucket */
443   int locking_version;
444   int32 st_dev;
445   int32 st_ino;
446   int num_share_mode_entries;
447   smb_shm_offset_t share_mode_entries; /* Chain of share mode entries for this file */
448   char file_name[1];
449 } share_mode_record;
450
451 /* share mode entry pointed to by share_mode_record struct */
452 typedef struct
453 {
454   smb_shm_offset_t next_share_mode_entry;
455   int pid;
456 #ifdef USE_OPLOCKS
457   uint16 op_port;
458   uint16 op_type;
459 #endif /* USE_OPLOCKS */
460   int share_mode;
461   struct timeval time;
462 } share_mode_entry;
463
464 /* struct returned by get_share_modes */
465 typedef struct
466 {
467   int pid;
468 #ifdef USE_OPLOCKS
469   uint16 op_port;
470   uint16 op_type;
471 #endif /* USE_OPLOCKS */
472   int share_mode;
473   struct timeval time;
474 } min_share_mode_entry;
475
476 /* Token returned by lock_share_entry (actually ignored by FAST_SHARE_MODES code) */
477 typedef int share_lock_token;
478
479 /* Conversion to hash entry index from device and inode numbers. */
480 #define HASH_ENTRY(dev,ino) ((( (uint32)(dev) )* ( (uint32)(ino) )) % lp_shmem_hash_size())
481
482 /* this is used for smbstatus */
483 struct connect_record
484 {
485   int magic;
486   int pid;
487   int cnum;
488   int uid;
489   int gid;
490   char name[24];
491   char addr[24];
492   char machine[128];
493   time_t start;
494 };
495
496 #ifndef LOCKING_VERSION
497 #ifdef USE_OPLOCKS
498 #define LOCKING_VERSION 4
499 #else /* USE_OPLOCKS */
500 #define LOCKING_VERSION 3
501 #endif /* USE_OPLOCKS */
502 #endif /* LOCKING_VERSION */
503
504 #if !defined(FAST_SHARE_MODES)
505 /* 
506  * Defines for slow share modes.
507  */
508
509 /* 
510  * Locking file header lengths & offsets. 
511  */
512 #define SMF_VERSION_OFFSET 0
513 #define SMF_NUM_ENTRIES_OFFSET 4
514 #define SMF_FILENAME_LEN_OFFSET 8
515 #define SMF_HEADER_LENGTH 10
516
517 #ifdef USE_OPLOCKS
518 #define SMF_ENTRY_LENGTH 20
519 #else /* USE_OPLOCKS */
520 #define SMF_ENTRY_LENGTH 16
521 #endif /* USE_OPLOCKS */
522
523 /*
524  * Share mode record offsets.
525  */
526
527 #define SME_SEC_OFFSET 0
528 #define SME_USEC_OFFSET 4
529 #define SME_SHAREMODE_OFFSET 8
530 #define SME_PID_OFFSET 12
531
532 #ifdef USE_OPLOCKS
533 #define SME_PORT_OFFSET 16
534 #define SME_OPLOCK_TYPE_OFFSET 18
535 #endif /* USE_OPLOCKS */
536
537 #endif /* FAST_SHARE_MODES */
538
539 /* these are useful macros for checking validity of handles */
540 #define VALID_FNUM(fnum)   (((fnum) >= 0) && ((fnum) < MAX_OPEN_FILES))
541 #define OPEN_FNUM(fnum)    (VALID_FNUM(fnum) && Files[fnum].open)
542 #define VALID_CNUM(cnum)   (((cnum) >= 0) && ((cnum) < MAX_CONNECTIONS))
543 #define OPEN_CNUM(cnum)    (VALID_CNUM(cnum) && Connections[cnum].open)
544 #define IS_IPC(cnum)       (VALID_CNUM(cnum) && Connections[cnum].ipc)
545 #define IS_PRINT(cnum)       (VALID_CNUM(cnum) && Connections[cnum].printer)
546 #define FNUM_OK(fnum,c) (OPEN_FNUM(fnum) && (c)==Files[fnum].cnum)
547
548 #define CHECK_FNUM(fnum,c) if (!FNUM_OK(fnum,c)) \
549                                return(ERROR(ERRDOS,ERRbadfid))
550 #define CHECK_READ(fnum) if (!Files[fnum].can_read) \
551                                return(ERROR(ERRDOS,ERRbadaccess))
552 #define CHECK_WRITE(fnum) if (!Files[fnum].can_write) \
553                                return(ERROR(ERRDOS,ERRbadaccess))
554 #define CHECK_ERROR(fnum) if (HAS_CACHED_ERROR(fnum)) \
555                                return(CACHED_ERROR(fnum))
556
557 /* translates a connection number into a service number */
558 #define SNUM(cnum)         (Connections[cnum].service)
559
560 /* access various service details */
561 #define SERVICE(snum)      (lp_servicename(snum))
562 #define PRINTCAP           (lp_printcapname())
563 #define PRINTCOMMAND(snum) (lp_printcommand(snum))
564 #define PRINTERNAME(snum)  (lp_printername(snum))
565 #define CAN_WRITE(cnum)    (OPEN_CNUM(cnum) && !Connections[cnum].read_only)
566 #define VALID_SNUM(snum)   (lp_snum_ok(snum))
567 #define GUEST_OK(snum)     (VALID_SNUM(snum) && lp_guest_ok(snum))
568 #define GUEST_ONLY(snum)   (VALID_SNUM(snum) && lp_guest_only(snum))
569 #define CAN_SETDIR(snum)   (!lp_no_set_dir(snum))
570 #define CAN_PRINT(cnum)    (OPEN_CNUM(cnum) && lp_print_ok(SNUM(cnum)))
571 #define POSTSCRIPT(cnum)   (OPEN_CNUM(cnum) && lp_postscript(SNUM(cnum)))
572 #define MAP_HIDDEN(cnum)   (OPEN_CNUM(cnum) && lp_map_hidden(SNUM(cnum)))
573 #define MAP_SYSTEM(cnum)   (OPEN_CNUM(cnum) && lp_map_system(SNUM(cnum)))
574 #define MAP_ARCHIVE(cnum)   (OPEN_CNUM(cnum) && lp_map_archive(SNUM(cnum)))
575 #define IS_HIDDEN_PATH(cnum,path)  (is_in_path((path),Connections[(cnum)].hide_list))
576 #define IS_VETO_PATH(cnum,path)  (is_in_path((path),Connections[(cnum)].veto_list))
577
578 #define SMBENCRYPT()       (lp_encrypted_passwords())
579
580 /* the basic packet size, assuming no words or bytes */
581 #define smb_size 39
582
583 /* offsets into message for common items */
584 #define smb_com 8
585 #define smb_rcls 9
586 #define smb_reh 10
587 #define smb_err 11
588 #define smb_flg 13
589 #define smb_flg2 14
590 #define smb_reb 13
591 #define smb_tid 28
592 #define smb_pid 30
593 #define smb_uid 32
594 #define smb_mid 34
595 #define smb_wct 36
596 #define smb_vwv 37
597 #define smb_vwv0 37
598 #define smb_vwv1 39
599 #define smb_vwv2 41
600 #define smb_vwv3 43
601 #define smb_vwv4 45
602 #define smb_vwv5 47
603 #define smb_vwv6 49
604 #define smb_vwv7 51
605 #define smb_vwv8 53
606 #define smb_vwv9 55
607 #define smb_vwv10 57
608 #define smb_vwv11 59
609 #define smb_vwv12 61
610 #define smb_vwv13 63
611 #define smb_vwv14 65
612 #define smb_vwv15 67
613 #define smb_vwv16 69
614 #define smb_vwv17 71
615
616
617 /* the complete */
618 #define SMBmkdir      0x00   /* create directory */
619 #define SMBrmdir      0x01   /* delete directory */
620 #define SMBopen       0x02   /* open file */
621 #define SMBcreate     0x03   /* create file */
622 #define SMBclose      0x04   /* close file */
623 #define SMBflush      0x05   /* flush file */
624 #define SMBunlink     0x06   /* delete file */
625 #define SMBmv         0x07   /* rename file */
626 #define SMBgetatr     0x08   /* get file attributes */
627 #define SMBsetatr     0x09   /* set file attributes */
628 #define SMBread       0x0A   /* read from file */
629 #define SMBwrite      0x0B   /* write to file */
630 #define SMBlock       0x0C   /* lock byte range */
631 #define SMBunlock     0x0D   /* unlock byte range */
632 #define SMBctemp      0x0E   /* create temporary file */
633 #define SMBmknew      0x0F   /* make new file */
634 #define SMBchkpth     0x10   /* check directory path */
635 #define SMBexit       0x11   /* process exit */
636 #define SMBlseek      0x12   /* seek */
637 #define SMBtcon       0x70   /* tree connect */
638 #define SMBtconX      0x75   /* tree connect and X*/
639 #define SMBtdis       0x71   /* tree disconnect */
640 #define SMBnegprot    0x72   /* negotiate protocol */
641 #define SMBdskattr    0x80   /* get disk attributes */
642 #define SMBsearch     0x81   /* search directory */
643 #define SMBsplopen    0xC0   /* open print spool file */
644 #define SMBsplwr      0xC1   /* write to print spool file */
645 #define SMBsplclose   0xC2   /* close print spool file */
646 #define SMBsplretq    0xC3   /* return print queue */
647 #define SMBsends      0xD0   /* send single block message */
648 #define SMBsendb      0xD1   /* send broadcast message */
649 #define SMBfwdname    0xD2   /* forward user name */
650 #define SMBcancelf    0xD3   /* cancel forward */
651 #define SMBgetmac     0xD4   /* get machine name */
652 #define SMBsendstrt   0xD5   /* send start of multi-block message */
653 #define SMBsendend    0xD6   /* send end of multi-block message */
654 #define SMBsendtxt    0xD7   /* send text of multi-block message */
655
656 /* Core+ protocol */
657 #define SMBlockread       0x13   /* Lock a range and read */
658 #define SMBwriteunlock 0x14 /* Unlock a range then write */
659 #define SMBreadbraw   0x1a  /* read a block of data with no smb header */
660 #define SMBwritebraw  0x1d  /* write a block of data with no smb header */
661 #define SMBwritec     0x20  /* secondary write request */
662 #define SMBwriteclose 0x2c  /* write a file then close it */
663
664 /* dos extended protocol */
665 #define SMBreadBraw      0x1A   /* read block raw */
666 #define SMBreadBmpx      0x1B   /* read block multiplexed */
667 #define SMBreadBs        0x1C   /* read block (secondary response) */
668 #define SMBwriteBraw     0x1D   /* write block raw */
669 #define SMBwriteBmpx     0x1E   /* write block multiplexed */
670 #define SMBwriteBs       0x1F   /* write block (secondary request) */
671 #define SMBwriteC        0x20   /* write complete response */
672 #define SMBsetattrE      0x22   /* set file attributes expanded */
673 #define SMBgetattrE      0x23   /* get file attributes expanded */
674 #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
675 #define SMBtrans         0x25   /* transaction - name, bytes in/out */
676 #define SMBtranss        0x26   /* transaction (secondary request/response) */
677 #define SMBioctl         0x27   /* IOCTL */
678 #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
679 #define SMBcopy          0x29   /* copy */
680 #define SMBmove          0x2A   /* move */
681 #define SMBecho          0x2B   /* echo */
682 #define SMBopenX         0x2D   /* open and X */
683 #define SMBreadX         0x2E   /* read and X */
684 #define SMBwriteX        0x2F   /* write and X */
685 #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
686 #define SMBffirst        0x82   /* find first */
687 #define SMBfunique       0x83   /* find unique */
688 #define SMBfclose        0x84   /* find close */
689 #define SMBinvalid       0xFE   /* invalid command */
690
691 /* Extended 2.0 protocol */
692 #define SMBtrans2        0x32   /* TRANS2 protocol set */
693 #define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
694 #define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
695 #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
696 #define SMBulogoffX      0x74   /* user logoff */
697
698
699 /* these are the TRANS2 sub commands */
700 #define TRANSACT2_OPEN          0
701 #define TRANSACT2_FINDFIRST     1
702 #define TRANSACT2_FINDNEXT      2
703 #define TRANSACT2_QFSINFO       3
704 #define TRANSACT2_SETFSINFO     4
705 #define TRANSACT2_QPATHINFO     5
706 #define TRANSACT2_SETPATHINFO   6
707 #define TRANSACT2_QFILEINFO     7
708 #define TRANSACT2_SETFILEINFO   8
709 #define TRANSACT2_FSCTL         9
710 #define TRANSACT2_IOCTL           10
711 #define TRANSACT2_FINDNOTIFYFIRST 11
712 #define TRANSACT2_FINDNOTIFYNEXT  12
713 #define TRANSACT2_MKDIR           13
714
715
716 /* these are the trans2 sub fields for primary requests */
717 #define smb_tpscnt smb_vwv0
718 #define smb_tdscnt smb_vwv1
719 #define smb_mprcnt smb_vwv2
720 #define smb_mdrcnt smb_vwv3
721 #define smb_msrcnt smb_vwv4
722 #define smb_flags smb_vwv5
723 #define smb_timeout smb_vwv6
724 #define smb_pscnt smb_vwv9
725 #define smb_psoff smb_vwv10
726 #define smb_dscnt smb_vwv11
727 #define smb_dsoff smb_vwv12
728 #define smb_suwcnt smb_vwv13
729 #define smb_setup smb_vwv14
730 #define smb_setup0 smb_setup
731 #define smb_setup1 (smb_setup+2)
732 #define smb_setup2 (smb_setup+4)
733
734 /* these are for the secondary requests */
735 #define smb_spscnt smb_vwv2
736 #define smb_spsoff smb_vwv3
737 #define smb_spsdisp smb_vwv4
738 #define smb_sdscnt smb_vwv5
739 #define smb_sdsoff smb_vwv6
740 #define smb_sdsdisp smb_vwv7
741 #define smb_sfid smb_vwv8
742
743 /* and these for responses */
744 #define smb_tprcnt smb_vwv0
745 #define smb_tdrcnt smb_vwv1
746 #define smb_prcnt smb_vwv3
747 #define smb_proff smb_vwv4
748 #define smb_prdisp smb_vwv5
749 #define smb_drcnt smb_vwv6
750 #define smb_droff smb_vwv7
751 #define smb_drdisp smb_vwv8
752
753 /* where to find the base of the SMB packet proper */
754 #define smb_base(buf) (((char *)(buf))+4)
755
756
757 #define SUCCESS 0  /* The request was successful. */
758 #define ERRDOS 0x01 /*  Error is from the core DOS operating system set. */
759 #define ERRSRV 0x02  /* Error is generated by the server network file manager.*/
760 #define ERRHRD 0x03  /* Error is an hardware error. */
761 #define ERRCMD 0xFF  /* Command was not in the "SMB" format. */
762
763 #ifdef __STDC__
764 int Debug1(char *, ...);
765 #else
766 int Debug1();
767 #endif
768
769 #ifdef DFS_AUTH
770 void dfs_unlogin(void);
771 extern int dcelogin_atmost_once;
772 #endif
773
774 #if AJT
775 void ajt_panic(void);
776 #endif
777
778 #ifdef NOSTRDUP
779 char *strdup(char *s);
780 #endif
781
782 #ifdef REPLACE_STRLEN
783 int Strlen(char *);
784 #endif
785
786 #ifdef REPLACE_STRSTR
787 char *Strstr(char *s, char *p);
788 #endif
789
790 #ifndef MIN
791 #define MIN(a,b) ((a)<(b)?(a):(b))
792 #endif
793 #ifndef MAX
794 #define MAX(a,b) ((a)>(b)?(a):(b))
795 #endif
796
797 #ifndef ABS
798 #define ABS(a) ((a)>0?(a):(-(a)))
799 #endif
800
801 #ifndef SIGNAL_CAST
802 #define SIGNAL_CAST
803 #endif
804
805 #ifndef SELECT_CAST
806 #define SELECT_CAST
807 #endif
808
809
810 /* Some POSIX definitions for those without */
811  
812 #ifndef S_IFDIR
813 #define S_IFDIR         0x4000
814 #endif
815 #ifndef S_ISDIR
816 #define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
817 #endif
818 #ifndef S_IRWXU
819 #define S_IRWXU 00700           /* read, write, execute: owner */
820 #endif
821 #ifndef S_IRUSR
822 #define S_IRUSR 00400           /* read permission: owner */
823 #endif
824 #ifndef S_IWUSR
825 #define S_IWUSR 00200           /* write permission: owner */
826 #endif
827 #ifndef S_IXUSR
828 #define S_IXUSR 00100           /* execute permission: owner */
829 #endif
830 #ifndef S_IRWXG
831 #define S_IRWXG 00070           /* read, write, execute: group */
832 #endif
833 #ifndef S_IRGRP
834 #define S_IRGRP 00040           /* read permission: group */
835 #endif
836 #ifndef S_IWGRP
837 #define S_IWGRP 00020           /* write permission: group */
838 #endif
839 #ifndef S_IXGRP
840 #define S_IXGRP 00010           /* execute permission: group */
841 #endif
842 #ifndef S_IRWXO
843 #define S_IRWXO 00007           /* read, write, execute: other */
844 #endif
845 #ifndef S_IROTH
846 #define S_IROTH 00004           /* read permission: other */
847 #endif
848 #ifndef S_IWOTH
849 #define S_IWOTH 00002           /* write permission: other */
850 #endif
851 #ifndef S_IXOTH
852 #define S_IXOTH 00001           /* execute permission: other */
853 #endif
854
855
856 /* these are used in NetServerEnum to choose what to receive */
857 #define SV_TYPE_WORKSTATION         0x00000001
858 #define SV_TYPE_SERVER              0x00000002
859 #define SV_TYPE_SQLSERVER           0x00000004
860 #define SV_TYPE_DOMAIN_CTRL         0x00000008
861 #define SV_TYPE_DOMAIN_BAKCTRL      0x00000010
862 #define SV_TYPE_TIME_SOURCE         0x00000020
863 #define SV_TYPE_AFP                 0x00000040
864 #define SV_TYPE_NOVELL              0x00000080
865 #define SV_TYPE_DOMAIN_MEMBER       0x00000100
866 #define SV_TYPE_PRINTQ_SERVER       0x00000200
867 #define SV_TYPE_DIALIN_SERVER       0x00000400
868 #define SV_TYPE_SERVER_UNIX         0x00000800
869 #define SV_TYPE_NT                  0x00001000
870 #define SV_TYPE_WFW                 0x00002000
871 #define SV_TYPE_SERVER_MFPN         0x00004000
872 #define SV_TYPE_SERVER_NT           0x00008000
873 #define SV_TYPE_POTENTIAL_BROWSER   0x00010000
874 #define SV_TYPE_BACKUP_BROWSER      0x00020000
875 #define SV_TYPE_MASTER_BROWSER      0x00040000
876 #define SV_TYPE_DOMAIN_MASTER       0x00080000
877 #define SV_TYPE_SERVER_OSF          0x00100000
878 #define SV_TYPE_SERVER_VMS          0x00200000
879 #define SV_TYPE_WIN95_PLUS          0x00400000
880 #define SV_TYPE_ALTERNATE_XPORT     0x20000000  
881 #define SV_TYPE_LOCAL_LIST_ONLY     0x40000000  
882 #define SV_TYPE_DOMAIN_ENUM         0x80000000
883 #define SV_TYPE_ALL                 0xFFFFFFFF  
884
885 /* what server type are we currently  - JHT Says we ARE 4.20 */
886 /* this was set by JHT in liaison with Jeremy Allison early 1997 */
887 /* setting to 4.20 at same time as announcing ourselves as NT Server */
888 /* History: */
889 /* Version 4.0 - never made public */
890 /* Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9 */
891 /*              - Reappeared in 1.9.16p11 with fixed smbd services */
892 /* Version 4.20 - To indicate that nmbd and browsing now works better */
893
894 #define DEFAULT_MAJOR_VERSION 0x04
895 #define DEFAULT_MINOR_VERSION 0x02
896
897 /* Browser Election Values */
898 #define BROWSER_ELECTION_VERSION        0x010f
899 #define BROWSER_CONSTANT        0xaa55
900
901
902 /* Capabilities.  see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
903
904 #define CAP_RAW_MODE         0x0001
905 #define CAP_MPX_MODE         0x0002
906 #define CAP_UNICODE          0x0004
907 #define CAP_LARGE_FILES      0x0008
908 #define CAP_NT_SMBS          0x0010
909 #define CAP_RPC_REMOTE_APIS  0x0020
910 #define CAP_STATUS32         0x0040
911 #define CAP_LEVEL_II_OPLOCKS 0x0080
912 #define CAP_LOCK_AND_READ    0x0100
913 #define CAP_NT_FIND          0x0200
914 #define CAP_DFS              0x1000
915 #define CAP_LARGE_READX      0x4000
916
917 /* protocol types. It assumes that higher protocols include lower protocols
918    as subsets */
919 enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
920
921 /* security levels */
922 enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER};
923
924 /* printing types */
925 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
926                      PRINT_QNX,PRINT_PLP,PRINT_LPRNG};
927
928 /* Remote architectures we know about. */
929 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_SAMBA};
930
931 /* case handling */
932 enum case_handling {CASE_LOWER,CASE_UPPER};
933
934
935 /* Macros to get at offsets within smb_lkrng and smb_unlkrng
936    structures. We cannot define these as actual structures
937    due to possible differences in structure packing
938    on different machines/compilers. */
939
940 #define SMB_LPID_OFFSET(indx) (10 * (indx))
941 #define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
942 #define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
943
944 /* Macro to cache an error in a write_bmpx_struct */
945 #define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
946                             w->wr_discard = True, -1)
947 /* Macro to test if an error has been cached for this fnum */
948 #define HAS_CACHED_ERROR(fnum) (Files[(fnum)].open && \
949                                 Files[(fnum)].wbmpx_ptr && \
950                                 Files[(fnum)].wbmpx_ptr->wr_discard)
951 /* Macro to turn the cached error into an error packet */
952 #define CACHED_ERROR(fnum) cached_error_packet(inbuf,outbuf,fnum,__LINE__)
953
954 /* these are the datagram types */
955 #define DGRAM_DIRECT_UNIQUE 0x10
956
957 #define ERROR(class,x) error_packet(inbuf,outbuf,class,x,__LINE__)
958
959 /* this is how errors are generated */
960 #define UNIXERROR(defclass,deferror) unix_error_packet(inbuf,outbuf,defclass,deferror,__LINE__)
961
962 #define ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
963
964 /*
965  * Global value meaing that the smb_uid field should be
966  * ingored (in share level security and protocol level == CORE)
967  */
968
969 #define UID_FIELD_INVALID 0
970 #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
971
972 #endif 
973
974 /* Defines needed for multi-codepage support. */
975 #define KANJI_CODEPAGE 932
976
977 #ifdef KANJI
978 /* 
979  * Default client code page - Japanese 
980  */
981 #define DEFAULT_CLIENT_CODE_PAGE KANJI_CODEPAGE
982 #else /* KANJI */
983 /* 
984  * Default client code page - 850 - Western European 
985  */
986 #define DEFAULT_CLIENT_CODE_PAGE 850
987 #endif /* KANJI */
988
989 /* 
990  * Size of buffer to use when moving files across filesystems. 
991  */
992 #define COPYBUF_SIZE (8*1024)
993
994 /* 
995  * Integers used to override error codes. 
996  */
997 extern int unix_ERR_class;
998 extern int unix_ERR_code;
999
1000 /*
1001  * Map the Core and Extended Oplock requesst bits down
1002  * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK).
1003  */
1004
1005 /*
1006  * Core protocol.
1007  */
1008 #define CORE_OPLOCK_REQUEST(inbuf) (((CVAL(inbuf,smb_flg)|(1<<5))>>5) | \
1009                                     ((CVAL(inbuf,smb_flg)|(1<<6))>>5))
1010
1011 /*
1012  * Extended protocol.
1013  */
1014 #define EXTENDED_OPLOCK_REQUEST(inbuf) (((SVAL(inbuf,smb_vwv2)|(1<<1))>>1) | \
1015                                         ((SVAL(inbuf,smb_vwv2)|(1<<2))>>1))
1016
1017 /* Lock types. */
1018 #define LOCKING_ANDX_SHARED_LOCK 0x1
1019 #define LOCKING_ANDX_OPLOCK_RELEASE 0x2
1020 #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x4
1021 #define LOCKING_ANDX_CANCEL_LOCK 0x8
1022 #define LOCKING_ANDX_LARGE_FILES 0x10
1023
1024 /* Oplock levels */
1025 #define OPLOCKLEVEL_NONE 0
1026 #define OPLOCKLEVEL_II 1
1027
1028 /*
1029  * Bits we test with.
1030  */
1031 #define EXCLUSIVE_OPLOCK 1
1032 #define BATCH_OPLOCK 2
1033
1034 #define CORE_OPLOCK_GRANTED (1<<5)
1035 #define EXTENDED_OPLOCK_GRANTED (1<<15)
1036
1037 /*
1038  * Loopback command offsets.
1039  */
1040
1041 #define UDP_CMD_LEN_OFFSET 0
1042 #define UDP_CMD_PORT_OFFSET 4
1043 #define UDP_CMD_HEADER_LEN 6
1044
1045 #define UDP_MESSAGE_CMD_OFFSET 0
1046
1047 /*
1048  * Oplock break command code to send over the udp socket.
1049  * 
1050  * Form of this is :
1051  *
1052  *  0     2       6        10       14      18       22
1053  *  +----+--------+--------+--------+-------+--------+
1054  *  | cmd| pid    | dev    | inode  | sec   |  usec  |
1055  *  +----+--------+--------+--------+-------+--------+
1056  */
1057
1058 #define OPLOCK_BREAK_CMD 0x1
1059 #define OPLOCK_BREAK_PID_OFFSET 2
1060 #define OPLOCK_BREAK_DEV_OFFSET 6
1061 #define OPLOCK_BREAK_INODE_OFFSET 10
1062 #define OPLOCK_BREAK_SEC_OFFSET 14
1063 #define OPLOCK_BREAK_USEC_OFFSET 18
1064 #define OPLOCK_BREAK_MSG_LEN 22
1065
1066
1067 #define CMD_REPLY 0x8000
1068
1069 /* _SMB_H */