summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2008-04-10 22:42:07 +0200
committerGünther Deschner <gd@samba.org>2008-04-10 22:42:07 +0200
commit3d5aecd2b940215c2566b2e429c2cc3803ff0ad4 (patch)
treefb5c1ea807e3294dcd82f90c73ec110b2738d761 /source3
parentaeb7f7db4014695eb6510cc7a713db4c6228bd1f (diff)
downloadsamba-3d5aecd2b940215c2566b2e429c2cc3803ff0ad4.tar.gz
samba-3d5aecd2b940215c2566b2e429c2cc3803ff0ad4.tar.bz2
samba-3d5aecd2b940215c2566b2e429c2cc3803ff0ad4.zip
Add libnetapi_open_pipe, inspired by the cli_cm_ interface.
Guenther (This used to be commit 87d8fc338f6e6b48691bff3eeebfc00c5d408ff7)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/netapi/cm.c110
-rw-r--r--source3/lib/netapi/netapi_private.h4
2 files changed, 114 insertions, 0 deletions
diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c
index a3b842f96e..96087247d2 100644
--- a/source3/lib/netapi/cm.c
+++ b/source3/lib/netapi/cm.c
@@ -73,3 +73,113 @@ WERROR libnetapi_shutdown_cm(struct libnetapi_ctx *ctx)
return WERR_OK;
}
+
+/********************************************************************
+********************************************************************/
+
+struct client_pipe_connection {
+ struct client_pipe_connection *prev, *next;
+ struct rpc_pipe_client *pipe;
+};
+
+static struct client_pipe_connection *pipe_connections;
+
+/********************************************************************
+********************************************************************/
+
+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 (!p->pipe->cli) {
+ *status = NT_STATUS_PIPE_EMPTY;
+ return NULL;
+ }
+
+ if (strequal(cli->desthost, p->pipe->cli->desthost) &&
+ pipe_idx == p->pipe->pipe_idx) {
+ *status = NT_STATUS_OK;
+ return p->pipe;
+ }
+ }
+
+ *status = NT_STATUS_PIPE_NOT_AVAILABLE;
+
+ return NULL;
+}
+
+/********************************************************************
+********************************************************************/
+
+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;
+
+ p = TALLOC_ZERO_ARRAY(mem_ctx, struct client_pipe_connection, 1);
+ if (!p) {
+ *status = NT_STATUS_NO_MEMORY;
+ return NULL;
+ }
+
+ p->pipe = cli_rpc_pipe_open_noauth(cli, pipe_idx, status);
+ if (!p->pipe) {
+ TALLOC_FREE(p);
+ return NULL;
+ }
+
+ DLIST_ADD(pipe_connections, p);
+
+ return p->pipe;
+}
+
+/********************************************************************
+********************************************************************/
+
+static struct rpc_pipe_client *pipe_cm_open(TALLOC_CTX *ctx,
+ struct cli_state *cli,
+ int pipe_idx,
+ NTSTATUS *status)
+{
+ 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 p;
+}
+
+/********************************************************************
+********************************************************************/
+
+WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx,
+ struct cli_state *cli,
+ int pipe_idx,
+ struct rpc_pipe_client **pipe_cli)
+{
+ NTSTATUS status;
+
+ if (!cli || !pipe_cli) {
+ return WERR_INVALID_PARAM;
+ }
+
+ *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(pipe_idx),
+ get_friendly_nt_error_msg(status));
+ return WERR_DEST_NOT_FOUND;
+ }
+
+ return WERR_OK;
+}
+
+
diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h
index 2591a7bc09..a575f42f4e 100644
--- a/source3/lib/netapi/netapi_private.h
+++ b/source3/lib/netapi/netapi_private.h
@@ -29,4 +29,8 @@ WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx,
const char *server_name,
struct cli_state **cli);
WERROR libnetapi_shutdown_cm(struct libnetapi_ctx *ctx);
+WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx,
+ struct cli_state *cli,
+ int pipe_idx,
+ struct rpc_pipe_client **pipe_cli);
#endif