/*
Unix SMB/CIFS implementation.
SMB parameters and setup, plus a whole lot more.
Copyright (C) Andrew Tridgell 1992-2000
Copyright (C) John H Terpstra 1996-2002
Copyright (C) Luke Kenneth Casson Leighton 1996-2000
Copyright (C) Paul Ashton 1998-2000
Copyright (C) Simo Sorce 2001-2002
Copyright (C) Martin Pool 2002
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#ifndef _SMB_H
#define _SMB_H
#include "libcli/smb/smb_common.h"
#include "libds/common/roles.h"
/* logged when starting the various Samba daemons */
#define COPYRIGHT_STARTUP_MESSAGE "Copyright Andrew Tridgell and the Samba Team 1992-2018"
#define SAFETY_MARGIN 1024
#define LARGE_WRITEX_HDR_SIZE 65
#define LARGE_WRITEX_BUFFER_SIZE (128*1024)
#define NMB_PORT 137
#define DGRAM_PORT 138
#define NBT_SMB_PORT 139 /* Port for SMB over NBT transport (IETF STD#19). */
#define TCP_SMB_PORT 445 /* Port for SMB over naked TCP transport. */
#define SMB_PORTS "445 139"
#define Undefined (-1)
#define False false
#define True true
#define Auto (2)
#define Required (3)
#define SIZEOFWORD 2
/* string manipulation flags - see clistr.c and srvstr.c */
#define STR_TERMINATE 1
#define STR_UPPER 2
#define STR_ASCII 4
#define STR_UNICODE 8
#define STR_NOALIGN 16
#define STR_TERMINATE_ASCII 128
/* how long to wait for secondary SMB packets (milli-seconds) */
#define SMB_SECONDARY_WAIT (60*1000)
#define DIR_STRUCT_SIZE 43
/* deny modes */
#define DENY_DOS 0
#define DENY_ALL 1
#define DENY_WRITE 2
#define DENY_READ 3
#define DENY_NONE 4
#define DENY_FCB 7
/* open modes */
#define DOS_OPEN_RDONLY 0
#define DOS_OPEN_WRONLY 1
#define DOS_OPEN_RDWR 2
#define DOS_OPEN_EXEC 3
#define DOS_OPEN_FCB 0xF
/* define shifts and masks for share and open modes. */
#define OPENX_MODE_MASK 0xF
#define DENY_MODE_SHIFT 4
#define DENY_MODE_MASK 0x7
#define GET_OPENX_MODE(x) ((x) & OPENX_MODE_MASK)
#define SET_OPENX_MODE(x) ((x) & OPENX_MODE_MASK)
#define GET_DENY_MODE(x) (((x)>>DENY_MODE_SHIFT) & DENY_MODE_MASK)
#define SET_DENY_MODE(x) (((x) & DENY_MODE_MASK) <>5)
/*
* Extended protocol.
*/
#define EXTENDED_OPLOCK_REQUEST(inbuf) ((SVAL(inbuf,smb_vwv2)&((1<<1)|(1<<2)))>>1)
/*
* Bits we test with.
* Note these must fit into 16-bits.
*/
#define NO_OPLOCK OPLOCK_NONE
#define EXCLUSIVE_OPLOCK OPLOCK_EXCLUSIVE
#define BATCH_OPLOCK OPLOCK_BATCH
#define LEVEL_II_OPLOCK OPLOCK_LEVEL_II
#define LEASE_OPLOCK 0x100
/* The following are Samba-private. */
#define INTERNAL_OPEN_ONLY 0x8
/* #define FAKE_LEVEL_II_OPLOCK 0x10 */ /* Not used anymore */
/* Client requested no_oplock, but we have to
* inform potential level2 holders on
* write. */
/* #define DEFERRED_OPEN_ENTRY 0x20 */ /* Not used anymore */
/* #define UNUSED_SHARE_MODE_ENTRY 0x40 */ /* Not used anymore */
/* #define FORCE_OPLOCK_BREAK_TO_NONE 0x80 */ /* Not used anymore */
/* None of the following should ever appear in fsp->oplock_request. */
#define SAMBA_PRIVATE_OPLOCK_MASK (INTERNAL_OPEN_ONLY)
#define EXCLUSIVE_OPLOCK_TYPE(lck) ((lck) & ((unsigned int)EXCLUSIVE_OPLOCK|(unsigned int)BATCH_OPLOCK))
#define BATCH_OPLOCK_TYPE(lck) ((lck) & (unsigned int)BATCH_OPLOCK)
#define LEVEL_II_OPLOCK_TYPE(lck) ((lck) & (unsigned int)LEVEL_II_OPLOCK)
/* kernel_oplock_message definition.
struct kernel_oplock_message {
uint64_t dev;
uint64_t inode;
unit64_t extid;
unsigned long file_id;
};
Offset Data length.
0 uint64_t dev 8 bytes
8 uint64_t inode 8 bytes
16 uint64_t extid 8 bytes
24 unsigned long file_id 4 bytes
28
*/
#define MSG_SMB_KERNEL_BREAK_SIZE 28
/* file_renamed_message definition.
struct file_renamed_message {
uint64_t dev;
uint64_t inode;
char names[1]; A variable area containing sharepath and filename.
};
Offset Data length.
0 uint64_t dev 8 bytes
8 uint64_t inode 8 bytes
16 unit64_t extid 8 bytes
24 char [] name zero terminated namelen bytes
minimum length == 24.
*/
#define MSG_FILE_RENAMED_MIN_SIZE 24
/*
* On the wire return values for oplock types.
*/
#define CORE_OPLOCK_GRANTED (1<<5)
#define EXTENDED_OPLOCK_GRANTED (1<<15)
#define NO_OPLOCK_RETURN 0
#define EXCLUSIVE_OPLOCK_RETURN 1
#define BATCH_OPLOCK_RETURN 2
#define LEVEL_II_OPLOCK_RETURN 3
/* Oplock levels */
#define OPLOCKLEVEL_NONE 0
#define OPLOCKLEVEL_II 1
/*
* Capabilities abstracted for different systems.
*/
enum smbd_capability {
KERNEL_OPLOCK_CAPABILITY,
DMAPI_ACCESS_CAPABILITY,
LEASE_CAPABILITY,
DAC_OVERRIDE_CAPABILITY
};
struct kernel_oplocks_ops;
struct kernel_oplocks {
const struct kernel_oplocks_ops *ops;
void *private_data;
};
enum level2_contention_type {
LEVEL2_CONTEND_ALLOC_SHRINK,
LEVEL2_CONTEND_ALLOC_GROW,
LEVEL2_CONTEND_SET_FILE_LEN,
LEVEL2_CONTEND_FILL_SPARSE,
LEVEL2_CONTEND_WRITE,
LEVEL2_CONTEND_WINDOWS_BRL,
LEVEL2_CONTEND_POSIX_BRL
};
/* if a kernel does support oplocks then a structure of the following
typee is used to describe how to interact with the kernel */
struct kernel_oplocks_ops {
bool (*set_oplock)(struct kernel_oplocks *ctx,
files_struct *fsp, int oplock_type);
void (*release_oplock)(struct kernel_oplocks *ctx,
files_struct *fsp, int oplock_type);
};
#include "smb_macros.h"
#define MAX_NETBIOSNAME_LEN 16
/* DOS character, NetBIOS namestring. Type used on the wire. */
typedef char nstring[MAX_NETBIOSNAME_LEN];
/* Unix character, NetBIOS namestring. Type used to manipulate name in nmbd. */
typedef char unstring[MAX_NETBIOSNAME_LEN*4];
/* A netbios name structure. */
struct nmb_name {
nstring name;
char scope[64];
unsigned int name_type;
};
/* A netbios node status array element. */
struct node_status {
nstring name;
unsigned char type;
unsigned char flags;
};
/* The extra info from a NetBIOS node status query */
struct node_status_extra {
unsigned char mac_addr[6];
/* There really is more here ... */
};
#define SAFE_NETBIOS_CHARS ". -_"
#define PORT_NONE 0
#ifndef LDAP_PORT
#define LDAP_PORT 389
#endif
#define LDAP_GC_PORT 3268
/* used by the IP comparison function */
struct ip_service {
struct sockaddr_storage ss;
unsigned port;
};
struct ea_struct {
uint8_t flags;
char *name;
DATA_BLOB value;
};
struct ea_list {
struct ea_list *next, *prev;
struct ea_struct ea;
};
/* EA names used internally in Samba. KEEP UP TO DATE with prohibited_ea_names in trans2.c !. */
#define SAMBA_POSIX_INHERITANCE_EA_NAME "user.SAMBA_PAI"
/* EA to use for DOS attributes */
#define SAMBA_XATTR_DOS_ATTRIB "user.DOSATTRIB"
/* Prefix for DosStreams in the vfs_streams_xattr module */
#define SAMBA_XATTR_DOSSTREAM_PREFIX "user.DosStream."
/* Prefix for xattrs storing streams. */
#define SAMBA_XATTR_MARKER "user.SAMBA_STREAMS"
/* usershare error codes. */
enum usershare_err {
USERSHARE_OK=0,
USERSHARE_MALFORMED_FILE,
USERSHARE_BAD_VERSION,
USERSHARE_MALFORMED_PATH,
USERSHARE_MALFORMED_COMMENT_DEF,
USERSHARE_MALFORMED_ACL_DEF,
USERSHARE_ACL_ERR,
USERSHARE_PATH_NOT_ABSOLUTE,
USERSHARE_PATH_IS_DENIED,
USERSHARE_PATH_NOT_ALLOWED,
USERSHARE_PATH_NOT_DIRECTORY,
USERSHARE_POSIX_ERR,
USERSHARE_MALFORMED_SHARENAME_DEF,
USERSHARE_BAD_SHARENAME
};
/* Different reasons for closing a file. */
enum file_close_type {NORMAL_CLOSE=0,SHUTDOWN_CLOSE,ERROR_CLOSE};
/* Used in SMB_FS_OBJECTID_INFORMATION requests. Must be exactly 48 bytes. */
#define SAMBA_EXTENDED_INFO_MAGIC 0x536d4261 /* "SmBa" */
#define SAMBA_EXTENDED_INFO_VERSION_STRING_LENGTH 28
struct smb_extended_info {
uint32_t samba_magic; /* Always SAMBA_EXTRA_INFO_MAGIC */
uint32_t samba_version; /* Major/Minor/Release/Revision */
uint32_t samba_subversion; /* Prerelease/RC/Vendor patch */
NTTIME samba_gitcommitdate;
char samba_version_string[SAMBA_EXTENDED_INFO_VERSION_STRING_LENGTH];
};
/*
* Reasons for cache flush.
*/
enum flush_reason_enum {
SAMBA_SEEK_FLUSH,
SAMBA_READ_FLUSH,
SAMBA_WRITE_FLUSH,
SAMBA_READRAW_FLUSH,
SAMBA_OPLOCK_RELEASE_FLUSH,
SAMBA_CLOSE_FLUSH,
SAMBA_SYNC_FLUSH,
SAMBA_SIZECHANGE_FLUSH,
};
#endif /* _SMB_H */