Ticket 1551: Update GPL version from 2 to 3
[midnight-commander.git] / src / vfs / smbfs / helpers / include / smb.h
blob5db911d75d5d6e715feafbdbdb11fce00ff9309e
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 SMB parameters and setup
5 */
6 #ifndef _SMB_H
7 #define _SMB_H
9 #define BUFFER_SIZE (0xFFFF)
10 #define SAFETY_MARGIN 1024
12 #define NMB_PORT 137
13 #define DGRAM_PORT 138
14 #define SMB_PORT 139
16 #define False (0)
17 #define True (1)
18 #define BOOLSTR(b) ((b) ? "Yes" : "No")
19 #define BITSETB(ptr,bit) ((((char *)ptr)[0] & (1<<(bit)))!=0)
20 #define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0)
22 #define IS_BITS_SET_ALL(var,bit) (((var)&(bit))==(bit))
23 #define IS_BITS_SET_SOME(var,bit) (((var)&(bit))!=0)
24 #define IS_BITS_CLR_ALL(var,bit) (((var)&(bit))==0)
26 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2)))
28 typedef int BOOL;
30 /* limiting size of ipc replies */
31 #define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024))
33 #define SIZEOFWORD 2
35 #ifndef DEF_CREATE_MASK
36 #define DEF_CREATE_MASK (0755)
37 #endif
39 /* how long to wait for secondary SMB packets (milli-seconds) */
40 #define SMB_SECONDARY_WAIT (60*1000)
42 /* -------------------------------------------------------------------------- **
43 * Debugging code. See also debug.c
46 /* mkproto.awk has trouble with ifdef'd function definitions (it ignores
47 * the #ifdef directive and will read both definitions, thus creating two
48 * diffferent prototype declarations), so we must do these by hand.
50 /* I know the __attribute__ stuff is ugly, but it does ensure we get the
51 arguemnts to DEBUG() right. We have got them wrong too often in the
52 past */
53 #ifdef HAVE_STDARG_H
54 int Debug1( const char *, ... )
55 #ifdef __GNUC__
56 __attribute__ ((format (printf, 1, 2)))
57 #endif
59 BOOL dbgtext( const char *, ... )
60 #ifdef __GNUC__
61 __attribute__ ((format (printf, 1, 2)))
62 #endif
64 #else
65 int Debug1();
66 BOOL dbgtext();
67 #endif
69 /* If we have these macros, we can add additional info to the header. */
70 #ifdef HAVE_FILE_MACRO
71 #define FILE_MACRO (__FILE__)
72 #else
73 #define FILE_MACRO ("")
74 #endif
76 #ifdef HAVE_FUNCTION_MACRO
77 #define FUNCTION_MACRO (__FUNCTION__)
78 #else
79 #define FUNCTION_MACRO ("")
80 #endif
82 /* Debugging macros.
83 * DEBUGLVL() - If level is <= the system-wide DEBUGLEVEL then generate a
84 * header using the default macros for file, line, and
85 * function name.
86 * Returns True if the debug level was <= DEBUGLEVEL.
87 * Example usage:
88 * if( DEBUGLVL( 2 ) )
89 * dbgtext( "Some text.\n" );
90 * DEGUG() - Good old DEBUG(). Each call to DEBUG() will generate a new
91 * header *unless* the previous debug output was unterminated
92 * (i.e., no '\n'). See debug.c:dbghdr() for more info.
93 * Example usage:
94 * DEBUG( 2, ("Some text.\n") );
95 * DEBUGADD() - If level <= DEBUGLEVEL, then the text is appended to the
96 * current message (i.e., no header).
97 * Usage:
98 * DEBUGADD( 2, ("Some additional text.\n") );
100 #define DEBUGLVL( level ) \
101 ( (DEBUGLEVEL >= (level)) \
102 && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
104 #if 0
106 #define DEBUG( level, body ) \
107 ( ( DEBUGLEVEL >= (level) \
108 && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) ) \
109 ? (void)(dbgtext body) : (void)0 )
111 #define DEBUGADD( level, body ) \
112 ( (DEBUGLEVEL >= (level)) ? (void)(dbgtext body) : (void)0 )
114 #else
116 #define DEBUG( level, body ) \
117 (void)( (DEBUGLEVEL >= (level)) \
118 && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \
119 && (dbgtext body) )
121 #define DEBUGADD( level, body ) \
122 (void)( (DEBUGLEVEL >= (level)) && (dbgtext body) )
124 #endif
126 /* End Debugging code section.
127 * -------------------------------------------------------------------------- **
130 /* this defines the error codes that receive_smb can put in smb_read_error */
131 #define READ_TIMEOUT 1
132 #define READ_EOF 2
133 #define READ_ERROR 3
136 #define DIR_STRUCT_SIZE 43
138 /* these define all the command types recognised by the server - there
139 are lots of gaps so probably there are some rare commands that are not
140 implemented */
142 #define pSETDIR '\377'
144 /* these define the attribute byte as seen by DOS */
145 #define aRONLY (1L<<0)
146 #define aHIDDEN (1L<<1)
147 #define aSYSTEM (1L<<2)
148 #define aVOLID (1L<<3)
149 #define aDIR (1L<<4)
150 #define aARCH (1L<<5)
152 /* for readability... */
153 #define IS_DOS_READONLY(test_mode) (((test_mode) & aRONLY) != 0)
154 #define IS_DOS_DIR(test_mode) (((test_mode) & aDIR) != 0)
155 #define IS_DOS_ARCHIVE(test_mode) (((test_mode) & aARCH) != 0)
156 #define IS_DOS_SYSTEM(test_mode) (((test_mode) & aSYSTEM) != 0)
157 #define IS_DOS_HIDDEN(test_mode) (((test_mode) & aHIDDEN) != 0)
159 /* deny modes */
160 #define DENY_DOS 0
161 #define DENY_ALL 1
162 #define DENY_WRITE 2
163 #define DENY_READ 3
164 #define DENY_NONE 4
165 #define DENY_FCB 7
167 /* open modes */
168 #define DOS_OPEN_RDONLY 0
169 #define DOS_OPEN_WRONLY 1
170 #define DOS_OPEN_RDWR 2
171 #define DOS_OPEN_FCB 0xF
173 /* define shifts and masks for share and open modes. */
174 #define OPEN_MODE_MASK 0xF
175 #define SHARE_MODE_SHIFT 4
176 #define SHARE_MODE_MASK 0x7
177 #define GET_OPEN_MODE(x) ((x) & OPEN_MODE_MASK)
178 #define SET_OPEN_MODE(x) ((x) & OPEN_MODE_MASK)
179 #define GET_DENY_MODE(x) (((x)>>SHARE_MODE_SHIFT) & SHARE_MODE_MASK)
180 #define SET_DENY_MODE(x) ((x)<<SHARE_MODE_SHIFT)
182 /* Sync on open file (not sure if used anymore... ?) */
183 #define FILE_SYNC_OPENMODE (1<<14)
184 #define GET_FILE_SYNC_OPENMODE(x) (((x) & FILE_SYNC_OPENMODE) ? True : False)
186 /* allow delete on open file mode (used by NT SMB's). */
187 #define ALLOW_SHARE_DELETE (1<<15)
188 #define GET_ALLOW_SHARE_DELETE(x) (((x) & ALLOW_SHARE_DELETE) ? True : False)
189 #define SET_ALLOW_SHARE_DELETE(x) ((x) ? ALLOW_SHARE_DELETE : 0)
191 /* delete on close flag (used by NT SMB's). */
192 #define DELETE_ON_CLOSE_FLAG (1<<16)
193 #define GET_DELETE_ON_CLOSE_FLAG(x) (((x) & DELETE_ON_CLOSE_FLAG) ? True : False)
194 #define SET_DELETE_ON_CLOSE_FLAG(x) ((x) ? DELETE_ON_CLOSE_FLAG : 0)
196 /* open disposition values */
197 #define FILE_EXISTS_FAIL 0
198 #define FILE_EXISTS_OPEN 1
199 #define FILE_EXISTS_TRUNCATE 2
201 /* mask for open disposition. */
202 #define FILE_OPEN_MASK 0x3
204 #define GET_FILE_OPEN_DISPOSITION(x) ((x) & FILE_OPEN_MASK)
205 #define SET_FILE_OPEN_DISPOSITION(x) ((x) & FILE_OPEN_MASK)
207 /* The above can be OR'ed with... */
208 #define FILE_CREATE_IF_NOT_EXIST 0x10
209 #define FILE_FAIL_IF_NOT_EXIST 0
211 #define GET_FILE_CREATE_DISPOSITION(x) ((x) & (FILE_CREATE_IF_NOT_EXIST|FILE_FAIL_IF_NOT_EXIST))
213 /* share types */
214 #define STYPE_DISKTREE 0 /* Disk drive */
215 #define STYPE_PRINTQ 1 /* Spooler queue */
216 #define STYPE_DEVICE 2 /* Serial device */
217 #define STYPE_IPC 3 /* Interprocess communication (IPC) */
218 #define STYPE_HIDDEN 0x80000000 /* share is a hidden one (ends with $) */
220 /* SMB X/Open error codes for the ERRDOS error class */
221 #define ERRbadfunc 1 /* Invalid function (or system call) */
222 #define ERRbadfile 2 /* File not found (pathname error) */
223 #define ERRbadpath 3 /* Directory not found */
224 #define ERRnofids 4 /* Too many open files */
225 #define ERRnoaccess 5 /* Access denied */
226 #define ERRbadfid 6 /* Invalid fid */
227 #define ERRnomem 8 /* Out of memory */
228 #define ERRbadmem 9 /* Invalid memory block address */
229 #define ERRbadenv 10 /* Invalid environment */
230 #define ERRbadaccess 12 /* Invalid open mode */
231 #define ERRbaddata 13 /* Invalid data (only from ioctl call) */
232 #define ERRres 14 /* reserved */
233 #define ERRbaddrive 15 /* Invalid drive */
234 #define ERRremcd 16 /* Attempt to delete current directory */
235 #define ERRdiffdevice 17 /* rename/move across different filesystems */
236 #define ERRnofiles 18 /* no more files found in file search */
237 #define ERRbadshare 32 /* Share mode on file conflict with open mode */
238 #define ERRlock 33 /* Lock request conflicts with existing lock */
239 #define ERRunsup 50 /* Request unsupported, returned by Win 95, RJS 20Jun98 */
240 #define ERRfilexists 80 /* File in operation already exists */
241 #define ERRcannotopen 110 /* Cannot open the file specified */
242 #define ERRunknownlevel 124
243 #define ERRrename 183
244 #define ERRbadpipe 230 /* Named pipe invalid */
245 #define ERRpipebusy 231 /* All instances of pipe are busy */
246 #define ERRpipeclosing 232 /* named pipe close in progress */
247 #define ERRnotconnected 233 /* No process on other end of named pipe */
248 #define ERRmoredata 234 /* More data to be returned */
249 #define ERRbaddirectory 267 /* Invalid directory name in a path. */
250 #define ERROR_EAS_DIDNT_FIT 275 /* Extended attributes didn't fit */
251 #define ERROR_EAS_NOT_SUPPORTED 282 /* Extended attributes not supported */
252 #define ERROR_NOTIFY_ENUM_DIR 1022 /* Buffer too small to return change notify. */
253 #define ERRunknownipc 2142
256 /* here's a special one from observing NT */
257 #define ERRnoipc 66 /* don't support ipc */
259 /* Error codes for the ERRSRV class */
261 #define ERRerror 1 /* Non specific error code */
262 #define ERRbadpw 2 /* Bad password */
263 #define ERRbadtype 3 /* reserved */
264 #define ERRaccess 4 /* No permissions to do the requested operation */
265 #define ERRinvnid 5 /* tid invalid */
266 #define ERRinvnetname 6 /* Invalid servername */
267 #define ERRinvdevice 7 /* Invalid device */
268 #define ERRqfull 49 /* Print queue full */
269 #define ERRqtoobig 50 /* Queued item too big */
270 #define ERRinvpfid 52 /* Invalid print file in smb_fid */
271 #define ERRsmbcmd 64 /* Unrecognised command */
272 #define ERRsrverror 65 /* smb server internal error */
273 #define ERRfilespecs 67 /* fid and pathname invalid combination */
274 #define ERRbadlink 68 /* reserved */
275 #define ERRbadpermits 69 /* Access specified for a file is not valid */
276 #define ERRbadpid 70 /* reserved */
277 #define ERRsetattrmode 71 /* attribute mode invalid */
278 #define ERRpaused 81 /* Message server paused */
279 #define ERRmsgoff 82 /* Not receiving messages */
280 #define ERRnoroom 83 /* No room for message */
281 #define ERRrmuns 87 /* too many remote usernames */
282 #define ERRtimeout 88 /* operation timed out */
283 #define ERRnoresource 89 /* No resources currently available for request. */
284 #define ERRtoomanyuids 90 /* too many userids */
285 #define ERRbaduid 91 /* bad userid */
286 #define ERRuseMPX 250 /* temporarily unable to use raw mode, use MPX mode */
287 #define ERRuseSTD 251 /* temporarily unable to use raw mode, use standard mode */
288 #define ERRcontMPX 252 /* resume MPX mode */
289 #define ERRbadPW /* reserved */
290 #define ERRnosupport 0xFFFF
291 #define ERRunknownsmb 22 /* from NT 3.5 response */
294 /* Error codes for the ERRHRD class */
296 #define ERRnowrite 19 /* read only media */
297 #define ERRbadunit 20 /* Unknown device */
298 #define ERRnotready 21 /* Drive not ready */
299 #define ERRbadcmd 22 /* Unknown command */
300 #define ERRdata 23 /* Data (CRC) error */
301 #define ERRbadreq 24 /* Bad request structure length */
302 #define ERRseek 25
303 #define ERRbadmedia 26
304 #define ERRbadsector 27
305 #define ERRnopaper 28
306 #define ERRwrite 29 /* write fault */
307 #define ERRread 30 /* read fault */
308 #define ERRgeneral 31 /* General hardware failure */
309 #define ERRwrongdisk 34
310 #define ERRFCBunavail 35
311 #define ERRsharebufexc 36 /* share buffer exceeded */
312 #define ERRdiskfull 39
315 typedef char pstring[1024];
316 typedef char fstring[128];
318 /* pipe string names */
319 #define PIPE_LANMAN "\\PIPE\\LANMAN"
320 #define PIPE_SRVSVC "\\PIPE\\srvsvc"
321 #define PIPE_SAMR "\\PIPE\\samr"
322 #define PIPE_WINREG "\\PIPE\\winreg"
323 #define PIPE_WKSSVC "\\PIPE\\wkssvc"
324 #define PIPE_NETLOGON "\\PIPE\\NETLOGON"
325 #define PIPE_NTLSA "\\PIPE\\ntlsa"
326 #define PIPE_NTSVCS "\\PIPE\\ntsvcs"
327 #define PIPE_LSASS "\\PIPE\\lsass"
328 #define PIPE_LSARPC "\\PIPE\\lsarpc"
331 /* 64 bit time (100usec) since ????? - cifs6.txt, section 3.5, page 30 */
332 typedef struct nttime_info
334 uint32 low;
335 uint32 high;
337 } NTTIME;
339 /* Allowable account control bits */
340 #define ACB_DISABLED 0x0001 /* 1 = User account disabled */
341 #define ACB_HOMDIRREQ 0x0002 /* 1 = Home directory required */
342 #define ACB_PWNOTREQ 0x0004 /* 1 = User password not required */
343 #define ACB_TEMPDUP 0x0008 /* 1 = Temporary duplicate account */
344 #define ACB_NORMAL 0x0010 /* 1 = Normal user account */
345 #define ACB_MNS 0x0020 /* 1 = MNS logon user account */
346 #define ACB_DOMTRUST 0x0040 /* 1 = Interdomain trust account */
347 #define ACB_WSTRUST 0x0080 /* 1 = Workstation trust account */
348 #define ACB_SVRTRUST 0x0100 /* 1 = Server trust account */
349 #define ACB_PWNOEXP 0x0200 /* 1 = User password does not expire */
350 #define ACB_AUTOLOCK 0x0400 /* 1 = Account auto locked */
352 #define MAX_HOURS_LEN 32
354 struct sam_passwd
356 time_t logon_time; /* logon time */
357 time_t logoff_time; /* logoff time */
358 time_t kickoff_time; /* kickoff time */
359 time_t pass_last_set_time; /* password last set time */
360 time_t pass_can_change_time; /* password can change time */
361 time_t pass_must_change_time; /* password must change time */
363 char *smb_name; /* username string */
364 char *full_name; /* user's full name string */
365 char *home_dir; /* home directory string */
366 char *dir_drive; /* home directory drive string */
367 char *logon_script; /* logon script string */
368 char *profile_path; /* profile path string */
369 char *acct_desc ; /* user description string */
370 char *workstations; /* login from workstations string */
371 char *unknown_str ; /* don't know what this is, yet. */
372 char *munged_dial ; /* munged path name and dial-back tel number */
374 uid_t smb_userid; /* this is actually the unix uid_t */
375 gid_t smb_grpid; /* this is actually the unix gid_t */
376 uint32 user_rid; /* Primary User ID */
377 uint32 group_rid; /* Primary Group ID */
379 unsigned char *smb_passwd; /* Null if no password */
380 unsigned char *smb_nt_passwd; /* Null if no password */
382 uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */
383 uint32 unknown_3; /* 0x00ff ffff */
385 uint16 logon_divs; /* 168 - number of hours in a week */
386 uint32 hours_len; /* normally 21 bytes */
387 uint8 hours[MAX_HOURS_LEN];
389 uint32 unknown_5; /* 0x0002 0000 */
390 uint32 unknown_6; /* 0x0000 04ec */
393 struct smb_passwd
395 uid_t smb_userid; /* this is actually the unix uid_t */
396 char *smb_name; /* username string */
398 unsigned char *smb_passwd; /* Null if no password */
399 unsigned char *smb_nt_passwd; /* Null if no password */
401 uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */
402 time_t pass_last_set_time; /* password last set time */
406 struct sam_disp_info
408 uint32 user_rid; /* Primary User ID */
409 char *smb_name; /* username string */
410 char *full_name; /* user's full name string */
413 #define MAXSUBAUTHS 15 /* max sub authorities in a SID */
415 /* DOM_SID - security id */
416 typedef struct sid_info
418 uint8 sid_rev_num; /* SID revision number */
419 uint8 num_auths; /* number of sub-authorities */
420 uint8 id_auth[6]; /* Identifier Authority */
422 * Note that the values in these uint32's are in *native* byteorder,
423 * not neccessarily little-endian...... JRA.
425 uint32 sub_auths[MAXSUBAUTHS]; /* pointer to sub-authorities. */
427 } DOM_SID;
430 /*** query a local group, get a list of these: shows who is in that group ***/
432 /* local group member info */
433 typedef struct local_grp_member_info
435 DOM_SID sid ; /* matches with name */
436 uint8 sid_use; /* usr=1 grp=2 dom=3 alias=4 wkng=5 del=6 inv=7 unk=8 */
437 fstring name ; /* matches with sid: must be of the form "DOMAIN\account" */
439 } LOCAL_GRP_MEMBER;
441 /* enumerate these to get list of local groups */
443 /* local group info */
444 typedef struct local_grp_info
446 fstring name;
447 fstring comment;
449 } LOCAL_GRP;
451 /*** enumerate these to get list of domain groups ***/
453 /* domain group member info */
454 typedef struct domain_grp_info
456 fstring name;
457 fstring comment;
458 uint32 rid; /* group rid */
459 uint8 attr; /* attributes forced to be set to 0x7: SE_GROUP_xxx */
461 } DOMAIN_GRP;
463 /*** query a domain group, get a list of these: shows who is in that group ***/
465 /* domain group info */
466 typedef struct domain_grp_member_info
468 fstring name;
469 uint8 attr; /* attributes forced to be set to 0x7: SE_GROUP_xxx */
471 } DOMAIN_GRP_MEMBER;
473 /* DOM_CHAL - challenge info */
474 typedef struct chal_info
476 uchar data[8]; /* credentials */
477 } DOM_CHAL;
479 /* 32 bit time (sec) since 01jan1970 - cifs6.txt, section 3.5, page 30 */
480 typedef struct time_info
482 uint32 time;
483 } UTIME;
485 /* DOM_CREDs - timestamped client or server credentials */
486 typedef struct cred_info
488 DOM_CHAL challenge; /* credentials */
489 UTIME timestamp; /* credential time-stamp */
490 } DOM_CRED;
492 /* Structure used when SMBwritebmpx is active */
493 typedef struct
495 size_t wr_total_written; /* So we know when to discard this */
496 int32 wr_timeout;
497 int32 wr_errclass;
498 int32 wr_error; /* Cached errors */
499 BOOL wr_mode; /* write through mode) */
500 BOOL wr_discard; /* discard all further data */
501 } write_bmpx_struct;
504 * Structure used to indirect fd's from the files_struct.
505 * Needed as POSIX locking is based on file and process, not
506 * file descriptor and process.
509 typedef struct file_fd_struct
511 struct file_fd_struct *next, *prev;
512 uint16 ref_count;
513 uint16 uid_cache_count;
514 uid_t uid_users_cache[10];
515 SMB_DEV_T dev;
516 SMB_INO_T inode;
517 int fd;
518 int fd_readonly;
519 int fd_writeonly;
520 int real_open_flags;
521 BOOL delete_on_close;
522 } file_fd_struct;
525 * Structure used to keep directory state information around.
526 * Used in NT change-notify code.
529 typedef struct
531 time_t modify_time;
532 time_t status_time;
533 } dir_status_struct;
535 struct uid_cache {
536 int entries;
537 uid_t list[UID_CACHE_SIZE];
540 typedef struct
542 char *name;
543 BOOL is_wild;
544 } name_compare_entry;
546 typedef struct connection_struct
548 struct connection_struct *next, *prev;
549 unsigned cnum; /* an index passed over the wire */
550 int service;
551 BOOL force_user;
552 struct uid_cache uid_cache;
553 void *dirptr;
554 BOOL printer;
555 BOOL ipc;
556 BOOL read_only;
557 BOOL admin_user;
558 char *dirpath;
559 char *connectpath;
560 char *origpath;
561 char *user; /* name of user who *opened* this connection */
562 uid_t uid; /* uid of user who *opened* this connection */
563 gid_t gid; /* gid of user who *opened* this connection */
565 uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
567 /* following groups stuff added by ih */
569 /* This groups info is valid for the user that *opened* the connection */
570 int ngroups;
571 gid_t *groups;
573 time_t lastused;
574 BOOL used;
575 int num_files_open;
576 name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */
577 name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */
578 name_compare_entry *veto_oplock_list; /* Per-share list of files to refuse oplocks on. */
580 } connection_struct;
582 struct current_user
584 connection_struct *conn;
585 uint16 vuid;
586 uid_t uid;
587 gid_t gid;
588 int ngroups;
589 gid_t *groups;
592 typedef struct files_struct
594 struct files_struct *next, *prev;
595 int fnum;
596 connection_struct *conn;
597 file_fd_struct *fd_ptr;
598 SMB_OFF_T pos;
599 SMB_OFF_T size;
600 mode_t mode;
601 uint16 vuid;
602 char *mmap_ptr;
603 SMB_OFF_T mmap_size;
604 write_bmpx_struct *wbmpx_ptr;
605 struct timeval open_time;
606 int share_mode;
607 time_t pending_modtime;
608 BOOL open;
609 BOOL can_lock;
610 BOOL can_read;
611 BOOL can_write;
612 BOOL print_file;
613 BOOL modified;
614 BOOL granted_oplock;
615 BOOL sent_oplock_break;
616 BOOL is_directory;
617 BOOL directory_delete_on_close;
618 BOOL stat_open;
619 char *fsp_name;
620 } files_struct;
622 /* Domain controller authentication protocol info */
623 struct dcinfo
625 DOM_CHAL clnt_chal; /* Initial challenge received from client */
626 DOM_CHAL srv_chal; /* Initial server challenge */
627 DOM_CRED clnt_cred; /* Last client credential */
628 DOM_CRED srv_cred; /* Last server credential */
630 uchar sess_key[8]; /* Session key */
631 uchar md4pw[16]; /* md4(machine password) */
634 typedef struct
636 uid_t uid; /* uid of a validated user */
637 gid_t gid; /* gid of a validated user */
639 fstring requested_name; /* user name from the client */
640 fstring name; /* unix user name of a validated user */
641 fstring real_name; /* to store real name from password file - simeon */
642 BOOL guest;
644 /* following groups stuff added by ih */
645 /* This groups info is needed for when we become_user() for this uid */
646 int n_groups;
647 gid_t *groups;
649 int n_sids;
650 int *sids;
652 /* per-user authentication information on NT RPCs */
653 struct dcinfo dc;
655 } user_struct;
658 enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING};
660 typedef struct
662 int job;
663 int size;
664 int status;
665 int priority;
666 time_t time;
667 char user[30];
668 char file[100];
669 } print_queue_struct;
671 enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
673 typedef struct
675 fstring message;
676 int status;
677 } print_status_struct;
679 /* used for server information: client, nameserv and ipc */
680 struct server_info_struct
682 fstring name;
683 uint32 type;
684 fstring comment;
685 fstring domain; /* used ONLY in ipc.c NOT namework.c */
686 BOOL server_added; /* used ONLY in ipc.c NOT namework.c */
690 /* used for network interfaces */
691 struct interface
693 struct interface *next;
694 struct in_addr ip;
695 struct in_addr bcast;
696 struct in_addr nmask;
699 /* struct returned by get_share_modes */
700 typedef struct
702 int pid;
703 uint16 op_port;
704 uint16 op_type;
705 int share_mode;
706 struct timeval time;
707 } share_mode_entry;
710 /* each implementation of the share mode code needs
711 to support the following operations */
712 struct share_ops {
713 BOOL (*stop_mgmt)(void);
714 BOOL (*lock_entry)(connection_struct *, SMB_DEV_T , SMB_INO_T , int *);
715 BOOL (*unlock_entry)(connection_struct *, SMB_DEV_T , SMB_INO_T , int );
716 int (*get_entries)(connection_struct *, int , SMB_DEV_T , SMB_INO_T , share_mode_entry **);
717 void (*del_entry)(int , files_struct *);
718 BOOL (*set_entry)(int, files_struct *, uint16 , uint16 );
719 BOOL (*mod_entry)(int, files_struct *, void (*)(share_mode_entry *, SMB_DEV_T, SMB_INO_T, void *), void *);
720 int (*forall)(void (*)(share_mode_entry *, char *));
721 void (*status)(FILE *);
724 /* each implementation of the shared memory code needs
725 to support the following operations */
726 struct shmem_ops {
727 BOOL (*shm_close)( void );
728 int (*shm_alloc)(int );
729 BOOL (*shm_free)(int );
730 int (*get_userdef_off)(void);
731 void *(*offset2addr)(int );
732 int (*addr2offset)(void *addr);
733 BOOL (*lock_hash_entry)(unsigned int);
734 BOOL (*unlock_hash_entry)( unsigned int );
735 BOOL (*get_usage)(int *,int *,int *);
736 unsigned (*hash_size)(void);
740 * Each implementation of the password database code needs
741 * to support the following operations.
744 struct passdb_ops {
746 * Password database ops.
748 void *(*startsmbpwent)(BOOL);
749 void (*endsmbpwent)(void *);
750 SMB_BIG_UINT (*getsmbpwpos)(void *);
751 BOOL (*setsmbpwpos)(void *, SMB_BIG_UINT);
754 * smb password database query functions.
756 struct smb_passwd *(*getsmbpwnam)(char *);
757 struct smb_passwd *(*getsmbpwuid)(uid_t);
758 struct smb_passwd *(*getsmbpwrid)(uint32);
759 struct smb_passwd *(*getsmbpwent)(void *);
762 * smb password database modification functions.
764 BOOL (*add_smbpwd_entry)(struct smb_passwd *);
765 BOOL (*mod_smbpwd_entry)(struct smb_passwd *, BOOL);
768 * Functions that manipulate a struct sam_passwd.
770 struct sam_passwd *(*getsam21pwent)(void *);
773 * sam password database query functions.
775 struct sam_passwd *(*getsam21pwnam)(char *);
776 struct sam_passwd *(*getsam21pwuid)(uid_t);
777 struct sam_passwd *(*getsam21pwrid)(uint32);
780 * sam password database modification functions.
782 BOOL (*add_sam21pwd_entry)(struct sam_passwd *);
783 BOOL (*mod_sam21pwd_entry)(struct sam_passwd *, BOOL);
786 * sam query display info functions.
788 struct sam_disp_info *(*getsamdispnam)(char *);
789 struct sam_disp_info *(*getsamdisprid)(uint32);
790 struct sam_disp_info *(*getsamdispent)(void *);
792 #if 0
794 * password checking functions
796 struct smb_passwd *(*smb_password_chal )(char *username, char lm_pass[24], char nt_pass[24], char chal[8]);
797 struct smb_passwd *(*smb_password_check )(char *username, char lm_hash[16], char nt_hash[16]);
798 struct passwd *(*unix_password_check)(char *username, char *pass, int pass_len);
799 #endif
802 /* this is used for smbstatus */
804 struct connect_record
806 int magic;
807 int pid;
808 int cnum;
809 uid_t uid;
810 gid_t gid;
811 char name[24];
812 char addr[24];
813 char machine[128];
814 time_t start;
817 /* This is used by smbclient to send it to a smbfs mount point */
818 struct connection_options {
819 int protocol;
820 /* Connection-Options */
821 uint32 max_xmit;
822 uint16 server_vuid;
823 uint16 tid;
824 /* The following are LANMAN 1.0 options */
825 uint16 sec_mode;
826 uint16 max_mux;
827 uint16 max_vcs;
828 uint16 rawmode;
829 uint32 sesskey;
830 /* The following are NT LM 0.12 options */
831 uint32 maxraw;
832 uint32 capabilities;
833 uint16 serverzone;
836 /* the following are used by loadparm for option lists */
837 typedef enum
839 P_BOOL,P_BOOLREV,P_CHAR,P_INTEGER,P_OCTAL,
840 P_STRING,P_USTRING,P_GSTRING,P_UGSTRING,P_ENUM,P_SEP
841 } parm_type;
843 typedef enum
845 P_LOCAL,P_GLOBAL,P_SEPARATOR,P_NONE
846 } parm_class;
848 struct enum_list {
849 int value;
850 const char *name;
853 struct parm_struct
855 const char *label;
856 parm_type type;
857 parm_class class;
858 void *ptr;
859 BOOL (*special)(const char *, char **);
860 const struct enum_list *enum_list;
861 unsigned flags;
862 union {
863 BOOL bvalue;
864 int ivalue;
865 char *svalue;
866 char cvalue;
867 } def;
870 struct bitmap {
871 uint32 *b;
872 int n;
875 #define FLAG_BASIC 0x01 /* fundamental options */
876 #define FLAG_SHARE 0x02 /* file sharing options */
877 #define FLAG_PRINT 0x04 /* printing options */
878 #define FLAG_GLOBAL 0x08 /* local options that should be globally settable in SWAT */
879 #define FLAG_DEPRECATED 0x10 /* options that should no longer be used */
880 #define FLAG_HIDE 0x20 /* options that should be hidden in SWAT */
882 #ifndef LOCKING_VERSION
883 #define LOCKING_VERSION 4
884 #endif /* LOCKING_VERSION */
886 /* these are useful macros for checking validity of handles */
887 #define OPEN_FSP(fsp) ((fsp) && (fsp)->open && !(fsp)->is_directory)
888 #define OPEN_CONN(conn) ((conn) && (conn)->open)
889 #define IS_IPC(conn) ((conn) && (conn)->ipc)
890 #define IS_PRINT(conn) ((conn) && (conn)->printer)
891 #define FNUM_OK(fsp,c) (OPEN_FSP(fsp) && (c)==(fsp)->conn)
893 #define CHECK_FSP(fsp,conn) if (!FNUM_OK(fsp,conn)) \
894 return(ERROR(ERRDOS,ERRbadfid)); \
895 else if((fsp)->fd_ptr == NULL) \
896 return(ERROR(ERRDOS,ERRbadaccess))
898 #define CHECK_READ(fsp) if (!(fsp)->can_read) \
899 return(ERROR(ERRDOS,ERRbadaccess))
900 #define CHECK_WRITE(fsp) if (!(fsp)->can_write) \
901 return(ERROR(ERRDOS,ERRbadaccess))
902 #define CHECK_ERROR(fsp) if (HAS_CACHED_ERROR(fsp)) \
903 return(CACHED_ERROR(fsp))
905 /* translates a connection number into a service number */
906 #define SNUM(conn) ((conn)?(conn)->service:-1)
908 /* access various service details */
909 #define SERVICE(snum) (lp_servicename(snum))
910 #define PRINTCAP (lp_printcapname())
911 #define PRINTCOMMAND(snum) (lp_printcommand(snum))
912 #define PRINTERNAME(snum) (lp_printername(snum))
913 #define CAN_WRITE(conn) (!conn->read_only)
914 #define VALID_SNUM(snum) (lp_snum_ok(snum))
915 #define GUEST_OK(snum) (VALID_SNUM(snum) && lp_guest_ok(snum))
916 #define GUEST_ONLY(snum) (VALID_SNUM(snum) && lp_guest_only(snum))
917 #define CAN_SETDIR(snum) (!lp_no_set_dir(snum))
918 #define CAN_PRINT(conn) ((conn) && lp_print_ok((conn)->service))
919 #define MAP_HIDDEN(conn) ((conn) && lp_map_hidden((conn)->service))
920 #define MAP_SYSTEM(conn) ((conn) && lp_map_system((conn)->service))
921 #define MAP_ARCHIVE(conn) ((conn) && lp_map_archive((conn)->service))
922 #define IS_HIDDEN_PATH(conn,path) ((conn) && is_in_path((path),(conn)->hide_list))
923 #define IS_VETO_PATH(conn,path) ((conn) && is_in_path((path),(conn)->veto_list))
924 #define IS_VETO_OPLOCK_PATH(conn,path) ((conn) && is_in_path((path),(conn)->veto_oplock_list))
927 * Used by the stat cache code to check if a returned
928 * stat structure is valid.
931 #define VALID_STAT(st) (st.st_nlink != 0)
932 #define VALID_STAT_OF_DIR(st) (VALID_STAT(st) && S_ISDIR(st.st_mode))
934 #define SMBENCRYPT() (lp_encrypted_passwords())
936 /* the basic packet size, assuming no words or bytes */
937 #define smb_size 39
939 /* offsets into message for common items */
940 #define smb_com 8
941 #define smb_rcls 9
942 #define smb_reh 10
943 #define smb_err 11
944 #define smb_flg 13
945 #define smb_flg2 14
946 #define smb_reb 13
947 #define smb_tid 28
948 #define smb_pid 30
949 #define smb_uid 32
950 #define smb_mid 34
951 #define smb_wct 36
952 #define smb_vwv 37
953 #define smb_vwv0 37
954 #define smb_vwv1 39
955 #define smb_vwv2 41
956 #define smb_vwv3 43
957 #define smb_vwv4 45
958 #define smb_vwv5 47
959 #define smb_vwv6 49
960 #define smb_vwv7 51
961 #define smb_vwv8 53
962 #define smb_vwv9 55
963 #define smb_vwv10 57
964 #define smb_vwv11 59
965 #define smb_vwv12 61
966 #define smb_vwv13 63
967 #define smb_vwv14 65
968 #define smb_vwv15 67
969 #define smb_vwv16 69
970 #define smb_vwv17 71
972 /* flag defines. CIFS spec 3.1.1 */
973 #define FLAG_SUPPORT_LOCKREAD 0x01
974 #define FLAG_CLIENT_BUF_AVAIL 0x02
975 #define FLAG_RESERVED 0x04
976 #define FLAG_CASELESS_PATHNAMES 0x08
977 #define FLAG_CANONICAL_PATHNAMES 0x10
978 #define FLAG_REQUEST_OPLOCK 0x20
979 #define FLAG_REQUEST_BATCH_OPLOCK 0x40
980 #define FLAG_REPLY 0x80
982 /* the complete */
983 #define SMBmkdir 0x00 /* create directory */
984 #define SMBrmdir 0x01 /* delete directory */
985 #define SMBopen 0x02 /* open file */
986 #define SMBcreate 0x03 /* create file */
987 #define SMBclose 0x04 /* close file */
988 #define SMBflush 0x05 /* flush file */
989 #define SMBunlink 0x06 /* delete file */
990 #define SMBmv 0x07 /* rename file */
991 #define SMBgetatr 0x08 /* get file attributes */
992 #define SMBsetatr 0x09 /* set file attributes */
993 #define SMBread 0x0A /* read from file */
994 #define SMBwrite 0x0B /* write to file */
995 #define SMBlock 0x0C /* lock byte range */
996 #define SMBunlock 0x0D /* unlock byte range */
997 #define SMBctemp 0x0E /* create temporary file */
998 #define SMBmknew 0x0F /* make new file */
999 #define SMBchkpth 0x10 /* check directory path */
1000 #define SMBexit 0x11 /* process exit */
1001 #define SMBlseek 0x12 /* seek */
1002 #define SMBtcon 0x70 /* tree connect */
1003 #define SMBtconX 0x75 /* tree connect and X*/
1004 #define SMBtdis 0x71 /* tree disconnect */
1005 #define SMBnegprot 0x72 /* negotiate protocol */
1006 #define SMBdskattr 0x80 /* get disk attributes */
1007 #define SMBsearch 0x81 /* search directory */
1008 #define SMBsplopen 0xC0 /* open print spool file */
1009 #define SMBsplwr 0xC1 /* write to print spool file */
1010 #define SMBsplclose 0xC2 /* close print spool file */
1011 #define SMBsplretq 0xC3 /* return print queue */
1012 #define SMBsends 0xD0 /* send single block message */
1013 #define SMBsendb 0xD1 /* send broadcast message */
1014 #define SMBfwdname 0xD2 /* forward user name */
1015 #define SMBcancelf 0xD3 /* cancel forward */
1016 #define SMBgetmac 0xD4 /* get machine name */
1017 #define SMBsendstrt 0xD5 /* send start of multi-block message */
1018 #define SMBsendend 0xD6 /* send end of multi-block message */
1019 #define SMBsendtxt 0xD7 /* send text of multi-block message */
1021 /* Core+ protocol */
1022 #define SMBlockread 0x13 /* Lock a range and read */
1023 #define SMBwriteunlock 0x14 /* Unlock a range then write */
1024 #define SMBreadbraw 0x1a /* read a block of data with no smb header */
1025 #define SMBwritebraw 0x1d /* write a block of data with no smb header */
1026 #define SMBwritec 0x20 /* secondary write request */
1027 #define SMBwriteclose 0x2c /* write a file then close it */
1029 /* dos extended protocol */
1030 #define SMBreadBraw 0x1A /* read block raw */
1031 #define SMBreadBmpx 0x1B /* read block multiplexed */
1032 #define SMBreadBs 0x1C /* read block (secondary response) */
1033 #define SMBwriteBraw 0x1D /* write block raw */
1034 #define SMBwriteBmpx 0x1E /* write block multiplexed */
1035 #define SMBwriteBs 0x1F /* write block (secondary request) */
1036 #define SMBwriteC 0x20 /* write complete response */
1037 #define SMBsetattrE 0x22 /* set file attributes expanded */
1038 #define SMBgetattrE 0x23 /* get file attributes expanded */
1039 #define SMBlockingX 0x24 /* lock/unlock byte ranges and X */
1040 #define SMBtrans 0x25 /* transaction - name, bytes in/out */
1041 #define SMBtranss 0x26 /* transaction (secondary request/response) */
1042 #define SMBioctl 0x27 /* IOCTL */
1043 #define SMBioctls 0x28 /* IOCTL (secondary request/response) */
1044 #define SMBcopy 0x29 /* copy */
1045 #define SMBmove 0x2A /* move */
1046 #define SMBecho 0x2B /* echo */
1047 #define SMBopenX 0x2D /* open and X */
1048 #define SMBreadX 0x2E /* read and X */
1049 #define SMBwriteX 0x2F /* write and X */
1050 #define SMBsesssetupX 0x73 /* Session Set Up & X (including User Logon) */
1051 #define SMBffirst 0x82 /* find first */
1052 #define SMBfunique 0x83 /* find unique */
1053 #define SMBfclose 0x84 /* find close */
1054 #define SMBinvalid 0xFE /* invalid command */
1056 /* Extended 2.0 protocol */
1057 #define SMBtrans2 0x32 /* TRANS2 protocol set */
1058 #define SMBtranss2 0x33 /* TRANS2 protocol set, secondary command */
1059 #define SMBfindclose 0x34 /* Terminate a TRANSACT2_FINDFIRST */
1060 #define SMBfindnclose 0x35 /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
1061 #define SMBulogoffX 0x74 /* user logoff */
1063 /* NT SMB extensions. */
1064 #define SMBnttrans 0xA0 /* NT transact */
1065 #define SMBnttranss 0xA1 /* NT transact secondary */
1066 #define SMBntcreateX 0xA2 /* NT create and X */
1067 #define SMBntcancel 0xA4 /* NT cancel */
1069 /* These are the TRANS2 sub commands */
1070 #define TRANSACT2_OPEN 0
1071 #define TRANSACT2_FINDFIRST 1
1072 #define TRANSACT2_FINDNEXT 2
1073 #define TRANSACT2_QFSINFO 3
1074 #define TRANSACT2_SETFSINFO 4
1075 #define TRANSACT2_QPATHINFO 5
1076 #define TRANSACT2_SETPATHINFO 6
1077 #define TRANSACT2_QFILEINFO 7
1078 #define TRANSACT2_SETFILEINFO 8
1079 #define TRANSACT2_FSCTL 9
1080 #define TRANSACT2_IOCTL 0xA
1081 #define TRANSACT2_FINDNOTIFYFIRST 0xB
1082 #define TRANSACT2_FINDNOTIFYNEXT 0xC
1083 #define TRANSACT2_MKDIR 0xD
1084 #define TRANSACT2_SESSION_SETUP 0xE
1085 #define TRANSACT2_GET_DFS_REFERRAL 0x10
1086 #define TRANSACT2_REPORT_DFS_INCONSISTANCY 0x11
1088 /* These are the NT transact sub commands. */
1089 #define NT_TRANSACT_CREATE 1
1090 #define NT_TRANSACT_IOCTL 2
1091 #define NT_TRANSACT_SET_SECURITY_DESC 3
1092 #define NT_TRANSACT_NOTIFY_CHANGE 4
1093 #define NT_TRANSACT_RENAME 5
1094 #define NT_TRANSACT_QUERY_SECURITY_DESC 6
1096 /* these are the trans2 sub fields for primary requests */
1097 #define smb_tpscnt smb_vwv0
1098 #define smb_tdscnt smb_vwv1
1099 #define smb_mprcnt smb_vwv2
1100 #define smb_mdrcnt smb_vwv3
1101 #define smb_msrcnt smb_vwv4
1102 #define smb_flags smb_vwv5
1103 #define smb_timeout smb_vwv6
1104 #define smb_pscnt smb_vwv9
1105 #define smb_psoff smb_vwv10
1106 #define smb_dscnt smb_vwv11
1107 #define smb_dsoff smb_vwv12
1108 #define smb_suwcnt smb_vwv13
1109 #define smb_setup smb_vwv14
1110 #define smb_setup0 smb_setup
1111 #define smb_setup1 (smb_setup+2)
1112 #define smb_setup2 (smb_setup+4)
1114 /* these are for the secondary requests */
1115 #define smb_spscnt smb_vwv2
1116 #define smb_spsoff smb_vwv3
1117 #define smb_spsdisp smb_vwv4
1118 #define smb_sdscnt smb_vwv5
1119 #define smb_sdsoff smb_vwv6
1120 #define smb_sdsdisp smb_vwv7
1121 #define smb_sfid smb_vwv8
1123 /* and these for responses */
1124 #define smb_tprcnt smb_vwv0
1125 #define smb_tdrcnt smb_vwv1
1126 #define smb_prcnt smb_vwv3
1127 #define smb_proff smb_vwv4
1128 #define smb_prdisp smb_vwv5
1129 #define smb_drcnt smb_vwv6
1130 #define smb_droff smb_vwv7
1131 #define smb_drdisp smb_vwv8
1133 /* these are for the NT trans primary request. */
1134 #define smb_nt_MaxSetupCount smb_vwv0
1135 #define smb_nt_Flags (smb_vwv0 + 1)
1136 #define smb_nt_TotalParameterCount (smb_vwv0 + 3)
1137 #define smb_nt_TotalDataCount (smb_vwv0 + 7)
1138 #define smb_nt_MaxParameterCount (smb_vwv0 + 11)
1139 #define smb_nt_MaxDataCount (smb_vwv0 + 15)
1140 #define smb_nt_ParameterCount (smb_vwv0 + 19)
1141 #define smb_nt_ParameterOffset (smb_vwv0 + 23)
1142 #define smb_nt_DataCount (smb_vwv0 + 27)
1143 #define smb_nt_DataOffset (smb_vwv0 + 31)
1144 #define smb_nt_SetupCount (smb_vwv0 + 35)
1145 #define smb_nt_Function (smb_vwv0 + 36)
1146 #define smb_nt_SetupStart (smb_vwv0 + 38)
1148 /* these are for the NT trans secondary request. */
1149 #define smb_nts_TotalParameterCount (smb_vwv0 + 3)
1150 #define smb_nts_TotalDataCount (smb_vwv0 + 7)
1151 #define smb_nts_ParameterCount (smb_vwv0 + 11)
1152 #define smb_nts_ParameterOffset (smb_vwv0 + 15)
1153 #define smb_nts_ParameterDisplacement (smb_vwv0 + 19)
1154 #define smb_nts_DataCount (smb_vwv0 + 23)
1155 #define smb_nts_DataOffset (smb_vwv0 + 27)
1156 #define smb_nts_DataDisplacement (smb_vwv0 + 31)
1158 /* these are for the NT trans reply. */
1159 #define smb_ntr_TotalParameterCount (smb_vwv0 + 3)
1160 #define smb_ntr_TotalDataCount (smb_vwv0 + 7)
1161 #define smb_ntr_ParameterCount (smb_vwv0 + 11)
1162 #define smb_ntr_ParameterOffset (smb_vwv0 + 15)
1163 #define smb_ntr_ParameterDisplacement (smb_vwv0 + 19)
1164 #define smb_ntr_DataCount (smb_vwv0 + 23)
1165 #define smb_ntr_DataOffset (smb_vwv0 + 27)
1166 #define smb_ntr_DataDisplacement (smb_vwv0 + 31)
1168 /* these are for the NT create_and_X */
1169 #define smb_ntcreate_NameLength (smb_vwv0 + 5)
1170 #define smb_ntcreate_Flags (smb_vwv0 + 7)
1171 #define smb_ntcreate_RootDirectoryFid (smb_vwv0 + 11)
1172 #define smb_ntcreate_DesiredAccess (smb_vwv0 + 15)
1173 #define smb_ntcreate_AllocationSize (smb_vwv0 + 19)
1174 #define smb_ntcreate_FileAttributes (smb_vwv0 + 27)
1175 #define smb_ntcreate_ShareAccess (smb_vwv0 + 31)
1176 #define smb_ntcreate_CreateDisposition (smb_vwv0 + 35)
1177 #define smb_ntcreate_CreateOptions (smb_vwv0 + 39)
1178 #define smb_ntcreate_ImpersonationLevel (smb_vwv0 + 43)
1179 #define smb_ntcreate_SecurityFlags (smb_vwv0 + 47)
1181 /* this is used on a TConX. I'm not sure the name is very helpful though */
1182 #define SMB_SUPPORT_SEARCH_BITS 0x0001
1184 /* these are the constants used in the above call. */
1185 /* DesiredAccess */
1186 /* File Specific access rights. */
1187 #define FILE_READ_DATA 0x001
1188 #define FILE_WRITE_DATA 0x002
1189 #define FILE_APPEND_DATA 0x004
1190 #define FILE_READ_EA 0x008
1191 #define FILE_WRITE_EA 0x010
1192 #define FILE_EXECUTE 0x020
1193 #define FILE_DELETE_CHILD 0x040
1194 #define FILE_READ_ATTRIBUTES 0x080
1195 #define FILE_WRITE_ATTRIBUTES 0x100
1197 #define FILE_ALL_ATTRIBUTES 0x1FF
1199 /* Generic access masks & rights. */
1200 #define SPECIFIC_RIGHTS_MASK 0x00FFFFL
1201 #define STANDARD_RIGHTS_MASK 0xFF0000L
1202 #define DELETE_ACCESS (1L<<16)
1203 #define READ_CONTROL_ACCESS (1L<<17)
1204 #define WRITE_DAC_ACCESS (1L<<18)
1205 #define WRITE_OWNER_ACCESS (1L<<19)
1206 #define SYNCHRONIZE_ACCESS (1L<<20)
1208 #define SYSTEM_SECURITY_ACCESS (1L<<24)
1209 #define GENERIC_ALL_ACCESS (1<<28)
1210 #define GENERIC_EXECUTE_ACCESS (1<<29)
1211 #define GENERIC_WRITE_ACCESS (1<<30)
1212 #define GENERIC_READ_ACCESS (1<<31)
1214 #define FILE_ALL_STANDARD_ACCESS 0x1F0000
1216 /* Mapping of access rights to UNIX perms. */
1217 #if 0 /* Don't use all here... JRA. */
1218 #define UNIX_ACCESS_RWX (FILE_ALL_ATTRIBUTES|FILE_ALL_STANDARD_ACCESS)
1219 #else
1220 #define UNIX_ACCESS_RWX (UNIX_ACCESS_R|UNIX_ACCESS_W|UNIX_ACCESS_X)
1221 #endif
1223 #define UNIX_ACCESS_R (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
1224 FILE_READ_ATTRIBUTES|FILE_READ_EA|FILE_READ_DATA)
1225 #define UNIX_ACCESS_W (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
1226 FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA|\
1227 FILE_APPEND_DATA|FILE_WRITE_DATA)
1228 #define UNIX_ACCESS_X (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
1229 FILE_EXECUTE|FILE_READ_ATTRIBUTES)
1231 #define UNIX_ACCESS_NONE (WRITE_OWNER_ACCESS)
1233 /* Flags field. */
1234 #define REQUEST_OPLOCK 2
1235 #define REQUEST_BATCH_OPLOCK 4
1236 #define OPEN_DIRECTORY 8
1238 /* ShareAccess field. */
1239 #define FILE_SHARE_NONE 0 /* Cannot be used in bitmask. */
1240 #define FILE_SHARE_READ 1
1241 #define FILE_SHARE_WRITE 2
1242 #define FILE_SHARE_DELETE 4
1244 /* FileAttributesField */
1245 #define FILE_ATTRIBUTE_READONLY aRONLY
1246 #define FILE_ATTRIBUTE_HIDDEN aHIDDEN
1247 #define FILE_ATTRIBUTE_SYSTEM aSYSTEM
1248 #define FILE_ATTRIBUTE_DIRECTORY aDIR
1249 #define FILE_ATTRIBUTE_ARCHIVE aARCH
1250 #define FILE_ATTRIBUTE_NORMAL 0x80L
1251 #define FILE_ATTRIBUTE_TEMPORARY 0x100L
1252 #define FILE_ATTRIBUTE_COMPRESSED 0x800L
1253 #define SAMBA_ATTRIBUTES_MASK 0x7F
1255 /* Flags - combined with attributes. */
1256 #define FILE_FLAG_WRITE_THROUGH 0x80000000L
1257 #define FILE_FLAG_NO_BUFFERING 0x20000000L
1258 #define FILE_FLAG_RANDOM_ACCESS 0x10000000L
1259 #define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000L
1260 #define FILE_FLAG_DELETE_ON_CLOSE 0x04000000L
1261 #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000L
1262 #define FILE_FLAG_POSIX_SEMANTICS 0x01000000L
1264 /* CreateDisposition field. */
1265 #define FILE_SUPERSEDE 0
1266 #define FILE_OPEN 1
1267 #define FILE_CREATE 2
1268 #define FILE_OPEN_IF 3
1269 #define FILE_OVERWRITE 4
1270 #define FILE_OVERWRITE_IF 5
1272 /* CreateOptions field. */
1273 #define FILE_DIRECTORY_FILE 0x0001
1274 #define FILE_WRITE_THROUGH 0x0002
1275 #define FILE_SEQUENTIAL_ONLY 0x0004
1276 #define FILE_NON_DIRECTORY_FILE 0x0040
1277 #define FILE_NO_EA_KNOWLEDGE 0x0200
1278 #define FILE_EIGHT_DOT_THREE_ONLY 0x0400
1279 #define FILE_RANDOM_ACCESS 0x0800
1280 #define FILE_DELETE_ON_CLOSE 0x1000
1282 /* Responses when opening a file. */
1283 #define FILE_WAS_OPENED 1
1284 #define FILE_WAS_CREATED 2
1285 #define FILE_WAS_OVERWRITTEN 3
1287 /* File type flags */
1288 #define FILE_TYPE_DISK 0
1289 #define FILE_TYPE_BYTE_MODE_PIPE 1
1290 #define FILE_TYPE_MESSAGE_MODE_PIPE 2
1291 #define FILE_TYPE_PRINTER 3
1292 #define FILE_TYPE_COMM_DEVICE 4
1293 #define FILE_TYPE_UNKNOWN 0xFFFF
1295 /* Flag for NT transact rename call. */
1296 #define RENAME_REPLACE_IF_EXISTS 1
1298 /* Filesystem Attributes. */
1299 #define FILE_CASE_SENSITIVE_SEARCH 0x1
1300 #define FILE_CASE_PRESERVED_NAMES 0x2
1301 #define FILE_UNICODE_ON_DISK 0x4
1302 #define FILE_PERSISTENT_ACLS 0x8
1304 /* ChangeNotify flags. */
1305 #define FILE_NOTIFY_CHANGE_FILE_NAME 0x001
1306 #define FILE_NOTIFY_CHANGE_DIR_NAME 0x002
1307 #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x004
1308 #define FILE_NOTIFY_CHANGE_SIZE 0x008
1309 #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x010
1310 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x020
1311 #define FILE_NOTIFY_CHANGE_CREATION 0x040
1312 #define FILE_NOTIFY_CHANGE_EA 0x080
1313 #define FILE_NOTIFY_CHANGE_SECURITY 0x100
1315 /* where to find the base of the SMB packet proper */
1316 #define smb_base(buf) (((char *)(buf))+4)
1319 #define SMB_SUCCESS 0 /* The request was successful. */
1320 #define ERRDOS 0x01 /* Error is from the core DOS operating system set. */
1321 #define ERRSRV 0x02 /* Error is generated by the server network file manager.*/
1322 #define ERRHRD 0x03 /* Error is an hardware error. */
1323 #define ERRCMD 0xFF /* Command was not in the "SMB" format. */
1325 #ifdef HAVE_STDARG_H
1326 int slprintf(char *str, int n, const char *format, ...)
1327 #ifdef __GNUC__
1328 __attribute__ ((format (printf, 3, 4)))
1329 #endif
1331 #else
1332 int slprintf();
1333 #endif
1335 #ifdef WITH_DFS
1336 void dfs_unlogin(void);
1337 extern int dcelogin_atmost_once;
1338 #endif
1340 #ifndef MIN
1341 #define MIN(a,b) ((a)<(b)?(a):(b))
1342 #endif
1343 #ifndef MAX
1344 #define MAX(a,b) ((a)>(b)?(a):(b))
1345 #endif
1347 #ifndef ABS
1348 #define ABS(a) ((a)>0?(a):(-(a)))
1349 #endif
1351 #ifndef SIGNAL_CAST
1352 #define SIGNAL_CAST (RETSIGTYPE (*)(int))
1353 #endif
1355 #ifndef SELECT_CAST
1356 #define SELECT_CAST
1357 #endif
1360 /* Some POSIX definitions for those without */
1362 #ifndef S_IFDIR
1363 #define S_IFDIR 0x4000
1364 #endif
1365 #ifndef S_ISDIR
1366 #define S_ISDIR(mode) ((mode & 0xF000) == S_IFDIR)
1367 #endif
1368 #ifndef S_IRWXU
1369 #define S_IRWXU 00700 /* read, write, execute: owner */
1370 #endif
1371 #ifndef S_IRUSR
1372 #define S_IRUSR 00400 /* read permission: owner */
1373 #endif
1374 #ifndef S_IWUSR
1375 #define S_IWUSR 00200 /* write permission: owner */
1376 #endif
1377 #ifndef S_IXUSR
1378 #define S_IXUSR 00100 /* execute permission: owner */
1379 #endif
1380 #ifndef S_IRWXG
1381 #define S_IRWXG 00070 /* read, write, execute: group */
1382 #endif
1383 #ifndef S_IRGRP
1384 #define S_IRGRP 00040 /* read permission: group */
1385 #endif
1386 #ifndef S_IWGRP
1387 #define S_IWGRP 00020 /* write permission: group */
1388 #endif
1389 #ifndef S_IXGRP
1390 #define S_IXGRP 00010 /* execute permission: group */
1391 #endif
1392 #ifndef S_IRWXO
1393 #define S_IRWXO 00007 /* read, write, execute: other */
1394 #endif
1395 #ifndef S_IROTH
1396 #define S_IROTH 00004 /* read permission: other */
1397 #endif
1398 #ifndef S_IWOTH
1399 #define S_IWOTH 00002 /* write permission: other */
1400 #endif
1401 #ifndef S_IXOTH
1402 #define S_IXOTH 00001 /* execute permission: other */
1403 #endif
1406 /* these are used in NetServerEnum to choose what to receive */
1407 #define SV_TYPE_WORKSTATION 0x00000001
1408 #define SV_TYPE_SERVER 0x00000002
1409 #define SV_TYPE_SQLSERVER 0x00000004
1410 #define SV_TYPE_DOMAIN_CTRL 0x00000008
1411 #define SV_TYPE_DOMAIN_BAKCTRL 0x00000010
1412 #define SV_TYPE_TIME_SOURCE 0x00000020
1413 #define SV_TYPE_AFP 0x00000040
1414 #define SV_TYPE_NOVELL 0x00000080
1415 #define SV_TYPE_DOMAIN_MEMBER 0x00000100
1416 #define SV_TYPE_PRINTQ_SERVER 0x00000200
1417 #define SV_TYPE_DIALIN_SERVER 0x00000400
1418 #define SV_TYPE_SERVER_UNIX 0x00000800
1419 #define SV_TYPE_NT 0x00001000
1420 #define SV_TYPE_WFW 0x00002000
1421 #define SV_TYPE_SERVER_MFPN 0x00004000
1422 #define SV_TYPE_SERVER_NT 0x00008000
1423 #define SV_TYPE_POTENTIAL_BROWSER 0x00010000
1424 #define SV_TYPE_BACKUP_BROWSER 0x00020000
1425 #define SV_TYPE_MASTER_BROWSER 0x00040000
1426 #define SV_TYPE_DOMAIN_MASTER 0x00080000
1427 #define SV_TYPE_SERVER_OSF 0x00100000
1428 #define SV_TYPE_SERVER_VMS 0x00200000
1429 #define SV_TYPE_WIN95_PLUS 0x00400000
1430 #define SV_TYPE_ALTERNATE_XPORT 0x20000000
1431 #define SV_TYPE_LOCAL_LIST_ONLY 0x40000000
1432 #define SV_TYPE_DOMAIN_ENUM 0x80000000
1433 #define SV_TYPE_ALL 0xFFFFFFFF
1435 /* what server type are we currently - JHT Says we ARE 4.20 */
1436 /* this was set by JHT in liaison with Jeremy Allison early 1997 */
1437 /* setting to 4.20 at same time as announcing ourselves as NT Server */
1438 /* History: */
1439 /* Version 4.0 - never made public */
1440 /* Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9 */
1441 /* - Reappeared in 1.9.16p11 with fixed smbd services */
1442 /* Version 4.20 - To indicate that nmbd and browsing now works better */
1444 #define DEFAULT_MAJOR_VERSION 0x04
1445 #define DEFAULT_MINOR_VERSION 0x02
1447 /* Browser Election Values */
1448 #define BROWSER_ELECTION_VERSION 0x010f
1449 #define BROWSER_CONSTANT 0xaa55
1451 /* NT Flags2 bits - cifs6.txt section 3.1.2 */
1453 #define FLAGS2_LONG_PATH_COMPONENTS 0x0001
1454 #define FLAGS2_EXTENDED_ATTRIBUTES 0x0002
1455 #define FLAGS2_DFS_PATHNAMES 0x1000
1456 #define FLAGS2_READ_PERMIT_NO_EXECUTE 0x2000
1457 #define FLAGS2_32_BIT_ERROR_CODES 0x4000
1458 #define FLAGS2_UNICODE_STRINGS 0x8000
1460 /* Capabilities. see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
1462 #define CAP_RAW_MODE 0x0001
1463 #define CAP_MPX_MODE 0x0002
1464 #define CAP_UNICODE 0x0004
1465 #define CAP_LARGE_FILES 0x0008
1466 #define CAP_NT_SMBS 0x0010
1467 #define CAP_RPC_REMOTE_APIS 0x0020
1468 #define CAP_STATUS32 0x0040
1469 #define CAP_LEVEL_II_OPLOCKS 0x0080
1470 #define CAP_LOCK_AND_READ 0x0100
1471 #define CAP_NT_FIND 0x0200
1472 #define CAP_DFS 0x1000
1473 #define CAP_LARGE_READX 0x4000
1475 /* protocol types. It assumes that higher protocols include lower protocols
1476 as subsets */
1477 enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
1479 /* security levels */
1480 enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER,SEC_DOMAIN};
1482 /* printing types */
1483 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
1484 PRINT_QNX,PRINT_PLP,PRINT_LPRNG,PRINT_SOFTQ};
1486 /* Remote architectures we know about. */
1487 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_SAMBA};
1489 /* case handling */
1490 enum case_handling {CASE_LOWER,CASE_UPPER};
1492 #ifdef WITH_SSL
1493 /* SSL version options */
1494 enum ssl_version_enum {SMB_SSL_V2,SMB_SSL_V3,SMB_SSL_V23,SMB_SSL_TLS1};
1495 #endif /* WITH_SSL */
1497 /* Macros to get at offsets within smb_lkrng and smb_unlkrng
1498 structures. We cannot define these as actual structures
1499 due to possible differences in structure packing
1500 on different machines/compilers. */
1502 #define SMB_LPID_OFFSET(indx) (10 * (indx))
1503 #define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
1504 #define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
1505 #define SMB_LARGE_LKOFF_OFFSET_HIGH(indx) (4 + (20 * (indx)))
1506 #define SMB_LARGE_LKOFF_OFFSET_LOW(indx) (8 + (20 * (indx)))
1507 #define SMB_LARGE_LKLEN_OFFSET_HIGH(indx) (12 + (20 * (indx)))
1508 #define SMB_LARGE_LKLEN_OFFSET_LOW(indx) (16 + (20 * (indx)))
1510 /* Macro to cache an error in a write_bmpx_struct */
1511 #define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
1512 w->wr_discard = True, -1)
1513 /* Macro to test if an error has been cached for this fnum */
1514 #define HAS_CACHED_ERROR(fsp) ((fsp)->open && (fsp)->wbmpx_ptr && \
1515 (fsp)->wbmpx_ptr->wr_discard)
1516 /* Macro to turn the cached error into an error packet */
1517 #define CACHED_ERROR(fsp) cached_error_packet(inbuf,outbuf,fsp,__LINE__)
1519 /* these are the datagram types */
1520 #define DGRAM_DIRECT_UNIQUE 0x10
1522 #define ERROR(class,x) error_packet(inbuf,outbuf,class,x,__LINE__)
1524 /* this is how errors are generated */
1525 #define UNIXERROR(defclass,deferror) unix_error_packet(inbuf,outbuf,defclass,deferror,__LINE__)
1527 #define SMB_ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
1530 * Global value meaing that the smb_uid field should be
1531 * ingored (in share level security and protocol level == CORE)
1534 #define UID_FIELD_INVALID 0
1535 #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
1537 /* Defines needed for multi-codepage support. */
1538 #define MSDOS_LATIN_1_CODEPAGE 850
1539 #define KANJI_CODEPAGE 932
1540 #define HANGUL_CODEPAGE 949
1541 #define BIG5_CODEPAGE 950
1542 #define SIMPLIFIED_CHINESE_CODEPAGE 936
1544 #ifdef KANJI
1546 * Default client code page - Japanese
1548 #define DEFAULT_CLIENT_CODE_PAGE KANJI_CODEPAGE
1549 #else /* KANJI */
1551 * Default client code page - 850 - Western European
1553 #define DEFAULT_CLIENT_CODE_PAGE MSDOS_LATIN_1_CODEPAGE
1554 #endif /* KANJI */
1557 * Size of buffer to use when moving files across filesystems.
1559 #define COPYBUF_SIZE (8*1024)
1562 * Integers used to override error codes.
1564 extern int unix_ERR_class;
1565 extern int unix_ERR_code;
1568 * Map the Core and Extended Oplock requesst bits down
1569 * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK).
1573 * Core protocol.
1575 #define CORE_OPLOCK_REQUEST(inbuf) \
1576 ((CVAL(inbuf,smb_flg)&(FLAG_REQUEST_OPLOCK|FLAG_REQUEST_BATCH_OPLOCK))>>5)
1579 * Extended protocol.
1581 #define EXTENDED_OPLOCK_REQUEST(inbuf) ((SVAL(inbuf,smb_vwv2)&((1<<1)|(1<<2)))>>1)
1583 /* Lock types. */
1584 #define LOCKING_ANDX_SHARED_LOCK 0x1
1585 #define LOCKING_ANDX_OPLOCK_RELEASE 0x2
1586 #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x4
1587 #define LOCKING_ANDX_CANCEL_LOCK 0x8
1588 #define LOCKING_ANDX_LARGE_FILES 0x10
1590 /* Oplock levels */
1591 #define OPLOCKLEVEL_NONE 0
1592 #define OPLOCKLEVEL_II 1
1595 * Bits we test with.
1597 #define EXCLUSIVE_OPLOCK 1
1598 #define BATCH_OPLOCK 2
1600 #define CORE_OPLOCK_GRANTED (1<<5)
1601 #define EXTENDED_OPLOCK_GRANTED (1<<15)
1604 * Loopback command offsets.
1607 #define OPBRK_CMD_LEN_OFFSET 0
1608 #define OPBRK_CMD_PORT_OFFSET 4
1609 #define OPBRK_CMD_HEADER_LEN 6
1611 #define OPBRK_MESSAGE_CMD_OFFSET 0
1614 * Oplock break command code to send over the udp socket.
1616 * Form of this is :
1618 * 0 2 6 10 14 14+devsize 14+devsize+inodesize
1619 * +----+--------+--------+--------+-------+--------+
1620 * | cmd| pid | sec | usec | dev | inode |
1621 * +----+--------+--------+--------+-------+--------+
1624 #define OPLOCK_BREAK_CMD 0x1
1625 #define OPLOCK_BREAK_PID_OFFSET 2
1626 #define OPLOCK_BREAK_SEC_OFFSET 6
1627 #define OPLOCK_BREAK_USEC_OFFSET 10
1628 #define OPLOCK_BREAK_DEV_OFFSET 14
1629 #define OPLOCK_BREAK_INODE_OFFSET (OPLOCK_BREAK_DEV_OFFSET + sizeof(SMB_DEV_T))
1630 #define OPLOCK_BREAK_MSG_LEN (OPLOCK_BREAK_INODE_OFFSET + sizeof(SMB_INO_T))
1633 * Capabilities abstracted for different systems.
1636 #define KERNEL_OPLOCK_CAPABILITY 0x1
1638 #if defined(HAVE_KERNEL_OPLOCKS)
1640 * Oplock break command code sent via the kernel interface.
1642 * Form of this is :
1644 * 0 2 2+devsize 2+devsize+inodesize
1645 * +----+--------+--------+
1646 * | cmd| dev | inode |
1647 * +----+--------+--------+
1650 #define KERNEL_OPLOCK_BREAK_CMD 0x2
1651 #define KERNEL_OPLOCK_BREAK_DEV_OFFSET 2
1652 #define KERNEL_OPLOCK_BREAK_INODE_OFFSET (KERNEL_OPLOCK_BREAK_DEV_OFFSET + sizeof(SMB_DEV_T))
1653 #define KERNEL_OPLOCK_BREAK_MSG_LEN (KERNEL_OPLOCK_BREAK_INODE_OFFSET + sizeof(SMB_INO_T))
1655 #endif /* HAVE_KERNEL_OPLOCKS */
1657 #define CMD_REPLY 0x8000
1659 /* useful macros */
1661 /* zero a structure */
1662 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
1664 /* zero a structure given a pointer to the structure - no zero check */
1665 #define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x)))
1667 /* zero a structure given a pointer to the structure */
1668 #define ZERO_STRUCTP(x) { if ((x) != NULL) ZERO_STRUCTPN(x); }
1670 /* zero an array - note that sizeof(array) must work - ie. it must not be a
1671 pointer */
1672 #define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x))
1674 #define SMB_ASSERT(b) ((b)?(void)0: \
1675 (DEBUG(0,("PANIC: assert failed at %s(%d)\n", \
1676 __FILE__, __LINE__)), smb_panic("assert failed")))
1677 #define SMB_ASSERT_ARRAY(a,n) SMB_ASSERT((sizeof(a)/sizeof((a)[0])) >= (n))
1679 /* A netbios name structure. */
1680 struct nmb_name {
1681 char name[17];
1682 char scope[64];
1683 unsigned int name_type;
1686 #include "client.h"
1689 * Size of new password account encoding string. DO NOT CHANGE.
1692 #define NEW_PW_FORMAT_SPACE_PADDED_LEN 14
1695 Do you want session setups at user level security with a invalid
1696 password to be rejected or allowed in as guest? WinNT rejects them
1697 but it can be a pain as it means "net view" needs to use a password
1699 You have 3 choices in the setting of map_to_guest:
1701 "NEVER_MAP_TO_GUEST" means session setups with an invalid password
1702 are rejected. This is the default.
1704 "MAP_TO_GUEST_ON_BAD_USER" means session setups with an invalid password
1705 are rejected, unless the username does not exist, in which case it
1706 is treated as a guest login
1708 "MAP_TO_GUEST_ON_BAD_PASSWORD" means session setups with an invalid password
1709 are treated as a guest login
1711 Note that map_to_guest only has an effect in user or server
1712 level security.
1715 #define NEVER_MAP_TO_GUEST 0
1716 #define MAP_TO_GUEST_ON_BAD_USER 1
1717 #define MAP_TO_GUEST_ON_BAD_PASSWORD 2
1719 #endif /* _SMB_H */
1721 /* _SMB_H */