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/>.
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
,
33 struct dcerpc_binding_handle
*h
= NULL
;
34 static struct client_address client_id
;
35 struct epm_entry_t
*entries
;
38 NTSTATUS result
= NT_STATUS_OK
;
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
;
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
60 /* Connect to the endpoint mapper locally */
61 ncalrpc_sock
= talloc_asprintf(tmp_ctx
,
65 if (ncalrpc_sock
== NULL
) {
66 status
= NT_STATUS_NO_MEMORY
;
70 status
= rpc_pipe_open_ncalrpc(tmp_ctx
,
72 &ndr_table_epmapper
.syntax_id
,
74 if (!NT_STATUS_IS_OK(status
)) {
79 strlcpy(client_id
.addr
, "localhost", sizeof(client_id
.addr
));
80 client_id
.name
= "localhost";
82 status
= rpcint_binding_handle(tmp_ctx
,
85 get_server_info_system(),
86 server_messaging_context(),
88 if (!NT_STATUS_IS_OK(status
)) {
89 DEBUG(0, ("dcerpc_ep_register: Could not connect to epmapper (%s)",
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
) {
106 status
= dcerpc_binding_build_tower(entries
,
109 if (!NT_STATUS_IS_OK(status
)) {
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
;
120 if (object_guid
!= NULL
) {
121 entries
[i
].object
= *object_guid
;
123 entries
[i
].object
= map_binding
->object
.uuid
;
127 status
= dcerpc_epm_Insert(h
,
133 if (!NT_STATUS_IS_OK(status
)) {
134 DEBUG(0, ("dcerpc_ep_register: Could not insert tower (%s)\n",
138 if (!NT_STATUS_IS_OK(result
)) {
139 DEBUG(0, ("dcerpc_ep_register: Could not insert tower (%s)\n",
146 talloc_free(tmp_ctx
);
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: */