1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-22 22:04:08 +03:00

librpc:core: Add a function to register an interface passing the binding handle

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
This commit is contained in:
Samuel Cabrero 2021-08-19 12:52:04 +02:00 committed by Volker Lendecke
parent 99bf0c1b26
commit 9c8521848b
2 changed files with 59 additions and 26 deletions

View File

@ -176,11 +176,47 @@ _PUBLIC_ NTSTATUS dcesrv_interface_register(struct dcesrv_context *dce_ctx,
const char *ncacn_np_secondary_endpoint,
const struct dcesrv_interface *iface,
const struct security_descriptor *sd)
{
struct dcerpc_binding *binding = NULL;
struct dcerpc_binding *binding2 = NULL;
NTSTATUS ret;
ret = dcerpc_parse_binding(dce_ctx, ep_name, &binding);
if (NT_STATUS_IS_ERR(ret)) {
DBG_ERR("Trouble parsing binding string '%s'\n", ep_name);
goto out;
}
if (ncacn_np_secondary_endpoint != NULL) {
ret = dcerpc_parse_binding(dce_ctx,
ncacn_np_secondary_endpoint,
&binding2);
if (NT_STATUS_IS_ERR(ret)) {
DBG_ERR("Trouble parsing 2nd binding string '%s'\n",
ncacn_np_secondary_endpoint);
goto out;
}
}
ret = dcesrv_interface_register_b(dce_ctx,
binding,
binding2,
iface,
sd);
out:
TALLOC_FREE(binding);
TALLOC_FREE(binding2);
return ret;
}
_PUBLIC_ NTSTATUS dcesrv_interface_register_b(struct dcesrv_context *dce_ctx,
struct dcerpc_binding *binding,
struct dcerpc_binding *binding2,
const struct dcesrv_interface *iface,
const struct security_descriptor *sd)
{
struct dcesrv_endpoint *ep;
struct dcesrv_if_list *ifl;
struct dcerpc_binding *binding;
struct dcerpc_binding *binding2 = NULL;
bool add_ep = false;
NTSTATUS status;
enum dcerpc_transport_t transport;
@ -201,13 +237,6 @@ _PUBLIC_ NTSTATUS dcesrv_interface_register(struct dcesrv_context *dce_ctx,
use_single_process = false;
}
status = dcerpc_parse_binding(dce_ctx, ep_name, &binding);
if (NT_STATUS_IS_ERR(status)) {
DEBUG(0, ("Trouble parsing binding string '%s'\n", ep_name));
return status;
}
transport = dcerpc_binding_get_transport(binding);
if (transport == NCACN_IP_TCP) {
int port;
@ -245,26 +274,19 @@ _PUBLIC_ NTSTATUS dcesrv_interface_register(struct dcesrv_context *dce_ctx,
}
}
if (transport == NCACN_NP && ncacn_np_secondary_endpoint != NULL) {
if (transport == NCACN_NP && binding2 != NULL) {
enum dcerpc_transport_t transport2;
status = dcerpc_parse_binding(dce_ctx,
ncacn_np_secondary_endpoint,
&binding2);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("Trouble parsing 2nd binding string '%s'\n",
ncacn_np_secondary_endpoint));
return status;
}
transport2 = dcerpc_binding_get_transport(binding2);
SMB_ASSERT(transport2 == transport);
}
/* see if the interface is already registered on the endpoint */
if (find_interface_by_binding(dce_ctx, binding, iface)!=NULL) {
DEBUG(0,("dcesrv_interface_register: interface '%s' already registered on endpoint '%s'\n",
iface->name, ep_name));
char *binding_string = dcerpc_binding_string(dce_ctx, binding);
DBG_ERR("Interface '%s' already registered on endpoint '%s'\n",
iface->name, binding_string);
TALLOC_FREE(binding_string);
return NT_STATUS_OBJECT_NAME_COLLISION;
}
@ -299,8 +321,11 @@ _PUBLIC_ NTSTATUS dcesrv_interface_register(struct dcesrv_context *dce_ctx,
if (!ep) {
return NT_STATUS_NO_MEMORY;
}
ep->ep_description = talloc_move(ep, &binding);
ep->ep_2nd_description = talloc_move(ep, &binding2);
ep->ep_description = dcerpc_binding_dup(ep, binding);
if (transport == NCACN_NP && binding2 != NULL) {
ep->ep_2nd_description =
dcerpc_binding_dup(ep, binding2);
}
add_ep = true;
/* add mgmt interface */
@ -367,9 +392,12 @@ _PUBLIC_ NTSTATUS dcesrv_interface_register(struct dcesrv_context *dce_ctx,
* or there was already one on the endpoint
*/
if (ep->sd != NULL) {
DEBUG(0,("dcesrv_interface_register: interface '%s' failed to setup a security descriptor\n"
" on endpoint '%s'\n",
iface->name, ep_name));
char *binding_string =
dcerpc_binding_string(dce_ctx, binding);
DBG_ERR("Interface '%s' failed to setup a security "
"descriptor on endpoint '%s'\n",
iface->name, binding_string);
TALLOC_FREE(binding_string);
if (add_ep) free(ep);
free(ifl);
return NT_STATUS_OBJECT_NAME_COLLISION;

View File

@ -462,6 +462,11 @@ NTSTATUS dcesrv_interface_register(struct dcesrv_context *dce_ctx,
const char *ncacn_np_secondary_endpoint,
const struct dcesrv_interface *iface,
const struct security_descriptor *sd);
NTSTATUS dcesrv_interface_register_b(struct dcesrv_context *dce_ctx,
struct dcerpc_binding *binding,
struct dcerpc_binding *binding2,
const struct dcesrv_interface *iface,
const struct security_descriptor *sd);
NTSTATUS dcerpc_register_ep_server(const struct dcesrv_endpoint_server *ep_server);
NTSTATUS dcesrv_init_ep_servers(struct dcesrv_context *dce_ctx,
const char **ep_servers);