s3-librpc: Added dcerpc register endpoint functions.
[Samba/gebeck_regimport.git] / source3 / librpc / rpc / dcerpc_ep.c
blobbf193662aad0cf244f9e0746b587fa062dcaaf0c
1 /*
2 * Endpoint Mapper Functions
3 * DCERPC local endpoint mapper client routines
4 * Copyright (c) 2010 Andreas Schneider.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "librpc/rpc/dcerpc.h"
22 #include "librpc/rpc/dcerpc_ep.h"
23 #include "librpc/gen_ndr/cli_epmapper.h"
25 #define EPM_MAX_ANNOTATION_SIZE 64
27 static NTSTATUS ep_register(const struct ndr_interface_table *iface,
28 const struct dcerpc_binding_vector *bind_vec,
29 const struct GUID *object_guid,
30 const char *annotation,
31 uint32_t replace)
33 struct dcerpc_binding_handle *h = NULL;
34 static struct client_address client_id;
35 struct epm_entry_t *entries;
36 uint32_t num_ents, i;
37 TALLOC_CTX *tmp_ctx;
38 NTSTATUS result = NT_STATUS_OK;
39 NTSTATUS status;
41 if (iface == NULL) {
42 return NT_STATUS_INVALID_PARAMETER;
45 if (bind_vec == NULL || bind_vec->count == 0) {
46 return NT_STATUS_INVALID_PARAMETER;
49 tmp_ctx = talloc_stackframe();
50 if (tmp_ctx == NULL) {
51 return NT_STATUS_NO_MEMORY;
54 #if 0
55 /* NOTE: Samba3 doesn't have a ncalrpc server component yet. As soon as
56 * this is supported, we should talk to the endpoint mapper over the
57 * local transport.
60 /* Connect to the endpoint mapper locally */
61 ncalrpc_sock = talloc_asprintf(tmp_ctx,
62 "%s/%s",
63 get_dyn_NCALRPCDIR(),
64 "epmapper");
65 if (ncalrpc_sock == NULL) {
66 status = NT_STATUS_NO_MEMORY;
67 goto done;
70 status = rpc_pipe_open_ncalrpc(tmp_ctx,
71 ncalrpc_sock,
72 &ndr_table_epmapper.syntax_id,
73 &cli);
74 if (!NT_STATUS_IS_OK(status)) {
75 goto done;
77 #endif
79 strlcpy(client_id.addr, "localhost", sizeof(client_id.addr));
80 client_id.name = "localhost";
82 status = rpcint_binding_handle(tmp_ctx,
83 &ndr_table_epmapper,
84 &client_id,
85 get_server_info_system(),
86 server_messaging_context(),
87 &h);
88 if (!NT_STATUS_IS_OK(status)) {
89 DEBUG(0, ("dcerpc_ep_register: Could not connect to epmapper (%s)",
90 nt_errstr(status)));
91 goto done;
94 num_ents = bind_vec->count;
95 entries = talloc_array(tmp_ctx, struct epm_entry_t, num_ents);
97 for (i = 0; i < num_ents; i++) {
98 struct dcerpc_binding *map_binding = &bind_vec->bindings[i];
99 struct epm_twr_t *map_tower;
101 map_tower = talloc_zero(entries, struct epm_twr_t);
102 if (map_tower == NULL) {
103 goto done;
106 status = dcerpc_binding_build_tower(entries,
107 map_binding,
108 &map_tower->tower);
109 if (!NT_STATUS_IS_OK(status)) {
110 goto done;
113 entries[i].tower = map_tower;
114 entries[i].annotation = talloc_strndup(entries, annotation,
115 EPM_MAX_ANNOTATION_SIZE);
116 if (entries[i].annotation == NULL) {
117 status = NT_STATUS_NO_MEMORY;
118 goto done;
120 if (object_guid != NULL) {
121 entries[i].object = *object_guid;
122 } else {
123 entries[i].object = map_binding->object.uuid;
127 status = dcerpc_epm_Insert(h,
128 tmp_ctx,
129 num_ents,
130 entries,
131 replace,
132 &result);
133 if (!NT_STATUS_IS_OK(status)) {
134 DEBUG(0, ("dcerpc_ep_register: Could not insert tower (%s)\n",
135 nt_errstr(status)));
136 goto done;
138 if (!NT_STATUS_IS_OK(result)) {
139 DEBUG(0, ("dcerpc_ep_register: Could not insert tower (%s)\n",
140 nt_errstr(result)));
141 status = result;
142 goto done;
145 done:
146 talloc_free(tmp_ctx);
148 return status;
151 NTSTATUS dcerpc_ep_register(const struct ndr_interface_table *iface,
152 const struct dcerpc_binding_vector *bind_vec,
153 const struct GUID *object_guid,
154 const char *annotation)
156 return ep_register(iface, bind_vec, object_guid, annotation, 1);
159 NTSTATUS dcerpc_ep_register_noreplace(const struct ndr_interface_table *iface,
160 const struct dcerpc_binding_vector *bind_vec,
161 const struct GUID *object_guid,
162 const char *annotation)
164 return ep_register(iface, bind_vec, object_guid, annotation, 0);
167 /* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */