@cetapod/react-native-smb 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +72 -0
  3. package/ReactNativeSmb.podspec +59 -0
  4. package/cpp/ios/OnLoad.mm +24 -0
  5. package/cpp/shared/HybridSMB.cpp +324 -0
  6. package/cpp/shared/HybridSMB.hpp +102 -0
  7. package/cpp/shared/ReactNativeSmb.hpp +428 -0
  8. package/cpp/shared/connection/ContextRequest.hpp +27 -0
  9. package/cpp/shared/connection/ContextRequestQueue.cpp +85 -0
  10. package/cpp/shared/connection/ContextRequestQueue.hpp +28 -0
  11. package/cpp/shared/connection/MetadataContextLease.hpp +33 -0
  12. package/cpp/shared/connection/PoolContextHandle.cpp +35 -0
  13. package/cpp/shared/connection/PoolContextHandle.hpp +44 -0
  14. package/cpp/shared/connection/PoolSlot.cpp +73 -0
  15. package/cpp/shared/connection/PoolSlot.hpp +46 -0
  16. package/cpp/shared/connection/PoolTypes.hpp +41 -0
  17. package/cpp/shared/connection/SmbConnection.cpp +385 -0
  18. package/cpp/shared/connection/SmbConnection.hpp +93 -0
  19. package/cpp/shared/connection/SmbConnectionPool.cpp +316 -0
  20. package/cpp/shared/connection/SmbConnectionPool.hpp +84 -0
  21. package/cpp/shared/core/CancellationToken.hpp +22 -0
  22. package/cpp/shared/core/OperatorContext.hpp +24 -0
  23. package/cpp/shared/core/SmbEnums.hpp +126 -0
  24. package/cpp/shared/core/SmbTask.cpp +131 -0
  25. package/cpp/shared/core/SmbTask.hpp +52 -0
  26. package/cpp/shared/core/SmbTaskCore.cpp +222 -0
  27. package/cpp/shared/core/SmbTaskCore.hpp +107 -0
  28. package/cpp/shared/core/SmbTypes.hpp +35 -0
  29. package/cpp/shared/core/TaskObserverHub.cpp +166 -0
  30. package/cpp/shared/core/TaskObserverHub.hpp +66 -0
  31. package/cpp/shared/core/TaskSnapshotCodec.cpp +32 -0
  32. package/cpp/shared/core/TaskSnapshotCodec.hpp +41 -0
  33. package/cpp/shared/io/SmbCopyTree.hpp +114 -0
  34. package/cpp/shared/io/SmbDirScan.hpp +80 -0
  35. package/cpp/shared/io/SmbFileIO.cpp +1355 -0
  36. package/cpp/shared/io/SmbFileIO.hpp +45 -0
  37. package/cpp/shared/io/SmbPathUtil.hpp +75 -0
  38. package/cpp/shared/io/SmbSecurity.cpp +308 -0
  39. package/cpp/shared/io/SmbSecurity.hpp +32 -0
  40. package/cpp/shared/io/SmbTreeOps.hpp +112 -0
  41. package/cpp/shared/operators/Operator.hpp +35 -0
  42. package/cpp/shared/operators/OperatorBase.cpp +57 -0
  43. package/cpp/shared/operators/OperatorBase.hpp +57 -0
  44. package/cpp/shared/operators/connection/ConnectOperator.cpp +19 -0
  45. package/cpp/shared/operators/connection/ConnectOperator.hpp +22 -0
  46. package/cpp/shared/operators/connection/ConnectShareOperator.cpp +19 -0
  47. package/cpp/shared/operators/connection/ConnectShareOperator.hpp +21 -0
  48. package/cpp/shared/operators/connection/DisconnectOperator.cpp +12 -0
  49. package/cpp/shared/operators/connection/DisconnectOperator.hpp +15 -0
  50. package/cpp/shared/operators/connection/InitializeOperator.cpp +12 -0
  51. package/cpp/shared/operators/connection/InitializeOperator.hpp +22 -0
  52. package/cpp/shared/operators/connection/ListSharesOperator.cpp +13 -0
  53. package/cpp/shared/operators/connection/ListSharesOperator.hpp +18 -0
  54. package/cpp/shared/operators/listing/GetPathInfoOperator.cpp +43 -0
  55. package/cpp/shared/operators/listing/GetPathInfoOperator.hpp +21 -0
  56. package/cpp/shared/operators/listing/GetSecurityDescriptorOperator.cpp +202 -0
  57. package/cpp/shared/operators/listing/GetSecurityDescriptorOperator.hpp +22 -0
  58. package/cpp/shared/operators/listing/ListDirectoryOperator.cpp +20 -0
  59. package/cpp/shared/operators/listing/ListDirectoryOperator.hpp +24 -0
  60. package/cpp/shared/operators/mutate/CopyItemOperator.cpp +19 -0
  61. package/cpp/shared/operators/mutate/CopyItemOperator.hpp +25 -0
  62. package/cpp/shared/operators/mutate/CreateDirectoryOperator.cpp +28 -0
  63. package/cpp/shared/operators/mutate/CreateDirectoryOperator.hpp +20 -0
  64. package/cpp/shared/operators/mutate/DeleteItemOperator.cpp +96 -0
  65. package/cpp/shared/operators/mutate/DeleteItemOperator.hpp +23 -0
  66. package/cpp/shared/operators/mutate/DuplicateItemOperator.cpp +48 -0
  67. package/cpp/shared/operators/mutate/DuplicateItemOperator.hpp +23 -0
  68. package/cpp/shared/operators/mutate/MoveItemOperator.cpp +32 -0
  69. package/cpp/shared/operators/mutate/MoveItemOperator.hpp +21 -0
  70. package/cpp/shared/operators/mutate/RenameItemOperator.cpp +37 -0
  71. package/cpp/shared/operators/mutate/RenameItemOperator.hpp +21 -0
  72. package/cpp/shared/operators/transfer/DownloadFileOperator.cpp +31 -0
  73. package/cpp/shared/operators/transfer/DownloadFileOperator.hpp +21 -0
  74. package/cpp/shared/operators/transfer/UploadFileOperator.cpp +27 -0
  75. package/cpp/shared/operators/transfer/UploadFileOperator.hpp +21 -0
  76. package/cpp/shared/util/SmbErrorMapper.hpp +229 -0
  77. package/cpp/shared/util/SmbLog.hpp +20 -0
  78. package/docs/API.md +105 -0
  79. package/docs/ARCHITECTURE.md +70 -0
  80. package/docs/TASK_MODEL.md +149 -0
  81. package/ios/include/smb2/libsmb2-dcerpc-lsa.h +172 -0
  82. package/ios/include/smb2/libsmb2-dcerpc-srvsvc.h +180 -0
  83. package/ios/include/smb2/libsmb2-dcerpc.h +155 -0
  84. package/ios/include/smb2/libsmb2-raw.h +497 -0
  85. package/ios/include/smb2/libsmb2.h +1384 -0
  86. package/ios/include/smb2/smb2-errors.h +549 -0
  87. package/ios/include/smb2/smb2.h +1251 -0
  88. package/ios/libs/device/libsmb2-device.a +0 -0
  89. package/ios/libs/libsmb2.xcframework/Info.plist +48 -0
  90. package/ios/libs/libsmb2.xcframework/ios-arm64/Headers/smb2/libsmb2-dcerpc-lsa.h +172 -0
  91. package/ios/libs/libsmb2.xcframework/ios-arm64/Headers/smb2/libsmb2-dcerpc-srvsvc.h +180 -0
  92. package/ios/libs/libsmb2.xcframework/ios-arm64/Headers/smb2/libsmb2-dcerpc.h +155 -0
  93. package/ios/libs/libsmb2.xcframework/ios-arm64/Headers/smb2/libsmb2-raw.h +497 -0
  94. package/ios/libs/libsmb2.xcframework/ios-arm64/Headers/smb2/libsmb2.h +1384 -0
  95. package/ios/libs/libsmb2.xcframework/ios-arm64/Headers/smb2/smb2-errors.h +549 -0
  96. package/ios/libs/libsmb2.xcframework/ios-arm64/Headers/smb2/smb2.h +1251 -0
  97. package/ios/libs/libsmb2.xcframework/ios-arm64/libsmb2.a +0 -0
  98. package/ios/libs/libsmb2.xcframework/ios-arm64_x86_64-simulator/Headers/smb2/libsmb2-dcerpc-lsa.h +172 -0
  99. package/ios/libs/libsmb2.xcframework/ios-arm64_x86_64-simulator/Headers/smb2/libsmb2-dcerpc-srvsvc.h +180 -0
  100. package/ios/libs/libsmb2.xcframework/ios-arm64_x86_64-simulator/Headers/smb2/libsmb2-dcerpc.h +155 -0
  101. package/ios/libs/libsmb2.xcframework/ios-arm64_x86_64-simulator/Headers/smb2/libsmb2-raw.h +497 -0
  102. package/ios/libs/libsmb2.xcframework/ios-arm64_x86_64-simulator/Headers/smb2/libsmb2.h +1384 -0
  103. package/ios/libs/libsmb2.xcframework/ios-arm64_x86_64-simulator/Headers/smb2/smb2-errors.h +549 -0
  104. package/ios/libs/libsmb2.xcframework/ios-arm64_x86_64-simulator/Headers/smb2/smb2.h +1251 -0
  105. package/ios/libs/libsmb2.xcframework/ios-arm64_x86_64-simulator/libsmb2.a +0 -0
  106. package/ios/libs/simulator/libsmb2-simulator.a +0 -0
  107. package/lib/ReactNativeSmb.d.ts +200 -0
  108. package/lib/ReactNativeSmb.js +1 -0
  109. package/lib/bridge/decode.d.ts +4 -0
  110. package/lib/bridge/decode.js +92 -0
  111. package/lib/core/SMB.d.ts +3 -0
  112. package/lib/core/SMB.js +4 -0
  113. package/lib/core/SmbClient.d.ts +35 -0
  114. package/lib/core/SmbClient.js +99 -0
  115. package/lib/core/SmbTask.d.ts +41 -0
  116. package/lib/core/SmbTask.js +74 -0
  117. package/lib/core/TransferStore.d.ts +22 -0
  118. package/lib/core/TransferStore.js +88 -0
  119. package/lib/core/ids.d.ts +1 -0
  120. package/lib/core/ids.js +3 -0
  121. package/lib/core/taskResult.d.ts +3 -0
  122. package/lib/core/taskResult.js +52 -0
  123. package/lib/hooks/useSubscribe.d.ts +20 -0
  124. package/lib/hooks/useSubscribe.js +36 -0
  125. package/lib/hooks/useTransfers.d.ts +7 -0
  126. package/lib/hooks/useTransfers.js +29 -0
  127. package/lib/index.d.ts +7 -0
  128. package/lib/index.js +7 -0
  129. package/lib/labels.d.ts +6 -0
  130. package/lib/labels.js +71 -0
  131. package/lib/types.d.ts +141 -0
  132. package/lib/types.js +59 -0
  133. package/lib/utils.d.ts +79 -0
  134. package/lib/utils.js +153 -0
  135. package/package.json +63 -0
  136. package/scripts/build-libsmb2.sh +143 -0
  137. package/scripts/create-xcframework.sh +84 -0
@@ -0,0 +1,1384 @@
1
+ /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
2
+ /*
3
+ Copyright (C) 2016 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
4
+
5
+ This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation; either version 2.1 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ #ifndef _LIBSMB2_H_
20
+ #define _LIBSMB2_H_
21
+
22
+ #ifdef __cplusplus
23
+ extern "C" {
24
+ #endif
25
+
26
+ #define LIBSMB2_SHARE_ENUM_V2 1
27
+
28
+ struct smb2_iovec {
29
+ uint8_t *buf;
30
+ size_t len;
31
+ void (*free)(void *);
32
+ };
33
+
34
+ struct smb2_context;
35
+
36
+ /*
37
+ * Generic callback for completion of smb2_*_async().
38
+ * command_data depends on status.
39
+ */
40
+ typedef void (*smb2_command_cb)(struct smb2_context *smb2, int status,
41
+ void *command_data, void *cb_data);
42
+
43
+ /*
44
+ * callback for getting error information when errors are set
45
+ * command_data depends on status.
46
+ */
47
+ typedef void (*smb2_error_cb)(struct smb2_context *smb2,
48
+ const char *error_string);
49
+
50
+ /*
51
+ * callback for server accepting a new connection
52
+ */
53
+ typedef int (*smb2_accepted_cb)(const int fd, void *cb_data);
54
+
55
+ /*
56
+ * callback when a new connection is made to setup context
57
+ */
58
+ typedef void (*smb2_client_connection)(struct smb2_context *smb2, void *cb_data);
59
+
60
+ /*
61
+ * callback when a server notifies of an oplock or lease break
62
+ * the type of break is determined from the stuct_size in the request
63
+ * (notification) passed in. the app can set the new oplock level
64
+ * or new lease state for the acknowledgement that will be sent back
65
+ */
66
+ struct smb2_oplock_or_lease_break_reply;
67
+
68
+ typedef void (*smb2_oplock_or_lease_break_cb)(struct smb2_context *smb2,
69
+ int status,
70
+ struct smb2_oplock_or_lease_break_reply *rep,
71
+ uint8_t *new_oplock_level,
72
+ uint32_t *new_lease_state);
73
+
74
+ /* Stat structure */
75
+ #define SMB2_TYPE_FILE 0x00000000
76
+ #define SMB2_TYPE_DIRECTORY 0x00000001
77
+ #define SMB2_TYPE_LINK 0x00000002
78
+ struct smb2_stat_64 {
79
+ uint32_t smb2_type;
80
+ uint32_t smb2_nlink;
81
+ uint64_t smb2_ino;
82
+ uint64_t smb2_size;
83
+ uint64_t smb2_atime;
84
+ uint64_t smb2_atime_nsec;
85
+ uint64_t smb2_mtime;
86
+ uint64_t smb2_mtime_nsec;
87
+ uint64_t smb2_ctime;
88
+ uint64_t smb2_ctime_nsec;
89
+ uint64_t smb2_btime;
90
+ uint64_t smb2_btime_nsec;
91
+ };
92
+
93
+ struct smb2_statvfs {
94
+ uint32_t f_bsize;
95
+ uint32_t f_frsize;
96
+ uint64_t f_blocks;
97
+ uint64_t f_bfree;
98
+ uint64_t f_bavail;
99
+ uint32_t f_files;
100
+ uint32_t f_ffree;
101
+ uint32_t f_favail;
102
+ uint32_t f_fsid;
103
+ uint32_t f_flag;
104
+ uint32_t f_namemax;
105
+ };
106
+
107
+ struct smb2dirent {
108
+ const char *name;
109
+ struct smb2_stat_64 st;
110
+ };
111
+
112
+ #if defined(_WINDOWS)
113
+ #ifdef __USE_WINSOCK__
114
+ #include <winsock.h>
115
+ #else
116
+ #include <ws2tcpip.h>
117
+ #include <winsock2.h>
118
+ #endif
119
+ #elif defined(_XBOX)
120
+ #include <xtl.h>
121
+ #include <winsockx.h>
122
+ #endif
123
+
124
+ #if defined(_WINDOWS) || defined(_XBOX)
125
+ typedef SOCKET t_socket;
126
+ #else
127
+ typedef int t_socket;
128
+ #endif
129
+
130
+ /*
131
+ * Create an SMB2 context.
132
+ * Function returns
133
+ * NULL : Failed to create a context.
134
+ * *smb2 : A pointer to an smb2 context.
135
+ */
136
+ struct smb2_context *smb2_init_context(void);
137
+
138
+ /*
139
+ * Close an SMB2 context
140
+ *
141
+ * closes socket if open, and clears keys but leave
142
+ * context allocated. the context will be destroyed
143
+ * at a time later when it won't be in-use
144
+ */
145
+ void smb2_close_context(struct smb2_context *smb2);
146
+
147
+ /*
148
+ * Destroy an smb2 context.
149
+ *
150
+ * Any open "struct smb2fh" will automatically be freed. You can not reference
151
+ * any "struct smb2fh" after the context is destroyed.
152
+ * Any open "struct smb2dir" will automatically be freed. You can not reference
153
+ * any "struct smb2dir" after the context is destroyed.
154
+ * Any pending async commands will be aborted with -ECONNRESET.
155
+ */
156
+ void smb2_destroy_context(struct smb2_context *smb2);
157
+
158
+ /*
159
+ * Get the list of currently allocated contexts
160
+ */
161
+ struct smb2_context *smb2_active_contexts(void);
162
+
163
+ /*
164
+ * Determine of the context is currently active. This lets
165
+ * code know if the context was destroyed in a callback for example
166
+ */
167
+ int smb2_context_active(struct smb2_context *smb2);
168
+
169
+ /*
170
+ * EVENT SYSTEM INTEGRATION
171
+ * ========================
172
+ * The following functions are used to integrate libsmb2 in an event
173
+ * system.
174
+ *
175
+ * The simplest way is by using smb2_get_fd() and smb2_which_events()
176
+ * in every loop of the event system to detect which fd to use (it can change)
177
+ * and which events should be waited for.
178
+ * This is very simple to use but has the drawback of the overhead having to
179
+ * call these two functions for every loop.
180
+ *
181
+ * This is suitable for trivial apps where you roll your event system
182
+ * using select() or poll().
183
+ *
184
+ * See for example smb2-cat-async.c for an example on how to use these
185
+ * two functions in an event loop.
186
+ */
187
+ /*
188
+ * Returns the file descriptor that libsmb2 uses.
189
+ */
190
+ t_socket smb2_get_fd(struct smb2_context *smb2);
191
+ /*
192
+ * Returns which events that we need to poll for for the smb2 file descriptor.
193
+ */
194
+ int smb2_which_events(struct smb2_context *smb2);
195
+
196
+ /*
197
+ * Returns file descriptors that libsmb2 use or is trying to connect to
198
+ *
199
+ * This function should be used when trying to connect with more than one
200
+ * addresses in parallel, cf. rfc8305: Happy Eyeballs.
201
+ *
202
+ * The timeout, in ms, is valid during the socket connection step. The caller
203
+ * should call smb2_service_fd() with fd = -1 when the timeout is reached.
204
+ * This will trigger a new socket connection on the next resolved address. All
205
+ * connecting fds will be closed when the first fd is connected. The timeout
206
+ * will be -1 (infinite) once connected or if there is no next addresses to
207
+ * connect to.
208
+ */
209
+ const t_socket *
210
+ smb2_get_fds(struct smb2_context *smb2, size_t *fd_count, int *timeout);
211
+
212
+ /*
213
+ * A much more scalable way to use smb2_fd_event_callbacks() to register
214
+ * callbacks for libsmb2 to call anytime a filedescriptor is changed or when
215
+ * the events we are waiting for changes.
216
+ * This way libsmb2 will do callbacks back into the application to inform
217
+ * when fd or events change.
218
+ *
219
+ * This is suitable when you want to plug libsmb2 into a more sophisticated
220
+ * eventsystem or if you use epoll() or similar.
221
+ *
222
+ * See for smb2-ls-async.c for a trivial example of using these callbacks.
223
+ */
224
+ #define SMB2_ADD_FD 0
225
+ #define SMB2_DEL_FD 1
226
+ typedef void (*smb2_change_fd_cb)(struct smb2_context *smb2, t_socket fd, int cmd);
227
+ typedef void (*smb2_change_events_cb)(struct smb2_context *smb2, t_socket fd,
228
+ int events);
229
+ void smb2_fd_event_callbacks(struct smb2_context *smb2,
230
+ smb2_change_fd_cb change_fd,
231
+ smb2_change_events_cb change_events);
232
+
233
+ /*
234
+ * Called to process the events when events become available for the smb2
235
+ * file descriptor.
236
+ *
237
+ * Returns:
238
+ * 0 : Success
239
+ * <0 : Unrecoverable failure. At this point the context can no longer be
240
+ * used and must be freed by calling smb2_destroy_context().
241
+ *
242
+ */
243
+ int smb2_service(struct smb2_context *smb2, int revents);
244
+
245
+ /*
246
+ * Called to process the events when events become available for the smb2
247
+ * file descriptor.
248
+ *
249
+ * Behave like smb2_service() with some differences:
250
+ * - must be called with a fd returned by smb2_get_fd() or smb2_get_fds(),
251
+ * - passing -1 as fd will trigger a new connection attempt on the next
252
+ * resolved address, cf. smb2_get_fds().
253
+ *
254
+ * Returns:
255
+ * 0 : Success
256
+ * <0 : Unrecoverable failure. At this point the context can no longer be
257
+ * used and must be freed by calling smb2_destroy_context().
258
+ *
259
+ */
260
+ int smb2_service_fd(struct smb2_context *smb2, t_socket fd, int revents);
261
+
262
+ /*
263
+ * Set the timeout in seconds after which a command will be aborted with
264
+ * SMB2_STATUS_IO_TIMEOUT.
265
+ * If you use timeouts with the async API you must make sure to call
266
+ * smb2_service() at least once every second.
267
+ *
268
+ * Default is 0: No timeout.
269
+ */
270
+ void smb2_set_timeout(struct smb2_context *smb2, int seconds);
271
+
272
+ /*
273
+ * Set passthrough-enable. Passthrough allows command packers
274
+ * and unpackers to keep the extra data on complex commands
275
+ * in its on-the-wire format without any interpretation. this
276
+ * is useful for proxy use cases where there might be no need
277
+ * to fully parse things like query-info replies or ioctl
278
+ * requests. If passthrough is not set, any command that
279
+ * that is processed that can't interpret the data will fail
280
+ * Most client use case will not need this
281
+ *
282
+ * Default is 0: no-passthrough
283
+ */
284
+ void smb2_set_passthrough(struct smb2_context *smb2,
285
+ int passthrough);
286
+
287
+ /*
288
+ * Get the current passthrough setting
289
+ */
290
+ void smb2_get_passthrough(struct smb2_context *smb2,
291
+ int *passthrough);
292
+
293
+ /*
294
+ * Set which version of SMB to negotiate.
295
+ * Default is to let the server pick the version.
296
+ */
297
+ enum smb2_negotiate_version {
298
+ SMB2_VERSION_ANY = 0,
299
+ SMB2_VERSION_ANY2 = 2,
300
+ SMB2_VERSION_ANY3 = 3,
301
+ SMB2_VERSION_0202 = 0x0202,
302
+ SMB2_VERSION_0210 = 0x0210,
303
+ SMB2_VERSION_0300 = 0x0300,
304
+ SMB2_VERSION_0302 = 0x0302,
305
+ SMB2_VERSION_0311 = 0x0311,
306
+ };
307
+
308
+ #define SMB2_VERSION_WILDCARD 0x02FF
309
+
310
+ void smb2_set_version(struct smb2_context *smb2,
311
+ enum smb2_negotiate_version version);
312
+
313
+ /*
314
+ * Sets which version libsmb2 uses.
315
+ */
316
+ #define LIBSMB2_MAJOR_VERSION 4
317
+ #define LIBSMB2_MINOR_VERSION 0
318
+ #define LIBSMB2_PATCH_VERSION 0
319
+
320
+ struct smb2_libversion
321
+ {
322
+ uint8_t major_version;
323
+ uint8_t minor_version;
324
+ uint8_t patch_version;
325
+ };
326
+
327
+ /*
328
+ * Gets the libsmb2 version being linked while used.
329
+ * This function will be available on 5.x
330
+ * @param struct smb2_libversion
331
+ */
332
+ void smb2_get_libsmb2Version(struct smb2_libversion *smb2_ver);
333
+
334
+ /*
335
+ * gets the (currently) negotiated dialect
336
+ */
337
+ uint16_t smb2_get_dialect(struct smb2_context *smb2);
338
+
339
+ /*
340
+ * Set the security mode for the connection.
341
+ * This is a combination of the flags SMB2_NEGOTIATE_SIGNING_ENABLED
342
+ * and SMB2_NEGOTIATE_SIGNING_REQUIRED
343
+ * Default is 0.
344
+ */
345
+ void smb2_set_security_mode(struct smb2_context *smb2, uint16_t security_mode);
346
+
347
+ /*
348
+ * Set whether smb3 encryption should be used or not.
349
+ * 0 : disable encryption. This is the default.
350
+ * !0 : enable encryption.
351
+ */
352
+ void smb2_set_seal(struct smb2_context *smb2, int val);
353
+
354
+ /*
355
+ * Set whether smb2 signing should be required or not
356
+ * 0 : do not require signing. This is the default.
357
+ * !0 : require signing.
358
+ */
359
+ void smb2_set_sign(struct smb2_context *smb2, int val);
360
+
361
+ enum smb2_sec {
362
+ SMB2_SEC_UNDEFINED = 0,
363
+ SMB2_SEC_NTLMSSP,
364
+ SMB2_SEC_KRB5,
365
+ };
366
+
367
+ /*
368
+ * Set authentication method.
369
+ * SMB2_SEC_UNDEFINED (use KRB if available or NTLM if not)
370
+ * SMB2_SEC_NTLMSSP
371
+ * SMB2_SEC_KRB5
372
+ */
373
+ void smb2_set_authentication(struct smb2_context *smb2, int val);
374
+
375
+ /*
376
+ * Set the username that we will try to authenticate as.
377
+ * Default is to try to authenticate as the current user.
378
+ */
379
+ void smb2_set_user(struct smb2_context *smb2, const char *user);
380
+
381
+ /*
382
+ * Get the username associated with a context.
383
+ * returns NULL if none
384
+ */
385
+ const char *smb2_get_user(struct smb2_context *smb2);
386
+
387
+ /*
388
+ * Set the password that we will try to authenticate as.
389
+ * This function is only needed when libsmb2 is built --without-libkrb5
390
+ */
391
+ void smb2_set_password(struct smb2_context *smb2, const char *password);
392
+
393
+ /*
394
+ * Convert a win timestamp to a unix timeval
395
+ */
396
+ void smb2_win_to_timeval(uint64_t smb2_time, struct smb2_timeval *tv);
397
+
398
+ /*
399
+ * Convert unit timeval to a win timestamp
400
+ */
401
+ uint64_t smb2_timeval_to_win(struct smb2_timeval *tv);
402
+
403
+ /*
404
+ * set the context error string
405
+ */
406
+ void smb2_set_error(struct smb2_context *smb2,
407
+ const char *error_string, ...);
408
+
409
+ /*
410
+ * Register an error callback, so any calls to smb2_set_error will call this
411
+ * function with the error string generated
412
+ */
413
+ void smb2_register_error_callback(struct smb2_context *smb,
414
+ smb2_error_cb error_cb);
415
+
416
+ /*
417
+ * register for oplock or lease break callbacks
418
+ */
419
+ void smb2_set_oplock_or_lease_break_callback(struct smb2_context *smb2,
420
+ smb2_oplock_or_lease_break_cb cb);
421
+
422
+ /*
423
+ * Set the smb2 context passworkd from a file (see NTLM_USER_FILE)
424
+ * depends on user/domain being already set in smb2 context
425
+ */
426
+ void smb2_set_password_from_file(struct smb2_context *smb2);
427
+
428
+ /*
429
+ * Set the domain when authenticating.
430
+ * This function is only needed when libsmb2 is built --without-libkrb5
431
+ */
432
+ void smb2_set_domain(struct smb2_context *smb2, const char *domain);
433
+
434
+ /*
435
+ * Get the domain associated with a context.
436
+ * returns NULL if none
437
+ */
438
+ const char *smb2_get_domain(struct smb2_context *smb2);
439
+ /*
440
+ * Set the workstation when authenticating.
441
+ * This function is only needed when libsmb2 is built --without-libkrb5
442
+ */
443
+ void smb2_set_workstation(struct smb2_context *smb2, const char *workstation);
444
+
445
+ /*
446
+ * Get the workstation associated with a context.
447
+ * returns NULL if none
448
+ */
449
+ const char *smb2_get_workstation(struct smb2_context *smb2);
450
+
451
+ /*
452
+ * Sets the address to some user defined object. May be used to make
453
+ * additional context data available in the async callbacks.
454
+ */
455
+ void smb2_set_opaque(struct smb2_context *smb2, void *opaque);
456
+
457
+ /*
458
+ * Returns the opaque pointer set with smb2_set_opaque.
459
+ */
460
+ void *smb2_get_opaque(struct smb2_context *smb2);
461
+
462
+ /*
463
+ * copy credential handle from one context to another (and set
464
+ * it NULL in source context)
465
+ * returns 0 if handle transferred,
466
+ * or -1 if not (no handle or no context, or not applicable)
467
+ */
468
+ int smb2_delegate_credentials(struct smb2_context *in, struct smb2_context *out);
469
+
470
+ /*
471
+ * Sets the client_guid for this context.
472
+ */
473
+ void smb2_set_client_guid(struct smb2_context *smb2, const uint8_t guid[SMB2_GUID_SIZE]);
474
+
475
+ /*
476
+ * Returns the client_guid for this context.
477
+ */
478
+ const char *smb2_get_client_guid(struct smb2_context *smb2);
479
+
480
+ /*
481
+ * Asynchronous call to connect a TCP connection to the server
482
+ *
483
+ * Returns:
484
+ * 0 if the call was initiated and a connection will be attempted. Result of
485
+ * the connection will be reported through the callback function.
486
+ * <0 if there was an error. The callback function will not be invoked.
487
+ *
488
+ * Callback parameters :
489
+ * status can be either of :
490
+ * 0 : Connection was successful. Command_data is NULL.
491
+ *
492
+ * -errno : Failed to establish the connection. Command_data is NULL.
493
+ */
494
+ int smb2_connect_async(struct smb2_context *smb2, const char *server,
495
+ smb2_command_cb cb, void *cb_data);
496
+
497
+ /*
498
+ * Async call to connect to a share.
499
+ * On unix, if user is NULL then default to the current user.
500
+ *
501
+ * Returns:
502
+ * 0 if the call was initiated and a connection will be attempted. Result of
503
+ * the connection will be reported through the callback function.
504
+ * -errno if there was an error. The callback function will not be invoked.
505
+ *
506
+ * Callback parameters :
507
+ * status can be either of :
508
+ * 0 : Connection was successful. Command_data is NULL.
509
+ *
510
+ * -errno : Failed to connect to the share. Command_data is NULL.
511
+ */
512
+ int smb2_connect_share_async(struct smb2_context *smb2,
513
+ const char *server,
514
+ const char *share,
515
+ const char *user,
516
+ smb2_command_cb cb, void *cb_data);
517
+
518
+ /*
519
+ * Sync call to connect to a share.
520
+ * On unix, if user is NULL then default to the current user.
521
+ *
522
+ * Returns:
523
+ * 0 : Connected to the share successfully.
524
+ * -errno : Failure.
525
+ */
526
+ int smb2_connect_share(struct smb2_context *smb2,
527
+ const char *server,
528
+ const char *share,
529
+ const char *user);
530
+
531
+ /*
532
+ * Async call to disconnect from a share/
533
+ *
534
+ * Returns:
535
+ * 0 if the call was initiated and a connection will be attempted. Result of
536
+ * the disconnect will be reported through the callback function.
537
+ * -errno if there was an error. The callback function will not be invoked.
538
+ *
539
+ * Callback parameters :
540
+ * status can be either of :
541
+ * 0 : Connection was successful. Command_data is NULL.
542
+ *
543
+ * -errno : Failed to disconnect the share. Command_data is NULL.
544
+ */
545
+ int smb2_disconnect_share_async(struct smb2_context *smb2,
546
+ smb2_command_cb cb, void *cb_data);
547
+
548
+ /*
549
+ * Sync call to disconnect from a share/
550
+ *
551
+ * Returns:
552
+ * 0 : Disconnected from the share successfully.
553
+ * -errno : Failure.
554
+ */
555
+ int smb2_disconnect_share(struct smb2_context *smb2);
556
+
557
+ /*
558
+ * Select a tree id that was previously connected. Sets the tree_id
559
+ * in the context to be used for subsequent requests
560
+ *
561
+ * Returns:
562
+ * 0 : OK
563
+ * -errno : tree wasn't connected
564
+ */
565
+ int smb2_select_tree_id(struct smb2_context *smb2, uint32_t tree_id);
566
+
567
+ struct smb2_pdu;
568
+
569
+ /*
570
+ * Get/Set the tree id of a pdu
571
+ *
572
+ * Returns:
573
+ * 0 : OK
574
+ * -errno : tree wasn't connected | no pdu | no context
575
+ */
576
+ int smb2_get_tree_id_for_pdu(struct smb2_context *smb2, struct smb2_pdu *pdu, uint32_t *tree_id);
577
+ int smb2_set_tree_id_for_pdu(struct smb2_context *smb2, struct smb2_pdu *pdu, uint32_t tree_id);
578
+
579
+ /*
580
+ * Get session id
581
+ *
582
+ * Returns:
583
+ * 0 : OK
584
+ * -errno :
585
+ */
586
+ int smb2_get_session_id(struct smb2_context *smb2, uint64_t *session_id);
587
+
588
+ /*
589
+ * This function returns a description of the last encountered error.
590
+ */
591
+ const char *smb2_get_error(struct smb2_context *smb2);
592
+
593
+ int smb2_get_nterror(struct smb2_context *smb2);
594
+
595
+ struct smb2_url {
596
+ const char *domain;
597
+ const char *user;
598
+ const char *server;
599
+ const char *share;
600
+ const char *path;
601
+ };
602
+
603
+ /* Convert an smb2/nt error code into a string */
604
+ const char *nterror_to_str(uint32_t status);
605
+
606
+ /* Convert an smb2/nt error code into an errno value */
607
+ int nterror_to_errno(uint32_t status);
608
+
609
+ /*
610
+ * This function is used to parse an SMB2 URL into as smb2_url structure.
611
+ * SMB2 URL format:
612
+ * smb2://[<domain;][<username>@]<server>/<share>/<path>
613
+ * where <server> has the format:
614
+ * <host>[:<port>].
615
+ *
616
+ * Function will return a pointer to an iscsi smb2 structure if successful,
617
+ * or it will return NULL and set smb2_get_error() accordingly if there was
618
+ * a problem with the URL.
619
+ *
620
+ * The returned structure is freed by calling smb2_destroy_url()
621
+ */
622
+ struct smb2_url *smb2_parse_url(struct smb2_context *smb2, const char *url);
623
+ void smb2_destroy_url(struct smb2_url *url);
624
+
625
+ /*
626
+ * These functions are used when creating compound low level commands.
627
+ * The general pattern for compound chains is
628
+ * 1, pdu = smb2_cmd_*_async(smb2, ...)
629
+ *
630
+ * 2, next = smb2_cmd_*_async(smb2, ...)
631
+ * 3, smb2_add_compound_pdu(smb2, pdu, next);
632
+ *
633
+ * 4, next = smb2_cmd_*_async(smb2, ...)
634
+ * 5, smb2_add_compound_pdu(smb2, pdu, next);
635
+ * ...
636
+ * *, smb2_queue_pdu(smb2, pdu);
637
+ *
638
+ * See libsmb2.c and smb2-raw-stat-async.c for examples on how to use
639
+ * this interface.
640
+ */
641
+ void smb2_add_compound_pdu(struct smb2_context *smb2,
642
+ struct smb2_pdu *pdu, struct smb2_pdu *next_pdu);
643
+ void smb2_free_pdu(struct smb2_context *smb2, struct smb2_pdu *pdu);
644
+ void smb2_queue_pdu(struct smb2_context *smb2, struct smb2_pdu *pdu);
645
+
646
+ /*
647
+ * These are used to access/modify pdus from application level
648
+ * useful for proxies, etc.
649
+ */
650
+ struct smb2_pdu *smb2_get_compound_pdu(struct smb2_context *smb2,
651
+ struct smb2_pdu *pdu);
652
+ void smb2_set_pdu_status(struct smb2_context *smb2, struct smb2_pdu *pdu, int status);
653
+ void smb2_set_pdu_message_id(struct smb2_context *smb2, struct smb2_pdu *pdu, uint64_t message_id);
654
+ uint64_t smb2_get_pdu_message_id(struct smb2_context *smb2, struct smb2_pdu *pdu);
655
+ uint64_t smb2_get_last_request_message_id(struct smb2_context *smb2);
656
+ uint64_t smb2_get_last_reply_message_id(struct smb2_context *smb2);
657
+ int smb2_pdu_is_compound(struct smb2_context *smb2);
658
+
659
+ /*
660
+ * OPENDIR
661
+ */
662
+ struct smb2dir;
663
+ /*
664
+ * Async opendir()
665
+ *
666
+ * Returns
667
+ * 0 : The operation was initiated. Result of the operation will be reported
668
+ * through the callback function.
669
+ * <0 : There was an error. The callback function will not be invoked.
670
+ *
671
+ * When the callback is invoked, status indicates the result:
672
+ * 0 : Success.
673
+ * Command_data is struct smb2dir.
674
+ * This structure is freed using smb2_closedir().
675
+ * -errno : An error occurred.
676
+ * Command_data is NULL.
677
+ */
678
+ int smb2_opendir_async(struct smb2_context *smb2, const char *path,
679
+ smb2_command_cb cb, void *cb_data);
680
+
681
+ /*
682
+ * Sync opendir()
683
+ *
684
+ * Returns NULL on failure.
685
+ */
686
+ struct smb2dir *smb2_opendir(struct smb2_context *smb2, const char *path);
687
+
688
+ /*
689
+ * closedir()
690
+ */
691
+ /*
692
+ * smb2_closedir() never blocks, thus no async version is needed.
693
+ */
694
+ void smb2_closedir(struct smb2_context *smb2, struct smb2dir *smb2dir);
695
+
696
+ /*
697
+ * readdir()
698
+ */
699
+ /*
700
+ * smb2_readdir() never blocks, thus no async version is needed.
701
+ */
702
+ struct smb2dirent *smb2_readdir(struct smb2_context *smb2,
703
+ struct smb2dir *smb2dir);
704
+
705
+ /*
706
+ * rewinddir()
707
+ */
708
+ /*
709
+ * smb2_rewinddir() never blocks, thus no async version is needed.
710
+ */
711
+ void smb2_rewinddir(struct smb2_context *smb2, struct smb2dir *smb2dir);
712
+
713
+ /*
714
+ * telldir()
715
+ */
716
+ /*
717
+ * smb2_telldir() never blocks, thus no async version is needed.
718
+ */
719
+ long smb2_telldir(struct smb2_context *smb2, struct smb2dir *smb2dir);
720
+
721
+ /*
722
+ * seekdir()
723
+ */
724
+ /*
725
+ * smb2_seekdir() never blocks, thus no async version is needed.
726
+ */
727
+ void smb2_seekdir(struct smb2_context *smb2, struct smb2dir *smb2dir,
728
+ long loc);
729
+
730
+ /*
731
+ * OPEN
732
+ */
733
+ struct smb2fh;
734
+ /*
735
+ * Async open()
736
+ *
737
+ * Opens or creates a file.
738
+ * Supported flags are:
739
+ * O_RDONLY
740
+ * O_WRONLY
741
+ * O_RDWR
742
+ * O_SYNC
743
+ * O_CREAT
744
+ * O_EXCL
745
+ *
746
+ * Returns
747
+ * 0 : The operation was initiated. Result of the operation will be
748
+ * reported through the callback function.
749
+ * -errno : There was an error. The callback function will not be invoked.
750
+ *
751
+ * When the callback is invoked, status indicates the result:
752
+ * 0 : Success.
753
+ * Command_data is struct smb2fh.
754
+ * This structure is freed using smb2_close().
755
+ * -errno : An error occurred.
756
+ * Command_data is NULL.
757
+ */
758
+ int smb2_open_async_with_oplock_or_lease(struct smb2_context *smb2, const char *path, int flags,
759
+ uint8_t oplock_level, uint32_t lease_state, smb2_lease_key lease_key,
760
+ smb2_command_cb cb, void *cb_data);
761
+
762
+ int smb2_open_async(struct smb2_context *smb2, const char *path, int flags,
763
+ smb2_command_cb cb, void *cb_data);
764
+
765
+ /*
766
+ * Sync open()
767
+ *
768
+ * Returns NULL on failure.
769
+ */
770
+ struct smb2fh *smb2_open(struct smb2_context *smb2, const char *path, int flags);
771
+
772
+ /*
773
+ * CLOSE
774
+ */
775
+ /*
776
+ * Async close()
777
+ *
778
+ * Returns
779
+ * 0 : The operation was initiated. Result of the operation will be
780
+ * reported through the callback function.
781
+ * -errno : There was an error. The callback function will not be invoked.
782
+ *
783
+ * When the callback is invoked, status indicates the result:
784
+ * 0 : Success.
785
+ * -errno : An error occurred.
786
+ *
787
+ * Command_data is always NULL.
788
+ */
789
+ int smb2_close_async(struct smb2_context *smb2, struct smb2fh *fh,
790
+ smb2_command_cb cb, void *cb_data);
791
+
792
+ /*
793
+ * Sync close()
794
+ */
795
+ int smb2_close(struct smb2_context *smb2, struct smb2fh *fh);
796
+
797
+ /*
798
+ * FSYNC
799
+ */
800
+ /*
801
+ * Async fsync()
802
+ *
803
+ * Returns
804
+ * 0 : The operation was initiated. Result of the operation will be
805
+ * reported through the callback function.
806
+ * -errno : There was an error. The callback function will not be invoked.
807
+ *
808
+ * When the callback is invoked, status indicates the result:
809
+ * 0 : Success.
810
+ * -errno : An error occurred.
811
+ *
812
+ * Command_data is always NULL.
813
+ */
814
+ int smb2_fsync_async(struct smb2_context *smb2, struct smb2fh *fh,
815
+ smb2_command_cb cb, void *cb_data);
816
+
817
+ /*
818
+ * Sync fsync()
819
+ */
820
+ int smb2_fsync(struct smb2_context *smb2, struct smb2fh *fh);
821
+
822
+ /*
823
+ * GetMaxReadWriteSize
824
+ * SMB2 servers have a maximum size for read/write data that they support.
825
+ */
826
+ uint32_t smb2_get_max_read_size(struct smb2_context *smb2);
827
+ uint32_t smb2_get_max_write_size(struct smb2_context *smb2);
828
+
829
+ struct smb2_read_cb_data {
830
+ struct smb2fh *fh;
831
+ uint8_t *buf;
832
+ uint32_t count;
833
+ uint64_t offset;
834
+ };
835
+
836
+ struct smb2_write_cb_data {
837
+ struct smb2fh *fh;
838
+ const uint8_t *buf;
839
+ uint32_t count;
840
+ uint64_t offset;
841
+ };
842
+
843
+ /*
844
+ * PREAD
845
+ */
846
+ /*
847
+ * Async pread()
848
+ * Use smb2_get_max_read_size to discover the maximum data size that the
849
+ * server supports.
850
+ *
851
+ * Returns
852
+ * 0 : The operation was initiated. Result of the operation will be
853
+ * reported through the callback function.
854
+ * -errno : There was an error. The callback function will not be invoked.
855
+ *
856
+ * When the callback is invoked, status indicates the result:
857
+ * >=0 : Number of bytes read.
858
+ * -errno : An error occurred.
859
+ *
860
+ * Command_data is struct smb2_read_cb_data, which holds the arguments
861
+ * that were given to smb2_pread_async.
862
+ * This structure is automatically freed.
863
+ */
864
+ int smb2_pread_async(struct smb2_context *smb2, struct smb2fh *fh,
865
+ uint8_t *buf, uint32_t count, uint64_t offset,
866
+ smb2_command_cb cb, void *cb_data);
867
+
868
+ /*
869
+ * Sync pread()
870
+ * Use smb2_get_max_read_size to discover the maximum data size that the
871
+ * server supports.
872
+ */
873
+ int smb2_pread(struct smb2_context *smb2, struct smb2fh *fh,
874
+ uint8_t *buf, uint32_t count, uint64_t offset);
875
+
876
+ /*
877
+ * PWRITE
878
+ */
879
+ /*
880
+ * Async pwrite()
881
+ * Use smb2_get_max_write_size to discover the maximum data size that the
882
+ * server supports.
883
+ *
884
+ * Returns
885
+ * 0 : The operation was initiated. Result of the operation will be
886
+ * reported through the callback function.
887
+ * -errno : There was an error. The callback function will not be invoked.
888
+ *
889
+ * When the callback is invoked, status indicates the result:
890
+ * >=0 : Number of bytes written.
891
+ * -errno : An error occurred.
892
+ *
893
+ * Command_data is struct smb2_write_cb_data, which holds the arguments
894
+ * that were given to smb2_pwrite_async.
895
+ * This structure is automatically freed.
896
+ */
897
+ int smb2_pwrite_async(struct smb2_context *smb2, struct smb2fh *fh,
898
+ const uint8_t *buf, uint32_t count, uint64_t offset,
899
+ smb2_command_cb cb, void *cb_data);
900
+
901
+ /*
902
+ * Sync pwrite()
903
+ * Use smb2_get_max_write_size to discover the maximum data size that the
904
+ * server supports.
905
+ */
906
+ int smb2_pwrite(struct smb2_context *smb2, struct smb2fh *fh,
907
+ const uint8_t *buf, uint32_t count, uint64_t offset);
908
+
909
+ /*
910
+ * READ
911
+ */
912
+ /*
913
+ * Async read()
914
+ *
915
+ * Returns
916
+ * 0 : The operation was initiated. Result of the operation will be
917
+ * reported through the callback function.
918
+ * -errno : There was an error. The callback function will not be invoked.
919
+ *
920
+ * When the callback is invoked, status indicates the result:
921
+ * >=0 : Number of bytes read.
922
+ * -errno : An error occurred.
923
+ *
924
+ * Command_data is struct smb2_read_cb_data, which holds the arguments
925
+ * that were given to smb2_read_async. offset denotes the offset in the file
926
+ * at which the read took place.
927
+ * This structure is automatically freed.
928
+ */
929
+ int smb2_read_async(struct smb2_context *smb2, struct smb2fh *fh,
930
+ uint8_t *buf, uint32_t count,
931
+ smb2_command_cb cb, void *cb_data);
932
+
933
+ /*
934
+ * Sync read()
935
+ */
936
+ int smb2_read(struct smb2_context *smb2, struct smb2fh *fh,
937
+ uint8_t *buf, uint32_t count);
938
+
939
+ /*
940
+ * WRITE
941
+ */
942
+ /*
943
+ * Async write()
944
+ *
945
+ * Returns
946
+ * 0 : The operation was initiated. Result of the operation will be
947
+ * reported through the callback function.
948
+ * -errno : There was an error. The callback function will not be invoked.
949
+ *
950
+ * When the callback is invoked, status indicates the result:
951
+ * >=0 : Number of bytes written.
952
+ * -errno : An error occurred.
953
+ *
954
+ * Command_data is struct smb2_write_cb_data, which holds the arguments
955
+ * that were given to smb2_write_async. offset denotes the offset in the file
956
+ * at which the write took place.
957
+ * This structure is automatically freed.
958
+ */
959
+ int smb2_write_async(struct smb2_context *smb2, struct smb2fh *fh,
960
+ const uint8_t *buf, uint32_t count,
961
+ smb2_command_cb cb, void *cb_data);
962
+
963
+ /*
964
+ * Sync write()
965
+ */
966
+ int smb2_write(struct smb2_context *smb2, struct smb2fh *fh,
967
+ const uint8_t *buf, uint32_t count);
968
+
969
+ /*
970
+ * Sync lseek()
971
+ */
972
+ /*
973
+ * smb2_seek() SEEK_SET and SEEK_CUR are fully supported.
974
+ * SEEK_END only returns the end-of-file from the original open.
975
+ * (it will not call fstat to discover the current file size and will not block)
976
+ */
977
+ int64_t smb2_lseek(struct smb2_context *smb2, struct smb2fh *fh,
978
+ int64_t offset, int whence, uint64_t *current_offset);
979
+
980
+ /*
981
+ * UNLINK
982
+ */
983
+ /*
984
+ * Async unlink()
985
+ *
986
+ * Returns
987
+ * 0 : The operation was initiated. Result of the operation will be
988
+ * reported through the callback function.
989
+ * -errno : There was an error. The callback function will not be invoked.
990
+ *
991
+ * When the callback is invoked, status indicates the result:
992
+ * 0 : Success.
993
+ * -errno : An error occurred.
994
+ *
995
+ * Command_data is always NULL.
996
+ */
997
+ int smb2_unlink_async(struct smb2_context *smb2, const char *path,
998
+ smb2_command_cb cb, void *cb_data);
999
+
1000
+ /*
1001
+ * Sync unlink()
1002
+ */
1003
+ int smb2_unlink(struct smb2_context *smb2, const char *path);
1004
+
1005
+ /*
1006
+ * RMDIR
1007
+ */
1008
+ /*
1009
+ * Async rmdir()
1010
+ *
1011
+ * Returns
1012
+ * 0 : The operation was initiated. Result of the operation will be
1013
+ * reported through the callback function.
1014
+ * -errno : There was an error. The callback function will not be invoked.
1015
+ *
1016
+ * When the callback is invoked, status indicates the result:
1017
+ * 0 : Success.
1018
+ * -errno : An error occurred.
1019
+ *
1020
+ * Command_data is always NULL.
1021
+ */
1022
+ int smb2_rmdir_async(struct smb2_context *smb2, const char *path,
1023
+ smb2_command_cb cb, void *cb_data);
1024
+
1025
+ /*
1026
+ * Sync rmdir()
1027
+ */
1028
+ int smb2_rmdir(struct smb2_context *smb2, const char *path);
1029
+
1030
+ /*
1031
+ * MKDIR
1032
+ */
1033
+ /*
1034
+ * Async mkdir()
1035
+ *
1036
+ * Returns
1037
+ * 0 : The operation was initiated. Result of the operation will be
1038
+ * reported through the callback function.
1039
+ * -errno : There was an error. The callback function will not be invoked.
1040
+ *
1041
+ * When the callback is invoked, status indicates the result:
1042
+ * 0 : Success.
1043
+ * -errno : An error occurred.
1044
+ *
1045
+ * Command_data is always NULL.
1046
+ */
1047
+ int smb2_mkdir_async(struct smb2_context *smb2, const char *path,
1048
+ smb2_command_cb cb, void *cb_data);
1049
+
1050
+ /*
1051
+ * Sync mkdir()
1052
+ */
1053
+ int smb2_mkdir(struct smb2_context *smb2, const char *path);
1054
+
1055
+ /*
1056
+ * STATVFS
1057
+ */
1058
+ /*
1059
+ * Async statvfs()
1060
+ *
1061
+ * Returns
1062
+ * 0 : The operation was initiated. Result of the operation will be
1063
+ * reported through the callback function.
1064
+ * -errno : There was an error. The callback function will not be invoked.
1065
+ *
1066
+ * When the callback is invoked, status indicates the result:
1067
+ * 0 : Success. Command_data is struct smb2_statvfs
1068
+ * -errno : An error occurred.
1069
+ */
1070
+ int smb2_statvfs_async(struct smb2_context *smb2, const char *path,
1071
+ struct smb2_statvfs *statvfs,
1072
+ smb2_command_cb cb, void *cb_data);
1073
+ /*
1074
+ * Sync statvfs()
1075
+ */
1076
+ int smb2_statvfs(struct smb2_context *smb2, const char *path,
1077
+ struct smb2_statvfs *statvfs);
1078
+
1079
+ /*
1080
+ * FSTAT
1081
+ */
1082
+ /*
1083
+ * Async fstat()
1084
+ *
1085
+ * Returns
1086
+ * 0 : The operation was initiated. Result of the operation will be
1087
+ * reported through the callback function.
1088
+ * -errno : There was an error. The callback function will not be invoked.
1089
+ *
1090
+ * When the callback is invoked, status indicates the result:
1091
+ * 0 : Success. Command_data is struct smb2_stat_64
1092
+ * -errno : An error occurred.
1093
+ */
1094
+ int smb2_fstat_async(struct smb2_context *smb2, struct smb2fh *fh,
1095
+ struct smb2_stat_64 *st,
1096
+ smb2_command_cb cb, void *cb_data);
1097
+ /*
1098
+ * Sync fstat()
1099
+ */
1100
+ int smb2_fstat(struct smb2_context *smb2, struct smb2fh *fh,
1101
+ struct smb2_stat_64 *st);
1102
+
1103
+ /*
1104
+ * Async stat()
1105
+ *
1106
+ * Returns
1107
+ * 0 : The operation was initiated. Result of the operation will be
1108
+ * reported through the callback function.
1109
+ * -errno : There was an error. The callback function will not be invoked.
1110
+ *
1111
+ * When the callback is invoked, status indicates the result:
1112
+ * 0 : Success. Command_data is struct smb2_stat_64
1113
+ * -errno : An error occurred.
1114
+ */
1115
+ int smb2_stat_async(struct smb2_context *smb2, const char *path,
1116
+ struct smb2_stat_64 *st,
1117
+ smb2_command_cb cb, void *cb_data);
1118
+ /*
1119
+ * Sync stat()
1120
+ */
1121
+ int smb2_stat(struct smb2_context *smb2, const char *path,
1122
+ struct smb2_stat_64 *st);
1123
+
1124
+ /*
1125
+ * Async rename()
1126
+ *
1127
+ * Returns
1128
+ * 0 : The operation was initiated. Result of the operation will be
1129
+ * reported through the callback function.
1130
+ * -errno : There was an error. The callback function will not be invoked.
1131
+ *
1132
+ * When the callback is invoked, status indicates the result:
1133
+ * 0 : Success.
1134
+ * -errno : An error occurred.
1135
+ */
1136
+ int smb2_rename_async(struct smb2_context *smb2, const char *oldpath,
1137
+ const char *newpath, smb2_command_cb cb, void *cb_data);
1138
+
1139
+ /*
1140
+ * Sync rename()
1141
+ */
1142
+ int smb2_rename(struct smb2_context *smb2, const char *oldpath,
1143
+ const char *newpath);
1144
+
1145
+ /*
1146
+ * Async truncate()
1147
+ *
1148
+ * Returns
1149
+ * 0 : The operation was initiated. Result of the operation will be
1150
+ * reported through the callback function.
1151
+ * -errno : There was an error. The callback function will not be invoked.
1152
+ *
1153
+ * When the callback is invoked, status indicates the result:
1154
+ * 0 : Success.
1155
+ * -errno : An error occurred.
1156
+ */
1157
+ int smb2_truncate_async(struct smb2_context *smb2, const char *path,
1158
+ uint64_t length, smb2_command_cb cb, void *cb_data);
1159
+ /*
1160
+ * Sync truncate()
1161
+ * Function returns
1162
+ * 0 : Success
1163
+ * -errno : An error occurred.
1164
+ */
1165
+ int smb2_truncate(struct smb2_context *smb2, const char *path,
1166
+ uint64_t length);
1167
+
1168
+ /*
1169
+ * Async ftruncate()
1170
+ *
1171
+ * Returns
1172
+ * 0 : The operation was initiated. Result of the operation will be
1173
+ * reported through the callback function.
1174
+ * -errno : There was an error. The callback function will not be invoked.
1175
+ *
1176
+ * When the callback is invoked, status indicates the result:
1177
+ * 0 : Success.
1178
+ * -errno : An error occurred.
1179
+ */
1180
+ int smb2_ftruncate_async(struct smb2_context *smb2, struct smb2fh *fh,
1181
+ uint64_t length, smb2_command_cb cb, void *cb_data);
1182
+ /*
1183
+ * Sync ftruncate()
1184
+ * Function returns
1185
+ * 0 : Success
1186
+ * -errno : An error occurred.
1187
+ */
1188
+ int smb2_ftruncate(struct smb2_context *smb2, struct smb2fh *fh,
1189
+ uint64_t length);
1190
+
1191
+
1192
+ /*
1193
+ * READLINK
1194
+ */
1195
+ /*
1196
+ * Async readlink()
1197
+ *
1198
+ * Returns
1199
+ * 0 : The operation was initiated. The link content will be
1200
+ * reported through the callback function.
1201
+ * -errno : There was an error. The callback function will not be invoked.
1202
+ *
1203
+ * When the callback is invoked, status indicates the result:
1204
+ * 0 : Success. Command_data is the link content.
1205
+ * -errno : An error occurred.
1206
+ */
1207
+ int smb2_readlink_async(struct smb2_context *smb2, const char *path,
1208
+ smb2_command_cb cb, void *cb_data);
1209
+
1210
+ /*
1211
+ * Sync readlink()
1212
+ */
1213
+ int smb2_readlink(struct smb2_context *smb2, const char *path, char *buf, uint32_t bufsiz);
1214
+
1215
+ /*
1216
+ * Async echo()
1217
+ *
1218
+ * Returns
1219
+ * 0 : The operation was initiated. Result of the operation will be
1220
+ * reported through the callback function.
1221
+ * -errno : There was an error. The callback function will not be invoked.
1222
+ *
1223
+ * When the callback is invoked, status indicates the result:
1224
+ * 0 : Success.
1225
+ * -errno : An error occurred.
1226
+ */
1227
+ int smb2_echo_async(struct smb2_context *smb2,
1228
+ smb2_command_cb cb, void *cb_data);
1229
+
1230
+ /*
1231
+ * Sync echo()
1232
+ *
1233
+ * Returns:
1234
+ * 0 : successfully send the message and received a reply.
1235
+ * -errno : Failure.
1236
+ */
1237
+ int smb2_echo(struct smb2_context *smb2);
1238
+
1239
+ void
1240
+ free_smb2_file_notify_change_information(struct smb2_context *smb2, struct smb2_file_notify_change_information *fnc);
1241
+
1242
+ int smb2_notify_change_async(struct smb2_context *smb2, const char *path, uint16_t flags, uint32_t filter, int loop,
1243
+ smb2_command_cb cb, void *cb_data);
1244
+
1245
+ int smb2_notify_change_filehandle_async(struct smb2_context *smb2, struct smb2fh *smb2_dir_fh, uint16_t flags, uint32_t filter, int loop,
1246
+ smb2_command_cb cb, void *cb_data);
1247
+
1248
+ /*
1249
+ * Sync notify_change()
1250
+ *
1251
+ */
1252
+ struct smb2_file_notify_change_information *smb2_notify_change(struct smb2_context *smb2, const char *path, uint16_t flags, uint32_t filter);
1253
+
1254
+ /* Utilities that help by being public
1255
+ */
1256
+
1257
+ /* SMB's UTF-16 is always in Little Endian */
1258
+ struct smb2_utf16 {
1259
+ int len;
1260
+ uint16_t val[1];
1261
+ };
1262
+
1263
+ /* Returns a string converted to UTF-16 format. Use free() to release
1264
+ * the utf16 string.
1265
+ */
1266
+ struct smb2_utf16 *smb2_utf8_to_utf16(const char *utf8);
1267
+
1268
+ /* Returns a string converted to UTF8 format. Use free() to release
1269
+ * the utf8 string.
1270
+ */
1271
+ const char *smb2_utf16_to_utf8(const uint16_t *str, size_t len);
1272
+
1273
+ /************* Server-side API **********************************************/
1274
+ struct smb2_server;
1275
+
1276
+ /* pdu handlers in general take the request from the client, and return
1277
+ * < 0 on error, and the library should create an error reply
1278
+ * == 0 on OK, and the library should use the reply struct (if needed) to create a reply
1279
+ * > 0 if the handler created and queued a reply itself
1280
+ */
1281
+ struct smb2_server_request_handlers {
1282
+ int (*destruction_event)(struct smb2_server *srvr, struct smb2_context *smb2);
1283
+ int (*authorize_user)(struct smb2_server *srvr, struct smb2_context *smb2,
1284
+ const char *user,
1285
+ const char *domain,
1286
+ const char *workstation);
1287
+ int (*session_established)(struct smb2_server *srvr, struct smb2_context *smb2);
1288
+ int (*logoff_cmd)(struct smb2_server *srvr, struct smb2_context *smb2);
1289
+ int (*tree_connect_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1290
+ struct smb2_tree_connect_request *req,
1291
+ struct smb2_tree_connect_reply *rep);
1292
+ int (*tree_disconnect_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1293
+ const uint32_t tree_id);
1294
+ int (*create_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1295
+ struct smb2_create_request *req,
1296
+ struct smb2_create_reply *rep);
1297
+ int (*close_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1298
+ struct smb2_close_request *req,
1299
+ struct smb2_close_reply *rep);
1300
+ int (*flush_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1301
+ struct smb2_flush_request *req);
1302
+ int (*read_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1303
+ struct smb2_read_request *req,
1304
+ struct smb2_read_reply *rep);
1305
+ int (*write_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1306
+ struct smb2_write_request *req,
1307
+ struct smb2_write_reply *rep);
1308
+ int (*oplock_break_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1309
+ struct smb2_oplock_break_acknowledgement *req);
1310
+ int (*lease_break_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1311
+ struct smb2_lease_break_acknowledgement *req);
1312
+ int (*lock_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1313
+ struct smb2_lock_request *req);
1314
+ int (*ioctl_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1315
+ struct smb2_ioctl_request *req,
1316
+ struct smb2_ioctl_reply *rep);
1317
+ int (*cancel_cmd)(struct smb2_server *srvr, struct smb2_context *smb2);
1318
+ int (*echo_cmd)(struct smb2_server *srvr, struct smb2_context *smb2);
1319
+ int (*query_directory_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1320
+ struct smb2_query_directory_request *req,
1321
+ struct smb2_query_directory_reply *rep);
1322
+ int (*change_notify_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1323
+ struct smb2_change_notify_request *req,
1324
+ struct smb2_change_notify_reply *rep);
1325
+ int (*query_info_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1326
+ struct smb2_query_info_request *req,
1327
+ struct smb2_query_info_reply *rep);
1328
+ int (*set_info_cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1329
+ struct smb2_set_info_request *req);
1330
+ /*
1331
+ int (*oplock_break cmd)(struct smb2_server *srvr, struct smb2_context *smb2,
1332
+ struct smb2_oplock_break_request *req);
1333
+ */
1334
+ };
1335
+
1336
+ struct smb2_server {
1337
+ uint8_t guid[16];
1338
+ char hostname[128];
1339
+ char domain[128];
1340
+ int fd;
1341
+ uint16_t port;
1342
+ uint64_t session_counter;
1343
+ struct smb2_server_request_handlers *handlers;
1344
+ uint32_t max_transact_size;
1345
+ uint32_t max_read_size;
1346
+ uint32_t max_write_size;
1347
+ int signing_enabled;
1348
+ int allow_anonymous;
1349
+ /* this can be set non-0 to delegate client authentication to
1350
+ * another client and allow any authentication to this server */
1351
+ int proxy_authentication;
1352
+ /* saved from negotiate to be used in validate negotiate info */
1353
+ uint32_t capabilities;
1354
+ uint32_t security_mode;
1355
+ /* for kerberos, credential context */
1356
+ char keytab_path[256];
1357
+ char error[128];
1358
+ void *auth_data;
1359
+ };
1360
+
1361
+ int smb2_bind_and_listen(const uint16_t port, const int max_connections, int *out_fd);
1362
+ int smb2_accept_connection_async(const int fd, const int to_msecs, smb2_accepted_cb cb, void *cb_data);
1363
+ int smb2_serve_port_async(const int fd, const int to_msecs, struct smb2_context **out_smb2);
1364
+
1365
+ /*
1366
+ * Sync serve port()
1367
+ *
1368
+ * Returns
1369
+ * 0 : The server is complete by exiting its loop normally (shouldnt happen)
1370
+ * -errno : There was an error causing server loop to exit
1371
+ */
1372
+ int smb2_serve_port(struct smb2_server *server, const int max_connections, smb2_client_connection cb, void *cb_data);
1373
+
1374
+ /*
1375
+ * Some symbols have moved over to a different header file to allow better
1376
+ * separation between dcerpc and smb2, so we need to include this header
1377
+ * here to retain compatibility for apps that depend on those symbols.
1378
+ */
1379
+ #include <smb2/libsmb2-dcerpc-srvsvc.h>
1380
+
1381
+ #ifdef __cplusplus
1382
+ }
1383
+ #endif
1384
+ #endif /* !_LIBSMB2_H_ */