- added FAST_SHARE_MODES code
[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-1995
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21 #ifndef _SMB_H
22 #define _SMB_H
23
24 #ifndef MAX_CONNECTIONS
25 #define MAX_CONNECTIONS 127
26 #endif
27
28 #ifndef MAX_OPEN_FILES
29 #define MAX_OPEN_FILES 50
30 #endif
31
32 #ifndef GUEST_ACCOUNT
33 #define GUEST_ACCOUNT "nobody"
34 #endif
35
36 #define BUFFER_SIZE (0xFFFF)
37 #define SAFETY_MARGIN 1024
38
39 /* size of shared memory used for share mode locking */
40 #ifndef SHMEM_SIZE
41 #define SHMEM_SIZE 102400
42 #endif
43
44 #define NMB_PORT 137
45 #define DGRAM_PORT 138
46 #define SMB_PORT 139
47
48 #define False (0)
49 #define True (1)
50 #define BOOLSTR(b) ((b) ? "Yes" : "No")
51 #define BITSETB(ptr,bit) ((((char *)ptr)[0] & (1<<(bit)))!=0)
52 #define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0)
53 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((char *)(p1)) - (char *)(p2)))
54
55 typedef int BOOL;
56
57 /* offset in shared memory */
58 typedef  int shm_offset_t;
59 #define NULL_OFFSET (shm_offset_t)(0)
60
61
62 /*
63    Samba needs type definitions for int16, int32, uint16 and uint32.
64    
65    Normally these are signed and unsigned 16 and 32 bit integers, but
66    they actually only need to be at least 16 and 32 bits
67    respectively. Thus if your word size is 8 bytes just defining them
68    as signed and unsigned int will work.
69 */
70
71 /* afs/stds.h defines int16 and int32 */
72 #ifndef AFS_AUTH
73 typedef short int16;
74 typedef int int32;
75 #endif
76
77 #ifndef uint16
78 typedef unsigned short uint16;
79 #endif
80
81 #ifndef uint32
82 typedef unsigned int uint32;
83 #endif
84
85 #ifndef uchar
86 #define uchar unsigned char
87 #endif
88 #ifndef int16
89 #define int16 short
90 #endif
91 #ifndef uint16
92 #define uint16 unsigned short
93 #endif
94 #ifndef uint32
95 #define uint32 unsigned int
96 #endif
97
98 #define SIZEOFWORD 2
99
100 #ifndef DEF_CREATE_MASK
101 #define DEF_CREATE_MASK (0755)
102 #endif
103
104 #ifndef DEFAULT_PIPE_TIMEOUT
105 #define DEFAULT_PIPE_TIMEOUT 10000000 /* Ten seconds */
106 #endif
107
108 /* how long to wait for secondary SMB packets (seconds) */
109 #define SMB_SECONDARY_WAIT 30
110
111 /* debugging code */
112 #ifndef SYSLOG
113 #define DEBUG(level,body) ((DEBUGLEVEL>=(level))?(Debug1 body):0)
114 #else
115 extern int syslog_level;
116
117 #define DEBUG(level,body) ((DEBUGLEVEL>=(level))? (syslog_level = (level), Debug1 body):0)
118 #endif
119
120 /* this defines the error codes that receive_smb can put in smb_read_error */
121 #define READ_TIMEOUT 1
122 #define READ_EOF 2
123 #define READ_ERROR 3
124
125
126 #define DIR_STRUCT_SIZE 43
127
128 /* these define all the command types recognised by the server - there
129 are lots of gaps so probably there are some rare commands that are not
130 implemented */
131
132 #define pSETDIR '\377'
133
134 /* these define the attribute byte as seen by DOS */
135 #define aRONLY (1L<<0)
136 #define aHIDDEN (1L<<1)
137 #define aSYSTEM (1L<<2)
138 #define aVOLID (1L<<3)
139 #define aDIR (1L<<4)
140 #define aARCH (1L<<5)
141
142 /* deny modes */
143 #define DENY_DOS 0
144 #define DENY_ALL 1
145 #define DENY_WRITE 2
146 #define DENY_READ 3
147 #define DENY_NONE 4
148 #define DENY_FCB 7
149
150 /* share types */
151 #define STYPE_DISKTREE  0       /* Disk drive */
152 #define STYPE_PRINTQ    1       /* Spooler queue */
153 #define STYPE_DEVICE    2       /* Serial device */
154 #define STYPE_IPC       3       /* Interprocess communication (IPC) */
155
156 /* SMB X/Open error codes for the ERRdos error class */
157 #define ERRbadfunc 1 /* Invalid function (or system call) */
158 #define ERRbadfile 2 /* File not found (pathname error) */
159 #define ERRbadpath 3 /* Directory not found */
160 #define ERRnofids 4 /* Too many open files */
161 #define ERRnoaccess 5 /* Access denied */
162 #define ERRbadfid 6 /* Invalid fid */
163 #define ERRnomem 8 /* Out of memory */
164 #define ERRbadmem 9 /* Invalid memory block address */
165 #define ERRbadenv 10 /* Invalid environment */
166 #define ERRbadaccess 12 /* Invalid open mode */
167 #define ERRbaddata 13 /* Invalid data (only from ioctl call) */
168 #define ERRres 14 /* reserved */
169 #define ERRbaddrive 15 /* Invalid drive */
170 #define ERRremcd 16 /* Attempt to delete current directory */
171 #define ERRdiffdevice 17 /* rename/move across different filesystems */
172 #define ERRnofiles 18 /* no more files found in file search */
173 #define ERRbadshare 32 /* Share mode on file conflict with open mode */
174 #define ERRlock 33 /* Lock request conflicts with existing lock */
175 #define ERRfilexists 80 /* File in operation already exists */
176 #define ERRbadpipe 230 /* Named pipe invalid */
177 #define ERRpipebusy 231 /* All instances of pipe are busy */
178 #define ERRpipeclosing 232 /* named pipe close in progress */
179 #define ERRnotconnected 233 /* No process on other end of named pipe */
180 #define ERRmoredata 234 /* More data to be returned */
181 #define ERROR_EAS_DIDNT_FIT 275 /* Extended attributes didn't fit */
182 #define ERROR_EAS_NOT_SUPPORTED 282 /* Extended attributes not suppored */
183 #define ERRunknownlevel 124
184 #define ERRunknownipc 2142
185
186
187 /* here's a special one from observing NT */
188 #define ERRnoipc 66 /* don't support ipc */
189
190 /* Error codes for the ERRSRV class */
191
192 #define ERRerror 1 /* Non specific error code */
193 #define ERRbadpw 2 /* Bad password */
194 #define ERRbadtype 3 /* reserved */
195 #define ERRaccess 4 /* No permissions to do the requested operation */
196 #define ERRinvnid 5 /* tid invalid */
197 #define ERRinvnetname 6 /* Invalid servername */
198 #define ERRinvdevice 7 /* Invalid device */
199 #define ERRqfull 49 /* Print queue full */
200 #define ERRqtoobig 50 /* Queued item too big */
201 #define ERRinvpfid 52 /* Invalid print file in smb_fid */
202 #define ERRsmbcmd 64 /* Unrecognised command */
203 #define ERRsrverror 65 /* smb server internal error */
204 #define ERRfilespecs 67 /* fid and pathname invalid combination */
205 #define ERRbadlink 68 /* reserved */
206 #define ERRbadpermits 69 /* Access specified for a file is not valid */
207 #define ERRbadpid 70 /* reserved */
208 #define ERRsetattrmode 71 /* attribute mode invalid */
209 #define ERRpaused 81 /* Message server paused */
210 #define ERRmsgoff 82 /* Not receiving messages */
211 #define ERRnoroom 83 /* No room for message */
212 #define ERRrmuns 87 /* too many remote usernames */
213 #define ERRtimeout 88 /* operation timed out */
214 #define ERRnoresource  89 /* No resources currently available for request. */
215 #define ERRtoomanyuids 90 /* too many userids */
216 #define ERRbaduid 91 /* bad userid */
217 #define ERRuseMPX 250 /* temporarily unable to use raw mode, use MPX mode */
218 #define ERRuseSTD 251 /* temporarily unable to use raw mode, use standard mode */
219 #define ERRcontMPX 252 /* resume MPX mode */
220 #define ERRbadPW /* reserved */
221 #define ERRnosupport 0xFFFF
222 #define ERRunknownsmb 22 /* from NT 3.5 response */
223
224
225 /* Error codes for the ERRHRD class */
226
227 #define ERRnowrite 19 /* read only media */
228 #define ERRbadunit 20 /* Unknown device */
229 #define ERRnotready 21 /* Drive not ready */
230 #define ERRbadcmd 22 /* Unknown command */
231 #define ERRdata 23 /* Data (CRC) error */
232 #define ERRbadreq 24 /* Bad request structure length */
233 #define ERRseek 25
234 #define ERRbadmedia 26
235 #define ERRbadsector 27
236 #define ERRnopaper 28
237 #define ERRwrite 29 /* write fault */
238 #define ERRread 30 /* read fault */
239 #define ERRgeneral 31 /* General hardware failure */
240 #define ERRwrongdisk 34
241 #define ERRFCBunavail 35
242 #define ERRsharebufexc 36 /* share buffer exceeded */
243 #define ERRdiskfull 39
244
245
246 typedef char pstring[1024];
247 typedef char fstring[128];
248 typedef fstring string;
249
250
251 struct smb_passwd {
252         int smb_userid;
253         char *smb_name;
254         unsigned char *smb_passwd; /* Null if no password */
255         unsigned char *smb_nt_passwd; /* Null if no password */
256         /* Other fields / flags may be added later */
257 };
258
259
260 struct current_user {
261   int cnum, id;
262   int uid, gid;
263   int ngroups;
264   gid_t *groups;
265   int *igroups;
266 };
267
268 typedef struct
269 {
270   int size;
271   int mode;
272   int uid;
273   int gid;
274   /* these times are normally kept in GMT */
275   time_t mtime;
276   time_t atime;
277   time_t ctime;
278   pstring name;
279 } file_info;
280
281
282 /* Structure used when SMBwritebmpx is active */
283 typedef struct
284         {
285         int   wr_total_written; /* So we know when to discard this */
286         int32 wr_timeout;
287         int32 wr_errclass;
288         int32 wr_error; /* Cached errors */
289         BOOL  wr_mode; /* write through mode) */
290         BOOL  wr_discard; /* discard all further data */
291         } write_bmpx_struct;
292
293 typedef struct
294 {
295   int cnum;
296   int fd;
297   int pos;
298   int size;
299   int mode;
300   char *mmap_ptr;
301   int mmap_size;
302   write_bmpx_struct *wbmpx_ptr;
303   time_t open_time;
304   BOOL open;
305   BOOL can_lock;
306   BOOL can_read;
307   BOOL can_write;
308   BOOL share_mode;
309   BOOL share_pending;
310   BOOL print_file;
311   BOOL modified;
312   char *name;
313 } files_struct;
314
315
316 struct uid_cache {
317   int entries;
318   int list[UID_CACHE_SIZE];
319 };
320
321 typedef struct
322 {
323   int service;
324   BOOL force_user;
325   int uid; /* uid of user who *opened* this connection */
326   int gid; /* gid of user who *opened* this connection */
327   struct uid_cache uid_cache;
328   void *dirptr;
329   BOOL open;
330   BOOL printer;
331   BOOL ipc;
332   BOOL read_only;
333   BOOL admin_user;
334   char *dirpath;
335   char *connectpath;
336   char *origpath;
337   char *user; /* name of user who *opened* this connection */
338   /* following groups stuff added by ih */
339   /* This groups info is valid for the user that *opened* the connection */
340   int ngroups;
341   gid_t *groups;
342   int *igroups; /* an integer version - some OSes are broken :-( */
343   time_t lastused;
344   BOOL used;
345   int num_files_open;
346 } connection_struct;
347
348
349 typedef struct
350 {
351   int uid; /* uid of a validated user */
352   int gid; /* gid of a validated user */
353   fstring name; /* name of a validated user */
354   BOOL guest;
355   /* following groups stuff added by ih */
356   /* This groups info is needed for when we become_user() for this uid */
357   int user_ngroups;
358   gid_t *user_groups;
359   int *user_igroups; /* an integer version - some OSes are broken :-( */
360 } user_struct;
361
362
363 enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING};
364
365 typedef struct
366 {
367   int job;
368   int size;
369   int status;
370   int priority;
371   time_t time;
372   char user[30];
373   char file[100];
374 } print_queue_struct;
375
376 enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
377
378 typedef struct
379 {
380   fstring message;
381   int status;
382 }  print_status_struct;
383
384 /* used for server information: client, nameserv and ipc */
385 struct server_info_struct
386 {
387   fstring name;
388   uint32 type;
389   fstring comment;
390   fstring domain; /* used ONLY in ipc.c NOT namework.c */
391   BOOL server_added; /* used ONLY in ipc.c NOT namework.c */
392 };
393
394
395 /* used for network interfaces */
396 struct interface
397 {
398         struct interface *next;
399         struct in_addr ip;
400         struct in_addr bcast;
401         struct in_addr nmask;
402 };
403
404 /* share mode record in shared memory */
405 typedef struct
406 {
407   shm_offset_t next_offset; /* offset of next record in list in shared mem */
408   int locking_version;
409   int share_mode;
410   time_t time;
411   int pid;
412   dev_t st_dev;
413   ino_t st_ino;
414   char file_name[1];   /* dynamically allocated with correct size */
415 } share_mode_record;
416
417
418 /* this is used for smbstatus */
419 struct connect_record
420 {
421   int magic;
422   int pid;
423   int cnum;
424   int uid;
425   int gid;
426   char name[24];
427   char addr[24];
428   char machine[128];
429   time_t start;
430 };
431
432
433 #define LOCKING_VERSION 2
434
435 /* these are useful macros for checking validity of handles */
436 #define VALID_FNUM(fnum)   (((fnum) >= 0) && ((fnum) < MAX_OPEN_FILES))
437 #define OPEN_FNUM(fnum)    (VALID_FNUM(fnum) && Files[fnum].open)
438 #define VALID_CNUM(cnum)   (((cnum) >= 0) && ((cnum) < MAX_CONNECTIONS))
439 #define OPEN_CNUM(cnum)    (VALID_CNUM(cnum) && Connections[cnum].open)
440 #define IS_IPC(cnum)       (VALID_CNUM(cnum) && Connections[cnum].ipc)
441 #define FNUM_OK(fnum,c) (OPEN_FNUM(fnum) && (c)==Files[fnum].cnum)
442
443 #define CHECK_FNUM(fnum,c) if (!FNUM_OK(fnum,c)) \
444                                return(ERROR(ERRDOS,ERRbadfid))
445 #define CHECK_READ(fnum) if (!Files[fnum].can_read) \
446                                return(ERROR(ERRDOS,ERRbadaccess))
447 #define CHECK_WRITE(fnum) if (!Files[fnum].can_write) \
448                                return(ERROR(ERRDOS,ERRbadaccess))
449 #define CHECK_ERROR(fnum) if (HAS_CACHED_ERROR(fnum)) \
450                                return(CACHED_ERROR(fnum))
451
452 /* translates a connection number into a service number */
453 #define SNUM(cnum)         (Connections[cnum].service)
454
455 /* access various service details */
456 #define SERVICE(snum)      (lp_servicename(snum))
457 #define PRINTCAP           (lp_printcapname())
458 #define PRINTCOMMAND(snum) (lp_printcommand(snum))
459 #define PRINTERNAME(snum)  (lp_printername(snum))
460 #define CAN_WRITE(cnum)    (OPEN_CNUM(cnum) && !Connections[cnum].read_only)
461 #define VALID_SNUM(snum)   (lp_snum_ok(snum))
462 #define GUEST_OK(snum)     (VALID_SNUM(snum) && lp_guest_ok(snum))
463 #define GUEST_ONLY(snum)   (VALID_SNUM(snum) && lp_guest_only(snum))
464 #define CAN_SETDIR(snum)   (!lp_no_set_dir(snum))
465 #define CAN_PRINT(cnum)    (OPEN_CNUM(cnum) && lp_print_ok(SNUM(cnum)))
466 #define POSTSCRIPT(cnum)   (OPEN_CNUM(cnum) && lp_postscript(SNUM(cnum)))
467 #define MAP_HIDDEN(cnum)   (OPEN_CNUM(cnum) && lp_map_hidden(SNUM(cnum)))
468 #define MAP_SYSTEM(cnum)   (OPEN_CNUM(cnum) && lp_map_system(SNUM(cnum)))
469 #define MAP_ARCHIVE(cnum)   (OPEN_CNUM(cnum) && lp_map_archive(SNUM(cnum)))
470 #define CREATE_MODE(cnum)  (lp_create_mode(SNUM(cnum)) | 0700)
471 #ifdef SMB_PASSWD
472 #define SMBENCRYPT()       (lp_encrypted_passwords())
473 #else
474 #define SMBENCRYPT() (False)
475 #endif
476
477 /* the basic packet size, assuming no words or bytes */
478 #define smb_size 39
479
480 /* offsets into message for common items */
481 #define smb_com 8
482 #define smb_rcls 9
483 #define smb_reh 10
484 #define smb_err 11
485 #define smb_flg 13
486 #define smb_flg2 14
487 #define smb_reb 13
488 #define smb_tid 28
489 #define smb_pid 30
490 #define smb_uid 32
491 #define smb_mid 34
492 #define smb_wct 36
493 #define smb_vwv 37
494 #define smb_vwv0 37
495 #define smb_vwv1 39
496 #define smb_vwv2 41
497 #define smb_vwv3 43
498 #define smb_vwv4 45
499 #define smb_vwv5 47
500 #define smb_vwv6 49
501 #define smb_vwv7 51
502 #define smb_vwv8 53
503 #define smb_vwv9 55
504 #define smb_vwv10 57
505 #define smb_vwv11 59
506 #define smb_vwv12 61
507 #define smb_vwv13 63
508 #define smb_vwv14 65
509 #define smb_vwv15 67
510 #define smb_vwv16 69
511 #define smb_vwv17 71
512
513
514 /* the complete */
515 #define SMBmkdir      0x00   /* create directory */
516 #define SMBrmdir      0x01   /* delete directory */
517 #define SMBopen       0x02   /* open file */
518 #define SMBcreate     0x03   /* create file */
519 #define SMBclose      0x04   /* close file */
520 #define SMBflush      0x05   /* flush file */
521 #define SMBunlink     0x06   /* delete file */
522 #define SMBmv         0x07   /* rename file */
523 #define SMBgetatr     0x08   /* get file attributes */
524 #define SMBsetatr     0x09   /* set file attributes */
525 #define SMBread       0x0A   /* read from file */
526 #define SMBwrite      0x0B   /* write to file */
527 #define SMBlock       0x0C   /* lock byte range */
528 #define SMBunlock     0x0D   /* unlock byte range */
529 #define SMBctemp      0x0E   /* create temporary file */
530 #define SMBmknew      0x0F   /* make new file */
531 #define SMBchkpth     0x10   /* check directory path */
532 #define SMBexit       0x11   /* process exit */
533 #define SMBlseek      0x12   /* seek */
534 #define SMBtcon       0x70   /* tree connect */
535 #define SMBtconX      0x75   /* tree connect and X*/
536 #define SMBtdis       0x71   /* tree disconnect */
537 #define SMBnegprot    0x72   /* negotiate protocol */
538 #define SMBdskattr    0x80   /* get disk attributes */
539 #define SMBsearch     0x81   /* search directory */
540 #define SMBsplopen    0xC0   /* open print spool file */
541 #define SMBsplwr      0xC1   /* write to print spool file */
542 #define SMBsplclose   0xC2   /* close print spool file */
543 #define SMBsplretq    0xC3   /* return print queue */
544 #define SMBsends      0xD0   /* send single block message */
545 #define SMBsendb      0xD1   /* send broadcast message */
546 #define SMBfwdname    0xD2   /* forward user name */
547 #define SMBcancelf    0xD3   /* cancel forward */
548 #define SMBgetmac     0xD4   /* get machine name */
549 #define SMBsendstrt   0xD5   /* send start of multi-block message */
550 #define SMBsendend    0xD6   /* send end of multi-block message */
551 #define SMBsendtxt    0xD7   /* send text of multi-block message */
552
553 /* Core+ protocol */
554 #define SMBlockread       0x13   /* Lock a range and read */
555 #define SMBwriteunlock 0x14 /* Unlock a range then write */
556 #define SMBreadbraw   0x1a  /* read a block of data with no smb header */
557 #define SMBwritebraw  0x1d  /* write a block of data with no smb header */
558 #define SMBwritec     0x20  /* secondary write request */
559 #define SMBwriteclose 0x2c  /* write a file then close it */
560
561 /* dos extended protocol */
562 #define SMBreadBraw      0x1A   /* read block raw */
563 #define SMBreadBmpx      0x1B   /* read block multiplexed */
564 #define SMBreadBs        0x1C   /* read block (secondary response) */
565 #define SMBwriteBraw     0x1D   /* write block raw */
566 #define SMBwriteBmpx     0x1E   /* write block multiplexed */
567 #define SMBwriteBs       0x1F   /* write block (secondary request) */
568 #define SMBwriteC        0x20   /* write complete response */
569 #define SMBsetattrE      0x22   /* set file attributes expanded */
570 #define SMBgetattrE      0x23   /* get file attributes expanded */
571 #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
572 #define SMBtrans         0x25   /* transaction - name, bytes in/out */
573 #define SMBtranss        0x26   /* transaction (secondary request/response) */
574 #define SMBioctl         0x27   /* IOCTL */
575 #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
576 #define SMBcopy          0x29   /* copy */
577 #define SMBmove          0x2A   /* move */
578 #define SMBecho          0x2B   /* echo */
579 #define SMBopenX         0x2D   /* open and X */
580 #define SMBreadX         0x2E   /* read and X */
581 #define SMBwriteX        0x2F   /* write and X */
582 #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
583 #define SMBffirst        0x82   /* find first */
584 #define SMBfunique       0x83   /* find unique */
585 #define SMBfclose        0x84   /* find close */
586 #define SMBinvalid       0xFE   /* invalid command */
587
588 /* Extended 2.0 protocol */
589 #define SMBtrans2        0x32   /* TRANS2 protocol set */
590 #define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
591 #define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
592 #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
593 #define SMBulogoffX      0x74   /* user logoff */
594
595
596 /* these are the TRANS2 sub commands */
597 #define TRANSACT2_OPEN          0
598 #define TRANSACT2_FINDFIRST     1
599 #define TRANSACT2_FINDNEXT      2
600 #define TRANSACT2_QFSINFO       3
601 #define TRANSACT2_SETFSINFO     4
602 #define TRANSACT2_QPATHINFO     5
603 #define TRANSACT2_SETPATHINFO   6
604 #define TRANSACT2_QFILEINFO     7
605 #define TRANSACT2_SETFILEINFO   8
606 #define TRANSACT2_FSCTL         9
607 #define TRANSACT2_IOCTL           10
608 #define TRANSACT2_FINDNOTIFYFIRST 11
609 #define TRANSACT2_FINDNOTIFYNEXT  12
610 #define TRANSACT2_MKDIR           13
611
612
613 /* these are the trans2 sub fields for primary requests */
614 #define smb_tpscnt smb_vwv0
615 #define smb_tdscnt smb_vwv1
616 #define smb_mprcnt smb_vwv2
617 #define smb_mdrcnt smb_vwv3
618 #define smb_msrcnt smb_vwv4
619 #define smb_flags smb_vwv5
620 #define smb_timeout smb_vwv6
621 #define smb_pscnt smb_vwv9
622 #define smb_psoff smb_vwv10
623 #define smb_dscnt smb_vwv11
624 #define smb_dsoff smb_vwv12
625 #define smb_suwcnt smb_vwv13
626 #define smb_setup smb_vwv14
627 #define smb_setup0 smb_setup
628 #define smb_setup1 (smb_setup+2)
629 #define smb_setup2 (smb_setup+4)
630
631 /* these are for the secondary requests */
632 #define smb_spscnt smb_vwv2
633 #define smb_spsoff smb_vwv3
634 #define smb_spsdisp smb_vwv4
635 #define smb_sdscnt smb_vwv5
636 #define smb_sdsoff smb_vwv6
637 #define smb_sdsdisp smb_vwv7
638 #define smb_sfid smb_vwv8
639
640 /* and these for responses */
641 #define smb_tprcnt smb_vwv0
642 #define smb_tdrcnt smb_vwv1
643 #define smb_prcnt smb_vwv3
644 #define smb_proff smb_vwv4
645 #define smb_prdisp smb_vwv5
646 #define smb_drcnt smb_vwv6
647 #define smb_droff smb_vwv7
648 #define smb_drdisp smb_vwv8
649
650 /* where to find the base of the SMB packet proper */
651 #define smb_base(buf) (((char *)(buf))+4)
652
653
654 #define SUCCESS 0  /* The request was successful. */
655 #define ERRDOS 0x01 /*  Error is from the core DOS operating system set. */
656 #define ERRSRV 0x02  /* Error is generated by the server network file manager.*/
657 #define ERRHRD 0x03  /* Error is an hardware error. */
658 #define ERRCMD 0xFF  /* Command was not in the "SMB" format. */
659
660 /* structure used to hold the incoming hosts info */
661 struct from_host {
662     char   *name;                       /* host name */
663     char   *addr;                       /* host address */
664     struct sockaddr_in *sin;            /* their side of the link */
665 };
666
667 #ifdef __STDC__
668 int Debug1(char *, ...);
669 #else
670 int Debug1();
671 #endif
672
673 #ifdef DFS_AUTH
674 void dfs_unlogin(void);
675 extern int dcelogin_atmost_once;
676 #endif
677
678 #if AJT
679 void ajt_panic(void);
680 #endif
681
682 #ifdef NOSTRDUP
683 char *strdup(char *s);
684 #endif
685
686 #ifdef REPLACE_STRLEN
687 int Strlen(char *);
688 #endif
689
690 #ifdef REPLACE_STRSTR
691 char *Strstr(char *s, char *p);
692 #endif
693
694 #ifndef MIN
695 #define MIN(a,b) ((a)<(b)?(a):(b))
696 #endif
697 #ifndef MAX
698 #define MAX(a,b) ((a)>(b)?(a):(b))
699 #endif
700
701 #ifndef ABS
702 #define ABS(a) ((a)>0?(a):(-(a)))
703 #endif
704
705 #ifndef SIGNAL_CAST
706 #define SIGNAL_CAST
707 #endif
708
709 #ifndef SELECT_CAST
710 #define SELECT_CAST
711 #endif
712
713
714 /* Some POSIX definitions for those without */
715  
716 #ifndef S_IFDIR
717 #define S_IFDIR         0x4000
718 #endif
719 #ifndef S_ISDIR
720 #define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
721 #endif
722 #ifndef S_IRWXU
723 #define S_IRWXU 00700           /* read, write, execute: owner */
724 #endif
725 #ifndef S_IRUSR
726 #define S_IRUSR 00400           /* read permission: owner */
727 #endif
728 #ifndef S_IWUSR
729 #define S_IWUSR 00200           /* write permission: owner */
730 #endif
731 #ifndef S_IXUSR
732 #define S_IXUSR 00100           /* execute permission: owner */
733 #endif
734 #ifndef S_IRWXG
735 #define S_IRWXG 00070           /* read, write, execute: group */
736 #endif
737 #ifndef S_IRGRP
738 #define S_IRGRP 00040           /* read permission: group */
739 #endif
740 #ifndef S_IWGRP
741 #define S_IWGRP 00020           /* write permission: group */
742 #endif
743 #ifndef S_IXGRP
744 #define S_IXGRP 00010           /* execute permission: group */
745 #endif
746 #ifndef S_IRWXO
747 #define S_IRWXO 00007           /* read, write, execute: other */
748 #endif
749 #ifndef S_IROTH
750 #define S_IROTH 00004           /* read permission: other */
751 #endif
752 #ifndef S_IWOTH
753 #define S_IWOTH 00002           /* write permission: other */
754 #endif
755 #ifndef S_IXOTH
756 #define S_IXOTH 00001           /* execute permission: other */
757 #endif
758
759
760 /* these are used in NetServerEnum to choose what to receive */
761 #define SV_TYPE_WORKSTATION         0x00000001
762 #define SV_TYPE_SERVER              0x00000002
763 #define SV_TYPE_SQLSERVER           0x00000004
764 #define SV_TYPE_DOMAIN_CTRL         0x00000008
765 #define SV_TYPE_DOMAIN_BAKCTRL      0x00000010
766 #define SV_TYPE_TIME_SOURCE         0x00000020
767 #define SV_TYPE_AFP                 0x00000040
768 #define SV_TYPE_NOVELL              0x00000080
769 #define SV_TYPE_DOMAIN_MEMBER       0x00000100
770 #define SV_TYPE_PRINTQ_SERVER       0x00000200
771 #define SV_TYPE_DIALIN_SERVER       0x00000400
772 #define SV_TYPE_SERVER_UNIX         0x00000800
773 #define SV_TYPE_NT                  0x00001000
774 #define SV_TYPE_WFW                 0x00002000
775 #define SV_TYPE_SERVER_MFPN         0x00004000
776 #define SV_TYPE_SERVER_NT           0x00008000
777 #define SV_TYPE_POTENTIAL_BROWSER   0x00010000
778 #define SV_TYPE_BACKUP_BROWSER      0x00020000
779 #define SV_TYPE_MASTER_BROWSER      0x00040000
780 #define SV_TYPE_DOMAIN_MASTER       0x00080000
781 #define SV_TYPE_SERVER_OSF          0x00100000
782 #define SV_TYPE_SERVER_VMS          0x00200000
783 #define SV_TYPE_ALTERNATE_XPORT     0x20000000  
784 #define SV_TYPE_LOCAL_LIST_ONLY     0x40000000  
785 #define SV_TYPE_DOMAIN_ENUM         0x80000000
786 #define SV_TYPE_ALL                 0xFFFFFFFF  
787
788
789
790 /* protocol types. It assumes that higher protocols include lower protocols
791    as subsets */
792 enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
793
794 /* security levels */
795 enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER};
796
797 /* printing types */
798 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
799                      PRINT_QNX,PRINT_PLP};
800
801
802 /* case handling */
803 enum case_handling {CASE_LOWER,CASE_UPPER};
804
805
806 /* Macros to get at offsets within smb_lkrng and smb_unlkrng
807    structures. We cannot define these as actual structures
808    due to possible differences in structure packing
809    on different machines/compilers. */
810
811 #define SMB_LPID_OFFSET(indx) (10 * (indx))
812 #define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
813 #define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
814
815 /* Macro to cache an error in a write_bmpx_struct */
816 #define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
817                             w->wr_discard = True, -1)
818 /* Macro to test if an error has been cached for this fnum */
819 #define HAS_CACHED_ERROR(fnum) (Files[(fnum)].open && \
820                                 Files[(fnum)].wbmpx_ptr && \
821                                 Files[(fnum)].wbmpx_ptr->wr_discard)
822 /* Macro to turn the cached error into an error packet */
823 #define CACHED_ERROR(fnum) cached_error_packet(inbuf,outbuf,fnum,__LINE__)
824
825 /* these are the datagram types */
826 #define DGRAM_DIRECT_UNIQUE 0x10
827
828 #define ERROR(class,x) error_packet(inbuf,outbuf,class,x,__LINE__)
829
830 /* this is how errors are generated */
831 #define UNIXERROR(defclass,deferror) unix_error_packet(inbuf,outbuf,defclass,deferror,__LINE__)
832
833 #define ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
834
835 #endif 
836 /* _SMB_H */