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"
30 /***********************************************************
31 Common function for pushing stings, used by smb_bytes_push_str()
32 and trans_bytes_push_str(). Only difference is the align_odd
34 ***********************************************************/
36 static uint8_t *internal_bytes_push_str(uint8_t *buf
, bool ucs2
,
37 const char *str
, size_t str_len
,
39 size_t *pconverted_size
)
43 size_t converted_size
;
49 buflen
= talloc_get_size(buf
);
51 if (align_odd
&& ucs2
&& (buflen
% 2 == 0)) {
53 * We're pushing into an SMB buffer, align odd
55 buf
= TALLOC_REALLOC_ARRAY(NULL
, buf
, uint8_t, buflen
+ 1);
63 if (!convert_string_talloc(talloc_tos(), CH_UNIX
,
64 ucs2
? CH_UTF16LE
: CH_DOS
,
65 str
, str_len
, &converted
,
66 &converted_size
, true)) {
70 buf
= TALLOC_REALLOC_ARRAY(NULL
, buf
, uint8_t,
71 buflen
+ converted_size
);
73 TALLOC_FREE(converted
);
77 memcpy(buf
+ buflen
, converted
, converted_size
);
79 TALLOC_FREE(converted
);
81 if (pconverted_size
) {
82 *pconverted_size
= converted_size
;
88 /***********************************************************
89 Push a string into an SMB buffer, with odd byte alignment
90 if it's a UCS2 string.
91 ***********************************************************/
93 uint8_t *smb_bytes_push_str(uint8_t *buf
, bool ucs2
,
94 const char *str
, size_t str_len
,
95 size_t *pconverted_size
)
97 return internal_bytes_push_str(buf
, ucs2
, str
, str_len
,
98 true, pconverted_size
);
101 uint8_t *smb_bytes_push_bytes(uint8_t *buf
, uint8_t prefix
,
102 const uint8_t *bytes
, size_t num_bytes
)
109 buflen
= talloc_get_size(buf
);
111 buf
= TALLOC_REALLOC_ARRAY(NULL
, buf
, uint8_t,
112 buflen
+ 1 + num_bytes
);
116 buf
[buflen
] = prefix
;
117 memcpy(&buf
[buflen
+1], bytes
, num_bytes
);
121 /***********************************************************
122 Same as smb_bytes_push_str(), but without the odd byte
123 align for ucs2 (we're pushing into a param or data block).
124 static for now, although this will probably change when
125 other modules use async trans calls.
126 ***********************************************************/
128 static uint8_t *trans2_bytes_push_str(uint8_t *buf
, bool ucs2
,
129 const char *str
, size_t str_len
,
130 size_t *pconverted_size
)
132 return internal_bytes_push_str(buf
, ucs2
, str
, str_len
,
133 false, pconverted_size
);
136 struct cli_setpathinfo_state
{
141 static void cli_setpathinfo_done(struct tevent_req
*subreq
);
143 struct tevent_req
*cli_setpathinfo_send(TALLOC_CTX
*mem_ctx
,
144 struct tevent_context
*ev
,
145 struct cli_state
*cli
,
151 struct tevent_req
*req
, *subreq
;
152 struct cli_setpathinfo_state
*state
;
154 req
= tevent_req_create(mem_ctx
, &state
,
155 struct cli_setpathinfo_state
);
160 /* Setup setup word. */
161 SSVAL(&state
->setup
, 0, TRANSACT2_SETPATHINFO
);
163 /* Setup param array. */
164 state
->param
= TALLOC_ZERO_ARRAY(state
, uint8_t, 6);
165 if (tevent_req_nomem(state
->param
, req
)) {
166 return tevent_req_post(req
, ev
);
168 SSVAL(state
->param
, 0, level
);
170 state
->param
= trans2_bytes_push_str(
171 state
->param
, cli_ucs2(cli
), path
, strlen(path
)+1, NULL
);
172 if (tevent_req_nomem(state
->param
, req
)) {
173 return tevent_req_post(req
, ev
);
176 subreq
= cli_trans_send(
177 state
, /* mem ctx. */
179 cli
, /* cli_state. */
180 SMBtrans2
, /* cmd. */
181 NULL
, /* pipe name. */
185 &state
->setup
, /* setup. */
186 1, /* num setup uint16_t words. */
187 0, /* max returned setup. */
188 state
->param
, /* param. */
189 talloc_get_size(state
->param
), /* num param. */
190 2, /* max returned param. */
192 data_len
, /* num data. */
193 0); /* max returned data. */
195 if (tevent_req_nomem(subreq
, req
)) {
196 return tevent_req_post(req
, ev
);
198 tevent_req_set_callback(subreq
, cli_setpathinfo_done
, req
);
202 static void cli_setpathinfo_done(struct tevent_req
*subreq
)
204 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, NULL
, 0, NULL
,
205 NULL
, 0, NULL
, NULL
, 0, NULL
);
206 tevent_req_simple_finish_ntstatus(subreq
, status
);
209 NTSTATUS
cli_setpathinfo_recv(struct tevent_req
*req
)
211 return tevent_req_simple_recv_ntstatus(req
);
214 NTSTATUS
cli_setpathinfo(struct cli_state
*cli
,
220 TALLOC_CTX
*frame
= talloc_stackframe();
221 struct tevent_context
*ev
;
222 struct tevent_req
*req
;
223 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
225 if (cli_has_async_calls(cli
)) {
227 * Can't use sync call while an async call is in flight
229 status
= NT_STATUS_INVALID_PARAMETER
;
232 ev
= tevent_context_init(frame
);
236 req
= cli_setpathinfo_send(ev
, ev
, cli
, level
, path
, data
, data_len
);
240 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
243 status
= cli_setpathinfo_recv(req
);
249 /****************************************************************************
250 Hard/Symlink a file (UNIX extensions).
251 Creates new name (sym)linked to oldname.
252 ****************************************************************************/
254 struct cli_posix_link_internal_state
{
258 static void cli_posix_link_internal_done(struct tevent_req
*subreq
);
260 static struct tevent_req
*cli_posix_link_internal_send(TALLOC_CTX
*mem_ctx
,
261 struct event_context
*ev
,
262 struct cli_state
*cli
,
267 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
268 struct cli_posix_link_internal_state
*state
= NULL
;
270 req
= tevent_req_create(mem_ctx
, &state
,
271 struct cli_posix_link_internal_state
);
276 /* Setup data array. */
277 state
->data
= talloc_array(state
, uint8_t, 0);
278 if (tevent_req_nomem(state
->data
, req
)) {
279 return tevent_req_post(req
, ev
);
281 state
->data
= trans2_bytes_push_str(
282 state
->data
, cli_ucs2(cli
), oldname
, strlen(oldname
)+1, NULL
);
284 subreq
= cli_setpathinfo_send(
285 state
, ev
, cli
, level
, newname
,
286 state
->data
, talloc_get_size(state
->data
));
287 if (tevent_req_nomem(subreq
, req
)) {
288 return tevent_req_post(req
, ev
);
290 tevent_req_set_callback(subreq
, cli_posix_link_internal_done
, req
);
294 static void cli_posix_link_internal_done(struct tevent_req
*subreq
)
296 NTSTATUS status
= cli_setpathinfo_recv(subreq
);
297 tevent_req_simple_finish_ntstatus(subreq
, status
);
300 /****************************************************************************
301 Symlink a file (UNIX extensions).
302 ****************************************************************************/
304 struct tevent_req
*cli_posix_symlink_send(TALLOC_CTX
*mem_ctx
,
305 struct event_context
*ev
,
306 struct cli_state
*cli
,
310 return cli_posix_link_internal_send(
311 mem_ctx
, ev
, cli
, SMB_SET_FILE_UNIX_LINK
, oldname
, newname
);
314 NTSTATUS
cli_posix_symlink_recv(struct tevent_req
*req
)
316 return tevent_req_simple_recv_ntstatus(req
);
319 NTSTATUS
cli_posix_symlink(struct cli_state
*cli
,
323 TALLOC_CTX
*frame
= talloc_stackframe();
324 struct event_context
*ev
= NULL
;
325 struct tevent_req
*req
= NULL
;
326 NTSTATUS status
= NT_STATUS_OK
;
328 if (cli_has_async_calls(cli
)) {
330 * Can't use sync call while an async call is in flight
332 status
= NT_STATUS_INVALID_PARAMETER
;
336 ev
= event_context_init(frame
);
338 status
= NT_STATUS_NO_MEMORY
;
342 req
= cli_posix_symlink_send(frame
,
348 status
= NT_STATUS_NO_MEMORY
;
352 if (!tevent_req_poll(req
, ev
)) {
353 status
= map_nt_error_from_unix(errno
);
357 status
= cli_posix_symlink_recv(req
);
361 if (!NT_STATUS_IS_OK(status
)) {
362 cli_set_error(cli
, status
);
367 /****************************************************************************
368 Read a POSIX symlink.
369 ****************************************************************************/
371 struct readlink_state
{
376 static void cli_posix_readlink_done(struct tevent_req
*subreq
);
378 struct tevent_req
*cli_posix_readlink_send(TALLOC_CTX
*mem_ctx
,
379 struct event_context
*ev
,
380 struct cli_state
*cli
,
384 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
385 struct readlink_state
*state
= NULL
;
386 uint32_t maxbytelen
= (uint32_t)(cli_ucs2(cli
) ? len
*3 : len
);
388 req
= tevent_req_create(mem_ctx
, &state
, struct readlink_state
);
394 * Len is in bytes, we need it in UCS2 units.
396 if ((2*len
< len
) || (maxbytelen
< len
)) {
397 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
398 return tevent_req_post(req
, ev
);
401 subreq
= cli_qpathinfo_send(state
, ev
, cli
, fname
,
402 SMB_QUERY_FILE_UNIX_LINK
, 1, maxbytelen
);
403 if (tevent_req_nomem(subreq
, req
)) {
404 return tevent_req_post(req
, ev
);
406 tevent_req_set_callback(subreq
, cli_posix_readlink_done
, req
);
410 static void cli_posix_readlink_done(struct tevent_req
*subreq
)
412 struct tevent_req
*req
= tevent_req_callback_data(
413 subreq
, struct tevent_req
);
414 struct readlink_state
*state
= tevent_req_data(
415 req
, struct readlink_state
);
418 status
= cli_qpathinfo_recv(subreq
, state
, &state
->data
,
421 if (tevent_req_nterror(req
, status
)) {
425 * num_data is > 1, we've given 1 as minimum to cli_qpathinfo_send
427 if (state
->data
[state
->num_data
-1] != '\0') {
428 tevent_req_nterror(req
, NT_STATUS_DATA_ERROR
);
431 tevent_req_done(req
);
434 NTSTATUS
cli_posix_readlink_recv(struct tevent_req
*req
, struct cli_state
*cli
,
435 char *retpath
, size_t len
)
438 char *converted
= NULL
;
439 size_t converted_size
= 0;
440 struct readlink_state
*state
= tevent_req_data(req
, struct readlink_state
);
442 if (tevent_req_is_nterror(req
, &status
)) {
445 /* The returned data is a pushed string, not raw data. */
446 if (!convert_string_talloc(state
,
447 cli_ucs2(cli
) ? CH_UTF16LE
: CH_DOS
,
454 return NT_STATUS_NO_MEMORY
;
457 len
= MIN(len
,converted_size
);
459 return NT_STATUS_DATA_ERROR
;
461 memcpy(retpath
, converted
, len
);
465 NTSTATUS
cli_posix_readlink(struct cli_state
*cli
, const char *fname
,
466 char *linkpath
, size_t len
)
468 TALLOC_CTX
*frame
= talloc_stackframe();
469 struct event_context
*ev
= NULL
;
470 struct tevent_req
*req
= NULL
;
471 NTSTATUS status
= NT_STATUS_OK
;
473 if (cli_has_async_calls(cli
)) {
475 * Can't use sync call while an async call is in flight
477 status
= NT_STATUS_INVALID_PARAMETER
;
481 ev
= event_context_init(frame
);
483 status
= NT_STATUS_NO_MEMORY
;
487 req
= cli_posix_readlink_send(frame
,
493 status
= NT_STATUS_NO_MEMORY
;
497 if (!tevent_req_poll(req
, ev
)) {
498 status
= map_nt_error_from_unix(errno
);
502 status
= cli_posix_readlink_recv(req
, cli
, linkpath
, len
);
506 if (!NT_STATUS_IS_OK(status
)) {
507 cli_set_error(cli
, status
);
512 /****************************************************************************
513 Hard link a file (UNIX extensions).
514 ****************************************************************************/
516 struct tevent_req
*cli_posix_hardlink_send(TALLOC_CTX
*mem_ctx
,
517 struct event_context
*ev
,
518 struct cli_state
*cli
,
522 return cli_posix_link_internal_send(
523 mem_ctx
, ev
, cli
, SMB_SET_FILE_UNIX_HLINK
, oldname
, newname
);
526 NTSTATUS
cli_posix_hardlink_recv(struct tevent_req
*req
)
528 return tevent_req_simple_recv_ntstatus(req
);
531 NTSTATUS
cli_posix_hardlink(struct cli_state
*cli
,
535 TALLOC_CTX
*frame
= talloc_stackframe();
536 struct event_context
*ev
= NULL
;
537 struct tevent_req
*req
= NULL
;
538 NTSTATUS status
= NT_STATUS_OK
;
540 if (cli_has_async_calls(cli
)) {
542 * Can't use sync call while an async call is in flight
544 status
= NT_STATUS_INVALID_PARAMETER
;
548 ev
= event_context_init(frame
);
550 status
= NT_STATUS_NO_MEMORY
;
554 req
= cli_posix_hardlink_send(frame
,
560 status
= NT_STATUS_NO_MEMORY
;
564 if (!tevent_req_poll(req
, ev
)) {
565 status
= map_nt_error_from_unix(errno
);
569 status
= cli_posix_hardlink_recv(req
);
573 if (!NT_STATUS_IS_OK(status
)) {
574 cli_set_error(cli
, status
);
579 /****************************************************************************
580 Map standard UNIX permissions onto wire representations.
581 ****************************************************************************/
583 uint32_t unix_perms_to_wire(mode_t perms
)
585 unsigned int ret
= 0;
587 ret
|= ((perms
& S_IXOTH
) ? UNIX_X_OTH
: 0);
588 ret
|= ((perms
& S_IWOTH
) ? UNIX_W_OTH
: 0);
589 ret
|= ((perms
& S_IROTH
) ? UNIX_R_OTH
: 0);
590 ret
|= ((perms
& S_IXGRP
) ? UNIX_X_GRP
: 0);
591 ret
|= ((perms
& S_IWGRP
) ? UNIX_W_GRP
: 0);
592 ret
|= ((perms
& S_IRGRP
) ? UNIX_R_GRP
: 0);
593 ret
|= ((perms
& S_IXUSR
) ? UNIX_X_USR
: 0);
594 ret
|= ((perms
& S_IWUSR
) ? UNIX_W_USR
: 0);
595 ret
|= ((perms
& S_IRUSR
) ? UNIX_R_USR
: 0);
597 ret
|= ((perms
& S_ISVTX
) ? UNIX_STICKY
: 0);
600 ret
|= ((perms
& S_ISGID
) ? UNIX_SET_GID
: 0);
603 ret
|= ((perms
& S_ISUID
) ? UNIX_SET_UID
: 0);
608 /****************************************************************************
609 Map wire permissions to standard UNIX.
610 ****************************************************************************/
612 mode_t
wire_perms_to_unix(uint32_t perms
)
614 mode_t ret
= (mode_t
)0;
616 ret
|= ((perms
& UNIX_X_OTH
) ? S_IXOTH
: 0);
617 ret
|= ((perms
& UNIX_W_OTH
) ? S_IWOTH
: 0);
618 ret
|= ((perms
& UNIX_R_OTH
) ? S_IROTH
: 0);
619 ret
|= ((perms
& UNIX_X_GRP
) ? S_IXGRP
: 0);
620 ret
|= ((perms
& UNIX_W_GRP
) ? S_IWGRP
: 0);
621 ret
|= ((perms
& UNIX_R_GRP
) ? S_IRGRP
: 0);
622 ret
|= ((perms
& UNIX_X_USR
) ? S_IXUSR
: 0);
623 ret
|= ((perms
& UNIX_W_USR
) ? S_IWUSR
: 0);
624 ret
|= ((perms
& UNIX_R_USR
) ? S_IRUSR
: 0);
626 ret
|= ((perms
& UNIX_STICKY
) ? S_ISVTX
: 0);
629 ret
|= ((perms
& UNIX_SET_GID
) ? S_ISGID
: 0);
632 ret
|= ((perms
& UNIX_SET_UID
) ? S_ISUID
: 0);
637 /****************************************************************************
638 Return the file type from the wire filetype for UNIX extensions.
639 ****************************************************************************/
641 static mode_t
unix_filetype_from_wire(uint32_t wire_type
)
649 case UNIX_TYPE_SYMLINK
:
653 case UNIX_TYPE_CHARDEV
:
657 case UNIX_TYPE_BLKDEV
:
665 case UNIX_TYPE_SOCKET
:
673 /****************************************************************************
674 Do a POSIX getfacl (UNIX extensions).
675 ****************************************************************************/
677 struct getfacl_state
{
682 static void cli_posix_getfacl_done(struct tevent_req
*subreq
);
684 struct tevent_req
*cli_posix_getfacl_send(TALLOC_CTX
*mem_ctx
,
685 struct event_context
*ev
,
686 struct cli_state
*cli
,
689 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
690 struct getfacl_state
*state
= NULL
;
692 req
= tevent_req_create(mem_ctx
, &state
, struct getfacl_state
);
696 subreq
= cli_qpathinfo_send(state
, ev
, cli
, fname
, SMB_QUERY_POSIX_ACL
,
698 if (tevent_req_nomem(subreq
, req
)) {
699 return tevent_req_post(req
, ev
);
701 tevent_req_set_callback(subreq
, cli_posix_getfacl_done
, req
);
705 static void cli_posix_getfacl_done(struct tevent_req
*subreq
)
707 struct tevent_req
*req
= tevent_req_callback_data(
708 subreq
, struct tevent_req
);
709 struct getfacl_state
*state
= tevent_req_data(
710 req
, struct getfacl_state
);
713 status
= cli_qpathinfo_recv(subreq
, state
, &state
->data
,
716 if (tevent_req_nterror(req
, status
)) {
719 tevent_req_done(req
);
722 NTSTATUS
cli_posix_getfacl_recv(struct tevent_req
*req
,
727 struct getfacl_state
*state
= tevent_req_data(req
, struct getfacl_state
);
730 if (tevent_req_is_nterror(req
, &status
)) {
733 *prb_size
= (size_t)state
->num_data
;
734 *retbuf
= (char *)talloc_move(mem_ctx
, &state
->data
);
738 NTSTATUS
cli_posix_getfacl(struct cli_state
*cli
,
744 TALLOC_CTX
*frame
= talloc_stackframe();
745 struct event_context
*ev
= NULL
;
746 struct tevent_req
*req
= NULL
;
747 NTSTATUS status
= NT_STATUS_OK
;
749 if (cli_has_async_calls(cli
)) {
751 * Can't use sync call while an async call is in flight
753 status
= NT_STATUS_INVALID_PARAMETER
;
757 ev
= event_context_init(frame
);
759 status
= NT_STATUS_NO_MEMORY
;
763 req
= cli_posix_getfacl_send(frame
,
768 status
= NT_STATUS_NO_MEMORY
;
772 if (!tevent_req_poll(req
, ev
)) {
773 status
= map_nt_error_from_unix(errno
);
777 status
= cli_posix_getfacl_recv(req
, mem_ctx
, prb_size
, retbuf
);
781 if (!NT_STATUS_IS_OK(status
)) {
782 cli_set_error(cli
, status
);
787 /****************************************************************************
788 Stat a file (UNIX extensions).
789 ****************************************************************************/
796 static void cli_posix_stat_done(struct tevent_req
*subreq
);
798 struct tevent_req
*cli_posix_stat_send(TALLOC_CTX
*mem_ctx
,
799 struct event_context
*ev
,
800 struct cli_state
*cli
,
803 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
804 struct stat_state
*state
= NULL
;
806 req
= tevent_req_create(mem_ctx
, &state
, struct stat_state
);
810 subreq
= cli_qpathinfo_send(state
, ev
, cli
, fname
,
811 SMB_QUERY_FILE_UNIX_BASIC
, 100, 100);
812 if (tevent_req_nomem(subreq
, req
)) {
813 return tevent_req_post(req
, ev
);
815 tevent_req_set_callback(subreq
, cli_posix_stat_done
, req
);
819 static void cli_posix_stat_done(struct tevent_req
*subreq
)
821 struct tevent_req
*req
= tevent_req_callback_data(
822 subreq
, struct tevent_req
);
823 struct stat_state
*state
= tevent_req_data(req
, struct stat_state
);
826 status
= cli_qpathinfo_recv(subreq
, state
, &state
->data
,
829 if (tevent_req_nterror(req
, status
)) {
832 tevent_req_done(req
);
835 NTSTATUS
cli_posix_stat_recv(struct tevent_req
*req
,
836 SMB_STRUCT_STAT
*sbuf
)
838 struct stat_state
*state
= tevent_req_data(req
, struct stat_state
);
841 if (tevent_req_is_nterror(req
, &status
)) {
845 sbuf
->st_ex_size
= IVAL2_TO_SMB_BIG_UINT(state
->data
,0); /* total size, in bytes */
846 sbuf
->st_ex_blocks
= IVAL2_TO_SMB_BIG_UINT(state
->data
,8); /* number of blocks allocated */
847 #if defined (HAVE_STAT_ST_BLOCKS) && defined(STAT_ST_BLOCKSIZE)
848 sbuf
->st_ex_blocks
/= STAT_ST_BLOCKSIZE
;
850 /* assume 512 byte blocks */
851 sbuf
->st_ex_blocks
/= 512;
853 sbuf
->st_ex_ctime
= interpret_long_date((char *)(state
->data
+ 16)); /* time of last change */
854 sbuf
->st_ex_atime
= interpret_long_date((char *)(state
->data
+ 24)); /* time of last access */
855 sbuf
->st_ex_mtime
= interpret_long_date((char *)(state
->data
+ 32)); /* time of last modification */
857 sbuf
->st_ex_uid
= (uid_t
) IVAL(state
->data
,40); /* user ID of owner */
858 sbuf
->st_ex_gid
= (gid_t
) IVAL(state
->data
,48); /* group ID of owner */
859 sbuf
->st_ex_mode
= unix_filetype_from_wire(IVAL(state
->data
, 56));
860 #if defined(HAVE_MAKEDEV)
862 uint32_t dev_major
= IVAL(state
->data
,60);
863 uint32_t dev_minor
= IVAL(state
->data
,68);
864 sbuf
->st_ex_rdev
= makedev(dev_major
, dev_minor
);
867 sbuf
->st_ex_ino
= (SMB_INO_T
)IVAL2_TO_SMB_BIG_UINT(state
->data
,76); /* inode */
868 sbuf
->st_ex_mode
|= wire_perms_to_unix(IVAL(state
->data
,84)); /* protection */
869 sbuf
->st_ex_nlink
= BIG_UINT(state
->data
,92); /* number of hard links */
874 NTSTATUS
cli_posix_stat(struct cli_state
*cli
,
876 SMB_STRUCT_STAT
*sbuf
)
878 TALLOC_CTX
*frame
= talloc_stackframe();
879 struct event_context
*ev
= NULL
;
880 struct tevent_req
*req
= NULL
;
881 NTSTATUS status
= NT_STATUS_OK
;
883 if (cli_has_async_calls(cli
)) {
885 * Can't use sync call while an async call is in flight
887 status
= NT_STATUS_INVALID_PARAMETER
;
891 ev
= event_context_init(frame
);
893 status
= NT_STATUS_NO_MEMORY
;
897 req
= cli_posix_stat_send(frame
,
902 status
= NT_STATUS_NO_MEMORY
;
906 if (!tevent_req_poll(req
, ev
)) {
907 status
= map_nt_error_from_unix(errno
);
911 status
= cli_posix_stat_recv(req
, sbuf
);
915 if (!NT_STATUS_IS_OK(status
)) {
916 cli_set_error(cli
, status
);
921 /****************************************************************************
922 Chmod or chown a file internal (UNIX extensions).
923 ****************************************************************************/
925 struct cli_posix_chown_chmod_internal_state
{
929 static void cli_posix_chown_chmod_internal_done(struct tevent_req
*subreq
);
931 static struct tevent_req
*cli_posix_chown_chmod_internal_send(TALLOC_CTX
*mem_ctx
,
932 struct event_context
*ev
,
933 struct cli_state
*cli
,
939 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
940 struct cli_posix_chown_chmod_internal_state
*state
= NULL
;
942 req
= tevent_req_create(mem_ctx
, &state
,
943 struct cli_posix_chown_chmod_internal_state
);
948 memset(state
->data
, 0xff, 40); /* Set all sizes/times to no change. */
949 memset(&state
->data
[40], '\0', 60);
950 SIVAL(state
->data
,40,uid
);
951 SIVAL(state
->data
,48,gid
);
952 SIVAL(state
->data
,84,mode
);
954 subreq
= cli_setpathinfo_send(state
, ev
, cli
, SMB_SET_FILE_UNIX_BASIC
,
955 fname
, state
->data
, sizeof(state
->data
));
956 if (tevent_req_nomem(subreq
, req
)) {
957 return tevent_req_post(req
, ev
);
959 tevent_req_set_callback(subreq
, cli_posix_chown_chmod_internal_done
,
964 static void cli_posix_chown_chmod_internal_done(struct tevent_req
*subreq
)
966 NTSTATUS status
= cli_setpathinfo_recv(subreq
);
967 tevent_req_simple_finish_ntstatus(subreq
, status
);
970 /****************************************************************************
971 chmod a file (UNIX extensions).
972 ****************************************************************************/
974 struct tevent_req
*cli_posix_chmod_send(TALLOC_CTX
*mem_ctx
,
975 struct event_context
*ev
,
976 struct cli_state
*cli
,
980 return cli_posix_chown_chmod_internal_send(mem_ctx
, ev
, cli
,
982 unix_perms_to_wire(mode
),
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 event_context
*ev
= NULL
;
996 struct tevent_req
*req
= NULL
;
997 NTSTATUS status
= NT_STATUS_OK
;
999 if (cli_has_async_calls(cli
)) {
1001 * Can't use sync call while an async call is in flight
1003 status
= NT_STATUS_INVALID_PARAMETER
;
1007 ev
= event_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(req
, ev
)) {
1024 status
= map_nt_error_from_unix(errno
);
1028 status
= cli_posix_chmod_recv(req
);
1032 if (!NT_STATUS_IS_OK(status
)) {
1033 cli_set_error(cli
, status
);
1038 /****************************************************************************
1039 chown a file (UNIX extensions).
1040 ****************************************************************************/
1042 struct tevent_req
*cli_posix_chown_send(TALLOC_CTX
*mem_ctx
,
1043 struct event_context
*ev
,
1044 struct cli_state
*cli
,
1049 return cli_posix_chown_chmod_internal_send(mem_ctx
, ev
, cli
,
1056 NTSTATUS
cli_posix_chown_recv(struct tevent_req
*req
)
1058 return tevent_req_simple_recv_ntstatus(req
);
1061 NTSTATUS
cli_posix_chown(struct cli_state
*cli
,
1066 TALLOC_CTX
*frame
= talloc_stackframe();
1067 struct event_context
*ev
= NULL
;
1068 struct tevent_req
*req
= NULL
;
1069 NTSTATUS status
= NT_STATUS_OK
;
1071 if (cli_has_async_calls(cli
)) {
1073 * Can't use sync call while an async call is in flight
1075 status
= NT_STATUS_INVALID_PARAMETER
;
1079 ev
= event_context_init(frame
);
1081 status
= NT_STATUS_NO_MEMORY
;
1085 req
= cli_posix_chown_send(frame
,
1092 status
= NT_STATUS_NO_MEMORY
;
1096 if (!tevent_req_poll(req
, ev
)) {
1097 status
= map_nt_error_from_unix(errno
);
1101 status
= cli_posix_chown_recv(req
);
1105 if (!NT_STATUS_IS_OK(status
)) {
1106 cli_set_error(cli
, status
);
1111 /****************************************************************************
1113 ****************************************************************************/
1115 static void cli_rename_done(struct tevent_req
*subreq
);
1117 struct cli_rename_state
{
1121 struct tevent_req
*cli_rename_send(TALLOC_CTX
*mem_ctx
,
1122 struct event_context
*ev
,
1123 struct cli_state
*cli
,
1124 const char *fname_src
,
1125 const char *fname_dst
)
1127 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1128 struct cli_rename_state
*state
= NULL
;
1129 uint8_t additional_flags
= 0;
1130 uint8_t *bytes
= NULL
;
1132 req
= tevent_req_create(mem_ctx
, &state
, struct cli_rename_state
);
1137 SSVAL(state
->vwv
+0, 0, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_DIRECTORY
);
1139 bytes
= talloc_array(state
, uint8_t, 1);
1140 if (tevent_req_nomem(bytes
, req
)) {
1141 return tevent_req_post(req
, ev
);
1144 bytes
= smb_bytes_push_str(bytes
, cli_ucs2(cli
), fname_src
,
1145 strlen(fname_src
)+1, NULL
);
1146 if (tevent_req_nomem(bytes
, req
)) {
1147 return tevent_req_post(req
, ev
);
1150 bytes
= TALLOC_REALLOC_ARRAY(state
, bytes
, uint8_t,
1151 talloc_get_size(bytes
)+1);
1152 if (tevent_req_nomem(bytes
, req
)) {
1153 return tevent_req_post(req
, ev
);
1156 bytes
[talloc_get_size(bytes
)-1] = 4;
1157 bytes
= smb_bytes_push_str(bytes
, cli_ucs2(cli
), fname_dst
,
1158 strlen(fname_dst
)+1, NULL
);
1159 if (tevent_req_nomem(bytes
, req
)) {
1160 return tevent_req_post(req
, ev
);
1163 subreq
= cli_smb_send(state
, ev
, cli
, SMBmv
, additional_flags
,
1164 1, state
->vwv
, talloc_get_size(bytes
), bytes
);
1165 if (tevent_req_nomem(subreq
, req
)) {
1166 return tevent_req_post(req
, ev
);
1168 tevent_req_set_callback(subreq
, cli_rename_done
, req
);
1172 static void cli_rename_done(struct tevent_req
*subreq
)
1174 struct tevent_req
*req
= tevent_req_callback_data(
1175 subreq
, struct tevent_req
);
1178 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
1179 TALLOC_FREE(subreq
);
1180 if (tevent_req_nterror(req
, status
)) {
1183 tevent_req_done(req
);
1186 NTSTATUS
cli_rename_recv(struct tevent_req
*req
)
1188 return tevent_req_simple_recv_ntstatus(req
);
1191 NTSTATUS
cli_rename(struct cli_state
*cli
, const char *fname_src
, const char *fname_dst
)
1193 TALLOC_CTX
*frame
= talloc_stackframe();
1194 struct event_context
*ev
;
1195 struct tevent_req
*req
;
1196 NTSTATUS status
= NT_STATUS_OK
;
1198 if (cli_has_async_calls(cli
)) {
1200 * Can't use sync call while an async call is in flight
1202 status
= NT_STATUS_INVALID_PARAMETER
;
1206 ev
= event_context_init(frame
);
1208 status
= NT_STATUS_NO_MEMORY
;
1212 req
= cli_rename_send(frame
, ev
, cli
, fname_src
, fname_dst
);
1214 status
= NT_STATUS_NO_MEMORY
;
1218 if (!tevent_req_poll(req
, ev
)) {
1219 status
= map_nt_error_from_unix(errno
);
1223 status
= cli_rename_recv(req
);
1227 if (!NT_STATUS_IS_OK(status
)) {
1228 cli_set_error(cli
, status
);
1233 /****************************************************************************
1235 ****************************************************************************/
1237 static void cli_ntrename_internal_done(struct tevent_req
*subreq
);
1239 struct cli_ntrename_internal_state
{
1243 static struct tevent_req
*cli_ntrename_internal_send(TALLOC_CTX
*mem_ctx
,
1244 struct event_context
*ev
,
1245 struct cli_state
*cli
,
1246 const char *fname_src
,
1247 const char *fname_dst
,
1248 uint16_t rename_flag
)
1250 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1251 struct cli_ntrename_internal_state
*state
= NULL
;
1252 uint8_t additional_flags
= 0;
1253 uint8_t *bytes
= NULL
;
1255 req
= tevent_req_create(mem_ctx
, &state
,
1256 struct cli_ntrename_internal_state
);
1261 SSVAL(state
->vwv
+0, 0 ,FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_DIRECTORY
);
1262 SSVAL(state
->vwv
+1, 0, rename_flag
);
1264 bytes
= talloc_array(state
, uint8_t, 1);
1265 if (tevent_req_nomem(bytes
, req
)) {
1266 return tevent_req_post(req
, ev
);
1269 bytes
= smb_bytes_push_str(bytes
, cli_ucs2(cli
), fname_src
,
1270 strlen(fname_src
)+1, NULL
);
1271 if (tevent_req_nomem(bytes
, req
)) {
1272 return tevent_req_post(req
, ev
);
1275 bytes
= TALLOC_REALLOC_ARRAY(state
, bytes
, uint8_t,
1276 talloc_get_size(bytes
)+1);
1277 if (tevent_req_nomem(bytes
, req
)) {
1278 return tevent_req_post(req
, ev
);
1281 bytes
[talloc_get_size(bytes
)-1] = 4;
1282 bytes
= smb_bytes_push_str(bytes
, cli_ucs2(cli
), fname_dst
,
1283 strlen(fname_dst
)+1, NULL
);
1284 if (tevent_req_nomem(bytes
, req
)) {
1285 return tevent_req_post(req
, ev
);
1288 subreq
= cli_smb_send(state
, ev
, cli
, SMBntrename
, additional_flags
,
1289 4, state
->vwv
, talloc_get_size(bytes
), bytes
);
1290 if (tevent_req_nomem(subreq
, req
)) {
1291 return tevent_req_post(req
, ev
);
1293 tevent_req_set_callback(subreq
, cli_ntrename_internal_done
, req
);
1297 static void cli_ntrename_internal_done(struct tevent_req
*subreq
)
1299 struct tevent_req
*req
= tevent_req_callback_data(
1300 subreq
, struct tevent_req
);
1303 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
1304 TALLOC_FREE(subreq
);
1305 if (tevent_req_nterror(req
, status
)) {
1308 tevent_req_done(req
);
1311 static NTSTATUS
cli_ntrename_internal_recv(struct tevent_req
*req
)
1313 return tevent_req_simple_recv_ntstatus(req
);
1316 struct tevent_req
*cli_ntrename_send(TALLOC_CTX
*mem_ctx
,
1317 struct event_context
*ev
,
1318 struct cli_state
*cli
,
1319 const char *fname_src
,
1320 const char *fname_dst
)
1322 return cli_ntrename_internal_send(mem_ctx
,
1327 RENAME_FLAG_RENAME
);
1330 NTSTATUS
cli_ntrename_recv(struct tevent_req
*req
)
1332 return cli_ntrename_internal_recv(req
);
1335 NTSTATUS
cli_ntrename(struct cli_state
*cli
, const char *fname_src
, const char *fname_dst
)
1337 TALLOC_CTX
*frame
= talloc_stackframe();
1338 struct event_context
*ev
;
1339 struct tevent_req
*req
;
1340 NTSTATUS status
= NT_STATUS_OK
;
1342 if (cli_has_async_calls(cli
)) {
1344 * Can't use sync call while an async call is in flight
1346 status
= NT_STATUS_INVALID_PARAMETER
;
1350 ev
= event_context_init(frame
);
1352 status
= NT_STATUS_NO_MEMORY
;
1356 req
= cli_ntrename_send(frame
, ev
, cli
, fname_src
, fname_dst
);
1358 status
= NT_STATUS_NO_MEMORY
;
1362 if (!tevent_req_poll(req
, ev
)) {
1363 status
= map_nt_error_from_unix(errno
);
1367 status
= cli_ntrename_recv(req
);
1371 if (!NT_STATUS_IS_OK(status
)) {
1372 cli_set_error(cli
, status
);
1377 /****************************************************************************
1379 ****************************************************************************/
1381 struct tevent_req
*cli_nt_hardlink_send(TALLOC_CTX
*mem_ctx
,
1382 struct event_context
*ev
,
1383 struct cli_state
*cli
,
1384 const char *fname_src
,
1385 const char *fname_dst
)
1387 return cli_ntrename_internal_send(mem_ctx
,
1392 RENAME_FLAG_HARD_LINK
);
1395 NTSTATUS
cli_nt_hardlink_recv(struct tevent_req
*req
)
1397 return cli_ntrename_internal_recv(req
);
1400 NTSTATUS
cli_nt_hardlink(struct cli_state
*cli
, const char *fname_src
, const char *fname_dst
)
1402 TALLOC_CTX
*frame
= talloc_stackframe();
1403 struct event_context
*ev
;
1404 struct tevent_req
*req
;
1405 NTSTATUS status
= NT_STATUS_OK
;
1407 if (cli_has_async_calls(cli
)) {
1409 * Can't use sync call while an async call is in flight
1411 status
= NT_STATUS_INVALID_PARAMETER
;
1415 ev
= event_context_init(frame
);
1417 status
= NT_STATUS_NO_MEMORY
;
1421 req
= cli_nt_hardlink_send(frame
, ev
, cli
, fname_src
, fname_dst
);
1423 status
= NT_STATUS_NO_MEMORY
;
1427 if (!tevent_req_poll(req
, ev
)) {
1428 status
= map_nt_error_from_unix(errno
);
1432 status
= cli_nt_hardlink_recv(req
);
1436 if (!NT_STATUS_IS_OK(status
)) {
1437 cli_set_error(cli
, status
);
1442 /****************************************************************************
1444 ****************************************************************************/
1446 static void cli_unlink_done(struct tevent_req
*subreq
);
1448 struct cli_unlink_state
{
1452 struct tevent_req
*cli_unlink_send(TALLOC_CTX
*mem_ctx
,
1453 struct event_context
*ev
,
1454 struct cli_state
*cli
,
1456 uint16_t mayhave_attrs
)
1458 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1459 struct cli_unlink_state
*state
= NULL
;
1460 uint8_t additional_flags
= 0;
1461 uint8_t *bytes
= NULL
;
1463 req
= tevent_req_create(mem_ctx
, &state
, struct cli_unlink_state
);
1468 SSVAL(state
->vwv
+0, 0, mayhave_attrs
);
1470 bytes
= talloc_array(state
, uint8_t, 1);
1471 if (tevent_req_nomem(bytes
, req
)) {
1472 return tevent_req_post(req
, ev
);
1475 bytes
= smb_bytes_push_str(bytes
, cli_ucs2(cli
), fname
,
1476 strlen(fname
)+1, NULL
);
1478 if (tevent_req_nomem(bytes
, req
)) {
1479 return tevent_req_post(req
, ev
);
1482 subreq
= cli_smb_send(state
, ev
, cli
, SMBunlink
, additional_flags
,
1483 1, state
->vwv
, talloc_get_size(bytes
), bytes
);
1484 if (tevent_req_nomem(subreq
, req
)) {
1485 return tevent_req_post(req
, ev
);
1487 tevent_req_set_callback(subreq
, cli_unlink_done
, req
);
1491 static void cli_unlink_done(struct tevent_req
*subreq
)
1493 struct tevent_req
*req
= tevent_req_callback_data(
1494 subreq
, struct tevent_req
);
1497 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
1498 TALLOC_FREE(subreq
);
1499 if (tevent_req_nterror(req
, status
)) {
1502 tevent_req_done(req
);
1505 NTSTATUS
cli_unlink_recv(struct tevent_req
*req
)
1507 return tevent_req_simple_recv_ntstatus(req
);
1510 NTSTATUS
cli_unlink(struct cli_state
*cli
, const char *fname
, uint16_t mayhave_attrs
)
1512 TALLOC_CTX
*frame
= talloc_stackframe();
1513 struct event_context
*ev
;
1514 struct tevent_req
*req
;
1515 NTSTATUS status
= NT_STATUS_OK
;
1517 if (cli_has_async_calls(cli
)) {
1519 * Can't use sync call while an async call is in flight
1521 status
= NT_STATUS_INVALID_PARAMETER
;
1525 ev
= event_context_init(frame
);
1527 status
= NT_STATUS_NO_MEMORY
;
1531 req
= cli_unlink_send(frame
, ev
, cli
, fname
, mayhave_attrs
);
1533 status
= NT_STATUS_NO_MEMORY
;
1537 if (!tevent_req_poll(req
, ev
)) {
1538 status
= map_nt_error_from_unix(errno
);
1542 status
= cli_unlink_recv(req
);
1546 if (!NT_STATUS_IS_OK(status
)) {
1547 cli_set_error(cli
, status
);
1552 /****************************************************************************
1554 ****************************************************************************/
1556 static void cli_mkdir_done(struct tevent_req
*subreq
);
1558 struct cli_mkdir_state
{
1562 struct tevent_req
*cli_mkdir_send(TALLOC_CTX
*mem_ctx
,
1563 struct event_context
*ev
,
1564 struct cli_state
*cli
,
1567 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1568 struct cli_mkdir_state
*state
= NULL
;
1569 uint8_t additional_flags
= 0;
1570 uint8_t *bytes
= NULL
;
1572 req
= tevent_req_create(mem_ctx
, &state
, struct cli_mkdir_state
);
1577 bytes
= talloc_array(state
, uint8_t, 1);
1578 if (tevent_req_nomem(bytes
, req
)) {
1579 return tevent_req_post(req
, ev
);
1582 bytes
= smb_bytes_push_str(bytes
, cli_ucs2(cli
), dname
,
1583 strlen(dname
)+1, NULL
);
1585 if (tevent_req_nomem(bytes
, req
)) {
1586 return tevent_req_post(req
, ev
);
1589 subreq
= cli_smb_send(state
, ev
, cli
, SMBmkdir
, additional_flags
,
1590 0, NULL
, talloc_get_size(bytes
), bytes
);
1591 if (tevent_req_nomem(subreq
, req
)) {
1592 return tevent_req_post(req
, ev
);
1594 tevent_req_set_callback(subreq
, cli_mkdir_done
, req
);
1598 static void cli_mkdir_done(struct tevent_req
*subreq
)
1600 struct tevent_req
*req
= tevent_req_callback_data(
1601 subreq
, struct tevent_req
);
1604 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
1605 TALLOC_FREE(subreq
);
1606 if (tevent_req_nterror(req
, status
)) {
1609 tevent_req_done(req
);
1612 NTSTATUS
cli_mkdir_recv(struct tevent_req
*req
)
1614 return tevent_req_simple_recv_ntstatus(req
);
1617 NTSTATUS
cli_mkdir(struct cli_state
*cli
, const char *dname
)
1619 TALLOC_CTX
*frame
= talloc_stackframe();
1620 struct event_context
*ev
;
1621 struct tevent_req
*req
;
1622 NTSTATUS status
= NT_STATUS_OK
;
1624 if (cli_has_async_calls(cli
)) {
1626 * Can't use sync call while an async call is in flight
1628 status
= NT_STATUS_INVALID_PARAMETER
;
1632 ev
= event_context_init(frame
);
1634 status
= NT_STATUS_NO_MEMORY
;
1638 req
= cli_mkdir_send(frame
, ev
, cli
, dname
);
1640 status
= NT_STATUS_NO_MEMORY
;
1644 if (!tevent_req_poll(req
, ev
)) {
1645 status
= map_nt_error_from_unix(errno
);
1649 status
= cli_mkdir_recv(req
);
1653 if (!NT_STATUS_IS_OK(status
)) {
1654 cli_set_error(cli
, status
);
1659 /****************************************************************************
1661 ****************************************************************************/
1663 static void cli_rmdir_done(struct tevent_req
*subreq
);
1665 struct cli_rmdir_state
{
1669 struct tevent_req
*cli_rmdir_send(TALLOC_CTX
*mem_ctx
,
1670 struct event_context
*ev
,
1671 struct cli_state
*cli
,
1674 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1675 struct cli_rmdir_state
*state
= NULL
;
1676 uint8_t additional_flags
= 0;
1677 uint8_t *bytes
= NULL
;
1679 req
= tevent_req_create(mem_ctx
, &state
, struct cli_rmdir_state
);
1684 bytes
= talloc_array(state
, uint8_t, 1);
1685 if (tevent_req_nomem(bytes
, req
)) {
1686 return tevent_req_post(req
, ev
);
1689 bytes
= smb_bytes_push_str(bytes
, cli_ucs2(cli
), dname
,
1690 strlen(dname
)+1, NULL
);
1692 if (tevent_req_nomem(bytes
, req
)) {
1693 return tevent_req_post(req
, ev
);
1696 subreq
= cli_smb_send(state
, ev
, cli
, SMBrmdir
, additional_flags
,
1697 0, NULL
, talloc_get_size(bytes
), bytes
);
1698 if (tevent_req_nomem(subreq
, req
)) {
1699 return tevent_req_post(req
, ev
);
1701 tevent_req_set_callback(subreq
, cli_rmdir_done
, req
);
1705 static void cli_rmdir_done(struct tevent_req
*subreq
)
1707 struct tevent_req
*req
= tevent_req_callback_data(
1708 subreq
, struct tevent_req
);
1711 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
1712 TALLOC_FREE(subreq
);
1713 if (tevent_req_nterror(req
, status
)) {
1716 tevent_req_done(req
);
1719 NTSTATUS
cli_rmdir_recv(struct tevent_req
*req
)
1721 return tevent_req_simple_recv_ntstatus(req
);
1724 NTSTATUS
cli_rmdir(struct cli_state
*cli
, const char *dname
)
1726 TALLOC_CTX
*frame
= talloc_stackframe();
1727 struct event_context
*ev
;
1728 struct tevent_req
*req
;
1729 NTSTATUS status
= NT_STATUS_OK
;
1731 if (cli_has_async_calls(cli
)) {
1733 * Can't use sync call while an async call is in flight
1735 status
= NT_STATUS_INVALID_PARAMETER
;
1739 ev
= event_context_init(frame
);
1741 status
= NT_STATUS_NO_MEMORY
;
1745 req
= cli_rmdir_send(frame
, ev
, cli
, dname
);
1747 status
= NT_STATUS_NO_MEMORY
;
1751 if (!tevent_req_poll(req
, ev
)) {
1752 status
= map_nt_error_from_unix(errno
);
1756 status
= cli_rmdir_recv(req
);
1760 if (!NT_STATUS_IS_OK(status
)) {
1761 cli_set_error(cli
, status
);
1766 /****************************************************************************
1767 Set or clear the delete on close flag.
1768 ****************************************************************************/
1776 static void cli_nt_delete_on_close_done(struct tevent_req
*subreq
)
1778 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, NULL
, 0, NULL
,
1779 NULL
, 0, NULL
, NULL
, 0, NULL
);
1780 tevent_req_simple_finish_ntstatus(subreq
, status
);
1783 struct tevent_req
*cli_nt_delete_on_close_send(TALLOC_CTX
*mem_ctx
,
1784 struct event_context
*ev
,
1785 struct cli_state
*cli
,
1789 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1790 struct doc_state
*state
= NULL
;
1792 req
= tevent_req_create(mem_ctx
, &state
, struct doc_state
);
1797 /* Setup setup word. */
1798 SSVAL(&state
->setup
, 0, TRANSACT2_SETFILEINFO
);
1800 /* Setup param array. */
1801 SSVAL(state
->param
,0,fnum
);
1802 SSVAL(state
->param
,2,SMB_SET_FILE_DISPOSITION_INFO
);
1804 /* Setup data array. */
1805 SCVAL(&state
->data
[0], 0, flag
? 1 : 0);
1807 subreq
= cli_trans_send(state
, /* mem ctx. */
1808 ev
, /* event ctx. */
1809 cli
, /* cli_state. */
1810 SMBtrans2
, /* cmd. */
1811 NULL
, /* pipe name. */
1815 &state
->setup
, /* setup. */
1816 1, /* num setup uint16_t words. */
1817 0, /* max returned setup. */
1818 state
->param
, /* param. */
1820 2, /* max returned param. */
1821 state
->data
, /* data. */
1823 0); /* max returned data. */
1825 if (tevent_req_nomem(subreq
, req
)) {
1826 return tevent_req_post(req
, ev
);
1828 tevent_req_set_callback(subreq
, cli_nt_delete_on_close_done
, req
);
1832 NTSTATUS
cli_nt_delete_on_close_recv(struct tevent_req
*req
)
1834 return tevent_req_simple_recv_ntstatus(req
);
1837 NTSTATUS
cli_nt_delete_on_close(struct cli_state
*cli
, uint16_t fnum
, bool flag
)
1839 TALLOC_CTX
*frame
= talloc_stackframe();
1840 struct event_context
*ev
= NULL
;
1841 struct tevent_req
*req
= NULL
;
1842 NTSTATUS status
= NT_STATUS_OK
;
1844 if (cli_has_async_calls(cli
)) {
1846 * Can't use sync call while an async call is in flight
1848 status
= NT_STATUS_INVALID_PARAMETER
;
1852 ev
= event_context_init(frame
);
1854 status
= NT_STATUS_NO_MEMORY
;
1858 req
= cli_nt_delete_on_close_send(frame
,
1864 status
= NT_STATUS_NO_MEMORY
;
1868 if (!tevent_req_poll(req
, ev
)) {
1869 status
= map_nt_error_from_unix(errno
);
1873 status
= cli_nt_delete_on_close_recv(req
);
1877 if (!NT_STATUS_IS_OK(status
)) {
1878 cli_set_error(cli
, status
);
1883 struct cli_ntcreate_state
{
1888 static void cli_ntcreate_done(struct tevent_req
*subreq
);
1890 struct tevent_req
*cli_ntcreate_send(TALLOC_CTX
*mem_ctx
,
1891 struct event_context
*ev
,
1892 struct cli_state
*cli
,
1894 uint32_t CreatFlags
,
1895 uint32_t DesiredAccess
,
1896 uint32_t FileAttributes
,
1897 uint32_t ShareAccess
,
1898 uint32_t CreateDisposition
,
1899 uint32_t CreateOptions
,
1900 uint8_t SecurityFlags
)
1902 struct tevent_req
*req
, *subreq
;
1903 struct cli_ntcreate_state
*state
;
1906 size_t converted_len
;
1908 req
= tevent_req_create(mem_ctx
, &state
, struct cli_ntcreate_state
);
1915 SCVAL(vwv
+0, 0, 0xFF);
1920 if (cli
->use_oplocks
) {
1921 CreatFlags
|= (REQUEST_OPLOCK
|REQUEST_BATCH_OPLOCK
);
1923 SIVAL(vwv
+3, 1, CreatFlags
);
1924 SIVAL(vwv
+5, 1, 0x0); /* RootDirectoryFid */
1925 SIVAL(vwv
+7, 1, DesiredAccess
);
1926 SIVAL(vwv
+9, 1, 0x0); /* AllocationSize */
1927 SIVAL(vwv
+11, 1, 0x0); /* AllocationSize */
1928 SIVAL(vwv
+13, 1, FileAttributes
);
1929 SIVAL(vwv
+15, 1, ShareAccess
);
1930 SIVAL(vwv
+17, 1, CreateDisposition
);
1931 SIVAL(vwv
+19, 1, CreateOptions
);
1932 SIVAL(vwv
+21, 1, 0x02); /* ImpersonationLevel */
1933 SCVAL(vwv
+23, 1, SecurityFlags
);
1935 bytes
= talloc_array(state
, uint8_t, 0);
1936 bytes
= smb_bytes_push_str(bytes
, cli_ucs2(cli
),
1937 fname
, strlen(fname
)+1,
1940 /* sigh. this copes with broken netapp filer behaviour */
1941 bytes
= smb_bytes_push_str(bytes
, cli_ucs2(cli
), "", 1, NULL
);
1943 if (tevent_req_nomem(bytes
, req
)) {
1944 return tevent_req_post(req
, ev
);
1947 SSVAL(vwv
+2, 1, converted_len
);
1949 subreq
= cli_smb_send(state
, ev
, cli
, SMBntcreateX
, 0, 24, vwv
,
1950 talloc_get_size(bytes
), bytes
);
1951 if (tevent_req_nomem(subreq
, req
)) {
1952 return tevent_req_post(req
, ev
);
1954 tevent_req_set_callback(subreq
, cli_ntcreate_done
, req
);
1958 static void cli_ntcreate_done(struct tevent_req
*subreq
)
1960 struct tevent_req
*req
= tevent_req_callback_data(
1961 subreq
, struct tevent_req
);
1962 struct cli_ntcreate_state
*state
= tevent_req_data(
1963 req
, struct cli_ntcreate_state
);
1971 status
= cli_smb_recv(subreq
, state
, &inbuf
, 3, &wct
, &vwv
,
1972 &num_bytes
, &bytes
);
1973 TALLOC_FREE(subreq
);
1974 if (tevent_req_nterror(req
, status
)) {
1977 state
->fnum
= SVAL(vwv
+2, 1);
1978 tevent_req_done(req
);
1981 NTSTATUS
cli_ntcreate_recv(struct tevent_req
*req
, uint16_t *pfnum
)
1983 struct cli_ntcreate_state
*state
= tevent_req_data(
1984 req
, struct cli_ntcreate_state
);
1987 if (tevent_req_is_nterror(req
, &status
)) {
1990 *pfnum
= state
->fnum
;
1991 return NT_STATUS_OK
;
1994 NTSTATUS
cli_ntcreate(struct cli_state
*cli
,
1996 uint32_t CreatFlags
,
1997 uint32_t DesiredAccess
,
1998 uint32_t FileAttributes
,
1999 uint32_t ShareAccess
,
2000 uint32_t CreateDisposition
,
2001 uint32_t CreateOptions
,
2002 uint8_t SecurityFlags
,
2005 TALLOC_CTX
*frame
= talloc_stackframe();
2006 struct event_context
*ev
;
2007 struct tevent_req
*req
;
2008 NTSTATUS status
= NT_STATUS_OK
;
2010 if (cli_has_async_calls(cli
)) {
2012 * Can't use sync call while an async call is in flight
2014 status
= NT_STATUS_INVALID_PARAMETER
;
2018 ev
= event_context_init(frame
);
2020 status
= NT_STATUS_NO_MEMORY
;
2024 req
= cli_ntcreate_send(frame
, ev
, cli
, fname
, CreatFlags
,
2025 DesiredAccess
, FileAttributes
, ShareAccess
,
2026 CreateDisposition
, CreateOptions
,
2029 status
= NT_STATUS_NO_MEMORY
;
2033 if (!tevent_req_poll(req
, ev
)) {
2034 status
= map_nt_error_from_unix(errno
);
2038 status
= cli_ntcreate_recv(req
, pfid
);
2041 if (!NT_STATUS_IS_OK(status
)) {
2042 cli_set_error(cli
, status
);
2047 /****************************************************************************
2049 WARNING: if you open with O_WRONLY then getattrE won't work!
2050 ****************************************************************************/
2052 struct cli_open_state
{
2058 static void cli_open_done(struct tevent_req
*subreq
);
2060 struct tevent_req
*cli_open_create(TALLOC_CTX
*mem_ctx
,
2061 struct event_context
*ev
,
2062 struct cli_state
*cli
, const char *fname
,
2063 int flags
, int share_mode
,
2064 struct tevent_req
**psmbreq
)
2066 struct tevent_req
*req
, *subreq
;
2067 struct cli_open_state
*state
;
2069 unsigned accessmode
;
2070 uint8_t additional_flags
;
2073 req
= tevent_req_create(mem_ctx
, &state
, struct cli_open_state
);
2079 if (flags
& O_CREAT
) {
2082 if (!(flags
& O_EXCL
)) {
2083 if (flags
& O_TRUNC
)
2089 accessmode
= (share_mode
<<4);
2091 if ((flags
& O_ACCMODE
) == O_RDWR
) {
2093 } else if ((flags
& O_ACCMODE
) == O_WRONLY
) {
2098 if ((flags
& O_SYNC
) == O_SYNC
) {
2099 accessmode
|= (1<<14);
2103 if (share_mode
== DENY_FCB
) {
2107 SCVAL(state
->vwv
+ 0, 0, 0xFF);
2108 SCVAL(state
->vwv
+ 0, 1, 0);
2109 SSVAL(state
->vwv
+ 1, 0, 0);
2110 SSVAL(state
->vwv
+ 2, 0, 0); /* no additional info */
2111 SSVAL(state
->vwv
+ 3, 0, accessmode
);
2112 SSVAL(state
->vwv
+ 4, 0, FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
);
2113 SSVAL(state
->vwv
+ 5, 0, 0);
2114 SIVAL(state
->vwv
+ 6, 0, 0);
2115 SSVAL(state
->vwv
+ 8, 0, openfn
);
2116 SIVAL(state
->vwv
+ 9, 0, 0);
2117 SIVAL(state
->vwv
+ 11, 0, 0);
2118 SIVAL(state
->vwv
+ 13, 0, 0);
2120 additional_flags
= 0;
2122 if (cli
->use_oplocks
) {
2123 /* if using oplocks then ask for a batch oplock via
2124 core and extended methods */
2126 FLAG_REQUEST_OPLOCK
|FLAG_REQUEST_BATCH_OPLOCK
;
2127 SSVAL(state
->vwv
+2, 0, SVAL(state
->vwv
+2, 0) | 6);
2130 bytes
= talloc_array(state
, uint8_t, 0);
2131 bytes
= smb_bytes_push_str(bytes
, cli_ucs2(cli
), fname
,
2132 strlen(fname
)+1, NULL
);
2134 if (tevent_req_nomem(bytes
, req
)) {
2135 return tevent_req_post(req
, ev
);
2138 state
->bytes
.iov_base
= (void *)bytes
;
2139 state
->bytes
.iov_len
= talloc_get_size(bytes
);
2141 subreq
= cli_smb_req_create(state
, ev
, cli
, SMBopenX
, additional_flags
,
2142 15, state
->vwv
, 1, &state
->bytes
);
2143 if (subreq
== NULL
) {
2147 tevent_req_set_callback(subreq
, cli_open_done
, req
);
2152 struct tevent_req
*cli_open_send(TALLOC_CTX
*mem_ctx
, struct event_context
*ev
,
2153 struct cli_state
*cli
, const char *fname
,
2154 int flags
, int share_mode
)
2156 struct tevent_req
*req
, *subreq
;
2159 req
= cli_open_create(mem_ctx
, ev
, cli
, fname
, flags
, share_mode
,
2165 status
= cli_smb_req_send(subreq
);
2166 if (tevent_req_nterror(req
, status
)) {
2167 return tevent_req_post(req
, ev
);
2172 static void cli_open_done(struct tevent_req
*subreq
)
2174 struct tevent_req
*req
= tevent_req_callback_data(
2175 subreq
, struct tevent_req
);
2176 struct cli_open_state
*state
= tevent_req_data(
2177 req
, struct cli_open_state
);
2183 status
= cli_smb_recv(subreq
, state
, &inbuf
, 3, &wct
, &vwv
, NULL
,
2185 TALLOC_FREE(subreq
);
2186 if (tevent_req_nterror(req
, status
)) {
2189 state
->fnum
= SVAL(vwv
+2, 0);
2190 tevent_req_done(req
);
2193 NTSTATUS
cli_open_recv(struct tevent_req
*req
, uint16_t *pfnum
)
2195 struct cli_open_state
*state
= tevent_req_data(
2196 req
, struct cli_open_state
);
2199 if (tevent_req_is_nterror(req
, &status
)) {
2202 *pfnum
= state
->fnum
;
2203 return NT_STATUS_OK
;
2206 NTSTATUS
cli_open(struct cli_state
*cli
, const char *fname
, int flags
,
2207 int share_mode
, uint16_t *pfnum
)
2209 TALLOC_CTX
*frame
= talloc_stackframe();
2210 struct event_context
*ev
;
2211 struct tevent_req
*req
;
2212 NTSTATUS status
= NT_STATUS_OK
;
2214 if (cli_has_async_calls(cli
)) {
2216 * Can't use sync call while an async call is in flight
2218 status
= NT_STATUS_INVALID_PARAMETER
;
2222 ev
= event_context_init(frame
);
2224 status
= NT_STATUS_NO_MEMORY
;
2228 req
= cli_open_send(frame
, ev
, cli
, fname
, flags
, share_mode
);
2230 status
= NT_STATUS_NO_MEMORY
;
2234 if (!tevent_req_poll(req
, ev
)) {
2235 status
= map_nt_error_from_unix(errno
);
2239 status
= cli_open_recv(req
, pfnum
);
2242 if (!NT_STATUS_IS_OK(status
)) {
2243 cli_set_error(cli
, status
);
2248 /****************************************************************************
2250 ****************************************************************************/
2252 struct cli_close_state
{
2256 static void cli_close_done(struct tevent_req
*subreq
);
2258 struct tevent_req
*cli_close_create(TALLOC_CTX
*mem_ctx
,
2259 struct event_context
*ev
,
2260 struct cli_state
*cli
,
2262 struct tevent_req
**psubreq
)
2264 struct tevent_req
*req
, *subreq
;
2265 struct cli_close_state
*state
;
2267 req
= tevent_req_create(mem_ctx
, &state
, struct cli_close_state
);
2272 SSVAL(state
->vwv
+0, 0, fnum
);
2273 SIVALS(state
->vwv
+1, 0, -1);
2275 subreq
= cli_smb_req_create(state
, ev
, cli
, SMBclose
, 0, 3, state
->vwv
,
2277 if (subreq
== NULL
) {
2281 tevent_req_set_callback(subreq
, cli_close_done
, req
);
2286 struct tevent_req
*cli_close_send(TALLOC_CTX
*mem_ctx
,
2287 struct event_context
*ev
,
2288 struct cli_state
*cli
,
2291 struct tevent_req
*req
, *subreq
;
2294 req
= cli_close_create(mem_ctx
, ev
, cli
, fnum
, &subreq
);
2299 status
= cli_smb_req_send(subreq
);
2300 if (tevent_req_nterror(req
, status
)) {
2301 return tevent_req_post(req
, ev
);
2306 static void cli_close_done(struct tevent_req
*subreq
)
2308 struct tevent_req
*req
= tevent_req_callback_data(
2309 subreq
, struct tevent_req
);
2312 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
2313 TALLOC_FREE(subreq
);
2314 if (tevent_req_nterror(req
, status
)) {
2317 tevent_req_done(req
);
2320 NTSTATUS
cli_close_recv(struct tevent_req
*req
)
2322 return tevent_req_simple_recv_ntstatus(req
);
2325 NTSTATUS
cli_close(struct cli_state
*cli
, uint16_t fnum
)
2327 TALLOC_CTX
*frame
= talloc_stackframe();
2328 struct event_context
*ev
;
2329 struct tevent_req
*req
;
2330 NTSTATUS status
= NT_STATUS_OK
;
2332 if (cli_has_async_calls(cli
)) {
2334 * Can't use sync call while an async call is in flight
2336 status
= NT_STATUS_INVALID_PARAMETER
;
2340 ev
= event_context_init(frame
);
2342 status
= NT_STATUS_NO_MEMORY
;
2346 req
= cli_close_send(frame
, ev
, cli
, fnum
);
2348 status
= NT_STATUS_NO_MEMORY
;
2352 if (!tevent_req_poll(req
, ev
)) {
2353 status
= map_nt_error_from_unix(errno
);
2357 status
= cli_close_recv(req
);
2360 if (!NT_STATUS_IS_OK(status
)) {
2361 cli_set_error(cli
, status
);
2366 /****************************************************************************
2367 Truncate a file to a specified size
2368 ****************************************************************************/
2370 struct ftrunc_state
{
2376 static void cli_ftruncate_done(struct tevent_req
*subreq
)
2378 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, NULL
, 0, NULL
,
2379 NULL
, 0, NULL
, NULL
, 0, NULL
);
2380 tevent_req_simple_finish_ntstatus(subreq
, status
);
2383 struct tevent_req
*cli_ftruncate_send(TALLOC_CTX
*mem_ctx
,
2384 struct event_context
*ev
,
2385 struct cli_state
*cli
,
2389 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
2390 struct ftrunc_state
*state
= NULL
;
2392 req
= tevent_req_create(mem_ctx
, &state
, struct ftrunc_state
);
2397 /* Setup setup word. */
2398 SSVAL(&state
->setup
, 0, TRANSACT2_SETFILEINFO
);
2400 /* Setup param array. */
2401 SSVAL(state
->param
,0,fnum
);
2402 SSVAL(state
->param
,2,SMB_SET_FILE_END_OF_FILE_INFO
);
2403 SSVAL(state
->param
,4,0);
2405 /* Setup data array. */
2406 SBVAL(state
->data
, 0, size
);
2408 subreq
= cli_trans_send(state
, /* mem ctx. */
2409 ev
, /* event ctx. */
2410 cli
, /* cli_state. */
2411 SMBtrans2
, /* cmd. */
2412 NULL
, /* pipe name. */
2416 &state
->setup
, /* setup. */
2417 1, /* num setup uint16_t words. */
2418 0, /* max returned setup. */
2419 state
->param
, /* param. */
2421 2, /* max returned param. */
2422 state
->data
, /* data. */
2424 0); /* max returned data. */
2426 if (tevent_req_nomem(subreq
, req
)) {
2427 return tevent_req_post(req
, ev
);
2429 tevent_req_set_callback(subreq
, cli_ftruncate_done
, req
);
2433 NTSTATUS
cli_ftruncate_recv(struct tevent_req
*req
)
2435 return tevent_req_simple_recv_ntstatus(req
);
2438 NTSTATUS
cli_ftruncate(struct cli_state
*cli
, uint16_t fnum
, uint64_t size
)
2440 TALLOC_CTX
*frame
= talloc_stackframe();
2441 struct event_context
*ev
= NULL
;
2442 struct tevent_req
*req
= NULL
;
2443 NTSTATUS status
= NT_STATUS_OK
;
2445 if (cli_has_async_calls(cli
)) {
2447 * Can't use sync call while an async call is in flight
2449 status
= NT_STATUS_INVALID_PARAMETER
;
2453 ev
= event_context_init(frame
);
2455 status
= NT_STATUS_NO_MEMORY
;
2459 req
= cli_ftruncate_send(frame
,
2465 status
= NT_STATUS_NO_MEMORY
;
2469 if (!tevent_req_poll(req
, ev
)) {
2470 status
= map_nt_error_from_unix(errno
);
2474 status
= cli_ftruncate_recv(req
);
2478 if (!NT_STATUS_IS_OK(status
)) {
2479 cli_set_error(cli
, status
);
2484 /****************************************************************************
2485 send a lock with a specified locktype
2486 this is used for testing LOCKING_ANDX_CANCEL_LOCK
2487 ****************************************************************************/
2489 NTSTATUS
cli_locktype(struct cli_state
*cli
, uint16_t fnum
,
2490 uint32_t offset
, uint32_t len
,
2491 int timeout
, unsigned char locktype
)
2498 SCVAL(vwv
+ 0, 0, 0xff);
2499 SCVAL(vwv
+ 0, 1, 0);
2500 SSVAL(vwv
+ 1, 0, 0);
2501 SSVAL(vwv
+ 2, 0, fnum
);
2502 SCVAL(vwv
+ 3, 0, locktype
);
2503 SCVAL(vwv
+ 3, 1, 0);
2504 SIVALS(vwv
+ 4, 0, timeout
);
2505 SSVAL(vwv
+ 6, 0, 0);
2506 SSVAL(vwv
+ 7, 0, 1);
2508 SSVAL(bytes
, 0, cli
->pid
);
2509 SIVAL(bytes
, 2, offset
);
2510 SIVAL(bytes
, 6, len
);
2512 saved_timeout
= cli
->timeout
;
2515 cli
->timeout
= (timeout
== -1)
2516 ? 0x7FFFFFFF : (timeout
+ 2*1000);
2519 status
= cli_smb(talloc_tos(), cli
, SMBlockingX
, 0, 8, vwv
,
2520 10, bytes
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
2522 cli
->timeout
= saved_timeout
;
2527 /****************************************************************************
2529 note that timeout is in units of 2 milliseconds
2530 ****************************************************************************/
2532 bool cli_lock(struct cli_state
*cli
, uint16_t fnum
,
2533 uint32_t offset
, uint32_t len
, int timeout
,
2534 enum brl_type lock_type
)
2538 status
= cli_locktype(cli
, fnum
, offset
, len
, timeout
,
2539 (lock_type
== READ_LOCK
? 1 : 0));
2540 cli_set_error(cli
, status
);
2541 return NT_STATUS_IS_OK(status
);
2544 /****************************************************************************
2546 ****************************************************************************/
2548 struct cli_unlock_state
{
2553 static void cli_unlock_done(struct tevent_req
*subreq
);
2555 struct tevent_req
*cli_unlock_send(TALLOC_CTX
*mem_ctx
,
2556 struct event_context
*ev
,
2557 struct cli_state
*cli
,
2563 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
2564 struct cli_unlock_state
*state
= NULL
;
2565 uint8_t additional_flags
= 0;
2567 req
= tevent_req_create(mem_ctx
, &state
, struct cli_unlock_state
);
2572 SCVAL(state
->vwv
+0, 0, 0xFF);
2573 SSVAL(state
->vwv
+2, 0, fnum
);
2574 SCVAL(state
->vwv
+3, 0, 0);
2575 SIVALS(state
->vwv
+4, 0, 0);
2576 SSVAL(state
->vwv
+6, 0, 1);
2577 SSVAL(state
->vwv
+7, 0, 0);
2579 SSVAL(state
->data
, 0, cli
->pid
);
2580 SIVAL(state
->data
, 2, offset
);
2581 SIVAL(state
->data
, 6, len
);
2583 subreq
= cli_smb_send(state
, ev
, cli
, SMBlockingX
, additional_flags
,
2584 8, state
->vwv
, 10, state
->data
);
2585 if (tevent_req_nomem(subreq
, req
)) {
2586 return tevent_req_post(req
, ev
);
2588 tevent_req_set_callback(subreq
, cli_unlock_done
, req
);
2592 static void cli_unlock_done(struct tevent_req
*subreq
)
2594 struct tevent_req
*req
= tevent_req_callback_data(
2595 subreq
, struct tevent_req
);
2598 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
2599 TALLOC_FREE(subreq
);
2600 if (tevent_req_nterror(req
, status
)) {
2603 tevent_req_done(req
);
2606 NTSTATUS
cli_unlock_recv(struct tevent_req
*req
)
2608 return tevent_req_simple_recv_ntstatus(req
);
2611 NTSTATUS
cli_unlock(struct cli_state
*cli
,
2616 TALLOC_CTX
*frame
= talloc_stackframe();
2617 struct event_context
*ev
;
2618 struct tevent_req
*req
;
2619 NTSTATUS status
= NT_STATUS_OK
;
2621 if (cli_has_async_calls(cli
)) {
2623 * Can't use sync call while an async call is in flight
2625 status
= NT_STATUS_INVALID_PARAMETER
;
2629 ev
= event_context_init(frame
);
2631 status
= NT_STATUS_NO_MEMORY
;
2635 req
= cli_unlock_send(frame
, ev
, cli
,
2638 status
= NT_STATUS_NO_MEMORY
;
2642 if (!tevent_req_poll(req
, ev
)) {
2643 status
= map_nt_error_from_unix(errno
);
2647 status
= cli_unlock_recv(req
);
2651 if (!NT_STATUS_IS_OK(status
)) {
2652 cli_set_error(cli
, status
);
2657 /****************************************************************************
2658 Lock a file with 64 bit offsets.
2659 ****************************************************************************/
2661 bool cli_lock64(struct cli_state
*cli
, uint16_t fnum
,
2662 uint64_t offset
, uint64_t len
, int timeout
,
2663 enum brl_type lock_type
)
2667 int saved_timeout
= cli
->timeout
;
2671 if (! (cli
->capabilities
& CAP_LARGE_FILES
)) {
2672 return cli_lock(cli
, fnum
, offset
, len
, timeout
, lock_type
);
2675 ltype
= (lock_type
== READ_LOCK
? 1 : 0);
2676 ltype
|= LOCKING_ANDX_LARGE_FILES
;
2678 SCVAL(vwv
+ 0, 0, 0xff);
2679 SCVAL(vwv
+ 0, 1, 0);
2680 SSVAL(vwv
+ 1, 0, 0);
2681 SSVAL(vwv
+ 2, 0, fnum
);
2682 SCVAL(vwv
+ 3, 0, ltype
);
2683 SCVAL(vwv
+ 3, 1, 0);
2684 SIVALS(vwv
+ 4, 0, timeout
);
2685 SSVAL(vwv
+ 6, 0, 0);
2686 SSVAL(vwv
+ 7, 0, 1);
2688 SIVAL(bytes
, 0, cli
->pid
);
2689 SOFF_T_R(bytes
, 4, offset
);
2690 SOFF_T_R(bytes
, 12, len
);
2692 saved_timeout
= cli
->timeout
;
2695 cli
->timeout
= (timeout
== -1)
2696 ? 0x7FFFFFFF : (timeout
+ 2*1000);
2699 status
= cli_smb(talloc_tos(), cli
, SMBlockingX
, 0, 8, vwv
,
2700 20, bytes
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
2702 cli
->timeout
= saved_timeout
;
2704 cli_set_error(cli
, status
);
2705 return NT_STATUS_IS_OK(status
);
2708 /****************************************************************************
2709 Unlock a file with 64 bit offsets.
2710 ****************************************************************************/
2712 struct cli_unlock64_state
{
2717 static void cli_unlock64_done(struct tevent_req
*subreq
);
2719 struct tevent_req
*cli_unlock64_send(TALLOC_CTX
*mem_ctx
,
2720 struct event_context
*ev
,
2721 struct cli_state
*cli
,
2727 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
2728 struct cli_unlock64_state
*state
= NULL
;
2729 uint8_t additional_flags
= 0;
2731 req
= tevent_req_create(mem_ctx
, &state
, struct cli_unlock64_state
);
2736 SCVAL(state
->vwv
+0, 0, 0xff);
2737 SSVAL(state
->vwv
+2, 0, fnum
);
2738 SCVAL(state
->vwv
+3, 0,LOCKING_ANDX_LARGE_FILES
);
2739 SIVALS(state
->vwv
+4, 0, 0);
2740 SSVAL(state
->vwv
+6, 0, 1);
2741 SSVAL(state
->vwv
+7, 0, 0);
2743 SIVAL(state
->data
, 0, cli
->pid
);
2744 SOFF_T_R(state
->data
, 4, offset
);
2745 SOFF_T_R(state
->data
, 12, len
);
2747 subreq
= cli_smb_send(state
, ev
, cli
, SMBlockingX
, additional_flags
,
2748 8, state
->vwv
, 20, state
->data
);
2749 if (tevent_req_nomem(subreq
, req
)) {
2750 return tevent_req_post(req
, ev
);
2752 tevent_req_set_callback(subreq
, cli_unlock64_done
, req
);
2756 static void cli_unlock64_done(struct tevent_req
*subreq
)
2758 struct tevent_req
*req
= tevent_req_callback_data(
2759 subreq
, struct tevent_req
);
2762 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
2763 TALLOC_FREE(subreq
);
2764 if (tevent_req_nterror(req
, status
)) {
2767 tevent_req_done(req
);
2770 NTSTATUS
cli_unlock64_recv(struct tevent_req
*req
)
2772 return tevent_req_simple_recv_ntstatus(req
);
2775 NTSTATUS
cli_unlock64(struct cli_state
*cli
,
2780 TALLOC_CTX
*frame
= talloc_stackframe();
2781 struct event_context
*ev
;
2782 struct tevent_req
*req
;
2783 NTSTATUS status
= NT_STATUS_OK
;
2785 if (! (cli
->capabilities
& CAP_LARGE_FILES
)) {
2786 return cli_unlock(cli
, fnum
, offset
, len
);
2789 if (cli_has_async_calls(cli
)) {
2791 * Can't use sync call while an async call is in flight
2793 status
= NT_STATUS_INVALID_PARAMETER
;
2797 ev
= event_context_init(frame
);
2799 status
= NT_STATUS_NO_MEMORY
;
2803 req
= cli_unlock64_send(frame
, ev
, cli
,
2806 status
= NT_STATUS_NO_MEMORY
;
2810 if (!tevent_req_poll(req
, ev
)) {
2811 status
= map_nt_error_from_unix(errno
);
2815 status
= cli_unlock64_recv(req
);
2819 if (!NT_STATUS_IS_OK(status
)) {
2820 cli_set_error(cli
, status
);
2825 /****************************************************************************
2826 Get/unlock a POSIX lock on a file - internal function.
2827 ****************************************************************************/
2829 struct posix_lock_state
{
2832 uint8_t data
[POSIX_LOCK_DATA_SIZE
];
2835 static void cli_posix_unlock_internal_done(struct tevent_req
*subreq
)
2837 NTSTATUS status
= cli_trans_recv(subreq
, NULL
, NULL
, NULL
, 0, NULL
,
2838 NULL
, 0, NULL
, NULL
, 0, NULL
);
2839 tevent_req_simple_finish_ntstatus(subreq
, status
);
2842 static struct tevent_req
*cli_posix_lock_internal_send(TALLOC_CTX
*mem_ctx
,
2843 struct event_context
*ev
,
2844 struct cli_state
*cli
,
2849 enum brl_type lock_type
)
2851 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
2852 struct posix_lock_state
*state
= NULL
;
2854 req
= tevent_req_create(mem_ctx
, &state
, struct posix_lock_state
);
2859 /* Setup setup word. */
2860 SSVAL(&state
->setup
, 0, TRANSACT2_SETFILEINFO
);
2862 /* Setup param array. */
2863 SSVAL(&state
->param
, 0, fnum
);
2864 SSVAL(&state
->param
, 2, SMB_SET_POSIX_LOCK
);
2866 /* Setup data array. */
2867 switch (lock_type
) {
2869 SSVAL(&state
->data
, POSIX_LOCK_TYPE_OFFSET
,
2870 POSIX_LOCK_TYPE_READ
);
2873 SSVAL(&state
->data
, POSIX_LOCK_TYPE_OFFSET
,
2874 POSIX_LOCK_TYPE_WRITE
);
2877 SSVAL(&state
->data
, POSIX_LOCK_TYPE_OFFSET
,
2878 POSIX_LOCK_TYPE_UNLOCK
);
2885 SSVAL(&state
->data
, POSIX_LOCK_FLAGS_OFFSET
,
2886 POSIX_LOCK_FLAG_WAIT
);
2888 SSVAL(state
->data
, POSIX_LOCK_FLAGS_OFFSET
,
2889 POSIX_LOCK_FLAG_NOWAIT
);
2892 SIVAL(&state
->data
, POSIX_LOCK_PID_OFFSET
, cli
->pid
);
2893 SOFF_T(&state
->data
, POSIX_LOCK_START_OFFSET
, offset
);
2894 SOFF_T(&state
->data
, POSIX_LOCK_LEN_OFFSET
, len
);
2896 subreq
= cli_trans_send(state
, /* mem ctx. */
2897 ev
, /* event ctx. */
2898 cli
, /* cli_state. */
2899 SMBtrans2
, /* cmd. */
2900 NULL
, /* pipe name. */
2904 &state
->setup
, /* setup. */
2905 1, /* num setup uint16_t words. */
2906 0, /* max returned setup. */
2907 state
->param
, /* param. */
2909 2, /* max returned param. */
2910 state
->data
, /* data. */
2911 POSIX_LOCK_DATA_SIZE
, /* num data. */
2912 0); /* max returned data. */
2914 if (tevent_req_nomem(subreq
, req
)) {
2915 return tevent_req_post(req
, ev
);
2917 tevent_req_set_callback(subreq
, cli_posix_unlock_internal_done
, req
);
2921 /****************************************************************************
2923 ****************************************************************************/
2925 struct tevent_req
*cli_posix_lock_send(TALLOC_CTX
*mem_ctx
,
2926 struct event_context
*ev
,
2927 struct cli_state
*cli
,
2932 enum brl_type lock_type
)
2934 return cli_posix_lock_internal_send(mem_ctx
, ev
, cli
, fnum
, offset
, len
,
2935 wait_lock
, lock_type
);
2938 NTSTATUS
cli_posix_lock_recv(struct tevent_req
*req
)
2940 return tevent_req_simple_recv_ntstatus(req
);
2943 NTSTATUS
cli_posix_lock(struct cli_state
*cli
, uint16_t fnum
,
2944 uint64_t offset
, uint64_t len
,
2945 bool wait_lock
, enum brl_type lock_type
)
2947 TALLOC_CTX
*frame
= talloc_stackframe();
2948 struct event_context
*ev
= NULL
;
2949 struct tevent_req
*req
= NULL
;
2950 NTSTATUS status
= NT_STATUS_OK
;
2952 if (cli_has_async_calls(cli
)) {
2954 * Can't use sync call while an async call is in flight
2956 status
= NT_STATUS_INVALID_PARAMETER
;
2960 if (lock_type
!= READ_LOCK
&& lock_type
!= WRITE_LOCK
) {
2961 status
= NT_STATUS_INVALID_PARAMETER
;
2965 ev
= event_context_init(frame
);
2967 status
= NT_STATUS_NO_MEMORY
;
2971 req
= cli_posix_lock_send(frame
,
2980 status
= NT_STATUS_NO_MEMORY
;
2984 if (!tevent_req_poll(req
, ev
)) {
2985 status
= map_nt_error_from_unix(errno
);
2989 status
= cli_posix_lock_recv(req
);
2993 if (!NT_STATUS_IS_OK(status
)) {
2994 cli_set_error(cli
, status
);
2999 /****************************************************************************
3000 POSIX Unlock a file.
3001 ****************************************************************************/
3003 struct tevent_req
*cli_posix_unlock_send(TALLOC_CTX
*mem_ctx
,
3004 struct event_context
*ev
,
3005 struct cli_state
*cli
,
3010 return cli_posix_lock_internal_send(mem_ctx
, ev
, cli
, fnum
, offset
, len
,
3011 false, UNLOCK_LOCK
);
3014 NTSTATUS
cli_posix_unlock_recv(struct tevent_req
*req
)
3016 return tevent_req_simple_recv_ntstatus(req
);
3019 NTSTATUS
cli_posix_unlock(struct cli_state
*cli
, uint16_t fnum
, uint64_t offset
, uint64_t len
)
3021 TALLOC_CTX
*frame
= talloc_stackframe();
3022 struct event_context
*ev
= NULL
;
3023 struct tevent_req
*req
= NULL
;
3024 NTSTATUS status
= NT_STATUS_OK
;
3026 if (cli_has_async_calls(cli
)) {
3028 * Can't use sync call while an async call is in flight
3030 status
= NT_STATUS_INVALID_PARAMETER
;
3034 ev
= event_context_init(frame
);
3036 status
= NT_STATUS_NO_MEMORY
;
3040 req
= cli_posix_unlock_send(frame
,
3047 status
= NT_STATUS_NO_MEMORY
;
3051 if (!tevent_req_poll(req
, ev
)) {
3052 status
= map_nt_error_from_unix(errno
);
3056 status
= cli_posix_unlock_recv(req
);
3060 if (!NT_STATUS_IS_OK(status
)) {
3061 cli_set_error(cli
, status
);
3066 /****************************************************************************
3067 Do a SMBgetattrE call.
3068 ****************************************************************************/
3070 static void cli_getattrE_done(struct tevent_req
*subreq
);
3072 struct cli_getattrE_state
{
3082 struct tevent_req
*cli_getattrE_send(TALLOC_CTX
*mem_ctx
,
3083 struct event_context
*ev
,
3084 struct cli_state
*cli
,
3087 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3088 struct cli_getattrE_state
*state
= NULL
;
3089 uint8_t additional_flags
= 0;
3091 req
= tevent_req_create(mem_ctx
, &state
, struct cli_getattrE_state
);
3096 state
->zone_offset
= cli
->serverzone
;
3097 SSVAL(state
->vwv
+0,0,fnum
);
3099 subreq
= cli_smb_send(state
, ev
, cli
, SMBgetattrE
, additional_flags
,
3100 1, state
->vwv
, 0, NULL
);
3101 if (tevent_req_nomem(subreq
, req
)) {
3102 return tevent_req_post(req
, ev
);
3104 tevent_req_set_callback(subreq
, cli_getattrE_done
, req
);
3108 static void cli_getattrE_done(struct tevent_req
*subreq
)
3110 struct tevent_req
*req
= tevent_req_callback_data(
3111 subreq
, struct tevent_req
);
3112 struct cli_getattrE_state
*state
= tevent_req_data(
3113 req
, struct cli_getattrE_state
);
3115 uint16_t *vwv
= NULL
;
3119 status
= cli_smb_recv(subreq
, state
, &inbuf
, 11, &wct
, &vwv
,
3121 TALLOC_FREE(subreq
);
3122 if (tevent_req_nterror(req
, status
)) {
3126 state
->size
= (SMB_OFF_T
)IVAL(vwv
+6,0);
3127 state
->attr
= SVAL(vwv
+10,0);
3128 state
->change_time
= make_unix_date2(vwv
+0, state
->zone_offset
);
3129 state
->access_time
= make_unix_date2(vwv
+2, state
->zone_offset
);
3130 state
->write_time
= make_unix_date2(vwv
+4, state
->zone_offset
);
3132 tevent_req_done(req
);
3135 NTSTATUS
cli_getattrE_recv(struct tevent_req
*req
,
3138 time_t *change_time
,
3139 time_t *access_time
,
3142 struct cli_getattrE_state
*state
= tevent_req_data(
3143 req
, struct cli_getattrE_state
);
3146 if (tevent_req_is_nterror(req
, &status
)) {
3150 *attr
= state
->attr
;
3153 *size
= state
->size
;
3156 *change_time
= state
->change_time
;
3159 *access_time
= state
->access_time
;
3162 *write_time
= state
->write_time
;
3164 return NT_STATUS_OK
;
3167 NTSTATUS
cli_getattrE(struct cli_state
*cli
,
3171 time_t *change_time
,
3172 time_t *access_time
,
3175 TALLOC_CTX
*frame
= talloc_stackframe();
3176 struct event_context
*ev
= NULL
;
3177 struct tevent_req
*req
= NULL
;
3178 NTSTATUS status
= NT_STATUS_OK
;
3180 if (cli_has_async_calls(cli
)) {
3182 * Can't use sync call while an async call is in flight
3184 status
= NT_STATUS_INVALID_PARAMETER
;
3188 ev
= event_context_init(frame
);
3190 status
= NT_STATUS_NO_MEMORY
;
3194 req
= cli_getattrE_send(frame
, ev
, cli
, fnum
);
3196 status
= NT_STATUS_NO_MEMORY
;
3200 if (!tevent_req_poll(req
, ev
)) {
3201 status
= map_nt_error_from_unix(errno
);
3205 status
= cli_getattrE_recv(req
,
3214 if (!NT_STATUS_IS_OK(status
)) {
3215 cli_set_error(cli
, status
);
3220 /****************************************************************************
3222 ****************************************************************************/
3224 static void cli_getatr_done(struct tevent_req
*subreq
);
3226 struct cli_getatr_state
{
3233 struct tevent_req
*cli_getatr_send(TALLOC_CTX
*mem_ctx
,
3234 struct event_context
*ev
,
3235 struct cli_state
*cli
,
3238 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3239 struct cli_getatr_state
*state
= NULL
;
3240 uint8_t additional_flags
= 0;
3241 uint8_t *bytes
= NULL
;
3243 req
= tevent_req_create(mem_ctx
, &state
, struct cli_getatr_state
);
3248 state
->zone_offset
= cli
->serverzone
;
3250 bytes
= talloc_array(state
, uint8_t, 1);
3251 if (tevent_req_nomem(bytes
, req
)) {
3252 return tevent_req_post(req
, ev
);
3255 bytes
= smb_bytes_push_str(bytes
, cli_ucs2(cli
), fname
,
3256 strlen(fname
)+1, NULL
);
3258 if (tevent_req_nomem(bytes
, req
)) {
3259 return tevent_req_post(req
, ev
);
3262 subreq
= cli_smb_send(state
, ev
, cli
, SMBgetatr
, additional_flags
,
3263 0, NULL
, talloc_get_size(bytes
), bytes
);
3264 if (tevent_req_nomem(subreq
, req
)) {
3265 return tevent_req_post(req
, ev
);
3267 tevent_req_set_callback(subreq
, cli_getatr_done
, req
);
3271 static void cli_getatr_done(struct tevent_req
*subreq
)
3273 struct tevent_req
*req
= tevent_req_callback_data(
3274 subreq
, struct tevent_req
);
3275 struct cli_getatr_state
*state
= tevent_req_data(
3276 req
, struct cli_getatr_state
);
3278 uint16_t *vwv
= NULL
;
3282 status
= cli_smb_recv(subreq
, state
, &inbuf
, 4, &wct
, &vwv
, NULL
,
3284 TALLOC_FREE(subreq
);
3285 if (tevent_req_nterror(req
, status
)) {
3289 state
->attr
= SVAL(vwv
+0,0);
3290 state
->size
= (SMB_OFF_T
)IVAL(vwv
+3,0);
3291 state
->write_time
= make_unix_date3(vwv
+1, state
->zone_offset
);
3293 tevent_req_done(req
);
3296 NTSTATUS
cli_getatr_recv(struct tevent_req
*req
,
3301 struct cli_getatr_state
*state
= tevent_req_data(
3302 req
, struct cli_getatr_state
);
3305 if (tevent_req_is_nterror(req
, &status
)) {
3309 *attr
= state
->attr
;
3312 *size
= state
->size
;
3315 *write_time
= state
->write_time
;
3317 return NT_STATUS_OK
;
3320 NTSTATUS
cli_getatr(struct cli_state
*cli
,
3326 TALLOC_CTX
*frame
= talloc_stackframe();
3327 struct event_context
*ev
= NULL
;
3328 struct tevent_req
*req
= NULL
;
3329 NTSTATUS status
= NT_STATUS_OK
;
3331 if (cli_has_async_calls(cli
)) {
3333 * Can't use sync call while an async call is in flight
3335 status
= NT_STATUS_INVALID_PARAMETER
;
3339 ev
= event_context_init(frame
);
3341 status
= NT_STATUS_NO_MEMORY
;
3345 req
= cli_getatr_send(frame
, ev
, cli
, fname
);
3347 status
= NT_STATUS_NO_MEMORY
;
3351 if (!tevent_req_poll(req
, ev
)) {
3352 status
= map_nt_error_from_unix(errno
);
3356 status
= cli_getatr_recv(req
,
3363 if (!NT_STATUS_IS_OK(status
)) {
3364 cli_set_error(cli
, status
);
3369 /****************************************************************************
3370 Do a SMBsetattrE call.
3371 ****************************************************************************/
3373 static void cli_setattrE_done(struct tevent_req
*subreq
);
3375 struct cli_setattrE_state
{
3379 struct tevent_req
*cli_setattrE_send(TALLOC_CTX
*mem_ctx
,
3380 struct event_context
*ev
,
3381 struct cli_state
*cli
,
3387 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3388 struct cli_setattrE_state
*state
= NULL
;
3389 uint8_t additional_flags
= 0;
3391 req
= tevent_req_create(mem_ctx
, &state
, struct cli_setattrE_state
);
3396 SSVAL(state
->vwv
+0, 0, fnum
);
3397 push_dos_date2((uint8_t *)&state
->vwv
[1], 0, change_time
,
3399 push_dos_date2((uint8_t *)&state
->vwv
[3], 0, access_time
,
3401 push_dos_date2((uint8_t *)&state
->vwv
[5], 0, write_time
,
3404 subreq
= cli_smb_send(state
, ev
, cli
, SMBsetattrE
, additional_flags
,
3405 7, state
->vwv
, 0, NULL
);
3406 if (tevent_req_nomem(subreq
, req
)) {
3407 return tevent_req_post(req
, ev
);
3409 tevent_req_set_callback(subreq
, cli_setattrE_done
, req
);
3413 static void cli_setattrE_done(struct tevent_req
*subreq
)
3415 struct tevent_req
*req
= tevent_req_callback_data(
3416 subreq
, struct tevent_req
);
3419 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
3420 TALLOC_FREE(subreq
);
3421 if (tevent_req_nterror(req
, status
)) {
3424 tevent_req_done(req
);
3427 NTSTATUS
cli_setattrE_recv(struct tevent_req
*req
)
3429 return tevent_req_simple_recv_ntstatus(req
);
3432 NTSTATUS
cli_setattrE(struct cli_state
*cli
,
3438 TALLOC_CTX
*frame
= talloc_stackframe();
3439 struct event_context
*ev
= NULL
;
3440 struct tevent_req
*req
= NULL
;
3441 NTSTATUS status
= NT_STATUS_OK
;
3443 if (cli_has_async_calls(cli
)) {
3445 * Can't use sync call while an async call is in flight
3447 status
= NT_STATUS_INVALID_PARAMETER
;
3451 ev
= event_context_init(frame
);
3453 status
= NT_STATUS_NO_MEMORY
;
3457 req
= cli_setattrE_send(frame
, ev
,
3465 status
= NT_STATUS_NO_MEMORY
;
3469 if (!tevent_req_poll(req
, ev
)) {
3470 status
= map_nt_error_from_unix(errno
);
3474 status
= cli_setattrE_recv(req
);
3478 if (!NT_STATUS_IS_OK(status
)) {
3479 cli_set_error(cli
, status
);
3484 /****************************************************************************
3485 Do a SMBsetatr call.
3486 ****************************************************************************/
3488 static void cli_setatr_done(struct tevent_req
*subreq
);
3490 struct cli_setatr_state
{
3494 struct tevent_req
*cli_setatr_send(TALLOC_CTX
*mem_ctx
,
3495 struct event_context
*ev
,
3496 struct cli_state
*cli
,
3501 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3502 struct cli_setatr_state
*state
= NULL
;
3503 uint8_t additional_flags
= 0;
3504 uint8_t *bytes
= NULL
;
3506 req
= tevent_req_create(mem_ctx
, &state
, struct cli_setatr_state
);
3511 SSVAL(state
->vwv
+0, 0, attr
);
3512 push_dos_date3((uint8_t *)&state
->vwv
[1], 0, mtime
, cli
->serverzone
);
3514 bytes
= talloc_array(state
, uint8_t, 1);
3515 if (tevent_req_nomem(bytes
, req
)) {
3516 return tevent_req_post(req
, ev
);
3519 bytes
= smb_bytes_push_str(bytes
, cli_ucs2(cli
), fname
,
3520 strlen(fname
)+1, NULL
);
3521 if (tevent_req_nomem(bytes
, req
)) {
3522 return tevent_req_post(req
, ev
);
3524 bytes
= TALLOC_REALLOC_ARRAY(state
, bytes
, uint8_t,
3525 talloc_get_size(bytes
)+1);
3526 if (tevent_req_nomem(bytes
, req
)) {
3527 return tevent_req_post(req
, ev
);
3530 bytes
[talloc_get_size(bytes
)-1] = 4;
3531 bytes
= smb_bytes_push_str(bytes
, cli_ucs2(cli
), "",
3533 if (tevent_req_nomem(bytes
, req
)) {
3534 return tevent_req_post(req
, ev
);
3537 subreq
= cli_smb_send(state
, ev
, cli
, SMBsetatr
, additional_flags
,
3538 8, state
->vwv
, talloc_get_size(bytes
), bytes
);
3539 if (tevent_req_nomem(subreq
, req
)) {
3540 return tevent_req_post(req
, ev
);
3542 tevent_req_set_callback(subreq
, cli_setatr_done
, req
);
3546 static void cli_setatr_done(struct tevent_req
*subreq
)
3548 struct tevent_req
*req
= tevent_req_callback_data(
3549 subreq
, struct tevent_req
);
3552 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
3553 TALLOC_FREE(subreq
);
3554 if (tevent_req_nterror(req
, status
)) {
3557 tevent_req_done(req
);
3560 NTSTATUS
cli_setatr_recv(struct tevent_req
*req
)
3562 return tevent_req_simple_recv_ntstatus(req
);
3565 NTSTATUS
cli_setatr(struct cli_state
*cli
,
3570 TALLOC_CTX
*frame
= talloc_stackframe();
3571 struct event_context
*ev
= NULL
;
3572 struct tevent_req
*req
= NULL
;
3573 NTSTATUS status
= NT_STATUS_OK
;
3575 if (cli_has_async_calls(cli
)) {
3577 * Can't use sync call while an async call is in flight
3579 status
= NT_STATUS_INVALID_PARAMETER
;
3583 ev
= event_context_init(frame
);
3585 status
= NT_STATUS_NO_MEMORY
;
3589 req
= cli_setatr_send(frame
, ev
, cli
, fname
, attr
, mtime
);
3591 status
= NT_STATUS_NO_MEMORY
;
3595 if (!tevent_req_poll(req
, ev
)) {
3596 status
= map_nt_error_from_unix(errno
);
3600 status
= cli_setatr_recv(req
);
3604 if (!NT_STATUS_IS_OK(status
)) {
3605 cli_set_error(cli
, status
);
3610 /****************************************************************************
3611 Check for existance of a dir.
3612 ****************************************************************************/
3614 static void cli_chkpath_done(struct tevent_req
*subreq
);
3616 struct cli_chkpath_state
{
3620 struct tevent_req
*cli_chkpath_send(TALLOC_CTX
*mem_ctx
,
3621 struct event_context
*ev
,
3622 struct cli_state
*cli
,
3625 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3626 struct cli_chkpath_state
*state
= NULL
;
3627 uint8_t additional_flags
= 0;
3628 uint8_t *bytes
= NULL
;
3630 req
= tevent_req_create(mem_ctx
, &state
, struct cli_chkpath_state
);
3635 bytes
= talloc_array(state
, uint8_t, 1);
3636 if (tevent_req_nomem(bytes
, req
)) {
3637 return tevent_req_post(req
, ev
);
3640 bytes
= smb_bytes_push_str(bytes
, cli_ucs2(cli
), fname
,
3641 strlen(fname
)+1, NULL
);
3643 if (tevent_req_nomem(bytes
, req
)) {
3644 return tevent_req_post(req
, ev
);
3647 subreq
= cli_smb_send(state
, ev
, cli
, SMBcheckpath
, additional_flags
,
3648 0, NULL
, talloc_get_size(bytes
), bytes
);
3649 if (tevent_req_nomem(subreq
, req
)) {
3650 return tevent_req_post(req
, ev
);
3652 tevent_req_set_callback(subreq
, cli_chkpath_done
, req
);
3656 static void cli_chkpath_done(struct tevent_req
*subreq
)
3658 struct tevent_req
*req
= tevent_req_callback_data(
3659 subreq
, struct tevent_req
);
3662 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
3663 TALLOC_FREE(subreq
);
3664 if (tevent_req_nterror(req
, status
)) {
3667 tevent_req_done(req
);
3670 NTSTATUS
cli_chkpath_recv(struct tevent_req
*req
)
3672 return tevent_req_simple_recv_ntstatus(req
);
3675 NTSTATUS
cli_chkpath(struct cli_state
*cli
, const char *path
)
3677 TALLOC_CTX
*frame
= talloc_stackframe();
3678 struct event_context
*ev
= NULL
;
3679 struct tevent_req
*req
= NULL
;
3681 NTSTATUS status
= NT_STATUS_OK
;
3683 if (cli_has_async_calls(cli
)) {
3685 * Can't use sync call while an async call is in flight
3687 status
= NT_STATUS_INVALID_PARAMETER
;
3691 path2
= talloc_strdup(frame
, path
);
3693 status
= NT_STATUS_NO_MEMORY
;
3696 trim_char(path2
,'\0','\\');
3698 path2
= talloc_strdup(frame
, "\\");
3700 status
= NT_STATUS_NO_MEMORY
;
3705 ev
= event_context_init(frame
);
3707 status
= NT_STATUS_NO_MEMORY
;
3711 req
= cli_chkpath_send(frame
, ev
, cli
, path2
);
3713 status
= NT_STATUS_NO_MEMORY
;
3717 if (!tevent_req_poll(req
, ev
)) {
3718 status
= map_nt_error_from_unix(errno
);
3722 status
= cli_chkpath_recv(req
);
3726 if (!NT_STATUS_IS_OK(status
)) {
3727 cli_set_error(cli
, status
);
3732 /****************************************************************************
3734 ****************************************************************************/
3736 static void cli_dskattr_done(struct tevent_req
*subreq
);
3738 struct cli_dskattr_state
{
3744 struct tevent_req
*cli_dskattr_send(TALLOC_CTX
*mem_ctx
,
3745 struct event_context
*ev
,
3746 struct cli_state
*cli
)
3748 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3749 struct cli_dskattr_state
*state
= NULL
;
3750 uint8_t additional_flags
= 0;
3752 req
= tevent_req_create(mem_ctx
, &state
, struct cli_dskattr_state
);
3757 subreq
= cli_smb_send(state
, ev
, cli
, SMBdskattr
, additional_flags
,
3759 if (tevent_req_nomem(subreq
, req
)) {
3760 return tevent_req_post(req
, ev
);
3762 tevent_req_set_callback(subreq
, cli_dskattr_done
, req
);
3766 static void cli_dskattr_done(struct tevent_req
*subreq
)
3768 struct tevent_req
*req
= tevent_req_callback_data(
3769 subreq
, struct tevent_req
);
3770 struct cli_dskattr_state
*state
= tevent_req_data(
3771 req
, struct cli_dskattr_state
);
3773 uint16_t *vwv
= NULL
;
3777 status
= cli_smb_recv(subreq
, state
, &inbuf
, 4, &wct
, &vwv
, NULL
,
3779 TALLOC_FREE(subreq
);
3780 if (tevent_req_nterror(req
, status
)) {
3783 state
->bsize
= SVAL(vwv
+1, 0)*SVAL(vwv
+2,0);
3784 state
->total
= SVAL(vwv
+0, 0);
3785 state
->avail
= SVAL(vwv
+3, 0);
3786 tevent_req_done(req
);
3789 NTSTATUS
cli_dskattr_recv(struct tevent_req
*req
, int *bsize
, int *total
, int *avail
)
3791 struct cli_dskattr_state
*state
= tevent_req_data(
3792 req
, struct cli_dskattr_state
);
3795 if (tevent_req_is_nterror(req
, &status
)) {
3798 *bsize
= state
->bsize
;
3799 *total
= state
->total
;
3800 *avail
= state
->avail
;
3801 return NT_STATUS_OK
;
3804 NTSTATUS
cli_dskattr(struct cli_state
*cli
, int *bsize
, int *total
, int *avail
)
3806 TALLOC_CTX
*frame
= talloc_stackframe();
3807 struct event_context
*ev
= NULL
;
3808 struct tevent_req
*req
= NULL
;
3809 NTSTATUS status
= NT_STATUS_OK
;
3811 if (cli_has_async_calls(cli
)) {
3813 * Can't use sync call while an async call is in flight
3815 status
= NT_STATUS_INVALID_PARAMETER
;
3819 ev
= event_context_init(frame
);
3821 status
= NT_STATUS_NO_MEMORY
;
3825 req
= cli_dskattr_send(frame
, ev
, cli
);
3827 status
= NT_STATUS_NO_MEMORY
;
3831 if (!tevent_req_poll(req
, ev
)) {
3832 status
= map_nt_error_from_unix(errno
);
3836 status
= cli_dskattr_recv(req
, bsize
, total
, avail
);
3840 if (!NT_STATUS_IS_OK(status
)) {
3841 cli_set_error(cli
, status
);
3846 /****************************************************************************
3847 Create and open a temporary file.
3848 ****************************************************************************/
3850 static void cli_ctemp_done(struct tevent_req
*subreq
);
3852 struct ctemp_state
{
3858 struct tevent_req
*cli_ctemp_send(TALLOC_CTX
*mem_ctx
,
3859 struct event_context
*ev
,
3860 struct cli_state
*cli
,
3863 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
3864 struct ctemp_state
*state
= NULL
;
3865 uint8_t additional_flags
= 0;
3866 uint8_t *bytes
= NULL
;
3868 req
= tevent_req_create(mem_ctx
, &state
, struct ctemp_state
);
3873 SSVAL(state
->vwv
,0,0);
3874 SIVALS(state
->vwv
+1,0,-1);
3876 bytes
= talloc_array(state
, uint8_t, 1);
3877 if (tevent_req_nomem(bytes
, req
)) {
3878 return tevent_req_post(req
, ev
);
3881 bytes
= smb_bytes_push_str(bytes
, cli_ucs2(cli
), path
,
3882 strlen(path
)+1, NULL
);
3883 if (tevent_req_nomem(bytes
, req
)) {
3884 return tevent_req_post(req
, ev
);
3887 subreq
= cli_smb_send(state
, ev
, cli
, SMBctemp
, additional_flags
,
3888 3, state
->vwv
, talloc_get_size(bytes
), bytes
);
3889 if (tevent_req_nomem(subreq
, req
)) {
3890 return tevent_req_post(req
, ev
);
3892 tevent_req_set_callback(subreq
, cli_ctemp_done
, req
);
3896 static void cli_ctemp_done(struct tevent_req
*subreq
)
3898 struct tevent_req
*req
= tevent_req_callback_data(
3899 subreq
, struct tevent_req
);
3900 struct ctemp_state
*state
= tevent_req_data(
3901 req
, struct ctemp_state
);
3905 uint32_t num_bytes
= 0;
3906 uint8_t *bytes
= NULL
;
3909 status
= cli_smb_recv(subreq
, state
, &inbuf
, 1, &wcnt
, &vwv
,
3910 &num_bytes
, &bytes
);
3911 TALLOC_FREE(subreq
);
3912 if (tevent_req_nterror(req
, status
)) {
3916 state
->fnum
= SVAL(vwv
+0, 0);
3918 /* From W2K3, the result is just the ASCII name */
3919 if (num_bytes
< 2) {
3920 tevent_req_nterror(req
, NT_STATUS_DATA_ERROR
);
3924 if (pull_string_talloc(state
,
3931 tevent_req_nterror(req
, NT_STATUS_NO_MEMORY
);
3934 tevent_req_done(req
);
3937 NTSTATUS
cli_ctemp_recv(struct tevent_req
*req
,
3942 struct ctemp_state
*state
= tevent_req_data(req
,
3943 struct ctemp_state
);
3946 if (tevent_req_is_nterror(req
, &status
)) {
3949 *pfnum
= state
->fnum
;
3950 *outfile
= talloc_strdup(ctx
, state
->ret_path
);
3952 return NT_STATUS_NO_MEMORY
;
3954 return NT_STATUS_OK
;
3957 NTSTATUS
cli_ctemp(struct cli_state
*cli
,
3963 TALLOC_CTX
*frame
= talloc_stackframe();
3964 struct event_context
*ev
;
3965 struct tevent_req
*req
;
3966 NTSTATUS status
= NT_STATUS_OK
;
3968 if (cli_has_async_calls(cli
)) {
3970 * Can't use sync call while an async call is in flight
3972 status
= NT_STATUS_INVALID_PARAMETER
;
3976 ev
= event_context_init(frame
);
3978 status
= NT_STATUS_NO_MEMORY
;
3982 req
= cli_ctemp_send(frame
, ev
, cli
, path
);
3984 status
= NT_STATUS_NO_MEMORY
;
3988 if (!tevent_req_poll(req
, ev
)) {
3989 status
= map_nt_error_from_unix(errno
);
3993 status
= cli_ctemp_recv(req
, ctx
, pfnum
, out_path
);
3997 if (!NT_STATUS_IS_OK(status
)) {
3998 cli_set_error(cli
, status
);
4004 send a raw ioctl - used by the torture code
4006 NTSTATUS
cli_raw_ioctl(struct cli_state
*cli
, uint16_t fnum
, uint32_t code
, DATA_BLOB
*blob
)
4011 SSVAL(vwv
+0, 0, fnum
);
4012 SSVAL(vwv
+1, 0, code
>>16);
4013 SSVAL(vwv
+2, 0, (code
&0xFFFF));
4015 status
= cli_smb(talloc_tos(), cli
, SMBioctl
, 0, 3, vwv
, 0, NULL
,
4016 NULL
, 0, NULL
, NULL
, NULL
, NULL
);
4017 if (!NT_STATUS_IS_OK(status
)) {
4020 *blob
= data_blob_null
;
4021 return NT_STATUS_OK
;
4024 /*********************************************************
4025 Set an extended attribute utility fn.
4026 *********************************************************/
4028 static NTSTATUS
cli_set_ea(struct cli_state
*cli
, uint16_t setup_val
,
4029 uint8_t *param
, unsigned int param_len
,
4030 const char *ea_name
,
4031 const char *ea_val
, size_t ea_len
)
4034 unsigned int data_len
= 0;
4035 uint8_t *data
= NULL
;
4037 size_t ea_namelen
= strlen(ea_name
);
4040 SSVAL(setup
, 0, setup_val
);
4042 if (ea_namelen
== 0 && ea_len
== 0) {
4044 data
= (uint8_t *)SMB_MALLOC(data_len
);
4046 return NT_STATUS_NO_MEMORY
;
4049 SIVAL(p
,0,data_len
);
4051 data_len
= 4 + 4 + ea_namelen
+ 1 + ea_len
;
4052 data
= (uint8_t *)SMB_MALLOC(data_len
);
4054 return NT_STATUS_NO_MEMORY
;
4057 SIVAL(p
,0,data_len
);
4059 SCVAL(p
, 0, 0); /* EA flags. */
4060 SCVAL(p
, 1, ea_namelen
);
4061 SSVAL(p
, 2, ea_len
);
4062 memcpy(p
+4, ea_name
, ea_namelen
+1); /* Copy in the name. */
4063 memcpy(p
+4+ea_namelen
+1, ea_val
, ea_len
);
4066 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
, NULL
, -1, 0, 0,
4068 param
, param_len
, 2,
4069 data
, data_len
, cli
->max_xmit
,
4071 NULL
, 0, NULL
, /* rsetup */
4072 NULL
, 0, NULL
, /* rparam */
4073 NULL
, 0, NULL
); /* rdata */
4078 /*********************************************************
4079 Set an extended attribute on a pathname.
4080 *********************************************************/
4082 NTSTATUS
cli_set_ea_path(struct cli_state
*cli
, const char *path
,
4083 const char *ea_name
, const char *ea_val
,
4086 unsigned int param_len
= 0;
4088 size_t srclen
= 2*(strlen(path
)+1);
4092 param
= SMB_MALLOC_ARRAY(uint8_t, 6+srclen
+2);
4094 return NT_STATUS_NO_MEMORY
;
4096 memset(param
, '\0', 6);
4097 SSVAL(param
,0,SMB_INFO_SET_EA
);
4098 p
= (char *)(¶m
[6]);
4100 p
+= clistr_push(cli
, p
, path
, srclen
, STR_TERMINATE
);
4101 param_len
= PTR_DIFF(p
, param
);
4103 status
= cli_set_ea(cli
, TRANSACT2_SETPATHINFO
, param
, param_len
,
4104 ea_name
, ea_val
, ea_len
);
4109 /*********************************************************
4110 Set an extended attribute on an fnum.
4111 *********************************************************/
4113 NTSTATUS
cli_set_ea_fnum(struct cli_state
*cli
, uint16_t fnum
,
4114 const char *ea_name
, const char *ea_val
,
4119 memset(param
, 0, 6);
4120 SSVAL(param
,0,fnum
);
4121 SSVAL(param
,2,SMB_INFO_SET_EA
);
4123 return cli_set_ea(cli
, TRANSACT2_SETFILEINFO
, param
, 6,
4124 ea_name
, ea_val
, ea_len
);
4127 /*********************************************************
4128 Get an extended attribute list utility fn.
4129 *********************************************************/
4131 static bool parse_ea_blob(TALLOC_CTX
*ctx
, const uint8_t *rdata
,
4133 size_t *pnum_eas
, struct ea_struct
**pea_list
)
4135 struct ea_struct
*ea_list
= NULL
;
4140 if (rdata_len
< 4) {
4144 ea_size
= (size_t)IVAL(rdata
,0);
4145 if (ea_size
> rdata_len
) {
4150 /* No EA's present. */
4159 /* Validate the EA list and count it. */
4160 for (num_eas
= 0; ea_size
>= 4; num_eas
++) {
4161 unsigned int ea_namelen
= CVAL(p
,1);
4162 unsigned int ea_valuelen
= SVAL(p
,2);
4163 if (ea_namelen
== 0) {
4166 if (4 + ea_namelen
+ 1 + ea_valuelen
> ea_size
) {
4169 ea_size
-= 4 + ea_namelen
+ 1 + ea_valuelen
;
4170 p
+= 4 + ea_namelen
+ 1 + ea_valuelen
;
4179 *pnum_eas
= num_eas
;
4181 /* Caller only wants number of EA's. */
4185 ea_list
= TALLOC_ARRAY(ctx
, struct ea_struct
, num_eas
);
4190 ea_size
= (size_t)IVAL(rdata
,0);
4193 for (num_eas
= 0; num_eas
< *pnum_eas
; num_eas
++ ) {
4194 struct ea_struct
*ea
= &ea_list
[num_eas
];
4195 fstring unix_ea_name
;
4196 unsigned int ea_namelen
= CVAL(p
,1);
4197 unsigned int ea_valuelen
= SVAL(p
,2);
4199 ea
->flags
= CVAL(p
,0);
4200 unix_ea_name
[0] = '\0';
4201 pull_ascii_fstring(unix_ea_name
, p
+ 4);
4202 ea
->name
= talloc_strdup(ea_list
, unix_ea_name
);
4206 /* Ensure the value is null terminated (in case it's a string). */
4207 ea
->value
= data_blob_talloc(ea_list
, NULL
, ea_valuelen
+ 1);
4208 if (!ea
->value
.data
) {
4212 memcpy(ea
->value
.data
, p
+4+ea_namelen
+1, ea_valuelen
);
4214 ea
->value
.data
[ea_valuelen
] = 0;
4216 p
+= 4 + ea_namelen
+ 1 + ea_valuelen
;
4219 *pea_list
= ea_list
;
4223 TALLOC_FREE(ea_list
);
4227 /*********************************************************
4228 Get an extended attribute list from a pathname.
4229 *********************************************************/
4231 struct cli_get_ea_list_path_state
{
4236 static void cli_get_ea_list_path_done(struct tevent_req
*subreq
);
4238 struct tevent_req
*cli_get_ea_list_path_send(TALLOC_CTX
*mem_ctx
,
4239 struct tevent_context
*ev
,
4240 struct cli_state
*cli
,
4243 struct tevent_req
*req
, *subreq
;
4244 struct cli_get_ea_list_path_state
*state
;
4246 req
= tevent_req_create(mem_ctx
, &state
,
4247 struct cli_get_ea_list_path_state
);
4251 subreq
= cli_qpathinfo_send(state
, ev
, cli
, fname
,
4252 SMB_INFO_QUERY_ALL_EAS
, 4,
4254 if (tevent_req_nomem(subreq
, req
)) {
4255 return tevent_req_post(req
, ev
);
4257 tevent_req_set_callback(subreq
, cli_get_ea_list_path_done
, req
);
4261 static void cli_get_ea_list_path_done(struct tevent_req
*subreq
)
4263 struct tevent_req
*req
= tevent_req_callback_data(
4264 subreq
, struct tevent_req
);
4265 struct cli_get_ea_list_path_state
*state
= tevent_req_data(
4266 req
, struct cli_get_ea_list_path_state
);
4269 status
= cli_qpathinfo_recv(subreq
, state
, &state
->data
,
4271 TALLOC_FREE(subreq
);
4272 if (tevent_req_nterror(req
, status
)) {
4275 tevent_req_done(req
);
4278 NTSTATUS
cli_get_ea_list_path_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
4279 size_t *pnum_eas
, struct ea_struct
**peas
)
4281 struct cli_get_ea_list_path_state
*state
= tevent_req_data(
4282 req
, struct cli_get_ea_list_path_state
);
4285 if (tevent_req_is_nterror(req
, &status
)) {
4288 if (!parse_ea_blob(mem_ctx
, state
->data
, state
->num_data
,
4290 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
4292 return NT_STATUS_OK
;
4295 NTSTATUS
cli_get_ea_list_path(struct cli_state
*cli
, const char *path
,
4298 struct ea_struct
**pea_list
)
4300 TALLOC_CTX
*frame
= talloc_stackframe();
4301 struct event_context
*ev
= NULL
;
4302 struct tevent_req
*req
= NULL
;
4303 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
4305 if (cli_has_async_calls(cli
)) {
4307 * Can't use sync call while an async call is in flight
4309 status
= NT_STATUS_INVALID_PARAMETER
;
4312 ev
= event_context_init(frame
);
4316 req
= cli_get_ea_list_path_send(frame
, ev
, cli
, path
);
4320 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
4323 status
= cli_get_ea_list_path_recv(req
, ctx
, pnum_eas
, pea_list
);
4326 if (!NT_STATUS_IS_OK(status
)) {
4327 cli_set_error(cli
, status
);
4332 /****************************************************************************
4333 Convert open "flags" arg to uint32_t on wire.
4334 ****************************************************************************/
4336 static uint32_t open_flags_to_wire(int flags
)
4338 int open_mode
= flags
& O_ACCMODE
;
4341 switch (open_mode
) {
4343 ret
|= SMB_O_WRONLY
;
4350 ret
|= SMB_O_RDONLY
;
4354 if (flags
& O_CREAT
) {
4357 if (flags
& O_EXCL
) {
4360 if (flags
& O_TRUNC
) {
4364 if (flags
& O_SYNC
) {
4368 if (flags
& O_APPEND
) {
4369 ret
|= SMB_O_APPEND
;
4371 #if defined(O_DIRECT)
4372 if (flags
& O_DIRECT
) {
4373 ret
|= SMB_O_DIRECT
;
4376 #if defined(O_DIRECTORY)
4377 if (flags
& O_DIRECTORY
) {
4378 ret
|= SMB_O_DIRECTORY
;
4384 /****************************************************************************
4385 Open a file - POSIX semantics. Returns fnum. Doesn't request oplock.
4386 ****************************************************************************/
4388 struct posix_open_state
{
4392 uint16_t fnum
; /* Out */
4395 static void cli_posix_open_internal_done(struct tevent_req
*subreq
)
4397 struct tevent_req
*req
= tevent_req_callback_data(
4398 subreq
, struct tevent_req
);
4399 struct posix_open_state
*state
= tevent_req_data(req
, struct posix_open_state
);
4404 status
= cli_trans_recv(subreq
, state
, NULL
, NULL
, 0, NULL
,
4405 NULL
, 0, NULL
, &data
, 12, &num_data
);
4406 TALLOC_FREE(subreq
);
4407 if (tevent_req_nterror(req
, status
)) {
4410 state
->fnum
= SVAL(data
,2);
4411 tevent_req_done(req
);
4414 static struct tevent_req
*cli_posix_open_internal_send(TALLOC_CTX
*mem_ctx
,
4415 struct event_context
*ev
,
4416 struct cli_state
*cli
,
4422 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
4423 struct posix_open_state
*state
= NULL
;
4424 uint32_t wire_flags
= open_flags_to_wire(flags
);
4426 req
= tevent_req_create(mem_ctx
, &state
, struct posix_open_state
);
4431 /* Setup setup word. */
4432 SSVAL(&state
->setup
, 0, TRANSACT2_SETPATHINFO
);
4434 /* Setup param array. */
4435 state
->param
= talloc_array(state
, uint8_t, 6);
4436 if (tevent_req_nomem(state
->param
, req
)) {
4437 return tevent_req_post(req
, ev
);
4439 memset(state
->param
, '\0', 6);
4440 SSVAL(state
->param
, 0, SMB_POSIX_PATH_OPEN
);
4442 state
->param
= trans2_bytes_push_str(state
->param
, cli_ucs2(cli
), fname
,
4443 strlen(fname
)+1, NULL
);
4445 if (tevent_req_nomem(state
->param
, req
)) {
4446 return tevent_req_post(req
, ev
);
4449 /* Setup data words. */
4451 wire_flags
|= SMB_O_DIRECTORY
;
4454 SIVAL(state
->data
,0,0); /* No oplock. */
4455 SIVAL(state
->data
,4,wire_flags
);
4456 SIVAL(state
->data
,8,unix_perms_to_wire(mode
));
4457 SIVAL(state
->data
,12,0); /* Top bits of perms currently undefined. */
4458 SSVAL(state
->data
,16,SMB_NO_INFO_LEVEL_RETURNED
); /* No info level returned. */
4460 subreq
= cli_trans_send(state
, /* mem ctx. */
4461 ev
, /* event ctx. */
4462 cli
, /* cli_state. */
4463 SMBtrans2
, /* cmd. */
4464 NULL
, /* pipe name. */
4468 &state
->setup
, /* setup. */
4469 1, /* num setup uint16_t words. */
4470 0, /* max returned setup. */
4471 state
->param
, /* param. */
4472 talloc_get_size(state
->param
),/* num param. */
4473 2, /* max returned param. */
4474 state
->data
, /* data. */
4476 12); /* max returned data. */
4478 if (tevent_req_nomem(subreq
, req
)) {
4479 return tevent_req_post(req
, ev
);
4481 tevent_req_set_callback(subreq
, cli_posix_open_internal_done
, req
);
4485 struct tevent_req
*cli_posix_open_send(TALLOC_CTX
*mem_ctx
,
4486 struct event_context
*ev
,
4487 struct cli_state
*cli
,
4492 return cli_posix_open_internal_send(mem_ctx
, ev
,
4493 cli
, fname
, flags
, mode
, false);
4496 NTSTATUS
cli_posix_open_recv(struct tevent_req
*req
, uint16_t *pfnum
)
4498 struct posix_open_state
*state
= tevent_req_data(req
, struct posix_open_state
);
4501 if (tevent_req_is_nterror(req
, &status
)) {
4504 *pfnum
= state
->fnum
;
4505 return NT_STATUS_OK
;
4508 /****************************************************************************
4509 Open - POSIX semantics. Doesn't request oplock.
4510 ****************************************************************************/
4512 NTSTATUS
cli_posix_open(struct cli_state
*cli
, const char *fname
,
4513 int flags
, mode_t mode
, uint16_t *pfnum
)
4516 TALLOC_CTX
*frame
= talloc_stackframe();
4517 struct event_context
*ev
= NULL
;
4518 struct tevent_req
*req
= NULL
;
4519 NTSTATUS status
= NT_STATUS_OK
;
4521 if (cli_has_async_calls(cli
)) {
4523 * Can't use sync call while an async call is in flight
4525 status
= NT_STATUS_INVALID_PARAMETER
;
4529 ev
= event_context_init(frame
);
4531 status
= NT_STATUS_NO_MEMORY
;
4535 req
= cli_posix_open_send(frame
,
4542 status
= NT_STATUS_NO_MEMORY
;
4546 if (!tevent_req_poll(req
, ev
)) {
4547 status
= map_nt_error_from_unix(errno
);
4551 status
= cli_posix_open_recv(req
, pfnum
);
4555 if (!NT_STATUS_IS_OK(status
)) {
4556 cli_set_error(cli
, status
);
4561 struct tevent_req
*cli_posix_mkdir_send(TALLOC_CTX
*mem_ctx
,
4562 struct event_context
*ev
,
4563 struct cli_state
*cli
,
4567 return cli_posix_open_internal_send(mem_ctx
, ev
,
4568 cli
, fname
, O_CREAT
, mode
, true);
4571 NTSTATUS
cli_posix_mkdir_recv(struct tevent_req
*req
)
4573 return tevent_req_simple_recv_ntstatus(req
);
4576 NTSTATUS
cli_posix_mkdir(struct cli_state
*cli
, const char *fname
, mode_t mode
)
4578 TALLOC_CTX
*frame
= talloc_stackframe();
4579 struct event_context
*ev
= NULL
;
4580 struct tevent_req
*req
= NULL
;
4581 NTSTATUS status
= NT_STATUS_OK
;
4583 if (cli_has_async_calls(cli
)) {
4585 * Can't use sync call while an async call is in flight
4587 status
= NT_STATUS_INVALID_PARAMETER
;
4591 ev
= event_context_init(frame
);
4593 status
= NT_STATUS_NO_MEMORY
;
4597 req
= cli_posix_mkdir_send(frame
,
4603 status
= NT_STATUS_NO_MEMORY
;
4607 if (!tevent_req_poll(req
, ev
)) {
4608 status
= map_nt_error_from_unix(errno
);
4612 status
= cli_posix_mkdir_recv(req
);
4616 if (!NT_STATUS_IS_OK(status
)) {
4617 cli_set_error(cli
, status
);
4622 /****************************************************************************
4623 unlink or rmdir - POSIX semantics.
4624 ****************************************************************************/
4626 struct cli_posix_unlink_internal_state
{
4630 static void cli_posix_unlink_internal_done(struct tevent_req
*subreq
);
4632 static struct tevent_req
*cli_posix_unlink_internal_send(TALLOC_CTX
*mem_ctx
,
4633 struct event_context
*ev
,
4634 struct cli_state
*cli
,
4638 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
4639 struct cli_posix_unlink_internal_state
*state
= NULL
;
4641 req
= tevent_req_create(mem_ctx
, &state
,
4642 struct cli_posix_unlink_internal_state
);
4647 /* Setup data word. */
4648 SSVAL(state
->data
, 0, level
);
4650 subreq
= cli_setpathinfo_send(state
, ev
, cli
,
4651 SMB_POSIX_PATH_UNLINK
,
4653 state
->data
, sizeof(state
->data
));
4654 if (tevent_req_nomem(subreq
, req
)) {
4655 return tevent_req_post(req
, ev
);
4657 tevent_req_set_callback(subreq
, cli_posix_unlink_internal_done
, req
);
4661 static void cli_posix_unlink_internal_done(struct tevent_req
*subreq
)
4663 NTSTATUS status
= cli_setpathinfo_recv(subreq
);
4664 tevent_req_simple_finish_ntstatus(subreq
, status
);
4667 struct tevent_req
*cli_posix_unlink_send(TALLOC_CTX
*mem_ctx
,
4668 struct event_context
*ev
,
4669 struct cli_state
*cli
,
4672 return cli_posix_unlink_internal_send(mem_ctx
, ev
, cli
, fname
,
4673 SMB_POSIX_UNLINK_FILE_TARGET
);
4676 NTSTATUS
cli_posix_unlink_recv(struct tevent_req
*req
)
4678 return tevent_req_simple_recv_ntstatus(req
);
4681 /****************************************************************************
4682 unlink - POSIX semantics.
4683 ****************************************************************************/
4685 NTSTATUS
cli_posix_unlink(struct cli_state
*cli
, const char *fname
)
4687 TALLOC_CTX
*frame
= talloc_stackframe();
4688 struct event_context
*ev
= NULL
;
4689 struct tevent_req
*req
= NULL
;
4690 NTSTATUS status
= NT_STATUS_OK
;
4692 if (cli_has_async_calls(cli
)) {
4694 * Can't use sync call while an async call is in flight
4696 status
= NT_STATUS_INVALID_PARAMETER
;
4700 ev
= event_context_init(frame
);
4702 status
= NT_STATUS_NO_MEMORY
;
4706 req
= cli_posix_unlink_send(frame
,
4711 status
= NT_STATUS_NO_MEMORY
;
4715 if (!tevent_req_poll(req
, ev
)) {
4716 status
= map_nt_error_from_unix(errno
);
4720 status
= cli_posix_unlink_recv(req
);
4724 if (!NT_STATUS_IS_OK(status
)) {
4725 cli_set_error(cli
, status
);
4730 /****************************************************************************
4731 rmdir - POSIX semantics.
4732 ****************************************************************************/
4734 struct tevent_req
*cli_posix_rmdir_send(TALLOC_CTX
*mem_ctx
,
4735 struct event_context
*ev
,
4736 struct cli_state
*cli
,
4739 return cli_posix_unlink_internal_send(
4740 mem_ctx
, ev
, cli
, fname
,
4741 SMB_POSIX_UNLINK_DIRECTORY_TARGET
);
4744 NTSTATUS
cli_posix_rmdir_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
)
4746 return tevent_req_simple_recv_ntstatus(req
);
4749 NTSTATUS
cli_posix_rmdir(struct cli_state
*cli
, const char *fname
)
4751 TALLOC_CTX
*frame
= talloc_stackframe();
4752 struct event_context
*ev
= NULL
;
4753 struct tevent_req
*req
= NULL
;
4754 NTSTATUS status
= NT_STATUS_OK
;
4756 if (cli_has_async_calls(cli
)) {
4758 * Can't use sync call while an async call is in flight
4760 status
= NT_STATUS_INVALID_PARAMETER
;
4764 ev
= event_context_init(frame
);
4766 status
= NT_STATUS_NO_MEMORY
;
4770 req
= cli_posix_rmdir_send(frame
,
4775 status
= NT_STATUS_NO_MEMORY
;
4779 if (!tevent_req_poll(req
, ev
)) {
4780 status
= map_nt_error_from_unix(errno
);
4784 status
= cli_posix_rmdir_recv(req
, frame
);
4788 if (!NT_STATUS_IS_OK(status
)) {
4789 cli_set_error(cli
, status
);
4794 /****************************************************************************
4796 ****************************************************************************/
4798 struct cli_notify_state
{
4800 uint32_t num_changes
;
4801 struct notify_change
*changes
;
4804 static void cli_notify_done(struct tevent_req
*subreq
);
4806 struct tevent_req
*cli_notify_send(TALLOC_CTX
*mem_ctx
,
4807 struct tevent_context
*ev
,
4808 struct cli_state
*cli
, uint16_t fnum
,
4809 uint32_t buffer_size
,
4810 uint32_t completion_filter
, bool recursive
)
4812 struct tevent_req
*req
, *subreq
;
4813 struct cli_notify_state
*state
;
4815 req
= tevent_req_create(mem_ctx
, &state
, struct cli_notify_state
);
4820 SIVAL(state
->setup
, 0, completion_filter
);
4821 SSVAL(state
->setup
, 4, fnum
);
4822 SSVAL(state
->setup
, 6, recursive
);
4824 subreq
= cli_trans_send(
4825 state
, /* mem ctx. */
4826 ev
, /* event ctx. */
4827 cli
, /* cli_state. */
4828 SMBnttrans
, /* cmd. */
4829 NULL
, /* pipe name. */
4831 NT_TRANSACT_NOTIFY_CHANGE
, /* function. */
4833 (uint16_t *)state
->setup
, /* setup. */
4834 4, /* num setup uint16_t words. */
4835 0, /* max returned setup. */
4838 buffer_size
, /* max returned param. */
4841 0); /* max returned data. */
4843 if (tevent_req_nomem(subreq
, req
)) {
4844 return tevent_req_post(req
, ev
);
4846 tevent_req_set_callback(subreq
, cli_notify_done
, req
);
4850 static void cli_notify_done(struct tevent_req
*subreq
)
4852 struct tevent_req
*req
= tevent_req_callback_data(
4853 subreq
, struct tevent_req
);
4854 struct cli_notify_state
*state
= tevent_req_data(
4855 req
, struct cli_notify_state
);
4858 uint32_t i
, ofs
, num_params
;
4861 status
= cli_trans_recv(subreq
, talloc_tos(), &flags2
, NULL
, 0, NULL
,
4862 ¶ms
, 0, &num_params
, NULL
, 0, NULL
);
4863 TALLOC_FREE(subreq
);
4864 if (tevent_req_nterror(req
, status
)) {
4865 DEBUG(10, ("cli_trans_recv returned %s\n", nt_errstr(status
)));
4869 state
->num_changes
= 0;
4872 while (num_params
- ofs
> 12) {
4873 uint32_t len
= IVAL(params
, ofs
);
4874 state
->num_changes
+= 1;
4876 if ((len
== 0) || (ofs
+len
>= num_params
)) {
4882 state
->changes
= talloc_array(state
, struct notify_change
,
4883 state
->num_changes
);
4884 if (tevent_req_nomem(state
->changes
, req
)) {
4885 TALLOC_FREE(params
);
4891 for (i
=0; i
<state
->num_changes
; i
++) {
4892 uint32_t next
= IVAL(params
, ofs
);
4893 uint32_t len
= IVAL(params
, ofs
+8);
4897 if ((next
!= 0) && (len
+12 != next
)) {
4898 TALLOC_FREE(params
);
4900 req
, NT_STATUS_INVALID_NETWORK_RESPONSE
);
4904 state
->changes
[i
].action
= IVAL(params
, ofs
+4);
4905 ret
= clistr_pull_talloc(params
, (char *)params
, flags2
,
4906 &name
, params
+ofs
+12, len
,
4907 STR_TERMINATE
|STR_UNICODE
);
4909 TALLOC_FREE(params
);
4910 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
4913 state
->changes
[i
].name
= name
;
4917 TALLOC_FREE(params
);
4918 tevent_req_done(req
);
4921 NTSTATUS
cli_notify_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
4922 uint32_t *pnum_changes
,
4923 struct notify_change
**pchanges
)
4925 struct cli_notify_state
*state
= tevent_req_data(
4926 req
, struct cli_notify_state
);
4929 if (tevent_req_is_nterror(req
, &status
)) {
4933 *pnum_changes
= state
->num_changes
;
4934 *pchanges
= talloc_move(mem_ctx
, &state
->changes
);
4935 return NT_STATUS_OK
;
4938 struct cli_qpathinfo_state
{
4947 static void cli_qpathinfo_done(struct tevent_req
*subreq
);
4949 struct tevent_req
*cli_qpathinfo_send(TALLOC_CTX
*mem_ctx
,
4950 struct tevent_context
*ev
,
4951 struct cli_state
*cli
, const char *fname
,
4952 uint16_t level
, uint32_t min_rdata
,
4955 struct tevent_req
*req
, *subreq
;
4956 struct cli_qpathinfo_state
*state
;
4958 req
= tevent_req_create(mem_ctx
, &state
, struct cli_qpathinfo_state
);
4962 state
->min_rdata
= min_rdata
;
4963 SSVAL(state
->setup
, 0, TRANSACT2_QPATHINFO
);
4965 state
->param
= talloc_zero_array(state
, uint8_t, 6);
4966 if (tevent_req_nomem(state
->param
, req
)) {
4967 return tevent_req_post(req
, ev
);
4969 SSVAL(state
->param
, 0, level
);
4970 state
->param
= trans2_bytes_push_str(
4971 state
->param
, cli_ucs2(cli
), fname
, strlen(fname
)+1, NULL
);
4972 if (tevent_req_nomem(state
->param
, req
)) {
4973 return tevent_req_post(req
, ev
);
4976 subreq
= cli_trans_send(
4977 state
, /* mem ctx. */
4978 ev
, /* event ctx. */
4979 cli
, /* cli_state. */
4980 SMBtrans2
, /* cmd. */
4981 NULL
, /* pipe name. */
4985 state
->setup
, /* setup. */
4986 1, /* num setup uint16_t words. */
4987 0, /* max returned setup. */
4988 state
->param
, /* param. */
4989 talloc_get_size(state
->param
), /* num param. */
4990 2, /* max returned param. */
4993 max_rdata
); /* max returned data. */
4995 if (tevent_req_nomem(subreq
, req
)) {
4996 return tevent_req_post(req
, ev
);
4998 tevent_req_set_callback(subreq
, cli_qpathinfo_done
, req
);
5002 static void cli_qpathinfo_done(struct tevent_req
*subreq
)
5004 struct tevent_req
*req
= tevent_req_callback_data(
5005 subreq
, struct tevent_req
);
5006 struct cli_qpathinfo_state
*state
= tevent_req_data(
5007 req
, struct cli_qpathinfo_state
);
5010 status
= cli_trans_recv(subreq
, state
, NULL
, NULL
, 0, NULL
,
5012 &state
->rdata
, state
->min_rdata
,
5014 if (tevent_req_nterror(req
, status
)) {
5017 tevent_req_done(req
);
5020 NTSTATUS
cli_qpathinfo_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
5021 uint8_t **rdata
, uint32_t *num_rdata
)
5023 struct cli_qpathinfo_state
*state
= tevent_req_data(
5024 req
, struct cli_qpathinfo_state
);
5027 if (tevent_req_is_nterror(req
, &status
)) {
5030 if (rdata
!= NULL
) {
5031 *rdata
= talloc_move(mem_ctx
, &state
->rdata
);
5033 TALLOC_FREE(state
->rdata
);
5035 if (num_rdata
!= NULL
) {
5036 *num_rdata
= state
->num_rdata
;
5038 return NT_STATUS_OK
;
5041 NTSTATUS
cli_qpathinfo(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
,
5042 const char *fname
, uint16_t level
, uint32_t min_rdata
,
5044 uint8_t **rdata
, uint32_t *num_rdata
)
5046 TALLOC_CTX
*frame
= talloc_stackframe();
5047 struct event_context
*ev
;
5048 struct tevent_req
*req
;
5049 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
5051 if (cli_has_async_calls(cli
)) {
5053 * Can't use sync call while an async call is in flight
5055 status
= NT_STATUS_INVALID_PARAMETER
;
5058 ev
= event_context_init(frame
);
5062 req
= cli_qpathinfo_send(frame
, ev
, cli
, fname
, level
, min_rdata
,
5067 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5070 status
= cli_qpathinfo_recv(req
, mem_ctx
, rdata
, num_rdata
);
5073 if (!NT_STATUS_IS_OK(status
)) {
5074 cli_set_error(cli
, status
);
5079 struct cli_qfileinfo_state
{
5088 static void cli_qfileinfo_done(struct tevent_req
*subreq
);
5090 struct tevent_req
*cli_qfileinfo_send(TALLOC_CTX
*mem_ctx
,
5091 struct tevent_context
*ev
,
5092 struct cli_state
*cli
, uint16_t fnum
,
5093 uint16_t level
, uint32_t min_rdata
,
5096 struct tevent_req
*req
, *subreq
;
5097 struct cli_qfileinfo_state
*state
;
5099 req
= tevent_req_create(mem_ctx
, &state
, struct cli_qfileinfo_state
);
5103 state
->min_rdata
= min_rdata
;
5104 SSVAL(state
->param
, 0, fnum
);
5105 SSVAL(state
->param
, 2, level
);
5106 SSVAL(state
->setup
, 0, TRANSACT2_QFILEINFO
);
5108 subreq
= cli_trans_send(
5109 state
, /* mem ctx. */
5110 ev
, /* event ctx. */
5111 cli
, /* cli_state. */
5112 SMBtrans2
, /* cmd. */
5113 NULL
, /* pipe name. */
5117 state
->setup
, /* setup. */
5118 1, /* num setup uint16_t words. */
5119 0, /* max returned setup. */
5120 state
->param
, /* param. */
5121 sizeof(state
->param
), /* num param. */
5122 2, /* max returned param. */
5125 max_rdata
); /* max returned data. */
5127 if (tevent_req_nomem(subreq
, req
)) {
5128 return tevent_req_post(req
, ev
);
5130 tevent_req_set_callback(subreq
, cli_qfileinfo_done
, req
);
5134 static void cli_qfileinfo_done(struct tevent_req
*subreq
)
5136 struct tevent_req
*req
= tevent_req_callback_data(
5137 subreq
, struct tevent_req
);
5138 struct cli_qfileinfo_state
*state
= tevent_req_data(
5139 req
, struct cli_qfileinfo_state
);
5142 status
= cli_trans_recv(subreq
, state
, NULL
, NULL
, 0, NULL
,
5144 &state
->rdata
, state
->min_rdata
,
5146 if (tevent_req_nterror(req
, status
)) {
5149 tevent_req_done(req
);
5152 NTSTATUS
cli_qfileinfo_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
5153 uint8_t **rdata
, uint32_t *num_rdata
)
5155 struct cli_qfileinfo_state
*state
= tevent_req_data(
5156 req
, struct cli_qfileinfo_state
);
5159 if (tevent_req_is_nterror(req
, &status
)) {
5162 if (rdata
!= NULL
) {
5163 *rdata
= talloc_move(mem_ctx
, &state
->rdata
);
5165 TALLOC_FREE(state
->rdata
);
5167 if (num_rdata
!= NULL
) {
5168 *num_rdata
= state
->num_rdata
;
5170 return NT_STATUS_OK
;
5173 NTSTATUS
cli_qfileinfo(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
,
5174 uint16_t fnum
, uint16_t level
, uint32_t min_rdata
,
5176 uint8_t **rdata
, uint32_t *num_rdata
)
5178 TALLOC_CTX
*frame
= talloc_stackframe();
5179 struct event_context
*ev
;
5180 struct tevent_req
*req
;
5181 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
5183 if (cli_has_async_calls(cli
)) {
5185 * Can't use sync call while an async call is in flight
5187 status
= NT_STATUS_INVALID_PARAMETER
;
5190 ev
= event_context_init(frame
);
5194 req
= cli_qfileinfo_send(frame
, ev
, cli
, fnum
, level
, min_rdata
,
5199 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5202 status
= cli_qfileinfo_recv(req
, mem_ctx
, rdata
, num_rdata
);
5205 if (!NT_STATUS_IS_OK(status
)) {
5206 cli_set_error(cli
, status
);
5211 struct cli_flush_state
{
5215 static void cli_flush_done(struct tevent_req
*subreq
);
5217 struct tevent_req
*cli_flush_send(TALLOC_CTX
*mem_ctx
,
5218 struct event_context
*ev
,
5219 struct cli_state
*cli
,
5222 struct tevent_req
*req
, *subreq
;
5223 struct cli_flush_state
*state
;
5225 req
= tevent_req_create(mem_ctx
, &state
, struct cli_flush_state
);
5229 SSVAL(state
->vwv
+ 0, 0, fnum
);
5231 subreq
= cli_smb_send(state
, ev
, cli
, SMBflush
, 0, 1, state
->vwv
,
5233 if (tevent_req_nomem(subreq
, req
)) {
5234 return tevent_req_post(req
, ev
);
5236 tevent_req_set_callback(subreq
, cli_flush_done
, req
);
5240 static void cli_flush_done(struct tevent_req
*subreq
)
5242 struct tevent_req
*req
= tevent_req_callback_data(
5243 subreq
, struct tevent_req
);
5246 status
= cli_smb_recv(subreq
, NULL
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
5247 TALLOC_FREE(subreq
);
5248 if (tevent_req_nterror(req
, status
)) {
5251 tevent_req_done(req
);
5254 NTSTATUS
cli_flush_recv(struct tevent_req
*req
)
5256 return tevent_req_simple_recv_ntstatus(req
);
5259 NTSTATUS
cli_flush(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
, uint16_t fnum
)
5261 TALLOC_CTX
*frame
= talloc_stackframe();
5262 struct event_context
*ev
;
5263 struct tevent_req
*req
;
5264 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
5266 if (cli_has_async_calls(cli
)) {
5268 * Can't use sync call while an async call is in flight
5270 status
= NT_STATUS_INVALID_PARAMETER
;
5273 ev
= event_context_init(frame
);
5277 req
= cli_flush_send(frame
, ev
, cli
, fnum
);
5281 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5284 status
= cli_flush_recv(req
);
5287 if (!NT_STATUS_IS_OK(status
)) {
5288 cli_set_error(cli
, status
);
5293 struct cli_shadow_copy_data_state
{
5300 static void cli_shadow_copy_data_done(struct tevent_req
*subreq
);
5302 struct tevent_req
*cli_shadow_copy_data_send(TALLOC_CTX
*mem_ctx
,
5303 struct tevent_context
*ev
,
5304 struct cli_state
*cli
,
5308 struct tevent_req
*req
, *subreq
;
5309 struct cli_shadow_copy_data_state
*state
;
5312 req
= tevent_req_create(mem_ctx
, &state
,
5313 struct cli_shadow_copy_data_state
);
5317 state
->get_names
= get_names
;
5318 ret_size
= get_names
? cli
->max_xmit
: 16;
5320 SIVAL(state
->setup
+ 0, 0, FSCTL_GET_SHADOW_COPY_DATA
);
5321 SSVAL(state
->setup
+ 2, 0, fnum
);
5322 SCVAL(state
->setup
+ 3, 0, 0); /* isFsctl */
5323 SCVAL(state
->setup
+ 3, 1, 0); /* compfilter, isFlags (WSSP) */
5325 subreq
= cli_trans_send(
5326 state
, ev
, cli
, SMBnttrans
, NULL
, 0, NT_TRANSACT_IOCTL
, 0,
5327 state
->setup
, ARRAY_SIZE(state
->setup
), 0,
5330 if (tevent_req_nomem(subreq
, req
)) {
5331 return tevent_req_post(req
, ev
);
5333 tevent_req_set_callback(subreq
, cli_shadow_copy_data_done
, req
);
5337 static void cli_shadow_copy_data_done(struct tevent_req
*subreq
)
5339 struct tevent_req
*req
= tevent_req_callback_data(
5340 subreq
, struct tevent_req
);
5341 struct cli_shadow_copy_data_state
*state
= tevent_req_data(
5342 req
, struct cli_shadow_copy_data_state
);
5345 status
= cli_trans_recv(subreq
, state
, NULL
,
5346 NULL
, 0, NULL
, /* setup */
5347 NULL
, 0, NULL
, /* param */
5348 &state
->data
, 12, &state
->num_data
);
5349 TALLOC_FREE(subreq
);
5350 if (tevent_req_nterror(req
, status
)) {
5353 tevent_req_done(req
);
5356 NTSTATUS
cli_shadow_copy_data_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
5357 char ***pnames
, int *pnum_names
)
5359 struct cli_shadow_copy_data_state
*state
= tevent_req_data(
5360 req
, struct cli_shadow_copy_data_state
);
5366 if (tevent_req_is_nterror(req
, &status
)) {
5369 num_names
= IVAL(state
->data
, 4);
5370 dlength
= IVAL(state
->data
, 8);
5372 if (!state
->get_names
) {
5373 *pnum_names
= num_names
;
5374 return NT_STATUS_OK
;
5377 if (dlength
+12 > state
->num_data
) {
5378 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
5380 names
= talloc_array(mem_ctx
, char *, num_names
);
5381 if (names
== NULL
) {
5382 return NT_STATUS_NO_MEMORY
;
5385 for (i
=0; i
<num_names
; i
++) {
5388 size_t converted_size
;
5390 src
= state
->data
+ 12 + i
* 2 * sizeof(SHADOW_COPY_LABEL
);
5391 ret
= convert_string_talloc(
5392 names
, CH_UTF16LE
, CH_UNIX
,
5393 src
, 2 * sizeof(SHADOW_COPY_LABEL
),
5394 &names
[i
], &converted_size
, True
);
5397 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
5400 *pnum_names
= num_names
;
5402 return NT_STATUS_OK
;
5405 NTSTATUS
cli_shadow_copy_data(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
,
5406 uint16_t fnum
, bool get_names
,
5407 char ***pnames
, int *pnum_names
)
5409 TALLOC_CTX
*frame
= talloc_stackframe();
5410 struct event_context
*ev
;
5411 struct tevent_req
*req
;
5412 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
5414 if (cli_has_async_calls(cli
)) {
5416 * Can't use sync call while an async call is in flight
5418 status
= NT_STATUS_INVALID_PARAMETER
;
5421 ev
= event_context_init(frame
);
5425 req
= cli_shadow_copy_data_send(frame
, ev
, cli
, fnum
, get_names
);
5429 if (!tevent_req_poll_ntstatus(req
, ev
, &status
)) {
5432 status
= cli_shadow_copy_data_recv(req
, mem_ctx
, pnames
, pnum_names
);
5435 if (!NT_STATUS_IS_OK(status
)) {
5436 cli_set_error(cli
, status
);