Răsfoiți Sursa

添加交叉编译smb库

chendeben 9 luni în urmă
părinte
comite
bd5436e19d
36 a modificat fișierele cu 7395 adăugiri și 47 ștergeri
  1. 1 1
      entry/build-profile.json5
  2. 4 11
      entry/oh-package-lock.json5
  3. 0 1
      entry/oh-package.json5
  4. 0 1
      entry/oh_modules/libentry.so/Index.d.ts
  5. 0 6
      entry/oh_modules/libentry.so/oh-package.json5
  6. 13 1
      entry/src/main/cpp/CMakeLists.txt
  7. 15 0
      entry/src/main/cpp/include/Makefile.am
  8. 139 0
      entry/src/main/cpp/include/amiga_os/config.h
  9. 139 0
      entry/src/main/cpp/include/apple/config.h
  10. 65 0
      entry/src/main/cpp/include/asprintf.h
  11. 139 0
      entry/src/main/cpp/include/esp/config.h
  12. 668 0
      entry/src/main/cpp/include/libsmb2-private.h
  13. 21 0
      entry/src/main/cpp/include/module.modulemap
  14. 143 0
      entry/src/main/cpp/include/picow/FreeRTOSConfig.h
  15. 2 0
      entry/src/main/cpp/include/picow/README.md
  16. 139 0
      entry/src/main/cpp/include/picow/config.h
  17. 27 0
      entry/src/main/cpp/include/picow/lwipopts.h
  18. 90 0
      entry/src/main/cpp/include/picow/lwipopts_examples_common.h
  19. 377 0
      entry/src/main/cpp/include/portable-endian.h
  20. 139 0
      entry/src/main/cpp/include/ps3/config.h
  21. 63 0
      entry/src/main/cpp/include/slist.h
  22. 172 0
      entry/src/main/cpp/include/smb2/libsmb2-dcerpc-lsa.h
  23. 180 0
      entry/src/main/cpp/include/smb2/libsmb2-dcerpc-srvsvc.h
  24. 155 0
      entry/src/main/cpp/include/smb2/libsmb2-dcerpc.h
  25. 497 0
      entry/src/main/cpp/include/smb2/libsmb2-raw.h
  26. 1406 0
      entry/src/main/cpp/include/smb2/libsmb2.h
  27. 549 0
      entry/src/main/cpp/include/smb2/smb2-errors.h
  28. 83 0
      entry/src/main/cpp/include/smb2/smb2-ioctl.h
  29. 1251 0
      entry/src/main/cpp/include/smb2/smb2.h
  30. 139 0
      entry/src/main/cpp/include/xbox 360/config.h
  31. 139 0
      entry/src/main/cpp/include/xbox/config.h
  32. BIN
      entry/src/main/cpp/libs/arm64-v8a/libsmb2.so
  33. 559 22
      entry/src/main/cpp/napi_init.cpp
  34. 22 1
      entry/src/main/cpp/types/libentry/Index.d.ts
  35. 56 1
      entry/src/main/ets/pages/SettingPage.ets
  36. 3 2
      entry/src/main/resources/base/profile/main_pages.json

+ 1 - 1
entry/build-profile.json5

@@ -20,4 +20,4 @@
       "name": "ohosTest",
       "name": "ohosTest",
     }
     }
   ]
   ]
-}
+}

+ 4 - 11
entry/oh-package-lock.json5

@@ -8,18 +8,17 @@
   "specifiers": {
   "specifiers": {
     "@ohos/ijkplayer@../ijkplayer": "@ohos/ijkplayer@../ijkplayer",
     "@ohos/ijkplayer@../ijkplayer": "@ohos/ijkplayer@../ijkplayer",
     "@tencent/wechat_open_sdk@1.0.0": "@tencent/wechat_open_sdk@1.0.0",
     "@tencent/wechat_open_sdk@1.0.0": "@tencent/wechat_open_sdk@1.0.0",
-    "@types/libijkplayer_audio_napi.so@../ijkplayer/src/main/cpp/types/ijkplayer_audio_napi": "@types/libijkplayer_audio_napi.so@../ijkplayer/src/main/cpp/types/ijkplayer_audio_napi",
-    "libentry.so@src/main/cpp/types/libentry": "libentry.so@src/main/cpp/types/libentry"
+    "@types/libijkplayer_audio_napi.so@../ijkplayer/src/main/cpp/types/ijkplayer_audio_napi": "@types/libijkplayer_audio_napi.so@../ijkplayer/src/main/cpp/types/ijkplayer_audio_napi"
   },
   },
   "packages": {
   "packages": {
     "@ohos/ijkplayer@../ijkplayer": {
     "@ohos/ijkplayer@../ijkplayer": {
       "name": "@ohos/ijkplayer",
       "name": "@ohos/ijkplayer",
       "version": "2.0.5",
       "version": "2.0.5",
-      "resolved": "../ijkplayer",
+      "resolved": "",
       "registryType": "local"
       "registryType": "local"
     },
     },
     "@tencent/wechat_open_sdk@1.0.0": {
     "@tencent/wechat_open_sdk@1.0.0": {
-      "name": "@tencent/wechat_open_sdk",
+      "name": "",
       "version": "1.0.0",
       "version": "1.0.0",
       "integrity": "sha512-rB1bWPTeMEir10+RguSlURf2ji/m7Xs0exh+EdRUEYhwKqnxMGylaASjX/A1nqZM1KBmx5+MVwt9DayTReP3mA==",
       "integrity": "sha512-rB1bWPTeMEir10+RguSlURf2ji/m7Xs0exh+EdRUEYhwKqnxMGylaASjX/A1nqZM1KBmx5+MVwt9DayTReP3mA==",
       "resolved": "https://repo.harmonyos.com/ohpm/@tencent/wechat_open_sdk/-/wechat_open_sdk-1.0.0.har",
       "resolved": "https://repo.harmonyos.com/ohpm/@tencent/wechat_open_sdk/-/wechat_open_sdk-1.0.0.har",
@@ -28,13 +27,7 @@
     "@types/libijkplayer_audio_napi.so@../ijkplayer/src/main/cpp/types/ijkplayer_audio_napi": {
     "@types/libijkplayer_audio_napi.so@../ijkplayer/src/main/cpp/types/ijkplayer_audio_napi": {
       "name": "@types/libijkplayer_audio_napi.so",
       "name": "@types/libijkplayer_audio_napi.so",
       "version": "2.0.3-rc.3",
       "version": "2.0.3-rc.3",
-      "resolved": "../ijkplayer/src/main/cpp/types/ijkplayer_audio_napi",
-      "registryType": "local"
-    },
-    "libentry.so@src/main/cpp/types/libentry": {
-      "name": "libentry.so",
-      "version": "1.0.0",
-      "resolved": "src/main/cpp/types/libentry",
+      "resolved": "",
       "registryType": "local"
       "registryType": "local"
     }
     }
   }
   }

+ 0 - 1
entry/oh-package.json5

@@ -7,7 +7,6 @@
   "license": "LGPLv2.1 or later",
   "license": "LGPLv2.1 or later",
   "dependencies": {
   "dependencies": {
     "@ohos/ijkplayer": "file:../ijkplayer",//注释掉这个代码,用ohpm install @ohos/ijkplayer去装2.0.6版本
     "@ohos/ijkplayer": "file:../ijkplayer",//注释掉这个代码,用ohpm install @ohos/ijkplayer去装2.0.6版本
-    "libentry.so": "file:./src/main/cpp/types/libentry",
 //    "@csj/openadsdk": "file:libs/openadsdk_6.7.0.har",
 //    "@csj/openadsdk": "file:libs/openadsdk_6.7.0.har",
     "@tencent/wechat_open_sdk": "1.0.0"
     "@tencent/wechat_open_sdk": "1.0.0"
   }
   }

+ 0 - 1
entry/oh_modules/libentry.so/Index.d.ts

@@ -1 +0,0 @@
-export const add: (a: number, b: number) => number;

+ 0 - 6
entry/oh_modules/libentry.so/oh-package.json5

@@ -1,6 +0,0 @@
-{
-  "name": "libentry.so",
-  "types": "./Index.d.ts",
-  "version": "1.0.0",
-  "description": "Please describe the basic information."
-}

+ 13 - 1
entry/src/main/cpp/CMakeLists.txt

@@ -2,6 +2,9 @@
 cmake_minimum_required(VERSION 3.5.0)
 cmake_minimum_required(VERSION 3.5.0)
 project(native7)
 project(native7)
 
 
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
 set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
 set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
 
 
 if(DEFINED PACKAGE_FIND_FILE)
 if(DEFINED PACKAGE_FIND_FILE)
@@ -17,5 +20,14 @@ include_directories(${NATIVERENDER_ROOT_PATH}
                     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../ijkplayer/src/main/cpp/ijksdl
                     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../ijkplayer/src/main/cpp/ijksdl
                     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../ijkplayer/src/main/cpp/ijkplayer)
                     ${CMAKE_CURRENT_SOURCE_DIR}/../../../../ijkplayer/src/main/cpp/ijkplayer)
 
 
+set(SMB2_LIB_NAME libsmb2.so.1)
+set(SMB2_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/libs/${OHOS_ARCH}/${SMB2_LIB_NAME})
+if(EXISTS ${SMB2_LIB_PATH})
+    add_library(smb2 SHARED IMPORTED)
+    set_target_properties(smb2 PROPERTIES IMPORTED_LOCATION ${SMB2_LIB_PATH})
+else()
+    message(FATAL_ERROR "${SMB2_LIB_NAME} not found for architecture ${OHOS_ARCH} at ${SMB2_LIB_PATH}")
+endif()
+
 add_library(entry SHARED napi_init.cpp)
 add_library(entry SHARED napi_init.cpp)
-target_link_libraries(entry PUBLIC libace_napi.z.so)
+target_link_libraries(entry PUBLIC libace_napi.z.so hilog_ndk.z smb2)

+ 15 - 0
entry/src/main/cpp/include/Makefile.am

@@ -0,0 +1,15 @@
+smb2dir = $(includedir)/smb2
+dist_smb2_HEADERS = \
+	smb2/libsmb2.h \
+	smb2/libsmb2-dcerpc.h \
+	smb2/libsmb2-dcerpc-lsa.h \
+	smb2/libsmb2-dcerpc-srvsvc.h \
+	smb2/libsmb2-raw.h \
+	smb2/smb2.h \
+	smb2/smb2-errors.h
+
+dist_noinst_HEADERS = \
+	asprintf.h \
+	libsmb2-private.h \
+	portable-endian.h \
+	slist.h

+ 139 - 0
entry/src/main/cpp/include/amiga_os/config.h

@@ -0,0 +1,139 @@
+/* config.h.  Generated from config.h.in by configure.  */
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Whether or not TCP sockets should be allowed to linger after closure */
+#define CONFIGURE_OPTION_TCP_LINGER 1
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+#define HAVE_ARPA_INET_H 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the <errno.h> header file. */
+#define HAVE_ERRNO_H 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the <gssapi/gssapi.h> header file. */
+/* #undef HAVE_GSSAPI_GSSAPI_H */
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Whether we use gssapi_krb5 or not */
+/* #undef HAVE_LIBKRB5 */
+
+/* Define to 1 if you have the `nsl' library (-lnsl). */
+/* #undef HAVE_LIBNSL */
+
+/* Define to 1 if you have the `socket' library (-lsocket). */
+/* #undef HAVE_LIBSOCKET */
+
+/* Whether we have linger */
+/* #undef HAVE_LINGER */
+
+/* Define to 1 if you have the <netdb.h> header file. */
+#define HAVE_NETDB_H 1
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#define HAVE_NETINET_IN_H 1
+
+/* Define to 1 if you have the <netinet/tcp.h> header file. */
+#define HAVE_NETINET_TCP_H 1
+
+/* Define to 1 if you have the <poll.h> header file. */
+/* #undef HAVE_POLL_H */
+
+/* Whether sockaddr struct has sa_len */
+#define HAVE_SOCKADDR_LEN 1
+
+/* Whether we have sockaddr_Storage */
+/* #undef HAVE_SOCKADDR_STORAGE */
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#define HAVE_STDIO_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/errno.h> header file. */
+#define HAVE_SYS_ERRNO_H 1
+
+/* Define to 1 if you have the <sys/fcntl.h> header file. */
+#define HAVE_SYS_FCNTL_H 1
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#define HAVE_SYS_IOCTL_H 1
+
+/* Define to 1 if you have the <sys/poll.h> header file. */
+/* #undef HAVE_SYS_POLL_H */
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#define HAVE_SYS_SOCKET_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/uio.h> header file. */
+#define HAVE_SYS_UIO_H 1
+
+/* Define to 1 if you have the <sys/unistd.h> header file. */
+#define HAVE_SYS_UNISTD_H 1
+
+/* Define to 1 if you have the <sys/_iovec.h> header file. */
+/* #undef HAVE_SYS__IOVEC_H */
+
+/* Define to 1 if you have the <time.h> header file. */
+#define HAVE_TIME_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to the sub-directory where libtool stores uninstalled libraries. */
+#define LT_OBJDIR ".libs/"
+
+/* Name of package */
+#define PACKAGE "libsmb2"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "ronniesahlberg@gmail.com"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libsmb2"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libsmb2 4.0.0"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libsmb2"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "4.0.0"
+
+/* Define to 1 if all of the C90 standard headers exist (not just the ones
+   required in a freestanding environment). This macro is provided for
+   backward compatibility; new code need not use it. */
+#define STDC_HEADERS 1
+
+/* Version number of package */
+#define VERSION "4.0.0"

+ 139 - 0
entry/src/main/cpp/include/apple/config.h

@@ -0,0 +1,139 @@
+/* config.h.  Generated from config.h.in by configure.  */
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Whether or not TCP sockets should be allowed to linger after closure */
+#define CONFIGURE_OPTION_TCP_LINGER 1
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+#define HAVE_ARPA_INET_H 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the <errno.h> header file. */
+#define HAVE_ERRNO_H 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the <gssapi/gssapi.h> header file. */
+#define HAVE_GSSAPI_GSSAPI_H 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Whether we use gssapi_krb5 or not */
+/* #undef HAVE_LIBKRB5 */
+
+/* Define to 1 if you have the `nsl' library (-lnsl). */
+/* #undef HAVE_LIBNSL */
+
+/* Define to 1 if you have the `socket' library (-lsocket). */
+/* #undef HAVE_LIBSOCKET */
+
+/* Whether we have linger */
+#define HAVE_LINGER 1
+
+/* Define to 1 if you have the <netdb.h> header file. */
+#define HAVE_NETDB_H 1
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#define HAVE_NETINET_IN_H 1
+
+/* Define to 1 if you have the <netinet/tcp.h> header file. */
+#define HAVE_NETINET_TCP_H 1
+
+/* Define to 1 if you have the <poll.h> header file. */
+#define HAVE_POLL_H 1
+
+/* Whether sockaddr struct has sa_len */
+#define HAVE_SOCKADDR_LEN 1
+
+/* Whether we have sockaddr_Storage */
+#define HAVE_SOCKADDR_STORAGE 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#define HAVE_STDIO_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/errno.h> header file. */
+#define HAVE_SYS_ERRNO_H 1
+
+/* Define to 1 if you have the <sys/fcntl.h> header file. */
+#define HAVE_SYS_FCNTL_H 1
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#define HAVE_SYS_IOCTL_H 1
+
+/* Define to 1 if you have the <sys/poll.h> header file. */
+#define HAVE_SYS_POLL_H 1
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#define HAVE_SYS_SOCKET_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/uio.h> header file. */
+#define HAVE_SYS_UIO_H 1
+
+/* Define to 1 if you have the <sys/unistd.h> header file. */
+#define HAVE_SYS_UNISTD_H 1
+
+/* Define to 1 if you have the <sys/_iovec.h> header file. */
+/* #undef HAVE_SYS__IOVEC_H */
+
+/* Define to 1 if you have the <time.h> header file. */
+#define HAVE_TIME_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to the sub-directory where libtool stores uninstalled libraries. */
+#define LT_OBJDIR ".libs/"
+
+/* Name of package */
+#define PACKAGE "libsmb2"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "ronniesahlberg@gmail.com"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libsmb2"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libsmb2 4.0.0"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libsmb2"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "4.0.0"
+
+/* Define to 1 if all of the C90 standard headers exist (not just the ones
+   required in a freestanding environment). This macro is provided for
+   backward compatibility; new code need not use it. */
+#define STDC_HEADERS 1
+
+/* Version number of package */
+#define VERSION "4.0.0"

+ 65 - 0
entry/src/main/cpp/include/asprintf.h

@@ -0,0 +1,65 @@
+
+#ifndef _ASPRINTF_H_
+#define _ASPRINTF_H_
+
+#if !defined(__AROS__) && !defined(__ps2sdk_iop__)
+#include <malloc.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#ifdef _XBOX
+#define inline __inline
+#endif
+
+#ifndef _XBOX
+#ifndef _vscprintf
+/* For some reason, MSVC fails to honour this #ifndef. */
+/* Hence function renamed to _vscprintf_so(). */
+static inline int _vscprintf_so(const char * format, va_list pargs) {
+  int retval;
+  va_list argcopy;
+  va_copy(argcopy, pargs);
+  retval = vsnprintf(NULL, 0, format, argcopy);
+  va_end(argcopy);
+  return retval;
+}
+#endif /* _vscprintf */
+#endif
+
+#ifndef vasprintf
+static inline int vasprintf(char **strp, const char *fmt, va_list ap) {
+#ifdef _XBOX
+  int len = _vscprintf(fmt, ap);
+#else
+  int len = _vscprintf_so(fmt, ap);
+#endif
+  char *str;
+  int r;
+  if (len == -1) return -1;
+  str = malloc((size_t)len + 1);
+  if (!str) return -1;
+#ifdef _XBOX
+  r = _vsnprintf(str, len + 1, fmt, ap); /* "secure" version of vsprintf */
+#else
+  r = vsnprintf(str, len + 1, fmt, ap); /* "secure" version of vsprintf */
+#endif
+  if (r == -1) return free(str), -1;
+  *strp = str;
+  return r;
+}
+#endif /* vasprintf */
+
+#ifndef asprintf
+static inline int asprintf(char *strp[], const char *fmt, ...) {
+  int r;
+  va_list ap;
+  va_start(ap, fmt);
+  r = vasprintf(strp, fmt, ap);
+  va_end(ap);
+  return r;
+}
+#endif /* asprintf */
+
+#endif /* ! _ASPRINTF_H_ */

+ 139 - 0
entry/src/main/cpp/include/esp/config.h

@@ -0,0 +1,139 @@
+/* config.h.  Generated from config.h.in by configure.  */
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Whether or not TCP sockets should be allowed to linger after closure */
+#define CONFIGURE_OPTION_TCP_LINGER 1
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+#define HAVE_ARPA_INET_H 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the <errno.h> header file. */
+#define HAVE_ERRNO_H 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the <gssapi/gssapi.h> header file. */
+/* #undef HAVE_GSSAPI_GSSAPI_H */
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Whether we use gssapi_krb5 or not */
+/* #undef HAVE_LIBKRB5 */
+
+/* Define to 1 if you have the `nsl' library (-lnsl). */
+/* #undef HAVE_LIBNSL */
+
+/* Define to 1 if you have the `socket' library (-lsocket). */
+/* #undef HAVE_LIBSOCKET */
+
+/* Whether we have linger */
+#define HAVE_LINGER 1
+
+/* Define to 1 if you have the <netdb.h> header file. */
+#define HAVE_NETDB_H 1
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#define HAVE_NETINET_IN_H 1
+
+/* Define to 1 if you have the <netinet/tcp.h> header file. */
+/* #undef HAVE_NETINET_TCP_H */
+
+/* Define to 1 if you have the <poll.h> header file. */
+/* #undef HAVE_POLL_H */
+
+/* Whether sockaddr struct has sa_len */
+/* #undef HAVE_SOCKADDR_LEN */
+
+/* Whether we have sockaddr_Storage */
+#define HAVE_SOCKADDR_STORAGE 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#define HAVE_STDIO_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/errno.h> header file. */
+/* #undef HAVE_SYS_ERRNO_H */
+
+/* Define to 1 if you have the <sys/fcntl.h> header file. */
+/* #undef HAVE_SYS_FCNTL_H */
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#define HAVE_SYS_IOCTL_H 1
+
+/* Define to 1 if you have the <sys/poll.h> header file. */
+#define HAVE_SYS_POLL_H 1
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#define HAVE_SYS_SOCKET_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+/* #undef HAVE_SYS_TIME_H */
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/uio.h> header file. */
+#define HAVE_SYS_UIO_H 1
+
+/* Define to 1 if you have the <sys/unistd.h> header file. */
+/* #undef HAVE_SYS_UNISTD_H */
+
+/* Define to 1 if you have the <sys/_iovec.h> header file. */
+/* #undef HAVE_SYS__IOVEC_H */
+
+/* Define to 1 if you have the <time.h> header file. */
+#define HAVE_TIME_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to the sub-directory where libtool stores uninstalled libraries. */
+#define LT_OBJDIR ".libs/"
+
+/* Name of package */
+#define PACKAGE "libsmb2"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "ronniesahlberg@gmail.com"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libsmb2"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libsmb2 4.0.0"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libsmb2"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "4.0.0"
+
+/* Define to 1 if all of the C90 standard headers exist (not just the ones
+   required in a freestanding environment). This macro is provided for
+   backward compatibility; new code need not use it. */
+#define STDC_HEADERS 1
+
+/* Version number of package */
+#define VERSION "4.0.0"

+ 668 - 0
entry/src/main/cpp/include/libsmb2-private.h

@@ -0,0 +1,668 @@
+/* -*-  mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil;  -*- */
+/*
+   Copyright (C) 2016 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _LIBSMB2_PRIVATE_H_
+#define _LIBSMB2_PRIVATE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef HAVE_LIBKRB5
+#include <krb5/krb5.h>
+
+#if __APPLE__
+#import <GSS/GSS.h>
+#else
+#include <gssapi/gssapi.h>
+#include <gssapi/gssapi_ext.h>
+#endif /* __APPLE__ */
+#endif /* HAVE_LIBKRB5 */
+
+#define MIN(a,b) (((a)<(b))?(a):(b))
+
+#ifndef discard_const
+#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
+#endif
+
+#define MAX_ERROR_SIZE 256
+
+#define PAD_TO_32BIT(len) ((len + 0x03) & 0xfffffffc)
+#define PAD_TO_64BIT(len) ((len + 0x07) & 0xfffffff8)
+
+#define SMB2_SPL_SIZE 4
+#define SMB2_HEADER_SIZE 64
+
+#define SMB2_SIGNATURE_SIZE 16
+#define SMB2_KEY_SIZE 16
+
+#define SMB2_MAX_VECTORS 256
+
+struct smb2_io_vectors {
+        size_t num_done;
+        size_t total_size;
+        int niov;
+        struct smb2_iovec iov[SMB2_MAX_VECTORS];
+};
+
+struct smb2_async {
+        uint64_t async_id;
+};
+
+struct smb2_sync {
+        uint32_t process_id;
+        uint32_t tree_id;
+};
+
+struct smb2_header {
+        uint8_t protocol_id[4];
+        uint16_t struct_size;
+        uint16_t credit_charge;
+        uint32_t status;
+        uint16_t command;
+        uint16_t credit_request_response;
+        uint32_t flags;
+        uint32_t next_command;
+        uint64_t message_id;
+        union {
+                struct smb2_async async;
+                struct smb2_sync sync;
+        };
+        uint64_t session_id;
+        uint8_t signature[16];
+};
+
+/* States that we transition when we read data back from the server for
+ * normal SMB2/3 :
+ * 1: SMB2_RECV_SPL        SPL
+ * 2: SMB2_RECV_HEADER     SMB2 Header
+ * 3: SMB2_RECV_FIXED      The fixed part of the payload.
+ * 4: SMB2_RECV_VARIABLE   Optional variable part of the payload.
+ * 5: SMB2_RECV_PAD        Optional padding
+ *
+ * 2-5 will be repeated for compound commands.
+ * 4-5 are optional and may or may not be present depending on the
+ *     type of command.
+ *
+ * States for SMB3 encryption:
+ * 1: SMB2_RECV_SPL        SPL
+ * 2: SMB2_RECV_HEADER     SMB3 Transform Header
+ * 3: SMB2_RECV_TRFM       encrypted payload
+ *
+ * States for cancelled PDUs
+ * This is used when we receive a reply for a PDU not in our waitlist.
+ * This can for example happen if we have cancelled a pdu when it was
+ * in-flight.
+ * 1: SMB2_RECV_SPL        SPL
+ * 2: SMB2_RECV_HEADER     SMB3 Transform Header
+ * 3: SMB2_RECV_UNKNOWN    data for a PDU we are not waiting for
+ */
+enum smb2_recv_state {
+        SMB2_RECV_SPL = 0,
+        SMB2_RECV_HEADER,
+        SMB2_RECV_FIXED,
+        SMB2_RECV_VARIABLE,
+        SMB2_RECV_PAD,
+        SMB2_RECV_TRFM,
+        SMB2_RECV_UNKNOWN,
+};
+
+/* current tree id stack, note: index 0 in the stack is not used
+*/
+#define SMB2_MAX_TREE_NESTING 32
+#define smb2_tree_id(smb2) (((smb2)->tree_id_cur >= 0)?smb2->tree_id[(smb2)->tree_id_cur]:0xdeadbeef)
+
+#define MAX_CREDITS 1024
+#define SMB2_SALT_SIZE 32
+
+struct sync_cb_data {
+	int is_finished;
+	int status;
+	void *ptr;
+};
+
+struct smb2_context {
+
+        t_socket fd;
+
+        struct smb2_server *owning_server;
+
+        t_socket *connecting_fds;
+        size_t connecting_fds_count;
+        struct addrinfo *addrinfos;
+        const struct addrinfo *next_addrinfo;
+
+        int timeout;
+
+        enum smb2_sec sec;
+
+        uint16_t security_mode;
+        uint32_t capabilities;
+        int use_cached_creds;
+
+        enum smb2_negotiate_version version;
+
+        const char *server;
+        const char *share;
+        const char *user;
+
+        /* Only used with --without-libkrb5 */
+        const char *password;
+        const char *domain;
+        const char *workstation;
+        char client_challenge[8];
+
+        void *opaque;
+
+        smb2_error_cb error_cb;
+        smb2_command_cb connect_cb;
+        void *connect_data;
+        struct sync_cb_data connect_cb_data;
+
+        int credits;
+
+        char client_guid[16];
+
+        uint32_t tree_id[SMB2_MAX_TREE_NESTING];
+        int  tree_id_top;
+        int  tree_id_cur;
+        uint64_t message_id;
+        uint64_t session_id;
+        uint64_t async_id;
+        uint8_t *session_key;
+        uint8_t session_key_size;
+
+        uint8_t seal:1;
+        uint8_t sign:1;
+        uint8_t signing_key[SMB2_KEY_SIZE];
+        uint8_t serverin_key[SMB2_KEY_SIZE];
+        uint8_t serverout_key[SMB2_KEY_SIZE];
+        uint8_t salt[SMB2_SALT_SIZE];
+        uint16_t cypher;
+        uint8_t preauthhash[SMB2_PREAUTH_HASH_SIZE];
+
+
+#ifdef HAVE_LIBKRB5
+        /* for delegation of client creds to proxy-client */
+        gss_cred_id_t cred_handle;
+#endif
+        /*
+         * For handling received smb3 encrypted blobs
+         */
+        unsigned char *enc;
+        size_t enc_len;
+        int enc_pos;
+
+        /*
+         * For sending PDUs
+         */
+        struct smb2_pdu *outqueue;
+        struct smb2_pdu *waitqueue;
+
+        /*
+         * For receiving PDUs
+         */
+        struct smb2_io_vectors in;
+        enum smb2_recv_state recv_state;
+        /* SPL for the (compound) command we are currently reading */
+        uint32_t spl;
+        /* buffer to avoid having to malloc the header */
+        uint8_t header[SMB2_HEADER_SIZE];
+        struct smb2_header hdr;
+        /* Offset into smb2->in where the payload for the current PDU starts */
+        size_t payload_offset;
+
+        /* Pointer to the current PDU that we are receiving the reply for.
+         * Only valid once the full smb2 header has been received.
+         */
+        struct smb2_pdu *pdu;
+
+        /* pointer to the pdu to read AFTER the current one is completed
+         * (if this context is a server)
+         */
+        struct smb2_pdu *next_pdu;
+
+        /* flag indicated command packers/unpackers can pass "extra"
+         * content without trying to decode or encode it.  this is
+         * useful for proxies and applies only to the commands with
+         * complex data: query-info, query-directory, ioctl, and
+         * create (contexts).  the command fixed part is always
+         * de/en-coded regardless of this setting
+         */
+        int passthrough;
+
+        /* for oplock/lease breaks, inform the app */
+        smb2_oplock_or_lease_break_cb oplock_or_lease_break_cb;
+
+        /* oplock state, needed to discriminate between notification or response */
+        int oplock_break_count;
+
+        /* last file_id in a create-reply, for "related requests" */
+        smb2_file_id last_file_id;
+
+        /* Server capabilities */
+        uint8_t supports_multi_credit;
+
+        uint32_t max_transact_size;
+        uint32_t max_read_size;
+        uint32_t max_write_size;
+        uint16_t dialect;
+
+        char error_string[MAX_ERROR_SIZE];
+        int nterror;
+
+        /* callbacks for the eventsystem */
+        int events;
+        smb2_change_fd_cb change_fd;
+        smb2_change_events_cb change_events;
+
+        /* dcerpc settings */
+        uint8_t ndr;
+        int endianness;
+
+        /* to maintain lists of contexts for server used */
+        struct smb2_context *next;
+};
+
+/*
+ * Callback for freeing a payload.
+ */
+typedef void (*smb2_free_payload)(struct smb2_context *smb2, void *payload);
+
+
+#define SMB2_MAX_PDU_SIZE 16*1024*1024
+
+struct smb2_pdu {
+        struct smb2_pdu *next;
+        struct smb2_header header;
+
+        struct smb2_pdu *next_compound;
+        uint64_t prev_compound_mid;
+
+        int caller_frees_pdu;
+        smb2_command_cb cb;
+        void *cb_data;
+        void (*free_cb)(void *);
+
+        /* buffer to avoid having to malloc the headers */
+        uint8_t hdr[SMB2_HEADER_SIZE];
+
+        /* pointer to the unmarshalled payload in a reply */
+        void *payload;
+
+        /* callback that frees the any additional memory allocated in the payload.
+         * Or null if no additional memory needs to be freed.
+         */
+        smb2_free_payload free_payload;
+
+        /* For sending/receiving
+         * out contains at least two vectors:
+         * [0]  64 bytes for the smb header
+         * [1+] command and and extra parameters
+         *
+         * in contains at least one vector:
+         * [0+] command and and extra parameters
+         */
+        struct smb2_io_vectors out;
+        struct smb2_io_vectors in;
+
+        /* Data we need to retain between request/reply for QUERY INFO */
+        uint8_t info_type;
+        uint8_t file_info_class;
+
+        /* For encrypted PDUs */
+        uint8_t seal:1;
+        uint32_t crypt_len;
+        unsigned char *crypt;
+        time_t timeout;
+};
+
+struct smb2_dirent_internal {
+        struct smb2_dirent_internal *next;
+        struct smb2dirent dirent;
+};
+
+struct smb2dir {
+        smb2_command_cb cb;
+        void (*free_cb_data)(void *);
+        void *cb_data;
+        smb2_file_id file_id;
+
+        struct smb2_dirent_internal *entries;
+        struct smb2_dirent_internal *current_entry;
+        int index;
+};
+
+
+#define smb2_is_server(ctx) ((ctx)->owning_server != NULL)
+
+void smb2_set_nterror(struct smb2_context *smb2, int nterror,
+                    const char *error_string, ...);
+
+void smb2_close_connecting_fds(struct smb2_context *smb2);
+
+void *smb2_alloc_init(struct smb2_context *smb2, size_t size);
+void *smb2_alloc_data(struct smb2_context *smb2, void *memctx, size_t size);
+
+struct smb2_iovec *smb2_add_iovector(struct smb2_context *smb2,
+                                     struct smb2_io_vectors *v,
+                                     uint8_t *buf, size_t len,
+                                     void (*free)(void *));
+
+int smb2_pad_to_64bit(struct smb2_context *smb2, struct smb2_io_vectors *v);
+
+int smb2_connect_tree_id(struct smb2_context *smb2, uint32_t tree_id);
+int smb2_disconnect_tree_id(struct smb2_context *smb2, uint32_t tree_id);
+
+struct smb2_pdu *smb2_allocate_pdu(struct smb2_context *smb2,
+                                   enum smb2_command command,
+                                   smb2_command_cb cb, void *cb_data);
+int smb2_process_payload_fixed(struct smb2_context *smb2,
+                               struct smb2_pdu *pdu);
+int smb2_process_payload_variable(struct smb2_context *smb2,
+                                  struct smb2_pdu *pdu);
+int smb2_get_fixed_size(struct smb2_context *smb2, struct smb2_pdu *pdu);
+
+struct smb2_pdu *smb2_find_pdu(struct smb2_context *smb2, uint64_t message_id);
+void smb2_free_iovector(struct smb2_context *smb2, struct smb2_io_vectors *v);
+
+void smb2_oplock_break_notify(struct smb2_context *smb2, int status, void *command_data, void *cb_data);
+
+int smb2_decode_header(struct smb2_context *smb2, struct smb2_iovec *iov,
+                       struct smb2_header *hdr);
+int smb2_calc_signature(struct smb2_context *smb2, uint8_t *signature,
+                        struct smb2_iovec *iov, size_t niov);
+
+int smb2_set_uint8(struct smb2_iovec *iov, int offset, uint8_t value);
+int smb2_set_uint16(struct smb2_iovec *iov, int offset, uint16_t value);
+int smb2_set_uint32(struct smb2_iovec *iov, int offset, uint32_t value);
+int smb2_set_uint64(struct smb2_iovec *iov, int offset, uint64_t value);
+
+int smb2_get_uint8(struct smb2_iovec *iov, int offset, uint8_t *value);
+int smb2_get_uint16(struct smb2_iovec *iov, int offset, uint16_t *value);
+int smb2_get_uint32(struct smb2_iovec *iov, int offset, uint32_t *value);
+int smb2_get_uint64(struct smb2_iovec *iov, int offset, uint64_t *value);
+
+int smb2_process_error_fixed(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_error_variable(struct smb2_context *smb2,
+                                struct smb2_pdu *pdu);
+int smb2_process_negotiate_fixed(struct smb2_context *smb2,
+                                 struct smb2_pdu *pdu);
+int smb2_process_negotiate_variable(struct smb2_context *smb2,
+                                    struct smb2_pdu *pdu);
+int smb2_process_negotiate_request_fixed(struct smb2_context *smb2,
+                                     struct smb2_pdu *pdu);
+int smb2_process_negotiate_request_variable(struct smb2_context *smb2,
+                                     struct smb2_pdu *pdu);
+int smb2_process_session_setup_fixed(struct smb2_context *smb2,
+                                     struct smb2_pdu *pdu);
+int smb2_process_session_setup_variable(struct smb2_context *smb2,
+                                        struct smb2_pdu *pdu);
+int smb2_process_session_setup_request_fixed(struct smb2_context *smb2,
+                                        struct smb2_pdu *pdu);
+int smb2_process_session_setup_request_variable(struct smb2_context *smb2,
+                                        struct smb2_pdu *pdu);
+int smb2_process_tree_connect_fixed(struct smb2_context *smb2,
+                                        struct smb2_pdu *pdu);
+int smb2_process_tree_connect_request_fixed(struct smb2_context *smb2,
+                                        struct smb2_pdu *pdu);
+int smb2_process_tree_connect_request_variable(struct smb2_context *smb2,
+                                        struct smb2_pdu *pdu);
+int smb2_process_create_fixed(struct smb2_context *smb2,
+                              struct smb2_pdu *pdu);
+int smb2_process_create_variable(struct smb2_context *smb2,
+                                 struct smb2_pdu *pdu);
+int smb2_process_create_request_fixed(struct smb2_context *smb2,
+                              struct smb2_pdu *pdu);
+int smb2_process_create_request_variable(struct smb2_context *smb2,
+                                 struct smb2_pdu *pdu);
+int smb2_process_query_directory_fixed(struct smb2_context *smb2,
+                                       struct smb2_pdu *pdu);
+int smb2_process_query_directory_variable(struct smb2_context *smb2,
+                                          struct smb2_pdu *pdu);
+int smb2_process_query_directory_request_fixed(struct smb2_context *smb2,
+                                       struct smb2_pdu *pdu);
+int smb2_process_query_directory_request_variable(struct smb2_context *smb2,
+                                          struct smb2_pdu *pdu);
+int smb2_process_change_notify_fixed(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_change_notify_variable(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_change_notify_request_fixed(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_query_info_fixed(struct smb2_context *smb2,
+                                  struct smb2_pdu *pdu);
+int smb2_process_query_info_variable(struct smb2_context *smb2,
+                                     struct smb2_pdu *pdu);
+int smb2_process_query_info_request_fixed(struct smb2_context *smb2,
+                                  struct smb2_pdu *pdu);
+int smb2_process_query_info_request_variable(struct smb2_context *smb2,
+                                     struct smb2_pdu *pdu);
+int smb2_process_close_fixed(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_close_request_fixed(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_set_info_fixed(struct smb2_context *smb2,
+                                struct smb2_pdu *pdu);
+int smb2_process_set_info_request_fixed(struct smb2_context *smb2,
+                                struct smb2_pdu *pdu);
+int smb2_process_set_info_request_variable(struct smb2_context *smb2,
+                                struct smb2_pdu *pdu);
+int smb2_process_tree_disconnect_fixed(struct smb2_context *smb2,
+                                       struct smb2_pdu *pdu);
+int smb2_process_tree_disconnect_request_fixed(struct smb2_context *smb2,
+                                       struct smb2_pdu *pdu);
+int smb2_process_logoff_fixed(struct smb2_context *smb2,
+                              struct smb2_pdu *pdu);
+int smb2_process_logoff_request_fixed(struct smb2_context *smb2,
+                              struct smb2_pdu *pdu);
+int smb2_process_lock_fixed(struct smb2_context *smb2,
+                            struct smb2_pdu *pdu);
+int smb2_process_lock_request_fixed(struct smb2_context *smb2,
+                            struct smb2_pdu *pdu);
+int smb2_process_lock_request_variable(struct smb2_context *smb2,
+                            struct smb2_pdu *pdu);
+int smb2_process_oplock_break_fixed(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_oplock_break_variable(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_oplock_break_request_fixed(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_oplock_break_request_variable(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_echo_fixed(struct smb2_context *smb2,
+                            struct smb2_pdu *pdu);
+int smb2_process_echo_request_fixed(struct smb2_context *smb2,
+                            struct smb2_pdu *pdu);
+int smb2_process_flush_fixed(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_flush_request_fixed(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_read_fixed(struct smb2_context *smb2,
+                            struct smb2_pdu *pdu);
+int smb2_process_read_variable(struct smb2_context *smb2,
+                            struct smb2_pdu *pdu);
+int smb2_process_read_request_fixed(struct smb2_context *smb2,
+                            struct smb2_pdu *pdu);
+int smb2_process_read_request_variable(struct smb2_context *smb2,
+                            struct smb2_pdu *pdu);
+int smb2_process_write_fixed(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_write_request_fixed(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_write_request_variable(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_ioctl_fixed(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_ioctl_variable(struct smb2_context *smb2,
+                                struct smb2_pdu *pdu);
+int smb2_process_ioctl_request_fixed(struct smb2_context *smb2,
+                             struct smb2_pdu *pdu);
+int smb2_process_ioctl_request_variable(struct smb2_context *smb2,
+                                struct smb2_pdu *pdu);
+
+int smb2_decode_file_basic_info(struct smb2_context *smb2,
+                                void *memctx,
+                                struct smb2_file_basic_info *fs,
+                                struct smb2_iovec *vec);
+int smb2_encode_file_basic_info(struct smb2_context *smb2,
+                                struct smb2_file_basic_info *fs,
+                                struct smb2_iovec *vec);
+
+int smb2_decode_file_standard_info(struct smb2_context *smb2,
+                                   void *memctx,
+                                   struct smb2_file_standard_info *fs,
+                                   struct smb2_iovec *vec);
+
+int smb2_encode_file_standard_info(struct smb2_context *smb2,
+                                   struct smb2_file_standard_info *fs,
+                                   struct smb2_iovec *vec);
+
+int smb2_decode_file_stream_info(struct smb2_context *smb2,
+                                   void *memctx,
+                                   struct smb2_file_stream_info *fs,
+                                   struct smb2_iovec *vec);
+
+int smb2_encode_file_stream_info(struct smb2_context *smb2,
+                                   struct smb2_file_stream_info *fs,
+                                   struct smb2_iovec *vec);
+
+int smb2_decode_file_position_info(struct smb2_context *smb2,
+                                   void *memctx,
+                                   struct smb2_file_position_info *fs,
+                                   struct smb2_iovec *vec);
+
+int smb2_encode_file_position_info(struct smb2_context *smb2,
+                                   struct smb2_file_position_info *fs,
+                                   struct smb2_iovec *vec);
+
+int smb2_decode_file_all_info(struct smb2_context *smb2,
+                              void *memctx,
+                              struct smb2_file_all_info *fs,
+                              struct smb2_iovec *vec);
+
+int smb2_encode_file_all_info(struct smb2_context *smb2,
+                              struct smb2_file_all_info *fs,
+                              struct smb2_iovec *vec);
+
+int smb2_decode_file_network_open_info(struct smb2_context *smb2,
+                                       void *memctx,
+                                       struct smb2_file_network_open_info *fs,
+                                       struct smb2_iovec *vec);
+
+int smb2_encode_file_network_open_info(struct smb2_context *smb2,
+                                       struct smb2_file_network_open_info *fs,
+                                       struct smb2_iovec *vec);
+
+int smb2_decode_file_normalized_name_info(struct smb2_context *smb2,
+                                          void *memctx,
+                                          struct smb2_file_name_info *fs,
+                                          struct smb2_iovec *vec);
+int smb2_encode_file_normalized_name_info(struct smb2_context *smb2,
+                                          struct smb2_file_name_info *fs,
+                                          struct smb2_iovec *vec);
+int smb2_decode_security_descriptor(struct smb2_context *smb2,
+                                    void *memctx,
+                                    struct smb2_security_descriptor *sd,
+                                    struct smb2_iovec *vec);
+
+int smb2_decode_file_fs_volume_info(struct smb2_context *smb2,
+                                    void *memctx,
+                                    struct smb2_file_fs_volume_info *fs,
+                                    struct smb2_iovec *vec);
+int smb2_encode_file_fs_volume_info(struct smb2_context *smb2,
+                                    struct smb2_file_fs_volume_info *fs,
+                                    struct smb2_iovec *vec);
+int smb2_decode_file_fs_size_info(struct smb2_context *smb2,
+                                  void *memctx,
+                                  struct smb2_file_fs_size_info *fs,
+                                  struct smb2_iovec *vec);
+int smb2_encode_file_fs_size_info(struct smb2_context *smb2,
+                                  struct smb2_file_fs_size_info *fs,
+                                  struct smb2_iovec *vec);
+int smb2_decode_file_fs_device_info(struct smb2_context *smb2,
+                                    void *memctx,
+                                    struct smb2_file_fs_device_info *fs,
+                                    struct smb2_iovec *vec);
+int smb2_encode_file_fs_device_info(struct smb2_context *smb2,
+                                    struct smb2_file_fs_device_info *fs,
+                                    struct smb2_iovec *vec);
+int smb2_decode_file_fs_attribute_info(struct smb2_context *smb2,
+                                  void *memctx,
+                                  struct smb2_file_fs_attribute_info *fs,
+                                  struct smb2_iovec *vec);
+int smb2_encode_file_fs_attribute_info(struct smb2_context *smb2,
+                                  struct smb2_file_fs_attribute_info *fs,
+                                  struct smb2_iovec *vec);
+int smb2_decode_file_fs_control_info(struct smb2_context *smb2,
+                                     void *memctx,
+                                     struct smb2_file_fs_control_info *fs,
+                                     struct smb2_iovec *vec);
+int smb2_encode_file_fs_control_info(struct smb2_context *smb2,
+                                     struct smb2_file_fs_control_info *fs,
+                                     struct smb2_iovec *vec);
+int smb2_decode_file_fs_full_size_info(struct smb2_context *smb2,
+                                       void *memctx,
+                                       struct smb2_file_fs_full_size_info *fs,
+                                       struct smb2_iovec *vec);
+int smb2_encode_file_fs_full_size_info(struct smb2_context *smb2,
+                                       struct smb2_file_fs_full_size_info *fs,
+                                       struct smb2_iovec *vec);
+int smb2_decode_file_fs_object_id_info(struct smb2_context *smb2,
+                                     void *memctx,
+                                     struct smb2_file_fs_object_id_info *fs,
+                                     struct smb2_iovec *vec);
+int smb2_encode_file_fs_object_id_info(struct smb2_context *smb2,
+                                     struct smb2_file_fs_object_id_info *fs,
+                                     struct smb2_iovec *vec);
+int smb2_decode_file_fs_sector_size_info(struct smb2_context *smb2,
+                                     void *memctx,
+                                     struct smb2_file_fs_sector_size_info *fs,
+                                     struct smb2_iovec *vec);
+int smb2_encode_file_fs_sector_size_info(struct smb2_context *smb2,
+                                     struct smb2_file_fs_sector_size_info *fs,
+                                     struct smb2_iovec *vec);
+int smb2_decode_reparse_data_buffer(struct smb2_context *smb2,
+                                    void *memctx,
+                                    struct smb2_reparse_data_buffer *rp,
+                                    struct smb2_iovec *vec);
+
+int smb2_read_from_buf(struct smb2_context *smb2);
+void smb2_change_events(struct smb2_context *smb2, t_socket fd, int events);
+void smb2_timeout_pdus(struct smb2_context *smb2);
+
+struct dcerpc_context;
+int dcerpc_set_uint8(struct dcerpc_context *ctx, struct smb2_iovec *iov,
+                     int *offset, uint8_t value);
+
+struct dcerpc_pdu;
+int dcerpc_pdu_direction(struct dcerpc_pdu *pdu);
+
+int dcerpc_align_3264(struct dcerpc_context *ctx, int offset);
+
+struct connect_data;                                           /* defined in libsmb2.c */
+void free_c_data(struct smb2_context*, struct connect_data*);  /* defined in libsmb2.c */
+
+int smb2_write_to_socket(struct smb2_context *smb2);
+        
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_LIBSMB2_PRIVATE_H_ */

+ 21 - 0
entry/src/main/cpp/include/module.modulemap

@@ -0,0 +1,21 @@
+module SMB2 [system] [extern_c] {
+    module LibSMB2 {
+        header "apple/config.h"
+        header "smb2/smb2-errors.h"
+        header "smb2/smb2.h"
+        header "smb2/libsmb2.h"
+		header "smb2/libsmb2-dcerpc.h"
+		header "smb2/libsmb2-dcerpc-lsa.h"
+        header "smb2/libsmb2-dcerpc-srvsvc.h"
+    }
+    
+    module Internal {
+        header "libsmb2-private.h"
+    }
+    
+    explicit module Raw {
+        header "smb2/libsmb2-raw.h"
+    }
+    
+    export SMB2
+}

+ 143 - 0
entry/src/main/cpp/include/picow/FreeRTOSConfig.h

@@ -0,0 +1,143 @@
+/*
+ * FreeRTOS V202111.00
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://www.FreeRTOS.org
+ * http://aws.amazon.com/freertos
+ *
+ * 1 tab == 4 spaces!
+ */
+
+#ifndef FREERTOS_CONFIG_H
+#define FREERTOS_CONFIG_H
+
+/*-----------------------------------------------------------
+ * Application specific definitions.
+ *
+ * These definitions should be adjusted for your particular hardware and
+ * application requirements.
+ *
+ * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
+ * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
+ *
+ * See http://www.freertos.org/a00110.html
+ *----------------------------------------------------------*/
+
+/* Scheduler Related */
+#define configUSE_PREEMPTION                    1
+#define configUSE_TICKLESS_IDLE                 0
+#define configUSE_IDLE_HOOK                     0
+#define configUSE_TICK_HOOK                     0
+#define configTICK_RATE_HZ                      ( ( TickType_t ) 1000 )
+#define configMAX_PRIORITIES                    32
+#define configMINIMAL_STACK_SIZE                ( configSTACK_DEPTH_TYPE ) 2048
+#define configUSE_16_BIT_TICKS                  0
+
+#define configIDLE_SHOULD_YIELD                 1
+
+/* Synchronization Related */
+#define configUSE_MUTEXES                       1
+#define configUSE_RECURSIVE_MUTEXES             1
+#define configUSE_APPLICATION_TASK_TAG          0
+#define configUSE_COUNTING_SEMAPHORES           1
+#define configQUEUE_REGISTRY_SIZE               8
+#define configUSE_QUEUE_SETS                    1
+#define configUSE_TIME_SLICING                  1
+#define configUSE_NEWLIB_REENTRANT              0
+// todo need this for lwip FreeRTOS sys_arch to compile
+#define configENABLE_BACKWARD_COMPATIBILITY     1
+#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
+
+/* System */
+#define configSTACK_DEPTH_TYPE                  uint32_t
+#define configMESSAGE_BUFFER_LENGTH_TYPE        size_t
+
+/* Memory allocation related definitions. */
+#define configSUPPORT_STATIC_ALLOCATION         0
+#define configSUPPORT_DYNAMIC_ALLOCATION        1
+#define configTOTAL_HEAP_SIZE                   (128*1024)
+#define configAPPLICATION_ALLOCATED_HEAP        0
+
+/* Hook function related definitions. */
+#define configCHECK_FOR_STACK_OVERFLOW          0
+#define configUSE_MALLOC_FAILED_HOOK            0
+#define configUSE_DAEMON_TASK_STARTUP_HOOK      0
+
+/* Run time and task stats gathering related definitions. */
+#define configGENERATE_RUN_TIME_STATS           0
+#define configUSE_TRACE_FACILITY                1
+#define configUSE_STATS_FORMATTING_FUNCTIONS    0
+
+/* Co-routine related definitions. */
+#define configUSE_CO_ROUTINES                   0
+#define configMAX_CO_ROUTINE_PRIORITIES         1
+
+/* Software timer related definitions. */
+#define configUSE_TIMERS                        1
+#define configTIMER_TASK_PRIORITY               ( configMAX_PRIORITIES - 1 )
+#define configTIMER_QUEUE_LENGTH                10
+#define configTIMER_TASK_STACK_DEPTH            1024
+
+/* Interrupt nesting behaviour configuration. */
+/*
+#define configKERNEL_INTERRUPT_PRIORITY         [dependent of processor]
+#define configMAX_SYSCALL_INTERRUPT_PRIORITY    [dependent on processor and application]
+#define configMAX_API_CALL_INTERRUPT_PRIORITY   [dependent on processor and application]
+*/
+
+#if FREE_RTOS_KERNEL_SMP // set by the RP2040 SMP port of FreeRTOS
+/* SMP port only */
+#define configNUM_CORES                         2
+#define configTICK_CORE                         0
+#define configRUN_MULTIPLE_PRIORITIES           1
+#define configUSE_CORE_AFFINITY                 1
+#endif
+
+/* RP2040 specific */
+#define configSUPPORT_PICO_SYNC_INTEROP         1
+#define configSUPPORT_PICO_TIME_INTEROP         1
+
+#include <assert.h>
+/* Define to trap errors during development. */
+#define configASSERT(x)                         assert(x)
+
+/* Set the following definitions to 1 to include the API function, or zero
+to exclude the API function. */
+#define INCLUDE_vTaskPrioritySet                1
+#define INCLUDE_uxTaskPriorityGet               1
+#define INCLUDE_vTaskDelete                     1
+#define INCLUDE_vTaskSuspend                    1
+#define INCLUDE_vTaskDelayUntil                 1
+#define INCLUDE_vTaskDelay                      1
+#define INCLUDE_xTaskGetSchedulerState          1
+#define INCLUDE_xTaskGetCurrentTaskHandle       1
+#define INCLUDE_uxTaskGetStackHighWaterMark     1
+#define INCLUDE_xTaskGetIdleTaskHandle          1
+#define INCLUDE_eTaskGetState                   1
+#define INCLUDE_xTimerPendFunctionCall          1
+#define INCLUDE_xTaskAbortDelay                 1
+#define INCLUDE_xTaskGetHandle                  1
+#define INCLUDE_xTaskResumeFromISR              1
+#define INCLUDE_xQueueGetMutexHolder            1
+
+/* A header file that defines trace macro can be included here. */
+
+#endif /* FREERTOS_CONFIG_H */
+

+ 2 - 0
entry/src/main/cpp/include/picow/README.md

@@ -0,0 +1,2 @@
+# Pico W config files
+These files should be seen as samples and you can start with these or use your own.  They are here so that the examples/picow sample will compile and build.  These have not been tuned in any way, other than to let libsmb2 compile with the Pico W, FreeRTOS and lwip.

+ 139 - 0
entry/src/main/cpp/include/picow/config.h

@@ -0,0 +1,139 @@
+/* config.h.  Generated from config.h.in by configure.  */
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Whether or not TCP sockets should be allowed to linger after closure */
+#define CONFIGURE_OPTION_TCP_LINGER 1
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+/* #undef HAVE_ARPA_INET_H */
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the <errno.h> header file. */
+/* #undef HAVE_ERRNO_H */
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the <gssapi/gssapi.h> header file. */
+/* #undef HAVE_GSSAPI_GSSAPI_H */
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+/* #undef HAVE_INTTYPES_H */
+
+/* Whether we use gssapi_krb5 or not */
+/* #undef HAVE_LIBKRB5 */
+
+/* Define to 1 if you have the `nsl' library (-lnsl). */
+/* #undef HAVE_LIBNSL */
+
+/* Define to 1 if you have the `socket' library (-lsocket). */
+/* #undef HAVE_LIBSOCKET */
+
+/* Whether we have linger */
+/* #undef HAVE_LINGER */
+
+/* Define to 1 if you have the <netdb.h> header file. */
+/* #undef HAVE_NETDB_H */
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+/* #undef HAVE_NETINET_IN_H */
+
+/* Define to 1 if you have the <netinet/tcp.h> header file. */
+/* #undef HAVE_NETINET_TCP_H */
+
+/* Define to 1 if you have the <poll.h> header file. */
+/* #undef HAVE_POLL_H */
+
+/* Whether sockaddr struct has sa_len */
+/* #undef HAVE_SOCKADDR_LEN */
+
+/* Whether we have sockaddr_Storage */
+#define HAVE_SOCKADDR_STORAGE 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#define HAVE_STDIO_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+/* #undef HAVE_STRINGS_H */
+
+/* Define to 1 if you have the <string.h> header file. */
+/* #undef HAVE_STRING_H */
+
+/* Define to 1 if you have the <sys/errno.h> header file. */
+/* #undef HAVE_SYS_ERRNO_H */
+
+/* Define to 1 if you have the <sys/fcntl.h> header file. */
+/* #undef HAVE_SYS_FCNTL_H */
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+/* #undef HAVE_SYS_IOCTL_H */
+
+/* Define to 1 if you have the <sys/poll.h> header file. */
+/* #undef HAVE_SYS_POLL_H */
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+/* #undef HAVE_SYS_SOCKET_H */
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+/* #undef HAVE_SYS_TIME_H */
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/uio.h> header file. */
+/* #undef HAVE_SYS_UIO_H */
+
+/* Define to 1 if you have the <sys/unistd.h> header file. */
+/* #undef HAVE_SYS_UNISTD_H */
+
+/* Define to 1 if you have the <sys/_iovec.h> header file. */
+/* #undef HAVE_SYS__IOVEC_H */
+
+/* Define to 1 if you have the <time.h> header file. */
+#define HAVE_TIME_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to the sub-directory where libtool stores uninstalled libraries. */
+#define LT_OBJDIR ".libs/"
+
+/* Name of package */
+#define PACKAGE "libsmb2"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "ronniesahlberg@gmail.com"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libsmb2"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libsmb2 4.0.0"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libsmb2"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "4.0.0"
+
+/* Define to 1 if all of the C90 standard headers exist (not just the ones
+   required in a freestanding environment). This macro is provided for
+   backward compatibility; new code need not use it. */
+#define STDC_HEADERS 1
+
+/* Version number of package */
+#define VERSION "4.0.0"

+ 27 - 0
entry/src/main/cpp/include/picow/lwipopts.h

@@ -0,0 +1,27 @@
+#ifndef _LWIPOPTS_H
+#define _LWIPOPTS_H
+
+// Generally you would define your own explicit list of lwIP options
+// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html)
+//
+// This example uses a common include to avoid repetition
+#include "lwipopts_examples_common.h"
+
+#define LWIP_SO_RCVBUF 1
+#define LWIP_TIMEVAL_PRIVATE 0
+#if !NO_SYS
+#define TCPIP_THREAD_STACKSIZE 1024
+#define DEFAULT_THREAD_STACKSIZE 1024
+#define DEFAULT_RAW_RECVMBOX_SIZE 8
+#define TCPIP_MBOX_SIZE 8
+//#define LWIP_TIMEVAL_PRIVATE 0
+
+#define DEFAULT_UDP_RECVMBOX_SIZE TCPIP_MBOX_SIZE
+#define DEFAULT_TCP_RECVMBOX_SIZE TCPIP_MBOX_SIZE
+#define DEFAULT_ACCEPTMBOX_SIZE TCPIP_MBOX_SIZE
+
+// not necessary, can be done either way
+#define LWIP_TCPIP_CORE_LOCKING_INPUT 1
+#endif
+
+#endif

+ 90 - 0
entry/src/main/cpp/include/picow/lwipopts_examples_common.h

@@ -0,0 +1,90 @@
+#ifndef _LWIPOPTS_EXAMPLE_COMMONH_H
+#define _LWIPOPTS_EXAMPLE_COMMONH_H
+
+
+// Common settings used in most of the pico_w examples
+// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details)
+
+// allow override in some examples
+#ifndef NO_SYS
+#define NO_SYS                      1
+#endif
+// allow override in some examples
+#ifndef LWIP_SOCKET
+#define LWIP_SOCKET                 1
+#endif
+#if PICO_CYW43_ARCH_POLL
+#define MEM_LIBC_MALLOC             1
+#else
+// MEM_LIBC_MALLOC is incompatible with non polling versions
+#define MEM_LIBC_MALLOC             0
+#endif
+#define MEM_ALIGNMENT               4
+#define MEM_SIZE                    4000
+#define MEMP_NUM_TCP_SEG            32
+#define MEMP_NUM_ARP_QUEUE          10
+#define PBUF_POOL_SIZE              24
+#define LWIP_ARP                    1
+#define LWIP_ETHERNET               1
+#define LWIP_ICMP                   1
+#define LWIP_RAW                    1
+#define TCP_WND                     (8 * TCP_MSS)
+#define TCP_MSS                     1460
+#define TCP_SND_BUF                 (8 * TCP_MSS)
+#define TCP_SND_QUEUELEN            ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
+#define LWIP_NETIF_STATUS_CALLBACK  1
+#define LWIP_NETIF_LINK_CALLBACK    1
+#define LWIP_NETIF_HOSTNAME         1
+#define LWIP_NETCONN                0
+#define MEM_STATS                   0
+#define SYS_STATS                   0
+#define MEMP_STATS                  0
+#define LINK_STATS                  0
+// #define ETH_PAD_SIZE                2
+#define LWIP_CHKSUM_ALGORITHM       3
+#define LWIP_DHCP                   1
+#define LWIP_IPV4                   1
+#define LWIP_TCP                    1
+#define LWIP_UDP                    1
+#define LWIP_DNS                    1
+#define LWIP_TCP_KEEPALIVE          1
+#define LWIP_NETIF_TX_SINGLE_PBUF   1
+#define DHCP_DOES_ARP_CHECK         0
+#define LWIP_DHCP_DOES_ACD_CHECK    0
+
+#ifndef NDEBUG
+#define LWIP_DEBUG                  1
+#define LWIP_STATS                  1
+#define LWIP_STATS_DISPLAY          1
+#endif
+
+#define ETHARP_DEBUG                LWIP_DBG_OFF
+#define NETIF_DEBUG                 LWIP_DBG_OFF
+#define PBUF_DEBUG                  LWIP_DBG_OFF
+#define API_LIB_DEBUG               LWIP_DBG_OFF
+#define API_MSG_DEBUG               LWIP_DBG_OFF
+#define SOCKETS_DEBUG               LWIP_DBG_OFF
+#define ICMP_DEBUG                  LWIP_DBG_OFF
+#define INET_DEBUG                  LWIP_DBG_OFF
+#define IP_DEBUG                    LWIP_DBG_OFF
+#define IP_REASS_DEBUG              LWIP_DBG_OFF
+#define RAW_DEBUG                   LWIP_DBG_OFF
+#define MEM_DEBUG                   LWIP_DBG_OFF
+#define MEMP_DEBUG                  LWIP_DBG_OFF
+#define SYS_DEBUG                   LWIP_DBG_OFF
+#define TCP_DEBUG                   LWIP_DBG_OFF
+#define TCP_INPUT_DEBUG             LWIP_DBG_OFF
+#define TCP_OUTPUT_DEBUG            LWIP_DBG_OFF
+#define TCP_RTO_DEBUG               LWIP_DBG_OFF
+#define TCP_CWND_DEBUG              LWIP_DBG_OFF
+#define TCP_WND_DEBUG               LWIP_DBG_OFF
+#define TCP_FR_DEBUG                LWIP_DBG_OFF
+#define TCP_QLEN_DEBUG              LWIP_DBG_OFF
+#define TCP_RST_DEBUG               LWIP_DBG_OFF
+#define UDP_DEBUG                   LWIP_DBG_OFF
+#define TCPIP_DEBUG                 LWIP_DBG_OFF
+#define PPP_DEBUG                   LWIP_DBG_OFF
+#define SLIP_DEBUG                  LWIP_DBG_OFF
+#define DHCP_DEBUG                  LWIP_DBG_OFF
+
+#endif /* __LWIPOPTS_H__ */

+ 377 - 0
entry/src/main/cpp/include/portable-endian.h

@@ -0,0 +1,377 @@
+// "License": Public Domain
+// I, Mathias Panzenbck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
+// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to
+// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it
+// an example on how to get the endian conversion functions on different platforms.
+
+#ifndef PORTABLE_ENDIAN_H__
+#define PORTABLE_ENDIAN_H__
+
+#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__) && !defined(_XBOX)
+#define __WINDOWS__
+#endif
+
+#if defined(__PS2__) || defined(PICO_PLATFORM)
+
+#ifndef _LITTLE_ENDIAN
+#define _LITTLE_ENDIAN LITTLE_ENDIAN
+#endif
+#if defined(_EE) || defined(PICO_PLATFORM)
+#include <machine/endian.h>
+#ifdef PICO_PLATFORM
+#include "lwip/def.h"
+#endif
+#endif
+
+#define be16toh(x) PP_NTOHS(x)
+#define htobe16(x) PP_HTONS(x)
+#define htole16(x) (x)
+#define le16toh(x) (x)
+
+#define be32toh(x) PP_NTOHL(x)
+#define htobe32(x) PP_HTONL(x)
+#define htole32(x) (x)
+#define le32toh(x) (x)
+
+#define htobe64(x) be64toh(x)
+#define htole64(x) (x)
+#define le64toh(x) (x)
+
+#elif defined(__DREAMCAST__)
+
+#include <machine/endian.h>
+
+#define be16toh(x) __builtin_bswap16(x)
+#define htobe16(x) __builtin_bswap16(x)
+#define htole16(x) (x)
+#define le16toh(x) (x)
+
+#define be32toh(x) __builtin_bswap32(x)
+#define htobe32(x) __builtin_bswap32(x)
+#define htole32(x) (x)
+#define le32toh(x) (x)
+
+#define be64toh(x) __builtin_bswap64(x)
+#define htobe64(x) __builtin_bswap64(x)
+#define htole64(x) (x)
+#define le64toh(x) (x)
+
+#elif defined(__linux__) || defined(__CYGWIN__) || defined(ESP_PLATFORM) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) || defined(__GNU__)
+
+#if defined(__linux__) || defined(__CYGWIN__) || defined(PS4_PLATFORM) || defined(ESP_PLATFORM) || defined(__GNU__)
+#include <endian.h>
+/* Include byteswap.h on linux since it might not be automatically included in some cases (e.g. alpine / musl) */
+#if defined(__linux__) || defined(__GLIBC__)
+#include <byteswap.h>
+#endif
+#else
+#include <sys/endian.h>
+#endif
+
+/* These 4 #defines may be needed with older esp-idf environments */
+#ifndef _LITTLE_ENDIAN
+#define _LITTLE_ENDIAN LITTLE_ENDIAN
+#endif
+
+#ifndef __bswap16
+#define __bswap16 __bswap_16
+#endif
+
+#ifndef __bswap32
+#define __bswap32 __bswap_32
+#endif
+
+#ifndef __bswap64
+#define __bswap64 __bswap_64
+#endif
+
+#ifndef be16toh
+#define be16toh(x) betoh16(x)
+#endif
+
+#ifndef le16toh
+#define le16toh(x) letoh16(x)
+#endif
+
+#ifndef be32toh
+#define be32toh(x) betoh32(x)
+#endif
+
+#ifndef le32toh
+#define le32toh(x) letoh32(x)
+#endif
+
+#ifndef be64toh
+#define be64toh(x) betoh64(x)
+#endif
+
+#ifndef le64toh
+#define le64toh(x) letoh64(x)
+#endif
+
+#elif defined(__APPLE__)
+
+#include <libkern/OSByteOrder.h>
+
+#define htobe16(x) OSSwapHostToBigInt16(x)
+#define htole16(x) OSSwapHostToLittleInt16(x)
+#define be16toh(x) OSSwapBigToHostInt16(x)
+#define le16toh(x) OSSwapLittleToHostInt16(x)
+
+#define htobe32(x) OSSwapHostToBigInt32(x)
+#define htole32(x) OSSwapHostToLittleInt32(x)
+#define be32toh(x) OSSwapBigToHostInt32(x)
+#define le32toh(x) OSSwapLittleToHostInt32(x)
+
+#define htobe64(x) OSSwapHostToBigInt64(x)
+#define htole64(x) OSSwapHostToLittleInt64(x)
+#define be64toh(x) OSSwapBigToHostInt64(x)
+#define le64toh(x) OSSwapLittleToHostInt64(x)
+
+#define __BYTE_ORDER BYTE_ORDER
+#define __BIG_ENDIAN BIG_ENDIAN
+#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#define __PDP_ENDIAN PDP_ENDIAN
+
+#elif defined(PS3_PPU_PLATFORM) || defined(__WIIU__) || defined(__WII__) || defined(__GC__)
+
+#define htobe16(x) (x)
+#define htole16(x) __builtin_bswap16(x)
+#define be16toh(x) (x)
+#define le16toh(x) __builtin_bswap16(x)
+
+#define htobe32(x) (x)
+#define htole32(x) __builtin_bswap32(x)
+#define be32toh(x) (x)
+#define le32toh(x) __builtin_bswap32(x)
+
+#define htobe64(x) (x)
+#define htole64(x) __builtin_bswap64(x)
+#define be64toh(x) (x)
+#define le64toh(x) __builtin_bswap64(x)
+
+#elif defined(__SWITCH__) || defined(__N3DS__) || defined(__NDS__)
+
+#include <machine/endian.h>
+#define htobe16(x) __bswap16(x)
+#define htole16(x) (x)
+#define be16toh(x) __bswap16(x)
+#define le16toh(x) (x)
+
+#define htobe32(x) __bswap32(x)
+#define htole32(x) (x)
+#define be32toh(x) __bswap32(x)
+#define le32toh(x) (x)
+
+#define htobe64(x) __bswap64(x)
+#define htole64(x) (x)
+#define be64toh(x) __bswap64(x)
+#define le64toh(x) (x)
+
+#elif defined(__WINDOWS__) || defined(_XBOX)
+
+#ifdef _XBOX
+#include <xtl.h>
+#else
+#include <windows.h>
+#endif
+
+#if defined(_MSC_VER)
+#include <stdlib.h>
+
+#define htobe16(x) _byteswap_ushort(x)
+#define htole16(x) (x)
+#define be16toh(x) _byteswap_ushort(x)
+#define le16toh(x) (x)
+
+#define htobe32(x) _byteswap_ulong(x)
+#define htole32(x) (x)
+#define be32toh(x) _byteswap_ulong(x)
+#define le32toh(x) (x)
+
+#define htobe64(x) _byteswap_uint64(x)
+#define htole64(x) (x)
+#define be64toh(x) _byteswap_uint64(x)
+#define le64toh(x) (x)
+
+#ifndef __BYTE_ORDER
+#define __BYTE_ORDER BYTE_ORDER
+#endif
+
+#ifndef __BIG_ENDIAN
+#define __BIG_ENDIAN BIG_ENDIAN
+#endif
+
+#ifndef __LITTLE_ENDIAN
+#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#endif
+
+#ifndef __PDP_ENDIAN
+#define __PDP_ENDIAN PDP_ENDIAN
+#endif
+
+#elif defined(__GNUC__) || defined(__clang__)
+
+#define htobe16(x) __builtin_bswap16(x)
+#define htole16(x) (x)
+#define be16toh(x) __builtin_bswap16(x)
+#define le16toh(x) (x)
+
+#define htobe32(x) __builtin_bswap32(x)
+#define htole32(x) (x)
+#define be32toh(x) __builtin_bswap32(x)
+#define le32toh(x) (x)
+
+#define htobe64(x) __builtin_bswap64(x)
+#define htole64(x) (x)
+#define be64toh(x) __builtin_bswap64(x)
+#define le64toh(x) (x)
+
+#else
+#error platform not supported
+#endif
+
+#elif defined(__amigaos4__) || defined(__AMIGA__)
+
+#if defined(__NEWLIB__)
+#include <machine/endian.h>
+
+#ifndef __bswap16
+#define __bswap16(x) __builtin_bswap16(x)
+#endif
+
+#ifndef __bswap32
+#define __bswap32(x) __builtin_bswap32(x)
+#endif
+
+#ifndef __bswap64
+#define __bswap64(x) __builtin_bswap64(x)
+#endif
+
+#define htobe16(x) (x)
+#define htole16(x) __bswap16(x)
+#define be16toh(x) (x)
+#define le16toh(x) __bswap16(x)
+
+#define htobe32(x) (x)
+#define htole32(x) __bswap32(x)
+#define be32toh(x) (x)
+#define le32toh(x) __bswap32(x)
+
+#define htobe64(x) (x)
+#define htole64(x) __bswap64(x)
+#define be64toh(x) (x)
+#define le64toh(x) __bswap64(x)
+
+#elif defined(__GNUC__)
+
+#define htobe16(x) (x)
+#define htole16(x) __builtin_bswap16(x)
+#define be16toh(x) (x)
+#define le16toh(x) __builtin_bswap16(x)
+
+#define htobe32(x) (x)
+#define htole32(x) __builtin_bswap32(x)
+#define be32toh(x) (x)
+#define le32toh(x) __builtin_bswap32(x)
+
+#define htobe64(x) (x)
+#define htole64(x) __builtin_bswap64(x)
+#define be64toh(x) (x)
+#define le64toh(x) __builtin_bswap64(x)
+
+#else
+#error platform not supported
+#endif
+
+#elif defined(__AROS__)
+
+#include <endian.h>
+
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR >= 8))
+
+#define __bswap16(x) __builtin_bswap16(x)
+#define __bswap32(x) __builtin_bswap32(x)
+#define __bswap64(x) __builtin_bswap64(x)
+
+#else
+
+#define __bswap16(x) ((((uint16_t)(x) & 0xFF00) >> 8) | \
+                         (((uint16_t)(x) & 0x00FF) << 8))
+#define __bswap32(x) ((((uint32_t)(x) & 0xFF000000) >> 24) | \
+                         (((uint32_t)(x) & 0x00FF0000) >>  8) | \
+                         (((uint32_t)(x) & 0x0000FF00) <<  8) | \
+                         (((uint32_t)(x) & 0x000000FF) << 24))
+#define __bswap64(x) ((((uint64_t)(x) & 0xFF00000000000000) >> 56) | \
+                         (((uint64_t)(x) & 0x00FF000000000000) >> 40) | \
+                         (((uint64_t)(x) & 0x0000FF0000000000) >> 24) | \
+                         (((uint64_t)(x) & 0x000000FF00000000) >>  8) | \
+                         (((uint64_t)(x) & 0x00000000FF000000) <<  8) | \
+                         (((uint64_t)(x) & 0x0000000000FF0000) << 24) | \
+                         (((uint64_t)(x) & 0x000000000000FF00) << 40) | \
+                         (((uint64_t)(x) & 0x00000000000000FF) << 56))
+
+#endif
+
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+
+#define htobe16(x) __bswap16(x)
+#define htole16(x) (x)
+#define be16toh(x) __bswap16(x)
+#define le16toh(x) (x)
+
+#define htobe32(x) __bswap32(x)
+#define htole32(x) (x)
+#define be32toh(x) __bswap32(x)
+#define le32toh(x) (x)
+
+#define htobe64(x) __bswap64(x)
+#define htole64(x) (x)
+#define be64toh(x) __bswap64(x)
+#define le64toh(x) (x)
+
+#else
+
+#define htobe16(x) (x)
+#define htole16(x) __bswap16(x)
+#define be16toh(x) (x)
+#define le16toh(x) __bswap16(x)
+
+#define htobe32(x) (x)
+#define htole32(x) __bswap32(x)
+#define be32toh(x) (x)
+#define le32toh(x) __bswap32(x)
+
+#define htobe64(x) (x)
+#define htole64(x) __bswap64(x)
+#define be64toh(x) (x)
+#define le64toh(x) __bswap64(x)
+
+#endif
+
+#elif defined(__GNUC__) || defined(__clang__)
+
+#ifdef __vita__
+#include <machine/endian.h>
+#endif
+
+#define htobe16(x) __builtin_bswap16(x)
+#define htole16(x) (x)
+#define be16toh(x) __builtin_bswap16(x)
+#define le16toh(x) (x)
+
+#define htobe32(x) __builtin_bswap32(x)
+#define htole32(x) (x)
+#define be32toh(x) __builtin_bswap32(x)
+#define le32toh(x) (x)
+
+#define htobe64(x) __builtin_bswap64(x)
+#define htole64(x) (x)
+#define be64toh(x) __builtin_bswap64(x)
+#define le64toh(x) (x)
+
+#else
+#error platform not supported
+#endif
+
+#endif

+ 139 - 0
entry/src/main/cpp/include/ps3/config.h

@@ -0,0 +1,139 @@
+/* config.h.  Generated from config.h.in by configure.  */
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Whether or not TCP sockets should be allowed to linger after closure */
+#define CONFIGURE_OPTION_TCP_LINGER 1
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+/* #undef HAVE_ARPA_INET_H */
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+/* #undef HAVE_DLFCN_H */
+
+/* Define to 1 if you have the <errno.h> header file. */
+#define HAVE_ERRNO_H 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the <gssapi/gssapi.h> header file. */
+/* #undef HAVE_GSSAPI_GSSAPI_H */
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+/* #undef HAVE_INTTYPES_H */
+
+/* Whether we use gssapi_krb5 or not */
+/* #undef HAVE_LIBKRB5 */
+
+/* Define to 1 if you have the `nsl' library (-lnsl). */
+/* #undef HAVE_LIBNSL */
+
+/* Define to 1 if you have the `socket' library (-lsocket). */
+/* #undef HAVE_LIBSOCKET */
+
+/* Whether we have linger */
+#define HAVE_LINGER 1
+
+/* Define to 1 if you have the <netdb.h> header file. */
+/* #undef HAVE_NETDB_H */
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#define HAVE_NETINET_IN_H 1
+
+/* Define to 1 if you have the <netinet/tcp.h> header file. */
+/* #undef HAVE_NETINET_TCP_H */
+
+/* Define to 1 if you have the <poll.h> header file. */
+/* #undef HAVE_POLL_H */
+
+/* Whether sockaddr struct has sa_len */
+/* #undef HAVE_SOCKADDR_LEN */
+
+/* Whether we have sockaddr_Storage */
+/* #undef HAVE_SOCKADDR_STORAGE */
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#define HAVE_STDIO_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+/* #undef HAVE_STRINGS_H */
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/errno.h> header file. */
+/* #undef HAVE_SYS_ERRNO_H */
+
+/* Define to 1 if you have the <sys/fcntl.h> header file. */
+/* #undef HAVE_SYS_FCNTL_H */
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+/* #undef HAVE_SYS_IOCTL_H */
+
+/* Define to 1 if you have the <sys/poll.h> header file. */
+/* #undef HAVE_SYS_POLL_H */
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+/* #undef HAVE_SYS_SOCKET_H */
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+/* #undef HAVE_SYS_STAT_H */
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+/* #undef HAVE_SYS_TIME_H */
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/uio.h> header file. */
+/* #undef HAVE_SYS_UIO_H */
+
+/* Define to 1 if you have the <sys/unistd.h> header file. */
+/* #undef HAVE_SYS_UNISTD_H */
+
+/* Define to 1 if you have the <sys/_iovec.h> header file. */
+/* #undef HAVE_SYS__IOVEC_H */
+
+/* Define to 1 if you have the <time.h> header file. */
+#define HAVE_TIME_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to the sub-directory where libtool stores uninstalled libraries. */
+#define LT_OBJDIR ".libs/"
+
+/* Name of package */
+#define PACKAGE "libsmb2"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "ronniesahlberg@gmail.com"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libsmb2"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libsmb2 4.0.0"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libsmb2"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "4.0.0"
+
+/* Define to 1 if all of the C90 standard headers exist (not just the ones
+   required in a freestanding environment). This macro is provided for
+   backward compatibility; new code need not use it. */
+#define STDC_HEADERS 1
+
+/* Version number of package */
+#define VERSION "4.0.0"

+ 63 - 0
entry/src/main/cpp/include/slist.h

@@ -0,0 +1,63 @@
+/*
+   Copyright (C) 2016 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __smb2_slist_h__
+#define __smb2_slist_h__
+
+#define SMB2_LIST_ADD(list, item) \
+	do {							\
+		(item)->next = (*list);				\
+		(*list) = (item);				\
+	} while (0);
+
+#define SMB2_LIST_ADD_END(list, item)	\
+	if ((*list) == NULL) {	 				\
+	   SMB2_LIST_ADD((list), (item));			\
+	} else {						\
+	   void *head = (*list);				\
+	   while ((*list)->next)				\
+	     (*list) = (*list)->next;				\
+	   (*list)->next = (item);				\
+	   (item)->next = NULL;					\
+	   (*list) = head;					\
+	}
+
+#define SMB2_LIST_REMOVE(list, item) \
+	if ((*list) == (item)) { 				\
+	   (*list) = (item)->next;				\
+	} else if (*list) {					\
+	   void *head = (*list);				\
+	   while ((*list)->next && (*list)->next != (item))     \
+	     (*list) = (*list)->next;				\
+	   if ((*list)->next != NULL) {		    	    	\
+	      (*list)->next = (*list)->next->next;		\
+	   }  		      					\
+	   (*list) = head;					\
+	}
+
+#define SMB2_LIST_LENGTH(list, length) \
+	do { \
+	    (length) = 0; \
+		void *head = (*list); \
+		while ((*list)) { \
+			(*list) = (*list)->next; \
+			(length)++; \
+		} \
+		(*list) = head; \
+	} while (0);
+
+#endif /* __smb2_slist_h__ */

+ 172 - 0
entry/src/main/cpp/include/smb2/libsmb2-dcerpc-lsa.h

@@ -0,0 +1,172 @@
+/* -*-  mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil;  -*- */
+/*
+   Copyright (C) 2020 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _LIBSMB2_DCERPC_LSA_H_
+#define _LIBSMB2_DCERPC_LSA_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define LSA_CLOSE          0x00
+#define LSA_OPENPOLICY2    0x2c
+#define LSA_LOOKUPSIDS2    0x39
+
+/* Access Mask. LSA specific flags. */
+#define POLICY_VIEW_LOCAL_INFORMATION    0x00000001
+#define POLICY_VIEW_AUDIT_INFORMATION    0x00000002
+#define POLICY_GET_PRIVATE_INFORMATION   0x00000004
+#define POLICY_TRUST_ADMIN               0x00000008
+#define POLICY_CREATE_ACCOUNT            0x00000010
+#define POLICY_CREATE_SECRET             0x00000020
+#define POLICY_CREATE_PRIVILEGE          0x00000040
+#define POLICY_SET_DEFAULT_QUOTA_LIMITS  0x00000080
+#define POLICY_SET_AUDIT_REQUIREMENTS    0x00000100
+#define POLICY_AUDIT_LOG_ADMIN           0x00000200
+#define POLICY_SERVER_ADMIN              0x00000400
+#define POLICY_LOOKUP_NAMES              0x00000800
+#define POLICY_NOTIFICATION              0x00001000
+
+extern unsigned char NT_SID_AUTHORITY[6];
+
+typedef struct RPC_SID {
+        uint8_t Revision;
+        uint8_t SubAuthorityCount;
+        uint8_t IdentifierAuthority[6];
+        uint32_t *SubAuthority;
+} RPC_SID, *PRPC_SID;
+
+typedef struct _LSAPR_TRANSLATED_NAME_EX {
+        uint32_t Use;
+        char *Name;
+        uint32_t DomainIndex;
+        uint32_t Flags;
+} LSAPR_TRANSLATED_NAME_EX, *PLSAPR_TRANSLATED_NAME_EX;
+
+typedef struct _LSAPR_TRANSLATED_NAMES_EX {
+        uint32_t Entries;
+        LSAPR_TRANSLATED_NAME_EX  *Names;
+} LSAPR_TRANSLATED_NAMES_EX, *PLSAPR_TRANSLATED_NAMES_EX;
+
+typedef struct _SID_ENUM_BUFFER {
+        uint32_t Entries;
+        PRPC_SID *SidInfo;
+} LSAPR_SID_ENUM_BUFFER, *PLSAPR_SID_ENUM_BUFFER;
+
+typedef enum _LSAP_LOOKUP_LEVEL {
+        LsapLookupWksta = 1,
+        LsapLookupPDC,
+        LsapLookupTDL,
+        LsapLookupGC,
+        LsapLookupXForestReferral,
+        LsapLookupXForestResolve,
+        LsapLookupRODCReferralToFullDC
+} LSAP_LOOKUP_LEVEL, *PLSAP_LOOKUP_LEVEL;
+
+typedef struct _LSAPR_TRUST_INFORMATION {
+        char *Name;
+        RPC_SID Sid;
+} LSAPR_TRUST_INFORMATION, *PLSAPR_TRUST_INFORMATION;
+
+typedef struct _LSAPR_REFERENCED_DOMAIN_LIST {
+        uint32_t Entries;
+        LSAPR_TRUST_INFORMATION *Domains;
+        uint32_t MaxEntries; /* must be ignored */
+} LSAPR_REFERENCED_DOMAIN_LIST, *PLSAPR_REFERENCED_DOMAIN_LIST;
+
+/* For OPENPOLICY2: RootDirectory MUST be zero. Everything else is ignored. */
+typedef struct _LSAPR_OBJECT_ATTRIBUTES {
+        uint32_t Length;
+        unsigned char *RootDirectory;
+        void *ObjectName;
+        uint32_t Attributes;
+        void *SecurityDescriptor;
+        void *SecurityQualityOfService;
+} LSAPR_OBJECT_ATTRIBUTES, *PLSAPR_OBJECT_ATTRIBUTES;
+
+struct lsa_close_req {
+        struct ndr_context_handle PolicyHandle;
+};
+
+struct lsa_close_rep {
+        uint32_t status;
+
+        struct ndr_context_handle PolicyHandle;
+};
+
+struct lsa_openpolicy2_req {
+        char *SystemName;
+        LSAPR_OBJECT_ATTRIBUTES ObjectAttributes;
+        uint32_t DesiredAccess;
+};
+
+struct lsa_openpolicy2_rep {
+        uint32_t status;
+
+        struct ndr_context_handle PolicyHandle;
+};
+
+struct lsa_lookupsids2_req {
+        struct ndr_context_handle PolicyHandle;
+        LSAPR_SID_ENUM_BUFFER SidEnumBuffer;
+        LSAPR_TRANSLATED_NAMES_EX TranslatedNames;
+        LSAP_LOOKUP_LEVEL LookupLevel;
+};
+
+struct lsa_lookupsids2_rep {
+        uint32_t status;
+
+        LSAPR_REFERENCED_DOMAIN_LIST ReferencedDomains;
+        LSAPR_TRANSLATED_NAMES_EX TranslatedNames;
+        uint32_t MappedCount;
+};
+
+int lsa_Close_rep_coder(struct dcerpc_context *dce,
+                        struct dcerpc_pdu *pdu,
+                        struct smb2_iovec *iov, int *offset,
+                        void *ptr);
+int lsa_Close_req_coder(struct dcerpc_context *dce,
+                        struct dcerpc_pdu *pdu,
+                        struct smb2_iovec *iov, int *offset,
+                        void *ptr);
+int lsa_LookupSids2_rep_coder(struct dcerpc_context *dce,
+                              struct dcerpc_pdu *pdu,
+                              struct smb2_iovec *iov, int *offset,
+                              void *ptr);
+int lsa_LookupSids2_req_coder(struct dcerpc_context *dce,
+                              struct dcerpc_pdu *pdu,
+                              struct smb2_iovec *iov, int *offset,
+                              void *ptr);
+int lsa_OpenPolicy2_rep_coder(struct dcerpc_context *dce,
+                              struct dcerpc_pdu *pdu,
+                              struct smb2_iovec *iov, int *offset,
+                              void *ptr);
+int lsa_OpenPolicy2_req_coder(struct dcerpc_context *dce,
+                              struct dcerpc_pdu *pdu,
+                              struct smb2_iovec *iov, int *offset,
+                              void *ptr);
+int lsa_RPC_SID_coder(struct dcerpc_context *dce,
+                      struct dcerpc_pdu *pdu,
+                      struct smb2_iovec *iov, int *offset,
+                      void *ptr);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_LIBSMB2_DCERPC_LSA_H_ */

+ 180 - 0
entry/src/main/cpp/include/smb2/libsmb2-dcerpc-srvsvc.h

@@ -0,0 +1,180 @@
+/* -*-  mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil;  -*- */
+/*
+   Copyright (C) 2018 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _LIBSMB2_DCERPC_SRVSVC_H_
+#define _LIBSMB2_DCERPC_SRVSVC_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <smb2/libsmb2-dcerpc.h>
+
+#define SRVSVC_NETRSHAREENUM      0x0f
+#define SRVSVC_NETRSHAREGETINFO   0x10
+
+struct dcerpc_context;
+struct dcerpc_pdu;
+
+
+/* Low 2 bits desctibe the type */
+#define SHARE_TYPE_DISKTREE  0
+#define SHARE_TYPE_PRINTQ    1
+#define SHARE_TYPE_DEVICE    2
+#define SHARE_TYPE_IPC       3
+
+#define SHARE_TYPE_TEMPORARY 0x40000000
+#define SHARE_TYPE_HIDDEN    0x80000000
+
+enum SHARE_INFO_enum {
+        SHARE_INFO_0 = 0,
+        SHARE_INFO_1 = 1,
+};
+
+struct srvsvc_SHARE_INFO_0 {
+        struct dcerpc_utf16 netname;
+};
+int srvsvc_SHARE_INFO_0_coder(struct dcerpc_context *ctx,
+                              struct dcerpc_pdu *pdu,
+                              struct smb2_iovec *iov, int *offset,
+                              void *ptr);
+
+struct srvsvc_SHARE_INFO_0_carray {
+        uint32_t max_count;
+        struct srvsvc_SHARE_INFO_0 *share_info_0;
+};
+
+struct srvsvc_SHARE_INFO_0_CONTAINER {
+        uint32_t EntriesRead;
+        struct srvsvc_SHARE_INFO_0_carray *Buffer;
+};
+
+struct srvsvc_SHARE_INFO_1 {
+        struct dcerpc_utf16 netname;
+        uint32_t type;
+        struct dcerpc_utf16 remark;
+};
+int srvsvc_SHARE_INFO_1_coder(struct dcerpc_context *ctx,
+                              struct dcerpc_pdu *pdu,
+                              struct smb2_iovec *iov, int *offset,
+                              void *ptr);
+
+struct srvsvc_SHARE_INFO_1_carray {
+        uint32_t max_count;
+        struct srvsvc_SHARE_INFO_1 *share_info_1;
+};
+
+struct srvsvc_SHARE_INFO_1_CONTAINER {
+        uint32_t EntriesRead;
+        struct srvsvc_SHARE_INFO_1_carray *Buffer;
+};
+        
+int srvsvc_SHARE_INFO_1_CONTAINER_coder(struct dcerpc_context *dce,
+                                        struct dcerpc_pdu *pdu,
+                                        struct smb2_iovec *iov, int *offset,
+                                        void *ptr);
+
+struct srvsvc_SHARE_ENUM_UNION {
+        uint32_t Level;
+        union {
+                struct srvsvc_SHARE_INFO_0_CONTAINER Level0;
+                struct srvsvc_SHARE_INFO_1_CONTAINER Level1;
+        };
+};
+
+struct srvsvc_SHARE_ENUM_STRUCT {
+        uint32_t Level;
+        struct srvsvc_SHARE_ENUM_UNION ShareInfo;
+};
+
+struct srvsvc_NetrShareEnum_req {
+        struct dcerpc_utf16 ServerName;
+        struct srvsvc_SHARE_ENUM_STRUCT ses;
+        uint32_t PreferedMaximumLength;
+        uint32_t ResumeHandle;
+};
+
+struct srvsvc_NetrShareEnum_rep {
+        uint32_t status;
+
+        struct srvsvc_SHARE_ENUM_STRUCT ses;
+        uint32_t total_entries;
+        uint32_t resume_handle;
+};
+
+struct srvsvc_SHARE_INFO {
+        uint32_t level;
+        union {
+                struct srvsvc_SHARE_INFO_1 ShareInfo1;
+        };
+};
+
+struct srvsvc_NetrShareGetInfo_req {
+        struct dcerpc_utf16 ServerName;
+        struct dcerpc_utf16 NetName;
+        uint32_t Level;
+};
+
+struct srvsvc_NetrShareGetInfo_rep {
+        uint32_t status;
+
+        struct srvsvc_SHARE_INFO InfoStruct;
+};
+
+struct srvsvc_rep {
+        uint32_t status;
+};
+
+/*
+ * Async share_enum()
+ * This function only works when connected to the IPC$ share.
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success. Command_data is struct srvsvc_NetrShareEnum_rep *
+ *          This pointer must be freed using smb2_free_data().
+ * -errno : An error occurred.
+ */
+int smb2_share_enum_async(struct smb2_context *smb2, enum SHARE_INFO_enum level,
+                          smb2_command_cb cb, void *cb_data);
+
+int srvsvc_NetrShareEnum_rep_coder(struct dcerpc_context *dce,
+                                   struct dcerpc_pdu *pdu,
+                                   struct smb2_iovec *iov, int *offset,
+                                   void *ptr);
+int srvsvc_NetrShareEnum_req_coder(struct dcerpc_context *ctx,
+                                   struct dcerpc_pdu *pdu,
+                                   struct smb2_iovec *iov, int *offset,
+                                   void *ptr);
+int srvsvc_NetrShareGetInfo_rep_coder(struct dcerpc_context *dce,
+                                      struct dcerpc_pdu *pdu,
+                                      struct smb2_iovec *iov, int *offset,
+                                      void *ptr);
+int srvsvc_NetrShareGetInfo_req_coder(struct dcerpc_context *ctx,
+                                      struct dcerpc_pdu *pdu,
+                                      struct smb2_iovec *iov, int *offset,
+                                      void *ptr);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_LIBSMB2_DCERPC_SRVSVC_H_ */

+ 155 - 0
entry/src/main/cpp/include/smb2/libsmb2-dcerpc.h

@@ -0,0 +1,155 @@
+/* -*-  mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil;  -*- */
+/*
+   Copyright (C) 2018 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _LIBSMB2_DCERPC_H_
+#define _LIBSMB2_DCERPC_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Data representation */
+/* Integer */
+#define DCERPC_DR_BIG_ENDIAN                    0x00
+#define DCERPC_DR_LITTLE_ENDIAN                 0x10
+/* Character */
+#define DCERPC_DR_ASCII                         0x00
+#define DCERPC_DR_EBCDIC                        0x01
+
+struct dcerpc_context;
+struct dcerpc_pdu;
+
+/* Encoder/Decoder for a DCERPC object */
+typedef int (*dcerpc_coder)(struct dcerpc_context *dce, struct dcerpc_pdu *pdu,
+                            struct smb2_iovec *iov, int *offset,
+                            void *ptr);
+
+enum ptr_type {
+        PTR_REF    = 0,
+        PTR_UNIQUE = 1,
+        PTR_FULL   = 2
+};
+
+typedef struct dcerpc_uuid {
+        uint32_t v1;
+        uint16_t v2;
+        uint16_t v3;
+        uint8_t v4[8];
+} dcerpc_uuid_t;
+
+typedef struct p_syntax_id {
+        dcerpc_uuid_t uuid;
+        uint16_t vers;
+        uint16_t vers_minor;
+} p_syntax_id_t;
+
+struct ndr_transfer_syntax {
+        dcerpc_uuid_t uuid;
+        uint16_t vers;
+};
+
+struct ndr_context_handle {
+        uint32_t context_handle_attributes;
+        dcerpc_uuid_t context_handle_uuid;
+};
+
+struct dcerpc_utf16 {
+        uint32_t max_count;       /* internal use only */
+        uint32_t offset;          /* internal use only */
+        uint32_t actual_count;    /* internal use only */
+
+        struct smb2_utf16 *utf16; /* internal use only */
+        
+        const char *utf8;
+};
+
+struct dcerpc_carray {
+        uint32_t max_count;
+        uint8_t *data;
+};
+        
+extern p_syntax_id_t lsa_interface;
+extern p_syntax_id_t srvsvc_interface;
+        
+typedef void (*dcerpc_cb)(struct dcerpc_context *dce, int status,
+                          void *command_data, void *cb_data);
+
+struct dcerpc_context *dcerpc_create_context(struct smb2_context *smb2);
+void dcerpc_free_data(struct dcerpc_context *dce, void *data);
+const char *dcerpc_get_error(struct dcerpc_context *dce);
+int dcerpc_connect_context_async(struct dcerpc_context *dce,
+                                 const char *path, p_syntax_id_t *syntax,
+                                 dcerpc_cb cb, void *cb_data);
+void dcerpc_destroy_context(struct dcerpc_context *dce);
+
+struct smb2_context *dcerpc_get_smb2_context(struct dcerpc_context *dce);
+void *dcerpc_get_pdu_payload(struct dcerpc_pdu *pdu);
+
+int dcerpc_open_async(struct dcerpc_context *dce, dcerpc_cb cb, void *cb_data);
+int dcerpc_call_async(struct dcerpc_context *dce,
+                      int opnum,
+                      dcerpc_coder req_coder, void *req,
+                      dcerpc_coder rep_coder, int decode_size,
+                      dcerpc_cb cb, void *cb_data);
+
+int dcerpc_do_coder(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
+                    struct smb2_iovec *iov,
+                    int *offset, void *ptr,
+                    dcerpc_coder coder);
+int dcerpc_ptr_coder(struct dcerpc_context *dce, struct dcerpc_pdu *pdu,
+                     struct smb2_iovec *iov, int *offset, void *ptr,
+                     enum ptr_type type, dcerpc_coder coder);
+int dcerpc_carray_coder(struct dcerpc_context *ctx,
+                        struct dcerpc_pdu *pdu,
+                        struct smb2_iovec *iov, int *offset,
+                        void *ptr, int elem_size, dcerpc_coder coder);
+int dcerpc_uint8_coder(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
+                    struct smb2_iovec *iov, int *offset, void *ptr);
+int dcerpc_uint16_coder(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
+                     struct smb2_iovec *iov, int *offset, void *ptr);
+int dcerpc_uint32_coder(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
+                     struct smb2_iovec *iov, int *offset, void *ptr);
+int dcerpc_uint3264_coder(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
+                       struct smb2_iovec *iov, int *offset, void *ptr);
+int dcerpc_conformance_coder(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
+                       struct smb2_iovec *iov, int *offset, void *ptr);
+int dcerpc_utf16_coder(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
+                      struct smb2_iovec *iov, int *offset, void *ptr);
+int dcerpc_utf16z_coder(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
+                        struct smb2_iovec *iov, int *offset, void *ptr);
+int dcerpc_context_handle_coder(struct dcerpc_context *dce,
+                                struct dcerpc_pdu *pdu,
+                                struct smb2_iovec *iov, int *offset,
+                                void *ptr);
+int dcerpc_uuid_coder(struct dcerpc_context *dce,
+                      struct dcerpc_pdu *pdu,
+                      struct smb2_iovec *iov, int *offset,
+                      dcerpc_uuid_t *uuid);
+int dcerpc_uint8_coder(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,
+                    struct smb2_iovec *iov, int *offset, void *ptr);
+#define DCERPC_DECODE 0
+#define DCERPC_ENCODE 1
+struct dcerpc_pdu *dcerpc_allocate_pdu(struct dcerpc_context *dce,
+                                       int direction, int payload_size);
+void dcerpc_free_pdu(struct dcerpc_context *dce, struct dcerpc_pdu *pdu);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_LIBSMB2_DCERPC_H_ */

+ 497 - 0
entry/src/main/cpp/include/smb2/libsmb2-raw.h

@@ -0,0 +1,497 @@
+/* -*-  mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil;  -*- */
+/*
+   Copyright (C) 2016 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _LIBSMB2_RAW_H_
+#define _LIBSMB2_RAW_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Low level RAW SMB2 interface
+ */
+/*
+ * Magic file Id used for compound commands.
+ */
+extern const smb2_file_id compound_file_id;
+
+/*
+ * This function is used to free the data returned by the query functions.
+ */
+void smb2_free_data(struct smb2_context *smb2, void *ptr);
+
+/*
+ * Asynchronous SMB2 Negotiate
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the negotiate will be reported through the callback
+ *        function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Returns:
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Negotiate was successful.
+ *            Command_data is a struct smb2_negotiate_reply.
+ *
+ *   !0     : Status is NT status code. Command_data is NULL.
+ */
+struct smb2_pdu *smb2_cmd_negotiate_async(struct smb2_context *smb2,
+                                          struct smb2_negotiate_request *req,
+                                          smb2_command_cb cb, void *cb_data);
+
+
+struct smb2_pdu *smb2_cmd_negotiate_reply_async(struct smb2_context *smb2,
+                                          struct smb2_negotiate_reply *rep,
+                                          smb2_command_cb cb, void *cb_data);
+
+/*
+ * Asynchronous SMB2 Session Setup
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the session setup will be reported through the callback
+ *        function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Session setup was successful.
+ *            Command_data is a struct smb2_session_setup_reply.
+ *
+ *   !0     : Status is NT status code.
+ */
+struct smb2_pdu *smb2_cmd_session_setup_async(struct smb2_context *smb2,
+                                 struct smb2_session_setup_request *req,
+                                 smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_session_setup_reply_async(struct smb2_context *smb2,
+                                struct smb2_session_setup_reply *rep,
+                                smb2_command_cb cb, void *cb_data);
+/*
+ * Asynchronous SMB2 Tree Connect
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the tree connect will be reported through the callback
+ *        function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Tree Connect was successful.
+ *            Command_data is a struct smb2_tree_connect_reply.
+ *
+ *   !0     : Status is NT status code. Command_data is NULL.
+ */
+struct smb2_pdu *smb2_cmd_tree_connect_async(struct smb2_context *smb2,
+                                struct smb2_tree_connect_request *req,
+                                smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_tree_connect_reply_async(struct smb2_context *smb2,
+                            struct smb2_tree_connect_reply *rep,
+                            uint32_t tree_id,
+                            smb2_command_cb cb, void *cb_data);
+/*
+ * Asynchronous SMB2 Tree Disconnect
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the tree connect will be reported through the callback
+ *        function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Tree Disconnect was successful.
+ *
+ *   !0     : Status is NT status code.
+ *
+ * Command_data is always NULL.
+ */
+struct smb2_pdu *smb2_cmd_tree_disconnect_async(struct smb2_context *smb2,
+                                  smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_tree_disconnect_reply_async(struct smb2_context *smb2,
+                                  smb2_command_cb cb, void *cb_data);
+
+/*
+ * Asynchronous SMB2 Create
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the create will be reported through the callback function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Create was successful.
+ *            Command_data is a struct smb2_create_reply.
+ *
+ *   !0     : Status is NT status code. Command_data is NULL.
+ */
+struct smb2_pdu *smb2_cmd_create_async(struct smb2_context *smb2,
+                                       struct smb2_create_request *req,
+                                       smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_create_reply_async(struct smb2_context *smb2,
+                                       struct smb2_create_reply *rep,
+                                       smb2_command_cb cb, void *cb_data);
+
+/*
+ * Asynchronous SMB2 Close
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the close will be reported through the callback function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Close was successful.
+ *            Command_data is a struct smb2_close_reply.
+ *
+ *   !0     : Status is NT status code. Command_data is NULL.
+ */
+struct smb2_pdu *smb2_cmd_close_async(struct smb2_context *smb2,
+                                      struct smb2_close_request *req,
+                                      smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_close_reply_async(struct smb2_context *smb2,
+                                      struct smb2_close_reply *rep,
+                                      smb2_command_cb cb, void *cb_data);
+
+/*
+ * Asynchronous SMB2 Read
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the read will be reported through the callback function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Read was successful.
+ *
+ *   !0     : Status is NT status code.
+ *
+ * command_data is always NULL.
+ */
+struct smb2_pdu *smb2_cmd_read_async(struct smb2_context *smb2,
+                                     struct smb2_read_request *req,
+                                     smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_read_reply_async(struct smb2_context *smb2,
+                                     struct smb2_read_reply *rep,
+                                     smb2_command_cb cb, void *cb_data);
+
+/*
+ * Asynchronous SMB2 Write
+ *
+ * use pass_buf_ownerhip non-0 to allow the request's buf to be
+ * freed along with the pdu when it is freed, use 0 to retain
+ * req->buf
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the write will be reported through the callback function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Write was successful.
+ *
+ *   !0     : Status is NT status code.
+ *
+ * command_data is always NULL.
+ */
+struct smb2_pdu *smb2_cmd_write_async(struct smb2_context *smb2,
+                                      struct smb2_write_request *req,
+                                      int pass_buf_ownership,
+                                      smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_write_reply_async(struct smb2_context *smb2,
+                                      struct smb2_write_reply *rep,
+                                      smb2_command_cb cb, void *cb_data);
+
+/*
+ * Asynchronous SMB2 Query Directory
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the QD will be reported through the callback function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Query was successful.
+ *            Command_data is a struct smb2_query_directory_reply.
+ *
+ *   !0     : Status is NT status code. Command_data is NULL.
+ */
+struct smb2_pdu *smb2_cmd_query_directory_async(struct smb2_context *smb2,
+                             struct smb2_query_directory_request *req,
+                             smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_query_directory_reply_async(struct smb2_context *smb2,
+                             struct smb2_query_directory_request *req,
+                             struct smb2_query_directory_reply *rep,
+                             smb2_command_cb cb, void *cb_data);
+
+/*
+ * Asynchronous SMB2 Change Notify
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the close will be reported through the callback function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Close was successful.
+ *            Command_data is a struct smb2_close_reply.
+ *
+ *   !0     : Status is NT status code. Command_data is NULL.
+ */
+struct smb2_pdu *smb2_cmd_change_notify_async(struct smb2_context *smb2,
+                                      struct smb2_change_notify_request *req,
+                                      smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_change_notify_reply_async(struct smb2_context *smb2,
+                                      struct smb2_change_notify_reply *rep,
+                                      smb2_command_cb cb, void *cb_data);
+
+/*
+ * Asynchronous SMB2 Query Info
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the QI will be reported through the callback function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Query was successful.
+ *            Command_data is a struct struct smb2_query_info_reply *
+ *            This structure contains a pointer to the requested data
+ *            structure in ->output_buffer.
+ *            Output_buffer must be freed by calling smb2_free_data()
+ *
+ *   !0     : Status is NT status code. Command_data is NULL.
+ */
+struct smb2_pdu *smb2_cmd_query_info_async(struct smb2_context *smb2,
+                                           struct smb2_query_info_request *req,
+                                           smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_query_info_reply_async(struct smb2_context *smb2,
+                                           struct smb2_query_info_request *req,
+                                           struct smb2_query_info_reply *rep,
+                                           smb2_command_cb cb, void *cb_data);
+
+/*
+ * Asynchronous SMB2 Set Info
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the QI will be reported through the callback function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Query was successful.
+ *            Command_data is a struct struct smb2_query_info_reply *
+ *
+ *   !0     : Status is NT status code. Command_data is NULL.
+ */
+struct smb2_pdu *smb2_cmd_set_info_async(struct smb2_context *smb2,
+                                         struct smb2_set_info_request *req,
+                                         smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_set_info_reply_async(struct smb2_context *smb2,
+                                         struct smb2_set_info_request *req,
+                                         smb2_command_cb cb, void *cb_data);
+
+/*
+ * Asynchronous SMB2 Ioctl
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the Ioctl will be reported through the callback function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Query was successful.
+ *            Command_data is a struct struct smb2_ioctl_reply *
+ *            This structure contains a pointer to the requested data
+ *            structure in ->output.
+ *            Output must be freed by calling smb2_free_data()
+ *
+ *   !0     : Status is NT status code. Command_data is NULL.
+ */
+struct smb2_pdu *smb2_cmd_ioctl_async(struct smb2_context *smb2,
+                                      struct smb2_ioctl_request *req,
+                                      smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_ioctl_reply_async(struct smb2_context *smb2,
+                                      struct smb2_ioctl_reply *rep,
+                                      smb2_command_cb cb, void *cb_data);
+
+/*
+ * Asynchronous SMB2 Echo
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the echo will be reported through the callback function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Echo was successful.
+ *
+ *   !0     : Status is NT status code.
+ *
+ * command_data is always NULL.
+ */
+struct smb2_pdu *smb2_cmd_echo_async(struct smb2_context *smb2,
+                                     smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_echo_reply_async(struct smb2_context *smb2,
+                                     smb2_command_cb cb, void *cb_data);
+
+/*
+ * Asynchronous SMB2 Lock
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the logoff will be reported through the callback function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Lock was successful.
+ *
+ *   !0     : Status is NT status code.
+ *
+ * command_data is always NULL.
+ */
+struct smb2_pdu *smb2_cmd_lock_async(struct smb2_context *smb2,
+                                       struct smb2_lock_request *req,
+                                       smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_lock_reply_async(struct smb2_context *smb2,
+                                       smb2_command_cb cb, void *cb_data);
+
+/*
+ * Asynchronous SMB2 Logoff
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the logoff will be reported through the callback function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Logoff was successful.
+ *
+ *   !0     : Status is NT status code.
+ *
+ * command_data is always NULL.
+ */
+struct smb2_pdu *smb2_cmd_logoff_async(struct smb2_context *smb2,
+                                       smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_logoff_reply_async(struct smb2_context *smb2,
+                                       smb2_command_cb cb, void *cb_data);
+
+/*
+ * Asynchronous SMB2 Flush
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the flush will be reported through the callback function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Flush was successful.
+ *
+ *   !0     : Status is NT status code.
+ *
+ * command_data is always NULL.
+ */
+struct smb2_pdu *smb2_cmd_flush_async(struct smb2_context *smb2,
+                                      struct smb2_flush_request *req,
+                                      smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_flush_reply_async(struct smb2_context *smb2,
+                                      smb2_command_cb cb, void *cb_data);
+
+/*
+ * Asynchronous SMB2 oplock-break;
+ *
+ * Returns:
+ * pdu  : If the call was initiated and a connection will be attempted.
+ *        Result of the flush will be reported through the callback function.
+ * NULL : If there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : successful.
+ *
+ *   !0     : Status is NT status code.
+ *
+ * command_data is always NULL.
+ */
+struct smb2_pdu *smb2_cmd_oplock_break_async(struct smb2_context *smb2,
+                                      struct smb2_oplock_break_acknowledgement *req,
+                                      smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_oplock_break_reply_async(struct smb2_context *smb2,
+                                      struct smb2_oplock_break_reply *rep,
+                                      smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_oplock_break_notification_async(struct smb2_context *smb2,
+                                      struct smb2_oplock_break_notification *rep,
+                                      smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_lease_break_async(struct smb2_context *smb2,
+                                      struct smb2_lease_break_acknowledgement *req,
+                                      smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_lease_break_reply_async(struct smb2_context *smb2,
+                                      struct smb2_lease_break_reply *rep,
+                                      smb2_command_cb cb, void *cb_data);
+
+struct smb2_pdu *smb2_cmd_lease_break_notification_async(struct smb2_context *smb2,
+                                      struct smb2_lease_break_notification *req,
+                                      smb2_command_cb cb, void *cb_data);
+/*
+ *
+ */
+struct smb2_pdu *smb2_cmd_error_reply_async(struct smb2_context *smb2,
+                                      struct smb2_error_reply *rep,
+                                      uint8_t causing_command,
+                                      int status,
+                                      smb2_command_cb cb, void *cb_data);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_LIBSMB2_RAW_H_ */

+ 1406 - 0
entry/src/main/cpp/include/smb2/libsmb2.h

@@ -0,0 +1,1406 @@
+/* -*-  mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil;  -*- */
+/*
+   Copyright (C) 2016 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _LIBSMB2_H_
+#define _LIBSMB2_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define LIBSMB2_SHARE_ENUM_V2 1
+
+struct smb2_iovec {
+        uint8_t *buf;
+        size_t len;
+        void (*free)(void *);
+};
+
+struct smb2_context;
+
+/*
+ * Generic callback for completion of smb2_*_async().
+ * command_data depends on status.
+ */
+typedef void (*smb2_command_cb)(struct smb2_context *smb2, int status,
+                                void *command_data, void *cb_data);
+
+/*
+ * callback for getting error information when errors are set
+ * command_data depends on status.
+ */
+typedef void (*smb2_error_cb)(struct smb2_context *smb2,
+                                const char *error_string);
+
+/*
+ * callback for server accepting a new connection
+ */
+typedef int (*smb2_accepted_cb)(const int fd, void *cb_data);
+
+/*
+ * callback when a new connection is made to setup context
+ */
+typedef void (*smb2_client_connection)(struct smb2_context *smb2, void *cb_data);
+
+/*
+ * callback when a server notifies of an oplock or lease break
+ * the type of break is determined from the stuct_size in the request
+ * (notification) passed in.  the app can set the new oplock level
+ * or new lease state for the acknowledgement that will be sent back
+ */
+struct smb2_oplock_or_lease_break_reply;
+
+typedef void (*smb2_oplock_or_lease_break_cb)(struct smb2_context *smb2,
+           int status,
+           struct smb2_oplock_or_lease_break_reply *rep,
+           uint8_t *new_oplock_level,
+           uint32_t *new_lease_state);
+
+/* Stat structure */
+#define SMB2_TYPE_FILE      0x00000000
+#define SMB2_TYPE_DIRECTORY 0x00000001
+#define SMB2_TYPE_LINK      0x00000002
+struct smb2_stat_64 {
+        uint32_t smb2_type;
+        uint32_t smb2_nlink;
+        uint64_t smb2_ino;
+        uint64_t smb2_size;
+        uint64_t smb2_atime;
+        uint64_t smb2_atime_nsec;
+        uint64_t smb2_mtime;
+        uint64_t smb2_mtime_nsec;
+        uint64_t smb2_ctime;
+        uint64_t smb2_ctime_nsec;
+        uint64_t smb2_btime;
+        uint64_t smb2_btime_nsec;
+};
+
+struct smb2_statvfs {
+        uint32_t        f_bsize;
+        uint32_t        f_frsize;
+        uint64_t        f_blocks;
+        uint64_t        f_bfree;
+        uint64_t        f_bavail;
+        uint32_t        f_files;
+        uint32_t        f_ffree;
+        uint32_t        f_favail;
+        uint32_t        f_fsid;
+        uint32_t        f_flag;
+        uint32_t        f_namemax;
+};
+
+struct smb2dirent {
+        const char *name;
+        struct smb2_stat_64 st;
+};
+
+#if defined(_WINDOWS)
+#ifdef __USE_WINSOCK__
+#include <winsock.h>
+#else
+#include <ws2tcpip.h>
+#include <winsock2.h>
+#endif
+#elif defined(_XBOX)
+#include <xtl.h>
+#include <winsockx.h>
+#endif
+
+#if defined(_WINDOWS) || defined(_XBOX)
+typedef SOCKET t_socket;
+#else
+typedef int t_socket;
+#endif
+
+/*
+ * Create an SMB2 context.
+ * Function returns
+ *  NULL  : Failed to create a context.
+ *  *smb2 : A pointer to an smb2 context.
+ */
+struct smb2_context *smb2_init_context(void);
+
+/*
+ * Close an SMB2 context
+ *
+ * closes socket if open, and clears keys but leave
+ * context allocated.  the context will be destroyed
+ * at a time later when it won't be in-use
+ */
+void smb2_close_context(struct smb2_context *smb2);
+
+/*
+ * Destroy an smb2 context.
+ *
+ * Any open "struct smb2fh" will automatically be freed. You can not reference
+ * any "struct smb2fh" after the context is destroyed.
+ * Any open "struct smb2dir" will automatically be freed. You can not reference
+ * any "struct smb2dir" after the context is destroyed.
+ * Any pending async commands will be aborted with -ECONNRESET.
+ */
+void smb2_destroy_context(struct smb2_context *smb2);
+
+/*
+ * Get the list of currently allocated contexts
+ */
+struct smb2_context *smb2_active_contexts(void);
+
+/*
+ * Determine of the context is currently active.  This lets
+ * code know if the context was destroyed in a callback for example
+ */
+int smb2_context_active(struct smb2_context *smb2);
+
+/*
+ * EVENT SYSTEM INTEGRATION
+ * ========================
+ * The following functions are used to integrate libsmb2 in an event
+ * system.
+ *
+ * The simplest way is by using smb2_get_fd() and smb2_which_events()
+ * in every loop of the event system to detect which fd to use (it can change)
+ * and which events should be waited for.
+ * This is very simple to use but has the drawback of the overhead having to
+ * call these two functions for every loop.
+ *
+ * This is suitable for trivial apps where you roll your event system
+ * using select() or poll().
+ *
+ * See for example smb2-cat-async.c for an example on how to use these
+ * two functions in an event loop.
+ */
+/*
+ * Returns the file descriptor that libsmb2 uses.
+ */
+t_socket smb2_get_fd(struct smb2_context *smb2);
+/*
+ * Returns which events that we need to poll for for the smb2 file descriptor.
+ */
+int smb2_which_events(struct smb2_context *smb2);
+
+/*
+ * Returns file descriptors that libsmb2 use or is trying to connect to
+ *
+ * This function should be used when trying to connect with more than one
+ * addresses in parallel, cf. rfc8305: Happy Eyeballs.
+ *
+ * The timeout, in ms, is valid during the socket connection step. The caller
+ * should call smb2_service_fd() with fd = -1 when the timeout is reached.
+ * This will trigger a new socket connection on the next resolved address. All
+ * connecting fds will be closed when the first fd is connected. The timeout
+ * will be -1 (infinite) once connected or if there is no next addresses to
+ * connect to.
+ */
+const t_socket *
+smb2_get_fds(struct smb2_context *smb2, size_t *fd_count, int *timeout);
+
+/*
+ * A much more scalable way to use smb2_fd_event_callbacks() to register
+ * callbacks for libsmb2 to call anytime a filedescriptor is changed or when
+ * the  events we are waiting for changes.
+ * This way libsmb2 will do callbacks back into the application to inform
+ * when fd or events change.
+ *
+ * This is suitable when you want to plug libsmb2 into a more sophisticated
+ * eventsystem or if you use epoll() or similar.
+ *
+ * See for smb2-ls-async.c for a trivial example of using these callbacks.
+ */
+#define SMB2_ADD_FD 0
+#define SMB2_DEL_FD 1
+typedef void (*smb2_change_fd_cb)(struct smb2_context *smb2, t_socket fd, int cmd);
+typedef void (*smb2_change_events_cb)(struct smb2_context *smb2, t_socket fd,
+                                      int events);
+void smb2_fd_event_callbacks(struct smb2_context *smb2,
+                             smb2_change_fd_cb change_fd,
+                             smb2_change_events_cb change_events);
+
+/*
+ * Called to process the events when events become available for the smb2
+ * file descriptor.
+ *
+ * Returns:
+ *  0 : Success
+ * <0 : Unrecoverable failure. At this point the context can no longer be
+ *      used and must be freed by calling smb2_destroy_context().
+ *
+ */
+int smb2_service(struct smb2_context *smb2, int revents);
+
+/*
+ * Called to process the events when events become available for the smb2
+ * file descriptor.
+ *
+ * Behave like smb2_service() with some differences:
+ *  - must be called with a fd returned by smb2_get_fd() or smb2_get_fds(),
+ *  - passing -1 as fd will trigger a new connection attempt on the next
+ *  resolved address, cf. smb2_get_fds().
+ *
+ * Returns:
+ *  0 : Success
+ * <0 : Unrecoverable failure. At this point the context can no longer be
+ *      used and must be freed by calling smb2_destroy_context().
+ *
+ */
+int smb2_service_fd(struct smb2_context *smb2, t_socket fd, int revents);
+
+/*
+ * Set the timeout in seconds after which a command will be aborted with
+ * SMB2_STATUS_IO_TIMEOUT.
+ * If you use timeouts with the async API you must make sure to call
+ * smb2_service() at least once every second.
+ *
+ * Default is 0: No timeout.
+ */
+void smb2_set_timeout(struct smb2_context *smb2, int seconds);
+
+/*
+ * Set passthrough-enable.  Passthrough allows command packers
+ * and unpackers to keep the extra data on complex commands
+ * in its on-the-wire format without any interpretation. this
+ * is useful for proxy use cases where there might be no need
+ * to fully parse things like query-info replies or ioctl
+ * requests.  If passthrough is not set, any command that
+ * that is processed that can't interpret the data will fail
+ * Most client use case will not need this
+ *
+ * Default is 0: no-passthrough
+ */
+void smb2_set_passthrough(struct smb2_context *smb2,
+                      int passthrough);
+
+/*
+ * Get the current passthrough setting
+ */
+void smb2_get_passthrough(struct smb2_context *smb2,
+                      int *passthrough);
+
+/*
+ * Set which version of SMB to negotiate.
+ * Default is to let the server pick the version.
+ */
+enum smb2_negotiate_version {
+        SMB2_VERSION_ANY  = 0,
+        SMB2_VERSION_ANY2 = 2,
+        SMB2_VERSION_ANY3 = 3,
+        SMB2_VERSION_0202 = 0x0202,
+        SMB2_VERSION_0210 = 0x0210,
+        SMB2_VERSION_0300 = 0x0300,
+        SMB2_VERSION_0302 = 0x0302,
+        SMB2_VERSION_0311 = 0x0311,
+};
+
+#define SMB2_VERSION_WILDCARD 0x02FF
+
+void smb2_set_version(struct smb2_context *smb2,
+                      enum smb2_negotiate_version version);
+
+/*
+ * Sets which version libsmb2 uses.
+*/
+#define LIBSMB2_MAJOR_VERSION 4
+#define LIBSMB2_MINOR_VERSION 0
+#define LIBSMB2_PATCH_VERSION 0
+
+struct smb2_libversion
+{
+     uint8_t major_version;
+     uint8_t minor_version;
+     uint8_t patch_version;
+};
+
+/*
+ * Gets the libsmb2 version being linked while used.
+ * This function will be available on 5.x
+ * @param struct smb2_libversion
+*/
+void smb2_get_libsmb2Version(struct smb2_libversion *smb2_ver);
+
+/*
+ * gets the (currently) negotiated dialect
+ */
+uint16_t smb2_get_dialect(struct smb2_context *smb2);
+
+/*
+ * Set the security mode for the connection.
+ * This is a combination of the flags SMB2_NEGOTIATE_SIGNING_ENABLED
+ * and  SMB2_NEGOTIATE_SIGNING_REQUIRED
+ * Default is 0.
+ */
+void smb2_set_security_mode(struct smb2_context *smb2, uint16_t security_mode);
+
+/*
+ * Set whether smb3 encryption should be used or not.
+ * 0  : disable encryption. This is the default.
+ * !0 : enable encryption.
+ */
+void smb2_set_seal(struct smb2_context *smb2, int val);
+
+/*
+ * Set whether smb2 signing should be required or not
+ * 0  : do not require signing. This is the default.
+ * !0 : require signing.
+ */
+void smb2_set_sign(struct smb2_context *smb2, int val);
+
+enum smb2_sec {
+        SMB2_SEC_UNDEFINED = 0,
+        SMB2_SEC_NTLMSSP,
+        SMB2_SEC_KRB5,
+};
+
+/*
+ * Set authentication method.
+ * SMB2_SEC_UNDEFINED (use KRB if available or NTLM if not)
+ * SMB2_SEC_NTLMSSP
+ * SMB2_SEC_KRB5
+ */
+void smb2_set_authentication(struct smb2_context *smb2, int val);
+
+/*
+ * Set the username that we will try to authenticate as.
+ * Default is to try to authenticate as the current user.
+ */
+void smb2_set_user(struct smb2_context *smb2, const char *user);
+
+/*
+ * Get the username associated with a context.
+ * returns NULL if none
+ */
+const char *smb2_get_user(struct smb2_context *smb2);
+
+/*
+ * Set the password that we will try to authenticate as.
+ * This function is only needed when libsmb2 is built --without-libkrb5
+ */
+void smb2_set_password(struct smb2_context *smb2, const char *password);
+
+/*
+ * Convert a win timestamp to a unix timeval
+ */
+void smb2_win_to_timeval(uint64_t smb2_time, struct smb2_timeval *tv);
+
+/*
+ * Convert unit timeval to a win timestamp
+ */
+uint64_t smb2_timeval_to_win(struct smb2_timeval *tv);
+
+/*
+ * set the context error string
+ */
+void smb2_set_error(struct smb2_context *smb2,
+                    const char *error_string, ...);
+
+/*
+ * Register an error callback, so any calls to smb2_set_error will call this
+ * function with the error string generated
+ */
+void smb2_register_error_callback(struct smb2_context *smb,
+                    smb2_error_cb error_cb);
+
+/*
+ * register for oplock or lease break callbacks
+ */
+void smb2_set_oplock_or_lease_break_callback(struct smb2_context *smb2,
+                    smb2_oplock_or_lease_break_cb cb);
+
+/*
+ * Set the smb2 context passworkd from a file (see NTLM_USER_FILE)
+ * depends on user/domain being already set in smb2 context
+ */
+void smb2_set_password_from_file(struct smb2_context *smb2);
+
+/*
+ * Set the domain when authenticating.
+ * This function is only needed when libsmb2 is built --without-libkrb5
+ */
+void smb2_set_domain(struct smb2_context *smb2, const char *domain);
+
+/*
+ * Get the domain associated with a context.
+ * returns NULL if none
+ */
+const char *smb2_get_domain(struct smb2_context *smb2);
+/*
+ * Set the workstation when authenticating.
+ * This function is only needed when libsmb2 is built --without-libkrb5
+ */
+void smb2_set_workstation(struct smb2_context *smb2, const char *workstation);
+
+/*
+ * Get the workstation associated with a context.
+ * returns NULL if none
+ */
+const char *smb2_get_workstation(struct smb2_context *smb2);
+
+/*
+ * Sets the address to some user defined object. May be used to make
+ * additional context data available in the async callbacks.
+ */
+void smb2_set_opaque(struct smb2_context *smb2, void *opaque);
+
+/*
+ * Returns the opaque pointer set with smb2_set_opaque.
+ */
+void *smb2_get_opaque(struct smb2_context *smb2);
+
+/*
+ * copy credential handle from one context to another (and set
+ * it NULL in source context)
+ * returns 0 if handle transferred,
+ * or -1 if not (no handle or no context, or not applicable)
+ */
+int smb2_delegate_credentials(struct smb2_context *in, struct smb2_context *out);
+
+/*
+ * Sets the client_guid for this context.
+ */
+void smb2_set_client_guid(struct smb2_context *smb2, const uint8_t guid[SMB2_GUID_SIZE]);
+
+/*
+ * Returns the client_guid for this context.
+ */
+const char *smb2_get_client_guid(struct smb2_context *smb2);
+
+/*
+ * Asynchronous call to connect a TCP connection to the server
+ *
+ * Returns:
+ *  0 if the call was initiated and a connection will be attempted. Result of
+ * the connection will be reported through the callback function.
+ * <0 if there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Connection was successful. Command_data is NULL.
+ *
+ *   -errno : Failed to establish the connection. Command_data is NULL.
+ */
+int smb2_connect_async(struct smb2_context *smb2, const char *server,
+                       smb2_command_cb cb, void *cb_data);
+
+/*
+ * Async call to connect to a share.
+ * On unix, if user is NULL then default to the current user.
+ *
+ * Returns:
+ *  0 if the call was initiated and a connection will be attempted. Result of
+ * the connection will be reported through the callback function.
+ * -errno if there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Connection was successful. Command_data is NULL.
+ *
+ *   -errno : Failed to connect to the share. Command_data is NULL.
+ */
+int smb2_connect_share_async(struct smb2_context *smb2,
+                             const char *server,
+                             const char *share,
+                             const char *user,
+                             smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync call to connect to a share.
+ * On unix, if user is NULL then default to the current user.
+ *
+ * Returns:
+ * 0      : Connected to the share successfully.
+ * -errno : Failure.
+ */
+int smb2_connect_share(struct smb2_context *smb2,
+                       const char *server,
+                       const char *share,
+                       const char *user);
+
+/*
+ * Async call to disconnect from a share/
+ *
+ * Returns:
+ *  0 if the call was initiated and a connection will be attempted. Result of
+ * the disconnect will be reported through the callback function.
+ * -errno if there was an error. The callback function will not be invoked.
+ *
+ * Callback parameters :
+ * status can be either of :
+ *    0     : Connection was successful. Command_data is NULL.
+ *
+ *   -errno : Failed to disconnect the share. Command_data is NULL.
+ */
+int smb2_disconnect_share_async(struct smb2_context *smb2,
+                                smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync call to disconnect from a share/
+ *
+ * Returns:
+ * 0      : Disconnected from the share successfully.
+ * -errno : Failure.
+ */
+int smb2_disconnect_share(struct smb2_context *smb2);
+
+/*
+ * Select a tree id that was previously connected. Sets the tree_id
+ * in the context to be used for subsequent requests
+ *
+ * Returns:
+ * 0      : OK
+ * -errno : tree wasn't connected
+ */
+int smb2_select_tree_id(struct smb2_context *smb2, uint32_t tree_id);
+
+struct smb2_pdu;
+
+/*
+ * Get/Set the tree id of a pdu
+ *
+ * Returns:
+ * 0      : OK
+ * -errno : tree wasn't connected | no pdu | no context
+ */
+int smb2_get_tree_id_for_pdu(struct smb2_context *smb2, struct smb2_pdu *pdu, uint32_t *tree_id);
+int smb2_set_tree_id_for_pdu(struct smb2_context *smb2, struct smb2_pdu *pdu, uint32_t tree_id);
+
+/*
+ * Get session id
+ *
+ * Returns:
+ * 0      : OK
+ * -errno :
+ */
+int smb2_get_session_id(struct smb2_context *smb2, uint64_t *session_id);
+
+/*
+ * This function returns a description of the last encountered error.
+ */
+const char *smb2_get_error(struct smb2_context *smb2);
+
+int smb2_get_nterror(struct smb2_context *smb2);
+
+struct smb2_url {
+        const char *domain;
+        const char *user;
+        const char *server;
+        const char *share;
+        const char *path;
+};
+
+/* Convert an smb2/nt error code into a string */
+const char *nterror_to_str(uint32_t status);
+
+/* Convert an smb2/nt error code into an errno value */
+int nterror_to_errno(uint32_t status);
+
+/*
+ * This function is used to parse an SMB2 URL into as smb2_url structure.
+ * SMB2 URL format:
+ *   smb2://[<domain;][<username>@]<server>/<share>/<path>
+ * where <server> has the format:
+ *   <host>[:<port>].
+ *
+ * Function will return a pointer to an iscsi smb2 structure if successful,
+ * or it will return NULL and set smb2_get_error() accordingly if there was
+ * a problem with the URL.
+ *
+ * The returned structure is freed by calling smb2_destroy_url()
+ */
+struct smb2_url *smb2_parse_url(struct smb2_context *smb2, const char *url);
+void smb2_destroy_url(struct smb2_url *url);
+
+/*
+ * These functions are used when creating compound low level commands.
+ * The general pattern for compound chains is
+ * 1, pdu = smb2_cmd_*_async(smb2, ...)
+ *
+ * 2, next = smb2_cmd_*_async(smb2, ...)
+ * 3, smb2_add_compound_pdu(smb2, pdu, next);
+ *
+ * 4, next = smb2_cmd_*_async(smb2, ...)
+ * 5, smb2_add_compound_pdu(smb2, pdu, next);
+ * ...
+ * *, smb2_queue_pdu(smb2, pdu);
+ *
+ * See libsmb2.c and smb2-raw-stat-async.c for examples on how to use
+ * this interface.
+ */
+void smb2_add_compound_pdu(struct smb2_context *smb2,
+                           struct smb2_pdu *pdu, struct smb2_pdu *next_pdu);
+void smb2_free_pdu(struct smb2_context *smb2, struct smb2_pdu *pdu);
+void smb2_queue_pdu(struct smb2_context *smb2, struct smb2_pdu *pdu);
+
+/*
+ * These are used to access/modify pdus from application level
+ * useful for proxies, etc.
+ */
+struct smb2_pdu *smb2_get_compound_pdu(struct smb2_context *smb2,
+                           struct smb2_pdu *pdu);
+void smb2_set_pdu_status(struct smb2_context *smb2, struct smb2_pdu *pdu, int status);
+void smb2_set_pdu_message_id(struct smb2_context *smb2, struct smb2_pdu *pdu, uint64_t message_id);
+uint64_t smb2_get_pdu_message_id(struct smb2_context *smb2, struct smb2_pdu *pdu);
+uint64_t smb2_get_last_request_message_id(struct smb2_context *smb2);
+uint64_t smb2_get_last_reply_message_id(struct smb2_context *smb2);
+int smb2_pdu_is_compound(struct smb2_context *smb2);
+
+/*
+ * OPENDIR
+ */
+struct smb2dir;
+
+/*
+ * Async opendir()
+ *
+ * Returns
+ * pdu :    The operation was initiated. Result of the operation will be reported
+ *          through the callback function.
+ *          The pdu must be freed by smb2_free_pdu().
+ *          The pdu can be cancelled before the callback is invoked by freeing
+ *          it.
+ * NULL :   There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success.
+ *          Command_data is struct smb2dir.
+ *          This structure is freed using smb2_closedir().
+ * -errno : An error occurred.
+ *          Command_data is NULL.
+ */
+struct smb2_pdu *
+smb2_opendir_async_pdu(struct smb2_context *smb2, const char *path,
+                       smb2_command_cb cb, void *cb_data, void (*free_cb)(void *));
+
+/*
+ * Sync opendir()
+ *
+ * Returns NULL on failure.
+ */
+struct smb2dir *smb2_opendir(struct smb2_context *smb2, const char *path);
+
+int smb2_opendir_async(struct smb2_context *smb2, const char *path,
+                       smb2_command_cb cb, void *cb_data);
+        
+/*
+ * closedir()
+ */
+/*
+ * smb2_closedir() never blocks, thus no async version is needed.
+ */
+void smb2_closedir(struct smb2_context *smb2, struct smb2dir *smb2dir);
+
+/*
+ * readdir()
+ */
+/*
+ * smb2_readdir() never blocks, thus no async version is needed.
+ */
+struct smb2dirent *smb2_readdir(struct smb2_context *smb2,
+                                struct smb2dir *smb2dir);
+
+/*
+ * rewinddir()
+ */
+/*
+ * smb2_rewinddir() never blocks, thus no async version is needed.
+ */
+void smb2_rewinddir(struct smb2_context *smb2, struct smb2dir *smb2dir);
+
+/*
+ * telldir()
+ */
+/*
+ * smb2_telldir() never blocks, thus no async version is needed.
+ */
+long smb2_telldir(struct smb2_context *smb2, struct smb2dir *smb2dir);
+
+/*
+ * seekdir()
+ */
+/*
+ * smb2_seekdir() never blocks, thus no async version is needed.
+ */
+void smb2_seekdir(struct smb2_context *smb2, struct smb2dir *smb2dir,
+                  long loc);
+
+/*
+ * OPEN
+ */
+struct smb2fh;
+/*
+ * Async open()
+ *
+ * Returns
+ * pdu :    The operation was initiated. Result of the operation will be reported
+ *          through the callback function.
+ *          The pdu must be freed by smb2_free_pdu().
+ *          The pdu can be cancelled before the callback is invoked by freeing
+ *          it.
+ * NULL :   There was an error. The callback function will not be invoked.
+ *
+ * Opens or creates a file.
+ * Supported flags are:
+ * O_RDONLY
+ * O_WRONLY
+ * O_RDWR
+ * O_SYNC
+ * O_CREAT
+ * O_EXCL
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success.
+ *          Command_data is struct smb2fh.
+ *          This structure is freed using smb2_close().
+ * -errno : An error occurred.
+ *          Command_data is NULL.
+ */
+struct smb2_pdu *
+smb2_open_async_pdu(struct smb2_context *smb2, const char *path, int flags,
+                    smb2_command_cb cb, void *cb_data, void (*free_cb)(void *));
+        
+/*
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ */  
+int smb2_open_async_with_oplock_or_lease(struct smb2_context *smb2, const char *path, int flags,
+                    uint8_t oplock_level, uint32_t lease_state, smb2_lease_key lease_key,
+                    smb2_command_cb cb, void *cb_data);
+
+int smb2_open_async(struct smb2_context *smb2, const char *path, int flags,
+                    smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync open()
+ *
+ * Returns NULL on failure.
+ */
+struct smb2fh *smb2_open(struct smb2_context *smb2, const char *path, int flags);
+
+/*
+ * CLOSE
+ */
+/*
+ * Async close()
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success.
+ * -errno : An error occurred.
+ *
+ * Command_data is always NULL.
+ */
+int smb2_close_async(struct smb2_context *smb2, struct smb2fh *fh,
+                     smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync close()
+ */
+int smb2_close(struct smb2_context *smb2, struct smb2fh *fh);
+
+/*
+ * FSYNC
+ */
+/*
+ * Async fsync()
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success.
+ * -errno : An error occurred.
+ *
+ * Command_data is always NULL.
+ */
+int smb2_fsync_async(struct smb2_context *smb2, struct smb2fh *fh,
+                     smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync fsync()
+ */
+int smb2_fsync(struct smb2_context *smb2, struct smb2fh *fh);
+
+/*
+ * GetMaxReadWriteSize
+ * SMB2 servers have a maximum size for read/write data that they support.
+ */
+uint32_t smb2_get_max_read_size(struct smb2_context *smb2);
+uint32_t smb2_get_max_write_size(struct smb2_context *smb2);
+
+struct smb2_read_cb_data {
+        struct smb2fh *fh;
+        uint8_t *buf;
+        uint32_t count;
+        uint64_t offset;
+};
+
+struct smb2_write_cb_data {
+        struct smb2fh *fh;
+        const uint8_t *buf;
+        uint32_t count;
+        uint64_t offset;
+};
+
+/*
+ * PREAD
+ */
+/*
+ * Async pread()
+ * Use smb2_get_max_read_size to discover the maximum data size that the
+ * server supports.
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *    >=0 : Number of bytes read.
+ * -errno : An error occurred.
+ *
+ * Command_data is struct smb2_read_cb_data, which holds the arguments
+ * that were given to smb2_pread_async.
+ * This structure is automatically freed.
+ */
+int smb2_pread_async(struct smb2_context *smb2, struct smb2fh *fh,
+                     uint8_t *buf, uint32_t count, uint64_t offset,
+                     smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync pread()
+ * Use smb2_get_max_read_size to discover the maximum data size that the
+ * server supports.
+ */
+int smb2_pread(struct smb2_context *smb2, struct smb2fh *fh,
+               uint8_t *buf, uint32_t count, uint64_t offset);
+
+/*
+ * PWRITE
+ */
+/*
+ * Async pwrite()
+ * Use smb2_get_max_write_size to discover the maximum data size that the
+ * server supports.
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *    >=0 : Number of bytes written.
+ * -errno : An error occurred.
+ *
+ * Command_data is struct smb2_write_cb_data, which holds the arguments
+ * that were given to smb2_pwrite_async.
+ * This structure is automatically freed.
+ */
+int smb2_pwrite_async(struct smb2_context *smb2, struct smb2fh *fh,
+                      const uint8_t *buf, uint32_t count, uint64_t offset,
+                      smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync pwrite()
+ * Use smb2_get_max_write_size to discover the maximum data size that the
+ * server supports.
+ */
+int smb2_pwrite(struct smb2_context *smb2, struct smb2fh *fh,
+                const uint8_t *buf, uint32_t count, uint64_t offset);
+
+/*
+ * READ
+ */
+/*
+ * Async read()
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *    >=0 : Number of bytes read.
+ * -errno : An error occurred.
+ *
+ * Command_data is struct smb2_read_cb_data, which holds the arguments
+ * that were given to smb2_read_async. offset denotes the offset in the file
+ * at which the read took place.
+ * This structure is automatically freed.
+ */
+int smb2_read_async(struct smb2_context *smb2, struct smb2fh *fh,
+                    uint8_t *buf, uint32_t count,
+                    smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync read()
+ */
+int smb2_read(struct smb2_context *smb2, struct smb2fh *fh,
+              uint8_t *buf, uint32_t count);
+
+/*
+ * WRITE
+ */
+/*
+ * Async write()
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *    >=0 : Number of bytes written.
+ * -errno : An error occurred.
+ *
+ * Command_data is struct smb2_write_cb_data, which holds the arguments
+ * that were given to smb2_write_async. offset denotes the offset in the file
+ * at which the write took place.
+ * This structure is automatically freed.
+ */
+int smb2_write_async(struct smb2_context *smb2, struct smb2fh *fh,
+                     const uint8_t *buf, uint32_t count,
+                     smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync write()
+ */
+int smb2_write(struct smb2_context *smb2, struct smb2fh *fh,
+               const uint8_t *buf, uint32_t count);
+
+/*
+ * Sync lseek()
+ */
+/*
+ * smb2_seek() SEEK_SET and SEEK_CUR are fully supported.
+ * SEEK_END only returns the end-of-file from the original open.
+ * (it will not call fstat to discover the current file size and will not block)
+ */
+int64_t smb2_lseek(struct smb2_context *smb2, struct smb2fh *fh,
+                   int64_t offset, int whence, uint64_t *current_offset);
+
+/*
+ * UNLINK
+ */
+/*
+ * Async unlink()
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success.
+ * -errno : An error occurred.
+ *
+ * Command_data is always NULL.
+ */
+int smb2_unlink_async(struct smb2_context *smb2, const char *path,
+                      smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync unlink()
+ */
+int smb2_unlink(struct smb2_context *smb2, const char *path);
+
+/*
+ * RMDIR
+ */
+/*
+ * Async rmdir()
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success.
+ * -errno : An error occurred.
+ *
+ * Command_data is always NULL.
+ */
+int smb2_rmdir_async(struct smb2_context *smb2, const char *path,
+                     smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync rmdir()
+ */
+int smb2_rmdir(struct smb2_context *smb2, const char *path);
+
+/*
+ * MKDIR
+ */
+/*
+ * Async mkdir()
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success.
+ * -errno : An error occurred.
+ *
+ * Command_data is always NULL.
+ */
+int smb2_mkdir_async(struct smb2_context *smb2, const char *path,
+                     smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync mkdir()
+ */
+int smb2_mkdir(struct smb2_context *smb2, const char *path);
+
+/*
+ * STATVFS
+ */
+/*
+ * Async statvfs()
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success. Command_data is struct smb2_statvfs
+ * -errno : An error occurred.
+ */
+int smb2_statvfs_async(struct smb2_context *smb2, const char *path,
+                       struct smb2_statvfs *statvfs,
+                       smb2_command_cb cb, void *cb_data);
+/*
+ * Sync statvfs()
+ */
+int smb2_statvfs(struct smb2_context *smb2, const char *path,
+                 struct smb2_statvfs *statvfs);
+
+/*
+ * FSTAT
+ */
+/*
+ * Async fstat()
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success. Command_data is struct smb2_stat_64
+ * -errno : An error occurred.
+ */
+int smb2_fstat_async(struct smb2_context *smb2, struct smb2fh *fh,
+                     struct smb2_stat_64 *st,
+                     smb2_command_cb cb, void *cb_data);
+/*
+ * Sync fstat()
+ */
+int smb2_fstat(struct smb2_context *smb2, struct smb2fh *fh,
+               struct smb2_stat_64 *st);
+
+/*
+ * Async stat()
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success. Command_data is struct smb2_stat_64
+ * -errno : An error occurred.
+ */
+int smb2_stat_async(struct smb2_context *smb2, const char *path,
+                    struct smb2_stat_64 *st,
+                    smb2_command_cb cb, void *cb_data);
+/*
+ * Sync stat()
+ */
+int smb2_stat(struct smb2_context *smb2, const char *path,
+              struct smb2_stat_64 *st);
+
+/*
+ * Async rename()
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success.
+ * -errno : An error occurred.
+ */
+int smb2_rename_async(struct smb2_context *smb2, const char *oldpath,
+                      const char *newpath, smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync rename()
+ */
+int smb2_rename(struct smb2_context *smb2, const char *oldpath,
+              const char *newpath);
+
+/*
+ * Async truncate()
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success.
+ * -errno : An error occurred.
+ */
+int smb2_truncate_async(struct smb2_context *smb2, const char *path,
+                        uint64_t length, smb2_command_cb cb, void *cb_data);
+/*
+ * Sync truncate()
+ * Function returns
+ *      0 : Success
+ * -errno : An error occurred.
+ */
+int smb2_truncate(struct smb2_context *smb2, const char *path,
+                  uint64_t length);
+
+/*
+ * Async ftruncate()
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success.
+ * -errno : An error occurred.
+ */
+int smb2_ftruncate_async(struct smb2_context *smb2, struct smb2fh *fh,
+                         uint64_t length, smb2_command_cb cb, void *cb_data);
+/*
+ * Sync ftruncate()
+ * Function returns
+ *      0 : Success
+ * -errno : An error occurred.
+ */
+int smb2_ftruncate(struct smb2_context *smb2, struct smb2fh *fh,
+                   uint64_t length);
+
+
+/*
+ * READLINK
+ */
+/*
+ * Async readlink()
+ *
+ * Returns
+ *  0     : The operation was initiated. The link content will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success. Command_data is the link content.
+ * -errno : An error occurred.
+ */
+int smb2_readlink_async(struct smb2_context *smb2, const char *path,
+                        smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync readlink()
+ */
+int smb2_readlink(struct smb2_context *smb2, const char *path, char *buf, uint32_t bufsiz);
+
+/*
+ * Async echo()
+ *
+ * Returns
+ *  0     : The operation was initiated. Result of the operation will be
+ *          reported through the callback function.
+ * -errno : There was an error. The callback function will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success.
+ * -errno : An error occurred.
+ */
+int smb2_echo_async(struct smb2_context *smb2,
+                    smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync echo()
+ *
+ * Returns:
+ * 0      : successfully send the message and received a reply.
+ * -errno : Failure.
+ */
+int smb2_echo(struct smb2_context *smb2);
+
+void
+free_smb2_file_notify_change_information(struct smb2_context *smb2, struct smb2_file_notify_change_information *fnc);
+
+int smb2_notify_change_async(struct smb2_context *smb2, const char *path, uint16_t flags, uint32_t filter, int loop,
+                       smb2_command_cb cb, void *cb_data);
+
+int smb2_notify_change_filehandle_async(struct smb2_context *smb2, struct smb2fh *smb2_dir_fh, uint16_t flags, uint32_t filter, int loop,
+                       smb2_command_cb cb, void *cb_data);
+
+/*
+ * Sync notify_change()
+ *
+ */
+struct smb2_file_notify_change_information *smb2_notify_change(struct smb2_context *smb2, const char *path, uint16_t flags, uint32_t filter);
+
+/* Utilities that help by being public
+*/
+
+/* SMB's UTF-16 is always in Little Endian */
+struct smb2_utf16 {
+        int len;
+        uint16_t val[1];
+};
+
+/* Returns a string converted to UTF-16 format. Use free() to release
+ * the utf16 string.
+ */
+struct smb2_utf16 *smb2_utf8_to_utf16(const char *utf8);
+
+/* Returns a string converted to UTF8 format. Use free() to release
+ * the utf8 string.
+ */
+const char *smb2_utf16_to_utf8(const uint16_t *str, size_t len);
+
+/************* Server-side API **********************************************/
+struct smb2_server;
+
+/* pdu handlers in general take the request from the client, and return
+ * < 0  on error, and the library should create an error reply
+ * == 0 on OK, and the library should use the reply struct (if needed) to create a reply
+ * > 0  if the handler created and queued a reply itself
+ */
+struct smb2_server_request_handlers {
+        int (*destruction_event)(struct smb2_server *srvr, struct smb2_context *smb2);
+        int (*authorize_user)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            const char *user,
+                            const char *domain,
+                            const char *workstation);
+        int (*session_established)(struct smb2_server *srvr, struct smb2_context *smb2);
+        int (*logoff_cmd)(struct smb2_server *srvr, struct smb2_context *smb2);
+        int (*tree_connect_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            struct smb2_tree_connect_request *req,
+                            struct smb2_tree_connect_reply *rep);
+        int (*tree_disconnect_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            const uint32_t tree_id);
+        int (*create_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            struct smb2_create_request *req,
+                            struct smb2_create_reply *rep);
+        int (*close_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            struct smb2_close_request *req,
+                            struct smb2_close_reply *rep);
+        int (*flush_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            struct smb2_flush_request *req);
+        int (*read_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            struct smb2_read_request *req,
+                            struct smb2_read_reply *rep);
+        int (*write_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            struct smb2_write_request *req,
+                            struct smb2_write_reply *rep);
+        int (*oplock_break_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            struct smb2_oplock_break_acknowledgement *req);
+        int (*lease_break_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            struct smb2_lease_break_acknowledgement *req);
+        int (*lock_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            struct smb2_lock_request *req);
+        int (*ioctl_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            struct smb2_ioctl_request *req,
+                            struct smb2_ioctl_reply *rep);
+        int (*cancel_cmd)(struct smb2_server *srvr, struct smb2_context *smb2);
+        int (*echo_cmd)(struct smb2_server *srvr, struct smb2_context *smb2);
+        int (*query_directory_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            struct smb2_query_directory_request *req,
+                            struct smb2_query_directory_reply *rep);
+        int (*change_notify_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            struct smb2_change_notify_request *req,
+                            struct smb2_change_notify_reply *rep);
+        int (*query_info_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            struct smb2_query_info_request *req,
+                            struct smb2_query_info_reply *rep);
+        int (*set_info_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            struct smb2_set_info_request *req);
+        /*
+        int (*oplock_break cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
+                            struct smb2_oplock_break_request *req);
+        */
+};
+
+struct smb2_server {
+        uint8_t guid[16];
+        char hostname[128];
+        char domain[128];
+        int fd;
+        uint16_t port;
+        uint64_t session_counter;
+        struct smb2_server_request_handlers *handlers;
+        uint32_t max_transact_size;
+        uint32_t max_read_size;
+        uint32_t max_write_size;
+        int signing_enabled;
+        int allow_anonymous;
+        /* this can be set non-0 to delegate client authentication to
+         * another client and allow any authentication to this server */
+        int proxy_authentication;
+        /* saved from negotiate to be used in validate negotiate info */
+        uint32_t capabilities;
+        uint32_t security_mode;
+        /* for kerberos, credential context */
+        char keytab_path[256];
+        char error[128];
+        void *auth_data;
+};
+
+int smb2_bind_and_listen(const uint16_t port, const int max_connections, int *out_fd);
+int smb2_accept_connection_async(const int fd, const int to_msecs, smb2_accepted_cb cb, void *cb_data);
+int smb2_serve_port_async(const int fd, const int to_msecs, struct smb2_context **out_smb2);
+
+/*
+ * Sync serve port()
+ *
+ * Returns
+ *  0     : The server is complete by exiting its loop normally (shouldnt happen)
+ * -errno : There was an error causing server loop to exit
+ */
+int smb2_serve_port(struct smb2_server *server, const int max_connections, smb2_client_connection cb, void *cb_data);
+
+/*
+ * Some symbols have moved over to a different header file to allow better
+ * separation between dcerpc and smb2, so we need to include this header
+ * here to retain compatibility for apps that depend on those symbols.
+ */
+#include <smb2/libsmb2-dcerpc-srvsvc.h>
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !_LIBSMB2_H_ */

+ 549 - 0
entry/src/main/cpp/include/smb2/smb2-errors.h

@@ -0,0 +1,549 @@
+/* -*-  mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil;  -*- */
+/*
+   Copyright (C) 2016 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+/*
+ * NTSTATUS fields
+ */
+#define SMB2_STATUS_SEVERITY_MASK    0xc0000000
+#define SMB2_STATUS_SEVERITY_SUCCESS 0x00000000
+#define SMB2_STATUS_SEVERITY_INFO    0x40000000
+#define SMB2_STATUS_SEVERITY_WARNING 0x80000000
+#define SMB2_STATUS_SEVERITY_ERROR   0xc0000000
+
+#define SMB2_STATUS_CUSTOMER_MASK    0x20000000
+
+#define SMB2_STATUS_FACILITY_MASK    0x0fff0000
+
+#define SMB2_STATUS_CODE_MASK        0x0000ffff
+
+
+/* Error codes */
+#define SMB2_STATUS_SUCCESS                            0x00000000
+#define SMB2_STATUS_SHUTDOWN                           0xffffffff
+#define SMB2_STATUS_PENDING                            0x00000103
+#define SMB2_STATUS_SMB_BAD_FID                        0x00060001
+#define SMB2_STATUS_NO_MORE_FILES                      0x80000006
+#define SMB2_STATUS_UNSUCCESSFUL                       0xC0000001
+#define SMB2_STATUS_NOT_IMPLEMENTED                    0xC0000002
+#define SMB2_STATUS_INVALID_INFO_CLASS                 0xC0000003
+#define SMB2_STATUS_INFO_LENGTH_MISMATCH               0xC0000004
+#define SMB2_STATUS_ACCESS_VIOLATION                   0xC0000005
+#define SMB2_STATUS_IN_PAGE_ERROR                      0xC0000006
+#define SMB2_STATUS_PAGEFILE_QUOTA                     0xC0000007
+#define SMB2_STATUS_INVALID_HANDLE                     0xC0000008
+#define SMB2_STATUS_BAD_INITIAL_STACK                  0xC0000009
+#define SMB2_STATUS_BAD_INITIAL_PC                     0xC000000A
+#define SMB2_STATUS_INVALID_CID                        0xC000000B
+#define SMB2_STATUS_TIMER_NOT_CANCELED                 0xC000000C
+#define SMB2_STATUS_INVALID_PARAMETER                  0xC000000D
+#define SMB2_STATUS_NO_SUCH_DEVICE                     0xC000000E
+#define SMB2_STATUS_NO_SUCH_FILE                       0xC000000F
+#define SMB2_STATUS_INVALID_DEVICE_REQUEST             0xC0000010
+#define SMB2_STATUS_END_OF_FILE                        0xC0000011
+#define SMB2_STATUS_WRONG_VOLUME                       0xC0000012
+#define SMB2_STATUS_NO_MEDIA_IN_DEVICE                 0xC0000013
+#define SMB2_STATUS_UNRECOGNIZED_MEDIA                 0xC0000014
+#define SMB2_STATUS_NONEXISTENT_SECTOR                 0xC0000015
+#define SMB2_STATUS_MORE_PROCESSING_REQUIRED           0xC0000016
+#define SMB2_STATUS_NO_MEMORY                          0xC0000017
+#define SMB2_STATUS_CONFLICTING_ADDRESSES              0xC0000018
+#define SMB2_STATUS_NOT_MAPPED_VIEW                    0xC0000019
+#define SMB2_STATUS_UNABLE_TO_FREE_VM                  0xC000001A
+#define SMB2_STATUS_UNABLE_TO_DELETE_SECTION           0xC000001B
+#define SMB2_STATUS_INVALID_SYSTEM_SERVICE             0xC000001C
+#define SMB2_STATUS_ILLEGAL_INSTRUCTION                0xC000001D
+#define SMB2_STATUS_INVALID_LOCK_SEQUENCE              0xC000001E
+#define SMB2_STATUS_INVALID_VIEW_SIZE                  0xC000001F
+#define SMB2_STATUS_INVALID_FILE_FOR_SECTION           0xC0000020
+#define SMB2_STATUS_ALREADY_COMMITTED                  0xC0000021
+#define SMB2_STATUS_ACCESS_DENIED                      0xC0000022
+#define SMB2_STATUS_BUFFER_TOO_SMALL                   0xC0000023
+#define SMB2_STATUS_OBJECT_TYPE_MISMATCH               0xC0000024
+#define SMB2_STATUS_NONCONTINUABLE_EXCEPTION           0xC0000025
+#define SMB2_STATUS_INVALID_DISPOSITION                0xC0000026
+#define SMB2_STATUS_UNWIND                             0xC0000027
+#define SMB2_STATUS_BAD_STACK                          0xC0000028
+#define SMB2_STATUS_INVALID_UNWIND_TARGET              0xC0000029
+#define SMB2_STATUS_NOT_LOCKED                         0xC000002A
+#define SMB2_STATUS_PARITY_ERROR                       0xC000002B
+#define SMB2_STATUS_UNABLE_TO_DECOMMIT_VM              0xC000002C
+#define SMB2_STATUS_NOT_COMMITTED                      0xC000002D
+#define SMB2_STATUS_INVALID_PORT_ATTRIBUTES            0xC000002E
+#define SMB2_STATUS_PORT_MESSAGE_TOO_LONG              0xC000002F
+#define SMB2_STATUS_INVALID_PARAMETER_MIX              0xC0000030
+#define SMB2_STATUS_INVALID_QUOTA_LOWER                0xC0000031
+#define SMB2_STATUS_DISK_CORRUPT_ERROR                 0xC0000032
+#define SMB2_STATUS_OBJECT_NAME_INVALID                0xC0000033
+#define SMB2_STATUS_OBJECT_NAME_NOT_FOUND              0xC0000034
+#define SMB2_STATUS_OBJECT_NAME_COLLISION              0xC0000035
+#define SMB2_STATUS_HANDLE_NOT_WAITABLE                0xC0000036
+#define SMB2_STATUS_PORT_DISCONNECTED                  0xC0000037
+#define SMB2_STATUS_DEVICE_ALREADY_ATTACHED            0xC0000038
+#define SMB2_STATUS_OBJECT_PATH_INVALID                0xC0000039
+#define SMB2_STATUS_OBJECT_PATH_NOT_FOUND              0xC000003A
+#define SMB2_STATUS_OBJECT_PATH_SYNTAX_BAD             0xC000003B
+#define SMB2_STATUS_DATA_OVERRUN                       0xC000003C
+#define SMB2_STATUS_DATA_LATE_ERROR                    0xC000003D
+#define SMB2_STATUS_DATA_ERROR                         0xC000003E
+#define SMB2_STATUS_CRC_ERROR                          0xC000003F
+#define SMB2_STATUS_SECTION_TOO_BIG                    0xC0000040
+#define SMB2_STATUS_PORT_CONNECTION_REFUSED            0xC0000041
+#define SMB2_STATUS_INVALID_PORT_HANDLE                0xC0000042
+#define SMB2_STATUS_SHARING_VIOLATION                  0xC0000043
+#define SMB2_STATUS_QUOTA_EXCEEDED                     0xC0000044
+#define SMB2_STATUS_INVALID_PAGE_PROTECTION            0xC0000045
+#define SMB2_STATUS_MUTANT_NOT_OWNED                   0xC0000046
+#define SMB2_STATUS_SEMAPHORE_LIMIT_EXCEEDED           0xC0000047
+#define SMB2_STATUS_PORT_ALREADY_SET                   0xC0000048
+#define SMB2_STATUS_SECTION_NOT_IMAGE                  0xC0000049
+#define SMB2_STATUS_SUSPEND_COUNT_EXCEEDED             0xC000004A
+#define SMB2_STATUS_THREAD_IS_TERMINATING              0xC000004B
+#define SMB2_STATUS_BAD_WORKING_SET_LIMIT              0xC000004C
+#define SMB2_STATUS_INCOMPATIBLE_FILE_MAP              0xC000004D
+#define SMB2_STATUS_SECTION_PROTECTION                 0xC000004E
+#define SMB2_STATUS_EAS_NOT_SUPPORTED                  0xC000004F
+#define SMB2_STATUS_EA_TOO_LARGE                       0xC0000050
+#define SMB2_STATUS_NONEXISTENT_EA_ENTRY               0xC0000051
+#define SMB2_STATUS_NO_EAS_ON_FILE                     0xC0000052
+#define SMB2_STATUS_EA_CORRUPT_ERROR                   0xC0000053
+#define SMB2_STATUS_FILE_LOCK_CONFLICT                 0xC0000054
+#define SMB2_STATUS_LOCK_NOT_GRANTED                   0xC0000055
+#define SMB2_STATUS_DELETE_PENDING                     0xC0000056
+#define SMB2_STATUS_CTL_FILE_NOT_SUPPORTED             0xC0000057
+#define SMB2_STATUS_UNKNOWN_REVISION                   0xC0000058
+#define SMB2_STATUS_REVISION_MISMATCH                  0xC0000059
+#define SMB2_STATUS_INVALID_OWNER                      0xC000005A
+#define SMB2_STATUS_INVALID_PRIMARY_GROUP              0xC000005B
+#define SMB2_STATUS_NO_IMPERSONATION_TOKEN             0xC000005C
+#define SMB2_STATUS_CANT_DISABLE_MANDATORY             0xC000005D
+#define SMB2_STATUS_NO_LOGON_SERVERS                   0xC000005E
+#define SMB2_STATUS_NO_SUCH_LOGON_SESSION              0xC000005F
+#define SMB2_STATUS_NO_SUCH_PRIVILEGE                  0xC0000060
+#define SMB2_STATUS_PRIVILEGE_NOT_HELD                 0xC0000061
+#define SMB2_STATUS_INVALID_ACCOUNT_NAME               0xC0000062
+#define SMB2_STATUS_USER_EXISTS                        0xC0000063
+#define SMB2_STATUS_NO_SUCH_USER                       0xC0000064
+#define SMB2_STATUS_GROUP_EXISTS                       0xC0000065
+#define SMB2_STATUS_NO_SUCH_GROUP                      0xC0000066
+#define SMB2_STATUS_MEMBER_IN_GROUP                    0xC0000067
+#define SMB2_STATUS_MEMBER_NOT_IN_GROUP                0xC0000068
+#define SMB2_STATUS_LAST_ADMIN                         0xC0000069
+#define SMB2_STATUS_WRONG_PASSWORD                     0xC000006A
+#define SMB2_STATUS_ILL_FORMED_PASSWORD                0xC000006B
+#define SMB2_STATUS_PASSWORD_RESTRICTION               0xC000006C
+#define SMB2_STATUS_LOGON_FAILURE                      0xC000006D
+#define SMB2_STATUS_ACCOUNT_RESTRICTION                0xC000006E
+#define SMB2_STATUS_INVALID_LOGON_HOURS                0xC000006F
+#define SMB2_STATUS_INVALID_WORKSTATION                0xC0000070
+#define SMB2_STATUS_PASSWORD_EXPIRED                   0xC0000071
+#define SMB2_STATUS_ACCOUNT_DISABLED                   0xC0000072
+#define SMB2_STATUS_NONE_MAPPED                        0xC0000073
+#define SMB2_STATUS_TOO_MANY_LUIDS_REQUESTED           0xC0000074
+#define SMB2_STATUS_LUIDS_EXHAUSTED                    0xC0000075
+#define SMB2_STATUS_INVALID_SUB_AUTHORITY              0xC0000076
+#define SMB2_STATUS_INVALID_ACL                        0xC0000077
+#define SMB2_STATUS_INVALID_SID                        0xC0000078
+#define SMB2_STATUS_INVALID_SECURITY_DESCR             0xC0000079
+#define SMB2_STATUS_PROCEDURE_NOT_FOUND                0xC000007A
+#define SMB2_STATUS_INVALID_IMAGE_FORMAT               0xC000007B
+#define SMB2_STATUS_NO_TOKEN                           0xC000007C
+#define SMB2_STATUS_BAD_INHERITANCE_ACL                0xC000007D
+#define SMB2_STATUS_RANGE_NOT_LOCKED                   0xC000007E
+#define SMB2_STATUS_DISK_FULL                          0xC000007F
+#define SMB2_STATUS_SERVER_DISABLED                    0xC0000080
+#define SMB2_STATUS_SERVER_NOT_DISABLED                0xC0000081
+#define SMB2_STATUS_TOO_MANY_GUIDS_REQUESTED           0xC0000082
+#define SMB2_STATUS_GUIDS_EXHAUSTED                    0xC0000083
+#define SMB2_STATUS_INVALID_ID_AUTHORITY               0xC0000084
+#define SMB2_STATUS_AGENTS_EXHAUSTED                   0xC0000085
+#define SMB2_STATUS_INVALID_VOLUME_LABEL               0xC0000086
+#define SMB2_STATUS_SECTION_NOT_EXTENDED               0xC0000087
+#define SMB2_STATUS_NOT_MAPPED_DATA                    0xC0000088
+#define SMB2_STATUS_RESOURCE_DATA_NOT_FOUND            0xC0000089
+#define SMB2_STATUS_RESOURCE_TYPE_NOT_FOUND            0xC000008A
+#define SMB2_STATUS_RESOURCE_NAME_NOT_FOUND            0xC000008B
+#define SMB2_STATUS_ARRAY_BOUNDS_EXCEEDED              0xC000008C
+#define SMB2_STATUS_FLOAT_DENORMAL_OPERAND             0xC000008D
+#define SMB2_STATUS_FLOAT_DIVIDE_BY_ZERO               0xC000008E
+#define SMB2_STATUS_FLOAT_INEXACT_RESULT               0xC000008F
+#define SMB2_STATUS_FLOAT_INVALID_OPERATION            0xC0000090
+#define SMB2_STATUS_FLOAT_OVERFLOW                     0xC0000091
+#define SMB2_STATUS_FLOAT_STACK_CHECK                  0xC0000092
+#define SMB2_STATUS_FLOAT_UNDERFLOW                    0xC0000093
+#define SMB2_STATUS_INTEGER_DIVIDE_BY_ZERO             0xC0000094
+#define SMB2_STATUS_INTEGER_OVERFLOW                   0xC0000095
+#define SMB2_STATUS_PRIVILEGED_INSTRUCTION             0xC0000096
+#define SMB2_STATUS_TOO_MANY_PAGING_FILES              0xC0000097
+#define SMB2_STATUS_FILE_INVALID                       0xC0000098
+#define SMB2_STATUS_ALLOTTED_SPACE_EXCEEDED            0xC0000099
+#define SMB2_STATUS_INSUFFICIENT_RESOURCES             0xC000009A
+#define SMB2_STATUS_DFS_EXIT_PATH_FOUND                0xC000009B
+#define SMB2_STATUS_DEVICE_DATA_ERROR                  0xC000009C
+#define SMB2_STATUS_DEVICE_NOT_CONNECTED               0xC000009D
+#define SMB2_STATUS_DEVICE_POWER_FAILURE               0xC000009E
+#define SMB2_STATUS_FREE_VM_NOT_AT_BASE                0xC000009F
+#define SMB2_STATUS_MEMORY_NOT_ALLOCATED               0xC00000A0
+#define SMB2_STATUS_WORKING_SET_QUOTA                  0xC00000A1
+#define SMB2_STATUS_MEDIA_WRITE_PROTECTED              0xC00000A2
+#define SMB2_STATUS_DEVICE_NOT_READY                   0xC00000A3
+#define SMB2_STATUS_INVALID_GROUP_ATTRIBUTES           0xC00000A4
+#define SMB2_STATUS_BAD_IMPERSONATION_LEVEL            0xC00000A5
+#define SMB2_STATUS_CANT_OPEN_ANONYMOUS                0xC00000A6
+#define SMB2_STATUS_BAD_VALIDATION_CLASS               0xC00000A7
+#define SMB2_STATUS_BAD_TOKEN_TYPE                     0xC00000A8
+#define SMB2_STATUS_BAD_MASTER_BOOT_RECORD             0xC00000A9
+#define SMB2_STATUS_INSTRUCTION_MISALIGNMENT           0xC00000AA
+#define SMB2_STATUS_INSTANCE_NOT_AVAILABLE             0xC00000AB
+#define SMB2_STATUS_PIPE_NOT_AVAILABLE                 0xC00000AC
+#define SMB2_STATUS_INVALID_PIPE_STATE                 0xC00000AD
+#define SMB2_STATUS_PIPE_BUSY                          0xC00000AE
+#define SMB2_STATUS_ILLEGAL_FUNCTION                   0xC00000AF
+#define SMB2_STATUS_PIPE_DISCONNECTED                  0xC00000B0
+#define SMB2_STATUS_PIPE_CLOSING                       0xC00000B1
+#define SMB2_STATUS_PIPE_CONNECTED                     0xC00000B2
+#define SMB2_STATUS_PIPE_LISTENING                     0xC00000B3
+#define SMB2_STATUS_INVALID_READ_MODE                  0xC00000B4
+#define SMB2_STATUS_IO_TIMEOUT                         0xC00000B5
+#define SMB2_STATUS_FILE_FORCED_CLOSED                 0xC00000B6
+#define SMB2_STATUS_PROFILING_NOT_STARTED              0xC00000B7
+#define SMB2_STATUS_PROFILING_NOT_STOPPED              0xC00000B8
+#define SMB2_STATUS_COULD_NOT_INTERPRET                0xC00000B9
+#define SMB2_STATUS_FILE_IS_A_DIRECTORY                0xC00000BA
+#define SMB2_STATUS_NOT_SUPPORTED                      0xC00000BB
+#define SMB2_STATUS_REMOTE_NOT_LISTENING               0xC00000BC
+#define SMB2_STATUS_DUPLICATE_NAME                     0xC00000BD
+#define SMB2_STATUS_BAD_NETWORK_PATH                   0xC00000BE
+#define SMB2_STATUS_NETWORK_BUSY                       0xC00000BF
+#define SMB2_STATUS_DEVICE_DOES_NOT_EXIST              0xC00000C0
+#define SMB2_STATUS_TOO_MANY_COMMANDS                  0xC00000C1
+#define SMB2_STATUS_ADAPTER_HARDWARE_ERROR             0xC00000C2
+#define SMB2_STATUS_INVALID_NETWORK_RESPONSE           0xC00000C3
+#define SMB2_STATUS_UNEXPECTED_NETWORK_ERROR           0xC00000C4
+#define SMB2_STATUS_BAD_REMOTE_ADAPTER                 0xC00000C5
+#define SMB2_STATUS_PRINT_QUEUE_FULL                   0xC00000C6
+#define SMB2_STATUS_NO_SPOOL_SPACE                     0xC00000C7
+#define SMB2_STATUS_PRINT_CANCELLED                    0xC00000C8
+#define SMB2_STATUS_NETWORK_NAME_DELETED               0xC00000C9
+#define SMB2_STATUS_NETWORK_ACCESS_DENIED              0xC00000CA
+#define SMB2_STATUS_BAD_DEVICE_TYPE                    0xC00000CB
+#define SMB2_STATUS_BAD_NETWORK_NAME                   0xC00000CC
+#define SMB2_STATUS_TOO_MANY_NAMES                     0xC00000CD
+#define SMB2_STATUS_TOO_MANY_SESSIONS                  0xC00000CE
+#define SMB2_STATUS_SHARING_PAUSED                     0xC00000CF
+#define SMB2_STATUS_REQUEST_NOT_ACCEPTED               0xC00000D0
+#define SMB2_STATUS_REDIRECTOR_PAUSED                  0xC00000D1
+#define SMB2_STATUS_NET_WRITE_FAULT                    0xC00000D2
+#define SMB2_STATUS_PROFILING_AT_LIMIT                 0xC00000D3
+#define SMB2_STATUS_NOT_SAME_DEVICE                    0xC00000D4
+#define SMB2_STATUS_FILE_RENAMED                       0xC00000D5
+#define SMB2_STATUS_VIRTUAL_CIRCUIT_CLOSED             0xC00000D6
+#define SMB2_STATUS_NO_SECURITY_ON_OBJECT              0xC00000D7
+#define SMB2_STATUS_CANT_WAIT                          0xC00000D8
+#define SMB2_STATUS_PIPE_EMPTY                         0xC00000D9
+#define SMB2_STATUS_CANT_ACCESS_DOMAIN_INFO            0xC00000DA
+#define SMB2_STATUS_CANT_TERMINATE_SELF                0xC00000DB
+#define SMB2_STATUS_INVALID_SERVER_STATE               0xC00000DC
+#define SMB2_STATUS_INVALID_DOMAIN_STATE               0xC00000DD
+#define SMB2_STATUS_INVALID_DOMAIN_ROLE                0xC00000DE
+#define SMB2_STATUS_NO_SUCH_DOMAIN                     0xC00000DF
+#define SMB2_STATUS_DOMAIN_EXISTS                      0xC00000E0
+#define SMB2_STATUS_DOMAIN_LIMIT_EXCEEDED              0xC00000E1
+#define SMB2_STATUS_OPLOCK_NOT_GRANTED                 0xC00000E2
+#define SMB2_STATUS_INVALID_OPLOCK_PROTOCOL            0xC00000E3
+#define SMB2_STATUS_INTERNAL_DB_CORRUPTION             0xC00000E4
+#define SMB2_STATUS_INTERNAL_ERROR                     0xC00000E5
+#define SMB2_STATUS_GENERIC_NOT_MAPPED                 0xC00000E6
+#define SMB2_STATUS_BAD_DESCRIPTOR_FORMAT              0xC00000E7
+#define SMB2_STATUS_INVALID_USER_BUFFER                0xC00000E8
+#define SMB2_STATUS_UNEXPECTED_IO_ERROR                0xC00000E9
+#define SMB2_STATUS_UNEXPECTED_MM_CREATE_ERR           0xC00000EA
+#define SMB2_STATUS_UNEXPECTED_MM_MAP_ERROR            0xC00000EB
+#define SMB2_STATUS_UNEXPECTED_MM_EXTEND_ERR           0xC00000EC
+#define SMB2_STATUS_NOT_LOGON_PROCESS                  0xC00000ED
+#define SMB2_STATUS_LOGON_SESSION_EXISTS               0xC00000EE
+#define SMB2_STATUS_INVALID_PARAMETER_1                0xC00000EF
+#define SMB2_STATUS_INVALID_PARAMETER_2                0xC00000F0
+#define SMB2_STATUS_INVALID_PARAMETER_3                0xC00000F1
+#define SMB2_STATUS_INVALID_PARAMETER_4                0xC00000F2
+#define SMB2_STATUS_INVALID_PARAMETER_5                0xC00000F3
+#define SMB2_STATUS_INVALID_PARAMETER_6                0xC00000F4
+#define SMB2_STATUS_INVALID_PARAMETER_7                0xC00000F5
+#define SMB2_STATUS_INVALID_PARAMETER_8                0xC00000F6
+#define SMB2_STATUS_INVALID_PARAMETER_9                0xC00000F7
+#define SMB2_STATUS_INVALID_PARAMETER_10               0xC00000F8
+#define SMB2_STATUS_INVALID_PARAMETER_11               0xC00000F9
+#define SMB2_STATUS_INVALID_PARAMETER_12               0xC00000FA
+#define SMB2_STATUS_REDIRECTOR_NOT_STARTED             0xC00000FB
+#define SMB2_STATUS_REDIRECTOR_STARTED                 0xC00000FC
+#define SMB2_STATUS_STACK_OVERFLOW                     0xC00000FD
+#define SMB2_STATUS_NO_SUCH_PACKAGE                    0xC00000FE
+#define SMB2_STATUS_BAD_FUNCTION_TABLE                 0xC00000FF
+#define SMB2_STATUS_DIRECTORY_NOT_EMPTY                0xC0000101
+#define SMB2_STATUS_FILE_CORRUPT_ERROR                 0xC0000102
+#define SMB2_STATUS_NOT_A_DIRECTORY                    0xC0000103
+#define SMB2_STATUS_BAD_LOGON_SESSION_STATE            0xC0000104
+#define SMB2_STATUS_LOGON_SESSION_COLLISION            0xC0000105
+#define SMB2_STATUS_NAME_TOO_LONG                      0xC0000106
+#define SMB2_STATUS_FILES_OPEN                         0xC0000107
+#define SMB2_STATUS_CONNECTION_IN_USE                  0xC0000108
+#define SMB2_STATUS_MESSAGE_NOT_FOUND                  0xC0000109
+#define SMB2_STATUS_PROCESS_IS_TERMINATING             0xC000010A
+#define SMB2_STATUS_INVALID_LOGON_TYPE                 0xC000010B
+#define SMB2_STATUS_NO_GUID_TRANSLATION                0xC000010C
+#define SMB2_STATUS_CANNOT_IMPERSONATE                 0xC000010D
+#define SMB2_STATUS_IMAGE_ALREADY_LOADED               0xC000010E
+#define SMB2_STATUS_ABIOS_NOT_PRESENT                  0xC000010F
+#define SMB2_STATUS_ABIOS_LID_NOT_EXIST                0xC0000110
+#define SMB2_STATUS_ABIOS_LID_ALREADY_OWNED            0xC0000111
+#define SMB2_STATUS_ABIOS_NOT_LID_OWNER                0xC0000112
+#define SMB2_STATUS_ABIOS_INVALID_COMMAND              0xC0000113
+#define SMB2_STATUS_ABIOS_INVALID_LID                  0xC0000114
+#define SMB2_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE       0xC0000115
+#define SMB2_STATUS_ABIOS_INVALID_SELECTOR             0xC0000116
+#define SMB2_STATUS_NO_LDT                             0xC0000117
+#define SMB2_STATUS_INVALID_LDT_SIZE                   0xC0000118
+#define SMB2_STATUS_INVALID_LDT_OFFSET                 0xC0000119
+#define SMB2_STATUS_INVALID_LDT_DESCRIPTOR             0xC000011A
+#define SMB2_STATUS_INVALID_IMAGE_NE_FORMAT            0xC000011B
+#define SMB2_STATUS_RXACT_INVALID_STATE                0xC000011C
+#define SMB2_STATUS_RXACT_COMMIT_FAILURE               0xC000011D
+#define SMB2_STATUS_MAPPED_FILE_SIZE_ZERO              0xC000011E
+#define SMB2_STATUS_TOO_MANY_OPENED_FILES              0xC000011F
+#define SMB2_STATUS_CANCELLED                          0xC0000120
+#define SMB2_STATUS_CANNOT_DELETE                      0xC0000121
+#define SMB2_STATUS_INVALID_COMPUTER_NAME              0xC0000122
+#define SMB2_STATUS_FILE_DELETED                       0xC0000123
+#define SMB2_STATUS_SPECIAL_ACCOUNT                    0xC0000124
+#define SMB2_STATUS_SPECIAL_GROUP                      0xC0000125
+#define SMB2_STATUS_SPECIAL_USER                       0xC0000126
+#define SMB2_STATUS_MEMBERS_PRIMARY_GROUP              0xC0000127
+#define SMB2_STATUS_FILE_CLOSED                        0xC0000128
+#define SMB2_STATUS_TOO_MANY_THREADS                   0xC0000129
+#define SMB2_STATUS_THREAD_NOT_IN_PROCESS              0xC000012A
+#define SMB2_STATUS_TOKEN_ALREADY_IN_USE               0xC000012B
+#define SMB2_STATUS_PAGEFILE_QUOTA_EXCEEDED            0xC000012C
+#define SMB2_STATUS_COMMITMENT_LIMIT                   0xC000012D
+#define SMB2_STATUS_INVALID_IMAGE_LE_FORMAT            0xC000012E
+#define SMB2_STATUS_INVALID_IMAGE_NOT_MZ               0xC000012F
+#define SMB2_STATUS_INVALID_IMAGE_PROTECT              0xC0000130
+#define SMB2_STATUS_INVALID_IMAGE_WIN_16               0xC0000131
+#define SMB2_STATUS_LOGON_SERVER_CONFLICT              0xC0000132
+#define SMB2_STATUS_TIME_DIFFERENCE_AT_DC              0xC0000133
+#define SMB2_STATUS_SYNCHRONIZATION_REQUIRED           0xC0000134
+#define SMB2_STATUS_DLL_NOT_FOUND                      0xC0000135
+#define SMB2_STATUS_OPEN_FAILED                        0xC0000136
+#define SMB2_STATUS_IO_PRIVILEGE_FAILED                0xC0000137
+#define SMB2_STATUS_ORDINAL_NOT_FOUND                  0xC0000138
+#define SMB2_STATUS_ENTRYPOINT_NOT_FOUND               0xC0000139
+#define SMB2_STATUS_CONTROL_C_EXIT                     0xC000013A
+#define SMB2_STATUS_LOCAL_DISCONNECT                   0xC000013B
+#define SMB2_STATUS_REMOTE_DISCONNECT                  0xC000013C
+#define SMB2_STATUS_REMOTE_RESOURCES                   0xC000013D
+#define SMB2_STATUS_LINK_FAILED                        0xC000013E
+#define SMB2_STATUS_LINK_TIMEOUT                       0xC000013F
+#define SMB2_STATUS_INVALID_CONNECTION                 0xC0000140
+#define SMB2_STATUS_INVALID_ADDRESS                    0xC0000141
+#define SMB2_STATUS_DLL_INIT_FAILED                    0xC0000142
+#define SMB2_STATUS_MISSING_SYSTEMFILE                 0xC0000143
+#define SMB2_STATUS_UNHANDLED_EXCEPTION                0xC0000144
+#define SMB2_STATUS_APP_INIT_FAILURE                   0xC0000145
+#define SMB2_STATUS_PAGEFILE_CREATE_FAILED             0xC0000146
+#define SMB2_STATUS_NO_PAGEFILE                        0xC0000147
+#define SMB2_STATUS_INVALID_LEVEL                      0xC0000148
+#define SMB2_STATUS_WRONG_PASSWORD_CORE                0xC0000149
+#define SMB2_STATUS_ILLEGAL_FLOAT_CONTEXT              0xC000014A
+#define SMB2_STATUS_PIPE_BROKEN                        0xC000014B
+#define SMB2_STATUS_REGISTRY_CORRUPT                   0xC000014C
+#define SMB2_STATUS_REGISTRY_IO_FAILED                 0xC000014D
+#define SMB2_STATUS_NO_EVENT_PAIR                      0xC000014E
+#define SMB2_STATUS_UNRECOGNIZED_VOLUME                0xC000014F
+#define SMB2_STATUS_SERIAL_NO_DEVICE_INITED            0xC0000150
+#define SMB2_STATUS_NO_SUCH_ALIAS                      0xC0000151
+#define SMB2_STATUS_MEMBER_NOT_IN_ALIAS                0xC0000152
+#define SMB2_STATUS_MEMBER_IN_ALIAS                    0xC0000153
+#define SMB2_STATUS_ALIAS_EXISTS                       0xC0000154
+#define SMB2_STATUS_LOGON_NOT_GRANTED                  0xC0000155
+#define SMB2_STATUS_TOO_MANY_SECRETS                   0xC0000156
+#define SMB2_STATUS_SECRET_TOO_LONG                    0xC0000157
+#define SMB2_STATUS_INTERNAL_DB_ERROR                  0xC0000158
+#define SMB2_STATUS_FULLSCREEN_MODE                    0xC0000159
+#define SMB2_STATUS_TOO_MANY_CONTEXT_IDS               0xC000015A
+#define SMB2_STATUS_LOGON_TYPE_NOT_GRANTED             0xC000015B
+#define SMB2_STATUS_NOT_REGISTRY_FILE                  0xC000015C
+#define SMB2_STATUS_NT_CROSS_ENCRYPTION_REQUIRED       0xC000015D
+#define SMB2_STATUS_DOMAIN_CTRLR_CONFIG_ERROR          0xC000015E
+#define SMB2_STATUS_FT_MISSING_MEMBER                  0xC000015F
+#define SMB2_STATUS_ILL_FORMED_SERVICE_ENTRY           0xC0000160
+#define SMB2_STATUS_ILLEGAL_CHARACTER                  0xC0000161
+#define SMB2_STATUS_UNMAPPABLE_CHARACTER               0xC0000162
+#define SMB2_STATUS_UNDEFINED_CHARACTER                0xC0000163
+#define SMB2_STATUS_FLOPPY_VOLUME                      0xC0000164
+#define SMB2_STATUS_FLOPPY_ID_MARK_NOT_FOUND           0xC0000165
+#define SMB2_STATUS_FLOPPY_WRONG_CYLINDER              0xC0000166
+#define SMB2_STATUS_FLOPPY_UNKNOWN_ERROR               0xC0000167
+#define SMB2_STATUS_FLOPPY_BAD_REGISTERS               0xC0000168
+#define SMB2_STATUS_DISK_RECALIBRATE_FAILED            0xC0000169
+#define SMB2_STATUS_DISK_OPERATION_FAILED              0xC000016A
+#define SMB2_STATUS_DISK_RESET_FAILED                  0xC000016B
+#define SMB2_STATUS_SHARED_IRQ_BUSY                    0xC000016C
+#define SMB2_STATUS_FT_ORPHANING                       0xC000016D
+#define SMB2_STATUS_PARTITION_FAILURE                  0xC0000172
+#define SMB2_STATUS_INVALID_BLOCK_LENGTH               0xC0000173
+#define SMB2_STATUS_DEVICE_NOT_PARTITIONED             0xC0000174
+#define SMB2_STATUS_UNABLE_TO_LOCK_MEDIA               0xC0000175
+#define SMB2_STATUS_UNABLE_TO_UNLOAD_MEDIA             0xC0000176
+#define SMB2_STATUS_EOM_OVERFLOW                       0xC0000177
+#define SMB2_STATUS_NO_MEDIA                           0xC0000178
+#define SMB2_STATUS_NO_SUCH_MEMBER                     0xC000017A
+#define SMB2_STATUS_INVALID_MEMBER                     0xC000017B
+#define SMB2_STATUS_KEY_DELETED                        0xC000017C
+#define SMB2_STATUS_NO_LOG_SPACE                       0xC000017D
+#define SMB2_STATUS_TOO_MANY_SIDS                      0xC000017E
+#define SMB2_STATUS_LM_CROSS_ENCRYPTION_REQUIRED       0xC000017F
+#define SMB2_STATUS_KEY_HAS_CHILDREN                   0xC0000180
+#define SMB2_STATUS_CHILD_MUST_BE_VOLATILE             0xC0000181
+#define SMB2_STATUS_DEVICE_CONFIGURATION_ERROR         0xC0000182
+#define SMB2_STATUS_DRIVER_INTERNAL_ERROR              0xC0000183
+#define SMB2_STATUS_INVALID_DEVICE_STATE               0xC0000184
+#define SMB2_STATUS_IO_DEVICE_ERROR                    0xC0000185
+#define SMB2_STATUS_DEVICE_PROTOCOL_ERROR              0xC0000186
+#define SMB2_STATUS_BACKUP_CONTROLLER                  0xC0000187
+#define SMB2_STATUS_LOG_FILE_FULL                      0xC0000188
+#define SMB2_STATUS_TOO_LATE                           0xC0000189
+#define SMB2_STATUS_NO_TRUST_LSA_SECRET                0xC000018A
+#define SMB2_STATUS_NO_TRUST_SAM_ACCOUNT               0xC000018B
+#define SMB2_STATUS_TRUSTED_DOMAIN_FAILURE             0xC000018C
+#define SMB2_STATUS_TRUSTED_RELATIONSHIP_FAILURE       0xC000018D
+#define SMB2_STATUS_EVENTLOG_FILE_CORRUPT              0xC000018E
+#define SMB2_STATUS_EVENTLOG_CANT_START                0xC000018F
+#define SMB2_STATUS_TRUST_FAILURE                      0xC0000190
+#define SMB2_STATUS_MUTANT_LIMIT_EXCEEDED              0xC0000191
+#define SMB2_STATUS_NETLOGON_NOT_STARTED               0xC0000192
+#define SMB2_STATUS_ACCOUNT_EXPIRED                    0xC0000193
+#define SMB2_STATUS_POSSIBLE_DEADLOCK                  0xC0000194
+#define SMB2_STATUS_NETWORK_CREDENTIAL_CONFLICT        0xC0000195
+#define SMB2_STATUS_REMOTE_SESSION_LIMIT               0xC0000196
+#define SMB2_STATUS_EVENTLOG_FILE_CHANGED              0xC0000197
+#define SMB2_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT  0xC0000198
+#define SMB2_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT  0xC0000199
+#define SMB2_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT       0xC000019A
+#define SMB2_STATUS_DOMAIN_TRUST_INCONSISTENT          0xC000019B
+#define SMB2_STATUS_FS_DRIVER_REQUIRED                 0xC000019C
+#define SMB2_STATUS_NO_USER_SESSION_KEY                0xC0000202
+#define SMB2_STATUS_USER_SESSION_DELETED               0xC0000203
+#define SMB2_STATUS_RESOURCE_LANG_NOT_FOUND            0xC0000204
+#define SMB2_STATUS_INSUFF_SERVER_RESOURCES            0xC0000205
+#define SMB2_STATUS_INVALID_BUFFER_SIZE                0xC0000206
+#define SMB2_STATUS_INVALID_ADDRESS_COMPONENT          0xC0000207
+#define SMB2_STATUS_INVALID_ADDRESS_WILDCARD           0xC0000208
+#define SMB2_STATUS_TOO_MANY_ADDRESSES                 0xC0000209
+#define SMB2_STATUS_ADDRESS_ALREADY_EXISTS             0xC000020A
+#define SMB2_STATUS_ADDRESS_CLOSED                     0xC000020B
+#define SMB2_STATUS_CONNECTION_DISCONNECTED            0xC000020C
+#define SMB2_STATUS_CONNECTION_RESET                   0xC000020D
+#define SMB2_STATUS_TOO_MANY_NODES                     0xC000020E
+#define SMB2_STATUS_TRANSACTION_ABORTED                0xC000020F
+#define SMB2_STATUS_TRANSACTION_TIMED_OUT              0xC0000210
+#define SMB2_STATUS_TRANSACTION_NO_RELEASE             0xC0000211
+#define SMB2_STATUS_TRANSACTION_NO_MATCH               0xC0000212
+#define SMB2_STATUS_TRANSACTION_RESPONDED              0xC0000213
+#define SMB2_STATUS_TRANSACTION_INVALID_ID             0xC0000214
+#define SMB2_STATUS_TRANSACTION_INVALID_TYPE           0xC0000215
+#define SMB2_STATUS_NOT_SERVER_SESSION                 0xC0000216
+#define SMB2_STATUS_NOT_CLIENT_SESSION                 0xC0000217
+#define SMB2_STATUS_CANNOT_LOAD_REGISTRY_FILE          0xC0000218
+#define SMB2_STATUS_DEBUG_ATTACH_FAILED                0xC0000219
+#define SMB2_STATUS_SYSTEM_PROCESS_TERMINATED          0xC000021A
+#define SMB2_STATUS_DATA_NOT_ACCEPTED                  0xC000021B
+#define SMB2_STATUS_NO_BROWSER_SERVERS_FOUND           0xC000021C
+#define SMB2_STATUS_VDM_HARD_ERROR                     0xC000021D
+#define SMB2_STATUS_DRIVER_CANCEL_TIMEOUT              0xC000021E
+#define SMB2_STATUS_REPLY_MESSAGE_MISMATCH             0xC000021F
+#define SMB2_STATUS_MAPPED_ALIGNMENT                   0xC0000220
+#define SMB2_STATUS_IMAGE_CHECKSUM_MISMATCH            0xC0000221
+#define SMB2_STATUS_LOST_WRITEBEHIND_DATA              0xC0000222
+#define SMB2_STATUS_CLIENT_SERVER_PARAMETERS_INVALID   0xC0000223
+#define SMB2_STATUS_PASSWORD_MUST_CHANGE               0xC0000224
+#define SMB2_STATUS_NOT_FOUND                          0xC0000225
+#define SMB2_STATUS_NOT_TINY_STREAM                    0xC0000226
+#define SMB2_STATUS_RECOVERY_FAILURE                   0xC0000227
+#define SMB2_STATUS_STACK_OVERFLOW_READ                0xC0000228
+#define SMB2_STATUS_FAIL_CHECK                         0xC0000229
+#define SMB2_STATUS_DUPLICATE_OBJECTID                 0xC000022A
+#define SMB2_STATUS_OBJECTID_EXISTS                    0xC000022B
+#define SMB2_STATUS_CONVERT_TO_LARGE                   0xC000022C
+#define SMB2_STATUS_RETRY                              0xC000022D
+#define SMB2_STATUS_FOUND_OUT_OF_SCOPE                 0xC000022E
+#define SMB2_STATUS_ALLOCATE_BUCKET                    0xC000022F
+#define SMB2_STATUS_PROPSET_NOT_FOUND                  0xC0000230
+#define SMB2_STATUS_MARSHALL_OVERFLOW                  0xC0000231
+#define SMB2_STATUS_INVALID_VARIANT                    0xC0000232
+#define SMB2_STATUS_DOMAIN_CONTROLLER_NOT_FOUND        0xC0000233
+#define SMB2_STATUS_ACCOUNT_LOCKED_OUT                 0xC0000234
+#define SMB2_STATUS_HANDLE_NOT_CLOSABLE                0xC0000235
+#define SMB2_STATUS_CONNECTION_REFUSED                 0xC0000236
+#define SMB2_STATUS_GRACEFUL_DISCONNECT                0xC0000237
+#define SMB2_STATUS_ADDRESS_ALREADY_ASSOCIATED         0xC0000238
+#define SMB2_STATUS_ADDRESS_NOT_ASSOCIATED             0xC0000239
+#define SMB2_STATUS_CONNECTION_INVALID                 0xC000023A
+#define SMB2_STATUS_CONNECTION_ACTIVE                  0xC000023B
+#define SMB2_STATUS_NETWORK_UNREACHABLE                0xC000023C
+#define SMB2_STATUS_HOST_UNREACHABLE                   0xC000023D
+#define SMB2_STATUS_PROTOCOL_UNREACHABLE               0xC000023E
+#define SMB2_STATUS_PORT_UNREACHABLE                   0xC000023F
+#define SMB2_STATUS_REQUEST_ABORTED                    0xC0000240
+#define SMB2_STATUS_CONNECTION_ABORTED                 0xC0000241
+#define SMB2_STATUS_BAD_COMPRESSION_BUFFER             0xC0000242
+#define SMB2_STATUS_USER_MAPPED_FILE                   0xC0000243
+#define SMB2_STATUS_AUDIT_FAILED                       0xC0000244
+#define SMB2_STATUS_TIMER_RESOLUTION_NOT_SET           0xC0000245
+#define SMB2_STATUS_CONNECTION_COUNT_LIMIT             0xC0000246
+#define SMB2_STATUS_LOGIN_TIME_RESTRICTION             0xC0000247
+#define SMB2_STATUS_LOGIN_WKSTA_RESTRICTION            0xC0000248
+#define SMB2_STATUS_IMAGE_MP_UP_MISMATCH               0xC0000249
+#define SMB2_STATUS_INSUFFICIENT_LOGON_INFO            0xC0000250
+#define SMB2_STATUS_BAD_DLL_ENTRYPOINT                 0xC0000251
+#define SMB2_STATUS_BAD_SERVICE_ENTRYPOINT             0xC0000252
+#define SMB2_STATUS_LPC_REPLY_LOST                     0xC0000253
+#define SMB2_STATUS_IP_ADDRESS_CONFLICT1               0xC0000254
+#define SMB2_STATUS_IP_ADDRESS_CONFLICT2               0xC0000255
+#define SMB2_STATUS_REGISTRY_QUOTA_LIMIT               0xC0000256
+#define SMB2_STATUS_PATH_NOT_COVERED                   0xC0000257
+#define SMB2_STATUS_NO_CALLBACK_ACTIVE                 0xC0000258
+#define SMB2_STATUS_LICENSE_QUOTA_EXCEEDED             0xC0000259
+#define SMB2_STATUS_PWD_TOO_SHORT                      0xC000025A
+#define SMB2_STATUS_PWD_TOO_RECENT                     0xC000025B
+#define SMB2_STATUS_PWD_HISTORY_CONFLICT               0xC000025C
+#define SMB2_STATUS_PLUGPLAY_NO_DEVICE                 0xC000025E
+#define SMB2_STATUS_UNSUPPORTED_COMPRESSION            0xC000025F
+#define SMB2_STATUS_INVALID_HW_PROFILE                 0xC0000260
+#define SMB2_STATUS_INVALID_PLUGPLAY_DEVICE_PATH       0xC0000261
+#define SMB2_STATUS_DRIVER_ORDINAL_NOT_FOUND           0xC0000262
+#define SMB2_STATUS_DRIVER_ENTRYPOINT_NOT_FOUND        0xC0000263
+#define SMB2_STATUS_RESOURCE_NOT_OWNED                 0xC0000264
+#define SMB2_STATUS_TOO_MANY_LINKS                     0xC0000265
+#define SMB2_STATUS_QUOTA_LIST_INCONSISTENT            0xC0000266
+#define SMB2_STATUS_FILE_IS_OFFLINE                    0xC0000267
+#define SMB2_STATUS_VOLUME_DISMOUNTED                  0xC000026E
+#define SMB2_STATUS_NOT_A_REPARSE_POINT                0xC0000275
+#define SMB2_STATUS_SERVER_UNAVAILABLE                 0xC0000466
+
+/* Warning codes */
+#define SMB2_STATUS_BUFFER_OVERFLOW                    0x80000005
+#define SMB2_STATUS_STOPPED_ON_SYMLINK                 0x8000002D
+

+ 83 - 0
entry/src/main/cpp/include/smb2/smb2-ioctl.h

@@ -0,0 +1,83 @@
+/*
+ * Copyright 2025 Ronnie Sahlberg <ronniesahberg@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the “Software”), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY
+ * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+ * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+/*
+ * Or optionally just relicense this file to whatever license you want.
+ */
+#ifndef _SMB2_IOCTL_H_
+#define _SMB2_IOCTL_H_
+
+#define FSCTL_CREATE_OR_GET_OBJECT_ID              0x000900C0
+#define FSCTL_DELETE_OBJECT_ID                     0x000900A0
+#define FSCTL_DELETE_REPARSE_POINT                 0x000900AC
+#define FSCTL_DUPLICATE_EXTENTS_TO_FILE            0x00098344
+#define FSCTL_DUPLICATE_EXTENTS_TO_FILE_EX         0x000983E8 
+#define FSCTL_FILESYSTEM_GET_STATISTICS            0x00090060
+#define FSCTL_FILE_LEVEL_TRIM                      0x00098208
+#define FSCTL_FIND_FILES_BY_SID                    0x0009008F
+#define FSCTL_GET_COMPRESSION                      0x0009003C
+#define FSCTL_GET_INTEGRITY_INFORMATION            0x0009027C
+#define FSCTL_GET_NTFS_VOLUME_DATA                 0x00090064
+#define FSCTL_GET_REFS_VOLUME_DATA                 0x000902D8
+#define FSCTL_GET_OBJECT_ID                        0x0009009C
+#define FSCTL_GET_REPARSE_POINT                    0x000900A8
+#define FSCTL_GET_RETRIEVAL_POINTER_COUNT          0x0009042B
+#define FSCTL_GET_RETRIEVAL_POINTERS               0x00090073
+#define FSCTL_GET_RETRIEVAL_POINTERS_AND_REFCOUNT  0x000903D3
+#define FSCTL_IS_PATHNAME_VALID                    0x0009002C
+#define FSCTL_LMR_SET_LINK_TRACKING_INFORMATION    0x001400EC
+#define FSCTL_MARK_HANDLE                          0x000900FC
+#define FSCTL_OFFLOAD_READ                         0x00094264
+#define FSCTL_OFFLOAD_WRITE                        0x00098268
+#define FSCTL_PIPE_PEEK                            0x0011400C
+#define FSCTL_PIPE_TRANSCEIVE                      0x0011C017
+#define FSCTL_PIPE_WAIT                            0x00110018
+#define FSCTL_QUERY_ALLOCATED_RANGES               0x000940CF
+#define FSCTL_QUERY_FAT_BPB                        0x00090058
+#define FSCTL_QUERY_FILE_REGIONS                   0x00090284
+#define FSCTL_QUERY_ON_DISK_VOLUME_INFO            0x0009013C
+#define FSCTL_QUERY_SPARING_INFO                   0x00090138
+#define FSCTL_READ_FILE_USN_DATA                   0x000900EB
+#define FSCTL_RECALL_FILE                          0x00090117
+#define FSCTL_REFS_STREAM_SNAPSHOT_MANAGEMENT      0x00090440
+#define FSCTL_SET_COMPRESSION                      0x0009C040
+#define FSCTL_SET_DEFECT_MANAGEMENT                0x00098134
+#define FSCTL_SET_ENCRYPTION                       0x000900D7
+#define FSCTL_SET_INTEGRITY_INFORMATION            0x0009C280
+#define FSCTL_SET_INTEGRITY_INFORMATION_EX         0x00090380
+#define FSCTL_SET_OBJECT_ID                        0x00090098
+#define FSCTL_SET_OBJECT_ID_EXTENDED               0x000900BC
+#define FSCTL_SET_REPARSE_POINT                    0x000900A4
+#define FSCTL_SET_SPARSE                           0x000900C4
+#define FSCTL_SET_ZERO_DATA                        0x000980C8
+#define FSCTL_SET_ZERO_ON_DEALLOCATION             0x00090194
+#define FSCTL_SIS_COPYFILE                         0x00090100
+#define FSCTL_WRITE_USN_CLOSE_RECORD               0x000900EF
+
+#define FSCTL_SRV_ENUMERATE_SNAPSHOTS              0x00144064
+#define FSCTL_GET_SHADOW_COPY_DATA                 0x00144064
+
+
+#endif /* _SMB2_IOCTL_H_ */

+ 1251 - 0
entry/src/main/cpp/include/smb2/smb2.h

@@ -0,0 +1,1251 @@
+/* -*-  mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil;  -*- */
+/*
+   Copyright (C) 2016 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _SMB2_H_
+#define _SMB2_H_
+
+#include <smb2/smb2-errors.h>
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct smb2_timeval {
+        time_t tv_sec;
+        long tv_usec;
+};
+#define SMB2_ERROR_REPLY_SIZE 9
+
+struct smb2_error_reply {
+        uint8_t error_context_count;
+        uint32_t byte_count;
+        uint8_t *error_data;
+};
+
+
+#define SMB2_FLAGS_SERVER_TO_REDIR    0x00000001
+#define SMB2_FLAGS_ASYNC_COMMAND      0x00000002
+#define SMB2_FLAGS_RELATED_OPERATIONS 0x00000004
+#define SMB2_FLAGS_SIGNED             0x00000008
+#define SMB2_FLAGS_PRIORITY_MASK      0x00000070
+#define SMB2_FLAGS_DFS_OPERATIONS     0x10000000
+#define SMB2_FLAGS_REPLAY_OPERATION   0x20000000
+
+enum smb2_command {
+        SMB2_NEGOTIATE       = 0,
+        SMB2_SESSION_SETUP   = 1,
+        SMB2_LOGOFF          = 2,
+        SMB2_TREE_CONNECT    = 3,
+        SMB2_TREE_DISCONNECT = 4,
+        SMB2_CREATE          = 5,
+        SMB2_CLOSE           = 6,
+        SMB2_FLUSH           = 7,
+        SMB2_READ            = 8,
+        SMB2_WRITE           = 9,
+        SMB2_LOCK            = 10,
+        SMB2_IOCTL           = 11,
+        SMB2_CANCEL          = 12,
+        SMB2_ECHO            = 13,
+        SMB2_QUERY_DIRECTORY = 14,
+        SMB2_CHANGE_NOTIFY   = 15,
+        SMB2_QUERY_INFO      = 16,
+        SMB2_SET_INFO        = 17,
+        SMB2_OPLOCK_BREAK    = 18,
+
+        SMB1_NEGOTIATE       = 114,
+};
+
+/*
+ * SMB2 NEGOTIATE
+ */
+#define SMB2_NEGOTIATE_SIGNING_ENABLED  0x0001
+#define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
+
+#define SMB2_GLOBAL_CAP_DFS                0x00000001
+#define SMB2_GLOBAL_CAP_LEASING            0x00000002
+#define SMB2_GLOBAL_CAP_LARGE_MTU          0x00000004
+#define SMB2_GLOBAL_CAP_MULTI_CHANNEL      0x00000008
+#define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010
+#define SMB2_GLOBAL_CAP_DIRECTORY_LEASING  0x00000020
+#define SMB2_GLOBAL_CAP_ENCRYPTION         0x00000040
+
+#define SMB2_PREAUTH_INTEGRITY_CAP         0x0001
+#define SMB2_ENCRYPTION_CAP                0x0002
+#define SMB2_COMPRESSION_CAP               0x0003
+#define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID  0x0005
+#define SMB2_TRANSPORT_CAP                 0x0006
+#define SMB2_RDMA_TRANSFORM_CAP            0x0007
+#define SMB2_SIGNING_CAP                   0x0008
+#define SMB2_CONTEXTTYPE_RESERVED          0x0100
+
+#define SMB2_HASH_SHA_512                  0x0001
+#define SMB2_PREAUTH_HASH_SIZE             64
+
+#define SMB2_ENCRYPTION_AES_128_CCM        0x0001
+#define SMB2_ENCRYPTION_AES_128_GCM        0x0002
+
+#define SMB2_NEGOTIATE_MAX_DIALECTS 10
+
+#define SMB2_NEGOTIATE_REQUEST_SIZE 36
+
+#define SMB2_GUID_SIZE 16
+typedef uint8_t smb2_guid[SMB2_GUID_SIZE];
+
+struct smb2_negotiate_request {
+        uint16_t dialect_count;
+        uint16_t security_mode;
+        uint32_t capabilities;
+        smb2_guid client_guid;
+        uint32_t negotiate_context_offset;
+        uint16_t negotiate_context_count;
+        uint16_t dialects[SMB2_NEGOTIATE_MAX_DIALECTS];
+};
+
+#define SMB2_NEGOTIATE_REPLY_SIZE 65
+
+struct smb2_negotiate_reply {
+        uint16_t security_mode;
+        uint16_t dialect_revision;
+        uint16_t cypher;
+        smb2_guid server_guid;
+        uint32_t capabilities;
+        uint32_t max_transact_size;
+        uint32_t max_read_size;
+        uint32_t max_write_size;
+        uint64_t system_time;
+        uint64_t server_start_time;
+        uint32_t negotiate_context_offset;
+        uint16_t negotiate_context_count;
+        uint16_t security_buffer_length;
+        uint16_t security_buffer_offset;
+        uint8_t *security_buffer;
+};
+
+/* session setup flags */
+#define SMB2_SESSION_FLAG_BINDING 0x01
+
+/* session setup capabilities */
+#define SMB2_GLOBAL_CAP_DFS     0x00000001
+#define SMB2_GLOBAL_CAP_UNUSED1 0x00000002
+#define SMB2_GLOBAL_CAP_UNUSED2 0x00000004
+#define SMB2_GLOBAL_CAP_UNUSED4 0x00000008
+
+#define SMB2_SESSION_SETUP_REQUEST_SIZE 25
+
+struct smb2_session_setup_request {
+        uint8_t flags;
+        uint8_t security_mode;
+        uint32_t capabilities;
+        uint32_t channel;
+        uint64_t previous_session_id;
+        uint16_t security_buffer_length;
+        uint8_t *security_buffer;
+};
+
+#define SMB2_SESSION_FLAG_IS_GUEST        0x0001
+#define SMB2_SESSION_FLAG_IS_NULL         0x0002
+#define SMB2_SESSION_FLAG_IS_ENCRYPT_DATA 0x0004
+
+#define SMB2_SESSION_SETUP_REPLY_SIZE 9
+
+struct smb2_session_setup_reply {
+        uint16_t session_flags;
+        uint16_t security_buffer_length;
+        uint16_t security_buffer_offset;
+        uint8_t *security_buffer;
+};
+
+#define SMB2_TREE_CONNECT_REQUEST_SIZE 9
+
+#define SMB2_SHAREFLAG_CLUSTER_RECONNECT 0x0001
+
+struct smb2_tree_connect_request {
+        uint16_t flags;
+        uint16_t path_offset;
+        uint16_t path_length;
+        uint16_t *path;
+};
+
+#define SMB2_SHARE_TYPE_DISK  0x01
+#define SMB2_SHARE_TYPE_PIPE  0x02
+#define SMB2_SHARE_TYPE_PRINT 0x03
+
+#define SMB2_SHAREFLAG_MANUAL_CACHING              0x00000000
+#define SMB2_SHAREFLAG_DFS                         0x00000001
+#define SMB2_SHAREFLAG_DFS_ROOT                    0x00000002
+#define SMB2_SHAREFLAG_AUTO_CACHING                0x00000010
+#define SMB2_SHAREFLAG_VDO_CACHING                 0x00000020
+#define SMB2_SHAREFLAG_NO_CACHING                  0x00000030
+#define SMB2_SHAREFLAG_RESTRICT_EXCLUSIVE_OPENS    0x00000100
+#define SMB2_SHAREFLAG_FORCE_SHARED_DELETE         0x00000200
+#define SMB2_SHAREFLAG_ALLOW_NAMESPACE_CACHING     0x00000400
+#define SMB2_SHAREFLAG_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
+#define SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK        0x00001000
+#define SMB2_SHAREFLAG_ENABLE_HASH_V1              0x00002000
+#define SMB2_SHAREFLAG_ENABLE_HASH_V2              0x00004000
+#define SMB2_SHAREFLAG_ENCRYPT_DATA                0x00008000
+
+#define SMB2_SHARE_CAP_DFS                         0x00000008
+#define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY     0x00000010
+#define SMB2_SHARE_CAP_SCALEOUT                    0x00000020
+#define SMB2_SHARE_CAP_CLUSTER                     0x00000040
+#define SMB2_SHARE_CAP_ASYMMETRIC                  0x00000080
+
+#define SMB2_TREE_CONNECT_REPLY_SIZE 16
+
+struct smb2_tree_connect_reply {
+        uint8_t share_type;
+        uint32_t share_flags;
+        uint32_t capabilities;
+        uint32_t maximal_access;
+};
+
+#define SMB2_CREATE_REQUEST_SIZE 57
+
+#define SMB2_OPLOCK_LEVEL_NONE      0x00
+#define SMB2_OPLOCK_LEVEL_II        0x01
+#define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
+#define SMB2_OPLOCK_LEVEL_BATCH     0x09
+#define SMB2_OPLOCK_LEVEL_LEASE     0xff
+
+#define SMB2_CREATE_REQUEST_LEASE_SIZE  32
+
+#define SMB2_IMPERSONATION_ANONYMOUS      0x00000000
+#define SMB2_IMPERSONATION_IDENTIFICATION 0x00000001
+#define SMB2_IMPERSONATION_IMPERSONATION  0x00000002
+#define SMB2_IMPERSONATION_DELEGATE       0x00000003
+
+/* Access mask common to all objects */
+#define SMB2_FILE_READ_EA           0x00000008
+#define SMB2_FILE_WRITE_EA          0x00000010
+#define SMB2_FILE_DELETE_CHILD      0x00000040
+#define SMB2_FILE_READ_ATTRIBUTES   0x00000080
+#define SMB2_FILE_WRITE_ATTRIBUTES  0x00000100
+#define SMB2_DELETE                 0x00010000
+#define SMB2_READ_CONTROL           0x00020000
+#define SMB2_WRITE_DACL             0x00040000
+#define SMB2_WRITE_OWNER            0x00080000
+#define SMB2_SYNCHRONIZE            0x00100000
+#define SMB2_ACCESS_SYSTEM_SECURITY 0x01000000
+#define SMB2_MAXIMUM_ALLOWED        0x02000000
+#define SMB2_GENERIC_ALL            0x10000000
+#define SMB2_GENERIC_EXECUTE        0x20000000
+#define SMB2_GENERIC_WRITE          0x40000000
+#define SMB2_GENERIC_READ           0x80000000
+
+/* Access mask unique for file/pipe/printer */
+#define SMB2_FILE_READ_DATA         0x00000001
+#define SMB2_FILE_WRITE_DATA        0x00000002
+#define SMB2_FILE_APPEND_DATA       0x00000004
+#define SMB2_FILE_EXECUTE           0x00000020
+
+/* Access mask unique for directories */
+#define SMB2_FILE_LIST_DIRECTORY    0x00000001
+#define SMB2_FILE_ADD_FILE          0x00000002
+#define SMB2_FILE_ADD_SUBDIRECTORY  0x00000004
+#define SMB2_FILE_TRAVERSE          0x00000020
+
+/* File attributes */
+#define SMB2_FILE_ATTRIBUTE_READONLY            0x00000001
+#define SMB2_FILE_ATTRIBUTE_HIDDEN              0x00000002
+#define SMB2_FILE_ATTRIBUTE_SYSTEM              0x00000004
+#define SMB2_FILE_ATTRIBUTE_DIRECTORY           0x00000010
+#define SMB2_FILE_ATTRIBUTE_ARCHIVE             0x00000020
+#define SMB2_FILE_ATTRIBUTE_NORMAL              0x00000080
+#define SMB2_FILE_ATTRIBUTE_TEMPORARY           0x00000100
+#define SMB2_FILE_ATTRIBUTE_SPARSE_FILE         0x00000200
+#define SMB2_FILE_ATTRIBUTE_REPARSE_POINT       0x00000400
+#define SMB2_FILE_ATTRIBUTE_COMPRESSED          0x00000800
+#define SMB2_FILE_ATTRIBUTE_OFFLINE             0x00001000
+#define SMB2_FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
+#define SMB2_FILE_ATTRIBUTE_ENCRYPTED           0x00004000
+#define SMB2_FILE_ATTRIBUTE_INTEGRITY_STREAM    0x00008000
+#define SMB2_FILE_ATTRIBUTE_NO_SCRUB_DATA       0x00020000
+
+/* Share access */
+#define SMB2_FILE_SHARE_READ 0x00000001
+#define SMB2_FILE_SHARE_WRITE 0x00000002
+#define SMB2_FILE_SHARE_DELETE 0x00000004
+
+/* Create disposition */
+#define SMB2_FILE_SUPERSEDE    0x00000000
+#define SMB2_FILE_OPEN         0x00000001
+#define SMB2_FILE_CREATE       0x00000002
+#define SMB2_FILE_OPEN_IF      0x00000003
+#define SMB2_FILE_OVERWRITE    0x00000004
+#define SMB2_FILE_OVERWRITE_IF 0x00000005
+
+/* Create options */
+#define SMB2_FILE_DIRECTORY_FILE            0x00000001
+#define SMB2_FILE_WRITE_THROUGH             0x00000002
+#define SMB2_FILE_SEQUENTIAL_ONLY           0x00000004
+#define SMB2_FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
+#define SMB2_FILE_SYNCHRONOUS_IO_ALERT      0x00000010
+#define SMB2_FILE_SYNCHRONOUS_IO_NONALERT   0x00000020
+#define SMB2_FILE_NON_DIRECTORY_FILE        0x00000040
+#define SMB2_FILE_COMPLETE_IF_OPLOCKED      0x00000100
+#define SMB2_FILE_NO_EA_KNOWLEDGE           0x00000200
+#define SMB2_FILE_RANDOM_ACCESS             0x00000800
+#define SMB2_FILE_DELETE_ON_CLOSE           0x00001000
+#define SMB2_FILE_OPEN_BY_FILE_ID           0x00002000
+#define SMB2_FILE_OPEN_FOR_BACKUP_INTENT    0x00004000
+#define SMB2_FILE_NO_COMPRESSION            0x00008000
+#define SMB2_FILE_OPEN_REMOTE_INSTANCE      0x00000400
+#define SMB2_FILE_OPEN_REQUIRING_OPLOCK     0x00010000
+#define SMB2_FILE_DISALLOW_EXCLUSIVE        0x00020000
+#define SMB2_FILE_RESERVE_OPFILTER          0x00100000
+#define SMB2_FILE_OPEN_REPARSE_POINT        0x00200000
+#define SMB2_FILE_OPEN_NO_RECALL            0x00400000
+#define SMB2_FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000
+
+struct smb2_create_request {
+        uint8_t security_flags;
+        uint8_t requested_oplock_level;
+        uint32_t impersonation_level;
+        uint64_t smb_create_flags;
+        uint32_t desired_access;
+        uint32_t file_attributes;
+        uint32_t share_access;
+        uint32_t create_disposition;
+        uint32_t create_options;
+        uint16_t name_offset;
+        uint16_t name_length;
+        const char *name;       /* name in UTF8 */
+        uint32_t create_context_offset;
+        uint32_t create_context_length;
+        uint8_t *create_context;
+};
+
+#define SMB2_CREATE_REPLY_SIZE 89
+
+#define SMB2_FD_SIZE 16
+typedef uint8_t smb2_file_id[SMB2_FD_SIZE];
+
+#define SMB2_LEASE_KEY_SIZE 16
+typedef uint8_t smb2_lease_key[SMB2_LEASE_KEY_SIZE];
+
+struct smb2fh;
+smb2_file_id *smb2_get_file_id(struct smb2fh *fh);
+
+/*
+ * This creates a new smb2fh based on fileid.
+ * Free it with smb2_close_async()
+ */
+struct smb2_context;
+struct smb2fh *smb2_fh_from_file_id(struct smb2_context *smb2,
+                                    smb2_file_id *fileid);
+
+struct smb2_create_reply {
+        uint8_t oplock_level;
+        uint8_t flags;
+        uint32_t create_action;
+        uint64_t creation_time;
+        uint64_t last_access_time;
+        uint64_t last_write_time;
+        uint64_t change_time;
+        uint64_t allocation_size;
+        uint64_t end_of_file;
+        uint32_t file_attributes;
+        smb2_file_id file_id;
+        uint32_t create_context_length;
+        uint32_t create_context_offset;
+        uint8_t *create_context;
+};
+
+#define SMB2_CLOSE_REQUEST_SIZE 24
+
+#define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB 0x0001
+
+struct smb2_close_request {
+        uint16_t flags;
+        smb2_file_id file_id;
+};
+
+#define SMB2_CLOSE_REPLY_SIZE 60
+
+struct smb2_close_reply {
+        uint16_t flags;
+        uint64_t creation_time;
+        uint64_t last_access_time;
+        uint64_t last_write_time;
+        uint64_t change_time;
+        uint64_t allocation_size;
+        uint64_t end_of_file;
+        uint32_t file_attributes;
+};
+
+#define SMB2_FLUSH_REQUEST_SIZE 24
+
+struct smb2_flush_request {
+        smb2_file_id file_id;
+};
+
+#define SMB2_LOGFF_REQUEST_SIZE 4
+
+struct smb2_logoff_request {
+        uint16_t reserved;
+};
+
+#define SMB2_ECHO_REQUEST_SIZE 4
+
+struct smb2_echo_request {
+        uint16_t reserved;
+};
+
+#define SMB2_FLUSH_REPLY_SIZE 4
+
+#define SMB2_QUERY_DIRECTORY_REQUEST_SIZE 33
+
+/* File information class */
+#define SMB2_FILE_DIRECTORY_INFORMATION         0x01
+#define SMB2_FILE_FULL_DIRECTORY_INFORMATION    0x02
+#define SMB2_FILE_BOTH_DIRECTORY_INFORMATION    0x03
+#define SMB2_FILE_ID_BOTH_DIRECTORY_INFORMATION 0x25
+#define SMB2_FILE_ID_FULL_DIRECTORY_INFORMATION 0x26
+
+/* query flags */
+#define SMB2_RESTART_SCANS       0x01
+#define SMB2_RETURN_SINGLE_ENTRY 0x02
+#define SMB2_INDEX_SPECIFIED     0x04
+#define SMB2_REOPEN              0x10
+
+#define SMB2_FILEID_FULL_DIRECTORY_INFORMATION_SIZE  80
+
+/* Structure for SMB2_FILE_ID_FULL_DIRECTORY_INFORMATION.
+ * This is also used as the dirent content.
+ */
+struct smb2_fileidfulldirectoryinformation {
+        uint32_t next_entry_offset;
+        uint32_t file_index;
+        struct smb2_timeval creation_time;
+        struct smb2_timeval last_access_time;
+        struct smb2_timeval last_write_time;
+        struct smb2_timeval change_time;
+        uint64_t end_of_file;
+        uint64_t allocation_size;
+        uint32_t file_attributes;
+        uint32_t file_name_length;
+        uint32_t ea_size;
+        uint64_t file_id;
+        const char *name; /* or "reserved" for replys */
+};
+
+#define SMB2_FILEID_BOTH_DIRECTORY_INFORMATION_SIZE  104
+
+/* Structure for SMB2_FILE_ID_BOTH_DIRECTORY_INFORMATION.
+ */
+struct smb2_fileidbothdirectoryinformation {
+        uint32_t next_entry_offset;
+        uint32_t file_index;
+        struct smb2_timeval creation_time;
+        struct smb2_timeval last_access_time;
+        struct smb2_timeval last_write_time;
+        struct smb2_timeval change_time;
+        uint64_t end_of_file;
+        uint64_t allocation_size;
+        uint32_t file_attributes;
+        uint32_t file_name_length;
+        uint32_t ea_size;
+        uint8_t short_name_length;
+        uint8_t short_name[24];
+        uint64_t file_id;
+        const char *name; /* or "reserved" for replys */
+};
+
+struct smb2_iovec;
+int smb2_decode_fileidfulldirectoryinformation(
+        struct smb2_context *smb2,
+        struct smb2_fileidfulldirectoryinformation *fs,
+        struct smb2_iovec *vec);
+
+struct smb2_query_directory_request {
+        uint8_t file_information_class;
+        uint8_t flags;
+        uint32_t file_index;
+        smb2_file_id file_id;
+        uint32_t output_buffer_length;
+        uint16_t file_name_offset;
+        uint16_t file_name_length;
+        const char *name;       /* name in UTF8 */
+};
+
+#define SMB2_QUERY_DIRECTORY_REPLY_SIZE 9
+
+struct smb2_query_directory_reply {
+        uint16_t output_buffer_offset;
+        uint32_t output_buffer_length;
+        uint8_t *output_buffer;
+};
+
+#define SMB2_READ_REQUEST_SIZE 49
+
+#define SMB2_READFLAG_READ_UNBUFFERED 0x01
+
+#define SMB2_CHANNEL_NONE               0x00000000
+#define SMB2_CHANNEL_RDMA_V1            0x00000001
+#define SMB2_CHANNEL_RDMA_V1_INVALIDATE 0x00000002
+
+struct smb2_read_request {
+        uint8_t flags;
+        uint32_t length;
+        uint64_t offset;
+        uint8_t *buf;
+        smb2_file_id file_id;
+        uint32_t minimum_count;
+        uint32_t channel;
+        uint32_t remaining_bytes;
+        uint16_t read_channel_info_offset;
+        uint16_t read_channel_info_length;
+        uint8_t *read_channel_info;
+};
+
+#define SMB2_READ_REPLY_SIZE 17
+
+struct smb2_read_reply {
+        uint8_t data_offset;
+        uint32_t data_length;
+        uint32_t data_remaining;
+        uint8_t *data;
+};
+
+#define SMB2_QUERY_INFO_REQUEST_SIZE 41
+
+/* info type */
+#define SMB2_0_INFO_FILE       0x01
+#define SMB2_0_INFO_FILESYSTEM 0x02
+#define SMB2_0_INFO_SECURITY   0x03
+#define SMB2_0_INFO_QUOTA      0x04
+
+/* File information class : for SMB2_0_INFO_FILE */
+#define SMB2_FILE_DIRECTORY_INFORMATION         0x01
+#define SMB2_FILE_FULL_DIRECTORY_INFORMATION    0x02
+#define SMB2_FILE_BOTH_DIRECTORY_INFORMATION    0x03
+#define SMB2_FILE_BASIC_INFORMATION             0x04
+#define SMB2_FILE_STANDARD_INFORMATION          0x05
+#define SMB2_FILE_INTERNAL_INFORMATION          0x06
+#define SMB2_FILE_EA_INFORMATION                0x07
+#define SMB2_FILE_ACCESS_INFORMATION            0x08
+#define SMB2_FILE_NAME_INFORMATION              0x09
+#define SMB2_FILE_RENAME_INFORMATION            0x0A
+#define SMB2_FILE_LINK_INFORMATION              0x0B
+#define SMB2_FILE_NAMES_INFORMATION             0x0C
+#define SMB2_FILE_DISPOSITION_INFORMATION       0x0D
+#define SMB2_FILE_POSITION_INFORMATION          0x0E
+#define SMB2_FILE_FULL_EA_INFORMATION           0x0F
+#define SMB2_FILE_MODE_INFORMATION              0x10
+#define SMB2_FILE_ALIGNMENT_INFORMATION         0x11
+#define SMB2_FILE_ALL_INFORMATION               0x12
+#define SMB2_FILE_ALLOCATION_INFORMATION        0x13
+#define SMB2_FILE_END_OF_FILE_INFORMATION       0x14
+#define SMB2_FILE_ALTERNATE_NAME_INFORMATION    0x15
+#define SMB2_FILE_OBJECT_ID_INFORMATION         0x1D
+#define SMB2_FILE_ATTRIBUTE_TAG_INFORMATION     0x23
+#define SMB2_FILE_VALID_DATA_LENGTH_INFORMATION 0x27
+#define SMB2_FILE_NORMALIZED_NAME_INFORMATION   0x30
+#define SMB2_FILE_ID_INFORMATION                0x3B
+
+#define SMB2_FILE_STREAM_INFORMATION            0x16
+#define SMB2_FILE_PIPE_INFORMATION              0x17
+#define SMB2_FILE_PIPE_LOCAL_INFORMATION        0x18
+#define SMB2_FILE_PIPE_REMOTE_INFORMATION       0x19
+#define SMB2_FILE_MAILSLOT_QUERY_INFORMATION    0x1A
+#define SMB2_FILE_MAILSLOT_SET_INFORMATION      0x1B
+#define SMB2_FILE_COMPRESSION_INFORMATION       0x1C
+#define SMB2_FILE_OBJECT_ID_INFORMATION         0x1D
+#define SMB2_FILE_QUOTA_INFORMATION             0x20
+#define SMB2_FILE_REPARSE_POINT_INFORMATION     0x21
+#define SMB2_FILE_NETWORK_OPEN_INFORMATION      0x22
+
+/* Filesystem information class : for SMB2_0_INFO_FILESYSTEM */
+#define SMB2_FILE_FS_VOLUME_INFORMATION            1
+#define SMB2_FILE_FS_SIZE_INFORMATION              3
+#define SMB2_FILE_FS_DEVICE_INFORMATION            4
+#define SMB2_FILE_FS_ATTRIBUTE_INFORMATION         5
+#define SMB2_FILE_FS_CONTROL_INFORMATION           6
+#define SMB2_FILE_FS_FULL_SIZE_INFORMATION         7
+#define SMB2_FILE_FS_OBJECT_ID_INFORMATION         8
+#define SMB2_FILE_FS_SECTOR_SIZE_INFORMATION      11
+
+#define SMB2_FILE_INFO_CLASS_RESERVED           0x40
+
+/* additional info */
+#define SMB2_OWNER_SECURITY_INFORMATION     0x00000001
+#define SMB2_GROUP_SECURITY_INFORMATION     0x00000002
+#define SMB2_DACL_SECURITY_INFORMATION      0x00000004
+#define SMB2_SACL_SECURITY_INFORMATION      0x00000008
+#define SMB2_LABEL_SECURITY_INFORMATION     0x00000010
+#define SMB2_ATTRIBUTE_SECURITY_INFORMATION 0x00000020
+#define SMB2_SCOPE_SECURITY_INFORMATION     0x00000040
+#define SMB2_BACKUP_SECURITY_INFORMATION    0x00010000
+
+/* flags */
+#define SL_RESTART_SCAN        0x00000001
+#define SL_RETURN_SINGLE_ENTRY 0x00000002
+#define SL_INDEX_SPECIFIED     0x00000004
+
+/*
+ * FILE_BASIC_INFORMATION
+ */
+struct smb2_file_basic_info {
+        struct smb2_timeval creation_time;
+        struct smb2_timeval last_access_time;
+        struct smb2_timeval last_write_time;
+        struct smb2_timeval change_time;
+        uint32_t file_attributes;
+};
+
+/*
+ * FILE_STANDARD_INFORMATION
+ */
+struct smb2_file_standard_info {
+        uint64_t allocation_size;
+        uint64_t end_of_file;
+        uint32_t number_of_links;
+        uint8_t delete_pending;
+        uint8_t directory;
+};
+
+/*
+ * FILE_STREAM_INFORMATION
+ */
+struct smb2_file_stream_info {
+        uint32_t next_entry_offset;
+        uint32_t stream_name_length;
+        uint64_t stream_size;
+        uint64_t stream_allocation_size;
+        const char *stream_name;
+};
+
+/*
+ * FILE_POSITION_INFORMATION
+ */
+struct smb2_file_position_info {
+        uint64_t current_byte_offset;
+};
+
+/*
+ * FILE_NAME_INFORMATION
+ */
+struct smb2_file_name_info {
+        uint32_t file_name_length;
+        const uint8_t *name;
+};
+
+/*
+ * FILE_ALL_INFORMATION.
+ */
+struct smb2_file_all_info {
+        struct smb2_file_basic_info basic;
+        struct smb2_file_standard_info standard;
+        uint64_t index_number;
+        uint32_t ea_size;
+        uint32_t access_flags;
+        uint64_t current_byte_offset;
+        uint32_t mode;
+        uint32_t alignment_requirement;
+        const uint8_t *name;
+};
+
+struct smb2_query_info_request {
+        uint8_t info_type;
+        uint8_t file_info_class;
+        uint32_t output_buffer_length;
+        uint16_t input_buffer_offset;
+        uint32_t input_buffer_length;
+        uint8_t *input_buffer;
+        uint32_t additional_information;
+        uint32_t flags;
+        smb2_file_id file_id;
+        const uint8_t *input;
+};
+
+/*
+ * FILE_END_OF_FILE_INFORMATION.
+ */
+struct smb2_file_end_of_file_info {
+        uint64_t end_of_file;
+};
+
+/*
+ * FILE_DISPOSITION_INFORMATION.
+ */
+struct smb2_file_disposition_info {
+        uint8_t delete_pending;
+};
+
+/*
+ * SMB2_FILE_RENAME_INFORMATION.
+ */
+struct smb2_file_rename_info {
+        uint8_t replace_if_exist;
+        const uint8_t* file_name;
+};
+
+/*
+ * FILE_NETWORK_OPEN_INFORMATION
+ */
+struct smb2_file_network_open_info {
+        struct smb2_timeval creation_time;
+        struct smb2_timeval last_access_time;
+        struct smb2_timeval last_write_time;
+        struct smb2_timeval change_time;
+        uint64_t allocation_size;
+        uint64_t end_of_file;
+        uint32_t file_attributes;
+};
+
+#define SMB2_SET_INFO_REQUEST_SIZE 33
+
+struct smb2_set_info_request {
+        uint8_t info_type;
+        uint8_t file_info_class;
+        uint32_t buffer_length;
+        uint16_t buffer_offset;
+        uint32_t additional_information;
+        smb2_file_id file_id;
+        void *input_data;
+};
+
+#define SMB2_SET_INFO_REPLY_SIZE 2
+
+/*
+ * SID
+ */
+#define SID_ID_AUTH_LEN 6
+
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning( disable : 4200 ) /* Silence c4200 warning. */
+#endif
+
+struct smb2_sid {
+        uint8_t revision;
+        uint8_t sub_auth_count;
+        uint8_t id_auth[SID_ID_AUTH_LEN];
+        uint32_t sub_auth[0];
+};
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
+/*
+ * ACE
+ */
+/* ace type */
+#define SMB2_ACCESS_ALLOWED_ACE_TYPE                 0x00
+#define SMB2_ACCESS_DENIED_ACE_TYPE                  0x01
+#define SMB2_SYSTEM_AUDIT_ACE_TYPE                   0x02
+/*
+ * Reserved for future use
+ * #define SMB2_SYSTEM_ALARM_ACE_TYPE                   0x03
+ */
+#define SMB2_ACCESS_ALLOWED_OBJECT_ACE_TYPE          0x05
+#define SMB2_ACCESS_DENIED_OBJECT_ACE_TYPE           0x06
+#define SMB2_SYSTEM_AUDIT_OBJECT_ACE_TYPE            0x07
+/*
+ * Reserved for future use
+ * #define SMB2_SYSTEM_ALARM_OBJECT_ACE_TYPE            0x08
+ */
+#define SMB2_ACCESS_ALLOWED_CALLBACK_ACE_TYPE        0x09
+#define SMB2_ACCESS_DENIED_CALLBACK_ACE_TYPE         0x10
+#define SMB2_SYSTEM_MANDATORY_LABEL_ACE_TYPE         0x11
+#define SMB2_SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE      0x12
+#define SMB2_SYSTEM_SCOPED_POLICY_ID_ACE_TYPE        0x13
+
+/* ace flags */
+#define SMB2_OBJECT_INHERIT_ACE         0x01
+#define SMB2_CONTAINER_INHERIT_ACE      0x02
+#define SMB2_NO_PROPAGATE_INHERIT_ACE   0x04
+#define SMB2_INHERIT_ONLY_ACE           0x08
+#define SMB2_INHERITED_ACE              0x10
+#define SMB2_SUCCESSFUL_ACCESS_ACE_FLAG 0x40
+#define SMB2_FAILED_ACCESS_ACE_FLAG     0x80
+
+#define SMB2_OBJECT_TYPE_SIZE 16
+
+struct smb2_ace {
+        struct smb2_ace *next;
+
+        uint8_t ace_type;
+        uint8_t ace_flags;
+        uint16_t ace_size;
+
+        /* Which fields are valid depends on the ace type */
+        uint32_t mask;
+        uint32_t flags;
+        struct smb2_sid *sid;
+        uint8_t object_type[SMB2_OBJECT_TYPE_SIZE];
+        uint8_t inherited_object_type[SMB2_OBJECT_TYPE_SIZE];
+
+        /* ApplicationData/AttributeData. Used by
+         * SMB2_ACCESS_ALLOWED_CALLBACK_ACE_TYPE,
+         * SMB2_DENIED_ALLOWED_CALLBACK_ACE_TYPE,
+         * SMB2_SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE
+         */
+        size_t ad_len;
+        char *ad_data;
+
+        /* raw blob, used for unknown ACE types */
+        size_t   raw_len;
+        char *raw_data;
+};
+
+/*
+ * ACL
+ */
+#define SMB2_ACL_REVISION    0x02
+#define SMB2_ACL_REVISION_DS 0x04
+
+struct smb2_acl {
+        uint8_t revision;
+        uint16_t ace_count;
+        struct smb2_ace *aces;
+};
+
+/*
+ * SECURITY_DESCRIPTOR
+ */
+/* Security descriptor control flags */
+#define SMB2_SD_CONTROL_OD 0x0001
+#define SMB2_SD_CONTROL_GD 0x0002
+#define SMB2_SD_CONTROL_DP 0x0004
+#define SMB2_SD_CONTROL_DD 0x0008
+#define SMB2_SD_CONTROL_SP 0x0010
+#define SMB2_SD_CONTROL_SD 0x0020
+#define SMB2_SD_CONTROL_SS 0x0040
+#define SMB2_SD_CONTROL_DT 0x0080
+#define SMB2_SD_CONTROL_DC 0x0100
+#define SMB2_SD_CONTROL_SC 0x0200
+#define SMB2_SD_CONTROL_DI 0x0400
+#define SMB2_SD_CONTROL_SI 0x0800
+#define SMB2_SD_CONTROL_PD 0x1000
+#define SMB2_SD_CONTROL_PS 0x2000
+#define SMB2_SD_CONTROL_RM 0x4000
+#define SMB2_SD_CONTROL_SR 0x8000
+
+struct smb2_security_descriptor {
+        uint8_t revision;
+        uint16_t control;
+        struct smb2_sid *owner;
+        struct smb2_sid *group;
+        struct smb2_acl *dacl;
+};
+
+struct smb2_file_fs_volume_info {
+        struct smb2_timeval creation_time;
+        uint32_t volume_serial_number;
+        uint32_t volume_label_length;
+        uint8_t supports_objects;
+        uint8_t reserved;
+        const uint8_t *volume_label;
+};
+
+struct smb2_file_fs_size_info {
+        uint64_t total_allocation_units;
+        uint64_t available_allocation_units;
+        uint32_t sectors_per_allocation_unit;
+        uint32_t bytes_per_sector;
+};
+
+struct smb2_file_fs_attribute_info {
+        uint32_t filesystem_attributes;
+        uint32_t maximum_component_name_length;
+        uint32_t filesystem_name_length;
+        const uint8_t *filesystem_name;
+};
+
+/* Device type */
+#define FILE_DEVICE_CD_ROM 0x00000002
+#define FILE_DEVICE_DISK   0x00000007
+
+/* Characteristics */
+#define FILE_REMOVABLE_MEDIA                     0x00000001
+#define FILE_READ_ONLY_DEVICE                    0x00000002
+#define FILE_FLOPPY_DISKETTE                     0x00000004
+#define FILE_WRITE_ONCE_MEDIA                    0x00000008
+#define FILE_REMOTE_DEVICE                       0x00000010
+#define FILE_DEVICE_IS_MOUNTED                   0x00000020
+#define FILE_VIRTUAL_VOLUME                      0x00000040
+#define FILE_DEVICE_SECURE_OPEN                  0x00000100
+#define FILE_CHARACTERISTIC_TS_DEVICE            0x00001000
+#define FILE_CHARACTERISTIC_WEBDAV_DEVICE        0x00002000
+#define FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL 0x00020000
+#define FILE_PORTABLE_DEVICE                     0x00040000
+
+struct smb2_file_fs_device_info {
+        uint32_t device_type;
+        uint32_t characteristics;
+};
+
+/* File System Control Flags */
+#define FILE_VC_QUOTA_TRACK            0x00000001
+#define FILE_VC_QUOTA_ENFORCE          0x00000002
+#define FILE_VC_CONTENT_INDEX_DISABLED 0x00000008
+#define FILE_VC_LOG_QUOTA_THRESHOLD    0x00000010
+#define FILE_VC_LOG_QUOTA_LIMIT        0x00000020
+#define FILE_VC_LOG_VOLUME_THRESHOLD   0x00000040
+#define FILE_VC_LOG_VOLUME_LIMIT       0x00000080
+#define FILE_VC_QUOTAS_INCOMPLETE      0x00000100
+#define FILE_VC_QUOTAS_REBUILDING      0x00000200
+
+struct smb2_file_fs_control_info {
+        uint64_t free_space_start_filtering;
+        uint64_t free_space_threshold;
+        uint64_t free_space_stop_filtering;
+        uint64_t default_quota_threshold;
+        uint64_t default_quota_limit;
+        uint32_t file_system_control_flags;
+};
+
+struct smb2_file_fs_full_size_info {
+        uint64_t total_allocation_units;
+        uint64_t caller_available_allocation_units;
+        uint64_t actual_available_allocation_units;
+        uint32_t sectors_per_allocation_unit;
+        uint32_t bytes_per_sector;
+};
+
+struct smb2_file_fs_object_id_info {
+        smb2_guid object_id;
+        uint8_t extended_info[48];
+};
+
+/* Flags */
+#define SSINFO_FLAGS_ALIGNED_DEVICE              0x00000001
+#define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
+#define SSINFO_FLAGS_NO_SEEK_PENALTY             0x00000004
+#define SSINFO_FLAGS_TRIM_ENABLED                0x00000008
+
+struct smb2_file_fs_sector_size_info {
+        uint32_t logical_bytes_per_sector;
+        uint32_t physical_bytes_per_sector_for_atomicity;
+        uint32_t physical_bytes_per_sector_for_performance;
+        uint32_t file_system_effective_physical_bytes_per_sector_for_atomicity;
+        uint32_t flags;
+        uint32_t byte_offset_for_sector_alignment;
+        uint32_t byte_offset_for_partition_alignment;
+};
+
+#define SMB2_QUERY_INFO_REPLY_SIZE 9
+
+struct smb2_query_info_reply {
+        uint16_t output_buffer_offset;
+        uint32_t output_buffer_length;
+        void *output_buffer;
+};
+
+#define SMB2_IOCTL_REQUEST_SIZE 57
+
+/* CtlCode */
+#define SMB2_FSCTL_DFS_GET_REFERRALS            0x00060194
+#define SMB2_FSCTL_PIPE_PEEK                    0x0011400C
+#define SMB2_FSCTL_PIPE_WAIT                    0x00110018
+#define SMB2_FSCTL_PIPE_TRANSCEIVE              0x0011C017
+#define SMB2_FSCTL_SRV_COPYCHUNK                0x001440F2
+#define SMB2_FSCTL_SRV_ENUMERATE_SNAPSHOTS      0x00144064
+#define SMB2_FSCTL_SRV_REQUEST_RESUME_KEY       0x00140078
+#define SMB2_FSCTL_SRV_READ_HASH                0x001441bb
+#define SMB2_FSCTL_SRV_COPYCHUNK_WRITE          0x001480F2
+#define SMB2_FSCTL_LMR_REQUEST_RESILIENCY       0x001401D4
+#define SMB2_FSCTL_QUERY_NETWORK_INTERFACE_INFO 0x001401FC
+#define SMB2_FSCTL_SET_REPARSE_POINT            0x000900A4
+#define SMB2_FSCTL_GET_REPARSE_POINT            0X000900A8
+#define SMB2_FSCTL_DFS_GET_REFERRALS_EX         0x000601B0
+#define SMB2_FSCTL_FILE_LEVEL_TRIM              0x00098208
+#define SMB2_FSCTL_VALIDATE_NEGOTIATE_INFO      0x00140204
+
+/* Flags */
+#define SMB2_0_IOCTL_IS_FSCTL                   0x00000001
+
+#define SMB2_SYMLINK_FLAG_RELATIVE 0x00000001
+struct smb2_symlink_reparse_buffer {
+        uint32_t flags;
+        char *subname;
+        char *printname;
+};
+
+#define SMB2_REPARSE_TAG_SYMLINK                0xa000000c
+/*
+ * Reparse_data_buffer
+ */
+struct smb2_reparse_data_buffer {
+        uint32_t reparse_tag;
+        uint16_t reparse_data_length;
+        union {
+                struct smb2_symlink_reparse_buffer symlink;
+        };
+};
+
+struct smb2_ioctl_request {
+        uint32_t ctl_code;
+        smb2_file_id file_id;
+        uint32_t input_offset;
+        uint32_t input_count;
+        uint32_t max_input_response;
+        uint32_t output_offset;
+        uint32_t output_count;
+        uint32_t max_output_response;
+        uint32_t flags;
+        void *input;
+};
+
+#define SMB2_IOCTL_REPLY_SIZE 49
+
+struct smb2_ioctl_reply {
+        uint32_t ctl_code;
+        smb2_file_id file_id;
+        uint32_t input_offset;
+        uint32_t input_count;
+        uint32_t output_offset;
+        uint32_t output_count;
+        uint32_t flags;
+        void *output;
+};
+
+#define SMB2_IOCTL_VALIDIATE_NEGOTIATE_INFO_SIZE 24
+
+struct  smb2_ioctl_validate_negotiate_info {
+        uint32_t capabilities;
+        uint8_t  guid[16];
+        uint16_t security_mode;
+        uint16_t dialect;
+};
+
+#define SMB2_CHANGE_NOTIFY_FILE_NOTIFY_CHANGE_FILE_NAME    0x00000001
+#define SMB2_CHANGE_NOTIFY_FILE_NOTIFY_CHANGE_DIR_NAME     0x00000002
+#define SMB2_CHANGE_NOTIFY_FILE_NOTIFY_CHANGE_ATTRIBUTES   0x00000004
+#define SMB2_CHANGE_NOTIFY_FILE_NOTIFY_CHANGE_SIZE         0x00000008
+#define SMB2_CHANGE_NOTIFY_FILE_NOTIFY_CHANGE_LAST_WRITE   0x00000010
+#define SMB2_CHANGE_NOTIFY_FILE_NOTIFY_CHANGE_LAST_ACCESS  0x00000020
+#define SMB2_CHANGE_NOTIFY_FILE_NOTIFY_CHANGE_CREATION     0x00000040
+#define SMB2_CHANGE_NOTIFY_FILE_NOTIFY_CHANGE_EA           0x00000080
+#define SMB2_CHANGE_NOTIFY_FILE_NOTIFY_CHANGE_SECURITY     0x00000100
+#define SMB2_CHANGE_NOTIFY_FILE_NOTIFY_CHANGE_STREAM_NAME  0x00000200
+#define SMB2_CHANGE_NOTIFY_FILE_NOTIFY_CHANGE_STREAM_SIZE  0x00000400
+#define SMB2_CHANGE_NOTIFY_FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
+
+#define SMB2_CHANGE_NOTIFY_WATCH_TREE    0x0001
+
+#define SMB2_CHANGE_NOTIFY_REQUEST_SIZE 32
+
+#define SMB2_NOTIFY_CHANGE_FILE_ACTION_ADDED                0x0001
+#define SMB2_NOTIFY_CHANGE_FILE_ACTION_REMOVED              0x0002
+#define SMB2_NOTIFY_CHANGE_FILE_ACTION_MODIFIED             0x0003
+#define SMB2_NOTIFY_CHANGE_FILE_ACTION_RENAMED_OLD_NAME     0x0004
+#define SMB2_NOTIFY_CHANGE_FILE_ACTION_RENAMED_NEW_NAME     0x0005
+#define SMB2_NOTIFY_CHANGE_FILE_ACTION_ADDED_STREAM         0x0006
+#define SMB2_NOTIFY_CHANGE_FILE_ACTION_REMOVED_STREAM       0x0007
+#define SMB2_NOTIFY_CHANGE_FILE_ACTION_MODIFIED_STREAM      0x0008
+
+struct smb2_change_notify_request {
+        uint16_t flags;
+        uint32_t output_buffer_length;
+        smb2_file_id file_id;
+        uint32_t completion_filter;
+};
+
+#define SMB2_CHANGE_NOTIFY_REPLY_SIZE 9
+
+struct smb2_change_notify_reply {
+        uint16_t output_buffer_offset;
+        uint32_t output_buffer_length;
+        uint8_t *output;
+};
+
+struct smb2_file_notify_change_information {
+        uint32_t action;
+        const char *name;
+        struct smb2_file_notify_change_information *next;
+};
+
+int
+smb2_decode_filenotifychangeinformation(
+    struct smb2_context *smb2,
+    struct smb2_file_notify_change_information *fnc,
+    struct smb2_iovec *vec,
+    uint32_t next_entry_offset);
+
+#define SMB2_OPLOCK_LEVEL_NONE        0x00
+#define SMB2_OPLOCK_LEVEL_II          0x01
+#define SMB2_OPLOCK_LEVEL_EXCLUSIVE   0x08
+
+#define SMB2_OPLOCK_BREAK_NOTIFICATION_SIZE 24
+
+struct smb2_oplock_break_notification {
+        uint8_t oplock_level;
+        smb2_file_id file_id;
+};
+
+#define SMB2_OPLOCK_BREAK_ACKNOWLEDGE_SIZE 24
+
+struct smb2_oplock_break_acknowledgement {
+        uint8_t oplock_level;
+        smb2_file_id file_id;
+};
+
+#define SMB2_OPLOCK_BREAK_REPLY_SIZE 24
+
+struct smb2_oplock_break_reply {
+        uint8_t oplock_level;
+        smb2_file_id file_id;
+};
+
+#define SMB2_LEASE_NONE                 0x00
+#define SMB2_LEASE_READ_CACHING         0x01
+#define SMB2_LEASE_HANDLE_CACHING       0x02
+#define SMB2_LEASE_WRITE_CACHING        0x04
+
+#define SMB2_BREAK_TYPE_OPLOCK_NOTIFICATION     0x01
+#define SMB2_BREAK_TYPE_OPLOCK_RESPONSE         0x02
+#define SMB2_BREAK_TYPE_OPLOCK_ACKNOWLEDGE      0x03
+
+#define SMB2_BREAK_TYPE_LEASE_NOTIFICATION      0x04
+#define SMB2_BREAK_TYPE_LEASE_RESPONSE          0x05
+#define SMB2_BREAK_TYPE_LEASE_ACKNOWLEDGE       0x06
+
+#define SMB2_LEASE_BREAK_NOTIFICATION_SIZE 44
+
+struct smb2_lease_break_notification {
+        uint16_t new_epoch;
+        uint32_t flags;
+        smb2_lease_key lease_key;
+        uint32_t current_lease_state;
+        uint32_t new_lease_state;
+        uint32_t break_reason;
+        uint32_t access_mask_hint;
+        uint32_t share_mask_hint;
+};
+
+#define SMB2_LEASE_BREAK_ACKNOWLEDGE_SIZE 36
+
+struct smb2_lease_break_acknowledgement {
+        uint32_t flags;
+        smb2_lease_key lease_key;
+        uint32_t lease_state;
+        uint64_t lease_duration;
+};
+
+#define SMB2_LEASE_BREAK_REPLY_SIZE 36
+
+struct smb2_lease_break_reply {
+        uint32_t flags;
+        smb2_lease_key lease_key;
+        uint32_t lease_state;
+        uint64_t lease_duration;
+};
+
+/* note that for oplocks, notifications (request) and responses (reply)
+ * come from the server, while acknowledgements come from the client
+ */
+struct smb2_oplock_or_lease_break_reply {
+        uint16_t struct_size;
+        int break_type;
+        union {
+                struct smb2_oplock_break_notification oplock;
+                struct smb2_oplock_break_reply oplockrep;
+                struct smb2_lease_break_notification lease;
+                struct smb2_lease_break_reply leaserep;
+        }
+        lock;
+};
+
+struct smb2_oplock_or_lease_break_request {
+        uint16_t struct_size;
+        int break_type;
+        union {
+                struct smb2_oplock_break_acknowledgement oplock;
+                struct smb2_lease_break_acknowledgement lease;
+        }
+        lock;
+};
+
+#define SMB2_WRITE_REQUEST_SIZE 49
+
+#define SMB2_WRITEFLAG_WRITE_THROUGH    0x00000001
+#define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002
+
+struct smb2_write_request {
+        uint16_t data_offset;
+        uint32_t length;
+        uint64_t offset;
+        const uint8_t* buf;
+        smb2_file_id file_id;
+        uint32_t channel;
+        uint32_t remaining_bytes;
+        uint16_t write_channel_info_offset;
+        uint16_t write_channel_info_length;
+        uint8_t *write_channel_info;
+        uint32_t flags;
+};
+
+#define SMB2_WRITE_REPLY_SIZE 17
+
+struct smb2_write_reply {
+        uint32_t count;
+        uint32_t remaining;
+};
+
+#define SMB2_LOCK_ELEMENT_SIZE 24
+
+struct smb2_lock_element {
+        uint64_t offset;
+        uint64_t length;
+        uint32_t flags;
+        uint32_t reserved;
+};
+
+/* Note that this size includes 1 lock element */
+#define SMB2_LOCK_REQUEST_SIZE 48
+
+struct smb2_lock_request {
+        uint16_t lock_count;
+        uint8_t  lock_sequence_number;
+        uint32_t lock_sequence_index;
+        smb2_file_id file_id;
+        struct smb2_lock_element *locks;
+};
+
+#define SMB2_LOCK_REPLY_SIZE 4
+
+
+#define SMB2_ECHO_REQUEST_SIZE 4
+#define SMB2_ECHO_REPLY_SIZE 4
+#define SMB2_CANCEL_REQUEST_SIZE 4
+
+#define SMB2_LOGOFF_REQUEST_SIZE 4
+#define SMB2_LOGOFF_REPLY_SIZE 4
+
+#define SMB2_TREE_DISCONNECT_REQUEST_SIZE 4
+#define SMB2_TREE_DISCONNECT_REPLY_SIZE 4
+
+#define SMB_ENCRYPTION_AES128_CCM     0x0001
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_SMB2_H_ */

+ 139 - 0
entry/src/main/cpp/include/xbox 360/config.h

@@ -0,0 +1,139 @@
+/* config.h.  Generated from config.h.in by configure.  */
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Whether or not TCP sockets should be allowed to linger after closure */
+#define CONFIGURE_OPTION_TCP_LINGER 1
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+/* #undef HAVE_ARPA_INET_H */
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+/* #undef HAVE_DLFCN_H */
+
+/* Define to 1 if you have the <errno.h> header file. */
+#define HAVE_ERRNO_H 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the <gssapi/gssapi.h> header file. */
+/* #undef HAVE_GSSAPI_GSSAPI_H */
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+/* #undef HAVE_INTTYPES_H */
+
+/* Whether we use gssapi_krb5 or not */
+/* #undef HAVE_LIBKRB5 */
+
+/* Define to 1 if you have the `nsl' library (-lnsl). */
+/* #undef HAVE_LIBNSL */
+
+/* Define to 1 if you have the `socket' library (-lsocket). */
+/* #undef HAVE_LIBSOCKET */
+
+/* Whether we have linger */
+#define HAVE_LINGER 1
+
+/* Define to 1 if you have the <netdb.h> header file. */
+/* #undef HAVE_NETDB_H */
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+/* #undef HAVE_NETINET_IN_H */
+
+/* Define to 1 if you have the <netinet/tcp.h> header file. */
+/* #undef HAVE_NETINET_TCP_H */
+
+/* Define to 1 if you have the <poll.h> header file. */
+/* #undef HAVE_POLL_H */
+
+/* Whether sockaddr struct has sa_len */
+/* #undef HAVE_SOCKADDR_LEN */
+
+/* Whether we have sockaddr_Storage */
+/* #undef HAVE_SOCKADDR_STORAGE */
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#define HAVE_STDIO_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+/* #undef HAVE_STRINGS_H 1 */
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/errno.h> header file. */
+/* #undef HAVE_SYS_ERRNO_H 1 */
+
+/* Define to 1 if you have the <sys/fcntl.h> header file. */
+/* #undef HAVE_SYS_FCNTL_H */
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+/* #undef HAVE_SYS_IOCTL_H */
+
+/* Define to 1 if you have the <sys/poll.h> header file. */
+/* #undef HAVE_SYS_POLL_H */
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+/* #undef HAVE_SYS_SOCKET_H */
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+/* #undef HAVE_SYS_TIME_H 1 */
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/uio.h> header file. */
+/* #undef HAVE_SYS_UIO_H */
+
+/* Define to 1 if you have the <sys/unistd.h> header file. */
+/* #undef HAVE_SYS_UNISTD_H */
+
+/* Define to 1 if you have the <sys/_iovec.h> header file. */
+/* #undef HAVE_SYS__IOVEC_H */
+
+/* Define to 1 if you have the <time.h> header file. */
+#define HAVE_TIME_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+/* #undef HAVE_UNISTD_H */
+
+/* Define to the sub-directory where libtool stores uninstalled libraries. */
+#define LT_OBJDIR ".libs/"
+
+/* Name of package */
+#define PACKAGE "libsmb2"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "ronniesahlberg@gmail.com"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libsmb2"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libsmb2 4.0.0"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libsmb2"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "4.0.0"
+
+/* Define to 1 if all of the C90 standard headers exist (not just the ones
+   required in a freestanding environment). This macro is provided for
+   backward compatibility; new code need not use it. */
+#define STDC_HEADERS 1
+
+/* Version number of package */
+#define VERSION "4.0.0"

+ 139 - 0
entry/src/main/cpp/include/xbox/config.h

@@ -0,0 +1,139 @@
+/* config.h.  Generated from config.h.in by configure.  */
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Whether or not TCP sockets should be allowed to linger after closure */
+#define CONFIGURE_OPTION_TCP_LINGER 1
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+/* #undef HAVE_ARPA_INET_H */
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+/* #undef HAVE_DLFCN_H */
+
+/* Define to 1 if you have the <errno.h> header file. */
+#define HAVE_ERRNO_H 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the <gssapi/gssapi.h> header file. */
+/* #undef HAVE_GSSAPI_GSSAPI_H */
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+/* #undef HAVE_INTTYPES_H */
+
+/* Whether we use gssapi_krb5 or not */
+/* #undef HAVE_LIBKRB5 */
+
+/* Define to 1 if you have the `nsl' library (-lnsl). */
+/* #undef HAVE_LIBNSL */
+
+/* Define to 1 if you have the `socket' library (-lsocket). */
+/* #undef HAVE_LIBSOCKET */
+
+/* Whether we have linger */
+#define HAVE_LINGER 1
+
+/* Define to 1 if you have the <netdb.h> header file. */
+/* #undef HAVE_NETDB_H */
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+/* #undef HAVE_NETINET_IN_H */
+
+/* Define to 1 if you have the <netinet/tcp.h> header file. */
+/* #undef HAVE_NETINET_TCP_H */
+
+/* Define to 1 if you have the <poll.h> header file. */
+/* #undef HAVE_POLL_H */
+
+/* Whether sockaddr struct has sa_len */
+/* #undef HAVE_SOCKADDR_LEN */
+
+/* Whether we have sockaddr_Storage */
+#define HAVE_SOCKADDR_STORAGE 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+/* #undef HAVE_STDINT_H */
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#define HAVE_STDIO_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+/* #undef HAVE_STRINGS_H */
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/errno.h> header file. */
+/* #undef HAVE_SYS_ERRNO_H */
+
+/* Define to 1 if you have the <sys/fcntl.h> header file. */
+/* #undef HAVE_SYS_FCNTL_H */
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+/* #undef HAVE_SYS_IOCTL_H */
+
+/* Define to 1 if you have the <sys/poll.h> header file. */
+/* #undef HAVE_SYS_POLL_H */
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+/* #undef HAVE_SYS_SOCKET_H */
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+/* #undef HAVE_SYS_TIME_H */
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/uio.h> header file. */
+/* #undef HAVE_SYS_UIO_H */
+
+/* Define to 1 if you have the <sys/unistd.h> header file. */
+/* #undef HAVE_SYS_UNISTD_H */
+
+/* Define to 1 if you have the <sys/_iovec.h> header file. */
+/* #undef HAVE_SYS__IOVEC_H */
+
+/* Define to 1 if you have the <time.h> header file. */
+#define HAVE_TIME_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+/* #undef HAVE_UNISTD_H */
+
+/* Define to the sub-directory where libtool stores uninstalled libraries. */
+#define LT_OBJDIR ".libs/"
+
+/* Name of package */
+#define PACKAGE "libsmb2"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "ronniesahlberg@gmail.com"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libsmb2"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libsmb2 4.0.0"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libsmb2"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "4.0.0"
+
+/* Define to 1 if all of the C90 standard headers exist (not just the ones
+   required in a freestanding environment). This macro is provided for
+   backward compatibility; new code need not use it. */
+#define STDC_HEADERS 1
+
+/* Version number of package */
+#define VERSION "4.0.0"

BIN
entry/src/main/cpp/libs/arm64-v8a/libsmb2.so


+ 559 - 22
entry/src/main/cpp/napi_init.cpp

@@ -1,53 +1,590 @@
 #include "napi/native_api.h"
 #include "napi/native_api.h"
 
 
-static napi_value Add(napi_env env, napi_callback_info info)
+#include <algorithm>
+#include <atomic>
+#include <cctype>
+#include <cstdint>
+#include <cstring>
+#include <memory>
+#include <mutex>
+#include <stdexcept>
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "hilog/log.h"
+
+extern "C" {
+#include "smb2/smb2.h"
+#include "smb2/libsmb2.h"
+}
+
+namespace {
+constexpr unsigned int SMB_LOG_DOMAIN = 0xD001780;
+constexpr const char *SMB_LOG_TAG = "libsmb2";
+
+#define SMB_LOGI(fmt, ...) OH_LOG_Print(LOG_APP, LOG_INFO, SMB_LOG_DOMAIN, SMB_LOG_TAG, fmt, ##__VA_ARGS__)
+#define SMB_LOGE(fmt, ...) OH_LOG_Print(LOG_APP, LOG_ERROR, SMB_LOG_DOMAIN, SMB_LOG_TAG, fmt, ##__VA_ARGS__)
+inline void NapiCheck(napi_status status, const char *message)
+{
+    if (status != napi_ok) {
+        throw std::runtime_error(message == nullptr ? "NAPI call failed" : message);
+    }
+}
+
+struct SambaClient {
+    int64_t id = 0;
+    std::string host;
+    smb2_context *ctx = nullptr;
+    bool closed = false;
+};
+
+struct SambaSession {
+    int64_t id = 0;
+    std::weak_ptr<SambaClient> client;
+    std::string username;
+    std::string password;
+    std::string domain;
+    bool closed = false;
+    int64_t activeTreeId = 0;
+};
+
+struct SambaTree {
+    int64_t id = 0;
+    std::weak_ptr<SambaSession> session;
+    std::string share;
+    bool connected = false;
+};
+
+std::atomic<int64_t> g_nextHandle{1};
+std::mutex g_mutex;
+std::unordered_map<int64_t, std::shared_ptr<SambaClient>> g_clients;
+std::unordered_map<int64_t, std::shared_ptr<SambaSession>> g_sessions;
+std::unordered_map<int64_t, std::shared_ptr<SambaTree>> g_trees;
+
+int64_t GenerateHandle()
+{
+    return g_nextHandle.fetch_add(1);
+}
+
+void Ensure(bool condition, const std::string &message)
+{
+    if (!condition) {
+        throw std::runtime_error(message);
+    }
+}
+
+std::string Trim(const std::string &value)
+{
+    if (value.empty()) {
+        return value;
+    }
+    size_t start = 0;
+    size_t end = value.size();
+    while (start < end && std::isspace(static_cast<unsigned char>(value[start])) != 0) {
+        start++;
+    }
+    if (start == end) {
+        return "";
+    }
+    while (end > start && std::isspace(static_cast<unsigned char>(value[end - 1])) != 0) {
+        end--;
+    }
+    return value.substr(start, end - start);
+}
+
+std::string NormalizeRemotePath(const std::string &raw)
 {
 {
-    size_t argc = 2;
-    napi_value args[2] = {nullptr};
+    std::string trimmed = Trim(raw);
+    if (trimmed.empty() || trimmed == "/" || trimmed == "\\") {
+        return "";
+    }
+    size_t index = 0;
+    while (index < trimmed.size() && (trimmed[index] == '/' || trimmed[index] == '\\')) {
+        index++;
+    }
+    std::string normalized = trimmed.substr(index);
+    if (normalized.empty()) {
+        return "";
+    }
+    std::replace(normalized.begin(), normalized.end(), '\\', '/');
+    return normalized;
+}
 
 
-    napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
+std::string BuildSmbErrorMessage(smb2_context *ctx, const std::string &fallback)
+{
+    const char *error = ctx != nullptr ? smb2_get_error(ctx) : nullptr;
+    if (error == nullptr || std::strlen(error) == 0) {
+        return fallback;
+    }
+    return fallback + ": " + error;
+}
 
 
-    napi_valuetype valuetype0;
-    napi_typeof(env, args[0], &valuetype0);
+std::string ReadString(napi_env env, napi_value value, const char *name, bool required)
+{
+    napi_valuetype type = napi_undefined;
+    NapiCheck(napi_typeof(env, value, &type), "Failed to read argument type");
+    if (type == napi_null || type == napi_undefined) {
+        if (required) {
+            throw std::runtime_error(std::string(name) + " is required");
+        }
+        return "";
+    }
+    if (type != napi_string) {
+        throw std::runtime_error(std::string(name) + " must be a string");
+    }
+    size_t length = 0;
+    NapiCheck(napi_get_value_string_utf8(env, value, nullptr, 0, &length), "Failed to measure string length");
+    std::string result(length, '\0');
+    size_t written = 0;
+    NapiCheck(napi_get_value_string_utf8(env, value, result.data(), length + 1, &written), "Failed to read string value");
+    result.resize(written);
+    return result;
+}
 
 
-    napi_valuetype valuetype1;
-    napi_typeof(env, args[1], &valuetype1);
+int64_t ReadInt64(napi_env env, napi_value value, const char *name)
+{
+    napi_valuetype type = napi_undefined;
+    NapiCheck(napi_typeof(env, value, &type), "Failed to read numeric argument type");
+    if (type != napi_number) {
+        throw std::runtime_error(std::string(name) + " must be a number");
+    }
+    int64_t result = 0;
+    NapiCheck(napi_get_value_int64(env, value, &result), "Failed to read numeric argument");
+    return result;
+}
+
+napi_value CreateInt64Value(napi_env env, int64_t value)
+{
+    napi_value result = nullptr;
+    NapiCheck(napi_create_int64(env, value, &result), "Failed to create int value");
+    return result;
+}
 
 
-    double value0;
-    napi_get_value_double(env, args[0], &value0);
+napi_value CreateUndefined(napi_env env)
+{
+    napi_value result = nullptr;
+    NapiCheck(napi_get_undefined(env, &result), "Failed to create undefined value");
+    return result;
+}
 
 
-    double value1;
-    napi_get_value_double(env, args[1], &value1);
+std::shared_ptr<SambaClient> RequireClient(int64_t clientId)
+{
+    std::lock_guard<std::mutex> lock(g_mutex);
+    auto it = g_clients.find(clientId);
+    if (it == g_clients.end() || it->second == nullptr || it->second->closed) {
+        throw std::runtime_error("Invalid SMB client handle");
+    }
+    return it->second;
+}
 
 
-    napi_value sum;
-    napi_create_double(env, value0 + value1, &sum);
+std::shared_ptr<SambaSession> RequireSession(int64_t sessionId)
+{
+    std::lock_guard<std::mutex> lock(g_mutex);
+    auto it = g_sessions.find(sessionId);
+    if (it == g_sessions.end() || it->second == nullptr || it->second->closed) {
+        throw std::runtime_error("Invalid SMB session handle");
+    }
+    return it->second;
+}
 
 
-    return sum;
+std::shared_ptr<SambaTree> RequireTree(int64_t treeId)
+{
+    std::lock_guard<std::mutex> lock(g_mutex);
+    auto it = g_trees.find(treeId);
+    if (it == g_trees.end() || it->second == nullptr) {
+        throw std::runtime_error("Invalid SMB tree handle");
+    }
+    return it->second;
+}
 
 
+void RemoveTreeEntry(int64_t treeId)
+{
+    std::lock_guard<std::mutex> lock(g_mutex);
+    g_trees.erase(treeId);
+}
+
+void ResetSessionTree(const std::shared_ptr<SambaSession> &session, int64_t treeId)
+{
+    if (session == nullptr) {
+        return;
+    }
+    std::lock_guard<std::mutex> lock(g_mutex);
+    if (session->activeTreeId == treeId) {
+        session->activeTreeId = 0;
+    }
+}
+
+void CloseTreeInternal(const std::shared_ptr<SambaTree> &tree)
+{
+    if (!tree) {
+        return;
+    }
+    auto session = tree->session.lock();
+    auto client = session ? session->client.lock() : nullptr;
+    if (client && client->ctx && tree->connected) {
+        smb2_disconnect_share(client->ctx);
+    }
+    tree->connected = false;
+    ResetSessionTree(session, tree->id);
+}
+
+void RemoveTreesForSession(int64_t sessionId)
+{
+    std::vector<std::shared_ptr<SambaTree>> ownedTrees;
+    {
+        std::lock_guard<std::mutex> lock(g_mutex);
+        for (auto it = g_trees.begin(); it != g_trees.end(); ) {
+            auto session = it->second ? it->second->session.lock() : nullptr;
+            if (!session || session->id == sessionId) {
+                ownedTrees.push_back(it->second);
+                it = g_trees.erase(it);
+                continue;
+            }
+            ++it;
+        }
+    }
+    for (const auto &tree : ownedTrees) {
+        CloseTreeInternal(tree);
+    }
+}
+
+void RemoveSessionsForClient(int64_t clientId)
+{
+    std::vector<std::shared_ptr<SambaSession>> sessions;
+    {
+        std::lock_guard<std::mutex> lock(g_mutex);
+        for (auto it = g_sessions.begin(); it != g_sessions.end(); ) {
+            auto client = it->second ? it->second->client.lock() : nullptr;
+            if (!client || client->id == clientId) {
+                it->second->closed = true;
+                sessions.push_back(it->second);
+                it = g_sessions.erase(it);
+                continue;
+            }
+            ++it;
+        }
+    }
+    for (const auto &session : sessions) {
+        RemoveTreesForSession(session->id);
+    }
+}
+
+void CloseClientContext(const std::shared_ptr<SambaClient> &client)
+{
+    if (!client || client->ctx == nullptr) {
+        return;
+    }
+    smb2_disconnect_share(client->ctx);
+    smb2_destroy_context(client->ctx);
+    client->ctx = nullptr;
+    client->closed = true;
+}
+
+napi_value CreateClient(napi_env env, napi_callback_info info)
+{
+    try {
+        size_t argc = 1;
+        napi_value args[1] = {nullptr};
+        NapiCheck(napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), "Failed to get arguments for createClient");
+        if (argc < 1) {
+            throw std::runtime_error("host argument is required");
+        }
+        std::string host = Trim(ReadString(env, args[0], "host", true));
+        Ensure(!host.empty(), "host must not be empty");
+
+        smb2_context *ctx = smb2_init_context();
+        if (ctx == nullptr) {
+            throw std::runtime_error("Unable to initialize libsmb2 context");
+        }
+        smb2_set_timeout(ctx, 15);
+        smb2_set_authentication(ctx, SMB2_SEC_NTLMSSP);
+
+        auto client = std::make_shared<SambaClient>();
+        client->id = GenerateHandle();
+        client->host = host;
+        client->ctx = ctx;
+        {
+            std::lock_guard<std::mutex> lock(g_mutex);
+            g_clients[client->id] = client;
+        }
+        return CreateInt64Value(env, client->id);
+    } catch (const std::exception &error) {
+        napi_throw_error(env, nullptr, error.what());
+        return nullptr;
+    }
+}
+
+napi_value DestroyClient(napi_env env, napi_callback_info info)
+{
+    try {
+        size_t argc = 1;
+        napi_value args[1] = {nullptr};
+        NapiCheck(napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), "Failed to get arguments for destroyClient");
+        if (argc < 1) {
+            return CreateUndefined(env);
+        }
+        int64_t clientId = ReadInt64(env, args[0], "clientId");
+        std::shared_ptr<SambaClient> client;
+        {
+            std::lock_guard<std::mutex> lock(g_mutex);
+            auto it = g_clients.find(clientId);
+            if (it != g_clients.end()) {
+                client = it->second;
+                g_clients.erase(it);
+            }
+        }
+        if (client) {
+            RemoveSessionsForClient(client->id);
+            CloseClientContext(client);
+        }
+        return CreateUndefined(env);
+    } catch (const std::exception &error) {
+        napi_throw_error(env, nullptr, error.what());
+        return nullptr;
+    }
+}
+
+napi_value Authenticate(napi_env env, napi_callback_info info)
+{
+    try {
+        size_t argc = 4;
+        napi_value args[4] = {nullptr};
+        NapiCheck(napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), "Failed to get arguments for authenticate");
+        if (argc < 3) {
+            throw std::runtime_error("authenticate requires clientId, username and password");
+        }
+        int64_t clientId = ReadInt64(env, args[0], "clientId");
+        std::string username = Trim(ReadString(env, args[1], "username", true));
+        std::string password = ReadString(env, args[2], "password", true);
+        std::string domain;
+        if (argc >= 4) {
+            domain = Trim(ReadString(env, args[3], "domain", false));
+        }
+        Ensure(!username.empty(), "username must not be empty");
+
+        auto client = RequireClient(clientId);
+        auto session = std::make_shared<SambaSession>();
+        session->id = GenerateHandle();
+        session->client = client;
+        session->username = username;
+        session->password = password;
+        session->domain = domain;
+        {
+            std::lock_guard<std::mutex> lock(g_mutex);
+            g_sessions[session->id] = session;
+        }
+        return CreateInt64Value(env, session->id);
+    } catch (const std::exception &error) {
+        napi_throw_error(env, nullptr, error.what());
+        return nullptr;
+    }
+}
+
+napi_value DisconnectSession(napi_env env, napi_callback_info info)
+{
+    try {
+        size_t argc = 1;
+        napi_value args[1] = {nullptr};
+        NapiCheck(napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), "Failed to get arguments for disconnectSession");
+        if (argc < 1) {
+            return CreateUndefined(env);
+        }
+        int64_t sessionId = ReadInt64(env, args[0], "sessionId");
+        std::shared_ptr<SambaSession> session;
+        {
+            std::lock_guard<std::mutex> lock(g_mutex);
+            auto it = g_sessions.find(sessionId);
+            if (it != g_sessions.end()) {
+                session = it->second;
+                g_sessions.erase(it);
+            }
+        }
+        if (session) {
+            session->closed = true;
+            RemoveTreesForSession(session->id);
+        }
+        return CreateUndefined(env);
+    } catch (const std::exception &error) {
+        napi_throw_error(env, nullptr, error.what());
+        return nullptr;
+    }
+}
+
+napi_value ConnectTree(napi_env env, napi_callback_info info)
+{
+    try {
+        size_t argc = 2;
+        napi_value args[2] = {nullptr};
+        NapiCheck(napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), "Failed to get arguments for connectTree");
+        if (argc < 2) {
+            throw std::runtime_error("connectTree requires sessionId and share name");
+        }
+        int64_t sessionId = ReadInt64(env, args[0], "sessionId");
+        std::string share = Trim(ReadString(env, args[1], "share", true));
+        Ensure(!share.empty(), "share must not be empty");
+
+        auto session = RequireSession(sessionId);
+        auto client = session->client.lock();
+        if (!client || client->closed) {
+            throw std::runtime_error("SMB client is not available");
+        }
+        Ensure(session->activeTreeId == 0, "Session already has an active tree");
+        smb2_context *ctx = client->ctx;
+        if (ctx == nullptr) {
+            throw std::runtime_error("SMB context is not initialized");
+        }
+        smb2_set_user(ctx, session->username.c_str());
+        smb2_set_password(ctx, session->password.c_str());
+        smb2_set_domain(ctx, session->domain.empty() ? nullptr : session->domain.c_str());
+
+        int rc = smb2_connect_share(ctx, client->host.c_str(), share.c_str(), session->username.c_str());
+        if (rc != 0) {
+            throw std::runtime_error(BuildSmbErrorMessage(ctx, "Failed to connect to share"));
+        }
+
+        auto tree = std::make_shared<SambaTree>();
+        tree->id = GenerateHandle();
+        tree->session = session;
+        tree->share = share;
+        tree->connected = true;
+        {
+            std::lock_guard<std::mutex> lock(g_mutex);
+            session->activeTreeId = tree->id;
+            g_trees[tree->id] = tree;
+        }
+        return CreateInt64Value(env, tree->id);
+    } catch (const std::exception &error) {
+        napi_throw_error(env, nullptr, error.what());
+        return nullptr;
+    }
+}
+
+napi_value DisconnectTree(napi_env env, napi_callback_info info)
+{
+    try {
+        size_t argc = 1;
+        napi_value args[1] = {nullptr};
+        NapiCheck(napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), "Failed to get arguments for disconnectTree");
+        if (argc < 1) {
+            return CreateUndefined(env);
+        }
+        int64_t treeId = ReadInt64(env, args[0], "treeId");
+        std::shared_ptr<SambaTree> tree;
+        {
+            std::lock_guard<std::mutex> lock(g_mutex);
+            auto it = g_trees.find(treeId);
+            if (it != g_trees.end()) {
+                tree = it->second;
+                g_trees.erase(it);
+            }
+        }
+        CloseTreeInternal(tree);
+        return CreateUndefined(env);
+    } catch (const std::exception &error) {
+        napi_throw_error(env, nullptr, error.what());
+        return nullptr;
+    }
+}
+
+napi_value ReadDirectory(napi_env env, napi_callback_info info)
+{
+    try {
+        size_t argc = 2;
+        napi_value args[2] = {nullptr};
+        NapiCheck(napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), "Failed to get arguments for readDirectory");
+        if (argc < 2) {
+            throw std::runtime_error("readDirectory requires treeId and remote path");
+        }
+        int64_t treeId = ReadInt64(env, args[0], "treeId");
+        std::string path = ReadString(env, args[1], "path", false);
+        auto tree = RequireTree(treeId);
+        auto session = tree->session.lock();
+        auto client = session ? session->client.lock() : nullptr;
+        if (!client || client->ctx == nullptr) {
+            throw std::runtime_error("SMB client context is not available");
+        }
+        Ensure(tree->connected, "SMB tree is not connected");
+        std::string normalized = NormalizeRemotePath(path);
+        SMB_LOGI("readDirectory invoked tree=%{public}lld path=%{public}s", static_cast<long long>(treeId), normalized.c_str());
+        smb2_context *ctx = client->ctx;
+        smb2dir *dir = smb2_opendir(ctx, normalized.c_str());
+        if (dir == nullptr) {
+            const char *err = ctx != nullptr ? smb2_get_error(ctx) : "";
+            SMB_LOGE("smb2_opendir failed tree=%{public}lld path=%{public}s err=%{public}s", static_cast<long long>(treeId), normalized.c_str(), err ? err : "");
+            throw std::runtime_error(BuildSmbErrorMessage(ctx, "Failed to open remote directory"));
+        }
+        std::vector<napi_value> entries;
+        struct smb2dirent *dirent = nullptr;
+        while ((dirent = smb2_readdir(ctx, dir)) != nullptr) {
+            if (!dirent->name) {
+                continue;
+            }
+            if (std::strcmp(dirent->name, ".") == 0 || std::strcmp(dirent->name, "..") == 0) {
+                continue;
+            }
+            napi_value entry = nullptr;
+            NapiCheck(napi_create_object(env, &entry), "Failed to create directory entry object");
+            napi_value nameValue = nullptr;
+            NapiCheck(napi_create_string_utf8(env, dirent->name, NAPI_AUTO_LENGTH, &nameValue), "Failed to create directory name");
+            NapiCheck(napi_set_named_property(env, entry, "name", nameValue), "Failed to set name property");
+            NapiCheck(napi_set_named_property(env, entry, "fileName", nameValue), "Failed to set fileName property");
+
+            bool isDirectory = dirent->st.smb2_type == SMB2_TYPE_DIRECTORY;
+            bool isFile = dirent->st.smb2_type == SMB2_TYPE_FILE;
+            napi_value dirValue = nullptr;
+            NapiCheck(napi_get_boolean(env, isDirectory, &dirValue), "Failed to create directory flag");
+            NapiCheck(napi_set_named_property(env, entry, "isDirectory", dirValue), "Failed to set directory flag");
+            napi_value fileValue = nullptr;
+            NapiCheck(napi_get_boolean(env, isFile, &fileValue), "Failed to create file flag");
+            NapiCheck(napi_set_named_property(env, entry, "isFile", fileValue), "Failed to set file flag");
+            napi_value sizeValue = nullptr;
+            NapiCheck(napi_create_double(env, static_cast<double>(dirent->st.smb2_size), &sizeValue), "Failed to create size value");
+            NapiCheck(napi_set_named_property(env, entry, "size", sizeValue), "Failed to set size property");
+            entries.push_back(entry);
+        }
+        smb2_closedir(ctx, dir);
+        napi_value result = nullptr;
+        NapiCheck(napi_create_array_with_length(env, entries.size(), &result), "Failed to create directory result array");
+        for (size_t i = 0; i < entries.size(); i++) {
+            NapiCheck(napi_set_element(env, result, i, entries[i]), "Failed to append directory entry");
+        }
+        return result;
+    } catch (const std::exception &error) {
+        napi_throw_error(env, nullptr, error.what());
+        return nullptr;
+    }
+}
 }
 }
 
 
 EXTERN_C_START
 EXTERN_C_START
 static napi_value Init(napi_env env, napi_value exports)
 static napi_value Init(napi_env env, napi_value exports)
 {
 {
-    napi_property_descriptor desc[] = {
-        { "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr }
+    napi_property_descriptor descriptors[] = {
+        {"createClient", nullptr, CreateClient, nullptr, nullptr, nullptr, napi_default, nullptr},
+        {"destroyClient", nullptr, DestroyClient, nullptr, nullptr, nullptr, napi_default, nullptr},
+        {"authenticate", nullptr, Authenticate, nullptr, nullptr, nullptr, napi_default, nullptr},
+        {"disconnectSession", nullptr, DisconnectSession, nullptr, nullptr, nullptr, napi_default, nullptr},
+        {"connectTree", nullptr, ConnectTree, nullptr, nullptr, nullptr, napi_default, nullptr},
+        {"disconnectTree", nullptr, DisconnectTree, nullptr, nullptr, nullptr, napi_default, nullptr},
+        {"readDirectory", nullptr, ReadDirectory, nullptr, nullptr, nullptr, napi_default, nullptr}
     };
     };
-    napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
+    NapiCheck(napi_define_properties(env, exports, sizeof(descriptors) / sizeof(descriptors[0]), descriptors), "Failed to define native exports");
     return exports;
     return exports;
 }
 }
 EXTERN_C_END
 EXTERN_C_END
 
 
-static napi_module demoModule = {
+static napi_module g_module = {
     .nm_version = 1,
     .nm_version = 1,
     .nm_flags = 0,
     .nm_flags = 0,
     .nm_filename = nullptr,
     .nm_filename = nullptr,
     .nm_register_func = Init,
     .nm_register_func = Init,
     .nm_modname = "entry",
     .nm_modname = "entry",
-    .nm_priv = ((void*)0),
-    .reserved = { 0 },
+    .nm_priv = nullptr,
+    .reserved = {0},
 };
 };
 
 
 extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
 extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
 {
 {
-    napi_module_register(&demoModule);
+    napi_module_register(&g_module);
 }
 }

+ 22 - 1
entry/src/main/cpp/types/libentry/Index.d.ts

@@ -1 +1,22 @@
-export const add: (a: number, b: number) => number;
+export interface NativeDirectoryEntry {
+  name?: string;
+  fileName?: string;
+  isDirectory?: boolean;
+  isFile?: boolean;
+  size?: number;
+}
+
+export interface NativeModule {
+  createClient(host: string): number;
+  destroyClient(clientId: number): void;
+  authenticate(clientId: number, username: string, password: string, domain?: string): number;
+  disconnectSession(sessionId: number): void;
+  connectTree(sessionId: number, share: string): number;
+  disconnectTree(treeId: number): void;
+  readDirectory(treeId: number, path: string): NativeDirectoryEntry[];
+}
+
+declare const libentry: NativeModule;
+
+export default libentry;
+export { NativeDirectoryEntry, NativeModule };

+ 56 - 1
entry/src/main/ets/pages/SettingPage.ets

@@ -1159,6 +1159,61 @@ export struct SettingPage {
           })
           })
           .padding(0)
           .padding(0)
 
 
+          // 网络工具
+          Column() {
+            Row() {
+              Text('网络工具')
+                .margin({ left: 18, right: 20 })
+                .fontSize(16)
+                .fontColor(Color.Gray)
+                .fontWeight(480)
+                .layoutWeight(1)
+            }
+            .height(48)
+
+            Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
+            Button({ type: ButtonType.Normal, stateEffect: true }) {
+              Row() {
+                Image($r('app.media.cloudDisk'))
+                  .width(22)
+                  .height(22)
+                  .alignSelf(ItemAlign.Center)
+                  .margin({ left: 15 })
+                Text('SMB 测试工具')
+                  .margin({ left: 8 })
+                  .fontSize(15)
+                  .fontColor(Color.Gray)
+                  .fontWeight(480)
+                  .layoutWeight(1)
+                Image($r('app.media.arrow_right'))
+                  .width(22)
+                  .height(22)
+                  .margin({ right: 18 })
+              }
+            }
+            .height(55)
+            .backgroundColor(Color.Transparent)
+            .clickEffect({ level: ClickEffectLevel.HEAVY })
+            .onClick(() => {
+              router.pushUrl({
+                url: 'pages/SmbTestPage'
+              });
+            })
+
+            Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
+          }
+          .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
+            .animation({ duration: 500, curve: Curve.Ease, delay: 260 }))
+          .backgroundColor($r('app.color.settings_background_main'))
+          .borderRadius(20)
+          .margin({
+            left: 0,
+            right: 0,
+            top: 0,
+            bottom: 10
+          })
+          .padding(0)
+
 
 
           // 音频设置分组
           // 音频设置分组
           Column() {
           Column() {
@@ -2523,4 +2578,4 @@ function chunkArray<T>(arr: Array<T>, size: number): Array<Array<T>> {
     result.push(row);
     result.push(row);
   }
   }
   return result;
   return result;
-}
+}

+ 3 - 2
entry/src/main/resources/base/profile/main_pages.json

@@ -7,6 +7,7 @@
     "pages/VerifyPage",
     "pages/VerifyPage",
     "pages/VipPage",
     "pages/VipPage",
     "pages/Demo",
     "pages/Demo",
-    "pages/PlaylistDetailPage"
+    "pages/PlaylistDetailPage",
+    "pages/SmbTestPage"
   ]
   ]
-}
+}