s3-dbwrap: Fix an unused var warning
[Samba.git] / source3 / librpc / rpc / rpc_common.c
blob65e3205f62a28991730293df0bfaf0c6035750a1
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Largely rewritten by Jeremy Allison 2005.
5 *
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/gen_ndr/ndr_lsa.h"
23 #include "../librpc/gen_ndr/ndr_dssetup.h"
24 #include "../librpc/gen_ndr/ndr_samr.h"
25 #include "../librpc/gen_ndr/ndr_netlogon.h"
26 #include "../librpc/gen_ndr/ndr_srvsvc.h"
27 #include "../librpc/gen_ndr/ndr_wkssvc.h"
28 #include "../librpc/gen_ndr/ndr_winreg.h"
29 #include "../librpc/gen_ndr/ndr_spoolss.h"
30 #include "../librpc/gen_ndr/ndr_dfs.h"
31 #include "../librpc/gen_ndr/ndr_echo.h"
32 #include "../librpc/gen_ndr/ndr_initshutdown.h"
33 #include "../librpc/gen_ndr/ndr_svcctl.h"
34 #include "../librpc/gen_ndr/ndr_eventlog.h"
35 #include "../librpc/gen_ndr/ndr_ntsvcs.h"
36 #include "../librpc/gen_ndr/ndr_epmapper.h"
37 #include "../librpc/gen_ndr/ndr_drsuapi.h"
39 static const char *get_pipe_name_from_iface(
40 TALLOC_CTX *mem_ctx, const struct ndr_interface_table *interface)
42 int i;
43 const struct ndr_interface_string_array *ep = interface->endpoints;
44 char *p;
46 for (i=0; i<ep->count; i++) {
47 if (strncmp(ep->names[i], "ncacn_np:[\\pipe\\", 16) == 0) {
48 break;
51 if (i == ep->count) {
52 return NULL;
56 * extract the pipe name without \\pipe from for example
57 * ncacn_np:[\\pipe\\epmapper]
59 p = strchr(ep->names[i]+15, ']');
60 if (p == NULL) {
61 return "PIPE";
63 return talloc_strndup(mem_ctx, ep->names[i]+15, p - ep->names[i] - 15);
66 static const struct ndr_interface_table **interfaces;
68 bool smb_register_ndr_interface(const struct ndr_interface_table *interface)
70 int num_interfaces = talloc_array_length(interfaces);
71 const struct ndr_interface_table **tmp;
72 int i;
74 for (i=0; i<num_interfaces; i++) {
75 if (ndr_syntax_id_equal(&interfaces[i]->syntax_id,
76 &interface->syntax_id)) {
77 return true;
81 tmp = talloc_realloc(NULL, interfaces,
82 const struct ndr_interface_table *,
83 num_interfaces + 1);
84 if (tmp == NULL) {
85 DEBUG(1, ("smb_register_ndr_interface: talloc failed\n"));
86 return false;
88 interfaces = tmp;
89 interfaces[num_interfaces] = interface;
90 return true;
93 static bool initialize_interfaces(void)
95 if (!smb_register_ndr_interface(&ndr_table_lsarpc)) {
96 return false;
98 if (!smb_register_ndr_interface(&ndr_table_dssetup)) {
99 return false;
101 if (!smb_register_ndr_interface(&ndr_table_samr)) {
102 return false;
104 if (!smb_register_ndr_interface(&ndr_table_netlogon)) {
105 return false;
107 if (!smb_register_ndr_interface(&ndr_table_srvsvc)) {
108 return false;
110 if (!smb_register_ndr_interface(&ndr_table_wkssvc)) {
111 return false;
113 if (!smb_register_ndr_interface(&ndr_table_winreg)) {
114 return false;
116 if (!smb_register_ndr_interface(&ndr_table_spoolss)) {
117 return false;
119 if (!smb_register_ndr_interface(&ndr_table_netdfs)) {
120 return false;
122 if (!smb_register_ndr_interface(&ndr_table_rpcecho)) {
123 return false;
125 if (!smb_register_ndr_interface(&ndr_table_initshutdown)) {
126 return false;
128 if (!smb_register_ndr_interface(&ndr_table_svcctl)) {
129 return false;
131 if (!smb_register_ndr_interface(&ndr_table_eventlog)) {
132 return false;
134 if (!smb_register_ndr_interface(&ndr_table_ntsvcs)) {
135 return false;
137 if (!smb_register_ndr_interface(&ndr_table_epmapper)) {
138 return false;
140 if (!smb_register_ndr_interface(&ndr_table_drsuapi)) {
141 return false;
143 return true;
146 const struct ndr_interface_table *get_iface_from_syntax(
147 const struct ndr_syntax_id *syntax)
149 int num_interfaces;
150 int i;
152 if (interfaces == NULL) {
153 if (!initialize_interfaces()) {
154 return NULL;
157 num_interfaces = talloc_array_length(interfaces);
159 for (i=0; i<num_interfaces; i++) {
160 if (ndr_syntax_id_equal(&interfaces[i]->syntax_id, syntax)) {
161 return interfaces[i];
165 return NULL;
168 /****************************************************************************
169 Return the pipe name from the interface.
170 ****************************************************************************/
172 const char *get_pipe_name_from_syntax(TALLOC_CTX *mem_ctx,
173 const struct ndr_syntax_id *syntax)
175 const struct ndr_interface_table *interface;
176 char *guid_str;
177 const char *result;
179 interface = get_iface_from_syntax(syntax);
180 if (interface != NULL) {
181 result = get_pipe_name_from_iface(mem_ctx, interface);
182 if (result != NULL) {
183 return result;
188 * Here we should ask \\epmapper, but for now our code is only
189 * interested in the known pipes mentioned in pipe_names[]
192 guid_str = GUID_string(talloc_tos(), &syntax->uuid);
193 if (guid_str == NULL) {
194 return NULL;
196 result = talloc_asprintf(mem_ctx, "Interface %s.%d", guid_str,
197 (int)syntax->if_version);
198 TALLOC_FREE(guid_str);
200 if (result == NULL) {
201 return "PIPE";
203 return result;