summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2009-05-05 20:59:22 -0700
committerJeremy Allison <jra@samba.org>2009-05-05 20:59:22 -0700
commit4cbd0c77e42627c76dda88af5326ef91415a652d (patch)
tree85fa13b4907088ada28d7b96a466d86f08f52dc9 /source3/libsmb
parent1db0b20d8a26fb60299d0ed7553d7a4847aee84f (diff)
downloadsamba-4cbd0c77e42627c76dda88af5326ef91415a652d.tar.gz
samba-4cbd0c77e42627c76dda88af5326ef91415a652d.tar.bz2
samba-4cbd0c77e42627c76dda88af5326ef91415a652d.zip
Make cli_getatr() async.
Jeremy.
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/clifile.c151
-rw-r--r--source3/libsmb/libsmb_file.c2
2 files changed, 126 insertions, 27 deletions
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index bc466d1315..357923abcb 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -2243,49 +2243,148 @@ NTSTATUS cli_getattrE(struct cli_state *cli,
Do a SMBgetatr call
****************************************************************************/
-bool cli_getatr(struct cli_state *cli, const char *fname,
- uint16_t *attr, SMB_OFF_T *size, time_t *write_time)
-{
- char *p;
+static void cli_getatr_done(struct tevent_req *subreq);
- memset(cli->outbuf,'\0',smb_size);
- memset(cli->inbuf,'\0',smb_size);
+struct cli_getatr_state {
+ int zone_offset;
+ uint16_t attr;
+ SMB_OFF_T size;
+ time_t write_time;
+};
- cli_set_message(cli->outbuf,0,0,True);
+struct tevent_req *cli_getatr_send(TALLOC_CTX *mem_ctx,
+ struct event_context *ev,
+ struct cli_state *cli,
+ const char *fname)
+{
+ struct tevent_req *req = NULL, *subreq = NULL;
+ struct cli_getatr_state *state = NULL;
+ uint8_t additional_flags = 0;
+ uint8_t *bytes = NULL;
- SCVAL(cli->outbuf,smb_com,SMBgetatr);
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
+ req = tevent_req_create(mem_ctx, &state, struct cli_getatr_state);
+ if (req == NULL) {
+ return NULL;
+ }
- p = smb_buf(cli->outbuf);
- *p++ = 4;
- p += clistr_push(cli, p, fname,
- cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE);
+ state->zone_offset = cli->serverzone;
- cli_setup_bcc(cli, p);
+ 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);
- cli_send_smb(cli);
- if (!cli_receive_smb(cli)) {
- return False;
+ if (tevent_req_nomem(bytes, req)) {
+ return tevent_req_post(req, ev);
}
- if (cli_is_error(cli)) {
- return False;
+ subreq = cli_smb_send(state, ev, cli, SMBgetatr, additional_flags,
+ 0, NULL, talloc_get_size(bytes), bytes);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
}
+ tevent_req_set_callback(subreq, cli_getatr_done, req);
+ return req;
+}
- if (size) {
- *size = IVAL(cli->inbuf, smb_vwv3);
+static void cli_getatr_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct cli_getatr_state *state = tevent_req_data(
+ req, struct cli_getatr_state);
+ uint8_t wct;
+ uint16_t *vwv = NULL;
+ NTSTATUS status;
+
+ status = cli_smb_recv(subreq, 4, &wct, &vwv, NULL, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ tevent_req_nterror(req, status);
+ return;
}
+ state->attr = SVAL(vwv+0,0);
+ state->size = (SMB_OFF_T)IVAL(vwv+3,0);
+ state->write_time = make_unix_date3(vwv+1, state->zone_offset);
+
+ TALLOC_FREE(subreq);
+ tevent_req_done(req);
+}
+
+NTSTATUS cli_getatr_recv(struct tevent_req *req,
+ uint16_t *attr,
+ SMB_OFF_T *size,
+ time_t *write_time)
+{
+ struct cli_getatr_state *state = tevent_req_data(
+ req, struct cli_getatr_state);
+ NTSTATUS status;
+
+ if (tevent_req_is_nterror(req, &status)) {
+ return status;
+ }
+ if (attr) {
+ *attr = state->attr;
+ }
+ if (size) {
+ *size = state->size;
+ }
if (write_time) {
- *write_time = cli_make_unix_date3(cli, cli->inbuf+smb_vwv1);
+ *write_time = state->write_time;
}
+ return NT_STATUS_OK;
+}
- if (attr) {
- *attr = SVAL(cli->inbuf,smb_vwv0);
+NTSTATUS cli_getatr(struct cli_state *cli,
+ const char *fname,
+ uint16_t *attr,
+ SMB_OFF_T *size,
+ time_t *write_time)
+{
+ 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;
}
- return True;
+ ev = event_context_init(frame);
+ if (ev == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto fail;
+ }
+
+ req = cli_getatr_send(frame, ev, cli, fname);
+ 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_getatr_recv(req,
+ attr,
+ size,
+ write_time);
+
+ fail:
+ TALLOC_FREE(frame);
+ if (!NT_STATUS_IS_OK(status)) {
+ cli_set_error(cli, status);
+ }
+ return status;
}
/****************************************************************************
diff --git a/source3/libsmb/libsmb_file.c b/source3/libsmb/libsmb_file.c
index a56126587a..63590d2fdf 100644
--- a/source3/libsmb/libsmb_file.c
+++ b/source3/libsmb/libsmb_file.c
@@ -578,7 +578,7 @@ SMBC_getatr(SMBCCTX * context,
return False;
}
- if (cli_getatr(targetcli, targetpath, mode, size, &write_time)) {
+ if (NT_STATUS_IS_OK(cli_getatr(targetcli, targetpath, mode, size, &write_time))) {
struct timespec w_time_ts;