1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

Make cli_mkdir async. Change it to return NTSTATUS.

Jeremy.
This commit is contained in:
Jeremy Allison 2009-04-21 05:52:34 -07:00
parent 4024abb0a8
commit dfc79de607
9 changed files with 123 additions and 14 deletions

View File

@ -1389,7 +1389,7 @@ static bool do_mkdir(const char *name)
return false;
}
if (!cli_mkdir(targetcli, targetname)) {
if (!NT_STATUS_IS_OK(cli_mkdir(targetcli, targetname))) {
d_printf("%s making remote directory %s\n",
cli_errstr(targetcli),name);
return false;

View File

@ -555,7 +555,7 @@ static bool ensurepath(const char *fname)
safe_strcat(partpath, p, strlen(fname) + 1);
if (!cli_chkpath(cli, partpath)) {
if (!cli_mkdir(cli, partpath)) {
if (!NT_STATUS_IS_OK(cli_mkdir(cli, partpath))) {
SAFE_FREE(partpath);
SAFE_FREE(ffname);
DEBUG(0, ("Error mkdir %s\n", cli_errstr(cli)));

View File

@ -2338,7 +2338,7 @@ bool cli_ntrename(struct cli_state *cli, const char *fname_src, const char *fnam
bool cli_nt_hardlink(struct cli_state *cli, const char *fname_src, const char *fname_dst);
bool cli_unlink_full(struct cli_state *cli, const char *fname, uint16 attrs);
bool cli_unlink(struct cli_state *cli, const char *fname);
bool cli_mkdir(struct cli_state *cli, const char *dname);
NTSTATUS cli_mkdir(struct cli_state *cli, const char *dname);
bool cli_rmdir(struct cli_state *cli, const char *dname);
int cli_nt_delete_on_close(struct cli_state *cli, int fnum, bool flag);
int cli_nt_create_full(struct cli_state *cli, const char *fname,

View File

@ -596,6 +596,7 @@ bool cli_unlink(struct cli_state *cli, const char *fname)
return cli_unlink_full(cli, fname, aSYSTEM | aHIDDEN);
}
#if 0
/****************************************************************************
Create a directory.
****************************************************************************/
@ -631,6 +632,115 @@ bool cli_mkdir(struct cli_state *cli, const char *dname)
return True;
}
#endif
/****************************************************************************
Create a directory.
****************************************************************************/
static void cli_mkdir_done(struct tevent_req *subreq);
struct cli_mkdir_state {
int dummy;
};
struct tevent_req *cli_mkdir_send(TALLOC_CTX *mem_ctx,
struct event_context *ev,
struct cli_state *cli,
const char *dname)
{
struct tevent_req *req = NULL, *subreq = NULL;
struct cli_mkdir_state *state = NULL;
uint8_t additional_flags = 0;
uint8_t *bytes = NULL;
req = tevent_req_create(mem_ctx, &state, struct cli_mkdir_state);
if (req == NULL) {
return NULL;
}
bytes = talloc_array(state, uint8_t, 1);
if (!bytes) {
return NULL;
}
bytes[0] = 4;
bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), dname,
strlen(dname)+1, NULL);
if (tevent_req_nomem(bytes, req)) {
return tevent_req_post(req, ev);
}
subreq = cli_smb_send(state, ev, cli, SMBmkdir, 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_mkdir_done, req);
return req;
}
static void cli_mkdir_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_mkdir_recv(struct tevent_req *req)
{
return tevent_req_simple_recv_ntstatus(req);
}
NTSTATUS cli_mkdir(struct cli_state *cli, const char *dname)
{
TALLOC_CTX *frame = talloc_stackframe();
struct event_context *ev;
struct tevent_req *req;
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_mkdir_send(frame, ev, cli, dname);
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_mkdir_recv(req);
fail:
TALLOC_FREE(frame);
if (!NT_STATUS_IS_OK(status)) {
cli_set_error(cli, status);
}
return status;
}
/****************************************************************************
Remove a directory.

View File

@ -1177,8 +1177,7 @@ SMBC_mkdir_ctx(SMBCCTX *context,
}
/*d_printf(">>>mkdir: resolved path as %s\n", targetpath);*/
if (!cli_mkdir(targetcli, targetpath)) {
if (!NT_STATUS_IS_OK(cli_mkdir(targetcli, targetpath))) {
errno = SMBC_errno(context, targetcli);
TALLOC_FREE(frame);
return -1;

View File

@ -180,7 +180,7 @@ bool torture_mangle(int dummy)
cli_unlink(cli, "\\mangle_test\\*");
cli_rmdir(cli, "\\mangle_test");
if (!cli_mkdir(cli, "\\mangle_test")) {
if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\mangle_test"))) {
printf("ERROR: Failed to make directory\n");
return False;
}

View File

@ -2625,7 +2625,7 @@ static bool run_trans2test(int dummy)
/* check if the server updates the directory modification time
when creating a new file */
if (!cli_mkdir(cli, dname)) {
if (!NT_STATUS_IS_OK(cli_mkdir(cli, dname))) {
printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
correct = False;
}
@ -4584,12 +4584,12 @@ bool torture_chkpath_test(int dummy)
cli_unlink(cli, "\\chkpath.dir\\*");
cli_rmdir(cli, "\\chkpath.dir");
if (!cli_mkdir(cli, "\\chkpath.dir")) {
if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir"))) {
printf("mkdir1 failed : %s\n", cli_errstr(cli));
return False;
}
if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir\\dir2"))) {
printf("mkdir2 failed : %s\n", cli_errstr(cli));
return False;
}
@ -4801,7 +4801,7 @@ static bool run_dirtest1(int dummy)
for (i=0;i<1000;i++) {
fstring fname;
slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
if (!cli_mkdir(cli, fname)) {
if (!NT_STATUS_IS_OK(cli_mkdir(cli, fname))) {
fprintf(stderr,"Failed to open %s\n", fname);
return False;
}
@ -5279,7 +5279,7 @@ static bool run_uid_regression_test(int dummy)
cli->vuid = old_vuid;
/* Try an operation. */
if (!cli_mkdir(cli, "\\uid_reg_test")) {
if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\uid_reg_test"))) {
/* We expect bad uid. */
if (!check_error(__LINE__, cli, ERRSRV, ERRbaduid,
NT_STATUS_NO_SUCH_USER)) {

View File

@ -132,7 +132,7 @@ bool torture_casetable(int dummy)
cli_unlink(cli, "\\utable\\*");
cli_rmdir(cli, "\\utable");
if (!cli_mkdir(cli, "\\utable")) {
if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\utable"))) {
printf("Failed to create utable directory!\n");
return False;
}

View File

@ -406,7 +406,7 @@ NTSTATUS net_copy_file(struct net_context *c,
DEBUGADD(3,("creating dir %s on the destination server\n",
dst_name));
if (!cli_mkdir(cli_share_dst, dst_name)) {
if (!NT_STATUS_IS_OK(cli_mkdir(cli_share_dst, dst_name))) {
DEBUG(0,("cannot create directory %s: %s\n",
dst_name, cli_errstr(cli_share_dst)));
nt_status = NT_STATUS_NO_SUCH_FILE;
@ -555,7 +555,7 @@ static NTSTATUS check_arch_dir(struct cli_state *cli_share, const char *short_ar
DEBUG(10,("creating print-driver dir for architecture: %s\n",
short_archi));
if (!cli_mkdir(cli_share, dir)) {
if (!NT_STATUS_IS_OK(cli_mkdir(cli_share, dir))) {
DEBUG(1,("cannot create directory %s: %s\n",
dir, cli_errstr(cli_share)));
nt_status = NT_STATUS_NO_SUCH_FILE;