merge from the autoconf2 branch to the main branch
[samba.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-1998
6    Copyright (C) John H Terpstra 1996-1998
7    Copyright (C) Luke Kenneth Casson Leighton 1996-1998
8    Copyright (C) Paul Ashton 1998
9    
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14    
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19    
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24 #ifndef _SMB_H
25 #define _SMB_H
26
27 #define BUFFER_SIZE (0xFFFF)
28 #define SAFETY_MARGIN 1024
29
30 #define NMB_PORT 137
31 #define DGRAM_PORT 138
32 #define SMB_PORT 139
33
34 #define False (0)
35 #define True (1)
36 #define BOOLSTR(b) ((b) ? "Yes" : "No")
37 #define BITSETB(ptr,bit) ((((char *)ptr)[0] & (1<<(bit)))!=0)
38 #define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0)
39
40 #define IS_BITS_SET_ALL(var,bit) (((var)&(bit))==(bit))
41 #define IS_BITS_SET_SOME(var,bit) (((var)&(bit))!=0)
42 #define IS_BITS_CLR_ALL(var,bit) (((var)&(~(bit)))==0)
43
44 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((char *)(p1)) - (char *)(p2)))
45
46 typedef int BOOL;
47
48 /* limiting size of ipc replies */
49 #define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024))
50
51 /*
52    Samba needs type definitions for int16, int32, uint16 and uint32.
53    
54    Normally these are signed and unsigned 16 and 32 bit integers, but
55    they actually only need to be at least 16 and 32 bits
56    respectively. Thus if your word size is 8 bytes just defining them
57    as signed and unsigned int will work.
58 */
59
60 #ifndef uint8
61 typedef unsigned char uint8;
62 #endif
63
64 #ifndef uint16
65 typedef unsigned short uint16;
66 #endif
67
68 #ifndef uchar
69 #define uchar unsigned char
70 #endif
71
72 #ifndef int16
73 #define int16 short
74 #endif
75
76 #ifndef uint16
77 #define uint16 unsigned short
78 #endif
79
80 #define SIZEOFWORD 2
81
82 #ifndef DEF_CREATE_MASK
83 #define DEF_CREATE_MASK (0755)
84 #endif
85
86 #ifndef PRINTCAP_NAME
87 #define PRINTCAP_NAME "/etc/printcap"
88 #endif
89
90 /* how long to wait for secondary SMB packets (milli-seconds) */
91 #define SMB_SECONDARY_WAIT (60*1000)
92
93 /* debugging code */
94 #if !defined(WITH_SYSLOG) || defined(NO_SYSLOG)
95 #define DEBUG(level,body) ((DEBUGLEVEL>=(level))?(Debug1 body):0)
96 #define DEBUGLVL(level) (DEBUGLEVEL>=(level))
97 #else
98 extern int syslog_level;
99
100 #define DEBUG(level,body) ((DEBUGLEVEL>=(level))? (syslog_level = (level), Debug1 body):0)
101 #define DEBUGLVL(level) ( DEBUGLEVEL >= (syslog_level=(level)) )
102 #endif
103
104 /* this defines the error codes that receive_smb can put in smb_read_error */
105 #define READ_TIMEOUT 1
106 #define READ_EOF 2
107 #define READ_ERROR 3
108
109
110 #define DIR_STRUCT_SIZE 43
111
112 /* these define all the command types recognised by the server - there
113 are lots of gaps so probably there are some rare commands that are not
114 implemented */
115
116 #define pSETDIR '\377'
117
118 /* these define the attribute byte as seen by DOS */
119 #define aRONLY (1L<<0)
120 #define aHIDDEN (1L<<1)
121 #define aSYSTEM (1L<<2)
122 #define aVOLID (1L<<3)
123 #define aDIR (1L<<4)
124 #define aARCH (1L<<5)
125
126 /* deny modes */
127 #define DENY_DOS 0
128 #define DENY_ALL 1
129 #define DENY_WRITE 2
130 #define DENY_READ 3
131 #define DENY_NONE 4
132 #define DENY_FCB 7
133
134 /* share types */
135 #define STYPE_DISKTREE  0       /* Disk drive */
136 #define STYPE_PRINTQ    1       /* Spooler queue */
137 #define STYPE_DEVICE    2       /* Serial device */
138 #define STYPE_IPC       3       /* Interprocess communication (IPC) */
139 #define STYPE_HIDDEN    0x80000000 /* share is a hidden one (ends with $) */
140
141 /* SMB X/Open error codes for the ERRdos error class */
142 #define ERRbadfunc 1 /* Invalid function (or system call) */
143 #define ERRbadfile 2 /* File not found (pathname error) */
144 #define ERRbadpath 3 /* Directory not found */
145 #define ERRnofids 4 /* Too many open files */
146 #define ERRnoaccess 5 /* Access denied */
147 #define ERRbadfid 6 /* Invalid fid */
148 #define ERRnomem 8 /* Out of memory */
149 #define ERRbadmem 9 /* Invalid memory block address */
150 #define ERRbadenv 10 /* Invalid environment */
151 #define ERRbadaccess 12 /* Invalid open mode */
152 #define ERRbaddata 13 /* Invalid data (only from ioctl call) */
153 #define ERRres 14 /* reserved */
154 #define ERRbaddrive 15 /* Invalid drive */
155 #define ERRremcd 16 /* Attempt to delete current directory */
156 #define ERRdiffdevice 17 /* rename/move across different filesystems */
157 #define ERRnofiles 18 /* no more files found in file search */
158 #define ERRbadshare 32 /* Share mode on file conflict with open mode */
159 #define ERRlock 33 /* Lock request conflicts with existing lock */
160 #define ERRunsup 50 /* Request unsupported, returned by Win 95, RJS 20Jun98 */
161 #define ERRfilexists 80 /* File in operation already exists */
162 #define ERRcannotopen 110 /* Cannot open the file specified */
163 #define ERRunknownlevel 124
164 #define ERRbadpipe 230 /* Named pipe invalid */
165 #define ERRpipebusy 231 /* All instances of pipe are busy */
166 #define ERRpipeclosing 232 /* named pipe close in progress */
167 #define ERRnotconnected 233 /* No process on other end of named pipe */
168 #define ERRmoredata 234 /* More data to be returned */
169 #define ERRbaddirectory 267 /* Invalid directory name in a path. */
170 #define ERROR_EAS_DIDNT_FIT 275 /* Extended attributes didn't fit */
171 #define ERROR_EAS_NOT_SUPPORTED 282 /* Extended attributes not supported */
172 #define ERRunknownipc 2142
173
174
175 /* here's a special one from observing NT */
176 #define ERRnoipc 66 /* don't support ipc */
177
178 /* Error codes for the ERRSRV class */
179
180 #define ERRerror 1 /* Non specific error code */
181 #define ERRbadpw 2 /* Bad password */
182 #define ERRbadtype 3 /* reserved */
183 #define ERRaccess 4 /* No permissions to do the requested operation */
184 #define ERRinvnid 5 /* tid invalid */
185 #define ERRinvnetname 6 /* Invalid servername */
186 #define ERRinvdevice 7 /* Invalid device */
187 #define ERRqfull 49 /* Print queue full */
188 #define ERRqtoobig 50 /* Queued item too big */
189 #define ERRinvpfid 52 /* Invalid print file in smb_fid */
190 #define ERRsmbcmd 64 /* Unrecognised command */
191 #define ERRsrverror 65 /* smb server internal error */
192 #define ERRfilespecs 67 /* fid and pathname invalid combination */
193 #define ERRbadlink 68 /* reserved */
194 #define ERRbadpermits 69 /* Access specified for a file is not valid */
195 #define ERRbadpid 70 /* reserved */
196 #define ERRsetattrmode 71 /* attribute mode invalid */
197 #define ERRpaused 81 /* Message server paused */
198 #define ERRmsgoff 82 /* Not receiving messages */
199 #define ERRnoroom 83 /* No room for message */
200 #define ERRrmuns 87 /* too many remote usernames */
201 #define ERRtimeout 88 /* operation timed out */
202 #define ERRnoresource  89 /* No resources currently available for request. */
203 #define ERRtoomanyuids 90 /* too many userids */
204 #define ERRbaduid 91 /* bad userid */
205 #define ERRuseMPX 250 /* temporarily unable to use raw mode, use MPX mode */
206 #define ERRuseSTD 251 /* temporarily unable to use raw mode, use standard mode */
207 #define ERRcontMPX 252 /* resume MPX mode */
208 #define ERRbadPW /* reserved */
209 #define ERRnosupport 0xFFFF
210 #define ERRunknownsmb 22 /* from NT 3.5 response */
211
212
213 /* Error codes for the ERRHRD class */
214
215 #define ERRnowrite 19 /* read only media */
216 #define ERRbadunit 20 /* Unknown device */
217 #define ERRnotready 21 /* Drive not ready */
218 #define ERRbadcmd 22 /* Unknown command */
219 #define ERRdata 23 /* Data (CRC) error */
220 #define ERRbadreq 24 /* Bad request structure length */
221 #define ERRseek 25
222 #define ERRbadmedia 26
223 #define ERRbadsector 27
224 #define ERRnopaper 28
225 #define ERRwrite 29 /* write fault */
226 #define ERRread 30 /* read fault */
227 #define ERRgeneral 31 /* General hardware failure */
228 #define ERRwrongdisk 34
229 #define ERRFCBunavail 35
230 #define ERRsharebufexc 36 /* share buffer exceeded */
231 #define ERRdiskfull 39
232
233
234 typedef char pstring[1024];
235 typedef char fstring[128];
236
237 /* pipe strings */
238 #define PIPE_LANMAN   "\\PIPE\\LANMAN"
239 #define PIPE_SRVSVC   "\\PIPE\\srvsvc"
240 #define PIPE_SAMR     "\\PIPE\\samr"
241 #define PIPE_WKSSVC   "\\PIPE\\wkssvc"
242 #define PIPE_NETLOGON "\\PIPE\\NETLOGON"
243 #define PIPE_NTLSA    "\\PIPE\\ntlsa"
244 #define PIPE_NTSVCS   "\\PIPE\\ntsvcs"
245 #define PIPE_LSASS    "\\PIPE\\lsass"
246 #define PIPE_LSARPC   "\\PIPE\\lsarpc"
247
248
249 /* 64 bit time (100usec) since ????? - cifs6.txt, section 3.5, page 30 */
250 typedef struct nttime_info
251 {
252   uint32 low;
253   uint32 high;
254
255 } NTTIME;
256
257 /* Allowable account control bits */
258 #define ACB_DISABLED   0x0001  /* 1 = User account disabled */
259 #define ACB_HOMDIRREQ  0x0002  /* 1 = Home directory required */
260 #define ACB_PWNOTREQ   0x0004  /* 1 = User password not required */
261 #define ACB_TEMPDUP    0x0008  /* 1 = Temporary duplicate account */
262 #define ACB_NORMAL     0x0010  /* 1 = Normal user account */
263 #define ACB_MNS        0x0020  /* 1 = MNS logon user account */
264 #define ACB_DOMTRUST   0x0040  /* 1 = Interdomain trust account */
265 #define ACB_WSTRUST    0x0080  /* 1 = Workstation trust account */
266 #define ACB_SVRTRUST   0x0100  /* 1 = Server trust account */
267 #define ACB_PWNOEXP    0x0200  /* 1 = User password does not expire */
268 #define ACB_AUTOLOCK   0x0400  /* 1 = Account auto locked */
269  
270 #define MAX_HOURS_LEN 32
271
272 struct sam_passwd
273 {
274         time_t logon_time;            /* logon time */
275         time_t logoff_time;           /* logoff time */
276         time_t kickoff_time;          /* kickoff time */
277         time_t pass_last_set_time;    /* password last set time */
278         time_t pass_can_change_time;  /* password can change time */
279         time_t pass_must_change_time; /* password must change time */
280
281         char *smb_name;     /* username string */
282         char *full_name;    /* user's full name string */
283         char *home_dir;     /* home directory string */
284         char *dir_drive;    /* home directory drive string */
285         char *logon_script; /* logon script string */
286         char *profile_path; /* profile path string */
287         char *acct_desc  ;  /* user description string */
288         char *workstations; /* login from workstations string */
289         char *unknown_str ; /* don't know what this is, yet. */
290         char *munged_dial ; /* munged path name and dial-back tel number */
291
292         int smb_userid;       /* this is actually the unix uid_t */
293         int smb_grpid;        /* this is actually the unix gid_t */
294         uint32 user_rid;      /* Primary User ID */
295         uint32 group_rid;     /* Primary Group ID */
296
297         unsigned char *smb_passwd; /* Null if no password */
298         unsigned char *smb_nt_passwd; /* Null if no password */
299
300         uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */
301         uint32 unknown_3; /* 0x00ff ffff */
302
303         uint16 logon_divs; /* 168 - number of hours in a week */
304         uint32 hours_len; /* normally 21 bytes */
305         uint8 hours[MAX_HOURS_LEN];
306
307         uint32 unknown_5; /* 0x0002 0000 */
308         uint32 unknown_6; /* 0x0000 04ec */
309 };
310
311 struct smb_passwd
312 {
313         int smb_userid;     /* this is actually the unix uid_t */
314         char *smb_name;     /* username string */
315
316         unsigned char *smb_passwd; /* Null if no password */
317         unsigned char *smb_nt_passwd; /* Null if no password */
318
319         uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */
320         time_t pass_last_set_time;    /* password last set time */
321 };
322
323
324 struct sam_disp_info
325 {
326         uint32 user_rid;      /* Primary User ID */
327         char *smb_name;     /* username string */
328         char *full_name;    /* user's full name string */
329 };
330
331 /* DOM_CHAL - challenge info */
332 typedef struct chal_info
333 {
334   uchar data[8]; /* credentials */
335 } DOM_CHAL;
336
337 /* 32 bit time (sec) since 01jan1970 - cifs6.txt, section 3.5, page 30 */
338 typedef struct time_info
339 {
340   uint32 time;
341 } UTIME;
342
343 /* DOM_CREDs - timestamped client or server credentials */
344 typedef struct cred_info
345 {  
346   DOM_CHAL challenge; /* credentials */
347   UTIME timestamp;    /* credential time-stamp */
348 } DOM_CRED;
349
350 struct cli_state {
351   int fd;
352   int cnum;
353   int pid;
354   int mid;
355   int uid;
356   int protocol;
357   int sec_mode;
358   int rap_error;
359   int privilages;
360   fstring eff_name;
361   fstring desthost;
362   char cryptkey[8];
363   uint32 sesskey;
364   int serverzone;
365   uint32 servertime;
366   int readbraw_supported;
367   int writebraw_supported;
368   int timeout;
369   int max_xmit;
370   char *outbuf;
371   char *inbuf;
372   int bufsize;
373   int initialised;
374   /*
375    * Only used in NT domain calls.
376    */
377   uint32 nt_error;                   /* NT RPC error code. */
378   uint16 nt_pipe_fnum;               /* Pipe handle. */
379   unsigned char sess_key[16];        /* Current session key. */
380   DOM_CRED clnt_cred;                /* Client credential. */
381   fstring mach_acct;                 /* MYNAME$. */
382   fstring srv_name_slash;            /* \\remote server. */
383   fstring clnt_name_slash;            /* \\local client. */
384 };
385
386
387 struct current_user
388 {
389   int cnum, vuid;
390   int uid, gid;
391   int ngroups;
392   gid_t *groups;
393   int *igroups;
394 };
395
396 typedef struct
397 {
398   int size;
399   int mode;
400   int uid;
401   int gid;
402   /* these times are normally kept in GMT */
403   time_t mtime;
404   time_t atime;
405   time_t ctime;
406   pstring name;
407
408 } file_info;
409
410
411 /* Structure used when SMBwritebmpx is active */
412 typedef struct
413 {
414   int   wr_total_written; /* So we know when to discard this */
415   int32 wr_timeout;
416   int32 wr_errclass;
417   int32 wr_error; /* Cached errors */
418   BOOL  wr_mode; /* write through mode) */
419   BOOL  wr_discard; /* discard all further data */
420 } write_bmpx_struct;
421
422 /*
423  * Structure used to indirect fd's from the files_struct.
424  * Needed as POSIX locking is based on file and process, not
425  * file descriptor and process.
426  */
427
428 typedef struct
429 {
430   uint16 ref_count;
431   uint16 uid_cache_count;
432   uid_t uid_users_cache[10];
433   uint32 dev;
434   uint32 inode;
435   int fd;
436   int fd_readonly;
437   int fd_writeonly;
438   int real_open_flags;
439 } file_fd_struct;
440
441 typedef struct
442 {
443   int cnum;
444   file_fd_struct *fd_ptr;
445   int pos;
446   uint32 size;
447   int mode;
448   int vuid;
449   char *mmap_ptr;
450   uint32 mmap_size;
451   write_bmpx_struct *wbmpx_ptr;
452   struct timeval open_time;
453   BOOL open;
454   BOOL can_lock;
455   BOOL can_read;
456   BOOL can_write;
457   BOOL share_mode;
458   BOOL print_file;
459   BOOL modified;
460   BOOL granted_oplock;
461   BOOL sent_oplock_break;
462   BOOL is_directory;
463   BOOL reserved;
464   char *name;
465 } files_struct;
466
467
468 struct uid_cache {
469   int entries;
470   int list[UID_CACHE_SIZE];
471 };
472
473 typedef struct
474 {
475   char *name;
476   BOOL is_wild;
477 } name_compare_entry;
478
479 typedef struct
480 {
481   int service;
482   BOOL force_user;
483   struct uid_cache uid_cache;
484   void *dirptr;
485   BOOL open;
486   BOOL printer;
487   BOOL ipc;
488   BOOL read_only;
489   BOOL admin_user;
490   char *dirpath;
491   char *connectpath;
492   char *origpath;
493   char *user; /* name of user who *opened* this connection */
494   int uid; /* uid of user who *opened* this connection */
495   int gid; /* gid of user who *opened* this connection */
496
497   uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
498
499   /* following groups stuff added by ih */
500
501   /* This groups info is valid for the user that *opened* the connection */
502   int ngroups;
503   gid_t *groups;
504   int *igroups; /* an integer version - some OSes are broken :-( */
505
506   time_t lastused;
507   BOOL used;
508   int num_files_open;
509   name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */
510   name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */
511   name_compare_entry *veto_oplock_list; /* Per-share list of files to refuse oplocks on. */
512
513 } connection_struct;
514
515 /* Domain controller authentication protocol info */
516 struct dcinfo
517 {
518   DOM_CHAL clnt_chal; /* Initial challenge received from client */
519   DOM_CHAL srv_chal;  /* Initial server challenge */
520   DOM_CRED clnt_cred; /* Last client credential */
521   DOM_CRED srv_cred;  /* Last server credential */
522
523   uchar  sess_key[8]; /* Session key */
524   uchar  md4pw[16];   /* md4(machine password) */
525 };
526
527 typedef struct
528 {
529   int uid; /* uid of a validated user */
530   int gid; /* gid of a validated user */
531
532   fstring requested_name; /* user name from the client */
533   fstring name; /* unix user name of a validated user */
534   fstring real_name;   /* to store real name from password file - simeon */
535   BOOL guest;
536
537   /* following groups stuff added by ih */
538   /* This groups info is needed for when we become_user() for this uid */
539   int n_groups;
540   gid_t *groups;
541   int *igroups; /* an integer version - some OSes are broken :-( */
542
543   int n_sids;
544   int *sids;
545
546   /* per-user authentication information on NT RPCs */
547   struct dcinfo dc;
548
549 } user_struct;
550
551
552 enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING};
553
554 typedef struct
555 {
556   int job;
557   int size;
558   int status;
559   int priority;
560   time_t time;
561   char user[30];
562   char file[100];
563 } print_queue_struct;
564
565 enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
566
567 typedef struct
568 {
569   fstring message;
570   int status;
571 }  print_status_struct;
572
573 /* used for server information: client, nameserv and ipc */
574 struct server_info_struct
575 {
576   fstring name;
577   uint32 type;
578   fstring comment;
579   fstring domain; /* used ONLY in ipc.c NOT namework.c */
580   BOOL server_added; /* used ONLY in ipc.c NOT namework.c */
581 };
582
583
584 /* used for network interfaces */
585 struct interface
586 {
587         struct interface *next;
588         struct in_addr ip;
589         struct in_addr bcast;
590         struct in_addr nmask;
591 };
592
593 /* struct returned by get_share_modes */
594 typedef struct
595 {
596   int pid;
597   uint16 op_port;
598   uint16 op_type;
599   int share_mode;
600   struct timeval time;
601 } share_mode_entry;
602
603
604 /* each implementation of the share mode code needs
605    to support the following operations */
606 struct share_ops {
607         BOOL (*stop_mgmt)(void);
608         BOOL (*lock_entry)(int , uint32 , uint32 , int *);
609         BOOL (*unlock_entry)(int , uint32 , uint32 , int );
610         int (*get_entries)(int , int , uint32 , uint32 , share_mode_entry **);
611         void (*del_entry)(int , int );
612         BOOL (*set_entry)(int , int , uint16 , uint16 );
613         BOOL (*remove_oplock)(int , int);
614         int (*forall)(void (*)(share_mode_entry *, char *));
615         void (*status)(FILE *);
616 };
617
618 /* each implementation of the shared memory code needs
619    to support the following operations */
620 struct shmem_ops {
621         BOOL (*shm_close)( void );
622         int (*shm_alloc)(int );
623         BOOL (*shm_free)(int );
624         int (*get_userdef_off)(void);
625         void *(*offset2addr)(int );
626         int (*addr2offset)(void *addr);
627         BOOL (*lock_hash_entry)(unsigned int);
628         BOOL (*unlock_hash_entry)( unsigned int );
629         BOOL (*get_usage)(int *,int *,int *);
630         unsigned (*hash_size)(void);
631 };
632
633 /*
634  * Each implementation of the password database code needs
635  * to support the following operations.
636  */
637
638 struct passdb_ops {
639   /*
640    * Password database ops.
641    */
642   void *(*startsmbpwent)(BOOL);
643   void (*endsmbpwent)(void *);
644   unsigned long (*getsmbpwpos)(void *);
645   BOOL (*setsmbpwpos)(void *, unsigned long);
646
647   /*
648    * smb password database query functions.
649    */
650   struct smb_passwd *(*getsmbpwnam)(char *);
651   struct smb_passwd *(*getsmbpwuid)(uid_t);
652   struct smb_passwd *(*getsmbpwent)(void *);
653
654   /*
655    * smb password database modification functions.
656    */
657   BOOL (*add_smbpwd_entry)(struct smb_passwd *);
658   BOOL (*mod_smbpwd_entry)(struct smb_passwd *, BOOL);
659
660   /*
661    * Functions that manupulate a struct sam_passwd.
662    */
663   struct sam_passwd *(*getsam21pwent)(void *);
664
665   /*
666    * sam password database query functions.
667    */
668   struct sam_passwd *(*getsam21pwnam)(char *);
669   struct sam_passwd *(*getsam21pwuid)(uid_t);
670   struct sam_passwd *(*getsam21pwrid)(uint32);
671
672   /*
673    * sam password database modification functions.
674    */
675   BOOL (*add_sam21pwd_entry)(struct sam_passwd *);
676   BOOL (*mod_sam21pwd_entry)(struct sam_passwd *, BOOL);
677
678   /*
679    * sam query display info functions.
680    */
681   struct sam_disp_info *(*getsamdispnam)(char *);
682   struct sam_disp_info *(*getsamdisprid)(uint32);
683   struct sam_disp_info *(*getsamdispent)(void *);
684
685 #if 0
686   /*
687    * password checking functions
688    */
689   struct smb_passwd *(*smb_password_chal  )(char *username, char lm_pass[24], char nt_pass[24], char chal[8]);
690   struct smb_passwd *(*smb_password_check )(char *username, char lm_hash[16], char nt_hash[16]);
691   struct passwd     *(*unix_password_check)(char *username, char *pass, int pass_len);
692 #endif
693 };
694
695 /* this is used for smbstatus */
696
697 struct connect_record
698 {
699   int magic;
700   int pid;
701   int cnum;
702   int uid;
703   int gid;
704   char name[24];
705   char addr[24];
706   char machine[128];
707   time_t start;
708 };
709
710 /* This is used by smbclient to send it to a smbfs mount point */
711 struct connection_options {
712   int protocol;
713   /* Connection-Options */
714   uint32 max_xmit;
715   uint16 server_uid;
716   uint16 tid;
717   /* The following are LANMAN 1.0 options */
718   uint16 sec_mode;
719   uint16 max_mux;
720   uint16 max_vcs;
721   uint16 rawmode;
722   uint32 sesskey;
723   /* The following are NT LM 0.12 options */
724   uint32 maxraw;
725   uint32 capabilities;
726   uint16 serverzone;
727 };
728
729 /* the following are used by loadparm for option lists */
730 typedef enum
731 {
732   P_BOOL,P_BOOLREV,P_CHAR,P_INTEGER,P_OCTAL,
733   P_STRING,P_USTRING,P_GSTRING,P_UGSTRING,P_ENUM,P_SEP
734 } parm_type;
735
736 typedef enum
737 {
738   P_LOCAL,P_GLOBAL,P_SEPARATOR,P_NONE
739 } parm_class;
740
741 struct enum_list {
742         int value;
743         char *name;
744 };
745
746 struct parm_struct
747 {
748         char *label;
749         parm_type type;
750         parm_class class;
751         void *ptr;
752         BOOL (*special)(char *, char **);
753         struct enum_list *enum_list;
754         unsigned flags;
755         union {
756                 BOOL bvalue;
757                 int ivalue;
758                 char *svalue;
759                 char cvalue;
760         } def;
761 };
762
763
764 #define FLAG_BASIC 1 /* fundamental options */
765 #define FLAG_HIDE  2 /* options that should be hidden in SWAT */
766 #define FLAG_PRINT 4 /* printing options */
767 #define FLAG_GLOBAL 8 /* local options that should be globally settable in SWAT */
768
769 #ifndef LOCKING_VERSION
770 #define LOCKING_VERSION 4
771 #endif /* LOCKING_VERSION */
772
773 /* these are useful macros for checking validity of handles */
774 #define VALID_FNUM(fnum)   (((fnum) >= 0) && ((fnum) < MAX_FNUMS))
775 #define OPEN_FNUM(fnum)    (VALID_FNUM(fnum) && Files[fnum].open && !Files[fnum].is_directory)
776 #define VALID_CNUM(cnum)   (((cnum) >= 0) && ((cnum) < MAX_CONNECTIONS))
777 #define OPEN_CNUM(cnum)    (VALID_CNUM(cnum) && Connections[cnum].open)
778 #define IS_IPC(cnum)       (VALID_CNUM(cnum) && Connections[cnum].ipc)
779 #define IS_PRINT(cnum)       (VALID_CNUM(cnum) && Connections[cnum].printer)
780 #define FNUM_OK(fnum,c) (OPEN_FNUM(fnum) && (c)==Files[fnum].cnum)
781
782 #define CHECK_FNUM(fnum,c) if (!FNUM_OK(fnum,c)) \
783                                return(ERROR(ERRDOS,ERRbadfid))
784 #define CHECK_READ(fnum) if (!Files[fnum].can_read) \
785                                return(ERROR(ERRDOS,ERRbadaccess))
786 #define CHECK_WRITE(fnum) if (!Files[fnum].can_write) \
787                                return(ERROR(ERRDOS,ERRbadaccess))
788 #define CHECK_ERROR(fnum) if (HAS_CACHED_ERROR(fnum)) \
789                                return(CACHED_ERROR(fnum))
790
791 /* translates a connection number into a service number */
792 #define SNUM(cnum)         (Connections[cnum].service)
793
794 /* access various service details */
795 #define SERVICE(snum)      (lp_servicename(snum))
796 #define PRINTCAP           (lp_printcapname())
797 #define PRINTCOMMAND(snum) (lp_printcommand(snum))
798 #define PRINTERNAME(snum)  (lp_printername(snum))
799 #define CAN_WRITE(cnum)    (OPEN_CNUM(cnum) && !Connections[cnum].read_only)
800 #define VALID_SNUM(snum)   (lp_snum_ok(snum))
801 #define GUEST_OK(snum)     (VALID_SNUM(snum) && lp_guest_ok(snum))
802 #define GUEST_ONLY(snum)   (VALID_SNUM(snum) && lp_guest_only(snum))
803 #define CAN_SETDIR(snum)   (!lp_no_set_dir(snum))
804 #define CAN_PRINT(cnum)    (OPEN_CNUM(cnum) && lp_print_ok(SNUM(cnum)))
805 #define POSTSCRIPT(cnum)   (OPEN_CNUM(cnum) && lp_postscript(SNUM(cnum)))
806 #define MAP_HIDDEN(cnum)   (OPEN_CNUM(cnum) && lp_map_hidden(SNUM(cnum)))
807 #define MAP_SYSTEM(cnum)   (OPEN_CNUM(cnum) && lp_map_system(SNUM(cnum)))
808 #define MAP_ARCHIVE(cnum)   (OPEN_CNUM(cnum) && lp_map_archive(SNUM(cnum)))
809 #define IS_HIDDEN_PATH(cnum,path)  (is_in_path((path),Connections[(cnum)].hide_list))
810 #define IS_VETO_PATH(cnum,path)  (is_in_path((path),Connections[(cnum)].veto_list))
811 #define IS_VETO_OPLOCK_PATH(cnum,path)  (is_in_path((path),Connections[(cnum)].veto_oplock_list))
812
813 #define SMBENCRYPT()       (lp_encrypted_passwords())
814
815 /* the basic packet size, assuming no words or bytes */
816 #define smb_size 39
817
818 /* offsets into message for common items */
819 #define smb_com 8
820 #define smb_rcls 9
821 #define smb_reh 10
822 #define smb_err 11
823 #define smb_flg 13
824 #define smb_flg2 14
825 #define smb_reb 13
826 #define smb_tid 28
827 #define smb_pid 30
828 #define smb_uid 32
829 #define smb_mid 34
830 #define smb_wct 36
831 #define smb_vwv 37
832 #define smb_vwv0 37
833 #define smb_vwv1 39
834 #define smb_vwv2 41
835 #define smb_vwv3 43
836 #define smb_vwv4 45
837 #define smb_vwv5 47
838 #define smb_vwv6 49
839 #define smb_vwv7 51
840 #define smb_vwv8 53
841 #define smb_vwv9 55
842 #define smb_vwv10 57
843 #define smb_vwv11 59
844 #define smb_vwv12 61
845 #define smb_vwv13 63
846 #define smb_vwv14 65
847 #define smb_vwv15 67
848 #define smb_vwv16 69
849 #define smb_vwv17 71
850
851
852 /* the complete */
853 #define SMBmkdir      0x00   /* create directory */
854 #define SMBrmdir      0x01   /* delete directory */
855 #define SMBopen       0x02   /* open file */
856 #define SMBcreate     0x03   /* create file */
857 #define SMBclose      0x04   /* close file */
858 #define SMBflush      0x05   /* flush file */
859 #define SMBunlink     0x06   /* delete file */
860 #define SMBmv         0x07   /* rename file */
861 #define SMBgetatr     0x08   /* get file attributes */
862 #define SMBsetatr     0x09   /* set file attributes */
863 #define SMBread       0x0A   /* read from file */
864 #define SMBwrite      0x0B   /* write to file */
865 #define SMBlock       0x0C   /* lock byte range */
866 #define SMBunlock     0x0D   /* unlock byte range */
867 #define SMBctemp      0x0E   /* create temporary file */
868 #define SMBmknew      0x0F   /* make new file */
869 #define SMBchkpth     0x10   /* check directory path */
870 #define SMBexit       0x11   /* process exit */
871 #define SMBlseek      0x12   /* seek */
872 #define SMBtcon       0x70   /* tree connect */
873 #define SMBtconX      0x75   /* tree connect and X*/
874 #define SMBtdis       0x71   /* tree disconnect */
875 #define SMBnegprot    0x72   /* negotiate protocol */
876 #define SMBdskattr    0x80   /* get disk attributes */
877 #define SMBsearch     0x81   /* search directory */
878 #define SMBsplopen    0xC0   /* open print spool file */
879 #define SMBsplwr      0xC1   /* write to print spool file */
880 #define SMBsplclose   0xC2   /* close print spool file */
881 #define SMBsplretq    0xC3   /* return print queue */
882 #define SMBsends      0xD0   /* send single block message */
883 #define SMBsendb      0xD1   /* send broadcast message */
884 #define SMBfwdname    0xD2   /* forward user name */
885 #define SMBcancelf    0xD3   /* cancel forward */
886 #define SMBgetmac     0xD4   /* get machine name */
887 #define SMBsendstrt   0xD5   /* send start of multi-block message */
888 #define SMBsendend    0xD6   /* send end of multi-block message */
889 #define SMBsendtxt    0xD7   /* send text of multi-block message */
890
891 /* Core+ protocol */
892 #define SMBlockread       0x13   /* Lock a range and read */
893 #define SMBwriteunlock 0x14 /* Unlock a range then write */
894 #define SMBreadbraw   0x1a  /* read a block of data with no smb header */
895 #define SMBwritebraw  0x1d  /* write a block of data with no smb header */
896 #define SMBwritec     0x20  /* secondary write request */
897 #define SMBwriteclose 0x2c  /* write a file then close it */
898
899 /* dos extended protocol */
900 #define SMBreadBraw      0x1A   /* read block raw */
901 #define SMBreadBmpx      0x1B   /* read block multiplexed */
902 #define SMBreadBs        0x1C   /* read block (secondary response) */
903 #define SMBwriteBraw     0x1D   /* write block raw */
904 #define SMBwriteBmpx     0x1E   /* write block multiplexed */
905 #define SMBwriteBs       0x1F   /* write block (secondary request) */
906 #define SMBwriteC        0x20   /* write complete response */
907 #define SMBsetattrE      0x22   /* set file attributes expanded */
908 #define SMBgetattrE      0x23   /* get file attributes expanded */
909 #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
910 #define SMBtrans         0x25   /* transaction - name, bytes in/out */
911 #define SMBtranss        0x26   /* transaction (secondary request/response) */
912 #define SMBioctl         0x27   /* IOCTL */
913 #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
914 #define SMBcopy          0x29   /* copy */
915 #define SMBmove          0x2A   /* move */
916 #define SMBecho          0x2B   /* echo */
917 #define SMBopenX         0x2D   /* open and X */
918 #define SMBreadX         0x2E   /* read and X */
919 #define SMBwriteX        0x2F   /* write and X */
920 #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
921 #define SMBffirst        0x82   /* find first */
922 #define SMBfunique       0x83   /* find unique */
923 #define SMBfclose        0x84   /* find close */
924 #define SMBinvalid       0xFE   /* invalid command */
925
926 /* Extended 2.0 protocol */
927 #define SMBtrans2        0x32   /* TRANS2 protocol set */
928 #define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
929 #define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
930 #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
931 #define SMBulogoffX      0x74   /* user logoff */
932
933 /* NT SMB extensions. */
934 #define SMBnttrans       0xA0   /* NT transact */
935 #define SMBnttranss      0xA1   /* NT transact secondary */
936 #define SMBntcreateX     0xA2   /* NT create and X */
937 #define SMBntcancel      0xA4   /* NT cancel */
938
939 /* These are the TRANS2 sub commands */
940 #define TRANSACT2_OPEN                        0
941 #define TRANSACT2_FINDFIRST                   1
942 #define TRANSACT2_FINDNEXT                    2
943 #define TRANSACT2_QFSINFO                     3
944 #define TRANSACT2_SETFSINFO                   4
945 #define TRANSACT2_QPATHINFO                   5
946 #define TRANSACT2_SETPATHINFO                 6
947 #define TRANSACT2_QFILEINFO                   7
948 #define TRANSACT2_SETFILEINFO                 8
949 #define TRANSACT2_FSCTL                       9
950 #define TRANSACT2_IOCTL                     0xA
951 #define TRANSACT2_FINDNOTIFYFIRST           0xB
952 #define TRANSACT2_FINDNOTIFYNEXT            0xC
953 #define TRANSACT2_MKDIR                     0xD
954 #define TRANSACT2_SESSION_SETUP             0xE
955 #define TRANSACT2_GET_DFS_REFERRAL         0x10
956 #define TRANSACT2_REPORT_DFS_INCONSISTANCY 0x11
957
958 /* These are the NT transact sub commands. */
959 #define NT_TRANSACT_CREATE                1
960 #define NT_TRANSACT_IOCTL                 2
961 #define NT_TRANSACT_SET_SECURITY_DESC     3
962 #define NT_TRANSACT_NOTIFY_CHANGE         4
963 #define NT_TRANSACT_RENAME                5
964 #define NT_TRANSACT_QUERY_SECURITY_DESC   6
965
966 /* these are the trans2 sub fields for primary requests */
967 #define smb_tpscnt smb_vwv0
968 #define smb_tdscnt smb_vwv1
969 #define smb_mprcnt smb_vwv2
970 #define smb_mdrcnt smb_vwv3
971 #define smb_msrcnt smb_vwv4
972 #define smb_flags smb_vwv5
973 #define smb_timeout smb_vwv6
974 #define smb_pscnt smb_vwv9
975 #define smb_psoff smb_vwv10
976 #define smb_dscnt smb_vwv11
977 #define smb_dsoff smb_vwv12
978 #define smb_suwcnt smb_vwv13
979 #define smb_setup smb_vwv14
980 #define smb_setup0 smb_setup
981 #define smb_setup1 (smb_setup+2)
982 #define smb_setup2 (smb_setup+4)
983
984 /* these are for the secondary requests */
985 #define smb_spscnt smb_vwv2
986 #define smb_spsoff smb_vwv3
987 #define smb_spsdisp smb_vwv4
988 #define smb_sdscnt smb_vwv5
989 #define smb_sdsoff smb_vwv6
990 #define smb_sdsdisp smb_vwv7
991 #define smb_sfid smb_vwv8
992
993 /* and these for responses */
994 #define smb_tprcnt smb_vwv0
995 #define smb_tdrcnt smb_vwv1
996 #define smb_prcnt smb_vwv3
997 #define smb_proff smb_vwv4
998 #define smb_prdisp smb_vwv5
999 #define smb_drcnt smb_vwv6
1000 #define smb_droff smb_vwv7
1001 #define smb_drdisp smb_vwv8
1002
1003 /* these are for the NT trans primary request. */
1004 #define smb_nt_MaxSetupCount smb_vwv0
1005 #define smb_nt_Flags (smb_vwv0 + 1)
1006 #define smb_nt_TotalParameterCount (smb_vwv0 + 3)
1007 #define smb_nt_TotalDataCount (smb_vwv0 + 7)
1008 #define smb_nt_MaxParameterCount (smb_vwv0 + 11)
1009 #define smb_nt_MaxDataCount (smb_vwv0 + 15)
1010 #define smb_nt_ParameterCount (smb_vwv0 + 19)
1011 #define smb_nt_ParameterOffset (smb_vwv0 + 23)
1012 #define smb_nt_DataCount (smb_vwv0 + 27)
1013 #define smb_nt_DataOffset (smb_vwv0 + 31)
1014 #define smb_nt_SetupCount (smb_vwv0 + 35)
1015 #define smb_nt_Function (smb_vwv0 + 36)
1016 #define smb_nt_SetupStart (smb_vwv0 + 39)
1017
1018 /* these are for the NT trans secondary request. */
1019 #define smb_nts_TotalParameterCount (smb_vwv0 + 3)
1020 #define smb_nts_TotalDataCount (smb_vwv0 + 7)
1021 #define smb_nts_ParameterCount (smb_vwv0 + 11)
1022 #define smb_nts_ParameterOffset (smb_vwv0 + 15)
1023 #define smb_nts_ParameterDisplacement (smb_vwv0 + 19)
1024 #define smb_nts_DataCount (smb_vwv0 + 23)
1025 #define smb_nts_DataOffset (smb_vwv0 + 27)
1026 #define smb_nts_DataDisplacement (smb_vwv0 + 31)
1027
1028 /* these are for the NT trans reply. */
1029 #define smb_ntr_TotalParameterCount (smb_vwv0 + 3)
1030 #define smb_ntr_TotalDataCount (smb_vwv0 + 7)
1031 #define smb_ntr_ParameterCount (smb_vwv0 + 11)
1032 #define smb_ntr_ParameterOffset (smb_vwv0 + 15)
1033 #define smb_ntr_ParameterDisplacement (smb_vwv0 + 19)
1034 #define smb_ntr_DataCount (smb_vwv0 + 23)
1035 #define smb_ntr_DataOffset (smb_vwv0 + 27)
1036 #define smb_ntr_DataDisplacement (smb_vwv0 + 31)
1037
1038 /* these are for the NT create_and_X */
1039 #define smb_ntcreate_NameLength (smb_vwv0 + 5)
1040 #define smb_ntcreate_Flags (smb_vwv0 + 7)
1041 #define smb_ntcreate_RootDirectoryFid (smb_wvw0 + 11)
1042 #define smb_ntcreate_DesiredAccess (smb_vwv0 + 15)
1043 #define smb_ntcreate_AllocationSize (smb_vwv0 + 19)
1044 #define smb_ntcreate_FileAttributes (smb_vwv0 + 27)
1045 #define smb_ntcreate_ShareAccess (smb_vwv0 + 31)
1046 #define smb_ntcreate_CreateDisposition (smb_vwv0 + 35)
1047 #define smb_ntcreate_CreateOptions (smb_vwv0 + 39)
1048 #define smb_ntcreate_ImpersonationLevel (smb_vwv0 + 43)
1049 #define smb_ntcreate_SecurityFlags (smb_vwv0 + 47)
1050
1051 /* these are the constants used in the above call. */
1052 /* DesiredAccess */
1053 /* File Specific access rights. */
1054 #define FILE_READ_DATA        0x001
1055 #define FILE_WRITE_DATA       0x002
1056 #define FILE_APPEND_DATA      0x004
1057 #define FILE_READ_EA          0x008
1058 #define FILE_WRITE_EA         0x010
1059 #define FILE_EXECUTE          0x020
1060 #define FILE_DELETE_CHILD     0x040
1061 #define FILE_READ_ATTRIBUTES  0x080
1062 #define FILE_WRITE_ATTRIBUTES 0x100
1063  
1064 /* Generic access masks & rights. */
1065 #define SPECIFIC_RIGHTS_MASK 0x00FFFFL
1066 #define STANDARD_RIGHTS_MASK 0xFF0000L
1067 #define DELETE_ACCESS        (1L<<16)
1068 #define READ_CONTROL_ACCESS  (1L<<17)
1069 #define WRITE_DAC_ACCESS     (1L<<18)
1070 #define WRITE_OWNER_ACCESS   (1L<<19)
1071 #define SYNCHRONIZE_ACCESS   (1L<<20)
1072 #define SYSTEM_SECURITY_ACCESS (1L<<24)
1073
1074 /* Flags field. */
1075 #define REQUEST_OPLOCK 2
1076 #define REQUEST_BATCH_OPLOCK 4
1077 #define OPEN_DIRECTORY 8
1078
1079 /* ShareAccess field. */
1080 #define FILE_SHARE_NONE 0 /* Cannot be used in bitmask. */
1081 #define FILE_SHARE_READ 1
1082 #define FILE_SHARE_WRITE 2
1083 #define FILE_SHARE_DELETE 4
1084
1085 /* FileAttributesField */
1086 #define FILE_ATTRIBUTE_READONLY aRONLY
1087 #define FILE_ATTRIBUTE_HIDDEN aHIDDEN
1088 #define FILE_ATTRIBUTE_SYSTEM aSYSTEM
1089 #define FILE_ATTRIBUTE_DIRECTORY aDIR
1090 #define FILE_ATTRIBUTE_ARCHIVE aARCH
1091 #define FILE_ATTRIBUTE_NORMAL 0x80L
1092 #define FILE_ATTRIBUTE_TEMPORARY 0x100L
1093 #define FILE_ATTRIBUTE_COMPRESSED 0x800L
1094 #define SAMBA_ATTRIBUTES_MASK 0x7F
1095
1096 /* Flags - combined with attributes. */
1097 #define FILE_FLAG_WRITE_THROUGH    0x80000000L
1098 #define FILE_FLAG_NO_BUFFERING     0x20000000L
1099 #define FILE_FLAG_RANDOM_ACCESS    0x10000000L
1100 #define FILE_FLAG_SEQUENTIAL_SCAN  0x08000000L
1101 #define FILE_FLAG_DELETE_ON_CLOSE  0x04000000L
1102 #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000L
1103 #define FILE_FLAG_POSIX_SEMANTICS  0x01000000L
1104
1105 /* CreateDisposition field. */
1106 #define FILE_SUPERSEDE 0
1107 #define FILE_OPEN 1
1108 #define FILE_CREATE 2
1109 #define FILE_OPEN_IF 3
1110 #define FILE_OVERWRITE 4
1111 #define FILE_OVERWRITE_IF 5
1112
1113 /* Responses when opening a file. */
1114 #define FILE_WAS_OPENED 1
1115 #define FILE_WAS_CREATED 2
1116 #define FILE_WAS_OVERWRITTEN 3
1117
1118 /* File type flags */
1119 #define FILE_TYPE_DISK  0
1120 #define FILE_TYPE_BYTE_MODE_PIPE 1
1121 #define FILE_TYPE_MESSAGE_MODE_PIPE 2
1122 #define FILE_TYPE_PRINTER 3
1123 #define FILE_TYPE_COMM_DEVICE 4
1124 #define FILE_TYPE_UNKNOWN 0xFFFF
1125
1126 /* Flag for NT transact rename call. */
1127 #define RENAME_REPLACE_IF_EXISTS 1
1128
1129 /* Filesystem Attributes. */
1130 #define FILE_CASE_SENSITIVE_SEARCH 0x1
1131 #define FILE_CASE_PRESERVED_NAMES 0x2
1132 #define FILE_UNICODE_ON_DISK 0x4
1133 #define FILE_PERISITANT_ACLS 0x8
1134
1135 /* where to find the base of the SMB packet proper */
1136 #define smb_base(buf) (((char *)(buf))+4)
1137
1138
1139 #define SMB_SUCCESS 0  /* The request was successful. */
1140 #define ERRDOS 0x01 /*  Error is from the core DOS operating system set. */
1141 #define ERRSRV 0x02  /* Error is generated by the server network file manager.*/
1142 #define ERRHRD 0x03  /* Error is an hardware error. */
1143 #define ERRCMD 0xFF  /* Command was not in the "SMB" format. */
1144
1145 #ifdef HAVE_STDARG_H
1146 int Debug1(char *, ...); 
1147 int slprintf(char *str, int n, char *format, ...);
1148 #else
1149 int Debug1(); 
1150 int slprintf();
1151 #endif
1152
1153 #ifdef WITH_DFS
1154 void dfs_unlogin(void);
1155 extern int dcelogin_atmost_once;
1156 #endif
1157
1158 #if AJT
1159 void ajt_panic(void);
1160 #endif
1161
1162 #ifdef NOSTRDUP
1163 char *strdup(char *s);
1164 #endif
1165
1166 #ifndef MIN
1167 #define MIN(a,b) ((a)<(b)?(a):(b))
1168 #endif
1169 #ifndef MAX
1170 #define MAX(a,b) ((a)>(b)?(a):(b))
1171 #endif
1172
1173 #ifndef ABS
1174 #define ABS(a) ((a)>0?(a):(-(a)))
1175 #endif
1176
1177 #ifndef SIGNAL_CAST
1178 #define SIGNAL_CAST (RETSIGTYPE (*)())
1179 #endif
1180
1181 #ifndef SELECT_CAST
1182 #define SELECT_CAST
1183 #endif
1184
1185
1186 /* Some POSIX definitions for those without */
1187  
1188 #ifndef S_IFDIR
1189 #define S_IFDIR         0x4000
1190 #endif
1191 #ifndef S_ISDIR
1192 #define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
1193 #endif
1194 #ifndef S_IRWXU
1195 #define S_IRWXU 00700           /* read, write, execute: owner */
1196 #endif
1197 #ifndef S_IRUSR
1198 #define S_IRUSR 00400           /* read permission: owner */
1199 #endif
1200 #ifndef S_IWUSR
1201 #define S_IWUSR 00200           /* write permission: owner */
1202 #endif
1203 #ifndef S_IXUSR
1204 #define S_IXUSR 00100           /* execute permission: owner */
1205 #endif
1206 #ifndef S_IRWXG
1207 #define S_IRWXG 00070           /* read, write, execute: group */
1208 #endif
1209 #ifndef S_IRGRP
1210 #define S_IRGRP 00040           /* read permission: group */
1211 #endif
1212 #ifndef S_IWGRP
1213 #define S_IWGRP 00020           /* write permission: group */
1214 #endif
1215 #ifndef S_IXGRP
1216 #define S_IXGRP 00010           /* execute permission: group */
1217 #endif
1218 #ifndef S_IRWXO
1219 #define S_IRWXO 00007           /* read, write, execute: other */
1220 #endif
1221 #ifndef S_IROTH
1222 #define S_IROTH 00004           /* read permission: other */
1223 #endif
1224 #ifndef S_IWOTH
1225 #define S_IWOTH 00002           /* write permission: other */
1226 #endif
1227 #ifndef S_IXOTH
1228 #define S_IXOTH 00001           /* execute permission: other */
1229 #endif
1230
1231
1232 /* these are used in NetServerEnum to choose what to receive */
1233 #define SV_TYPE_WORKSTATION         0x00000001
1234 #define SV_TYPE_SERVER              0x00000002
1235 #define SV_TYPE_SQLSERVER           0x00000004
1236 #define SV_TYPE_DOMAIN_CTRL         0x00000008
1237 #define SV_TYPE_DOMAIN_BAKCTRL      0x00000010
1238 #define SV_TYPE_TIME_SOURCE         0x00000020
1239 #define SV_TYPE_AFP                 0x00000040
1240 #define SV_TYPE_NOVELL              0x00000080
1241 #define SV_TYPE_DOMAIN_MEMBER       0x00000100
1242 #define SV_TYPE_PRINTQ_SERVER       0x00000200
1243 #define SV_TYPE_DIALIN_SERVER       0x00000400
1244 #define SV_TYPE_SERVER_UNIX         0x00000800
1245 #define SV_TYPE_NT                  0x00001000
1246 #define SV_TYPE_WFW                 0x00002000
1247 #define SV_TYPE_SERVER_MFPN         0x00004000
1248 #define SV_TYPE_SERVER_NT           0x00008000
1249 #define SV_TYPE_POTENTIAL_BROWSER   0x00010000
1250 #define SV_TYPE_BACKUP_BROWSER      0x00020000
1251 #define SV_TYPE_MASTER_BROWSER      0x00040000
1252 #define SV_TYPE_DOMAIN_MASTER       0x00080000
1253 #define SV_TYPE_SERVER_OSF          0x00100000
1254 #define SV_TYPE_SERVER_VMS          0x00200000
1255 #define SV_TYPE_WIN95_PLUS          0x00400000
1256 #define SV_TYPE_ALTERNATE_XPORT     0x20000000  
1257 #define SV_TYPE_LOCAL_LIST_ONLY     0x40000000  
1258 #define SV_TYPE_DOMAIN_ENUM         0x80000000
1259 #define SV_TYPE_ALL                 0xFFFFFFFF  
1260
1261 /* what server type are we currently  - JHT Says we ARE 4.20 */
1262 /* this was set by JHT in liaison with Jeremy Allison early 1997 */
1263 /* setting to 4.20 at same time as announcing ourselves as NT Server */
1264 /* History: */
1265 /* Version 4.0 - never made public */
1266 /* Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9 */
1267 /*              - Reappeared in 1.9.16p11 with fixed smbd services */
1268 /* Version 4.20 - To indicate that nmbd and browsing now works better */
1269
1270 #define DEFAULT_MAJOR_VERSION 0x04
1271 #define DEFAULT_MINOR_VERSION 0x02
1272
1273 /* Browser Election Values */
1274 #define BROWSER_ELECTION_VERSION        0x010f
1275 #define BROWSER_CONSTANT        0xaa55
1276
1277 /* NT Flags2 bits - cifs6.txt section 3.1.2 */
1278    
1279 #define FLAGS2_LONG_PATH_COMPONENTS   0x0001
1280 #define FLAGS2_EXTENDED_ATTRIBUTES    0x0002
1281 #define FLAGS2_DFS_PATHNAMES          0x1000
1282 #define FLAGS2_READ_PERMIT_NO_EXECUTE 0x2000
1283 #define FLAGS2_32_BIT_ERROR_CODES     0x4000 
1284 #define FLAGS2_UNICODE_STRINGS        0x8000
1285
1286 /* Capabilities.  see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
1287
1288 #define CAP_RAW_MODE         0x0001
1289 #define CAP_MPX_MODE         0x0002
1290 #define CAP_UNICODE          0x0004
1291 #define CAP_LARGE_FILES      0x0008
1292 #define CAP_NT_SMBS          0x0010
1293 #define CAP_RPC_REMOTE_APIS  0x0020
1294 #define CAP_STATUS32         0x0040
1295 #define CAP_LEVEL_II_OPLOCKS 0x0080
1296 #define CAP_LOCK_AND_READ    0x0100
1297 #define CAP_NT_FIND          0x0200
1298 #define CAP_DFS              0x1000
1299 #define CAP_LARGE_READX      0x4000
1300
1301 /* protocol types. It assumes that higher protocols include lower protocols
1302    as subsets */
1303 enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
1304
1305 /* security levels */
1306 enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER,SEC_DOMAIN};
1307
1308 /* printing types */
1309 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
1310                      PRINT_QNX,PRINT_PLP,PRINT_LPRNG,PRINT_SOFTQ};
1311
1312 /* Remote architectures we know about. */
1313 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_SAMBA};
1314
1315 /* case handling */
1316 enum case_handling {CASE_LOWER,CASE_UPPER};
1317
1318 #ifdef WITH_SSL
1319 /* SSL version options */
1320 enum ssl_version_enum {SMB_SSL_V2,SMB_SSL_V3,SMB_SSL_V23,SMB_SSL_TLS1};
1321 #endif /* WITH_SSL */
1322
1323 /* Macros to get at offsets within smb_lkrng and smb_unlkrng
1324    structures. We cannot define these as actual structures
1325    due to possible differences in structure packing
1326    on different machines/compilers. */
1327
1328 #define SMB_LPID_OFFSET(indx) (10 * (indx))
1329 #define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
1330 #define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
1331
1332 /* Macro to cache an error in a write_bmpx_struct */
1333 #define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
1334                             w->wr_discard = True, -1)
1335 /* Macro to test if an error has been cached for this fnum */
1336 #define HAS_CACHED_ERROR(fnum) (Files[(fnum)].open && \
1337                                 Files[(fnum)].wbmpx_ptr && \
1338                                 Files[(fnum)].wbmpx_ptr->wr_discard)
1339 /* Macro to turn the cached error into an error packet */
1340 #define CACHED_ERROR(fnum) cached_error_packet(inbuf,outbuf,fnum,__LINE__)
1341
1342 /* these are the datagram types */
1343 #define DGRAM_DIRECT_UNIQUE 0x10
1344
1345 #define ERROR(class,x) error_packet(inbuf,outbuf,class,x,__LINE__)
1346
1347 /* this is how errors are generated */
1348 #define UNIXERROR(defclass,deferror) unix_error_packet(inbuf,outbuf,defclass,deferror,__LINE__)
1349
1350 #define ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
1351
1352 /*
1353  * Global value meaing that the smb_uid field should be
1354  * ingored (in share level security and protocol level == CORE)
1355  */
1356
1357 #define UID_FIELD_INVALID 0
1358 #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
1359
1360 /* Defines needed for multi-codepage support. */
1361 #define MSDOS_LATIN_1_CODEPAGE 850
1362 #define KANJI_CODEPAGE 932
1363 #define HANGUL_CODEPAGE 949
1364 #define BIG5_CODEPAGE 950
1365 #define SIMPLIFIED_CHINESE_CODEPAGE 936
1366
1367 #ifdef KANJI
1368 /* 
1369  * Default client code page - Japanese 
1370  */
1371 #define DEFAULT_CLIENT_CODE_PAGE KANJI_CODEPAGE
1372 #else /* KANJI */
1373 /* 
1374  * Default client code page - 850 - Western European 
1375  */
1376 #define DEFAULT_CLIENT_CODE_PAGE MSDOS_LATIN_1_CODEPAGE
1377 #endif /* KANJI */
1378
1379 /* 
1380  * Size of buffer to use when moving files across filesystems. 
1381  */
1382 #define COPYBUF_SIZE (8*1024)
1383
1384 /* 
1385  * Integers used to override error codes. 
1386  */
1387 extern int unix_ERR_class;
1388 extern int unix_ERR_code;
1389
1390 /*
1391  * Map the Core and Extended Oplock requesst bits down
1392  * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK).
1393  */
1394
1395 /*
1396  * Core protocol.
1397  */
1398 #define CORE_OPLOCK_REQUEST(inbuf) ((CVAL(inbuf,smb_flg)&((1<<5)|(1<<6)))>>5)
1399
1400 /*
1401  * Extended protocol.
1402  */
1403 #define EXTENDED_OPLOCK_REQUEST(inbuf) ((SVAL(inbuf,smb_vwv2)&((1<<1)|(1<<2)))>>1)
1404
1405 /* Lock types. */
1406 #define LOCKING_ANDX_SHARED_LOCK 0x1
1407 #define LOCKING_ANDX_OPLOCK_RELEASE 0x2
1408 #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x4
1409 #define LOCKING_ANDX_CANCEL_LOCK 0x8
1410 #define LOCKING_ANDX_LARGE_FILES 0x10
1411
1412 /* Oplock levels */
1413 #define OPLOCKLEVEL_NONE 0
1414 #define OPLOCKLEVEL_II 1
1415
1416 /*
1417  * Bits we test with.
1418  */
1419 #define EXCLUSIVE_OPLOCK 1
1420 #define BATCH_OPLOCK 2
1421
1422 #define CORE_OPLOCK_GRANTED (1<<5)
1423 #define EXTENDED_OPLOCK_GRANTED (1<<15)
1424
1425 /*
1426  * Loopback command offsets.
1427  */
1428
1429 #define UDP_CMD_LEN_OFFSET 0
1430 #define UDP_CMD_PORT_OFFSET 4
1431 #define UDP_CMD_HEADER_LEN 6
1432
1433 #define UDP_MESSAGE_CMD_OFFSET 0
1434
1435 /*
1436  * Oplock break command code to send over the udp socket.
1437  * 
1438  * Form of this is :
1439  *
1440  *  0     2       6        10       14      18       22
1441  *  +----+--------+--------+--------+-------+--------+
1442  *  | cmd| pid    | dev    | inode  | sec   |  usec  |
1443  *  +----+--------+--------+--------+-------+--------+
1444  */
1445
1446 #define OPLOCK_BREAK_CMD 0x1
1447 #define OPLOCK_BREAK_PID_OFFSET 2
1448 #define OPLOCK_BREAK_DEV_OFFSET 6
1449 #define OPLOCK_BREAK_INODE_OFFSET 10
1450 #define OPLOCK_BREAK_SEC_OFFSET 14
1451 #define OPLOCK_BREAK_USEC_OFFSET 18
1452 #define OPLOCK_BREAK_MSG_LEN 22
1453
1454
1455 #define CMD_REPLY 0x8000
1456
1457 #endif /* _SMB_H */
1458
1459 #include "ntdomain.h"
1460
1461 /* _SMB_H */