-1, 0, /* fid, flags */
&setup, 1, 0, /* setup, length, max */
param, param_len, 2, /* param, length, max */
- (char *)&data, data_len, cli->max_xmit /* data, length, max */
+ data, data_len, cli->max_xmit /* data, length, max */
)) {
SAFE_FREE(data);
SAFE_FREE(param);
return SVAL(cli->inbuf,smb_vwv2 + 1);
}
+struct async_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx,
+ struct event_context *ev,
+ struct cli_state *cli,
+ const char *fname,
+ uint32_t CreatFlags,
+ uint32_t DesiredAccess,
+ uint32_t FileAttributes,
+ uint32_t ShareAccess,
+ uint32_t CreateDisposition,
+ uint32_t CreateOptions,
+ uint8_t SecurityFlags)
+{
+ struct async_req *result;
+ uint8_t *bytes;
+ size_t converted_len;
+ uint16_t vwv[24];
+
+ SCVAL(vwv+0, 0, 0xFF);
+ SCVAL(vwv+0, 1, 0);
+ SSVAL(vwv+1, 0, 0);
+ SCVAL(vwv+2, 0, 0);
+
+ if (cli->use_oplocks) {
+ CreatFlags |= (REQUEST_OPLOCK|REQUEST_BATCH_OPLOCK);
+ }
+ SIVAL(vwv+3, 1, CreatFlags);
+ SIVAL(vwv+5, 1, 0x0); /* RootDirectoryFid */
+ SIVAL(vwv+7, 1, DesiredAccess);
+ SIVAL(vwv+9, 1, 0x0); /* AllocationSize */
+ SIVAL(vwv+11, 1, 0x0); /* AllocationSize */
+ SIVAL(vwv+13, 1, FileAttributes);
+ SIVAL(vwv+15, 1, ShareAccess);
+ SIVAL(vwv+17, 1, CreateDisposition);
+ SIVAL(vwv+19, 1, CreateOptions);
+ SIVAL(vwv+21, 1, 0x02); /* ImpersonationLevel */
+ SCVAL(vwv+23, 1, SecurityFlags);
+
+ bytes = talloc_array(talloc_tos(), uint8_t, 0);
+ bytes = smb_bytes_push_str(bytes, cli_ucs2(cli),
+ fname, strlen(fname)+1,
+ &converted_len);
+
+ /* sigh. this copes with broken netapp filer behaviour */
+ bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), "", 1, NULL);
+
+ if (bytes == NULL) {
+ return NULL;
+ }
+
+ SIVAL(vwv+2, 1, converted_len);
+
+ result = cli_request_send(mem_ctx, ev, cli, SMBntcreateX, 0,
+ 24, vwv, 0, talloc_get_size(bytes), bytes);
+ TALLOC_FREE(bytes);
+ return result;
+}
+
+NTSTATUS cli_ntcreate_recv(struct async_req *req, uint16_t *pfnum)
+{
+ uint8_t wct;
+ uint16_t *vwv;
+ uint16_t num_bytes;
+ uint8_t *bytes;
+ NTSTATUS status;
+
+ if (async_req_is_nterror(req, &status)) {
+ return status;
+ }
+
+ status = cli_pull_reply(req, &wct, &vwv, &num_bytes, &bytes);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ if (wct < 3) {
+ return NT_STATUS_INVALID_NETWORK_RESPONSE;
+ }
+
+ *pfnum = SVAL(vwv+2, 1);
+
+ return NT_STATUS_OK;
+}
+
+NTSTATUS cli_ntcreate(struct cli_state *cli,
+ const char *fname,
+ uint32_t CreatFlags,
+ uint32_t DesiredAccess,
+ uint32_t FileAttributes,
+ uint32_t ShareAccess,
+ uint32_t CreateDisposition,
+ uint32_t CreateOptions,
+ uint8_t SecurityFlags,
+ uint16_t *pfid)
+{
+ TALLOC_CTX *frame = talloc_stackframe();
+ struct event_context *ev;
+ struct async_req *req;
+ NTSTATUS status;
+
+ if (cli->fd_event != NULL) {
+ /*
+ * Can't use sync call while an async call is in flight
+ */
+ status = NT_STATUS_INVALID_PARAMETER;
+ goto fail;
+ }
+
+ ev = event_context_init(frame);
+ if (ev == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto fail;
+ }
+
+ req = cli_ntcreate_send(frame, ev, cli, fname, CreatFlags,
+ DesiredAccess, FileAttributes, ShareAccess,
+ CreateDisposition, CreateOptions,
+ SecurityFlags);
+ if (req == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto fail;
+ }
+
+ while (req->state < ASYNC_REQ_DONE) {
+ event_loop_once(ev);
+ }
+
+ status = cli_ntcreate_recv(req, pfid);
+ fail:
+ TALLOC_FREE(frame);
+ return status;
+}
+
/****************************************************************************
Open a file.
****************************************************************************/
FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0);
}
+uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2,
+ const char *str, size_t str_len,
+ size_t *pconverted_size)
+{
+ size_t buflen;
+ char *converted;
+ size_t converted_size;
+
+ if (buf == NULL) {
+ return NULL;
+ }
+
+ buflen = talloc_get_size(buf);
+ /*
+ * We're pushing into an SMB buffer, align odd
+ */
+ if (ucs2 && (buflen % 2 == 0)) {
+ buf = TALLOC_REALLOC_ARRAY(NULL, buf, uint8_t, buflen + 1);
+ if (buf == NULL) {
+ return NULL;
+ }
+ buf[buflen] = '\0';
+ buflen += 1;
+ }
+
+ if (!convert_string_allocate(talloc_tos(), CH_UNIX,
+ ucs2 ? CH_UTF16LE : CH_DOS,
+ str, str_len, &converted,
+ &converted_size, true)) {
+ return NULL;
+ }
+
+ buf = TALLOC_REALLOC_ARRAY(NULL, buf, uint8_t,
+ buflen + converted_size);
+ if (buf == NULL) {
+ TALLOC_FREE(converted);
+ return NULL;
+ }
+
+ memcpy(buf + buflen, converted, converted_size);
+
+ TALLOC_FREE(converted);
+
+ if (pconverted_size) {
+ *pconverted_size = converted_size;
+ }
+
+ return buf;
+}
+
/****************************************************************************
Open a file
WARNING: if you open with O_WRONLY then getattrE won't work!
****************************************************************************/
-int cli_open(struct cli_state *cli, const char *fname, int flags, int share_mode)
+struct async_req *cli_open_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
+ struct cli_state *cli,
+ const char *fname, int flags, int share_mode)
{
- char *p;
- unsigned openfn=0;
- unsigned accessmode=0;
+ unsigned openfn = 0;
+ unsigned accessmode = 0;
+ uint8_t additional_flags = 0;
+ uint8_t *bytes;
+ uint16_t vwv[15];
+ struct async_req *result;
- if (flags & O_CREAT)
+ if (flags & O_CREAT) {
openfn |= (1<<4);
+ }
if (!(flags & O_EXCL)) {
if (flags & O_TRUNC)
openfn |= (1<<1);
accessmode = 0xFF;
}
- memset(cli->outbuf,'\0',smb_size);
- memset(cli->inbuf,'\0',smb_size);
-
- cli_set_message(cli->outbuf,15,0, true);
-
- SCVAL(cli->outbuf,smb_com,SMBopenX);
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- SSVAL(cli->outbuf,smb_vwv0,0xFF);
- SSVAL(cli->outbuf,smb_vwv2,0); /* no additional info */
- SSVAL(cli->outbuf,smb_vwv3,accessmode);
- SSVAL(cli->outbuf,smb_vwv4,aSYSTEM | aHIDDEN);
- SSVAL(cli->outbuf,smb_vwv5,0);
- SSVAL(cli->outbuf,smb_vwv8,openfn);
+ SCVAL(vwv + 0, 0, 0xFF);
+ SCVAL(vwv + 0, 1, 0);
+ SSVAL(vwv + 1, 0, 0);
+ SSVAL(vwv + 2, 0, 0); /* no additional info */
+ SSVAL(vwv + 3, 0, accessmode);
+ SSVAL(vwv + 4, 0, aSYSTEM | aHIDDEN);
+ SSVAL(vwv + 5, 0, 0);
+ SIVAL(vwv + 6, 0, 0);
+ SSVAL(vwv + 8, 0, openfn);
+ SIVAL(vwv + 9, 0, 0);
+ SIVAL(vwv + 11, 0, 0);
+ SIVAL(vwv + 13, 0, 0);
if (cli->use_oplocks) {
/* if using oplocks then ask for a batch oplock via
core and extended methods */
- SCVAL(cli->outbuf,smb_flg, CVAL(cli->outbuf,smb_flg)|
- FLAG_REQUEST_OPLOCK|FLAG_REQUEST_BATCH_OPLOCK);
- SSVAL(cli->outbuf,smb_vwv2,SVAL(cli->outbuf,smb_vwv2) | 6);
+ additional_flags =
+ FLAG_REQUEST_OPLOCK|FLAG_REQUEST_BATCH_OPLOCK;
+ SSVAL(vwv+2, 0, SVAL(vwv+2, 0) | 6);
}
- p = smb_buf(cli->outbuf);
- p += clistr_push(cli, p, fname,
- cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE);
+ bytes = talloc_array(talloc_tos(), uint8_t, 0);
+ bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname,
+ strlen(fname)+1, NULL);
+ if (bytes == NULL) {
+ return NULL;
+ }
- cli_setup_bcc(cli, p);
+ result = cli_request_send(mem_ctx, ev, cli, SMBopenX, additional_flags,
+ 15, vwv, 0, talloc_get_size(bytes), bytes);
+ TALLOC_FREE(bytes);
+ return result;
+}
- cli_send_smb(cli);
- if (!cli_receive_smb(cli)) {
- return -1;
+NTSTATUS cli_open_recv(struct async_req *req, int *fnum)
+{
+ uint8_t wct;
+ uint16_t *vwv;
+ uint16_t num_bytes;
+ uint8_t *bytes;
+ NTSTATUS status;
+
+ if (async_req_is_nterror(req, &status)) {
+ return status;
}
- if (cli_is_error(cli)) {
- return -1;
+ status = cli_pull_reply(req, &wct, &vwv, &num_bytes, &bytes);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ if (wct < 3) {
+ return NT_STATUS_INVALID_NETWORK_RESPONSE;
+ }
+
+ *fnum = SVAL(vwv+2, 0);
+
+ return NT_STATUS_OK;
+}
+
+int cli_open(struct cli_state *cli, const char *fname, int flags,
+ int share_mode)
+{
+ TALLOC_CTX *frame = talloc_stackframe();
+ struct event_context *ev;
+ struct async_req *req;
+ int result = -1;
+
+ if (cli->fd_event != NULL) {
+ /*
+ * Can't use sync call while an async call is in flight
+ */
+ cli_set_error(cli, NT_STATUS_INVALID_PARAMETER);
+ goto fail;
+ }
+
+ ev = event_context_init(frame);
+ if (ev == NULL) {
+ goto fail;
}
- return SVAL(cli->inbuf,smb_vwv2);
+ req = cli_open_send(frame, ev, cli, fname, flags, share_mode);
+ if (req == NULL) {
+ goto fail;
+ }
+
+ while (req->state < ASYNC_REQ_DONE) {
+ event_loop_once(ev);
+ }
+
+ cli_open_recv(req, &result);
+ fail:
+ TALLOC_FREE(frame);
+ return result;
}
/****************************************************************************
Close a file.
****************************************************************************/
-bool cli_close(struct cli_state *cli, int fnum)
+struct async_req *cli_close_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
+ struct cli_state *cli, int fnum)
{
- memset(cli->outbuf,'\0',smb_size);
- memset(cli->inbuf,'\0',smb_size);
+ uint16_t vwv[3];
- cli_set_message(cli->outbuf,3,0,True);
+ SSVAL(vwv+0, 0, fnum);
+ SIVALS(vwv+1, 0, -1);
- SCVAL(cli->outbuf,smb_com,SMBclose);
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
+ return cli_request_send(mem_ctx, ev, cli, SMBclose, 0, 3, vwv, 0,
+ 0, NULL);
+}
- SSVAL(cli->outbuf,smb_vwv0,fnum);
- SIVALS(cli->outbuf,smb_vwv1,-1);
+NTSTATUS cli_close_recv(struct async_req *req)
+{
+ uint8_t wct;
+ uint16_t *vwv;
+ uint16_t num_bytes;
+ uint8_t *bytes;
+ NTSTATUS status;
- cli_send_smb(cli);
- if (!cli_receive_smb(cli)) {
- return False;
+ if (async_req_is_nterror(req, &status)) {
+ return status;
}
- return !cli_is_error(cli);
+ return cli_pull_reply(req, &wct, &vwv, &num_bytes, &bytes);
}
+bool cli_close(struct cli_state *cli, int fnum)
+{
+ TALLOC_CTX *frame = talloc_stackframe();
+ struct event_context *ev;
+ struct async_req *req;
+ bool result = false;
+
+ if (cli->fd_event != NULL) {
+ /*
+ * Can't use sync call while an async call is in flight
+ */
+ cli_set_error(cli, NT_STATUS_INVALID_PARAMETER);
+ goto fail;
+ }
+
+ ev = event_context_init(frame);
+ if (ev == NULL) {
+ goto fail;
+ }
+
+ req = cli_close_send(frame, ev, cli, fnum);
+ if (req == NULL) {
+ goto fail;
+ }
+
+ while (req->state < ASYNC_REQ_DONE) {
+ event_loop_once(ev);
+ }
+
+ result = NT_STATUS_IS_OK(cli_close_recv(req));
+ fail:
+ TALLOC_FREE(frame);
+ return result;
+}
/****************************************************************************
Truncate a file to a specified size
****************************************************************************/
bool cli_lock64(struct cli_state *cli, int fnum,
- SMB_BIG_UINT offset, SMB_BIG_UINT len, int timeout, enum brl_type lock_type)
+ uint64_t offset, uint64_t len, int timeout, enum brl_type lock_type)
{
char *p;
int saved_timeout = cli->timeout;
Unlock a file with 64 bit offsets.
****************************************************************************/
-bool cli_unlock64(struct cli_state *cli, int fnum, SMB_BIG_UINT offset, SMB_BIG_UINT len)
+bool cli_unlock64(struct cli_state *cli, int fnum, uint64_t offset, uint64_t len)
{
char *p;
****************************************************************************/
static bool cli_posix_lock_internal(struct cli_state *cli, int fnum,
- SMB_BIG_UINT offset, SMB_BIG_UINT len, bool wait_lock, enum brl_type lock_type)
+ uint64_t offset, uint64_t len, bool wait_lock, enum brl_type lock_type)
{
unsigned int param_len = 4;
unsigned int data_len = POSIX_LOCK_DATA_SIZE;
****************************************************************************/
bool cli_posix_lock(struct cli_state *cli, int fnum,
- SMB_BIG_UINT offset, SMB_BIG_UINT len,
+ uint64_t offset, uint64_t len,
bool wait_lock, enum brl_type lock_type)
{
if (lock_type != READ_LOCK && lock_type != WRITE_LOCK) {
POSIX Unlock a file.
****************************************************************************/
-bool cli_posix_unlock(struct cli_state *cli, int fnum, SMB_BIG_UINT offset, SMB_BIG_UINT len)
+bool cli_posix_unlock(struct cli_state *cli, int fnum, uint64_t offset, uint64_t len)
{
return cli_posix_lock_internal(cli, fnum, offset, len, False, UNLOCK_LOCK);
}
POSIX Get any lock covering a file.
****************************************************************************/
-bool cli_posix_getlock(struct cli_state *cli, int fnum, SMB_BIG_UINT *poffset, SMB_BIG_UINT *plen)
+bool cli_posix_getlock(struct cli_state *cli, int fnum, uint64_t *poffset, uint64_t *plen)
{
return True;
}
if (!path2) {
return -1;
}
- clistr_pull(cli, path2, p,
+ clistr_pull(cli->inbuf, path2, p,
len+1, len, STR_ASCII);
*tmp_path = path2;
}
}
/*********************************************************
- Get an extended attribute list tility fn.
+ Get an extended attribute list utility fn.
*********************************************************/
static bool cli_get_ea_list(struct cli_state *cli,