summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2009-05-06 16:13:42 -0700
committerJeremy Allison <jra@samba.org>2009-05-06 16:13:42 -0700
commit606edf0f350000978a437ddfb7c23525a16d9854 (patch)
tree976f7948635fcc032edc247d0891ae28a5af1ada /source3/libsmb
parent78fb479325ce7073ab8383ada3903080d12aef91 (diff)
downloadsamba-606edf0f350000978a437ddfb7c23525a16d9854.tar.gz
samba-606edf0f350000978a437ddfb7c23525a16d9854.tar.bz2
samba-606edf0f350000978a437ddfb7c23525a16d9854.zip
Make cli_setatr async.
Jeremy.
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/clifile.c127
-rw-r--r--source3/libsmb/libsmb_dir.c2
-rw-r--r--source3/libsmb/libsmb_file.c2
3 files changed, 129 insertions, 2 deletions
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 7983516f87..e210d76b28 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -2506,6 +2506,132 @@ NTSTATUS cli_setattrE(struct cli_state *cli,
Do a SMBsetatr call.
****************************************************************************/
+static void cli_setatr_done(struct tevent_req *subreq);
+
+struct cli_setatr_state {
+ int dummy;
+};
+
+struct tevent_req *cli_setatr_send(TALLOC_CTX *mem_ctx,
+ struct event_context *ev,
+ struct cli_state *cli,
+ const char *fname,
+ uint16_t attr,
+ time_t mtime)
+{
+ struct tevent_req *req = NULL, *subreq = NULL;
+ struct cli_setatr_state *state = NULL;
+ uint8_t additional_flags = 0;
+ uint16_t vwv[8];
+ uint8_t *bytes = NULL;
+
+ req = tevent_req_create(mem_ctx, &state, struct cli_setatr_state);
+ if (req == NULL) {
+ return NULL;
+ }
+
+ memset(vwv, '\0', sizeof(vwv));
+ SSVAL(vwv+0, 0, attr);
+ cli_put_dos_date3(cli, (char *)&vwv[1], 0, mtime);
+
+ bytes = talloc_array(state, uint8_t, 1);
+ if (tevent_req_nomem(bytes, req)) {
+ return tevent_req_post(req, ev);
+ }
+ bytes[0] = 4;
+ bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname,
+ strlen(fname)+1, NULL);
+ if (tevent_req_nomem(bytes, req)) {
+ return tevent_req_post(req, ev);
+ }
+ bytes = TALLOC_REALLOC_ARRAY(state, bytes, uint8_t,
+ talloc_get_size(bytes)+1);
+ if (tevent_req_nomem(bytes, req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ bytes[talloc_get_size(bytes)-1] = 4;
+ bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), "",
+ 1, NULL);
+ if (tevent_req_nomem(bytes, req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ subreq = cli_smb_send(state, ev, cli, SMBsetatr, additional_flags,
+ 8, vwv, talloc_get_size(bytes), bytes);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, cli_setatr_done, req);
+ return req;
+}
+
+static void cli_setatr_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ NTSTATUS status;
+
+ status = cli_smb_recv(subreq, 0, NULL, NULL, NULL, NULL);
+ TALLOC_FREE(subreq);
+ if (!NT_STATUS_IS_OK(status)) {
+ tevent_req_nterror(req, status);
+ return;
+ }
+ tevent_req_done(req);
+}
+
+NTSTATUS cli_setatr_recv(struct tevent_req *req)
+{
+ return tevent_req_simple_recv_ntstatus(req);
+}
+
+NTSTATUS cli_setatr(struct cli_state *cli,
+ const char *fname,
+ uint16_t attr,
+ time_t mtime)
+{
+ TALLOC_CTX *frame = talloc_stackframe();
+ struct event_context *ev = NULL;
+ struct tevent_req *req = NULL;
+ NTSTATUS status = NT_STATUS_OK;
+
+ if (cli_has_async_calls(cli)) {
+ /*
+ * 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_setatr_send(frame, ev, cli, fname, attr, mtime);
+ if (req == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto fail;
+ }
+
+ if (!tevent_req_poll(req, ev)) {
+ status = map_nt_error_from_unix(errno);
+ goto fail;
+ }
+
+ status = cli_setatr_recv(req);
+
+ fail:
+ TALLOC_FREE(frame);
+ if (!NT_STATUS_IS_OK(status)) {
+ cli_set_error(cli, status);
+ }
+ return status;
+}
+
+#if 0
bool cli_setatr(struct cli_state *cli, const char *fname, uint16_t attr, time_t t)
{
char *p;
@@ -2541,6 +2667,7 @@ bool cli_setatr(struct cli_state *cli, const char *fname, uint16_t attr, time_t
return True;
}
+#endif
/****************************************************************************
Check for existance of a dir.
diff --git a/source3/libsmb/libsmb_dir.c b/source3/libsmb/libsmb_dir.c
index d230275685..a3f63f204d 100644
--- a/source3/libsmb/libsmb_dir.c
+++ b/source3/libsmb/libsmb_dir.c
@@ -1573,7 +1573,7 @@ SMBC_chmod_ctx(SMBCCTX *context,
if ((newmode & S_IXGRP) && lp_map_system(-1)) mode |= aSYSTEM;
if ((newmode & S_IXOTH) && lp_map_hidden(-1)) mode |= aHIDDEN;
- if (!cli_setatr(targetcli, targetpath, mode, 0)) {
+ if (!NT_STATUS_IS_OK(cli_setatr(targetcli, targetpath, mode, 0))) {
errno = SMBC_errno(context, targetcli);
TALLOC_FREE(frame);
return -1;
diff --git a/source3/libsmb/libsmb_file.c b/source3/libsmb/libsmb_file.c
index 1bb12123a5..abfec172e4 100644
--- a/source3/libsmb/libsmb_file.c
+++ b/source3/libsmb/libsmb_file.c
@@ -684,7 +684,7 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
* seems to work on win98.
*/
if (ret && mode != (uint16) -1) {
- ret = cli_setatr(srv->cli, path, mode, 0);
+ ret = NT_STATUS_IS_OK(cli_setatr(srv->cli, path, mode, 0));
}
if (! ret) {