/* * 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 spsmb3c_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 spsmb3c_* are owned by the library and valid until the next call * that changes the same state. Copy them. */ #ifndef SPSMB3C_H #define SPSMB3C_H #include #ifdef __cplusplus extern "C" { #endif #if defined(SPSMB3C_STATIC) # define SPSMB3C_API #elif defined(_WIN32) # if defined(SPSMB3C_BUILD) # define SPSMB3C_API __declspec(dllexport) # else # define SPSMB3C_API __declspec(dllimport) # endif #else # define SPSMB3C_API __attribute__((visibility("default"))) #endif #define SPSMB3C_VERSION "1.0.0" /* ---- error taxonomy (SPEC section 10). Values frozen. ---- */ #define SPSMB3C_OK 0 #define SPSMB3C_E_NETWORK -1 /* refused, reset, timeout, host not found */ #define SPSMB3C_E_PROTOCOL -2 /* malformed / truncated / unexpected reply */ #define SPSMB3C_E_AUTH -3 /* LOGON_FAILURE / WRONG_PASSWORD / ACCESS_DENIED */ #define SPSMB3C_E_NOTFOUND -4 /* no such share / file / folder (NT status kept) */ #define SPSMB3C_E_NO_SESSION -5 /* not connected / not authenticated */ #define SPSMB3C_E_INVALID_ARG -6 #define SPSMB3C_E_LIMIT -7 /* a bounded decode limit was exceeded */ #define SPSMB3C_E_UNSUPPORTED -8 /* server refused the 2.x dialects / fsctl etc. */ #define SPSMB3C_E_BUFFER -9 /* out buffer too small */ #define SPSMB3C_E_EOF -10 /* read past EOF (returns bytes read + this code) */ #define SPSMB3C_E_OOM -11 /* short aliases (the vendored row-44 server code uses these names) */ #define SPSMB3C_E_ARG SPSMB3C_E_INVALID_ARG #define SPSMB3C_E_PATH SPSMB3C_E_INVALID_ARG #define SPSMB3C_E_RANGE SPSMB3C_E_LIMIT /* ---- handle semantics ---- * spsmb3c_open returns a handle >= 1, or < 0 on error. Handles live until * spsmb3c_close(h) / spsmb3c_disconnect(). spsmb3c_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 SPSMB3C_OK. */ /* ---- connect + authenticate (SMB2ClientPortable.CreateClient) ---- */ /* host: name or IP; port 0 = 445 (DirectTCPTransport legacy default) */ SPSMB3C_API int spsmb3c_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 */ SPSMB3C_API int spsmb3c_connect_json(const char *runtime_settings_json); /* full disconnect: LOGOFF + TREE_DISCONNECTs + transport close */ SPSMB3C_API void spsmb3c_disconnect(void); SPSMB3C_API const char *spsmb3c_session_json(void); /* ---- shares (the empty-Path legacy rule: ListShares) ---- */ SPSMB3C_API int spsmb3c_shares(void); /* count, <0 error */ SPSMB3C_API const char *spsmb3c_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 ($ . @). */ SPSMB3C_API int spsmb3c_list(const char *share, const char *path); SPSMB3C_API const char *spsmb3c_item_json(int i); /* {"path":..,"share":..,"items":[{name,path,folder,size,mtime_ms,hidden}..]} (#26 shape) */ SPSMB3C_API const char *spsmb3c_list_json(void); SPSMB3C_API int spsmb3c_list_hidden_count(void); /* entries dropped by the filter */ SPSMB3C_API int spsmb3c_is_hidden_name(const char *name); /* ---- file reads (CREATE read-only + READ) ---- */ SPSMB3C_API int spsmb3c_open(const char *share, const char *path); /* handle >= 1 */ SPSMB3C_API long long spsmb3c_size(int h); /* EndOfFile at open, <0 error */ SPSMB3C_API int spsmb3c_read_at(int h, long long off, void *buf, int len); /* EOF-capped, bytes or <0 */ SPSMB3C_API void spsmb3c_close(int h); SPSMB3C_API long long spsmb3c_frame_count(void); /* SMB2 frames sent since connect */ /* ---- pure, socket-free helpers ---- */ /* split "share/sub/dir" -> share + sub-path (the legacy TreeConnectPath rule) */ SPSMB3C_API int spsmb3c_split_path(const char *path, char *share, int share_cap, char *sub, int sub_cap); SPSMB3C_API const char *spsmb3c_ntstatus_name(unsigned status); /* "LOGON_FAILURE" etc */ SPSMB3C_API int spsmb3c_selftest(void); /* 0 = crypto + framing vectors pass */ /* ---- transports (SPEC section 3) ---- */ SPSMB3C_API int spsmb3c_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; SPSMB3C_API int spsmb3c_use_io(const struct scorpiox_io *io); /* frames tunnelled through scorpiox_io */ SPSMB3C_API const struct scorpiox_io *spsmb3c_io_socket(void); /* the in-process fake SMB2 server (tests, console --test). tree_json: SPEC section 12 */ SPSMB3C_API int spsmb3c_use_fake(const char *tree_json); SPSMB3C_API const struct scorpiox_io *spsmb3c_io_fake(void); SPSMB3C_API int spsmb3c_fake_set_fault(const char *what, int value); /* SPEC section 12 */ SPSMB3C_API long long spsmb3c_fake_calls(int cmd); /* SMB2 commands the client sent */ /* ---- results + adapters ---- */ /* "NETWORK 0x00000000 refused" style: the last failure's class + NTSTATUS + message */ SPSMB3C_API const char *spsmb3c_last_error(void); SPSMB3C_API int spsmb3c_last_code(void); SPSMB3C_API unsigned spsmb3c_last_ntstatus(void); SPSMB3C_API const char *spsmb3c_strerror(int code); SPSMB3C_API const char *spsmb3c_version(void); SPSMB3C_API const void *spsmb3c_sprch_handler(void); /* const sprch_handler * (row 54) */ SPSMB3C_API const void *spsmb3c_spffa_backend(void); /* const spffa_backend * (#26) */ #ifdef __cplusplus } #endif #endif /* SPSMB3C_H */