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/gen_ndr/ndr_schannel.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
)
43 const struct ndr_interface_string_array
*ep
= interface
->endpoints
;
46 for (i
=0; i
<ep
->count
; i
++) {
47 if (strncmp(ep
->names
[i
], "ncacn_np:[\\pipe\\", 16) == 0) {
56 * extract the pipe name without \\pipe from for example
57 * ncacn_np:[\\pipe\\epmapper]
59 p
= strchr(ep
->names
[i
]+15, ']');
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
;
74 for (i
=0; i
<num_interfaces
; i
++) {
75 if (ndr_syntax_id_equal(&interfaces
[i
]->syntax_id
,
76 &interface
->syntax_id
)) {
81 tmp
= talloc_realloc(NULL
, interfaces
,
82 const struct ndr_interface_table
*,
85 DEBUG(1, ("smb_register_ndr_interface: talloc failed\n"));
89 interfaces
[num_interfaces
] = interface
;
93 static bool initialize_interfaces(void)
95 if (!smb_register_ndr_interface(&ndr_table_lsarpc
)) {
98 if (!smb_register_ndr_interface(&ndr_table_dssetup
)) {
101 if (!smb_register_ndr_interface(&ndr_table_samr
)) {
104 if (!smb_register_ndr_interface(&ndr_table_netlogon
)) {
107 if (!smb_register_ndr_interface(&ndr_table_srvsvc
)) {
110 if (!smb_register_ndr_interface(&ndr_table_wkssvc
)) {
113 if (!smb_register_ndr_interface(&ndr_table_winreg
)) {
116 if (!smb_register_ndr_interface(&ndr_table_spoolss
)) {
119 if (!smb_register_ndr_interface(&ndr_table_netdfs
)) {
122 if (!smb_register_ndr_interface(&ndr_table_rpcecho
)) {
125 if (!smb_register_ndr_interface(&ndr_table_initshutdown
)) {
128 if (!smb_register_ndr_interface(&ndr_table_svcctl
)) {
131 if (!smb_register_ndr_interface(&ndr_table_eventlog
)) {
134 if (!smb_register_ndr_interface(&ndr_table_ntsvcs
)) {
137 if (!smb_register_ndr_interface(&ndr_table_epmapper
)) {
140 if (!smb_register_ndr_interface(&ndr_table_drsuapi
)) {
146 const struct ndr_interface_table
*get_iface_from_syntax(
147 const struct ndr_syntax_id
*syntax
)
152 if (interfaces
== NULL
) {
153 if (!initialize_interfaces()) {
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
];
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
;
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
) {
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
) {
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
) {