4#ifndef PROTOCORE_SMB_CLIENT_H
5#define PROTOCORE_SMB_CLIENT_H
38 SMB_ERR_PROTOCOL = -3,
40 SMB_ERR_OVERFLOW = -5,
49typedef int (*
SmbSendFn)(
void *ctx,
const uint8_t *data,
size_t len);
51typedef int (*
SmbRecvFn)(
void *ctx, uint8_t *buf,
size_t cap);
159typedef int (*
SmbSendFn)(
void *ctx,
const uint8_t *data,
size_t len);
#define PROTOCORE_UNUSED
Suppress the unused warning. Every module ends in a namespace most callers only partly use.
#define PROTOCORE_NS_LAYOUT(T,...)
Pin every dispatch slot of a table that is nothing but function pointers.
#define PROTOCORE_NS
Storage for a dispatch table. The const is load bearing.
SMB2 client wire codec (MS-SMB2), PROTOCORE_ENABLE_SMB - increment 1: the transport frame,...
#define PROTOCORE_SMB2_MAX_CIPHER_KEY_LEN
Largest cipher key length across the four SMB 3.1.1 ciphers (AES-256), for buffer sizing.
SmbResult protocore_smb_client_smb_open(uint8_t *work, const SmbConfig *cfg, SmbHandle *h, SmbSendFn send, SmbRecvFn recv, void *ctx)
Run NEGOTIATE -> NTLMv2 SESSION_SETUP -> TREE_CONNECT -> CREATE and .
int(* SmbRecvFn)(void *ctx, uint8_t *buf, size_t cap)
int(* SmbSendFn)(void *ctx, const uint8_t *data, size_t len)
Transport seam: the engine moves raw bytes only through these, so it runs against a real socket (prot...
uint8_t * protocore_smb_client_span(void)
The PROTOCORE_SMB_CLIENT_BORROW bytes this module's state lives in.
SmbResult protocore_smb_client_smb_write(uint8_t *work, SmbHandle *h, uint64_t offset, const uint8_t *data, size_t len, size_t *written, SmbSendFn send, SmbRecvFn recv, void *ctx)
Write len bytes at offset of the open handle, looping WRITE .
SmbResult protocore_smb_client_smb_close(uint8_t *work, SmbHandle *h, SmbSendFn send, SmbRecvFn recv, void *ctx)
CLOSE the open handle (releases the server-side FileId).
SmbResult protocore_smb_client_smb_read(uint8_t *work, SmbHandle *h, uint64_t offset, uint8_t *out, size_t cap, size_t *out_len, SmbSendFn send, SmbRecvFn recv, void *ctx)
Read up to cap bytes from offset of the open handle, looping READ .
EMBED_ENUM_BYTE(SmbResult, SMB_OK=0, SMB_ERR_ARG=-1, SMB_ERR_IO=-2, SMB_ERR_PROTOCOL=-3, SMB_ERR_AUTH=-4, SMB_ERR_OVERFLOW=-5,)
Result of an SMB client operation. 0 is success; each failure is a distinct code.
Dispatch table. Addressed by offset, so the layout is asserted below.
SmbResult(* smb_open)(uint8_t *, const SmbConfig *, SmbHandle *, SmbSendFn, SmbRecvFn, void *)
SmbResult(* smb_write)(uint8_t *, SmbHandle *, uint64_t, const uint8_t *, size_t, size_t *, SmbSendFn, SmbRecvFn, void *)
SmbResult(* smb_close)(uint8_t *, SmbHandle *, SmbSendFn, SmbRecvFn, void *)
SmbResult(* smb_read)(uint8_t *, SmbHandle *, uint64_t, uint8_t *, size_t, size_t *, SmbSendFn, SmbRecvFn, void *)
Server credentials + the file to open. Strings are ASCII/UTF-8 (encoded UTF-16LE for you).
const char * path
file name relative to the share root (e.g. PROGRAMS\A.NC)
uint32_t disposition
SMB2_FILE_OPEN / _OPEN_IF / _OVERWRITE_IF / _CREATE.
const char * workstation
client name to announce (null => none)
const char * user
account name
uint32_t desired_access
SMB2_FILE_GENERIC_READ and/or _WRITE.
const char * pass
password
const char * share
the tree path, UNC \\server\share
const char * domain
NTLM domain (null/empty for a local account).
An open file on an authenticated session; the ids thread the follow-up requests.
embed_bool encrypt_active
SMB 3.x transport encryption is in force (server session or share required it).
uint64_t enc_nonce
monotonic per-session AEAD nonce counter, persisted across read/write/close
uint64_t next_message_id
the MessageId for the next request on this handle
uint8_t signing_key[16]
the session signing key when signing_active (2.x: NTLMv2 key; 3.x: KDF-derived)
uint64_t file_size
EndofFile from CREATE (the current size).
uint8_t enc_c2s[PROTOCORE_SMB2_MAX_CIPHER_KEY_LEN]
client->server cipher key (encrypts requests)
Smb2SignAlgo signing_algo
HMAC-SHA256 (SMB 2.x) or AES-CMAC (SMB 3.x), from the negotiated dialect.
embed_bool signing_active
the session negotiated SMB signing (server set SigningRequired, not guest/null)
uint8_t enc_s2c[PROTOCORE_SMB2_MAX_CIPHER_KEY_LEN]
server->client cipher key (decrypts responses)
uint16_t enc_cipher
negotiated Smb2Cipher id (selects the key + nonce length) when encrypt_active