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