/* * spsmb1c.h — scorpiox-scorpioplayer-smb-v1-cifs-file-client * * SCORPIO PLAYER 2027 engine, row 43. Pure C99, zero external deps (vendored yyjson only). * A read-only SMB 1 / CIFS (NT LM 0.12) CLIENT: NEGOTIATE, SESSION_SETUP_ANDX (NTLMv2 over * SPNEGO extended security, with the raw-NTLM non-extended fallback, guest supported), * TREE_CONNECT_ANDX, share enumeration (MS-SRVS NetShareEnumAll over IPC$), TRANS2 * FIND_FIRST2 / FIND_NEXT2 (FileBothDirectoryInformation, paged), NT_CREATE_ANDX (read-only * open), READ_ANDX at 64-bit offsets, CLOSE, FIND_CLOSE2, LOGOFF_ANDX, TREE_DISCONNECT, * and SMB1 signing (MD5, macSigningKey = sessionKey + zeros) when the server demands it. * * It replaces SharpCifs.Std 0.2.13 (the jCIFS port), whose SmbFile surface returned no * reason for any failure — the C engine surfaces the NT status / DOS error class+code of * every failure via spsmb1c_last_error(). * * Also implements the row-54 `sprch_handler` boundary (RuntimeType "SMBCIFS", the legacy * SMBCIFSRuntimeConfigHandler string) and the #26 `spffa_backend` storage vtable (id * "smb1"). See SPEC.md for every decision. * * Threading: one global session (fleet style). Not thread-safe; call from one thread. * Strings returned by spsmb1c_* are owned by the library and valid until the next call * that changes the same state. Copy them. */ #ifndef SPSMB1C_H #define SPSMB1C_H #include #ifdef __cplusplus extern "C" { #endif #if defined(SPSMB1C_STATIC) # define SPSMB1C_API #elif defined(_WIN32) # if defined(SPSMB1C_BUILD) # define SPSMB1C_API __declspec(dllexport) # else # define SPSMB1C_API __declspec(dllimport) # endif #else # define SPSMB1C_API __attribute__((visibility("default"))) #endif #define SPSMB1C_VERSION "1.0.0" /* ---- error taxonomy (SPEC section 8). Values frozen (same family as spsmbc.h). ---- */ #define SPSMB1C_OK 0 #define SPSMB1C_E_NETWORK -1 /* refused, reset, timeout, DNS, no NBSS header */ #define SPSMB1C_E_PROTOCOL -2 /* malformed / truncated / unexpected reply */ #define SPSMB1C_E_AUTH -3 /* LOGON_FAILURE / ACCESS_DENIED / logon denied */ #define SPSMB1C_E_NOTFOUND -4 /* no such share / file / folder (status kept) */ #define SPSMB1C_E_NO_SESSION -5 /* not connected / not authenticated */ #define SPSMB1C_E_INVALID_ARG -6 #define SPSMB1C_E_LIMIT -7 /* a bounded decode limit was exceeded */ #define SPSMB1C_E_UNSUPPORTED -8 /* the server refused NT LM 0.12 / trans2 unsupported */ #define SPSMB1C_E_BUFFER -9 /* out buffer too small */ #define SPSMB1C_E_EOF -10 /* read past EOF (returns bytes read + this code) */ #define SPSMB1C_E_OOM -11 /* short aliases */ #define SPSMB1C_E_ARG SPSMB1C_E_INVALID_ARG #define SPSMB1C_E_PATH SPSMB1C_E_INVALID_ARG #define SPSMB1C_E_RANGE SPSMB1C_E_LIMIT /* ---- handle semantics ---- * spsmb1c_open returns a handle >= 1, or < 0 on error. Handles live until * spsmb1c_close(h) / spsmb1c_disconnect(). spsmb1c_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 SPSMB1C_OK. */ /* ---- connect + authenticate (the legacy settings path) ---- */ /* host: name or IP; port 0 = 445 (SmbConstants.DefaultPort) */ SPSMB1C_API int spsmb1c_connect(const char *host, int port, const char *domain, const char *user, const char *pass); /* legacy RuntimeSettings keys unchanged: HostName, ServerPort, LocalPort, UserName, * Password, Path, FullUrl, DomainName, ID (the SMBCIFSRuntimeConfigHandler set) */ SPSMB1C_API int spsmb1c_connect_json(const char *runtime_settings_json); /* the legacy FullUrl form, parsed (pure, unit-tested): see spsmb1c_url_parse */ SPSMB1C_API int spsmb1c_url_parse(const char *url, char *host, int hcap, int *port, char *user, int ucap, char *pass, int pcap, char *domain, int dcap, char *path, int pcap2); /* full disconnect: LOGOFF_ANDX + TREE_DISCONNECTs + transport close */ SPSMB1C_API void spsmb1c_disconnect(void); SPSMB1C_API const char *spsmb1c_session_json(void); /* ---- shares (the empty-Path legacy rule: ListShares) ---- */ SPSMB1C_API int spsmb1c_shares(void); /* count, <0 error */ SPSMB1C_API const char *spsmb1c_share_name(int i); /* valid until the next shares/list call */ /* ---- listing (TRANS2 FIND_FIRST2 + FIND_NEXT2, FileBothDirectoryInformation, paged) ---- */ /* path NULL/"" = the share root. Count is AFTER the legacy hidden filter ($ . @). */ SPSMB1C_API int spsmb1c_list(const char *share, const char *path); SPSMB1C_API const char *spsmb1c_item_json(int i); /* {"path":..,"share":..,"items":[{name,path,folder,size,mtime_ms,hidden}..]} (#26 shape) */ SPSMB1C_API const char *spsmb1c_list_json(void); SPSMB1C_API int spsmb1c_list_hidden_count(void); /* entries dropped by the filter */ SPSMB1C_API int spsmb1c_is_hidden_name(const char *name); /* ---- file reads (NT_CREATE_ANDX read-only + READ_ANDX) ---- */ SPSMB1C_API int spsmb1c_open(const char *share, const char *path); /* handle >= 1 */ SPSMB1C_API long long spsmb1c_size(int h); /* EndOfFile at open, <0 error */ SPSMB1C_API int spsmb1c_read_at(int h, long long off, void *buf, int len); /* EOF-capped, bytes or <0 */ SPSMB1C_API void spsmb1c_close(int h); SPSMB1C_API long long spsmb1c_frame_count(void); /* SMB1 frames sent since connect */ /* ---- pure, socket-free helpers ---- */ /* split "share/sub/dir" -> share + sub-path (the legacy TreeConnectPath rule) */ SPSMB1C_API int spsmb1c_split_path(const char *path, char *share, int share_cap, char *sub, int sub_cap); SPSMB1C_API const char *spsmb1c_status_name(unsigned status); /* "LOGON_FAILURE"/DOS names */ SPSMB1C_API int spsmb1c_selftest(void); /* 0 = crypto + framing vectors pass */ /* ---- transports (SPEC section 4) ---- */ SPSMB1C_API int spsmb1c_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; SPSMB1C_API int spsmb1c_use_io(const struct scorpiox_io *io); /* frames tunnelled through scorpiox_io */ SPSMB1C_API const struct scorpiox_io *spsmb1c_io_socket(void); /* the in-process fake SMB1 server (tests, console --test). tree_json: SPEC section 10 */ SPSMB1C_API int spsmb1c_use_fake(const char *tree_json); SPSMB1C_API const struct scorpiox_io *spsmb1c_io_fake(void); SPSMB1C_API int spsmb1c_fake_set_fault(const char *what, int value); /* SPEC section 10 */ SPSMB1C_API long long spsmb1c_fake_calls(int cmd); /* SMB1 commands the client sent */ /* ---- results + adapters ---- */ /* "NETWORK 0x00000000 refused" style: the last failure's class + status + message */ SPSMB1C_API const char *spsmb1c_last_error(void); SPSMB1C_API int spsmb1c_last_code(void); SPSMB1C_API unsigned spsmb1c_last_status(void); SPSMB1C_API const char *spsmb1c_strerror(int code); SPSMB1C_API const char *spsmb1c_version(void); SPSMB1C_API const void *spsmb1c_sprch_handler(void); /* const sprch_handler * (row 54) */ SPSMB1C_API const void *spsmb1c_spffa_backend(void); /* const spffa_backend * (#26) */ #ifdef __cplusplus } #endif #endif /* SPSMB1C_H */