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