/*
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-2012"
#define BUFFER_SIZE (128*1024)
#define SAFETY_MARGIN 1024
#define LARGE_WRITEX_HDR_SIZE 65
#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
#ifndef DEF_CREATE_MASK
#define DEF_CREATE_MASK (0755)
#endif
/* 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
/* The following are Samba-private. */
#define INTERNAL_OPEN_ONLY 0x8
#define FAKE_LEVEL_II_OPLOCK 0x10 /* Client requested no_oplock, but we have to
* inform potential level2 holders on
* write. */
#define DEFERRED_OPEN_ENTRY 0x20
/* #define UNUSED_SHARE_MODE_ENTRY 0x40 */ /* Not used anymore */
#define FORCE_OPLOCK_BREAK_TO_NONE 0x80
/* None of the following should ever appear in fsp->oplock_request. */
#define SAMBA_PRIVATE_OPLOCK_MASK (INTERNAL_OPEN_ONLY|DEFERRED_OPEN_ENTRY|FORCE_OPLOCK_BREAK_TO_NONE)
#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|(unsigned int)FAKE_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
};
/*
* Kernel oplocks capability flags.
*/
/* Level 2 oplocks are supported natively by kernel oplocks. */
#define KOPLOCKS_LEVEL2_SUPPORTED 0x1
/* The kernel notifies deferred openers when they can retry the open. */
#define KOPLOCKS_DEFERRED_OPEN_NOTIFICATION 0x2
/* The kernel notifies smbds when an oplock break times out. */
#define KOPLOCKS_TIMEOUT_NOTIFICATION 0x4
/* The kernel notifies smbds when an oplock is broken. */
#define KOPLOCKS_OPLOCK_BROKEN_NOTIFICATION 0x8
struct kernel_oplocks_ops;
struct kernel_oplocks {
const struct kernel_oplocks_ops *ops;
uint32_t flags;
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);
void (*contend_level2_oplocks_begin)(files_struct *fsp,
enum level2_contention_type type);
void (*contend_level2_oplocks_end)(files_struct *fsp,
enum level2_contention_type 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 ... */
};
typedef struct user_struct {
struct user_struct *next, *prev;
uint16 vuid; /* Tag for this entry. */
char *session_keystr; /* used by utmp and pam session code.
TDB key string */
int homes_snum;
struct auth_session_info *session_info;
struct gensec_security *gensec_security;
} user_struct;
/*
Do you want session setups at user level security with a invalid
password to be rejected or allowed in as guest? WinNT rejects them
but it can be a pain as it means "net view" needs to use a password
You have 3 choices in the setting of map_to_guest:
"NEVER_MAP_TO_GUEST" means session setups with an invalid password
are rejected. This is the default.
"MAP_TO_GUEST_ON_BAD_USER" means session setups with an invalid password
are rejected, unless the username does not exist, in which case it
is treated as a guest login
"MAP_TO_GUEST_ON_BAD_PASSWORD" means session setups with an invalid password
are treated as a guest login
Note that map_to_guest only has an effect in user or server
level security.
*/
#define NEVER_MAP_TO_GUEST 0
#define MAP_TO_GUEST_ON_BAD_USER 1
#define MAP_TO_GUEST_ON_BAD_PASSWORD 2
#define MAP_TO_GUEST_ON_BAD_UID 3
#define SAFE_NETBIOS_CHARS ". -_"
/* The maximum length of a trust account password.
Used when we randomly create it, 15 char passwords
exceed NT4's max password length */
#define DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH 14
#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 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"
/* map readonly options */
enum mapreadonly_options {MAP_READONLY_NO, MAP_READONLY_YES, MAP_READONLY_PERMISSIONS};
/* 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 samba_magic; /* Always SAMBA_EXTRA_INFO_MAGIC */
uint32 samba_version; /* Major/Minor/Release/Revision */
uint32 samba_subversion; /* Prerelease/RC/Vendor patch */
NTTIME samba_gitcommitdate;
char samba_version_string[SAMBA_EXTENDED_INFO_VERSION_STRING_LENGTH];
};
/* Used inside aio code. */
struct aio_extra;
/*
* Reasons for cache flush.
*/
enum flush_reason_enum {
SEEK_FLUSH,
READ_FLUSH,
WRITE_FLUSH,
READRAW_FLUSH,
OPLOCK_RELEASE_FLUSH,
CLOSE_FLUSH,
SYNC_FLUSH,
SIZECHANGE_FLUSH,
/* NUM_FLUSH_REASONS must remain the last value in the enumeration. */
NUM_FLUSH_REASONS};
#endif /* _SMB_H */