2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Largely rewritten by Jeremy Allison 2005.
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/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"
38 #include "../librpc/gen_ndr/ndr_fsrvp.h"
40 static const char *get_pipe_name_from_iface(
41 TALLOC_CTX
*mem_ctx
, const struct ndr_interface_table
*interface
)
44 const struct ndr_interface_string_array
*ep
= interface
->endpoints
;
47 for (i
=0; i
<ep
->count
; i
++) {
48 if (strncmp(ep
->names
[i
], "ncacn_np:[\\pipe\\", 16) == 0) {
57 * extract the pipe name without \\pipe from for example
58 * ncacn_np:[\\pipe\\epmapper]
60 p
= strchr(ep
->names
[i
]+15, ']');
64 return talloc_strndup(mem_ctx
, ep
->names
[i
]+15, p
- ep
->names
[i
] - 15);
67 static const struct ndr_interface_table
**interfaces
;
69 bool smb_register_ndr_interface(const struct ndr_interface_table
*interface
)
71 int num_interfaces
= talloc_array_length(interfaces
);
72 const struct ndr_interface_table
**tmp
;
75 for (i
=0; i
<num_interfaces
; i
++) {
76 if (ndr_syntax_id_equal(&interfaces
[i
]->syntax_id
,
77 &interface
->syntax_id
)) {
82 tmp
= talloc_realloc(NULL
, interfaces
,
83 const struct ndr_interface_table
*,
86 DEBUG(1, ("smb_register_ndr_interface: talloc failed\n"));
90 interfaces
[num_interfaces
] = interface
;
94 static bool initialize_interfaces(void)
96 if (!smb_register_ndr_interface(&ndr_table_lsarpc
)) {
99 if (!smb_register_ndr_interface(&ndr_table_dssetup
)) {
102 if (!smb_register_ndr_interface(&ndr_table_samr
)) {
105 if (!smb_register_ndr_interface(&ndr_table_netlogon
)) {
108 if (!smb_register_ndr_interface(&ndr_table_srvsvc
)) {
111 if (!smb_register_ndr_interface(&ndr_table_wkssvc
)) {
114 if (!smb_register_ndr_interface(&ndr_table_winreg
)) {
117 if (!smb_register_ndr_interface(&ndr_table_spoolss
)) {
120 if (!smb_register_ndr_interface(&ndr_table_netdfs
)) {
123 if (!smb_register_ndr_interface(&ndr_table_rpcecho
)) {
126 if (!smb_register_ndr_interface(&ndr_table_initshutdown
)) {
129 if (!smb_register_ndr_interface(&ndr_table_svcctl
)) {
132 if (!smb_register_ndr_interface(&ndr_table_eventlog
)) {
135 if (!smb_register_ndr_interface(&ndr_table_ntsvcs
)) {
138 if (!smb_register_ndr_interface(&ndr_table_epmapper
)) {
141 if (!smb_register_ndr_interface(&ndr_table_drsuapi
)) {
144 if (!smb_register_ndr_interface(&ndr_table_FileServerVssAgent
)) {
150 const struct ndr_interface_table
*get_iface_from_syntax(
151 const struct ndr_syntax_id
*syntax
)
156 if (interfaces
== NULL
) {
157 if (!initialize_interfaces()) {
161 num_interfaces
= talloc_array_length(interfaces
);
163 for (i
=0; i
<num_interfaces
; i
++) {
164 if (ndr_syntax_id_equal(&interfaces
[i
]->syntax_id
, syntax
)) {
165 return interfaces
[i
];
172 /****************************************************************************
173 Return the pipe name from the interface.
174 ****************************************************************************/
176 const char *get_pipe_name_from_syntax(TALLOC_CTX
*mem_ctx
,
177 const struct ndr_syntax_id
*syntax
)
179 const struct ndr_interface_table
*interface
;
183 interface
= get_iface_from_syntax(syntax
);
184 if (interface
!= NULL
) {
185 result
= get_pipe_name_from_iface(mem_ctx
, interface
);
186 if (result
!= NULL
) {
192 * Here we should ask \\epmapper, but for now our code is only
193 * interested in the known pipes mentioned in pipe_names[]
196 guid_str
= GUID_string(talloc_tos(), &syntax
->uuid
);
197 if (guid_str
== NULL
) {
200 result
= talloc_asprintf(mem_ctx
, "Interface %s.%d", guid_str
,
201 (int)syntax
->if_version
);
202 TALLOC_FREE(guid_str
);
204 if (result
== NULL
) {