make it possible to use alternative username for the share-enum example
[libsmb2.git] / include / smb2 / libsmb2.h
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 #ifndef UINT64_MAX
23 #include <stdint.h>
24 #endif
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 struct smb2_iovec {
31         uint8_t *buf;
32         size_t len;
33         void (*free)(void *);
34 };
35         
36 struct smb2_context;
37
38 /*
39  * Generic callback for completion of smb2_*_async().
40  * command_data depends on status.
41  */
42 typedef void (*smb2_command_cb)(struct smb2_context *smb2, int status,
43                                 void *command_data, void *cb_data);
44
45 /* Stat structure */
46 #define SMB2_TYPE_FILE      0x00000000
47 #define SMB2_TYPE_DIRECTORY 0x00000001
48 #define SMB2_TYPE_LINK      0x00000002
49 struct smb2_stat_64 {
50         uint32_t smb2_type;
51         uint32_t smb2_nlink;
52         uint64_t smb2_ino;
53         uint64_t smb2_size;
54         uint64_t smb2_atime;
55         uint64_t smb2_atime_nsec;
56         uint64_t smb2_mtime;
57         uint64_t smb2_mtime_nsec;
58         uint64_t smb2_ctime;
59         uint64_t smb2_ctime_nsec;
60     uint64_t smb2_btime;
61     uint64_t smb2_btime_nsec;
62 };
63
64 struct smb2_statvfs {
65         uint32_t        f_bsize;
66         uint32_t        f_frsize;
67         uint64_t        f_blocks;
68         uint64_t        f_bfree;
69         uint64_t        f_bavail;
70         uint32_t        f_files;
71         uint32_t        f_ffree;
72         uint32_t        f_favail;
73         uint32_t        f_fsid;
74         uint32_t        f_flag;
75         uint32_t        f_namemax;
76 };
77
78 struct smb2dirent {
79         const char *name;
80         struct smb2_stat_64 st;
81 };
82
83 #ifdef _MSC_VER
84 #include <winsock2.h>
85 typedef SOCKET t_socket;
86 #else
87 typedef int t_socket;
88 #endif
89
90 /*
91  * Create an SMB2 context.
92  * Function returns
93  *  NULL  : Failed to create a context.
94  *  *smb2 : A pointer to an smb2 context.
95  */
96 struct smb2_context *smb2_init_context(void);
97
98 /*
99  * Destroy an smb2 context.
100  *
101  * Any open "struct smb2fh" will automatically be freed. You can not reference
102  * any "struct smb2fh" after the context is destroyed.
103  * Any open "struct smb2dir" will automatically be freed. You can not reference
104  * any "struct smb2dir" after the context is destroyed.
105  * Any pending async commands will be aborted with -ECONNRESET.
106  */
107 void smb2_destroy_context(struct smb2_context *smb2);
108
109 /*
110  * The following three functions are used to integrate libsmb2 in an event
111  * system.
112  */
113 /*
114  * Returns the file descriptor that libsmb2 uses.
115  */
116 t_socket smb2_get_fd(struct smb2_context *smb2);
117 /*
118  * Returns which events that we need to poll for for the smb2 file descriptor.
119  */
120 int smb2_which_events(struct smb2_context *smb2);
121 /*
122  * Called to process the events when events become available for the smb2
123  * file descriptor.
124  *
125  * Returns:
126  *  0 : Success
127  * <0 : Unrecoverable failure. At this point the context can no longer be
128  *      used and must be freed by calling smb2_destroy_context().
129  *
130  */
131 int smb2_service(struct smb2_context *smb2, int revents);
132
133 /*
134  * Set the security mode for the connection.
135  * This is a combination of the flags SMB2_NEGOTIATE_SIGNING_ENABLED
136  * and  SMB2_NEGOTIATE_SIGNING_REQUIRED
137  * Default is 0.
138  */
139 void smb2_set_security_mode(struct smb2_context *smb2, uint16_t security_mode);
140
141 /*
142  * Set whether smb3 encryption should be used or not.
143  * 0  : disable encryption. This is the default.
144  * !0 : enable encryption.
145  */
146 void smb2_set_seal(struct smb2_context *smb2, int val);
147
148 /*
149  * Set authentication method.
150  * SMB2_SEC_UNDEFINED (use KRB if available or NTLM if not)
151  * SMB2_SEC_NTLMSSP
152  * SMB2_SEC_KRB5
153  */
154 void smb2_set_authentication(struct smb2_context *smb2, int val);
155
156 /*
157  * Set the username that we will try to authenticate as.
158  * Default is to try to authenticate as the current user.
159  */
160 void smb2_set_user(struct smb2_context *smb2, const char *user);
161 /*
162  * Set the password that we will try to authenticate as.
163  * This function is only needed when libsmb2 is built --without-libkrb5
164  */
165 void smb2_set_password(struct smb2_context *smb2, const char *password);
166 /*
167  * Set the domain when authenticating.
168  * This function is only needed when libsmb2 is built --without-libkrb5
169  */
170 void smb2_set_domain(struct smb2_context *smb2, const char *domain);
171 /*
172  * Set the workstation when authenticating.
173  * This function is only needed when libsmb2 is built --without-libkrb5
174  */
175 void smb2_set_workstation(struct smb2_context *smb2, const char *workstation);
176
177
178 /*
179  * Returns the client_guid for this context.
180  */
181 const char *smb2_get_client_guid(struct smb2_context *smb2);
182
183 /*
184  * Asynchronous call to connect a TCP connection to the server
185  *
186  * Returns:
187  *  0 if the call was initiated and a connection will be attempted. Result of
188  * the connection will be reported through the callback function.
189  * <0 if there was an error. The callback function will not be invoked.
190  *
191  * Callback parameters :
192  * status can be either of :
193  *    0     : Connection was successful. Command_data is NULL.
194  *
195  *   <0     : Failed to establish the connection. Command_data is NULL.
196  */
197 int smb2_connect_async(struct smb2_context *smb2, const char *server,
198                        smb2_command_cb cb, void *cb_data);
199
200 /*
201  * Async call to connect to a share.
202  * On unix, if user is NULL then default to the current user.
203  *
204  * Returns:
205  *  0 if the call was initiated and a connection will be attempted. Result of
206  * the connection will be reported through the callback function.
207  * -errno if there was an error. The callback function will not be invoked.
208  *
209  * Callback parameters :
210  * status can be either of :
211  *    0     : Connection was successful. Command_data is NULL.
212  *
213  *   -errno : Failed to connect to the share. Command_data is NULL.
214  */
215 int smb2_connect_share_async(struct smb2_context *smb2,
216                              const char *server,
217                              const char *share,
218                              const char *user,
219                              smb2_command_cb cb, void *cb_data);
220
221 /*
222  * Sync call to connect to a share.
223  * On unix, if user is NULL then default to the current user.
224  *
225  * Returns:
226  * 0      : Connected to the share successfully.
227  * -errno : Failure.
228  */
229 int smb2_connect_share(struct smb2_context *smb2,
230                        const char *server,
231                        const char *share,
232                        const char *user);
233
234 /*
235  * Async call to disconnect from a share/
236  *
237  * Returns:
238  *  0 if the call was initiated and a connection will be attempted. Result of
239  * the disconnect will be reported through the callback function.
240  * -errno if there was an error. The callback function will not be invoked.
241  *
242  * Callback parameters :
243  * status can be either of :
244  *    0     : Connection was successful. Command_data is NULL.
245  *
246  *   -errno : Failed to disconnect the share. Command_data is NULL.
247  */
248 int smb2_disconnect_share_async(struct smb2_context *smb2,
249                                 smb2_command_cb cb, void *cb_data);
250
251 /*
252  * Sync call to disconnect from a share/
253  *
254  * Returns:
255  * 0      : Disconnected from the share successfully.
256  * -errno : Failure.
257  */
258 int smb2_disconnect_share(struct smb2_context *smb2);
259
260 /*
261  * This function returns a description of the last encountered error.
262  */
263 const char *smb2_get_error(struct smb2_context *smb2);
264
265 struct smb2_url {
266         const char *domain;
267         const char *user;
268         const char *server;
269         const char *share;
270         const char *path;
271 };
272
273 /* Convert an smb2/nt error code into a string */
274 const char *nterror_to_str(uint32_t status);
275
276 /* Convert an smb2/nt error code into an errno value */
277 int nterror_to_errno(uint32_t status);
278
279 /*
280  * This function is used to parse an SMB2 URL into as smb2_url structure.
281  * SMB2 URL format:
282  *   smb2://[<domain;][<username>@]<server>/<share>/<path>
283  * where <server> has the format:
284  *   <host>[:<port>].
285  *
286  * Function will return a pointer to an iscsi smb2 structure if successful,
287  * or it will return NULL and set smb2_get_error() accordingly if there was
288  * a problem with the URL.
289  *
290  * The returned structure is freed by calling smb2_destroy_url()
291  */
292 struct smb2_url *smb2_parse_url(struct smb2_context *smb2, const char *url);
293 void smb2_destroy_url(struct smb2_url *url);
294
295 struct smb2_pdu;
296 /*
297  * The functions are used when creating compound low level commands.
298  * The general pattern for compound chains is
299  * 1, pdu = smb2_cmd_*_async(smb2, ...)
300  *
301  * 2, next = smb2_cmd_*_async(smb2, ...)
302  * 3, smb2_add_compound_pdu(smb2, pdu, next);
303  *
304  * 4, next = smb2_cmd_*_async(smb2, ...)
305  * 5, smb2_add_compound_pdu(smb2, pdu, next);
306  * ...
307  * *, smb2_queue_pdu(smb2, pdu);
308  *
309  * See libsmb2.c and smb2-raw-stat-async.c for examples on how to use
310  * this interface.
311  */
312 void smb2_add_compound_pdu(struct smb2_context *smb2,
313                            struct smb2_pdu *pdu, struct smb2_pdu *next_pdu);
314 void smb2_free_pdu(struct smb2_context *smb2, struct smb2_pdu *pdu);
315 void smb2_queue_pdu(struct smb2_context *smb2, struct smb2_pdu *pdu);
316
317 /*
318  * OPENDIR
319  */
320 struct smb2dir;
321 /*
322  * Async opendir()
323  *
324  * Returns
325  *  0 : The operation was initiated. Result of the operation will be reported
326  * through the callback function.
327  * <0 : There was an error. The callback function will not be invoked.
328  *
329  * When the callback is invoked, status indicates the result:
330  *      0 : Success.
331  *          Command_data is struct smb2dir.
332  *          This structure is freed using smb2_closedir().
333  * -errno : An error occured.
334  *          Command_data is NULL.
335  */       
336 int smb2_opendir_async(struct smb2_context *smb2, const char *path,
337                        smb2_command_cb cb, void *cb_data);
338
339 /*
340  * Sync opendir()
341  *
342  * Returns NULL on failure.
343  */
344 struct smb2dir *smb2_opendir(struct smb2_context *smb2, const char *path);
345
346 /*
347  * closedir()
348  */
349 /*
350  * smb2_closedir() never blocks, thus no async version is needed.
351  */
352 void smb2_closedir(struct smb2_context *smb2, struct smb2dir *smb2dir);
353
354 /*
355  * readdir()
356  */
357 /*
358  * smb2_readdir() never blocks, thus no async version is needed.
359  */
360 struct smb2dirent *smb2_readdir(struct smb2_context *smb2,
361                                 struct smb2dir *smb2dir);
362
363 /*
364  * rewinddir()
365  */
366 /*
367  * smb2_rewinddir() never blocks, thus no async version is needed.
368  */
369 void smb2_rewinddir(struct smb2_context *smb2, struct smb2dir *smb2dir);
370
371 /*
372  * telldir()
373  */
374 /*
375  * smb2_telldir() never blocks, thus no async version is needed.
376  */
377 long smb2_telldir(struct smb2_context *smb2, struct smb2dir *smb2dir);
378
379 /*
380  * seekdir()
381  */
382 /*
383  * smb2_seekdir() never blocks, thus no async version is needed.
384  */
385 void smb2_seekdir(struct smb2_context *smb2, struct smb2dir *smb2dir,
386                   long loc);
387
388 /*
389  * OPEN
390  */
391 struct smb2fh;
392 /*
393  * Async open()
394  *
395  * Opens or creates a file.
396  * Supported flags are:
397  * O_RDONLY
398  * O_WRONLY
399  * O_RDWR
400  * O_SYNC
401  * O_CREAT
402  * O_EXCL
403  *
404  * Returns
405  *  0     : The operation was initiated. Result of the operation will be
406  *          reported through the callback function.
407  * -errno : There was an error. The callback function will not be invoked.
408  *
409  * When the callback is invoked, status indicates the result:
410  *      0 : Success.
411  *          Command_data is struct smb2fh.
412  *          This structure is freed using smb2_close().
413  * -errno : An error occured.
414  *          Command_data is NULL.
415  */       
416 int smb2_open_async(struct smb2_context *smb2, const char *path, int flags,
417                     smb2_command_cb cb, void *cb_data);
418
419 /*
420  * Sync open()
421  *
422  * Returns NULL on failure.
423  */
424 struct smb2fh *smb2_open(struct smb2_context *smb2, const char *path, int flags);
425
426 /*
427  * CLOSE
428  */
429 /*
430  * Async close()
431  *
432  * Returns
433  *  0     : The operation was initiated. Result of the operation will be
434  *          reported through the callback function.
435  * -errno : There was an error. The callback function will not be invoked.
436  *
437  * When the callback is invoked, status indicates the result:
438  *      0 : Success.
439  * -errno : An error occured.
440  *
441  * Command_data is always NULL.
442  */
443 int smb2_close_async(struct smb2_context *smb2, struct smb2fh *fh,
444                      smb2_command_cb cb, void *cb_data);
445
446 /*
447  * Sync close()
448  */
449 int smb2_close(struct smb2_context *smb2, struct smb2fh *fh);
450
451 /*
452  * FSYNC
453  */
454 /*
455  * Async fsync()
456  *
457  * Returns
458  *  0     : The operation was initiated. Result of the operation will be
459  *          reported through the callback function.
460  * -errno : There was an error. The callback function will not be invoked.
461  *
462  * When the callback is invoked, status indicates the result:
463  *      0 : Success.
464  * -errno : An error occured.
465  *
466  * Command_data is always NULL.
467  */
468 int smb2_fsync_async(struct smb2_context *smb2, struct smb2fh *fh,
469                      smb2_command_cb cb, void *cb_data);
470
471 /*
472  * Sync fsync()
473  */
474 int smb2_fsync(struct smb2_context *smb2, struct smb2fh *fh);
475
476 /*
477  * GetMaxReadWriteSize
478  * SMB2 servers have a maximum size for read/write data that they support.
479  */
480 uint32_t smb2_get_max_read_size(struct smb2_context *smb2);
481 uint32_t smb2_get_max_write_size(struct smb2_context *smb2);
482
483 /*
484  * PREAD
485  */
486 /*
487  * Async pread()
488  * Use smb2_get_max_read_size to discover the maximum data size that the
489  * server supports.
490  *
491  * Returns
492  *  0     : The operation was initiated. Result of the operation will be
493  *          reported through the callback function.
494  * -errno : There was an error. The callback function will not be invoked.
495  *
496  * When the callback is invoked, status indicates the result:
497  *    >=0 : Number of bytes read.
498  * -errno : An error occured.
499  *
500  * Command_data is always NULL.
501  */       
502 int smb2_pread_async(struct smb2_context *smb2, struct smb2fh *fh,
503                      uint8_t *buf, uint32_t count, uint64_t offset,
504                      smb2_command_cb cb, void *cb_data);
505
506 /*
507  * Sync pread()
508  * Use smb2_get_max_read_size to discover the maximum data size that the
509  * server supports.
510  */
511 int smb2_pread(struct smb2_context *smb2, struct smb2fh *fh,
512                uint8_t *buf, uint32_t count, uint64_t offset);
513
514 /*
515  * PWRITE
516  */
517 /*
518  * Async pwrite()
519  * Use smb2_get_max_write_size to discover the maximum data size that the
520  * server supports.
521  *
522  * Returns
523  *  0     : The operation was initiated. Result of the operation will be
524  *          reported through the callback function.
525  * -errno : There was an error. The callback function will not be invoked.
526  *
527  * When the callback is invoked, status indicates the result:
528  *    >=0 : Number of bytes written.
529  * -errno : An error occured.
530  *
531  * Command_data is always NULL.
532  */       
533 int smb2_pwrite_async(struct smb2_context *smb2, struct smb2fh *fh,
534                       uint8_t *buf, uint32_t count, uint64_t offset,
535                       smb2_command_cb cb, void *cb_data);
536
537 /*
538  * Sync pwrite()
539  * Use smb2_get_max_write_size to discover the maximum data size that the
540  * server supports.
541  */
542 int smb2_pwrite(struct smb2_context *smb2, struct smb2fh *fh,
543                 uint8_t *buf, uint32_t count, uint64_t offset);
544
545 /*
546  * READ
547  */
548 /*
549  * Async read()
550  *
551  * Returns
552  *  0     : The operation was initiated. Result of the operation will be
553  *          reported through the callback function.
554  * -errno : There was an error. The callback function will not be invoked.
555  *
556  * When the callback is invoked, status indicates the result:
557  *    >=0 : Number of bytes read.
558  * -errno : An error occured.
559  *
560  * Command_data is always NULL.
561  */
562 int smb2_read_async(struct smb2_context *smb2, struct smb2fh *fh,
563                     uint8_t *buf, uint32_t count,
564                     smb2_command_cb cb, void *cb_data);
565
566 /*
567  * Sync read()
568  */
569 int smb2_read(struct smb2_context *smb2, struct smb2fh *fh,
570               uint8_t *buf, uint32_t count);
571
572 /*
573  * WRITE
574  */
575 /*
576  * Async write()
577  *
578  * Returns
579  *  0     : The operation was initiated. Result of the operation will be
580  *          reported through the callback function.
581  * -errno : There was an error. The callback function will not be invoked.
582  *
583  * When the callback is invoked, status indicates the result:
584  *    >=0 : Number of bytes written.
585  * -errno : An error occured.
586  *
587  * Command_data is always NULL.
588  */
589 int smb2_write_async(struct smb2_context *smb2, struct smb2fh *fh,
590                      uint8_t *buf, uint32_t count,
591                      smb2_command_cb cb, void *cb_data);
592
593 /*
594  * Sync write()
595  */
596 int smb2_write(struct smb2_context *smb2, struct smb2fh *fh,
597                uint8_t *buf, uint32_t count);
598
599 /*
600  * Sync lseek()
601  */
602 /*
603  * smb2_seek() never blocks, thus no async version is needed.
604  */
605 int64_t smb2_lseek(struct smb2_context *smb2, struct smb2fh *fh,
606                    int64_t offset, int whence, uint64_t *current_offset);
607
608 /*
609  * UNLINK
610  */
611 /*
612  * Async unlink()
613  *
614  * Returns
615  *  0     : The operation was initiated. Result of the operation will be
616  *          reported through the callback function.
617  * -errno : There was an error. The callback function will not be invoked.
618  *
619  * When the callback is invoked, status indicates the result:
620  *      0 : Success.
621  * -errno : An error occured.
622  *
623  * Command_data is always NULL.
624  */
625 int smb2_unlink_async(struct smb2_context *smb2, const char *path,
626                       smb2_command_cb cb, void *cb_data);
627
628 /*
629  * Sync unlink()
630  */
631 int smb2_unlink(struct smb2_context *smb2, const char *path);
632
633 /*
634  * RMDIR
635  */
636 /*
637  * Async rmdir()
638  *
639  * Returns
640  *  0     : The operation was initiated. Result of the operation will be
641  *          reported through the callback function.
642  * -errno : There was an error. The callback function will not be invoked.
643  *
644  * When the callback is invoked, status indicates the result:
645  *      0 : Success.
646  * -errno : An error occured.
647  *
648  * Command_data is always NULL.
649  */
650 int smb2_rmdir_async(struct smb2_context *smb2, const char *path,
651                      smb2_command_cb cb, void *cb_data);
652
653 /*
654  * Sync rmdir()
655  */
656 int smb2_rmdir(struct smb2_context *smb2, const char *path);
657
658 /*
659  * MKDIR
660  */
661 /*
662  * Async mkdir()
663  *
664  * Returns
665  *  0     : The operation was initiated. Result of the operation will be
666  *          reported through the callback function.
667  * -errno : There was an error. The callback function will not be invoked.
668  *
669  * When the callback is invoked, status indicates the result:
670  *      0 : Success.
671  * -errno : An error occured.
672  *
673  * Command_data is always NULL.
674  */
675 int smb2_mkdir_async(struct smb2_context *smb2, const char *path,
676                      smb2_command_cb cb, void *cb_data);
677
678 /*
679  * Sync mkdir()
680  */
681 int smb2_mkdir(struct smb2_context *smb2, const char *path);
682
683 /*
684  * STATVFS
685  */
686 /*
687  * Async statvfs()
688  *
689  * Returns
690  *  0     : The operation was initiated. Result of the operation will be
691  *          reported through the callback function.
692  * -errno : There was an error. The callback function will not be invoked.
693  *
694  * When the callback is invoked, status indicates the result:
695  *      0 : Success. Command_data is struct smb2_statvfs
696  * -errno : An error occured.
697  */
698 int smb2_statvfs_async(struct smb2_context *smb2, const char *path,
699                        struct smb2_statvfs *statvfs,
700                        smb2_command_cb cb, void *cb_data);
701 /*
702  * Sync statvfs()
703  */
704 int smb2_statvfs(struct smb2_context *smb2, const char *path,
705                  struct smb2_statvfs *statvfs);
706
707 /*
708  * FSTAT
709  */
710 /*
711  * Async fstat()
712  *
713  * Returns
714  *  0     : The operation was initiated. Result of the operation will be
715  *          reported through the callback function.
716  * -errno : There was an error. The callback function will not be invoked.
717  *
718  * When the callback is invoked, status indicates the result:
719  *      0 : Success. Command_data is struct smb2_stat_64
720  * -errno : An error occured.
721  */
722 int smb2_fstat_async(struct smb2_context *smb2, struct smb2fh *fh,
723                      struct smb2_stat_64 *st,
724                      smb2_command_cb cb, void *cb_data);
725 /*
726  * Sync fstat()
727  */
728 int smb2_fstat(struct smb2_context *smb2, struct smb2fh *fh,
729                struct smb2_stat_64 *st);
730
731 /*
732  * Async stat()
733  *
734  * Returns
735  *  0     : The operation was initiated. Result of the operation will be
736  *          reported through the callback function.
737  * -errno : There was an error. The callback function will not be invoked.
738  *
739  * When the callback is invoked, status indicates the result:
740  *      0 : Success. Command_data is struct smb2_stat_64
741  * -errno : An error occured.
742  */
743 int smb2_stat_async(struct smb2_context *smb2, const char *path,
744                     struct smb2_stat_64 *st,
745                     smb2_command_cb cb, void *cb_data);
746 /*
747  * Sync stat()
748  */
749 int smb2_stat(struct smb2_context *smb2, const char *path,
750               struct smb2_stat_64 *st);
751
752 /*
753  * Async rename()
754  *
755  * Returns
756  *  0     : The operation was initiated. Result of the operation will be
757  *          reported through the callback function.
758  * -errno : There was an error. The callback function will not be invoked.
759  *
760  * When the callback is invoked, status indicates the result:
761  *      0 : Success.
762  * -errno : An error occured.
763  */
764 int smb2_rename_async(struct smb2_context *smb2, const char *oldpath,
765                       const char *newpath, smb2_command_cb cb, void *cb_data);
766
767 /*
768  * Sync rename()
769  */
770 int smb2_rename(struct smb2_context *smb2, const char *oldpath,
771               const char *newpath);
772         
773 /*
774  * Async truncate()
775  *
776  * Returns
777  *  0     : The operation was initiated. Result of the operation will be
778  *          reported through the callback function.
779  * -errno : There was an error. The callback function will not be invoked.
780  *
781  * When the callback is invoked, status indicates the result:
782  *      0 : Success.
783  * -errno : An error occured.
784  */
785 int smb2_truncate_async(struct smb2_context *smb2, const char *path,
786                         uint64_t length, smb2_command_cb cb, void *cb_data);
787 /*
788  * Sync truncate()
789  * Function returns
790  *      0 : Success
791  * -errno : An error occured.
792  */
793 int smb2_truncate(struct smb2_context *smb2, const char *path,
794                   uint64_t length);
795
796 /*
797  * Async ftruncate()
798  *
799  * Returns
800  *  0     : The operation was initiated. Result of the operation will be
801  *          reported through the callback function.
802  * -errno : There was an error. The callback function will not be invoked.
803  *
804  * When the callback is invoked, status indicates the result:
805  *      0 : Success.
806  * -errno : An error occured.
807  */
808 int smb2_ftruncate_async(struct smb2_context *smb2, struct smb2fh *fh,
809                          uint64_t length, smb2_command_cb cb, void *cb_data);
810 /*
811  * Sync ftruncate()
812  * Function returns
813  *      0 : Success
814  * -errno : An error occured.
815  */
816 int smb2_ftruncate(struct smb2_context *smb2, struct smb2fh *fh,
817                    uint64_t length);
818
819
820 /*
821  * READLINK
822  */
823 /*
824  * Async readlink()
825  *
826  * Returns
827  *  0     : The operation was initiated. The link content will be
828  *          reported through the callback function.
829  * -errno : There was an error. The callback function will not be invoked.
830  *
831  * When the callback is invoked, status indicates the result:
832  *      0 : Success. Command_data is the link content.
833  * -errno : An error occured.
834  */
835 int smb2_readlink_async(struct smb2_context *smb2, const char *path,
836                         smb2_command_cb cb, void *cb_data);
837
838 /*
839  * Sync readlink()
840  */
841 int smb2_readlink(struct smb2_context *smb2, const char *path, char *buf, uint32_t bufsiz);
842
843 /*
844  * Async echo()
845  *
846  * Returns
847  *  0     : The operation was initiated. Result of the operation will be
848  *          reported through the callback function.
849  * -errno : There was an error. The callback function will not be invoked.
850  *
851  * When the callback is invoked, status indicates the result:
852  *      0 : Success.
853  * -errno : An error occured.
854  */
855 int smb2_echo_async(struct smb2_context *smb2,
856                     smb2_command_cb cb, void *cb_data);
857
858 /*
859  * Sync echo()
860  *
861  * Returns:
862  * 0      : successfully send the message and received a reply.
863  * -errno : Failure.
864  */
865 int smb2_echo(struct smb2_context *smb2);
866
867 #ifdef __cplusplus
868 }
869 #endif
870
871 /* Low 2 bits desctibe the type */
872 #define SHARE_TYPE_DISKTREE  0
873 #define SHARE_TYPE_PRINTQ    1
874 #define SHARE_TYPE_DEVICE    2
875 #define SHARE_TYPE_IPC       3
876
877 #define SHARE_TYPE_TEMPORARY 0x40000000
878 #define SHARE_TYPE_HIDDEN    0x80000000
879
880 struct srvsvc_netshareinfo1 {
881         const char *name;
882         uint32_t type;
883         const char *comment;
884 };
885
886 struct srvsvc_netsharectr1 {
887         uint32_t count;
888         struct srvsvc_netshareinfo1 *array;
889 };
890
891 struct srvsvc_netsharectr {
892         uint32_t level;
893         union {
894                 struct srvsvc_netsharectr1 ctr1;
895         };
896 };
897
898 struct srvsvc_netshareenumall_req {
899         const char *server;
900         uint32_t level;
901         struct srvsvc_netsharectr *ctr;
902         uint32_t max_buffer;
903         uint32_t resume_handle;
904 };
905
906 struct srvsvc_netshareenumall_rep {
907         uint32_t level;
908         struct srvsvc_netsharectr *ctr;
909         uint32_t total_entries;
910         uint32_t resume_handle;
911
912         uint32_t status;
913 };
914
915 /*
916  * Async share_enum()
917  * This function only works when connected to the IPC$ share.
918  *
919  * Returns
920  *  0     : The operation was initiated. Result of the operation will be
921  *          reported through the callback function.
922  * -errno : There was an error. The callback function will not be invoked.
923  *
924  * When the callback is invoked, status indicates the result:
925  *      0 : Success. Command_data is struct srvsvc_netshareenumall_rep *
926  *          This pointer must be freed using smb2_free_data().
927  * -errno : An error occured.
928  */
929 int smb2_share_enum_async(struct smb2_context *smb2,
930                           smb2_command_cb cb, void *cb_data);
931
932 #endif /* !_LIBSMB2_H_ */