diff options
-rw-r--r-- | source3/client/clitar.c | 4 | ||||
-rw-r--r-- | source3/include/proto.h | 12 | ||||
-rw-r--r-- | source3/libsmb/clifile.c | 127 | ||||
-rw-r--r-- | source3/libsmb/libsmb_dir.c | 2 | ||||
-rw-r--r-- | source3/libsmb/libsmb_file.c | 2 | ||||
-rw-r--r-- | source3/torture/torture.c | 4 | ||||
-rw-r--r-- | source3/utils/net_rpc_printer.c | 2 |
7 files changed, 145 insertions, 8 deletions
diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 80f6c81880..ff71924555 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -604,7 +604,7 @@ static void do_setrattr(char *name, uint16 attr, int set) attr = oldattr & ~attr; } - if (!cli_setatr(cli, name, attr, 0)) { + if (!NT_STATUS_IS_OK(cli_setatr(cli, name, attr, 0))) { DEBUG(1,("setatr failed: %s\n", cli_errstr(cli))); } } @@ -1078,7 +1078,7 @@ static int get_file(file_info2 finfo) /* Now we update the creation date ... */ DEBUG(5, ("Updating creation date on %s\n", finfo.name)); - if (!cli_setatr(cli, finfo.name, finfo.mode, finfo.mtime_ts.tv_sec)) { + if (!NT_STATUS_IS_OK(cli_setatr(cli, finfo.name, finfo.mode, finfo.mtime_ts.tv_sec))) { if (tar_real_noisy) { DEBUG(0, ("Could not set time on file: %s\n", finfo.name)); /*return(False); */ /* Ignore, as Win95 does not allow changes */ diff --git a/source3/include/proto.h b/source3/include/proto.h index 9a8b6a8fc9..c8b79278ea 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -2486,7 +2486,17 @@ NTSTATUS cli_getatr(struct cli_state *cli, 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_setatr_send(TALLOC_CTX *mem_ctx, + struct event_context *ev, + struct cli_state *cli, + const char *fname, + uint16_t attr, + time_t mtime); +NTSTATUS cli_setatr_recv(struct tevent_req *req); +NTSTATUS cli_setatr(struct cli_state *cli, + const char *fname, + uint16_t attr, + time_t mtime); struct tevent_req *cli_chkpath_send(TALLOC_CTX *mem_ctx, struct event_context *ev, struct cli_state *cli, 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) { diff --git a/source3/torture/torture.c b/source3/torture/torture.c index bc7ac12a76..9c0449a16e 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -2485,7 +2485,7 @@ static bool run_attrtest(int dummy) t2 = t-60*60*24; /* 1 day ago */ - if (!cli_setatr(cli, fname, 0, t2)) { + if (!NT_STATUS_IS_OK(cli_setatr(cli, fname, 0, t2))) { printf("setatr failed (%s)\n", cli_errstr(cli)); correct = True; } @@ -3726,7 +3726,7 @@ static bool run_opentest(int dummy) return False; } - if (!cli_setatr(cli1, fname, aRONLY, 0)) { + if (!NT_STATUS_IS_OK(cli_setatr(cli1, fname, aRONLY, 0))) { printf("cli_setatr failed (%s)\n", cli_errstr(cli1)); return False; } diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index b01c5af1dd..3914a42ade 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -243,7 +243,7 @@ NTSTATUS net_copy_fileattr(struct net_context *c, if (copy_attrs) { /* set attrs */ - if (!cli_setatr(cli_share_dst, dst_name, attr, 0)) { + if (!NT_STATUS_IS_OK(cli_setatr(cli_share_dst, dst_name, attr, 0))) { DEBUG(0,("failed to set file-attrs: %s\n", cli_errstr(cli_share_dst))); nt_status = cli_nt_error(cli_share_dst); |