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.
|
---|
10 | *
|
---|
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.
|
---|
15 | *
|
---|
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/>.
|
---|
18 | */
|
---|
19 |
|
---|
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"
|
---|
38 |
|
---|
39 | static const char *get_pipe_name_from_iface(
|
---|
40 | TALLOC_CTX *mem_ctx, const struct ndr_interface_table *interface)
|
---|
41 | {
|
---|
42 | int i;
|
---|
43 | const struct ndr_interface_string_array *ep = interface->endpoints;
|
---|
44 | char *p;
|
---|
45 |
|
---|
46 | for (i=0; i<ep->count; i++) {
|
---|
47 | if (strncmp(ep->names[i], "ncacn_np:[\\pipe\\", 16) == 0) {
|
---|
48 | break;
|
---|
49 | }
|
---|
50 | }
|
---|
51 | if (i == ep->count) {
|
---|
52 | return NULL;
|
---|
53 | }
|
---|
54 |
|
---|
55 | /*
|
---|
56 | * extract the pipe name without \\pipe from for example
|
---|
57 | * ncacn_np:[\\pipe\\epmapper]
|
---|
58 | */
|
---|
59 | p = strchr(ep->names[i]+15, ']');
|
---|
60 | if (p == NULL) {
|
---|
61 | return "PIPE";
|
---|
62 | }
|
---|
63 | return talloc_strndup(mem_ctx, ep->names[i]+15, p - ep->names[i] - 15);
|
---|
64 | }
|
---|
65 |
|
---|
66 | static const struct ndr_interface_table **interfaces;
|
---|
67 |
|
---|
68 | bool smb_register_ndr_interface(const struct ndr_interface_table *interface)
|
---|
69 | {
|
---|
70 | int num_interfaces = talloc_array_length(interfaces);
|
---|
71 | const struct ndr_interface_table **tmp;
|
---|
72 | int i;
|
---|
73 |
|
---|
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;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
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;
|
---|
87 | }
|
---|
88 | interfaces = tmp;
|
---|
89 | interfaces[num_interfaces] = interface;
|
---|
90 | return true;
|
---|
91 | }
|
---|
92 |
|
---|
93 | static bool initialize_interfaces(void)
|
---|
94 | {
|
---|
95 | if (!smb_register_ndr_interface(&ndr_table_lsarpc)) {
|
---|
96 | return false;
|
---|
97 | }
|
---|
98 | if (!smb_register_ndr_interface(&ndr_table_dssetup)) {
|
---|
99 | return false;
|
---|
100 | }
|
---|
101 | if (!smb_register_ndr_interface(&ndr_table_samr)) {
|
---|
102 | return false;
|
---|
103 | }
|
---|
104 | if (!smb_register_ndr_interface(&ndr_table_netlogon)) {
|
---|
105 | return false;
|
---|
106 | }
|
---|
107 | if (!smb_register_ndr_interface(&ndr_table_srvsvc)) {
|
---|
108 | return false;
|
---|
109 | }
|
---|
110 | if (!smb_register_ndr_interface(&ndr_table_wkssvc)) {
|
---|
111 | return false;
|
---|
112 | }
|
---|
113 | if (!smb_register_ndr_interface(&ndr_table_winreg)) {
|
---|
114 | return false;
|
---|
115 | }
|
---|
116 | if (!smb_register_ndr_interface(&ndr_table_spoolss)) {
|
---|
117 | return false;
|
---|
118 | }
|
---|
119 | if (!smb_register_ndr_interface(&ndr_table_netdfs)) {
|
---|
120 | return false;
|
---|
121 | }
|
---|
122 | if (!smb_register_ndr_interface(&ndr_table_rpcecho)) {
|
---|
123 | return false;
|
---|
124 | }
|
---|
125 | if (!smb_register_ndr_interface(&ndr_table_initshutdown)) {
|
---|
126 | return false;
|
---|
127 | }
|
---|
128 | if (!smb_register_ndr_interface(&ndr_table_svcctl)) {
|
---|
129 | return false;
|
---|
130 | }
|
---|
131 | if (!smb_register_ndr_interface(&ndr_table_eventlog)) {
|
---|
132 | return false;
|
---|
133 | }
|
---|
134 | if (!smb_register_ndr_interface(&ndr_table_ntsvcs)) {
|
---|
135 | return false;
|
---|
136 | }
|
---|
137 | if (!smb_register_ndr_interface(&ndr_table_epmapper)) {
|
---|
138 | return false;
|
---|
139 | }
|
---|
140 | if (!smb_register_ndr_interface(&ndr_table_drsuapi)) {
|
---|
141 | return false;
|
---|
142 | }
|
---|
143 | return true;
|
---|
144 | }
|
---|
145 |
|
---|
146 | const struct ndr_interface_table *get_iface_from_syntax(
|
---|
147 | const struct ndr_syntax_id *syntax)
|
---|
148 | {
|
---|
149 | int num_interfaces;
|
---|
150 | int i;
|
---|
151 |
|
---|
152 | if (interfaces == NULL) {
|
---|
153 | if (!initialize_interfaces()) {
|
---|
154 | return NULL;
|
---|
155 | }
|
---|
156 | }
|
---|
157 | num_interfaces = talloc_array_length(interfaces);
|
---|
158 |
|
---|
159 | for (i=0; i<num_interfaces; i++) {
|
---|
160 | if (ndr_syntax_id_equal(&interfaces[i]->syntax_id, syntax)) {
|
---|
161 | return interfaces[i];
|
---|
162 | }
|
---|
163 | }
|
---|
164 |
|
---|
165 | return NULL;
|
---|
166 | }
|
---|
167 |
|
---|
168 | /****************************************************************************
|
---|
169 | Return the pipe name from the interface.
|
---|
170 | ****************************************************************************/
|
---|
171 |
|
---|
172 | const char *get_pipe_name_from_syntax(TALLOC_CTX *mem_ctx,
|
---|
173 | const struct ndr_syntax_id *syntax)
|
---|
174 | {
|
---|
175 | const struct ndr_interface_table *interface;
|
---|
176 | char *guid_str;
|
---|
177 | const char *result;
|
---|
178 |
|
---|
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;
|
---|
184 | }
|
---|
185 | }
|
---|
186 |
|
---|
187 | /*
|
---|
188 | * Here we should ask \\epmapper, but for now our code is only
|
---|
189 | * interested in the known pipes mentioned in pipe_names[]
|
---|
190 | */
|
---|
191 |
|
---|
192 | guid_str = GUID_string(talloc_tos(), &syntax->uuid);
|
---|
193 | if (guid_str == NULL) {
|
---|
194 | return NULL;
|
---|
195 | }
|
---|
196 | result = talloc_asprintf(mem_ctx, "Interface %s.%d", guid_str,
|
---|
197 | (int)syntax->if_version);
|
---|
198 | TALLOC_FREE(guid_str);
|
---|
199 |
|
---|
200 | if (result == NULL) {
|
---|
201 | return "PIPE";
|
---|
202 | }
|
---|
203 | return result;
|
---|
204 | }
|
---|
205 |
|
---|