Updated Samba minor version so it announces itself as NT Server version
[ira/wip.git] / source3 / include / smb.h
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    SMB parameters and setup
5    Copyright (C) Andrew Tridgell 1992-1997
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 smb_shm_offset_t;
59 #define NULL_OFFSET (smb_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 /*
290  * Structure used to indirect fd's from the files_struct.
291  * Needed as POSIX locking is based on file and process, not
292  * file descriptor and process.
293  */
294
295 typedef struct
296 {
297   uint16 ref_count;
298   int32 dev;
299   int32 inode;
300   int fd;
301   int fd_readonly;
302   int fd_writeonly;
303   int real_open_flags;
304 } file_fd_struct;
305
306 typedef struct
307 {
308   int cnum;
309   file_fd_struct *fd_ptr;
310   int pos;
311   int size;
312   int mode;
313   int uid;
314   char *mmap_ptr;
315   int mmap_size;
316   write_bmpx_struct *wbmpx_ptr;
317   struct timeval open_time;
318   BOOL open;
319   BOOL can_lock;
320   BOOL can_read;
321   BOOL can_write;
322   BOOL share_mode;
323   BOOL share_pending;
324   BOOL print_file;
325   BOOL modified;
326   char *name;
327 } files_struct;
328
329
330 struct uid_cache {
331   int entries;
332   int list[UID_CACHE_SIZE];
333 };
334
335 typedef struct
336 {
337   int service;
338   BOOL force_user;
339   struct uid_cache uid_cache;
340   void *dirptr;
341   BOOL open;
342   BOOL printer;
343   BOOL ipc;
344   BOOL read_only;
345   BOOL admin_user;
346   char *dirpath;
347   char *connectpath;
348   char *origpath;
349   char *user; /* name of user who *opened* this connection */
350   int uid; /* uid of user who *opened* this connection */
351   int gid; /* gid of user who *opened* this connection */
352   uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
353   /* following groups stuff added by ih */
354   /* This groups info is valid for the user that *opened* the connection */
355   int ngroups;
356   gid_t *groups;
357   int *igroups; /* an integer version - some OSes are broken :-( */
358   time_t lastused;
359   BOOL used;
360   int num_files_open;
361 } connection_struct;
362
363
364 typedef struct
365 {
366   int uid; /* uid of a validated user */
367   int gid; /* gid of a validated user */
368   fstring name; /* name of a validated user */
369   BOOL guest;
370   /* following groups stuff added by ih */
371   /* This groups info is needed for when we become_user() for this uid */
372   int user_ngroups;
373   gid_t *user_groups;
374   int *user_igroups; /* an integer version - some OSes are broken :-( */
375 #if (defined(NETGROUP) && defined(AUTOMOUNT))
376   char *home_share;  /* to store NIS home of a user - simeon */
377 #endif
378   char *real_name;   /* to store real name from password file - simeon */
379 } user_struct;
380
381
382 enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING};
383
384 typedef struct
385 {
386   int job;
387   int size;
388   int status;
389   int priority;
390   time_t time;
391   char user[30];
392   char file[100];
393 } print_queue_struct;
394
395 enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
396
397 typedef struct
398 {
399   fstring message;
400   int status;
401 }  print_status_struct;
402
403 /* used for server information: client, nameserv and ipc */
404 struct server_info_struct
405 {
406   fstring name;
407   uint32 type;
408   fstring comment;
409   fstring domain; /* used ONLY in ipc.c NOT namework.c */
410   BOOL server_added; /* used ONLY in ipc.c NOT namework.c */
411 };
412
413
414 /* used for network interfaces */
415 struct interface
416 {
417         struct interface *next;
418         struct in_addr ip;
419         struct in_addr bcast;
420         struct in_addr nmask;
421 };
422
423 /* share mode record in shared memory */
424 typedef struct
425 {
426   smb_shm_offset_t next_offset; /* offset of next record in list in shared mem */
427   int locking_version;
428   int share_mode;
429   struct timeval time;
430   int pid;
431   dev_t st_dev;
432   ino_t st_ino;
433   char file_name[1];   /* dynamically allocated with correct size */
434 } share_mode_record;
435
436
437 /* this is used for smbstatus */
438 struct connect_record
439 {
440   int magic;
441   int pid;
442   int cnum;
443   int uid;
444   int gid;
445   char name[24];
446   char addr[24];
447   char machine[128];
448   time_t start;
449 };
450
451
452 #define LOCKING_VERSION 3
453
454 /* these are useful macros for checking validity of handles */
455 #define VALID_FNUM(fnum)   (((fnum) >= 0) && ((fnum) < MAX_OPEN_FILES))
456 #define OPEN_FNUM(fnum)    (VALID_FNUM(fnum) && Files[fnum].open)
457 #define VALID_CNUM(cnum)   (((cnum) >= 0) && ((cnum) < MAX_CONNECTIONS))
458 #define OPEN_CNUM(cnum)    (VALID_CNUM(cnum) && Connections[cnum].open)
459 #define IS_IPC(cnum)       (VALID_CNUM(cnum) && Connections[cnum].ipc)
460 #define FNUM_OK(fnum,c) (OPEN_FNUM(fnum) && (c)==Files[fnum].cnum)
461
462 #define CHECK_FNUM(fnum,c) if (!FNUM_OK(fnum,c)) \
463                                return(ERROR(ERRDOS,ERRbadfid))
464 #define CHECK_READ(fnum) if (!Files[fnum].can_read) \
465                                return(ERROR(ERRDOS,ERRbadaccess))
466 #define CHECK_WRITE(fnum) if (!Files[fnum].can_write) \
467                                return(ERROR(ERRDOS,ERRbadaccess))
468 #define CHECK_ERROR(fnum) if (HAS_CACHED_ERROR(fnum)) \
469                                return(CACHED_ERROR(fnum))
470
471 /* translates a connection number into a service number */
472 #define SNUM(cnum)         (Connections[cnum].service)
473
474 /* access various service details */
475 #define SERVICE(snum)      (lp_servicename(snum))
476 #define PRINTCAP           (lp_printcapname())
477 #define PRINTCOMMAND(snum) (lp_printcommand(snum))
478 #define PRINTERNAME(snum)  (lp_printername(snum))
479 #define CAN_WRITE(cnum)    (OPEN_CNUM(cnum) && !Connections[cnum].read_only)
480 #define VALID_SNUM(snum)   (lp_snum_ok(snum))
481 #define GUEST_OK(snum)     (VALID_SNUM(snum) && lp_guest_ok(snum))
482 #define GUEST_ONLY(snum)   (VALID_SNUM(snum) && lp_guest_only(snum))
483 #define CAN_SETDIR(snum)   (!lp_no_set_dir(snum))
484 #define CAN_PRINT(cnum)    (OPEN_CNUM(cnum) && lp_print_ok(SNUM(cnum)))
485 #define POSTSCRIPT(cnum)   (OPEN_CNUM(cnum) && lp_postscript(SNUM(cnum)))
486 #define MAP_HIDDEN(cnum)   (OPEN_CNUM(cnum) && lp_map_hidden(SNUM(cnum)))
487 #define MAP_SYSTEM(cnum)   (OPEN_CNUM(cnum) && lp_map_system(SNUM(cnum)))
488 #define MAP_ARCHIVE(cnum)   (OPEN_CNUM(cnum) && lp_map_archive(SNUM(cnum)))
489 #define CREATE_MODE(cnum)  (lp_create_mode(SNUM(cnum)) | 0700)
490 #ifdef SMB_PASSWD
491 #define SMBENCRYPT()       (lp_encrypted_passwords())
492 #else
493 #define SMBENCRYPT() (False)
494 #endif
495
496 /* the basic packet size, assuming no words or bytes */
497 #define smb_size 39
498
499 /* offsets into message for common items */
500 #define smb_com 8
501 #define smb_rcls 9
502 #define smb_reh 10
503 #define smb_err 11
504 #define smb_flg 13
505 #define smb_flg2 14
506 #define smb_reb 13
507 #define smb_tid 28
508 #define smb_pid 30
509 #define smb_uid 32
510 #define smb_mid 34
511 #define smb_wct 36
512 #define smb_vwv 37
513 #define smb_vwv0 37
514 #define smb_vwv1 39
515 #define smb_vwv2 41
516 #define smb_vwv3 43
517 #define smb_vwv4 45
518 #define smb_vwv5 47
519 #define smb_vwv6 49
520 #define smb_vwv7 51
521 #define smb_vwv8 53
522 #define smb_vwv9 55
523 #define smb_vwv10 57
524 #define smb_vwv11 59
525 #define smb_vwv12 61
526 #define smb_vwv13 63
527 #define smb_vwv14 65
528 #define smb_vwv15 67
529 #define smb_vwv16 69
530 #define smb_vwv17 71
531
532
533 /* the complete */
534 #define SMBmkdir      0x00   /* create directory */
535 #define SMBrmdir      0x01   /* delete directory */
536 #define SMBopen       0x02   /* open file */
537 #define SMBcreate     0x03   /* create file */
538 #define SMBclose      0x04   /* close file */
539 #define SMBflush      0x05   /* flush file */
540 #define SMBunlink     0x06   /* delete file */
541 #define SMBmv         0x07   /* rename file */
542 #define SMBgetatr     0x08   /* get file attributes */
543 #define SMBsetatr     0x09   /* set file attributes */
544 #define SMBread       0x0A   /* read from file */
545 #define SMBwrite      0x0B   /* write to file */
546 #define SMBlock       0x0C   /* lock byte range */
547 #define SMBunlock     0x0D   /* unlock byte range */
548 #define SMBctemp      0x0E   /* create temporary file */
549 #define SMBmknew      0x0F   /* make new file */
550 #define SMBchkpth     0x10   /* check directory path */
551 #define SMBexit       0x11   /* process exit */
552 #define SMBlseek      0x12   /* seek */
553 #define SMBtcon       0x70   /* tree connect */
554 #define SMBtconX      0x75   /* tree connect and X*/
555 #define SMBtdis       0x71   /* tree disconnect */
556 #define SMBnegprot    0x72   /* negotiate protocol */
557 #define SMBdskattr    0x80   /* get disk attributes */
558 #define SMBsearch     0x81   /* search directory */
559 #define SMBsplopen    0xC0   /* open print spool file */
560 #define SMBsplwr      0xC1   /* write to print spool file */
561 #define SMBsplclose   0xC2   /* close print spool file */
562 #define SMBsplretq    0xC3   /* return print queue */
563 #define SMBsends      0xD0   /* send single block message */
564 #define SMBsendb      0xD1   /* send broadcast message */
565 #define SMBfwdname    0xD2   /* forward user name */
566 #define SMBcancelf    0xD3   /* cancel forward */
567 #define SMBgetmac     0xD4   /* get machine name */
568 #define SMBsendstrt   0xD5   /* send start of multi-block message */
569 #define SMBsendend    0xD6   /* send end of multi-block message */
570 #define SMBsendtxt    0xD7   /* send text of multi-block message */
571
572 /* Core+ protocol */
573 #define SMBlockread       0x13   /* Lock a range and read */
574 #define SMBwriteunlock 0x14 /* Unlock a range then write */
575 #define SMBreadbraw   0x1a  /* read a block of data with no smb header */
576 #define SMBwritebraw  0x1d  /* write a block of data with no smb header */
577 #define SMBwritec     0x20  /* secondary write request */
578 #define SMBwriteclose 0x2c  /* write a file then close it */
579
580 /* dos extended protocol */
581 #define SMBreadBraw      0x1A   /* read block raw */
582 #define SMBreadBmpx      0x1B   /* read block multiplexed */
583 #define SMBreadBs        0x1C   /* read block (secondary response) */
584 #define SMBwriteBraw     0x1D   /* write block raw */
585 #define SMBwriteBmpx     0x1E   /* write block multiplexed */
586 #define SMBwriteBs       0x1F   /* write block (secondary request) */
587 #define SMBwriteC        0x20   /* write complete response */
588 #define SMBsetattrE      0x22   /* set file attributes expanded */
589 #define SMBgetattrE      0x23   /* get file attributes expanded */
590 #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
591 #define SMBtrans         0x25   /* transaction - name, bytes in/out */
592 #define SMBtranss        0x26   /* transaction (secondary request/response) */
593 #define SMBioctl         0x27   /* IOCTL */
594 #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
595 #define SMBcopy          0x29   /* copy */
596 #define SMBmove          0x2A   /* move */
597 #define SMBecho          0x2B   /* echo */
598 #define SMBopenX         0x2D   /* open and X */
599 #define SMBreadX         0x2E   /* read and X */
600 #define SMBwriteX        0x2F   /* write and X */
601 #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
602 #define SMBffirst        0x82   /* find first */
603 #define SMBfunique       0x83   /* find unique */
604 #define SMBfclose        0x84   /* find close */
605 #define SMBinvalid       0xFE   /* invalid command */
606
607 /* Extended 2.0 protocol */
608 #define SMBtrans2        0x32   /* TRANS2 protocol set */
609 #define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
610 #define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
611 #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
612 #define SMBulogoffX      0x74   /* user logoff */
613
614
615 /* these are the TRANS2 sub commands */
616 #define TRANSACT2_OPEN          0
617 #define TRANSACT2_FINDFIRST     1
618 #define TRANSACT2_FINDNEXT      2
619 #define TRANSACT2_QFSINFO       3
620 #define TRANSACT2_SETFSINFO     4
621 #define TRANSACT2_QPATHINFO     5
622 #define TRANSACT2_SETPATHINFO   6
623 #define TRANSACT2_QFILEINFO     7
624 #define TRANSACT2_SETFILEINFO   8
625 #define TRANSACT2_FSCTL         9
626 #define TRANSACT2_IOCTL           10
627 #define TRANSACT2_FINDNOTIFYFIRST 11
628 #define TRANSACT2_FINDNOTIFYNEXT  12
629 #define TRANSACT2_MKDIR           13
630
631
632 /* these are the trans2 sub fields for primary requests */
633 #define smb_tpscnt smb_vwv0
634 #define smb_tdscnt smb_vwv1
635 #define smb_mprcnt smb_vwv2
636 #define smb_mdrcnt smb_vwv3
637 #define smb_msrcnt smb_vwv4
638 #define smb_flags smb_vwv5
639 #define smb_timeout smb_vwv6
640 #define smb_pscnt smb_vwv9
641 #define smb_psoff smb_vwv10
642 #define smb_dscnt smb_vwv11
643 #define smb_dsoff smb_vwv12
644 #define smb_suwcnt smb_vwv13
645 #define smb_setup smb_vwv14
646 #define smb_setup0 smb_setup
647 #define smb_setup1 (smb_setup+2)
648 #define smb_setup2 (smb_setup+4)
649
650 /* these are for the secondary requests */
651 #define smb_spscnt smb_vwv2
652 #define smb_spsoff smb_vwv3
653 #define smb_spsdisp smb_vwv4
654 #define smb_sdscnt smb_vwv5
655 #define smb_sdsoff smb_vwv6
656 #define smb_sdsdisp smb_vwv7
657 #define smb_sfid smb_vwv8
658
659 /* and these for responses */
660 #define smb_tprcnt smb_vwv0
661 #define smb_tdrcnt smb_vwv1
662 #define smb_prcnt smb_vwv3
663 #define smb_proff smb_vwv4
664 #define smb_prdisp smb_vwv5
665 #define smb_drcnt smb_vwv6
666 #define smb_droff smb_vwv7
667 #define smb_drdisp smb_vwv8
668
669 /* where to find the base of the SMB packet proper */
670 #define smb_base(buf) (((char *)(buf))+4)
671
672
673 #define SUCCESS 0  /* The request was successful. */
674 #define ERRDOS 0x01 /*  Error is from the core DOS operating system set. */
675 #define ERRSRV 0x02  /* Error is generated by the server network file manager.*/
676 #define ERRHRD 0x03  /* Error is an hardware error. */
677 #define ERRCMD 0xFF  /* Command was not in the "SMB" format. */
678
679 #ifdef __STDC__
680 int Debug1(char *, ...);
681 #else
682 int Debug1();
683 #endif
684
685 #ifdef DFS_AUTH
686 void dfs_unlogin(void);
687 extern int dcelogin_atmost_once;
688 #endif
689
690 #if AJT
691 void ajt_panic(void);
692 #endif
693
694 #ifdef NOSTRDUP
695 char *strdup(char *s);
696 #endif
697
698 #ifdef REPLACE_STRLEN
699 int Strlen(char *);
700 #endif
701
702 #ifdef REPLACE_STRSTR
703 char *Strstr(char *s, char *p);
704 #endif
705
706 #ifndef MIN
707 #define MIN(a,b) ((a)<(b)?(a):(b))
708 #endif
709 #ifndef MAX
710 #define MAX(a,b) ((a)>(b)?(a):(b))
711 #endif
712
713 #ifndef ABS
714 #define ABS(a) ((a)>0?(a):(-(a)))
715 #endif
716
717 #ifndef SIGNAL_CAST
718 #define SIGNAL_CAST
719 #endif
720
721 #ifndef SELECT_CAST
722 #define SELECT_CAST
723 #endif
724
725
726 /* Some POSIX definitions for those without */
727  
728 #ifndef S_IFDIR
729 #define S_IFDIR         0x4000
730 #endif
731 #ifndef S_ISDIR
732 #define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
733 #endif
734 #ifndef S_IRWXU
735 #define S_IRWXU 00700           /* read, write, execute: owner */
736 #endif
737 #ifndef S_IRUSR
738 #define S_IRUSR 00400           /* read permission: owner */
739 #endif
740 #ifndef S_IWUSR
741 #define S_IWUSR 00200           /* write permission: owner */
742 #endif
743 #ifndef S_IXUSR
744 #define S_IXUSR 00100           /* execute permission: owner */
745 #endif
746 #ifndef S_IRWXG
747 #define S_IRWXG 00070           /* read, write, execute: group */
748 #endif
749 #ifndef S_IRGRP
750 #define S_IRGRP 00040           /* read permission: group */
751 #endif
752 #ifndef S_IWGRP
753 #define S_IWGRP 00020           /* write permission: group */
754 #endif
755 #ifndef S_IXGRP
756 #define S_IXGRP 00010           /* execute permission: group */
757 #endif
758 #ifndef S_IRWXO
759 #define S_IRWXO 00007           /* read, write, execute: other */
760 #endif
761 #ifndef S_IROTH
762 #define S_IROTH 00004           /* read permission: other */
763 #endif
764 #ifndef S_IWOTH
765 #define S_IWOTH 00002           /* write permission: other */
766 #endif
767 #ifndef S_IXOTH
768 #define S_IXOTH 00001           /* execute permission: other */
769 #endif
770
771
772 /* these are used in NetServerEnum to choose what to receive */
773 #define SV_TYPE_WORKSTATION         0x00000001
774 #define SV_TYPE_SERVER              0x00000002
775 #define SV_TYPE_SQLSERVER           0x00000004
776 #define SV_TYPE_DOMAIN_CTRL         0x00000008
777 #define SV_TYPE_DOMAIN_BAKCTRL      0x00000010
778 #define SV_TYPE_TIME_SOURCE         0x00000020
779 #define SV_TYPE_AFP                 0x00000040
780 #define SV_TYPE_NOVELL              0x00000080
781 #define SV_TYPE_DOMAIN_MEMBER       0x00000100
782 #define SV_TYPE_PRINTQ_SERVER       0x00000200
783 #define SV_TYPE_DIALIN_SERVER       0x00000400
784 #define SV_TYPE_SERVER_UNIX         0x00000800
785 #define SV_TYPE_NT                  0x00001000
786 #define SV_TYPE_WFW                 0x00002000
787 #define SV_TYPE_SERVER_MFPN         0x00004000
788 #define SV_TYPE_SERVER_NT           0x00008000
789 #define SV_TYPE_POTENTIAL_BROWSER   0x00010000
790 #define SV_TYPE_BACKUP_BROWSER      0x00020000
791 #define SV_TYPE_MASTER_BROWSER      0x00040000
792 #define SV_TYPE_DOMAIN_MASTER       0x00080000
793 #define SV_TYPE_SERVER_OSF          0x00100000
794 #define SV_TYPE_SERVER_VMS          0x00200000
795 #define SV_TYPE_WIN95_PLUS          0x00400000
796 #define SV_TYPE_ALTERNATE_XPORT     0x20000000  
797 #define SV_TYPE_LOCAL_LIST_ONLY     0x40000000  
798 #define SV_TYPE_DOMAIN_ENUM         0x80000000
799 #define SV_TYPE_ALL                 0xFFFFFFFF  
800
801 /* What server type are we currently  - JHT Says we ARE 4.20 */
802 /* History: */
803 /* Version 4.0 - never made public */
804 /* Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9 */
805 /*              - Reappeared in 1.9.16p11 with fixed smbd services */
806 /* Version 4.20 - To indicate that nmbd and browsing now works better */
807 #define MAJOR_VERSION 0x04
808 #define MINOR_VERSION 0x02
809
810 /* Browser Election Values */
811 #define BROWSER_ELECTION_VERSION        0x010f
812 #define BROWSER_CONSTANT        0xaa55
813
814
815 /* Capabilities.  see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
816
817 #define CAP_RAW_MODE         0x0001
818 #define CAP_MPX_MODE         0x0002
819 #define CAP_UNICODE          0x0004
820 #define CAP_LARGE_FILES      0x0008
821 #define CAP_NT_SMBS          0x0010
822 #define CAP_RPC_REMOTE_APIS  0x0020
823 #define CAP_STATUS32         0x0040
824 #define CAP_LEVEL_II_OPLOCKS 0x0080
825 #define CAP_LOCK_AND_READ    0x0100
826 #define CAP_NT_FIND          0x0200
827 #define CAP_DFS              0x1000
828 #define CAP_LARGE_READX      0x4000
829
830 /* protocol types. It assumes that higher protocols include lower protocols
831    as subsets */
832 enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
833
834 /* security levels */
835 enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER};
836
837 /* printing types */
838 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
839                      PRINT_QNX,PRINT_PLP,PRINT_LPRNG};
840
841
842 /* case handling */
843 enum case_handling {CASE_LOWER,CASE_UPPER};
844
845
846 /* Macros to get at offsets within smb_lkrng and smb_unlkrng
847    structures. We cannot define these as actual structures
848    due to possible differences in structure packing
849    on different machines/compilers. */
850
851 #define SMB_LPID_OFFSET(indx) (10 * (indx))
852 #define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
853 #define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
854
855 /* Macro to cache an error in a write_bmpx_struct */
856 #define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
857                             w->wr_discard = True, -1)
858 /* Macro to test if an error has been cached for this fnum */
859 #define HAS_CACHED_ERROR(fnum) (Files[(fnum)].open && \
860                                 Files[(fnum)].wbmpx_ptr && \
861                                 Files[(fnum)].wbmpx_ptr->wr_discard)
862 /* Macro to turn the cached error into an error packet */
863 #define CACHED_ERROR(fnum) cached_error_packet(inbuf,outbuf,fnum,__LINE__)
864
865 /* these are the datagram types */
866 #define DGRAM_DIRECT_UNIQUE 0x10
867
868 #define ERROR(class,x) error_packet(inbuf,outbuf,class,x,__LINE__)
869
870 /* this is how errors are generated */
871 #define UNIXERROR(defclass,deferror) unix_error_packet(inbuf,outbuf,defclass,deferror,__LINE__)
872
873 #define ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
874
875 /*
876  * Global value meaing that the smb_uid field should be
877  * ingored (in share level security and protocol level == CORE)
878  */
879
880 #define UID_FIELD_INVALID 0
881 #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
882
883 #endif 
884 /* _SMB_H */