2 Unix SMB/Netbios implementation.
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
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.
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.
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.
27 #define BUFFER_SIZE (0xFFFF)
28 #define SAFETY_MARGIN 1024
31 #define DGRAM_PORT 138
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)
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)
44 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2)))
48 /* limiting size of ipc replies */
49 #define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024))
53 #ifndef DEF_CREATE_MASK
54 #define DEF_CREATE_MASK (0755)
57 /* how long to wait for secondary SMB packets (milli-seconds) */
58 #define SMB_SECONDARY_WAIT (60*1000)
60 /* -------------------------------------------------------------------------- **
61 * Debugging code. See also debug.c
64 /* mkproto.awk has trouble with ifdef'd function definitions (it ignores
65 * the #ifdef directive and will read both definitions, thus creating two
66 * diffferent prototype declarations), so we must do these by hand.
68 /* I know the __attribute__ stuff is ugly, but it does ensure we get the
69 arguemnts to DEBUG() right. We have got them wrong too often in the
73 int Debug1( char *, ... )
75 __attribute__ ((format (printf, 1, 2)))
78 BOOL dbgtext( char *, ... )
80 __attribute__ ((format (printf, 1, 2)))
88 /* If we have these macros, we can add additional info to the header. */
89 #ifdef HAVE_FILE_MACRO
90 #define FILE_MACRO (__FILE__)
92 #define FILE_MACRO ("")
95 #ifdef HAVE_FUNCTION_MACRO
96 #define FUNCTION_MACRO (__FUNCTION__)
98 #define FUNCTION_MACRO ("")
102 * DEBUGLVL() - If level is <= the system-wide DEBUGLEVEL then generate a
103 * header using the default macros for file, line, and
105 * Returns True if the debug level was <= DEBUGLEVEL.
107 * if( DEBUGLVL( 2 ) )
108 * dbgtext( "Some text.\n" );
109 * DEGUG() - Good old DEBUG(). Each call to DEBUG() will generate a new
110 * header *unless* the previous debug output was unterminated
111 * (i.e., no '\n'). See debug.c:dbghdr() for more info.
113 * DEBUG( 2, ("Some text.\n") );
114 * DEBUGADD() - If level <= DEBUGLEVEL, then the text is appended to the
115 * current message (i.e., no header).
117 * DEBUGADD( 2, ("Some additional text.\n") );
119 #define DEBUGLVL( level ) \
120 ( (DEBUGLEVEL >= (level)) \
121 && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
123 #define DEBUG( level, body ) \
124 (void)( (DEBUGLEVEL >= (level)) \
125 && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \
128 #define DEBUGADD( level, body ) \
129 (void)( (DEBUGLEVEL >= (level)) && (dbgtext body) )
131 /* -------------------------------------------------------------------------- **
132 * These are the tokens returned by dbg_char2token().
149 /* End Debugging code section.
150 * -------------------------------------------------------------------------- **
153 /* this defines the error codes that receive_smb can put in smb_read_error */
154 #define READ_TIMEOUT 1
159 #define DIR_STRUCT_SIZE 43
161 /* these define all the command types recognised by the server - there
162 are lots of gaps so probably there are some rare commands that are not
165 #define pSETDIR '\377'
167 /* these define the attribute byte as seen by DOS */
168 #define aRONLY (1L<<0)
169 #define aHIDDEN (1L<<1)
170 #define aSYSTEM (1L<<2)
171 #define aVOLID (1L<<3)
173 #define aARCH (1L<<5)
175 /* for readability... */
176 #define IS_DOS_READONLY(test_mode) (((test_mode) & aRONLY) != 0)
177 #define IS_DOS_DIR(test_mode) (((test_mode) & aDIR) != 0)
178 #define IS_DOS_ARCHIVE(test_mode) (((test_mode) & aARCH) != 0)
179 #define IS_DOS_SYSTEM(test_mode) (((test_mode) & aSYSTEM) != 0)
180 #define IS_DOS_HIDDEN(test_mode) (((test_mode) & aHIDDEN) != 0)
191 #define DOS_OPEN_RDONLY 0
192 #define DOS_OPEN_WRONLY 1
193 #define DOS_OPEN_RDWR 2
194 #define DOS_OPEN_FCB 0xF
196 /* define shifts and masks for share and open modes. */
197 #define OPEN_MODE_MASK 0xF
198 #define SHARE_MODE_SHIFT 4
199 #define SHARE_MODE_MASK 0x7
200 #define GET_OPEN_MODE(x) ((x) & OPEN_MODE_MASK)
201 #define SET_OPEN_MODE(x) ((x) & OPEN_MODE_MASK)
202 #define GET_DENY_MODE(x) (((x)>>SHARE_MODE_SHIFT) & SHARE_MODE_MASK)
203 #define SET_DENY_MODE(x) ((x)<<SHARE_MODE_SHIFT)
205 /* Sync on open file (not sure if used anymore... ?) */
206 #define FILE_SYNC_OPENMODE (1<<14)
207 #define GET_FILE_SYNC_OPENMODE(x) (((x) & FILE_SYNC_OPENMODE) ? True : False)
209 /* allow delete on open file mode (used by NT SMB's). */
210 #define ALLOW_SHARE_DELETE (1<<15)
211 #define GET_ALLOW_SHARE_DELETE(x) (((x) & ALLOW_SHARE_DELETE) ? True : False)
212 #define SET_ALLOW_SHARE_DELETE(x) ((x) ? ALLOW_SHARE_DELETE : 0)
214 /* delete on close flag (used by NT SMB's). */
215 #define DELETE_ON_CLOSE_FLAG (1<<16)
216 #define GET_DELETE_ON_CLOSE_FLAG(x) (((x) & DELETE_ON_CLOSE_FLAG) ? True : False)
217 #define SET_DELETE_ON_CLOSE_FLAG(x) ((x) ? DELETE_ON_CLOSE_FLAG : 0)
219 /* open disposition values */
220 #define FILE_EXISTS_FAIL 0
221 #define FILE_EXISTS_OPEN 1
222 #define FILE_EXISTS_TRUNCATE 2
224 /* mask for open disposition. */
225 #define FILE_OPEN_MASK 0x3
227 #define GET_FILE_OPEN_DISPOSITION(x) ((x) & FILE_OPEN_MASK)
228 #define SET_FILE_OPEN_DISPOSITION(x) ((x) & FILE_OPEN_MASK)
230 /* The above can be OR'ed with... */
231 #define FILE_CREATE_IF_NOT_EXIST 0x10
232 #define FILE_FAIL_IF_NOT_EXIST 0
234 #define GET_FILE_CREATE_DISPOSITION(x) ((x) & (FILE_CREATE_IF_NOT_EXIST|FILE_FAIL_IF_NOT_EXIST))
237 #define STYPE_DISKTREE 0 /* Disk drive */
238 #define STYPE_PRINTQ 1 /* Spooler queue */
239 #define STYPE_DEVICE 2 /* Serial device */
240 #define STYPE_IPC 3 /* Interprocess communication (IPC) */
241 #define STYPE_HIDDEN 0x80000000 /* share is a hidden one (ends with $) */
243 /* SMB X/Open error codes for the ERRDOS error class */
244 #define ERRbadfunc 1 /* Invalid function (or system call) */
245 #define ERRbadfile 2 /* File not found (pathname error) */
246 #define ERRbadpath 3 /* Directory not found */
247 #define ERRnofids 4 /* Too many open files */
248 #define ERRnoaccess 5 /* Access denied */
249 #define ERRbadfid 6 /* Invalid fid */
250 #define ERRnomem 8 /* Out of memory */
251 #define ERRbadmem 9 /* Invalid memory block address */
252 #define ERRbadenv 10 /* Invalid environment */
253 #define ERRbadaccess 12 /* Invalid open mode */
254 #define ERRbaddata 13 /* Invalid data (only from ioctl call) */
255 #define ERRres 14 /* reserved */
256 #define ERRbaddrive 15 /* Invalid drive */
257 #define ERRremcd 16 /* Attempt to delete current directory */
258 #define ERRdiffdevice 17 /* rename/move across different filesystems */
259 #define ERRnofiles 18 /* no more files found in file search */
260 #define ERRbadshare 32 /* Share mode on file conflict with open mode */
261 #define ERRlock 33 /* Lock request conflicts with existing lock */
262 #define ERRunsup 50 /* Request unsupported, returned by Win 95, RJS 20Jun98 */
263 #define ERRfilexists 80 /* File in operation already exists */
264 #define ERRcannotopen 110 /* Cannot open the file specified */
265 #define ERRunknownlevel 124
266 #define ERRrename 183
267 #define ERRbadpipe 230 /* Named pipe invalid */
268 #define ERRpipebusy 231 /* All instances of pipe are busy */
269 #define ERRpipeclosing 232 /* named pipe close in progress */
270 #define ERRnotconnected 233 /* No process on other end of named pipe */
271 #define ERRmoredata 234 /* More data to be returned */
272 #define ERRbaddirectory 267 /* Invalid directory name in a path. */
273 #define ERROR_EAS_DIDNT_FIT 275 /* Extended attributes didn't fit */
274 #define ERROR_EAS_NOT_SUPPORTED 282 /* Extended attributes not supported */
275 #define ERROR_NOTIFY_ENUM_DIR 1022 /* Buffer too small to return change notify. */
276 #define ERRunknownipc 2142
279 /* here's a special one from observing NT */
280 #define ERRnoipc 66 /* don't support ipc */
282 /* Error codes for the ERRSRV class */
284 #define ERRerror 1 /* Non specific error code */
285 #define ERRbadpw 2 /* Bad password */
286 #define ERRbadtype 3 /* reserved */
287 #define ERRaccess 4 /* No permissions to do the requested operation */
288 #define ERRinvnid 5 /* tid invalid */
289 #define ERRinvnetname 6 /* Invalid servername */
290 #define ERRinvdevice 7 /* Invalid device */
291 #define ERRqfull 49 /* Print queue full */
292 #define ERRqtoobig 50 /* Queued item too big */
293 #define ERRinvpfid 52 /* Invalid print file in smb_fid */
294 #define ERRsmbcmd 64 /* Unrecognised command */
295 #define ERRsrverror 65 /* smb server internal error */
296 #define ERRfilespecs 67 /* fid and pathname invalid combination */
297 #define ERRbadlink 68 /* reserved */
298 #define ERRbadpermits 69 /* Access specified for a file is not valid */
299 #define ERRbadpid 70 /* reserved */
300 #define ERRsetattrmode 71 /* attribute mode invalid */
301 #define ERRpaused 81 /* Message server paused */
302 #define ERRmsgoff 82 /* Not receiving messages */
303 #define ERRnoroom 83 /* No room for message */
304 #define ERRrmuns 87 /* too many remote usernames */
305 #define ERRtimeout 88 /* operation timed out */
306 #define ERRnoresource 89 /* No resources currently available for request. */
307 #define ERRtoomanyuids 90 /* too many userids */
308 #define ERRbaduid 91 /* bad userid */
309 #define ERRuseMPX 250 /* temporarily unable to use raw mode, use MPX mode */
310 #define ERRuseSTD 251 /* temporarily unable to use raw mode, use standard mode */
311 #define ERRcontMPX 252 /* resume MPX mode */
312 #define ERRbadPW /* reserved */
313 #define ERRnosupport 0xFFFF
314 #define ERRunknownsmb 22 /* from NT 3.5 response */
317 /* Error codes for the ERRHRD class */
319 #define ERRnowrite 19 /* read only media */
320 #define ERRbadunit 20 /* Unknown device */
321 #define ERRnotready 21 /* Drive not ready */
322 #define ERRbadcmd 22 /* Unknown command */
323 #define ERRdata 23 /* Data (CRC) error */
324 #define ERRbadreq 24 /* Bad request structure length */
326 #define ERRbadmedia 26
327 #define ERRbadsector 27
328 #define ERRnopaper 28
329 #define ERRwrite 29 /* write fault */
330 #define ERRread 30 /* read fault */
331 #define ERRgeneral 31 /* General hardware failure */
332 #define ERRwrongdisk 34
333 #define ERRFCBunavail 35
334 #define ERRsharebufexc 36 /* share buffer exceeded */
335 #define ERRdiskfull 39
338 typedef char pstring[1024];
339 typedef char fstring[128];
341 /* pipe string names */
342 #define PIPE_LANMAN "\\PIPE\\LANMAN"
343 #define PIPE_SRVSVC "\\PIPE\\srvsvc"
344 #define PIPE_SAMR "\\PIPE\\samr"
345 #define PIPE_WINREG "\\PIPE\\winreg"
346 #define PIPE_WKSSVC "\\PIPE\\wkssvc"
347 #define PIPE_NETLOGON "\\PIPE\\NETLOGON"
348 #define PIPE_SVCCTL "\\PIPE\\SVCCTL"
349 #define PIPE_NTLSA "\\PIPE\\ntlsa"
350 #define PIPE_NTSVCS "\\PIPE\\ntsvcs"
351 #define PIPE_LSASS "\\PIPE\\lsass"
352 #define PIPE_LSARPC "\\PIPE\\lsarpc"
355 /* 64 bit time (100usec) since ????? - cifs6.txt, section 3.5, page 30 */
356 typedef struct nttime_info
363 /* Allowable account control bits */
364 #define ACB_DISABLED 0x0001 /* 1 = User account disabled */
365 #define ACB_HOMDIRREQ 0x0002 /* 1 = Home directory required */
366 #define ACB_PWNOTREQ 0x0004 /* 1 = User password not required */
367 #define ACB_TEMPDUP 0x0008 /* 1 = Temporary duplicate account */
368 #define ACB_NORMAL 0x0010 /* 1 = Normal user account */
369 #define ACB_MNS 0x0020 /* 1 = MNS logon user account */
370 #define ACB_DOMTRUST 0x0040 /* 1 = Interdomain trust account */
371 #define ACB_WSTRUST 0x0080 /* 1 = Workstation trust account */
372 #define ACB_SVRTRUST 0x0100 /* 1 = Server trust account */
373 #define ACB_PWNOEXP 0x0200 /* 1 = User password does not expire */
374 #define ACB_AUTOLOCK 0x0400 /* 1 = Account auto locked */
375 #define ACB_PWLOCK 0x0800 /* 1 = Password is locked and connot be changed remotely */
377 #define MAX_HOURS_LEN 32
381 NTTIME logon_time; /* logon time */
382 NTTIME logoff_time; /* logoff time */
383 NTTIME kickoff_time; /* kickoff time */
384 NTTIME pass_last_set_time; /* password last set time */
385 NTTIME pass_can_change_time; /* password can change time */
386 NTTIME pass_must_change_time; /* password must change time */
388 char *unix_name; /* unix username string */
389 char *nt_name; /* nt username string */
390 char *full_name; /* user's full name string */
391 char *home_dir; /* home directory string */
392 char *dir_drive; /* home directory drive string */
393 char *logon_script; /* logon script string */
394 char *profile_path; /* profile path string */
395 char *acct_desc ; /* user description string */
396 char *workstations; /* login from workstations string */
397 char *unknown_str ; /* don't know what this is, yet. */
398 char *munged_dial ; /* munged path name and dial-back tel number */
400 uid_t unix_uid; /* this is actually the unix uid_t */
401 gid_t unix_gid; /* this is actually the unix gid_t */
402 uint32 user_rid; /* Primary User ID */
403 uint32 group_rid; /* Primary Group ID */
405 unsigned char *smb_passwd; /* Null if no password */
406 unsigned char *smb_nt_passwd; /* Null if no password */
408 uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */
409 uint32 unknown_3; /* 0x00ff ffff */
411 uint16 logon_divs; /* 168 - number of hours in a week */
412 uint32 hours_len; /* normally 21 bytes */
413 uint8 hours[MAX_HOURS_LEN];
415 uint32 unknown_5; /* 0x0002 0000 */
416 uint32 unknown_6; /* 0x0000 04ec */
421 uid_t unix_uid; /* unix userid */
422 char *unix_name; /* unix username string */
424 uint32 user_rid; /* Primary User ID */
425 char *nt_name; /* unix username string */
427 unsigned char *smb_passwd; /* Null if no password */
428 unsigned char *smb_nt_passwd; /* Null if no password */
430 uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */
431 time_t pass_last_set_time; /* password last set time */
437 uint32 user_rid; /* Primary User ID */
438 char *nt_name; /* username string */
439 char *full_name; /* user's full name string */
442 #define MAXSUBAUTHS 15 /* max sub authorities in a SID */
444 /* DOM_SID - security id */
445 typedef struct sid_info
447 uint8 sid_rev_num; /* SID revision number */
448 uint8 num_auths; /* number of sub-authorities */
449 uint8 id_auth[6]; /* Identifier Authority */
451 * Note that the values in these uint32's are in *native* byteorder,
452 * not neccessarily little-endian...... JRA.
454 uint32 sub_auths[MAXSUBAUTHS]; /* pointer to sub-authorities. */
459 typedef struct group_name_info
471 /* map either local aliases, domain groups or builtin aliases */
481 /*** query a local group, get a list of these: shows who is in that group ***/
483 /* local group member info */
484 typedef struct local_grp_member_info
486 DOM_SID sid ; /* matches with name */
487 uint8 sid_use; /* usr=1 grp=2 dom=3 alias=4 wkng=5 del=6 inv=7 unk=8 */
488 fstring name ; /* matches with sid: must be of the form "DOMAIN\account" */
492 /* enumerate these to get list of local groups */
494 /* local group info */
495 typedef struct local_grp_info
499 uint32 rid; /* alias rid */
503 /*** query a domain group, get a list of these: shows who is in that group ***/
505 /* domain group info */
506 typedef struct domain_grp_member_info
509 uint8 attr; /* attributes forced to be set to 0x7: SE_GROUP_xxx */
510 uint32 rid; /* rid of domain group member */
511 uint8 sid_use; /* usr=1 grp=2 dom=3 alias=4 wkng=5 del=6 inv=7 unk=8 */
515 /*** enumerate these to get list of domain groups ***/
517 /* domain group member info */
518 typedef struct domain_grp_info
522 uint32 rid; /* group rid */
523 uint8 attr; /* attributes forced to be set to 0x7: SE_GROUP_xxx */
527 /* DOM_CHAL - challenge info */
528 typedef struct chal_info
530 uchar data[8]; /* credentials */
533 /* 32 bit time (sec) since 01jan1970 - cifs6.txt, section 3.5, page 30 */
534 typedef struct time_info
539 /* DOM_CREDs - timestamped client or server credentials */
540 typedef struct cred_info
542 DOM_CHAL challenge; /* credentials */
543 UTIME timestamp; /* credential time-stamp */
546 /* Structure used when SMBwritebmpx is active */
549 size_t wr_total_written; /* So we know when to discard this */
552 int32 wr_error; /* Cached errors */
553 BOOL wr_mode; /* write through mode) */
554 BOOL wr_discard; /* discard all further data */
558 * Structure used to indirect fd's from the files_struct.
559 * Needed as POSIX locking is based on file and process, not
560 * file descriptor and process.
563 typedef struct file_fd_struct
565 struct file_fd_struct *next, *prev;
567 uint16 uid_cache_count;
568 uid_t uid_users_cache[10];
575 BOOL delete_on_close;
579 * Structure used to keep directory state information around.
580 * Used in NT change-notify code.
591 uid_t list[UID_CACHE_SIZE];
598 } name_compare_entry;
600 typedef struct connection_struct
602 struct connection_struct *next, *prev;
603 unsigned cnum; /* an index passed over the wire */
606 struct uid_cache uid_cache;
615 char *user; /* name of user who *opened* this connection */
617 uid_t uid; /* uid of user who *opened* this connection */
618 gid_t gid; /* gid of user who *opened* this connection */
620 uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
622 /* following groups stuff added by ih */
624 /* This groups info is valid for the user that *opened* the connection */
631 name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */
632 name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */
633 name_compare_entry *veto_oplock_list; /* Per-share list of files to refuse oplocks on. */
649 /* this should (will?) probably become a SEC_DESC */
660 struct unix_sec_ctxt unix;
661 struct nt_sec_ctxt nt;
667 connection_struct *conn;
675 typedef struct files_struct
677 struct files_struct *next, *prev;
679 connection_struct *conn;
680 file_fd_struct *fd_ptr;
687 write_bmpx_struct *wbmpx_ptr;
688 struct timeval open_time;
690 time_t pending_modtime;
698 BOOL sent_oplock_break;
703 /* Domain controller authentication protocol info */
706 DOM_CHAL clnt_chal; /* Initial challenge received from client */
707 DOM_CHAL srv_chal; /* Initial server challenge */
708 DOM_CRED clnt_cred; /* Last client credential */
709 DOM_CRED srv_cred; /* Last server credential */
711 uchar sess_key[8]; /* Session key */
712 uchar md4pw[16]; /* md4(machine password) */
713 uchar user_sess_key[16]; /* user session key (md4 nt#) */
718 uid_t uid; /* uid of a validated user */
719 gid_t gid; /* gid of a validated user */
721 fstring requested_name; /* user name from the client */
722 fstring name; /* unix user name of a validated user */
723 fstring real_name; /* to store real name from password file - simeon */
726 /* following groups stuff added by ih */
727 /* This groups info is needed for when we become_user() for this uid */
734 /* per-user authentication information on NT RPCs */
740 enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING};
751 } print_queue_struct;
753 enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
759 } print_status_struct;
761 /* used for server information: client, nameserv and ipc */
762 struct server_info_struct
767 fstring domain; /* used ONLY in ipc.c NOT namework.c */
768 BOOL server_added; /* used ONLY in ipc.c NOT namework.c */
772 /* used for network interfaces */
775 struct interface *next;
777 struct in_addr bcast;
778 struct in_addr nmask;
781 /* struct returned by get_share_modes */
792 /* each implementation of the share mode code needs
793 to support the following operations */
795 BOOL (*stop_mgmt)(void);
796 BOOL (*lock_entry)(connection_struct *, SMB_DEV_T , SMB_INO_T , int *);
797 BOOL (*unlock_entry)(connection_struct *, SMB_DEV_T , SMB_INO_T , int );
798 int (*get_entries)(connection_struct *, int , SMB_DEV_T , SMB_INO_T , share_mode_entry **);
799 void (*del_entry)(int , files_struct *);
800 BOOL (*set_entry)(int, files_struct *, uint16 , uint16 );
801 BOOL (*mod_entry)(int, files_struct *, void (*)(share_mode_entry *, SMB_DEV_T, SMB_INO_T, void *), void *);
802 int (*forall)(void (*)(share_mode_entry *, char *));
803 void (*status)(FILE *);
806 /* each implementation of the shared memory code needs
807 to support the following operations */
809 BOOL (*shm_close)( void );
810 int (*shm_alloc)(int );
811 BOOL (*shm_free)(int );
812 int (*get_userdef_off)(void);
813 void *(*offset2addr)(int );
814 int (*addr2offset)(void *addr);
815 BOOL (*lock_hash_entry)(unsigned int);
816 BOOL (*unlock_hash_entry)( unsigned int );
817 BOOL (*get_usage)(int *,int *,int *);
818 unsigned (*hash_size)(void);
822 * Each implementation of the password database code needs
823 * to support the following operations.
826 struct smb_passdb_ops
829 * Password database operations.
831 void *(*startsmbpwent)(BOOL);
832 void (*endsmbpwent)(void *);
833 SMB_BIG_UINT (*getsmbpwpos)(void *);
834 BOOL (*setsmbpwpos)(void *, SMB_BIG_UINT);
837 * smb password database query functions.
839 struct smb_passwd *(*getsmbpwnam)(const char *);
840 struct smb_passwd *(*getsmbpwuid)(uid_t);
841 struct smb_passwd *(*getsmbpwent)(void *);
844 * smb password database modification functions.
846 BOOL (*add_smbpwd_entry)(struct smb_passwd *);
847 BOOL (*mod_smbpwd_entry)(struct smb_passwd *, BOOL);
851 * password checking functions
853 struct smb_passwd *(*smb_password_chal )(const char *username, const char lm_pass[24], const char nt_pass[24], char chal[8]);
854 struct smb_passwd *(*smb_password_check )(const char *username, const char lm_hash[16], const char nt_hash[16]);
855 struct passwd *(*unix_password_check)(const char *username, const char *pass, int pass_len);
860 * Each implementation of the password database code needs
861 * to support the following operations.
864 struct sam_passdb_ops {
866 * Password database operations.
868 void *(*startsam21pwent)(BOOL);
869 void (*endsam21pwent)(void *);
870 SMB_BIG_UINT (*getsam21pwpos)(void *);
871 BOOL (*setsam21pwpos)(void *, SMB_BIG_UINT);
874 * sam password database query functions.
876 struct sam_passwd *(*getsam21pwntnam)(const char *);
877 struct sam_passwd *(*getsam21pwuid)(uid_t);
878 struct sam_passwd *(*getsam21pwrid)(uint32);
879 struct sam_passwd *(*getsam21pwent)(void *);
882 * sam password database modification functions.
884 BOOL (*add_sam21pwd_entry)(struct sam_passwd *);
885 BOOL (*mod_sam21pwd_entry)(struct sam_passwd *, BOOL);
888 * sam query display info functions.
890 struct sam_disp_info *(*getsamdispntnam)(const char *);
891 struct sam_disp_info *(*getsamdisprid)(uint32);
892 struct sam_disp_info *(*getsamdispent)(void *);
897 * Each implementation of the passgrp database code needs
898 * to support the following operations.
904 * Password group database ops.
906 void *(*startsmbgrpent)(BOOL);
907 void (*endsmbgrpent)(void *);
908 SMB_BIG_UINT (*getsmbgrppos)(void *);
909 BOOL (*setsmbgrppos)(void *, SMB_BIG_UINT);
912 * smb passgrp database query functions, by user attributes.
914 struct smb_passwd *(*getsmbgrpntnam)(const char *, uint32**, int*, uint32**, int*);
915 struct smb_passwd *(*getsmbgrpuid)(uid_t , uint32**, int*, uint32**, int*);
916 struct smb_passwd *(*getsmbgrprid)(uint32, uint32**, int*, uint32**, int*);
917 struct smb_passwd *(*getsmbgrpent)(void *, uint32**, int*, uint32**, int*);
921 * Each implementation of the group database code needs
922 * to support the following operations.
924 * This allows enumeration, modification and addition of groups. there
925 * is _no_ deletion of groups: you can only modify them to a status of
926 * "deleted" (this by the way is a requirement of c2 rating)
932 * Group database ops.
934 void *(*startgroupent)(BOOL);
935 void (*endgroupent)(void *);
936 SMB_BIG_UINT (*getgrouppos)(void *);
937 BOOL (*setgrouppos)(void *, SMB_BIG_UINT);
940 * group database query functions.
942 DOMAIN_GRP *(*getgroupntnam)(const char *, DOMAIN_GRP_MEMBER **, int *);
943 DOMAIN_GRP *(*getgroupgid)(gid_t , DOMAIN_GRP_MEMBER **, int *);
944 DOMAIN_GRP *(*getgrouprid)(uint32, DOMAIN_GRP_MEMBER **, int *);
945 DOMAIN_GRP *(*getgroupent)(void *, DOMAIN_GRP_MEMBER **, int *);
948 * group database modification functions.
950 BOOL (*add_group_entry)(DOMAIN_GRP *);
951 BOOL (*mod_group_entry)(DOMAIN_GRP *);
952 BOOL (*del_group_entry)(uint32);
954 BOOL (*add_group_member)(uint32, uint32);
955 BOOL (*del_group_member)(uint32, uint32);
958 * user group functions
960 BOOL (*getusergroupsntnam)(const char *, DOMAIN_GRP **, int *);
964 * Each implementation of the alias database code needs
965 * to support the following operations.
967 * This allows enumeration, modification and addition of aliases. there
968 * is _no_ deletion of aliases: you can only modify them to a status of
969 * "deleted" (this by the way is a requirement of c2 rating)
975 * Alias database ops.
977 void *(*startaliasent)(BOOL);
978 void (*endaliasent)(void *);
979 SMB_BIG_UINT (*getaliaspos)(void *);
980 BOOL (*setaliaspos)(void *, SMB_BIG_UINT);
983 * alias database query functions.
985 LOCAL_GRP *(*getaliasntnam)(const char *, LOCAL_GRP_MEMBER **, int *);
986 LOCAL_GRP *(*getaliasgid)(gid_t , LOCAL_GRP_MEMBER **, int *);
987 LOCAL_GRP *(*getaliasrid)(uint32, LOCAL_GRP_MEMBER **, int *);
988 LOCAL_GRP *(*getaliasent)(void *, LOCAL_GRP_MEMBER **, int *);
991 * alias database modification functions.
993 BOOL (*add_alias_entry)(LOCAL_GRP *);
994 BOOL (*mod_alias_entry)(LOCAL_GRP *);
995 BOOL (*del_alias_entry)(uint32);
997 BOOL (*add_alias_member)(uint32, DOM_SID*);
998 BOOL (*del_alias_member)(uint32, DOM_SID*);
1001 * user alias functions
1003 BOOL (*getuseraliasntnam)(const char *, LOCAL_GRP **, int *);
1006 /* this is used for smbstatus */
1008 struct connect_record
1021 /* This is used by smbclient to send it to a smbfs mount point */
1022 struct connection_options {
1024 /* Connection-Options */
1028 /* The following are LANMAN 1.0 options */
1034 /* The following are NT LM 0.12 options */
1036 uint32 capabilities;
1040 /* the following are used by loadparm for option lists */
1043 P_BOOL,P_BOOLREV,P_CHAR,P_INTEGER,P_OCTAL,
1044 P_STRING,P_USTRING,P_GSTRING,P_UGSTRING,P_ENUM,P_SEP
1049 P_LOCAL,P_GLOBAL,P_SEPARATOR,P_NONE
1063 BOOL (*special)(char *, char **);
1064 struct enum_list *enum_list;
1079 #define FLAG_BASIC 1 /* fundamental options */
1080 #define FLAG_HIDE 2 /* options that should be hidden in SWAT */
1081 #define FLAG_PRINT 4 /* printing options */
1082 #define FLAG_GLOBAL 8 /* local options that should be globally settable in SWAT */
1083 #define FLAG_DEPRECATED 0x10 /* options that should no longer be used */
1085 #ifndef LOCKING_VERSION
1086 #define LOCKING_VERSION 4
1087 #endif /* LOCKING_VERSION */
1089 /* these are useful macros for checking validity of handles */
1090 #define OPEN_FSP(fsp) ((fsp) && (fsp)->open && !(fsp)->is_directory)
1091 #define OPEN_CONN(conn) ((conn) && (conn)->open)
1092 #define IS_IPC(conn) ((conn) && (conn)->ipc)
1093 #define IS_PRINT(conn) ((conn) && (conn)->printer)
1094 #define FNUM_OK(fsp,c) (OPEN_FSP(fsp) && (c)==(fsp)->conn)
1096 #define CHECK_FSP(fsp,conn) if (!FNUM_OK(fsp,conn)) \
1097 return(ERROR(ERRDOS,ERRbadfid))
1098 #define CHECK_READ(fsp) if (!(fsp)->can_read) \
1099 return(ERROR(ERRDOS,ERRbadaccess))
1100 #define CHECK_WRITE(fsp) if (!(fsp)->can_write) \
1101 return(ERROR(ERRDOS,ERRbadaccess))
1102 #define CHECK_ERROR(fsp) if (HAS_CACHED_ERROR(fsp)) \
1103 return(CACHED_ERROR(fsp))
1105 /* translates a connection number into a service number */
1106 #define SNUM(conn) ((conn)?(conn)->service:-1)
1108 /* access various service details */
1109 #define SERVICE(snum) (lp_servicename(snum))
1110 #define PRINTCAP (lp_printcapname())
1111 #define PRINTCOMMAND(snum) (lp_printcommand(snum))
1112 #define PRINTERNAME(snum) (lp_printername(snum))
1113 #define CAN_WRITE(conn) (!conn->read_only)
1114 #define VALID_SNUM(snum) (lp_snum_ok(snum))
1115 #define GUEST_OK(snum) (VALID_SNUM(snum) && lp_guest_ok(snum))
1116 #define GUEST_ONLY(snum) (VALID_SNUM(snum) && lp_guest_only(snum))
1117 #define CAN_SETDIR(snum) (!lp_no_set_dir(snum))
1118 #define CAN_PRINT(conn) ((conn) && lp_print_ok((conn)->service))
1119 #define MAP_HIDDEN(conn) ((conn) && lp_map_hidden((conn)->service))
1120 #define MAP_SYSTEM(conn) ((conn) && lp_map_system((conn)->service))
1121 #define MAP_ARCHIVE(conn) ((conn) && lp_map_archive((conn)->service))
1122 #define IS_HIDDEN_PATH(conn,path) ((conn) && is_in_path((path),(conn)->hide_list))
1123 #define IS_VETO_PATH(conn,path) ((conn) && is_in_path((path),(conn)->veto_list))
1124 #define IS_VETO_OPLOCK_PATH(conn,path) ((conn) && is_in_path((path),(conn)->veto_oplock_list))
1127 * Used by the stat cache code to check if a returned
1128 * stat structure is valid.
1131 #define VALID_STAT(st) (st.st_nlink != 0)
1132 #define VALID_STAT_OF_DIR(st) (VALID_STAT(st) && S_ISDIR(st.st_mode))
1134 #define SMBENCRYPT() (lp_encrypted_passwords())
1136 /* the basic packet size, assuming no words or bytes */
1139 /* offsets into message for common items */
1163 #define smb_vwv10 57
1164 #define smb_vwv11 59
1165 #define smb_vwv12 61
1166 #define smb_vwv13 63
1167 #define smb_vwv14 65
1168 #define smb_vwv15 67
1169 #define smb_vwv16 69
1170 #define smb_vwv17 71
1172 /* flag defines. CIFS spec 3.1.1 */
1173 #define FLAG_SUPPORT_LOCKREAD 0x01
1174 #define FLAG_CLIENT_BUF_AVAIL 0x02
1175 #define FLAG_RESERVED 0x04
1176 #define FLAG_CASELESS_PATHNAMES 0x08
1177 #define FLAG_CANONICAL_PATHNAMES 0x10
1178 #define FLAG_REQUEST_OPLOCK 0x20
1179 #define FLAG_REQUEST_BATCH_OPLOCK 0x40
1180 #define FLAG_REPLY 0x80
1183 #define SMBmkdir 0x00 /* create directory */
1184 #define SMBrmdir 0x01 /* delete directory */
1185 #define SMBopen 0x02 /* open file */
1186 #define SMBcreate 0x03 /* create file */
1187 #define SMBclose 0x04 /* close file */
1188 #define SMBflush 0x05 /* flush file */
1189 #define SMBunlink 0x06 /* delete file */
1190 #define SMBmv 0x07 /* rename file */
1191 #define SMBgetatr 0x08 /* get file attributes */
1192 #define SMBsetatr 0x09 /* set file attributes */
1193 #define SMBread 0x0A /* read from file */
1194 #define SMBwrite 0x0B /* write to file */
1195 #define SMBlock 0x0C /* lock byte range */
1196 #define SMBunlock 0x0D /* unlock byte range */
1197 #define SMBctemp 0x0E /* create temporary file */
1198 #define SMBmknew 0x0F /* make new file */
1199 #define SMBchkpth 0x10 /* check directory path */
1200 #define SMBexit 0x11 /* process exit */
1201 #define SMBlseek 0x12 /* seek */
1202 #define SMBtcon 0x70 /* tree connect */
1203 #define SMBtconX 0x75 /* tree connect and X*/
1204 #define SMBtdis 0x71 /* tree disconnect */
1205 #define SMBnegprot 0x72 /* negotiate protocol */
1206 #define SMBdskattr 0x80 /* get disk attributes */
1207 #define SMBsearch 0x81 /* search directory */
1208 #define SMBsplopen 0xC0 /* open print spool file */
1209 #define SMBsplwr 0xC1 /* write to print spool file */
1210 #define SMBsplclose 0xC2 /* close print spool file */
1211 #define SMBsplretq 0xC3 /* return print queue */
1212 #define SMBsends 0xD0 /* send single block message */
1213 #define SMBsendb 0xD1 /* send broadcast message */
1214 #define SMBfwdname 0xD2 /* forward user name */
1215 #define SMBcancelf 0xD3 /* cancel forward */
1216 #define SMBgetmac 0xD4 /* get machine name */
1217 #define SMBsendstrt 0xD5 /* send start of multi-block message */
1218 #define SMBsendend 0xD6 /* send end of multi-block message */
1219 #define SMBsendtxt 0xD7 /* send text of multi-block message */
1221 /* Core+ protocol */
1222 #define SMBlockread 0x13 /* Lock a range and read */
1223 #define SMBwriteunlock 0x14 /* Unlock a range then write */
1224 #define SMBreadbraw 0x1a /* read a block of data with no smb header */
1225 #define SMBwritebraw 0x1d /* write a block of data with no smb header */
1226 #define SMBwritec 0x20 /* secondary write request */
1227 #define SMBwriteclose 0x2c /* write a file then close it */
1229 /* dos extended protocol */
1230 #define SMBreadBraw 0x1A /* read block raw */
1231 #define SMBreadBmpx 0x1B /* read block multiplexed */
1232 #define SMBreadBs 0x1C /* read block (secondary response) */
1233 #define SMBwriteBraw 0x1D /* write block raw */
1234 #define SMBwriteBmpx 0x1E /* write block multiplexed */
1235 #define SMBwriteBs 0x1F /* write block (secondary request) */
1236 #define SMBwriteC 0x20 /* write complete response */
1237 #define SMBsetattrE 0x22 /* set file attributes expanded */
1238 #define SMBgetattrE 0x23 /* get file attributes expanded */
1239 #define SMBlockingX 0x24 /* lock/unlock byte ranges and X */
1240 #define SMBtrans 0x25 /* transaction - name, bytes in/out */
1241 #define SMBtranss 0x26 /* transaction (secondary request/response) */
1242 #define SMBioctl 0x27 /* IOCTL */
1243 #define SMBioctls 0x28 /* IOCTL (secondary request/response) */
1244 #define SMBcopy 0x29 /* copy */
1245 #define SMBmove 0x2A /* move */
1246 #define SMBecho 0x2B /* echo */
1247 #define SMBopenX 0x2D /* open and X */
1248 #define SMBreadX 0x2E /* read and X */
1249 #define SMBwriteX 0x2F /* write and X */
1250 #define SMBsesssetupX 0x73 /* Session Set Up & X (including User Logon) */
1251 #define SMBffirst 0x82 /* find first */
1252 #define SMBfunique 0x83 /* find unique */
1253 #define SMBfclose 0x84 /* find close */
1254 #define SMBinvalid 0xFE /* invalid command */
1256 /* Extended 2.0 protocol */
1257 #define SMBtrans2 0x32 /* TRANS2 protocol set */
1258 #define SMBtranss2 0x33 /* TRANS2 protocol set, secondary command */
1259 #define SMBfindclose 0x34 /* Terminate a TRANSACT2_FINDFIRST */
1260 #define SMBfindnclose 0x35 /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
1261 #define SMBulogoffX 0x74 /* user logoff */
1263 /* NT SMB extensions. */
1264 #define SMBnttrans 0xA0 /* NT transact */
1265 #define SMBnttranss 0xA1 /* NT transact secondary */
1266 #define SMBntcreateX 0xA2 /* NT create and X */
1267 #define SMBntcancel 0xA4 /* NT cancel */
1269 /* These are the TRANS2 sub commands */
1270 #define TRANSACT2_OPEN 0
1271 #define TRANSACT2_FINDFIRST 1
1272 #define TRANSACT2_FINDNEXT 2
1273 #define TRANSACT2_QFSINFO 3
1274 #define TRANSACT2_SETFSINFO 4
1275 #define TRANSACT2_QPATHINFO 5
1276 #define TRANSACT2_SETPATHINFO 6
1277 #define TRANSACT2_QFILEINFO 7
1278 #define TRANSACT2_SETFILEINFO 8
1279 #define TRANSACT2_FSCTL 9
1280 #define TRANSACT2_IOCTL 0xA
1281 #define TRANSACT2_FINDNOTIFYFIRST 0xB
1282 #define TRANSACT2_FINDNOTIFYNEXT 0xC
1283 #define TRANSACT2_MKDIR 0xD
1284 #define TRANSACT2_SESSION_SETUP 0xE
1285 #define TRANSACT2_GET_DFS_REFERRAL 0x10
1286 #define TRANSACT2_REPORT_DFS_INCONSISTANCY 0x11
1288 /* These are the NT transact sub commands. */
1289 #define NT_TRANSACT_CREATE 1
1290 #define NT_TRANSACT_IOCTL 2
1291 #define NT_TRANSACT_SET_SECURITY_DESC 3
1292 #define NT_TRANSACT_NOTIFY_CHANGE 4
1293 #define NT_TRANSACT_RENAME 5
1294 #define NT_TRANSACT_QUERY_SECURITY_DESC 6
1296 /* these are the trans2 sub fields for primary requests */
1297 #define smb_tpscnt smb_vwv0
1298 #define smb_tdscnt smb_vwv1
1299 #define smb_mprcnt smb_vwv2
1300 #define smb_mdrcnt smb_vwv3
1301 #define smb_msrcnt smb_vwv4
1302 #define smb_flags smb_vwv5
1303 #define smb_timeout smb_vwv6
1304 #define smb_pscnt smb_vwv9
1305 #define smb_psoff smb_vwv10
1306 #define smb_dscnt smb_vwv11
1307 #define smb_dsoff smb_vwv12
1308 #define smb_suwcnt smb_vwv13
1309 #define smb_setup smb_vwv14
1310 #define smb_setup0 smb_setup
1311 #define smb_setup1 (smb_setup+2)
1312 #define smb_setup2 (smb_setup+4)
1314 /* these are for the secondary requests */
1315 #define smb_spscnt smb_vwv2
1316 #define smb_spsoff smb_vwv3
1317 #define smb_spsdisp smb_vwv4
1318 #define smb_sdscnt smb_vwv5
1319 #define smb_sdsoff smb_vwv6
1320 #define smb_sdsdisp smb_vwv7
1321 #define smb_sfid smb_vwv8
1323 /* and these for responses */
1324 #define smb_tprcnt smb_vwv0
1325 #define smb_tdrcnt smb_vwv1
1326 #define smb_prcnt smb_vwv3
1327 #define smb_proff smb_vwv4
1328 #define smb_prdisp smb_vwv5
1329 #define smb_drcnt smb_vwv6
1330 #define smb_droff smb_vwv7
1331 #define smb_drdisp smb_vwv8
1333 /* these are for the NT trans primary request. */
1334 #define smb_nt_MaxSetupCount smb_vwv0
1335 #define smb_nt_Flags (smb_vwv0 + 1)
1336 #define smb_nt_TotalParameterCount (smb_vwv0 + 3)
1337 #define smb_nt_TotalDataCount (smb_vwv0 + 7)
1338 #define smb_nt_MaxParameterCount (smb_vwv0 + 11)
1339 #define smb_nt_MaxDataCount (smb_vwv0 + 15)
1340 #define smb_nt_ParameterCount (smb_vwv0 + 19)
1341 #define smb_nt_ParameterOffset (smb_vwv0 + 23)
1342 #define smb_nt_DataCount (smb_vwv0 + 27)
1343 #define smb_nt_DataOffset (smb_vwv0 + 31)
1344 #define smb_nt_SetupCount (smb_vwv0 + 35)
1345 #define smb_nt_Function (smb_vwv0 + 36)
1346 #define smb_nt_SetupStart (smb_vwv0 + 38)
1348 /* these are for the NT trans secondary request. */
1349 #define smb_nts_TotalParameterCount (smb_vwv0 + 3)
1350 #define smb_nts_TotalDataCount (smb_vwv0 + 7)
1351 #define smb_nts_ParameterCount (smb_vwv0 + 11)
1352 #define smb_nts_ParameterOffset (smb_vwv0 + 15)
1353 #define smb_nts_ParameterDisplacement (smb_vwv0 + 19)
1354 #define smb_nts_DataCount (smb_vwv0 + 23)
1355 #define smb_nts_DataOffset (smb_vwv0 + 27)
1356 #define smb_nts_DataDisplacement (smb_vwv0 + 31)
1358 /* these are for the NT trans reply. */
1359 #define smb_ntr_TotalParameterCount (smb_vwv0 + 3)
1360 #define smb_ntr_TotalDataCount (smb_vwv0 + 7)
1361 #define smb_ntr_ParameterCount (smb_vwv0 + 11)
1362 #define smb_ntr_ParameterOffset (smb_vwv0 + 15)
1363 #define smb_ntr_ParameterDisplacement (smb_vwv0 + 19)
1364 #define smb_ntr_DataCount (smb_vwv0 + 23)
1365 #define smb_ntr_DataOffset (smb_vwv0 + 27)
1366 #define smb_ntr_DataDisplacement (smb_vwv0 + 31)
1368 /* these are for the NT create_and_X */
1369 #define smb_ntcreate_NameLength (smb_vwv0 + 5)
1370 #define smb_ntcreate_Flags (smb_vwv0 + 7)
1371 #define smb_ntcreate_RootDirectoryFid (smb_vwv0 + 11)
1372 #define smb_ntcreate_DesiredAccess (smb_vwv0 + 15)
1373 #define smb_ntcreate_AllocationSize (smb_vwv0 + 19)
1374 #define smb_ntcreate_FileAttributes (smb_vwv0 + 27)
1375 #define smb_ntcreate_ShareAccess (smb_vwv0 + 31)
1376 #define smb_ntcreate_CreateDisposition (smb_vwv0 + 35)
1377 #define smb_ntcreate_CreateOptions (smb_vwv0 + 39)
1378 #define smb_ntcreate_ImpersonationLevel (smb_vwv0 + 43)
1379 #define smb_ntcreate_SecurityFlags (smb_vwv0 + 47)
1381 /* this is used on a TConX. I'm not sure the name is very helpful though */
1382 #define SMB_SUPPORT_SEARCH_BITS 0x0001
1384 /* these are the constants used in the above call. */
1386 /* File Specific access rights. */
1387 #define FILE_READ_DATA 0x001
1388 #define FILE_WRITE_DATA 0x002
1389 #define FILE_APPEND_DATA 0x004
1390 #define FILE_READ_EA 0x008
1391 #define FILE_WRITE_EA 0x010
1392 #define FILE_EXECUTE 0x020
1393 #define FILE_DELETE_CHILD 0x040
1394 #define FILE_READ_ATTRIBUTES 0x080
1395 #define FILE_WRITE_ATTRIBUTES 0x100
1397 /* Generic access masks & rights. */
1398 #define SPECIFIC_RIGHTS_MASK 0x00FFFFL
1399 #define STANDARD_RIGHTS_MASK 0xFF0000L
1400 #define DELETE_ACCESS (1L<<16)
1401 #define READ_CONTROL_ACCESS (1L<<17)
1402 #define WRITE_DAC_ACCESS (1L<<18)
1403 #define WRITE_OWNER_ACCESS (1L<<19)
1404 #define SYNCHRONIZE_ACCESS (1L<<20)
1405 #define SYSTEM_SECURITY_ACCESS (1L<<24)
1408 #define REQUEST_OPLOCK 2
1409 #define REQUEST_BATCH_OPLOCK 4
1410 #define OPEN_DIRECTORY 8
1412 /* ShareAccess field. */
1413 #define FILE_SHARE_NONE 0 /* Cannot be used in bitmask. */
1414 #define FILE_SHARE_READ 1
1415 #define FILE_SHARE_WRITE 2
1416 #define FILE_SHARE_DELETE 4
1418 /* FileAttributesField */
1419 #define FILE_ATTRIBUTE_READONLY aRONLY
1420 #define FILE_ATTRIBUTE_HIDDEN aHIDDEN
1421 #define FILE_ATTRIBUTE_SYSTEM aSYSTEM
1422 #define FILE_ATTRIBUTE_DIRECTORY aDIR
1423 #define FILE_ATTRIBUTE_ARCHIVE aARCH
1424 #define FILE_ATTRIBUTE_NORMAL 0x80L
1425 #define FILE_ATTRIBUTE_TEMPORARY 0x100L
1426 #define FILE_ATTRIBUTE_COMPRESSED 0x800L
1427 #define SAMBA_ATTRIBUTES_MASK 0x7F
1429 /* Flags - combined with attributes. */
1430 #define FILE_FLAG_WRITE_THROUGH 0x80000000L
1431 #define FILE_FLAG_NO_BUFFERING 0x20000000L
1432 #define FILE_FLAG_RANDOM_ACCESS 0x10000000L
1433 #define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000L
1434 #define FILE_FLAG_DELETE_ON_CLOSE 0x04000000L
1435 #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000L
1436 #define FILE_FLAG_POSIX_SEMANTICS 0x01000000L
1438 /* CreateDisposition field. */
1439 #define FILE_SUPERSEDE 0
1441 #define FILE_CREATE 2
1442 #define FILE_OPEN_IF 3
1443 #define FILE_OVERWRITE 4
1444 #define FILE_OVERWRITE_IF 5
1446 /* CreateOptions field. */
1447 #define FILE_DIRECTORY_FILE 0x0001
1448 #define FILE_WRITE_THROUGH 0x0002
1449 #define FILE_SEQUENTIAL_ONLY 0x0004
1450 #define FILE_NON_DIRECTORY_FILE 0x0040
1451 #define FILE_NO_EA_KNOWLEDGE 0x0200
1452 #define FILE_EIGHT_DOT_THREE_ONLY 0x0400
1453 #define FILE_RANDOM_ACCESS 0x0800
1454 #define FILE_DELETE_ON_CLOSE 0x1000
1456 /* Responses when opening a file. */
1457 #define FILE_WAS_OPENED 1
1458 #define FILE_WAS_CREATED 2
1459 #define FILE_WAS_OVERWRITTEN 3
1461 /* File type flags */
1462 #define FILE_TYPE_DISK 0
1463 #define FILE_TYPE_BYTE_MODE_PIPE 1
1464 #define FILE_TYPE_MESSAGE_MODE_PIPE 2
1465 #define FILE_TYPE_PRINTER 3
1466 #define FILE_TYPE_COMM_DEVICE 4
1467 #define FILE_TYPE_UNKNOWN 0xFFFF
1469 /* Flag for NT transact rename call. */
1470 #define RENAME_REPLACE_IF_EXISTS 1
1472 /* Filesystem Attributes. */
1473 #define FILE_CASE_SENSITIVE_SEARCH 0x1
1474 #define FILE_CASE_PRESERVED_NAMES 0x2
1475 #define FILE_UNICODE_ON_DISK 0x4
1476 #define FILE_PERISITANT_ACLS 0x8
1478 /* ChangeNotify flags. */
1479 #define FILE_NOTIFY_CHANGE_FILE_NAME 0x001
1480 #define FILE_NOTIFY_CHANGE_DIR_NAME 0x002
1481 #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x004
1482 #define FILE_NOTIFY_CHANGE_SIZE 0x008
1483 #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x010
1484 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x020
1485 #define FILE_NOTIFY_CHANGE_CREATION 0x040
1486 #define FILE_NOTIFY_CHANGE_EA 0x080
1487 #define FILE_NOTIFY_CHANGE_SECURITY 0x100
1489 /* where to find the base of the SMB packet proper */
1490 #define smb_base(buf) (((char *)(buf))+4)
1493 #define SMB_SUCCESS 0 /* The request was successful. */
1494 #define ERRDOS 0x01 /* Error is from the core DOS operating system set. */
1495 #define ERRSRV 0x02 /* Error is generated by the server network file manager.*/
1496 #define ERRHRD 0x03 /* Error is an hardware error. */
1497 #define ERRCMD 0xFF /* Command was not in the "SMB" format. */
1499 #ifdef HAVE_STDARG_H
1500 int slprintf(char *str, int n, char *format, ...)
1502 __attribute__ ((format (printf, 3, 4)))
1510 void dfs_unlogin(void);
1511 extern int dcelogin_atmost_once;
1515 char *strdup(char *s);
1519 #define MIN(a,b) ((a)<(b)?(a):(b))
1522 #define MAX(a,b) ((a)>(b)?(a):(b))
1526 #define ABS(a) ((a)>0?(a):(-(a)))
1530 #define SIGNAL_CAST (RETSIGTYPE (*)(int))
1538 /* Some POSIX definitions for those without */
1541 #define S_IFDIR 0x4000
1544 #define S_ISDIR(mode) ((mode & 0xF000) == S_IFDIR)
1547 #define S_IRWXU 00700 /* read, write, execute: owner */
1550 #define S_IRUSR 00400 /* read permission: owner */
1553 #define S_IWUSR 00200 /* write permission: owner */
1556 #define S_IXUSR 00100 /* execute permission: owner */
1559 #define S_IRWXG 00070 /* read, write, execute: group */
1562 #define S_IRGRP 00040 /* read permission: group */
1565 #define S_IWGRP 00020 /* write permission: group */
1568 #define S_IXGRP 00010 /* execute permission: group */
1571 #define S_IRWXO 00007 /* read, write, execute: other */
1574 #define S_IROTH 00004 /* read permission: other */
1577 #define S_IWOTH 00002 /* write permission: other */
1580 #define S_IXOTH 00001 /* execute permission: other */
1584 /* these are used in NetServerEnum to choose what to receive */
1585 #define SV_TYPE_WORKSTATION 0x00000001
1586 #define SV_TYPE_SERVER 0x00000002
1587 #define SV_TYPE_SQLSERVER 0x00000004
1588 #define SV_TYPE_DOMAIN_CTRL 0x00000008
1589 #define SV_TYPE_DOMAIN_BAKCTRL 0x00000010
1590 #define SV_TYPE_TIME_SOURCE 0x00000020
1591 #define SV_TYPE_AFP 0x00000040
1592 #define SV_TYPE_NOVELL 0x00000080
1593 #define SV_TYPE_DOMAIN_MEMBER 0x00000100
1594 #define SV_TYPE_PRINTQ_SERVER 0x00000200
1595 #define SV_TYPE_DIALIN_SERVER 0x00000400
1596 #define SV_TYPE_SERVER_UNIX 0x00000800
1597 #define SV_TYPE_NT 0x00001000
1598 #define SV_TYPE_WFW 0x00002000
1599 #define SV_TYPE_SERVER_MFPN 0x00004000
1600 #define SV_TYPE_SERVER_NT 0x00008000
1601 #define SV_TYPE_POTENTIAL_BROWSER 0x00010000
1602 #define SV_TYPE_BACKUP_BROWSER 0x00020000
1603 #define SV_TYPE_MASTER_BROWSER 0x00040000
1604 #define SV_TYPE_DOMAIN_MASTER 0x00080000
1605 #define SV_TYPE_SERVER_OSF 0x00100000
1606 #define SV_TYPE_SERVER_VMS 0x00200000
1607 #define SV_TYPE_WIN95_PLUS 0x00400000
1608 #define SV_TYPE_ALTERNATE_XPORT 0x20000000
1609 #define SV_TYPE_LOCAL_LIST_ONLY 0x40000000
1610 #define SV_TYPE_DOMAIN_ENUM 0x80000000
1611 #define SV_TYPE_ALL 0xFFFFFFFF
1613 /* what server type are we currently - JHT Says we ARE 4.20 */
1614 /* this was set by JHT in liaison with Jeremy Allison early 1997 */
1615 /* setting to 4.20 at same time as announcing ourselves as NT Server */
1617 /* Version 4.0 - never made public */
1618 /* Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9 */
1619 /* - Reappeared in 1.9.16p11 with fixed smbd services */
1620 /* Version 4.20 - To indicate that nmbd and browsing now works better */
1622 #define DEFAULT_MAJOR_VERSION 0x04
1623 #define DEFAULT_MINOR_VERSION 0x02
1625 /* Browser Election Values */
1626 #define BROWSER_ELECTION_VERSION 0x010f
1627 #define BROWSER_CONSTANT 0xaa55
1629 /* NT Flags2 bits - cifs6.txt section 3.1.2 */
1631 #define FLAGS2_LONG_PATH_COMPONENTS 0x0001
1632 #define FLAGS2_EXTENDED_ATTRIBUTES 0x0002
1633 #define FLAGS2_DFS_PATHNAMES 0x1000
1634 #define FLAGS2_READ_PERMIT_NO_EXECUTE 0x2000
1635 #define FLAGS2_32_BIT_ERROR_CODES 0x4000
1636 #define FLAGS2_UNICODE_STRINGS 0x8000
1638 /* Capabilities. see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
1640 #define CAP_RAW_MODE 0x0001
1641 #define CAP_MPX_MODE 0x0002
1642 #define CAP_UNICODE 0x0004
1643 #define CAP_LARGE_FILES 0x0008
1644 #define CAP_NT_SMBS 0x0010
1645 #define CAP_RPC_REMOTE_APIS 0x0020
1646 #define CAP_STATUS32 0x0040
1647 #define CAP_LEVEL_II_OPLOCKS 0x0080
1648 #define CAP_LOCK_AND_READ 0x0100
1649 #define CAP_NT_FIND 0x0200
1650 #define CAP_DFS 0x1000
1651 #define CAP_LARGE_READX 0x4000
1653 /* protocol types. It assumes that higher protocols include lower protocols
1655 enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
1657 /* security levels */
1658 enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER,SEC_DOMAIN};
1669 /* printing types */
1670 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
1671 PRINT_QNX,PRINT_PLP,PRINT_LPRNG,PRINT_SOFTQ};
1673 /* Remote architectures we know about. */
1674 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_SAMBA};
1677 enum case_handling {CASE_LOWER,CASE_UPPER};
1680 /* SSL version options */
1681 enum ssl_version_enum {SMB_SSL_V2,SMB_SSL_V3,SMB_SSL_V23,SMB_SSL_TLS1};
1682 #endif /* WITH_SSL */
1684 /* Macros to get at offsets within smb_lkrng and smb_unlkrng
1685 structures. We cannot define these as actual structures
1686 due to possible differences in structure packing
1687 on different machines/compilers. */
1689 #define SMB_LPID_OFFSET(indx) (10 * (indx))
1690 #define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
1691 #define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
1692 #define SMB_LARGE_LKOFF_OFFSET_HIGH(indx) (4 + (20 * (indx)))
1693 #define SMB_LARGE_LKOFF_OFFSET_LOW(indx) (8 + (20 * (indx)))
1694 #define SMB_LARGE_LKLEN_OFFSET_HIGH(indx) (12 + (20 * (indx)))
1695 #define SMB_LARGE_LKLEN_OFFSET_LOW(indx) (16 + (20 * (indx)))
1697 /* Macro to cache an error in a write_bmpx_struct */
1698 #define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
1699 w->wr_discard = True, -1)
1700 /* Macro to test if an error has been cached for this fnum */
1701 #define HAS_CACHED_ERROR(fsp) ((fsp)->open && (fsp)->wbmpx_ptr && \
1702 (fsp)->wbmpx_ptr->wr_discard)
1703 /* Macro to turn the cached error into an error packet */
1704 #define CACHED_ERROR(fsp) cached_error_packet(inbuf,outbuf,fsp,__LINE__)
1706 /* these are the datagram types */
1707 #define DGRAM_DIRECT_UNIQUE 0x10
1709 #define ERROR(class,x) error_packet(inbuf,outbuf,class,x,__LINE__)
1711 /* this is how errors are generated */
1712 #define UNIXERROR(defclass,deferror) unix_error_packet(inbuf,outbuf,defclass,deferror,__LINE__)
1714 #define SMB_ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
1717 * Global value meaing that the smb_uid field should be
1718 * ingored (in share level security and protocol level == CORE)
1721 #define UID_FIELD_INVALID 0
1722 #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
1724 /* Defines needed for multi-codepage support. */
1725 #define MSDOS_LATIN_1_CODEPAGE 850
1726 #define KANJI_CODEPAGE 932
1727 #define HANGUL_CODEPAGE 949
1728 #define BIG5_CODEPAGE 950
1729 #define SIMPLIFIED_CHINESE_CODEPAGE 936
1733 * Default client code page - Japanese
1735 #define DEFAULT_CLIENT_CODE_PAGE KANJI_CODEPAGE
1738 * Default client code page - 850 - Western European
1740 #define DEFAULT_CLIENT_CODE_PAGE MSDOS_LATIN_1_CODEPAGE
1744 * Size of buffer to use when moving files across filesystems.
1746 #define COPYBUF_SIZE (8*1024)
1749 * Integers used to override error codes.
1751 extern int unix_ERR_class;
1752 extern int unix_ERR_code;
1755 * Map the Core and Extended Oplock requesst bits down
1756 * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK).
1762 #define CORE_OPLOCK_REQUEST(inbuf) \
1763 ((CVAL(inbuf,smb_flg)&(FLAG_REQUEST_OPLOCK|FLAG_REQUEST_BATCH_OPLOCK))>>5)
1766 * Extended protocol.
1768 #define EXTENDED_OPLOCK_REQUEST(inbuf) ((SVAL(inbuf,smb_vwv2)&((1<<1)|(1<<2)))>>1)
1771 #define LOCKING_ANDX_SHARED_LOCK 0x1
1772 #define LOCKING_ANDX_OPLOCK_RELEASE 0x2
1773 #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x4
1774 #define LOCKING_ANDX_CANCEL_LOCK 0x8
1775 #define LOCKING_ANDX_LARGE_FILES 0x10
1778 #define OPLOCKLEVEL_NONE 0
1779 #define OPLOCKLEVEL_II 1
1782 * Bits we test with.
1784 #define EXCLUSIVE_OPLOCK 1
1785 #define BATCH_OPLOCK 2
1787 #define CORE_OPLOCK_GRANTED (1<<5)
1788 #define EXTENDED_OPLOCK_GRANTED (1<<15)
1791 * Loopback command offsets.
1794 #define OPBRK_CMD_LEN_OFFSET 0
1795 #define OPBRK_CMD_PORT_OFFSET 4
1796 #define OPBRK_CMD_HEADER_LEN 6
1798 #define OPBRK_MESSAGE_CMD_OFFSET 0
1801 * Oplock break command code to send over the udp socket.
1805 * 0 2 6 10 14 14+devsize 14+devsize+inodesize
1806 * +----+--------+--------+--------+-------+--------+
1807 * | cmd| pid | sec | usec | dev | inode |
1808 * +----+--------+--------+--------+-------+--------+
1811 #define OPLOCK_BREAK_CMD 0x1
1812 #define OPLOCK_BREAK_PID_OFFSET 2
1813 #define OPLOCK_BREAK_SEC_OFFSET 6
1814 #define OPLOCK_BREAK_USEC_OFFSET 10
1815 #define OPLOCK_BREAK_DEV_OFFSET 14
1816 #define OPLOCK_BREAK_INODE_OFFSET (OPLOCK_BREAK_DEV_OFFSET + sizeof(SMB_DEV_T))
1817 #define OPLOCK_BREAK_MSG_LEN (OPLOCK_BREAK_INODE_OFFSET + sizeof(SMB_INO_T))
1820 * Capabilities abstracted for different systems.
1823 #define KERNEL_OPLOCK_CAPABILITY 0x1
1825 #if defined(HAVE_KERNEL_OPLOCKS)
1827 * Oplock break command code sent via the kernel interface.
1831 * 0 2 2+devsize 2+devsize+inodesize
1832 * +----+--------+--------+
1833 * | cmd| dev | inode |
1834 * +----+--------+--------+
1837 #define KERNEL_OPLOCK_BREAK_CMD 0x2
1838 #define KERNEL_OPLOCK_BREAK_DEV_OFFSET 2
1839 #define KERNEL_OPLOCK_BREAK_INODE_OFFSET (KERNEL_OPLOCK_BREAK_DEV_OFFSET + sizeof(SMB_DEV_T))
1840 #define KERNEL_OPLOCK_BREAK_MSG_LEN (KERNEL_OPLOCK_BREAK_INODE_OFFSET + sizeof(SMB_INO_T))
1842 #endif /* HAVE_KERNEL_OPLOCKS */
1844 #define CMD_REPLY 0x8000
1848 /* zero a structure */
1849 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
1851 /* zero a structure given a pointer to the structure */
1852 #define ZERO_STRUCTP(x) { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); }
1854 /* zero an array - note that sizeof(array) must work - ie. it must not be a
1856 #define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x))
1858 #define SMB_ASSERT(b) ((b)?(void)0: \
1859 (DEBUG(0,("PANIC: assert failed at %s(%d)\n", \
1860 __FILE__, __LINE__)), smb_panic("assert failed")))
1861 #define SMB_ASSERT_ARRAY(a,n) SMB_ASSERT((sizeof(a)/sizeof((a)[0])) >= (n))
1863 #include "ntdomain.h"
1865 /* A netbios name structure. */
1869 unsigned int name_type;
1873 #include "rpcclient.h"
1876 * Size of new password account encoding string. DO NOT CHANGE.
1879 #define NEW_PW_FORMAT_SPACE_PADDED_LEN 14
1882 Do you want session setups at user level security with a invalid
1883 password to be rejected or allowed in as guest? WinNT rejects them
1884 but it can be a pain as it means "net view" needs to use a password
1886 You have 3 choices in the setting of map_to_guest:
1888 "NEVER_MAP_TO_GUEST" means session setups with an invalid password
1889 are rejected. This is the default.
1891 "MAP_TO_GUEST_ON_BAD_USER" means session setups with an invalid password
1892 are rejected, unless the username does not exist, in which case it
1893 is treated as a guest login
1895 "MAP_TO_GUEST_ON_BAD_PASSWORD" means session setups with an invalid password
1896 are treated as a guest login
1898 Note that map_to_guest only has an effect in user or server
1902 #define NEVER_MAP_TO_GUEST 0
1903 #define MAP_TO_GUEST_ON_BAD_USER 1
1904 #define MAP_TO_GUEST_ON_BAD_PASSWORD 2
1906 /* associate bit field or enumeration field with a string */