/* form a binding string from a binding structure */ _PUBLIC_ char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b) { char *s = talloc_strdup(mem_ctx, ""); int i; const char *t_name = NULL; if (b->transport != NCA_UNKNOWN) { t_name = derpc_transport_string_by_transport(b->transport); if (!t_name) { return NULL; } } if (!GUID_all_zero(&b->object.uuid)) { s = talloc_asprintf(s, "%s@", GUID_string(mem_ctx, &b->object.uuid)); } if (t_name != NULL) { s = talloc_asprintf_append_buffer(s, "%s:", t_name); if (s == NULL) { return NULL; } } if (b->host) { s = talloc_asprintf_append_buffer(s, "%s", b->host); } if (!b->endpoint && !b->options && !b->flags) { return s; } s = talloc_asprintf_append_buffer(s, "["); if (b->endpoint) { s = talloc_asprintf_append_buffer(s, "%s", b->endpoint); } /* this is a *really* inefficent way of dealing with strings, but this is rarely called and the strings are always short, so I don't care */ for (i=0;b->options && b->options[i];i++) { s = talloc_asprintf_append_buffer(s, ",%s", b->options[i]); if (!s) return NULL; } for (i=0;i<ARRAY_SIZE(ncacn_options);i++) { if (b->flags & ncacn_options[i].flag) { s = talloc_asprintf_append_buffer(s, ",%s", ncacn_options[i].name); if (!s) return NULL; } } s = talloc_asprintf_append_buffer(s, "]"); return s; }
/* * epm_Insert * * Add the specified entries to an endpoint map. */ error_status_t _epm_Insert(struct pipes_struct *p, struct epm_Insert *r) { TALLOC_CTX *tmp_ctx; error_status_t rc; NTSTATUS status; uint32_t i; struct dcerpc_binding *b; struct dcesrv_endpoint *ep; struct dcesrv_iface_list *iflist; struct dcesrv_iface *iface; bool add_ep; /* If this is not a priviledged users, return */ if (p->transport != NCALRPC || !is_priviledged_pipe(p->session_info)) { p->fault_state = DCERPC_FAULT_OP_RNG_ERROR; return EPMAPPER_STATUS_CANT_PERFORM_OP; } tmp_ctx = talloc_stackframe(); if (tmp_ctx == NULL) { return EPMAPPER_STATUS_NO_MEMORY; } DEBUG(3, ("_epm_Insert: Trying to add %u new entries.\n", r->in.num_ents)); for (i = 0; i < r->in.num_ents; i++) { add_ep = false; b = NULL; status = dcerpc_binding_from_tower(tmp_ctx, &r->in.entries[i].tower->tower, &b); if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MEMORY)) { rc = EPMAPPER_STATUS_NO_MEMORY; goto done; } if (!NT_STATUS_IS_OK(status)) { rc = EPMAPPER_STATUS_CANT_PERFORM_OP; goto done; } DEBUG(3, ("_epm_Insert: Adding transport %s for %s\n", derpc_transport_string_by_transport(b->transport), r->in.entries[i].annotation)); /* Check if the entry already exits */ ep = find_endpoint(endpoint_table, b); if (ep == NULL) { /* No entry found, create it */ ep = talloc_zero(NULL, struct dcesrv_endpoint); if (ep == NULL) { rc = EPMAPPER_STATUS_NO_MEMORY; goto done; } add_ep = true; ep->ep_description = talloc_steal(ep, b); } /* TODO Replace the entry if the replace flag is set */ /* Create an interface */ iface = talloc(tmp_ctx, struct dcesrv_iface); if (iface == NULL) { rc = EPMAPPER_STATUS_NO_MEMORY; goto done; } iface->name = talloc_strdup(iface, r->in.entries[i].annotation); if (iface->name == NULL) { rc = EPMAPPER_STATUS_NO_MEMORY; goto done; } iface->syntax_id = b->object; /* * Check if the rpc service is alrady registered on the * endpoint. */ if (find_interface(ep, iface) != NULL) { DEBUG(8, ("dcesrv_interface_register: interface '%s' " "already registered on endpoint\n", iface->name)); /* FIXME wrong error code? */ rc = EPMAPPER_STATUS_OK; goto done; } /* Create an entry for the interface */ iflist = talloc(ep, struct dcesrv_iface_list); if (iflist == NULL) { rc = EPMAPPER_STATUS_NO_MEMORY; goto done; } iflist->iface = talloc_move(iflist, &iface); /* Finally add the interface on the endpoint */ DLIST_ADD(ep->iface_list, iflist); /* If it's a new endpoint add it to the endpoint_table */ if (add_ep) { DLIST_ADD(endpoint_table, ep); } }
/* form a binding string from a binding structure */ _PUBLIC_ char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b) { char *s = talloc_strdup(mem_ctx, ""); char *o = s; int i; const char *t_name = NULL; bool option_section = false; const char *target_hostname = NULL; if (b->transport != NCA_UNKNOWN) { t_name = derpc_transport_string_by_transport(b->transport); if (!t_name) { talloc_free(o); return NULL; } } if (!GUID_all_zero(&b->object)) { o = s; s = talloc_asprintf_append_buffer(s, "%s@", GUID_string(mem_ctx, &b->object)); if (s == NULL) { talloc_free(o); return NULL; } } if (t_name != NULL) { o = s; s = talloc_asprintf_append_buffer(s, "%s:", t_name); if (s == NULL) { talloc_free(o); return NULL; } } if (b->host) { o = s; s = talloc_asprintf_append_buffer(s, "%s", b->host); if (s == NULL) { talloc_free(o); return NULL; } } target_hostname = b->target_hostname; if (target_hostname != NULL && b->host != NULL) { if (strcmp(target_hostname, b->host) == 0) { target_hostname = NULL; } } if (b->endpoint) { option_section = true; } else if (target_hostname) { option_section = true; } else if (b->target_principal) { option_section = true; } else if (b->assoc_group_id != 0) { option_section = true; } else if (b->options) { option_section = true; } else if (b->flags) { option_section = true; } if (!option_section) { return s; } o = s; s = talloc_asprintf_append_buffer(s, "["); if (s == NULL) { talloc_free(o); return NULL; } if (b->endpoint) { o = s; s = talloc_asprintf_append_buffer(s, "%s", b->endpoint); if (s == NULL) { talloc_free(o); return NULL; } } for (i=0;i<ARRAY_SIZE(ncacn_options);i++) { if (!(b->flags & ncacn_options[i].flag)) { continue; } o = s; s = talloc_asprintf_append_buffer(s, ",%s", ncacn_options[i].name); if (s == NULL) { talloc_free(o); return NULL; } } if (target_hostname) { o = s; s = talloc_asprintf_append_buffer(s, ",target_hostname=%s", b->target_hostname); if (s == NULL) { talloc_free(o); return NULL; } } if (b->target_principal) { o = s; s = talloc_asprintf_append_buffer(s, ",target_principal=%s", b->target_principal); if (s == NULL) { talloc_free(o); return NULL; } } if (b->assoc_group_id != 0) { o = s; s = talloc_asprintf_append_buffer(s, ",assoc_group_id=0x%08x", b->assoc_group_id); if (s == NULL) { talloc_free(o); return NULL; } } for (i=0;b->options && b->options[i];i++) { o = s; s = talloc_asprintf_append_buffer(s, ",%s", b->options[i]); if (s == NULL) { talloc_free(o); return NULL; } } o = s; s = talloc_asprintf_append_buffer(s, "]"); if (s == NULL) { talloc_free(o); return NULL; } return s; }