| 1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 |
/* |
| 3 |
* Copyright (C) 2018 Samsung Electronics Co., Ltd. |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifndef __SMB_SERVER_COMMON_H__ |
| 7 |
#define __SMB_SERVER_COMMON_H__ |
| 8 |
|
| 9 |
#include <linux/kernel.h> |
| 10 |
|
| 11 |
#include "glob.h" |
| 12 |
#include "../common/smbglob.h" |
| 13 |
#include "../common/smb1pdu.h" |
| 14 |
#include "../common/smb2pdu.h" |
| 15 |
#include "../common/fscc.h" |
| 16 |
#include "smb2pdu.h" |
| 17 |
|
| 18 |
/* ksmbd's Specific ERRNO */ |
| 19 |
#define ESHARE 50000 |
| 20 |
|
| 21 |
#define SMB1_PROT 0 |
| 22 |
#define SMB2_PROT 1 |
| 23 |
#define SMB21_PROT 2 |
| 24 |
/* multi-protocol negotiate request */ |
| 25 |
#define SMB2X_PROT 3 |
| 26 |
#define SMB30_PROT 4 |
| 27 |
#define SMB302_PROT 5 |
| 28 |
#define SMB311_PROT 6 |
| 29 |
#define BAD_PROT 0xFFFF |
| 30 |
|
| 31 |
#define SMB_ECHO_INTERVAL (60 * HZ) |
| 32 |
|
| 33 |
#define MAX_STREAM_PROT_LEN 0x00FFFFFF |
| 34 |
|
| 35 |
/* Responses when opening a file. */ |
| 36 |
#define F_SUPERSEDED 0 |
| 37 |
#define F_OPENED 1 |
| 38 |
#define F_CREATED 2 |
| 39 |
#define F_OVERWRITTEN 3 |
| 40 |
|
| 41 |
/* Combinations of file access permission bits */ |
| 42 |
#define SET_FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA \ |
| 43 |
| FILE_READ_ATTRIBUTES \ |
| 44 |
| DELETE | READ_CONTROL | WRITE_DAC \ |
| 45 |
| WRITE_OWNER | SYNCHRONIZE) |
| 46 |
#define SET_FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \ |
| 47 |
| FILE_WRITE_EA \ |
| 48 |
| FILE_DELETE_CHILD \ |
| 49 |
| FILE_WRITE_ATTRIBUTES \ |
| 50 |
| DELETE | READ_CONTROL | WRITE_DAC \ |
| 51 |
| WRITE_OWNER | SYNCHRONIZE) |
| 52 |
|
| 53 |
/* generic flags for file open */ |
| 54 |
#define GENERIC_READ_FLAGS (READ_CONTROL | FILE_READ_DATA | \ |
| 55 |
FILE_READ_ATTRIBUTES | \ |
| 56 |
FILE_READ_EA | SYNCHRONIZE) |
| 57 |
|
| 58 |
#define GENERIC_WRITE_FLAGS (READ_CONTROL | FILE_WRITE_DATA | \ |
| 59 |
FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA | \ |
| 60 |
FILE_APPEND_DATA | SYNCHRONIZE) |
| 61 |
|
| 62 |
#define GENERIC_EXECUTE_FLAGS (READ_CONTROL | FILE_EXECUTE | \ |
| 63 |
FILE_READ_ATTRIBUTES | SYNCHRONIZE) |
| 64 |
|
| 65 |
#define GENERIC_ALL_FLAGS (DELETE | READ_CONTROL | WRITE_DAC | \ |
| 66 |
WRITE_OWNER | SYNCHRONIZE | FILE_READ_DATA | \ |
| 67 |
FILE_WRITE_DATA | FILE_APPEND_DATA | \ |
| 68 |
FILE_READ_EA | FILE_WRITE_EA | \ |
| 69 |
FILE_EXECUTE | FILE_DELETE_CHILD | \ |
| 70 |
FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES) |
| 71 |
|
| 72 |
#define SMB_COM_NEGOTIATE 0x72 /* See MS-CIFS 2.2.2.1 */ |
| 73 |
|
| 74 |
/* See MS-CIFS 2.2.3.1 */ |
| 75 |
#define SMBFLG_RESPONSE 0x80 /* this PDU is a response from server */ |
| 76 |
|
| 77 |
/* |
| 78 |
* See MS-CIFS 2.2.3.1 |
| 79 |
* MS-SMB 2.2.3.1 |
| 80 |
*/ |
| 81 |
#define SMBFLG2_IS_LONG_NAME cpu_to_le16(0x40) |
| 82 |
#define SMBFLG2_EXT_SEC cpu_to_le16(0x800) |
| 83 |
#define SMBFLG2_ERR_STATUS cpu_to_le16(0x4000) |
| 84 |
#define SMBFLG2_UNICODE cpu_to_le16(0x8000) |
| 85 |
|
| 86 |
/* See MS-CIFS 2.2.4.52.2 */ |
| 87 |
struct smb_negotiate_rsp { |
| 88 |
struct smb_hdr hdr; /* wct = 17 */ |
| 89 |
__le16 DialectIndex; /* 0xFFFF = no dialect acceptable */ |
| 90 |
__le16 ByteCount; |
| 91 |
} __packed; |
| 92 |
|
| 93 |
struct filesystem_vol_info { |
| 94 |
__le64 VolumeCreationTime; |
| 95 |
__le32 SerialNumber; |
| 96 |
__le32 VolumeLabelSize; |
| 97 |
__le16 Reserved; |
| 98 |
__le16 VolumeLabel[]; |
| 99 |
} __packed; |
| 100 |
|
| 101 |
#define EXTENDED_INFO_MAGIC 0x43667364 /* Cfsd */ |
| 102 |
#define STRING_LENGTH 28 |
| 103 |
|
| 104 |
struct fs_extended_info { |
| 105 |
__le32 magic; |
| 106 |
__le32 version; |
| 107 |
__le32 release; |
| 108 |
__u64 rel_date; |
| 109 |
char version_string[STRING_LENGTH]; |
| 110 |
} __packed; |
| 111 |
|
| 112 |
struct object_id_info { |
| 113 |
char objid[16]; |
| 114 |
struct fs_extended_info extended_info; |
| 115 |
} __packed; |
| 116 |
|
| 117 |
struct file_names_info { |
| 118 |
__le32 NextEntryOffset; |
| 119 |
__u32 FileIndex; |
| 120 |
__le32 FileNameLength; |
| 121 |
char FileName[]; |
| 122 |
} __packed; /* level 0xc FF resp data */ |
| 123 |
|
| 124 |
struct file_id_both_directory_info { |
| 125 |
__le32 NextEntryOffset; |
| 126 |
__u32 FileIndex; |
| 127 |
__le64 CreationTime; |
| 128 |
__le64 LastAccessTime; |
| 129 |
__le64 LastWriteTime; |
| 130 |
__le64 ChangeTime; |
| 131 |
__le64 EndOfFile; |
| 132 |
__le64 AllocationSize; |
| 133 |
__le32 ExtFileAttributes; |
| 134 |
__le32 FileNameLength; |
| 135 |
__le32 EaSize; /* length of the xattrs */ |
| 136 |
__u8 ShortNameLength; |
| 137 |
__u8 Reserved; |
| 138 |
__u8 ShortName[24]; |
| 139 |
__le16 Reserved2; |
| 140 |
__le64 UniqueId; |
| 141 |
char FileName[]; |
| 142 |
} __packed; |
| 143 |
|
| 144 |
struct smb_version_ops { |
| 145 |
u16 (*get_cmd_val)(struct ksmbd_work *swork); |
| 146 |
void (*inc_reqs)(unsigned int cmd); |
| 147 |
int (*init_rsp_hdr)(struct ksmbd_work *swork); |
| 148 |
void (*set_rsp_status)(struct ksmbd_work *swork, __le32 err); |
| 149 |
int (*allocate_rsp_buf)(struct ksmbd_work *work); |
| 150 |
int (*set_rsp_credits)(struct ksmbd_work *work); |
| 151 |
int (*check_user_session)(struct ksmbd_work *work); |
| 152 |
int (*get_ksmbd_tcon)(struct ksmbd_work *work); |
| 153 |
bool (*is_sign_req)(struct ksmbd_work *work, unsigned int command); |
| 154 |
int (*check_sign_req)(struct ksmbd_work *work); |
| 155 |
void (*set_sign_rsp)(struct ksmbd_work *work); |
| 156 |
int (*generate_signingkey)(struct ksmbd_session *sess, struct ksmbd_conn *conn); |
| 157 |
void (*generate_encryptionkey)(struct ksmbd_conn *conn, struct ksmbd_session *sess); |
| 158 |
bool (*is_transform_hdr)(void *buf); |
| 159 |
int (*decrypt_req)(struct ksmbd_work *work); |
| 160 |
int (*encrypt_resp)(struct ksmbd_work *work); |
| 161 |
}; |
| 162 |
|
| 163 |
struct smb_version_cmds { |
| 164 |
int (*proc)(struct ksmbd_work *swork); |
| 165 |
}; |
| 166 |
|
| 167 |
int ksmbd_min_protocol(void); |
| 168 |
int ksmbd_max_protocol(void); |
| 169 |
const char *ksmbd_get_protocol_string(int version); |
| 170 |
|
| 171 |
int ksmbd_lookup_protocol_idx(char *str); |
| 172 |
|
| 173 |
int ksmbd_verify_smb_message(struct ksmbd_work *work); |
| 174 |
bool ksmbd_smb_request(struct ksmbd_conn *conn); |
| 175 |
|
| 176 |
int ksmbd_lookup_dialect_by_id(__le16 *cli_dialects, __le16 dialects_count); |
| 177 |
|
| 178 |
int ksmbd_init_smb_server(struct ksmbd_conn *conn); |
| 179 |
|
| 180 |
struct ksmbd_kstat; |
| 181 |
int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work, |
| 182 |
int info_level, |
| 183 |
struct ksmbd_file *dir, |
| 184 |
struct ksmbd_dir_info *d_info, |
| 185 |
char *search_pattern, |
| 186 |
int (*fn)(struct ksmbd_conn *, |
| 187 |
int, |
| 188 |
struct ksmbd_dir_info *, |
| 189 |
struct ksmbd_kstat *)); |
| 190 |
|
| 191 |
int ksmbd_extract_shortname(struct ksmbd_conn *conn, |
| 192 |
const char *longname, |
| 193 |
char *shortname); |
| 194 |
|
| 195 |
int ksmbd_smb_negotiate_common(struct ksmbd_work *work, unsigned int command); |
| 196 |
|
| 197 |
int ksmbd_smb_check_shared_mode(struct file *filp, struct ksmbd_file *curr_fp); |
| 198 |
int __ksmbd_override_fsids(struct ksmbd_work *work, |
| 199 |
struct ksmbd_share_config *share); |
| 200 |
int ksmbd_override_fsids(struct ksmbd_work *work); |
| 201 |
void ksmbd_revert_fsids(struct ksmbd_work *work); |
| 202 |
|
| 203 |
unsigned int ksmbd_server_side_copy_max_chunk_count(void); |
| 204 |
unsigned int ksmbd_server_side_copy_max_chunk_size(void); |
| 205 |
unsigned int ksmbd_server_side_copy_max_total_size(void); |
| 206 |
bool is_asterisk(char *p); |
| 207 |
__le32 smb_map_generic_desired_access(__le32 daccess); |
| 208 |
|
| 209 |
/* |
| 210 |
* Get the body of the smb message excluding the 4 byte rfc1002 headers |
| 211 |
* from request/response buffer. |
| 212 |
*/ |
| 213 |
static inline void *smb_get_msg(void *buf) |
| 214 |
{ |
| 215 |
return buf + 4; |
| 216 |
} |
| 217 |
#endif /* __SMB_SERVER_COMMON_H__ */ |