summaryrefslogtreecommitdiff
path: root/source/lib/netapi/cm.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/lib/netapi/cm.c')
-rw-r--r--source/lib/netapi/cm.c95
1 files changed, 43 insertions, 52 deletions
diff --git a/source/lib/netapi/cm.c b/source/lib/netapi/cm.c
index a5c85bfe6b..071ebfd4bc 100644
--- a/source/lib/netapi/cm.c
+++ b/source/lib/netapi/cm.c
@@ -25,9 +25,9 @@
/********************************************************************
********************************************************************/
-static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx,
- const char *server_name,
- struct cli_state **cli)
+WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx,
+ const char *server_name,
+ struct cli_state **cli)
{
struct cli_state *cli_ipc = NULL;
@@ -91,107 +91,98 @@ static struct client_pipe_connection *pipe_connections;
/********************************************************************
********************************************************************/
-static NTSTATUS pipe_cm_find(struct cli_state *cli,
- const struct ndr_syntax_id *interface,
- struct rpc_pipe_client **presult)
+static struct rpc_pipe_client *pipe_cm_find(struct cli_state *cli,
+ int pipe_idx,
+ NTSTATUS *status)
{
struct client_pipe_connection *p;
for (p = pipe_connections; p; p = p->next) {
- if (!rpc_pipe_np_smb_conn(p->pipe)) {
- return NT_STATUS_PIPE_EMPTY;
+ if (!p->pipe->cli) {
+ *status = NT_STATUS_PIPE_EMPTY;
+ return NULL;
}
- if (strequal(cli->desthost, p->pipe->desthost)
- && ndr_syntax_id_equal(&p->pipe->abstract_syntax,
- interface)) {
- *presult = p->pipe;
- return NT_STATUS_OK;
+ if (strequal(cli->desthost, p->pipe->cli->desthost) &&
+ pipe_idx == p->pipe->pipe_idx) {
+ *status = NT_STATUS_OK;
+ return p->pipe;
}
}
- return NT_STATUS_PIPE_NOT_AVAILABLE;
+ *status = NT_STATUS_PIPE_NOT_AVAILABLE;
+
+ return NULL;
}
/********************************************************************
********************************************************************/
-static NTSTATUS pipe_cm_connect(TALLOC_CTX *mem_ctx,
- struct cli_state *cli,
- const struct ndr_syntax_id *interface,
- struct rpc_pipe_client **presult)
+static struct rpc_pipe_client *pipe_cm_connect(TALLOC_CTX *mem_ctx,
+ struct cli_state *cli,
+ int pipe_idx,
+ NTSTATUS *status)
{
struct client_pipe_connection *p;
- NTSTATUS status;
p = TALLOC_ZERO_ARRAY(mem_ctx, struct client_pipe_connection, 1);
if (!p) {
- return NT_STATUS_NO_MEMORY;
+ *status = NT_STATUS_NO_MEMORY;
+ return NULL;
}
- status = cli_rpc_pipe_open_noauth(cli, interface, &p->pipe);
- if (!NT_STATUS_IS_OK(status)) {
+ p->pipe = cli_rpc_pipe_open_noauth(cli, pipe_idx, status);
+ if (!p->pipe) {
TALLOC_FREE(p);
- return status;
+ return NULL;
}
DLIST_ADD(pipe_connections, p);
- *presult = p->pipe;
- return NT_STATUS_OK;
+ return p->pipe;
}
/********************************************************************
********************************************************************/
-static NTSTATUS pipe_cm_open(TALLOC_CTX *ctx,
- struct cli_state *cli,
- const struct ndr_syntax_id *interface,
- struct rpc_pipe_client **presult)
+static struct rpc_pipe_client *pipe_cm_open(TALLOC_CTX *ctx,
+ struct cli_state *cli,
+ int pipe_idx,
+ NTSTATUS *status)
{
- if (NT_STATUS_IS_OK(pipe_cm_find(cli, interface, presult))) {
- return NT_STATUS_OK;
+ struct rpc_pipe_client *p;
+
+ p = pipe_cm_find(cli, pipe_idx, status);
+ if (!p) {
+ p = pipe_cm_connect(ctx, cli, pipe_idx, status);
}
- return pipe_cm_connect(ctx, cli, interface, presult);
+ return p;
}
/********************************************************************
********************************************************************/
WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx,
- const char *server_name,
- const struct ndr_syntax_id *interface,
- struct cli_state **pcli,
- struct rpc_pipe_client **presult)
+ struct cli_state *cli,
+ int pipe_idx,
+ struct rpc_pipe_client **pipe_cli)
{
- struct rpc_pipe_client *result = NULL;
NTSTATUS status;
- WERROR werr;
- struct cli_state *cli = NULL;
- if (!presult) {
+ if (!cli || !pipe_cli) {
return WERR_INVALID_PARAM;
}
- werr = libnetapi_open_ipc_connection(ctx, server_name, &cli);
- if (!W_ERROR_IS_OK(werr)) {
- return werr;
- }
-
- status = pipe_cm_open(ctx, cli, interface, &result);
- if (!NT_STATUS_IS_OK(status)) {
+ *pipe_cli = pipe_cm_open(ctx, cli, pipe_idx, &status);
+ if (!*pipe_cli) {
libnetapi_set_error_string(ctx, "failed to open PIPE %s: %s",
- cli_get_pipe_name_from_iface(debug_ctx(), cli,
- interface),
+ cli_get_pipe_name(pipe_idx),
get_friendly_nt_error_msg(status));
return WERR_DEST_NOT_FOUND;
}
- *presult = result;
- *pcli = cli;
-
return WERR_OK;
}