rugged 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (288) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -0
  3. data/README.md +1 -1
  4. data/ext/rugged/rugged.c +7 -4
  5. data/ext/rugged/rugged_object.c +1 -1
  6. data/ext/rugged/rugged_repo.c +3 -3
  7. data/lib/rugged/repository.rb +2 -2
  8. data/lib/rugged/version.rb +1 -1
  9. data/vendor/libgit2/CMakeLists.txt +11 -6
  10. data/vendor/libgit2/COPYING +109 -1
  11. data/vendor/libgit2/cmake/Findfutimens.cmake +14 -0
  12. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +4 -0
  13. data/vendor/libgit2/cmake/SelectHashes.cmake +1 -0
  14. data/vendor/libgit2/deps/chromium-zlib/CMakeLists.txt +101 -0
  15. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +18 -5
  16. data/vendor/libgit2/deps/ntlmclient/compat.h +0 -34
  17. data/vendor/libgit2/deps/ntlmclient/crypt.h +14 -9
  18. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.c +20 -20
  19. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.h +3 -3
  20. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.c +37 -36
  21. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.h +4 -3
  22. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +178 -51
  23. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.h +74 -5
  24. data/vendor/libgit2/deps/ntlmclient/ntlm.c +156 -124
  25. data/vendor/libgit2/deps/ntlmclient/ntlm.h +13 -9
  26. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +16 -3
  27. data/vendor/libgit2/deps/ntlmclient/unicode.h +10 -4
  28. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.c +16 -27
  29. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.h +20 -0
  30. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.c +28 -52
  31. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.h +22 -0
  32. data/vendor/libgit2/deps/ntlmclient/util.c +15 -1
  33. data/vendor/libgit2/deps/ntlmclient/util.h +2 -1
  34. data/vendor/libgit2/include/git2/apply.h +2 -0
  35. data/vendor/libgit2/include/git2/attr.h +89 -0
  36. data/vendor/libgit2/include/git2/blame.h +93 -42
  37. data/vendor/libgit2/include/git2/blob.h +31 -3
  38. data/vendor/libgit2/include/git2/branch.h +25 -0
  39. data/vendor/libgit2/include/git2/cert.h +42 -5
  40. data/vendor/libgit2/include/git2/checkout.h +28 -12
  41. data/vendor/libgit2/include/git2/commit.h +35 -19
  42. data/vendor/libgit2/include/git2/common.h +19 -4
  43. data/vendor/libgit2/include/git2/config.h +1 -1
  44. data/vendor/libgit2/include/git2/deprecated.h +206 -6
  45. data/vendor/libgit2/include/git2/diff.h +35 -20
  46. data/vendor/libgit2/include/git2/errors.h +6 -6
  47. data/vendor/libgit2/include/git2/filter.h +57 -17
  48. data/vendor/libgit2/include/git2/graph.h +20 -2
  49. data/vendor/libgit2/include/git2/index.h +3 -3
  50. data/vendor/libgit2/include/git2/indexer.h +2 -1
  51. data/vendor/libgit2/include/git2/odb.h +44 -20
  52. data/vendor/libgit2/include/git2/patch.h +8 -0
  53. data/vendor/libgit2/include/git2/rebase.h +25 -1
  54. data/vendor/libgit2/include/git2/refs.h +9 -5
  55. data/vendor/libgit2/include/git2/remote.h +59 -6
  56. data/vendor/libgit2/include/git2/repository.h +95 -52
  57. data/vendor/libgit2/include/git2/revparse.h +5 -5
  58. data/vendor/libgit2/include/git2/status.h +115 -59
  59. data/vendor/libgit2/include/git2/submodule.h +9 -0
  60. data/vendor/libgit2/include/git2/sys/commit_graph.h +174 -0
  61. data/vendor/libgit2/include/git2/sys/filter.h +49 -28
  62. data/vendor/libgit2/include/git2/sys/midx.h +74 -0
  63. data/vendor/libgit2/include/git2/sys/odb_backend.h +7 -0
  64. data/vendor/libgit2/include/git2/sys/transport.h +1 -0
  65. data/vendor/libgit2/include/git2/tag.h +12 -0
  66. data/vendor/libgit2/include/git2/transport.h +1 -1
  67. data/vendor/libgit2/include/git2/tree.h +2 -14
  68. data/vendor/libgit2/include/git2/types.h +9 -0
  69. data/vendor/libgit2/include/git2/version.h +3 -3
  70. data/vendor/libgit2/include/git2/worktree.h +1 -0
  71. data/vendor/libgit2/src/CMakeLists.txt +25 -4
  72. data/vendor/libgit2/src/alloc.c +21 -8
  73. data/vendor/libgit2/src/allocators/failalloc.c +92 -0
  74. data/vendor/libgit2/src/allocators/failalloc.h +23 -0
  75. data/vendor/libgit2/src/allocators/stdalloc.c +41 -10
  76. data/vendor/libgit2/src/allocators/win32_leakcheck.c +118 -0
  77. data/vendor/libgit2/src/allocators/{win32_crtdbg.h → win32_leakcheck.h} +3 -3
  78. data/vendor/libgit2/src/annotated_commit.c +21 -9
  79. data/vendor/libgit2/src/apply.c +16 -7
  80. data/vendor/libgit2/src/array.h +11 -11
  81. data/vendor/libgit2/src/attr.c +181 -74
  82. data/vendor/libgit2/src/attr_file.c +84 -39
  83. data/vendor/libgit2/src/attr_file.h +32 -11
  84. data/vendor/libgit2/src/attrcache.c +42 -37
  85. data/vendor/libgit2/src/attrcache.h +4 -5
  86. data/vendor/libgit2/src/blame.c +26 -15
  87. data/vendor/libgit2/src/blob.c +44 -24
  88. data/vendor/libgit2/src/branch.c +69 -17
  89. data/vendor/libgit2/src/buffer.c +334 -25
  90. data/vendor/libgit2/src/buffer.h +153 -2
  91. data/vendor/libgit2/src/cache.c +2 -2
  92. data/vendor/libgit2/src/cache.h +7 -7
  93. data/vendor/libgit2/src/cc-compat.h +10 -2
  94. data/vendor/libgit2/src/checkout.c +48 -26
  95. data/vendor/libgit2/src/cherrypick.c +6 -2
  96. data/vendor/libgit2/src/clone.c +26 -11
  97. data/vendor/libgit2/src/commit.c +41 -28
  98. data/vendor/libgit2/src/commit_graph.c +1209 -0
  99. data/vendor/libgit2/src/commit_graph.h +162 -0
  100. data/vendor/libgit2/src/commit_list.c +46 -0
  101. data/vendor/libgit2/src/commit_list.h +2 -0
  102. data/vendor/libgit2/src/common.h +25 -2
  103. data/vendor/libgit2/src/config.c +37 -15
  104. data/vendor/libgit2/src/config_cache.c +9 -4
  105. data/vendor/libgit2/src/config_file.c +16 -8
  106. data/vendor/libgit2/src/config_parse.c +4 -6
  107. data/vendor/libgit2/src/crlf.c +16 -6
  108. data/vendor/libgit2/src/date.c +4 -3
  109. data/vendor/libgit2/src/delta.c +1 -1
  110. data/vendor/libgit2/src/describe.c +6 -3
  111. data/vendor/libgit2/src/diff.c +11 -8
  112. data/vendor/libgit2/src/diff_driver.c +21 -17
  113. data/vendor/libgit2/src/diff_file.c +2 -6
  114. data/vendor/libgit2/src/diff_generate.c +46 -17
  115. data/vendor/libgit2/src/diff_print.c +19 -6
  116. data/vendor/libgit2/src/diff_stats.c +7 -5
  117. data/vendor/libgit2/src/diff_tform.c +11 -10
  118. data/vendor/libgit2/src/diff_xdiff.c +4 -2
  119. data/vendor/libgit2/src/diff_xdiff.h +1 -1
  120. data/vendor/libgit2/src/errors.c +24 -19
  121. data/vendor/libgit2/src/features.h.in +5 -1
  122. data/vendor/libgit2/src/fetch.c +5 -2
  123. data/vendor/libgit2/src/fetchhead.c +8 -4
  124. data/vendor/libgit2/src/filebuf.c +9 -7
  125. data/vendor/libgit2/src/filter.c +206 -110
  126. data/vendor/libgit2/src/filter.h +24 -5
  127. data/vendor/libgit2/src/futils.c +5 -5
  128. data/vendor/libgit2/src/futils.h +1 -1
  129. data/vendor/libgit2/src/graph.c +64 -9
  130. data/vendor/libgit2/src/hash/sha1/collisiondetect.c +3 -3
  131. data/vendor/libgit2/src/hash/sha1/common_crypto.c +3 -3
  132. data/vendor/libgit2/src/hash/sha1/generic.h +1 -1
  133. data/vendor/libgit2/src/hash/sha1/mbedtls.c +12 -12
  134. data/vendor/libgit2/src/hash/sha1/openssl.c +3 -3
  135. data/vendor/libgit2/src/hash/sha1/sha1dc/sha1.c +0 -2
  136. data/vendor/libgit2/src/hash/sha1/win32.c +15 -11
  137. data/vendor/libgit2/src/hash.c +16 -13
  138. data/vendor/libgit2/src/hash.h +1 -1
  139. data/vendor/libgit2/src/hashsig.c +23 -10
  140. data/vendor/libgit2/src/ident.c +13 -3
  141. data/vendor/libgit2/src/ignore.c +35 -19
  142. data/vendor/libgit2/src/index.c +112 -75
  143. data/vendor/libgit2/src/index.h +1 -1
  144. data/vendor/libgit2/src/indexer.c +50 -32
  145. data/vendor/libgit2/src/integer.h +79 -2
  146. data/vendor/libgit2/src/iterator.c +36 -24
  147. data/vendor/libgit2/src/iterator.h +1 -1
  148. data/vendor/libgit2/src/khash.h +2 -11
  149. data/vendor/libgit2/src/{settings.c → libgit2.c} +117 -50
  150. data/vendor/libgit2/src/libgit2.h +15 -0
  151. data/vendor/libgit2/src/mailmap.c +23 -10
  152. data/vendor/libgit2/src/map.h +3 -3
  153. data/vendor/libgit2/src/merge.c +75 -32
  154. data/vendor/libgit2/src/merge.h +2 -1
  155. data/vendor/libgit2/src/merge_driver.c +19 -13
  156. data/vendor/libgit2/src/merge_file.c +11 -3
  157. data/vendor/libgit2/src/message.c +3 -1
  158. data/vendor/libgit2/src/midx.c +471 -10
  159. data/vendor/libgit2/src/midx.h +28 -1
  160. data/vendor/libgit2/src/mwindow.c +106 -60
  161. data/vendor/libgit2/src/mwindow.h +3 -3
  162. data/vendor/libgit2/src/net.c +127 -3
  163. data/vendor/libgit2/src/net.h +16 -2
  164. data/vendor/libgit2/src/netops.c +6 -4
  165. data/vendor/libgit2/src/netops.h +2 -2
  166. data/vendor/libgit2/src/notes.c +10 -10
  167. data/vendor/libgit2/src/object.c +22 -14
  168. data/vendor/libgit2/src/odb.c +289 -51
  169. data/vendor/libgit2/src/odb.h +16 -2
  170. data/vendor/libgit2/src/odb_loose.c +28 -18
  171. data/vendor/libgit2/src/odb_mempack.c +1 -1
  172. data/vendor/libgit2/src/odb_pack.c +391 -114
  173. data/vendor/libgit2/src/oid.c +5 -4
  174. data/vendor/libgit2/src/pack-objects.c +54 -48
  175. data/vendor/libgit2/src/pack.c +339 -125
  176. data/vendor/libgit2/src/pack.h +25 -7
  177. data/vendor/libgit2/src/patch.c +14 -7
  178. data/vendor/libgit2/src/patch_generate.c +2 -2
  179. data/vendor/libgit2/src/patch_parse.c +2 -1
  180. data/vendor/libgit2/src/path.c +98 -53
  181. data/vendor/libgit2/src/path.h +79 -6
  182. data/vendor/libgit2/src/pathspec.c +8 -8
  183. data/vendor/libgit2/src/pool.c +13 -7
  184. data/vendor/libgit2/src/posix.c +43 -12
  185. data/vendor/libgit2/src/posix.h +9 -0
  186. data/vendor/libgit2/src/reader.c +10 -6
  187. data/vendor/libgit2/src/rebase.c +93 -49
  188. data/vendor/libgit2/src/refdb.c +30 -13
  189. data/vendor/libgit2/src/refdb_fs.c +125 -71
  190. data/vendor/libgit2/src/reflog.c +19 -14
  191. data/vendor/libgit2/src/refs.c +91 -43
  192. data/vendor/libgit2/src/refs.h +1 -1
  193. data/vendor/libgit2/src/refspec.c +80 -44
  194. data/vendor/libgit2/src/remote.c +281 -105
  195. data/vendor/libgit2/src/remote.h +2 -1
  196. data/vendor/libgit2/src/repository.c +191 -118
  197. data/vendor/libgit2/src/repository.h +13 -2
  198. data/vendor/libgit2/src/reset.c +7 -6
  199. data/vendor/libgit2/src/revert.c +6 -2
  200. data/vendor/libgit2/src/revparse.c +14 -9
  201. data/vendor/libgit2/src/revwalk.c +32 -15
  202. data/vendor/libgit2/src/runtime.c +162 -0
  203. data/vendor/libgit2/src/runtime.h +62 -0
  204. data/vendor/libgit2/src/settings.h +11 -0
  205. data/vendor/libgit2/src/signature.c +6 -5
  206. data/vendor/libgit2/src/sortedcache.h +10 -8
  207. data/vendor/libgit2/src/stash.c +3 -1
  208. data/vendor/libgit2/src/status.c +7 -4
  209. data/vendor/libgit2/src/strarray.c +2 -1
  210. data/vendor/libgit2/src/streams/mbedtls.c +14 -17
  211. data/vendor/libgit2/src/streams/mbedtls.h +1 -1
  212. data/vendor/libgit2/src/streams/openssl.c +101 -201
  213. data/vendor/libgit2/src/streams/openssl.h +9 -1
  214. data/vendor/libgit2/src/streams/openssl_dynamic.c +309 -0
  215. data/vendor/libgit2/src/streams/openssl_dynamic.h +348 -0
  216. data/vendor/libgit2/src/streams/openssl_legacy.c +203 -0
  217. data/vendor/libgit2/src/streams/openssl_legacy.h +63 -0
  218. data/vendor/libgit2/src/streams/registry.c +5 -6
  219. data/vendor/libgit2/src/streams/socket.c +6 -2
  220. data/vendor/libgit2/src/streams/stransport.c +6 -3
  221. data/vendor/libgit2/src/streams/tls.c +5 -3
  222. data/vendor/libgit2/src/submodule.c +128 -62
  223. data/vendor/libgit2/src/submodule.h +9 -9
  224. data/vendor/libgit2/src/sysdir.c +4 -6
  225. data/vendor/libgit2/src/tag.c +47 -11
  226. data/vendor/libgit2/src/thread.c +140 -0
  227. data/vendor/libgit2/src/thread.h +479 -0
  228. data/vendor/libgit2/src/threadstate.c +83 -0
  229. data/vendor/libgit2/src/threadstate.h +24 -0
  230. data/vendor/libgit2/src/trace.c +2 -2
  231. data/vendor/libgit2/src/trace.h +17 -13
  232. data/vendor/libgit2/src/transaction.c +19 -8
  233. data/vendor/libgit2/src/transport.c +3 -3
  234. data/vendor/libgit2/src/transports/auth.c +1 -1
  235. data/vendor/libgit2/src/transports/auth_negotiate.c +11 -4
  236. data/vendor/libgit2/src/transports/auth_ntlm.c +10 -6
  237. data/vendor/libgit2/src/transports/credential.c +15 -7
  238. data/vendor/libgit2/src/transports/git.c +1 -3
  239. data/vendor/libgit2/src/transports/http.c +19 -17
  240. data/vendor/libgit2/src/transports/http.h +1 -0
  241. data/vendor/libgit2/src/transports/httpclient.c +62 -30
  242. data/vendor/libgit2/src/transports/httpclient.h +1 -1
  243. data/vendor/libgit2/src/transports/local.c +3 -3
  244. data/vendor/libgit2/src/transports/smart.c +12 -7
  245. data/vendor/libgit2/src/transports/smart.h +1 -1
  246. data/vendor/libgit2/src/transports/smart_protocol.c +11 -5
  247. data/vendor/libgit2/src/transports/ssh.c +51 -17
  248. data/vendor/libgit2/src/transports/winhttp.c +138 -81
  249. data/vendor/libgit2/src/tree.c +100 -77
  250. data/vendor/libgit2/src/tree.h +1 -0
  251. data/vendor/libgit2/src/tsort.c +0 -2
  252. data/vendor/libgit2/src/unix/map.c +3 -1
  253. data/vendor/libgit2/src/unix/posix.h +3 -0
  254. data/vendor/libgit2/src/unix/pthread.h +2 -1
  255. data/vendor/libgit2/src/utf8.c +150 -0
  256. data/vendor/libgit2/src/utf8.h +52 -0
  257. data/vendor/libgit2/src/util.c +53 -129
  258. data/vendor/libgit2/src/util.h +33 -39
  259. data/vendor/libgit2/src/vector.c +23 -19
  260. data/vendor/libgit2/src/vector.h +4 -2
  261. data/vendor/libgit2/src/win32/findfile.c +4 -2
  262. data/vendor/libgit2/src/win32/map.c +1 -1
  263. data/vendor/libgit2/src/win32/msvc-compat.h +9 -1
  264. data/vendor/libgit2/src/win32/path_w32.c +22 -24
  265. data/vendor/libgit2/src/win32/path_w32.h +0 -1
  266. data/vendor/libgit2/src/win32/posix_w32.c +77 -1
  267. data/vendor/libgit2/src/win32/precompiled.h +0 -1
  268. data/vendor/libgit2/src/win32/reparse.h +4 -4
  269. data/vendor/libgit2/src/win32/thread.c +24 -15
  270. data/vendor/libgit2/src/win32/thread.h +1 -1
  271. data/vendor/libgit2/src/win32/w32_buffer.c +3 -3
  272. data/vendor/libgit2/src/win32/w32_common.h +18 -9
  273. data/vendor/libgit2/src/win32/{w32_crtdbg_stacktrace.c → w32_leakcheck.c} +269 -33
  274. data/vendor/libgit2/src/win32/w32_leakcheck.h +222 -0
  275. data/vendor/libgit2/src/win32/w32_util.h +6 -6
  276. data/vendor/libgit2/src/worktree.c +32 -14
  277. data/vendor/libgit2/src/zstream.c +1 -1
  278. metadata +32 -16
  279. data/vendor/libgit2/src/allocators/win32_crtdbg.c +0 -118
  280. data/vendor/libgit2/src/buf_text.c +0 -316
  281. data/vendor/libgit2/src/buf_text.h +0 -122
  282. data/vendor/libgit2/src/global.c +0 -363
  283. data/vendor/libgit2/src/global.h +0 -41
  284. data/vendor/libgit2/src/thread-utils.c +0 -58
  285. data/vendor/libgit2/src/thread-utils.h +0 -364
  286. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +0 -127
  287. data/vendor/libgit2/src/win32/w32_stack.c +0 -188
  288. data/vendor/libgit2/src/win32/w32_stack.h +0 -140
@@ -9,7 +9,6 @@
9
9
  #include <stdlib.h>
10
10
  #include <stdint.h>
11
11
  #include <string.h>
12
- #include <assert.h>
13
12
  #include <errno.h>
14
13
  #include <ctype.h>
15
14
  #include <unistd.h>
@@ -24,6 +23,18 @@
24
23
  #include "compat.h"
25
24
  #include "util.h"
26
25
 
26
+ #define NTLM_ASSERT_ARG(expr) do { \
27
+ if (!(expr)) \
28
+ return NTLM_CLIENT_ERROR_INVALID_INPUT; \
29
+ } while(0)
30
+
31
+ #define NTLM_ASSERT(ntlm, expr) do { \
32
+ if (!(expr)) { \
33
+ ntlm_client_set_errmsg(ntlm, "internal error: " #expr); \
34
+ return -1; \
35
+ } \
36
+ } while(0)
37
+
27
38
  unsigned char ntlm_client_signature[] = NTLM_SIGNATURE;
28
39
 
29
40
  static bool supports_unicode(ntlm_client *ntlm)
@@ -52,17 +63,20 @@ ntlm_client *ntlm_client_init(ntlm_client_flags flags)
52
63
 
53
64
  ntlm->flags = flags;
54
65
 
55
- if ((ntlm->hmac_ctx = ntlm_hmac_ctx_init()) == NULL ||
56
- (ntlm->unicode_ctx = ntlm_unicode_ctx_init(ntlm)) == NULL) {
57
- ntlm_hmac_ctx_free(ntlm->hmac_ctx);
58
- ntlm_unicode_ctx_free(ntlm->unicode_ctx);
59
- free(ntlm);
60
- return NULL;
61
- }
62
-
63
66
  return ntlm;
64
67
  }
65
68
 
69
+ #define ENSURE_INITIALIZED(ntlm) \
70
+ do { \
71
+ if (!(ntlm)->unicode_initialized) \
72
+ (ntlm)->unicode_initialized = ntlm_unicode_init((ntlm)); \
73
+ if (!(ntlm)->crypt_initialized) \
74
+ (ntlm)->crypt_initialized = ntlm_crypt_init((ntlm)); \
75
+ if (!(ntlm)->unicode_initialized || \
76
+ !(ntlm)->crypt_initialized) \
77
+ return -1; \
78
+ } while(0)
79
+
66
80
  void ntlm_client_set_errmsg(ntlm_client *ntlm, const char *errmsg)
67
81
  {
68
82
  ntlm->state = NTLM_STATE_ERROR;
@@ -71,7 +85,9 @@ void ntlm_client_set_errmsg(ntlm_client *ntlm, const char *errmsg)
71
85
 
72
86
  const char *ntlm_client_errmsg(ntlm_client *ntlm)
73
87
  {
74
- assert(ntlm);
88
+ if (!ntlm)
89
+ return "internal error";
90
+
75
91
  return ntlm->errmsg ? ntlm->errmsg : "no error";
76
92
  }
77
93
 
@@ -81,7 +97,7 @@ int ntlm_client_set_version(
81
97
  uint8_t minor,
82
98
  uint16_t build)
83
99
  {
84
- assert(ntlm);
100
+ NTLM_ASSERT_ARG(ntlm);
85
101
 
86
102
  ntlm->host_version.major = major;
87
103
  ntlm->host_version.minor = minor;
@@ -93,20 +109,25 @@ int ntlm_client_set_version(
93
109
  return 0;
94
110
  }
95
111
 
112
+ #define reset(ptr) do { free(ptr); ptr = NULL; } while(0)
113
+
114
+ static void free_hostname(ntlm_client *ntlm)
115
+ {
116
+ reset(ntlm->hostname);
117
+ reset(ntlm->hostdomain);
118
+ reset(ntlm->hostname_utf16);
119
+ ntlm->hostname_utf16_len = 0;
120
+ }
121
+
96
122
  int ntlm_client_set_hostname(
97
123
  ntlm_client *ntlm,
98
124
  const char *hostname,
99
125
  const char *domain)
100
126
  {
101
- assert(ntlm);
102
-
103
- free(ntlm->hostname);
104
- free(ntlm->hostdomain);
105
- free(ntlm->hostname_utf16);
127
+ NTLM_ASSERT_ARG(ntlm);
128
+ ENSURE_INITIALIZED(ntlm);
106
129
 
107
- ntlm->hostname = NULL;
108
- ntlm->hostdomain = NULL;
109
- ntlm->hostname_utf16 = NULL;
130
+ free_hostname(ntlm);
110
131
 
111
132
  if (hostname && (ntlm->hostname = strdup(hostname)) == NULL) {
112
133
  ntlm_client_set_errmsg(ntlm, "out of memory");
@@ -121,7 +142,7 @@ int ntlm_client_set_hostname(
121
142
  if (hostname && supports_unicode(ntlm) && !ntlm_unicode_utf8_to_16(
122
143
  &ntlm->hostname_utf16,
123
144
  &ntlm->hostname_utf16_len,
124
- ntlm->unicode_ctx,
145
+ ntlm,
125
146
  hostname,
126
147
  strlen(hostname)))
127
148
  return -1;
@@ -132,30 +153,25 @@ int ntlm_client_set_hostname(
132
153
  static void free_credentials(ntlm_client *ntlm)
133
154
  {
134
155
  if (ntlm->password)
135
- memzero(ntlm->password, strlen(ntlm->password));
156
+ ntlm_memzero(ntlm->password, strlen(ntlm->password));
136
157
 
137
158
  if (ntlm->password_utf16)
138
- memzero(ntlm->password_utf16, ntlm->password_utf16_len);
139
-
140
- free(ntlm->username);
141
- free(ntlm->username_upper);
142
- free(ntlm->userdomain);
143
- free(ntlm->password);
144
-
145
- free(ntlm->username_utf16);
146
- free(ntlm->username_upper_utf16);
147
- free(ntlm->userdomain_utf16);
148
- free(ntlm->password_utf16);
149
-
150
- ntlm->username = NULL;
151
- ntlm->username_upper = NULL;
152
- ntlm->userdomain = NULL;
153
- ntlm->password = NULL;
154
-
155
- ntlm->username_utf16 = NULL;
156
- ntlm->username_upper_utf16 = NULL;
157
- ntlm->userdomain_utf16 = NULL;
158
- ntlm->password_utf16 = NULL;
159
+ ntlm_memzero(ntlm->password_utf16, ntlm->password_utf16_len);
160
+
161
+ reset(ntlm->username);
162
+ reset(ntlm->username_upper);
163
+ reset(ntlm->userdomain);
164
+ reset(ntlm->password);
165
+
166
+ reset(ntlm->username_utf16);
167
+ reset(ntlm->username_upper_utf16);
168
+ reset(ntlm->userdomain_utf16);
169
+ reset(ntlm->password_utf16);
170
+
171
+ ntlm->username_utf16_len = 0;
172
+ ntlm->username_upper_utf16_len = 0;
173
+ ntlm->userdomain_utf16_len = 0;
174
+ ntlm->password_utf16_len = 0;
159
175
  }
160
176
 
161
177
  int ntlm_client_set_credentials(
@@ -164,7 +180,8 @@ int ntlm_client_set_credentials(
164
180
  const char *domain,
165
181
  const char *password)
166
182
  {
167
- assert(ntlm);
183
+ NTLM_ASSERT_ARG(ntlm);
184
+ ENSURE_INITIALIZED(ntlm);
168
185
 
169
186
  free_credentials(ntlm);
170
187
 
@@ -185,7 +202,7 @@ int ntlm_client_set_credentials(
185
202
  if (!ntlm_unicode_utf8_to_16(
186
203
  &ntlm->username_utf16,
187
204
  &ntlm->username_utf16_len,
188
- ntlm->unicode_ctx,
205
+ ntlm,
189
206
  ntlm->username,
190
207
  strlen(ntlm->username)))
191
208
  return -1;
@@ -193,7 +210,7 @@ int ntlm_client_set_credentials(
193
210
  if (!ntlm_unicode_utf8_to_16(
194
211
  &ntlm->username_upper_utf16,
195
212
  &ntlm->username_upper_utf16_len,
196
- ntlm->unicode_ctx,
213
+ ntlm,
197
214
  ntlm->username_upper,
198
215
  strlen(ntlm->username_upper)))
199
216
  return -1;
@@ -202,7 +219,7 @@ int ntlm_client_set_credentials(
202
219
  if (domain && supports_unicode(ntlm) && !ntlm_unicode_utf8_to_16(
203
220
  &ntlm->userdomain_utf16,
204
221
  &ntlm->userdomain_utf16_len,
205
- ntlm->unicode_ctx,
222
+ ntlm,
206
223
  ntlm->userdomain,
207
224
  strlen(ntlm->userdomain)))
208
225
  return -1;
@@ -212,7 +229,8 @@ int ntlm_client_set_credentials(
212
229
 
213
230
  int ntlm_client_set_target(ntlm_client *ntlm, const char *target)
214
231
  {
215
- assert(ntlm);
232
+ NTLM_ASSERT_ARG(ntlm);
233
+ ENSURE_INITIALIZED(ntlm);
216
234
 
217
235
  free(ntlm->target);
218
236
  free(ntlm->target_utf16);
@@ -229,7 +247,7 @@ int ntlm_client_set_target(ntlm_client *ntlm, const char *target)
229
247
  if (supports_unicode(ntlm) && !ntlm_unicode_utf8_to_16(
230
248
  &ntlm->target_utf16,
231
249
  &ntlm->target_utf16_len,
232
- ntlm->unicode_ctx,
250
+ ntlm,
233
251
  ntlm->target,
234
252
  strlen(ntlm->target)))
235
253
  return -1;
@@ -240,14 +258,16 @@ int ntlm_client_set_target(ntlm_client *ntlm, const char *target)
240
258
 
241
259
  int ntlm_client_set_nonce(ntlm_client *ntlm, uint64_t nonce)
242
260
  {
243
- assert(ntlm);
261
+ NTLM_ASSERT_ARG(ntlm);
262
+
244
263
  ntlm->nonce = nonce;
245
264
  return 0;
246
265
  }
247
266
 
248
267
  int ntlm_client_set_timestamp(ntlm_client *ntlm, uint64_t timestamp)
249
268
  {
250
- assert(ntlm);
269
+ NTLM_ASSERT_ARG(ntlm);
270
+
251
271
  ntlm->timestamp = timestamp;
252
272
  return 0;
253
273
  }
@@ -475,7 +495,7 @@ static inline bool read_string_unicode(
475
495
  size_t out_len;
476
496
  int ret = ntlm_unicode_utf16_to_8(out,
477
497
  &out_len,
478
- ntlm->unicode_ctx,
498
+ ntlm,
479
499
  (char *)&message->buf[message->pos],
480
500
  string_len);
481
501
 
@@ -593,7 +613,9 @@ int ntlm_client_negotiate(
593
613
  size_t hostname_offset = 0;
594
614
  uint32_t flags = 0;
595
615
 
596
- assert(out && out_len && ntlm);
616
+ NTLM_ASSERT_ARG(out);
617
+ NTLM_ASSERT_ARG(out_len);
618
+ NTLM_ASSERT_ARG(ntlm);
597
619
 
598
620
  *out = NULL;
599
621
  *out_len = 0;
@@ -676,20 +698,22 @@ int ntlm_client_negotiate(
676
698
  return -1;
677
699
 
678
700
  if (hostname_len > 0) {
679
- assert(hostname_offset == ntlm->negotiate.pos);
701
+ NTLM_ASSERT(ntlm, hostname_offset == ntlm->negotiate.pos);
702
+
680
703
  if (!write_buf(ntlm, &ntlm->negotiate,
681
704
  (const unsigned char *)ntlm->hostname, hostname_len))
682
705
  return -1;
683
706
  }
684
707
 
685
708
  if (domain_len > 0) {
686
- assert(domain_offset == ntlm->negotiate.pos);
709
+ NTLM_ASSERT(ntlm, domain_offset == ntlm->negotiate.pos);
710
+
687
711
  if (!write_buf(ntlm, &ntlm->negotiate,
688
712
  (const unsigned char *)ntlm->hostdomain, domain_len))
689
713
  return -1;
690
714
  }
691
715
 
692
- assert(ntlm->negotiate.pos == ntlm->negotiate.len);
716
+ NTLM_ASSERT(ntlm, ntlm->negotiate.pos == ntlm->negotiate.len);
693
717
 
694
718
  ntlm->state = NTLM_STATE_CHALLENGE;
695
719
 
@@ -711,7 +735,10 @@ int ntlm_client_set_challenge(
711
735
  uint32_t name_offset, info_offset = 0;
712
736
  bool unicode, has_target_info = false;
713
737
 
714
- assert(ntlm && (challenge_msg || !challenge_msg_len));
738
+ NTLM_ASSERT_ARG(ntlm);
739
+ NTLM_ASSERT_ARG(challenge_msg || !challenge_msg_len);
740
+
741
+ ENSURE_INITIALIZED(ntlm);
715
742
 
716
743
  if (ntlm->state != NTLM_STATE_NEGOTIATE &&
717
744
  ntlm->state != NTLM_STATE_CHALLENGE) {
@@ -940,6 +967,7 @@ static void des_key_from_password(
940
967
 
941
968
  static inline bool generate_lm_hash(
942
969
  ntlm_des_block out[2],
970
+ ntlm_client *ntlm,
943
971
  const char *password)
944
972
  {
945
973
  /* LM encrypts this known plaintext using the password as a key */
@@ -968,8 +996,8 @@ static inline bool generate_lm_hash(
968
996
  des_key_from_password(&key1, keystr1, keystr1_len);
969
997
  des_key_from_password(&key2, keystr2, keystr2_len);
970
998
 
971
- return ntlm_des_encrypt(&out[0], &plaintext, &key1) &&
972
- ntlm_des_encrypt(&out[1], &plaintext, &key2);
999
+ return ntlm_des_encrypt(&out[0], ntlm, &plaintext, &key1) &&
1000
+ ntlm_des_encrypt(&out[1], ntlm, &plaintext, &key2);
973
1001
  }
974
1002
 
975
1003
  static void des_keys_from_lm_hash(ntlm_des_block out[3], ntlm_des_block lm_hash[2])
@@ -994,16 +1022,16 @@ static bool generate_lm_response(ntlm_client *ntlm)
994
1022
  ntlm_des_block *challenge = (ntlm_des_block *)&ntlm->challenge.nonce;
995
1023
 
996
1024
  /* Generate the LM hash from the password */
997
- if (!generate_lm_hash(lm_hash, ntlm->password))
1025
+ if (!generate_lm_hash(lm_hash, ntlm, ntlm->password))
998
1026
  return false;
999
1027
 
1000
1028
  /* Convert that LM hash to three DES keys */
1001
1029
  des_keys_from_lm_hash(key, lm_hash);
1002
1030
 
1003
1031
  /* Finally, encrypt the challenge with each of these keys */
1004
- if (!ntlm_des_encrypt(&lm_response[0], challenge, &key[0]) ||
1005
- !ntlm_des_encrypt(&lm_response[1], challenge, &key[1]) ||
1006
- !ntlm_des_encrypt(&lm_response[2], challenge, &key[2]))
1032
+ if (!ntlm_des_encrypt(&lm_response[0], ntlm, challenge, &key[0]) ||
1033
+ !ntlm_des_encrypt(&lm_response[1], ntlm, challenge, &key[1]) ||
1034
+ !ntlm_des_encrypt(&lm_response[2], ntlm, challenge, &key[2]))
1007
1035
  return false;
1008
1036
 
1009
1037
  memcpy(&ntlm->lm_response[0], lm_response[0], 8);
@@ -1022,12 +1050,13 @@ static bool generate_ntlm_hash(
1022
1050
  if (ntlm->password && !ntlm_unicode_utf8_to_16(
1023
1051
  &ntlm->password_utf16,
1024
1052
  &ntlm->password_utf16_len,
1025
- ntlm->unicode_ctx,
1053
+ ntlm,
1026
1054
  ntlm->password,
1027
1055
  strlen(ntlm->password)))
1028
1056
  return false;
1029
1057
 
1030
1058
  return ntlm_md4_digest(out,
1059
+ ntlm,
1031
1060
  (const unsigned char *)ntlm->password_utf16,
1032
1061
  ntlm->password_utf16_len);
1033
1062
  }
@@ -1048,9 +1077,9 @@ static bool generate_ntlm_response(ntlm_client *ntlm)
1048
1077
  des_key_from_password(&key[2], &ntlm_hash[14], 2);
1049
1078
 
1050
1079
  /* Finally, encrypt the challenge with each of these keys */
1051
- if (!ntlm_des_encrypt(&ntlm_response[0], challenge, &key[0]) ||
1052
- !ntlm_des_encrypt(&ntlm_response[1], challenge, &key[1]) ||
1053
- !ntlm_des_encrypt(&ntlm_response[2], challenge, &key[2]))
1080
+ if (!ntlm_des_encrypt(&ntlm_response[0], ntlm, challenge, &key[0]) ||
1081
+ !ntlm_des_encrypt(&ntlm_response[1], ntlm, challenge, &key[1]) ||
1082
+ !ntlm_des_encrypt(&ntlm_response[2], ntlm, challenge, &key[2]))
1054
1083
  return false;
1055
1084
 
1056
1085
  memcpy(&ntlm->ntlm_response[0], ntlm_response[0], 8);
@@ -1081,16 +1110,15 @@ static bool generate_ntlm2_hash(
1081
1110
  target_len = ntlm->target_utf16_len;
1082
1111
  }
1083
1112
 
1084
- if (!ntlm_hmac_ctx_reset(ntlm->hmac_ctx) ||
1085
- !ntlm_hmac_md5_init(ntlm->hmac_ctx, ntlm_hash, sizeof(ntlm_hash)) ||
1086
- !ntlm_hmac_md5_update(ntlm->hmac_ctx, username, username_len) ||
1087
- !ntlm_hmac_md5_update(ntlm->hmac_ctx, target, target_len) ||
1088
- !ntlm_hmac_md5_final(out, &out_len, ntlm->hmac_ctx)) {
1113
+ if (!ntlm_hmac_md5_init(ntlm, ntlm_hash, sizeof(ntlm_hash)) ||
1114
+ !ntlm_hmac_md5_update(ntlm, username, username_len) ||
1115
+ !ntlm_hmac_md5_update(ntlm, target, target_len) ||
1116
+ !ntlm_hmac_md5_final(out, &out_len, ntlm)) {
1089
1117
  ntlm_client_set_errmsg(ntlm, "failed to create HMAC-MD5");
1090
1118
  return false;
1091
1119
  }
1092
1120
 
1093
- assert(out_len == NTLM_NTLM2_HASH_LEN);
1121
+ NTLM_ASSERT(ntlm, out_len == NTLM_NTLM2_HASH_LEN);
1094
1122
  return true;
1095
1123
  }
1096
1124
 
@@ -1103,18 +1131,15 @@ static bool generate_ntlm2_challengehash(
1103
1131
  {
1104
1132
  size_t out_len = 16;
1105
1133
 
1106
- if (!ntlm_hmac_ctx_reset(ntlm->hmac_ctx) ||
1107
- !ntlm_hmac_md5_init(ntlm->hmac_ctx,
1108
- ntlm2_hash, NTLM_NTLM2_HASH_LEN) ||
1109
- !ntlm_hmac_md5_update(ntlm->hmac_ctx,
1110
- (const unsigned char *)&ntlm->challenge.nonce, 8) ||
1111
- !ntlm_hmac_md5_update(ntlm->hmac_ctx, blob, blob_len) ||
1112
- !ntlm_hmac_md5_final(out, &out_len, ntlm->hmac_ctx)) {
1134
+ if (!ntlm_hmac_md5_init(ntlm, ntlm2_hash, NTLM_NTLM2_HASH_LEN) ||
1135
+ !ntlm_hmac_md5_update(ntlm, (const unsigned char *)&ntlm->challenge.nonce, 8) ||
1136
+ !ntlm_hmac_md5_update(ntlm, blob, blob_len) ||
1137
+ !ntlm_hmac_md5_final(out, &out_len, ntlm)) {
1113
1138
  ntlm_client_set_errmsg(ntlm, "failed to create HMAC-MD5");
1114
1139
  return false;
1115
1140
  }
1116
1141
 
1117
- assert(out_len == 16);
1142
+ NTLM_ASSERT(ntlm, out_len == 16);
1118
1143
  return true;
1119
1144
  }
1120
1145
 
@@ -1125,21 +1150,17 @@ static bool generate_lm2_response(ntlm_client *ntlm,
1125
1150
  size_t lm2_len = 16;
1126
1151
  uint64_t local_nonce;
1127
1152
 
1128
- local_nonce = htonll(ntlm->nonce);
1153
+ local_nonce = ntlm_htonll(ntlm->nonce);
1129
1154
 
1130
- if (!ntlm_hmac_ctx_reset(ntlm->hmac_ctx) ||
1131
- !ntlm_hmac_md5_init(ntlm->hmac_ctx,
1132
- ntlm2_hash, NTLM_NTLM2_HASH_LEN) ||
1133
- !ntlm_hmac_md5_update(ntlm->hmac_ctx,
1134
- (const unsigned char *)&ntlm->challenge.nonce, 8) ||
1135
- !ntlm_hmac_md5_update(ntlm->hmac_ctx,
1136
- (const unsigned char *)&local_nonce, 8) ||
1137
- !ntlm_hmac_md5_final(lm2_challengehash, &lm2_len, ntlm->hmac_ctx)) {
1155
+ if (!ntlm_hmac_md5_init(ntlm, ntlm2_hash, NTLM_NTLM2_HASH_LEN) ||
1156
+ !ntlm_hmac_md5_update(ntlm, (const unsigned char *)&ntlm->challenge.nonce, 8) ||
1157
+ !ntlm_hmac_md5_update(ntlm, (const unsigned char *)&local_nonce, 8) ||
1158
+ !ntlm_hmac_md5_final(lm2_challengehash, &lm2_len, ntlm)) {
1138
1159
  ntlm_client_set_errmsg(ntlm, "failed to create HMAC-MD5");
1139
1160
  return false;
1140
1161
  }
1141
1162
 
1142
- assert(lm2_len == 16);
1163
+ NTLM_ASSERT(ntlm, lm2_len == 16);
1143
1164
 
1144
1165
  memcpy(&ntlm->lm_response[0], lm2_challengehash, 16);
1145
1166
  memcpy(&ntlm->lm_response[16], &local_nonce, 8);
@@ -1163,7 +1184,7 @@ static bool generate_nonce(ntlm_client *ntlm)
1163
1184
  if (ntlm->nonce)
1164
1185
  return true;
1165
1186
 
1166
- if (!ntlm_random_bytes(ntlm, buf, 8))
1187
+ if (!ntlm_random_bytes(buf, ntlm, 8))
1167
1188
  return false;
1168
1189
 
1169
1190
  memcpy(&ntlm->nonce, buf, sizeof(uint64_t));
@@ -1197,8 +1218,8 @@ static bool generate_ntlm2_response(ntlm_client *ntlm)
1197
1218
 
1198
1219
  /* the blob's integer values are in network byte order */
1199
1220
  signature = htonl(0x01010000);
1200
- timestamp = htonll(ntlm->timestamp);
1201
- nonce = htonll(ntlm->nonce);
1221
+ timestamp = ntlm_htonll(ntlm->timestamp);
1222
+ nonce = ntlm_htonll(ntlm->nonce);
1202
1223
 
1203
1224
  /* construct the blob */
1204
1225
  memcpy(&blob[0], &signature, 4);
@@ -1233,7 +1254,11 @@ int ntlm_client_response(
1233
1254
  uint32_t flags = 0;
1234
1255
  bool unicode;
1235
1256
 
1236
- assert(out && out_len && ntlm);
1257
+ NTLM_ASSERT_ARG(out);
1258
+ NTLM_ASSERT_ARG(out_len);
1259
+ NTLM_ASSERT_ARG(ntlm);
1260
+
1261
+ ENSURE_INITIALIZED(ntlm);
1237
1262
 
1238
1263
  *out = NULL;
1239
1264
  *out_len = 0;
@@ -1356,7 +1381,7 @@ int ntlm_client_response(
1356
1381
  !write_buf(ntlm, &ntlm->response, session, session_len))
1357
1382
  return -1;
1358
1383
 
1359
- assert(ntlm->response.pos == ntlm->response.len);
1384
+ NTLM_ASSERT(ntlm, ntlm->response.pos == ntlm->response.len);
1360
1385
 
1361
1386
  ntlm->state = NTLM_STATE_COMPLETE;
1362
1387
 
@@ -1368,41 +1393,48 @@ int ntlm_client_response(
1368
1393
 
1369
1394
  void ntlm_client_reset(ntlm_client *ntlm)
1370
1395
  {
1371
- ntlm_client_flags flags;
1372
- ntlm_hmac_ctx *hmac_ctx;
1373
- ntlm_unicode_ctx *unicode_ctx;
1374
-
1375
- assert(ntlm);
1396
+ if (!ntlm)
1397
+ return;
1376
1398
 
1377
- free(ntlm->negotiate.buf);
1378
- free(ntlm->challenge.target_info);
1379
- free(ntlm->challenge.target);
1380
- free(ntlm->challenge.target_domain);
1381
- free(ntlm->challenge.target_domain_dns);
1382
- free(ntlm->challenge.target_server);
1383
- free(ntlm->challenge.target_server_dns);
1384
- free(ntlm->response.buf);
1399
+ ntlm->state = NTLM_STATE_NEGOTIATE;
1385
1400
 
1386
- free(ntlm->hostname);
1387
- free(ntlm->hostname_utf16);
1388
- free(ntlm->hostdomain);
1401
+ free_hostname(ntlm);
1389
1402
 
1390
- free(ntlm->target);
1391
- free(ntlm->target_utf16);
1403
+ memset(&ntlm->host_version, 0, sizeof(ntlm_version));
1392
1404
 
1393
- free(ntlm->ntlm2_response);
1405
+ reset(ntlm->target);
1406
+ reset(ntlm->target_utf16);
1407
+ ntlm->target_utf16_len = 0;
1394
1408
 
1395
1409
  free_credentials(ntlm);
1396
1410
 
1397
- flags = ntlm->flags;
1398
- hmac_ctx = ntlm->hmac_ctx;
1399
- unicode_ctx = ntlm->unicode_ctx;
1411
+ ntlm->nonce = 0;
1412
+ ntlm->timestamp = 0;
1400
1413
 
1401
- memset(ntlm, 0, sizeof(struct ntlm_client));
1414
+ memset(ntlm->lm_response, 0, NTLM_LM_RESPONSE_LEN);
1415
+ ntlm->lm_response_len = 0;
1402
1416
 
1403
- ntlm->flags = flags;
1404
- ntlm->hmac_ctx = hmac_ctx;
1405
- ntlm->unicode_ctx = unicode_ctx;
1417
+ memset(ntlm->ntlm_response, 0, NTLM_NTLM_RESPONSE_LEN);
1418
+ ntlm->ntlm_response_len = 0;
1419
+
1420
+ reset(ntlm->ntlm2_response);
1421
+ ntlm->ntlm2_response_len = 0;
1422
+
1423
+ reset(ntlm->negotiate.buf);
1424
+ ntlm->negotiate.pos = 0;
1425
+ ntlm->negotiate.len = 0;
1426
+
1427
+ reset(ntlm->response.buf);
1428
+ ntlm->response.pos = 0;
1429
+ ntlm->response.len = 0;
1430
+
1431
+ free(ntlm->challenge.target_info);
1432
+ free(ntlm->challenge.target);
1433
+ free(ntlm->challenge.target_domain);
1434
+ free(ntlm->challenge.target_domain_dns);
1435
+ free(ntlm->challenge.target_server);
1436
+ free(ntlm->challenge.target_server_dns);
1437
+ memset(&ntlm->challenge, 0, sizeof(ntlm_challenge));
1406
1438
  }
1407
1439
 
1408
1440
  void ntlm_client_free(ntlm_client *ntlm)
@@ -1410,10 +1442,10 @@ void ntlm_client_free(ntlm_client *ntlm)
1410
1442
  if (!ntlm)
1411
1443
  return;
1412
1444
 
1413
- ntlm_client_reset(ntlm);
1445
+ ntlm_crypt_shutdown(ntlm);
1446
+ ntlm_unicode_shutdown(ntlm);
1414
1447
 
1415
- ntlm_hmac_ctx_free(ntlm->hmac_ctx);
1416
- ntlm_unicode_ctx_free(ntlm->unicode_ctx);
1448
+ ntlm_client_reset(ntlm);
1417
1449
 
1418
1450
  free(ntlm);
1419
1451
  }
@@ -14,6 +14,8 @@
14
14
  #include "crypt.h"
15
15
  #include "compat.h"
16
16
 
17
+ #define NTLM_UNUSED(x) ((void)(x))
18
+
17
19
  #define NTLM_LM_RESPONSE_LEN 24
18
20
  #define NTLM_NTLM_RESPONSE_LEN 24
19
21
  #define NTLM_NTLM_HASH_LEN 16
@@ -66,9 +68,11 @@ struct ntlm_client {
66
68
 
67
69
  ntlm_state state;
68
70
 
69
- /* crypto contexts */
70
- ntlm_hmac_ctx *hmac_ctx;
71
- ntlm_unicode_ctx *unicode_ctx;
71
+ /* subsystem contexts */
72
+ ntlm_crypt_ctx crypt_ctx;
73
+ ntlm_unicode_ctx unicode_ctx;
74
+ int crypt_initialized : 1,
75
+ unicode_initialized : 1;
72
76
 
73
77
  /* error message as set by the library */
74
78
  const char *errmsg;
@@ -85,24 +89,24 @@ struct ntlm_client {
85
89
  char *password;
86
90
 
87
91
  /* strings as converted to utf16 */
92
+ char *hostname_utf16;
88
93
  char *target_utf16;
89
94
  char *username_utf16;
90
95
  char *username_upper_utf16;
91
96
  char *userdomain_utf16;
92
- char *hostname_utf16;
93
97
  char *password_utf16;
94
98
 
95
- /* timestamp and nonce; only for debugging */
96
- uint64_t nonce;
97
- uint64_t timestamp;
98
-
99
+ size_t hostname_utf16_len;
99
100
  size_t username_utf16_len;
100
101
  size_t username_upper_utf16_len;
101
102
  size_t userdomain_utf16_len;
102
- size_t hostname_utf16_len;
103
103
  size_t password_utf16_len;
104
104
  size_t target_utf16_len;
105
105
 
106
+ /* timestamp and nonce; only for debugging */
107
+ uint64_t nonce;
108
+ uint64_t timestamp;
109
+
106
110
  unsigned char lm_response[NTLM_LM_RESPONSE_LEN];
107
111
  size_t lm_response_len;
108
112
 
@@ -15,13 +15,26 @@
15
15
  extern "C" {
16
16
  #endif
17
17
 
18
- #define NTLM_CLIENT_VERSION "0.0.1"
18
+ #define NTLM_CLIENT_VERSION "0.9.0"
19
19
  #define NTLM_CLIENT_VERSION_MAJOR 0
20
- #define NTLM_CLIENT_VERSION_MINOR 0
21
- #define NTLM_CLIENT_VERSION_TEENY 1
20
+ #define NTLM_CLIENT_VERSION_MINOR 9
21
+ #define NTLM_CLIENT_VERSION_TEENY 0
22
22
 
23
23
  typedef struct ntlm_client ntlm_client;
24
24
 
25
+ typedef enum {
26
+ /**
27
+ * An error occurred; more details are available by querying
28
+ * `ntlm_client_errmsg`.
29
+ */
30
+ NTLM_CLIENT_ERROR = -1,
31
+
32
+ /**
33
+ * The input provided to the function is missing or invalid.
34
+ */
35
+ NTLM_CLIENT_ERROR_INVALID_INPUT = -2,
36
+ } ntlm_error_code;
37
+
25
38
  /*
26
39
  * Flags for initializing the `ntlm_client` context. A combination of
27
40
  * these flags can be provided to `ntlm_client_init`.
@@ -11,26 +11,32 @@
11
11
 
12
12
  #include "compat.h"
13
13
 
14
+ #ifdef UNICODE_ICONV
15
+ # include "unicode_iconv.h"
16
+ #elif UNICODE_BUILTIN
17
+ # include "unicode_builtin.h"
18
+ #endif
19
+
14
20
  #define NTLM_UNICODE_MAX_LEN 2048
15
21
 
16
22
  typedef struct ntlm_unicode_ctx ntlm_unicode_ctx;
17
23
 
18
- extern ntlm_unicode_ctx *ntlm_unicode_ctx_init(ntlm_client *ntlm);
24
+ extern bool ntlm_unicode_init(ntlm_client *ntlm);
19
25
 
20
26
  bool ntlm_unicode_utf8_to_16(
21
27
  char **converted,
22
28
  size_t *converted_len,
23
- ntlm_unicode_ctx *ctx,
29
+ ntlm_client *ntlm,
24
30
  const char *string,
25
31
  size_t string_len);
26
32
 
27
33
  bool ntlm_unicode_utf16_to_8(
28
34
  char **converted,
29
35
  size_t *converted_len,
30
- ntlm_unicode_ctx *ctx,
36
+ ntlm_client *ntlm,
31
37
  const char *string,
32
38
  size_t string_len);
33
39
 
34
- extern void ntlm_unicode_ctx_free(ntlm_unicode_ctx *ctx);
40
+ extern void ntlm_unicode_shutdown(ntlm_client *ntlm);
35
41
 
36
42
  #endif /* PRIVATE_UNICODE_H__ */