diff options
author | Simo Sorce <idra@samba.org> | 2011-07-21 11:02:59 -0400 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2011-07-21 19:50:02 +0200 |
commit | 156a0ffe542339952a6e2db191ffc586227edd5a (patch) | |
tree | 84d6b14cb96e7b0ed9c4311df175e01ef0115f70 /source3 | |
parent | 759a04e58a88b400dbf0cafc2b86ab58ea196433 (diff) | |
download | samba-156a0ffe542339952a6e2db191ffc586227edd5a.tar.gz samba-156a0ffe542339952a6e2db191ffc586227edd5a.tar.bz2 samba-156a0ffe542339952a6e2db191ffc586227edd5a.zip |
s3-rpc_server: Create common function to allocate pipes_struct
Avoid code duplication and fix bug where a new pipe was not added to
InternalPipes upon creation in make_server_pipes_struct()
Signed-off-by: Andreas Schneider <asn@samba.org>
Autobuild-User: Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date: Thu Jul 21 19:50:02 CEST 2011 on sn-devel-104
Diffstat (limited to 'source3')
-rw-r--r-- | source3/rpc_server/rpc_handles.c | 50 | ||||
-rw-r--r-- | source3/rpc_server/rpc_ncacn_np.c | 41 | ||||
-rw-r--r-- | source3/rpc_server/rpc_pipes.h | 8 | ||||
-rw-r--r-- | source3/rpc_server/rpc_server.c | 45 |
4 files changed, 76 insertions, 68 deletions
diff --git a/source3/rpc_server/rpc_handles.c b/source3/rpc_server/rpc_handles.c index 1fbee9e3c0..c40029bd08 100644 --- a/source3/rpc_server/rpc_handles.c +++ b/source3/rpc_server/rpc_handles.c @@ -25,6 +25,7 @@ #include "auth.h" #include "rpc_server/rpc_pipes.h" #include "../libcli/security/security.h" +#include "lib/tsocket/tsocket.h" #undef DBGC_CLASS #define DBGC_CLASS DBGC_RPC_SRV @@ -41,6 +42,55 @@ static struct pipes_struct *InternalPipes; * system _anyway_. so that's the next step... */ +int make_base_pipes_struct(TALLOC_CTX *mem_ctx, + struct messaging_context *msg_ctx, + const char *pipe_name, + enum dcerpc_transport_t transport, + bool endian, bool ncalrpc_as_system, + const struct tsocket_address *remote_address, + const struct tsocket_address *local_address, + struct pipes_struct **_p) +{ + struct pipes_struct *p; + + p = talloc_zero(mem_ctx, struct pipes_struct); + if (!p) { + return ENOMEM; + } + + p->mem_ctx = talloc_named(p, 0, "pipe %s %p", pipe_name, p); + if (!p->mem_ctx) { + talloc_free(p); + return ENOMEM; + } + + p->msg_ctx = msg_ctx; + p->transport = transport; + p->endian = endian; + p->ncalrpc_as_system = ncalrpc_as_system; + + p->remote_address = tsocket_address_copy(remote_address, p); + if (p->remote_address == NULL) { + talloc_free(p); + return ENOMEM; + } + + if (local_address) { + p->local_address = tsocket_address_copy(remote_address, p); + if (p->local_address == NULL) { + talloc_free(p); + return ENOMEM; + } + } + + DLIST_ADD(InternalPipes, p); + talloc_set_destructor(p, close_internal_rpc_pipe_hnd); + + *_p = p; + return 0; +} + + bool check_open_pipes(void) { struct pipes_struct *p; diff --git a/source3/rpc_server/rpc_ncacn_np.c b/source3/rpc_server/rpc_ncacn_np.c index dea079f3f5..2ed4a01704 100644 --- a/source3/rpc_server/rpc_ncacn_np.c +++ b/source3/rpc_server/rpc_ncacn_np.c @@ -31,7 +31,7 @@ #include "librpc/gen_ndr/auth.h" #include "../auth/auth_sam_reply.h" #include "auth.h" -#include "ntdomain.h" +#include "rpc_server/rpc_pipes.h" #include "../lib/tsocket/tsocket.h" #include "../lib/util/tevent_ntstatus.h" #include "rpc_contexts.h" @@ -51,26 +51,21 @@ struct pipes_struct *make_internal_rpc_pipe_p(TALLOC_CTX *mem_ctx, { struct pipes_struct *p; struct pipe_rpc_fns *context_fns; + const char *pipe_name; + int ret; - DEBUG(4,("Create pipe requested %s\n", - get_pipe_name_from_syntax(talloc_tos(), syntax))); + pipe_name = get_pipe_name_from_syntax(talloc_tos(), syntax); - p = talloc_zero(mem_ctx, struct pipes_struct); + DEBUG(4,("Create pipe requested %s\n", pipe_name)); - if (!p) { + ret = make_base_pipes_struct(mem_ctx, msg_ctx, pipe_name, + NCALRPC, RPC_LITTLE_ENDIAN, false, + remote_address, NULL, &p); + if (ret) { DEBUG(0,("ERROR! no memory for pipes_struct!\n")); return NULL; } - p->mem_ctx = talloc_named(p, 0, "pipe %s %p", - get_pipe_name_from_syntax(talloc_tos(), - syntax), p); - if (p->mem_ctx == NULL) { - DEBUG(0,("open_rpc_pipe_p: talloc_init failed.\n")); - TALLOC_FREE(p); - return NULL; - } - if (!init_pipe_handles(p, syntax)) { DEBUG(0,("open_rpc_pipe_p: init_pipe_handles failed.\n")); TALLOC_FREE(p); @@ -85,19 +80,6 @@ struct pipes_struct *make_internal_rpc_pipe_p(TALLOC_CTX *mem_ctx, return NULL; } - p->msg_ctx = msg_ctx; - - DLIST_ADD(InternalPipes, p); - - p->remote_address = tsocket_address_copy(remote_address, p); - if (p->remote_address == NULL) { - return false; - } - - p->endian = RPC_LITTLE_ENDIAN; - - p->transport = NCALRPC; - context_fns = SMB_MALLOC_P(struct pipe_rpc_fns); if (context_fns == NULL) { DEBUG(0,("malloc() failed!\n")); @@ -113,10 +95,7 @@ struct pipes_struct *make_internal_rpc_pipe_p(TALLOC_CTX *mem_ctx, /* add to the list of open contexts */ DLIST_ADD(p->contexts, context_fns); - DEBUG(4,("Created internal pipe %s\n", - get_pipe_name_from_syntax(talloc_tos(), syntax))); - - talloc_set_destructor(p, close_internal_rpc_pipe_hnd); + DEBUG(4,("Created internal pipe %s\n", pipe_name)); return p; } diff --git a/source3/rpc_server/rpc_pipes.h b/source3/rpc_server/rpc_pipes.h index 9315830351..bfef5d6d11 100644 --- a/source3/rpc_server/rpc_pipes.h +++ b/source3/rpc_server/rpc_pipes.h @@ -182,6 +182,14 @@ struct pipes_struct { }; +int make_base_pipes_struct(TALLOC_CTX *mem_ctx, + struct messaging_context *msg_ctx, + const char *pipe_name, + enum dcerpc_transport_t transport, + bool endian, bool ncalrpc_as_system, + const struct tsocket_address *remote_address, + const struct tsocket_address *local_address, + struct pipes_struct **_p); bool check_open_pipes(void); int close_internal_rpc_pipe_hnd(struct pipes_struct *p); diff --git a/source3/rpc_server/rpc_server.c b/source3/rpc_server/rpc_server.c index 7b0982e9b1..43e549b5ae 100644 --- a/source3/rpc_server/rpc_server.c +++ b/source3/rpc_server/rpc_server.c @@ -20,7 +20,7 @@ */ #include "includes.h" -#include "ntdomain.h" +#include "rpc_server/rpc_pipes.h" #include "rpc_server/rpc_server.h" #include "rpc_dce.h" #include "librpc/gen_ndr/netlogon.h" @@ -64,29 +64,18 @@ static int make_server_pipes_struct(TALLOC_CTX *mem_ctx, { struct pipes_struct *p; NTSTATUS status; + int ret; - p = talloc_zero(mem_ctx, struct pipes_struct); - if (!p) { - *perrno = ENOMEM; - return -1; - } - - p->transport = transport; - p->ncalrpc_as_system = ncalrpc_as_system; - - p->mem_ctx = talloc_named(p, 0, "pipe %s %p", pipe_name, p); - if (!p->mem_ctx) { - TALLOC_FREE(p); - *perrno = ENOMEM; + ret = make_base_pipes_struct(mem_ctx, NULL, pipe_name, + transport, RPC_LITTLE_ENDIAN, + ncalrpc_as_system, + remote_address, local_address, &p); + if (ret) { + *perrno = ret; return -1; } p->msg_ctx = msg_ctx; - data_blob_free(&p->in_data.data); - data_blob_free(&p->in_data.pdu); - - p->endian = RPC_LITTLE_ENDIAN; - if (session_info->unix_token && session_info->unix_info && session_info->security_token) { /* Don't call create_local_token(), we already have the full details here */ p->session_info = talloc_steal(p, session_info); @@ -145,24 +134,6 @@ static int make_server_pipes_struct(TALLOC_CTX *mem_ctx, } } - p->remote_address = tsocket_address_copy(remote_address, p); - if (p->remote_address == NULL) { - TALLOC_FREE(p); - *perrno = ENOMEM; - return -1; - } - - if (local_address != NULL) { - p->local_address = tsocket_address_copy(local_address, p); - if (p->local_address == NULL) { - TALLOC_FREE(p); - *perrno = ENOMEM; - return -1; - } - } - - talloc_set_destructor(p, close_internal_rpc_pipe_hnd); - *_p = p; return 0; } |