2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1994-1998
5 Copyright (C) Jeremy Allison 2001-2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "system/filesys.h"
23 #include "libsmb/libsmb.h"
24 #include "../lib/util/tevent_ntstatus.h"
25 #include "async_smb.h"
26 #include "libsmb/clirap.h"
29 #include "libcli/security/secdesc.h"
30 #include "../libcli/smb/smbXcli_base.h"
32 /***********************************************************
33 Common function for pushing stings, used by smb_bytes_push_str()
34 and trans_bytes_push_str(). Only difference is the align_odd
36 ***********************************************************/
38 static uint8_t *internal_bytes_push_str(uint8_t *buf
, bool ucs2
,
39 const char *str
, size_t str_len
,
41 size_t *pconverted_size
)
45 size_t converted_size
;
51 buflen
= talloc_get_size(buf
);
54 ((align_odd
&& (buflen
% 2 == 0)) ||
55 (!align_odd
&& (buflen
% 2 == 1)))) {
57 * We're pushing into an SMB buffer, align odd
59 buf
= talloc_realloc(NULL
, buf
, uint8_t, buflen
+ 1);
67 if (!convert_string_talloc(talloc_tos(), CH_UNIX
,
68 ucs2
? CH_UTF16LE
: CH_DOS
,
69 str
, str_len
, &converted
,
74 buf
= talloc_realloc(NULL
, buf
, uint8_t,
75 buflen
+ converted_size
);
77 TALLOC_FREE(converted
);
81 memcpy(buf
+ buflen
, converted
, converted_size
);
83 TALLOC_FREE(converted
);
85 if (pconverted_size
) {
86 *pconverted_size
= converted_size
;
92 /***********************************************************
93 Push a string into an SMB buffer, with odd byte alignment
94 if it's a UCS2 string.
95 ***********************************************************/
97 uint8_t *smb_bytes_push_str(uint8_t *buf
, bool ucs2
,
98 const char *str
, size_t str_len
,
99 size_t *pconverted_size
)
101 return internal_bytes_push_str(buf
, ucs2
, str
, str_len
,
102 true, pconverted_size
);
105 uint8_t *smb_bytes_push_bytes(uint8_t *buf
, uint8_t prefix
,
106 const uint8_t *bytes
, size_t num_bytes
)
113 buflen
= talloc_get_size(buf
);
115 buf
= talloc_realloc(NULL
, buf
, uint8_t,
116 buflen
+ 1 + num_bytes
);
120 buf
[buflen
] = prefix
;
121 memcpy(&buf
[buflen
+1], bytes
, num_bytes
);
125 /***********************************************************
126 Same as smb_bytes_push_str(), but without the odd byte
127 align for ucs2 (we're pushing into a param or data block).
128 static for now, although this will probably change when
129 other modules use async trans calls.
130 ***********************************************************/
132 uint8_t *trans2_bytes_push_str(uint8_t *buf
, bool ucs2
,
133 const char *str
, size_t str_len
,
134 size_t *pconverted_size
)
136 return internal_bytes_push_str(buf
, ucs2
, str
, str_len
,
137 false, pconverted_size
);
140 uint8_t *trans2_bytes_push_bytes(uint8_t *buf
,
141 const uint8_t *bytes
, size_t num_bytes
)
148 buflen
= talloc_get_size(buf
);
150 buf
= talloc_realloc(NULL
, buf
, uint8_t,
155 memcpy(&buf
[buflen
], bytes
, num_bytes
);
159 struct cli_setpathinfo_state
{
164 static void cli_setpathinfo_done(struct tevent_req
*subreq
);
166 struct tevent_req
*cli_setpathinfo_send(TALLOC_CTX
*mem_ctx
,
167 struct tevent_context
*ev
,
168 struct cli_state
*cli
,
174 struct tevent_req
*req
, *subreq
;
175 struct cli_setpathinfo_state
*state
;
176 uint16_t additional_flags2
= 0;
178 req
= tevent_req_create(mem_ctx
, &state
,
179 struct cli_setpathinfo_state
);
184 /* Setup setup word. */
185 SSVAL(&state
->setup
, 0, TRANSACT2_SETPATHINFO
);
187 /* Setup param array. */
188 state
->param
= talloc_zero_array(state
, uint8_t, 6);
189 if (tevent_req_nomem(state
->param
, req
)) {
190 return tevent_req_post(req
, ev
);
192 SSVAL(state
->param
, 0, level
);
194 state
->param
= trans2_bytes_push_str(
195 state
->param
, smbXcli_conn_use_unicode(cli
->conn
), path
, strlen(path
)+1, NULL
);
196 if (tevent_req_nomem(state
->param
, req
)) {
197 return tevent_req_post(req
, ev
);
200 if (clistr_is_previous_version_path(path
) &&
201 !INFO_LEVEL_IS_UNIX(level
)) {
202 additional_flags2
= FLAGS2_REPARSE_PATH
;
205 subreq
= cli_trans_send(
206 state
, /* mem ctx. */
208 cli
, /* cli_state. */
209 additional_flags2
, /* additional_flags2 */
210 SMBtrans2
, /* cmd. */
211 NULL
, /* pipe name. */
215 &state
->setup
, /* setup. */
216 1, /* num setup uint16_t words. */
217 0, /* max returned setup. */
218 state
->param
, /* param. */
219 talloc_get_size(state
->param
), /* num param. */
220 2, /* max returned param. */
222 data_len
, /* num data. */
223 0); /* max returned data. */
225 if (tevent_req_nomem(subreq
, req
)) {
226 return tevent_req_post(req
, ev
);
228 tevent_req_set_callback(subreq
, cli_setpathinfo_done
, req
);
232 static void cli_setpathinfo_done(struct tevent_req
*subreq
)
234 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, NULL
, 0, NULL
,
235 NULL
, 0, NULL
, NULL
, 0, NULL
);
236 tevent_req_simple_finish_ntstatus(subreq
, status
);
239 NTSTATUS
cli_setpathinfo_recv(struct tevent_req
*req
)
241 return tevent_req_simple_recv_ntstatus(req
);
244 NTSTATUS
cli_setpathinfo(struct cli_state
*cli
,
250 TALLOC_CTX
*frame
= talloc_stackframe();
251 struct tevent_context
*ev
;
252 struct tevent_req
*req
;
253 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
255 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
257 * Can't use sync call while an async call is in flight
259 status
= NT_STATUS_INVALID_PARAMETER
;
262 ev
= samba_tevent_context_init(frame
);
266 req
= cli_setpathinfo_send(ev
, ev
, cli
, level
, path
, data
, data_len
);
270 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
273 status
= cli_setpathinfo_recv(req
);
279 /****************************************************************************
280 Hard/Symlink a file (UNIX extensions).
281 Creates new name (sym)linked to oldname.
282 ****************************************************************************/
284 struct cli_posix_link_internal_state
{
288 static void cli_posix_link_internal_done(struct tevent_req
*subreq
);
290 static struct tevent_req
*cli_posix_link_internal_send(TALLOC_CTX
*mem_ctx
,
291 struct tevent_context
*ev
,
292 struct cli_state
*cli
,
297 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
298 struct cli_posix_link_internal_state
*state
= NULL
;
300 req
= tevent_req_create(mem_ctx
, &state
,
301 struct cli_posix_link_internal_state
);
306 /* Setup data array. */
307 state
->data
= talloc_array(state
, uint8_t, 0);
308 if (tevent_req_nomem(state
->data
, req
)) {
309 return tevent_req_post(req
, ev
);
311 state
->data
= trans2_bytes_push_str(
312 state
->data
, smbXcli_conn_use_unicode(cli
->conn
), oldname
, strlen(oldname
)+1, NULL
);
314 subreq
= cli_setpathinfo_send(
315 state
, ev
, cli
, level
, newname
,
316 state
->data
, talloc_get_size(state
->data
));
317 if (tevent_req_nomem(subreq
, req
)) {
318 return tevent_req_post(req
, ev
);
320 tevent_req_set_callback(subreq
, cli_posix_link_internal_done
, req
);
324 static void cli_posix_link_internal_done(struct tevent_req
*subreq
)
326 NTSTATUS status
= cli_setpathinfo_recv(subreq
);
327 tevent_req_simple_finish_ntstatus(subreq
, status
);
330 /****************************************************************************
331 Symlink a file (UNIX extensions).
332 ****************************************************************************/
334 struct tevent_req
*cli_posix_symlink_send(TALLOC_CTX
*mem_ctx
,
335 struct tevent_context
*ev
,
336 struct cli_state
*cli
,
340 return cli_posix_link_internal_send(
341 mem_ctx
, ev
, cli
, SMB_SET_FILE_UNIX_LINK
, oldname
, newname
);
344 NTSTATUS
cli_posix_symlink_recv(struct tevent_req
*req
)
346 return tevent_req_simple_recv_ntstatus(req
);
349 NTSTATUS
cli_posix_symlink(struct cli_state
*cli
,
353 TALLOC_CTX
*frame
= talloc_stackframe();
354 struct tevent_context
*ev
= NULL
;
355 struct tevent_req
*req
= NULL
;
356 NTSTATUS status
= NT_STATUS_OK
;
358 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
360 * Can't use sync call while an async call is in flight
362 status
= NT_STATUS_INVALID_PARAMETER
;
366 ev
= samba_tevent_context_init(frame
);
368 status
= NT_STATUS_NO_MEMORY
;
372 req
= cli_posix_symlink_send(frame
,
378 status
= NT_STATUS_NO_MEMORY
;
382 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
386 status
= cli_posix_symlink_recv(req
);
393 /****************************************************************************
394 Read a POSIX symlink.
395 ****************************************************************************/
397 struct readlink_state
{
402 static void cli_posix_readlink_done(struct tevent_req
*subreq
);
404 struct tevent_req
*cli_posix_readlink_send(TALLOC_CTX
*mem_ctx
,
405 struct tevent_context
*ev
,
406 struct cli_state
*cli
,
410 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
411 struct readlink_state
*state
= NULL
;
412 uint32_t maxbytelen
= (uint32_t)(smbXcli_conn_use_unicode(cli
->conn
) ? len
*3 : len
);
414 req
= tevent_req_create(mem_ctx
, &state
, struct readlink_state
);
420 * Len is in bytes, we need it in UCS2 units.
422 if ((2*len
< len
) || (maxbytelen
< len
)) {
423 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
424 return tevent_req_post(req
, ev
);
427 subreq
= cli_qpathinfo_send(state
, ev
, cli
, fname
,
428 SMB_QUERY_FILE_UNIX_LINK
, 1, maxbytelen
);
429 if (tevent_req_nomem(subreq
, req
)) {
430 return tevent_req_post(req
, ev
);
432 tevent_req_set_callback(subreq
, cli_posix_readlink_done
, req
);
436 static void cli_posix_readlink_done(struct tevent_req
*subreq
)
438 struct tevent_req
*req
= tevent_req_callback_data(
439 subreq
, struct tevent_req
);
440 struct readlink_state
*state
= tevent_req_data(
441 req
, struct readlink_state
);
444 status
= cli_qpathinfo_recv(subreq
, state
, &state
->data
,
447 if (tevent_req_nterror(req
, status
)) {
451 * num_data is > 1, we've given 1 as minimum to cli_qpathinfo_send
453 if (state
->data
[state
->num_data
-1] != '\0') {
454 tevent_req_nterror(req
, NT_STATUS_DATA_ERROR
);
457 tevent_req_done(req
);
460 NTSTATUS
cli_posix_readlink_recv(struct tevent_req
*req
, struct cli_state
*cli
,
461 char *retpath
, size_t len
)
464 char *converted
= NULL
;
465 size_t converted_size
= 0;
466 struct readlink_state
*state
= tevent_req_data(req
, struct readlink_state
);
468 if (tevent_req_is_nterror(req
, &status
)) {
471 /* The returned data is a pushed string, not raw data. */
472 if (!convert_string_talloc(state
,
473 smbXcli_conn_use_unicode(cli
->conn
) ? CH_UTF16LE
: CH_DOS
,
479 return NT_STATUS_NO_MEMORY
;
482 len
= MIN(len
,converted_size
);
484 return NT_STATUS_DATA_ERROR
;
486 memcpy(retpath
, converted
, len
);
490 NTSTATUS
cli_posix_readlink(struct cli_state
*cli
, const char *fname
,
491 char *linkpath
, size_t len
)
493 TALLOC_CTX
*frame
= talloc_stackframe();
494 struct tevent_context
*ev
= NULL
;
495 struct tevent_req
*req
= NULL
;
496 NTSTATUS status
= NT_STATUS_OK
;
498 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
500 * Can't use sync call while an async call is in flight
502 status
= NT_STATUS_INVALID_PARAMETER
;
506 ev
= samba_tevent_context_init(frame
);
508 status
= NT_STATUS_NO_MEMORY
;
512 req
= cli_posix_readlink_send(frame
,
518 status
= NT_STATUS_NO_MEMORY
;
522 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
526 status
= cli_posix_readlink_recv(req
, cli
, linkpath
, len
);
533 /****************************************************************************
534 Hard link a file (UNIX extensions).
535 ****************************************************************************/
537 struct tevent_req
*cli_posix_hardlink_send(TALLOC_CTX
*mem_ctx
,
538 struct tevent_context
*ev
,
539 struct cli_state
*cli
,
543 return cli_posix_link_internal_send(
544 mem_ctx
, ev
, cli
, SMB_SET_FILE_UNIX_HLINK
, oldname
, newname
);
547 NTSTATUS
cli_posix_hardlink_recv(struct tevent_req
*req
)
549 return tevent_req_simple_recv_ntstatus(req
);
552 NTSTATUS
cli_posix_hardlink(struct cli_state
*cli
,
556 TALLOC_CTX
*frame
= talloc_stackframe();
557 struct tevent_context
*ev
= NULL
;
558 struct tevent_req
*req
= NULL
;
559 NTSTATUS status
= NT_STATUS_OK
;
561 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
563 * Can't use sync call while an async call is in flight
565 status
= NT_STATUS_INVALID_PARAMETER
;
569 ev
= samba_tevent_context_init(frame
);
571 status
= NT_STATUS_NO_MEMORY
;
575 req
= cli_posix_hardlink_send(frame
,
581 status
= NT_STATUS_NO_MEMORY
;
585 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
589 status
= cli_posix_hardlink_recv(req
);
596 /****************************************************************************
597 Do a POSIX getacl - pathname based ACL get (UNIX extensions).
598 ****************************************************************************/
600 struct getacl_state
{
605 static void cli_posix_getacl_done(struct tevent_req
*subreq
);
607 struct tevent_req
*cli_posix_getacl_send(TALLOC_CTX
*mem_ctx
,
608 struct tevent_context
*ev
,
609 struct cli_state
*cli
,
612 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
613 struct getacl_state
*state
= NULL
;
615 req
= tevent_req_create(mem_ctx
, &state
, struct getacl_state
);
619 subreq
= cli_qpathinfo_send(state
, ev
, cli
, fname
, SMB_QUERY_POSIX_ACL
,
621 if (tevent_req_nomem(subreq
, req
)) {
622 return tevent_req_post(req
, ev
);
624 tevent_req_set_callback(subreq
, cli_posix_getacl_done
, req
);
628 static void cli_posix_getacl_done(struct tevent_req
*subreq
)
630 struct tevent_req
*req
= tevent_req_callback_data(
631 subreq
, struct tevent_req
);
632 struct getacl_state
*state
= tevent_req_data(
633 req
, struct getacl_state
);
636 status
= cli_qpathinfo_recv(subreq
, state
, &state
->data
,
639 if (tevent_req_nterror(req
, status
)) {
642 tevent_req_done(req
);
645 NTSTATUS
cli_posix_getacl_recv(struct tevent_req
*req
,
650 struct getacl_state
*state
= tevent_req_data(req
, struct getacl_state
);
653 if (tevent_req_is_nterror(req
, &status
)) {
656 *prb_size
= (size_t)state
->num_data
;
657 *retbuf
= (char *)talloc_move(mem_ctx
, &state
->data
);
661 NTSTATUS
cli_posix_getacl(struct cli_state
*cli
,
667 TALLOC_CTX
*frame
= talloc_stackframe();
668 struct tevent_context
*ev
= NULL
;
669 struct tevent_req
*req
= NULL
;
670 NTSTATUS status
= NT_STATUS_OK
;
672 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
674 * Can't use sync call while an async call is in flight
676 status
= NT_STATUS_INVALID_PARAMETER
;
680 ev
= samba_tevent_context_init(frame
);
682 status
= NT_STATUS_NO_MEMORY
;
686 req
= cli_posix_getacl_send(frame
,
691 status
= NT_STATUS_NO_MEMORY
;
695 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
699 status
= cli_posix_getacl_recv(req
, mem_ctx
, prb_size
, retbuf
);
706 /****************************************************************************
707 Do a POSIX setacl - pathname based ACL set (UNIX extensions).
708 ****************************************************************************/
710 struct setacl_state
{
714 static void cli_posix_setacl_done(struct tevent_req
*subreq
);
716 struct tevent_req
*cli_posix_setacl_send(TALLOC_CTX
*mem_ctx
,
717 struct tevent_context
*ev
,
718 struct cli_state
*cli
,
723 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
724 struct setacl_state
*state
= NULL
;
726 req
= tevent_req_create(mem_ctx
, &state
, struct setacl_state
);
730 state
->data
= talloc_memdup(state
, data
, num_data
);
731 if (tevent_req_nomem(state
->data
, req
)) {
732 return tevent_req_post(req
, ev
);
735 subreq
= cli_setpathinfo_send(state
,
742 if (tevent_req_nomem(subreq
, req
)) {
743 return tevent_req_post(req
, ev
);
745 tevent_req_set_callback(subreq
, cli_posix_setacl_done
, req
);
749 static void cli_posix_setacl_done(struct tevent_req
*subreq
)
751 NTSTATUS status
= cli_setpathinfo_recv(subreq
);
752 tevent_req_simple_finish_ntstatus(subreq
, status
);
755 NTSTATUS
cli_posix_setacl_recv(struct tevent_req
*req
)
757 return tevent_req_simple_recv_ntstatus(req
);
760 NTSTATUS
cli_posix_setacl(struct cli_state
*cli
,
765 TALLOC_CTX
*frame
= talloc_stackframe();
766 struct tevent_context
*ev
= NULL
;
767 struct tevent_req
*req
= NULL
;
768 NTSTATUS status
= NT_STATUS_OK
;
770 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
772 * Can't use sync call while an async call is in flight
774 status
= NT_STATUS_INVALID_PARAMETER
;
778 ev
= samba_tevent_context_init(frame
);
780 status
= NT_STATUS_NO_MEMORY
;
784 req
= cli_posix_setacl_send(frame
,
791 status
= NT_STATUS_NO_MEMORY
;
795 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
799 status
= cli_posix_setacl_recv(req
);
806 /****************************************************************************
807 Stat a file (UNIX extensions).
808 ****************************************************************************/
815 static void cli_posix_stat_done(struct tevent_req
*subreq
);
817 struct tevent_req
*cli_posix_stat_send(TALLOC_CTX
*mem_ctx
,
818 struct tevent_context
*ev
,
819 struct cli_state
*cli
,
822 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
823 struct stat_state
*state
= NULL
;
825 req
= tevent_req_create(mem_ctx
, &state
, struct stat_state
);
829 subreq
= cli_qpathinfo_send(state
, ev
, cli
, fname
,
830 SMB_QUERY_FILE_UNIX_BASIC
, 100, 100);
831 if (tevent_req_nomem(subreq
, req
)) {
832 return tevent_req_post(req
, ev
);
834 tevent_req_set_callback(subreq
, cli_posix_stat_done
, req
);
838 static void cli_posix_stat_done(struct tevent_req
*subreq
)
840 struct tevent_req
*req
= tevent_req_callback_data(
841 subreq
, struct tevent_req
);
842 struct stat_state
*state
= tevent_req_data(req
, struct stat_state
);
845 status
= cli_qpathinfo_recv(subreq
, state
, &state
->data
,
848 if (tevent_req_nterror(req
, status
)) {
851 tevent_req_done(req
);
854 NTSTATUS
cli_posix_stat_recv(struct tevent_req
*req
,
855 SMB_STRUCT_STAT
*sbuf
)
857 struct stat_state
*state
= tevent_req_data(req
, struct stat_state
);
860 if (tevent_req_is_nterror(req
, &status
)) {
864 sbuf
->st_ex_size
= IVAL2_TO_SMB_BIG_UINT(state
->data
,0); /* total size, in bytes */
865 sbuf
->st_ex_blocks
= IVAL2_TO_SMB_BIG_UINT(state
->data
,8); /* number of blocks allocated */
866 #if defined (HAVE_STAT_ST_BLOCKS) && defined(STAT_ST_BLOCKSIZE)
867 sbuf
->st_ex_blocks
/= STAT_ST_BLOCKSIZE
;
869 /* assume 512 byte blocks */
870 sbuf
->st_ex_blocks
/= 512;
872 sbuf
->st_ex_ctime
= interpret_long_date((char *)(state
->data
+ 16)); /* time of last change */
873 sbuf
->st_ex_atime
= interpret_long_date((char *)(state
->data
+ 24)); /* time of last access */
874 sbuf
->st_ex_mtime
= interpret_long_date((char *)(state
->data
+ 32)); /* time of last modification */
876 sbuf
->st_ex_uid
= (uid_t
) IVAL(state
->data
,40); /* user ID of owner */
877 sbuf
->st_ex_gid
= (gid_t
) IVAL(state
->data
,48); /* group ID of owner */
878 sbuf
->st_ex_mode
= unix_filetype_from_wire(IVAL(state
->data
, 56));
879 #if defined(HAVE_MAKEDEV)
881 uint32_t dev_major
= IVAL(state
->data
,60);
882 uint32_t dev_minor
= IVAL(state
->data
,68);
883 sbuf
->st_ex_rdev
= makedev(dev_major
, dev_minor
);
886 sbuf
->st_ex_ino
= (SMB_INO_T
)IVAL2_TO_SMB_BIG_UINT(state
->data
,76); /* inode */
887 sbuf
->st_ex_mode
|= wire_perms_to_unix(IVAL(state
->data
,84)); /* protection */
888 sbuf
->st_ex_nlink
= BIG_UINT(state
->data
,92); /* number of hard links */
893 NTSTATUS
cli_posix_stat(struct cli_state
*cli
,
895 SMB_STRUCT_STAT
*sbuf
)
897 TALLOC_CTX
*frame
= talloc_stackframe();
898 struct tevent_context
*ev
= NULL
;
899 struct tevent_req
*req
= NULL
;
900 NTSTATUS status
= NT_STATUS_OK
;
902 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
904 * Can't use sync call while an async call is in flight
906 status
= NT_STATUS_INVALID_PARAMETER
;
910 ev
= samba_tevent_context_init(frame
);
912 status
= NT_STATUS_NO_MEMORY
;
916 req
= cli_posix_stat_send(frame
,
921 status
= NT_STATUS_NO_MEMORY
;
925 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
929 status
= cli_posix_stat_recv(req
, sbuf
);
936 /****************************************************************************
937 Chmod or chown a file internal (UNIX extensions).
938 ****************************************************************************/
940 struct cli_posix_chown_chmod_internal_state
{
944 static void cli_posix_chown_chmod_internal_done(struct tevent_req
*subreq
);
946 static struct tevent_req
*cli_posix_chown_chmod_internal_send(TALLOC_CTX
*mem_ctx
,
947 struct tevent_context
*ev
,
948 struct cli_state
*cli
,
954 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
955 struct cli_posix_chown_chmod_internal_state
*state
= NULL
;
957 req
= tevent_req_create(mem_ctx
, &state
,
958 struct cli_posix_chown_chmod_internal_state
);
963 memset(state
->data
, 0xff, 40); /* Set all sizes/times to no change. */
964 memset(&state
->data
[40], '\0', 60);
965 SIVAL(state
->data
,40,uid
);
966 SIVAL(state
->data
,48,gid
);
967 SIVAL(state
->data
,84,mode
);
969 subreq
= cli_setpathinfo_send(state
, ev
, cli
, SMB_SET_FILE_UNIX_BASIC
,
970 fname
, state
->data
, sizeof(state
->data
));
971 if (tevent_req_nomem(subreq
, req
)) {
972 return tevent_req_post(req
, ev
);
974 tevent_req_set_callback(subreq
, cli_posix_chown_chmod_internal_done
,
979 static void cli_posix_chown_chmod_internal_done(struct tevent_req
*subreq
)
981 NTSTATUS status
= cli_setpathinfo_recv(subreq
);
982 tevent_req_simple_finish_ntstatus(subreq
, status
);
985 /****************************************************************************
986 chmod a file (UNIX extensions).
987 ****************************************************************************/
989 struct tevent_req
*cli_posix_chmod_send(TALLOC_CTX
*mem_ctx
,
990 struct tevent_context
*ev
,
991 struct cli_state
*cli
,
995 return cli_posix_chown_chmod_internal_send(mem_ctx
, ev
, cli
,
997 unix_perms_to_wire(mode
),
1002 NTSTATUS
cli_posix_chmod_recv(struct tevent_req
*req
)
1004 return tevent_req_simple_recv_ntstatus(req
);
1007 NTSTATUS
cli_posix_chmod(struct cli_state
*cli
, const char *fname
, mode_t mode
)
1009 TALLOC_CTX
*frame
= talloc_stackframe();
1010 struct tevent_context
*ev
= NULL
;
1011 struct tevent_req
*req
= NULL
;
1012 NTSTATUS status
= NT_STATUS_OK
;
1014 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1016 * Can't use sync call while an async call is in flight
1018 status
= NT_STATUS_INVALID_PARAMETER
;
1022 ev
= samba_tevent_context_init(frame
);
1024 status
= NT_STATUS_NO_MEMORY
;
1028 req
= cli_posix_chmod_send(frame
,
1034 status
= NT_STATUS_NO_MEMORY
;
1038 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
1042 status
= cli_posix_chmod_recv(req
);
1049 /****************************************************************************
1050 chown a file (UNIX extensions).
1051 ****************************************************************************/
1053 struct tevent_req
*cli_posix_chown_send(TALLOC_CTX
*mem_ctx
,
1054 struct tevent_context
*ev
,
1055 struct cli_state
*cli
,
1060 return cli_posix_chown_chmod_internal_send(mem_ctx
, ev
, cli
,
1067 NTSTATUS
cli_posix_chown_recv(struct tevent_req
*req
)
1069 return tevent_req_simple_recv_ntstatus(req
);
1072 NTSTATUS
cli_posix_chown(struct cli_state
*cli
,
1077 TALLOC_CTX
*frame
= talloc_stackframe();
1078 struct tevent_context
*ev
= NULL
;
1079 struct tevent_req
*req
= NULL
;
1080 NTSTATUS status
= NT_STATUS_OK
;
1082 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1084 * Can't use sync call while an async call is in flight
1086 status
= NT_STATUS_INVALID_PARAMETER
;
1090 ev
= samba_tevent_context_init(frame
);
1092 status
= NT_STATUS_NO_MEMORY
;
1096 req
= cli_posix_chown_send(frame
,
1103 status
= NT_STATUS_NO_MEMORY
;
1107 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
1111 status
= cli_posix_chown_recv(req
);
1118 /****************************************************************************
1120 ****************************************************************************/
1122 static void cli_rename_done(struct tevent_req
*subreq
);
1124 struct cli_rename_state
{
1128 struct tevent_req
*cli_rename_send(TALLOC_CTX
*mem_ctx
,
1129 struct tevent_context
*ev
,
1130 struct cli_state
*cli
,
1131 const char *fname_src
,
1132 const char *fname_dst
)
1134 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1135 struct cli_rename_state
*state
= NULL
;
1136 uint8_t additional_flags
= 0;
1137 uint16_t additional_flags2
= 0;
1138 uint8_t *bytes
= NULL
;
1140 req
= tevent_req_create(mem_ctx
, &state
, struct cli_rename_state
);
1145 SSVAL(state
->vwv
+0, 0, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_DIRECTORY
);
1147 bytes
= talloc_array(state
, uint8_t, 1);
1148 if (tevent_req_nomem(bytes
, req
)) {
1149 return tevent_req_post(req
, ev
);
1152 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname_src
,
1153 strlen(fname_src
)+1, NULL
);
1154 if (tevent_req_nomem(bytes
, req
)) {
1155 return tevent_req_post(req
, ev
);
1158 if (clistr_is_previous_version_path(fname_src
)) {
1159 additional_flags2
= FLAGS2_REPARSE_PATH
;
1162 bytes
= talloc_realloc(state
, bytes
, uint8_t,
1163 talloc_get_size(bytes
)+1);
1164 if (tevent_req_nomem(bytes
, req
)) {
1165 return tevent_req_post(req
, ev
);
1168 bytes
[talloc_get_size(bytes
)-1] = 4;
1169 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname_dst
,
1170 strlen(fname_dst
)+1, NULL
);
1171 if (tevent_req_nomem(bytes
, req
)) {
1172 return tevent_req_post(req
, ev
);
1175 subreq
= cli_smb_send(state
, ev
, cli
, SMBmv
, additional_flags
,
1177 1, state
->vwv
, talloc_get_size(bytes
), bytes
);
1178 if (tevent_req_nomem(subreq
, req
)) {
1179 return tevent_req_post(req
, ev
);
1181 tevent_req_set_callback(subreq
, cli_rename_done
, req
);
1185 static void cli_rename_done(struct tevent_req
*subreq
)
1187 struct tevent_req
*req
= tevent_req_callback_data(
1188 subreq
, struct tevent_req
);
1191 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
1192 TALLOC_FREE(subreq
);
1193 if (tevent_req_nterror(req
, status
)) {
1196 tevent_req_done(req
);
1199 NTSTATUS
cli_rename_recv(struct tevent_req
*req
)
1201 return tevent_req_simple_recv_ntstatus(req
);
1204 NTSTATUS
cli_rename(struct cli_state
*cli
, const char *fname_src
, const char *fname_dst
)
1206 TALLOC_CTX
*frame
= NULL
;
1207 struct tevent_context
*ev
;
1208 struct tevent_req
*req
;
1209 NTSTATUS status
= NT_STATUS_OK
;
1211 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
1212 return cli_smb2_rename(cli
,
1217 frame
= talloc_stackframe();
1219 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1221 * Can't use sync call while an async call is in flight
1223 status
= NT_STATUS_INVALID_PARAMETER
;
1227 ev
= samba_tevent_context_init(frame
);
1229 status
= NT_STATUS_NO_MEMORY
;
1233 req
= cli_rename_send(frame
, ev
, cli
, fname_src
, fname_dst
);
1235 status
= NT_STATUS_NO_MEMORY
;
1239 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
1243 status
= cli_rename_recv(req
);
1250 /****************************************************************************
1252 ****************************************************************************/
1254 static void cli_ntrename_internal_done(struct tevent_req
*subreq
);
1256 struct cli_ntrename_internal_state
{
1260 static struct tevent_req
*cli_ntrename_internal_send(TALLOC_CTX
*mem_ctx
,
1261 struct tevent_context
*ev
,
1262 struct cli_state
*cli
,
1263 const char *fname_src
,
1264 const char *fname_dst
,
1265 uint16_t rename_flag
)
1267 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1268 struct cli_ntrename_internal_state
*state
= NULL
;
1269 uint8_t additional_flags
= 0;
1270 uint16_t additional_flags2
= 0;
1271 uint8_t *bytes
= NULL
;
1273 req
= tevent_req_create(mem_ctx
, &state
,
1274 struct cli_ntrename_internal_state
);
1279 SSVAL(state
->vwv
+0, 0 ,FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_DIRECTORY
);
1280 SSVAL(state
->vwv
+1, 0, rename_flag
);
1282 bytes
= talloc_array(state
, uint8_t, 1);
1283 if (tevent_req_nomem(bytes
, req
)) {
1284 return tevent_req_post(req
, ev
);
1287 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname_src
,
1288 strlen(fname_src
)+1, NULL
);
1289 if (tevent_req_nomem(bytes
, req
)) {
1290 return tevent_req_post(req
, ev
);
1293 if (clistr_is_previous_version_path(fname_src
)) {
1294 additional_flags2
= FLAGS2_REPARSE_PATH
;
1297 bytes
= talloc_realloc(state
, bytes
, uint8_t,
1298 talloc_get_size(bytes
)+1);
1299 if (tevent_req_nomem(bytes
, req
)) {
1300 return tevent_req_post(req
, ev
);
1303 bytes
[talloc_get_size(bytes
)-1] = 4;
1304 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname_dst
,
1305 strlen(fname_dst
)+1, NULL
);
1306 if (tevent_req_nomem(bytes
, req
)) {
1307 return tevent_req_post(req
, ev
);
1310 subreq
= cli_smb_send(state
, ev
, cli
, SMBntrename
, additional_flags
,
1312 4, state
->vwv
, talloc_get_size(bytes
), bytes
);
1313 if (tevent_req_nomem(subreq
, req
)) {
1314 return tevent_req_post(req
, ev
);
1316 tevent_req_set_callback(subreq
, cli_ntrename_internal_done
, req
);
1320 static void cli_ntrename_internal_done(struct tevent_req
*subreq
)
1322 struct tevent_req
*req
= tevent_req_callback_data(
1323 subreq
, struct tevent_req
);
1326 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
1327 TALLOC_FREE(subreq
);
1328 if (tevent_req_nterror(req
, status
)) {
1331 tevent_req_done(req
);
1334 static NTSTATUS
cli_ntrename_internal_recv(struct tevent_req
*req
)
1336 return tevent_req_simple_recv_ntstatus(req
);
1339 struct tevent_req
*cli_ntrename_send(TALLOC_CTX
*mem_ctx
,
1340 struct tevent_context
*ev
,
1341 struct cli_state
*cli
,
1342 const char *fname_src
,
1343 const char *fname_dst
)
1345 return cli_ntrename_internal_send(mem_ctx
,
1350 RENAME_FLAG_RENAME
);
1353 NTSTATUS
cli_ntrename_recv(struct tevent_req
*req
)
1355 return cli_ntrename_internal_recv(req
);
1358 NTSTATUS
cli_ntrename(struct cli_state
*cli
, const char *fname_src
, const char *fname_dst
)
1360 TALLOC_CTX
*frame
= talloc_stackframe();
1361 struct tevent_context
*ev
;
1362 struct tevent_req
*req
;
1363 NTSTATUS status
= NT_STATUS_OK
;
1365 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1367 * Can't use sync call while an async call is in flight
1369 status
= NT_STATUS_INVALID_PARAMETER
;
1373 ev
= samba_tevent_context_init(frame
);
1375 status
= NT_STATUS_NO_MEMORY
;
1379 req
= cli_ntrename_send(frame
, ev
, cli
, fname_src
, fname_dst
);
1381 status
= NT_STATUS_NO_MEMORY
;
1385 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
1389 status
= cli_ntrename_recv(req
);
1396 /****************************************************************************
1398 ****************************************************************************/
1400 struct tevent_req
*cli_nt_hardlink_send(TALLOC_CTX
*mem_ctx
,
1401 struct tevent_context
*ev
,
1402 struct cli_state
*cli
,
1403 const char *fname_src
,
1404 const char *fname_dst
)
1406 return cli_ntrename_internal_send(mem_ctx
,
1411 RENAME_FLAG_HARD_LINK
);
1414 NTSTATUS
cli_nt_hardlink_recv(struct tevent_req
*req
)
1416 return cli_ntrename_internal_recv(req
);
1419 NTSTATUS
cli_nt_hardlink(struct cli_state
*cli
, const char *fname_src
, const char *fname_dst
)
1421 TALLOC_CTX
*frame
= talloc_stackframe();
1422 struct tevent_context
*ev
;
1423 struct tevent_req
*req
;
1424 NTSTATUS status
= NT_STATUS_OK
;
1426 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1428 * Can't use sync call while an async call is in flight
1430 status
= NT_STATUS_INVALID_PARAMETER
;
1434 ev
= samba_tevent_context_init(frame
);
1436 status
= NT_STATUS_NO_MEMORY
;
1440 req
= cli_nt_hardlink_send(frame
, ev
, cli
, fname_src
, fname_dst
);
1442 status
= NT_STATUS_NO_MEMORY
;
1446 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
1450 status
= cli_nt_hardlink_recv(req
);
1457 /****************************************************************************
1459 ****************************************************************************/
1461 static void cli_unlink_done(struct tevent_req
*subreq
);
1463 struct cli_unlink_state
{
1467 struct tevent_req
*cli_unlink_send(TALLOC_CTX
*mem_ctx
,
1468 struct tevent_context
*ev
,
1469 struct cli_state
*cli
,
1471 uint16_t mayhave_attrs
)
1473 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1474 struct cli_unlink_state
*state
= NULL
;
1475 uint8_t additional_flags
= 0;
1476 uint16_t additional_flags2
= 0;
1477 uint8_t *bytes
= NULL
;
1479 req
= tevent_req_create(mem_ctx
, &state
, struct cli_unlink_state
);
1484 SSVAL(state
->vwv
+0, 0, mayhave_attrs
);
1486 bytes
= talloc_array(state
, uint8_t, 1);
1487 if (tevent_req_nomem(bytes
, req
)) {
1488 return tevent_req_post(req
, ev
);
1491 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname
,
1492 strlen(fname
)+1, NULL
);
1494 if (tevent_req_nomem(bytes
, req
)) {
1495 return tevent_req_post(req
, ev
);
1498 if (clistr_is_previous_version_path(fname
)) {
1499 additional_flags2
= FLAGS2_REPARSE_PATH
;
1502 subreq
= cli_smb_send(state
, ev
, cli
, SMBunlink
, additional_flags
,
1504 1, state
->vwv
, talloc_get_size(bytes
), bytes
);
1505 if (tevent_req_nomem(subreq
, req
)) {
1506 return tevent_req_post(req
, ev
);
1508 tevent_req_set_callback(subreq
, cli_unlink_done
, req
);
1512 static void cli_unlink_done(struct tevent_req
*subreq
)
1514 struct tevent_req
*req
= tevent_req_callback_data(
1515 subreq
, struct tevent_req
);
1518 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
1519 TALLOC_FREE(subreq
);
1520 if (tevent_req_nterror(req
, status
)) {
1523 tevent_req_done(req
);
1526 NTSTATUS
cli_unlink_recv(struct tevent_req
*req
)
1528 return tevent_req_simple_recv_ntstatus(req
);
1531 NTSTATUS
cli_unlink(struct cli_state
*cli
, const char *fname
, uint16_t mayhave_attrs
)
1533 TALLOC_CTX
*frame
= NULL
;
1534 struct tevent_context
*ev
;
1535 struct tevent_req
*req
;
1536 NTSTATUS status
= NT_STATUS_OK
;
1538 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
1539 return cli_smb2_unlink(cli
, fname
);
1542 frame
= talloc_stackframe();
1544 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1546 * Can't use sync call while an async call is in flight
1548 status
= NT_STATUS_INVALID_PARAMETER
;
1552 ev
= samba_tevent_context_init(frame
);
1554 status
= NT_STATUS_NO_MEMORY
;
1558 req
= cli_unlink_send(frame
, ev
, cli
, fname
, mayhave_attrs
);
1560 status
= NT_STATUS_NO_MEMORY
;
1564 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
1568 status
= cli_unlink_recv(req
);
1575 /****************************************************************************
1577 ****************************************************************************/
1579 static void cli_mkdir_done(struct tevent_req
*subreq
);
1581 struct cli_mkdir_state
{
1585 struct tevent_req
*cli_mkdir_send(TALLOC_CTX
*mem_ctx
,
1586 struct tevent_context
*ev
,
1587 struct cli_state
*cli
,
1590 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1591 struct cli_mkdir_state
*state
= NULL
;
1592 uint8_t additional_flags
= 0;
1593 uint16_t additional_flags2
= 0;
1594 uint8_t *bytes
= NULL
;
1596 req
= tevent_req_create(mem_ctx
, &state
, struct cli_mkdir_state
);
1601 bytes
= talloc_array(state
, uint8_t, 1);
1602 if (tevent_req_nomem(bytes
, req
)) {
1603 return tevent_req_post(req
, ev
);
1606 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), dname
,
1607 strlen(dname
)+1, NULL
);
1609 if (tevent_req_nomem(bytes
, req
)) {
1610 return tevent_req_post(req
, ev
);
1613 if (clistr_is_previous_version_path(dname
)) {
1614 additional_flags2
= FLAGS2_REPARSE_PATH
;
1617 subreq
= cli_smb_send(state
, ev
, cli
, SMBmkdir
, additional_flags
,
1619 0, NULL
, talloc_get_size(bytes
), bytes
);
1620 if (tevent_req_nomem(subreq
, req
)) {
1621 return tevent_req_post(req
, ev
);
1623 tevent_req_set_callback(subreq
, cli_mkdir_done
, req
);
1627 static void cli_mkdir_done(struct tevent_req
*subreq
)
1629 struct tevent_req
*req
= tevent_req_callback_data(
1630 subreq
, struct tevent_req
);
1633 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
1634 TALLOC_FREE(subreq
);
1635 if (tevent_req_nterror(req
, status
)) {
1638 tevent_req_done(req
);
1641 NTSTATUS
cli_mkdir_recv(struct tevent_req
*req
)
1643 return tevent_req_simple_recv_ntstatus(req
);
1646 NTSTATUS
cli_mkdir(struct cli_state
*cli
, const char *dname
)
1648 TALLOC_CTX
*frame
= NULL
;
1649 struct tevent_context
*ev
;
1650 struct tevent_req
*req
;
1651 NTSTATUS status
= NT_STATUS_OK
;
1653 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
1654 return cli_smb2_mkdir(cli
, dname
);
1657 frame
= talloc_stackframe();
1659 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1661 * Can't use sync call while an async call is in flight
1663 status
= NT_STATUS_INVALID_PARAMETER
;
1667 ev
= samba_tevent_context_init(frame
);
1669 status
= NT_STATUS_NO_MEMORY
;
1673 req
= cli_mkdir_send(frame
, ev
, cli
, dname
);
1675 status
= NT_STATUS_NO_MEMORY
;
1679 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
1683 status
= cli_mkdir_recv(req
);
1690 /****************************************************************************
1692 ****************************************************************************/
1694 static void cli_rmdir_done(struct tevent_req
*subreq
);
1696 struct cli_rmdir_state
{
1700 struct tevent_req
*cli_rmdir_send(TALLOC_CTX
*mem_ctx
,
1701 struct tevent_context
*ev
,
1702 struct cli_state
*cli
,
1705 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1706 struct cli_rmdir_state
*state
= NULL
;
1707 uint8_t additional_flags
= 0;
1708 uint8_t *bytes
= NULL
;
1710 req
= tevent_req_create(mem_ctx
, &state
, struct cli_rmdir_state
);
1715 bytes
= talloc_array(state
, uint8_t, 1);
1716 if (tevent_req_nomem(bytes
, req
)) {
1717 return tevent_req_post(req
, ev
);
1720 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), dname
,
1721 strlen(dname
)+1, NULL
);
1723 if (tevent_req_nomem(bytes
, req
)) {
1724 return tevent_req_post(req
, ev
);
1727 subreq
= cli_smb_send(state
, ev
, cli
, SMBrmdir
, additional_flags
, 0,
1728 0, NULL
, talloc_get_size(bytes
), bytes
);
1729 if (tevent_req_nomem(subreq
, req
)) {
1730 return tevent_req_post(req
, ev
);
1732 tevent_req_set_callback(subreq
, cli_rmdir_done
, req
);
1736 static void cli_rmdir_done(struct tevent_req
*subreq
)
1738 struct tevent_req
*req
= tevent_req_callback_data(
1739 subreq
, struct tevent_req
);
1742 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
1743 TALLOC_FREE(subreq
);
1744 if (tevent_req_nterror(req
, status
)) {
1747 tevent_req_done(req
);
1750 NTSTATUS
cli_rmdir_recv(struct tevent_req
*req
)
1752 return tevent_req_simple_recv_ntstatus(req
);
1755 NTSTATUS
cli_rmdir(struct cli_state
*cli
, const char *dname
)
1757 TALLOC_CTX
*frame
= NULL
;
1758 struct tevent_context
*ev
;
1759 struct tevent_req
*req
;
1760 NTSTATUS status
= NT_STATUS_OK
;
1762 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
1763 return cli_smb2_rmdir(cli
, dname
);
1766 frame
= talloc_stackframe();
1768 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1770 * Can't use sync call while an async call is in flight
1772 status
= NT_STATUS_INVALID_PARAMETER
;
1776 ev
= samba_tevent_context_init(frame
);
1778 status
= NT_STATUS_NO_MEMORY
;
1782 req
= cli_rmdir_send(frame
, ev
, cli
, dname
);
1784 status
= NT_STATUS_NO_MEMORY
;
1788 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
1792 status
= cli_rmdir_recv(req
);
1799 /****************************************************************************
1800 Set or clear the delete on close flag.
1801 ****************************************************************************/
1809 static void cli_nt_delete_on_close_done(struct tevent_req
*subreq
)
1811 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, NULL
, 0, NULL
,
1812 NULL
, 0, NULL
, NULL
, 0, NULL
);
1813 tevent_req_simple_finish_ntstatus(subreq
, status
);
1816 struct tevent_req
*cli_nt_delete_on_close_send(TALLOC_CTX
*mem_ctx
,
1817 struct tevent_context
*ev
,
1818 struct cli_state
*cli
,
1822 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1823 struct doc_state
*state
= NULL
;
1825 req
= tevent_req_create(mem_ctx
, &state
, struct doc_state
);
1830 /* Setup setup word. */
1831 SSVAL(&state
->setup
, 0, TRANSACT2_SETFILEINFO
);
1833 /* Setup param array. */
1834 SSVAL(state
->param
,0,fnum
);
1835 SSVAL(state
->param
,2,SMB_SET_FILE_DISPOSITION_INFO
);
1837 /* Setup data array. */
1838 SCVAL(&state
->data
[0], 0, flag
? 1 : 0);
1840 subreq
= cli_trans_send(state
, /* mem ctx. */
1841 ev
, /* event ctx. */
1842 cli
, /* cli_state. */
1843 0, /* additional_flags2 */
1844 SMBtrans2
, /* cmd. */
1845 NULL
, /* pipe name. */
1849 &state
->setup
, /* setup. */
1850 1, /* num setup uint16_t words. */
1851 0, /* max returned setup. */
1852 state
->param
, /* param. */
1854 2, /* max returned param. */
1855 state
->data
, /* data. */
1857 0); /* max returned data. */
1859 if (tevent_req_nomem(subreq
, req
)) {
1860 return tevent_req_post(req
, ev
);
1862 tevent_req_set_callback(subreq
, cli_nt_delete_on_close_done
, req
);
1866 NTSTATUS
cli_nt_delete_on_close_recv(struct tevent_req
*req
)
1868 return tevent_req_simple_recv_ntstatus(req
);
1871 NTSTATUS
cli_nt_delete_on_close(struct cli_state
*cli
, uint16_t fnum
, bool flag
)
1873 TALLOC_CTX
*frame
= talloc_stackframe();
1874 struct tevent_context
*ev
= NULL
;
1875 struct tevent_req
*req
= NULL
;
1876 NTSTATUS status
= NT_STATUS_OK
;
1878 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1880 * Can't use sync call while an async call is in flight
1882 status
= NT_STATUS_INVALID_PARAMETER
;
1886 ev
= samba_tevent_context_init(frame
);
1888 status
= NT_STATUS_NO_MEMORY
;
1892 req
= cli_nt_delete_on_close_send(frame
,
1898 status
= NT_STATUS_NO_MEMORY
;
1902 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
1906 status
= cli_nt_delete_on_close_recv(req
);
1913 struct cli_ntcreate1_state
{
1916 struct smb_create_returns cr
;
1917 struct tevent_req
*subreq
;
1920 static void cli_ntcreate1_done(struct tevent_req
*subreq
);
1921 static bool cli_ntcreate1_cancel(struct tevent_req
*req
);
1923 static struct tevent_req
*cli_ntcreate1_send(TALLOC_CTX
*mem_ctx
,
1924 struct tevent_context
*ev
,
1925 struct cli_state
*cli
,
1927 uint32_t CreatFlags
,
1928 uint32_t DesiredAccess
,
1929 uint32_t FileAttributes
,
1930 uint32_t ShareAccess
,
1931 uint32_t CreateDisposition
,
1932 uint32_t CreateOptions
,
1933 uint8_t SecurityFlags
)
1935 struct tevent_req
*req
, *subreq
;
1936 struct cli_ntcreate1_state
*state
;
1939 size_t converted_len
;
1941 req
= tevent_req_create(mem_ctx
, &state
, struct cli_ntcreate1_state
);
1948 SCVAL(vwv
+0, 0, 0xFF);
1953 if (cli
->use_oplocks
) {
1954 CreatFlags
|= (REQUEST_OPLOCK
|REQUEST_BATCH_OPLOCK
);
1956 SIVAL(vwv
+3, 1, CreatFlags
);
1957 SIVAL(vwv
+5, 1, 0x0); /* RootDirectoryFid */
1958 SIVAL(vwv
+7, 1, DesiredAccess
);
1959 SIVAL(vwv
+9, 1, 0x0); /* AllocationSize */
1960 SIVAL(vwv
+11, 1, 0x0); /* AllocationSize */
1961 SIVAL(vwv
+13, 1, FileAttributes
);
1962 SIVAL(vwv
+15, 1, ShareAccess
);
1963 SIVAL(vwv
+17, 1, CreateDisposition
);
1964 SIVAL(vwv
+19, 1, CreateOptions
|
1965 (cli
->backup_intent
? FILE_OPEN_FOR_BACKUP_INTENT
: 0));
1966 SIVAL(vwv
+21, 1, 0x02); /* ImpersonationLevel */
1967 SCVAL(vwv
+23, 1, SecurityFlags
);
1969 bytes
= talloc_array(state
, uint8_t, 0);
1970 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
),
1971 fname
, strlen(fname
)+1,
1974 /* sigh. this copes with broken netapp filer behaviour */
1975 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), "", 1, NULL
);
1977 if (tevent_req_nomem(bytes
, req
)) {
1978 return tevent_req_post(req
, ev
);
1981 SSVAL(vwv
+2, 1, converted_len
);
1983 subreq
= cli_smb_send(state
, ev
, cli
, SMBntcreateX
, 0, 0, 24, vwv
,
1984 talloc_get_size(bytes
), bytes
);
1985 if (tevent_req_nomem(subreq
, req
)) {
1986 return tevent_req_post(req
, ev
);
1988 tevent_req_set_callback(subreq
, cli_ntcreate1_done
, req
);
1990 state
->subreq
= subreq
;
1991 tevent_req_set_cancel_fn(req
, cli_ntcreate1_cancel
);
1996 static void cli_ntcreate1_done(struct tevent_req
*subreq
)
1998 struct tevent_req
*req
= tevent_req_callback_data(
1999 subreq
, struct tevent_req
);
2000 struct cli_ntcreate1_state
*state
= tevent_req_data(
2001 req
, struct cli_ntcreate1_state
);
2008 status
= cli_smb_recv(subreq
, state
, NULL
, 34, &wct
, &vwv
,
2009 &num_bytes
, &bytes
);
2010 TALLOC_FREE(subreq
);
2011 if (tevent_req_nterror(req
, status
)) {
2014 state
->cr
.oplock_level
= CVAL(vwv
+2, 0);
2015 state
->fnum
= SVAL(vwv
+2, 1);
2016 state
->cr
.create_action
= IVAL(vwv
+3, 1);
2017 state
->cr
.creation_time
= BVAL(vwv
+5, 1);
2018 state
->cr
.last_access_time
= BVAL(vwv
+9, 1);
2019 state
->cr
.last_write_time
= BVAL(vwv
+13, 1);
2020 state
->cr
.change_time
= BVAL(vwv
+17, 1);
2021 state
->cr
.file_attributes
= IVAL(vwv
+21, 1);
2022 state
->cr
.allocation_size
= BVAL(vwv
+23, 1);
2023 state
->cr
.end_of_file
= BVAL(vwv
+27, 1);
2025 tevent_req_done(req
);
2028 static bool cli_ntcreate1_cancel(struct tevent_req
*req
)
2030 struct cli_ntcreate1_state
*state
= tevent_req_data(
2031 req
, struct cli_ntcreate1_state
);
2032 return tevent_req_cancel(state
->subreq
);
2035 static NTSTATUS
cli_ntcreate1_recv(struct tevent_req
*req
,
2037 struct smb_create_returns
*cr
)
2039 struct cli_ntcreate1_state
*state
= tevent_req_data(
2040 req
, struct cli_ntcreate1_state
);
2043 if (tevent_req_is_nterror(req
, &status
)) {
2046 *pfnum
= state
->fnum
;
2050 return NT_STATUS_OK
;
2053 struct cli_ntcreate_state
{
2054 NTSTATUS (*recv
)(struct tevent_req
*req
, uint16_t *fnum
,
2055 struct smb_create_returns
*cr
);
2056 struct smb_create_returns cr
;
2058 struct tevent_req
*subreq
;
2061 static void cli_ntcreate_done(struct tevent_req
*subreq
);
2062 static bool cli_ntcreate_cancel(struct tevent_req
*req
);
2064 struct tevent_req
*cli_ntcreate_send(TALLOC_CTX
*mem_ctx
,
2065 struct tevent_context
*ev
,
2066 struct cli_state
*cli
,
2068 uint32_t create_flags
,
2069 uint32_t desired_access
,
2070 uint32_t file_attributes
,
2071 uint32_t share_access
,
2072 uint32_t create_disposition
,
2073 uint32_t create_options
,
2074 uint8_t security_flags
)
2076 struct tevent_req
*req
, *subreq
;
2077 struct cli_ntcreate_state
*state
;
2079 req
= tevent_req_create(mem_ctx
, &state
, struct cli_ntcreate_state
);
2084 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
2085 state
->recv
= cli_smb2_create_fnum_recv
;
2087 if (cli
->use_oplocks
) {
2088 create_flags
|= REQUEST_OPLOCK
|REQUEST_BATCH_OPLOCK
;
2091 subreq
= cli_smb2_create_fnum_send(
2092 state
, ev
, cli
, fname
, create_flags
, desired_access
,
2093 file_attributes
, share_access
, create_disposition
,
2096 state
->recv
= cli_ntcreate1_recv
;
2097 subreq
= cli_ntcreate1_send(
2098 state
, ev
, cli
, fname
, create_flags
, desired_access
,
2099 file_attributes
, share_access
, create_disposition
,
2100 create_options
, security_flags
);
2102 if (tevent_req_nomem(subreq
, req
)) {
2103 return tevent_req_post(req
, ev
);
2105 tevent_req_set_callback(subreq
, cli_ntcreate_done
, req
);
2107 state
->subreq
= subreq
;
2108 tevent_req_set_cancel_fn(req
, cli_ntcreate_cancel
);
2113 static void cli_ntcreate_done(struct tevent_req
*subreq
)
2115 struct tevent_req
*req
= tevent_req_callback_data(
2116 subreq
, struct tevent_req
);
2117 struct cli_ntcreate_state
*state
= tevent_req_data(
2118 req
, struct cli_ntcreate_state
);
2121 status
= state
->recv(subreq
, &state
->fnum
, &state
->cr
);
2122 TALLOC_FREE(subreq
);
2123 if (tevent_req_nterror(req
, status
)) {
2126 tevent_req_done(req
);
2129 static bool cli_ntcreate_cancel(struct tevent_req
*req
)
2131 struct cli_ntcreate_state
*state
= tevent_req_data(
2132 req
, struct cli_ntcreate_state
);
2133 return tevent_req_cancel(state
->subreq
);
2136 NTSTATUS
cli_ntcreate_recv(struct tevent_req
*req
, uint16_t *fnum
,
2137 struct smb_create_returns
*cr
)
2139 struct cli_ntcreate_state
*state
= tevent_req_data(
2140 req
, struct cli_ntcreate_state
);
2143 if (tevent_req_is_nterror(req
, &status
)) {
2147 *fnum
= state
->fnum
;
2152 return NT_STATUS_OK
;
2155 NTSTATUS
cli_ntcreate(struct cli_state
*cli
,
2157 uint32_t CreatFlags
,
2158 uint32_t DesiredAccess
,
2159 uint32_t FileAttributes
,
2160 uint32_t ShareAccess
,
2161 uint32_t CreateDisposition
,
2162 uint32_t CreateOptions
,
2163 uint8_t SecurityFlags
,
2165 struct smb_create_returns
*cr
)
2167 TALLOC_CTX
*frame
= talloc_stackframe();
2168 struct tevent_context
*ev
;
2169 struct tevent_req
*req
;
2170 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
2172 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
2174 * Can't use sync call while an async call is in flight
2176 status
= NT_STATUS_INVALID_PARAMETER
;
2180 ev
= samba_tevent_context_init(frame
);
2185 req
= cli_ntcreate_send(frame
, ev
, cli
, fname
, CreatFlags
,
2186 DesiredAccess
, FileAttributes
, ShareAccess
,
2187 CreateDisposition
, CreateOptions
,
2193 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
2197 status
= cli_ntcreate_recv(req
, pfid
, cr
);
2203 struct cli_nttrans_create_state
{
2205 struct smb_create_returns cr
;
2208 static void cli_nttrans_create_done(struct tevent_req
*subreq
);
2210 struct tevent_req
*cli_nttrans_create_send(TALLOC_CTX
*mem_ctx
,
2211 struct tevent_context
*ev
,
2212 struct cli_state
*cli
,
2214 uint32_t CreatFlags
,
2215 uint32_t DesiredAccess
,
2216 uint32_t FileAttributes
,
2217 uint32_t ShareAccess
,
2218 uint32_t CreateDisposition
,
2219 uint32_t CreateOptions
,
2220 uint8_t SecurityFlags
,
2221 struct security_descriptor
*secdesc
,
2222 struct ea_struct
*eas
,
2225 struct tevent_req
*req
, *subreq
;
2226 struct cli_nttrans_create_state
*state
;
2228 uint8_t *secdesc_buf
;
2231 size_t converted_len
;
2233 req
= tevent_req_create(mem_ctx
,
2234 &state
, struct cli_nttrans_create_state
);
2239 if (secdesc
!= NULL
) {
2240 status
= marshall_sec_desc(talloc_tos(), secdesc
,
2241 &secdesc_buf
, &secdesc_len
);
2242 if (tevent_req_nterror(req
, status
)) {
2243 DEBUG(10, ("marshall_sec_desc failed: %s\n",
2244 nt_errstr(status
)));
2245 return tevent_req_post(req
, ev
);
2256 tevent_req_nterror(req
, NT_STATUS_NOT_IMPLEMENTED
);
2257 return tevent_req_post(req
, ev
);
2260 param
= talloc_array(state
, uint8_t, 53);
2261 if (tevent_req_nomem(param
, req
)) {
2262 return tevent_req_post(req
, ev
);
2265 param
= trans2_bytes_push_str(param
, smbXcli_conn_use_unicode(cli
->conn
),
2266 fname
, strlen(fname
),
2268 if (tevent_req_nomem(param
, req
)) {
2269 return tevent_req_post(req
, ev
);
2272 SIVAL(param
, 0, CreatFlags
);
2273 SIVAL(param
, 4, 0x0); /* RootDirectoryFid */
2274 SIVAL(param
, 8, DesiredAccess
);
2275 SIVAL(param
, 12, 0x0); /* AllocationSize */
2276 SIVAL(param
, 16, 0x0); /* AllocationSize */
2277 SIVAL(param
, 20, FileAttributes
);
2278 SIVAL(param
, 24, ShareAccess
);
2279 SIVAL(param
, 28, CreateDisposition
);
2280 SIVAL(param
, 32, CreateOptions
|
2281 (cli
->backup_intent
? FILE_OPEN_FOR_BACKUP_INTENT
: 0));
2282 SIVAL(param
, 36, secdesc_len
);
2283 SIVAL(param
, 40, 0); /* EA length*/
2284 SIVAL(param
, 44, converted_len
);
2285 SIVAL(param
, 48, 0x02); /* ImpersonationLevel */
2286 SCVAL(param
, 52, SecurityFlags
);
2288 subreq
= cli_trans_send(state
, ev
, cli
,
2289 0, /* additional_flags2 */
2291 NULL
, -1, /* name, fid */
2292 NT_TRANSACT_CREATE
, 0,
2293 NULL
, 0, 0, /* setup */
2294 param
, talloc_get_size(param
), 128, /* param */
2295 secdesc_buf
, secdesc_len
, 0); /* data */
2296 if (tevent_req_nomem(subreq
, req
)) {
2297 return tevent_req_post(req
, ev
);
2299 tevent_req_set_callback(subreq
, cli_nttrans_create_done
, req
);
2303 static void cli_nttrans_create_done(struct tevent_req
*subreq
)
2305 struct tevent_req
*req
= tevent_req_callback_data(
2306 subreq
, struct tevent_req
);
2307 struct cli_nttrans_create_state
*state
= tevent_req_data(
2308 req
, struct cli_nttrans_create_state
);
2313 status
= cli_trans_recv(subreq
, talloc_tos(), NULL
,
2314 NULL
, 0, NULL
, /* rsetup */
2315 ¶m
, 69, &num_param
,
2317 if (tevent_req_nterror(req
, status
)) {
2320 state
->cr
.oplock_level
= CVAL(param
, 0);
2321 state
->fnum
= SVAL(param
, 2);
2322 state
->cr
.create_action
= IVAL(param
, 4);
2323 state
->cr
.creation_time
= BVAL(param
, 12);
2324 state
->cr
.last_access_time
= BVAL(param
, 20);
2325 state
->cr
.last_write_time
= BVAL(param
, 28);
2326 state
->cr
.change_time
= BVAL(param
, 36);
2327 state
->cr
.file_attributes
= IVAL(param
, 44);
2328 state
->cr
.allocation_size
= BVAL(param
, 48);
2329 state
->cr
.end_of_file
= BVAL(param
, 56);
2332 tevent_req_done(req
);
2335 NTSTATUS
cli_nttrans_create_recv(struct tevent_req
*req
,
2337 struct smb_create_returns
*cr
)
2339 struct cli_nttrans_create_state
*state
= tevent_req_data(
2340 req
, struct cli_nttrans_create_state
);
2343 if (tevent_req_is_nterror(req
, &status
)) {
2346 *fnum
= state
->fnum
;
2350 return NT_STATUS_OK
;
2353 NTSTATUS
cli_nttrans_create(struct cli_state
*cli
,
2355 uint32_t CreatFlags
,
2356 uint32_t DesiredAccess
,
2357 uint32_t FileAttributes
,
2358 uint32_t ShareAccess
,
2359 uint32_t CreateDisposition
,
2360 uint32_t CreateOptions
,
2361 uint8_t SecurityFlags
,
2362 struct security_descriptor
*secdesc
,
2363 struct ea_struct
*eas
,
2366 struct smb_create_returns
*cr
)
2368 TALLOC_CTX
*frame
= talloc_stackframe();
2369 struct tevent_context
*ev
;
2370 struct tevent_req
*req
;
2371 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
2373 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
2375 * Can't use sync call while an async call is in flight
2377 status
= NT_STATUS_INVALID_PARAMETER
;
2380 ev
= samba_tevent_context_init(frame
);
2384 req
= cli_nttrans_create_send(frame
, ev
, cli
, fname
, CreatFlags
,
2385 DesiredAccess
, FileAttributes
,
2386 ShareAccess
, CreateDisposition
,
2387 CreateOptions
, SecurityFlags
,
2388 secdesc
, eas
, num_eas
);
2392 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
2395 status
= cli_nttrans_create_recv(req
, pfid
, cr
);
2401 /****************************************************************************
2403 WARNING: if you open with O_WRONLY then getattrE won't work!
2404 ****************************************************************************/
2406 struct cli_openx_state
{
2413 static void cli_openx_done(struct tevent_req
*subreq
);
2415 struct tevent_req
*cli_openx_create(TALLOC_CTX
*mem_ctx
,
2416 struct tevent_context
*ev
,
2417 struct cli_state
*cli
, const char *fname
,
2418 int flags
, int share_mode
,
2419 struct tevent_req
**psmbreq
)
2421 struct tevent_req
*req
, *subreq
;
2422 struct cli_openx_state
*state
;
2424 unsigned accessmode
;
2425 uint8_t additional_flags
;
2428 req
= tevent_req_create(mem_ctx
, &state
, struct cli_openx_state
);
2434 if (flags
& O_CREAT
) {
2437 if (!(flags
& O_EXCL
)) {
2438 if (flags
& O_TRUNC
)
2444 accessmode
= (share_mode
<<4);
2446 if ((flags
& O_ACCMODE
) == O_RDWR
) {
2448 } else if ((flags
& O_ACCMODE
) == O_WRONLY
) {
2453 if ((flags
& O_SYNC
) == O_SYNC
) {
2454 accessmode
|= (1<<14);
2458 if (share_mode
== DENY_FCB
) {
2462 SCVAL(state
->vwv
+ 0, 0, 0xFF);
2463 SCVAL(state
->vwv
+ 0, 1, 0);
2464 SSVAL(state
->vwv
+ 1, 0, 0);
2465 SSVAL(state
->vwv
+ 2, 0, 0); /* no additional info */
2466 SSVAL(state
->vwv
+ 3, 0, accessmode
);
2467 SSVAL(state
->vwv
+ 4, 0, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2468 SSVAL(state
->vwv
+ 5, 0, 0);
2469 SIVAL(state
->vwv
+ 6, 0, 0);
2470 SSVAL(state
->vwv
+ 8, 0, openfn
);
2471 SIVAL(state
->vwv
+ 9, 0, 0);
2472 SIVAL(state
->vwv
+ 11, 0, 0);
2473 SIVAL(state
->vwv
+ 13, 0, 0);
2475 additional_flags
= 0;
2477 if (cli
->use_oplocks
) {
2478 /* if using oplocks then ask for a batch oplock via
2479 core and extended methods */
2481 FLAG_REQUEST_OPLOCK
|FLAG_REQUEST_BATCH_OPLOCK
;
2482 SSVAL(state
->vwv
+2, 0, SVAL(state
->vwv
+2, 0) | 6);
2485 bytes
= talloc_array(state
, uint8_t, 0);
2486 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname
,
2487 strlen(fname
)+1, NULL
);
2489 if (tevent_req_nomem(bytes
, req
)) {
2490 return tevent_req_post(req
, ev
);
2493 state
->bytes
.iov_base
= (void *)bytes
;
2494 state
->bytes
.iov_len
= talloc_get_size(bytes
);
2496 subreq
= cli_smb_req_create(state
, ev
, cli
, SMBopenX
, additional_flags
,
2497 0, 15, state
->vwv
, 1, &state
->bytes
);
2498 if (subreq
== NULL
) {
2502 tevent_req_set_callback(subreq
, cli_openx_done
, req
);
2507 struct tevent_req
*cli_openx_send(TALLOC_CTX
*mem_ctx
, struct tevent_context
*ev
,
2508 struct cli_state
*cli
, const char *fname
,
2509 int flags
, int share_mode
)
2511 struct tevent_req
*req
, *subreq
;
2514 req
= cli_openx_create(mem_ctx
, ev
, cli
, fname
, flags
, share_mode
,
2520 status
= smb1cli_req_chain_submit(&subreq
, 1);
2521 if (tevent_req_nterror(req
, status
)) {
2522 return tevent_req_post(req
, ev
);
2527 static void cli_openx_done(struct tevent_req
*subreq
)
2529 struct tevent_req
*req
= tevent_req_callback_data(
2530 subreq
, struct tevent_req
);
2531 struct cli_openx_state
*state
= tevent_req_data(
2532 req
, struct cli_openx_state
);
2537 status
= cli_smb_recv(subreq
, state
, NULL
, 3, &wct
, &vwv
, NULL
,
2539 TALLOC_FREE(subreq
);
2540 if (tevent_req_nterror(req
, status
)) {
2543 state
->fnum
= SVAL(vwv
+2, 0);
2544 tevent_req_done(req
);
2547 NTSTATUS
cli_openx_recv(struct tevent_req
*req
, uint16_t *pfnum
)
2549 struct cli_openx_state
*state
= tevent_req_data(
2550 req
, struct cli_openx_state
);
2553 if (tevent_req_is_nterror(req
, &status
)) {
2556 *pfnum
= state
->fnum
;
2557 return NT_STATUS_OK
;
2560 NTSTATUS
cli_openx(struct cli_state
*cli
, const char *fname
, int flags
,
2561 int share_mode
, uint16_t *pfnum
)
2563 TALLOC_CTX
*frame
= talloc_stackframe();
2564 struct tevent_context
*ev
;
2565 struct tevent_req
*req
;
2566 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
2568 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
2570 * Can't use sync call while an async call is in flight
2572 status
= NT_STATUS_INVALID_PARAMETER
;
2576 ev
= samba_tevent_context_init(frame
);
2581 req
= cli_openx_send(frame
, ev
, cli
, fname
, flags
, share_mode
);
2586 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
2590 status
= cli_openx_recv(req
, pfnum
);
2595 /****************************************************************************
2596 Synchronous wrapper function that does an NtCreateX open by preference
2597 and falls back to openX if this fails.
2598 ****************************************************************************/
2600 NTSTATUS
cli_open(struct cli_state
*cli
, const char *fname
, int flags
,
2601 int share_mode_in
, uint16_t *pfnum
)
2604 unsigned int openfn
= 0;
2605 unsigned int dos_deny
= 0;
2606 uint32_t access_mask
, share_mode
, create_disposition
, create_options
;
2607 struct smb_create_returns cr
;
2609 /* Do the initial mapping into OpenX parameters. */
2610 if (flags
& O_CREAT
) {
2613 if (!(flags
& O_EXCL
)) {
2614 if (flags
& O_TRUNC
)
2620 dos_deny
= (share_mode_in
<<4);
2622 if ((flags
& O_ACCMODE
) == O_RDWR
) {
2624 } else if ((flags
& O_ACCMODE
) == O_WRONLY
) {
2629 if ((flags
& O_SYNC
) == O_SYNC
) {
2630 dos_deny
|= (1<<14);
2634 if (share_mode_in
== DENY_FCB
) {
2639 /* Hmmm. This is what I think the above code
2640 should look like if it's using the constants
2643 if (flags
& O_CREAT
) {
2644 openfn
|= OPENX_FILE_CREATE_IF_NOT_EXIST
;
2646 if (!(flags
& O_EXCL
)) {
2647 if (flags
& O_TRUNC
)
2648 openfn
|= OPENX_FILE_EXISTS_TRUNCATE
;
2650 openfn
|= OPENX_FILE_EXISTS_OPEN
;
2653 dos_deny
= SET_DENY_MODE(share_mode_in
);
2655 if ((flags
& O_ACCMODE
) == O_RDWR
) {
2656 dos_deny
|= DOS_OPEN_RDWR
;
2657 } else if ((flags
& O_ACCMODE
) == O_WRONLY
) {
2658 dos_deny
|= DOS_OPEN_WRONLY
;
2662 if ((flags
& O_SYNC
) == O_SYNC
) {
2663 dos_deny
|= FILE_SYNC_OPENMODE
;
2667 if (share_mode_in
== DENY_FCB
) {
2672 if (!map_open_params_to_ntcreate(fname
, dos_deny
,
2673 openfn
, &access_mask
,
2674 &share_mode
, &create_disposition
,
2675 &create_options
, NULL
)) {
2679 status
= cli_ntcreate(cli
,
2691 /* Try and cope will all varients of "we don't do this call"
2692 and fall back to openX. */
2694 if (NT_STATUS_EQUAL(status
,NT_STATUS_NOT_IMPLEMENTED
) ||
2695 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_INFO_CLASS
) ||
2696 NT_STATUS_EQUAL(status
,NT_STATUS_PROCEDURE_NOT_FOUND
) ||
2697 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_LEVEL
) ||
2698 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_PARAMETER
) ||
2699 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_DEVICE_REQUEST
) ||
2700 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_DEVICE_STATE
) ||
2701 NT_STATUS_EQUAL(status
,NT_STATUS_CTL_FILE_NOT_SUPPORTED
) ||
2702 NT_STATUS_EQUAL(status
,NT_STATUS_UNSUCCESSFUL
)) {
2706 if (NT_STATUS_IS_OK(status
) &&
2707 (create_options
& FILE_NON_DIRECTORY_FILE
) &&
2708 (cr
.file_attributes
& FILE_ATTRIBUTE_DIRECTORY
))
2711 * Some (broken) servers return a valid handle
2712 * for directories even if FILE_NON_DIRECTORY_FILE
2713 * is set. Just close the handle and set the
2714 * error explicitly to NT_STATUS_FILE_IS_A_DIRECTORY.
2716 status
= cli_close(cli
, *pfnum
);
2717 if (!NT_STATUS_IS_OK(status
)) {
2720 status
= NT_STATUS_FILE_IS_A_DIRECTORY
;
2721 /* Set this so libsmbclient can retrieve it. */
2722 cli
->raw_status
= status
;
2729 return cli_openx(cli
, fname
, flags
, share_mode_in
, pfnum
);
2732 /****************************************************************************
2734 ****************************************************************************/
2736 struct cli_close_state
{
2740 static void cli_close_done(struct tevent_req
*subreq
);
2742 struct tevent_req
*cli_close_create(TALLOC_CTX
*mem_ctx
,
2743 struct tevent_context
*ev
,
2744 struct cli_state
*cli
,
2746 struct tevent_req
**psubreq
)
2748 struct tevent_req
*req
, *subreq
;
2749 struct cli_close_state
*state
;
2751 req
= tevent_req_create(mem_ctx
, &state
, struct cli_close_state
);
2756 SSVAL(state
->vwv
+0, 0, fnum
);
2757 SIVALS(state
->vwv
+1, 0, -1);
2759 subreq
= cli_smb_req_create(state
, ev
, cli
, SMBclose
, 0, 0,
2760 3, state
->vwv
, 0, NULL
);
2761 if (subreq
== NULL
) {
2765 tevent_req_set_callback(subreq
, cli_close_done
, req
);
2770 struct tevent_req
*cli_close_send(TALLOC_CTX
*mem_ctx
,
2771 struct tevent_context
*ev
,
2772 struct cli_state
*cli
,
2775 struct tevent_req
*req
, *subreq
;
2778 req
= cli_close_create(mem_ctx
, ev
, cli
, fnum
, &subreq
);
2783 status
= smb1cli_req_chain_submit(&subreq
, 1);
2784 if (tevent_req_nterror(req
, status
)) {
2785 return tevent_req_post(req
, ev
);
2790 static void cli_close_done(struct tevent_req
*subreq
)
2792 struct tevent_req
*req
= tevent_req_callback_data(
2793 subreq
, struct tevent_req
);
2796 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
2797 TALLOC_FREE(subreq
);
2798 if (tevent_req_nterror(req
, status
)) {
2801 tevent_req_done(req
);
2804 NTSTATUS
cli_close_recv(struct tevent_req
*req
)
2806 return tevent_req_simple_recv_ntstatus(req
);
2809 NTSTATUS
cli_close(struct cli_state
*cli
, uint16_t fnum
)
2811 TALLOC_CTX
*frame
= NULL
;
2812 struct tevent_context
*ev
;
2813 struct tevent_req
*req
;
2814 NTSTATUS status
= NT_STATUS_OK
;
2816 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
2817 return cli_smb2_close_fnum(cli
, fnum
);
2820 frame
= talloc_stackframe();
2822 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
2824 * Can't use sync call while an async call is in flight
2826 status
= NT_STATUS_INVALID_PARAMETER
;
2830 ev
= samba_tevent_context_init(frame
);
2832 status
= NT_STATUS_NO_MEMORY
;
2836 req
= cli_close_send(frame
, ev
, cli
, fnum
);
2838 status
= NT_STATUS_NO_MEMORY
;
2842 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
2846 status
= cli_close_recv(req
);
2852 /****************************************************************************
2853 Truncate a file to a specified size
2854 ****************************************************************************/
2856 struct ftrunc_state
{
2862 static void cli_ftruncate_done(struct tevent_req
*subreq
)
2864 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, NULL
, 0, NULL
,
2865 NULL
, 0, NULL
, NULL
, 0, NULL
);
2866 tevent_req_simple_finish_ntstatus(subreq
, status
);
2869 struct tevent_req
*cli_ftruncate_send(TALLOC_CTX
*mem_ctx
,
2870 struct tevent_context
*ev
,
2871 struct cli_state
*cli
,
2875 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
2876 struct ftrunc_state
*state
= NULL
;
2878 req
= tevent_req_create(mem_ctx
, &state
, struct ftrunc_state
);
2883 /* Setup setup word. */
2884 SSVAL(&state
->setup
, 0, TRANSACT2_SETFILEINFO
);
2886 /* Setup param array. */
2887 SSVAL(state
->param
,0,fnum
);
2888 SSVAL(state
->param
,2,SMB_SET_FILE_END_OF_FILE_INFO
);
2889 SSVAL(state
->param
,4,0);
2891 /* Setup data array. */
2892 SBVAL(state
->data
, 0, size
);
2894 subreq
= cli_trans_send(state
, /* mem ctx. */
2895 ev
, /* event ctx. */
2896 cli
, /* cli_state. */
2897 0, /* additional_flags2 */
2898 SMBtrans2
, /* cmd. */
2899 NULL
, /* pipe name. */
2903 &state
->setup
, /* setup. */
2904 1, /* num setup uint16_t words. */
2905 0, /* max returned setup. */
2906 state
->param
, /* param. */
2908 2, /* max returned param. */
2909 state
->data
, /* data. */
2911 0); /* max returned data. */
2913 if (tevent_req_nomem(subreq
, req
)) {
2914 return tevent_req_post(req
, ev
);
2916 tevent_req_set_callback(subreq
, cli_ftruncate_done
, req
);
2920 NTSTATUS
cli_ftruncate_recv(struct tevent_req
*req
)
2922 return tevent_req_simple_recv_ntstatus(req
);
2925 NTSTATUS
cli_ftruncate(struct cli_state
*cli
, uint16_t fnum
, uint64_t size
)
2927 TALLOC_CTX
*frame
= talloc_stackframe();
2928 struct tevent_context
*ev
= NULL
;
2929 struct tevent_req
*req
= NULL
;
2930 NTSTATUS status
= NT_STATUS_OK
;
2932 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
2934 * Can't use sync call while an async call is in flight
2936 status
= NT_STATUS_INVALID_PARAMETER
;
2940 ev
= samba_tevent_context_init(frame
);
2942 status
= NT_STATUS_NO_MEMORY
;
2946 req
= cli_ftruncate_send(frame
,
2952 status
= NT_STATUS_NO_MEMORY
;
2956 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
2960 status
= cli_ftruncate_recv(req
);
2967 /****************************************************************************
2968 send a lock with a specified locktype
2969 this is used for testing LOCKING_ANDX_CANCEL_LOCK
2970 ****************************************************************************/
2972 NTSTATUS
cli_locktype(struct cli_state
*cli
, uint16_t fnum
,
2973 uint32_t offset
, uint32_t len
,
2974 int timeout
, unsigned char locktype
)
2979 unsigned int set_timeout
= 0;
2980 unsigned int saved_timeout
= 0;
2982 SCVAL(vwv
+ 0, 0, 0xff);
2983 SCVAL(vwv
+ 0, 1, 0);
2984 SSVAL(vwv
+ 1, 0, 0);
2985 SSVAL(vwv
+ 2, 0, fnum
);
2986 SCVAL(vwv
+ 3, 0, locktype
);
2987 SCVAL(vwv
+ 3, 1, 0);
2988 SIVALS(vwv
+ 4, 0, timeout
);
2989 SSVAL(vwv
+ 6, 0, 0);
2990 SSVAL(vwv
+ 7, 0, 1);
2992 SSVAL(bytes
, 0, cli_getpid(cli
));
2993 SIVAL(bytes
, 2, offset
);
2994 SIVAL(bytes
, 6, len
);
2997 if (timeout
== -1) {
2998 set_timeout
= 0x7FFFFFFF;
3000 set_timeout
= timeout
+ 2*1000;
3002 saved_timeout
= cli_set_timeout(cli
, set_timeout
);
3005 status
= cli_smb(talloc_tos(), cli
, SMBlockingX
, 0, 8, vwv
,
3006 10, bytes
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
3008 if (saved_timeout
!= 0) {
3009 cli_set_timeout(cli
, saved_timeout
);
3015 /****************************************************************************
3017 note that timeout is in units of 2 milliseconds
3018 ****************************************************************************/
3020 NTSTATUS
cli_lock32(struct cli_state
*cli
, uint16_t fnum
,
3021 uint32_t offset
, uint32_t len
, int timeout
,
3022 enum brl_type lock_type
)
3026 status
= cli_locktype(cli
, fnum
, offset
, len
, timeout
,
3027 (lock_type
== READ_LOCK
? 1 : 0));
3031 /****************************************************************************
3033 ****************************************************************************/
3035 struct cli_unlock_state
{
3040 static void cli_unlock_done(struct tevent_req
*subreq
);
3042 struct tevent_req
*cli_unlock_send(TALLOC_CTX
*mem_ctx
,
3043 struct tevent_context
*ev
,
3044 struct cli_state
*cli
,
3050 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3051 struct cli_unlock_state
*state
= NULL
;
3052 uint8_t additional_flags
= 0;
3054 req
= tevent_req_create(mem_ctx
, &state
, struct cli_unlock_state
);
3059 SCVAL(state
->vwv
+0, 0, 0xFF);
3060 SSVAL(state
->vwv
+2, 0, fnum
);
3061 SCVAL(state
->vwv
+3, 0, 0);
3062 SIVALS(state
->vwv
+4, 0, 0);
3063 SSVAL(state
->vwv
+6, 0, 1);
3064 SSVAL(state
->vwv
+7, 0, 0);
3066 SSVAL(state
->data
, 0, cli_getpid(cli
));
3067 SIVAL(state
->data
, 2, offset
);
3068 SIVAL(state
->data
, 6, len
);
3070 subreq
= cli_smb_send(state
, ev
, cli
, SMBlockingX
, additional_flags
, 0,
3071 8, state
->vwv
, 10, state
->data
);
3072 if (tevent_req_nomem(subreq
, req
)) {
3073 return tevent_req_post(req
, ev
);
3075 tevent_req_set_callback(subreq
, cli_unlock_done
, req
);
3079 static void cli_unlock_done(struct tevent_req
*subreq
)
3081 struct tevent_req
*req
= tevent_req_callback_data(
3082 subreq
, struct tevent_req
);
3085 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
3086 TALLOC_FREE(subreq
);
3087 if (tevent_req_nterror(req
, status
)) {
3090 tevent_req_done(req
);
3093 NTSTATUS
cli_unlock_recv(struct tevent_req
*req
)
3095 return tevent_req_simple_recv_ntstatus(req
);
3098 NTSTATUS
cli_unlock(struct cli_state
*cli
,
3103 TALLOC_CTX
*frame
= talloc_stackframe();
3104 struct tevent_context
*ev
;
3105 struct tevent_req
*req
;
3106 NTSTATUS status
= NT_STATUS_OK
;
3108 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
3110 * Can't use sync call while an async call is in flight
3112 status
= NT_STATUS_INVALID_PARAMETER
;
3116 ev
= samba_tevent_context_init(frame
);
3118 status
= NT_STATUS_NO_MEMORY
;
3122 req
= cli_unlock_send(frame
, ev
, cli
,
3125 status
= NT_STATUS_NO_MEMORY
;
3129 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
3133 status
= cli_unlock_recv(req
);
3140 /****************************************************************************
3141 Lock a file with 64 bit offsets.
3142 ****************************************************************************/
3144 NTSTATUS
cli_lock64(struct cli_state
*cli
, uint16_t fnum
,
3145 uint64_t offset
, uint64_t len
, int timeout
,
3146 enum brl_type lock_type
)
3150 unsigned int set_timeout
= 0;
3151 unsigned int saved_timeout
= 0;
3155 if (! (smb1cli_conn_capabilities(cli
->conn
) & CAP_LARGE_FILES
)) {
3156 return cli_lock32(cli
, fnum
, offset
, len
, timeout
, lock_type
);
3159 ltype
= (lock_type
== READ_LOCK
? 1 : 0);
3160 ltype
|= LOCKING_ANDX_LARGE_FILES
;
3162 SCVAL(vwv
+ 0, 0, 0xff);
3163 SCVAL(vwv
+ 0, 1, 0);
3164 SSVAL(vwv
+ 1, 0, 0);
3165 SSVAL(vwv
+ 2, 0, fnum
);
3166 SCVAL(vwv
+ 3, 0, ltype
);
3167 SCVAL(vwv
+ 3, 1, 0);
3168 SIVALS(vwv
+ 4, 0, timeout
);
3169 SSVAL(vwv
+ 6, 0, 0);
3170 SSVAL(vwv
+ 7, 0, 1);
3172 SIVAL(bytes
, 0, cli_getpid(cli
));
3173 SOFF_T_R(bytes
, 4, offset
);
3174 SOFF_T_R(bytes
, 12, len
);
3177 if (timeout
== -1) {
3178 set_timeout
= 0x7FFFFFFF;
3180 set_timeout
= timeout
+ 2*1000;
3182 saved_timeout
= cli_set_timeout(cli
, set_timeout
);
3185 status
= cli_smb(talloc_tos(), cli
, SMBlockingX
, 0, 8, vwv
,
3186 20, bytes
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
3188 if (saved_timeout
!= 0) {
3189 cli_set_timeout(cli
, saved_timeout
);
3195 /****************************************************************************
3196 Unlock a file with 64 bit offsets.
3197 ****************************************************************************/
3199 struct cli_unlock64_state
{
3204 static void cli_unlock64_done(struct tevent_req
*subreq
);
3206 struct tevent_req
*cli_unlock64_send(TALLOC_CTX
*mem_ctx
,
3207 struct tevent_context
*ev
,
3208 struct cli_state
*cli
,
3214 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3215 struct cli_unlock64_state
*state
= NULL
;
3216 uint8_t additional_flags
= 0;
3218 req
= tevent_req_create(mem_ctx
, &state
, struct cli_unlock64_state
);
3223 SCVAL(state
->vwv
+0, 0, 0xff);
3224 SSVAL(state
->vwv
+2, 0, fnum
);
3225 SCVAL(state
->vwv
+3, 0,LOCKING_ANDX_LARGE_FILES
);
3226 SIVALS(state
->vwv
+4, 0, 0);
3227 SSVAL(state
->vwv
+6, 0, 1);
3228 SSVAL(state
->vwv
+7, 0, 0);
3230 SIVAL(state
->data
, 0, cli_getpid(cli
));
3231 SOFF_T_R(state
->data
, 4, offset
);
3232 SOFF_T_R(state
->data
, 12, len
);
3234 subreq
= cli_smb_send(state
, ev
, cli
, SMBlockingX
, additional_flags
, 0,
3235 8, state
->vwv
, 20, state
->data
);
3236 if (tevent_req_nomem(subreq
, req
)) {
3237 return tevent_req_post(req
, ev
);
3239 tevent_req_set_callback(subreq
, cli_unlock64_done
, req
);
3243 static void cli_unlock64_done(struct tevent_req
*subreq
)
3245 struct tevent_req
*req
= tevent_req_callback_data(
3246 subreq
, struct tevent_req
);
3249 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
3250 TALLOC_FREE(subreq
);
3251 if (tevent_req_nterror(req
, status
)) {
3254 tevent_req_done(req
);
3257 NTSTATUS
cli_unlock64_recv(struct tevent_req
*req
)
3259 return tevent_req_simple_recv_ntstatus(req
);
3262 NTSTATUS
cli_unlock64(struct cli_state
*cli
,
3267 TALLOC_CTX
*frame
= talloc_stackframe();
3268 struct tevent_context
*ev
;
3269 struct tevent_req
*req
;
3270 NTSTATUS status
= NT_STATUS_OK
;
3272 if (! (smb1cli_conn_capabilities(cli
->conn
) & CAP_LARGE_FILES
)) {
3273 return cli_unlock(cli
, fnum
, offset
, len
);
3276 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
3278 * Can't use sync call while an async call is in flight
3280 status
= NT_STATUS_INVALID_PARAMETER
;
3284 ev
= samba_tevent_context_init(frame
);
3286 status
= NT_STATUS_NO_MEMORY
;
3290 req
= cli_unlock64_send(frame
, ev
, cli
,
3293 status
= NT_STATUS_NO_MEMORY
;
3297 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
3301 status
= cli_unlock64_recv(req
);
3308 /****************************************************************************
3309 Get/unlock a POSIX lock on a file - internal function.
3310 ****************************************************************************/
3312 struct posix_lock_state
{
3315 uint8_t data
[POSIX_LOCK_DATA_SIZE
];
3318 static void cli_posix_unlock_internal_done(struct tevent_req
*subreq
)
3320 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, NULL
, 0, NULL
,
3321 NULL
, 0, NULL
, NULL
, 0, NULL
);
3322 tevent_req_simple_finish_ntstatus(subreq
, status
);
3325 static struct tevent_req
*cli_posix_lock_internal_send(TALLOC_CTX
*mem_ctx
,
3326 struct tevent_context
*ev
,
3327 struct cli_state
*cli
,
3332 enum brl_type lock_type
)
3334 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3335 struct posix_lock_state
*state
= NULL
;
3337 req
= tevent_req_create(mem_ctx
, &state
, struct posix_lock_state
);
3342 /* Setup setup word. */
3343 SSVAL(&state
->setup
, 0, TRANSACT2_SETFILEINFO
);
3345 /* Setup param array. */
3346 SSVAL(&state
->param
, 0, fnum
);
3347 SSVAL(&state
->param
, 2, SMB_SET_POSIX_LOCK
);
3349 /* Setup data array. */
3350 switch (lock_type
) {
3352 SSVAL(&state
->data
, POSIX_LOCK_TYPE_OFFSET
,
3353 POSIX_LOCK_TYPE_READ
);
3356 SSVAL(&state
->data
, POSIX_LOCK_TYPE_OFFSET
,
3357 POSIX_LOCK_TYPE_WRITE
);
3360 SSVAL(&state
->data
, POSIX_LOCK_TYPE_OFFSET
,
3361 POSIX_LOCK_TYPE_UNLOCK
);
3368 SSVAL(&state
->data
, POSIX_LOCK_FLAGS_OFFSET
,
3369 POSIX_LOCK_FLAG_WAIT
);
3371 SSVAL(state
->data
, POSIX_LOCK_FLAGS_OFFSET
,
3372 POSIX_LOCK_FLAG_NOWAIT
);
3375 SIVAL(&state
->data
, POSIX_LOCK_PID_OFFSET
, cli_getpid(cli
));
3376 SOFF_T(&state
->data
, POSIX_LOCK_START_OFFSET
, offset
);
3377 SOFF_T(&state
->data
, POSIX_LOCK_LEN_OFFSET
, len
);
3379 subreq
= cli_trans_send(state
, /* mem ctx. */
3380 ev
, /* event ctx. */
3381 cli
, /* cli_state. */
3382 0, /* additional_flags2 */
3383 SMBtrans2
, /* cmd. */
3384 NULL
, /* pipe name. */
3388 &state
->setup
, /* setup. */
3389 1, /* num setup uint16_t words. */
3390 0, /* max returned setup. */
3391 state
->param
, /* param. */
3393 2, /* max returned param. */
3394 state
->data
, /* data. */
3395 POSIX_LOCK_DATA_SIZE
, /* num data. */
3396 0); /* max returned data. */
3398 if (tevent_req_nomem(subreq
, req
)) {
3399 return tevent_req_post(req
, ev
);
3401 tevent_req_set_callback(subreq
, cli_posix_unlock_internal_done
, req
);
3405 /****************************************************************************
3407 ****************************************************************************/
3409 struct tevent_req
*cli_posix_lock_send(TALLOC_CTX
*mem_ctx
,
3410 struct tevent_context
*ev
,
3411 struct cli_state
*cli
,
3416 enum brl_type lock_type
)
3418 return cli_posix_lock_internal_send(mem_ctx
, ev
, cli
, fnum
, offset
, len
,
3419 wait_lock
, lock_type
);
3422 NTSTATUS
cli_posix_lock_recv(struct tevent_req
*req
)
3424 return tevent_req_simple_recv_ntstatus(req
);
3427 NTSTATUS
cli_posix_lock(struct cli_state
*cli
, uint16_t fnum
,
3428 uint64_t offset
, uint64_t len
,
3429 bool wait_lock
, enum brl_type lock_type
)
3431 TALLOC_CTX
*frame
= talloc_stackframe();
3432 struct tevent_context
*ev
= NULL
;
3433 struct tevent_req
*req
= NULL
;
3434 NTSTATUS status
= NT_STATUS_OK
;
3436 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
3438 * Can't use sync call while an async call is in flight
3440 status
= NT_STATUS_INVALID_PARAMETER
;
3444 if (lock_type
!= READ_LOCK
&& lock_type
!= WRITE_LOCK
) {
3445 status
= NT_STATUS_INVALID_PARAMETER
;
3449 ev
= samba_tevent_context_init(frame
);
3451 status
= NT_STATUS_NO_MEMORY
;
3455 req
= cli_posix_lock_send(frame
,
3464 status
= NT_STATUS_NO_MEMORY
;
3468 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
3472 status
= cli_posix_lock_recv(req
);
3479 /****************************************************************************
3480 POSIX Unlock a file.
3481 ****************************************************************************/
3483 struct tevent_req
*cli_posix_unlock_send(TALLOC_CTX
*mem_ctx
,
3484 struct tevent_context
*ev
,
3485 struct cli_state
*cli
,
3490 return cli_posix_lock_internal_send(mem_ctx
, ev
, cli
, fnum
, offset
, len
,
3491 false, UNLOCK_LOCK
);
3494 NTSTATUS
cli_posix_unlock_recv(struct tevent_req
*req
)
3496 return tevent_req_simple_recv_ntstatus(req
);
3499 NTSTATUS
cli_posix_unlock(struct cli_state
*cli
, uint16_t fnum
, uint64_t offset
, uint64_t len
)
3501 TALLOC_CTX
*frame
= talloc_stackframe();
3502 struct tevent_context
*ev
= NULL
;
3503 struct tevent_req
*req
= NULL
;
3504 NTSTATUS status
= NT_STATUS_OK
;
3506 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
3508 * Can't use sync call while an async call is in flight
3510 status
= NT_STATUS_INVALID_PARAMETER
;
3514 ev
= samba_tevent_context_init(frame
);
3516 status
= NT_STATUS_NO_MEMORY
;
3520 req
= cli_posix_unlock_send(frame
,
3527 status
= NT_STATUS_NO_MEMORY
;
3531 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
3535 status
= cli_posix_unlock_recv(req
);
3542 /****************************************************************************
3543 Do a SMBgetattrE call.
3544 ****************************************************************************/
3546 static void cli_getattrE_done(struct tevent_req
*subreq
);
3548 struct cli_getattrE_state
{
3558 struct tevent_req
*cli_getattrE_send(TALLOC_CTX
*mem_ctx
,
3559 struct tevent_context
*ev
,
3560 struct cli_state
*cli
,
3563 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3564 struct cli_getattrE_state
*state
= NULL
;
3565 uint8_t additional_flags
= 0;
3567 req
= tevent_req_create(mem_ctx
, &state
, struct cli_getattrE_state
);
3572 state
->zone_offset
= smb1cli_conn_server_time_zone(cli
->conn
);
3573 SSVAL(state
->vwv
+0,0,fnum
);
3575 subreq
= cli_smb_send(state
, ev
, cli
, SMBgetattrE
, additional_flags
, 0,
3576 1, state
->vwv
, 0, NULL
);
3577 if (tevent_req_nomem(subreq
, req
)) {
3578 return tevent_req_post(req
, ev
);
3580 tevent_req_set_callback(subreq
, cli_getattrE_done
, req
);
3584 static void cli_getattrE_done(struct tevent_req
*subreq
)
3586 struct tevent_req
*req
= tevent_req_callback_data(
3587 subreq
, struct tevent_req
);
3588 struct cli_getattrE_state
*state
= tevent_req_data(
3589 req
, struct cli_getattrE_state
);
3591 uint16_t *vwv
= NULL
;
3594 status
= cli_smb_recv(subreq
, state
, NULL
, 11, &wct
, &vwv
,
3596 TALLOC_FREE(subreq
);
3597 if (tevent_req_nterror(req
, status
)) {
3601 state
->size
= (off_t
)IVAL(vwv
+6,0);
3602 state
->attr
= SVAL(vwv
+10,0);
3603 state
->change_time
= make_unix_date2(vwv
+0, state
->zone_offset
);
3604 state
->access_time
= make_unix_date2(vwv
+2, state
->zone_offset
);
3605 state
->write_time
= make_unix_date2(vwv
+4, state
->zone_offset
);
3607 tevent_req_done(req
);
3610 NTSTATUS
cli_getattrE_recv(struct tevent_req
*req
,
3613 time_t *change_time
,
3614 time_t *access_time
,
3617 struct cli_getattrE_state
*state
= tevent_req_data(
3618 req
, struct cli_getattrE_state
);
3621 if (tevent_req_is_nterror(req
, &status
)) {
3625 *attr
= state
->attr
;
3628 *size
= state
->size
;
3631 *change_time
= state
->change_time
;
3634 *access_time
= state
->access_time
;
3637 *write_time
= state
->write_time
;
3639 return NT_STATUS_OK
;
3642 NTSTATUS
cli_getattrE(struct cli_state
*cli
,
3646 time_t *change_time
,
3647 time_t *access_time
,
3650 TALLOC_CTX
*frame
= NULL
;
3651 struct tevent_context
*ev
= NULL
;
3652 struct tevent_req
*req
= NULL
;
3653 NTSTATUS status
= NT_STATUS_OK
;
3655 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
3656 return cli_smb2_getattrE(cli
,
3665 frame
= talloc_stackframe();
3667 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
3669 * Can't use sync call while an async call is in flight
3671 status
= NT_STATUS_INVALID_PARAMETER
;
3675 ev
= samba_tevent_context_init(frame
);
3677 status
= NT_STATUS_NO_MEMORY
;
3681 req
= cli_getattrE_send(frame
, ev
, cli
, fnum
);
3683 status
= NT_STATUS_NO_MEMORY
;
3687 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
3691 status
= cli_getattrE_recv(req
,
3703 /****************************************************************************
3705 ****************************************************************************/
3707 static void cli_getatr_done(struct tevent_req
*subreq
);
3709 struct cli_getatr_state
{
3716 struct tevent_req
*cli_getatr_send(TALLOC_CTX
*mem_ctx
,
3717 struct tevent_context
*ev
,
3718 struct cli_state
*cli
,
3721 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3722 struct cli_getatr_state
*state
= NULL
;
3723 uint8_t additional_flags
= 0;
3724 uint8_t *bytes
= NULL
;
3726 req
= tevent_req_create(mem_ctx
, &state
, struct cli_getatr_state
);
3731 state
->zone_offset
= smb1cli_conn_server_time_zone(cli
->conn
);
3733 bytes
= talloc_array(state
, uint8_t, 1);
3734 if (tevent_req_nomem(bytes
, req
)) {
3735 return tevent_req_post(req
, ev
);
3738 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname
,
3739 strlen(fname
)+1, NULL
);
3741 if (tevent_req_nomem(bytes
, req
)) {
3742 return tevent_req_post(req
, ev
);
3745 subreq
= cli_smb_send(state
, ev
, cli
, SMBgetatr
, additional_flags
, 0,
3746 0, NULL
, talloc_get_size(bytes
), bytes
);
3747 if (tevent_req_nomem(subreq
, req
)) {
3748 return tevent_req_post(req
, ev
);
3750 tevent_req_set_callback(subreq
, cli_getatr_done
, req
);
3754 static void cli_getatr_done(struct tevent_req
*subreq
)
3756 struct tevent_req
*req
= tevent_req_callback_data(
3757 subreq
, struct tevent_req
);
3758 struct cli_getatr_state
*state
= tevent_req_data(
3759 req
, struct cli_getatr_state
);
3761 uint16_t *vwv
= NULL
;
3764 status
= cli_smb_recv(subreq
, state
, NULL
, 4, &wct
, &vwv
, NULL
,
3766 TALLOC_FREE(subreq
);
3767 if (tevent_req_nterror(req
, status
)) {
3771 state
->attr
= SVAL(vwv
+0,0);
3772 state
->size
= (off_t
)IVAL(vwv
+3,0);
3773 state
->write_time
= make_unix_date3(vwv
+1, state
->zone_offset
);
3775 tevent_req_done(req
);
3778 NTSTATUS
cli_getatr_recv(struct tevent_req
*req
,
3783 struct cli_getatr_state
*state
= tevent_req_data(
3784 req
, struct cli_getatr_state
);
3787 if (tevent_req_is_nterror(req
, &status
)) {
3791 *attr
= state
->attr
;
3794 *size
= state
->size
;
3797 *write_time
= state
->write_time
;
3799 return NT_STATUS_OK
;
3802 NTSTATUS
cli_getatr(struct cli_state
*cli
,
3808 TALLOC_CTX
*frame
= NULL
;
3809 struct tevent_context
*ev
= NULL
;
3810 struct tevent_req
*req
= NULL
;
3811 NTSTATUS status
= NT_STATUS_OK
;
3813 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
3814 return cli_smb2_getatr(cli
,
3821 frame
= talloc_stackframe();
3823 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
3825 * Can't use sync call while an async call is in flight
3827 status
= NT_STATUS_INVALID_PARAMETER
;
3831 ev
= samba_tevent_context_init(frame
);
3833 status
= NT_STATUS_NO_MEMORY
;
3837 req
= cli_getatr_send(frame
, ev
, cli
, fname
);
3839 status
= NT_STATUS_NO_MEMORY
;
3843 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
3847 status
= cli_getatr_recv(req
,
3857 /****************************************************************************
3858 Do a SMBsetattrE call.
3859 ****************************************************************************/
3861 static void cli_setattrE_done(struct tevent_req
*subreq
);
3863 struct cli_setattrE_state
{
3867 struct tevent_req
*cli_setattrE_send(TALLOC_CTX
*mem_ctx
,
3868 struct tevent_context
*ev
,
3869 struct cli_state
*cli
,
3875 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3876 struct cli_setattrE_state
*state
= NULL
;
3877 uint8_t additional_flags
= 0;
3879 req
= tevent_req_create(mem_ctx
, &state
, struct cli_setattrE_state
);
3884 SSVAL(state
->vwv
+0, 0, fnum
);
3885 push_dos_date2((uint8_t *)&state
->vwv
[1], 0, change_time
,
3886 smb1cli_conn_server_time_zone(cli
->conn
));
3887 push_dos_date2((uint8_t *)&state
->vwv
[3], 0, access_time
,
3888 smb1cli_conn_server_time_zone(cli
->conn
));
3889 push_dos_date2((uint8_t *)&state
->vwv
[5], 0, write_time
,
3890 smb1cli_conn_server_time_zone(cli
->conn
));
3892 subreq
= cli_smb_send(state
, ev
, cli
, SMBsetattrE
, additional_flags
, 0,
3893 7, state
->vwv
, 0, NULL
);
3894 if (tevent_req_nomem(subreq
, req
)) {
3895 return tevent_req_post(req
, ev
);
3897 tevent_req_set_callback(subreq
, cli_setattrE_done
, req
);
3901 static void cli_setattrE_done(struct tevent_req
*subreq
)
3903 struct tevent_req
*req
= tevent_req_callback_data(
3904 subreq
, struct tevent_req
);
3907 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
3908 TALLOC_FREE(subreq
);
3909 if (tevent_req_nterror(req
, status
)) {
3912 tevent_req_done(req
);
3915 NTSTATUS
cli_setattrE_recv(struct tevent_req
*req
)
3917 return tevent_req_simple_recv_ntstatus(req
);
3920 NTSTATUS
cli_setattrE(struct cli_state
*cli
,
3926 TALLOC_CTX
*frame
= NULL
;
3927 struct tevent_context
*ev
= NULL
;
3928 struct tevent_req
*req
= NULL
;
3929 NTSTATUS status
= NT_STATUS_OK
;
3931 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
3932 return cli_smb2_setattrE(cli
,
3939 frame
= talloc_stackframe();
3941 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
3943 * Can't use sync call while an async call is in flight
3945 status
= NT_STATUS_INVALID_PARAMETER
;
3949 ev
= samba_tevent_context_init(frame
);
3951 status
= NT_STATUS_NO_MEMORY
;
3955 req
= cli_setattrE_send(frame
, ev
,
3963 status
= NT_STATUS_NO_MEMORY
;
3967 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
3971 status
= cli_setattrE_recv(req
);
3978 /****************************************************************************
3979 Do a SMBsetatr call.
3980 ****************************************************************************/
3982 static void cli_setatr_done(struct tevent_req
*subreq
);
3984 struct cli_setatr_state
{
3988 struct tevent_req
*cli_setatr_send(TALLOC_CTX
*mem_ctx
,
3989 struct tevent_context
*ev
,
3990 struct cli_state
*cli
,
3995 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3996 struct cli_setatr_state
*state
= NULL
;
3997 uint8_t additional_flags
= 0;
3998 uint8_t *bytes
= NULL
;
4000 req
= tevent_req_create(mem_ctx
, &state
, struct cli_setatr_state
);
4005 SSVAL(state
->vwv
+0, 0, attr
);
4006 push_dos_date3((uint8_t *)&state
->vwv
[1], 0, mtime
, smb1cli_conn_server_time_zone(cli
->conn
));
4008 bytes
= talloc_array(state
, uint8_t, 1);
4009 if (tevent_req_nomem(bytes
, req
)) {
4010 return tevent_req_post(req
, ev
);
4013 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname
,
4014 strlen(fname
)+1, NULL
);
4015 if (tevent_req_nomem(bytes
, req
)) {
4016 return tevent_req_post(req
, ev
);
4018 bytes
= talloc_realloc(state
, bytes
, uint8_t,
4019 talloc_get_size(bytes
)+1);
4020 if (tevent_req_nomem(bytes
, req
)) {
4021 return tevent_req_post(req
, ev
);
4024 bytes
[talloc_get_size(bytes
)-1] = 4;
4025 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), "",
4027 if (tevent_req_nomem(bytes
, req
)) {
4028 return tevent_req_post(req
, ev
);
4031 subreq
= cli_smb_send(state
, ev
, cli
, SMBsetatr
, additional_flags
, 0,
4032 8, state
->vwv
, talloc_get_size(bytes
), bytes
);
4033 if (tevent_req_nomem(subreq
, req
)) {
4034 return tevent_req_post(req
, ev
);
4036 tevent_req_set_callback(subreq
, cli_setatr_done
, req
);
4040 static void cli_setatr_done(struct tevent_req
*subreq
)
4042 struct tevent_req
*req
= tevent_req_callback_data(
4043 subreq
, struct tevent_req
);
4046 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
4047 TALLOC_FREE(subreq
);
4048 if (tevent_req_nterror(req
, status
)) {
4051 tevent_req_done(req
);
4054 NTSTATUS
cli_setatr_recv(struct tevent_req
*req
)
4056 return tevent_req_simple_recv_ntstatus(req
);
4059 NTSTATUS
cli_setatr(struct cli_state
*cli
,
4064 TALLOC_CTX
*frame
= NULL
;
4065 struct tevent_context
*ev
= NULL
;
4066 struct tevent_req
*req
= NULL
;
4067 NTSTATUS status
= NT_STATUS_OK
;
4069 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
4070 return cli_smb2_setatr(cli
,
4076 frame
= talloc_stackframe();
4078 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
4080 * Can't use sync call while an async call is in flight
4082 status
= NT_STATUS_INVALID_PARAMETER
;
4086 ev
= samba_tevent_context_init(frame
);
4088 status
= NT_STATUS_NO_MEMORY
;
4092 req
= cli_setatr_send(frame
, ev
, cli
, fname
, attr
, mtime
);
4094 status
= NT_STATUS_NO_MEMORY
;
4098 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
4102 status
= cli_setatr_recv(req
);
4109 /****************************************************************************
4110 Check for existance of a dir.
4111 ****************************************************************************/
4113 static void cli_chkpath_done(struct tevent_req
*subreq
);
4115 struct cli_chkpath_state
{
4119 struct tevent_req
*cli_chkpath_send(TALLOC_CTX
*mem_ctx
,
4120 struct tevent_context
*ev
,
4121 struct cli_state
*cli
,
4124 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
4125 struct cli_chkpath_state
*state
= NULL
;
4126 uint8_t additional_flags
= 0;
4127 uint8_t *bytes
= NULL
;
4129 req
= tevent_req_create(mem_ctx
, &state
, struct cli_chkpath_state
);
4134 bytes
= talloc_array(state
, uint8_t, 1);
4135 if (tevent_req_nomem(bytes
, req
)) {
4136 return tevent_req_post(req
, ev
);
4139 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname
,
4140 strlen(fname
)+1, NULL
);
4142 if (tevent_req_nomem(bytes
, req
)) {
4143 return tevent_req_post(req
, ev
);
4146 subreq
= cli_smb_send(state
, ev
, cli
, SMBcheckpath
, additional_flags
, 0,
4147 0, NULL
, talloc_get_size(bytes
), bytes
);
4148 if (tevent_req_nomem(subreq
, req
)) {
4149 return tevent_req_post(req
, ev
);
4151 tevent_req_set_callback(subreq
, cli_chkpath_done
, req
);
4155 static void cli_chkpath_done(struct tevent_req
*subreq
)
4157 struct tevent_req
*req
= tevent_req_callback_data(
4158 subreq
, struct tevent_req
);
4161 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
4162 TALLOC_FREE(subreq
);
4163 if (tevent_req_nterror(req
, status
)) {
4166 tevent_req_done(req
);
4169 NTSTATUS
cli_chkpath_recv(struct tevent_req
*req
)
4171 return tevent_req_simple_recv_ntstatus(req
);
4174 NTSTATUS
cli_chkpath(struct cli_state
*cli
, const char *path
)
4176 TALLOC_CTX
*frame
= talloc_stackframe();
4177 struct tevent_context
*ev
= NULL
;
4178 struct tevent_req
*req
= NULL
;
4180 NTSTATUS status
= NT_STATUS_OK
;
4182 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
4184 * Can't use sync call while an async call is in flight
4186 status
= NT_STATUS_INVALID_PARAMETER
;
4190 path2
= talloc_strdup(frame
, path
);
4192 status
= NT_STATUS_NO_MEMORY
;
4195 trim_char(path2
,'\0','\\');
4197 path2
= talloc_strdup(frame
, "\\");
4199 status
= NT_STATUS_NO_MEMORY
;
4204 ev
= samba_tevent_context_init(frame
);
4206 status
= NT_STATUS_NO_MEMORY
;
4210 req
= cli_chkpath_send(frame
, ev
, cli
, path2
);
4212 status
= NT_STATUS_NO_MEMORY
;
4216 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
4220 status
= cli_chkpath_recv(req
);
4227 /****************************************************************************
4229 ****************************************************************************/
4231 static void cli_dskattr_done(struct tevent_req
*subreq
);
4233 struct cli_dskattr_state
{
4239 struct tevent_req
*cli_dskattr_send(TALLOC_CTX
*mem_ctx
,
4240 struct tevent_context
*ev
,
4241 struct cli_state
*cli
)
4243 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
4244 struct cli_dskattr_state
*state
= NULL
;
4245 uint8_t additional_flags
= 0;
4247 req
= tevent_req_create(mem_ctx
, &state
, struct cli_dskattr_state
);
4252 subreq
= cli_smb_send(state
, ev
, cli
, SMBdskattr
, additional_flags
, 0,
4254 if (tevent_req_nomem(subreq
, req
)) {
4255 return tevent_req_post(req
, ev
);
4257 tevent_req_set_callback(subreq
, cli_dskattr_done
, req
);
4261 static void cli_dskattr_done(struct tevent_req
*subreq
)
4263 struct tevent_req
*req
= tevent_req_callback_data(
4264 subreq
, struct tevent_req
);
4265 struct cli_dskattr_state
*state
= tevent_req_data(
4266 req
, struct cli_dskattr_state
);
4268 uint16_t *vwv
= NULL
;
4271 status
= cli_smb_recv(subreq
, state
, NULL
, 4, &wct
, &vwv
, NULL
,
4273 TALLOC_FREE(subreq
);
4274 if (tevent_req_nterror(req
, status
)) {
4277 state
->bsize
= SVAL(vwv
+1, 0)*SVAL(vwv
+2,0);
4278 state
->total
= SVAL(vwv
+0, 0);
4279 state
->avail
= SVAL(vwv
+3, 0);
4280 tevent_req_done(req
);
4283 NTSTATUS
cli_dskattr_recv(struct tevent_req
*req
, int *bsize
, int *total
, int *avail
)
4285 struct cli_dskattr_state
*state
= tevent_req_data(
4286 req
, struct cli_dskattr_state
);
4289 if (tevent_req_is_nterror(req
, &status
)) {
4292 *bsize
= state
->bsize
;
4293 *total
= state
->total
;
4294 *avail
= state
->avail
;
4295 return NT_STATUS_OK
;
4298 NTSTATUS
cli_dskattr(struct cli_state
*cli
, int *bsize
, int *total
, int *avail
)
4300 TALLOC_CTX
*frame
= NULL
;
4301 struct tevent_context
*ev
= NULL
;
4302 struct tevent_req
*req
= NULL
;
4303 NTSTATUS status
= NT_STATUS_OK
;
4305 frame
= talloc_stackframe();
4307 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
4309 * Can't use sync call while an async call is in flight
4311 status
= NT_STATUS_INVALID_PARAMETER
;
4315 ev
= samba_tevent_context_init(frame
);
4317 status
= NT_STATUS_NO_MEMORY
;
4321 req
= cli_dskattr_send(frame
, ev
, cli
);
4323 status
= NT_STATUS_NO_MEMORY
;
4327 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
4331 status
= cli_dskattr_recv(req
, bsize
, total
, avail
);
4338 NTSTATUS
cli_disk_size(struct cli_state
*cli
, const char *path
, uint64_t *bsize
,
4339 uint64_t *total
, uint64_t *avail
)
4341 uint64_t sectors_per_block
;
4342 uint64_t bytes_per_sector
;
4343 int old_bsize
, old_total
, old_avail
;
4346 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
4347 return cli_smb2_dskattr(cli
, path
, bsize
, total
, avail
);
4351 * Try the trans2 disk full size info call first.
4352 * We already use this in SMBC_fstatvfs_ctx().
4353 * Ignore 'actual_available_units' as we only
4354 * care about the quota for the caller.
4357 status
= cli_get_fs_full_size_info(cli
,
4364 /* Try and cope will all varients of "we don't do this call"
4365 and fall back to cli_dskattr. */
4367 if (NT_STATUS_EQUAL(status
,NT_STATUS_NOT_IMPLEMENTED
) ||
4368 NT_STATUS_EQUAL(status
,NT_STATUS_NOT_SUPPORTED
) ||
4369 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_INFO_CLASS
) ||
4370 NT_STATUS_EQUAL(status
,NT_STATUS_PROCEDURE_NOT_FOUND
) ||
4371 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_LEVEL
) ||
4372 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_PARAMETER
) ||
4373 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_DEVICE_REQUEST
) ||
4374 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_DEVICE_STATE
) ||
4375 NT_STATUS_EQUAL(status
,NT_STATUS_CTL_FILE_NOT_SUPPORTED
) ||
4376 NT_STATUS_EQUAL(status
,NT_STATUS_UNSUCCESSFUL
)) {
4380 if (!NT_STATUS_IS_OK(status
)) {
4385 *bsize
= sectors_per_block
*
4389 return NT_STATUS_OK
;
4393 /* Old SMB1 core protocol fallback. */
4394 status
= cli_dskattr(cli
, &old_bsize
, &old_total
, &old_avail
);
4395 if (!NT_STATUS_IS_OK(status
)) {
4399 *bsize
= (uint64_t)old_bsize
;
4402 *total
= (uint64_t)old_total
;
4405 *avail
= (uint64_t)old_avail
;
4407 return NT_STATUS_OK
;
4410 /****************************************************************************
4411 Create and open a temporary file.
4412 ****************************************************************************/
4414 static void cli_ctemp_done(struct tevent_req
*subreq
);
4416 struct ctemp_state
{
4422 struct tevent_req
*cli_ctemp_send(TALLOC_CTX
*mem_ctx
,
4423 struct tevent_context
*ev
,
4424 struct cli_state
*cli
,
4427 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
4428 struct ctemp_state
*state
= NULL
;
4429 uint8_t additional_flags
= 0;
4430 uint8_t *bytes
= NULL
;
4432 req
= tevent_req_create(mem_ctx
, &state
, struct ctemp_state
);
4437 SSVAL(state
->vwv
,0,0);
4438 SIVALS(state
->vwv
+1,0,-1);
4440 bytes
= talloc_array(state
, uint8_t, 1);
4441 if (tevent_req_nomem(bytes
, req
)) {
4442 return tevent_req_post(req
, ev
);
4445 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), path
,
4446 strlen(path
)+1, NULL
);
4447 if (tevent_req_nomem(bytes
, req
)) {
4448 return tevent_req_post(req
, ev
);
4451 subreq
= cli_smb_send(state
, ev
, cli
, SMBctemp
, additional_flags
, 0,
4452 3, state
->vwv
, talloc_get_size(bytes
), bytes
);
4453 if (tevent_req_nomem(subreq
, req
)) {
4454 return tevent_req_post(req
, ev
);
4456 tevent_req_set_callback(subreq
, cli_ctemp_done
, req
);
4460 static void cli_ctemp_done(struct tevent_req
*subreq
)
4462 struct tevent_req
*req
= tevent_req_callback_data(
4463 subreq
, struct tevent_req
);
4464 struct ctemp_state
*state
= tevent_req_data(
4465 req
, struct ctemp_state
);
4469 uint32_t num_bytes
= 0;
4470 uint8_t *bytes
= NULL
;
4472 status
= cli_smb_recv(subreq
, state
, NULL
, 1, &wcnt
, &vwv
,
4473 &num_bytes
, &bytes
);
4474 TALLOC_FREE(subreq
);
4475 if (tevent_req_nterror(req
, status
)) {
4479 state
->fnum
= SVAL(vwv
+0, 0);
4481 /* From W2K3, the result is just the ASCII name */
4482 if (num_bytes
< 2) {
4483 tevent_req_nterror(req
, NT_STATUS_DATA_ERROR
);
4487 if (pull_string_talloc(state
,
4494 tevent_req_nterror(req
, NT_STATUS_NO_MEMORY
);
4497 tevent_req_done(req
);
4500 NTSTATUS
cli_ctemp_recv(struct tevent_req
*req
,
4505 struct ctemp_state
*state
= tevent_req_data(req
,
4506 struct ctemp_state
);
4509 if (tevent_req_is_nterror(req
, &status
)) {
4512 *pfnum
= state
->fnum
;
4513 *outfile
= talloc_strdup(ctx
, state
->ret_path
);
4515 return NT_STATUS_NO_MEMORY
;
4517 return NT_STATUS_OK
;
4520 NTSTATUS
cli_ctemp(struct cli_state
*cli
,
4526 TALLOC_CTX
*frame
= talloc_stackframe();
4527 struct tevent_context
*ev
;
4528 struct tevent_req
*req
;
4529 NTSTATUS status
= NT_STATUS_OK
;
4531 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
4533 * Can't use sync call while an async call is in flight
4535 status
= NT_STATUS_INVALID_PARAMETER
;
4539 ev
= samba_tevent_context_init(frame
);
4541 status
= NT_STATUS_NO_MEMORY
;
4545 req
= cli_ctemp_send(frame
, ev
, cli
, path
);
4547 status
= NT_STATUS_NO_MEMORY
;
4551 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
4555 status
= cli_ctemp_recv(req
, ctx
, pfnum
, out_path
);
4563 send a raw ioctl - used by the torture code
4565 NTSTATUS
cli_raw_ioctl(struct cli_state
*cli
, uint16_t fnum
, uint32_t code
, DATA_BLOB
*blob
)
4570 SSVAL(vwv
+0, 0, fnum
);
4571 SSVAL(vwv
+1, 0, code
>>16);
4572 SSVAL(vwv
+2, 0, (code
&0xFFFF));
4574 status
= cli_smb(talloc_tos(), cli
, SMBioctl
, 0, 3, vwv
, 0, NULL
,
4575 NULL
, 0, NULL
, NULL
, NULL
, NULL
);
4576 if (!NT_STATUS_IS_OK(status
)) {
4579 *blob
= data_blob_null
;
4580 return NT_STATUS_OK
;
4583 /*********************************************************
4584 Set an extended attribute utility fn.
4585 *********************************************************/
4587 static NTSTATUS
cli_set_ea(struct cli_state
*cli
, uint16_t setup_val
,
4588 uint8_t *param
, unsigned int param_len
,
4589 const char *ea_name
,
4590 const char *ea_val
, size_t ea_len
)
4593 unsigned int data_len
= 0;
4594 uint8_t *data
= NULL
;
4596 size_t ea_namelen
= strlen(ea_name
);
4599 SSVAL(setup
, 0, setup_val
);
4601 if (ea_namelen
== 0 && ea_len
== 0) {
4603 data
= talloc_array(talloc_tos(),
4607 return NT_STATUS_NO_MEMORY
;
4610 SIVAL(p
,0,data_len
);
4612 data_len
= 4 + 4 + ea_namelen
+ 1 + ea_len
;
4613 data
= talloc_array(talloc_tos(),
4617 return NT_STATUS_NO_MEMORY
;
4620 SIVAL(p
,0,data_len
);
4622 SCVAL(p
, 0, 0); /* EA flags. */
4623 SCVAL(p
, 1, ea_namelen
);
4624 SSVAL(p
, 2, ea_len
);
4625 memcpy(p
+4, ea_name
, ea_namelen
+1); /* Copy in the name. */
4626 memcpy(p
+4+ea_namelen
+1, ea_val
, ea_len
);
4629 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
, NULL
, -1, 0, 0,
4631 param
, param_len
, 2,
4634 NULL
, 0, NULL
, /* rsetup */
4635 NULL
, 0, NULL
, /* rparam */
4636 NULL
, 0, NULL
); /* rdata */
4641 /*********************************************************
4642 Set an extended attribute on a pathname.
4643 *********************************************************/
4645 NTSTATUS
cli_set_ea_path(struct cli_state
*cli
, const char *path
,
4646 const char *ea_name
, const char *ea_val
,
4649 unsigned int param_len
= 0;
4652 TALLOC_CTX
*frame
= NULL
;
4654 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
4655 return cli_smb2_set_ea_path(cli
,
4662 frame
= talloc_stackframe();
4664 param
= talloc_array(frame
, uint8_t, 6);
4666 status
= NT_STATUS_NO_MEMORY
;
4669 SSVAL(param
,0,SMB_INFO_SET_EA
);
4673 param
= trans2_bytes_push_str(param
, smbXcli_conn_use_unicode(cli
->conn
),
4674 path
, strlen(path
)+1,
4676 param_len
= talloc_get_size(param
);
4678 status
= cli_set_ea(cli
, TRANSACT2_SETPATHINFO
, param
, param_len
,
4679 ea_name
, ea_val
, ea_len
);
4687 /*********************************************************
4688 Set an extended attribute on an fnum.
4689 *********************************************************/
4691 NTSTATUS
cli_set_ea_fnum(struct cli_state
*cli
, uint16_t fnum
,
4692 const char *ea_name
, const char *ea_val
,
4697 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
4698 return cli_smb2_set_ea_fnum(cli
,
4705 memset(param
, 0, 6);
4706 SSVAL(param
,0,fnum
);
4707 SSVAL(param
,2,SMB_INFO_SET_EA
);
4709 return cli_set_ea(cli
, TRANSACT2_SETFILEINFO
, param
, 6,
4710 ea_name
, ea_val
, ea_len
);
4713 /*********************************************************
4714 Get an extended attribute list utility fn.
4715 *********************************************************/
4717 static bool parse_ea_blob(TALLOC_CTX
*ctx
, const uint8_t *rdata
,
4719 size_t *pnum_eas
, struct ea_struct
**pea_list
)
4721 struct ea_struct
*ea_list
= NULL
;
4726 if (rdata_len
< 4) {
4730 ea_size
= (size_t)IVAL(rdata
,0);
4731 if (ea_size
> rdata_len
) {
4736 /* No EA's present. */
4745 /* Validate the EA list and count it. */
4746 for (num_eas
= 0; ea_size
>= 4; num_eas
++) {
4747 unsigned int ea_namelen
= CVAL(p
,1);
4748 unsigned int ea_valuelen
= SVAL(p
,2);
4749 if (ea_namelen
== 0) {
4752 if (4 + ea_namelen
+ 1 + ea_valuelen
> ea_size
) {
4755 ea_size
-= 4 + ea_namelen
+ 1 + ea_valuelen
;
4756 p
+= 4 + ea_namelen
+ 1 + ea_valuelen
;
4765 *pnum_eas
= num_eas
;
4767 /* Caller only wants number of EA's. */
4771 ea_list
= talloc_array(ctx
, struct ea_struct
, num_eas
);
4776 ea_size
= (size_t)IVAL(rdata
,0);
4779 for (num_eas
= 0; num_eas
< *pnum_eas
; num_eas
++ ) {
4780 struct ea_struct
*ea
= &ea_list
[num_eas
];
4781 fstring unix_ea_name
;
4782 unsigned int ea_namelen
= CVAL(p
,1);
4783 unsigned int ea_valuelen
= SVAL(p
,2);
4785 ea
->flags
= CVAL(p
,0);
4786 unix_ea_name
[0] = '\0';
4787 pull_ascii(unix_ea_name
, p
+ 4, sizeof(unix_ea_name
), rdata_len
- PTR_DIFF(p
+4, rdata
), STR_TERMINATE
);
4788 ea
->name
= talloc_strdup(ea_list
, unix_ea_name
);
4792 /* Ensure the value is null terminated (in case it's a string). */
4793 ea
->value
= data_blob_talloc(ea_list
, NULL
, ea_valuelen
+ 1);
4794 if (!ea
->value
.data
) {
4798 memcpy(ea
->value
.data
, p
+4+ea_namelen
+1, ea_valuelen
);
4800 ea
->value
.data
[ea_valuelen
] = 0;
4802 p
+= 4 + ea_namelen
+ 1 + ea_valuelen
;
4805 *pea_list
= ea_list
;
4809 TALLOC_FREE(ea_list
);
4813 /*********************************************************
4814 Get an extended attribute list from a pathname.
4815 *********************************************************/
4817 struct cli_get_ea_list_path_state
{
4822 static void cli_get_ea_list_path_done(struct tevent_req
*subreq
);
4824 struct tevent_req
*cli_get_ea_list_path_send(TALLOC_CTX
*mem_ctx
,
4825 struct tevent_context
*ev
,
4826 struct cli_state
*cli
,
4829 struct tevent_req
*req
, *subreq
;
4830 struct cli_get_ea_list_path_state
*state
;
4832 req
= tevent_req_create(mem_ctx
, &state
,
4833 struct cli_get_ea_list_path_state
);
4837 subreq
= cli_qpathinfo_send(state
, ev
, cli
, fname
,
4838 SMB_INFO_QUERY_ALL_EAS
, 4,
4840 if (tevent_req_nomem(subreq
, req
)) {
4841 return tevent_req_post(req
, ev
);
4843 tevent_req_set_callback(subreq
, cli_get_ea_list_path_done
, req
);
4847 static void cli_get_ea_list_path_done(struct tevent_req
*subreq
)
4849 struct tevent_req
*req
= tevent_req_callback_data(
4850 subreq
, struct tevent_req
);
4851 struct cli_get_ea_list_path_state
*state
= tevent_req_data(
4852 req
, struct cli_get_ea_list_path_state
);
4855 status
= cli_qpathinfo_recv(subreq
, state
, &state
->data
,
4857 TALLOC_FREE(subreq
);
4858 if (tevent_req_nterror(req
, status
)) {
4861 tevent_req_done(req
);
4864 NTSTATUS
cli_get_ea_list_path_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
4865 size_t *pnum_eas
, struct ea_struct
**peas
)
4867 struct cli_get_ea_list_path_state
*state
= tevent_req_data(
4868 req
, struct cli_get_ea_list_path_state
);
4871 if (tevent_req_is_nterror(req
, &status
)) {
4874 if (!parse_ea_blob(mem_ctx
, state
->data
, state
->num_data
,
4876 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
4878 return NT_STATUS_OK
;
4881 NTSTATUS
cli_get_ea_list_path(struct cli_state
*cli
, const char *path
,
4884 struct ea_struct
**pea_list
)
4886 TALLOC_CTX
*frame
= NULL
;
4887 struct tevent_context
*ev
= NULL
;
4888 struct tevent_req
*req
= NULL
;
4889 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
4891 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
4892 return cli_smb2_get_ea_list_path(cli
,
4899 frame
= talloc_stackframe();
4901 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
4903 * Can't use sync call while an async call is in flight
4905 status
= NT_STATUS_INVALID_PARAMETER
;
4908 ev
= samba_tevent_context_init(frame
);
4912 req
= cli_get_ea_list_path_send(frame
, ev
, cli
, path
);
4916 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
4919 status
= cli_get_ea_list_path_recv(req
, ctx
, pnum_eas
, pea_list
);
4925 /****************************************************************************
4926 Convert open "flags" arg to uint32_t on wire.
4927 ****************************************************************************/
4929 static uint32_t open_flags_to_wire(int flags
)
4931 int open_mode
= flags
& O_ACCMODE
;
4934 switch (open_mode
) {
4936 ret
|= SMB_O_WRONLY
;
4943 ret
|= SMB_O_RDONLY
;
4947 if (flags
& O_CREAT
) {
4950 if (flags
& O_EXCL
) {
4953 if (flags
& O_TRUNC
) {
4957 if (flags
& O_SYNC
) {
4961 if (flags
& O_APPEND
) {
4962 ret
|= SMB_O_APPEND
;
4964 #if defined(O_DIRECT)
4965 if (flags
& O_DIRECT
) {
4966 ret
|= SMB_O_DIRECT
;
4969 #if defined(O_DIRECTORY)
4970 if (flags
& O_DIRECTORY
) {
4971 ret
|= SMB_O_DIRECTORY
;
4977 /****************************************************************************
4978 Open a file - POSIX semantics. Returns fnum. Doesn't request oplock.
4979 ****************************************************************************/
4981 struct posix_open_state
{
4985 uint16_t fnum
; /* Out */
4988 static void cli_posix_open_internal_done(struct tevent_req
*subreq
)
4990 struct tevent_req
*req
= tevent_req_callback_data(
4991 subreq
, struct tevent_req
);
4992 struct posix_open_state
*state
= tevent_req_data(req
, struct posix_open_state
);
4997 status
= cli_trans_recv(subreq
, state
, NULL
, NULL
, 0, NULL
,
4998 NULL
, 0, NULL
, &data
, 12, &num_data
);
4999 TALLOC_FREE(subreq
);
5000 if (tevent_req_nterror(req
, status
)) {
5003 state
->fnum
= SVAL(data
,2);
5004 tevent_req_done(req
);
5007 static struct tevent_req
*cli_posix_open_internal_send(TALLOC_CTX
*mem_ctx
,
5008 struct tevent_context
*ev
,
5009 struct cli_state
*cli
,
5015 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
5016 struct posix_open_state
*state
= NULL
;
5017 uint32_t wire_flags
= open_flags_to_wire(flags
);
5019 req
= tevent_req_create(mem_ctx
, &state
, struct posix_open_state
);
5024 /* Setup setup word. */
5025 SSVAL(&state
->setup
, 0, TRANSACT2_SETPATHINFO
);
5027 /* Setup param array. */
5028 state
->param
= talloc_array(state
, uint8_t, 6);
5029 if (tevent_req_nomem(state
->param
, req
)) {
5030 return tevent_req_post(req
, ev
);
5032 memset(state
->param
, '\0', 6);
5033 SSVAL(state
->param
, 0, SMB_POSIX_PATH_OPEN
);
5035 state
->param
= trans2_bytes_push_str(state
->param
, smbXcli_conn_use_unicode(cli
->conn
), fname
,
5036 strlen(fname
)+1, NULL
);
5038 if (tevent_req_nomem(state
->param
, req
)) {
5039 return tevent_req_post(req
, ev
);
5042 /* Setup data words. */
5044 wire_flags
|= SMB_O_DIRECTORY
;
5047 SIVAL(state
->data
,0,0); /* No oplock. */
5048 SIVAL(state
->data
,4,wire_flags
);
5049 SIVAL(state
->data
,8,unix_perms_to_wire(mode
));
5050 SIVAL(state
->data
,12,0); /* Top bits of perms currently undefined. */
5051 SSVAL(state
->data
,16,SMB_NO_INFO_LEVEL_RETURNED
); /* No info level returned. */
5053 subreq
= cli_trans_send(state
, /* mem ctx. */
5054 ev
, /* event ctx. */
5055 cli
, /* cli_state. */
5056 0, /* additional_flags2 */
5057 SMBtrans2
, /* cmd. */
5058 NULL
, /* pipe name. */
5062 &state
->setup
, /* setup. */
5063 1, /* num setup uint16_t words. */
5064 0, /* max returned setup. */
5065 state
->param
, /* param. */
5066 talloc_get_size(state
->param
),/* num param. */
5067 2, /* max returned param. */
5068 state
->data
, /* data. */
5070 12); /* max returned data. */
5072 if (tevent_req_nomem(subreq
, req
)) {
5073 return tevent_req_post(req
, ev
);
5075 tevent_req_set_callback(subreq
, cli_posix_open_internal_done
, req
);
5079 struct tevent_req
*cli_posix_open_send(TALLOC_CTX
*mem_ctx
,
5080 struct tevent_context
*ev
,
5081 struct cli_state
*cli
,
5086 return cli_posix_open_internal_send(mem_ctx
, ev
,
5087 cli
, fname
, flags
, mode
, false);
5090 NTSTATUS
cli_posix_open_recv(struct tevent_req
*req
, uint16_t *pfnum
)
5092 struct posix_open_state
*state
= tevent_req_data(req
, struct posix_open_state
);
5095 if (tevent_req_is_nterror(req
, &status
)) {
5098 *pfnum
= state
->fnum
;
5099 return NT_STATUS_OK
;
5102 /****************************************************************************
5103 Open - POSIX semantics. Doesn't request oplock.
5104 ****************************************************************************/
5106 NTSTATUS
cli_posix_open(struct cli_state
*cli
, const char *fname
,
5107 int flags
, mode_t mode
, uint16_t *pfnum
)
5110 TALLOC_CTX
*frame
= talloc_stackframe();
5111 struct tevent_context
*ev
= NULL
;
5112 struct tevent_req
*req
= NULL
;
5113 NTSTATUS status
= NT_STATUS_OK
;
5115 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
5117 * Can't use sync call while an async call is in flight
5119 status
= NT_STATUS_INVALID_PARAMETER
;
5123 ev
= samba_tevent_context_init(frame
);
5125 status
= NT_STATUS_NO_MEMORY
;
5129 req
= cli_posix_open_send(frame
,
5136 status
= NT_STATUS_NO_MEMORY
;
5140 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5144 status
= cli_posix_open_recv(req
, pfnum
);
5151 struct tevent_req
*cli_posix_mkdir_send(TALLOC_CTX
*mem_ctx
,
5152 struct tevent_context
*ev
,
5153 struct cli_state
*cli
,
5157 return cli_posix_open_internal_send(mem_ctx
, ev
,
5158 cli
, fname
, O_CREAT
, mode
, true);
5161 NTSTATUS
cli_posix_mkdir_recv(struct tevent_req
*req
)
5163 return tevent_req_simple_recv_ntstatus(req
);
5166 NTSTATUS
cli_posix_mkdir(struct cli_state
*cli
, const char *fname
, mode_t mode
)
5168 TALLOC_CTX
*frame
= talloc_stackframe();
5169 struct tevent_context
*ev
= NULL
;
5170 struct tevent_req
*req
= NULL
;
5171 NTSTATUS status
= NT_STATUS_OK
;
5173 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
5175 * Can't use sync call while an async call is in flight
5177 status
= NT_STATUS_INVALID_PARAMETER
;
5181 ev
= samba_tevent_context_init(frame
);
5183 status
= NT_STATUS_NO_MEMORY
;
5187 req
= cli_posix_mkdir_send(frame
,
5193 status
= NT_STATUS_NO_MEMORY
;
5197 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5201 status
= cli_posix_mkdir_recv(req
);
5208 /****************************************************************************
5209 unlink or rmdir - POSIX semantics.
5210 ****************************************************************************/
5212 struct cli_posix_unlink_internal_state
{
5216 static void cli_posix_unlink_internal_done(struct tevent_req
*subreq
);
5218 static struct tevent_req
*cli_posix_unlink_internal_send(TALLOC_CTX
*mem_ctx
,
5219 struct tevent_context
*ev
,
5220 struct cli_state
*cli
,
5224 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
5225 struct cli_posix_unlink_internal_state
*state
= NULL
;
5227 req
= tevent_req_create(mem_ctx
, &state
,
5228 struct cli_posix_unlink_internal_state
);
5233 /* Setup data word. */
5234 SSVAL(state
->data
, 0, level
);
5236 subreq
= cli_setpathinfo_send(state
, ev
, cli
,
5237 SMB_POSIX_PATH_UNLINK
,
5239 state
->data
, sizeof(state
->data
));
5240 if (tevent_req_nomem(subreq
, req
)) {
5241 return tevent_req_post(req
, ev
);
5243 tevent_req_set_callback(subreq
, cli_posix_unlink_internal_done
, req
);
5247 static void cli_posix_unlink_internal_done(struct tevent_req
*subreq
)
5249 NTSTATUS status
= cli_setpathinfo_recv(subreq
);
5250 tevent_req_simple_finish_ntstatus(subreq
, status
);
5253 struct tevent_req
*cli_posix_unlink_send(TALLOC_CTX
*mem_ctx
,
5254 struct tevent_context
*ev
,
5255 struct cli_state
*cli
,
5258 return cli_posix_unlink_internal_send(mem_ctx
, ev
, cli
, fname
,
5259 SMB_POSIX_UNLINK_FILE_TARGET
);
5262 NTSTATUS
cli_posix_unlink_recv(struct tevent_req
*req
)
5264 return tevent_req_simple_recv_ntstatus(req
);
5267 /****************************************************************************
5268 unlink - POSIX semantics.
5269 ****************************************************************************/
5271 NTSTATUS
cli_posix_unlink(struct cli_state
*cli
, const char *fname
)
5273 TALLOC_CTX
*frame
= talloc_stackframe();
5274 struct tevent_context
*ev
= NULL
;
5275 struct tevent_req
*req
= NULL
;
5276 NTSTATUS status
= NT_STATUS_OK
;
5278 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
5280 * Can't use sync call while an async call is in flight
5282 status
= NT_STATUS_INVALID_PARAMETER
;
5286 ev
= samba_tevent_context_init(frame
);
5288 status
= NT_STATUS_NO_MEMORY
;
5292 req
= cli_posix_unlink_send(frame
,
5297 status
= NT_STATUS_NO_MEMORY
;
5301 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5305 status
= cli_posix_unlink_recv(req
);
5312 /****************************************************************************
5313 rmdir - POSIX semantics.
5314 ****************************************************************************/
5316 struct tevent_req
*cli_posix_rmdir_send(TALLOC_CTX
*mem_ctx
,
5317 struct tevent_context
*ev
,
5318 struct cli_state
*cli
,
5321 return cli_posix_unlink_internal_send(
5322 mem_ctx
, ev
, cli
, fname
,
5323 SMB_POSIX_UNLINK_DIRECTORY_TARGET
);
5326 NTSTATUS
cli_posix_rmdir_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
)
5328 return tevent_req_simple_recv_ntstatus(req
);
5331 NTSTATUS
cli_posix_rmdir(struct cli_state
*cli
, const char *fname
)
5333 TALLOC_CTX
*frame
= talloc_stackframe();
5334 struct tevent_context
*ev
= NULL
;
5335 struct tevent_req
*req
= NULL
;
5336 NTSTATUS status
= NT_STATUS_OK
;
5338 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
5340 * Can't use sync call while an async call is in flight
5342 status
= NT_STATUS_INVALID_PARAMETER
;
5346 ev
= samba_tevent_context_init(frame
);
5348 status
= NT_STATUS_NO_MEMORY
;
5352 req
= cli_posix_rmdir_send(frame
,
5357 status
= NT_STATUS_NO_MEMORY
;
5361 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5365 status
= cli_posix_rmdir_recv(req
, frame
);
5372 /****************************************************************************
5374 ****************************************************************************/
5376 struct cli_notify_state
{
5378 uint32_t num_changes
;
5379 struct notify_change
*changes
;
5382 static void cli_notify_done(struct tevent_req
*subreq
);
5384 struct tevent_req
*cli_notify_send(TALLOC_CTX
*mem_ctx
,
5385 struct tevent_context
*ev
,
5386 struct cli_state
*cli
, uint16_t fnum
,
5387 uint32_t buffer_size
,
5388 uint32_t completion_filter
, bool recursive
)
5390 struct tevent_req
*req
, *subreq
;
5391 struct cli_notify_state
*state
;
5392 unsigned old_timeout
;
5394 req
= tevent_req_create(mem_ctx
, &state
, struct cli_notify_state
);
5399 SIVAL(state
->setup
, 0, completion_filter
);
5400 SSVAL(state
->setup
, 4, fnum
);
5401 SSVAL(state
->setup
, 6, recursive
);
5404 * Notifies should not time out
5406 old_timeout
= cli_set_timeout(cli
, 0);
5408 subreq
= cli_trans_send(
5409 state
, /* mem ctx. */
5410 ev
, /* event ctx. */
5411 cli
, /* cli_state. */
5412 0, /* additional_flags2 */
5413 SMBnttrans
, /* cmd. */
5414 NULL
, /* pipe name. */
5416 NT_TRANSACT_NOTIFY_CHANGE
, /* function. */
5418 (uint16_t *)state
->setup
, /* setup. */
5419 4, /* num setup uint16_t words. */
5420 0, /* max returned setup. */
5423 buffer_size
, /* max returned param. */
5426 0); /* max returned data. */
5428 cli_set_timeout(cli
, old_timeout
);
5430 if (tevent_req_nomem(subreq
, req
)) {
5431 return tevent_req_post(req
, ev
);
5433 tevent_req_set_callback(subreq
, cli_notify_done
, req
);
5437 static void cli_notify_done(struct tevent_req
*subreq
)
5439 struct tevent_req
*req
= tevent_req_callback_data(
5440 subreq
, struct tevent_req
);
5441 struct cli_notify_state
*state
= tevent_req_data(
5442 req
, struct cli_notify_state
);
5445 uint32_t i
, ofs
, num_params
;
5448 status
= cli_trans_recv(subreq
, talloc_tos(), &flags2
, NULL
, 0, NULL
,
5449 ¶ms
, 0, &num_params
, NULL
, 0, NULL
);
5450 TALLOC_FREE(subreq
);
5451 if (tevent_req_nterror(req
, status
)) {
5452 DEBUG(10, ("cli_trans_recv returned %s\n", nt_errstr(status
)));
5456 state
->num_changes
= 0;
5459 while (num_params
- ofs
> 12) {
5460 uint32_t next
= IVAL(params
, ofs
);
5461 state
->num_changes
+= 1;
5463 if ((next
== 0) || (ofs
+next
>= num_params
)) {
5469 state
->changes
= talloc_array(state
, struct notify_change
,
5470 state
->num_changes
);
5471 if (tevent_req_nomem(state
->changes
, req
)) {
5472 TALLOC_FREE(params
);
5478 for (i
=0; i
<state
->num_changes
; i
++) {
5479 uint32_t next
= IVAL(params
, ofs
);
5480 uint32_t len
= IVAL(params
, ofs
+8);
5484 if (trans_oob(num_params
, ofs
+ 12, len
)) {
5485 TALLOC_FREE(params
);
5487 req
, NT_STATUS_INVALID_NETWORK_RESPONSE
);
5491 state
->changes
[i
].action
= IVAL(params
, ofs
+4);
5492 ret
= clistr_pull_talloc(state
->changes
, (char *)params
, flags2
,
5493 &name
, params
+ofs
+12, len
,
5494 STR_TERMINATE
|STR_UNICODE
);
5496 TALLOC_FREE(params
);
5497 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
5500 state
->changes
[i
].name
= name
;
5504 TALLOC_FREE(params
);
5505 tevent_req_done(req
);
5508 NTSTATUS
cli_notify_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
5509 uint32_t *pnum_changes
,
5510 struct notify_change
**pchanges
)
5512 struct cli_notify_state
*state
= tevent_req_data(
5513 req
, struct cli_notify_state
);
5516 if (tevent_req_is_nterror(req
, &status
)) {
5520 *pnum_changes
= state
->num_changes
;
5521 *pchanges
= talloc_move(mem_ctx
, &state
->changes
);
5522 return NT_STATUS_OK
;
5525 NTSTATUS
cli_notify(struct cli_state
*cli
, uint16_t fnum
, uint32_t buffer_size
,
5526 uint32_t completion_filter
, bool recursive
,
5527 TALLOC_CTX
*mem_ctx
, uint32_t *pnum_changes
,
5528 struct notify_change
**pchanges
)
5530 TALLOC_CTX
*frame
= talloc_stackframe();
5531 struct tevent_context
*ev
;
5532 struct tevent_req
*req
;
5533 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
5535 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
5537 * Can't use sync call while an async call is in flight
5539 status
= NT_STATUS_INVALID_PARAMETER
;
5542 ev
= samba_tevent_context_init(frame
);
5546 req
= cli_notify_send(ev
, ev
, cli
, fnum
, buffer_size
,
5547 completion_filter
, recursive
);
5551 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5554 status
= cli_notify_recv(req
, mem_ctx
, pnum_changes
, pchanges
);
5560 struct cli_qpathinfo_state
{
5569 static void cli_qpathinfo_done(struct tevent_req
*subreq
);
5571 struct tevent_req
*cli_qpathinfo_send(TALLOC_CTX
*mem_ctx
,
5572 struct tevent_context
*ev
,
5573 struct cli_state
*cli
, const char *fname
,
5574 uint16_t level
, uint32_t min_rdata
,
5577 struct tevent_req
*req
, *subreq
;
5578 struct cli_qpathinfo_state
*state
;
5579 uint16_t additional_flags2
= 0;
5581 req
= tevent_req_create(mem_ctx
, &state
, struct cli_qpathinfo_state
);
5585 state
->min_rdata
= min_rdata
;
5586 SSVAL(state
->setup
, 0, TRANSACT2_QPATHINFO
);
5588 state
->param
= talloc_zero_array(state
, uint8_t, 6);
5589 if (tevent_req_nomem(state
->param
, req
)) {
5590 return tevent_req_post(req
, ev
);
5592 SSVAL(state
->param
, 0, level
);
5593 state
->param
= trans2_bytes_push_str(
5594 state
->param
, smbXcli_conn_use_unicode(cli
->conn
), fname
, strlen(fname
)+1, NULL
);
5595 if (tevent_req_nomem(state
->param
, req
)) {
5596 return tevent_req_post(req
, ev
);
5599 if (clistr_is_previous_version_path(fname
) &&
5600 !INFO_LEVEL_IS_UNIX(level
)) {
5601 additional_flags2
= FLAGS2_REPARSE_PATH
;
5604 subreq
= cli_trans_send(
5605 state
, /* mem ctx. */
5606 ev
, /* event ctx. */
5607 cli
, /* cli_state. */
5608 additional_flags2
, /* additional_flags2 */
5609 SMBtrans2
, /* cmd. */
5610 NULL
, /* pipe name. */
5614 state
->setup
, /* setup. */
5615 1, /* num setup uint16_t words. */
5616 0, /* max returned setup. */
5617 state
->param
, /* param. */
5618 talloc_get_size(state
->param
), /* num param. */
5619 2, /* max returned param. */
5622 max_rdata
); /* max returned data. */
5624 if (tevent_req_nomem(subreq
, req
)) {
5625 return tevent_req_post(req
, ev
);
5627 tevent_req_set_callback(subreq
, cli_qpathinfo_done
, req
);
5631 static void cli_qpathinfo_done(struct tevent_req
*subreq
)
5633 struct tevent_req
*req
= tevent_req_callback_data(
5634 subreq
, struct tevent_req
);
5635 struct cli_qpathinfo_state
*state
= tevent_req_data(
5636 req
, struct cli_qpathinfo_state
);
5639 status
= cli_trans_recv(subreq
, state
, NULL
, NULL
, 0, NULL
,
5641 &state
->rdata
, state
->min_rdata
,
5643 if (tevent_req_nterror(req
, status
)) {
5646 tevent_req_done(req
);
5649 NTSTATUS
cli_qpathinfo_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
5650 uint8_t **rdata
, uint32_t *num_rdata
)
5652 struct cli_qpathinfo_state
*state
= tevent_req_data(
5653 req
, struct cli_qpathinfo_state
);
5656 if (tevent_req_is_nterror(req
, &status
)) {
5659 if (rdata
!= NULL
) {
5660 *rdata
= talloc_move(mem_ctx
, &state
->rdata
);
5662 TALLOC_FREE(state
->rdata
);
5664 if (num_rdata
!= NULL
) {
5665 *num_rdata
= state
->num_rdata
;
5667 return NT_STATUS_OK
;
5670 NTSTATUS
cli_qpathinfo(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
,
5671 const char *fname
, uint16_t level
, uint32_t min_rdata
,
5673 uint8_t **rdata
, uint32_t *num_rdata
)
5675 TALLOC_CTX
*frame
= talloc_stackframe();
5676 struct tevent_context
*ev
;
5677 struct tevent_req
*req
;
5678 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
5680 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
5682 * Can't use sync call while an async call is in flight
5684 status
= NT_STATUS_INVALID_PARAMETER
;
5687 ev
= samba_tevent_context_init(frame
);
5691 req
= cli_qpathinfo_send(frame
, ev
, cli
, fname
, level
, min_rdata
,
5696 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5699 status
= cli_qpathinfo_recv(req
, mem_ctx
, rdata
, num_rdata
);
5705 struct cli_qfileinfo_state
{
5709 uint16_t recv_flags2
;
5715 static void cli_qfileinfo_done(struct tevent_req
*subreq
);
5717 struct tevent_req
*cli_qfileinfo_send(TALLOC_CTX
*mem_ctx
,
5718 struct tevent_context
*ev
,
5719 struct cli_state
*cli
, uint16_t fnum
,
5720 uint16_t level
, uint32_t min_rdata
,
5723 struct tevent_req
*req
, *subreq
;
5724 struct cli_qfileinfo_state
*state
;
5726 req
= tevent_req_create(mem_ctx
, &state
, struct cli_qfileinfo_state
);
5730 state
->min_rdata
= min_rdata
;
5731 SSVAL(state
->param
, 0, fnum
);
5732 SSVAL(state
->param
, 2, level
);
5733 SSVAL(state
->setup
, 0, TRANSACT2_QFILEINFO
);
5735 subreq
= cli_trans_send(
5736 state
, /* mem ctx. */
5737 ev
, /* event ctx. */
5738 cli
, /* cli_state. */
5739 0, /* additional_flags2 */
5740 SMBtrans2
, /* cmd. */
5741 NULL
, /* pipe name. */
5745 state
->setup
, /* setup. */
5746 1, /* num setup uint16_t words. */
5747 0, /* max returned setup. */
5748 state
->param
, /* param. */
5749 sizeof(state
->param
), /* num param. */
5750 2, /* max returned param. */
5753 max_rdata
); /* max returned data. */
5755 if (tevent_req_nomem(subreq
, req
)) {
5756 return tevent_req_post(req
, ev
);
5758 tevent_req_set_callback(subreq
, cli_qfileinfo_done
, req
);
5762 static void cli_qfileinfo_done(struct tevent_req
*subreq
)
5764 struct tevent_req
*req
= tevent_req_callback_data(
5765 subreq
, struct tevent_req
);
5766 struct cli_qfileinfo_state
*state
= tevent_req_data(
5767 req
, struct cli_qfileinfo_state
);
5770 status
= cli_trans_recv(subreq
, state
,
5771 &state
->recv_flags2
,
5774 &state
->rdata
, state
->min_rdata
,
5776 if (tevent_req_nterror(req
, status
)) {
5779 tevent_req_done(req
);
5782 NTSTATUS
cli_qfileinfo_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
5783 uint16_t *recv_flags2
,
5784 uint8_t **rdata
, uint32_t *num_rdata
)
5786 struct cli_qfileinfo_state
*state
= tevent_req_data(
5787 req
, struct cli_qfileinfo_state
);
5790 if (tevent_req_is_nterror(req
, &status
)) {
5794 if (recv_flags2
!= NULL
) {
5795 *recv_flags2
= state
->recv_flags2
;
5797 if (rdata
!= NULL
) {
5798 *rdata
= talloc_move(mem_ctx
, &state
->rdata
);
5800 TALLOC_FREE(state
->rdata
);
5802 if (num_rdata
!= NULL
) {
5803 *num_rdata
= state
->num_rdata
;
5805 return NT_STATUS_OK
;
5808 NTSTATUS
cli_qfileinfo(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
,
5809 uint16_t fnum
, uint16_t level
, uint32_t min_rdata
,
5810 uint32_t max_rdata
, uint16_t *recv_flags2
,
5811 uint8_t **rdata
, uint32_t *num_rdata
)
5813 TALLOC_CTX
*frame
= talloc_stackframe();
5814 struct tevent_context
*ev
;
5815 struct tevent_req
*req
;
5816 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
5818 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
5820 * Can't use sync call while an async call is in flight
5822 status
= NT_STATUS_INVALID_PARAMETER
;
5825 ev
= samba_tevent_context_init(frame
);
5829 req
= cli_qfileinfo_send(frame
, ev
, cli
, fnum
, level
, min_rdata
,
5834 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5837 status
= cli_qfileinfo_recv(req
, mem_ctx
, recv_flags2
, rdata
, num_rdata
);
5843 struct cli_flush_state
{
5847 static void cli_flush_done(struct tevent_req
*subreq
);
5849 struct tevent_req
*cli_flush_send(TALLOC_CTX
*mem_ctx
,
5850 struct tevent_context
*ev
,
5851 struct cli_state
*cli
,
5854 struct tevent_req
*req
, *subreq
;
5855 struct cli_flush_state
*state
;
5857 req
= tevent_req_create(mem_ctx
, &state
, struct cli_flush_state
);
5861 SSVAL(state
->vwv
+ 0, 0, fnum
);
5863 subreq
= cli_smb_send(state
, ev
, cli
, SMBflush
, 0, 0, 1, state
->vwv
,
5865 if (tevent_req_nomem(subreq
, req
)) {
5866 return tevent_req_post(req
, ev
);
5868 tevent_req_set_callback(subreq
, cli_flush_done
, req
);
5872 static void cli_flush_done(struct tevent_req
*subreq
)
5874 struct tevent_req
*req
= tevent_req_callback_data(
5875 subreq
, struct tevent_req
);
5878 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
5879 TALLOC_FREE(subreq
);
5880 if (tevent_req_nterror(req
, status
)) {
5883 tevent_req_done(req
);
5886 NTSTATUS
cli_flush_recv(struct tevent_req
*req
)
5888 return tevent_req_simple_recv_ntstatus(req
);
5891 NTSTATUS
cli_flush(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
, uint16_t fnum
)
5893 TALLOC_CTX
*frame
= talloc_stackframe();
5894 struct tevent_context
*ev
;
5895 struct tevent_req
*req
;
5896 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
5898 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
5900 * Can't use sync call while an async call is in flight
5902 status
= NT_STATUS_INVALID_PARAMETER
;
5905 ev
= samba_tevent_context_init(frame
);
5909 req
= cli_flush_send(frame
, ev
, cli
, fnum
);
5913 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5916 status
= cli_flush_recv(req
);
5922 struct cli_shadow_copy_data_state
{
5929 static void cli_shadow_copy_data_done(struct tevent_req
*subreq
);
5931 struct tevent_req
*cli_shadow_copy_data_send(TALLOC_CTX
*mem_ctx
,
5932 struct tevent_context
*ev
,
5933 struct cli_state
*cli
,
5937 struct tevent_req
*req
, *subreq
;
5938 struct cli_shadow_copy_data_state
*state
;
5941 req
= tevent_req_create(mem_ctx
, &state
,
5942 struct cli_shadow_copy_data_state
);
5946 state
->get_names
= get_names
;
5947 ret_size
= get_names
? CLI_BUFFER_SIZE
: 16;
5949 SIVAL(state
->setup
+ 0, 0, FSCTL_GET_SHADOW_COPY_DATA
);
5950 SSVAL(state
->setup
+ 2, 0, fnum
);
5951 SCVAL(state
->setup
+ 3, 0, 1); /* isFsctl */
5952 SCVAL(state
->setup
+ 3, 1, 0); /* compfilter, isFlags (WSSP) */
5954 subreq
= cli_trans_send(
5955 state
, ev
, cli
, 0, SMBnttrans
, NULL
, 0, NT_TRANSACT_IOCTL
, 0,
5956 state
->setup
, ARRAY_SIZE(state
->setup
), 0,
5959 if (tevent_req_nomem(subreq
, req
)) {
5960 return tevent_req_post(req
, ev
);
5962 tevent_req_set_callback(subreq
, cli_shadow_copy_data_done
, req
);
5966 static void cli_shadow_copy_data_done(struct tevent_req
*subreq
)
5968 struct tevent_req
*req
= tevent_req_callback_data(
5969 subreq
, struct tevent_req
);
5970 struct cli_shadow_copy_data_state
*state
= tevent_req_data(
5971 req
, struct cli_shadow_copy_data_state
);
5974 status
= cli_trans_recv(subreq
, state
, NULL
,
5975 NULL
, 0, NULL
, /* setup */
5976 NULL
, 0, NULL
, /* param */
5977 &state
->data
, 12, &state
->num_data
);
5978 TALLOC_FREE(subreq
);
5979 if (tevent_req_nterror(req
, status
)) {
5982 tevent_req_done(req
);
5985 NTSTATUS
cli_shadow_copy_data_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
5986 char ***pnames
, int *pnum_names
)
5988 struct cli_shadow_copy_data_state
*state
= tevent_req_data(
5989 req
, struct cli_shadow_copy_data_state
);
5995 if (tevent_req_is_nterror(req
, &status
)) {
5998 num_names
= IVAL(state
->data
, 4);
5999 dlength
= IVAL(state
->data
, 8);
6001 if (!state
->get_names
) {
6002 *pnum_names
= num_names
;
6003 return NT_STATUS_OK
;
6006 if (dlength
+12 > state
->num_data
) {
6007 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
6009 names
= talloc_array(mem_ctx
, char *, num_names
);
6010 if (names
== NULL
) {
6011 return NT_STATUS_NO_MEMORY
;
6014 for (i
=0; i
<num_names
; i
++) {
6017 size_t converted_size
;
6019 src
= state
->data
+ 12 + i
* 2 * sizeof(SHADOW_COPY_LABEL
);
6020 ret
= convert_string_talloc(
6021 names
, CH_UTF16LE
, CH_UNIX
,
6022 src
, 2 * sizeof(SHADOW_COPY_LABEL
),
6023 &names
[i
], &converted_size
);
6026 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
6029 *pnum_names
= num_names
;
6031 return NT_STATUS_OK
;
6034 NTSTATUS
cli_shadow_copy_data(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
,
6035 uint16_t fnum
, bool get_names
,
6036 char ***pnames
, int *pnum_names
)
6038 TALLOC_CTX
*frame
= talloc_stackframe();
6039 struct tevent_context
*ev
;
6040 struct tevent_req
*req
;
6041 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
6043 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
6045 * Can't use sync call while an async call is in flight
6047 status
= NT_STATUS_INVALID_PARAMETER
;
6050 ev
= samba_tevent_context_init(frame
);
6054 req
= cli_shadow_copy_data_send(frame
, ev
, cli
, fnum
, get_names
);
6058 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
6061 status
= cli_shadow_copy_data_recv(req
, mem_ctx
, pnames
, pnum_names
);