summaryrefslogtreecommitdiff
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
parent1db0b20d8a26fb60299d0ed7553d7a4847aee84f (diff)
downloadsamba-4cbd0c77e42627c76dda88af5326ef91415a652d.tar.gz
samba-4cbd0c77e42627c76dda88af5326ef91415a652d.tar.bz2
samba-4cbd0c77e42627c76dda88af5326ef91415a652d.zip
Make cli_getatr() async.
Jeremy.
-rw-r--r--source3/client/clitar.c4
-rw-r--r--source3/include/proto.h16
-rw-r--r--source3/lib/time.c2
-rw-r--r--source3/libsmb/clifile.c151
-rw-r--r--source3/libsmb/libsmb_file.c2
-rw-r--r--source3/torture/torture.c10
6 files changed, 149 insertions, 36 deletions
diff --git a/source3/client/clitar.c b/source3/client/clitar.c
index fd6c4ccef9..80f6c81880 100644
--- a/source3/client/clitar.c
+++ b/source3/client/clitar.c
@@ -594,7 +594,9 @@ static void do_setrattr(char *name, uint16 attr, int set)
{
uint16 oldattr;
- if (!cli_getatr(cli, name, &oldattr, NULL, NULL)) return;
+ if (!NT_STATUS_IS_OK(cli_getatr(cli, name, &oldattr, NULL, NULL))) {
+ return;
+ }
if (set == ATTRSET) {
attr |= oldattr;
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 30c11a50ee..194d74db5e 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1018,6 +1018,7 @@ struct timespec get_ctimespec(const SMB_STRUCT_STAT *pst);
void set_ctimespec(SMB_STRUCT_STAT *pst, struct timespec ts);
void dos_filetime_timespec(struct timespec *tsp);
time_t make_unix_date2(const void *date_ptr, int zone_offset);
+time_t make_unix_date3(const void *date_ptr, int zone_offset);
time_t srv_make_unix_date(const void *date_ptr);
time_t srv_make_unix_date2(const void *date_ptr);
time_t srv_make_unix_date3(const void *date_ptr);
@@ -2459,12 +2460,23 @@ NTSTATUS cli_getattrE(struct cli_state *cli,
time_t *change_time,
time_t *access_time,
time_t *write_time);
-bool cli_getatr(struct cli_state *cli, const char *fname,
- uint16_t *attr, SMB_OFF_T *size, time_t *write_time);
bool cli_setattrE(struct cli_state *cli, int fd,
time_t change_time,
time_t access_time,
time_t write_time);
+struct tevent_req *cli_getatr_send(TALLOC_CTX *mem_ctx,
+ struct event_context *ev,
+ struct cli_state *cli,
+ const char *fname);
+NTSTATUS cli_getatr_recv(struct tevent_req *req,
+ uint16_t *attr,
+ SMB_OFF_T *size,
+ time_t *write_time);
+NTSTATUS cli_getatr(struct cli_state *cli,
+ const char *fname,
+ uint16_t *attr,
+ SMB_OFF_T *size,
+ time_t *write_time);
bool cli_setatr(struct cli_state *cli, const char *fname, uint16_t attr, time_t t);
struct tevent_req *cli_chkpath_send(TALLOC_CTX *mem_ctx,
struct event_context *ev,
diff --git a/source3/lib/time.c b/source3/lib/time.c
index 3e45a2e6e4..611debe366 100644
--- a/source3/lib/time.c
+++ b/source3/lib/time.c
@@ -621,7 +621,7 @@ time_t make_unix_date2(const void *date_ptr, int zone_offset)
these generally arrive as localtimes, with corresponding DST.
******************************************************************/
-static time_t make_unix_date3(const void *date_ptr, int zone_offset)
+time_t make_unix_date3(const void *date_ptr, int zone_offset)
{
time_t t = (time_t)IVAL(date_ptr,0);
if (!null_mtime(t)) {
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;
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 00e8266a22..bc7ac12a76 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -2471,7 +2471,7 @@ static bool run_attrtest(int dummy)
cli_open(cli, fname,
O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
cli_close(cli, fnum);
- if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
+ if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
printf("getatr failed (%s)\n", cli_errstr(cli));
correct = False;
}
@@ -2490,7 +2490,7 @@ static bool run_attrtest(int dummy)
correct = True;
}
- if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
+ if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
printf("getatr failed (%s)\n", cli_errstr(cli));
correct = True;
}
@@ -3796,7 +3796,7 @@ static bool run_opentest(int dummy)
}
/* Ensure size == 20. */
- if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
+ if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
return False;
}
@@ -3819,7 +3819,7 @@ static bool run_opentest(int dummy)
}
/* Ensure size == 0. */
- if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
+ if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
return False;
}
@@ -4285,7 +4285,7 @@ static bool run_openattrtest(int dummy)
return False;
}
- if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
+ if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, &attr, NULL, NULL))) {
printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
return False;
}