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/security.h"
30 #include "../libcli/smb/smbXcli_base.h"
32 struct cli_setpathinfo_state
{
37 static void cli_setpathinfo_done(struct tevent_req
*subreq
);
39 struct tevent_req
*cli_setpathinfo_send(TALLOC_CTX
*mem_ctx
,
40 struct tevent_context
*ev
,
41 struct cli_state
*cli
,
47 struct tevent_req
*req
, *subreq
;
48 struct cli_setpathinfo_state
*state
;
49 uint16_t additional_flags2
= 0;
51 req
= tevent_req_create(mem_ctx
, &state
,
52 struct cli_setpathinfo_state
);
57 /* Setup setup word. */
58 SSVAL(&state
->setup
, 0, TRANSACT2_SETPATHINFO
);
60 /* Setup param array. */
61 state
->param
= talloc_zero_array(state
, uint8_t, 6);
62 if (tevent_req_nomem(state
->param
, req
)) {
63 return tevent_req_post(req
, ev
);
65 SSVAL(state
->param
, 0, level
);
67 state
->param
= trans2_bytes_push_str(
68 state
->param
, smbXcli_conn_use_unicode(cli
->conn
), path
, strlen(path
)+1, NULL
);
69 if (tevent_req_nomem(state
->param
, req
)) {
70 return tevent_req_post(req
, ev
);
73 if (clistr_is_previous_version_path(path
, NULL
, NULL
, NULL
) &&
74 !INFO_LEVEL_IS_UNIX(level
)) {
75 additional_flags2
= FLAGS2_REPARSE_PATH
;
78 subreq
= cli_trans_send(
82 additional_flags2
, /* additional_flags2 */
84 NULL
, /* pipe name. */
88 &state
->setup
, /* setup. */
89 1, /* num setup uint16_t words. */
90 0, /* max returned setup. */
91 state
->param
, /* param. */
92 talloc_get_size(state
->param
), /* num param. */
93 2, /* max returned param. */
95 data_len
, /* num data. */
96 0); /* max returned data. */
98 if (tevent_req_nomem(subreq
, req
)) {
99 return tevent_req_post(req
, ev
);
101 tevent_req_set_callback(subreq
, cli_setpathinfo_done
, req
);
105 static void cli_setpathinfo_done(struct tevent_req
*subreq
)
107 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, NULL
, 0, NULL
,
108 NULL
, 0, NULL
, NULL
, 0, NULL
);
109 tevent_req_simple_finish_ntstatus(subreq
, status
);
112 NTSTATUS
cli_setpathinfo_recv(struct tevent_req
*req
)
114 return tevent_req_simple_recv_ntstatus(req
);
117 NTSTATUS
cli_setpathinfo(struct cli_state
*cli
,
123 TALLOC_CTX
*frame
= talloc_stackframe();
124 struct tevent_context
*ev
;
125 struct tevent_req
*req
;
126 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
128 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
130 * Can't use sync call while an async call is in flight
132 status
= NT_STATUS_INVALID_PARAMETER
;
135 ev
= samba_tevent_context_init(frame
);
139 req
= cli_setpathinfo_send(ev
, ev
, cli
, level
, path
, data
, data_len
);
143 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
146 status
= cli_setpathinfo_recv(req
);
152 /****************************************************************************
153 Hard/Symlink a file (UNIX extensions).
154 Creates new name (sym)linked to link_target.
155 ****************************************************************************/
157 struct cli_posix_link_internal_state
{
161 static void cli_posix_link_internal_done(struct tevent_req
*subreq
);
163 static struct tevent_req
*cli_posix_link_internal_send(TALLOC_CTX
*mem_ctx
,
164 struct tevent_context
*ev
,
165 struct cli_state
*cli
,
167 const char *link_target
,
170 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
171 struct cli_posix_link_internal_state
*state
= NULL
;
173 req
= tevent_req_create(mem_ctx
, &state
,
174 struct cli_posix_link_internal_state
);
179 /* Setup data array. */
180 state
->data
= talloc_array(state
, uint8_t, 0);
181 if (tevent_req_nomem(state
->data
, req
)) {
182 return tevent_req_post(req
, ev
);
184 state
->data
= trans2_bytes_push_str(
185 state
->data
, smbXcli_conn_use_unicode(cli
->conn
),
186 link_target
, strlen(link_target
)+1, NULL
);
188 subreq
= cli_setpathinfo_send(
189 state
, ev
, cli
, level
, newname
,
190 state
->data
, talloc_get_size(state
->data
));
191 if (tevent_req_nomem(subreq
, req
)) {
192 return tevent_req_post(req
, ev
);
194 tevent_req_set_callback(subreq
, cli_posix_link_internal_done
, req
);
198 static void cli_posix_link_internal_done(struct tevent_req
*subreq
)
200 NTSTATUS status
= cli_setpathinfo_recv(subreq
);
201 tevent_req_simple_finish_ntstatus(subreq
, status
);
204 static NTSTATUS
cli_posix_link_internal_recv(struct tevent_req
*req
)
206 return tevent_req_simple_recv_ntstatus(req
);
209 /****************************************************************************
210 Symlink a file (UNIX extensions).
211 ****************************************************************************/
213 struct cli_posix_symlink_state
{
217 static void cli_posix_symlink_done(struct tevent_req
*subreq
);
219 struct tevent_req
*cli_posix_symlink_send(TALLOC_CTX
*mem_ctx
,
220 struct tevent_context
*ev
,
221 struct cli_state
*cli
,
222 const char *link_target
,
225 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
226 struct cli_posix_symlink_state
*state
= NULL
;
228 req
= tevent_req_create(
229 mem_ctx
, &state
, struct cli_posix_symlink_state
);
234 subreq
= cli_posix_link_internal_send(
235 mem_ctx
, ev
, cli
, SMB_SET_FILE_UNIX_LINK
, link_target
, newname
);
236 if (tevent_req_nomem(subreq
, req
)) {
237 return tevent_req_post(req
, ev
);
239 tevent_req_set_callback(subreq
, cli_posix_symlink_done
, req
);
243 static void cli_posix_symlink_done(struct tevent_req
*subreq
)
245 NTSTATUS status
= cli_posix_link_internal_recv(subreq
);
246 tevent_req_simple_finish_ntstatus(subreq
, status
);
249 NTSTATUS
cli_posix_symlink_recv(struct tevent_req
*req
)
251 return tevent_req_simple_recv_ntstatus(req
);
254 NTSTATUS
cli_posix_symlink(struct cli_state
*cli
,
255 const char *link_target
,
258 TALLOC_CTX
*frame
= talloc_stackframe();
259 struct tevent_context
*ev
= NULL
;
260 struct tevent_req
*req
= NULL
;
261 NTSTATUS status
= NT_STATUS_OK
;
263 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
265 * Can't use sync call while an async call is in flight
267 status
= NT_STATUS_INVALID_PARAMETER
;
271 ev
= samba_tevent_context_init(frame
);
273 status
= NT_STATUS_NO_MEMORY
;
277 req
= cli_posix_symlink_send(frame
,
283 status
= NT_STATUS_NO_MEMORY
;
287 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
291 status
= cli_posix_symlink_recv(req
);
298 /****************************************************************************
299 Read a POSIX symlink.
300 ****************************************************************************/
302 struct cli_posix_readlink_state
{
303 struct cli_state
*cli
;
307 static void cli_posix_readlink_done(struct tevent_req
*subreq
);
309 struct tevent_req
*cli_posix_readlink_send(TALLOC_CTX
*mem_ctx
,
310 struct tevent_context
*ev
,
311 struct cli_state
*cli
,
314 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
315 struct cli_posix_readlink_state
*state
= NULL
;
317 req
= tevent_req_create(
318 mem_ctx
, &state
, struct cli_posix_readlink_state
);
324 subreq
= cli_qpathinfo_send(
329 SMB_QUERY_FILE_UNIX_LINK
,
332 if (tevent_req_nomem(subreq
, req
)) {
333 return tevent_req_post(req
, ev
);
335 tevent_req_set_callback(subreq
, cli_posix_readlink_done
, req
);
339 static void cli_posix_readlink_done(struct tevent_req
*subreq
)
341 struct tevent_req
*req
= tevent_req_callback_data(
342 subreq
, struct tevent_req
);
343 struct cli_posix_readlink_state
*state
= tevent_req_data(
344 req
, struct cli_posix_readlink_state
);
346 uint8_t *data
= NULL
;
349 size_t converted_size
;
352 status
= cli_qpathinfo_recv(subreq
, state
, &data
, &num_data
);
354 if (tevent_req_nterror(req
, status
)) {
358 * num_data is > 1, we've given 1 as minimum to cli_qpathinfo_send
360 if (data
[num_data
-1] != '\0') {
361 tevent_req_nterror(req
, NT_STATUS_DATA_ERROR
);
365 charset
= smbXcli_conn_use_unicode(state
->cli
->conn
) ?
368 /* The returned data is a pushed string, not raw data. */
369 ok
= convert_string_talloc(
381 tevent_req_done(req
);
384 NTSTATUS
cli_posix_readlink_recv(
385 struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
, char **target
)
387 struct cli_posix_readlink_state
*state
= tevent_req_data(
388 req
, struct cli_posix_readlink_state
);
391 if (tevent_req_is_nterror(req
, &status
)) {
394 *target
= talloc_move(mem_ctx
, &state
->converted
);
398 NTSTATUS
cli_posix_readlink(
399 struct cli_state
*cli
,
404 TALLOC_CTX
*frame
= talloc_stackframe();
405 struct tevent_context
*ev
= NULL
;
406 struct tevent_req
*req
= NULL
;
407 NTSTATUS status
= NT_STATUS_OK
;
409 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
411 * Can't use sync call while an async call is in flight
413 status
= NT_STATUS_INVALID_PARAMETER
;
417 ev
= samba_tevent_context_init(frame
);
419 status
= NT_STATUS_NO_MEMORY
;
423 req
= cli_posix_readlink_send(frame
, ev
, cli
, fname
);
425 status
= NT_STATUS_NO_MEMORY
;
429 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
433 status
= cli_posix_readlink_recv(req
, mem_ctx
, target
);
440 /****************************************************************************
441 Hard link a file (UNIX extensions).
442 ****************************************************************************/
444 struct cli_posix_hardlink_state
{
448 static void cli_posix_hardlink_done(struct tevent_req
*subreq
);
450 struct tevent_req
*cli_posix_hardlink_send(TALLOC_CTX
*mem_ctx
,
451 struct tevent_context
*ev
,
452 struct cli_state
*cli
,
456 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
457 struct cli_posix_hardlink_state
*state
= NULL
;
459 req
= tevent_req_create(
460 mem_ctx
, &state
, struct cli_posix_hardlink_state
);
465 subreq
= cli_posix_link_internal_send(
466 state
, ev
, cli
, SMB_SET_FILE_UNIX_HLINK
, oldname
, newname
);
467 if (tevent_req_nomem(subreq
, req
)) {
468 return tevent_req_post(req
, ev
);
470 tevent_req_set_callback(subreq
, cli_posix_hardlink_done
, req
);
474 static void cli_posix_hardlink_done(struct tevent_req
*subreq
)
476 NTSTATUS status
= cli_posix_link_internal_recv(subreq
);
477 tevent_req_simple_finish_ntstatus(subreq
, status
);
480 NTSTATUS
cli_posix_hardlink_recv(struct tevent_req
*req
)
482 return tevent_req_simple_recv_ntstatus(req
);
485 NTSTATUS
cli_posix_hardlink(struct cli_state
*cli
,
489 TALLOC_CTX
*frame
= talloc_stackframe();
490 struct tevent_context
*ev
= NULL
;
491 struct tevent_req
*req
= NULL
;
492 NTSTATUS status
= NT_STATUS_OK
;
494 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
496 * Can't use sync call while an async call is in flight
498 status
= NT_STATUS_INVALID_PARAMETER
;
502 ev
= samba_tevent_context_init(frame
);
504 status
= NT_STATUS_NO_MEMORY
;
508 req
= cli_posix_hardlink_send(frame
,
514 status
= NT_STATUS_NO_MEMORY
;
518 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
522 status
= cli_posix_hardlink_recv(req
);
529 /****************************************************************************
530 Do a POSIX getacl - pathname based ACL get (UNIX extensions).
531 ****************************************************************************/
533 struct getacl_state
{
538 static void cli_posix_getacl_done(struct tevent_req
*subreq
);
540 struct tevent_req
*cli_posix_getacl_send(TALLOC_CTX
*mem_ctx
,
541 struct tevent_context
*ev
,
542 struct cli_state
*cli
,
545 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
546 struct getacl_state
*state
= NULL
;
548 req
= tevent_req_create(mem_ctx
, &state
, struct getacl_state
);
552 subreq
= cli_qpathinfo_send(state
, ev
, cli
, fname
, SMB_QUERY_POSIX_ACL
,
554 if (tevent_req_nomem(subreq
, req
)) {
555 return tevent_req_post(req
, ev
);
557 tevent_req_set_callback(subreq
, cli_posix_getacl_done
, req
);
561 static void cli_posix_getacl_done(struct tevent_req
*subreq
)
563 struct tevent_req
*req
= tevent_req_callback_data(
564 subreq
, struct tevent_req
);
565 struct getacl_state
*state
= tevent_req_data(
566 req
, struct getacl_state
);
569 status
= cli_qpathinfo_recv(subreq
, state
, &state
->data
,
572 if (tevent_req_nterror(req
, status
)) {
575 tevent_req_done(req
);
578 NTSTATUS
cli_posix_getacl_recv(struct tevent_req
*req
,
583 struct getacl_state
*state
= tevent_req_data(req
, struct getacl_state
);
586 if (tevent_req_is_nterror(req
, &status
)) {
589 *prb_size
= (size_t)state
->num_data
;
590 *retbuf
= (char *)talloc_move(mem_ctx
, &state
->data
);
594 NTSTATUS
cli_posix_getacl(struct cli_state
*cli
,
600 TALLOC_CTX
*frame
= talloc_stackframe();
601 struct tevent_context
*ev
= NULL
;
602 struct tevent_req
*req
= NULL
;
603 NTSTATUS status
= NT_STATUS_OK
;
605 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
607 * Can't use sync call while an async call is in flight
609 status
= NT_STATUS_INVALID_PARAMETER
;
613 ev
= samba_tevent_context_init(frame
);
615 status
= NT_STATUS_NO_MEMORY
;
619 req
= cli_posix_getacl_send(frame
,
624 status
= NT_STATUS_NO_MEMORY
;
628 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
632 status
= cli_posix_getacl_recv(req
, mem_ctx
, prb_size
, retbuf
);
639 /****************************************************************************
640 Do a POSIX setacl - pathname based ACL set (UNIX extensions).
641 ****************************************************************************/
643 struct setacl_state
{
647 static void cli_posix_setacl_done(struct tevent_req
*subreq
);
649 struct tevent_req
*cli_posix_setacl_send(TALLOC_CTX
*mem_ctx
,
650 struct tevent_context
*ev
,
651 struct cli_state
*cli
,
656 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
657 struct setacl_state
*state
= NULL
;
659 req
= tevent_req_create(mem_ctx
, &state
, struct setacl_state
);
663 state
->data
= talloc_memdup(state
, data
, num_data
);
664 if (tevent_req_nomem(state
->data
, req
)) {
665 return tevent_req_post(req
, ev
);
668 subreq
= cli_setpathinfo_send(state
,
675 if (tevent_req_nomem(subreq
, req
)) {
676 return tevent_req_post(req
, ev
);
678 tevent_req_set_callback(subreq
, cli_posix_setacl_done
, req
);
682 static void cli_posix_setacl_done(struct tevent_req
*subreq
)
684 NTSTATUS status
= cli_setpathinfo_recv(subreq
);
685 tevent_req_simple_finish_ntstatus(subreq
, status
);
688 NTSTATUS
cli_posix_setacl_recv(struct tevent_req
*req
)
690 return tevent_req_simple_recv_ntstatus(req
);
693 NTSTATUS
cli_posix_setacl(struct cli_state
*cli
,
698 TALLOC_CTX
*frame
= talloc_stackframe();
699 struct tevent_context
*ev
= NULL
;
700 struct tevent_req
*req
= NULL
;
701 NTSTATUS status
= NT_STATUS_OK
;
703 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
705 * Can't use sync call while an async call is in flight
707 status
= NT_STATUS_INVALID_PARAMETER
;
711 ev
= samba_tevent_context_init(frame
);
713 status
= NT_STATUS_NO_MEMORY
;
717 req
= cli_posix_setacl_send(frame
,
724 status
= NT_STATUS_NO_MEMORY
;
728 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
732 status
= cli_posix_setacl_recv(req
);
739 /****************************************************************************
740 Stat a file (UNIX extensions).
741 ****************************************************************************/
744 SMB_STRUCT_STAT
*sbuf
;
747 static void cli_posix_stat_done(struct tevent_req
*subreq
);
749 struct tevent_req
*cli_posix_stat_send(TALLOC_CTX
*mem_ctx
,
750 struct tevent_context
*ev
,
751 struct cli_state
*cli
,
753 SMB_STRUCT_STAT
*sbuf
)
755 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
756 struct stat_state
*state
= NULL
;
758 req
= tevent_req_create(mem_ctx
, &state
, struct stat_state
);
764 subreq
= cli_qpathinfo_send(state
, ev
, cli
, fname
,
765 SMB_QUERY_FILE_UNIX_BASIC
, 100, 100);
766 if (tevent_req_nomem(subreq
, req
)) {
767 return tevent_req_post(req
, ev
);
769 tevent_req_set_callback(subreq
, cli_posix_stat_done
, req
);
773 static void cli_posix_stat_done(struct tevent_req
*subreq
)
775 struct tevent_req
*req
= tevent_req_callback_data(
776 subreq
, struct tevent_req
);
777 struct stat_state
*state
= tevent_req_data(req
, struct stat_state
);
778 SMB_STRUCT_STAT
*sbuf
= state
->sbuf
;
783 status
= cli_qpathinfo_recv(subreq
, state
, &data
, &num_data
);
785 if (tevent_req_nterror(req
, status
)) {
789 if (num_data
!= 100) {
791 * Paranoia, cli_qpathinfo should have guaranteed
792 * this, but you never know...
794 tevent_req_nterror(req
, NT_STATUS_INVALID_NETWORK_RESPONSE
);
798 *sbuf
= (SMB_STRUCT_STAT
) { 0 };
800 /* total size, in bytes */
801 sbuf
->st_ex_size
= IVAL2_TO_SMB_BIG_UINT(data
, 0);
803 /* number of blocks allocated */
804 sbuf
->st_ex_blocks
= IVAL2_TO_SMB_BIG_UINT(data
,8);
805 #if defined (HAVE_STAT_ST_BLOCKS) && defined(STAT_ST_BLOCKSIZE)
806 sbuf
->st_ex_blocks
/= STAT_ST_BLOCKSIZE
;
808 /* assume 512 byte blocks */
809 sbuf
->st_ex_blocks
/= 512;
811 /* time of last change */
812 sbuf
->st_ex_ctime
= interpret_long_date((char *)(data
+ 16));
814 /* time of last access */
815 sbuf
->st_ex_atime
= interpret_long_date((char *)(data
+ 24));
817 /* time of last modification */
818 sbuf
->st_ex_mtime
= interpret_long_date((char *)(data
+ 32));
820 sbuf
->st_ex_uid
= (uid_t
) IVAL(data
, 40); /* user ID of owner */
821 sbuf
->st_ex_gid
= (gid_t
) IVAL(data
, 48); /* group ID of owner */
822 sbuf
->st_ex_mode
= unix_filetype_from_wire(IVAL(data
, 56));
824 #if defined(HAVE_MAKEDEV)
826 uint32_t dev_major
= IVAL(data
,60);
827 uint32_t dev_minor
= IVAL(data
,68);
828 sbuf
->st_ex_rdev
= makedev(dev_major
, dev_minor
);
832 sbuf
->st_ex_ino
= (SMB_INO_T
)IVAL2_TO_SMB_BIG_UINT(data
, 76);
835 sbuf
->st_ex_mode
|= wire_perms_to_unix(IVAL(data
, 84));
837 /* number of hard links */
838 sbuf
->st_ex_nlink
= BIG_UINT(data
, 92);
840 tevent_req_done(req
);
843 NTSTATUS
cli_posix_stat_recv(struct tevent_req
*req
)
845 return tevent_req_simple_recv_ntstatus(req
);
848 NTSTATUS
cli_posix_stat(struct cli_state
*cli
,
850 SMB_STRUCT_STAT
*sbuf
)
852 TALLOC_CTX
*frame
= talloc_stackframe();
853 struct tevent_context
*ev
= NULL
;
854 struct tevent_req
*req
= NULL
;
855 NTSTATUS status
= NT_STATUS_OK
;
857 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
859 * Can't use sync call while an async call is in flight
861 status
= NT_STATUS_INVALID_PARAMETER
;
865 ev
= samba_tevent_context_init(frame
);
867 status
= NT_STATUS_NO_MEMORY
;
871 req
= cli_posix_stat_send(frame
, ev
, cli
, fname
, sbuf
);
873 status
= NT_STATUS_NO_MEMORY
;
877 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
881 status
= cli_posix_stat_recv(req
);
888 /****************************************************************************
889 Chmod or chown a file internal (UNIX extensions).
890 ****************************************************************************/
892 struct cli_posix_chown_chmod_internal_state
{
896 static void cli_posix_chown_chmod_internal_done(struct tevent_req
*subreq
);
898 static struct tevent_req
*cli_posix_chown_chmod_internal_send(TALLOC_CTX
*mem_ctx
,
899 struct tevent_context
*ev
,
900 struct cli_state
*cli
,
906 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
907 struct cli_posix_chown_chmod_internal_state
*state
= NULL
;
909 req
= tevent_req_create(mem_ctx
, &state
,
910 struct cli_posix_chown_chmod_internal_state
);
915 memset(state
->data
, 0xff, 40); /* Set all sizes/times to no change. */
916 memset(&state
->data
[40], '\0', 60);
917 SIVAL(state
->data
,40,uid
);
918 SIVAL(state
->data
,48,gid
);
919 SIVAL(state
->data
,84,mode
);
921 subreq
= cli_setpathinfo_send(state
, ev
, cli
, SMB_SET_FILE_UNIX_BASIC
,
922 fname
, state
->data
, sizeof(state
->data
));
923 if (tevent_req_nomem(subreq
, req
)) {
924 return tevent_req_post(req
, ev
);
926 tevent_req_set_callback(subreq
, cli_posix_chown_chmod_internal_done
,
931 static void cli_posix_chown_chmod_internal_done(struct tevent_req
*subreq
)
933 NTSTATUS status
= cli_setpathinfo_recv(subreq
);
934 tevent_req_simple_finish_ntstatus(subreq
, status
);
937 static NTSTATUS
cli_posix_chown_chmod_internal_recv(struct tevent_req
*req
)
939 return tevent_req_simple_recv_ntstatus(req
);
942 /****************************************************************************
943 chmod a file (UNIX extensions).
944 ****************************************************************************/
946 struct cli_posix_chmod_state
{
950 static void cli_posix_chmod_done(struct tevent_req
*subreq
);
952 struct tevent_req
*cli_posix_chmod_send(TALLOC_CTX
*mem_ctx
,
953 struct tevent_context
*ev
,
954 struct cli_state
*cli
,
958 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
959 struct cli_posix_chmod_state
*state
= NULL
;
961 req
= tevent_req_create(mem_ctx
, &state
, struct cli_posix_chmod_state
);
966 subreq
= cli_posix_chown_chmod_internal_send(
971 unix_perms_to_wire(mode
),
974 if (tevent_req_nomem(subreq
, req
)) {
975 return tevent_req_post(req
, ev
);
977 tevent_req_set_callback(subreq
, cli_posix_chmod_done
, req
);
981 static void cli_posix_chmod_done(struct tevent_req
*subreq
)
983 NTSTATUS status
= cli_posix_chown_chmod_internal_recv(subreq
);
984 tevent_req_simple_finish_ntstatus(subreq
, status
);
987 NTSTATUS
cli_posix_chmod_recv(struct tevent_req
*req
)
989 return tevent_req_simple_recv_ntstatus(req
);
992 NTSTATUS
cli_posix_chmod(struct cli_state
*cli
, const char *fname
, mode_t mode
)
994 TALLOC_CTX
*frame
= talloc_stackframe();
995 struct tevent_context
*ev
= NULL
;
996 struct tevent_req
*req
= NULL
;
997 NTSTATUS status
= NT_STATUS_OK
;
999 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1001 * Can't use sync call while an async call is in flight
1003 status
= NT_STATUS_INVALID_PARAMETER
;
1007 ev
= samba_tevent_context_init(frame
);
1009 status
= NT_STATUS_NO_MEMORY
;
1013 req
= cli_posix_chmod_send(frame
,
1019 status
= NT_STATUS_NO_MEMORY
;
1023 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
1027 status
= cli_posix_chmod_recv(req
);
1034 /****************************************************************************
1035 chown a file (UNIX extensions).
1036 ****************************************************************************/
1038 struct cli_posix_chown_state
{
1042 static void cli_posix_chown_done(struct tevent_req
*subreq
);
1044 struct tevent_req
*cli_posix_chown_send(TALLOC_CTX
*mem_ctx
,
1045 struct tevent_context
*ev
,
1046 struct cli_state
*cli
,
1051 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1052 struct cli_posix_chown_state
*state
= NULL
;
1054 req
= tevent_req_create(
1055 mem_ctx
, &state
, struct cli_posix_chown_state
);
1060 subreq
= cli_posix_chown_chmod_internal_send(
1068 if (tevent_req_nomem(subreq
, req
)) {
1069 return tevent_req_post(req
, ev
);
1071 tevent_req_set_callback(subreq
, cli_posix_chown_done
, req
);
1075 static void cli_posix_chown_done(struct tevent_req
*subreq
)
1077 NTSTATUS status
= cli_posix_chown_chmod_internal_recv(subreq
);
1078 tevent_req_simple_finish_ntstatus(subreq
, status
);
1081 NTSTATUS
cli_posix_chown_recv(struct tevent_req
*req
)
1083 return tevent_req_simple_recv_ntstatus(req
);
1086 NTSTATUS
cli_posix_chown(struct cli_state
*cli
,
1091 TALLOC_CTX
*frame
= talloc_stackframe();
1092 struct tevent_context
*ev
= NULL
;
1093 struct tevent_req
*req
= NULL
;
1094 NTSTATUS status
= NT_STATUS_OK
;
1096 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1098 * Can't use sync call while an async call is in flight
1100 status
= NT_STATUS_INVALID_PARAMETER
;
1104 ev
= samba_tevent_context_init(frame
);
1106 status
= NT_STATUS_NO_MEMORY
;
1110 req
= cli_posix_chown_send(frame
,
1117 status
= NT_STATUS_NO_MEMORY
;
1121 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
1125 status
= cli_posix_chown_recv(req
);
1132 /****************************************************************************
1134 ****************************************************************************/
1136 static struct tevent_req
*cli_cifs_rename_send(TALLOC_CTX
*mem_ctx
,
1137 struct tevent_context
*ev
,
1138 struct cli_state
*cli
,
1139 const char *fname_src
,
1140 const char *fname_dst
,
1143 static struct tevent_req
*cli_smb1_rename_send(TALLOC_CTX
*mem_ctx
,
1144 struct tevent_context
*ev
,
1145 struct cli_state
*cli
,
1146 const char *fname_src
,
1147 const char *fname_dst
,
1150 struct tevent_req
*cli_rename_send(TALLOC_CTX
*mem_ctx
,
1151 struct tevent_context
*ev
,
1152 struct cli_state
*cli
,
1153 const char *fname_src
,
1154 const char *fname_dst
,
1157 if (replace
&& smbXcli_conn_support_passthrough(cli
->conn
)) {
1158 return cli_smb1_rename_send(mem_ctx
, ev
, cli
, fname_src
,
1159 fname_dst
, replace
);
1161 return cli_cifs_rename_send(mem_ctx
, ev
, cli
, fname_src
,
1162 fname_dst
, replace
);
1166 struct cli_smb1_rename_state
{
1170 static void cli_smb1_rename_done(struct tevent_req
*subreq
);
1172 static struct tevent_req
*cli_smb1_rename_send(TALLOC_CTX
*mem_ctx
,
1173 struct tevent_context
*ev
,
1174 struct cli_state
*cli
,
1175 const char *fname_src
,
1176 const char *fname_dst
,
1180 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1181 struct cli_smb1_rename_state
*state
= NULL
;
1182 smb_ucs2_t
*converted_str
= NULL
;
1183 size_t converted_size_bytes
= 0;
1185 req
= tevent_req_create(mem_ctx
, &state
, struct cli_smb1_rename_state
);
1190 if (!push_ucs2_talloc(talloc_tos(), &converted_str
, fname_dst
,
1191 &converted_size_bytes
)) {
1192 status
= NT_STATUS_INVALID_PARAMETER
;
1196 /* W2K8 insists the dest name is not null
1197 terminated. Remove the last 2 zero bytes
1198 and reduce the name length. */
1200 if (converted_size_bytes
< 2) {
1201 status
= NT_STATUS_INVALID_PARAMETER
;
1204 converted_size_bytes
-= 2;
1207 talloc_zero_array(state
, uint8_t, 12 + converted_size_bytes
);
1208 if (state
->data
== NULL
) {
1209 status
= NT_STATUS_NO_MEMORY
;
1214 SCVAL(state
->data
, 0, 1);
1217 SIVAL(state
->data
, 8, converted_size_bytes
);
1218 memcpy(state
->data
+ 12, converted_str
, converted_size_bytes
);
1220 TALLOC_FREE(converted_str
);
1222 subreq
= cli_setpathinfo_send(
1223 state
, ev
, cli
, SMB_FILE_RENAME_INFORMATION
, fname_src
, state
->data
,
1224 talloc_get_size(state
->data
));
1225 if (tevent_req_nomem(subreq
, req
)) {
1226 status
= NT_STATUS_NO_MEMORY
;
1229 tevent_req_set_callback(subreq
, cli_smb1_rename_done
, req
);
1233 TALLOC_FREE(converted_str
);
1234 tevent_req_nterror(req
, status
);
1235 return tevent_req_post(req
, ev
);
1238 static void cli_smb1_rename_done(struct tevent_req
*subreq
)
1240 NTSTATUS status
= cli_setpathinfo_recv(subreq
);
1241 tevent_req_simple_finish_ntstatus(subreq
, status
);
1244 static void cli_cifs_rename_done(struct tevent_req
*subreq
);
1246 struct cli_cifs_rename_state
{
1250 static struct tevent_req
*cli_cifs_rename_send(TALLOC_CTX
*mem_ctx
,
1251 struct tevent_context
*ev
,
1252 struct cli_state
*cli
,
1253 const char *fname_src
,
1254 const char *fname_dst
,
1257 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1258 struct cli_cifs_rename_state
*state
= NULL
;
1259 uint8_t additional_flags
= 0;
1260 uint16_t additional_flags2
= 0;
1261 uint8_t *bytes
= NULL
;
1263 req
= tevent_req_create(mem_ctx
, &state
, struct cli_cifs_rename_state
);
1270 * CIFS doesn't support replace
1272 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1273 return tevent_req_post(req
, ev
);
1276 SSVAL(state
->vwv
+0, 0, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_DIRECTORY
);
1278 bytes
= talloc_array(state
, uint8_t, 1);
1279 if (tevent_req_nomem(bytes
, req
)) {
1280 return tevent_req_post(req
, ev
);
1283 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname_src
,
1284 strlen(fname_src
)+1, NULL
);
1285 if (tevent_req_nomem(bytes
, req
)) {
1286 return tevent_req_post(req
, ev
);
1289 if (clistr_is_previous_version_path(fname_src
, NULL
, NULL
, NULL
)) {
1290 additional_flags2
= FLAGS2_REPARSE_PATH
;
1293 bytes
= talloc_realloc(state
, bytes
, uint8_t,
1294 talloc_get_size(bytes
)+1);
1295 if (tevent_req_nomem(bytes
, req
)) {
1296 return tevent_req_post(req
, ev
);
1299 bytes
[talloc_get_size(bytes
)-1] = 4;
1300 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname_dst
,
1301 strlen(fname_dst
)+1, NULL
);
1302 if (tevent_req_nomem(bytes
, req
)) {
1303 return tevent_req_post(req
, ev
);
1306 subreq
= cli_smb_send(state
, ev
, cli
, SMBmv
, additional_flags
,
1308 1, state
->vwv
, talloc_get_size(bytes
), bytes
);
1309 if (tevent_req_nomem(subreq
, req
)) {
1310 return tevent_req_post(req
, ev
);
1312 tevent_req_set_callback(subreq
, cli_cifs_rename_done
, req
);
1316 static void cli_cifs_rename_done(struct tevent_req
*subreq
)
1318 struct tevent_req
*req
= tevent_req_callback_data(
1319 subreq
, struct tevent_req
);
1322 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
1323 TALLOC_FREE(subreq
);
1324 if (tevent_req_nterror(req
, status
)) {
1327 tevent_req_done(req
);
1330 NTSTATUS
cli_rename_recv(struct tevent_req
*req
)
1332 return tevent_req_simple_recv_ntstatus(req
);
1335 NTSTATUS
cli_rename(struct cli_state
*cli
,
1336 const char *fname_src
,
1337 const char *fname_dst
,
1340 TALLOC_CTX
*frame
= NULL
;
1341 struct tevent_context
*ev
;
1342 struct tevent_req
*req
;
1343 NTSTATUS status
= NT_STATUS_OK
;
1345 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
1346 return cli_smb2_rename(cli
, fname_src
, fname_dst
, replace
);
1349 frame
= talloc_stackframe();
1351 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1353 * Can't use sync call while an async call is in flight
1355 status
= NT_STATUS_INVALID_PARAMETER
;
1359 ev
= samba_tevent_context_init(frame
);
1361 status
= NT_STATUS_NO_MEMORY
;
1365 req
= cli_rename_send(frame
, ev
, cli
, fname_src
, fname_dst
, replace
);
1367 status
= NT_STATUS_NO_MEMORY
;
1371 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
1375 status
= cli_rename_recv(req
);
1382 /****************************************************************************
1384 ****************************************************************************/
1386 static void cli_ntrename_internal_done(struct tevent_req
*subreq
);
1388 struct cli_ntrename_internal_state
{
1392 static struct tevent_req
*cli_ntrename_internal_send(TALLOC_CTX
*mem_ctx
,
1393 struct tevent_context
*ev
,
1394 struct cli_state
*cli
,
1395 const char *fname_src
,
1396 const char *fname_dst
,
1397 uint16_t rename_flag
)
1399 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1400 struct cli_ntrename_internal_state
*state
= NULL
;
1401 uint8_t additional_flags
= 0;
1402 uint16_t additional_flags2
= 0;
1403 uint8_t *bytes
= NULL
;
1405 req
= tevent_req_create(mem_ctx
, &state
,
1406 struct cli_ntrename_internal_state
);
1411 SSVAL(state
->vwv
+0, 0 ,FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_DIRECTORY
);
1412 SSVAL(state
->vwv
+1, 0, rename_flag
);
1414 bytes
= talloc_array(state
, uint8_t, 1);
1415 if (tevent_req_nomem(bytes
, req
)) {
1416 return tevent_req_post(req
, ev
);
1419 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname_src
,
1420 strlen(fname_src
)+1, NULL
);
1421 if (tevent_req_nomem(bytes
, req
)) {
1422 return tevent_req_post(req
, ev
);
1425 if (clistr_is_previous_version_path(fname_src
, NULL
, NULL
, NULL
)) {
1426 additional_flags2
= FLAGS2_REPARSE_PATH
;
1429 bytes
= talloc_realloc(state
, bytes
, uint8_t,
1430 talloc_get_size(bytes
)+1);
1431 if (tevent_req_nomem(bytes
, req
)) {
1432 return tevent_req_post(req
, ev
);
1435 bytes
[talloc_get_size(bytes
)-1] = 4;
1436 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname_dst
,
1437 strlen(fname_dst
)+1, NULL
);
1438 if (tevent_req_nomem(bytes
, req
)) {
1439 return tevent_req_post(req
, ev
);
1442 subreq
= cli_smb_send(state
, ev
, cli
, SMBntrename
, additional_flags
,
1444 4, state
->vwv
, talloc_get_size(bytes
), bytes
);
1445 if (tevent_req_nomem(subreq
, req
)) {
1446 return tevent_req_post(req
, ev
);
1448 tevent_req_set_callback(subreq
, cli_ntrename_internal_done
, req
);
1452 static void cli_ntrename_internal_done(struct tevent_req
*subreq
)
1454 NTSTATUS status
= cli_smb_recv(
1455 subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
1456 tevent_req_simple_finish_ntstatus(subreq
, status
);
1459 static NTSTATUS
cli_ntrename_internal_recv(struct tevent_req
*req
)
1461 return tevent_req_simple_recv_ntstatus(req
);
1464 struct tevent_req
*cli_ntrename_send(TALLOC_CTX
*mem_ctx
,
1465 struct tevent_context
*ev
,
1466 struct cli_state
*cli
,
1467 const char *fname_src
,
1468 const char *fname_dst
)
1470 return cli_ntrename_internal_send(mem_ctx
,
1475 RENAME_FLAG_RENAME
);
1478 NTSTATUS
cli_ntrename_recv(struct tevent_req
*req
)
1480 return cli_ntrename_internal_recv(req
);
1483 NTSTATUS
cli_ntrename(struct cli_state
*cli
, const char *fname_src
, const char *fname_dst
)
1485 TALLOC_CTX
*frame
= talloc_stackframe();
1486 struct tevent_context
*ev
;
1487 struct tevent_req
*req
;
1488 NTSTATUS status
= NT_STATUS_OK
;
1490 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1492 * Can't use sync call while an async call is in flight
1494 status
= NT_STATUS_INVALID_PARAMETER
;
1498 ev
= samba_tevent_context_init(frame
);
1500 status
= NT_STATUS_NO_MEMORY
;
1504 req
= cli_ntrename_send(frame
, ev
, cli
, fname_src
, fname_dst
);
1506 status
= NT_STATUS_NO_MEMORY
;
1510 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
1514 status
= cli_ntrename_recv(req
);
1521 /****************************************************************************
1523 ****************************************************************************/
1525 static struct tevent_req
*cli_nt_hardlink_send(TALLOC_CTX
*mem_ctx
,
1526 struct tevent_context
*ev
,
1527 struct cli_state
*cli
,
1528 const char *fname_src
,
1529 const char *fname_dst
)
1531 return cli_ntrename_internal_send(mem_ctx
,
1536 RENAME_FLAG_HARD_LINK
);
1539 static NTSTATUS
cli_nt_hardlink_recv(struct tevent_req
*req
)
1541 return cli_ntrename_internal_recv(req
);
1544 struct cli_smb2_hardlink_state
{
1545 struct tevent_context
*ev
;
1546 struct cli_state
*cli
;
1548 const char *fname_dst
;
1553 static void cli_smb2_hardlink_opened(struct tevent_req
*subreq
);
1554 static void cli_smb2_hardlink_info_set(struct tevent_req
*subreq
);
1555 static void cli_smb2_hardlink_closed(struct tevent_req
*subreq
);
1557 static struct tevent_req
*cli_smb2_hardlink_send(
1558 TALLOC_CTX
*mem_ctx
,
1559 struct tevent_context
*ev
,
1560 struct cli_state
*cli
,
1561 const char *fname_src
,
1562 const char *fname_dst
,
1564 struct smb2_create_blobs
*in_cblobs
)
1566 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1567 struct cli_smb2_hardlink_state
*state
= NULL
;
1569 req
= tevent_req_create(
1570 mem_ctx
, &state
, struct cli_smb2_hardlink_state
);
1576 state
->fname_dst
= fname_dst
;
1577 state
->overwrite
= overwrite
;
1579 subreq
= cli_smb2_create_fnum_send(
1584 0, /* create_flags */
1585 SMB2_IMPERSONATION_IMPERSONATION
,
1586 FILE_WRITE_ATTRIBUTES
,
1587 0, /* file attributes */
1590 FILE_SHARE_DELETE
, /* share_access */
1591 FILE_OPEN
, /* create_disposition */
1592 FILE_NON_DIRECTORY_FILE
, /* no hardlinks on directories */
1594 if (tevent_req_nomem(subreq
, req
)) {
1595 return tevent_req_post(req
, ev
);
1597 tevent_req_set_callback(subreq
, cli_smb2_hardlink_opened
, req
);
1601 static void cli_smb2_hardlink_opened(struct tevent_req
*subreq
)
1603 struct tevent_req
*req
= tevent_req_callback_data(
1604 subreq
, struct tevent_req
);
1605 struct cli_smb2_hardlink_state
*state
= tevent_req_data(
1606 req
, struct cli_smb2_hardlink_state
);
1608 smb_ucs2_t
*ucs2_dst
;
1613 status
= cli_smb2_create_fnum_recv(
1614 subreq
, &state
->fnum_src
, NULL
, NULL
, NULL
);
1615 TALLOC_FREE(subreq
);
1616 if (tevent_req_nterror(req
, status
)) {
1620 ok
= push_ucs2_talloc(state
, &ucs2_dst
, state
->fname_dst
, &ucs2_len
);
1621 if (!ok
|| (ucs2_len
< 2)) {
1622 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1625 /* Don't 0-terminate the name */
1628 inbuf
= data_blob_talloc_zero(state
, ucs2_len
+ 20);
1629 if (tevent_req_nomem(inbuf
.data
, req
)) {
1633 if (state
->overwrite
) {
1634 SCVAL(inbuf
.data
, 0, 1);
1636 SIVAL(inbuf
.data
, 16, ucs2_len
);
1637 memcpy(inbuf
.data
+ 20, ucs2_dst
, ucs2_len
);
1638 TALLOC_FREE(ucs2_dst
);
1640 subreq
= cli_smb2_set_info_fnum_send(
1645 1, /* in_info_type */
1646 SMB_FILE_LINK_INFORMATION
- 1000, /* in_file_info_class */
1648 0); /* in_additional_info */
1649 if (tevent_req_nomem(subreq
, req
)) {
1652 tevent_req_set_callback(subreq
, cli_smb2_hardlink_info_set
, req
);
1655 static void cli_smb2_hardlink_info_set(struct tevent_req
*subreq
)
1657 struct tevent_req
*req
= tevent_req_callback_data(
1658 subreq
, struct tevent_req
);
1659 struct cli_smb2_hardlink_state
*state
= tevent_req_data(
1660 req
, struct cli_smb2_hardlink_state
);
1662 state
->status
= cli_smb2_set_info_fnum_recv(subreq
);
1663 TALLOC_FREE(subreq
);
1665 /* ignore error here, we need to close the file */
1667 subreq
= cli_smb2_close_fnum_send(
1668 state
, state
->ev
, state
->cli
, state
->fnum_src
);
1669 if (tevent_req_nomem(subreq
, req
)) {
1672 tevent_req_set_callback(subreq
, cli_smb2_hardlink_closed
, req
);
1675 static void cli_smb2_hardlink_closed(struct tevent_req
*subreq
)
1677 NTSTATUS status
= cli_smb2_close_fnum_recv(subreq
);
1678 tevent_req_simple_finish_ntstatus(subreq
, status
);
1681 static NTSTATUS
cli_smb2_hardlink_recv(struct tevent_req
*req
)
1683 struct cli_smb2_hardlink_state
*state
= tevent_req_data(
1684 req
, struct cli_smb2_hardlink_state
);
1687 if (tevent_req_is_nterror(req
, &status
)) {
1690 return state
->status
;
1693 struct cli_hardlink_state
{
1697 static void cli_hardlink_done(struct tevent_req
*subreq
);
1698 static void cli_hardlink_done2(struct tevent_req
*subreq
);
1700 struct tevent_req
*cli_hardlink_send(
1701 TALLOC_CTX
*mem_ctx
,
1702 struct tevent_context
*ev
,
1703 struct cli_state
*cli
,
1704 const char *fname_src
,
1705 const char *fname_dst
)
1707 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1708 struct cli_hardlink_state
*state
;
1710 req
= tevent_req_create(mem_ctx
, &state
, struct cli_hardlink_state
);
1715 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
1716 subreq
= cli_smb2_hardlink_send(
1717 state
, ev
, cli
, fname_src
, fname_dst
, false, NULL
);
1718 if (tevent_req_nomem(subreq
, req
)) {
1719 return tevent_req_post(req
, ev
);
1721 tevent_req_set_callback(subreq
, cli_hardlink_done2
, req
);
1725 subreq
= cli_nt_hardlink_send(state
, ev
, cli
, fname_src
, fname_dst
);
1726 if (tevent_req_nomem(subreq
, req
)) {
1727 return tevent_req_post(req
, ev
);
1729 tevent_req_set_callback(subreq
, cli_hardlink_done
, req
);
1733 static void cli_hardlink_done(struct tevent_req
*subreq
)
1735 NTSTATUS status
= cli_nt_hardlink_recv(subreq
);
1736 tevent_req_simple_finish_ntstatus(subreq
, status
);
1739 static void cli_hardlink_done2(struct tevent_req
*subreq
)
1741 NTSTATUS status
= cli_smb2_hardlink_recv(subreq
);
1742 tevent_req_simple_finish_ntstatus(subreq
, status
);
1745 NTSTATUS
cli_hardlink_recv(struct tevent_req
*req
)
1747 return tevent_req_simple_recv_ntstatus(req
);
1750 NTSTATUS
cli_hardlink(
1751 struct cli_state
*cli
, const char *fname_src
, const char *fname_dst
)
1753 TALLOC_CTX
*frame
= talloc_stackframe();
1754 struct tevent_context
*ev
= NULL
;
1755 struct tevent_req
*req
= NULL
;
1756 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
1758 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1759 status
= NT_STATUS_INVALID_PARAMETER
;
1762 ev
= samba_tevent_context_init(frame
);
1766 req
= cli_hardlink_send(frame
, ev
, cli
, fname_src
, fname_dst
);
1770 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
1773 status
= cli_hardlink_recv(req
);
1779 /****************************************************************************
1781 ****************************************************************************/
1783 static void cli_unlink_done(struct tevent_req
*subreq
);
1785 struct cli_unlink_state
{
1789 struct tevent_req
*cli_unlink_send(TALLOC_CTX
*mem_ctx
,
1790 struct tevent_context
*ev
,
1791 struct cli_state
*cli
,
1793 uint16_t mayhave_attrs
)
1795 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1796 struct cli_unlink_state
*state
= NULL
;
1797 uint8_t additional_flags
= 0;
1798 uint16_t additional_flags2
= 0;
1799 uint8_t *bytes
= NULL
;
1801 req
= tevent_req_create(mem_ctx
, &state
, struct cli_unlink_state
);
1806 SSVAL(state
->vwv
+0, 0, mayhave_attrs
);
1808 bytes
= talloc_array(state
, uint8_t, 1);
1809 if (tevent_req_nomem(bytes
, req
)) {
1810 return tevent_req_post(req
, ev
);
1813 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname
,
1814 strlen(fname
)+1, NULL
);
1816 if (tevent_req_nomem(bytes
, req
)) {
1817 return tevent_req_post(req
, ev
);
1820 if (clistr_is_previous_version_path(fname
, NULL
, NULL
, NULL
)) {
1821 additional_flags2
= FLAGS2_REPARSE_PATH
;
1824 subreq
= cli_smb_send(state
, ev
, cli
, SMBunlink
, additional_flags
,
1826 1, state
->vwv
, talloc_get_size(bytes
), bytes
);
1827 if (tevent_req_nomem(subreq
, req
)) {
1828 return tevent_req_post(req
, ev
);
1830 tevent_req_set_callback(subreq
, cli_unlink_done
, req
);
1834 static void cli_unlink_done(struct tevent_req
*subreq
)
1836 struct tevent_req
*req
= tevent_req_callback_data(
1837 subreq
, struct tevent_req
);
1840 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
1841 TALLOC_FREE(subreq
);
1842 if (tevent_req_nterror(req
, status
)) {
1845 tevent_req_done(req
);
1848 NTSTATUS
cli_unlink_recv(struct tevent_req
*req
)
1850 return tevent_req_simple_recv_ntstatus(req
);
1853 NTSTATUS
cli_unlink(struct cli_state
*cli
, const char *fname
, uint16_t mayhave_attrs
)
1855 TALLOC_CTX
*frame
= NULL
;
1856 struct tevent_context
*ev
;
1857 struct tevent_req
*req
;
1858 NTSTATUS status
= NT_STATUS_OK
;
1860 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
1861 return cli_smb2_unlink(cli
, fname
, NULL
);
1864 frame
= talloc_stackframe();
1866 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1868 * Can't use sync call while an async call is in flight
1870 status
= NT_STATUS_INVALID_PARAMETER
;
1874 ev
= samba_tevent_context_init(frame
);
1876 status
= NT_STATUS_NO_MEMORY
;
1880 req
= cli_unlink_send(frame
, ev
, cli
, fname
, mayhave_attrs
);
1882 status
= NT_STATUS_NO_MEMORY
;
1886 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
1890 status
= cli_unlink_recv(req
);
1897 /****************************************************************************
1899 ****************************************************************************/
1901 static void cli_mkdir_done(struct tevent_req
*subreq
);
1903 struct cli_mkdir_state
{
1907 struct tevent_req
*cli_mkdir_send(TALLOC_CTX
*mem_ctx
,
1908 struct tevent_context
*ev
,
1909 struct cli_state
*cli
,
1912 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1913 struct cli_mkdir_state
*state
= NULL
;
1914 uint8_t additional_flags
= 0;
1915 uint16_t additional_flags2
= 0;
1916 uint8_t *bytes
= NULL
;
1918 req
= tevent_req_create(mem_ctx
, &state
, struct cli_mkdir_state
);
1923 bytes
= talloc_array(state
, uint8_t, 1);
1924 if (tevent_req_nomem(bytes
, req
)) {
1925 return tevent_req_post(req
, ev
);
1928 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), dname
,
1929 strlen(dname
)+1, NULL
);
1931 if (tevent_req_nomem(bytes
, req
)) {
1932 return tevent_req_post(req
, ev
);
1935 if (clistr_is_previous_version_path(dname
, NULL
, NULL
, NULL
)) {
1936 additional_flags2
= FLAGS2_REPARSE_PATH
;
1939 subreq
= cli_smb_send(state
, ev
, cli
, SMBmkdir
, additional_flags
,
1941 0, NULL
, talloc_get_size(bytes
), bytes
);
1942 if (tevent_req_nomem(subreq
, req
)) {
1943 return tevent_req_post(req
, ev
);
1945 tevent_req_set_callback(subreq
, cli_mkdir_done
, req
);
1949 static void cli_mkdir_done(struct tevent_req
*subreq
)
1951 struct tevent_req
*req
= tevent_req_callback_data(
1952 subreq
, struct tevent_req
);
1955 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
1956 TALLOC_FREE(subreq
);
1957 if (tevent_req_nterror(req
, status
)) {
1960 tevent_req_done(req
);
1963 NTSTATUS
cli_mkdir_recv(struct tevent_req
*req
)
1965 return tevent_req_simple_recv_ntstatus(req
);
1968 NTSTATUS
cli_mkdir(struct cli_state
*cli
, const char *dname
)
1970 TALLOC_CTX
*frame
= NULL
;
1971 struct tevent_context
*ev
;
1972 struct tevent_req
*req
;
1973 NTSTATUS status
= NT_STATUS_OK
;
1975 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
1976 return cli_smb2_mkdir(cli
, dname
);
1979 frame
= talloc_stackframe();
1981 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
1983 * Can't use sync call while an async call is in flight
1985 status
= NT_STATUS_INVALID_PARAMETER
;
1989 ev
= samba_tevent_context_init(frame
);
1991 status
= NT_STATUS_NO_MEMORY
;
1995 req
= cli_mkdir_send(frame
, ev
, cli
, dname
);
1997 status
= NT_STATUS_NO_MEMORY
;
2001 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
2005 status
= cli_mkdir_recv(req
);
2012 /****************************************************************************
2014 ****************************************************************************/
2016 static void cli_rmdir_done(struct tevent_req
*subreq
);
2018 struct cli_rmdir_state
{
2022 struct tevent_req
*cli_rmdir_send(TALLOC_CTX
*mem_ctx
,
2023 struct tevent_context
*ev
,
2024 struct cli_state
*cli
,
2027 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
2028 struct cli_rmdir_state
*state
= NULL
;
2029 uint8_t additional_flags
= 0;
2030 uint16_t additional_flags2
= 0;
2031 uint8_t *bytes
= NULL
;
2033 req
= tevent_req_create(mem_ctx
, &state
, struct cli_rmdir_state
);
2038 bytes
= talloc_array(state
, uint8_t, 1);
2039 if (tevent_req_nomem(bytes
, req
)) {
2040 return tevent_req_post(req
, ev
);
2043 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), dname
,
2044 strlen(dname
)+1, NULL
);
2046 if (tevent_req_nomem(bytes
, req
)) {
2047 return tevent_req_post(req
, ev
);
2050 if (clistr_is_previous_version_path(dname
, NULL
, NULL
, NULL
)) {
2051 additional_flags2
= FLAGS2_REPARSE_PATH
;
2054 subreq
= cli_smb_send(state
, ev
, cli
, SMBrmdir
, additional_flags
,
2056 0, NULL
, talloc_get_size(bytes
), bytes
);
2057 if (tevent_req_nomem(subreq
, req
)) {
2058 return tevent_req_post(req
, ev
);
2060 tevent_req_set_callback(subreq
, cli_rmdir_done
, req
);
2064 static void cli_rmdir_done(struct tevent_req
*subreq
)
2066 struct tevent_req
*req
= tevent_req_callback_data(
2067 subreq
, struct tevent_req
);
2070 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
2071 TALLOC_FREE(subreq
);
2072 if (tevent_req_nterror(req
, status
)) {
2075 tevent_req_done(req
);
2078 NTSTATUS
cli_rmdir_recv(struct tevent_req
*req
)
2080 return tevent_req_simple_recv_ntstatus(req
);
2083 NTSTATUS
cli_rmdir(struct cli_state
*cli
, const char *dname
)
2085 TALLOC_CTX
*frame
= NULL
;
2086 struct tevent_context
*ev
;
2087 struct tevent_req
*req
;
2088 NTSTATUS status
= NT_STATUS_OK
;
2090 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
2091 return cli_smb2_rmdir(cli
, dname
, NULL
);
2094 frame
= talloc_stackframe();
2096 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
2098 * Can't use sync call while an async call is in flight
2100 status
= NT_STATUS_INVALID_PARAMETER
;
2104 ev
= samba_tevent_context_init(frame
);
2106 status
= NT_STATUS_NO_MEMORY
;
2110 req
= cli_rmdir_send(frame
, ev
, cli
, dname
);
2112 status
= NT_STATUS_NO_MEMORY
;
2116 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
2120 status
= cli_rmdir_recv(req
);
2127 /****************************************************************************
2128 Set or clear the delete on close flag.
2129 ****************************************************************************/
2137 static void cli_nt_delete_on_close_smb1_done(struct tevent_req
*subreq
);
2138 static void cli_nt_delete_on_close_smb2_done(struct tevent_req
*subreq
);
2140 struct tevent_req
*cli_nt_delete_on_close_send(TALLOC_CTX
*mem_ctx
,
2141 struct tevent_context
*ev
,
2142 struct cli_state
*cli
,
2146 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
2147 struct doc_state
*state
= NULL
;
2149 req
= tevent_req_create(mem_ctx
, &state
, struct doc_state
);
2154 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
2155 subreq
= cli_smb2_delete_on_close_send(state
, ev
, cli
,
2157 if (tevent_req_nomem(subreq
, req
)) {
2158 return tevent_req_post(req
, ev
);
2160 tevent_req_set_callback(subreq
,
2161 cli_nt_delete_on_close_smb2_done
,
2166 /* Setup setup word. */
2167 SSVAL(&state
->setup
, 0, TRANSACT2_SETFILEINFO
);
2169 /* Setup param array. */
2170 SSVAL(state
->param
,0,fnum
);
2171 SSVAL(state
->param
,2,SMB_SET_FILE_DISPOSITION_INFO
);
2173 /* Setup data array. */
2174 SCVAL(&state
->data
[0], 0, flag
? 1 : 0);
2176 subreq
= cli_trans_send(state
, /* mem ctx. */
2177 ev
, /* event ctx. */
2178 cli
, /* cli_state. */
2179 0, /* additional_flags2 */
2180 SMBtrans2
, /* cmd. */
2181 NULL
, /* pipe name. */
2185 &state
->setup
, /* setup. */
2186 1, /* num setup uint16_t words. */
2187 0, /* max returned setup. */
2188 state
->param
, /* param. */
2190 2, /* max returned param. */
2191 state
->data
, /* data. */
2193 0); /* max returned data. */
2195 if (tevent_req_nomem(subreq
, req
)) {
2196 return tevent_req_post(req
, ev
);
2198 tevent_req_set_callback(subreq
,
2199 cli_nt_delete_on_close_smb1_done
,
2204 static void cli_nt_delete_on_close_smb1_done(struct tevent_req
*subreq
)
2206 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, NULL
, 0, NULL
,
2207 NULL
, 0, NULL
, NULL
, 0, NULL
);
2208 tevent_req_simple_finish_ntstatus(subreq
, status
);
2211 static void cli_nt_delete_on_close_smb2_done(struct tevent_req
*subreq
)
2213 NTSTATUS status
= cli_smb2_delete_on_close_recv(subreq
);
2214 tevent_req_simple_finish_ntstatus(subreq
, status
);
2217 NTSTATUS
cli_nt_delete_on_close_recv(struct tevent_req
*req
)
2219 return tevent_req_simple_recv_ntstatus(req
);
2222 NTSTATUS
cli_nt_delete_on_close(struct cli_state
*cli
, uint16_t fnum
, bool flag
)
2224 TALLOC_CTX
*frame
= talloc_stackframe();
2225 struct tevent_context
*ev
= NULL
;
2226 struct tevent_req
*req
= NULL
;
2227 NTSTATUS status
= NT_STATUS_OK
;
2229 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
2231 * Can't use sync call while an async call is in flight
2233 status
= NT_STATUS_INVALID_PARAMETER
;
2237 ev
= samba_tevent_context_init(frame
);
2239 status
= NT_STATUS_NO_MEMORY
;
2243 req
= cli_nt_delete_on_close_send(frame
,
2249 status
= NT_STATUS_NO_MEMORY
;
2253 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
2257 status
= cli_nt_delete_on_close_recv(req
);
2264 struct cli_ntcreate1_state
{
2267 struct smb_create_returns cr
;
2268 struct tevent_req
*subreq
;
2271 static void cli_ntcreate1_done(struct tevent_req
*subreq
);
2272 static bool cli_ntcreate1_cancel(struct tevent_req
*req
);
2274 static struct tevent_req
*cli_ntcreate1_send(TALLOC_CTX
*mem_ctx
,
2275 struct tevent_context
*ev
,
2276 struct cli_state
*cli
,
2278 uint32_t CreatFlags
,
2279 uint32_t DesiredAccess
,
2280 uint32_t FileAttributes
,
2281 uint32_t ShareAccess
,
2282 uint32_t CreateDisposition
,
2283 uint32_t CreateOptions
,
2284 uint32_t ImpersonationLevel
,
2285 uint8_t SecurityFlags
)
2287 struct tevent_req
*req
, *subreq
;
2288 struct cli_ntcreate1_state
*state
;
2291 size_t converted_len
;
2292 uint16_t additional_flags2
= 0;
2294 req
= tevent_req_create(mem_ctx
, &state
, struct cli_ntcreate1_state
);
2301 SCVAL(vwv
+0, 0, 0xFF);
2306 if (cli
->use_oplocks
) {
2307 CreatFlags
|= (REQUEST_OPLOCK
|REQUEST_BATCH_OPLOCK
);
2309 SIVAL(vwv
+3, 1, CreatFlags
);
2310 SIVAL(vwv
+5, 1, 0x0); /* RootDirectoryFid */
2311 SIVAL(vwv
+7, 1, DesiredAccess
);
2312 SIVAL(vwv
+9, 1, 0x0); /* AllocationSize */
2313 SIVAL(vwv
+11, 1, 0x0); /* AllocationSize */
2314 SIVAL(vwv
+13, 1, FileAttributes
);
2315 SIVAL(vwv
+15, 1, ShareAccess
);
2316 SIVAL(vwv
+17, 1, CreateDisposition
);
2317 SIVAL(vwv
+19, 1, CreateOptions
|
2318 (cli
->backup_intent
? FILE_OPEN_FOR_BACKUP_INTENT
: 0));
2319 SIVAL(vwv
+21, 1, ImpersonationLevel
);
2320 SCVAL(vwv
+23, 1, SecurityFlags
);
2322 bytes
= talloc_array(state
, uint8_t, 0);
2323 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
),
2324 fname
, strlen(fname
)+1,
2327 if (clistr_is_previous_version_path(fname
, NULL
, NULL
, NULL
)) {
2328 additional_flags2
= FLAGS2_REPARSE_PATH
;
2331 /* sigh. this copes with broken netapp filer behaviour */
2332 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), "", 1, NULL
);
2334 if (tevent_req_nomem(bytes
, req
)) {
2335 return tevent_req_post(req
, ev
);
2338 SSVAL(vwv
+2, 1, converted_len
);
2340 subreq
= cli_smb_send(state
, ev
, cli
, SMBntcreateX
, 0,
2341 additional_flags2
, 24, vwv
,
2342 talloc_get_size(bytes
), bytes
);
2343 if (tevent_req_nomem(subreq
, req
)) {
2344 return tevent_req_post(req
, ev
);
2346 tevent_req_set_callback(subreq
, cli_ntcreate1_done
, req
);
2348 state
->subreq
= subreq
;
2349 tevent_req_set_cancel_fn(req
, cli_ntcreate1_cancel
);
2354 static void cli_ntcreate1_done(struct tevent_req
*subreq
)
2356 struct tevent_req
*req
= tevent_req_callback_data(
2357 subreq
, struct tevent_req
);
2358 struct cli_ntcreate1_state
*state
= tevent_req_data(
2359 req
, struct cli_ntcreate1_state
);
2366 status
= cli_smb_recv(subreq
, state
, NULL
, 34, &wct
, &vwv
,
2367 &num_bytes
, &bytes
);
2368 TALLOC_FREE(subreq
);
2369 if (tevent_req_nterror(req
, status
)) {
2372 state
->cr
.oplock_level
= CVAL(vwv
+2, 0);
2373 state
->fnum
= SVAL(vwv
+2, 1);
2374 state
->cr
.create_action
= IVAL(vwv
+3, 1);
2375 state
->cr
.creation_time
= BVAL(vwv
+5, 1);
2376 state
->cr
.last_access_time
= BVAL(vwv
+9, 1);
2377 state
->cr
.last_write_time
= BVAL(vwv
+13, 1);
2378 state
->cr
.change_time
= BVAL(vwv
+17, 1);
2379 state
->cr
.file_attributes
= IVAL(vwv
+21, 1);
2380 state
->cr
.allocation_size
= BVAL(vwv
+23, 1);
2381 state
->cr
.end_of_file
= BVAL(vwv
+27, 1);
2383 tevent_req_done(req
);
2386 static bool cli_ntcreate1_cancel(struct tevent_req
*req
)
2388 struct cli_ntcreate1_state
*state
= tevent_req_data(
2389 req
, struct cli_ntcreate1_state
);
2390 return tevent_req_cancel(state
->subreq
);
2393 static NTSTATUS
cli_ntcreate1_recv(struct tevent_req
*req
,
2395 struct smb_create_returns
*cr
)
2397 struct cli_ntcreate1_state
*state
= tevent_req_data(
2398 req
, struct cli_ntcreate1_state
);
2401 if (tevent_req_is_nterror(req
, &status
)) {
2404 *pfnum
= state
->fnum
;
2408 return NT_STATUS_OK
;
2411 struct cli_ntcreate_state
{
2412 struct smb_create_returns cr
;
2414 struct tevent_req
*subreq
;
2417 static void cli_ntcreate_done_nt1(struct tevent_req
*subreq
);
2418 static void cli_ntcreate_done_smb2(struct tevent_req
*subreq
);
2419 static bool cli_ntcreate_cancel(struct tevent_req
*req
);
2421 struct tevent_req
*cli_ntcreate_send(TALLOC_CTX
*mem_ctx
,
2422 struct tevent_context
*ev
,
2423 struct cli_state
*cli
,
2425 uint32_t create_flags
,
2426 uint32_t desired_access
,
2427 uint32_t file_attributes
,
2428 uint32_t share_access
,
2429 uint32_t create_disposition
,
2430 uint32_t create_options
,
2431 uint32_t impersonation_level
,
2432 uint8_t security_flags
)
2434 struct tevent_req
*req
, *subreq
;
2435 struct cli_ntcreate_state
*state
;
2437 req
= tevent_req_create(mem_ctx
, &state
, struct cli_ntcreate_state
);
2442 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
2443 if (cli
->use_oplocks
) {
2444 create_flags
|= REQUEST_OPLOCK
|REQUEST_BATCH_OPLOCK
;
2447 subreq
= cli_smb2_create_fnum_send(
2453 impersonation_level
,
2460 if (tevent_req_nomem(subreq
, req
)) {
2461 return tevent_req_post(req
, ev
);
2463 tevent_req_set_callback(subreq
, cli_ntcreate_done_smb2
, req
);
2465 subreq
= cli_ntcreate1_send(
2466 state
, ev
, cli
, fname
, create_flags
, desired_access
,
2467 file_attributes
, share_access
, create_disposition
,
2468 create_options
, impersonation_level
, security_flags
);
2469 if (tevent_req_nomem(subreq
, req
)) {
2470 return tevent_req_post(req
, ev
);
2472 tevent_req_set_callback(subreq
, cli_ntcreate_done_nt1
, req
);
2475 state
->subreq
= subreq
;
2476 tevent_req_set_cancel_fn(req
, cli_ntcreate_cancel
);
2481 static void cli_ntcreate_done_nt1(struct tevent_req
*subreq
)
2483 struct tevent_req
*req
= tevent_req_callback_data(
2484 subreq
, struct tevent_req
);
2485 struct cli_ntcreate_state
*state
= tevent_req_data(
2486 req
, struct cli_ntcreate_state
);
2489 status
= cli_ntcreate1_recv(subreq
, &state
->fnum
, &state
->cr
);
2490 TALLOC_FREE(subreq
);
2491 if (tevent_req_nterror(req
, status
)) {
2494 tevent_req_done(req
);
2497 static void cli_ntcreate_done_smb2(struct tevent_req
*subreq
)
2499 struct tevent_req
*req
= tevent_req_callback_data(
2500 subreq
, struct tevent_req
);
2501 struct cli_ntcreate_state
*state
= tevent_req_data(
2502 req
, struct cli_ntcreate_state
);
2505 status
= cli_smb2_create_fnum_recv(
2511 TALLOC_FREE(subreq
);
2512 if (tevent_req_nterror(req
, status
)) {
2515 tevent_req_done(req
);
2518 static bool cli_ntcreate_cancel(struct tevent_req
*req
)
2520 struct cli_ntcreate_state
*state
= tevent_req_data(
2521 req
, struct cli_ntcreate_state
);
2522 return tevent_req_cancel(state
->subreq
);
2525 NTSTATUS
cli_ntcreate_recv(struct tevent_req
*req
, uint16_t *fnum
,
2526 struct smb_create_returns
*cr
)
2528 struct cli_ntcreate_state
*state
= tevent_req_data(
2529 req
, struct cli_ntcreate_state
);
2532 if (tevent_req_is_nterror(req
, &status
)) {
2536 *fnum
= state
->fnum
;
2541 return NT_STATUS_OK
;
2544 NTSTATUS
cli_ntcreate(struct cli_state
*cli
,
2546 uint32_t CreatFlags
,
2547 uint32_t DesiredAccess
,
2548 uint32_t FileAttributes
,
2549 uint32_t ShareAccess
,
2550 uint32_t CreateDisposition
,
2551 uint32_t CreateOptions
,
2552 uint8_t SecurityFlags
,
2554 struct smb_create_returns
*cr
)
2556 TALLOC_CTX
*frame
= talloc_stackframe();
2557 struct tevent_context
*ev
;
2558 struct tevent_req
*req
;
2559 uint32_t ImpersonationLevel
= SMB2_IMPERSONATION_IMPERSONATION
;
2560 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
2562 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
2564 * Can't use sync call while an async call is in flight
2566 status
= NT_STATUS_INVALID_PARAMETER
;
2570 ev
= samba_tevent_context_init(frame
);
2575 req
= cli_ntcreate_send(frame
, ev
, cli
, fname
, CreatFlags
,
2576 DesiredAccess
, FileAttributes
, ShareAccess
,
2577 CreateDisposition
, CreateOptions
,
2578 ImpersonationLevel
, SecurityFlags
);
2583 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
2587 status
= cli_ntcreate_recv(req
, pfid
, cr
);
2593 struct cli_nttrans_create_state
{
2595 struct smb_create_returns cr
;
2598 static void cli_nttrans_create_done(struct tevent_req
*subreq
);
2600 struct tevent_req
*cli_nttrans_create_send(TALLOC_CTX
*mem_ctx
,
2601 struct tevent_context
*ev
,
2602 struct cli_state
*cli
,
2604 uint32_t CreatFlags
,
2605 uint32_t DesiredAccess
,
2606 uint32_t FileAttributes
,
2607 uint32_t ShareAccess
,
2608 uint32_t CreateDisposition
,
2609 uint32_t CreateOptions
,
2610 uint8_t SecurityFlags
,
2611 struct security_descriptor
*secdesc
,
2612 struct ea_struct
*eas
,
2615 struct tevent_req
*req
, *subreq
;
2616 struct cli_nttrans_create_state
*state
;
2618 uint8_t *secdesc_buf
;
2621 size_t converted_len
;
2622 uint16_t additional_flags2
= 0;
2624 req
= tevent_req_create(mem_ctx
,
2625 &state
, struct cli_nttrans_create_state
);
2630 if (secdesc
!= NULL
) {
2631 status
= marshall_sec_desc(talloc_tos(), secdesc
,
2632 &secdesc_buf
, &secdesc_len
);
2633 if (tevent_req_nterror(req
, status
)) {
2634 DEBUG(10, ("marshall_sec_desc failed: %s\n",
2635 nt_errstr(status
)));
2636 return tevent_req_post(req
, ev
);
2647 tevent_req_nterror(req
, NT_STATUS_NOT_IMPLEMENTED
);
2648 return tevent_req_post(req
, ev
);
2651 param
= talloc_array(state
, uint8_t, 53);
2652 if (tevent_req_nomem(param
, req
)) {
2653 return tevent_req_post(req
, ev
);
2656 param
= trans2_bytes_push_str(param
, smbXcli_conn_use_unicode(cli
->conn
),
2657 fname
, strlen(fname
),
2659 if (tevent_req_nomem(param
, req
)) {
2660 return tevent_req_post(req
, ev
);
2663 if (clistr_is_previous_version_path(fname
, NULL
, NULL
, NULL
)) {
2664 additional_flags2
= FLAGS2_REPARSE_PATH
;
2667 SIVAL(param
, 0, CreatFlags
);
2668 SIVAL(param
, 4, 0x0); /* RootDirectoryFid */
2669 SIVAL(param
, 8, DesiredAccess
);
2670 SIVAL(param
, 12, 0x0); /* AllocationSize */
2671 SIVAL(param
, 16, 0x0); /* AllocationSize */
2672 SIVAL(param
, 20, FileAttributes
);
2673 SIVAL(param
, 24, ShareAccess
);
2674 SIVAL(param
, 28, CreateDisposition
);
2675 SIVAL(param
, 32, CreateOptions
|
2676 (cli
->backup_intent
? FILE_OPEN_FOR_BACKUP_INTENT
: 0));
2677 SIVAL(param
, 36, secdesc_len
);
2678 SIVAL(param
, 40, 0); /* EA length*/
2679 SIVAL(param
, 44, converted_len
);
2680 SIVAL(param
, 48, 0x02); /* ImpersonationLevel */
2681 SCVAL(param
, 52, SecurityFlags
);
2683 subreq
= cli_trans_send(state
, ev
, cli
,
2684 additional_flags2
, /* additional_flags2 */
2686 NULL
, -1, /* name, fid */
2687 NT_TRANSACT_CREATE
, 0,
2688 NULL
, 0, 0, /* setup */
2689 param
, talloc_get_size(param
), 128, /* param */
2690 secdesc_buf
, secdesc_len
, 0); /* data */
2691 if (tevent_req_nomem(subreq
, req
)) {
2692 return tevent_req_post(req
, ev
);
2694 tevent_req_set_callback(subreq
, cli_nttrans_create_done
, req
);
2698 static void cli_nttrans_create_done(struct tevent_req
*subreq
)
2700 struct tevent_req
*req
= tevent_req_callback_data(
2701 subreq
, struct tevent_req
);
2702 struct cli_nttrans_create_state
*state
= tevent_req_data(
2703 req
, struct cli_nttrans_create_state
);
2708 status
= cli_trans_recv(subreq
, talloc_tos(), NULL
,
2709 NULL
, 0, NULL
, /* rsetup */
2710 ¶m
, 69, &num_param
,
2712 if (tevent_req_nterror(req
, status
)) {
2715 state
->cr
.oplock_level
= CVAL(param
, 0);
2716 state
->fnum
= SVAL(param
, 2);
2717 state
->cr
.create_action
= IVAL(param
, 4);
2718 state
->cr
.creation_time
= BVAL(param
, 12);
2719 state
->cr
.last_access_time
= BVAL(param
, 20);
2720 state
->cr
.last_write_time
= BVAL(param
, 28);
2721 state
->cr
.change_time
= BVAL(param
, 36);
2722 state
->cr
.file_attributes
= IVAL(param
, 44);
2723 state
->cr
.allocation_size
= BVAL(param
, 48);
2724 state
->cr
.end_of_file
= BVAL(param
, 56);
2727 tevent_req_done(req
);
2730 NTSTATUS
cli_nttrans_create_recv(struct tevent_req
*req
,
2732 struct smb_create_returns
*cr
)
2734 struct cli_nttrans_create_state
*state
= tevent_req_data(
2735 req
, struct cli_nttrans_create_state
);
2738 if (tevent_req_is_nterror(req
, &status
)) {
2741 *fnum
= state
->fnum
;
2745 return NT_STATUS_OK
;
2748 NTSTATUS
cli_nttrans_create(struct cli_state
*cli
,
2750 uint32_t CreatFlags
,
2751 uint32_t DesiredAccess
,
2752 uint32_t FileAttributes
,
2753 uint32_t ShareAccess
,
2754 uint32_t CreateDisposition
,
2755 uint32_t CreateOptions
,
2756 uint8_t SecurityFlags
,
2757 struct security_descriptor
*secdesc
,
2758 struct ea_struct
*eas
,
2761 struct smb_create_returns
*cr
)
2763 TALLOC_CTX
*frame
= talloc_stackframe();
2764 struct tevent_context
*ev
;
2765 struct tevent_req
*req
;
2766 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
2768 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
2770 * Can't use sync call while an async call is in flight
2772 status
= NT_STATUS_INVALID_PARAMETER
;
2775 ev
= samba_tevent_context_init(frame
);
2779 req
= cli_nttrans_create_send(frame
, ev
, cli
, fname
, CreatFlags
,
2780 DesiredAccess
, FileAttributes
,
2781 ShareAccess
, CreateDisposition
,
2782 CreateOptions
, SecurityFlags
,
2783 secdesc
, eas
, num_eas
);
2787 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
2790 status
= cli_nttrans_create_recv(req
, pfid
, cr
);
2796 /****************************************************************************
2798 WARNING: if you open with O_WRONLY then getattrE won't work!
2799 ****************************************************************************/
2801 struct cli_openx_state
{
2808 static void cli_openx_done(struct tevent_req
*subreq
);
2810 struct tevent_req
*cli_openx_create(TALLOC_CTX
*mem_ctx
,
2811 struct tevent_context
*ev
,
2812 struct cli_state
*cli
, const char *fname
,
2813 int flags
, int share_mode
,
2814 struct tevent_req
**psmbreq
)
2816 struct tevent_req
*req
, *subreq
;
2817 struct cli_openx_state
*state
;
2819 unsigned accessmode
;
2820 uint8_t additional_flags
;
2821 uint16_t additional_flags2
= 0;
2824 req
= tevent_req_create(mem_ctx
, &state
, struct cli_openx_state
);
2830 if (flags
& O_CREAT
) {
2833 if (!(flags
& O_EXCL
)) {
2834 if (flags
& O_TRUNC
)
2840 accessmode
= (share_mode
<<4);
2842 if ((flags
& O_ACCMODE
) == O_RDWR
) {
2844 } else if ((flags
& O_ACCMODE
) == O_WRONLY
) {
2849 if ((flags
& O_SYNC
) == O_SYNC
) {
2850 accessmode
|= (1<<14);
2854 if (share_mode
== DENY_FCB
) {
2858 SCVAL(state
->vwv
+ 0, 0, 0xFF);
2859 SCVAL(state
->vwv
+ 0, 1, 0);
2860 SSVAL(state
->vwv
+ 1, 0, 0);
2861 SSVAL(state
->vwv
+ 2, 0, 0); /* no additional info */
2862 SSVAL(state
->vwv
+ 3, 0, accessmode
);
2863 SSVAL(state
->vwv
+ 4, 0, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2864 SSVAL(state
->vwv
+ 5, 0, 0);
2865 SIVAL(state
->vwv
+ 6, 0, 0);
2866 SSVAL(state
->vwv
+ 8, 0, openfn
);
2867 SIVAL(state
->vwv
+ 9, 0, 0);
2868 SIVAL(state
->vwv
+ 11, 0, 0);
2869 SIVAL(state
->vwv
+ 13, 0, 0);
2871 additional_flags
= 0;
2873 if (cli
->use_oplocks
) {
2874 /* if using oplocks then ask for a batch oplock via
2875 core and extended methods */
2877 FLAG_REQUEST_OPLOCK
|FLAG_REQUEST_BATCH_OPLOCK
;
2878 SSVAL(state
->vwv
+2, 0, SVAL(state
->vwv
+2, 0) | 6);
2881 bytes
= talloc_array(state
, uint8_t, 0);
2882 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname
,
2883 strlen(fname
)+1, NULL
);
2885 if (tevent_req_nomem(bytes
, req
)) {
2886 return tevent_req_post(req
, ev
);
2889 if (clistr_is_previous_version_path(fname
, NULL
, NULL
, NULL
)) {
2890 additional_flags2
= FLAGS2_REPARSE_PATH
;
2893 state
->bytes
.iov_base
= (void *)bytes
;
2894 state
->bytes
.iov_len
= talloc_get_size(bytes
);
2896 subreq
= cli_smb_req_create(state
, ev
, cli
, SMBopenX
, additional_flags
,
2897 additional_flags2
, 15, state
->vwv
, 1, &state
->bytes
);
2898 if (subreq
== NULL
) {
2902 tevent_req_set_callback(subreq
, cli_openx_done
, req
);
2907 struct tevent_req
*cli_openx_send(TALLOC_CTX
*mem_ctx
, struct tevent_context
*ev
,
2908 struct cli_state
*cli
, const char *fname
,
2909 int flags
, int share_mode
)
2911 struct tevent_req
*req
, *subreq
;
2914 req
= cli_openx_create(mem_ctx
, ev
, cli
, fname
, flags
, share_mode
,
2920 status
= smb1cli_req_chain_submit(&subreq
, 1);
2921 if (tevent_req_nterror(req
, status
)) {
2922 return tevent_req_post(req
, ev
);
2927 static void cli_openx_done(struct tevent_req
*subreq
)
2929 struct tevent_req
*req
= tevent_req_callback_data(
2930 subreq
, struct tevent_req
);
2931 struct cli_openx_state
*state
= tevent_req_data(
2932 req
, struct cli_openx_state
);
2937 status
= cli_smb_recv(subreq
, state
, NULL
, 3, &wct
, &vwv
, NULL
,
2939 TALLOC_FREE(subreq
);
2940 if (tevent_req_nterror(req
, status
)) {
2943 state
->fnum
= SVAL(vwv
+2, 0);
2944 tevent_req_done(req
);
2947 NTSTATUS
cli_openx_recv(struct tevent_req
*req
, uint16_t *pfnum
)
2949 struct cli_openx_state
*state
= tevent_req_data(
2950 req
, struct cli_openx_state
);
2953 if (tevent_req_is_nterror(req
, &status
)) {
2956 *pfnum
= state
->fnum
;
2957 return NT_STATUS_OK
;
2960 NTSTATUS
cli_openx(struct cli_state
*cli
, const char *fname
, int flags
,
2961 int share_mode
, uint16_t *pfnum
)
2963 TALLOC_CTX
*frame
= talloc_stackframe();
2964 struct tevent_context
*ev
;
2965 struct tevent_req
*req
;
2966 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
2968 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
2970 * Can't use sync call while an async call is in flight
2972 status
= NT_STATUS_INVALID_PARAMETER
;
2976 ev
= samba_tevent_context_init(frame
);
2981 req
= cli_openx_send(frame
, ev
, cli
, fname
, flags
, share_mode
);
2986 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
2990 status
= cli_openx_recv(req
, pfnum
);
2995 /****************************************************************************
2996 Synchronous wrapper function that does an NtCreateX open by preference
2997 and falls back to openX if this fails.
2998 ****************************************************************************/
3000 NTSTATUS
cli_open(struct cli_state
*cli
, const char *fname
, int flags
,
3001 int share_mode_in
, uint16_t *pfnum
)
3004 unsigned int openfn
= 0;
3005 unsigned int dos_deny
= 0;
3006 uint32_t access_mask
, share_mode
, create_disposition
, create_options
;
3007 struct smb_create_returns cr
;
3009 /* Do the initial mapping into OpenX parameters. */
3010 if (flags
& O_CREAT
) {
3013 if (!(flags
& O_EXCL
)) {
3014 if (flags
& O_TRUNC
)
3020 dos_deny
= (share_mode_in
<<4);
3022 if ((flags
& O_ACCMODE
) == O_RDWR
) {
3024 } else if ((flags
& O_ACCMODE
) == O_WRONLY
) {
3029 if ((flags
& O_SYNC
) == O_SYNC
) {
3030 dos_deny
|= (1<<14);
3034 if (share_mode_in
== DENY_FCB
) {
3039 /* Hmmm. This is what I think the above code
3040 should look like if it's using the constants
3043 if (flags
& O_CREAT
) {
3044 openfn
|= OPENX_FILE_CREATE_IF_NOT_EXIST
;
3046 if (!(flags
& O_EXCL
)) {
3047 if (flags
& O_TRUNC
)
3048 openfn
|= OPENX_FILE_EXISTS_TRUNCATE
;
3050 openfn
|= OPENX_FILE_EXISTS_OPEN
;
3053 dos_deny
= SET_DENY_MODE(share_mode_in
);
3055 if ((flags
& O_ACCMODE
) == O_RDWR
) {
3056 dos_deny
|= DOS_OPEN_RDWR
;
3057 } else if ((flags
& O_ACCMODE
) == O_WRONLY
) {
3058 dos_deny
|= DOS_OPEN_WRONLY
;
3062 if ((flags
& O_SYNC
) == O_SYNC
) {
3063 dos_deny
|= FILE_SYNC_OPENMODE
;
3067 if (share_mode_in
== DENY_FCB
) {
3072 if (!map_open_params_to_ntcreate(fname
, dos_deny
,
3073 openfn
, &access_mask
,
3074 &share_mode
, &create_disposition
,
3075 &create_options
, NULL
)) {
3079 status
= cli_ntcreate(cli
,
3091 /* Try and cope will all varients of "we don't do this call"
3092 and fall back to openX. */
3094 if (NT_STATUS_EQUAL(status
,NT_STATUS_NOT_IMPLEMENTED
) ||
3095 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_INFO_CLASS
) ||
3096 NT_STATUS_EQUAL(status
,NT_STATUS_PROCEDURE_NOT_FOUND
) ||
3097 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_LEVEL
) ||
3098 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_PARAMETER
) ||
3099 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_DEVICE_REQUEST
) ||
3100 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_DEVICE_STATE
) ||
3101 NT_STATUS_EQUAL(status
,NT_STATUS_CTL_FILE_NOT_SUPPORTED
) ||
3102 NT_STATUS_EQUAL(status
,NT_STATUS_UNSUCCESSFUL
)) {
3106 if (NT_STATUS_IS_OK(status
) &&
3107 (create_options
& FILE_NON_DIRECTORY_FILE
) &&
3108 (cr
.file_attributes
& FILE_ATTRIBUTE_DIRECTORY
))
3111 * Some (broken) servers return a valid handle
3112 * for directories even if FILE_NON_DIRECTORY_FILE
3113 * is set. Just close the handle and set the
3114 * error explicitly to NT_STATUS_FILE_IS_A_DIRECTORY.
3116 status
= cli_close(cli
, *pfnum
);
3117 if (!NT_STATUS_IS_OK(status
)) {
3120 status
= NT_STATUS_FILE_IS_A_DIRECTORY
;
3121 /* Set this so libsmbclient can retrieve it. */
3122 cli
->raw_status
= status
;
3129 return cli_openx(cli
, fname
, flags
, share_mode_in
, pfnum
);
3132 /****************************************************************************
3134 ****************************************************************************/
3136 struct cli_smb1_close_state
{
3140 static void cli_smb1_close_done(struct tevent_req
*subreq
);
3142 struct tevent_req
*cli_smb1_close_create(TALLOC_CTX
*mem_ctx
,
3143 struct tevent_context
*ev
,
3144 struct cli_state
*cli
,
3146 struct tevent_req
**psubreq
)
3148 struct tevent_req
*req
, *subreq
;
3149 struct cli_smb1_close_state
*state
;
3151 req
= tevent_req_create(mem_ctx
, &state
, struct cli_smb1_close_state
);
3156 SSVAL(state
->vwv
+0, 0, fnum
);
3157 SIVALS(state
->vwv
+1, 0, -1);
3159 subreq
= cli_smb_req_create(state
, ev
, cli
, SMBclose
, 0, 0,
3160 3, state
->vwv
, 0, NULL
);
3161 if (subreq
== NULL
) {
3165 tevent_req_set_callback(subreq
, cli_smb1_close_done
, req
);
3170 static void cli_smb1_close_done(struct tevent_req
*subreq
)
3172 struct tevent_req
*req
= tevent_req_callback_data(
3173 subreq
, struct tevent_req
);
3176 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
3177 TALLOC_FREE(subreq
);
3178 if (tevent_req_nterror(req
, status
)) {
3181 tevent_req_done(req
);
3184 struct cli_close_state
{
3188 static void cli_close_done(struct tevent_req
*subreq
);
3190 struct tevent_req
*cli_close_send(TALLOC_CTX
*mem_ctx
,
3191 struct tevent_context
*ev
,
3192 struct cli_state
*cli
,
3195 struct tevent_req
*req
, *subreq
;
3196 struct cli_close_state
*state
;
3199 req
= tevent_req_create(mem_ctx
, &state
, struct cli_close_state
);
3204 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
3205 subreq
= cli_smb2_close_fnum_send(state
,
3209 if (tevent_req_nomem(subreq
, req
)) {
3210 return tevent_req_post(req
, ev
);
3213 struct tevent_req
*ch_req
= NULL
;
3214 subreq
= cli_smb1_close_create(state
, ev
, cli
, fnum
, &ch_req
);
3215 if (tevent_req_nomem(subreq
, req
)) {
3216 return tevent_req_post(req
, ev
);
3218 status
= smb1cli_req_chain_submit(&ch_req
, 1);
3219 if (tevent_req_nterror(req
, status
)) {
3220 return tevent_req_post(req
, ev
);
3224 tevent_req_set_callback(subreq
, cli_close_done
, req
);
3228 static void cli_close_done(struct tevent_req
*subreq
)
3230 struct tevent_req
*req
= tevent_req_callback_data(
3231 subreq
, struct tevent_req
);
3232 NTSTATUS status
= NT_STATUS_OK
;
3233 bool err
= tevent_req_is_nterror(subreq
, &status
);
3235 TALLOC_FREE(subreq
);
3237 tevent_req_nterror(req
, status
);
3240 tevent_req_done(req
);
3243 NTSTATUS
cli_close_recv(struct tevent_req
*req
)
3245 return tevent_req_simple_recv_ntstatus(req
);
3248 NTSTATUS
cli_close(struct cli_state
*cli
, uint16_t fnum
)
3250 TALLOC_CTX
*frame
= NULL
;
3251 struct tevent_context
*ev
;
3252 struct tevent_req
*req
;
3253 NTSTATUS status
= NT_STATUS_OK
;
3255 frame
= talloc_stackframe();
3257 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
3259 * Can't use sync call while an async call is in flight
3261 status
= NT_STATUS_INVALID_PARAMETER
;
3265 ev
= samba_tevent_context_init(frame
);
3267 status
= NT_STATUS_NO_MEMORY
;
3271 req
= cli_close_send(frame
, ev
, cli
, fnum
);
3273 status
= NT_STATUS_NO_MEMORY
;
3277 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
3281 status
= cli_close_recv(req
);
3287 /****************************************************************************
3288 Truncate a file to a specified size
3289 ****************************************************************************/
3291 struct ftrunc_state
{
3297 static void cli_ftruncate_done(struct tevent_req
*subreq
)
3299 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, NULL
, 0, NULL
,
3300 NULL
, 0, NULL
, NULL
, 0, NULL
);
3301 tevent_req_simple_finish_ntstatus(subreq
, status
);
3304 struct tevent_req
*cli_ftruncate_send(TALLOC_CTX
*mem_ctx
,
3305 struct tevent_context
*ev
,
3306 struct cli_state
*cli
,
3310 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3311 struct ftrunc_state
*state
= NULL
;
3313 req
= tevent_req_create(mem_ctx
, &state
, struct ftrunc_state
);
3318 /* Setup setup word. */
3319 SSVAL(&state
->setup
, 0, TRANSACT2_SETFILEINFO
);
3321 /* Setup param array. */
3322 SSVAL(state
->param
,0,fnum
);
3323 SSVAL(state
->param
,2,SMB_SET_FILE_END_OF_FILE_INFO
);
3324 SSVAL(state
->param
,4,0);
3326 /* Setup data array. */
3327 SBVAL(state
->data
, 0, size
);
3329 subreq
= cli_trans_send(state
, /* mem ctx. */
3330 ev
, /* event ctx. */
3331 cli
, /* cli_state. */
3332 0, /* additional_flags2 */
3333 SMBtrans2
, /* cmd. */
3334 NULL
, /* pipe name. */
3338 &state
->setup
, /* setup. */
3339 1, /* num setup uint16_t words. */
3340 0, /* max returned setup. */
3341 state
->param
, /* param. */
3343 2, /* max returned param. */
3344 state
->data
, /* data. */
3346 0); /* max returned data. */
3348 if (tevent_req_nomem(subreq
, req
)) {
3349 return tevent_req_post(req
, ev
);
3351 tevent_req_set_callback(subreq
, cli_ftruncate_done
, req
);
3355 NTSTATUS
cli_ftruncate_recv(struct tevent_req
*req
)
3357 return tevent_req_simple_recv_ntstatus(req
);
3360 NTSTATUS
cli_ftruncate(struct cli_state
*cli
, uint16_t fnum
, uint64_t size
)
3362 TALLOC_CTX
*frame
= NULL
;
3363 struct tevent_context
*ev
= NULL
;
3364 struct tevent_req
*req
= NULL
;
3365 NTSTATUS status
= NT_STATUS_OK
;
3367 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
3368 return cli_smb2_ftruncate(cli
, fnum
, size
);
3371 frame
= talloc_stackframe();
3373 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
3375 * Can't use sync call while an async call is in flight
3377 status
= NT_STATUS_INVALID_PARAMETER
;
3381 ev
= samba_tevent_context_init(frame
);
3383 status
= NT_STATUS_NO_MEMORY
;
3387 req
= cli_ftruncate_send(frame
,
3393 status
= NT_STATUS_NO_MEMORY
;
3397 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
3401 status
= cli_ftruncate_recv(req
);
3408 /****************************************************************************
3409 send a lock with a specified locktype
3410 this is used for testing LOCKING_ANDX_CANCEL_LOCK
3411 ****************************************************************************/
3413 NTSTATUS
cli_locktype(struct cli_state
*cli
, uint16_t fnum
,
3414 uint32_t offset
, uint32_t len
,
3415 int timeout
, unsigned char locktype
)
3420 unsigned int set_timeout
= 0;
3421 unsigned int saved_timeout
= 0;
3423 SCVAL(vwv
+ 0, 0, 0xff);
3424 SCVAL(vwv
+ 0, 1, 0);
3425 SSVAL(vwv
+ 1, 0, 0);
3426 SSVAL(vwv
+ 2, 0, fnum
);
3427 SCVAL(vwv
+ 3, 0, locktype
);
3428 SCVAL(vwv
+ 3, 1, 0);
3429 SIVALS(vwv
+ 4, 0, timeout
);
3430 SSVAL(vwv
+ 6, 0, 0);
3431 SSVAL(vwv
+ 7, 0, 1);
3433 SSVAL(bytes
, 0, cli_getpid(cli
));
3434 SIVAL(bytes
, 2, offset
);
3435 SIVAL(bytes
, 6, len
);
3438 if (timeout
== -1) {
3439 set_timeout
= 0x7FFFFFFF;
3441 set_timeout
= timeout
+ 2*1000;
3443 saved_timeout
= cli_set_timeout(cli
, set_timeout
);
3446 status
= cli_smb(talloc_tos(), cli
, SMBlockingX
, 0, 8, vwv
,
3447 10, bytes
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
3449 if (saved_timeout
!= 0) {
3450 cli_set_timeout(cli
, saved_timeout
);
3456 /****************************************************************************
3458 note that timeout is in units of 2 milliseconds
3459 ****************************************************************************/
3461 NTSTATUS
cli_lock32(struct cli_state
*cli
, uint16_t fnum
,
3462 uint32_t offset
, uint32_t len
, int timeout
,
3463 enum brl_type lock_type
)
3467 status
= cli_locktype(cli
, fnum
, offset
, len
, timeout
,
3468 (lock_type
== READ_LOCK
? 1 : 0));
3472 /****************************************************************************
3474 ****************************************************************************/
3476 struct cli_unlock_state
{
3481 static void cli_unlock_done(struct tevent_req
*subreq
);
3483 struct tevent_req
*cli_unlock_send(TALLOC_CTX
*mem_ctx
,
3484 struct tevent_context
*ev
,
3485 struct cli_state
*cli
,
3491 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3492 struct cli_unlock_state
*state
= NULL
;
3493 uint8_t additional_flags
= 0;
3495 req
= tevent_req_create(mem_ctx
, &state
, struct cli_unlock_state
);
3500 SCVAL(state
->vwv
+0, 0, 0xFF);
3501 SSVAL(state
->vwv
+2, 0, fnum
);
3502 SCVAL(state
->vwv
+3, 0, 0);
3503 SIVALS(state
->vwv
+4, 0, 0);
3504 SSVAL(state
->vwv
+6, 0, 1);
3505 SSVAL(state
->vwv
+7, 0, 0);
3507 SSVAL(state
->data
, 0, cli_getpid(cli
));
3508 SIVAL(state
->data
, 2, offset
);
3509 SIVAL(state
->data
, 6, len
);
3511 subreq
= cli_smb_send(state
, ev
, cli
, SMBlockingX
, additional_flags
, 0,
3512 8, state
->vwv
, 10, state
->data
);
3513 if (tevent_req_nomem(subreq
, req
)) {
3514 return tevent_req_post(req
, ev
);
3516 tevent_req_set_callback(subreq
, cli_unlock_done
, req
);
3520 static void cli_unlock_done(struct tevent_req
*subreq
)
3522 struct tevent_req
*req
= tevent_req_callback_data(
3523 subreq
, struct tevent_req
);
3526 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
3527 TALLOC_FREE(subreq
);
3528 if (tevent_req_nterror(req
, status
)) {
3531 tevent_req_done(req
);
3534 NTSTATUS
cli_unlock_recv(struct tevent_req
*req
)
3536 return tevent_req_simple_recv_ntstatus(req
);
3539 NTSTATUS
cli_unlock(struct cli_state
*cli
,
3544 TALLOC_CTX
*frame
= talloc_stackframe();
3545 struct tevent_context
*ev
;
3546 struct tevent_req
*req
;
3547 NTSTATUS status
= NT_STATUS_OK
;
3549 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
3551 * Can't use sync call while an async call is in flight
3553 status
= NT_STATUS_INVALID_PARAMETER
;
3557 ev
= samba_tevent_context_init(frame
);
3559 status
= NT_STATUS_NO_MEMORY
;
3563 req
= cli_unlock_send(frame
, ev
, cli
,
3566 status
= NT_STATUS_NO_MEMORY
;
3570 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
3574 status
= cli_unlock_recv(req
);
3581 /****************************************************************************
3582 Lock a file with 64 bit offsets.
3583 ****************************************************************************/
3585 NTSTATUS
cli_lock64(struct cli_state
*cli
, uint16_t fnum
,
3586 uint64_t offset
, uint64_t len
, int timeout
,
3587 enum brl_type lock_type
)
3591 unsigned int set_timeout
= 0;
3592 unsigned int saved_timeout
= 0;
3596 if (! (smb1cli_conn_capabilities(cli
->conn
) & CAP_LARGE_FILES
)) {
3597 return cli_lock32(cli
, fnum
, offset
, len
, timeout
, lock_type
);
3600 ltype
= (lock_type
== READ_LOCK
? 1 : 0);
3601 ltype
|= LOCKING_ANDX_LARGE_FILES
;
3603 SCVAL(vwv
+ 0, 0, 0xff);
3604 SCVAL(vwv
+ 0, 1, 0);
3605 SSVAL(vwv
+ 1, 0, 0);
3606 SSVAL(vwv
+ 2, 0, fnum
);
3607 SCVAL(vwv
+ 3, 0, ltype
);
3608 SCVAL(vwv
+ 3, 1, 0);
3609 SIVALS(vwv
+ 4, 0, timeout
);
3610 SSVAL(vwv
+ 6, 0, 0);
3611 SSVAL(vwv
+ 7, 0, 1);
3613 SIVAL(bytes
, 0, cli_getpid(cli
));
3614 SOFF_T_R(bytes
, 4, offset
);
3615 SOFF_T_R(bytes
, 12, len
);
3618 if (timeout
== -1) {
3619 set_timeout
= 0x7FFFFFFF;
3621 set_timeout
= timeout
+ 2*1000;
3623 saved_timeout
= cli_set_timeout(cli
, set_timeout
);
3626 status
= cli_smb(talloc_tos(), cli
, SMBlockingX
, 0, 8, vwv
,
3627 20, bytes
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
3629 if (saved_timeout
!= 0) {
3630 cli_set_timeout(cli
, saved_timeout
);
3636 /****************************************************************************
3637 Unlock a file with 64 bit offsets.
3638 ****************************************************************************/
3640 struct cli_unlock64_state
{
3645 static void cli_unlock64_done(struct tevent_req
*subreq
);
3647 struct tevent_req
*cli_unlock64_send(TALLOC_CTX
*mem_ctx
,
3648 struct tevent_context
*ev
,
3649 struct cli_state
*cli
,
3655 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3656 struct cli_unlock64_state
*state
= NULL
;
3657 uint8_t additional_flags
= 0;
3659 req
= tevent_req_create(mem_ctx
, &state
, struct cli_unlock64_state
);
3664 SCVAL(state
->vwv
+0, 0, 0xff);
3665 SSVAL(state
->vwv
+2, 0, fnum
);
3666 SCVAL(state
->vwv
+3, 0,LOCKING_ANDX_LARGE_FILES
);
3667 SIVALS(state
->vwv
+4, 0, 0);
3668 SSVAL(state
->vwv
+6, 0, 1);
3669 SSVAL(state
->vwv
+7, 0, 0);
3671 SIVAL(state
->data
, 0, cli_getpid(cli
));
3672 SOFF_T_R(state
->data
, 4, offset
);
3673 SOFF_T_R(state
->data
, 12, len
);
3675 subreq
= cli_smb_send(state
, ev
, cli
, SMBlockingX
, additional_flags
, 0,
3676 8, state
->vwv
, 20, state
->data
);
3677 if (tevent_req_nomem(subreq
, req
)) {
3678 return tevent_req_post(req
, ev
);
3680 tevent_req_set_callback(subreq
, cli_unlock64_done
, req
);
3684 static void cli_unlock64_done(struct tevent_req
*subreq
)
3686 struct tevent_req
*req
= tevent_req_callback_data(
3687 subreq
, struct tevent_req
);
3690 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
3691 TALLOC_FREE(subreq
);
3692 if (tevent_req_nterror(req
, status
)) {
3695 tevent_req_done(req
);
3698 NTSTATUS
cli_unlock64_recv(struct tevent_req
*req
)
3700 return tevent_req_simple_recv_ntstatus(req
);
3703 NTSTATUS
cli_unlock64(struct cli_state
*cli
,
3708 TALLOC_CTX
*frame
= talloc_stackframe();
3709 struct tevent_context
*ev
;
3710 struct tevent_req
*req
;
3711 NTSTATUS status
= NT_STATUS_OK
;
3713 if (! (smb1cli_conn_capabilities(cli
->conn
) & CAP_LARGE_FILES
)) {
3714 return cli_unlock(cli
, fnum
, offset
, len
);
3717 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
3719 * Can't use sync call while an async call is in flight
3721 status
= NT_STATUS_INVALID_PARAMETER
;
3725 ev
= samba_tevent_context_init(frame
);
3727 status
= NT_STATUS_NO_MEMORY
;
3731 req
= cli_unlock64_send(frame
, ev
, cli
,
3734 status
= NT_STATUS_NO_MEMORY
;
3738 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
3742 status
= cli_unlock64_recv(req
);
3749 /****************************************************************************
3750 Get/unlock a POSIX lock on a file - internal function.
3751 ****************************************************************************/
3753 struct posix_lock_state
{
3756 uint8_t data
[POSIX_LOCK_DATA_SIZE
];
3759 static void cli_posix_unlock_internal_done(struct tevent_req
*subreq
)
3761 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, NULL
, 0, NULL
,
3762 NULL
, 0, NULL
, NULL
, 0, NULL
);
3763 tevent_req_simple_finish_ntstatus(subreq
, status
);
3766 static struct tevent_req
*cli_posix_lock_internal_send(TALLOC_CTX
*mem_ctx
,
3767 struct tevent_context
*ev
,
3768 struct cli_state
*cli
,
3773 enum brl_type lock_type
)
3775 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3776 struct posix_lock_state
*state
= NULL
;
3778 req
= tevent_req_create(mem_ctx
, &state
, struct posix_lock_state
);
3783 /* Setup setup word. */
3784 SSVAL(&state
->setup
, 0, TRANSACT2_SETFILEINFO
);
3786 /* Setup param array. */
3787 SSVAL(&state
->param
, 0, fnum
);
3788 SSVAL(&state
->param
, 2, SMB_SET_POSIX_LOCK
);
3790 /* Setup data array. */
3791 switch (lock_type
) {
3793 SSVAL(&state
->data
, POSIX_LOCK_TYPE_OFFSET
,
3794 POSIX_LOCK_TYPE_READ
);
3797 SSVAL(&state
->data
, POSIX_LOCK_TYPE_OFFSET
,
3798 POSIX_LOCK_TYPE_WRITE
);
3801 SSVAL(&state
->data
, POSIX_LOCK_TYPE_OFFSET
,
3802 POSIX_LOCK_TYPE_UNLOCK
);
3809 SSVAL(&state
->data
, POSIX_LOCK_FLAGS_OFFSET
,
3810 POSIX_LOCK_FLAG_WAIT
);
3812 SSVAL(state
->data
, POSIX_LOCK_FLAGS_OFFSET
,
3813 POSIX_LOCK_FLAG_NOWAIT
);
3816 SIVAL(&state
->data
, POSIX_LOCK_PID_OFFSET
, cli_getpid(cli
));
3817 SOFF_T(&state
->data
, POSIX_LOCK_START_OFFSET
, offset
);
3818 SOFF_T(&state
->data
, POSIX_LOCK_LEN_OFFSET
, len
);
3820 subreq
= cli_trans_send(state
, /* mem ctx. */
3821 ev
, /* event ctx. */
3822 cli
, /* cli_state. */
3823 0, /* additional_flags2 */
3824 SMBtrans2
, /* cmd. */
3825 NULL
, /* pipe name. */
3829 &state
->setup
, /* setup. */
3830 1, /* num setup uint16_t words. */
3831 0, /* max returned setup. */
3832 state
->param
, /* param. */
3834 2, /* max returned param. */
3835 state
->data
, /* data. */
3836 POSIX_LOCK_DATA_SIZE
, /* num data. */
3837 0); /* max returned data. */
3839 if (tevent_req_nomem(subreq
, req
)) {
3840 return tevent_req_post(req
, ev
);
3842 tevent_req_set_callback(subreq
, cli_posix_unlock_internal_done
, req
);
3846 /****************************************************************************
3848 ****************************************************************************/
3850 struct tevent_req
*cli_posix_lock_send(TALLOC_CTX
*mem_ctx
,
3851 struct tevent_context
*ev
,
3852 struct cli_state
*cli
,
3857 enum brl_type lock_type
)
3859 return cli_posix_lock_internal_send(mem_ctx
, ev
, cli
, fnum
, offset
, len
,
3860 wait_lock
, lock_type
);
3863 NTSTATUS
cli_posix_lock_recv(struct tevent_req
*req
)
3865 return tevent_req_simple_recv_ntstatus(req
);
3868 NTSTATUS
cli_posix_lock(struct cli_state
*cli
, uint16_t fnum
,
3869 uint64_t offset
, uint64_t len
,
3870 bool wait_lock
, enum brl_type lock_type
)
3872 TALLOC_CTX
*frame
= talloc_stackframe();
3873 struct tevent_context
*ev
= NULL
;
3874 struct tevent_req
*req
= NULL
;
3875 NTSTATUS status
= NT_STATUS_OK
;
3877 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
3879 * Can't use sync call while an async call is in flight
3881 status
= NT_STATUS_INVALID_PARAMETER
;
3885 if (lock_type
!= READ_LOCK
&& lock_type
!= WRITE_LOCK
) {
3886 status
= NT_STATUS_INVALID_PARAMETER
;
3890 ev
= samba_tevent_context_init(frame
);
3892 status
= NT_STATUS_NO_MEMORY
;
3896 req
= cli_posix_lock_send(frame
,
3905 status
= NT_STATUS_NO_MEMORY
;
3909 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
3913 status
= cli_posix_lock_recv(req
);
3920 /****************************************************************************
3921 POSIX Unlock a file.
3922 ****************************************************************************/
3924 struct tevent_req
*cli_posix_unlock_send(TALLOC_CTX
*mem_ctx
,
3925 struct tevent_context
*ev
,
3926 struct cli_state
*cli
,
3931 return cli_posix_lock_internal_send(mem_ctx
, ev
, cli
, fnum
, offset
, len
,
3932 false, UNLOCK_LOCK
);
3935 NTSTATUS
cli_posix_unlock_recv(struct tevent_req
*req
)
3937 return tevent_req_simple_recv_ntstatus(req
);
3940 NTSTATUS
cli_posix_unlock(struct cli_state
*cli
, uint16_t fnum
, uint64_t offset
, uint64_t len
)
3942 TALLOC_CTX
*frame
= talloc_stackframe();
3943 struct tevent_context
*ev
= NULL
;
3944 struct tevent_req
*req
= NULL
;
3945 NTSTATUS status
= NT_STATUS_OK
;
3947 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
3949 * Can't use sync call while an async call is in flight
3951 status
= NT_STATUS_INVALID_PARAMETER
;
3955 ev
= samba_tevent_context_init(frame
);
3957 status
= NT_STATUS_NO_MEMORY
;
3961 req
= cli_posix_unlock_send(frame
,
3968 status
= NT_STATUS_NO_MEMORY
;
3972 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
3976 status
= cli_posix_unlock_recv(req
);
3983 /****************************************************************************
3984 Do a SMBgetattrE call.
3985 ****************************************************************************/
3987 static void cli_getattrE_done(struct tevent_req
*subreq
);
3989 struct cli_getattrE_state
{
3999 struct tevent_req
*cli_getattrE_send(TALLOC_CTX
*mem_ctx
,
4000 struct tevent_context
*ev
,
4001 struct cli_state
*cli
,
4004 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
4005 struct cli_getattrE_state
*state
= NULL
;
4006 uint8_t additional_flags
= 0;
4008 req
= tevent_req_create(mem_ctx
, &state
, struct cli_getattrE_state
);
4013 state
->zone_offset
= smb1cli_conn_server_time_zone(cli
->conn
);
4014 SSVAL(state
->vwv
+0,0,fnum
);
4016 subreq
= cli_smb_send(state
, ev
, cli
, SMBgetattrE
, additional_flags
, 0,
4017 1, state
->vwv
, 0, NULL
);
4018 if (tevent_req_nomem(subreq
, req
)) {
4019 return tevent_req_post(req
, ev
);
4021 tevent_req_set_callback(subreq
, cli_getattrE_done
, req
);
4025 static void cli_getattrE_done(struct tevent_req
*subreq
)
4027 struct tevent_req
*req
= tevent_req_callback_data(
4028 subreq
, struct tevent_req
);
4029 struct cli_getattrE_state
*state
= tevent_req_data(
4030 req
, struct cli_getattrE_state
);
4032 uint16_t *vwv
= NULL
;
4035 status
= cli_smb_recv(subreq
, state
, NULL
, 11, &wct
, &vwv
,
4037 TALLOC_FREE(subreq
);
4038 if (tevent_req_nterror(req
, status
)) {
4042 state
->size
= (off_t
)IVAL(vwv
+6,0);
4043 state
->attr
= SVAL(vwv
+10,0);
4044 state
->change_time
= make_unix_date2(vwv
+0, state
->zone_offset
);
4045 state
->access_time
= make_unix_date2(vwv
+2, state
->zone_offset
);
4046 state
->write_time
= make_unix_date2(vwv
+4, state
->zone_offset
);
4048 tevent_req_done(req
);
4051 NTSTATUS
cli_getattrE_recv(struct tevent_req
*req
,
4054 time_t *change_time
,
4055 time_t *access_time
,
4058 struct cli_getattrE_state
*state
= tevent_req_data(
4059 req
, struct cli_getattrE_state
);
4062 if (tevent_req_is_nterror(req
, &status
)) {
4066 *attr
= state
->attr
;
4069 *size
= state
->size
;
4072 *change_time
= state
->change_time
;
4075 *access_time
= state
->access_time
;
4078 *write_time
= state
->write_time
;
4080 return NT_STATUS_OK
;
4083 NTSTATUS
cli_getattrE(struct cli_state
*cli
,
4087 time_t *change_time
,
4088 time_t *access_time
,
4091 TALLOC_CTX
*frame
= NULL
;
4092 struct tevent_context
*ev
= NULL
;
4093 struct tevent_req
*req
= NULL
;
4094 NTSTATUS status
= NT_STATUS_OK
;
4096 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
4097 return cli_smb2_getattrE(cli
,
4106 frame
= talloc_stackframe();
4108 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
4110 * Can't use sync call while an async call is in flight
4112 status
= NT_STATUS_INVALID_PARAMETER
;
4116 ev
= samba_tevent_context_init(frame
);
4118 status
= NT_STATUS_NO_MEMORY
;
4122 req
= cli_getattrE_send(frame
, ev
, cli
, fnum
);
4124 status
= NT_STATUS_NO_MEMORY
;
4128 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
4132 status
= cli_getattrE_recv(req
,
4144 /****************************************************************************
4146 ****************************************************************************/
4148 static void cli_getatr_done(struct tevent_req
*subreq
);
4150 struct cli_getatr_state
{
4157 struct tevent_req
*cli_getatr_send(TALLOC_CTX
*mem_ctx
,
4158 struct tevent_context
*ev
,
4159 struct cli_state
*cli
,
4162 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
4163 struct cli_getatr_state
*state
= NULL
;
4164 uint8_t additional_flags
= 0;
4165 uint16_t additional_flags2
= 0;
4166 uint8_t *bytes
= NULL
;
4168 req
= tevent_req_create(mem_ctx
, &state
, struct cli_getatr_state
);
4173 state
->zone_offset
= smb1cli_conn_server_time_zone(cli
->conn
);
4175 bytes
= talloc_array(state
, uint8_t, 1);
4176 if (tevent_req_nomem(bytes
, req
)) {
4177 return tevent_req_post(req
, ev
);
4180 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname
,
4181 strlen(fname
)+1, NULL
);
4183 if (tevent_req_nomem(bytes
, req
)) {
4184 return tevent_req_post(req
, ev
);
4187 if (clistr_is_previous_version_path(fname
, NULL
, NULL
, NULL
)) {
4188 additional_flags2
= FLAGS2_REPARSE_PATH
;
4191 subreq
= cli_smb_send(state
, ev
, cli
, SMBgetatr
, additional_flags
,
4193 0, NULL
, talloc_get_size(bytes
), bytes
);
4194 if (tevent_req_nomem(subreq
, req
)) {
4195 return tevent_req_post(req
, ev
);
4197 tevent_req_set_callback(subreq
, cli_getatr_done
, req
);
4201 static void cli_getatr_done(struct tevent_req
*subreq
)
4203 struct tevent_req
*req
= tevent_req_callback_data(
4204 subreq
, struct tevent_req
);
4205 struct cli_getatr_state
*state
= tevent_req_data(
4206 req
, struct cli_getatr_state
);
4208 uint16_t *vwv
= NULL
;
4211 status
= cli_smb_recv(subreq
, state
, NULL
, 4, &wct
, &vwv
, NULL
,
4213 TALLOC_FREE(subreq
);
4214 if (tevent_req_nterror(req
, status
)) {
4218 state
->attr
= SVAL(vwv
+0,0);
4219 state
->size
= (off_t
)IVAL(vwv
+3,0);
4220 state
->write_time
= make_unix_date3(vwv
+1, state
->zone_offset
);
4222 tevent_req_done(req
);
4225 NTSTATUS
cli_getatr_recv(struct tevent_req
*req
,
4230 struct cli_getatr_state
*state
= tevent_req_data(
4231 req
, struct cli_getatr_state
);
4234 if (tevent_req_is_nterror(req
, &status
)) {
4238 *attr
= state
->attr
;
4241 *size
= state
->size
;
4244 *write_time
= state
->write_time
;
4246 return NT_STATUS_OK
;
4249 NTSTATUS
cli_getatr(struct cli_state
*cli
,
4255 TALLOC_CTX
*frame
= NULL
;
4256 struct tevent_context
*ev
= NULL
;
4257 struct tevent_req
*req
= NULL
;
4258 NTSTATUS status
= NT_STATUS_OK
;
4260 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
4261 return cli_smb2_getatr(cli
,
4268 frame
= talloc_stackframe();
4270 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
4272 * Can't use sync call while an async call is in flight
4274 status
= NT_STATUS_INVALID_PARAMETER
;
4278 ev
= samba_tevent_context_init(frame
);
4280 status
= NT_STATUS_NO_MEMORY
;
4284 req
= cli_getatr_send(frame
, ev
, cli
, fname
);
4286 status
= NT_STATUS_NO_MEMORY
;
4290 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
4294 status
= cli_getatr_recv(req
,
4304 /****************************************************************************
4305 Do a SMBsetattrE call.
4306 ****************************************************************************/
4308 static void cli_setattrE_done(struct tevent_req
*subreq
);
4310 struct cli_setattrE_state
{
4314 struct tevent_req
*cli_setattrE_send(TALLOC_CTX
*mem_ctx
,
4315 struct tevent_context
*ev
,
4316 struct cli_state
*cli
,
4322 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
4323 struct cli_setattrE_state
*state
= NULL
;
4324 uint8_t additional_flags
= 0;
4326 req
= tevent_req_create(mem_ctx
, &state
, struct cli_setattrE_state
);
4331 SSVAL(state
->vwv
+0, 0, fnum
);
4332 push_dos_date2((uint8_t *)&state
->vwv
[1], 0, change_time
,
4333 smb1cli_conn_server_time_zone(cli
->conn
));
4334 push_dos_date2((uint8_t *)&state
->vwv
[3], 0, access_time
,
4335 smb1cli_conn_server_time_zone(cli
->conn
));
4336 push_dos_date2((uint8_t *)&state
->vwv
[5], 0, write_time
,
4337 smb1cli_conn_server_time_zone(cli
->conn
));
4339 subreq
= cli_smb_send(state
, ev
, cli
, SMBsetattrE
, additional_flags
, 0,
4340 7, state
->vwv
, 0, NULL
);
4341 if (tevent_req_nomem(subreq
, req
)) {
4342 return tevent_req_post(req
, ev
);
4344 tevent_req_set_callback(subreq
, cli_setattrE_done
, req
);
4348 static void cli_setattrE_done(struct tevent_req
*subreq
)
4350 struct tevent_req
*req
= tevent_req_callback_data(
4351 subreq
, struct tevent_req
);
4354 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
4355 TALLOC_FREE(subreq
);
4356 if (tevent_req_nterror(req
, status
)) {
4359 tevent_req_done(req
);
4362 NTSTATUS
cli_setattrE_recv(struct tevent_req
*req
)
4364 return tevent_req_simple_recv_ntstatus(req
);
4367 NTSTATUS
cli_setattrE(struct cli_state
*cli
,
4373 TALLOC_CTX
*frame
= NULL
;
4374 struct tevent_context
*ev
= NULL
;
4375 struct tevent_req
*req
= NULL
;
4376 NTSTATUS status
= NT_STATUS_OK
;
4378 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
4379 return cli_smb2_setattrE(cli
,
4386 frame
= talloc_stackframe();
4388 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
4390 * Can't use sync call while an async call is in flight
4392 status
= NT_STATUS_INVALID_PARAMETER
;
4396 ev
= samba_tevent_context_init(frame
);
4398 status
= NT_STATUS_NO_MEMORY
;
4402 req
= cli_setattrE_send(frame
, ev
,
4410 status
= NT_STATUS_NO_MEMORY
;
4414 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
4418 status
= cli_setattrE_recv(req
);
4425 /****************************************************************************
4426 Do a SMBsetatr call.
4427 ****************************************************************************/
4429 static void cli_setatr_done(struct tevent_req
*subreq
);
4431 struct cli_setatr_state
{
4435 struct tevent_req
*cli_setatr_send(TALLOC_CTX
*mem_ctx
,
4436 struct tevent_context
*ev
,
4437 struct cli_state
*cli
,
4442 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
4443 struct cli_setatr_state
*state
= NULL
;
4444 uint8_t additional_flags
= 0;
4445 uint16_t additional_flags2
= 0;
4446 uint8_t *bytes
= NULL
;
4448 req
= tevent_req_create(mem_ctx
, &state
, struct cli_setatr_state
);
4453 SSVAL(state
->vwv
+0, 0, attr
);
4454 push_dos_date3((uint8_t *)&state
->vwv
[1], 0, mtime
, smb1cli_conn_server_time_zone(cli
->conn
));
4456 bytes
= talloc_array(state
, uint8_t, 1);
4457 if (tevent_req_nomem(bytes
, req
)) {
4458 return tevent_req_post(req
, ev
);
4461 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname
,
4462 strlen(fname
)+1, NULL
);
4463 if (tevent_req_nomem(bytes
, req
)) {
4464 return tevent_req_post(req
, ev
);
4466 bytes
= talloc_realloc(state
, bytes
, uint8_t,
4467 talloc_get_size(bytes
)+1);
4468 if (tevent_req_nomem(bytes
, req
)) {
4469 return tevent_req_post(req
, ev
);
4472 bytes
[talloc_get_size(bytes
)-1] = 4;
4473 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), "",
4475 if (tevent_req_nomem(bytes
, req
)) {
4476 return tevent_req_post(req
, ev
);
4479 if (clistr_is_previous_version_path(fname
, NULL
, NULL
, NULL
)) {
4480 additional_flags2
= FLAGS2_REPARSE_PATH
;
4483 subreq
= cli_smb_send(state
, ev
, cli
, SMBsetatr
, additional_flags
,
4485 8, state
->vwv
, talloc_get_size(bytes
), bytes
);
4486 if (tevent_req_nomem(subreq
, req
)) {
4487 return tevent_req_post(req
, ev
);
4489 tevent_req_set_callback(subreq
, cli_setatr_done
, req
);
4493 static void cli_setatr_done(struct tevent_req
*subreq
)
4495 struct tevent_req
*req
= tevent_req_callback_data(
4496 subreq
, struct tevent_req
);
4499 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
4500 TALLOC_FREE(subreq
);
4501 if (tevent_req_nterror(req
, status
)) {
4504 tevent_req_done(req
);
4507 NTSTATUS
cli_setatr_recv(struct tevent_req
*req
)
4509 return tevent_req_simple_recv_ntstatus(req
);
4512 NTSTATUS
cli_setatr(struct cli_state
*cli
,
4517 TALLOC_CTX
*frame
= NULL
;
4518 struct tevent_context
*ev
= NULL
;
4519 struct tevent_req
*req
= NULL
;
4520 NTSTATUS status
= NT_STATUS_OK
;
4522 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
4523 return cli_smb2_setatr(cli
,
4529 frame
= talloc_stackframe();
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_setatr_send(frame
, ev
, cli
, fname
, attr
, mtime
);
4547 status
= NT_STATUS_NO_MEMORY
;
4551 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
4555 status
= cli_setatr_recv(req
);
4562 /****************************************************************************
4563 Check for existence of a dir.
4564 ****************************************************************************/
4566 static void cli_chkpath_done(struct tevent_req
*subreq
);
4568 struct cli_chkpath_state
{
4572 struct tevent_req
*cli_chkpath_send(TALLOC_CTX
*mem_ctx
,
4573 struct tevent_context
*ev
,
4574 struct cli_state
*cli
,
4577 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
4578 struct cli_chkpath_state
*state
= NULL
;
4579 uint8_t additional_flags
= 0;
4580 uint16_t additional_flags2
= 0;
4581 uint8_t *bytes
= NULL
;
4583 req
= tevent_req_create(mem_ctx
, &state
, struct cli_chkpath_state
);
4588 bytes
= talloc_array(state
, uint8_t, 1);
4589 if (tevent_req_nomem(bytes
, req
)) {
4590 return tevent_req_post(req
, ev
);
4593 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), fname
,
4594 strlen(fname
)+1, NULL
);
4596 if (tevent_req_nomem(bytes
, req
)) {
4597 return tevent_req_post(req
, ev
);
4600 if (clistr_is_previous_version_path(fname
, NULL
, NULL
, NULL
)) {
4601 additional_flags2
= FLAGS2_REPARSE_PATH
;
4604 subreq
= cli_smb_send(state
, ev
, cli
, SMBcheckpath
, additional_flags
,
4606 0, NULL
, talloc_get_size(bytes
), bytes
);
4607 if (tevent_req_nomem(subreq
, req
)) {
4608 return tevent_req_post(req
, ev
);
4610 tevent_req_set_callback(subreq
, cli_chkpath_done
, req
);
4614 static void cli_chkpath_done(struct tevent_req
*subreq
)
4616 struct tevent_req
*req
= tevent_req_callback_data(
4617 subreq
, struct tevent_req
);
4620 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
4621 TALLOC_FREE(subreq
);
4622 if (tevent_req_nterror(req
, status
)) {
4625 tevent_req_done(req
);
4628 NTSTATUS
cli_chkpath_recv(struct tevent_req
*req
)
4630 return tevent_req_simple_recv_ntstatus(req
);
4633 NTSTATUS
cli_chkpath(struct cli_state
*cli
, const char *path
)
4635 TALLOC_CTX
*frame
= NULL
;
4636 struct tevent_context
*ev
= NULL
;
4637 struct tevent_req
*req
= NULL
;
4639 NTSTATUS status
= NT_STATUS_OK
;
4641 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
4642 return cli_smb2_chkpath(cli
, path
);
4645 frame
= talloc_stackframe();
4647 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
4649 * Can't use sync call while an async call is in flight
4651 status
= NT_STATUS_INVALID_PARAMETER
;
4655 path2
= talloc_strdup(frame
, path
);
4657 status
= NT_STATUS_NO_MEMORY
;
4660 trim_char(path2
,'\0','\\');
4662 path2
= talloc_strdup(frame
, "\\");
4664 status
= NT_STATUS_NO_MEMORY
;
4669 ev
= samba_tevent_context_init(frame
);
4671 status
= NT_STATUS_NO_MEMORY
;
4675 req
= cli_chkpath_send(frame
, ev
, cli
, path2
);
4677 status
= NT_STATUS_NO_MEMORY
;
4681 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
4685 status
= cli_chkpath_recv(req
);
4692 /****************************************************************************
4694 ****************************************************************************/
4696 static void cli_dskattr_done(struct tevent_req
*subreq
);
4698 struct cli_dskattr_state
{
4704 struct tevent_req
*cli_dskattr_send(TALLOC_CTX
*mem_ctx
,
4705 struct tevent_context
*ev
,
4706 struct cli_state
*cli
)
4708 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
4709 struct cli_dskattr_state
*state
= NULL
;
4710 uint8_t additional_flags
= 0;
4712 req
= tevent_req_create(mem_ctx
, &state
, struct cli_dskattr_state
);
4717 subreq
= cli_smb_send(state
, ev
, cli
, SMBdskattr
, additional_flags
, 0,
4719 if (tevent_req_nomem(subreq
, req
)) {
4720 return tevent_req_post(req
, ev
);
4722 tevent_req_set_callback(subreq
, cli_dskattr_done
, req
);
4726 static void cli_dskattr_done(struct tevent_req
*subreq
)
4728 struct tevent_req
*req
= tevent_req_callback_data(
4729 subreq
, struct tevent_req
);
4730 struct cli_dskattr_state
*state
= tevent_req_data(
4731 req
, struct cli_dskattr_state
);
4733 uint16_t *vwv
= NULL
;
4736 status
= cli_smb_recv(subreq
, state
, NULL
, 4, &wct
, &vwv
, NULL
,
4738 TALLOC_FREE(subreq
);
4739 if (tevent_req_nterror(req
, status
)) {
4742 state
->bsize
= SVAL(vwv
+1, 0)*SVAL(vwv
+2,0);
4743 state
->total
= SVAL(vwv
+0, 0);
4744 state
->avail
= SVAL(vwv
+3, 0);
4745 tevent_req_done(req
);
4748 NTSTATUS
cli_dskattr_recv(struct tevent_req
*req
, int *bsize
, int *total
, int *avail
)
4750 struct cli_dskattr_state
*state
= tevent_req_data(
4751 req
, struct cli_dskattr_state
);
4754 if (tevent_req_is_nterror(req
, &status
)) {
4757 *bsize
= state
->bsize
;
4758 *total
= state
->total
;
4759 *avail
= state
->avail
;
4760 return NT_STATUS_OK
;
4763 NTSTATUS
cli_dskattr(struct cli_state
*cli
, int *bsize
, int *total
, int *avail
)
4765 TALLOC_CTX
*frame
= NULL
;
4766 struct tevent_context
*ev
= NULL
;
4767 struct tevent_req
*req
= NULL
;
4768 NTSTATUS status
= NT_STATUS_OK
;
4770 frame
= talloc_stackframe();
4772 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
4774 * Can't use sync call while an async call is in flight
4776 status
= NT_STATUS_INVALID_PARAMETER
;
4780 ev
= samba_tevent_context_init(frame
);
4782 status
= NT_STATUS_NO_MEMORY
;
4786 req
= cli_dskattr_send(frame
, ev
, cli
);
4788 status
= NT_STATUS_NO_MEMORY
;
4792 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
4796 status
= cli_dskattr_recv(req
, bsize
, total
, avail
);
4803 NTSTATUS
cli_disk_size(struct cli_state
*cli
, const char *path
, uint64_t *bsize
,
4804 uint64_t *total
, uint64_t *avail
)
4806 uint64_t sectors_per_block
;
4807 uint64_t bytes_per_sector
;
4808 int old_bsize
, old_total
, old_avail
;
4811 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
4812 return cli_smb2_dskattr(cli
, path
, bsize
, total
, avail
);
4816 * Try the trans2 disk full size info call first.
4817 * We already use this in SMBC_fstatvfs_ctx().
4818 * Ignore 'actual_available_units' as we only
4819 * care about the quota for the caller.
4822 status
= cli_get_fs_full_size_info(cli
,
4829 /* Try and cope will all varients of "we don't do this call"
4830 and fall back to cli_dskattr. */
4832 if (NT_STATUS_EQUAL(status
,NT_STATUS_NOT_IMPLEMENTED
) ||
4833 NT_STATUS_EQUAL(status
,NT_STATUS_NOT_SUPPORTED
) ||
4834 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_INFO_CLASS
) ||
4835 NT_STATUS_EQUAL(status
,NT_STATUS_PROCEDURE_NOT_FOUND
) ||
4836 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_LEVEL
) ||
4837 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_PARAMETER
) ||
4838 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_DEVICE_REQUEST
) ||
4839 NT_STATUS_EQUAL(status
,NT_STATUS_INVALID_DEVICE_STATE
) ||
4840 NT_STATUS_EQUAL(status
,NT_STATUS_CTL_FILE_NOT_SUPPORTED
) ||
4841 NT_STATUS_EQUAL(status
,NT_STATUS_UNSUCCESSFUL
)) {
4845 if (!NT_STATUS_IS_OK(status
)) {
4850 *bsize
= sectors_per_block
*
4854 return NT_STATUS_OK
;
4858 /* Old SMB1 core protocol fallback. */
4859 status
= cli_dskattr(cli
, &old_bsize
, &old_total
, &old_avail
);
4860 if (!NT_STATUS_IS_OK(status
)) {
4864 *bsize
= (uint64_t)old_bsize
;
4867 *total
= (uint64_t)old_total
;
4870 *avail
= (uint64_t)old_avail
;
4872 return NT_STATUS_OK
;
4875 /****************************************************************************
4876 Create and open a temporary file.
4877 ****************************************************************************/
4879 static void cli_ctemp_done(struct tevent_req
*subreq
);
4881 struct ctemp_state
{
4887 struct tevent_req
*cli_ctemp_send(TALLOC_CTX
*mem_ctx
,
4888 struct tevent_context
*ev
,
4889 struct cli_state
*cli
,
4892 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
4893 struct ctemp_state
*state
= NULL
;
4894 uint8_t additional_flags
= 0;
4895 uint16_t additional_flags2
= 0;
4896 uint8_t *bytes
= NULL
;
4898 req
= tevent_req_create(mem_ctx
, &state
, struct ctemp_state
);
4903 SSVAL(state
->vwv
,0,0);
4904 SIVALS(state
->vwv
+1,0,-1);
4906 bytes
= talloc_array(state
, uint8_t, 1);
4907 if (tevent_req_nomem(bytes
, req
)) {
4908 return tevent_req_post(req
, ev
);
4911 bytes
= smb_bytes_push_str(bytes
, smbXcli_conn_use_unicode(cli
->conn
), path
,
4912 strlen(path
)+1, NULL
);
4913 if (tevent_req_nomem(bytes
, req
)) {
4914 return tevent_req_post(req
, ev
);
4917 if (clistr_is_previous_version_path(path
, NULL
, NULL
, NULL
)) {
4918 additional_flags2
= FLAGS2_REPARSE_PATH
;
4921 subreq
= cli_smb_send(state
, ev
, cli
, SMBctemp
, additional_flags
,
4923 3, state
->vwv
, talloc_get_size(bytes
), bytes
);
4924 if (tevent_req_nomem(subreq
, req
)) {
4925 return tevent_req_post(req
, ev
);
4927 tevent_req_set_callback(subreq
, cli_ctemp_done
, req
);
4931 static void cli_ctemp_done(struct tevent_req
*subreq
)
4933 struct tevent_req
*req
= tevent_req_callback_data(
4934 subreq
, struct tevent_req
);
4935 struct ctemp_state
*state
= tevent_req_data(
4936 req
, struct ctemp_state
);
4940 uint32_t num_bytes
= 0;
4941 uint8_t *bytes
= NULL
;
4943 status
= cli_smb_recv(subreq
, state
, NULL
, 1, &wcnt
, &vwv
,
4944 &num_bytes
, &bytes
);
4945 TALLOC_FREE(subreq
);
4946 if (tevent_req_nterror(req
, status
)) {
4950 state
->fnum
= SVAL(vwv
+0, 0);
4952 /* From W2K3, the result is just the ASCII name */
4953 if (num_bytes
< 2) {
4954 tevent_req_nterror(req
, NT_STATUS_DATA_ERROR
);
4958 if (pull_string_talloc(state
,
4965 tevent_req_nterror(req
, NT_STATUS_NO_MEMORY
);
4968 tevent_req_done(req
);
4971 NTSTATUS
cli_ctemp_recv(struct tevent_req
*req
,
4976 struct ctemp_state
*state
= tevent_req_data(req
,
4977 struct ctemp_state
);
4980 if (tevent_req_is_nterror(req
, &status
)) {
4983 *pfnum
= state
->fnum
;
4984 *outfile
= talloc_strdup(ctx
, state
->ret_path
);
4986 return NT_STATUS_NO_MEMORY
;
4988 return NT_STATUS_OK
;
4991 NTSTATUS
cli_ctemp(struct cli_state
*cli
,
4997 TALLOC_CTX
*frame
= talloc_stackframe();
4998 struct tevent_context
*ev
;
4999 struct tevent_req
*req
;
5000 NTSTATUS status
= NT_STATUS_OK
;
5002 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
5004 * Can't use sync call while an async call is in flight
5006 status
= NT_STATUS_INVALID_PARAMETER
;
5010 ev
= samba_tevent_context_init(frame
);
5012 status
= NT_STATUS_NO_MEMORY
;
5016 req
= cli_ctemp_send(frame
, ev
, cli
, path
);
5018 status
= NT_STATUS_NO_MEMORY
;
5022 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5026 status
= cli_ctemp_recv(req
, ctx
, pfnum
, out_path
);
5034 send a raw ioctl - used by the torture code
5036 NTSTATUS
cli_raw_ioctl(struct cli_state
*cli
, uint16_t fnum
, uint32_t code
, DATA_BLOB
*blob
)
5041 SSVAL(vwv
+0, 0, fnum
);
5042 SSVAL(vwv
+1, 0, code
>>16);
5043 SSVAL(vwv
+2, 0, (code
&0xFFFF));
5045 status
= cli_smb(talloc_tos(), cli
, SMBioctl
, 0, 3, vwv
, 0, NULL
,
5046 NULL
, 0, NULL
, NULL
, NULL
, NULL
);
5047 if (!NT_STATUS_IS_OK(status
)) {
5050 *blob
= data_blob_null
;
5051 return NT_STATUS_OK
;
5054 /*********************************************************
5055 Set an extended attribute utility fn.
5056 *********************************************************/
5058 static NTSTATUS
cli_set_ea(struct cli_state
*cli
, uint16_t setup_val
,
5059 uint8_t *param
, unsigned int param_len
,
5060 const char *ea_name
,
5061 const char *ea_val
, size_t ea_len
)
5064 unsigned int data_len
= 0;
5065 uint8_t *data
= NULL
;
5067 size_t ea_namelen
= strlen(ea_name
);
5070 SSVAL(setup
, 0, setup_val
);
5072 if (ea_namelen
== 0 && ea_len
== 0) {
5074 data
= talloc_array(talloc_tos(),
5078 return NT_STATUS_NO_MEMORY
;
5081 SIVAL(p
,0,data_len
);
5083 data_len
= 4 + 4 + ea_namelen
+ 1 + ea_len
;
5084 data
= talloc_array(talloc_tos(),
5088 return NT_STATUS_NO_MEMORY
;
5091 SIVAL(p
,0,data_len
);
5093 SCVAL(p
, 0, 0); /* EA flags. */
5094 SCVAL(p
, 1, ea_namelen
);
5095 SSVAL(p
, 2, ea_len
);
5096 memcpy(p
+4, ea_name
, ea_namelen
+1); /* Copy in the name. */
5097 memcpy(p
+4+ea_namelen
+1, ea_val
, ea_len
);
5101 * FIXME - if we want to do previous version path
5102 * processing on an EA set call we need to turn this
5103 * into calls to cli_trans_send()/cli_trans_recv()
5104 * with a temporary event context, as cli_trans_send()
5105 * have access to the additional_flags2 needed to
5106 * send @GMT- paths. JRA.
5109 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
, NULL
, -1, 0, 0,
5111 param
, param_len
, 2,
5114 NULL
, 0, NULL
, /* rsetup */
5115 NULL
, 0, NULL
, /* rparam */
5116 NULL
, 0, NULL
); /* rdata */
5121 /*********************************************************
5122 Set an extended attribute on a pathname.
5123 *********************************************************/
5125 NTSTATUS
cli_set_ea_path(struct cli_state
*cli
, const char *path
,
5126 const char *ea_name
, const char *ea_val
,
5129 unsigned int param_len
= 0;
5132 TALLOC_CTX
*frame
= NULL
;
5134 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
5135 return cli_smb2_set_ea_path(cli
,
5142 frame
= talloc_stackframe();
5144 param
= talloc_array(frame
, uint8_t, 6);
5146 status
= NT_STATUS_NO_MEMORY
;
5149 SSVAL(param
,0,SMB_INFO_SET_EA
);
5153 param
= trans2_bytes_push_str(param
, smbXcli_conn_use_unicode(cli
->conn
),
5154 path
, strlen(path
)+1,
5156 param_len
= talloc_get_size(param
);
5158 status
= cli_set_ea(cli
, TRANSACT2_SETPATHINFO
, param
, param_len
,
5159 ea_name
, ea_val
, ea_len
);
5167 /*********************************************************
5168 Set an extended attribute on an fnum.
5169 *********************************************************/
5171 NTSTATUS
cli_set_ea_fnum(struct cli_state
*cli
, uint16_t fnum
,
5172 const char *ea_name
, const char *ea_val
,
5177 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
5178 return cli_smb2_set_ea_fnum(cli
,
5185 memset(param
, 0, 6);
5186 SSVAL(param
,0,fnum
);
5187 SSVAL(param
,2,SMB_INFO_SET_EA
);
5189 return cli_set_ea(cli
, TRANSACT2_SETFILEINFO
, param
, 6,
5190 ea_name
, ea_val
, ea_len
);
5193 /*********************************************************
5194 Get an extended attribute list utility fn.
5195 *********************************************************/
5197 static bool parse_ea_blob(TALLOC_CTX
*ctx
, const uint8_t *rdata
,
5199 size_t *pnum_eas
, struct ea_struct
**pea_list
)
5201 struct ea_struct
*ea_list
= NULL
;
5206 if (rdata_len
< 4) {
5210 ea_size
= (size_t)IVAL(rdata
,0);
5211 if (ea_size
> rdata_len
) {
5216 /* No EA's present. */
5225 /* Validate the EA list and count it. */
5226 for (num_eas
= 0; ea_size
>= 4; num_eas
++) {
5227 unsigned int ea_namelen
= CVAL(p
,1);
5228 unsigned int ea_valuelen
= SVAL(p
,2);
5229 if (ea_namelen
== 0) {
5232 if (4 + ea_namelen
+ 1 + ea_valuelen
> ea_size
) {
5235 ea_size
-= 4 + ea_namelen
+ 1 + ea_valuelen
;
5236 p
+= 4 + ea_namelen
+ 1 + ea_valuelen
;
5245 *pnum_eas
= num_eas
;
5247 /* Caller only wants number of EA's. */
5251 ea_list
= talloc_array(ctx
, struct ea_struct
, num_eas
);
5256 ea_size
= (size_t)IVAL(rdata
,0);
5259 for (num_eas
= 0; num_eas
< *pnum_eas
; num_eas
++ ) {
5260 struct ea_struct
*ea
= &ea_list
[num_eas
];
5261 fstring unix_ea_name
;
5262 unsigned int ea_namelen
= CVAL(p
,1);
5263 unsigned int ea_valuelen
= SVAL(p
,2);
5265 ea
->flags
= CVAL(p
,0);
5266 unix_ea_name
[0] = '\0';
5267 pull_ascii(unix_ea_name
, p
+ 4, sizeof(unix_ea_name
), rdata_len
- PTR_DIFF(p
+4, rdata
), STR_TERMINATE
);
5268 ea
->name
= talloc_strdup(ea_list
, unix_ea_name
);
5272 /* Ensure the value is null terminated (in case it's a string). */
5273 ea
->value
= data_blob_talloc(ea_list
, NULL
, ea_valuelen
+ 1);
5274 if (!ea
->value
.data
) {
5278 memcpy(ea
->value
.data
, p
+4+ea_namelen
+1, ea_valuelen
);
5280 ea
->value
.data
[ea_valuelen
] = 0;
5282 p
+= 4 + ea_namelen
+ 1 + ea_valuelen
;
5285 *pea_list
= ea_list
;
5289 TALLOC_FREE(ea_list
);
5293 /*********************************************************
5294 Get an extended attribute list from a pathname.
5295 *********************************************************/
5297 struct cli_get_ea_list_path_state
{
5302 static void cli_get_ea_list_path_done(struct tevent_req
*subreq
);
5304 struct tevent_req
*cli_get_ea_list_path_send(TALLOC_CTX
*mem_ctx
,
5305 struct tevent_context
*ev
,
5306 struct cli_state
*cli
,
5309 struct tevent_req
*req
, *subreq
;
5310 struct cli_get_ea_list_path_state
*state
;
5312 req
= tevent_req_create(mem_ctx
, &state
,
5313 struct cli_get_ea_list_path_state
);
5317 subreq
= cli_qpathinfo_send(state
, ev
, cli
, fname
,
5318 SMB_INFO_QUERY_ALL_EAS
, 4,
5320 if (tevent_req_nomem(subreq
, req
)) {
5321 return tevent_req_post(req
, ev
);
5323 tevent_req_set_callback(subreq
, cli_get_ea_list_path_done
, req
);
5327 static void cli_get_ea_list_path_done(struct tevent_req
*subreq
)
5329 struct tevent_req
*req
= tevent_req_callback_data(
5330 subreq
, struct tevent_req
);
5331 struct cli_get_ea_list_path_state
*state
= tevent_req_data(
5332 req
, struct cli_get_ea_list_path_state
);
5335 status
= cli_qpathinfo_recv(subreq
, state
, &state
->data
,
5337 TALLOC_FREE(subreq
);
5338 if (tevent_req_nterror(req
, status
)) {
5341 tevent_req_done(req
);
5344 NTSTATUS
cli_get_ea_list_path_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
5345 size_t *pnum_eas
, struct ea_struct
**peas
)
5347 struct cli_get_ea_list_path_state
*state
= tevent_req_data(
5348 req
, struct cli_get_ea_list_path_state
);
5351 if (tevent_req_is_nterror(req
, &status
)) {
5354 if (!parse_ea_blob(mem_ctx
, state
->data
, state
->num_data
,
5356 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
5358 return NT_STATUS_OK
;
5361 NTSTATUS
cli_get_ea_list_path(struct cli_state
*cli
, const char *path
,
5364 struct ea_struct
**pea_list
)
5366 TALLOC_CTX
*frame
= NULL
;
5367 struct tevent_context
*ev
= NULL
;
5368 struct tevent_req
*req
= NULL
;
5369 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
5371 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
5372 return cli_smb2_get_ea_list_path(cli
,
5379 frame
= talloc_stackframe();
5381 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
5383 * Can't use sync call while an async call is in flight
5385 status
= NT_STATUS_INVALID_PARAMETER
;
5388 ev
= samba_tevent_context_init(frame
);
5392 req
= cli_get_ea_list_path_send(frame
, ev
, cli
, path
);
5396 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5399 status
= cli_get_ea_list_path_recv(req
, ctx
, pnum_eas
, pea_list
);
5405 /****************************************************************************
5406 Convert open "flags" arg to uint32_t on wire.
5407 ****************************************************************************/
5409 static uint32_t open_flags_to_wire(int flags
)
5411 int open_mode
= flags
& O_ACCMODE
;
5414 switch (open_mode
) {
5416 ret
|= SMB_O_WRONLY
;
5423 ret
|= SMB_O_RDONLY
;
5427 if (flags
& O_CREAT
) {
5430 if (flags
& O_EXCL
) {
5433 if (flags
& O_TRUNC
) {
5437 if (flags
& O_SYNC
) {
5441 if (flags
& O_APPEND
) {
5442 ret
|= SMB_O_APPEND
;
5444 #if defined(O_DIRECT)
5445 if (flags
& O_DIRECT
) {
5446 ret
|= SMB_O_DIRECT
;
5449 #if defined(O_DIRECTORY)
5450 if (flags
& O_DIRECTORY
) {
5451 ret
|= SMB_O_DIRECTORY
;
5457 /****************************************************************************
5458 Open a file - POSIX semantics. Returns fnum. Doesn't request oplock.
5459 ****************************************************************************/
5461 struct cli_posix_open_internal_state
{
5465 uint16_t fnum
; /* Out */
5468 static void cli_posix_open_internal_done(struct tevent_req
*subreq
);
5470 static struct tevent_req
*cli_posix_open_internal_send(TALLOC_CTX
*mem_ctx
,
5471 struct tevent_context
*ev
,
5472 struct cli_state
*cli
,
5474 uint32_t wire_flags
,
5477 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
5478 struct cli_posix_open_internal_state
*state
= NULL
;
5480 req
= tevent_req_create(
5481 mem_ctx
, &state
, struct cli_posix_open_internal_state
);
5486 /* Setup setup word. */
5487 SSVAL(&state
->setup
, 0, TRANSACT2_SETPATHINFO
);
5489 /* Setup param array. */
5490 state
->param
= talloc_zero_array(state
, uint8_t, 6);
5491 if (tevent_req_nomem(state
->param
, req
)) {
5492 return tevent_req_post(req
, ev
);
5494 SSVAL(state
->param
, 0, SMB_POSIX_PATH_OPEN
);
5496 state
->param
= trans2_bytes_push_str(
5498 smbXcli_conn_use_unicode(cli
->conn
),
5503 if (tevent_req_nomem(state
->param
, req
)) {
5504 return tevent_req_post(req
, ev
);
5507 SIVAL(state
->data
,0,0); /* No oplock. */
5508 SIVAL(state
->data
,4,wire_flags
);
5509 SIVAL(state
->data
,8,unix_perms_to_wire(mode
));
5510 SIVAL(state
->data
,12,0); /* Top bits of perms currently undefined. */
5511 SSVAL(state
->data
,16,SMB_NO_INFO_LEVEL_RETURNED
); /* No info level returned. */
5513 subreq
= cli_trans_send(state
, /* mem ctx. */
5514 ev
, /* event ctx. */
5515 cli
, /* cli_state. */
5516 0, /* additional_flags2 */
5517 SMBtrans2
, /* cmd. */
5518 NULL
, /* pipe name. */
5522 &state
->setup
, /* setup. */
5523 1, /* num setup uint16_t words. */
5524 0, /* max returned setup. */
5525 state
->param
, /* param. */
5526 talloc_get_size(state
->param
),/* num param. */
5527 2, /* max returned param. */
5528 state
->data
, /* data. */
5530 12); /* max returned data. */
5532 if (tevent_req_nomem(subreq
, req
)) {
5533 return tevent_req_post(req
, ev
);
5535 tevent_req_set_callback(subreq
, cli_posix_open_internal_done
, req
);
5539 static void cli_posix_open_internal_done(struct tevent_req
*subreq
)
5541 struct tevent_req
*req
= tevent_req_callback_data(
5542 subreq
, struct tevent_req
);
5543 struct cli_posix_open_internal_state
*state
= tevent_req_data(
5544 req
, struct cli_posix_open_internal_state
);
5549 status
= cli_trans_recv(
5562 TALLOC_FREE(subreq
);
5563 if (tevent_req_nterror(req
, status
)) {
5566 state
->fnum
= SVAL(data
,2);
5567 tevent_req_done(req
);
5570 static NTSTATUS
cli_posix_open_internal_recv(struct tevent_req
*req
,
5573 struct cli_posix_open_internal_state
*state
= tevent_req_data(
5574 req
, struct cli_posix_open_internal_state
);
5577 if (tevent_req_is_nterror(req
, &status
)) {
5580 *pfnum
= state
->fnum
;
5581 return NT_STATUS_OK
;
5584 struct cli_posix_open_state
{
5588 static void cli_posix_open_done(struct tevent_req
*subreq
);
5590 struct tevent_req
*cli_posix_open_send(TALLOC_CTX
*mem_ctx
,
5591 struct tevent_context
*ev
,
5592 struct cli_state
*cli
,
5597 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
5598 struct cli_posix_open_state
*state
= NULL
;
5599 uint32_t wire_flags
;
5601 req
= tevent_req_create(mem_ctx
, &state
,
5602 struct cli_posix_open_state
);
5607 wire_flags
= open_flags_to_wire(flags
);
5609 subreq
= cli_posix_open_internal_send(
5610 mem_ctx
, ev
, cli
, fname
, wire_flags
, mode
);
5611 if (tevent_req_nomem(subreq
, req
)) {
5612 return tevent_req_post(req
, ev
);
5614 tevent_req_set_callback(subreq
, cli_posix_open_done
, req
);
5618 static void cli_posix_open_done(struct tevent_req
*subreq
)
5620 struct tevent_req
*req
= tevent_req_callback_data(
5621 subreq
, struct tevent_req
);
5622 struct cli_posix_open_state
*state
= tevent_req_data(
5623 req
, struct cli_posix_open_state
);
5626 status
= cli_posix_open_internal_recv(subreq
, &state
->fnum
);
5627 tevent_req_simple_finish_ntstatus(subreq
, status
);
5630 NTSTATUS
cli_posix_open_recv(struct tevent_req
*req
, uint16_t *pfnum
)
5632 struct cli_posix_open_state
*state
= tevent_req_data(
5633 req
, struct cli_posix_open_state
);
5636 if (tevent_req_is_nterror(req
, &status
)) {
5639 *pfnum
= state
->fnum
;
5640 return NT_STATUS_OK
;
5643 /****************************************************************************
5644 Open - POSIX semantics. Doesn't request oplock.
5645 ****************************************************************************/
5647 NTSTATUS
cli_posix_open(struct cli_state
*cli
, const char *fname
,
5648 int flags
, mode_t mode
, uint16_t *pfnum
)
5651 TALLOC_CTX
*frame
= talloc_stackframe();
5652 struct tevent_context
*ev
= NULL
;
5653 struct tevent_req
*req
= NULL
;
5654 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
5656 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
5658 * Can't use sync call while an async call is in flight
5660 status
= NT_STATUS_INVALID_PARAMETER
;
5663 ev
= samba_tevent_context_init(frame
);
5667 req
= cli_posix_open_send(
5668 frame
, ev
, cli
, fname
, flags
, mode
);
5672 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5675 status
= cli_posix_open_recv(req
, pfnum
);
5681 struct cli_posix_mkdir_state
{
5682 struct tevent_context
*ev
;
5683 struct cli_state
*cli
;
5686 static void cli_posix_mkdir_done(struct tevent_req
*subreq
);
5688 struct tevent_req
*cli_posix_mkdir_send(TALLOC_CTX
*mem_ctx
,
5689 struct tevent_context
*ev
,
5690 struct cli_state
*cli
,
5694 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
5695 struct cli_posix_mkdir_state
*state
= NULL
;
5696 uint32_t wire_flags
;
5698 req
= tevent_req_create(
5699 mem_ctx
, &state
, struct cli_posix_mkdir_state
);
5706 wire_flags
= SMB_O_CREAT
| SMB_O_DIRECTORY
;
5708 subreq
= cli_posix_open_internal_send(
5709 mem_ctx
, ev
, cli
, fname
, wire_flags
, mode
);
5710 if (tevent_req_nomem(subreq
, req
)) {
5711 return tevent_req_post(req
, ev
);
5713 tevent_req_set_callback(subreq
, cli_posix_mkdir_done
, req
);
5717 static void cli_posix_mkdir_done(struct tevent_req
*subreq
)
5719 struct tevent_req
*req
= tevent_req_callback_data(
5720 subreq
, struct tevent_req
);
5724 status
= cli_posix_open_internal_recv(subreq
, &fnum
);
5725 TALLOC_FREE(subreq
);
5726 if (tevent_req_nterror(req
, status
)) {
5729 tevent_req_done(req
);
5732 NTSTATUS
cli_posix_mkdir_recv(struct tevent_req
*req
)
5734 return tevent_req_simple_recv_ntstatus(req
);
5737 NTSTATUS
cli_posix_mkdir(struct cli_state
*cli
, const char *fname
, mode_t mode
)
5739 TALLOC_CTX
*frame
= talloc_stackframe();
5740 struct tevent_context
*ev
= NULL
;
5741 struct tevent_req
*req
= NULL
;
5742 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
5744 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
5746 * Can't use sync call while an async call is in flight
5748 status
= NT_STATUS_INVALID_PARAMETER
;
5752 ev
= samba_tevent_context_init(frame
);
5756 req
= cli_posix_mkdir_send(
5757 frame
, ev
, cli
, fname
, mode
);
5761 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5764 status
= cli_posix_mkdir_recv(req
);
5770 /****************************************************************************
5771 unlink or rmdir - POSIX semantics.
5772 ****************************************************************************/
5774 struct cli_posix_unlink_internal_state
{
5778 static void cli_posix_unlink_internal_done(struct tevent_req
*subreq
);
5780 static struct tevent_req
*cli_posix_unlink_internal_send(TALLOC_CTX
*mem_ctx
,
5781 struct tevent_context
*ev
,
5782 struct cli_state
*cli
,
5786 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
5787 struct cli_posix_unlink_internal_state
*state
= NULL
;
5789 req
= tevent_req_create(mem_ctx
, &state
,
5790 struct cli_posix_unlink_internal_state
);
5795 /* Setup data word. */
5796 SSVAL(state
->data
, 0, level
);
5798 subreq
= cli_setpathinfo_send(state
, ev
, cli
,
5799 SMB_POSIX_PATH_UNLINK
,
5801 state
->data
, sizeof(state
->data
));
5802 if (tevent_req_nomem(subreq
, req
)) {
5803 return tevent_req_post(req
, ev
);
5805 tevent_req_set_callback(subreq
, cli_posix_unlink_internal_done
, req
);
5809 static void cli_posix_unlink_internal_done(struct tevent_req
*subreq
)
5811 NTSTATUS status
= cli_setpathinfo_recv(subreq
);
5812 tevent_req_simple_finish_ntstatus(subreq
, status
);
5815 static NTSTATUS
cli_posix_unlink_internal_recv(struct tevent_req
*req
)
5817 return tevent_req_simple_recv_ntstatus(req
);
5820 struct cli_posix_unlink_state
{
5824 static void cli_posix_unlink_done(struct tevent_req
*subreq
);
5826 struct tevent_req
*cli_posix_unlink_send(TALLOC_CTX
*mem_ctx
,
5827 struct tevent_context
*ev
,
5828 struct cli_state
*cli
,
5831 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
5832 struct cli_posix_unlink_state
*state
;
5834 req
= tevent_req_create(
5835 mem_ctx
, &state
, struct cli_posix_unlink_state
);
5839 subreq
= cli_posix_unlink_internal_send(
5840 mem_ctx
, ev
, cli
, fname
, SMB_POSIX_UNLINK_FILE_TARGET
);
5841 if (tevent_req_nomem(subreq
, req
)) {
5842 return tevent_req_post(req
, ev
);
5844 tevent_req_set_callback(subreq
, cli_posix_unlink_done
, req
);
5848 static void cli_posix_unlink_done(struct tevent_req
*subreq
)
5850 NTSTATUS status
= cli_posix_unlink_internal_recv(subreq
);
5851 tevent_req_simple_finish_ntstatus(subreq
, status
);
5854 NTSTATUS
cli_posix_unlink_recv(struct tevent_req
*req
)
5856 return tevent_req_simple_recv_ntstatus(req
);
5859 /****************************************************************************
5860 unlink - POSIX semantics.
5861 ****************************************************************************/
5863 NTSTATUS
cli_posix_unlink(struct cli_state
*cli
, const char *fname
)
5865 TALLOC_CTX
*frame
= talloc_stackframe();
5866 struct tevent_context
*ev
= NULL
;
5867 struct tevent_req
*req
= NULL
;
5868 NTSTATUS status
= NT_STATUS_OK
;
5870 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
5872 * Can't use sync call while an async call is in flight
5874 status
= NT_STATUS_INVALID_PARAMETER
;
5878 ev
= samba_tevent_context_init(frame
);
5880 status
= NT_STATUS_NO_MEMORY
;
5884 req
= cli_posix_unlink_send(frame
,
5889 status
= NT_STATUS_NO_MEMORY
;
5893 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5897 status
= cli_posix_unlink_recv(req
);
5904 /****************************************************************************
5905 rmdir - POSIX semantics.
5906 ****************************************************************************/
5908 struct cli_posix_rmdir_state
{
5912 static void cli_posix_rmdir_done(struct tevent_req
*subreq
);
5914 struct tevent_req
*cli_posix_rmdir_send(TALLOC_CTX
*mem_ctx
,
5915 struct tevent_context
*ev
,
5916 struct cli_state
*cli
,
5919 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
5920 struct cli_posix_rmdir_state
*state
;
5922 req
= tevent_req_create(mem_ctx
, &state
, struct cli_posix_rmdir_state
);
5926 subreq
= cli_posix_unlink_internal_send(
5927 mem_ctx
, ev
, cli
, fname
, SMB_POSIX_UNLINK_DIRECTORY_TARGET
);
5928 if (tevent_req_nomem(subreq
, req
)) {
5929 return tevent_req_post(req
, ev
);
5931 tevent_req_set_callback(subreq
, cli_posix_rmdir_done
, req
);
5935 static void cli_posix_rmdir_done(struct tevent_req
*subreq
)
5937 NTSTATUS status
= cli_posix_unlink_internal_recv(subreq
);
5938 tevent_req_simple_finish_ntstatus(subreq
, status
);
5941 NTSTATUS
cli_posix_rmdir_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
)
5943 return tevent_req_simple_recv_ntstatus(req
);
5946 NTSTATUS
cli_posix_rmdir(struct cli_state
*cli
, const char *fname
)
5948 TALLOC_CTX
*frame
= talloc_stackframe();
5949 struct tevent_context
*ev
= NULL
;
5950 struct tevent_req
*req
= NULL
;
5951 NTSTATUS status
= NT_STATUS_OK
;
5953 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
5955 * Can't use sync call while an async call is in flight
5957 status
= NT_STATUS_INVALID_PARAMETER
;
5961 ev
= samba_tevent_context_init(frame
);
5963 status
= NT_STATUS_NO_MEMORY
;
5967 req
= cli_posix_rmdir_send(frame
,
5972 status
= NT_STATUS_NO_MEMORY
;
5976 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5980 status
= cli_posix_rmdir_recv(req
, frame
);
5987 /****************************************************************************
5989 ****************************************************************************/
5991 struct cli_notify_state
{
5992 struct tevent_req
*subreq
;
5994 uint32_t num_changes
;
5995 struct notify_change
*changes
;
5998 static void cli_notify_done(struct tevent_req
*subreq
);
5999 static void cli_notify_done_smb2(struct tevent_req
*subreq
);
6000 static bool cli_notify_cancel(struct tevent_req
*req
);
6002 struct tevent_req
*cli_notify_send(TALLOC_CTX
*mem_ctx
,
6003 struct tevent_context
*ev
,
6004 struct cli_state
*cli
, uint16_t fnum
,
6005 uint32_t buffer_size
,
6006 uint32_t completion_filter
, bool recursive
)
6008 struct tevent_req
*req
;
6009 struct cli_notify_state
*state
;
6010 unsigned old_timeout
;
6012 req
= tevent_req_create(mem_ctx
, &state
, struct cli_notify_state
);
6017 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
6019 * Notifies should not time out
6021 old_timeout
= cli_set_timeout(cli
, 0);
6023 state
->subreq
= cli_smb2_notify_send(
6032 cli_set_timeout(cli
, old_timeout
);
6034 if (tevent_req_nomem(state
->subreq
, req
)) {
6035 return tevent_req_post(req
, ev
);
6037 tevent_req_set_callback(
6038 state
->subreq
, cli_notify_done_smb2
, req
);
6042 SIVAL(state
->setup
, 0, completion_filter
);
6043 SSVAL(state
->setup
, 4, fnum
);
6044 SSVAL(state
->setup
, 6, recursive
);
6047 * Notifies should not time out
6049 old_timeout
= cli_set_timeout(cli
, 0);
6051 state
->subreq
= cli_trans_send(
6052 state
, /* mem ctx. */
6053 ev
, /* event ctx. */
6054 cli
, /* cli_state. */
6055 0, /* additional_flags2 */
6056 SMBnttrans
, /* cmd. */
6057 NULL
, /* pipe name. */
6059 NT_TRANSACT_NOTIFY_CHANGE
, /* function. */
6061 (uint16_t *)state
->setup
, /* setup. */
6062 4, /* num setup uint16_t words. */
6063 0, /* max returned setup. */
6066 buffer_size
, /* max returned param. */
6069 0); /* max returned data. */
6071 cli_set_timeout(cli
, old_timeout
);
6073 if (tevent_req_nomem(state
->subreq
, req
)) {
6074 return tevent_req_post(req
, ev
);
6076 tevent_req_set_callback(state
->subreq
, cli_notify_done
, req
);
6078 tevent_req_set_cancel_fn(req
, cli_notify_cancel
);
6082 static bool cli_notify_cancel(struct tevent_req
*req
)
6084 struct cli_notify_state
*state
= tevent_req_data(
6085 req
, struct cli_notify_state
);
6088 ok
= tevent_req_cancel(state
->subreq
);
6092 static void cli_notify_done(struct tevent_req
*subreq
)
6094 struct tevent_req
*req
= tevent_req_callback_data(
6095 subreq
, struct tevent_req
);
6096 struct cli_notify_state
*state
= tevent_req_data(
6097 req
, struct cli_notify_state
);
6100 uint32_t i
, ofs
, num_params
;
6103 status
= cli_trans_recv(subreq
, talloc_tos(), &flags2
, NULL
, 0, NULL
,
6104 ¶ms
, 0, &num_params
, NULL
, 0, NULL
);
6105 TALLOC_FREE(subreq
);
6106 state
->subreq
= NULL
;
6107 if (tevent_req_nterror(req
, status
)) {
6108 DEBUG(10, ("cli_trans_recv returned %s\n", nt_errstr(status
)));
6112 state
->num_changes
= 0;
6115 while (num_params
- ofs
> 12) {
6116 uint32_t next
= IVAL(params
, ofs
);
6117 state
->num_changes
+= 1;
6119 if ((next
== 0) || (ofs
+next
>= num_params
)) {
6125 state
->changes
= talloc_array(state
, struct notify_change
,
6126 state
->num_changes
);
6127 if (tevent_req_nomem(state
->changes
, req
)) {
6128 TALLOC_FREE(params
);
6134 for (i
=0; i
<state
->num_changes
; i
++) {
6135 uint32_t next
= IVAL(params
, ofs
);
6136 uint32_t len
= IVAL(params
, ofs
+8);
6140 if (trans_oob(num_params
, ofs
+ 12, len
)) {
6141 TALLOC_FREE(params
);
6143 req
, NT_STATUS_INVALID_NETWORK_RESPONSE
);
6147 state
->changes
[i
].action
= IVAL(params
, ofs
+4);
6148 ret
= clistr_pull_talloc(state
->changes
, (char *)params
, flags2
,
6149 &name
, params
+ofs
+12, len
,
6150 STR_TERMINATE
|STR_UNICODE
);
6152 TALLOC_FREE(params
);
6153 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
6156 state
->changes
[i
].name
= name
;
6160 TALLOC_FREE(params
);
6161 tevent_req_done(req
);
6164 static void cli_notify_done_smb2(struct tevent_req
*subreq
)
6166 struct tevent_req
*req
= tevent_req_callback_data(
6167 subreq
, struct tevent_req
);
6168 struct cli_notify_state
*state
= tevent_req_data(
6169 req
, struct cli_notify_state
);
6172 status
= cli_smb2_notify_recv(
6176 &state
->num_changes
);
6177 TALLOC_FREE(subreq
);
6178 if (tevent_req_nterror(req
, status
)) {
6181 tevent_req_done(req
);
6184 NTSTATUS
cli_notify_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
6185 uint32_t *pnum_changes
,
6186 struct notify_change
**pchanges
)
6188 struct cli_notify_state
*state
= tevent_req_data(
6189 req
, struct cli_notify_state
);
6192 if (tevent_req_is_nterror(req
, &status
)) {
6196 *pnum_changes
= state
->num_changes
;
6197 *pchanges
= talloc_move(mem_ctx
, &state
->changes
);
6198 return NT_STATUS_OK
;
6201 NTSTATUS
cli_notify(struct cli_state
*cli
, uint16_t fnum
, uint32_t buffer_size
,
6202 uint32_t completion_filter
, bool recursive
,
6203 TALLOC_CTX
*mem_ctx
, uint32_t *pnum_changes
,
6204 struct notify_change
**pchanges
)
6207 struct tevent_context
*ev
;
6208 struct tevent_req
*req
;
6209 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
6211 frame
= talloc_stackframe();
6213 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
6215 * Can't use sync call while an async call is in flight
6217 status
= NT_STATUS_INVALID_PARAMETER
;
6220 ev
= samba_tevent_context_init(frame
);
6224 req
= cli_notify_send(ev
, ev
, cli
, fnum
, buffer_size
,
6225 completion_filter
, recursive
);
6229 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
6232 status
= cli_notify_recv(req
, mem_ctx
, pnum_changes
, pchanges
);
6238 struct cli_qpathinfo_state
{
6247 static void cli_qpathinfo_done(struct tevent_req
*subreq
);
6249 struct tevent_req
*cli_qpathinfo_send(TALLOC_CTX
*mem_ctx
,
6250 struct tevent_context
*ev
,
6251 struct cli_state
*cli
, const char *fname
,
6252 uint16_t level
, uint32_t min_rdata
,
6255 struct tevent_req
*req
, *subreq
;
6256 struct cli_qpathinfo_state
*state
;
6257 uint16_t additional_flags2
= 0;
6259 req
= tevent_req_create(mem_ctx
, &state
, struct cli_qpathinfo_state
);
6263 state
->min_rdata
= min_rdata
;
6264 SSVAL(state
->setup
, 0, TRANSACT2_QPATHINFO
);
6266 state
->param
= talloc_zero_array(state
, uint8_t, 6);
6267 if (tevent_req_nomem(state
->param
, req
)) {
6268 return tevent_req_post(req
, ev
);
6270 SSVAL(state
->param
, 0, level
);
6271 state
->param
= trans2_bytes_push_str(
6272 state
->param
, smbXcli_conn_use_unicode(cli
->conn
), fname
, strlen(fname
)+1, NULL
);
6273 if (tevent_req_nomem(state
->param
, req
)) {
6274 return tevent_req_post(req
, ev
);
6277 if (clistr_is_previous_version_path(fname
, NULL
, NULL
, NULL
) &&
6278 !INFO_LEVEL_IS_UNIX(level
)) {
6279 additional_flags2
= FLAGS2_REPARSE_PATH
;
6282 subreq
= cli_trans_send(
6283 state
, /* mem ctx. */
6284 ev
, /* event ctx. */
6285 cli
, /* cli_state. */
6286 additional_flags2
, /* additional_flags2 */
6287 SMBtrans2
, /* cmd. */
6288 NULL
, /* pipe name. */
6292 state
->setup
, /* setup. */
6293 1, /* num setup uint16_t words. */
6294 0, /* max returned setup. */
6295 state
->param
, /* param. */
6296 talloc_get_size(state
->param
), /* num param. */
6297 2, /* max returned param. */
6300 max_rdata
); /* max returned data. */
6302 if (tevent_req_nomem(subreq
, req
)) {
6303 return tevent_req_post(req
, ev
);
6305 tevent_req_set_callback(subreq
, cli_qpathinfo_done
, req
);
6309 static void cli_qpathinfo_done(struct tevent_req
*subreq
)
6311 struct tevent_req
*req
= tevent_req_callback_data(
6312 subreq
, struct tevent_req
);
6313 struct cli_qpathinfo_state
*state
= tevent_req_data(
6314 req
, struct cli_qpathinfo_state
);
6317 status
= cli_trans_recv(subreq
, state
, NULL
, NULL
, 0, NULL
,
6319 &state
->rdata
, state
->min_rdata
,
6321 if (tevent_req_nterror(req
, status
)) {
6324 tevent_req_done(req
);
6327 NTSTATUS
cli_qpathinfo_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
6328 uint8_t **rdata
, uint32_t *num_rdata
)
6330 struct cli_qpathinfo_state
*state
= tevent_req_data(
6331 req
, struct cli_qpathinfo_state
);
6334 if (tevent_req_is_nterror(req
, &status
)) {
6337 if (rdata
!= NULL
) {
6338 *rdata
= talloc_move(mem_ctx
, &state
->rdata
);
6340 TALLOC_FREE(state
->rdata
);
6342 if (num_rdata
!= NULL
) {
6343 *num_rdata
= state
->num_rdata
;
6345 return NT_STATUS_OK
;
6348 NTSTATUS
cli_qpathinfo(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
,
6349 const char *fname
, uint16_t level
, uint32_t min_rdata
,
6351 uint8_t **rdata
, uint32_t *num_rdata
)
6353 TALLOC_CTX
*frame
= talloc_stackframe();
6354 struct tevent_context
*ev
;
6355 struct tevent_req
*req
;
6356 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
6358 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
6360 * Can't use sync call while an async call is in flight
6362 status
= NT_STATUS_INVALID_PARAMETER
;
6365 ev
= samba_tevent_context_init(frame
);
6369 req
= cli_qpathinfo_send(frame
, ev
, cli
, fname
, level
, min_rdata
,
6374 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
6377 status
= cli_qpathinfo_recv(req
, mem_ctx
, rdata
, num_rdata
);
6383 struct cli_qfileinfo_state
{
6387 uint16_t recv_flags2
;
6393 static void cli_qfileinfo_done(struct tevent_req
*subreq
);
6395 struct tevent_req
*cli_qfileinfo_send(TALLOC_CTX
*mem_ctx
,
6396 struct tevent_context
*ev
,
6397 struct cli_state
*cli
, uint16_t fnum
,
6398 uint16_t level
, uint32_t min_rdata
,
6401 struct tevent_req
*req
, *subreq
;
6402 struct cli_qfileinfo_state
*state
;
6404 req
= tevent_req_create(mem_ctx
, &state
, struct cli_qfileinfo_state
);
6408 state
->min_rdata
= min_rdata
;
6409 SSVAL(state
->param
, 0, fnum
);
6410 SSVAL(state
->param
, 2, level
);
6411 SSVAL(state
->setup
, 0, TRANSACT2_QFILEINFO
);
6413 subreq
= cli_trans_send(
6414 state
, /* mem ctx. */
6415 ev
, /* event ctx. */
6416 cli
, /* cli_state. */
6417 0, /* additional_flags2 */
6418 SMBtrans2
, /* cmd. */
6419 NULL
, /* pipe name. */
6423 state
->setup
, /* setup. */
6424 1, /* num setup uint16_t words. */
6425 0, /* max returned setup. */
6426 state
->param
, /* param. */
6427 sizeof(state
->param
), /* num param. */
6428 2, /* max returned param. */
6431 max_rdata
); /* max returned data. */
6433 if (tevent_req_nomem(subreq
, req
)) {
6434 return tevent_req_post(req
, ev
);
6436 tevent_req_set_callback(subreq
, cli_qfileinfo_done
, req
);
6440 static void cli_qfileinfo_done(struct tevent_req
*subreq
)
6442 struct tevent_req
*req
= tevent_req_callback_data(
6443 subreq
, struct tevent_req
);
6444 struct cli_qfileinfo_state
*state
= tevent_req_data(
6445 req
, struct cli_qfileinfo_state
);
6448 status
= cli_trans_recv(subreq
, state
,
6449 &state
->recv_flags2
,
6452 &state
->rdata
, state
->min_rdata
,
6454 if (tevent_req_nterror(req
, status
)) {
6457 tevent_req_done(req
);
6460 NTSTATUS
cli_qfileinfo_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
6461 uint16_t *recv_flags2
,
6462 uint8_t **rdata
, uint32_t *num_rdata
)
6464 struct cli_qfileinfo_state
*state
= tevent_req_data(
6465 req
, struct cli_qfileinfo_state
);
6468 if (tevent_req_is_nterror(req
, &status
)) {
6472 if (recv_flags2
!= NULL
) {
6473 *recv_flags2
= state
->recv_flags2
;
6475 if (rdata
!= NULL
) {
6476 *rdata
= talloc_move(mem_ctx
, &state
->rdata
);
6478 TALLOC_FREE(state
->rdata
);
6480 if (num_rdata
!= NULL
) {
6481 *num_rdata
= state
->num_rdata
;
6483 return NT_STATUS_OK
;
6486 NTSTATUS
cli_qfileinfo(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
,
6487 uint16_t fnum
, uint16_t level
, uint32_t min_rdata
,
6488 uint32_t max_rdata
, uint16_t *recv_flags2
,
6489 uint8_t **rdata
, uint32_t *num_rdata
)
6491 TALLOC_CTX
*frame
= talloc_stackframe();
6492 struct tevent_context
*ev
;
6493 struct tevent_req
*req
;
6494 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
6496 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
6498 * Can't use sync call while an async call is in flight
6500 status
= NT_STATUS_INVALID_PARAMETER
;
6503 ev
= samba_tevent_context_init(frame
);
6507 req
= cli_qfileinfo_send(frame
, ev
, cli
, fnum
, level
, min_rdata
,
6512 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
6515 status
= cli_qfileinfo_recv(req
, mem_ctx
, recv_flags2
, rdata
, num_rdata
);
6521 struct cli_flush_state
{
6525 static void cli_flush_done(struct tevent_req
*subreq
);
6527 struct tevent_req
*cli_flush_send(TALLOC_CTX
*mem_ctx
,
6528 struct tevent_context
*ev
,
6529 struct cli_state
*cli
,
6532 struct tevent_req
*req
, *subreq
;
6533 struct cli_flush_state
*state
;
6535 req
= tevent_req_create(mem_ctx
, &state
, struct cli_flush_state
);
6539 SSVAL(state
->vwv
+ 0, 0, fnum
);
6541 subreq
= cli_smb_send(state
, ev
, cli
, SMBflush
, 0, 0, 1, state
->vwv
,
6543 if (tevent_req_nomem(subreq
, req
)) {
6544 return tevent_req_post(req
, ev
);
6546 tevent_req_set_callback(subreq
, cli_flush_done
, req
);
6550 static void cli_flush_done(struct tevent_req
*subreq
)
6552 struct tevent_req
*req
= tevent_req_callback_data(
6553 subreq
, struct tevent_req
);
6556 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
6557 TALLOC_FREE(subreq
);
6558 if (tevent_req_nterror(req
, status
)) {
6561 tevent_req_done(req
);
6564 NTSTATUS
cli_flush_recv(struct tevent_req
*req
)
6566 return tevent_req_simple_recv_ntstatus(req
);
6569 NTSTATUS
cli_flush(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
, uint16_t fnum
)
6571 TALLOC_CTX
*frame
= talloc_stackframe();
6572 struct tevent_context
*ev
;
6573 struct tevent_req
*req
;
6574 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
6576 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
6578 * Can't use sync call while an async call is in flight
6580 status
= NT_STATUS_INVALID_PARAMETER
;
6583 ev
= samba_tevent_context_init(frame
);
6587 req
= cli_flush_send(frame
, ev
, cli
, fnum
);
6591 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
6594 status
= cli_flush_recv(req
);
6600 struct cli_shadow_copy_data_state
{
6607 static void cli_shadow_copy_data_done(struct tevent_req
*subreq
);
6609 struct tevent_req
*cli_shadow_copy_data_send(TALLOC_CTX
*mem_ctx
,
6610 struct tevent_context
*ev
,
6611 struct cli_state
*cli
,
6615 struct tevent_req
*req
, *subreq
;
6616 struct cli_shadow_copy_data_state
*state
;
6619 req
= tevent_req_create(mem_ctx
, &state
,
6620 struct cli_shadow_copy_data_state
);
6624 state
->get_names
= get_names
;
6625 ret_size
= get_names
? CLI_BUFFER_SIZE
: 16;
6627 SIVAL(state
->setup
+ 0, 0, FSCTL_GET_SHADOW_COPY_DATA
);
6628 SSVAL(state
->setup
+ 2, 0, fnum
);
6629 SCVAL(state
->setup
+ 3, 0, 1); /* isFsctl */
6630 SCVAL(state
->setup
+ 3, 1, 0); /* compfilter, isFlags (WSSP) */
6632 subreq
= cli_trans_send(
6633 state
, ev
, cli
, 0, SMBnttrans
, NULL
, 0, NT_TRANSACT_IOCTL
, 0,
6634 state
->setup
, ARRAY_SIZE(state
->setup
),
6635 ARRAY_SIZE(state
->setup
),
6638 if (tevent_req_nomem(subreq
, req
)) {
6639 return tevent_req_post(req
, ev
);
6641 tevent_req_set_callback(subreq
, cli_shadow_copy_data_done
, req
);
6645 static void cli_shadow_copy_data_done(struct tevent_req
*subreq
)
6647 struct tevent_req
*req
= tevent_req_callback_data(
6648 subreq
, struct tevent_req
);
6649 struct cli_shadow_copy_data_state
*state
= tevent_req_data(
6650 req
, struct cli_shadow_copy_data_state
);
6653 status
= cli_trans_recv(subreq
, state
, NULL
,
6654 NULL
, 0, NULL
, /* setup */
6655 NULL
, 0, NULL
, /* param */
6656 &state
->data
, 12, &state
->num_data
);
6657 TALLOC_FREE(subreq
);
6658 if (tevent_req_nterror(req
, status
)) {
6661 tevent_req_done(req
);
6664 NTSTATUS
cli_shadow_copy_data_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
6665 char ***pnames
, int *pnum_names
)
6667 struct cli_shadow_copy_data_state
*state
= tevent_req_data(
6668 req
, struct cli_shadow_copy_data_state
);
6669 char **names
= NULL
;
6670 uint32_t i
, num_names
;
6672 uint8_t *endp
= NULL
;
6675 if (tevent_req_is_nterror(req
, &status
)) {
6679 if (state
->num_data
< 16) {
6680 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
6683 num_names
= IVAL(state
->data
, 4);
6684 dlength
= IVAL(state
->data
, 8);
6686 if (num_names
> 0x7FFFFFFF) {
6687 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
6690 if (!state
->get_names
) {
6691 *pnum_names
= (int)num_names
;
6692 return NT_STATUS_OK
;
6695 if (dlength
+ 12 < 12) {
6696 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
6698 if (dlength
+ 12 > state
->num_data
) {
6699 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
6701 if (state
->num_data
+ (2 * sizeof(SHADOW_COPY_LABEL
)) <
6703 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
6706 names
= talloc_array(mem_ctx
, char *, num_names
);
6707 if (names
== NULL
) {
6708 return NT_STATUS_NO_MEMORY
;
6711 endp
= state
->data
+ state
->num_data
;
6713 for (i
=0; i
<num_names
; i
++) {
6716 size_t converted_size
;
6718 src
= state
->data
+ 12 + i
* 2 * sizeof(SHADOW_COPY_LABEL
);
6720 if (src
+ (2 * sizeof(SHADOW_COPY_LABEL
)) > endp
) {
6721 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
6724 ret
= convert_string_talloc(
6725 names
, CH_UTF16LE
, CH_UNIX
,
6726 src
, 2 * sizeof(SHADOW_COPY_LABEL
),
6727 &names
[i
], &converted_size
);
6730 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
6733 *pnum_names
= (int)num_names
;
6735 return NT_STATUS_OK
;
6738 NTSTATUS
cli_shadow_copy_data(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
,
6739 uint16_t fnum
, bool get_names
,
6740 char ***pnames
, int *pnum_names
)
6742 TALLOC_CTX
*frame
= NULL
;
6743 struct tevent_context
*ev
;
6744 struct tevent_req
*req
;
6745 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
6747 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
6748 return cli_smb2_shadow_copy_data(mem_ctx
,
6756 frame
= talloc_stackframe();
6758 if (smbXcli_conn_has_async_calls(cli
->conn
)) {
6760 * Can't use sync call while an async call is in flight
6762 status
= NT_STATUS_INVALID_PARAMETER
;
6765 ev
= samba_tevent_context_init(frame
);
6769 req
= cli_shadow_copy_data_send(frame
, ev
, cli
, fnum
, get_names
);
6773 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
6776 status
= cli_shadow_copy_data_recv(req
, mem_ctx
, pnames
, pnum_names
);