diff options
Diffstat (limited to 'source3/libsmb')
-rw-r--r-- | source3/libsmb/clifile.c | 389 | ||||
-rw-r--r-- | source3/libsmb/errormap.c | 41 | ||||
-rw-r--r-- | source3/libsmb/libsmb_dir.c | 3 |
3 files changed, 346 insertions, 87 deletions
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index 5be18366b9..3d1da5f412 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -596,44 +596,6 @@ bool cli_unlink(struct cli_state *cli, const char *fname) return cli_unlink_full(cli, fname, aSYSTEM | aHIDDEN); } -#if 0 -/**************************************************************************** - Create a directory. -****************************************************************************/ - -bool cli_mkdir(struct cli_state *cli, const char *dname) -{ - char *p; - - memset(cli->outbuf,'\0',smb_size); - memset(cli->inbuf,'\0',smb_size); - - cli_set_message(cli->outbuf,0, 0, true); - - SCVAL(cli->outbuf,smb_com,SMBmkdir); - SSVAL(cli->outbuf,smb_tid,cli->cnum); - cli_setup_packet(cli); - - p = smb_buf(cli->outbuf); - *p++ = 4; - p += clistr_push(cli, p, dname, - cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); - - cli_setup_bcc(cli, p); - - cli_send_smb(cli); - if (!cli_receive_smb(cli)) { - return False; - } - - if (cli_is_error(cli)) { - return False; - } - - return True; -} -#endif - /**************************************************************************** Create a directory. ****************************************************************************/ @@ -660,8 +622,8 @@ struct tevent_req *cli_mkdir_send(TALLOC_CTX *mem_ctx, } bytes = talloc_array(state, uint8_t, 1); - if (!bytes) { - return NULL; + if (tevent_req_nomem(bytes, req)) { + return tevent_req_post(req, ev); } bytes[0] = 4; bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), dname, @@ -672,7 +634,7 @@ struct tevent_req *cli_mkdir_send(TALLOC_CTX *mem_ctx, } subreq = cli_smb_send(state, ev, cli, SMBmkdir, additional_flags, - 0, NULL, talloc_get_size(bytes), bytes); + 0, NULL, talloc_get_size(bytes), bytes); if (tevent_req_nomem(subreq, req)) { return tevent_req_post(req, ev); } @@ -746,36 +708,108 @@ NTSTATUS cli_mkdir(struct cli_state *cli, const char *dname) Remove a directory. ****************************************************************************/ -bool cli_rmdir(struct cli_state *cli, const char *dname) +static void cli_rmdir_done(struct tevent_req *subreq); + +struct cli_rmdir_state { + int dummy; +}; + +struct tevent_req *cli_rmdir_send(TALLOC_CTX *mem_ctx, + struct event_context *ev, + struct cli_state *cli, + const char *dname) { - char *p; + struct tevent_req *req = NULL, *subreq = NULL; + struct cli_rmdir_state *state = NULL; + uint8_t additional_flags = 0; + uint8_t *bytes = NULL; - memset(cli->outbuf,'\0',smb_size); - memset(cli->inbuf,'\0',smb_size); + req = tevent_req_create(mem_ctx, &state, struct cli_rmdir_state); + if (req == NULL) { + return NULL; + } - cli_set_message(cli->outbuf,0, 0, true); + 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), dname, + strlen(dname)+1, NULL); - SCVAL(cli->outbuf,smb_com,SMBrmdir); - SSVAL(cli->outbuf,smb_tid,cli->cnum); - cli_setup_packet(cli); + if (tevent_req_nomem(bytes, req)) { + return tevent_req_post(req, ev); + } - p = smb_buf(cli->outbuf); - *p++ = 4; - p += clistr_push(cli, p, dname, - cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); + subreq = cli_smb_send(state, ev, cli, SMBrmdir, 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_rmdir_done, req); + return req; +} - cli_setup_bcc(cli, p); +static void cli_rmdir_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + NTSTATUS status; - cli_send_smb(cli); - if (!cli_receive_smb(cli)) { - return false; + 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); +} - if (cli_is_error(cli)) { - return false; +NTSTATUS cli_rmdir_recv(struct tevent_req *req) +{ + return tevent_req_simple_recv_ntstatus(req); +} + +NTSTATUS cli_rmdir(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; } - return true; + ev = event_context_init(frame); + if (ev == NULL) { + status = NT_STATUS_NO_MEMORY; + goto fail; + } + + req = cli_rmdir_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_rmdir_recv(req); + + fail: + TALLOC_FREE(frame); + if (!NT_STATUS_IS_OK(status)) { + cli_set_error(cli, status); + } + return status; } /**************************************************************************** @@ -2010,55 +2044,239 @@ bool cli_setatr(struct cli_state *cli, const char *fname, uint16 attr, time_t t) Check for existance of a dir. ****************************************************************************/ -bool cli_chkpath(struct cli_state *cli, const char *path) +static void cli_chkpath_done(struct tevent_req *subreq); + +struct cli_chkpath_state { + int dummy; +}; + +struct tevent_req *cli_chkpath_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_chkpath_state *state = NULL; + uint8_t additional_flags = 0; + uint8_t *bytes = NULL; + + req = tevent_req_create(mem_ctx, &state, struct cli_chkpath_state); + if (req == NULL) { + return NULL; + } + + 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); + } + + subreq = cli_smb_send(state, ev, cli, SMBcheckpath, 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_chkpath_done, req); + return req; +} + +static void cli_chkpath_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_chkpath_recv(struct tevent_req *req) +{ + return tevent_req_simple_recv_ntstatus(req); +} + +NTSTATUS cli_chkpath(struct cli_state *cli, const char *path) { - char *path2 = NULL; - char *p; TALLOC_CTX *frame = talloc_stackframe(); + struct event_context *ev = NULL; + struct tevent_req *req = NULL; + char *path2 = 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; + } path2 = talloc_strdup(frame, path); if (!path2) { - TALLOC_FREE(frame); - return false; + status = NT_STATUS_NO_MEMORY; + goto fail; } trim_char(path2,'\0','\\'); if (!*path2) { path2 = talloc_strdup(frame, "\\"); if (!path2) { - TALLOC_FREE(frame); - return false; + status = NT_STATUS_NO_MEMORY; + goto fail; } } - memset(cli->outbuf,'\0',smb_size); - cli_set_message(cli->outbuf,0,0,True); - SCVAL(cli->outbuf,smb_com,SMBcheckpath); - SSVAL(cli->outbuf,smb_tid,cli->cnum); - cli_setup_packet(cli); - p = smb_buf(cli->outbuf); - *p++ = 4; - p += clistr_push(cli, p, path2, - cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); - - cli_setup_bcc(cli, p); + ev = event_context_init(frame); + if (ev == NULL) { + status = NT_STATUS_NO_MEMORY; + goto fail; + } - cli_send_smb(cli); - if (!cli_receive_smb(cli)) { - TALLOC_FREE(frame); - return False; + req = cli_chkpath_send(frame, ev, cli, path2); + if (req == NULL) { + status = NT_STATUS_NO_MEMORY; + goto fail; } - TALLOC_FREE(frame); + if (!tevent_req_poll(req, ev)) { + status = map_nt_error_from_unix(errno); + goto fail; + } - if (cli_is_error(cli)) return False; + status = cli_chkpath_recv(req); - return True; + fail: + TALLOC_FREE(frame); + if (!NT_STATUS_IS_OK(status)) { + cli_set_error(cli, status); + } + return status; } /**************************************************************************** Query disk space. ****************************************************************************/ +static void cli_dskattr_done(struct tevent_req *subreq); + +struct cli_dskattr_state { + int bsize; + int total; + int avail; +}; + +struct tevent_req *cli_dskattr_send(TALLOC_CTX *mem_ctx, + struct event_context *ev, + struct cli_state *cli) +{ + struct tevent_req *req = NULL, *subreq = NULL; + struct cli_dskattr_state *state = NULL; + uint8_t additional_flags = 0; + + req = tevent_req_create(mem_ctx, &state, struct cli_dskattr_state); + if (req == NULL) { + return NULL; + } + + subreq = cli_smb_send(state, ev, cli, SMBdskattr, additional_flags, + 0, NULL, 0, NULL); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, cli_dskattr_done, req); + return req; +} + +static void cli_dskattr_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct cli_dskattr_state *state = tevent_req_data( + req, struct cli_dskattr_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->bsize = SVAL(vwv+1, 0)*SVAL(vwv+2,0); + state->total = SVAL(vwv+0, 0); + state->avail = SVAL(vwv+3, 0); + TALLOC_FREE(subreq); + tevent_req_done(req); +} + +NTSTATUS cli_dskattr_recv(struct tevent_req *req, int *bsize, int *total, int *avail) +{ + struct cli_dskattr_state *state = tevent_req_data( + req, struct cli_dskattr_state); + NTSTATUS status; + + if (tevent_req_is_nterror(req, &status)) { + return status; + } + *bsize = state->bsize; + *total = state->total; + *avail = state->avail; + return NT_STATUS_OK; +} + +NTSTATUS cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail) +{ + 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_dskattr_send(frame, ev, cli); + 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_dskattr_recv(req, bsize, total, avail); + + fail: + TALLOC_FREE(frame); + if (!NT_STATUS_IS_OK(status)) { + cli_set_error(cli, status); + } + return status; +} + +#if 0 bool cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail) { memset(cli->outbuf,'\0',smb_size); @@ -2078,6 +2296,7 @@ bool cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail) return True; } +#endif /**************************************************************************** Create and open a temporary file. diff --git a/source3/libsmb/errormap.c b/source3/libsmb/errormap.c index 4ec30f7e17..0285f22be4 100644 --- a/source3/libsmb/errormap.c +++ b/source3/libsmb/errormap.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "nsswitch/libwbclient/wbclient.h" /* This map was extracted by the ERRMAPEXTRACT smbtorture command. The setup was a Samba HEAD (2002-01-03) PDC and an Win2k member @@ -1503,6 +1504,46 @@ WERROR ntstatus_to_werror(NTSTATUS error) return W_ERROR(NT_STATUS_V(error) & 0xffff); } +/******************************************************************************* + Map between wbcErr and NT status. +*******************************************************************************/ + +static const struct { + wbcErr wbc_err; + NTSTATUS nt_status; +} wbcErr_ntstatus_map[] = { + { WBC_ERR_SUCCESS, NT_STATUS_OK }, + { WBC_ERR_NOT_IMPLEMENTED, NT_STATUS_NOT_IMPLEMENTED }, + { WBC_ERR_UNKNOWN_FAILURE, NT_STATUS_UNSUCCESSFUL }, + { WBC_ERR_NO_MEMORY, NT_STATUS_NO_MEMORY }, + { WBC_ERR_INVALID_SID, NT_STATUS_INVALID_SID }, + { WBC_ERR_INVALID_PARAM, NT_STATUS_INVALID_PARAMETER }, + { WBC_ERR_WINBIND_NOT_AVAILABLE, NT_STATUS_SERVER_DISABLED }, + { WBC_ERR_DOMAIN_NOT_FOUND, NT_STATUS_NO_SUCH_DOMAIN }, + { WBC_ERR_INVALID_RESPONSE, NT_STATUS_INVALID_NETWORK_RESPONSE }, + { WBC_ERR_NSS_ERROR, NT_STATUS_INTERNAL_ERROR }, + { WBC_ERR_AUTH_ERROR, NT_STATUS_LOGON_FAILURE }, + { WBC_ERR_UNKNOWN_USER, NT_STATUS_NO_SUCH_USER }, + { WBC_ERR_UNKNOWN_GROUP, NT_STATUS_NO_SUCH_GROUP }, + { WBC_ERR_PWD_CHANGE_FAILED, NT_STATUS_PASSWORD_RESTRICTION } +}; + +NTSTATUS map_nt_error_from_wbcErr(wbcErr wbc_err) +{ + int i; + + /* Look through list */ + for (i=0;i<ARRAY_SIZE(wbcErr_ntstatus_map);i++) { + if (wbcErr_ntstatus_map[i].wbc_err == wbc_err) { + return wbcErr_ntstatus_map[i].nt_status; + } + } + + /* Default return */ + return NT_STATUS_UNSUCCESSFUL; +} + + #if defined(HAVE_GSSAPI) /******************************************************************************* Map between gssapi errors and NT status. I made these up :-(. JRA. diff --git a/source3/libsmb/libsmb_dir.c b/source3/libsmb/libsmb_dir.c index 5afc8e48b6..508810538f 100644 --- a/source3/libsmb/libsmb_dir.c +++ b/source3/libsmb/libsmb_dir.c @@ -1284,8 +1284,7 @@ SMBC_rmdir_ctx(SMBCCTX *context, } /*d_printf(">>>rmdir: resolved path as %s\n", targetpath);*/ - - if (!cli_rmdir(targetcli, targetpath)) { + if (!NT_STATUS_IS_OK(cli_rmdir(targetcli, targetpath))) { errno = SMBC_errno(context, targetcli); |