diff --git a/source3/rpc_server/mdssvc/mdssvc.c b/source3/rpc_server/mdssvc/mdssvc.c index 956e097eaf4..fc6931f227e 100644 --- a/source3/rpc_server/mdssvc/mdssvc.c +++ b/source3/rpc_server/mdssvc/mdssvc.c @@ -1585,13 +1585,14 @@ static int mds_ctx_destructor_cb(struct mds_ctx *mds_ctx) * This ends up being called for every tcon, because the client does a * RPC bind for every tcon, so this is acually a per tcon context. **/ -struct mds_ctx *mds_init_ctx(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct messaging_context *msg_ctx, - struct auth_session_info *session_info, - int snum, - const char *sharename, - const char *path) +NTSTATUS mds_init_ctx(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct messaging_context *msg_ctx, + struct auth_session_info *session_info, + int snum, + const char *sharename, + const char *path, + struct mds_ctx **_mds_ctx) { const struct loadparm_substitution *lp_sub = loadparm_s3_global_substitution(); @@ -1605,13 +1606,13 @@ struct mds_ctx *mds_init_ctx(TALLOC_CTX *mem_ctx, mds_ctx = talloc_zero(mem_ctx, struct mds_ctx); if (mds_ctx == NULL) { - return NULL; + return NT_STATUS_NO_MEMORY; } talloc_set_destructor(mds_ctx, mds_ctx_destructor_cb); mds_ctx->mdssvc_ctx = mdssvc_init(ev); if (mds_ctx->mdssvc_ctx == NULL) { - goto error; + return NT_STATUS_NO_MEMORY; } backend = lp_spotlight_backend(snum); @@ -1637,6 +1638,7 @@ struct mds_ctx *mds_init_ctx(TALLOC_CTX *mem_ctx, default: DBG_ERR("Unknown backend %d\n", backend); TALLOC_FREE(mdssvc_ctx); + status = NT_STATUS_INTERNAL_ERROR; goto error; } @@ -1645,6 +1647,7 @@ struct mds_ctx *mds_init_ctx(TALLOC_CTX *mem_ctx, "UTF8-NFC", false); if (iconv_hnd == (smb_iconv_t)-1) { + status = NT_STATUS_INTERNAL_ERROR; goto error; } mds_ctx->ic_nfc_to_nfd = iconv_hnd; @@ -1654,17 +1657,20 @@ struct mds_ctx *mds_init_ctx(TALLOC_CTX *mem_ctx, "UTF8-NFD", false); if (iconv_hnd == (smb_iconv_t)-1) { + status = NT_STATUS_INTERNAL_ERROR; goto error; } mds_ctx->ic_nfd_to_nfc = iconv_hnd; mds_ctx->sharename = talloc_strdup(mds_ctx, sharename); if (mds_ctx->sharename == NULL) { + status = NT_STATUS_NO_MEMORY; goto error; } mds_ctx->spath = talloc_strdup(mds_ctx, path); if (mds_ctx->spath == NULL) { + status = NT_STATUS_NO_MEMORY; goto error; } @@ -1672,6 +1678,7 @@ struct mds_ctx *mds_init_ctx(TALLOC_CTX *mem_ctx, mds_ctx->pipe_session_info = session_info; if (session_info->security_token->num_sids < 1) { + status = NT_STATUS_BAD_LOGON_SESSION_STATE; goto error; } sid_copy(&mds_ctx->sid, &session_info->security_token->sids[0]); @@ -1680,6 +1687,7 @@ struct mds_ctx *mds_init_ctx(TALLOC_CTX *mem_ctx, mds_ctx->ino_path_map = db_open_rbt(mds_ctx); if (mds_ctx->ino_path_map == NULL) { DEBUG(1,("open inode map db failed\n")); + status = NT_STATUS_INTERNAL_ERROR; goto error; } @@ -1704,16 +1712,19 @@ struct mds_ctx *mds_init_ctx(TALLOC_CTX *mem_ctx, if (ret != 0) { DBG_ERR("vfs_ChDir [%s] failed: %s\n", conn_basedir.base_name, strerror(errno)); + status = map_nt_error_from_unix(errno); goto error; } ok = mds_ctx->backend->connect(mds_ctx); if (!ok) { DBG_ERR("backend connect failed\n"); + status = NT_STATUS_CONNECTION_RESET; goto error; } - return mds_ctx; + *_mds_ctx = mds_ctx; + return NT_STATUS_OK; error: if (mds_ctx->ic_nfc_to_nfd != NULL) { @@ -1724,7 +1735,7 @@ error: } TALLOC_FREE(mds_ctx); - return NULL; + return status; } /** diff --git a/source3/rpc_server/mdssvc/mdssvc.h b/source3/rpc_server/mdssvc/mdssvc.h index 392482767dd..205417c4be1 100644 --- a/source3/rpc_server/mdssvc/mdssvc.h +++ b/source3/rpc_server/mdssvc/mdssvc.h @@ -149,13 +149,14 @@ struct mdssvc_backend { */ extern bool mds_init(struct messaging_context *msg_ctx); extern bool mds_shutdown(void); -struct mds_ctx *mds_init_ctx(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct messaging_context *msg_ctx, - struct auth_session_info *session_info, - int snum, - const char *sharename, - const char *path); +NTSTATUS mds_init_ctx(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct messaging_context *msg_ctx, + struct auth_session_info *session_info, + int snum, + const char *sharename, + const char *path, + struct mds_ctx **_mds_ctx); extern bool mds_dispatch(struct mds_ctx *query_ctx, struct mdssvc_blob *request_blob, struct mdssvc_blob *response_blob); diff --git a/source3/rpc_server/mdssvc/srv_mdssvc_nt.c b/source3/rpc_server/mdssvc/srv_mdssvc_nt.c index 01c191bf01d..2d572a887d0 100644 --- a/source3/rpc_server/mdssvc/srv_mdssvc_nt.c +++ b/source3/rpc_server/mdssvc/srv_mdssvc_nt.c @@ -48,19 +48,22 @@ static NTSTATUS create_mdssvc_policy_handle(TALLOC_CTX *mem_ctx, struct auth_session_info *session_info = dcesrv_call_session_info(dce_call); struct mds_ctx *mds_ctx; + NTSTATUS status; ZERO_STRUCTP(handle); - mds_ctx = mds_init_ctx(mem_ctx, - messaging_tevent_context(p->msg_ctx), - p->msg_ctx, - session_info, - snum, - sharename, - path); - if (mds_ctx == NULL) { - DEBUG(1, ("error in mds_init_ctx for: %s\n", path)); - return NT_STATUS_UNSUCCESSFUL; + status = mds_init_ctx(mem_ctx, + messaging_tevent_context(p->msg_ctx), + p->msg_ctx, + session_info, + snum, + sharename, + path, + &mds_ctx); + if (!NT_STATUS_IS_OK(status)) { + DBG_WARNING("mds_init_ctx() path [%s] failed: %s\n", + path, nt_errstr(status)); + return status; } if (!create_policy_hnd(p, handle, 0, mds_ctx)) {