/* * spsmbc.h — scorpiox-scorpioplayer-smb-v2-file-client * * SCORPIO PLAYER 2027 engine, row 45. Pure C99, zero external deps (vendored yyjson only). * A read-only SMB 2.0.2/2.1 CLIENT: NEGOTIATE, SESSION_SETUP (NTLMv2 over SPNEGO, guest * supported), TREE_CONNECT, share enumeration (MS-SRVS NetShareEnumAll over IPC$), * QUERY_DIRECTORY paging, CREATE (read-only), READ at 64-bit offsets (MaxReadSize chunks, * several reads in flight), CLOSE, LOGOFF. Nothing writes, deletes or renames. * * It replaces SMBLibrary 1.5.3.4's SMB2Client (legacy `SMB2ClientPortable`), whose * `Connect`+`Login` failure returned null with no reason — the C engine surfaces the * NTSTATUS of every failure via spsmbc_last_error(). * * Also implements the row-54 `sprch_handler` boundary (RuntimeType "SMB2") and the #26 * `spffa_backend` storage vtable (id "smb2"). See SPEC.md for every decision. * * Threading: one global session (fleet style). Not thread-safe; call from one thread. * Strings returned by spsmbc_* are owned by the library and valid until the next call * that changes the same state. Copy them. */ #ifndef SPSMBC_H #define SPSMBC_H #include #ifdef __cplusplus extern "C" { #endif #if defined(SPSMBC_STATIC) # define SPSMBC_API #elif defined(_WIN32) # if defined(SPSMBC_BUILD) # define SPSMBC_API __declspec(dllexport) # else # define SPSMBC_API __declspec(dllimport) # endif #else # define SPSMBC_API __attribute__((visibility("default"))) #endif #define SPSMBC_VERSION "1.0.1" /* ---- error taxonomy (SPEC section 10). Values frozen. ---- */ #define SPSMBC_OK 0 #define SPSMBC_E_NETWORK -1 /* refused, reset, timeout, host not found */ #define SPSMBC_E_PROTOCOL -2 /* malformed / truncated / unexpected reply */ #define SPSMBC_E_AUTH -3 /* LOGON_FAILURE / WRONG_PASSWORD / ACCESS_DENIED */ #define SPSMBC_E_NOTFOUND -4 /* no such share / file / folder (NT status kept) */ #define SPSMBC_E_NO_SESSION -5 /* not connected / not authenticated */ #define SPSMBC_E_INVALID_ARG -6 #define SPSMBC_E_LIMIT -7 /* a bounded decode limit was exceeded */ #define SPSMBC_E_UNSUPPORTED -8 /* server refused the 2.x dialects / fsctl etc. */ #define SPSMBC_E_BUFFER -9 /* out buffer too small */ #define SPSMBC_E_EOF -10 /* read past EOF (returns bytes read + this code) */ #define SPSMBC_E_OOM -11 /* short aliases (the vendored row-44 server code uses these names) */ #define SPSMBC_E_ARG SPSMBC_E_INVALID_ARG #define SPSMBC_E_PATH SPSMBC_E_INVALID_ARG #define SPSMBC_E_RANGE SPSMBC_E_LIMIT /* ---- handle semantics ---- * spsmbc_open returns a handle >= 1, or < 0 on error. Handles live until * spsmbc_close(h) / spsmbc_disconnect(). spsmbc_read_at EOF-caps and never pads: * it returns the bytes read (>= 0) or < 0 on error; a read starting at/after EOF * returns 0 with SPSMBC_OK. */ /* ---- connect + authenticate (SMB2ClientPortable.CreateClient) ---- */ /* host: name or IP; port 0 = 445 (DirectTCPTransport legacy default) */ SPSMBC_API int spsmbc_connect(const char *host, int port, const char *domain, const char *user, const char *pass); /* legacy RuntimeSettings keys unchanged: HostName, UserName, Password, Path * (share/sub/dir), DomainName, ID */ SPSMBC_API int spsmbc_connect_json(const char *runtime_settings_json); /* full disconnect: LOGOFF + TREE_DISCONNECTs + transport close */ SPSMBC_API void spsmbc_disconnect(void); SPSMBC_API const char *spsmbc_session_json(void); /* ---- shares (the empty-Path legacy rule: ListShares) ---- */ SPSMBC_API int spsmbc_shares(void); /* count, <0 error */ SPSMBC_API const char *spsmbc_share_name(int i); /* valid until the next shares/list call */ /* ---- listing (QUERY_DIRECTORY FileIdBothDirectoryInformation, paged internally) ---- */ /* path NULL/"" = the share root. Count is AFTER the legacy hidden filter ($ . @). */ SPSMBC_API int spsmbc_list(const char *share, const char *path); SPSMBC_API const char *spsmbc_item_json(int i); /* {"path":..,"share":..,"items":[{name,path,folder,size,mtime_ms,hidden}..]} (#26 shape) */ SPSMBC_API const char *spsmbc_list_json(void); SPSMBC_API int spsmbc_list_hidden_count(void); /* entries dropped by the filter */ SPSMBC_API int spsmbc_is_hidden_name(const char *name); /* ---- file reads (CREATE read-only + READ) ---- */ SPSMBC_API int spsmbc_open(const char *share, const char *path); /* handle >= 1 */ SPSMBC_API long long spsmbc_size(int h); /* EndOfFile at open, <0 error */ SPSMBC_API int spsmbc_read_at(int h, long long off, void *buf, int len); /* EOF-capped, bytes or <0 */ SPSMBC_API void spsmbc_close(int h); SPSMBC_API long long spsmbc_frame_count(void); /* SMB2 frames sent since connect */ /* ---- pure, socket-free helpers ---- */ /* split "share/sub/dir" -> share + sub-path (the legacy TreeConnectPath rule) */ SPSMBC_API int spsmbc_split_path(const char *path, char *share, int share_cap, char *sub, int sub_cap); SPSMBC_API const char *spsmbc_ntstatus_name(unsigned status); /* "LOGON_FAILURE" etc */ SPSMBC_API int spsmbc_selftest(void); /* 0 = crypto + framing vectors pass */ /* ---- transports (SPEC section 3) ---- */ SPSMBC_API int spsmbc_use_sockets(void); /* default: real TCP */ /* the forward type only: the full typedef lives in scorpiox-io.h (a re-typedef of the * same name is a C11-only feature and clang -Werror rejects it) */ struct scorpiox_io; SPSMBC_API int spsmbc_use_io(const struct scorpiox_io *io); /* frames tunnelled through scorpiox_io */ SPSMBC_API const struct scorpiox_io *spsmbc_io_socket(void); /* the in-process fake SMB2 server (tests, console --test). tree_json: SPEC section 12 */ SPSMBC_API int spsmbc_use_fake(const char *tree_json); SPSMBC_API const struct scorpiox_io *spsmbc_io_fake(void); SPSMBC_API int spsmbc_fake_set_fault(const char *what, int value); /* SPEC section 12 */ SPSMBC_API long long spsmbc_fake_calls(int cmd); /* SMB2 commands the client sent */ /* ---- results + adapters ---- */ /* "NETWORK 0x00000000 refused" style: the last failure's class + NTSTATUS + message */ SPSMBC_API const char *spsmbc_last_error(void); SPSMBC_API int spsmbc_last_code(void); SPSMBC_API unsigned spsmbc_last_ntstatus(void); SPSMBC_API const char *spsmbc_strerror(int code); SPSMBC_API const char *spsmbc_version(void); SPSMBC_API const void *spsmbc_sprch_handler(void); /* const sprch_handler * (row 54) */ SPSMBC_API const void *spsmbc_spffa_backend(void); /* const spffa_backend * (#26) */ #ifdef __cplusplus } #endif #endif /* SPSMBC_H */