diff options
author | Jeremy Allison <jra@samba.org> | 2009-04-21 05:52:34 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2009-04-21 05:52:34 -0700 |
commit | dfc79de607e94179114a8e1d0b0e56117f34595b (patch) | |
tree | 4e717d763a1c19f0cb1926804e6f977d56a0cec5 /source3 | |
parent | 4024abb0a80e5ec10dd2f86b378bcea89b919050 (diff) | |
download | samba-dfc79de607e94179114a8e1d0b0e56117f34595b.tar.gz samba-dfc79de607e94179114a8e1d0b0e56117f34595b.tar.bz2 samba-dfc79de607e94179114a8e1d0b0e56117f34595b.zip |
Make cli_mkdir async. Change it to return NTSTATUS.
Jeremy.
Diffstat (limited to 'source3')
-rw-r--r-- | source3/client/client.c | 2 | ||||
-rw-r--r-- | source3/client/clitar.c | 2 | ||||
-rw-r--r-- | source3/include/proto.h | 2 | ||||
-rw-r--r-- | source3/libsmb/clifile.c | 110 | ||||
-rw-r--r-- | source3/libsmb/libsmb_dir.c | 3 | ||||
-rw-r--r-- | source3/torture/mangle_test.c | 2 | ||||
-rw-r--r-- | source3/torture/torture.c | 10 | ||||
-rw-r--r-- | source3/torture/utable.c | 2 | ||||
-rw-r--r-- | source3/utils/net_rpc_printer.c | 4 |
9 files changed, 123 insertions, 14 deletions
diff --git a/source3/client/client.c b/source3/client/client.c index fcb9b27f1f..d74de35bc5 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -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; diff --git a/source3/client/clitar.c b/source3/client/clitar.c index c9f3e87c4d..7512583e19 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -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))); diff --git a/source3/include/proto.h b/source3/include/proto.h index fa6dafa1b0..3ddbf6f3b9 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -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, diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index 0a1168fd0f..5be18366b9 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -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. diff --git a/source3/libsmb/libsmb_dir.c b/source3/libsmb/libsmb_dir.c index 219bbe64e1..5afc8e48b6 100644 --- a/source3/libsmb/libsmb_dir.c +++ b/source3/libsmb/libsmb_dir.c @@ -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; diff --git a/source3/torture/mangle_test.c b/source3/torture/mangle_test.c index 00457719a8..525a1eb3c3 100644 --- a/source3/torture/mangle_test.c +++ b/source3/torture/mangle_test.c @@ -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; } diff --git a/source3/torture/torture.c b/source3/torture/torture.c index 07945fccf1..0328cfe545 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -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)) { diff --git a/source3/torture/utable.c b/source3/torture/utable.c index e36b0388c4..aaa763a2a3 100644 --- a/source3/torture/utable.c +++ b/source3/torture/utable.c @@ -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; } diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 9721628f02..477ddf7f26 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -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; |